Add mesh instance id to identify a mesh in the node hierarchy.

This commit is contained in:
kovacsv 2021-10-24 09:43:24 +02:00
parent 24e53e242a
commit f045d214c7
3 changed files with 33 additions and 21 deletions

View File

@ -1,3 +1,17 @@
OV.MeshInstanceId = class
{
constructor (nodeId, meshIndex)
{
this.nodeId = nodeId;
this.meshIndex = meshIndex;
}
IsEqual (rhs)
{
return this.nodeId === rhs.nodeId && this.meshIndex === rhs.meshIndex;
}
};
OV.Model = class extends OV.Element
{
constructor ()

View File

@ -184,9 +184,9 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
return threeMaterial;
}
function CreateThreeMesh (model, nodeId, meshIndex, modelThreeMaterials)
function CreateThreeMesh (model, meshInstanceId, modelThreeMaterials)
{
let mesh = model.GetMesh (meshIndex);
let mesh = model.GetMesh (meshInstanceId.meshIndex);
let triangleCount = mesh.TriangleCount ();
if (triangleCount === 0) {
return null;
@ -272,8 +272,7 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
let threeMesh = new THREE.Mesh (threeGeometry, meshThreeMaterials);
threeMesh.userData = {
originalNodeId : nodeId,
originalMeshIndex : meshIndex,
originalMeshId : meshInstanceId,
originalMaterials : meshOriginalMaterials,
threeMaterials : null
};
@ -281,11 +280,11 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
return threeMesh;
}
function ConvertMesh (threeObject, model, nodeId, meshIndex, modelThreeMaterials)
function ConvertMesh (threeObject, model, meshInstanceId, modelThreeMaterials)
{
let mesh = model.GetMesh (meshIndex);
let mesh = model.GetMesh (meshInstanceId.meshIndex);
if (mesh.TriangleCount () > 0) {
let threeMesh = CreateThreeMesh (model, nodeId, meshIndex, modelThreeMaterials);
let threeMesh = CreateThreeMesh (model, meshInstanceId, modelThreeMaterials);
threeObject.add (threeMesh);
}
}
@ -303,9 +302,8 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
OV.RunTasksBatch (node.MeshIndexCount (), 100, {
runTask : (firstNodeMeshIndex, lastNodeMeshIndex, ready) => {
for (let nodeMeshIndex = firstNodeMeshIndex; nodeMeshIndex <= lastNodeMeshIndex; nodeMeshIndex++) {
const nodeId = node.GetId ();
const meshIndex = node.GetMeshIndex (nodeMeshIndex);
ConvertMesh (threeNode, model, nodeId, meshIndex, modelThreeMaterials);
let meshInstanceId = new OV.MeshInstanceId (node.GetId (), node.GetMeshIndex (lastNodeMeshIndex));
ConvertMesh (threeNode, model, meshInstanceId, modelThreeMaterials);
}
ready ();
},
@ -325,8 +323,8 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
OV.RunTasksBatch (model.MeshCount (), 100, {
runTask : (firstIndex, lastIndex, ready) => {
for (let meshIndex = firstIndex; meshIndex <= lastIndex; meshIndex++) {
let nodeId = -1;
ConvertMesh (threeObject, model, nodeId, meshIndex, modelThreeMaterials);
let meshInstanceId = new OV.MeshInstanceId (-1, meshIndex);
ConvertMesh (threeObject, model, meshInstanceId, modelThreeMaterials);
}
ready ();
},

View File

@ -148,7 +148,7 @@ OV.Website = class
if (meshUserData === null) {
this.navigator.SetSelection (null);
} else {
this.navigator.SetSelection (new OV.Selection (OV.SelectionType.Mesh, meshUserData.originalMeshIndex));
this.navigator.SetSelection (new OV.Selection (OV.SelectionType.Mesh, meshUserData.originalMeshId.meshIndex));
}
}
}
@ -175,7 +175,7 @@ OV.Website = class
});
}
} else {
let meshIndex = meshUserData.originalMeshIndex;
let meshIndex = meshUserData.originalMeshId.meshIndex;
items.push ({
name : 'Hide mesh',
icon : 'hidden',
@ -242,7 +242,7 @@ OV.Website = class
{
let animation = !onLoad;
let boundingSphere = this.viewer.GetBoundingSphere ((meshUserData) => {
return this.navigator.IsMeshVisible (meshUserData.originalMeshIndex);
return this.navigator.IsMeshVisible (meshUserData.originalMeshId.meshIndex);
});
if (onLoad) {
this.viewer.AdjustClippingPlanesToSphere (boundingSphere);
@ -253,7 +253,7 @@ OV.Website = class
FitMeshToWindow (meshIndex)
{
let boundingSphere = this.viewer.GetBoundingSphere ((meshUserData) => {
return meshUserData.originalMeshIndex === meshIndex;
return meshUserData.originalMeshId.meshIndex === meshIndex;
});
this.viewer.FitSphereToWindow (boundingSphere, true);
}
@ -261,7 +261,7 @@ OV.Website = class
UpdateMeshesVisibility ()
{
this.viewer.SetMeshesVisibility ((meshUserData) => {
return this.navigator.IsMeshVisible (meshUserData.originalMeshIndex);
return this.navigator.IsMeshVisible (meshUserData.originalMeshId.meshIndex);
});
}
@ -269,7 +269,7 @@ OV.Website = class
{
let selectedMeshIndex = this.navigator.GetSelectedMeshIndex ();
this.viewer.SetMeshesHighlight (this.highlightMaterial, (meshUserData) => {
if (meshUserData.originalMeshIndex === selectedMeshIndex) {
if (meshUserData.originalMeshId.meshIndex === selectedMeshIndex) {
return true;
}
return false;
@ -617,7 +617,7 @@ OV.Website = class
{
let userData = null;
viewer.EnumerateMeshesUserData ((meshUserData) => {
if (meshUserData.originalMeshIndex === meshIndex) {
if (meshUserData.originalMeshId.meshIndex === meshIndex) {
userData = meshUserData;
}
});
@ -629,9 +629,9 @@ OV.Website = class
let usedByMeshes = [];
viewer.EnumerateMeshesUserData ((meshUserData) => {
if (meshUserData.originalMaterials.indexOf (materialIndex) !== -1) {
const mesh = model.GetMesh (meshUserData.originalMeshIndex);
const mesh = model.GetMesh (meshUserData.originalMeshId.meshIndex);
usedByMeshes.push ({
index : meshUserData.originalMeshIndex,
index : meshUserData.originalMeshId.meshIndex,
name : mesh.GetName ()
});
}