Add mesh material which is inherited to triangles during finalization.
This commit is contained in:
parent
2969050880
commit
b526bea0bb
@ -28,6 +28,9 @@ OV.Generator = class
|
||||
if (this.params.name !== null) {
|
||||
this.mesh.SetName (this.params.name);
|
||||
}
|
||||
if (this.params.material !== null) {
|
||||
this.mesh.SetMaterial (this.params.material);
|
||||
}
|
||||
this.curve = null;
|
||||
}
|
||||
|
||||
@ -65,9 +68,6 @@ OV.Generator = class
|
||||
AddTriangle (v0, v1, v2)
|
||||
{
|
||||
let triangle = new OV.Triangle (v0, v1, v2);
|
||||
if (this.params.material !== null) {
|
||||
triangle.SetMaterial (this.params.material);
|
||||
}
|
||||
if (this.curve !== null) {
|
||||
triangle.SetCurve (this.curve);
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ OV.Mesh = class extends OV.ModelObject3D
|
||||
this.normals = [];
|
||||
this.uvs = [];
|
||||
this.triangles = [];
|
||||
this.mat = null;
|
||||
}
|
||||
|
||||
VertexCount ()
|
||||
@ -110,6 +111,16 @@ OV.Mesh = class extends OV.ModelObject3D
|
||||
return this.triangles[index];
|
||||
}
|
||||
|
||||
SetMaterial (mat)
|
||||
{
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
GetMaterial ()
|
||||
{
|
||||
return this.mat;
|
||||
}
|
||||
|
||||
EnumerateVertices (onVertex)
|
||||
{
|
||||
for (const vertex of this.vertices) {
|
||||
@ -165,6 +176,8 @@ OV.Mesh = class extends OV.ModelObject3D
|
||||
cloned.AddTriangle (triangle.Clone ());
|
||||
}
|
||||
|
||||
cloned.SetMaterial (this.GetMaterial ());
|
||||
|
||||
return cloned;
|
||||
}
|
||||
};
|
||||
|
||||
@ -111,7 +111,12 @@ OV.ModelFinalizer = class
|
||||
this.FinalizeTriangle (mesh, triangle, meshStatus);
|
||||
|
||||
if (triangle.mat === null) {
|
||||
triangle.mat = this.GetDefaultMaterialIndex (model);
|
||||
let meshMaterial = mesh.GetMaterial ();
|
||||
if (meshMaterial !== null) {
|
||||
triangle.mat = meshMaterial;
|
||||
} else {
|
||||
triangle.mat = this.GetDefaultMaterialIndex (model);
|
||||
}
|
||||
}
|
||||
|
||||
if (triangle.HasVertexColors ()) {
|
||||
@ -292,6 +297,19 @@ OV.CheckModel = function (model)
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < mesh.VertexColorCount (); i++) {
|
||||
let color = mesh.GetVertexColor (i);
|
||||
if (!IsCorrectNumber (color.r)) {
|
||||
return false;
|
||||
}
|
||||
if (!IsCorrectNumber (color.g)) {
|
||||
return false;
|
||||
}
|
||||
if (!IsCorrectNumber (color.b)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < mesh.NormalCount (); i++) {
|
||||
let normal = mesh.GetNormal (i);
|
||||
if (!IsCorrectNumber (normal.x)) {
|
||||
@ -322,6 +340,13 @@ OV.CheckModel = function (model)
|
||||
}
|
||||
}
|
||||
|
||||
let meshMaterial = mesh.GetMaterial ();
|
||||
if (meshMaterial !== null) {
|
||||
if (!IsCorrectIndex (meshMaterial, model.MaterialCount ())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -331,5 +356,6 @@ OV.CheckModel = function (model)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
@ -10,10 +10,7 @@ describe ('Generator', function () {
|
||||
it ('Cuboid with Material', function () {
|
||||
const params = new OV.GeneratorParams ().SetMaterial (1);
|
||||
const cuboid = OV.GenerateCuboid (params, 1.0, 1.0, 1.0);
|
||||
for (let i = 0; i < cuboid.TriangleCount (); i++) {
|
||||
const triangle = cuboid.GetTriangle (i);
|
||||
assert.strictEqual (triangle.mat, 1);
|
||||
}
|
||||
assert.strictEqual (cuboid.GetMaterial (), 1);
|
||||
});
|
||||
|
||||
it ('Cylinder with Default Parameters', function () {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user