diff --git a/source/engine/threejs/threeconverter.js b/source/engine/threejs/threeconverter.js index 3ba0dcb..954576f 100644 --- a/source/engine/threejs/threeconverter.js +++ b/source/engine/threejs/threeconverter.js @@ -2,7 +2,7 @@ import { RunTasksBatch } from '../core/taskrunner.js'; import { IsEqual } from '../geometry/geometry.js'; import { CreateObjectUrl, CreateObjectUrlWithMimeType } from '../io/bufferutils.js'; import { MaterialType } from '../model/material.js'; -import { MeshInstanceId } from '../model/meshinstance.js'; +import { MeshInstance, MeshInstanceId } from '../model/meshinstance.js'; import { GetMeshType, MeshType } from '../model/meshutils.js'; import { ConvertColorToThreeColor, GetShadingType, ShadingType } from './threeutils.js'; @@ -63,10 +63,11 @@ export class ThreeConversionStateHandler export class ThreeNodeTree { - constructor (rootNode, threeRootNode) + constructor (model, threeRootNode) { - this.meshInstances = []; - this.AddNode (rootNode, threeRootNode); + this.model = model; + this.threeNodeItems = []; + this.AddNode (model.GetRootNode (), threeRootNode); } AddNode (node, threeNode) @@ -81,17 +82,18 @@ export class ThreeNodeTree this.AddNode (childNode, threeChildNode); } for (let meshIndex of node.GetMeshIndices ()) { - this.meshInstances.push ({ - node : node, - threeNode : threeNode, - meshIndex : meshIndex + let id = new MeshInstanceId (node.GetId (), meshIndex); + let mesh = this.model.GetMesh (meshIndex); + this.threeNodeItems.push ({ + meshInstance : new MeshInstance (id, node, mesh), + threeNode : threeNode }); } } - GetMeshInstances () + GetNodeItems () { - return this.meshInstances; + return this.threeNodeItems; } } @@ -211,9 +213,9 @@ export function ConvertModelToThreeObject (model, params, output, callbacks) return threeMaterial; } - function CreateThreeMesh (model, meshInstanceId, modelThreeMaterials) + function CreateThreeMesh (meshInstance, modelThreeMaterials) { - let mesh = model.GetMesh (meshInstanceId.meshIndex); + let mesh = meshInstance.mesh; let triangleCount = mesh.TriangleCount (); let triangleIndices = []; @@ -317,7 +319,7 @@ export function ConvertModelToThreeObject (model, params, output, callbacks) let threeMesh = new THREE.Mesh (threeGeometry, meshThreeMaterials); threeMesh.name = mesh.GetName (); threeMesh.userData = { - originalMeshId : meshInstanceId, + originalMeshInstance : meshInstance, originalMaterials : meshOriginalMaterials, threeMaterials : null }; @@ -325,30 +327,25 @@ export function ConvertModelToThreeObject (model, params, output, callbacks) return threeMesh; } - function ConvertMesh (threeObject, model, meshInstanceId, modelThreeMaterials) + function ConvertMesh (threeObject, meshInstance, modelThreeMaterials) { - let mesh = model.GetMesh (meshInstanceId.meshIndex); - let type = GetMeshType (mesh); + let type = GetMeshType (meshInstance.mesh); if (type === MeshType.TriangleMesh) { - let threeMesh = CreateThreeMesh (model, meshInstanceId, modelThreeMaterials); + let threeMesh = CreateThreeMesh (meshInstance, modelThreeMaterials); threeObject.add (threeMesh); } } function ConvertNodeHierarchy (threeRootNode, model, modelThreeMaterials, stateHandler) { - let rootNode = model.GetRootNode (); - let nodeTree = new ThreeNodeTree (rootNode, threeRootNode); - let meshInstances = nodeTree.GetMeshInstances (); + let nodeTree = new ThreeNodeTree (model, threeRootNode); + let threeNodeItems = nodeTree.GetNodeItems (); - RunTasksBatch (meshInstances.length, 100, { + RunTasksBatch (threeNodeItems.length, 100, { runTask : (firstMeshInstanceIndex, lastMeshInstanceIndex, onReady) => { for (let meshInstanceIndex = firstMeshInstanceIndex; meshInstanceIndex <= lastMeshInstanceIndex; meshInstanceIndex++) { - let meshInstance = meshInstances[meshInstanceIndex]; - let node = meshInstance.node; - let threeNode = meshInstance.threeNode; - let meshInstanceId = new MeshInstanceId (node.GetId (), meshInstance.meshIndex); - ConvertMesh (threeNode, model, meshInstanceId, modelThreeMaterials); + let nodeItem = threeNodeItems[meshInstanceIndex]; + ConvertMesh (nodeItem.threeNode, nodeItem.meshInstance, modelThreeMaterials); } onReady (); }, diff --git a/source/website/navigatormaterialspanel.js b/source/website/navigatormaterialspanel.js index c122222..ea33f80 100644 --- a/source/website/navigatormaterialspanel.js +++ b/source/website/navigatormaterialspanel.js @@ -9,31 +9,31 @@ class NavigatorMeshesPopupButton extends NavigatorPopupButton constructor (parentDiv) { super (parentDiv); - this.meshInfoArray = null; + this.meshInstanceArray = null; } - Update (meshInfoArray) + Update (meshInstanceArray) { - this.meshInfoArray = meshInfoArray; - if (this.meshInfoArray === null) { + this.meshInstanceArray = meshInstanceArray; + if (this.meshInstanceArray === null) { return; } - let meshesText = 'Meshes (' + this.meshInfoArray.length + ')'; + let meshesText = 'Meshes (' + this.meshInstanceArray.length + ')'; this.buttonText.innerHTML = meshesText; } OnButtonClick () { - if (this.meshInfoArray === null) { + if (this.meshInstanceArray === null) { return; } let meshItems = []; - for (let i = 0; i < this.meshInfoArray.length; i++) { - let meshInfo = this.meshInfoArray[i]; + for (let i = 0; i < this.meshInstanceArray.length; i++) { + let meshInstance = this.meshInstanceArray[i]; meshItems.push ({ - name : GetMeshName (meshInfo.name) + name : GetMeshName (meshInstance.node.GetName (), meshInstance.mesh.GetName ()) }); } @@ -46,15 +46,15 @@ class NavigatorMeshesPopupButton extends NavigatorPopupButton return CalculatePopupPositionToElementBottomRight (this.button, contentDiv); }, onHoverStart : (index) => { - const meshData = this.meshInfoArray[index]; - this.callbacks.onMeshHover (meshData.meshId); + const meshInstance = this.meshInstanceArray[index]; + this.callbacks.onMeshHover (meshInstance.id); }, onHoverStop : (index) => { this.callbacks.onMeshHover (null); }, onClick : (index) => { - const meshData = this.meshInfoArray[index]; - this.callbacks.onMeshSelected (meshData.meshId); + const meshInstance = this.meshInstanceArray[index]; + this.callbacks.onMeshSelected (meshInstance.id); } }); } @@ -137,8 +137,8 @@ export class NavigatorMaterialsPanel extends NavigatorPanel this.GetMaterialItem (materialIndex).SetSelected (isSelected); } - UpdateMeshList (meshInfoArray) + UpdateMeshList (meshInstanceArray) { - this.meshesButton.Update (meshInfoArray); + this.meshesButton.Update (meshInstanceArray); } } diff --git a/source/website/navigatormeshespanel.js b/source/website/navigatormeshespanel.js index c6490f0..03a210b 100644 --- a/source/website/navigatormeshespanel.js +++ b/source/website/navigatormeshespanel.js @@ -323,7 +323,7 @@ export class NavigatorMeshesPanel extends NavigatorPanel function AddMeshToNodeTree (panel, model, node, meshIndex, parentItem, mode) { let mesh = model.GetMesh (meshIndex); - let meshName = GetMeshName (mesh.GetName ()); + let meshName = GetMeshName (node.GetName (), mesh.GetName ()); let meshInstanceId = new MeshInstanceId (node.GetId (), meshIndex); let meshItemIcon = (mode === MeshesPanelMode.TreeView ? 'tree_mesh' : null); let meshItem = new MeshItem (meshName, meshItemIcon, meshInstanceId, { diff --git a/source/website/utils.js b/source/website/utils.js index 5b689c3..94e03de 100644 --- a/source/website/utils.js +++ b/source/website/utils.js @@ -15,8 +15,9 @@ export function GetNodeName (originalName) return GetNameOrDefault (originalName, 'No Name'); } -export function GetMeshName (originalName) +export function GetMeshName (originalNodeName, originalMeshName) { + let originalName = (originalMeshName.length > 0 ? originalMeshName : originalNodeName); return GetNameOrDefault (originalName, 'No Name'); } diff --git a/source/website/website.js b/source/website/website.js index 63e2cc4..5621465 100644 --- a/source/website/website.js +++ b/source/website/website.js @@ -314,7 +314,7 @@ export class Website if (meshUserData === null) { this.navigator.SetSelection (null); } else { - this.navigator.SetSelection (new Selection (SelectionType.Mesh, meshUserData.originalMeshId)); + this.navigator.SetSelection (new Selection (SelectionType.Mesh, meshUserData.originalMeshInstance.id)); } } @@ -351,18 +351,18 @@ export class Website name : 'Hide mesh', icon : 'hidden', onClick : () => { - this.navigator.ToggleMeshVisibility (meshUserData.originalMeshId); + this.navigator.ToggleMeshVisibility (meshUserData.originalMeshInstance.id); } }); items.push ({ name : 'Fit mesh to window', icon : 'fit', onClick : () => { - this.navigator.FitMeshToWindow (meshUserData.originalMeshId); + this.navigator.FitMeshToWindow (meshUserData.originalMeshInstance.id); } }); if (this.navigator.MeshItemCount () > 1) { - let isMeshIsolated = this.navigator.IsMeshIsolated (meshUserData.originalMeshId); + let isMeshIsolated = this.navigator.IsMeshIsolated (meshUserData.originalMeshInstance.id); items.push ({ name : isMeshIsolated ? 'Remove isolation' : 'Isolate mesh', icon : isMeshIsolated ? 'deisolate' : 'isolate', @@ -370,7 +370,7 @@ export class Website if (isMeshIsolated) { this.navigator.ShowAllMeshes (true); } else { - this.navigator.IsolateMesh (meshUserData.originalMeshId); + this.navigator.IsolateMesh (meshUserData.originalMeshInstance.id); } } }); @@ -418,7 +418,7 @@ export class Website { let animation = !onLoad; let boundingSphere = this.viewer.GetBoundingSphere ((meshUserData) => { - return this.navigator.IsMeshVisible (meshUserData.originalMeshId); + return this.navigator.IsMeshVisible (meshUserData.originalMeshInstance.id); }); if (onLoad) { this.viewer.AdjustClippingPlanesToSphere (boundingSphere); @@ -429,7 +429,7 @@ export class Website FitMeshToWindow (meshInstanceId) { let boundingSphere = this.viewer.GetBoundingSphere ((meshUserData) => { - return meshUserData.originalMeshId.IsEqual (meshInstanceId); + return meshUserData.originalMeshInstance.id.IsEqual (meshInstanceId); }); this.viewer.FitSphereToWindow (boundingSphere, true); } @@ -441,7 +441,7 @@ export class Website meshInstanceIdKeys.add (meshInstanceId.GetKey ()); } let boundingSphere = this.viewer.GetBoundingSphere ((meshUserData) => { - return meshInstanceIdKeys.has (meshUserData.originalMeshId.GetKey ()); + return meshInstanceIdKeys.has (meshUserData.originalMeshInstance.id.GetKey ()); }); this.viewer.FitSphereToWindow (boundingSphere, true); } @@ -449,7 +449,7 @@ export class Website UpdateMeshesVisibility () { this.viewer.SetMeshesVisibility ((meshUserData) => { - return this.navigator.IsMeshVisible (meshUserData.originalMeshId); + return this.navigator.IsMeshVisible (meshUserData.originalMeshInstance.id); }); } @@ -457,7 +457,7 @@ export class Website { let selectedMeshId = this.navigator.GetSelectedMeshId (); this.viewer.SetMeshesHighlight (this.highlightColor, (meshUserData) => { - if (selectedMeshId !== null && meshUserData.originalMeshId.IsEqual (selectedMeshId)) { + if (selectedMeshId !== null && meshUserData.originalMeshInstance.id.IsEqual (selectedMeshId)) { return true; } return false; @@ -813,23 +813,19 @@ export class Website { let userData = null; viewer.EnumerateMeshesUserData ((meshUserData) => { - if (meshUserData.originalMeshId.IsEqual (meshInstanceId)) { + if (meshUserData.originalMeshInstance.id.IsEqual (meshInstanceId)) { userData = meshUserData; } }); return userData; } - function GetMeshesForMaterial (viewer, model, materialIndex) + function GetMeshesForMaterial (viewer, materialIndex) { let usedByMeshes = []; viewer.EnumerateMeshesUserData ((meshUserData) => { if (materialIndex === null || meshUserData.originalMaterials.indexOf (materialIndex) !== -1) { - const mesh = model.GetMesh (meshUserData.originalMeshId.meshIndex); - usedByMeshes.push ({ - meshId : meshUserData.originalMeshId, - name : mesh.GetName () - }); + usedByMeshes.push (meshUserData.originalMeshInstance); } }); return usedByMeshes; @@ -876,7 +872,7 @@ export class Website this.FitMeshesToWindow (meshInstanceIdSet); }, getMeshesForMaterial : (materialIndex) => { - return GetMeshesForMaterial (this.viewer, this.model, materialIndex); + return GetMeshesForMaterial (this.viewer, materialIndex); }, getMaterialsForMesh : (meshInstanceId) => { return GetMaterialsForMesh (this.viewer, this.model, meshInstanceId);