2 lines
20 KiB
JavaScript
2 lines
20 KiB
JavaScript
|
(()=>{var e=function(){return void 0!==window.pageYOffset?window.pageYOffset:document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop?document.body.scrollTop:0},t=function(){return void 0!==window.pageXOffset?window.pageXOffset:document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft?document.body.scrollLeft:0},n=function(e){this.manager=void 0!==e?e:THREE.DefaultLoadingManager};function o(e,t){if(this.modelUrl=e,this.$container=t,!a.webgl)return void a.addGetWebGLMessage({parent:this.$container[0]});o.instanceCount=(o.instanceCount||0)+1;let r="stlwv2-fullscreen-checkbox-"+(o.instanceCount-1);this.$container.append(['<input class="stlwv2-fullscreen-checkbox" id="'+r+'" type="checkbox"></input>','<div class="stlwv2-inner">',' <div class="stlwv2-percent"></div>',' <label class="stlwv2-hud stlwv2-fullscreen-on" title="Fullscreen" for="'+r+'">'," ⇱</label>",' <label class="stlwv2-hud stlwv2-fullscreen-off" title="Close" for="'+r+'">'," ×</label>",' <a class="stlwv2-hud stlwv2-github-link" target="_blank" href="https://github.com/brentyi/stl_web_viewer2">'," STL Web Viewer</a>","</div>"].join("\n")),this.$innerContainer=this.$container.children(".stlwv2-inner"),this.$fullscreenCheckbox=$("#"+r),this.$fullscreenCheckbox.on("change",this.fullscreenToggleHandler.bind(this)),this.scene=new THREE.Scene,this.camera=new THREE.PerspectiveCamera(40,this.$innerContainer.width()/this.$innerContainer.height(),1,15e3),this.cameraTarget=new THREE.Vector3,this.renderer=this.makeRenderer(antialias=!0),this.$innerContainer.append(this.renderer.domElement),this.controls=new i(this.camera,this.$innerContainer.get(0)),this.controls.target=this.cameraTarget,this.controls.enableDamping=!0,this.controls.enableKeys=!1,this.controls.rotateSpeed=.15,this.controls.dampingFactor=.125,this.controls.enableZoom=!0,this.controls.autoRotate=!0,this.controls.autoRotateSpeed=.25,this.controls.autoRotateDelay=5e3,this.hemisphereLight=new THREE.HemisphereLight(10066329,5592405),this.scene.add(this.hemisphereLight),this.pointLight=new THREE.PointLight(14540253,.75,0),this.camera.add(this.pointLight),this.scene.add(this.camera),(new n).load(this.modelUrl,this.stlLoadedCallback.bind(this),this.updateProgress.bind(this))}n.prototype={constructor:n,load:function(e,t,n,o){var a=this,i=new THREE.FileLoader(a.manager);i.setResponseType("arraybuffer"),i.load(e,(function(e){t(a.parse(e))}),n,o)},parse:function(e){var t=this.ensureBinary(e);return function(){var e;if(50,84+50*(e=new DataView(t)).getUint32(80,!0)===e.byteLength)return!0;for(var n=e.byteLength,o=0;o<n;o++)if(e.getUint8(o,!1)>127)return!0;return!1}()?this.parseBinary(t):this.parseASCII(this.ensureString(e))},parseBinary:function(e){for(var t,n,o,a,i,r,s,c,l=new DataView(e),d=l.getUint32(80,!0),h=!1,u=0;u<70;u++)1129270351==l.getUint32(u,!1)&&82==l.getUint8(u+4)&&61==l.getUint8(u+5)&&(h=!0,a=[],i=l.getUint8(u+6)/255,r=l.getUint8(u+7)/255,s=l.getUint8(u+8)/255,c=l.getUint8(u+9)/255);for(var m=new THREE.BufferGeometry,p=[],b=[],f=0;f<d;f++){var g=84+50*f,E=l.getFloat32(g,!0),w=l.getFloat32(g+4,!0),v=l.getFloat32(g+8,!0);if(h){var y=l.getUint16(g+48,!0);0==(32768&y)?(t=(31&y)/31,n=(y>>5&31)/31,o=(y>>10&31)/31):(t=i,n=r,o=s)}for(var R=1;R<=3;R++){var T=g+12*R;p.push(l.getFloat32(T,!0)),p.push(l.getFloat32(T+4,!0)),p.push(l.getFloat32(T+8,!0)),b.push(E,w,v),h&&a.push(t,n,o)}}return m.addAttribute("position",new THREE.BufferAttribute(new Float32Array(p),3)),m.addAttribute("normal",new THREE.BufferAttribute(new Float32Array(b),3)),h&&(m.addAttribute("color",new THREE.BufferAttribute(new Float32Array(a),3)),m.hasColors=!0,m.alpha=c),m},parseASCII:function(e){var t,n,o,a,i,r;t=new THREE.BufferGeometry,n=/facet([\s\S]*?)endfacet/g;for(var s=[],c=[],l=new THREE.Vector3;null!==(i=n.exec(e));){for(r=i[0],o=/normal[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;null!==(i=o.exec(r));)l.x=parseFloat(i[1]),
|