Possibility to set the default material color for importer in case of no-material surfaces.
This commit is contained in:
parent
774e32af5b
commit
b60305dd19
5
source/external/three.model.loader.js
vendored
5
source/external/three.model.loader.js
vendored
@ -12,6 +12,11 @@ OV.ThreeModelLoader = class
|
||||
this.callbacks = callbacks;
|
||||
}
|
||||
|
||||
SetDefaultColor (defaultColor)
|
||||
{
|
||||
this.importer.SetDefaultColor (defaultColor);
|
||||
}
|
||||
|
||||
LoadFromUrlList (urls)
|
||||
{
|
||||
if (this.inProgress) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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 ();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user