From b60305dd194409939a9e9a65abde2a852af402be Mon Sep 17 00:00:00 2001 From: Viktor Kovacs Date: Fri, 2 Apr 2021 09:25:41 +0200 Subject: [PATCH] Possibility to set the default material color for importer in case of no-material surfaces. --- source/external/three.model.loader.js | 5 +++++ source/import/importer.js | 8 +++++++- test/tests/importer_test.js | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/source/external/three.model.loader.js b/source/external/three.model.loader.js index 236ded1..7e6157e 100644 --- a/source/external/three.model.loader.js +++ b/source/external/three.model.loader.js @@ -12,6 +12,11 @@ OV.ThreeModelLoader = class this.callbacks = callbacks; } + SetDefaultColor (defaultColor) + { + this.importer.SetDefaultColor (defaultColor); + } + LoadFromUrlList (urls) { if (this.inProgress) { diff --git a/source/import/importer.js b/source/import/importer.js index 3bd5825..4575172 100644 --- a/source/import/importer.js +++ b/source/import/importer.js @@ -260,6 +260,7 @@ OV.Importer = class new OV.ImporterGltf () ]; this.fileList = new OV.FileList (this.importers); + this.defaultColor = new OV.Color (200, 200, 200); this.model = null; this.usedFiles = []; this.missingFiles = []; @@ -275,6 +276,11 @@ OV.Importer = class this.LoadFiles (fileList, OV.FileSource.File, onReady); } + SetDefaultColor (defaultColor) + { + this.defaultColor = defaultColor; + } + Import (callbacks) { let mainFile = this.fileList.GetMainFile (); @@ -310,7 +316,7 @@ OV.Importer = class importer.Import (mainFile.file.content, mainFile.file.extension, { getDefaultMaterial : function () { let material = new OV.Material (); - material.diffuse = new OV.Color (200, 200, 200); + material.diffuse = obj.defaultColor; return material; }, getFileBuffer : function (filePath) { diff --git a/test/tests/importer_test.js b/test/tests/importer_test.js index 0e375b4..2e5b7f8 100644 --- a/test/tests/importer_test.js +++ b/test/tests/importer_test.js @@ -233,4 +233,24 @@ describe ('Importer Test', function () { } }); }); + + it ('Default color', function () { + let files = [ + new FileObject ('stl', 'single_triangle.stl') + ]; + let theImporter = new OV.Importer (); + theImporter.SetDefaultColor (new OV.Color (200, 0, 0)); + ImportFilesWithImporter (theImporter, files, { + success : function (importer, importResult) { + assert (!OV.IsModelEmpty (importResult.model)); + assert.deepStrictEqual (importResult.usedFiles, ['single_triangle.stl']); + assert.deepStrictEqual (importResult.missingFiles, []); + let material = importResult.model.GetMaterial (0); + assert.deepStrictEqual (material.diffuse, new OV.Color (200, 0, 0)); + }, + error : function (importer, importError) { + assert.fail (); + } + }); + }); });