shop-components 0.4.16 → 0.4.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/shop-components.cjs
CHANGED
|
@@ -3935,9 +3935,9 @@ vec3 texelOld = texture2D(previousShadowMap, vUv).rgb;
|
|
|
3935
3935
|
// Combine
|
|
3936
3936
|
gl_FragColor = vec4(uColor, alpha * fade * uOpacity);
|
|
3937
3937
|
}
|
|
3938
|
-
`});super(s,a),this.position.z=-.02}}const vc="https://cdn2.seer-group.com/libs/hdr/aristea_wreck_512.hdr",_c="https://cdn2.seer-group.com/libs/hdr/lightroom_14b_512.hdr",yc="https://cdn2.seer-group.com/libs/fonts.type.json",xc=new ln.Font(yc);class ss{constructor(e){var i;this._props=e,this.name="",this._defaults={color:"",metalness:0,roughness:0,envMapIntensity:1},this.color="",this.metalness=0,this.roughness=0,this.envMapIntensity=1,this.name=this._props.name;const t=this.material;t&&(this.color=this._defaults.color="#"+((i=t.color)==null?void 0:i.getHexString()),this.metalness=this._defaults.metalness=t.metalness??0,this.roughness=this._defaults.roughness=t.roughness??1,this.envMapIntensity=this._defaults.envMapIntensity=t.envMapIntensity??1)}get material(){if(this._props.target instanceof f.MeshStandardMaterial)return this._props.target;if(this._props.target instanceof f.Mesh){if(Array.isArray(this._props.target.material))return this._props.target.material.find(e=>e instanceof f.MeshStandardMaterial);if(this._props.target.material instanceof f.MeshStandardMaterial)return this._props.target.material}}change(e){var i;this.color=e;const t=this.material;(i=t==null?void 0:t.color)==null||i.set(e)}reset(){this.change(this._defaults.color);const e=this.material;e&&(e.metalness=this._defaults.metalness,e.roughness=this._defaults.roughness,e.envMapIntensity=this._defaults.envMapIntensity,e.needsUpdate=!0)}}var Zr=(o=>(o[o.DEFAULT=0]="DEFAULT",o[o.CAN_INSTALL=1]="CAN_INSTALL",o))(Zr||{});const fr=.15;f.Object3D.DEFAULT_UP.set(0,0,1);let nt,li=0,rs=0;const wc=()=>{nt=void 0,li=0,rs=0},bc=new f.MeshBasicMaterial({colorWrite:!1});class Ac{constructor(e){this.props=e,this.stats=new Lt,this.scene=new f.Scene,this.overlayScene=new f.Scene,this.renderer=new f.WebGLRenderer({antialias:!0,alpha:!0,logarithmicDepthBuffer:!0,powerPreference:"high-performance",preserveDrawingBuffer:!0}),this.css2dRenderer=new me.CSS2DRenderer,this.mousePos=new f.Vector2,this.mouseCoord=new f.Vector2,this.offset=new f.Vector2,this.size=new f.Vector2,this.amr=new Hr({showSizeBox:!0,showController:!0}),this._selectedForOutline=[],this._clock=new f.Clock(!0),this._uiHiddenTime=this._clock.getElapsedTime(),this.camera=new f.PerspectiveCamera(39.6,window.innerWidth/window.innerHeight,.1,1e4),this.d=2,this.orthographicCamera=new f.OrthographicCamera(-this.d*(window.innerWidth/window.innerHeight),this.d*(window.innerWidth/window.innerHeight),this.d,-this.d,.1,1e3),this._axisMoving=!1,this._container=new f.Group,this._raycaster=new f.Raycaster,this._selected=[],this._pointerDownTimeout=0,this._dragging=!1,this.maxSample=1024*2,this.sampleCount=0,this._usePathTracing=!1,this._fpsCache=[],this._fpsCacheMax=20,this._emitter=new pt,this.sound=new ka,this._rafId=null,this._destroyed=!1,this._ground=new f.Mesh(new f.PlaneGeometry(100,100),new f.MeshPhysicalMaterial({color:new f.Color("#eee"),metalness:.4,roughness:.1,clearcoat:1,clearcoatRoughness:.1})),this._sciFiGrid=new gc(18,40),this._amrRender=new f.WebGLRenderTarget(1024,1024,{format:f.RGBAFormat,type:f.UnsignedByteType,colorSpace:f.SRGBColorSpace,samples:8}),this._lastTarget=new f.Vector3,this._shadowMode=!1,this.addEventListener=this._emitter.on.bind(this._emitter),this.removeEventListener=this._emitter.on.bind(this._emitter),this._showSlots=!0,this._showSize=!0,this._showControls=!0,this._drag=c=>{this._dragging=!0,this._pointermove(c)},this._dragend=c=>{this._dragging=!1},this._pointermove=c=>{if(this._pointerDownTimeout)return clearTimeout(this._pointerDownTimeout),this._pointerDownTimeout=0;let{top:h,left:d}=this.renderer.domElement.getBoundingClientRect();this.offset.set(d,h),this.mousePos.set(c.clientX-d,c.clientY-h),this.mouseCoord.set((c.clientX-d)/this.size.x*2-1,-((c.clientY-h)/this.size.y)*2+1),this._raycaster.setFromCamera(this.mouseCoord,this.camera)},this._pointerdown=c=>{const h=()=>{this.amr.slots.forEach(r=>r.selected=!1);const p=this._raycaster.intersectObjects(this.amr.slots,!1)[0];p&&this.amr.slots.forEach(r=>{r.traverse(l=>{l==p.object||(r.deviceSelected=!1)})}),this._pointerDownTimeout=0};this._pointerDownTimeout=window.setTimeout(h,200)},this._detectTrackpad=()=>{nt||typeof nt<"u"||(li===0&&(rs=performance.now()),li++,performance.now()-rs>66&&(li>5?nt=!0:nt=!1,nt?this.controls.zoomSpeed=.2:this.controls.zoomSpeed=1,setTimeout(wc,2e3)))},this.debounceForkHeightChange=Ua(()=>{var c;this._progressShadow.clear(),(c=this._progressShadow)==null||c.recalculate()},300),this.focusObjects=(c,h)=>{var j;if(!c.length){this.fit();return}this.scene.updateMatrixWorld(!0),this._focusRestoreView=void 0,(j=this._fitAnimation)==null||j.stop();const d=new f.Box3,p=new f.Box3,r=new f.Vector3,l=new f.Vector3,u=new f.Vector3,g=new f.Vector3,y=U=>{U.geometry&&(U.geometry.boundingBox||U.geometry.computeBoundingBox(),p.copy(U.geometry.boundingBox).applyMatrix4(U.matrixWorld),p.isEmpty()||d.union(p))},m=U=>{var vs,_s;const Q=U.geometry,re=(vs=Q==null?void 0:Q.attributes)==null?void 0:vs.position;if(!re){y(U);return}const te=((_s=Q.morphAttributes)==null?void 0:_s.position)||[],gs=U.morphTargetInfluences||[],Xr=te.length>0&&gs.length>0;for(let Ae=0;Ae<re.count;Ae++){if(r.set(re.getX(Ae),re.getY(Ae),re.getZ(Ae)),Xr){l.set(0,0,0);let gi=0;for(let Ne=0;Ne<te.length;Ne++){const kt=gs[Ne]||0;kt&&(gi+=kt,u.set(te[Ne].getX(Ae),te[Ne].getY(Ae),te[Ne].getZ(Ae)),Q.morphTargetsRelative,l.addScaledVector(u,kt))}Q.morphTargetsRelative?r.add(l):gi>0&&(r.multiplyScalar(1-gi),r.add(l))}g.copy(r).applyMatrix4(U.matrixWorld),d.expandByPoint(g)}};if(c.forEach(U=>{U.traverse(Q=>{if(Q.visible){if(Q instanceof f.Mesh){m(Q);return}(Q.isPoint||Q.isLine)&&y(Q)}})}),d.isEmpty())return;const v=new f.Vector3;d.getCenter(v);const _=new f.Vector3;d.getSize(_);const x=v.clone();this._lastTarget.copy(x);let w;h?w=h.clone().normalize().negate():w=this.camera.position.clone().sub(this.controls.target).normalize();const b=_.clone().multiplyScalar(.5),T=[new f.Vector3(b.x,b.y,b.z),new f.Vector3(b.x,b.y,-b.z),new f.Vector3(b.x,-b.y,b.z),new f.Vector3(b.x,-b.y,-b.z),new f.Vector3(-b.x,b.y,b.z),new f.Vector3(-b.x,b.y,-b.z),new f.Vector3(-b.x,-b.y,b.z),new f.Vector3(-b.x,-b.y,-b.z)],S=new f.Vector3(0,1,0);Math.abs(w.dot(S))>.99&&S.set(0,0,1);const I=new f.Vector3().crossVectors(w,S).normalize(),C=new f.Vector3().crossVectors(I,w).normalize();let L=0;T.forEach(U=>{const Q=U.dot(I),re=U.dot(C),te=Math.sqrt(Q*Q+re*re);L=Math.max(L,te)}),L=L/2+.4;const R=this.camera.fov*Math.PI/180,A=2*Math.atan(Math.tan(R/2)*this.camera.aspect),M=L/Math.tan(A/2),D=L/Math.tan(R/2),P=Math.max(M,D),E=v.clone().add(w.multiplyScalar(P)),B=this.camera.position.clone(),V=this.controls.target.clone();let N=500;const W=B.distanceTo(E)+V.distanceTo(x);W>.001&&(N=Math.min(1e3,Math.max(450,W*45))),this._animateCamera(B,E,V,x,N)},this.focusSlots=c=>{var C,L;if(this.amr.slots.forEach(R=>{R.focused=!1,R.hide()}),!c.length)if(this._lastTarget.set(0,0,this._lastTarget.z),this.amr.slots.forEach(R=>{R.show()}),this.shadowMode=!1,this._focusRestoreView){const R=this._focusRestoreView;this._focusRestoreView=void 0;const A=this.camera.position.clone(),M=this.controls.target.clone(),D=R.position.clone(),P=R.target.clone();let E=500;const B=A.distanceTo(D)+M.distanceTo(P);B>.001&&(E=Math.min(1e3,Math.max(450,B*45))),this._animateCamera(A,D,M,P,E,()=>{this.camera.up.copy(R.up)});return}else{this.fit();return}(C=this._fitAnimation)!=null&&C.isPlaying()||this.shadowMode||(this._focusRestoreView={position:this.camera.position.clone(),target:new f.Vector3(0,0,this.controls.target.z),up:this.camera.up.clone()}),(L=this._fitAnimation)==null||L.stop(),this.shadowMode=!0;const h=c.flatMap(R=>{if(R.show(),R.focused=!0,!R.parent)return[];const A=new f.Vector3;return R.parent.getWorldPosition(A),[A]});if(!h.length)return;const d=h.reduce((R,A)=>R.add(A),new f.Vector3).multiplyScalar(1/h.length),p=this.controls.target.clone(),r=this.camera.position.clone().sub(p).normalize();let l=0;for(const R of h){const A=R.clone().sub(d),M=A.dot(r),D=Math.sqrt(Math.max(0,A.lengthSq()-M*M));D>l&&(l=D)}l=l+.4;const u=this.camera.fov*Math.PI/180,g=2*Math.atan(Math.tan(u/2)*this.camera.aspect),y=l/Math.tan(g/2),m=l/Math.tan(u/2),v=Math.max(y,m),_=d.clone(),x=d.clone().add(r.clone().multiplyScalar(v<1?1:v)),w=this.camera.position.clone(),b=p.clone(),T={t:0};let S=500;const I=w.distanceTo(x)+b.distanceTo(_);I>.001&&(S=Math.min(1e3,Math.max(450,I*45))),this._lastTarget=_.clone(),this._fitAnimation=new ci(T).to({t:1},S).easing(Le.Easing.Quadratic.InOut).onStart(()=>{this.controls.enabled=!1}).onUpdate(()=>{const R=T.t;this.camera.position.lerpVectors(w,x,R),this.controls.target.lerpVectors(b,_,R)}).onComplete(()=>{this.controls.enabled=!0}).start()},this.fit=()=>{this._focusRestoreView=void 0,new f.Box3().setFromObject(this._container);const h=this.amr.sizeBox.size.getSize(new f.Vector3),d=h.clone().multiplyScalar(.5),p=new f.Vector3(0,0,d.z);this._lastTarget.copy(p);let r=d.clone().sub(p);r.lengthSq()<1e-6&&(r=new f.Vector3(1,0,0));const l=r.clone().normalize(),u=h.clone().multiplyScalar(.5),g=[new f.Vector3(u.x,u.y,u.z),new f.Vector3(u.x,u.y,-u.z),new f.Vector3(u.x,-u.y,u.z),new f.Vector3(u.x,-u.y,-u.z),new f.Vector3(-u.x,u.y,u.z),new f.Vector3(-u.x,u.y,-u.z),new f.Vector3(-u.x,-u.y,u.z),new f.Vector3(-u.x,-u.y,-u.z)];let y=0;for(const A of g){const M=A.dot(l),D=Math.sqrt(Math.max(0,A.lengthSq()-M*M));D>y&&(y=D)}y=y*1.05;const m=this.camera.fov*Math.PI/180,v=2*Math.atan(Math.tan(m/2)*this.camera.aspect),_=y/Math.tan(v/2),x=y/Math.tan(m/2),w=Math.max(_,x),b=d.clone();let T=h.z/3;h.z<h.x&&h.z<h.y&&(T=h.x*.8),h.z>h.x&&h.z>h.y&&(T=0),b.z+=T;const S=r.clone().normalize().multiplyScalar(w<1?1:w).add(b);Math.max(h.x*2,5);const I=this.camera.position.clone(),C=this.controls.target.clone();let L=600;const R=I.distanceTo(S)+C.distanceTo(p);R>.001&&(L=Math.min(800,Math.max(650,R*45))),this._animateCamera(I,S,C,p,L,()=>{this.shadowMode||(this._progressShadow.visible=!0,this._progressShadow.isFinished||this._progressShadow.recalculate())}),this.controls.minDistance=Math.max(.2,Math.min(w*.25,w-.1)),this.controls.maxDistance=w*4},this.resize=()=>{var p,r;const c=this.renderer.domElement.parentElement;if(!c)return;c.style.display="flex",this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.renderer.domElement.style.flexGrow="1";const h=c.clientWidth,d=c.clientHeight;this.size.set(h,d),this.camera.aspect=h/d,this.camera.updateProjectionMatrix(),this._amrRender.setSize(h,d),this._updateCamera(),this.css2dRenderer.setSize(h,d),this.renderer.getPixelRatio(),(p=this.pathTracer)==null||p.updateCamera(),this.sampleCount=0,this.renderer.setSize(h,d),(r=this._jumpFlood)==null||r.setSize(h,d)},this.ticker=c=>{if(!this._destroyed){if(this.stats.begin(),this.renderer.domElement.dispatchEvent(new CustomEvent("ticker",{detail:c})),this._rafId=requestAnimationFrame(this.ticker),this.renderer.clear(),this.usePathTracing){this.hideAmrUI(),this.sampleCount<this.maxSample?this.sampleCount++:this.pathTracer.pausePathTracing=!0,this.pathTracer.renderSample();const h=this.renderer.autoClear;this.renderer.autoClear=!1,this.scene.overrideMaterial=bc,this.renderer.clearDepth(),this.renderer.render(this.scene,this.mainCamera),this.scene.overrideMaterial=null,this.renderer.render(this.overlayScene,this.mainCamera),this.renderer.autoClear=h}else{this._clock.getElapsedTime()-this._uiHiddenTime>.15?this.showControls&&this.amr.controllers.forEach(p=>p.show()):this.amr.controllers.forEach(p=>p.hide());const d=this.stats.fps();if(this.usePathTracing||(this._fpsCache.length>this._fpsCacheMax&&this._fpsCache.shift(),this._fpsCache.push(d)),this.amr.slots.forEach(p=>{this._dragging?p.getCanInstall()&&p.render(this):p.render(this)}),Le.update(),this.controls.update(),this._progressShadow.update(this.mainCamera),this.css2dRenderer.render(this.scene,this.mainCamera),this.updatePosition(),this.scene.overrideMaterial=null,this.renderer.render(this.scene,this.mainCamera),this._jumpFlood&&this._selectedForOutline.length>0){const p=this.scene.background;this.scene.background=null,this._jumpFlood.render(this._selectedForOutline),this.scene.background=p}}this.stats.end()}},this.stats.showPanel(0),this.hideState(),e.fov&&(this.camera.fov=e.fov,this.camera.updateProjectionMatrix()),Pr(He,this.renderer),this._ground.visible=!1,this.controls=new an.OrbitControls(this.camera,this.renderer.domElement),this.controls.enablePan=!0,this.controls.rotateSpeed=this.props.isMobile?.6:.5,this.controls.dampingFactor=fr,this.controls.enableDamping=!0,this.controls.maxDistance=10,this.controls.minDistance=1,this.controls.zoomSpeed=this.props.isMobile?.3:kr()?.2:1,this._cameraPositionUI=new uc(this.controls),this.renderer.setPixelRatio(window.devicePixelRatio||1),this.renderer.autoClear=!0,this.renderer.toneMapping=f.ACESFilmicToneMapping,this.renderer.toneMappingExposure=1.4,this.renderer.outputColorSpace=f.SRGBColorSpace,this.renderer.localClippingEnabled=!0,this.renderer.shadowMap.enabled=!0,this.css2dRenderer.domElement.style.pointerEvents="none",this.css2dRenderer.domElement.style.position="absolute",this.css2dRenderer.domElement.style.top="0px",this.camera.position.set(10,-10,5),this.camera.lookAt(new f.Vector3);const{tiles:t}=za();this.pathTracer=new ea(this.renderer),this.pathTracer.multipleImportanceSampling=!0,this.pathTracer.filterGlossyFactor=.6;let i=window.devicePixelRatio;i<2&&(i=2),this.pathTracer.renderScale=this.props.isMobile?1:i,this.pathTracer.bounces=this.props.isMobile?8:10,this.pathTracer.transmissiveBounces=this.props.isMobile?1:3,this.pathTracer.tiles.set(t,t),this.pathTracer.minSamples=10,this.pathTracer.dynamicLowRes=!0,this.pathTracer.lowResScale=.5,this.pathTracer.fadeDuration=0;const s=new oc(e.workerUrl),a=typeof navigator<"u"?navigator.hardwareConcurrency:4;s.maxWorkerCount=a,this.pathTracer.setBVHWorker(s),this.orthographicCamera.left=-20,this.orthographicCamera.right=20,this.orthographicCamera.top=-20,this.orthographicCamera.bottom=20,this._lastTarget=this.controls.target.clone();const n=()=>{let c=this._lastTarget.x,h=this._lastTarget.y;this.controls.target.x=c,this.controls.target.y=h};this.controls.addEventListener("change",()=>{var c;this.sampleCount=0,n(),this._uiHiddenTime=this._clock.getElapsedTime(),this.orthographicCamera.position.copy(this.camera.position),this.orthographicCamera.lookAt(this.controls.target),this.usePathTracing&&(this.pathTracer.pausePathTracing=!1,(c=this.pathTracer)==null||c.updateCamera()),this._updateCamera(),!(Math.abs(this.camera.position.x)<.001||Math.abs(this.camera.position.y)<.001)&&(this._axisMoving||(this.mainCamera=this.camera,this.usePathTracing&&this.generateBVH().then()))}),this._mainCamera=this.camera,this._progressShadow=new lc(this.renderer,this.scene,{size:8,lightCount:12,frames:40,lightRadius:8,ambientWeight:.65}),this._progressShadow.lightOrigin.position.set(3,2.5,.6),this._progressShadow.visible=!1,this._container.add(this.amr),this.scene.add(this._container),this.ticker(0),this._loadEnv(),this._initEvents(),this.scene.add(this._cameraPositionUI),this._ground.rotateX(-Math.PI/2),this.scene.add(this._ground),this._jumpFlood=new mc(this.renderer,this.scene,this.camera,{thickness:4,color:"#fff"}),(typeof e.useAxisBall!="boolean"||e.useAxisBall)&&(this._controlsGizmo=new ac(this.controls,{size:160,padding:12,offset:e.axisBallOffset||new f.Vector2(10,10),fontSize:17,bubbleSizePrimary:18,bubbleSizeSecondary:14}),this._controlsGizmo.addListener("axis-select-start",()=>{this._axisMoving=!0,this.mainCamera=this.orthographicCamera,this.usePathTracing&&this.generateBVH().then()}),this._controlsGizmo.addListener("axis-select-end",()=>{this._axisMoving=!1}))}get usePathTracing(){return this._usePathTracing}_clearAmrContent(){const e=this.renderer.getRenderTarget();this.renderer.setRenderTarget(this._amrRender),this.renderer.setClearColor(0,0),this.renderer.clear(!0,!0,!0),this.renderer.setRenderTarget(e)}get shadowMode(){return this._shadowMode}set shadowMode(e){e?(this._progressShadow.visible=!1,this.amr.bodyOpacity=.2):(this._progressShadow.visible=!0,this.amr.bodyOpacity=1,this._progressShadow.isFinished||this._progressShadow.recalculate().then()),this._shadowMode=e}set usePathTracing(e){this._clearAmrContent(),e?(this.scene.background=new f.Color("transparent"),this.renderer.toneMappingExposure=1.8,this.overlayScene.add(this._progressShadow.shadowCatcherMesh),this.amr&&(this.amr.bodyOpacity=1),this.hideAmrUI(),this.pathTracer.renderToCanvas=!0,this.scene.background=null,this._ptEnvMap?(this.scene.environment=this._ptEnvMap,this.pathTracer.updateEnvironment()):new xs.HDRLoader().load(_c,t=>{t.mapping=f.EquirectangularReflectionMapping,this._ptEnvMap=t,this.usePathTracing&&(this.scene.environment=t,this.pathTracer.updateEnvironment())})):(this.renderer.toneMappingExposure=1.4,this.scene.add(this._progressShadow.shadowCatcherMesh),this.pathTracer.renderToCanvas=!1,this.amr.logos.forEach(t=>{var i;(i=t.parent)==null||i.add(t.target)}),this.showAmrUI(),this.amr&&this.amr.opacityCache!==void 0?(this.amr.bodyOpacity=this.amr.opacityCache,this.amr.opacityCache=void 0):this.amr&&(this.amr.bodyOpacity=1),this.pathTracer.reset(),this._ground.visible=!1,this._envMap&&(this.scene.background=this._envMap,this.scene.environment=this._envMap)),this._usePathTracing=e,this.controls.dampingFactor=e?1:fr,this.sampleCount=0}get fpsAverage(){return Br(this._fpsCache)}get mainCamera(){return this._mainCamera}set mainCamera(e){this._mainCamera=e,e instanceof f.OrthographicCamera?this.scene.background=null:this.scene.background=this.scene.environment}showState(){this.stats.dom.style.display="block"}hideState(){this.stats.dom.style.display="none"}hideAmrUI(e=!0,t=!0){this.shadowMode||this.amr.slots.forEach(i=>i.hide()),this.amr.sizeBox.hide(e),this.amr.controllers.forEach(i=>i.hide()),t&&this.amr.goods.forEach(i=>i.hide())}showAmrUI(e=!0){this.showSlots&&this.amr.slots.forEach(t=>t.show()),this.showSize&&this.amr.sizeBox.show(e),this.showControls&&this.amr.controllers.forEach(t=>t.show()),this.amr.goods.forEach(t=>t.show())}get showSlots(){return this._showSlots}set showSlots(e){this._showSlots=e,this.amr.slots.forEach(t=>e?t.show():t.hide())}get showSize(){return this._showSize}set showSize(e){this._showSize=e,e?this.amr.sizeBox.show(!0):this.amr.sizeBox.hide(!0)}get showControls(){return this._showControls}set showControls(e){this._showControls=e,this.amr.controllers.forEach(t=>e?t.show():t.hide())}_updateCamera(){const e=this.mainCamera.position.distanceTo(this.controls.target),t=2*Math.tan(this.camera.fov*.5*Math.PI/180)*e,i=this.size.x/this.size.y;this.orthographicCamera.left=-t*i/2,this.orthographicCamera.right=t*i/2,this.orthographicCamera.top=t/2,this.orthographicCamera.bottom=-t/2,this.orthographicCamera.updateProjectionMatrix()}_loadEnv(){new xs.HDRLoader().load(vc,t=>{t.mapping=f.EquirectangularReflectionMapping,this._envMap=t,this._usePathTracing||(this.scene.background=t,this.scene.backgroundBlurriness=1,this.scene.backgroundIntensity=1,this.scene.backgroundRotation=new f.Euler(Math.PI/2,0,Math.PI*.98*.8),this.scene.environment=t,this.overlayScene.environment=t,this.scene.environmentRotation=this.scene.backgroundRotation,this.overlayScene.environmentRotation=this.scene.environmentRotation,this.scene.environmentIntensity=1.4,this.overlayScene.environmentIntensity=this.scene.environmentIntensity),this.pathTracer.updateEnvironment()},()=>{},()=>{})}_initEvents(){window.addEventListener("drag",this._drag),window.addEventListener("dragend",this._dragend),document.addEventListener("wheel",this._detectTrackpad),window.addEventListener("pointermove",this._pointermove),this.renderer.domElement.addEventListener("pointerdown",this._pointerdown);const e=this.scene.children.find(t=>t.type==="Mesh");e&&this.select(e)}switchCamera(){this.mainCamera=this.mainCamera===this.camera?this.orthographicCamera:this.camera}toCameraTop(){const e=this.camera.position.distanceTo(this.controls.target);this.camera.position.copy(new f.Vector3(0,e+this.controls.target.y,0))}toCameraRight(){const e=this.camera.position.distanceTo(this.controls.target);this.camera.position.copy(new f.Vector3(0,this.controls.target.y,e))}toCameraFace(){const e=this.camera.position.distanceTo(this.controls.target);this.camera.position.copy(new f.Vector3(e,this.controls.target.y,0))}async generateBVH(){this.pathTracer.pausePathTracing=!1,this.amr.slots.forEach(e=>e.hide()),this.amr&&(this.amr.opacityCache=this.amr.bodyOpacity,this.amr.bodyOpacity=1,this.overlayScene.clear(),this.amr.logos.forEach(e=>{const t=new f.Group;e.target.updateMatrixWorld(!0),t.applyMatrix4(e.target.matrixWorld),t.add(e.target),this.overlayScene.add(t)})),this.usePathTracing=!0,this.pathTracer.setScene(this.scene,this.mainCamera)}async download(e=!1){if(e&&!this.usePathTracing){const t=this._amrRender.width,i=this._amrRender.height,s=new Uint8Array(t*i*4);this.renderer.setRenderTarget(this._amrRender),this.renderer.readRenderTargetPixels(this._amrRender,0,0,t,i,s),this.renderer.setRenderTarget(null);const a=document.createElement("canvas");a.width=t,a.height=i;const n=a.getContext("2d"),c=new ImageData(t,i);for(let h=0;h<i;h++)for(let d=0;d<t;d++){const p=((i-h-1)*t+d)*4,r=(h*t+d)*4;c.data[r]=s[p],c.data[r+1]=s[p+1],c.data[r+2]=s[p+2],c.data[r+3]=s[p+3]}return n.putImageData(c,0,0),a.toDataURL("image/png")}else return new Promise((t,i)=>{this._uiHiddenTime=this._clock.getElapsedTime(),this.hideAmrUI();const s=this.scene.background;this.scene.background=null,setTimeout(()=>{const a=this.renderer.domElement.toDataURL("image/png");return this.scene.background=s,t(a)},this.fpsAverage)})}async captureTriViews(e){var n;const t=(e==null?void 0:e.subject)??this._container;(n=this._progressShadow)==null||n.visible;const i=this.scene.background,s=this.showSize;return new Kr({renderer:this.renderer,scene:this.scene,overlayScene:this.overlayScene,subject:t,onBeforeCapture:()=>{this.scene.background=null,this.hideAmrUI(),this.showSize=!1,this.usePathTracing&&(this.usePathTracing=!1),this._progressShadow.visible=!1},onAfterCapture:()=>{this.scene.background=i,this.showAmrUI(),this.showSize=s,this._progressShadow.visible=!0}}).capture(e)}clearAMR(){ge(this.overlayScene),this.amr.clean(),this.usePathTracing=!1}async exportAMR(){const e=this._container.clone(!0);return e.traverse(t=>{t.dispose&&(t.dispose(),t.removeFromParent())}),await zr.parseAsync(e,{onlyVisible:!0,binary:!0})}async addAMR(e,t=""){this.amr.init(this),await this.amr.load(e,t),this.amr.addEventListener("fork-height-change",this.debounceForkHeightChange),this.amr.addEventListener("shape-key-changed",(i,s)=>{this.pathTracer.reset(),this.sampleCount=0,this.pathTracer.setScene(this.scene,this.camera),this.overlayScene.traverse(a=>{if(!Object.keys(a.morphTargetDictionary||{}).includes(i))return;let n=s;a.userData[`origin_${i}`]&&(n-=a.userData[`origin_${i}`]);const c=a.morphTargetDictionary[i];a.morphTargetInfluences&&(a.morphTargetInfluences[c]=n),a instanceof f.Mesh&&a.geometry.translate(0,0,1e-5)}),["width","length","liftLength","liftWidth","liftOuterWidth"].includes(i)&&(this._progressShadow.clear(),this.debounceForkHeightChange())})}_animateCamera(e,t,i,s,a,n){var h;const c={t:0};(h=this._fitAnimation)==null||h.stop(),this._fitAnimation=new ci(c).to({t:1},a).easing(Le.Easing.Quadratic.InOut).onStart(()=>{this.controls.enabled=!1}).onUpdate(()=>{const d=c.t;this.controls.target.lerpVectors(i,s,d);const p=s.clone(),r=e.clone().sub(p),l=t.clone().sub(p),u=r.length(),g=l.length(),y=u+(g-u)*d;let m;if(u>.001&&g>.001){const v=r.clone().normalize(),_=l.clone().normalize(),x=v.angleTo(_);if(x>.001){const w=new f.Vector3().crossVectors(v,_);if(w.lengthSq()>.001){w.normalize();const b=new f.Quaternion().setFromAxisAngle(w,x*d),T=v.clone().applyQuaternion(b);m=p.clone().add(T.multiplyScalar(y))}else m=p.clone().add(v.multiplyScalar(y))}else m=p.clone().add(v.multiplyScalar(y))}else m=e.clone().lerp(t,d);this.camera.position.copy(m),this.camera.lookAt(this.controls.target)}).onComplete(()=>{this.controls.enabled=!0,n==null||n()}).start()}select(e,t=4){if(this._jumpFlood&&(this._jumpFlood.params.thickness=t),!e){this._selectedForOutline=[];return}typeof e=="string"||(Array.isArray(e)?this._selectedForOutline=[...e]:this._selectedForOutline=[e])}appendTo(e){e.append(this.renderer.domElement),e.append(this.stats.dom),e.append(this.css2dRenderer.domElement),this.props.isMobile?(e.classList.add("is-mobile"),e.style.cssText=`
|
|
3938
|
+
`});super(s,a),this.position.z=-.02}}const vc="https://cdn2.seer-group.com/libs/hdr/aristea_wreck_512.hdr",_c="https://cdn2.seer-group.com/libs/hdr/lightroom_14b_512.hdr",yc="https://cdn2.seer-group.com/libs/fonts.type.json",xc=new ln.Font(yc);class ss{constructor(e){var i;this._props=e,this.name="",this._defaults={color:"",metalness:0,roughness:0,envMapIntensity:1},this.color="",this.metalness=0,this.roughness=0,this.envMapIntensity=1,this.name=this._props.name;const t=this.material;t&&(this.color=this._defaults.color="#"+((i=t.color)==null?void 0:i.getHexString()),this.metalness=this._defaults.metalness=t.metalness??0,this.roughness=this._defaults.roughness=t.roughness??1,this.envMapIntensity=this._defaults.envMapIntensity=t.envMapIntensity??1)}get material(){if(this._props.target instanceof f.MeshStandardMaterial)return this._props.target;if(this._props.target instanceof f.Mesh){if(Array.isArray(this._props.target.material))return this._props.target.material.find(e=>e instanceof f.MeshStandardMaterial);if(this._props.target.material instanceof f.MeshStandardMaterial)return this._props.target.material}}change(e){var i;this.color=e;const t=this.material;(i=t==null?void 0:t.color)==null||i.set(e)}reset(){this.change(this._defaults.color);const e=this.material;e&&(e.metalness=this._defaults.metalness,e.roughness=this._defaults.roughness,e.envMapIntensity=this._defaults.envMapIntensity,e.needsUpdate=!0)}}var Zr=(o=>(o[o.DEFAULT=0]="DEFAULT",o[o.CAN_INSTALL=1]="CAN_INSTALL",o))(Zr||{});const fr=.15;f.Object3D.DEFAULT_UP.set(0,0,1);let nt,li=0,rs=0;const wc=()=>{nt=void 0,li=0,rs=0},bc=new f.MeshBasicMaterial({colorWrite:!1});class Ac{constructor(e){this.props=e,this.stats=new Lt,this.scene=new f.Scene,this.overlayScene=new f.Scene,this.renderer=new f.WebGLRenderer({antialias:!0,alpha:!0,logarithmicDepthBuffer:!0,powerPreference:"high-performance",preserveDrawingBuffer:!0}),this.css2dRenderer=new me.CSS2DRenderer,this.mousePos=new f.Vector2,this.mouseCoord=new f.Vector2,this.offset=new f.Vector2,this.size=new f.Vector2,this.amr=new Hr({showSizeBox:!0,showController:!0}),this._selectedForOutline=[],this._clock=new f.Clock(!0),this._uiHiddenTime=this._clock.getElapsedTime(),this.camera=new f.PerspectiveCamera(39.6,window.innerWidth/window.innerHeight,.1,1e4),this.d=2,this.orthographicCamera=new f.OrthographicCamera(-this.d*(window.innerWidth/window.innerHeight),this.d*(window.innerWidth/window.innerHeight),this.d,-this.d,.1,1e3),this._axisMoving=!1,this._container=new f.Group,this._raycaster=new f.Raycaster,this._selected=[],this._pointerDownTimeout=0,this._dragging=!1,this.maxSample=1024*2,this.sampleCount=0,this._usePathTracing=!1,this._fpsCache=[],this._fpsCacheMax=20,this._emitter=new pt,this.sound=new ka,this._rafId=null,this._destroyed=!1,this._ground=new f.Mesh(new f.PlaneGeometry(100,100),new f.MeshPhysicalMaterial({color:new f.Color("#eee"),metalness:.4,roughness:.1,clearcoat:1,clearcoatRoughness:.1})),this._sciFiGrid=new gc(18,40),this._amrRender=new f.WebGLRenderTarget(1024,1024,{format:f.RGBAFormat,type:f.UnsignedByteType,colorSpace:f.SRGBColorSpace,samples:8}),this._lastTarget=new f.Vector3,this._shadowMode=!1,this.addEventListener=this._emitter.on.bind(this._emitter),this.removeEventListener=this._emitter.on.bind(this._emitter),this._showSlots=!0,this._showSize=!0,this._showControls=!0,this._drag=c=>{this._dragging=!0,this._pointermove(c)},this._dragend=c=>{this._dragging=!1},this._pointermove=c=>{if(this._pointerDownTimeout)return clearTimeout(this._pointerDownTimeout),this._pointerDownTimeout=0;let{top:h,left:d}=this.renderer.domElement.getBoundingClientRect();this.offset.set(d,h),this.mousePos.set(c.clientX-d,c.clientY-h),this.mouseCoord.set((c.clientX-d)/this.size.x*2-1,-((c.clientY-h)/this.size.y)*2+1),this._raycaster.setFromCamera(this.mouseCoord,this.camera)},this._pointerdown=c=>{const h=()=>{this.amr.slots.forEach(r=>r.selected=!1);const p=this._raycaster.intersectObjects(this.amr.slots,!1)[0];p&&this.amr.slots.forEach(r=>{r.traverse(l=>{l==p.object||(r.deviceSelected=!1)})}),this._pointerDownTimeout=0};this._pointerDownTimeout=window.setTimeout(h,200)},this._detectTrackpad=()=>{nt||typeof nt<"u"||(li===0&&(rs=performance.now()),li++,performance.now()-rs>66&&(li>5?nt=!0:nt=!1,nt?this.controls.zoomSpeed=.2:this.controls.zoomSpeed=1,setTimeout(wc,2e3)))},this.debounceForkHeightChange=Ua(()=>{var c;this._progressShadow.clear(),(c=this._progressShadow)==null||c.recalculate()},300),this.focusObjects=(c,h)=>{var j;if(!c.length){this.fit();return}this.scene.updateMatrixWorld(!0),this._focusRestoreView=void 0,(j=this._fitAnimation)==null||j.stop();const d=new f.Box3,p=new f.Box3,r=new f.Vector3,l=new f.Vector3,u=new f.Vector3,g=new f.Vector3,y=U=>{U.geometry&&(U.geometry.boundingBox||U.geometry.computeBoundingBox(),p.copy(U.geometry.boundingBox).applyMatrix4(U.matrixWorld),p.isEmpty()||d.union(p))},m=U=>{var vs,_s;const Q=U.geometry,re=(vs=Q==null?void 0:Q.attributes)==null?void 0:vs.position;if(!re){y(U);return}const te=((_s=Q.morphAttributes)==null?void 0:_s.position)||[],gs=U.morphTargetInfluences||[],Xr=te.length>0&&gs.length>0;for(let Ae=0;Ae<re.count;Ae++){if(r.set(re.getX(Ae),re.getY(Ae),re.getZ(Ae)),Xr){l.set(0,0,0);let gi=0;for(let Ne=0;Ne<te.length;Ne++){const kt=gs[Ne]||0;kt&&(gi+=kt,u.set(te[Ne].getX(Ae),te[Ne].getY(Ae),te[Ne].getZ(Ae)),Q.morphTargetsRelative,l.addScaledVector(u,kt))}Q.morphTargetsRelative?r.add(l):gi>0&&(r.multiplyScalar(1-gi),r.add(l))}g.copy(r).applyMatrix4(U.matrixWorld),d.expandByPoint(g)}};if(c.forEach(U=>{U.traverse(Q=>{if(Q.visible){if(Q instanceof f.Mesh){m(Q);return}(Q.isPoint||Q.isLine)&&y(Q)}})}),d.isEmpty())return;const v=new f.Vector3;d.getCenter(v);const _=new f.Vector3;d.getSize(_);const x=v.clone();this._lastTarget.copy(x);let w;h?w=h.clone().normalize().negate():w=this.camera.position.clone().sub(this.controls.target).normalize();const b=_.clone().multiplyScalar(.5),T=[new f.Vector3(b.x,b.y,b.z),new f.Vector3(b.x,b.y,-b.z),new f.Vector3(b.x,-b.y,b.z),new f.Vector3(b.x,-b.y,-b.z),new f.Vector3(-b.x,b.y,b.z),new f.Vector3(-b.x,b.y,-b.z),new f.Vector3(-b.x,-b.y,b.z),new f.Vector3(-b.x,-b.y,-b.z)],S=new f.Vector3(0,1,0);Math.abs(w.dot(S))>.99&&S.set(0,0,1);const I=new f.Vector3().crossVectors(w,S).normalize(),C=new f.Vector3().crossVectors(I,w).normalize();let L=0;T.forEach(U=>{const Q=U.dot(I),re=U.dot(C),te=Math.sqrt(Q*Q+re*re);L=Math.max(L,te)}),L=L/2+.4;const R=this.camera.fov*Math.PI/180,A=2*Math.atan(Math.tan(R/2)*this.camera.aspect),M=L/Math.tan(A/2),D=L/Math.tan(R/2),P=Math.max(M,D),E=v.clone().add(w.multiplyScalar(P)),B=this.camera.position.clone(),V=this.controls.target.clone();let N=500;const W=B.distanceTo(E)+V.distanceTo(x);W>.001&&(N=Math.min(1e3,Math.max(450,W*45))),this._animateCamera(B,E,V,x,N)},this.focusSlots=c=>{var C,L;if(this.amr.slots.forEach(R=>{R.focused=!1,R.hide()}),!c.length)if(this._lastTarget.set(0,0,this._lastTarget.z),this.amr.slots.forEach(R=>{R.show()}),this.shadowMode=!1,this._focusRestoreView){const R=this._focusRestoreView;this._focusRestoreView=void 0;const A=this.camera.position.clone(),M=this.controls.target.clone(),D=R.position.clone(),P=R.target.clone();let E=500;const B=A.distanceTo(D)+M.distanceTo(P);B>.001&&(E=Math.min(1e3,Math.max(450,B*45))),this._animateCamera(A,D,M,P,E,()=>{this.camera.up.copy(R.up)});return}else{this.fit();return}(C=this._fitAnimation)!=null&&C.isPlaying()||this.shadowMode||(this._focusRestoreView={position:this.camera.position.clone(),target:new f.Vector3(0,0,this.controls.target.z),up:this.camera.up.clone()}),(L=this._fitAnimation)==null||L.stop(),this.shadowMode=!0;const h=c.flatMap(R=>{if(R.show(),R.focused=!0,!R.parent)return[];const A=new f.Vector3;return R.parent.getWorldPosition(A),[A]});if(!h.length)return;const d=h.reduce((R,A)=>R.add(A),new f.Vector3).multiplyScalar(1/h.length),p=this.controls.target.clone(),r=this.camera.position.clone().sub(p).normalize();let l=0;for(const R of h){const A=R.clone().sub(d),M=A.dot(r),D=Math.sqrt(Math.max(0,A.lengthSq()-M*M));D>l&&(l=D)}l=l+.4;const u=this.camera.fov*Math.PI/180,g=2*Math.atan(Math.tan(u/2)*this.camera.aspect),y=l/Math.tan(g/2),m=l/Math.tan(u/2),v=Math.max(y,m),_=d.clone(),x=d.clone().add(r.clone().multiplyScalar(v<1?1:v)),w=this.camera.position.clone(),b=p.clone(),T={t:0};let S=500;const I=w.distanceTo(x)+b.distanceTo(_);I>.001&&(S=Math.min(1e3,Math.max(450,I*45))),this._lastTarget=_.clone(),this._fitAnimation=new ci(T).to({t:1},S).easing(Le.Easing.Quadratic.InOut).onStart(()=>{this.controls.enabled=!1}).onUpdate(()=>{const R=T.t;this.camera.position.lerpVectors(w,x,R),this.controls.target.lerpVectors(b,_,R)}).onComplete(()=>{this.controls.enabled=!0}).start()},this.fit=()=>{this._focusRestoreView=void 0,new f.Box3().setFromObject(this._container);const h=this.amr.sizeBox.size.getSize(new f.Vector3),d=h.clone().multiplyScalar(.5),p=new f.Vector3(0,0,d.z);this._lastTarget.copy(p);let r=d.clone().sub(p);r.lengthSq()<1e-6&&(r=new f.Vector3(1,0,0));const l=r.clone().normalize(),u=h.clone().multiplyScalar(.5),g=[new f.Vector3(u.x,u.y,u.z),new f.Vector3(u.x,u.y,-u.z),new f.Vector3(u.x,-u.y,u.z),new f.Vector3(u.x,-u.y,-u.z),new f.Vector3(-u.x,u.y,u.z),new f.Vector3(-u.x,u.y,-u.z),new f.Vector3(-u.x,-u.y,u.z),new f.Vector3(-u.x,-u.y,-u.z)];let y=0;for(const A of g){const M=A.dot(l),D=Math.sqrt(Math.max(0,A.lengthSq()-M*M));D>y&&(y=D)}y=y*1.05;const m=this.camera.fov*Math.PI/180,v=2*Math.atan(Math.tan(m/2)*this.camera.aspect),_=y/Math.tan(v/2),x=y/Math.tan(m/2),w=Math.max(_,x),b=d.clone();let T=h.z/3;h.z<h.x&&h.z<h.y&&(T=h.x*.8),h.z>h.x&&h.z>h.y&&(T=0),b.z+=T;const S=r.clone().normalize().multiplyScalar(w<1?1:w).add(b);Math.max(h.x*2,5);const I=this.camera.position.clone(),C=this.controls.target.clone();let L=600;const R=I.distanceTo(S)+C.distanceTo(p);R>.001&&(L=Math.min(800,Math.max(650,R*45))),this._animateCamera(I,S,C,p,L,()=>{this.shadowMode||(this._progressShadow.visible=!0,this._progressShadow.isFinished||this._progressShadow.recalculate())}),this.controls.minDistance=Math.max(.2,Math.min(w*.25,w-.1)),this.controls.maxDistance=w*4},this.resize=()=>{var p,r;const c=this.renderer.domElement.parentElement;if(!c)return;c.style.display="flex",this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.renderer.domElement.style.flexGrow="1";const h=c.clientWidth,d=c.clientHeight;this.size.set(h,d),this.camera.aspect=h/d,this.camera.updateProjectionMatrix(),this._amrRender.setSize(h,d),this._updateCamera(),this.css2dRenderer.setSize(h,d),this.renderer.getPixelRatio(),(p=this.pathTracer)==null||p.updateCamera(),this.sampleCount=0,this.renderer.setSize(h,d),(r=this._jumpFlood)==null||r.setSize(h,d)},this.ticker=c=>{if(!this._destroyed){if(this.stats.begin(),this.renderer.domElement.dispatchEvent(new CustomEvent("ticker",{detail:c})),this._rafId=requestAnimationFrame(this.ticker),this.renderer.clear(),this.usePathTracing){this.hideAmrUI(),this.sampleCount<this.maxSample?this.sampleCount++:this.pathTracer.pausePathTracing=!0,this.pathTracer.renderSample();const h=this.renderer.autoClear;this.renderer.autoClear=!1,this.scene.overrideMaterial=bc,this.renderer.clearDepth(),this.renderer.render(this.scene,this.mainCamera),this.scene.overrideMaterial=null,this.renderer.render(this.overlayScene,this.mainCamera),this.renderer.autoClear=h}else{this._clock.getElapsedTime()-this._uiHiddenTime>.15?this.showControls&&this.amr.controllers.forEach(p=>p.show()):this.amr.controllers.forEach(p=>p.hide());const d=this.stats.fps();if(this.usePathTracing||(this._fpsCache.length>this._fpsCacheMax&&this._fpsCache.shift(),this._fpsCache.push(d)),this.amr.slots.forEach(p=>{this._dragging?p.getCanInstall()&&p.render(this):p.render(this)}),Le.update(),this.controls.update(),this._progressShadow.update(this.mainCamera),this.css2dRenderer.render(this.scene,this.mainCamera),this.updatePosition(),this.scene.overrideMaterial=null,this.renderer.render(this.scene,this.mainCamera),this._jumpFlood&&this._selectedForOutline.length>0){const p=this.scene.background;this.scene.background=null,this._jumpFlood.render(this._selectedForOutline),this.scene.background=p}}this.stats.end()}},this.stats.showPanel(0),this.hideState(),e.fov&&(this.camera.fov=e.fov,this.camera.updateProjectionMatrix()),Pr(He,this.renderer),this._ground.visible=!1,this.controls=new an.OrbitControls(this.camera,this.renderer.domElement),this.controls.enablePan=!0,this.controls.rotateSpeed=this.props.isMobile?.6:.5,this.controls.dampingFactor=fr,this.controls.enableDamping=!0,this.controls.maxDistance=10,this.controls.minDistance=1,this.controls.zoomSpeed=this.props.isMobile?.3:kr()?.2:1,this._cameraPositionUI=new uc(this.controls),this.renderer.setPixelRatio(window.devicePixelRatio||1),this.renderer.autoClear=!0,this.renderer.toneMapping=f.ACESFilmicToneMapping,this.renderer.toneMappingExposure=1.4,this.renderer.outputColorSpace=f.SRGBColorSpace,this.renderer.localClippingEnabled=!0,this.renderer.shadowMap.enabled=!0,this.css2dRenderer.domElement.style.pointerEvents="none",this.css2dRenderer.domElement.style.position="absolute",this.css2dRenderer.domElement.style.top="0px",this.camera.position.set(10,-10,5),this.camera.lookAt(new f.Vector3);const{tiles:t}=za();this.pathTracer=new ea(this.renderer),this.pathTracer.multipleImportanceSampling=!0,this.pathTracer.filterGlossyFactor=.6;let i=window.devicePixelRatio;i<2&&(i=2),this.pathTracer.renderScale=this.props.isMobile?1:i,this.pathTracer.bounces=this.props.isMobile?8:10,this.pathTracer.transmissiveBounces=this.props.isMobile?1:3,this.pathTracer.tiles.set(t,t),this.pathTracer.minSamples=10,this.pathTracer.dynamicLowRes=!0,this.pathTracer.lowResScale=.5,this.pathTracer.fadeDuration=0;const s=new oc(e.workerUrl),a=typeof navigator<"u"?navigator.hardwareConcurrency:4;s.maxWorkerCount=a,this.pathTracer.setBVHWorker(s),this.orthographicCamera.left=-20,this.orthographicCamera.right=20,this.orthographicCamera.top=-20,this.orthographicCamera.bottom=20,this._lastTarget=this.controls.target.clone();const n=()=>{let c=this._lastTarget.x,h=this._lastTarget.y;this.controls.target.x=c,this.controls.target.y=h};this.controls.addEventListener("change",()=>{var c;this.sampleCount=0,n(),this._uiHiddenTime=this._clock.getElapsedTime(),this.orthographicCamera.position.copy(this.camera.position),this.orthographicCamera.lookAt(this.controls.target),this.usePathTracing&&(this.pathTracer.pausePathTracing=!1,(c=this.pathTracer)==null||c.updateCamera()),this._updateCamera(),!(Math.abs(this.camera.position.x)<.001||Math.abs(this.camera.position.y)<.001)&&(this._axisMoving||(this.mainCamera=this.camera,this.usePathTracing&&this.generateBVH().then()))}),this._mainCamera=this.camera,this._progressShadow=new lc(this.renderer,this.scene,{size:8,lightCount:12,frames:e.isMobile?20:60,lightRadius:2,ambientWeight:.8}),this._progressShadow.lightOrigin.position.set(3,2.5,.6),this._progressShadow.visible=!1,this._container.add(this.amr),this.scene.add(this._container),this.ticker(0),this._loadEnv(),this._initEvents(),this.scene.add(this._cameraPositionUI),this._ground.rotateX(-Math.PI/2),this.scene.add(this._ground),this._jumpFlood=new mc(this.renderer,this.scene,this.camera,{thickness:4,color:"#fff"}),(typeof e.useAxisBall!="boolean"||e.useAxisBall)&&(this._controlsGizmo=new ac(this.controls,{size:160,padding:12,offset:e.axisBallOffset||new f.Vector2(10,10),fontSize:17,bubbleSizePrimary:18,bubbleSizeSecondary:14}),this._controlsGizmo.addListener("axis-select-start",()=>{this._axisMoving=!0,this.mainCamera=this.orthographicCamera,this.usePathTracing&&this.generateBVH().then()}),this._controlsGizmo.addListener("axis-select-end",()=>{this._axisMoving=!1}))}get usePathTracing(){return this._usePathTracing}_clearAmrContent(){const e=this.renderer.getRenderTarget();this.renderer.setRenderTarget(this._amrRender),this.renderer.setClearColor(0,0),this.renderer.clear(!0,!0,!0),this.renderer.setRenderTarget(e)}get shadowMode(){return this._shadowMode}set shadowMode(e){e?(this._progressShadow.visible=!1,this.amr.bodyOpacity=.2):(this._progressShadow.visible=!0,this.amr.bodyOpacity=1,this._progressShadow.isFinished||this._progressShadow.recalculate().then()),this._shadowMode=e}set usePathTracing(e){this._clearAmrContent(),e?(this.scene.background=new f.Color("transparent"),this.renderer.toneMappingExposure=1.8,this.overlayScene.add(this._progressShadow.shadowCatcherMesh),this.amr&&(this.amr.bodyOpacity=1),this.hideAmrUI(),this.pathTracer.renderToCanvas=!0,this.scene.background=null,this._ptEnvMap?(this.scene.environment=this._ptEnvMap,this.pathTracer.updateEnvironment()):new xs.HDRLoader().load(_c,t=>{t.mapping=f.EquirectangularReflectionMapping,this._ptEnvMap=t,this.usePathTracing&&(this.scene.environment=t,this.pathTracer.updateEnvironment())})):(this.renderer.toneMappingExposure=1.4,this.scene.add(this._progressShadow.shadowCatcherMesh),this.pathTracer.renderToCanvas=!1,this.amr.logos.forEach(t=>{var i;(i=t.parent)==null||i.add(t.target)}),this.showAmrUI(),this.amr&&this.amr.opacityCache!==void 0?(this.amr.bodyOpacity=this.amr.opacityCache,this.amr.opacityCache=void 0):this.amr&&(this.amr.bodyOpacity=1),this.pathTracer.reset(),this._ground.visible=!1,this._envMap&&(this.scene.background=this._envMap,this.scene.environment=this._envMap)),this._usePathTracing=e,this.controls.dampingFactor=e?1:fr,this.sampleCount=0}get fpsAverage(){return Br(this._fpsCache)}get mainCamera(){return this._mainCamera}set mainCamera(e){this._mainCamera=e,e instanceof f.OrthographicCamera?this.scene.background=null:this.scene.background=this.scene.environment}showState(){this.stats.dom.style.display="block"}hideState(){this.stats.dom.style.display="none"}hideAmrUI(e=!0,t=!0){this.shadowMode||this.amr.slots.forEach(i=>i.hide()),this.amr.sizeBox.hide(e),this.amr.controllers.forEach(i=>i.hide()),t&&this.amr.goods.forEach(i=>i.hide())}showAmrUI(e=!0){this.showSlots&&this.amr.slots.forEach(t=>t.show()),this.showSize&&this.amr.sizeBox.show(e),this.showControls&&this.amr.controllers.forEach(t=>t.show()),this.amr.goods.forEach(t=>t.show())}get showSlots(){return this._showSlots}set showSlots(e){this._showSlots=e,this.amr.slots.forEach(t=>e?t.show():t.hide())}get showSize(){return this._showSize}set showSize(e){this._showSize=e,e?this.amr.sizeBox.show(!0):this.amr.sizeBox.hide(!0)}get showControls(){return this._showControls}set showControls(e){this._showControls=e,this.amr.controllers.forEach(t=>e?t.show():t.hide())}_updateCamera(){const e=this.mainCamera.position.distanceTo(this.controls.target),t=2*Math.tan(this.camera.fov*.5*Math.PI/180)*e,i=this.size.x/this.size.y;this.orthographicCamera.left=-t*i/2,this.orthographicCamera.right=t*i/2,this.orthographicCamera.top=t/2,this.orthographicCamera.bottom=-t/2,this.orthographicCamera.updateProjectionMatrix()}_loadEnv(){new xs.HDRLoader().load(vc,t=>{t.mapping=f.EquirectangularReflectionMapping,this._envMap=t,this._usePathTracing||(this.scene.background=t,this.scene.backgroundBlurriness=1,this.scene.backgroundIntensity=1,this.scene.backgroundRotation=new f.Euler(Math.PI/2,0,Math.PI*.98*.8),this.scene.environment=t,this.overlayScene.environment=t,this.scene.environmentRotation=this.scene.backgroundRotation,this.overlayScene.environmentRotation=this.scene.environmentRotation,this.scene.environmentIntensity=1.4,this.overlayScene.environmentIntensity=this.scene.environmentIntensity),this.pathTracer.updateEnvironment()},()=>{},()=>{})}_initEvents(){window.addEventListener("drag",this._drag),window.addEventListener("dragend",this._dragend),document.addEventListener("wheel",this._detectTrackpad),window.addEventListener("pointermove",this._pointermove),this.renderer.domElement.addEventListener("pointerdown",this._pointerdown);const e=this.scene.children.find(t=>t.type==="Mesh");e&&this.select(e)}switchCamera(){this.mainCamera=this.mainCamera===this.camera?this.orthographicCamera:this.camera}toCameraTop(){const e=this.camera.position.distanceTo(this.controls.target);this.camera.position.copy(new f.Vector3(0,e+this.controls.target.y,0))}toCameraRight(){const e=this.camera.position.distanceTo(this.controls.target);this.camera.position.copy(new f.Vector3(0,this.controls.target.y,e))}toCameraFace(){const e=this.camera.position.distanceTo(this.controls.target);this.camera.position.copy(new f.Vector3(e,this.controls.target.y,0))}async generateBVH(){this.pathTracer.pausePathTracing=!1,this.amr.slots.forEach(e=>e.hide()),this.amr&&(this.amr.opacityCache=this.amr.bodyOpacity,this.amr.bodyOpacity=1,this.overlayScene.clear(),this.amr.logos.forEach(e=>{const t=new f.Group;e.target.updateMatrixWorld(!0),t.applyMatrix4(e.target.matrixWorld),t.add(e.target),this.overlayScene.add(t)})),this.usePathTracing=!0,this.pathTracer.setScene(this.scene,this.mainCamera)}async download(e=!1){if(e&&!this.usePathTracing){const t=this._amrRender.width,i=this._amrRender.height,s=new Uint8Array(t*i*4);this.renderer.setRenderTarget(this._amrRender),this.renderer.readRenderTargetPixels(this._amrRender,0,0,t,i,s),this.renderer.setRenderTarget(null);const a=document.createElement("canvas");a.width=t,a.height=i;const n=a.getContext("2d"),c=new ImageData(t,i);for(let h=0;h<i;h++)for(let d=0;d<t;d++){const p=((i-h-1)*t+d)*4,r=(h*t+d)*4;c.data[r]=s[p],c.data[r+1]=s[p+1],c.data[r+2]=s[p+2],c.data[r+3]=s[p+3]}return n.putImageData(c,0,0),a.toDataURL("image/png")}else return new Promise((t,i)=>{this._uiHiddenTime=this._clock.getElapsedTime(),this.hideAmrUI();const s=this.scene.background;this.scene.background=null,setTimeout(()=>{const a=this.renderer.domElement.toDataURL("image/png");return this.scene.background=s,t(a)},this.fpsAverage)})}async captureTriViews(e){var n;const t=(e==null?void 0:e.subject)??this._container;(n=this._progressShadow)==null||n.visible;const i=this.scene.background,s=this.showSize;return new Kr({renderer:this.renderer,scene:this.scene,overlayScene:this.overlayScene,subject:t,onBeforeCapture:()=>{this.scene.background=null,this.hideAmrUI(),this.showSize=!1,this.usePathTracing&&(this.usePathTracing=!1),this._progressShadow.visible=!1},onAfterCapture:()=>{this.scene.background=i,this.showAmrUI(),this.showSize=s,this._progressShadow.visible=!0}}).capture(e)}clearAMR(){ge(this.overlayScene),this.amr.clean(),this.usePathTracing=!1}async exportAMR(){const e=this._container.clone(!0);return e.traverse(t=>{t.dispose&&(t.dispose(),t.removeFromParent())}),await zr.parseAsync(e,{onlyVisible:!0,binary:!0})}async addAMR(e,t=""){this.amr.init(this),await this.amr.load(e,t),this.amr.addEventListener("fork-height-change",this.debounceForkHeightChange),this.amr.addEventListener("shape-key-changed",(i,s)=>{this.pathTracer.reset(),this.sampleCount=0,this.pathTracer.setScene(this.scene,this.camera),this.overlayScene.traverse(a=>{if(!Object.keys(a.morphTargetDictionary||{}).includes(i))return;let n=s;a.userData[`origin_${i}`]&&(n-=a.userData[`origin_${i}`]);const c=a.morphTargetDictionary[i];a.morphTargetInfluences&&(a.morphTargetInfluences[c]=n),a instanceof f.Mesh&&a.geometry.translate(0,0,1e-5)}),["width","length","liftLength","liftWidth","liftOuterWidth"].includes(i)&&(this._progressShadow.clear(),this.debounceForkHeightChange())})}_animateCamera(e,t,i,s,a,n){var h;const c={t:0};(h=this._fitAnimation)==null||h.stop(),this._fitAnimation=new ci(c).to({t:1},a).easing(Le.Easing.Quadratic.InOut).onStart(()=>{this.controls.enabled=!1}).onUpdate(()=>{const d=c.t;this.controls.target.lerpVectors(i,s,d);const p=s.clone(),r=e.clone().sub(p),l=t.clone().sub(p),u=r.length(),g=l.length(),y=u+(g-u)*d;let m;if(u>.001&&g>.001){const v=r.clone().normalize(),_=l.clone().normalize(),x=v.angleTo(_);if(x>.001){const w=new f.Vector3().crossVectors(v,_);if(w.lengthSq()>.001){w.normalize();const b=new f.Quaternion().setFromAxisAngle(w,x*d),T=v.clone().applyQuaternion(b);m=p.clone().add(T.multiplyScalar(y))}else m=p.clone().add(v.multiplyScalar(y))}else m=p.clone().add(v.multiplyScalar(y))}else m=e.clone().lerp(t,d);this.camera.position.copy(m),this.camera.lookAt(this.controls.target)}).onComplete(()=>{this.controls.enabled=!0,n==null||n()}).start()}select(e,t=4){if(this._jumpFlood&&(this._jumpFlood.params.thickness=t),!e){this._selectedForOutline=[];return}typeof e=="string"||(Array.isArray(e)?this._selectedForOutline=[...e]:this._selectedForOutline=[e])}appendTo(e){e.append(this.renderer.domElement),e.append(this.stats.dom),e.append(this.css2dRenderer.domElement),this.props.isMobile?(e.classList.add("is-mobile"),e.style.cssText=`
|
|
3939
3939
|
-webkit-user-select: none;
|
|
3940
3940
|
user-select: none;
|
|
3941
3941
|
touch-action: none;
|
|
3942
3942
|
-webkit-touch-callout: none;
|
|
3943
|
-
`):e.style.background="radial-gradient(326% 141% at 50% 103%, #E0E0E0 0%, #D9D9D9 38%, #C2C2C2 47%, #C2C2C2 52%, #F0F0F0 100%)",this._controlsGizmo&&this._controlsGizmo.appendTo(e),this.stats.dom.style.bottom="0",this.stats.dom.style.top="auto",this.resize(),this._resizeObserver=new ResizeObserver(this.resize.bind(this)),this._resizeObserver.observe(e)}add(e){this._container.add(e)}updatePosition(){}removeFromParent(){var t;const e=this.renderer.domElement.parentElement;e&&((t=this._resizeObserver)==null||t.unobserve(e),e.removeChild(this.renderer.domElement))}clean(){this.amr.clean(),this._progressShadow.clear()}destroy(){var t,i,s,a,n,c;this._destroyed=!0,this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null),this._clock.stop(),(t=this._controlsGizmo)==null||t.destroy(),this.amr.destroy(),this.amr.removeFromParent(),this._progressShadow.destroy(),(i=this._sciFiGrid)==null||i.removeFromParent(),(s=this._sciFiGrid)==null||s.geometry.dispose(),(a=this._sciFiGrid.material)==null||a.dispose(),Le.removeAll(),this.stats.dom.remove(),this._emitter.removeAllListeners(),(n=this._fitAnimation)==null||n.stop(),window.removeEventListener("drag",this._drag),document.removeEventListener("wheel",this._detectTrackpad),window.removeEventListener("pointermove",this._pointermove),this.renderer.domElement.removeEventListener("pointerdown",this._pointerdown);const e=this.renderer.domElement.parentElement;e&&((c=this._resizeObserver)==null||c.unobserve(e)),this.controls.dispose(),this.renderer.domElement.remove(),this.renderer.dispose(),ge(this.scene),this.scene.clear()}}class Kr{constructor(e){this.deps=e,this.canvas=null,this.pixelBuffer=null,this.orthoCamera=new f.OrthographicCamera(-1,1,1,-1,.1,1e3),this.orthoCamera.position.set(0,0,5),this.perspectiveCamera=new f.PerspectiveCamera(45,1,.1,2e3)}async capture(e){var g,y,m,v,_,x;const t=this.deps.renderer,i=(e==null?void 0:e.subject)??this.deps.subject;if(!i)throw new Error("TriViewCapture: subject is required.");const s=new f.Vector2;t.getSize(s);const a=((g=e==null?void 0:e.size)==null?void 0:g.width)??Math.round(s.x),n=((y=e==null?void 0:e.size)==null?void 0:y.height)??Math.round(s.y),c=(e==null?void 0:e.margin)??.15,h=(e==null?void 0:e.includeOverlay)??!1,d=a/n||1,p=this.resolveViews(e==null?void 0:e.views),r=new f.WebGLRenderTarget(a,n,{format:f.RGBAFormat,type:f.UnsignedByteType});r.texture.colorSpace=f.SRGBColorSpace,r.texture.generateMipmaps=!1,r.depthBuffer=!0;const l=this.storeRendererState(t),u={};try{(v=(m=this.deps).onBeforeCapture)==null||v.call(m);const w=this.computeBounds(i);this.applyRendererState(t,a,n,e==null?void 0:e.backgroundColor);for(const b of p){const T=this.configureCamera(w,b,d,c,a,n);t.setRenderTarget(r),t.clear(!0,!0,!0),t.render(this.deps.scene,T),h&&this.deps.overlayScene&&(t.clearDepth(),t.render(this.deps.overlayScene,T));const S=this.readPixels(t,r,a,n);u[b.key]=S}}finally{r.dispose(),this.restoreRendererState(t,l),(x=(_=this.deps).onAfterCapture)==null||x.call(_)}return u}resolveViews(e){return e&&e.length?e.map(t=>({key:t.key,direction:t.direction.clone(),up:t.up.clone(),plane:t.plane})):[{key:"top",direction:new f.Vector3(0,0,1),up:new f.Vector3(0,1,0),plane:{width:"x",height:"y",depth:"z"}},{key:"front",direction:new f.Vector3(0,-1,0),up:new f.Vector3(0,0,1),plane:{width:"x",height:"z",depth:"y"}},{key:"side",direction:new f.Vector3(1,0,0),up:new f.Vector3(0,0,1),plane:{width:"y",height:"z",depth:"x"}},{key:"perspective",direction:new f.Vector3(1,1,1),up:new f.Vector3(0,0,1),plane:{width:"x",height:"z",depth:"y"},mode:"perspective",fov:39.6}]}computeBounds(e){const t=new f.Box3,i=new f.Box3,s=new f.Vector3,a=new f.Vector3,n=new f.Sphere;return e.updateMatrixWorld(!0),e.traverse(c=>{if(!c.visible)return;const d=c.geometry;if(!d)return;d.boundingBox||d.computeBoundingBox();const p=d.boundingBox;p&&(i.copy(p).applyMatrix4(c.matrixWorld),t.union(i))}),t.isEmpty()?(t.setFromCenterAndSize(s,new f.Vector3(.001,.001,.001)),a.set(.001,.001,.001),n.center.copy(s),n.radius=.001):(t.getCenter(s),t.getSize(a),t.getBoundingSphere(n)),(!Number.isFinite(n.radius)||n.radius<=0)&&(n.radius=Math.max(a.length()*.5,.001)),{box:t,center:s,size:a,sphere:n}}configureCamera(e,t,i,s,a,n){const c=t.direction.clone().normalize();c.lengthSq()===0&&c.set(0,0,1);const h=t.up.clone().normalize();if(Math.abs(h.dot(c))>.999&&(h.set(0,0,1),Math.abs(h.dot(c))>.999&&h.set(0,1,0)),(t.mode??"orthographic")==="perspective"){const w=this.perspectiveCamera,b=t.fov??45,T=f.MathUtils.degToRad(b),S=Math.max(Math.tan(T/2),1e-4),I=Math.max(S*(i||1),1e-4),C=this.getPerspectiveDirection(t,e.size).normalize(),L=new f.Vector3().crossVectors(C,h).normalize();L.lengthSq()<1e-6&&L.set(1,0,0);const R=new f.Vector3().crossVectors(L,C).normalize(),A=Math.max(e.size.x*.5,1e-4),M=Math.max(e.size.y*.5,1e-4),D=Math.max(e.size.z*.5,1e-4),P=[new f.Vector3(-A,-M,-D),new f.Vector3(-A,-M,D),new f.Vector3(-A,M,-D),new f.Vector3(-A,M,D),new f.Vector3(A,-M,-D),new f.Vector3(A,-M,D),new f.Vector3(A,M,-D),new f.Vector3(A,M,D)];let E=0,B=-1/0;for(const W of P){const j=L.dot(W),U=R.dot(W),Q=C.dot(W);B=Math.max(B,Q);const re=Q+Math.abs(j)/I,te=Q+Math.abs(U)/S;E=Math.max(E,re,te)}E=Math.max(E,B+.1);const V=E*(1+s);let N=1/0;for(const W of P){const j=C.dot(W),U=V-j;U>.001&&(N=Math.min(N,U))}return w.fov=b,w.aspect=i||a/Math.max(n,1),w.near=Math.max(.1,Number.isFinite(N)?N*.5:V*.1),w.far=Math.max(w.near+1,V+e.sphere.radius*3),w.position.copy(e.center).add(C.clone().multiplyScalar(V)),w.up.copy(R),w.lookAt(e.center),w.updateProjectionMatrix(),w.updateMatrixWorld(!0),w}const p=this.orthoCamera,r=e.size,l=e.center,u=Math.max(r[t.plane.width]*.5,.01),g=Math.max(r[t.plane.height]*.5,.01),y=Math.max(r[t.plane.depth]*.5,.01);let m=u*(1+s),v=g*(1+s);m/i>v?v=m/i:m=v*i;const _=y*(1+s)+Math.max(m,v),x=l.clone().add(c.multiplyScalar(_));return p.left=-m,p.right=m,p.top=v,p.bottom=-v,p.near=.1,p.far=_*4,p.zoom=1,p.position.copy(x),p.up.copy(h),p.lookAt(l),p.updateProjectionMatrix(),p.updateMatrixWorld(!0),p}getPerspectiveDirection(e,t){const i=e.direction.clone();i.lengthSq()===0&&i.set(1,1,1);const s=new f.Vector3(Math.abs(i.x)||1,Math.abs(i.y)||1,Math.abs(i.z)||1),a=new f.Vector3(Math.sign(i.x||1),Math.sign(i.y||1),Math.sign(i.z||1)),n=.25,c=new f.Vector3(Math.max(n,s.x)*Math.max(t.x,.001),Math.max(n,s.y)*Math.max(t.y,.001),0),h=Math.max((t.x+t.y)*.5,.001),d=Math.max(t.z,.001),p=Math.max(n,s.z),r=d*.5+h*.5;return c.z=p*r,c.multiply(a),c}storeRendererState(e){const t=new f.Vector2;e.getSize(t);const i=new f.Vector4;e.getViewport(i);const s=new f.Vector4;e.getScissor(s);const a=e.getClearColor(new f.Color),n=e.getClearAlpha();return{size:t,pixelRatio:e.getPixelRatio(),viewport:i,scissor:s,scissorTest:e.getScissorTest(),autoClear:e.autoClear,target:e.getRenderTarget(),clearColor:a,clearAlpha:n}}applyRendererState(e,t,i,s){if(e.setPixelRatio(1),e.setSize(t,i,!1),e.setViewport(0,0,t,i),e.setScissor(0,0,t,i),e.setScissorTest(!1),e.autoClear=!0,s!==void 0)if(s===null){const a=e.getClearColor(new f.Color);e.setClearColor(a,0)}else s instanceof f.Color?e.setClearColor(s,1):e.setClearColor(new f.Color(s),1);else{const a=e.getClearColor(new f.Color);e.setClearColor(a,0)}}restoreRendererState(e,t){e.setPixelRatio(t.pixelRatio),e.setSize(t.size.x,t.size.y,!1),e.setViewport(t.viewport.x,t.viewport.y,t.viewport.z,t.viewport.w),e.setScissor(t.scissor.x,t.scissor.y,t.scissor.z,t.scissor.w),e.setScissorTest(t.scissorTest),e.autoClear=t.autoClear,e.setRenderTarget(t.target),e.setClearColor(t.clearColor,t.clearAlpha)}readPixels(e,t,i,s){const a=i*s*4;(!this.pixelBuffer||this.pixelBuffer.length!==a)&&(this.pixelBuffer=new Uint8Array(a)),e.readRenderTargetPixels(t,0,0,i,s,this.pixelBuffer);const n=this.ensureCanvas(i,s),c=n.getContext("2d");if(!c)throw new Error("TriViewCapture: failed to get 2D context.");const h=c.createImageData(i,s),d=h.data,p=this.pixelBuffer;for(let r=0;r<s;r+=1){const u=(s-r-1)*i*4,g=r*i*4;d.set(p.subarray(u,u+i*4),g)}return c.putImageData(h,0,0),n.toDataURL("image/png")}ensureCanvas(e,t){if(typeof document>"u")throw new Error("TriViewCapture: document is not available in this environment.");return this.canvas||(this.canvas=document.createElement("canvas")),(this.canvas.width!==e||this.canvas.height!==t)&&(this.canvas.width=e,this.canvas.height=t),this.canvas}}const Tc="shop-components",Sc="0.4.16",Mc="Shop components",Cc="dist/shop-components.umd.js",Rc="dist/shop-components.mjs",Ic="dist/main.d.ts",Dc={dts:"tsc --emitDeclarationOnly & tsc & storybook build -o dist",dev:"vite dev",build:"vite build","build:web":"BUILD_WEB=1 vite build --outDir dist/web --emptyOutDir",v:"auto-changelog -p && git add CHANGELOG.md"},Lc=["dist","package.json"],Pc=[],Fc="machengda<machengda@seer-group.com>",Ec="ISC",Bc={"@needle-tools/gltf-progressive":"^3.3.5","auto-changelog":"^2.4.0",vite:"5.1.6","vite-plugin-dts":"^3.7.3"},kc={"string-width":"4.2.3"},Oc={"@nodetoy/three-nodetoy":"^0.1.36","@tweakpane/core":"^2.0.3","@tweenjs/tween.js":"^23.1.2","@types/bezier-js":"^4.1.1","@types/howler":"^2.2.11","@types/three":"0.182.0","bezier-js":"^6.1.4",eventemitter3:"^5.0.1",howler:"^2.2.4","stats-fps.js":"0.0.6",stylus:"^0.63.0",terser:"^5.44.0",three:"0.182.0","three-gpu-pathtracer":"^0.0.23","three-mesh-bvh":"^0.7.5","troika-three-text":"^0.49.1",tweakpane:"^4.0.3"},zc={name:Tc,version:Sc,description:Mc,main:Cc,module:Rc,types:Ic,scripts:Dc,files:Lc,keywords:Pc,author:Fc,license:Ec,devDependencies:Bc,resolutions:kc,dependencies:Oc};function dr(){const o="Nebula Engin",e=zc.version,t=`%c ${o} %c v${e} `;console.log(t,"background:#111827;color:#ffffff;padding:4px 10px;border-radius:4px 0 0 4px;font-weight:700;","background:#10B981;color:#ffffff;padding:4px 10px;border-radius:0 4px 4px 0;font-weight:700;")}const pr="__SHOP_COMPONENTS_BANNER_PRINTED__";try{const o=globalThis;o[pr]||(o[pr]=!0,dr())}catch{dr()}exports.Amr=Hr;exports.Logo=Qi;exports.SGLBLoader=Et;exports.SLOT_EVENTS=K;exports.Scene3D=Ac;exports.Skin=ss;exports.Slot=ji;exports.SlotState=Zr;exports.TriViewCapture=Kr;exports.arrayBufferToUrl=Gi;exports.calculateArrayAverage=Br;exports.calculateFocalLength=Ea;exports.createSGLBFile=Ga;exports.downloadBlob=Fa;exports.dracoExporter=Na;exports.font=xc;exports.gltfExporter=zr;exports.gltfLoader=He;exports.imageBitmapToUrl=qi;exports.isAppleDevice=kr;exports.textureLoader=fs;
|
|
3943
|
+
`):e.style.background="radial-gradient(326% 141% at 50% 103%, #E0E0E0 0%, #D9D9D9 38%, #C2C2C2 47%, #C2C2C2 52%, #F0F0F0 100%)",this._controlsGizmo&&this._controlsGizmo.appendTo(e),this.stats.dom.style.bottom="0",this.stats.dom.style.top="auto",this.resize(),this._resizeObserver=new ResizeObserver(this.resize.bind(this)),this._resizeObserver.observe(e)}add(e){this._container.add(e)}updatePosition(){}removeFromParent(){var t;const e=this.renderer.domElement.parentElement;e&&((t=this._resizeObserver)==null||t.unobserve(e),e.removeChild(this.renderer.domElement))}clean(){this.amr.clean(),this._progressShadow.clear()}destroy(){var t,i,s,a,n,c;this._destroyed=!0,this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null),this._clock.stop(),(t=this._controlsGizmo)==null||t.destroy(),this.amr.destroy(),this.amr.removeFromParent(),this._progressShadow.destroy(),(i=this._sciFiGrid)==null||i.removeFromParent(),(s=this._sciFiGrid)==null||s.geometry.dispose(),(a=this._sciFiGrid.material)==null||a.dispose(),Le.removeAll(),this.stats.dom.remove(),this._emitter.removeAllListeners(),(n=this._fitAnimation)==null||n.stop(),window.removeEventListener("drag",this._drag),document.removeEventListener("wheel",this._detectTrackpad),window.removeEventListener("pointermove",this._pointermove),this.renderer.domElement.removeEventListener("pointerdown",this._pointerdown);const e=this.renderer.domElement.parentElement;e&&((c=this._resizeObserver)==null||c.unobserve(e)),this.controls.dispose(),this.renderer.domElement.remove(),this.renderer.dispose(),ge(this.scene),this.scene.clear()}}class Kr{constructor(e){this.deps=e,this.canvas=null,this.pixelBuffer=null,this.orthoCamera=new f.OrthographicCamera(-1,1,1,-1,.1,1e3),this.orthoCamera.position.set(0,0,5),this.perspectiveCamera=new f.PerspectiveCamera(45,1,.1,2e3)}async capture(e){var g,y,m,v,_,x;const t=this.deps.renderer,i=(e==null?void 0:e.subject)??this.deps.subject;if(!i)throw new Error("TriViewCapture: subject is required.");const s=new f.Vector2;t.getSize(s);const a=((g=e==null?void 0:e.size)==null?void 0:g.width)??Math.round(s.x),n=((y=e==null?void 0:e.size)==null?void 0:y.height)??Math.round(s.y),c=(e==null?void 0:e.margin)??.15,h=(e==null?void 0:e.includeOverlay)??!1,d=a/n||1,p=this.resolveViews(e==null?void 0:e.views),r=new f.WebGLRenderTarget(a,n,{format:f.RGBAFormat,type:f.UnsignedByteType});r.texture.colorSpace=f.SRGBColorSpace,r.texture.generateMipmaps=!1,r.depthBuffer=!0;const l=this.storeRendererState(t),u={};try{(v=(m=this.deps).onBeforeCapture)==null||v.call(m);const w=this.computeBounds(i);this.applyRendererState(t,a,n,e==null?void 0:e.backgroundColor);for(const b of p){const T=this.configureCamera(w,b,d,c,a,n);t.setRenderTarget(r),t.clear(!0,!0,!0),t.render(this.deps.scene,T),h&&this.deps.overlayScene&&(t.clearDepth(),t.render(this.deps.overlayScene,T));const S=this.readPixels(t,r,a,n);u[b.key]=S}}finally{r.dispose(),this.restoreRendererState(t,l),(x=(_=this.deps).onAfterCapture)==null||x.call(_)}return u}resolveViews(e){return e&&e.length?e.map(t=>({key:t.key,direction:t.direction.clone(),up:t.up.clone(),plane:t.plane})):[{key:"top",direction:new f.Vector3(0,0,1),up:new f.Vector3(0,1,0),plane:{width:"x",height:"y",depth:"z"}},{key:"front",direction:new f.Vector3(0,-1,0),up:new f.Vector3(0,0,1),plane:{width:"x",height:"z",depth:"y"}},{key:"side",direction:new f.Vector3(1,0,0),up:new f.Vector3(0,0,1),plane:{width:"y",height:"z",depth:"x"}},{key:"perspective",direction:new f.Vector3(1,1,1),up:new f.Vector3(0,0,1),plane:{width:"x",height:"z",depth:"y"},mode:"perspective",fov:39.6}]}computeBounds(e){const t=new f.Box3,i=new f.Box3,s=new f.Vector3,a=new f.Vector3,n=new f.Sphere;return e.updateMatrixWorld(!0),e.traverse(c=>{if(!c.visible)return;const d=c.geometry;if(!d)return;d.boundingBox||d.computeBoundingBox();const p=d.boundingBox;p&&(i.copy(p).applyMatrix4(c.matrixWorld),t.union(i))}),t.isEmpty()?(t.setFromCenterAndSize(s,new f.Vector3(.001,.001,.001)),a.set(.001,.001,.001),n.center.copy(s),n.radius=.001):(t.getCenter(s),t.getSize(a),t.getBoundingSphere(n)),(!Number.isFinite(n.radius)||n.radius<=0)&&(n.radius=Math.max(a.length()*.5,.001)),{box:t,center:s,size:a,sphere:n}}configureCamera(e,t,i,s,a,n){const c=t.direction.clone().normalize();c.lengthSq()===0&&c.set(0,0,1);const h=t.up.clone().normalize();if(Math.abs(h.dot(c))>.999&&(h.set(0,0,1),Math.abs(h.dot(c))>.999&&h.set(0,1,0)),(t.mode??"orthographic")==="perspective"){const w=this.perspectiveCamera,b=t.fov??45,T=f.MathUtils.degToRad(b),S=Math.max(Math.tan(T/2),1e-4),I=Math.max(S*(i||1),1e-4),C=this.getPerspectiveDirection(t,e.size).normalize(),L=new f.Vector3().crossVectors(C,h).normalize();L.lengthSq()<1e-6&&L.set(1,0,0);const R=new f.Vector3().crossVectors(L,C).normalize(),A=Math.max(e.size.x*.5,1e-4),M=Math.max(e.size.y*.5,1e-4),D=Math.max(e.size.z*.5,1e-4),P=[new f.Vector3(-A,-M,-D),new f.Vector3(-A,-M,D),new f.Vector3(-A,M,-D),new f.Vector3(-A,M,D),new f.Vector3(A,-M,-D),new f.Vector3(A,-M,D),new f.Vector3(A,M,-D),new f.Vector3(A,M,D)];let E=0,B=-1/0;for(const W of P){const j=L.dot(W),U=R.dot(W),Q=C.dot(W);B=Math.max(B,Q);const re=Q+Math.abs(j)/I,te=Q+Math.abs(U)/S;E=Math.max(E,re,te)}E=Math.max(E,B+.1);const V=E*(1+s);let N=1/0;for(const W of P){const j=C.dot(W),U=V-j;U>.001&&(N=Math.min(N,U))}return w.fov=b,w.aspect=i||a/Math.max(n,1),w.near=Math.max(.1,Number.isFinite(N)?N*.5:V*.1),w.far=Math.max(w.near+1,V+e.sphere.radius*3),w.position.copy(e.center).add(C.clone().multiplyScalar(V)),w.up.copy(R),w.lookAt(e.center),w.updateProjectionMatrix(),w.updateMatrixWorld(!0),w}const p=this.orthoCamera,r=e.size,l=e.center,u=Math.max(r[t.plane.width]*.5,.01),g=Math.max(r[t.plane.height]*.5,.01),y=Math.max(r[t.plane.depth]*.5,.01);let m=u*(1+s),v=g*(1+s);m/i>v?v=m/i:m=v*i;const _=y*(1+s)+Math.max(m,v),x=l.clone().add(c.multiplyScalar(_));return p.left=-m,p.right=m,p.top=v,p.bottom=-v,p.near=.1,p.far=_*4,p.zoom=1,p.position.copy(x),p.up.copy(h),p.lookAt(l),p.updateProjectionMatrix(),p.updateMatrixWorld(!0),p}getPerspectiveDirection(e,t){const i=e.direction.clone();i.lengthSq()===0&&i.set(1,1,1);const s=new f.Vector3(Math.abs(i.x)||1,Math.abs(i.y)||1,Math.abs(i.z)||1),a=new f.Vector3(Math.sign(i.x||1),Math.sign(i.y||1),Math.sign(i.z||1)),n=.25,c=new f.Vector3(Math.max(n,s.x)*Math.max(t.x,.001),Math.max(n,s.y)*Math.max(t.y,.001),0),h=Math.max((t.x+t.y)*.5,.001),d=Math.max(t.z,.001),p=Math.max(n,s.z),r=d*.5+h*.5;return c.z=p*r,c.multiply(a),c}storeRendererState(e){const t=new f.Vector2;e.getSize(t);const i=new f.Vector4;e.getViewport(i);const s=new f.Vector4;e.getScissor(s);const a=e.getClearColor(new f.Color),n=e.getClearAlpha();return{size:t,pixelRatio:e.getPixelRatio(),viewport:i,scissor:s,scissorTest:e.getScissorTest(),autoClear:e.autoClear,target:e.getRenderTarget(),clearColor:a,clearAlpha:n}}applyRendererState(e,t,i,s){if(e.setPixelRatio(1),e.setSize(t,i,!1),e.setViewport(0,0,t,i),e.setScissor(0,0,t,i),e.setScissorTest(!1),e.autoClear=!0,s!==void 0)if(s===null){const a=e.getClearColor(new f.Color);e.setClearColor(a,0)}else s instanceof f.Color?e.setClearColor(s,1):e.setClearColor(new f.Color(s),1);else{const a=e.getClearColor(new f.Color);e.setClearColor(a,0)}}restoreRendererState(e,t){e.setPixelRatio(t.pixelRatio),e.setSize(t.size.x,t.size.y,!1),e.setViewport(t.viewport.x,t.viewport.y,t.viewport.z,t.viewport.w),e.setScissor(t.scissor.x,t.scissor.y,t.scissor.z,t.scissor.w),e.setScissorTest(t.scissorTest),e.autoClear=t.autoClear,e.setRenderTarget(t.target),e.setClearColor(t.clearColor,t.clearAlpha)}readPixels(e,t,i,s){const a=i*s*4;(!this.pixelBuffer||this.pixelBuffer.length!==a)&&(this.pixelBuffer=new Uint8Array(a)),e.readRenderTargetPixels(t,0,0,i,s,this.pixelBuffer);const n=this.ensureCanvas(i,s),c=n.getContext("2d");if(!c)throw new Error("TriViewCapture: failed to get 2D context.");const h=c.createImageData(i,s),d=h.data,p=this.pixelBuffer;for(let r=0;r<s;r+=1){const u=(s-r-1)*i*4,g=r*i*4;d.set(p.subarray(u,u+i*4),g)}return c.putImageData(h,0,0),n.toDataURL("image/png")}ensureCanvas(e,t){if(typeof document>"u")throw new Error("TriViewCapture: document is not available in this environment.");return this.canvas||(this.canvas=document.createElement("canvas")),(this.canvas.width!==e||this.canvas.height!==t)&&(this.canvas.width=e,this.canvas.height=t),this.canvas}}const Tc="shop-components",Sc="0.4.17",Mc="Shop components",Cc="dist/shop-components.umd.js",Rc="dist/shop-components.mjs",Ic="dist/main.d.ts",Dc={dts:"tsc --emitDeclarationOnly & tsc & storybook build -o dist",dev:"vite dev",build:"vite build","build:web":"BUILD_WEB=1 vite build --outDir dist/web --emptyOutDir",v:"auto-changelog -p && git add CHANGELOG.md"},Lc=["dist","package.json"],Pc=[],Fc="machengda<machengda@seer-group.com>",Ec="ISC",Bc={"@needle-tools/gltf-progressive":"^3.3.5","auto-changelog":"^2.4.0",vite:"5.1.6","vite-plugin-dts":"^3.7.3"},kc={"string-width":"4.2.3"},Oc={"@nodetoy/three-nodetoy":"^0.1.36","@tweakpane/core":"^2.0.3","@tweenjs/tween.js":"^23.1.2","@types/bezier-js":"^4.1.1","@types/howler":"^2.2.11","@types/three":"0.182.0","bezier-js":"^6.1.4",eventemitter3:"^5.0.1",howler:"^2.2.4","stats-fps.js":"0.0.6",stylus:"^0.63.0",terser:"^5.44.0",three:"0.182.0","three-gpu-pathtracer":"^0.0.23","three-mesh-bvh":"^0.7.5","troika-three-text":"^0.49.1",tweakpane:"^4.0.3"},zc={name:Tc,version:Sc,description:Mc,main:Cc,module:Rc,types:Ic,scripts:Dc,files:Lc,keywords:Pc,author:Fc,license:Ec,devDependencies:Bc,resolutions:kc,dependencies:Oc};function dr(){const o="Nebula Engin",e=zc.version,t=`%c ${o} %c v${e} `;console.log(t,"background:#111827;color:#ffffff;padding:4px 10px;border-radius:4px 0 0 4px;font-weight:700;","background:#10B981;color:#ffffff;padding:4px 10px;border-radius:0 4px 4px 0;font-weight:700;")}const pr="__SHOP_COMPONENTS_BANNER_PRINTED__";try{const o=globalThis;o[pr]||(o[pr]=!0,dr())}catch{dr()}exports.Amr=Hr;exports.Logo=Qi;exports.SGLBLoader=Et;exports.SLOT_EVENTS=K;exports.Scene3D=Ac;exports.Skin=ss;exports.Slot=ji;exports.SlotState=Zr;exports.TriViewCapture=Kr;exports.arrayBufferToUrl=Gi;exports.calculateArrayAverage=Br;exports.calculateFocalLength=Ea;exports.createSGLBFile=Ga;exports.downloadBlob=Fa;exports.dracoExporter=Na;exports.font=xc;exports.gltfExporter=zr;exports.gltfLoader=He;exports.imageBitmapToUrl=qi;exports.isAppleDevice=kr;exports.textureLoader=fs;
|
package/dist/shop-components.mjs
CHANGED
|
@@ -13663,9 +13663,9 @@ class Mu {
|
|
|
13663
13663
|
}), this._mainCamera = this.camera, this._progressShadow = new bh(this.renderer, this.scene, {
|
|
13664
13664
|
size: 8,
|
|
13665
13665
|
lightCount: 12,
|
|
13666
|
-
frames:
|
|
13667
|
-
lightRadius:
|
|
13668
|
-
ambientWeight: 0.
|
|
13666
|
+
frames: e.isMobile ? 20 : 60,
|
|
13667
|
+
lightRadius: 2,
|
|
13668
|
+
ambientWeight: 0.8
|
|
13669
13669
|
}), this._progressShadow.lightOrigin.position.set(3, 2.5, 0.6), this._progressShadow.visible = !1, this._container.add(this.amr), this.scene.add(this._container), this.ticker(0), this._loadEnv(), this._initEvents(), this.scene.add(this._cameraPositionUI), this._ground.rotateX(-Math.PI / 2), this.scene.add(this._ground), this._jumpFlood = new Rh(this.renderer, this.scene, this.camera, {
|
|
13670
13670
|
thickness: 4,
|
|
13671
13671
|
color: "#fff"
|
|
@@ -14102,7 +14102,7 @@ class Oh {
|
|
|
14102
14102
|
return this.canvas || (this.canvas = document.createElement("canvas")), (this.canvas.width !== e || this.canvas.height !== t) && (this.canvas.width = e, this.canvas.height = t), this.canvas;
|
|
14103
14103
|
}
|
|
14104
14104
|
}
|
|
14105
|
-
const zh = "shop-components", Uh = "0.4.
|
|
14105
|
+
const zh = "shop-components", Uh = "0.4.17", Hh = "Shop components", Wh = "dist/shop-components.umd.js", Nh = "dist/shop-components.mjs", Vh = "dist/main.d.ts", Gh = {
|
|
14106
14106
|
dts: "tsc --emitDeclarationOnly & tsc & storybook build -o dist",
|
|
14107
14107
|
dev: "vite dev",
|
|
14108
14108
|
build: "vite build",
|