UNPKG

@inweb/viewer-three

Version:

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

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