Store instance id in mesh instances.
This commit is contained in:
parent
1df376745f
commit
233cc2c2d7
@ -19,13 +19,19 @@ OV.MeshInstanceId = class
|
|||||||
|
|
||||||
OV.MeshInstance = class extends OV.ModelObject3D
|
OV.MeshInstance = class extends OV.ModelObject3D
|
||||||
{
|
{
|
||||||
constructor (node, mesh)
|
constructor (id, node, mesh)
|
||||||
{
|
{
|
||||||
super ();
|
super ();
|
||||||
|
this.id = id;
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.mesh = mesh;
|
this.mesh = mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetId ()
|
||||||
|
{
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
VertexCount ()
|
VertexCount ()
|
||||||
{
|
{
|
||||||
return this.mesh.VertexCount ();
|
return this.mesh.VertexCount ();
|
||||||
|
|||||||
@ -128,7 +128,8 @@ OV.Model = class extends OV.ModelObject3D
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
let foundMesh = this.GetMesh (instanceId.meshIndex);
|
let foundMesh = this.GetMesh (instanceId.meshIndex);
|
||||||
return new OV.MeshInstance (foundNode, foundMesh);
|
let id = new OV.MeshInstanceId (foundNode.GetId (), instanceId.meshIndex);
|
||||||
|
return new OV.MeshInstance (id, foundNode, foundMesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
EnumerateMeshes (onMesh)
|
EnumerateMeshes (onMesh)
|
||||||
@ -142,8 +143,9 @@ OV.Model = class extends OV.ModelObject3D
|
|||||||
{
|
{
|
||||||
this.root.Enumerate ((node) => {
|
this.root.Enumerate ((node) => {
|
||||||
for (let meshIndex of node.GetMeshIndices ()) {
|
for (let meshIndex of node.GetMeshIndices ()) {
|
||||||
|
let id = new OV.MeshInstanceId (node.GetId (), meshIndex);
|
||||||
let mesh = this.GetMesh (meshIndex);
|
let mesh = this.GetMesh (meshIndex);
|
||||||
let meshInstance = new OV.MeshInstance (node, mesh);
|
let meshInstance = new OV.MeshInstance (id, node, mesh);
|
||||||
onMeshInstance (meshInstance);
|
onMeshInstance (meshInstance);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -403,4 +403,15 @@ describe ('Node Hierarchy', function () {
|
|||||||
assert.strictEqual (model.TextureUVCount (), 0);
|
assert.strictEqual (model.TextureUVCount (), 0);
|
||||||
assert.strictEqual (model.TriangleCount (), 12 * 3);
|
assert.strictEqual (model.TriangleCount (), 12 * 3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it ('Instance enumeration', function () {
|
||||||
|
let model = testUtils.GetTranslatedRotatedCubesModel ();
|
||||||
|
let meshInstances = [];
|
||||||
|
model.EnumerateMeshInstances ((meshInstance) => {
|
||||||
|
meshInstances.push (meshInstance);
|
||||||
|
});
|
||||||
|
assert (meshInstances[0].GetId ().IsEqual (new OV.MeshInstanceId (0, 0)));
|
||||||
|
assert (meshInstances[1].GetId ().IsEqual (new OV.MeshInstanceId (1, 0)));
|
||||||
|
assert (meshInstances[2].GetId ().IsEqual (new OV.MeshInstanceId (3, 0)));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -14,7 +14,7 @@ describe ('Model Utils', function () {
|
|||||||
let transformation = new OV.Transformation (new OV.Matrix ().CreateTranslation (2.0, 0.0, 0.0));
|
let transformation = new OV.Transformation (new OV.Matrix ().CreateTranslation (2.0, 0.0, 0.0));
|
||||||
let node = new OV.Node ();
|
let node = new OV.Node ();
|
||||||
node.SetTransformation (transformation);
|
node.SetTransformation (transformation);
|
||||||
let cubeInstance = new OV.MeshInstance (node, cube);
|
let cubeInstance = new OV.MeshInstance (null, node, cube);
|
||||||
let cubeInstanceBounds = OV.GetBoundingBox (cubeInstance);
|
let cubeInstanceBounds = OV.GetBoundingBox (cubeInstance);
|
||||||
assert (OV.CoordIsEqual3D (cubeInstanceBounds.min, new OV.Coord3D (2.0, 0.0, 0.0)));
|
assert (OV.CoordIsEqual3D (cubeInstanceBounds.min, new OV.Coord3D (2.0, 0.0, 0.0)));
|
||||||
assert (OV.CoordIsEqual3D (cubeInstanceBounds.max, new OV.Coord3D (3.0, 1.0, 1.0)));
|
assert (OV.CoordIsEqual3D (cubeInstanceBounds.max, new OV.Coord3D (3.0, 1.0, 1.0)));
|
||||||
|
|||||||
@ -105,7 +105,7 @@ describe ('Quantities', function () {
|
|||||||
const transformation = new OV.Transformation (new OV.Matrix ().CreateScale (2.0, 2.0, 2.0));
|
const transformation = new OV.Transformation (new OV.Matrix ().CreateScale (2.0, 2.0, 2.0));
|
||||||
let node = new OV.Node ();
|
let node = new OV.Node ();
|
||||||
node.SetTransformation (transformation);
|
node.SetTransformation (transformation);
|
||||||
const meshInstance = new OV.MeshInstance (node, mesh);
|
const meshInstance = new OV.MeshInstance (null, node, mesh);
|
||||||
assert (OV.IsSolid (meshInstance));
|
assert (OV.IsSolid (meshInstance));
|
||||||
assert (OV.IsEqual (OV.CalculateVolume (meshInstance), 8.0));
|
assert (OV.IsEqual (OV.CalculateVolume (meshInstance), 8.0));
|
||||||
assert (OV.IsEqual (OV.CalculateSurfaceArea (meshInstance), 24.0));
|
assert (OV.IsEqual (OV.CalculateSurfaceArea (meshInstance), 24.0));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user