@olearis/view3d
Version:
Fast & Customizable glTF 3D model viewer, packed with full of features!
10 lines • 211 kB
JavaScript
/*
Copyright (c) NAVER Corp.
name: @olearis/view3d
license: MIT
author: NAVER Corp.
repository: https://github.com/naver/egjs-view3d
version: 2.10.2
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("three"),require("@egjs/component")):"function"==typeof define&&define.amd?define(["three","@egjs/component"],t):(e=e||self).View3D=t(e.THREE,e.Component)}(this,function(P,D){"use strict";class h extends Error{constructor(e,t){super(e),Object.setPrototypeOf(this,h.prototype),this.name="View3DError",this.code=t}}var r={WRONG_TYPE:0,ELEMENT_NOT_FOUND:1,CANVAS_NOT_FOUND:2,WEBGL_NOT_SUPPORTED:3,PROVIDE_SRC_FIRST:4,FILE_NOT_SUPPORTED:5,NOT_INITIALIZED:6,MODEL_FAIL_TO_LOAD:7},l=r,c={WRONG_TYPE:(e,t)=>typeof e+` is not a ${t.map(e=>`"${e}"`).join(" or ")}.`,ELEMENT_NOT_FOUND:e=>`Element with selector "${e}" not found.`,CANVAS_NOT_FOUND:"The canvas element was not found inside the given root element.",WEBGL_NOT_SUPPORTED:"WebGL is not supported on this browser.",PROVIDE_SRC_FIRST:'"src" should be provided before initialization.',FILE_NOT_SUPPORTED:e=>`Given file "${e}" is not supported.`,NOT_INITIALIZED:"View3D is not initialized yet.",MODEL_FAIL_TO_LOAD:e=>`Failed to load/parse the 3D model with the given url: "${e}". Check "loadError" event for actual error instance.`};const I=e=>"number"==typeof e,n=e=>"string"==typeof e,N=e=>!!e&&e.nodeType===Node.ELEMENT_NODE,F=(e,t)=>{let i=null;if(n(e)){t=(t||document).querySelector(e);if(!t)return null;i=t}else N(e)&&(i=e);return i},ee=(e,t)=>{t=F(e,t);if(t)return t;throw n(e)?new h(c.ELEMENT_NOT_FOUND(e),l.ELEMENT_NOT_FOUND):new h(c.WRONG_TYPE(e,["HTMLElement","string"]),l.WRONG_TYPE)},U=(e,t)=>{e=e.querySelector(t);if(e)return e;throw new h(c.CANVAS_NOT_FOUND,l.CANVAS_NOT_FOUND)},B=e=>{if(!n(e))return!1;var t=document.createDocumentFragment();try{t.querySelector(e)}catch(e){return!1}return!0},k=e=>!e||e<=0?[]:Array.apply(0,Array(e)).map((e,t)=>t),_=e=>e*Math.PI/180,p=e=>180*e/Math.PI,d=(e,t,i)=>Math.max(Math.min(e,i),t),H=(e,t,i)=>e*(1-i)+t*i,u=(e,t,i)=>{var s=Math.abs(i-t);return e<t?e=i-(t-e)%s:i<e&&(e=t+(e-i)%s),e},V=(s,...e)=>(e.forEach(i=>{Object.keys(i).forEach(e=>{var t=i[e];Array.isArray(s[e])&&Array.isArray(t)?s[e]=[...s[e],...t]:s[e]=t})}),s);const G=e=>{let t=1;for(;t<e;)t*=2;return t};const z=(e,t,i)=>{t=(new P.Vector2).subVectors(t,e).normalize(),i=(new P.Vector2).subVectors(i,e).normalize().angle()-t.angle(),e=-Math.sign(i)*(2*Math.PI-Math.abs(i));return Math.abs(i)<Math.abs(e)?i:e},Z=e=>"object"==typeof e?e:{},W=e=>e?"true":"false",j=(e,t,i)=>{var t=_(t),i=_(i),s=new P.Vector3(0,0,0);return s.y=e*Math.sin(i),s.z=e*Math.cos(i),s.x=s.z*Math.sin(-t),s.z=s.z*Math.cos(-t),s},K=e=>{var t=new P.Vector2(e.x,e.z),i=new P.Vector2;return{yaw:Math.abs(e.y)<=.99?z(i,new P.Vector2(0,1),t):0,pitch:Math.atan2(e.y,t.distanceTo(i))}},X=(e,t)=>{t={src:t,loaded:0,total:0,lengthComputable:!1,initialized:!1};return e.loadingContext.push(t),t},q=e=>{var t;return e.normalized&&ArrayBuffer.isView(e.array)?(e=e.array,t=te(e),e=1/(Math.pow(2,8*e.BYTES_PER_ELEMENT)-1),t?2*e:e):1},Y=(e,t,i,s)=>{var r=t.geometry,n=r.attributes.position,a=r.attributes.skinIndex,r=r.attributes.skinWeight;const o=t.skeleton.boneMatrices;n=(new P.Vector3).fromBufferAttribute(n,e).multiplyScalar(i);const h=new P.Vector4(0,0,0,0),l=new P.Vector4(n.x,n.y,n.z).applyMatrix4(t.bindMatrix);i=[r.getX(e),r.getY(e),r.getZ(e),r.getW(e)].map(e=>e*s);const c=[a.getX(e),a.getY(e),a.getZ(e),a.getW(e)];i.forEach((e,t)=>{t=(new P.Matrix4).fromArray(o,16*c[t]);h.add(l.clone().applyMatrix4(t).multiplyScalar(e))});n=(new P.Vector3).fromArray(h.applyMatrix4(t.bindMatrixInverse).toArray());return n.applyMatrix4(t.matrixWorld),n},te=e=>{e=new e.constructor(1);return e[0]=-1,e[0]<0},ie=e=>{if(e.capabilities.isWebGL2)return!0;{var e=e.getContext(),i=e.createTexture();let t=!0;try{var s=new Uint16Array(4),r=e.getExtension("OES_texture_half_float");t=!!r&&(e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,r.HALF_FLOAT_OES,s),e.getError()===e.NO_ERROR)}catch(e){t=!1}return e.deleteTexture(i),t}},se=(e,t,i)=>{if(!e||t<0||i<0)return null;e=e.meshes[t];const s=null==(t=null==e?void 0:e.geometry.index)?void 0:t.array;t=s?k(3).map(e=>s[3*i+e]):null;if(!e||!s||!t||t.some(e=>null==e))return null;const r=e.geometry.getAttribute("position");return t.map(e=>(new P.Vector3).fromBufferAttribute(r,e))},re=(e,t,i)=>{var s=se(e,t,i);if(!s)return null;const r=e.meshes[t],n=r.geometry.getIndex().array.slice(3*i,3*i+3);if(r.isSkinnedMesh){e=r.geometry,t=e.attributes.position,i=e.attributes.skinWeight;const a=q(t),o=q(i);s.forEach((e,t)=>{t=n[t],t=Y(t,r,a,o);e.copy(t)})}else s.forEach(e=>{e.applyMatrix4(r.matrixWorld)});return s};const ne=(e,t,i=!1)=>!e||!i&&e.constructor===t?e:"number"==typeof t.BYTES_PER_ELEMENT?new t(e):Array.prototype.slice.call(e),ae=(e,t)=>{const s=t.min.toArray(),r=(new P.Vector3).subVectors(t.max,t.min).toArray();return(new P.Vector3).fromArray(e.map((e,t)=>{var i;return n(e)?(i=.01*parseFloat(e),s[t]+i*r[t]):e}))};function oe(e,t){var i={};for(r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(i[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var s=0,r=Object.getOwnPropertySymbols(e);s<r.length;s++)t.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(e,r[s])&&(i[r[s]]=e[r[s]]);return i}function Q(e,a,o,h){return new(o=o||Promise)(function(i,t){function s(e){try{n(h.next(e))}catch(e){t(e)}}function r(e){try{n(h.throw(e))}catch(e){t(e)}}function n(e){var t;e.done?i(e.value):((t=e.value)instanceof o?t:new o(function(e){e(t)})).then(s,r)}n((h=h.apply(e,a||[])).next())})}var he={uniforms:{tDiffuse:{value:null},opacity:{value:1}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\n\t\tuniform float opacity;\n\n\t\tuniform sampler2D tDiffuse;\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvec4 texel = texture2D( tDiffuse, vUv );\n\t\t\tgl_FragColor = opacity * texel;\n\n\t\t}"};class le{constructor(){this.enabled=!0,this.needsSwap=!0,this.clear=!1,this.renderToScreen=!1}setSize(){}render(){console.error("THREE.Pass: .render() must be implemented in derived pass.")}}var ce=new P.OrthographicCamera(-1,1,1,-1,0,1),de=new P.BufferGeometry;de.setAttribute("position",new P.Float32BufferAttribute([-1,3,0,-1,-1,0,3,-1,0],3)),de.setAttribute("uv",new P.Float32BufferAttribute([0,2,0,0,2,0],2));class ue{constructor(e){this._mesh=new P.Mesh(de,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,ce)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}}class _e extends le{constructor(e,t){super(),this.textureID=void 0!==t?t:"tDiffuse",e instanceof P.ShaderMaterial?(this.uniforms=e.uniforms,this.material=e):e&&(this.uniforms=P.UniformsUtils.clone(e.uniforms),this.material=new P.ShaderMaterial({defines:Object.assign({},e.defines),uniforms:this.uniforms,vertexShader:e.vertexShader,fragmentShader:e.fragmentShader})),this.fsQuad=new ue(this.material)}render(e,t,i){this.uniforms[this.textureID]&&(this.uniforms[this.textureID].value=i.texture),this.fsQuad.material=this.material,this.renderToScreen?e.setRenderTarget(null):(e.setRenderTarget(t),this.clear&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil)),this.fsQuad.render(e)}}class pe extends le{constructor(e,t){super(),this.scene=e,this.camera=t,this.clear=!0,this.needsSwap=!1,this.inverse=!1}render(e,t,i){var s,r,n=e.getContext(),a=e.state;a.buffers.color.setMask(!1),a.buffers.depth.setMask(!1),a.buffers.color.setLocked(!0),a.buffers.depth.setLocked(!0),r=this.inverse?(s=0,1):(s=1,0),a.buffers.stencil.setTest(!0),a.buffers.stencil.setOp(n.REPLACE,n.REPLACE,n.REPLACE),a.buffers.stencil.setFunc(n.ALWAYS,s,4294967295),a.buffers.stencil.setClear(r),a.buffers.stencil.setLocked(!0),e.setRenderTarget(i),this.clear&&e.clear(),e.render(this.scene,this.camera),e.setRenderTarget(t),this.clear&&e.clear(),e.render(this.scene,this.camera),a.buffers.color.setLocked(!1),a.buffers.depth.setLocked(!1),a.buffers.stencil.setLocked(!1),a.buffers.stencil.setFunc(n.EQUAL,1,4294967295),a.buffers.stencil.setOp(n.KEEP,n.KEEP,n.KEEP),a.buffers.stencil.setLocked(!0)}}class me{constructor(e,t){var i,s;this.renderer=e,void 0===t?(i={minFilter:P.LinearFilter,magFilter:P.LinearFilter,format:P.RGBAFormat},s=e.getSize(new P.Vector2),this._pixelRatio=e.getPixelRatio(),this._width=s.width,this._height=s.height,(t=new P.WebGLRenderTarget(this._width*this._pixelRatio,this._height*this._pixelRatio,i)).texture.name="EffectComposer.rt1"):(this._pixelRatio=1,this._width=t.width,this._height=t.height),this.renderTarget1=t,this.renderTarget2=t.clone(),this.renderTarget2.texture.name="EffectComposer.rt2",this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2,this.renderToScreen=!0,this.passes=[],void 0===_e&&console.error("THREE.EffectComposer relies on ShaderPass"),this.copyPass=new _e(he),this.clock=new P.Clock}swapBuffers(){var e=this.readBuffer;this.readBuffer=this.writeBuffer,this.writeBuffer=e}addPass(e){this.passes.push(e),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}insertPass(e,t){this.passes.splice(t,0,e),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}removePass(e){e=this.passes.indexOf(e);-1!==e&&this.passes.splice(e,1)}isLastEnabledPass(e){for(var t=e+1;t<this.passes.length;t++)if(this.passes[t].enabled)return!1;return!0}render(e){void 0===e&&(e=this.clock.getDelta());for(var t=this.renderer.getRenderTarget(),i=!1,s=0,r=this.passes.length;s<r;s++){var n,a,o=this.passes[s];!1!==o.enabled&&(o.renderToScreen=this.renderToScreen&&this.isLastEnabledPass(s),o.render(this.renderer,this.writeBuffer,this.readBuffer,e,i),o.needsSwap&&(i&&(n=this.renderer.getContext(),(a=this.renderer.state.buffers.stencil).setFunc(n.NOTEQUAL,1,4294967295),this.copyPass.render(this.renderer,this.writeBuffer,this.readBuffer,e),a.setFunc(n.EQUAL,1,4294967295)),this.swapBuffers()),void 0!==pe)&&(o instanceof pe?i=!0:!1&&(i=!1))}this.renderer.setRenderTarget(t)}reset(e){var t;void 0===e&&(t=this.renderer.getSize(new P.Vector2),this._pixelRatio=this.renderer.getPixelRatio(),this._width=t.width,this._height=t.height,(e=this.renderTarget1.clone()).setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)),this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.renderTarget1=e,this.renderTarget2=e.clone(),this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2}setSize(e,t){this._width=e,this._height=t;var i=this._width*this._pixelRatio,s=this._height*this._pixelRatio;this.renderTarget1.setSize(i,s),this.renderTarget2.setSize(i,s);for(var r=0;r<this.passes.length;r++)this.passes[r].setSize(i,s)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}}new P.OrthographicCamera(-1,1,1,-1,0,1);var e=new P.BufferGeometry;e.setAttribute("position",new P.Float32BufferAttribute([-1,3,0,-1,-1,0,3,-1,0],3)),e.setAttribute("uv",new P.Float32BufferAttribute([0,2,0,0,2,0],2));class ve extends le{constructor(e,t,i,s,r){super(),this.scene=e,this.camera=t,this.overrideMaterial=i,this.clearColor=s,this.clearAlpha=void 0!==r?r:0,this.clear=!0,this.clearDepth=!1,this.needsSwap=!1,this._oldClearColor=new P.Color}render(e,t,i){var s,r,n=e.autoClear;e.autoClear=!1,void 0!==this.overrideMaterial&&(r=this.scene.overrideMaterial,this.scene.overrideMaterial=this.overrideMaterial),this.clearColor&&(e.getClearColor(this._oldClearColor),s=e.getClearAlpha(),e.setClearColor(this.clearColor,this.clearAlpha)),this.clearDepth&&e.clearDepth(),e.setRenderTarget(this.renderToScreen?null:i),this.clear&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),e.render(this.scene,this.camera),this.clearColor&&e.setClearColor(this._oldClearColor,s),void 0!==this.overrideMaterial&&(this.scene.overrideMaterial=r),e.autoClear=n}}class ge extends le{constructor(e){super();var t=he;this.textureID="tDiffuse",this.uniforms=P.UniformsUtils.clone(t.uniforms),this.material=new P.ShaderMaterial({uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader}),this.renderTarget=e,void 0===this.renderTarget&&(this.renderTarget=new P.WebGLRenderTarget(window.innerWidth,window.innerHeight,{minFilter:P.LinearFilter,magFilter:P.LinearFilter,format:P.RGBFormat}),this.renderTarget.texture.name="SavePass.rt"),this.needsSwap=!1,this.fsQuad=new ue(this.material)}render(e,t,i){this.uniforms[this.textureID]&&(this.uniforms[this.textureID].value=i.texture),e.setRenderTarget(this.renderTarget),this.clear&&e.clear(),this.fsQuad.render(e)}}var o,fe={uniforms:{tDiffuse1:{value:null},tDiffuse2:{value:null},mixRatio:{value:.5},opacity:{value:1}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\n\t\tuniform float opacity;\n\t\tuniform float mixRatio;\n\n\t\tuniform sampler2D tDiffuse1;\n\t\tuniform sampler2D tDiffuse2;\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvec4 texel1 = texture2D( tDiffuse1, vUv );\n\t\t\tvec4 texel2 = texture2D( tDiffuse2, vUv );\n\t\t\tgl_FragColor = opacity * mix( texel1, texel2, mixRatio );\n\n\t\t}"},Ee={uniforms:{tDiffuse:{value:null}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\n\t\tuniform sampler2D tDiffuse;\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvec4 tex = texture2D( tDiffuse, vUv );\n\n\t\t\tgl_FragColor = LinearTosRGB( tex ); // optional: LinearToGamma( tex, float( GAMMA_FACTOR ) );\n\n\t\t}"};const m={MOUSE_DOWN:"mousedown",MOUSE_MOVE:"mousemove",MOUSE_UP:"mouseup",TOUCH_START:"touchstart",TOUCH_MOVE:"touchmove",TOUCH_END:"touchend",WHEEL:"wheel",RESIZE:"resize",CONTEXT_MENU:"contextmenu",MOUSE_ENTER:"mouseenter",MOUSE_LEAVE:"mouseleave",POINTER_DOWN:"pointerdown",POINTER_MOVE:"pointermove",POINTER_UP:"pointerup",POINTER_ENTER:"pointerenter",POINTER_LEAVE:"pointerleave",LOAD:"load",ERROR:"error",CLICK:"click",DOUBLE_CLICK:"dblclick",CONTEXT_LOST:"webglcontextlost",CONTEXT_RESTORED:"webglcontextrestored"},i={GRAB:"grab",GRABBING:"grabbing",NONE:""},Te=((e=o=o||{})[e.LEFT=0]="LEFT",e[e.MIDDLE=1]="MIDDLE",e[e.RIGHT=2]="RIGHT","anonymous"),f="div",we="button",$="auto",E={READY:"ready",LOAD_START:"loadStart",LOAD:"load",LOAD_ERROR:"loadError",LOAD_FINISH:"loadFinish",MODEL_CHANGE:"modelChange",RESIZE:"resize",BEFORE_RENDER:"beforeRender",RENDER:"render",PROGRESS:"progress",INPUT_START:"inputStart",INPUT_END:"inputEnd",CAMERA_CHANGE:"cameraChange",ANIMATION_START:"animationStart",ANIMATION_LOOP:"animationLoop",ANIMATION_FINISHED:"animationFinished",ANNOTATION_FOCUS:"annotationFocus",ANNOTATION_UNFOCUS:"annotationUnfocus",AR_START:"arStart",AR_END:"arEnd",AR_MODEL_PLACED:"arModelPlaced",QUICK_LOOK_TAP:"quickLookTap"},be={SINE_WAVE:e=>Math.sin(e*Math.PI*2),EASE_OUT_CUBIC:e=>1-Math.pow(1-e,3),EASE_OUT_BOUNCE:e=>{var t=7.5625,i=2.75;return e<1/i?t*e*e:e<2/i?t*(e-=1.5/i)*e+.75:e<2.5/i?t*(e-=2.25/i)*e+.9375:t*(e-=2.625/i)*e+.984375}},J={WRAPPER:"view3d-wrapper",CANVAS:"view3d-canvas",POSTER:"view3d-poster",AR_OVERLAY:"view3d-ar-overlay",ANNOTATION_WRAPPER:"view3d-annotation-wrapper",ANNOTATION:"view3d-annotation",ANNOTATION_TOOLTIP:"view3d-annotation-tooltip",ANNOTATION_DEFAULT:"default",ANNOTATION_SELECTED:"selected",ANNOTATION_HIDDEN:"hidden",ANNOTATION_FLIP_X:"flip-x",ANNOTATION_FLIP_Y:"flip-y",CTX_LOST:"ctx-lost"},xe={LINEAR:P.LinearToneMapping,REINHARD:P.ReinhardToneMapping,CINEON:P.CineonToneMapping,ACES_FILMIC:P.ACESFilmicToneMapping},Se={FOV:"fov",DISTANCE:"distance"};e={WEBXR:"webAR",SCENE_VIEWER:"sceneViewer",QUICK_LOOK:"quickLook"};const ye={ONLY_AR:"ar_only",ONLY_3D:"3d_only",PREFER_AR:"ar_preferred",PREFER_3D:"3d_preferred"};var v;const g={ROTATE:0,TRANSLATE:1,ZOOM:2},Re={ONE:"one",NONE:"none",ALL:"all"};class Le{constructor(e){this._defaultRenderLoop=e=>{var{control:t,autoPlayer:i,animator:s}=this._view3D;(s.animating||t.animating||i.animating)&&this._renderFrame(e)},this._onContextLost=()=>{this._canvas.classList.add(J.CTX_LOST)},this._onContextRestore=()=>{var e=this._canvas,t=this._view3D.scene;e.classList.remove(J.CTX_LOST),t.initTextures(),this.renderSingleFrame()};var t=U(e.rootEl,e.canvasSelector),i=(this._canvas=t,this._view3D=e,this._renderQueued=!1,new P.WebGLRenderer({canvas:t,alpha:!0,antialias:!0,preserveDrawingBuffer:!0}));i.toneMapping=e.toneMapping,i.toneMappingExposure=e.exposure,i.outputEncoding=P.sRGBEncoding,i.setClearColor(0,0),this._halfFloatAvailable=ie(i),this._renderer=i,this._clock=new P.Clock(!1),this._canvasSize=new P.Vector2,t.addEventListener(m.CONTEXT_LOST,this._onContextLost),t.addEventListener(m.CONTEXT_RESTORED,this._onContextRestore)}get canvas(){return this._canvas}get context(){return this._renderer.getContext()}get threeRenderer(){return this._renderer}get defaultRenderLoop(){return this._defaultRenderLoop}get size(){var e=this._renderer.getSize(new P.Vector2);return{width:e.width,height:e.y}}get canvasSize(){return this._canvasSize}get capabilities(){var e=this._renderer;return Object.assign(Object.assign({},e.capabilities),{halfFloat:this._halfFloatAvailable})}effectsOn(e){this._effectsOn=e}setBlenMixRatio(e){this.blendPass.uniforms.mixRatio.value=e}destroy(){var e=this._canvas;this.stopAnimationLoop(),this._renderer.dispose(),e.removeEventListener(m.CONTEXT_LOST,this._onContextLost),e.removeEventListener(m.CONTEXT_RESTORED,this._onContextRestore)}resize(){var e,t=this._renderer,i=this._canvas;t.xr.isPresenting||(e=i.clientWidth||1,i=i.clientHeight||1,t.setPixelRatio(window.devicePixelRatio),t.setSize(e,i,!1),this._canvasSize.set(e,i))}setAnimationLoop(s){const r=this._view3D,n=this._clock;var e=this._canvas,t=(this.renderPass=new ve(r.scene.root,r.camera.threeCamera),new _e(Ee)),e=new P.WebGLRenderTarget((e.clientWidth||1)*window.devicePixelRatio,(e.clientHeight||1)*window.devicePixelRatio,{colorSpace:"srgb",stencilBuffer:!1}),e=new ge(e),i=(this.blendPass=new _e(fe,"tDiffuse1"),this.blendPass.uniforms.tDiffuse2.value=e.renderTarget.texture,this.blendPass.uniforms.mixRatio.value=0,new _e(he));i.renderToScreen=!0,this.composer=new me(this._renderer),this.composer.setSize(window.innerWidth,window.innerHeight),this.composer.setPixelRatio(window.devicePixelRatio),this.composer.addPass(this.renderPass),this.composer.addPass(t),this.composer.addPass(this.blendPass),this.composer.addPass(e),this.composer.addPass(i),n.start(),this._renderer.setAnimationLoop((e,t)=>{var i=Math.min(n.getDelta(),r.maxDeltaTime);s(i,t)})}stopAnimationLoop(){this._clock.stop(),this._renderer.setAnimationLoop(null)}renderSingleFrame(e=!1){this._renderer.xr.isPresenting||(e?this._renderFrame(0):this._renderQueued||(requestAnimationFrame(()=>{this._renderFrame(0)}),this._renderQueued=!0))}_renderFrame(e){var t,i=this._view3D,s=this._renderer,{scene:r,camera:n,control:a,autoPlayer:o,animator:h,annotation:l}=i;s.getContext().isContextLost()||(t=1e3*e,this._renderQueued=!1,h.update(e),a.update(t),o.update(t),i.trigger(E.BEFORE_RENDER,{type:E.BEFORE_RENDER,target:i,delta:t}),n.updatePosition(),r.shadowPlane.render(),this._effectsOn?this.composer.render():s.render(r.root,n.threeCamera),l.render(),i.trigger(E.RENDER,{type:E.RENDER,target:i,delta:t}))}}class Ae extends P.DataTextureLoader{constructor(e){super(e),this.type=P.HalfFloatType}parse(e){var t,i,s,r,n,a,o,h,l,c,d=-1,E=1,u=2,T=3,w=4,b=function(e,t){switch(e){case E:console.error("THREE.RGBELoader Read Error: "+(t||""));break;case u:console.error("THREE.RGBELoader Write Error: "+(t||""));break;case T:console.error("THREE.RGBELoader Bad File Format: "+(t||""));break;default:console.error("THREE.RGBELoader: Error: "+(t||""))}return d},_=1,p=2,m=4,v="\n",g=function(e,t,i){t=t||1024;for(var s=e.pos,r=-1,n=0,a="",o=String.fromCharCode.apply(null,new Uint16Array(e.subarray(s,s+128)));(r=o.indexOf(v))<0&&n<t&&s<e.byteLength;)a+=o,n+=o.length,s+=128,o+=String.fromCharCode.apply(null,new Uint16Array(e.subarray(s,s+128)));return-1<r&&(!1!==i&&(e.pos+=n+r+1),a+o.slice(0,r))},e=new Uint8Array(e),f=(e.pos=0,function(e){var t,i,s=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,r=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,n=/^\s*FORMAT=(\S+)\s*$/,a=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,o={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};if(e.pos>=e.byteLength||!(t=g(e)))return b(E,"no header found");if(!(i=t.match(/^#\?(\S+)/)))return b(T,"bad initial token");for(o.valid|=_,o.programtype=i[1],o.string+=t+"\n";;){if(!1===(t=g(e)))break;if(o.string+=t+"\n","#"===t.charAt(0))o.comments+=t+"\n";else if((i=t.match(s))&&(o.gamma=parseFloat(i[1],10)),(i=t.match(r))&&(o.exposure=parseFloat(i[1],10)),(i=t.match(n))&&(o.valid|=p,o.format=i[1]),(i=t.match(a))&&(o.valid|=m,o.height=parseInt(i[1],10),o.width=parseInt(i[2],10)),o.valid&p&&o.valid&m)break}return o.valid&p?o.valid&m?o:b(T,"missing image size specifier"):b(T,"missing format specifier")}(e));if(d!==f){var x,S,y,R=f.width,L=f.height,A=function(e,t,i){var s=t;if(s<8||32767<s||2!==e[0]||2!==e[1]||128&e[2])return new Uint8Array(e);if(s!==(e[2]<<8|e[3]))return b(T,"wrong scanline width");var r=new Uint8Array(4*t*i);if(!r.length)return b(w,"unable to allocate buffer space");for(var n=0,a=0,o=4*s,h=new Uint8Array(4),l=new Uint8Array(o),c=i;0<c&&a<e.byteLength;){if(a+4>e.byteLength)return b(E);if(h[0]=e[a++],h[1]=e[a++],h[2]=e[a++],h[3]=e[a++],2!=h[0]||2!=h[1]||(h[2]<<8|h[3])!=s)return b(T,"bad rgbe scanline format");for(var d=0,u=void 0;d<o&&a<e.byteLength;){var _=128<(u=e[a++]);if(_&&(u-=128),0===u||o<d+u)return b(T,"bad scanline data");if(_)for(var p=e[a++],m=0;m<u;m++)l[d++]=p;else l.set(e.subarray(a,a+u),d),d+=u,a+=u}for(var v=s,g=0;g<v;g++){var f=0;r[n]=l[g+0],f+=s,r[n+1]=l[g+f],f+=s,r[n+2]=l[g+f],f+=s,r[n+3]=l[g+f],n+=4}c--}return r}(e.subarray(e.pos),R,L);if(d!==A){switch(this.type){case P.UnsignedByteType:x=A,S=P.RGBEFormat,y=P.UnsignedByteType;break;case P.FloatType:for(var O=A.length/4,C=new Float32Array(3*O),M=0;M<O;M++)h=C,l=3*M,c=void 0,c=(a=A)[(o=4*M)+3],c=Math.pow(2,c-128)/255,h[l+0]=a[o+0]*c,h[l+1]=a[o+1]*c,h[l+2]=a[o+2]*c;x=C,S=P.RGBFormat,y=P.FloatType;break;case P.HalfFloatType:O=A.length/4;for(var D=new Uint16Array(3*O),I=0;I<O;I++)s=D,r=3*I,n=void 0,n=(t=A)[(i=4*I)+3],n=Math.pow(2,n-128)/255,s[r+0]=P.DataUtils.toHalfFloat(Math.min(t[i+0]*n,65504)),s[r+1]=P.DataUtils.toHalfFloat(Math.min(t[i+1]*n,65504)),s[r+2]=P.DataUtils.toHalfFloat(Math.min(t[i+2]*n,65504));x=D,S=P.RGBFormat,y=P.HalfFloatType;break;default:console.error("THREE.RGBELoader: unsupported type: ",this.type)}return{width:R,height:L,data:x,header:f.string,gamma:f.gamma,exposure:f.exposure,format:S,type:y}}}return null}setDataType(e){return this.type=e,this}load(e,i,t,s){return super.load(e,function(e,t){switch(e.type){case P.UnsignedByteType:e.encoding=P.RGBEEncoding,e.minFilter=P.NearestFilter,e.magFilter=P.NearestFilter,e.generateMipmaps=!1,e.flipY=!0;break;case P.FloatType:case P.HalfFloatType:e.encoding=P.LinearEncoding,e.minFilter=P.LinearFilter,e.magFilter=P.LinearFilter,e.generateMipmaps=!1,e.flipY=!0}i&&i(e,t)},t,s)}}class Oe{constructor(e){this._onLoadingProgress=(e,t,i)=>{var s=this._view3D;i.initialized=!0,i.lengthComputable=e.lengthComputable,i.loaded=e.loaded,i.total=e.total,s.trigger(E.PROGRESS,{type:E.PROGRESS,target:s,src:t,lengthComputable:e.lengthComputable,loaded:e.loaded,total:e.total})},this._view3D=e}}class Ce extends Oe{constructor(e){super(e)}load(r){const n=this._view3D;return new Promise((e,t)=>{var i=new P.TextureLoader;const s=X(n,r);i.setCrossOrigin(Te),i.load(r,e,e=>this._onLoadingProgress(e,r,s),e=>{s.initialized=!0,t(e)})})}loadHDRTexture(r){const n=this._view3D;return new Promise((t,i)=>{var e=new Ae;n.renderer.capabilities.halfFloat||(e.type=P.FloatType);const s=X(n,r);e.setCrossOrigin(Te),e.load(r,e=>{e.mapping=P.EquirectangularReflectionMapping,t(e)},e=>this._onLoadingProgress(e,r,s),e=>{s.initialized=!0,i(e)})})}}const Me=["alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","envMap","lightMap","map","metalnessMap","normalMap","roughnessMap","sheenColorMap","sheenRoughnessMap","specularColorMap","specularIntensityMap","transmissionMap","clearcoatMap","clearcoatNormalMap"],T={HOLD:"hold",RELEASE:"release",ENABLE:"enable",DISABLE:"disable"},De=((t=v=v||{})[t.NONE=0]="NONE",t[t.ONE_FINGER_HORIZONTAL=1]="ONE_FINGER_HORIZONTAL",t[t.ONE_FINGER_VERTICAL=2]="ONE_FINGER_VERTICAL",t[t.ONE_FINGER=3]="ONE_FINGER",t[t.TWO_FINGER_HORIZONTAL=4]="TWO_FINGER_HORIZONTAL",t[t.TWO_FINGER_VERTICAL=8]="TWO_FINGER_VERTICAL",t[t.TWO_FINGER=12]="TWO_FINGER",t[t.PINCH=16]="PINCH","KHR_materials_variants"),Ie="EXT_View3D_texture_LOD",Pe="view3d-lod",Ne="view3d-annotation";var w,a,Fe={uniforms:{tDiffuse:{value:null},h:{value:1/512}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\n\t\tuniform sampler2D tDiffuse;\n\t\tuniform float h;\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvec4 sum = vec4( 0.0 );\n\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x - 4.0 * h, vUv.y ) ) * 0.051;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x - 3.0 * h, vUv.y ) ) * 0.0918;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x - 2.0 * h, vUv.y ) ) * 0.12245;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x - 1.0 * h, vUv.y ) ) * 0.1531;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x + 1.0 * h, vUv.y ) ) * 0.1531;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x + 2.0 * h, vUv.y ) ) * 0.12245;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x + 3.0 * h, vUv.y ) ) * 0.0918;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x + 4.0 * h, vUv.y ) ) * 0.051;\n\n\t\t\tgl_FragColor = sum;\n\n\t\t}"},Ue={uniforms:{tDiffuse:{value:null},v:{value:1/512}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\n\t\tuniform sampler2D tDiffuse;\n\t\tuniform float v;\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvec4 sum = vec4( 0.0 );\n\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * v ) ) * 0.051;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * v ) ) * 0.0918;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * v ) ) * 0.12245;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * v ) ) * 0.1531;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * v ) ) * 0.1531;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * v ) ) * 0.12245;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * v ) ) * 0.0918;\n\t\t\tsum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * v ) ) * 0.051;\n\n\t\t\tgl_FragColor = sum;\n\n\t\t}"};class Be{constructor(e,{darkness:t=.5,mapSize:i=9,blur:s=3.5,shadowScale:r=1,planeScale:n=2}={}){this._view3D=e,this._darkness=t,this._mapSize=i,this._blur=s,this._shadowScale=r,this._planeScale=n;t=e.renderer.threeRenderer,s=Math.min(Math.pow(2,Math.floor(i)),t.capabilities.maxTextureSize),this._root=new P.Group,this._renderTarget=new P.WebGLRenderTarget(s,s,{format:P.RGBAFormat}),this._blurTarget=new P.WebGLRenderTarget(s,s,{format:P.RGBAFormat}),this._renderTarget.texture.generateMipmaps=!1,this._blurTarget.texture.generateMipmaps=!1,r=new P.OrthographicCamera(-.5,.5,.5,-.5,0),r.rotation.x=Math.PI/2,this._shadowCamera=r,this._root.add(r),n=new P.OrthographicCamera(-.5,.5,.5,-.5,0);this._blurCamera=n,this._setupPlanes()}get root(){return this._root}get darkness(){return this._darkness}get mapSize(){return this._mapSize}get blur(){return this._blur}get shadowScale(){return this._shadowScale}get planeScale(){return this._planeScale}set darkness(e){this._plane.material.opacity=e,this._darkness=e}set blur(e){this._blur=e}set shadowScale(e){this._shadowScale=e;e=this._view3D.model;e&&this.updateDimensions(e)}updateDimensions(e){var t=this._root,i=this._shadowCamera,s=this._planeScale,r=e.bbox.getBoundingSphere(new P.Sphere),s=2*s*r.radius,n=this._shadowScale;i.far=n*(e.bbox.max.y-e.bbox.min.y)/s,i.rotation.set(Math.PI/2,Math.PI,0,"YXZ"),t.position.copy(r.center).setY(e.bbox.min.y),t.scale.setScalar(s),i.updateProjectionMatrix()}render(){this._plane.visible=!1;var e=this._view3D,{renderer:t,ar:i}=e,s=this._shadowCamera,t=t.threeRenderer,i=i.activeSession?i.activeSession.arScene:e.scene,e=t.xr.enabled,i=(t.xr.enabled=!1,i.root),r=i.background,n=(i.background=null,i.overrideMaterial=this._depthMaterial,t.getClearAlpha()),a=(t.setClearAlpha(0),t.getRenderTarget());t.setRenderTarget(this._renderTarget),t.clear(),t.render(i,s),i.overrideMaterial=null,this._blurShadow(this._blur),this._blurShadow(.4*this._blur),t.xr.enabled=e,t.setRenderTarget(a),t.setClearAlpha(n),i.background=r,this._plane.visible=!0}_blurShadow(e){var t=this._view3D["renderer"],i=this._blurCamera,t=t.threeRenderer,s=this._blurPlane,r=this._renderTarget,n=this._blurTarget,a=this._horizontalBlurMaterial,o=this._verticalBlurMaterial;s.visible=!0,a.uniforms.tDiffuse.value=r.texture,a.uniforms.h.value=+e/256,a.needsUpdate=!0,s.material=a,t.setRenderTarget(n),t.render(s,i),o.uniforms.tDiffuse.value=n.texture,o.uniforms.v.value=+e/256,o.needsUpdate=!0,s.material=o,t.setRenderTarget(r),t.render(s,i),s.visible=!1}_setupPlanes(){var e=this._root,t=new P.PlaneBufferGeometry,i=new P.MeshBasicMaterial({opacity:this._darkness,transparent:!0,side:P.BackSide,depthWrite:!1,map:this._renderTarget.texture}),i=new P.Mesh(t,i),e=(i.renderOrder=1,i.scale.set(-1,-1,1),i.rotation.order="YXZ",i.rotation.x=Math.PI/2,this._plane=i,e.add(i),new P.Mesh(t)),i=(this._blurPlane=e,new P.MeshDepthMaterial),t=(i.onBeforeCompile=e=>{e.fragmentShader=`
`+e.fragmentShader.replace("gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );","gl_FragColor = vec4( vec3( 0.0 ), ( 1.0 - fragCoordZ ) * opacity );")},this._depthMaterial=i,new P.ShaderMaterial(Fe)),e=(t.depthTest=!1,this._horizontalBlurMaterial=t,new P.ShaderMaterial(Ue));e.depthTest=!1,this._verticalBlurMaterial=e}}class ke{static fromCubeTexture(e){for(var t=0,i=new P.Vector3,s=new P.Vector3,r=new P.Color,n=[0,0,0,0,0,0,0,0,0],a=new P.SphericalHarmonics3,o=a.coefficients,h=0;h<6;h++)for(var l=e.image[h],c=l.width,d=l.height,u=document.createElement("canvas"),u=(u.width=c,u.height=d,u.getContext("2d")),l=(u.drawImage(l,0,0,c,d),u.getImageData(0,0,c,d)),_=l.data,p=l.width,m=2/p,v=0,g=_.length;v<g;v+=4){r.setRGB(_[v]/255,_[v+1]/255,_[v+2]/255),He(r,e.encoding);var f=v/4,E=(f%p+.5)*m-1,T=1-(Math.floor(f/p)+.5)*m;switch(h){case 0:i.set(-1,T,-E);break;case 1:i.set(1,T,E);break;case 2:i.set(-E,1,-T);break;case 3:i.set(-E,-1,T);break;case 4:i.set(-E,T,1);break;case 5:i.set(E,T,-1)}var f=i.lengthSq(),w=4/(Math.sqrt(f)*f);t+=w,s.copy(i).normalize(),P.SphericalHarmonics3.getBasisAt(s,n);for(var b=0;b<9;b++)o[b].x+=n[b]*r.r*w,o[b].y+=n[b]*r.g*w,o[b].z+=n[b]*r.b*w}for(var x=4*Math.PI/t,S=0;S<9;S++)o[S].x*=x,o[S].y*=x,o[S].z*=x;return new P.LightProbe(a)}static fromCubeRenderTarget(e,t){for(var i=0,s=new P.Vector3,r=new P.Vector3,n=new P.Color,a=[0,0,0,0,0,0,0,0,0],o=new P.SphericalHarmonics3,h=o.coefficients,l=0;l<6;l++)for(var c=t.width,d=new Uint8Array(c*c*4),u=(e.readRenderTargetPixels(t,0,0,c,c,d,l),2/c),_=0,p=d.length;_<p;_+=4){n.setRGB(d[_]/255,d[_+1]/255,d[_+2]/255),He(n,t.texture.encoding);var m=_/4,v=(m%c+.5)*u-1,g=1-(Math.floor(m/c)+.5)*u;switch(l){case 0:s.set(1,g,-v);break;case 1:s.set(-1,g,v);break;case 2:s.set(v,1,-g);break;case 3:s.set(v,-1,g);break;case 4:s.set(v,g,1);break;case 5:s.set(-v,g,-1)}var m=s.lengthSq(),f=4/(Math.sqrt(m)*m);i+=f,r.copy(s).normalize(),P.SphericalHarmonics3.getBasisAt(r,a);for(var E=0;E<9;E++)h[E].x+=a[E]*n.r*f,h[E].y+=a[E]*n.g*f,h[E].z+=a[E]*n.b*f}for(var T=4*Math.PI/i,w=0;w<9;w++)h[w].x*=T,h[w].y*=T,h[w].z*=T;return new P.LightProbe(o)}}function He(e,t){switch(t){case P.sRGBEncoding:e.convertSRGBToLinear();break;case P.LinearEncoding:break;default:console.warn("WARNING: LightProbeGenerator convertColorToLinear() encountered an unsupported encoding.")}}class b{static createDefaultEnv(e){var t=new P.Scene,i=new P.PointLight(16777215,.8,20),i=(i.decay=2,i.position.set(0,7,0),t.add(i),new P.BoxBufferGeometry(1,1,1)),s=new P.MeshStandardMaterial({side:P.BackSide}),i=new P.Mesh(i,s),s=(i.castShadow=!1,i.scale.set(15,45,15),i.position.set(0,20,0),t.add(i),b._createRectAreaLightSource({intensity:4.5,width:4,height:4})),i=(s.position.set(0,2.5,0),s.rotateX(Math.PI/2),b._createRectAreaLightSource({intensity:3,width:2,height:2})),r=(i.position.set(0,1,4),i.lookAt(0,0,0),b._createRectAreaLightSource({intensity:3,width:2,height:2})),n=(r.position.set(-4,1,1),r.lookAt(0,0,0),b._createRectAreaLightSource({intensity:3,width:2,height:2})),a=(n.position.set(4,1,1),n.lookAt(0,0,0),b._createRectAreaLightSource({intensity:2.5,width:2,height:2})),o=(a.position.set(1.5,1,-4),a.lookAt(0,0,0),b._createRectAreaLightSource({intensity:2.5,width:2,height:2})),s=(o.position.set(-1.5,1,-4),o.lookAt(0,0,0),t.add(s,i,r,n,a,o),e.outputEncoding),i=e.toneMapping,r=(e.outputEncoding=P.LinearEncoding,e.toneMapping=P.NoToneMapping,new P.PMREMGenerator(e).fromScene(t,.035));return e.outputEncoding=s,e.toneMapping=i,r.texture}static createBlurredHDR(e,t){var e=e.renderer.threeRenderer,i=new P.Scene,t=(i.background=t,e.toneMappingExposure),s=(e.toneMappingExposure=1,new P.WebGLCubeRenderTarget(256,{encoding:P.sRGBEncoding,format:P.RGBAFormat})),r=new P.CubeCamera(.1,1e3,s),i=(r.update(e,i),ke.fromCubeRenderTarget(e,s)),n=new P.MeshStandardMaterial({side:P.BackSide}),a=new P.IcosahedronBufferGeometry(1,4),o=new P.Scene,n=new P.Mesh(a,n),h=a.getAttribute("normal");for(let e=0;e<h.count;e++)h.setXYZ(e,-h.getX(e),-h.getY(e),-h.getZ(e));return o.add(n),o.add(i),r.update(e,o),e.toneMappingExposure=t,s.texture}static _createRectAreaLightSource({intensity:e,width:t,height:i}){t=new P.PlaneBufferGeometry(t,i),i=new P.MeshBasicMaterial;return i.color.setScalar(e),new P.Mesh(t,i)}}class Ve{constructor(e){this._view3D=e,this._root=new P.Scene,this._userObjects=new P.Group,this._envObjects=new P.Group,this._fixedObjects=new P.Group,this._shadowPlane=new Be(e,Z(e.shadow));var t=this._root,i=this._userObjects,s=this._envObjects,r=this._fixedObjects,n=this._shadowPlane;i.name="userObjects",s.name="envObjects",r.name="fixedObjects",t.add(i,s,r),e.shadow&&r.add(n.root)}get root(){return this._root}get shadowPlane(){return this._shadowPlane}get userObjects(){return this._userObjects}get envObjects(){return this._envObjects}get fixedObjects(){return this._fixedObjects}reset({volatileOnly:e=!0}={}){this._removeChildsOf(this._userObjects),e||this._removeChildsOf(this._envObjects)}add(e,t=!0){t=t?this._userObjects:this._envObjects,e=Array.isArray(e)?e:[e];t.add(...e)}remove(e){e=Array.isArray(e)?e:[e];this._userObjects.remove(...e),this._envObjects.remove(...e)}setBackground(s){return Q(this,void 0,void 0,function*(){var e,t=this._view3D,i=this._root;"number"==typeof s||"#"===s.charAt(0)?i.background=new P.Color(s):((e=yield new Ce(t).load(s)).encoding=P.sRGBEncoding,i.background=e),t.renderer.renderSingleFrame()})}setSkybox(s){return Q(this,void 0,void 0,function*(){var e,t=this._root,i=this._view3D;t.background&&t.background.isTexture&&t.background.dispose(),s?(e=yield new Ce(i).loadHDRTexture(s),i.skyboxBlur?t.background=b.createBlurredHDR(i,e):t.background=e,t.environment=e):(t.background=null,t.environment=null),i.renderer.renderSingleFrame()})}setEnvMap(s){return Q(this,void 0,void 0,function*(){var e,t=this._view3D,i=this._root;s?(e=yield new Ce(t).loadHDRTexture(s),i.environment=e):i.environment=null,t.renderer.renderSingleFrame()})}initTextures(){var{skybox:e,envmap:t,background:i,useDefaultEnv:s}=this._view3D,r=[],s=(s&&this.setDefaultEnv(),e||t);return s&&(s=e?this.setSkybox(e):this.setEnvMap(t),r.push(s)),!e&&i&&r.push(this.setBackground(i)),r}setDefaultEnv(){var e=this._view3D.renderer,e=b.createDefaultEnv(e.threeRenderer);this._root.environment=e}_removeChildsOf(e){for(e.traverse(e=>{e.isMesh&&((e=e).geometry.dispose(),(Array.isArray(e.material)?e.material:[e.material]).forEach(t=>{Me.forEach(e=>{t[e]&&t[e].dispose()})}))});0<e.children.length;)e.remove(e.children[0])}}const x=be.EASE_OUT_CUBIC,Ge={min:0,max:1},ze={min:-1/0,max:1/0},We={min:-89.9,max:89.9},je={165:0,135:.4,0:1},Ke=[e.WEBXR,e.SCENE_VIEWER,e.QUICK_LOOK];class S{constructor({duration:e=300,loop:t=!1,range:i=Ge,easing:s=x}={}){this._duration=e,this._loop=t,this._range=i,this._easing=s,this._activated=!1,this.reset(0)}get val(){return this._val}get start(){return this._start}get end(){return this._end}get progress(){return this._progress}get duration(){return this._duration}get loop(){return this._loop}get range(){return this._range}get easing(){return this._easing}get activated(){return this._activated}set duration(e){this._duration=e}set loop(e){this._loop=e}set range(e){this._range=e}set easing(e){this._easing=e}update(e){var t,i,s,r,n;return this._activated?(t=this._start,i=this._end,n=this._duration,s=this._val,r=this._loop,e=this._progress+e/n,this._progress=(r?u:d)(e,0,1),n=this._easing(this._progress),this._val=H(t,i,n),!r&&1<=this._progress&&(this._activated=!1),this._val-s):0}reset(e){var t=this._range,e=d(e,t.min,t.max);this._start=e,this._end=e,this._val=e,this._progress=0,this._activated=!1}setEndDelta(e){var t=this._range;this._start=this._val,this._end=d(this._end+e,t.min,t.max),this._progress=0,this._activated=!0}}class Xe{constructor(e,t,i,{duration:s=300,easing:r=x,disableOnFinish:n=!0}={}){this._enabled=!1,this._finishCallbacks=[],this._view3D=e,this._motion=new S({duration:s,range:Ge,easing:r}),this._disableOnFinish=n,this.changeStartEnd(t,i)}get element(){return null}get enabled(){return this._enabled}get duration(){return this._motion.duration}get easing(){return this._motion.easing}get animating(){return this._motion.activated}set duration(e){this._motion.duration=e}set easing(e){this._motion.easing=e}destroy(){this.disable()}changeStartEnd(e,t){e=e.clone(),t=t.clone(),e.yaw=u(e.yaw,0,360),t.yaw=u(t.yaw,0,360),180<Math.abs(t.yaw-e.yaw)&&(t.yaw=t.yaw<e.yaw?t.yaw+360:t.yaw-360),this._from=e,this._to=t}update(e){var t,i,s,r;this._enabled&&(t=this._view3D.camera,i=this._from,s=this._to,(r=this._motion).update(e),e=r.val,t.yaw=H(i.yaw,s.yaw,e),t.pitch=H(i.pitch,s.pitch,e),t.zoom=H(i.zoom,s.zoom,e),t.pivot=i.pivot.clone().lerp(s.pivot,e),1<=e)&&(this._disableOnFinish&&this.disable(),this._finishCallbacks.forEach(e=>e()),this.clearFinished())}enable(){this._enabled||(this._enabled=!0,this.reset())}disable(){this._enabled&&(this._enabled=!1)}reset(){this._motion.reset(0),this._motion.setEndDelta(1)}onFinished(e){this._finishCallbacks.push(e)}clearFinished(){this._finishCallbacks=[]}resize(e){}sync(){}}class y{constructor(e,t,i,s=[0,0,0]){this.yaw=e,this.pitch=t,this.zoom=i,this.pivot=(new P.Vector3).fromArray(s)}clone(){return new y(this.yaw,this.pitch,this.zoom,this.pivot.toArray())}copy(e){this.yaw=e.yaw,this.pitch=e.pitch,this.zoom=e.zoom,this.pivot.copy(e.pivot)}equals(e){var{yaw:t,pitch:i,zoom:s,pivot:r}=this;return u(t,0,360)===u(e.yaw,0,360)&&i===e.pitch&&s===e.zoom&&r.equals(e.pivot)}}class qe{constructor(e){this._view3D=e,this._threeCamera=new P.PerspectiveCamera,this._maxTanHalfHFov=0,this._baseFov=45,this._baseDistance=0;var t=I(e.initialZoom)?e.initialZoom:0;this._defaultPose=new y(e.yaw,e.pitch,t),this._currentPose=this._defaultPose.clone(),this._newPose=this._currentPose.clone()}get threeCamera(){return this._threeCamera}get defaultPose(){return this._defaultPose}get currentPose(){return this._currentPose.clone()}get newPose(){return this._newPose}get yaw(){return this._currentPose.yaw}get pitch(){return this._currentPose.pitch}get zoom(){return this._currentPose.zoom}get distance(){return this._view3D.control.zoom.type===Se.FOV?this._baseDistance:this._baseDistance-this._currentPose.zoom}get baseDistance(){return this._baseDistance}get baseFov(){return this._baseFov}get pivot(){return this._currentPose.pivot}get fov(){return this._threeCamera.fov}get renderWidth(){return this.renderHeight*this._threeCamera.aspect}get renderHeight(){return 2*this.distance*Math.tan(_(this._threeCamera.getEffectiveFOV()/2))}set yaw(e){this._newPose.yaw=e}set pitch(e){this._newPose.pitch=e}set zoom(e){this._newPose.zoom=e}set pivot(e){this._newPose.pivot.copy(e)}set baseFov(e){this._baseFov=e}reset(e=0,t=x,i){var s=this._view3D;const r=s.control,n=s.autoPlayer,a=this._newPose,o=this._currentPose,h=null!=i?i:this._defaultPose;if(e<=0)return a.copy(h),o.copy(h),s.renderer.renderSingleFrame(),r.sync(),Promise.resolve();{const l=n.enabled,c=new Xe(s,o,h);return c.duration=e,c.easing=t,c.enable(),l&&n.disable(),r.add(c),new Promise(e=>{c.onFinished(()=>{a.copy(h),o.copy(h),r.remove(c),r.sync(),l&&n.enableAfterDelay(),e()})})}}resize({width:e,height:t},i=null){var{control:s,fov:r,maintainSize:n}=this._view3D;this._threeCamera.aspect=e/t,r===$?n&&null!=i?(e=t/i.height,n=this._currentPose.zoom,t=Math.tan(_((this._baseFov-n)/2)),this._baseFov=p(2*Math.atan(e*t))+n):this._applyEffectiveFov(45):this._baseFov=r,s.zoom.updateRange()}fit(e){var t=this._view3D,i=this._threeCamera,s=this._defaultPose,r=t.control,n=t.pivot,a=e.bbox,o=t.fov,h=o===$?45:o;const l=e.center;var c=t.ignoreCenterOnFit||t.center===$?(new P.Vector3).subVectors(a.max,a.min).lengthSq()/4:e.reduceVertices((e,t)=>Math.max(e,t.distanceToSquared(l)),0),c=Math.sqrt(c);const d=c/Math.sin(_(h/2));var u=e.reduceVertices((e,t)=>{var t=(new P.Vector3).subVectors(t,l),i=Math.hypot(t.x,t.z);return Math.max(e,i/(d-Math.abs(t.y)))},0);o===$?(this._maxTanHalfHFov=u,this._applyEffectiveFov(h)):this._maxTanHalfHFov=o,s.pivot=n===$?l.clone():ae(n,a),this._baseDistance=d,i.near=.1*(d-c),i.far=10*(d+c),r.zoom.updateRange(),I(t.initialZoom)?s.zoom=t.initialZoom:(u=this._baseFov,h=e.bbox,o=t.initialZoom.axis,n=t.initialZoom.ratio,c=(a=(new P.Vector3).subVectors(h.max,h.min))[o],r="y"===o?c/n:c/(n*i.aspect),e="z"!==o?d-a.z/2:d-a.x/2,t=p(2*Math.atan(r/(2*e))),s.zoom=u-t)}updatePosition(){var e=this._view3D,t=e.control,i=this._threeCamera,s=this._currentPose,r=this._newPose,n=this._baseFov,a=this._baseDistance,t=t.zoom.type===Se.FOV,o=s.clone(),n=(s.yaw=u(r.yaw,0,360),s.pitch=d(r.pitch,We.min,We.max),s.zoom=r.zoom,s.pivot.copy(r.pivot),t?n-s.zoom:n),t=t?a:a-s.zoom,a=j(t,s.yaw,s.pitch);a.add(s.pivot),i.fov=n,i.position.copy(a),i.lookAt(s.pivot),i.updateProjectionMatrix(),r.copy(s),e.trigger(E.CAMERA_CHANGE,{type:E.CAMERA_CHANGE,target:e,pose:s.clone(),prevPose:o})}_applyEffectiveFov(e){var t=this._threeCamera,e=Math.tan(_(e/2)),e=e*Math.max(1,this._maxTanHalfHFov/e/t.aspect);this._baseFov=p(2*Math.atan(e))}_parseBboxRatioOption(e,t){const s=t.min.toArray(),r=(new P.Vector3).subVectors(t.max,t.min).toArray();return e.map((e,t)=>{var i;return n(e)?(i=.01*parseFloat(e),s[t]+i*r[t]):e})}}class Ye{constructor(e){this._onResize=()=>{this._view3d.resize()},this._skipFirstResize=(()=>{let e=!0;return()=>{e?e=!1:this._onResize()}})(),this._view3d=e,this._enabled=!1,this._resizeObserver=null}get enabled(){return this._enabled}enable(){var e,t,i=this._view3d;return this._enabled&&this.disable(),i.useResizeObserver&&window.ResizeObserver?(t=0!==(t=(e=i.renderer.canvas).getBoundingClientRect()).width||0!==t.height,(t=new ResizeObserver(t?this._skipFirstResize:this._onResize)).observe(e),this._resizeObserver=t):(i.resize(),window.addEventListener(m.RESIZE,this._onResize)),this._enabled=!0,this}disable(){var e;return this._enabled&&((e=this._resizeObserver)?(e.disconnect(),this._resizeObserver=null):window.removeEventListener(m.RESIZE,this._onResize),this._enabled=!1),this}}class Ze{constructor(e){this._onAnimationLoop=t=>{var e=this._view3D,i=this._actions,s=this._clips,i=i.findIndex(e=>e===t.action);e.trigger(E.ANIMATION_LOOP,{type:E.ANIMATION_LOOP,target:e,index:i,action:t.action,clip:s[i]}),e.animationRepeatMode===Re.ALL&&(e=i+1>=s.length?0:i+1,this.play(e))},this._onAnimationFinished=t=>{var e=this._view3D,i=this._actions,s=this._clips,i=i.findIndex(e=>e===t.action);e.trigger(E.ANIMATION_FINISHED,{type:E.ANIMATION_FINISHED,target:e,index:i,action:t.action,clip:s[i]})},this._view3D=e,this._mixer=new P.AnimationMixer(e.scene.userObjects),this._clips=[],this._actions=[],this._activeAnimationIdx=-1,this._timeScale=1,this._fadePromises=[]}get clips(){return this._clips}get mixer(){return this._mixer}get actions(){return this._actions}get animationCount(){return this._clips.length}get activeAnimation(){var e;return null!=(e=this._clips[this._activeAnimationIdx])?e:null}get activeAction(){var e;return null!=(e=this._actions[this._activeAnimationIdx])?e:null}get activeAnimationIndex(){return this._activeAnimationIdx}get paused(){return 0===this._mixer.timeScale}get animating(){var e;return(null==(e=this.activeAction)?void 0:e.isRunning())&&!this.paused}get timeScale(){return this._timeScale}set timeScale(e){this._timeScale=e}init(){this._mixer.addEventListener("loop",this._onAnimationLoop),this._mixer.addEventListener("finished",this._onAnimationFinished)}destroy(){this.reset(),this._mixer.removeEventListener("loop",this._onAnimationLoop),this._mixer.removeEventListener("finished",this._onAnimationFinished)}setClips(e){const t=this._mixer;this._clips=e,this._actions=e.map(e=>{e=t.clipAction(e);return e.setEffectiveWeight(0),e}),this.updateRepeatMode()}play(e){var t=this._view3D,i=this._actions[e];i&&(this.stop(),this._restoreTimeScale(),i.setEffectiveTimeScale(1),i.setEffectiveWeight(1),i.play(),this._activeAnimationIdx=e,this._flushFadePromises(),t.trigger(E.ANIMATION_START,{type:E.ANIMATION_START,target:t,index:e,action:i,clip:this._clips[e]}))}crossFade(l,c,{synchronize:d=!1}={}){var u;return Q(this,void 0,void 0,function*(){const i=this._view3D,t=this._mixer;var e=this._actions,s=this._activeAnimationIdx;const r=e[l],n=null!=(u=e[s])?u:r,a="loop",o=(this._restoreTimeScale(),()=>{r.enabled=!0,r.setEffectiveTimeScale(1),r.setEffectiveWeight(1),r.time=0,r.play(),n.crossFadeTo(r,c/1e3,!0),this._activeAnimationIdx=l});if(d){const h=e=>{e.action===n&&(t.removeEventListener(a,h),o())};t.addEventListener(a,h)}else o();return this._flushFadePromises(),new Promise(e=>{const t=()=>{r.getEffectiveWeight()<1||(i.off(E.BEFORE_RENDER,t),e(!0))};i.on(E.BEFORE_RENDER,t),this._fadePromises.push({listener:t,resolve:e})})})}fadeOut(e){return Q(this,void 0,void 0,function*(){const i=this._view3D;const s=this._actions[this._activeAnimationIdx];return!!s&&(this._flushFadePromises(),this._restoreTimeScale(),s.fadeOut(e/1e3),new Promise(e=>{const t=()=>{0<s.getEffectiveWeight()||(i.off(E.BEFORE_RENDER,t),this._activeAnimationIdx=-1,e(!0))};i.on(E.BEFORE_RENDER,t),this._fadePromises.push({listener:t,resolve:e})}))})}pause(){this._mixer.timeScale=0}resume(){this._restoreTimeScale()}stop(){this._actions.forEach(e=>{e.stop(),e.setEffectiveWeight(0)}),this._view3D.renderer.renderSingleFrame(),this._activeAnimationIdx=-1,this._flushFadePromises()}update(e){this._mixer.update(e)}updateRepeatMode(){var e=this._view3D,t=this._actions;e.animationRepeatMode===Re.NONE?t.forEach(e=>{e.clampWhenFinished=!0,e.loop=P.LoopOnce}):t.forEach(e=>{e.clampWhenFinished=!1,e.loop=P.LoopRepeat})}reset(){var e=this._mixer;this.stop(),e.uncacheRoot(e.getRoot()),this._clips=[],this._actions=[]}_restoreTimeScale(){this._mixer.timeScale=this._timeScale}_flushFadePromises(){const i=this._view3D;this._fadePromises.forEach(({resolve:e,listener:t})=>{e(!1),i.off(E.BEFORE_RENDER,t)}),this._fadePromises=[]}}class Qe extends D{constructor({context:e=window,repeat:t=0,duration:i=300,easing:s=x}={}){super(),this._loop=()=>{var e=this._getDeltaTime(),t=this._duration,i=this._repeat,e=this._time+e,s=Math.floor(e/t),e=(this._time=(this._loopCount>=i?d:u)(e,0,t),this._time/t),r={progress:e,easedProgress:this._easing(e)};this.trigger("progress",r);for(let e=0;e<s;e++){if(this._loopCount++,this._loopCount>i)return this.trigger("finish"),void this.stop();this.trigger("loop",Object.assign(Object.assign({},r),{loopIndex:this._loopCount}))}this._rafId=this._ctx.requestAnimationFrame(this._loop)},this._repeat=t,this._duration=i,this._easing=s,this._ctx=e,this._rafId=-1,this._time=0,this._clock=0,this._loopCount=0}start(){0<=this._rafId||(this._updateClock(),this._loop())}stop(){this._rafId<0||(this._time=0,this._loopCount=0,this._stopLoop())}pause(){this._rafId<0||this._stopLoop()}_stopLoop(){this._ctx.cancelAnimationFrame(this._rafId),this._rafId=-1}_getDeltaTime(){var e=this._clock;return this._updateClock(),this._clock-e}_updateClock(){this._clock=Date.now()}}const $e={AR:"immersive-ar",VR:"immersive-vr"},Je={LOCAL:"local",LOCAL_FLOOR:"local-floor",VIEWER:"viewer"},R={SELECT_START:"selectstart",SELECT:"select",SELECT_END:"selectend",ESTIMATION_START:"estimationstart",ESTIMATION_END:"estimationend"},et={TOUCH:"generic-touchscreen"},tt={HIT_TEST:{requiredFeatures:["hit-test"]},DOM_OVERLAY:e=>e?{requiredFeatures:["dom-overlay"],domOverlay:{root:e}}:{},LIGHT_ESTIMATION:{optionalFeatures:["light-estimation"]}},it={},st={INTENT_AR_CORE:(e,t)=>`intent://arvr.google.com/scene-viewer/1.2?${e}#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;${t?`S.browser_fallback_url=${t};`:""}end;`,INTENT_SEARCHBOX:(e,t)=>`intent://arvr.google.com/scene-viewer/1.2?${e}#Intent;scheme=https;package=com.google.android.googlequicksearchbox;action=android.intent.action.VIEW;${t?`S.browser_fallback_url=${t};`:""}end;`,FALLBACK_DEFAULT:e=>"https://arvr.google.com/scene-viewer?"+e};class rt{constructor({scale:e=1}={}){this.rotation=new P.Quaternion,this._axis=new P.Vector3(0,1,0),this._enabled=!1,this._