Possibility to set the default material color for importer in case of no-material surfaces.

This commit is contained in:
Viktor Kovacs 2021-04-02 09:25:41 +02:00
parent 774e32af5b
commit b60305dd19
3 changed files with 32 additions and 1 deletions

View File

@ -12,6 +12,11 @@ OV.ThreeModelLoader = class
this.callbacks = callbacks;
}
SetDefaultColor (defaultColor)
{
this.importer.SetDefaultColor (defaultColor);
}
LoadFromUrlList (urls)
{
if (this.inProgress) {

View File

@ -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) {

View File

@ -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 ();
}
});
});
});