Provide only material color for importer.
This commit is contained in:
parent
630f85145b
commit
6dc21ae06b
@ -205,10 +205,8 @@ OV.Importer = class
|
||||
});
|
||||
|
||||
importer.Import (mainFile.file.name, mainFile.file.extension, mainFile.file.content, {
|
||||
getDefaultMaterial : () => {
|
||||
let material = new OV.PhongMaterial ();
|
||||
material.color = settings.defaultColor;
|
||||
return material;
|
||||
getDefaultMaterialColor : () => {
|
||||
return settings.defaultColor;
|
||||
},
|
||||
getFileBuffer : (filePath) => {
|
||||
return fileAccessor.GetFileBuffer (filePath);
|
||||
|
||||
@ -52,7 +52,9 @@ OV.ImporterBase = class
|
||||
return;
|
||||
}
|
||||
|
||||
OV.FinalizeModel (this.model, this.callbacks.getDefaultMaterial);
|
||||
OV.FinalizeModel (this.model, {
|
||||
getDefaultMaterialColor : this.callbacks.getDefaultMaterialColor
|
||||
});
|
||||
|
||||
callbacks.onSuccess ();
|
||||
callbacks.onComplete ();
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
OV.ModelFinalizer = class
|
||||
{
|
||||
constructor (getDefaultMaterial)
|
||||
constructor (params)
|
||||
{
|
||||
this.getDefaultMaterial = getDefaultMaterial;
|
||||
this.params = {
|
||||
getDefaultMaterialColor : () => {
|
||||
return new OV.Color (0, 0, 0);
|
||||
}
|
||||
};
|
||||
OV.CopyObjectAttributes (params, this.params);
|
||||
this.defaultMaterialIndex = null;
|
||||
}
|
||||
|
||||
@ -102,7 +107,12 @@ OV.ModelFinalizer = class
|
||||
|
||||
for (let i = 0; i < mesh.TriangleCount (); i++) {
|
||||
let triangle = mesh.GetTriangle (i);
|
||||
this.FinalizeTriangle (model, mesh, triangle, meshStatus);
|
||||
this.FinalizeTriangle (mesh, triangle, meshStatus);
|
||||
|
||||
if (triangle.mat === null) {
|
||||
triangle.mat = this.GetDefaultMaterialIndex (model);
|
||||
}
|
||||
|
||||
if (triangle.HasVertexColors ()) {
|
||||
let material = model.GetMaterial (triangle.mat);
|
||||
material.vertexColors = true;
|
||||
@ -114,7 +124,7 @@ OV.ModelFinalizer = class
|
||||
}
|
||||
}
|
||||
|
||||
FinalizeTriangle (model, mesh, triangle, meshStatus)
|
||||
FinalizeTriangle (mesh, triangle, meshStatus)
|
||||
{
|
||||
if (!triangle.HasNormals ()) {
|
||||
if (triangle.curve === null || triangle.curve === 0) {
|
||||
@ -129,10 +139,6 @@ OV.ModelFinalizer = class
|
||||
}
|
||||
}
|
||||
|
||||
if (triangle.mat === null) {
|
||||
triangle.mat = this.GetDefaultMaterialIndex (model);
|
||||
}
|
||||
|
||||
if (triangle.curve === null) {
|
||||
triangle.curve = 0;
|
||||
}
|
||||
@ -165,7 +171,9 @@ OV.ModelFinalizer = class
|
||||
GetDefaultMaterialIndex (model)
|
||||
{
|
||||
if (this.defaultMaterialIndex === null) {
|
||||
let defaultMaterial = this.getDefaultMaterial ();
|
||||
let defaultMaterialColor = this.params.getDefaultMaterialColor ();
|
||||
let defaultMaterial = new OV.PhongMaterial ();
|
||||
defaultMaterial.color = defaultMaterialColor;
|
||||
defaultMaterial.isDefault = true;
|
||||
this.defaultMaterialIndex = model.AddMaterial (defaultMaterial);
|
||||
}
|
||||
@ -178,9 +186,9 @@ OV.ModelFinalizer = class
|
||||
}
|
||||
};
|
||||
|
||||
OV.FinalizeModel = function (model, getDefaultMaterial)
|
||||
OV.FinalizeModel = function (model, params)
|
||||
{
|
||||
let finalizer = new OV.ModelFinalizer (getDefaultMaterial);
|
||||
let finalizer = new OV.ModelFinalizer (params);
|
||||
finalizer.Finalize (model);
|
||||
};
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@ function CreateTestModel ()
|
||||
mesh2.AddTriangle (triangle4);
|
||||
model.AddMeshToRootNode (mesh2);
|
||||
|
||||
OV.FinalizeModel (model, null);
|
||||
OV.FinalizeModel (model);
|
||||
return model;
|
||||
}
|
||||
|
||||
@ -215,8 +215,8 @@ describe ('Exporter', function () {
|
||||
let contentBuffer = stlFile.GetBufferContent ();
|
||||
let importer = new OV.ImporterStl ();
|
||||
importer.Import (stlFile.GetName (), 'stl', contentBuffer, {
|
||||
getDefaultMaterial () {
|
||||
return new OV.PhongMaterial ();
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.Color (0, 0, 0);
|
||||
},
|
||||
onSuccess () {
|
||||
let importedModel = importer.GetModel ();
|
||||
@ -309,8 +309,8 @@ describe ('Exporter', function () {
|
||||
let contentBuffer = plyFile.GetBufferContent ();
|
||||
let importer = new OV.ImporterPly ();
|
||||
importer.Import (plyFile.GetName (), 'ply', contentBuffer, {
|
||||
getDefaultMaterial () {
|
||||
return new OV.PhongMaterial ();
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.Color (0, 0, 0);
|
||||
},
|
||||
onSuccess () {
|
||||
let importedModel = importer.GetModel ();
|
||||
@ -339,8 +339,8 @@ describe ('Exporter', function () {
|
||||
let contentBuffer = gltfFile.GetBufferContent ();
|
||||
let importer = new OV.ImporterGltf ();
|
||||
importer.Import (gltfFile.GetName (), 'gltf', contentBuffer, {
|
||||
getDefaultMaterial () {
|
||||
return new OV.PhongMaterial ();
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.Color (0, 0, 0);
|
||||
},
|
||||
getFileBuffer (filePath) {
|
||||
if (filePath == 'model.bin') {
|
||||
@ -377,8 +377,8 @@ describe ('Exporter', function () {
|
||||
let contentBuffer = glbFile.GetBufferContent ();
|
||||
let importer = new OV.ImporterGltf ();
|
||||
importer.Import (glbFile.GetName (), 'glb', contentBuffer, {
|
||||
getDefaultMaterial () {
|
||||
return new OV.PhongMaterial ();
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.Color (0, 0, 0);
|
||||
},
|
||||
getFileBuffer (filePath) {
|
||||
return null;
|
||||
|
||||
@ -21,7 +21,7 @@ function CreateTestModel ()
|
||||
root.AddChildNode (node);
|
||||
}
|
||||
|
||||
OV.FinalizeModel (model, null);
|
||||
OV.FinalizeModel (model);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
@ -102,7 +102,7 @@ function CreateTestModel ()
|
||||
meshWithPhysicalMaterial.AddTriangle (new OV.Triangle (0, 1, 2).SetMaterial (2));
|
||||
node3.AddMeshIndex (model.AddMesh (meshWithPhysicalMaterial));
|
||||
|
||||
OV.FinalizeModel (model, () => { return new OV.PhongMaterial (); });
|
||||
OV.FinalizeModel (model);
|
||||
return model;
|
||||
}
|
||||
|
||||
@ -230,7 +230,7 @@ describe ('Export-Import Vertex Colors Test', function () {
|
||||
mesh.AddVertexColor (new OV.Color (1.0, 0.0, 0.0));
|
||||
mesh.AddTriangle (new OV.Triangle (0, 1, 2).SetVertexColors (0, 0, 0));
|
||||
model.AddMeshToRootNode (mesh);
|
||||
OV.FinalizeModel (model, () => { return new OV.PhongMaterial (); });
|
||||
OV.FinalizeModel (model);
|
||||
ExportImport (model, OV.FileFormat.Binary, 'glb', (model2) => {
|
||||
assert.strictEqual (model2.MeshCount (), 1);
|
||||
let mesh2 = model2.GetMesh (0);
|
||||
|
||||
@ -144,9 +144,7 @@ describe ('Mesh Buffer', function () {
|
||||
mesh.AddTriangle (new OV.Triangle (4, 6, 7).SetNormals (5, 5, 5));
|
||||
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, function () {
|
||||
return new OV.PhongMaterial ();
|
||||
});
|
||||
OV.FinalizeModel (model);
|
||||
assert (OV.CheckModel (model));
|
||||
|
||||
let buffer = OV.ConvertMeshToMeshBuffer (mesh);
|
||||
@ -184,9 +182,7 @@ describe ('Mesh Buffer', function () {
|
||||
mesh.AddTriangle (new OV.Triangle (4, 6, 7));
|
||||
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, function () {
|
||||
return new OV.PhongMaterial ();
|
||||
});
|
||||
OV.FinalizeModel (model);
|
||||
assert (OV.CheckModel (model));
|
||||
|
||||
let buffer = OV.ConvertMeshToMeshBuffer (mesh);
|
||||
@ -226,9 +222,7 @@ describe ('Mesh Buffer', function () {
|
||||
mesh.AddTriangle (new OV.Triangle (4, 6, 7).SetCurve (1));
|
||||
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, function () {
|
||||
return new OV.PhongMaterial ();
|
||||
});
|
||||
OV.FinalizeModel (model);
|
||||
assert (OV.CheckModel (model));
|
||||
|
||||
let buffer = OV.ConvertMeshToMeshBuffer (mesh);
|
||||
@ -270,9 +264,7 @@ describe ('Mesh Buffer', function () {
|
||||
mesh.AddTriangle (new OV.Triangle (4, 6, 7).SetMaterial (1));
|
||||
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, function () {
|
||||
return new OV.PhongMaterial ();
|
||||
});
|
||||
OV.FinalizeModel (model);
|
||||
assert (OV.CheckModel (model));
|
||||
|
||||
let buffer = OV.ConvertMeshToMeshBuffer (mesh);
|
||||
@ -320,9 +312,7 @@ describe ('Mesh Buffer', function () {
|
||||
mesh.AddTriangle (new OV.Triangle (4, 6, 7));
|
||||
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, function () {
|
||||
return new OV.PhongMaterial ();
|
||||
});
|
||||
OV.FinalizeModel (model);
|
||||
assert (OV.CheckModel (model));
|
||||
|
||||
let buffer = OV.ConvertMeshToMeshBuffer (mesh);
|
||||
@ -363,9 +353,7 @@ describe ('Mesh Buffer', function () {
|
||||
mesh.AddTriangle (new OV.Triangle (4, 6, 7).SetTextureUVs (0, 1, 2));
|
||||
|
||||
model.AddMesh (mesh);
|
||||
OV.FinalizeModel (model, function () {
|
||||
return new OV.PhongMaterial ();
|
||||
});
|
||||
OV.FinalizeModel (model);
|
||||
assert (OV.CheckModel (model));
|
||||
|
||||
let buffer = OV.ConvertMeshToMeshBuffer (mesh);
|
||||
|
||||
@ -91,7 +91,7 @@ describe ('Model Finalization', function () {
|
||||
var model = new OV.Model ();
|
||||
var meshIndex = model.AddMesh (mesh);
|
||||
assert.strictEqual (model.MaterialCount (), 0);
|
||||
OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
|
||||
OV.FinalizeModel (model);
|
||||
assert.strictEqual (model.MaterialCount (), 1);
|
||||
var theMesh = model.GetMesh (meshIndex);
|
||||
assert.strictEqual (theMesh.NormalCount (), 1);
|
||||
@ -120,7 +120,7 @@ describe ('Model Finalization', function () {
|
||||
var model = new OV.Model ()
|
||||
var meshIndex = model.AddMesh (mesh);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
|
||||
OV.FinalizeModel (model);
|
||||
|
||||
var theMesh = model.GetMesh (meshIndex);
|
||||
assert.strictEqual (theMesh.NormalCount (), 6);
|
||||
@ -153,7 +153,7 @@ describe ('Model Finalization', function () {
|
||||
var model = new OV.Model ()
|
||||
var meshIndex = model.AddMesh (mesh);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
|
||||
OV.FinalizeModel (model);
|
||||
|
||||
var theMesh = model.GetMesh (meshIndex);
|
||||
assert.strictEqual (theMesh.NormalCount (), 9);
|
||||
@ -192,7 +192,7 @@ describe ('Model Finalization', function () {
|
||||
node3.AddMeshIndex (meshIndex);
|
||||
node3.AddMeshIndex (emptyMeshIndex);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
|
||||
OV.FinalizeModel (model);
|
||||
assert.strictEqual (model.MeshCount (), 1);
|
||||
|
||||
let meshInstances = [];
|
||||
@ -210,7 +210,7 @@ describe ('Model Finalization', function () {
|
||||
|
||||
it ('Remove Empty Nodes Recursively', function () {
|
||||
let model = testUtils.GetHierarchicalModelNoFinalization ();
|
||||
OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
|
||||
OV.FinalizeModel (model);
|
||||
assert.strictEqual (model.MeshCount (), 0);
|
||||
assert.strictEqual (model.MeshInstanceCount (), 0);
|
||||
assert (model.GetRootNode ().IsEmpty ());
|
||||
@ -395,7 +395,7 @@ describe ('Node Hierarchy', function () {
|
||||
|
||||
it ('Instance counters', function () {
|
||||
let model = testUtils.GetTranslatedRotatedCubesModel ();
|
||||
OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
|
||||
OV.FinalizeModel (model);
|
||||
assert.strictEqual (model.MeshCount (), 1);
|
||||
assert.strictEqual (model.MeshInstanceCount (), 3);
|
||||
assert.strictEqual (model.VertexCount (), 8 * 3);
|
||||
|
||||
@ -37,7 +37,7 @@ describe ('Model Utils', function () {
|
||||
mesh2.AddTriangle (new OV.Triangle (0, 1, 2));
|
||||
model.AddMeshToRootNode (mesh2);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.PhongMaterial (); });
|
||||
OV.FinalizeModel (model);
|
||||
|
||||
let mesh1Bounds = OV.GetBoundingBox (model.GetMesh (0));
|
||||
assert (OV.CoordIsEqual3D (mesh1Bounds.min, new OV.Coord3D (0.0, 0.0, 0.0)));
|
||||
|
||||
@ -54,9 +54,8 @@ module.exports =
|
||||
return fileContent;
|
||||
});
|
||||
importer.Import (fileName, extension, content, {
|
||||
getDefaultMaterial : function () {
|
||||
var material = new OV.PhongMaterial ();
|
||||
return material;
|
||||
getDefaultMaterialColor () {
|
||||
return new OV.Color (0, 0, 0);
|
||||
},
|
||||
getFileBuffer : function (filePath) {
|
||||
return fileAccessor.GetFileBuffer (filePath);
|
||||
|
||||
@ -171,7 +171,7 @@ module.exports =
|
||||
OV.TransformMesh (cube2, new OV.Transformation (matrix));
|
||||
model.AddMeshToRootNode (cube2);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
|
||||
OV.FinalizeModel (model);
|
||||
return model;
|
||||
},
|
||||
|
||||
@ -187,7 +187,7 @@ module.exports =
|
||||
OV.TransformMesh (cube2, new OV.Transformation (matrix))
|
||||
model.AddMeshToRootNode (cube2);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
|
||||
OV.FinalizeModel (model);
|
||||
return model;
|
||||
},
|
||||
|
||||
@ -203,7 +203,7 @@ module.exports =
|
||||
OV.TransformMesh (cube2, new OV.Transformation (matrix));
|
||||
model.AddMeshToRootNode (cube2);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
|
||||
OV.FinalizeModel (model);
|
||||
return model;
|
||||
},
|
||||
|
||||
@ -252,7 +252,7 @@ module.exports =
|
||||
{
|
||||
var model = new OV.Model ();
|
||||
model.AddMeshToRootNode (mesh);
|
||||
OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
|
||||
OV.FinalizeModel (model);
|
||||
return model;
|
||||
},
|
||||
|
||||
@ -376,7 +376,7 @@ module.exports =
|
||||
root.AddChildNode (rotatedNode);
|
||||
rotatedNode.AddChildNode (translatedRotatedNode);
|
||||
|
||||
OV.FinalizeModel (model, function () { return new OV.PhongMaterial () });
|
||||
OV.FinalizeModel (model);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user