UNPKG

@inweb/viewer-three

Version:

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

25 lines (23 loc) 3.9 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";var t=function(){var e=0,i=document.createElement("div");function n(e){return i.appendChild(e.dom),e}function a(t){for(var n=0;n<i.children.length;n++)i.children[n].style.display=n===t?"block":"none";e=t}i.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000",i.addEventListener("click",function(t){t.preventDefault(),a(++e%i.children.length)},!1);var l=(performance||Date).now(),s=l,o=0,r=n(new t.Panel("FPS","#0ff","#002")),d=n(new t.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var f=n(new t.Panel("MB","#f08","#201"));return a(0),{REVISION:16,dom:i,addPanel:n,showPanel:a,begin:function(){l=(performance||Date).now()},end:function(){o++;var e=(performance||Date).now();if(d.update(e-l,200),e>=s+1e3&&(r.update(1e3*o/(e-s),100),s=e,o=0,f)){var t=performance.memory;f.update(t.usedJSHeapSize/1048576,t.jsHeapSizeLimit/1048576)}return e},update:function(){l=this.end()},domElement:i,setMode:a}};t.Panel=function(e,t,i){var n=1/0,a=0,l=Math.round,s=l(window.devicePixelRatio||1),o=80*s,r=48*s,d=3*s,f=2*s,p=3*s,c=15*s,h=74*s,u=30*s,m=document.createElement("canvas");m.width=o,m.height=r,m.style.cssText="width:80px;height:48px";var v=m.getContext("2d");return v.font="bold "+9*s+"px Helvetica,Arial,sans-serif",v.textBaseline="top",v.fillStyle=i,v.fillRect(0,0,o,r),v.fillStyle=t,v.fillText(e,d,f),v.fillRect(p,c,h,u),v.fillStyle=i,v.globalAlpha=.9,v.fillRect(p,c,h,u),{dom:m,update:function(r,w){n=Math.min(n,r),a=Math.max(a,r),v.fillStyle=i,v.globalAlpha=1,v.fillRect(0,0,o,c),v.fillStyle=t,v.fillText(l(r)+" "+e+" ("+l(n)+"-"+l(a)+")",d,f),v.drawImage(m,p+s,c,h-s,u,p,c,h-s,u),v.fillRect(p+h-s,c,s,u),v.fillStyle=i,v.globalAlpha=.9,v.fillRect(p+h-s,c,s,l((1-r/w)*u))}}};class i{constructor(e){this.updateStats=()=>{this.stats.update()},this.updateViewer=()=>{this.viewer.update()},this.stats=new t,this.stats.dom.style.position="absolute",this.stats.dom.style.left="0px",this.stats.dom.style.top="0px",e.canvas.parentElement.appendChild(this.stats.dom),this.viewer=e,this.viewer.addEventListener("render",this.updateStats),this.viewer.addEventListener("animate",this.updateViewer)}dispose(){this.viewer.removeEventListener("render",this.updateStats),this.viewer.removeEventListener("animate",this.updateViewer),this.stats.dom.remove(),this.stats=void 0}}e.components.registerComponent("StatsPanelComponent",e=>new i(e))});