From ec3ec68648009053efae578d862af3d19ed16639 Mon Sep 17 00:00:00 2001 From: changhua <39176194+changhua0118@users.noreply.github.com> Date: Tue, 6 Jun 2023 16:58:58 +0800 Subject: [PATCH] optimizing LOD mesh trianglecount display (#15336) --- editor/inspector/assets/fbx/model.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/editor/inspector/assets/fbx/model.js b/editor/inspector/assets/fbx/model.js index d4877d42f9..9a8c235fc6 100644 --- a/editor/inspector/assets/fbx/model.js +++ b/editor/inspector/assets/fbx/model.js @@ -131,6 +131,7 @@ exports.template = /* html */`
+
@@ -224,9 +225,11 @@ ui-section { background: var(--color-hover-fill-weaker); color: var(--color-focus-contrast-emphasis); } +.lods .not-lod-mesh-label, .lods .no-lod-label { color: var(--color-default-fill-weakest) } +.lods .not-lod-mesh-label[hidden], .lods .no-lod-label[hidden] { display: none; } @@ -283,6 +286,7 @@ exports.$ = { lodsCheckbox: '.lods-checkbox', lodItems: '.lod-items', noLodLabel: '.no-lod-label', + notLodMeshLabel: '.not-lod-mesh-label', loadMask: '.load-mask', }; @@ -823,6 +827,13 @@ const Elements = { const hasBuiltinLOD = panel.meta.userData.lods && panel.meta.userData.lods.hasBuiltinLOD || false; panel.$.lodItems.innerHTML = getLodItemHTML(lodOptions, panel.LODTriangleCounts, hasBuiltinLOD); hasBuiltinLOD ? panel.$.noLodLabel.setAttribute('hidden', '') : panel.$.noLodLabel.removeAttribute('hidden'); + if (panel.notLODTriangleCounts && panel.notLODTriangleCounts.length > 0) { + const totalNotLODTriangleCounts = panel.notLODTriangleCounts.reduce((accumulator, currentValue) => accumulator + currentValue, 0); + panel.$.notLodMeshLabel.innerHTML = `There are ${panel.notLODTriangleCounts.length} non-LOD mesh(es) in the FBX, and the total triangles count is ${totalNotLODTriangleCounts}.`; + panel.$.notLodMeshLabel.removeAttribute('hidden'); + } else { + panel.$.notLodMeshLabel.setAttribute('hidden', ''); + } if (panel.$.loadMask.style.display === 'block' && this.asset.imported) { panel.$.loadMask.style.display = 'none'; } @@ -921,7 +932,9 @@ exports.update = function(assetList, metaList) { this.metaList = metaList; this.asset = assetList[0]; this.meta = metaList[0]; - this.LODTriangleCounts = handleLODTriangleCounts(this.meta); + const { LODTriangleCounts, notLODTriangleCounts } = handleLODTriangleCounts(this.meta); + this.LODTriangleCounts = LODTriangleCounts; + this.notLODTriangleCounts = notLODTriangleCounts; for (const prop in Elements) { const element = Elements[prop]; @@ -947,15 +960,24 @@ function handleLODTriangleCounts(meta) { return []; } let LODTriangleCounts = new Array(meta.userData.lods.options.length).fill(0); + let notLODTriangleCounts = new Array(); for (const key in meta.subMetas) { const subMeta = meta.subMetas[key]; if (subMeta.importer === 'gltf-mesh') { const { lodOptions, triangleCount, lodLevel } = subMeta.userData; const index = !meta.userData.lods.hasBuiltinLOD ? (lodOptions ? lodLevel : 0) : lodLevel; + // When an FBX comes with LOD, there may be non-LOD meshes, and the count of these meshes should be calculated separately. + if (index === undefined) { + notLODTriangleCounts.push(triangleCount || 0); + continue; + } LODTriangleCounts[index] = (LODTriangleCounts[index] || 0) + (triangleCount || 0); } } - return LODTriangleCounts; + return { + LODTriangleCounts, + notLODTriangleCounts, + }; } function getLodItemHTML(lodOptions, LODTriangleCounts, hasBuiltinLOD = false) {