From 921c2a9040427c26408dae183b42dd90169368b3 Mon Sep 17 00:00:00 2001 From: Viktor Kovacs Date: Thu, 20 May 2021 14:59:25 +0200 Subject: [PATCH] Remove unnecessary callback from info panel calculation. --- website/o3dv/info.js | 13 +++++++------ website/o3dv/menu.js | 8 ++------ website/o3dv/website.js | 24 ++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/website/o3dv/info.js b/website/o3dv/info.js index e5c1688..daae11e 100644 --- a/website/o3dv/info.js +++ b/website/o3dv/info.js @@ -96,7 +96,7 @@ OV.InfoPanel = class }); } - FillWithModelInfo (info, getMaterialInfo, callbacks) + FillWithModelInfo (info, callbacks) { function AddCounter (parent, name, value) { @@ -124,10 +124,10 @@ OV.InfoPanel = class let materialItems = []; for (let i = 0; i < info.usedMaterials.length; i++) { - let materialInfo = getMaterialInfo (info.usedMaterials[i]); + let usedMaterial = info.usedMaterials[i]; materialItems.push ({ - name : OV.GetMaterialName (materialInfo.name), - color : OV.ColorToHexString (materialInfo.diffuse) + name : OV.GetMaterialName (usedMaterial.name), + color : OV.ColorToHexString (usedMaterial.diffuse) }); } @@ -136,10 +136,11 @@ OV.InfoPanel = class this.CreateButton (contentDiv, materialsText, function (button) { obj.popup = OV.ShowListPopup (button, materialItems, { onClick : function (index) { - callbacks.onMaterialSelect (info.usedMaterials[index]); + let usedMaterial = info.usedMaterials[index]; + callbacks.onMaterialSelect (usedMaterial.index); } }); - }); + }); } CreateButton (parentDiv, buttonText, onClick) diff --git a/website/o3dv/menu.js b/website/o3dv/menu.js index d6a7f0c..cdffda7 100644 --- a/website/o3dv/menu.js +++ b/website/o3dv/menu.js @@ -221,11 +221,7 @@ OV.Menu = class let obj = this; if (this.selection === null) { let modelInfo = this.callbacks.getModelInformation (); - modelInfo.usedMaterials = []; - for (let i = 0; i < this.modelData.MaterialCount (); i++) { - modelInfo.usedMaterials.push (i); - } - this.infoPanel.FillWithModelInfo (modelInfo, this.callbacks.getMaterialInformation, { + this.infoPanel.FillWithModelInfo (modelInfo, { onMaterialSelect : function (materialIndex) { obj.SetSelection (new OV.Selection (OV.SelectionType.Material, materialIndex)); } @@ -243,7 +239,7 @@ OV.Menu = class }); } else if (this.selection.type === OV.SelectionType.Mesh) { let meshInfo = this.callbacks.getMeshInformation (this.selection.index); - this.infoPanel.FillWithModelInfo (meshInfo, this.callbacks.getMaterialInformation, { + this.infoPanel.FillWithModelInfo (meshInfo, { onMaterialSelect : function (materialIndex) { obj.SetSelection (new OV.Selection (OV.SelectionType.Material, materialIndex)); } diff --git a/website/o3dv/website.js b/website/o3dv/website.js index 246a9cf..ff55817 100644 --- a/website/o3dv/website.js +++ b/website/o3dv/website.js @@ -423,6 +423,16 @@ OV.Website = class return materialInfo; } + function GetMaterialReferenceInfo (model, materialIndex) + { + const material = model.GetMaterial (materialIndex); + return { + index : materialIndex, + name : material.name, + diffuse : material.diffuse.Clone () + }; + } + function GetMeshInfo (viewer, model, meshIndex) { let result = { @@ -439,8 +449,14 @@ OV.Website = class result.triangleCount = mesh.TriangleCount (); let userData = GetMeshUserData (viewer, meshIndex); - result.usedMaterials = userData.originalMaterials; - result.usedMaterials.sort (); + result.usedMaterials = []; + for (let i = 0; i < userData.originalMaterials.length; i++) { + const materialIndex = userData.originalMaterials[i]; + result.usedMaterials.push (GetMaterialReferenceInfo (model, materialIndex)); + } + result.usedMaterials.sort (function (a, b) { + return a.index - b.index; + }); let boundingBox = viewer.GetBoundingBox (function (meshUserData) { return meshUserData.originalMeshIndex === meshIndex; @@ -461,6 +477,10 @@ OV.Website = class let boundingBox = viewer.GetBoundingBox (function (meshUserData) { return true; }); + result.usedMaterials = []; + for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) { + result.usedMaterials.push (GetMaterialReferenceInfo (model, materialIndex)); + } result.boundingBox = GetBoundingBoxInfo (boundingBox); return result; }