UNPKG

@inweb/viewer-three

Version:

JavaScript library for rendering CAD and BIM files in a browser using Three.js

25 lines (23 loc) 5.37 kB
/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a // license agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("@inweb/viewer-three")):"function"==typeof define&&define.amd?define(["@inweb/viewer-three"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ODA.Three)}(this,function(e){"use strict";const t={B:1,KB:1024,MB:1<<20,GB:1<<30};function n(e){if(!e)return"-";let n;n=e>=t.GB?"GB":e>=t.MB?"MB":e>=t.KB?"KB":"B";return(e/t[n]).toFixed()+" "+n}class i{constructor(e){this.dom=document.createElement("div"),this.label=document.createElement("div"),this.label.style.padding="0.25rem 0",this.label.style.fontWeight="600",this.label.innerText=e,this.dom.appendChild(this.label),this.text=document.createElement("small"),this.text.style.display="block",this.text.style.padding="0 0.5rem",this.dom.appendChild(this.text)}update(e){this.text.innerText!==e&&(this.text.innerText=e)}}class s{constructor(e){this.updateRenderInfo=()=>{const e=this.viewer.info,t=[];t.push(`FPS: ${e.performance.fps}`),t.push(`Frame Time: ${e.performance.frameTime} ms`),this.performancePanel.update(t.join("\n")),t.length=0,t.push(`Viewport: ${e.render.viewport.width} x ${e.render.viewport.height}`),t.push(`Antialiasing: ${e.render.antialiasing}`),t.push(`Draw Calls: ${e.render.drawCalls}`),t.push(`Triangles: ${e.render.triangles}`),t.push(`Points: ${e.render.points}`),t.push(`Lines: ${e.render.lines}`),this.renderPanel.update(t.join("\n"))},this.updateSceneInfo=()=>{const e=this.viewer.info,t=[];t.push(`Objects: ${e.optimizedScene.objects}`),t.push(`Triangles: ${e.optimizedScene.triangles}`),t.push(`Points: ${e.optimizedScene.points}`),t.push(`Lines: ${e.optimizedScene.lines}`),t.push(`Edges: ${e.optimizedScene.edges}`),this.optimizedPanel.update(t.join("\n")),t.length=0,t.push(`Objects: ${e.scene.objects}`),t.push(`Triangles: ${e.scene.triangles}`),t.push(`Points: ${e.scene.points}`),t.push(`Lines: ${e.scene.lines}`),t.push(`Edges: ${e.scene.edges}`),this.scenePanel.update(t.join("\n")),t.length=0,t.push(`Geometries: ${e.memory.geometries}`),t.push(`Textures: ${e.memory.textures}`),t.push(`Materials: ${e.memory.materials}`),t.push(`GPU Used: ${n(e.memory.totalEstimatedGpuBytes)}`),t.push(`JS Heap Used: ${n(e.memory.usedJSHeapSize)}`),this.memoryPanel.update(t.join("\n"))},this.updateViewer=()=>{this.viewer.update()},this.container=document.createElement("div"),this.container.id="info-container",this.container.style.position="absolute",this.container.style.left="0px",this.container.style.top="0px",this.container.style.maxHeight="100%",this.container.style.overflow="auto",this.container.style.padding="1rem",this.setTheme("dark"),this.performancePanel=new i("Performance"),this.renderPanel=new i("Render"),this.optimizedPanel=new i("Optimized Scene"),this.scenePanel=new i("Scene"),this.memoryPanel=new i("Memory"),this.container.appendChild(this.performancePanel.dom),this.container.appendChild(this.renderPanel.dom),this.container.appendChild(this.optimizedPanel.dom),this.container.appendChild(this.scenePanel.dom),this.container.appendChild(this.memoryPanel.dom),e.canvas.parentElement.appendChild(this.container),this.viewer=e,this.viewer.addEventListener("clear",this.updateSceneInfo),this.viewer.addEventListener("geometryend",this.updateSceneInfo),this.viewer.addEventListener("render",this.updateRenderInfo),this.viewer.addEventListener("animate",this.updateViewer),this.updateRenderInfo(),this.updateSceneInfo()}dispose(){this.viewer.removeEventListener("clear",this.updateSceneInfo),this.viewer.removeEventListener("geometryend",this.updateSceneInfo),this.viewer.removeEventListener("render",this.updateRenderInfo),this.viewer.removeEventListener("animate",this.updateViewer),this.performancePanel=void 0,this.renderPanel=void 0,this.optimizedPanel=void 0,this.scenePanel=void 0,this.memoryPanel=void 0,this.container.remove(),this.container=void 0}setTheme(e){"light"===e&&(this.container.style.background="rgba(0, 0, 0, 0.025)",this.container.style.color="#3d3d3d"),"dark"===e&&(this.container.style.background="rgba(0, 0, 0, 0.88)",this.container.style.color="#ebebeb")}}e.components.registerComponent("InfoPanelComponent",e=>new s(e))});