Set vertex color for materials only if they have vertex color in all appearances.
This commit is contained in:
parent
671a0cac85
commit
dbf1865c46
@ -47,6 +47,11 @@ OV.MeshInstance = class extends OV.ModelObject3D
|
||||
return this.mesh.VertexCount ();
|
||||
}
|
||||
|
||||
VertexColorCount ()
|
||||
{
|
||||
return this.mesh.VertexColorCount ();
|
||||
}
|
||||
|
||||
NormalCount ()
|
||||
{
|
||||
return this.mesh.NormalCount ();
|
||||
|
||||
@ -41,6 +41,15 @@ OV.Model = class extends OV.ModelObject3D
|
||||
return count;
|
||||
}
|
||||
|
||||
VertexColorCount ()
|
||||
{
|
||||
let count = 0;
|
||||
this.EnumerateMeshInstances ((meshInstance) => {
|
||||
count += meshInstance.VertexColorCount ();
|
||||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
NormalCount ()
|
||||
{
|
||||
let count = 0;
|
||||
|
||||
@ -16,17 +16,45 @@ OV.ModelFinalizer = class
|
||||
this.Reset ();
|
||||
|
||||
this.FinalizeMeshes (model);
|
||||
this.FinalizeMaterials (model);
|
||||
this.FinalizeNodes (model);
|
||||
}
|
||||
|
||||
FinalizeMaterials (model)
|
||||
{
|
||||
let hasVertexColors = (model.VertexColorCount () > 0);
|
||||
if (!hasVertexColors) {
|
||||
return;
|
||||
}
|
||||
|
||||
let materialHasVertexColors = new Map ();
|
||||
for (let meshIndex = 0; meshIndex < model.MeshCount (); meshIndex++) {
|
||||
let mesh = model.GetMesh (meshIndex);
|
||||
for (let triangleIndex = 0; triangleIndex < mesh.TriangleCount (); triangleIndex++) {
|
||||
let triangle = mesh.GetTriangle (triangleIndex);
|
||||
let hasVertexColors = triangle.HasVertexColors ();
|
||||
if (!materialHasVertexColors.has (triangle.mat)) {
|
||||
materialHasVertexColors.set (triangle.mat, hasVertexColors);
|
||||
} else if (!hasVertexColors) {
|
||||
materialHasVertexColors.set (triangle.mat, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (let [materialIndex, hasVertexColors] of materialHasVertexColors) {
|
||||
let material = model.GetMaterial (materialIndex);
|
||||
material.vertexColors = hasVertexColors;
|
||||
}
|
||||
}
|
||||
|
||||
FinalizeMeshes (model)
|
||||
{
|
||||
for (let i = 0; i < model.MeshCount (); i++) {
|
||||
let mesh = model.GetMesh (i);
|
||||
for (let meshIndex = 0; meshIndex < model.MeshCount (); meshIndex++) {
|
||||
let mesh = model.GetMesh (meshIndex);
|
||||
let type = OV.GetMeshType (mesh);
|
||||
if (type === OV.MeshType.Empty) {
|
||||
model.RemoveMesh (i);
|
||||
i = i - 1;
|
||||
model.RemoveMesh (meshIndex);
|
||||
meshIndex = meshIndex - 1;
|
||||
continue;
|
||||
}
|
||||
this.FinalizeMesh (model, mesh);
|
||||
@ -113,11 +141,6 @@ OV.ModelFinalizer = class
|
||||
if (triangle.mat === null) {
|
||||
triangle.mat = this.GetDefaultMaterialIndex (model);
|
||||
}
|
||||
|
||||
if (triangle.HasVertexColors ()) {
|
||||
let material = model.GetMaterial (triangle.mat);
|
||||
material.vertexColors = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (meshStatus.calculateCurveNormals) {
|
||||
|
||||
@ -10,6 +10,11 @@ OV.Object3D = class
|
||||
return 0;
|
||||
}
|
||||
|
||||
VertexColorCount ()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NormalCount ()
|
||||
{
|
||||
return 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user