a3js 0.0.49 → 0.0.50

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/a3js.cjs.js CHANGED
@@ -289,5 +289,5 @@ See: https://chevrotain.io/docs/changes/BREAKING_CHANGES.html#_7-0-0`)}return I}
289
289
  <button class="btn left">L</button>
290
290
  <button class="btn right">R</button>
291
291
  </div>
292
- `,this.canvas=this.shadowRoot.querySelector("canvas-a3"),this.scene=this.canvas.scene,this.camera=this.canvas.camera,this.controller=this.canvas.controller,this._maxDistance=40,this._leftActive=!1,this._leftCenter={x:0,y:0},this.leftJoystick={x:0,y:0},this._rightActive=!1,this._rightCenter={x:0,y:0},this.rightJoystick={x:0,y:0},this.leftButton=!1,this.rightButton=!1,this.keys=new Set,this._leftButtonCount=0,this._rightButtonCount=0;const t=this.shadowRoot.querySelector(".joystick.left .stick");if(!t)return;t.addEventListener("pointerdown",s=>{this._leftActive=!0;const c=t.getBoundingClientRect();this._leftCenter.x=c.left+c.width/2,this._leftCenter.y=c.top+c.height/2,t.setPointerCapture(s.pointerId)}),t.addEventListener("pointermove",s=>{if(!this._leftActive)return;const c=s.clientX-this._leftCenter.x,A=s.clientY-this._leftCenter.y,a=Math.sqrt(c*c+A*A);let d=c,u=A;if(a>40){const m=Math.atan2(A,c);d=Math.cos(m)*this._maxDistance,u=Math.sin(m)*this._maxDistance}t.style.transform=`translate(calc(-50% + ${d}px), calc(-50% + ${u}px))`,this.leftJoystick.x=d/this._maxDistance,this.leftJoystick.y=-(u/this._maxDistance)}),t.addEventListener("pointerup",()=>{this._leftActive=!1,t.style.transform="translate(-50%, -50%)",this.leftJoystick.x=0,this.leftJoystick.y=0});const n=this.shadowRoot.querySelector(".joystick.right .stick");if(!n)return;n.addEventListener("pointerdown",s=>{this._rightActive=!0;const c=n.getBoundingClientRect();this._rightCenter.x=c.left+c.width/2,this._rightCenter.y=c.top+c.height/2,n.setPointerCapture(s.pointerId)}),n.addEventListener("pointermove",s=>{if(!this._rightActive)return;const c=s.clientX-this._rightCenter.x,A=s.clientY-this._rightCenter.y,a=Math.sqrt(c*c+A*A);let d=c,u=A;if(a>40){const m=Math.atan2(A,c);d=Math.cos(m)*this._maxDistance,u=Math.sin(m)*this._maxDistance}n.style.transform=`translate(calc(-50% + ${d}px), calc(-50% + ${u}px))`,this.rightJoystick.x=d/this._maxDistance,this.rightJoystick.y=-(u/this._maxDistance)}),n.addEventListener("pointerup",()=>{this._rightActive=!1,n.style.transform="translate(-50%, -50%)",this.rightJoystick.x=0,this.rightJoystick.y=0});const r=this.shadowRoot.querySelector(".btn.left");if(!r)return;r.addEventListener("pointerdown",()=>{this.leftButton=!0,this._leftButtonCount++}),r.addEventListener("pointerup",()=>{this.leftButton=!1});const o=this.shadowRoot.querySelector(".btn.right");o&&(o.addEventListener("pointerdown",()=>{this.rightButton=!0,this._rightButtonCount++}),o.addEventListener("pointerup",()=>{this.rightButton=!1}),window.addEventListener("keydown",this.keyDownListener),window.addEventListener("keyup",this.keyUpListener),this.options.touchDevice||(this.shadowRoot.querySelectorAll(".joystick").forEach(s=>{s.style.display="none"}),this.shadowRoot.querySelectorAll(".btn").forEach(s=>{s.style.display="none"})))}keyDownListener=e=>{this.keys.add(e.code),this.updateUIFromKeyInfo()};keyUpListener=e=>{this.keys.delete(e.code),this.updateUIFromKeyInfo()};connectedCallback(){this._ro=new ResizeObserver(e=>{const t=e[0],n=t.contentRect.width,r=t.contentRect.height;if(!(n===0||r===0))if(n>r){const o=this.shadowRoot.querySelector(".btn.left");o.style.bottom="50px",o.style.left="200px";const s=this.shadowRoot.querySelector(".btn.right");s.style.bottom="50px",s.style.right="200px"}else{const o=this.shadowRoot.querySelector(".btn.left");o.style.bottom="200px",o.style.left="50px";const s=this.shadowRoot.querySelector(".btn.right");s.style.bottom="200px",s.style.right="50px"}}),this._ro.observe(this)}disconnectedCallback(){this._ro?.disconnect(),window.removeEventListener("keydown",this.keyDownListener),window.removeEventListener("keyup",this.keyUpListener)}updateUIFromKeyInfo(){const e={x:0,y:0},t={x:0,y:0};this.keys.has("KeyW")&&(e.y+=1),this.keys.has("KeyA")&&(e.x-=1),this.keys.has("KeyS")&&(e.y-=1),this.keys.has("KeyD")&&(e.x+=1),this.keys.has("ArrowUp")&&(t.y+=1),this.keys.has("ArrowLeft")&&(t.x-=1),this.keys.has("ArrowDown")&&(t.y-=1),this.keys.has("ArrowRight")&&(t.x+=1);const n=Math.sqrt(e.x*e.x+e.y*e.y);n>0&&(e.x/=n,e.y/=n),this.leftJoystick=e;const r=Math.sqrt(t.x*t.x+t.y*t.y);r>0&&(t.x/=r,t.y/=r),this.rightJoystick=t,this.keys.has("Space")?(this.leftButton=!0,this._leftButtonCount++):this.leftButton=!1,this.keys.has("Enter")?(this.rightButton=!0,this._rightButtonCount++):this.rightButton=!1}getLeftButtonCount(){const e=this._leftButtonCount;return this._leftButtonCount=0,e}getRightButtonCount(){const e=this._rightButtonCount;return this._rightButtonCount=0,e}replaceScene(e){return this.canvas.replaceScene(e)}setController(e){this.canvas.setController(e)}worldToScreen(e){return this.canvas.worldToScreen(e)}screenToWorld(e,t,n){return this.canvas.screenToWorld(e,t,n)}cameraToScreen(e){return this.canvas.cameraToScreen(e)}screenToCamera(e,t,n){return this.canvas.screenToCamera(e,t,n)}waitForRender(){return this.canvas.waitForRender()}alert(e,t){return this.canvas.alert(e,t)}prompt(e,t){return this.canvas.prompt(e,t)}setShadowMap(e){this.canvas.setShadowMap(e)}}customElements.define("game-canvas-a3",mr);const Er={mass:10,defaultLocation:{x:0,y:1,z:0},defaultQuat:{x:0,y:0,z:0,w:1},chassisWidth:2,chassisHeight:1,chassisLength:4,chassisOffset:{x:0,y:-.5,z:0},chassisFriction:.1,wheelFrontYPosition:0,wheelFrontZPosition:1.5,wheelFrontAxleLength:2,wheelRearYPosition:0,wheelRearZPosition:-1.5,wheelRearAxleLength:2,wheelFrontRadius:.3,wheelRearRadius:.3,wheelFrontWidth:.4,wheelRearWidth:.4,wheelFrontSuspensionRestLength:.8,wheelRearSuspensionRestLength:.8,wheelFrontDirection:{x:0,y:-1,z:0},wheelRearDirection:{x:0,y:-1,z:0},wheelFrontAxle:{x:-1,y:0,z:0},wheelRearAxle:{x:-1,y:0,z:0},wheelFrontSuspensionStiffness:24,wheelRearSuspensionStiffness:24,wheelFrontSuspensionCompression:4,wheelRearSuspensionCompression:4,wheelFrontSuspensionRelaxation:3,wheelRearSuspensionRelaxation:3,wheelFrontWheelFrictionSlip:100,wheelRearWheelFrictionSlip:100,wheelFrontMaxSuspensionTravel:.25,wheelRearMaxSuspensionTravel:.25,aerodynamicDrag:0};class ra{opt;trans;motion;constructor(e){this.opt={...Er,...e},this.trans=new Ir(this),this.motion=new br(this)}steer(e){this.trans.controller&&(this.trans.controller.setWheelSteering(0,e),this.trans.controller.setWheelSteering(1,e))}accelerate(e){this.trans.controller&&(this.trans.controller.setWheelEngineForce(0,e),this.trans.controller.setWheelEngineForce(1,e),this.trans.controller.setWheelEngineForce(2,e),this.trans.controller.setWheelEngineForce(3,e))}brake(e){this.trans.controller&&(this.trans.controller.setWheelBrake(0,e),this.trans.controller.setWheelBrake(1,e),this.trans.controller.setWheelBrake(2,e),this.trans.controller.setWheelBrake(3,e))}reset(e,t){this.trans.chassisBody&&(e?this.trans.chassisBody.setTranslation({x:e.x,y:e.y,z:e.z},!0):this.trans.chassisBody.setTranslation(this.opt.defaultLocation,!0),t?this.trans.chassisBody.setRotation({x:t.x,y:t.y,z:t.z,w:t.w},!0):this.trans.chassisBody.setRotation(this.opt.defaultQuat,!0),this.trans.chassisBody.setLinvel({x:0,y:0,z:0},!0),this.trans.chassisBody.setAngvel({x:0,y:0,z:0},!0))}}class Ir{cc;transform;objectA3;controller;chassisBodyDesc;chassisBody;chassisColliderDesc;chassisCollider;constructor(e){this.cc=e,this.transform=new ze}init(e,t){this.transform.set(e),this.objectA3=t,this.chassisBodyDesc=new Pe.RigidBodyDesc(Pe.RigidBodyType.Dynamic),this.chassisColliderDesc=Pe.ColliderDesc.cuboid(this.cc.opt.chassisWidth/2,this.cc.opt.chassisHeight/2,this.cc.opt.chassisLength/2),this.chassisColliderDesc.setMass(this.cc.opt.mass),this.chassisColliderDesc.setFriction(this.cc.opt.chassisFriction)}addOneselfToPhysics(e){if(this.chassisBodyDesc&&(this.chassisBody=e.world.createRigidBody(this.chassisBodyDesc),this.chassisBody.setTranslation(this.cc.opt.defaultLocation,!0),this.chassisBody.setRotation(this.cc.opt.defaultQuat,!0)),this.chassisColliderDesc&&(this.chassisCollider=e.world.createCollider(this.chassisColliderDesc,this.chassisBody)),this.chassisCollider&&this.objectA3&&tt.set(this.chassisCollider.handle,this.objectA3),this.chassisBody&&(this.controller=e.world.createVehicleController(this.chassisBody)),this.controller){const t={x:0,y:0,z:0};t.x=-this.cc.opt.wheelFrontAxleLength/2,t.y=this.cc.opt.wheelFrontYPosition,t.z=this.cc.opt.wheelFrontZPosition,this.controller.addWheel(t,this.cc.opt.wheelFrontDirection,this.cc.opt.wheelFrontAxle,this.cc.opt.wheelFrontSuspensionRestLength,this.cc.opt.wheelFrontRadius),this.controller.setWheelSuspensionStiffness(0,this.cc.opt.wheelFrontSuspensionStiffness),this.controller.setWheelSuspensionCompression(0,this.cc.opt.wheelFrontSuspensionCompression),this.controller.setWheelSuspensionRelaxation(0,this.cc.opt.wheelFrontSuspensionRelaxation),this.controller.setWheelFrictionSlip(0,this.cc.opt.wheelFrontWheelFrictionSlip),this.controller.setWheelMaxSuspensionTravel(0,this.cc.opt.wheelFrontMaxSuspensionTravel),t.x=this.cc.opt.wheelFrontAxleLength/2,t.y=this.cc.opt.wheelFrontYPosition,t.z=this.cc.opt.wheelFrontZPosition,this.controller.addWheel(t,this.cc.opt.wheelFrontDirection,this.cc.opt.wheelFrontAxle,this.cc.opt.wheelFrontSuspensionRestLength,this.cc.opt.wheelFrontRadius),this.controller.setWheelSuspensionStiffness(1,this.cc.opt.wheelFrontSuspensionStiffness),this.controller.setWheelSuspensionCompression(1,this.cc.opt.wheelFrontSuspensionCompression),this.controller.setWheelSuspensionRelaxation(1,this.cc.opt.wheelFrontSuspensionRelaxation),this.controller.setWheelFrictionSlip(1,this.cc.opt.wheelFrontWheelFrictionSlip),this.controller.setWheelMaxSuspensionTravel(1,this.cc.opt.wheelFrontMaxSuspensionTravel),t.x=-this.cc.opt.wheelRearAxleLength/2,t.y=this.cc.opt.wheelRearYPosition,t.z=this.cc.opt.wheelRearZPosition,this.controller.addWheel(t,this.cc.opt.wheelRearDirection,this.cc.opt.wheelRearAxle,this.cc.opt.wheelRearSuspensionRestLength,this.cc.opt.wheelRearRadius),this.controller.setWheelSuspensionStiffness(2,this.cc.opt.wheelRearSuspensionStiffness),this.controller.setWheelSuspensionCompression(2,this.cc.opt.wheelRearSuspensionCompression),this.controller.setWheelSuspensionRelaxation(2,this.cc.opt.wheelRearSuspensionRelaxation),this.controller.setWheelFrictionSlip(2,this.cc.opt.wheelRearWheelFrictionSlip),this.controller.setWheelMaxSuspensionTravel(2,this.cc.opt.wheelRearMaxSuspensionTravel),t.x=this.cc.opt.wheelRearAxleLength/2,t.y=this.cc.opt.wheelRearYPosition,t.z=this.cc.opt.wheelRearZPosition,this.controller.addWheel(t,this.cc.opt.wheelRearDirection,this.cc.opt.wheelRearAxle,this.cc.opt.wheelRearSuspensionRestLength,this.cc.opt.wheelRearRadius),this.controller.setWheelSuspensionStiffness(3,this.cc.opt.wheelRearSuspensionStiffness),this.controller.setWheelSuspensionCompression(3,this.cc.opt.wheelRearSuspensionCompression),this.controller.setWheelSuspensionRelaxation(3,this.cc.opt.wheelRearSuspensionRelaxation),this.controller.setWheelFrictionSlip(3,this.cc.opt.wheelRearWheelFrictionSlip),this.controller.setWheelMaxSuspensionTravel(3,this.cc.opt.wheelRearMaxSuspensionTravel)}}removeOneselfFromPhysics(e){this.chassisCollider&&(e.world.removeCollider(this.chassisCollider,!0),tt.delete(this.chassisCollider.handle),this.chassisCollider=void 0),this.chassisBody&&e.world.removeRigidBody(this.chassisBody),this.chassisBody=void 0}setPosition(e){}setPositionNow(e){}setQuat(e){}setQuatNow(e){}setScale(e){}setScaleNow(e){}setLinearVelocity(e){}getLinearVelocity(e){return e||(e=new ae),this.chassisBody?e.set(this.chassisBody.linvel()):this.chassisBodyDesc&&e.set(this.chassisBodyDesc.linvel),e}setAngularVelocity(e){}getAngularVelocity(e){return e||(e=new ae),this.chassisBody?e.set(this.chassisBody.angvel()):this.chassisBodyDesc&&e.set(this.chassisBodyDesc.angvel),e}resetForce(){}addForce(e){}addForceAtPoint(e,t){}resetTorque(){}addTorque(e){}applyImpulse(e){}applyImpulseAtPoint(e,t){}applyTorqueImpulse(e){}isGrounded(){if(!this.controller)return!0;let e=!1;return e||=this.controller.wheelIsInContact(0),e||=this.controller.wheelIsInContact(1),e||=this.controller.wheelIsInContact(2),e||=this.controller.wheelIsInContact(3),e}vv=new ae;update(e){if(this.cc.opt.aerodynamicDrag>0&&this.chassisBody){const t=new ae(this.chassisBody.linvel());Math.abs(t.y)>3&&t.set(t.x,3*t.y/Math.abs(t.y),t.z),this.vv.lerp(this.vv,t,.9);const n=this.vv.length();n!==0&&(t.set(this.vv),t.normalize(),t.scale(-n*n*this.cc.opt.aerodynamicDrag),this.chassisBody.resetForces(!0),this.chassisBody.addForce({x:t.x,y:t.y,z:t.z},!0))}this.controller?.updateVehicle(e),this.chassisBody&&this.transform.loc.set(this.chassisBody.translation()),this.chassisBody&&this.transform.quat.set(this.chassisBody.rotation())}}class br{cm;name;playCount;time;finishListener;constructor(e){this.cm=e,this.name="default",this.playCount=0,this.time=0}addOneselfToPhysics(e){}removeOneselfFromPhysics(e){}setPause(e){}setTime(e){}setFinishListener(e){this.finishListener=e}update(e){if(!this.cm.trans.chassisBody)return{};if(!this.cm.trans.controller)return{};const t=new ae(this.cm.trans.chassisBody.translation()),n=new Me(this.cm.trans.chassisBody.rotation()),r=new Me(-n.x,-n.y,-n.z,n.w),o=new ae(this.cm.trans.chassisBody.translation());o.add(this.cm.opt.chassisOffset),o.sub(t);const s=new Me(this.cm.trans.chassisBody.rotation());s.mul(r);const c=new Me,A=new ae,a=new Me;{const l=this.cm.opt.wheelFrontAxle,h=this.cm.trans.controller.wheelSuspensionLength(0)||0,f=this.cm.trans.controller.wheelSteering(0)||0,C=this.cm.trans.controller.wheelRotation(0)||0;A.set(-this.cm.opt.wheelFrontAxleLength/2,this.cm.opt.wheelFrontYPosition,this.cm.opt.wheelFrontZPosition),A.sub(0,h,0),a.set(0,Math.sin(f/2),0,Math.cos(f/2)),c.set(l.x*Math.sin(C/2),l.y*Math.sin(C/2),l.z*Math.sin(C/2),Math.cos(C/2)),a.mul(c)}const d=new ae,u=new Me;{const l=this.cm.opt.wheelFrontAxle,h=this.cm.trans.controller.wheelSuspensionLength(1)||0,f=this.cm.trans.controller.wheelSteering(1)||0,C=this.cm.trans.controller.wheelRotation(1)||0;d.set(this.cm.opt.wheelFrontAxleLength/2,this.cm.opt.wheelFrontYPosition,this.cm.opt.wheelFrontZPosition),d.sub(0,h,0),u.set(0,Math.sin(f/2),0,Math.cos(f/2)),c.set(l.x*Math.sin(C/2),l.y*Math.sin(C/2),l.z*Math.sin(C/2),Math.cos(C/2)),u.mul(c)}const m=new ae,p=new Me;{const l=this.cm.opt.wheelRearAxle,h=this.cm.trans.controller.wheelSuspensionLength(2)||0,f=this.cm.trans.controller.wheelSteering(2)||0,C=this.cm.trans.controller.wheelRotation(2)||0;m.set(-this.cm.opt.wheelRearAxleLength/2,this.cm.opt.wheelRearYPosition,this.cm.opt.wheelRearZPosition),m.sub(0,h,0),p.set(0,Math.sin(f/2),0,Math.cos(f/2)),c.set(l.x*Math.sin(C/2),l.y*Math.sin(C/2),l.z*Math.sin(C/2),Math.cos(C/2)),p.mul(c)}const I=new ae,g=new Me;{const l=this.cm.opt.wheelRearAxle,h=this.cm.trans.controller.wheelSuspensionLength(3)||0,f=this.cm.trans.controller.wheelSteering(3)||0,C=this.cm.trans.controller.wheelRotation(3)||0;I.set(this.cm.opt.wheelRearAxleLength/2,this.cm.opt.wheelRearYPosition,this.cm.opt.wheelRearZPosition),I.sub(0,h,0),g.set(0,Math.sin(f/2),0,Math.cos(f/2)),c.set(l.x*Math.sin(C/2),l.y*Math.sin(C/2),l.z*Math.sin(C/2),Math.cos(C/2)),g.mul(c)}return{chassis:{loc:o,quat:s},frontRight:{loc:d,quat:u},frontLeft:{loc:A,quat:a},rearRight:{loc:I,quat:g},rearLeft:{loc:m,quat:p}}}}class kn extends vn{camera;headLight;constructor(e){super(),this.camera=e??new K.PerspectiveCamera(75,1,.01,1e3),this.headLight=new K.SpotLight(16777215,1,0,Math.PI/3,0,0),this.headLight.position.set(0,0,0);const t=new K.Object3D;t.position.set(0,0,-10),this.headLight.target=t,this.object3D.add(this.camera),this.object3D.add(this.headLight),this.object3D.add(t)}initObject(){return new K.Object3D}setAudioListener(e){this.camera.add(e)}setHeadLightEnable(e){this.headLight.intensity=e?1:0}calcNDC(e){const t=new K.Vector3(e.x,e.y,e.z);return t.project(this.camera),{x:t.x,y:t.y}}}const Cr={camera:void 0,antialias:!1,optionalFeatures:[],requiredFeatures:[]};class yr extends HTMLElement{options;base;renderer;scene;camera;controller;camera3js;timer;vrButton;currentSession=null;constructor(e){super(),this.options={...Cr,...e},this.options.camera?(this.camera3js=this.options.camera.camera,this.camera=this.options.camera):(this.camera3js=new K.PerspectiveCamera(75,1,.01,1e3),this.camera=new kn(this.camera3js)),this.base=new Lt(this.camera),this.scene=this.base.scene,this.camera=this.base.camera,this.controller=this.base.controller,this.timer=new K.Timer,this.renderer=new K.WebGLRenderer({antialias:this.options.antialias}),this.renderer.xr.enabled=!0,_t({renderer:this.renderer}),this.vrButton=this.createVRButton(),this.renderer.setAnimationLoop(this.renderingLoop)}connectedCallback(){this.appendChild(this.vrButton)}createVRButton(){const e=document.createElement("button");return e.textContent="VR非対応",e.disabled=!0,navigator.xr&&navigator.xr.isSessionSupported("immersive-vr").then(t=>{t?(e.textContent="VRに入る",e.disabled=!1,e.addEventListener("click",()=>this.onButtonClick())):e.textContent="VR非対応"}),e}async onButtonClick(){if(this.currentSession){await this.currentSession.end();return}const e={optionalFeatures:this.options.optionalFeatures,requiredFeatures:this.options.requiredFeatures},t=await navigator.xr.requestSession("immersive-vr",e);this.renderer.xr.setSession(t),this.currentSession=t,this.vrButton.textContent="VRを終了",t.addEventListener("end",()=>{this.currentSession=null,this.vrButton.textContent="VRに入る"})}disconnectedCallback(){this.renderer.setAnimationLoop(null),this.currentSession&&this.currentSession.end()}replaceScene(e){return this.scene=e,this.base.replaceScene(e)}setController(e){this.controller=e,this.base.setController(e)}renderingLoop=()=>{this.timer.update();const e=this.timer.getDelta();this.base.updateScene(e),this.renderer.render(this.scene.scene,this.camera3js),this.waitingRenderResolves.forEach(t=>{t(e)}),this.waitingRenderResolves=[]};waitingRenderResolves=[];waitForRender(){return new Promise(e=>{this.waitingRenderResolves.push(e)})}worldToScreen(e){const t=new K.Vector3(e.x,e.y,e.z);t.project(this.camera3js);const n=new K.Vector2;this.renderer.getSize(n);const r=(t.x+1)/2*n.x,o=(1-t.y)/2*n.y;return{x:r,y:o}}screenToWorld(e,t,n){const r=new K.Vector2;this.renderer.getSize(r);const o=new K.Vector3(e/r.x*2-1,-(t/r.y)*2+1,.5);o.unproject(this.camera3js);const s=o.sub(this.camera3js.position).normalize(),c=this.camera3js.position;return new ae(c.x+s.x*n,c.y+s.y*n,c.z+s.z*n)}cameraToScreen(e){const n=new K.Vector3(e.x,e.y,e.z).applyMatrix4(this.camera3js.matrixWorld);return x.v0.set(n),this.worldToScreen(x.v0)}screenToCamera(e,t,n){const r=this.screenToWorld(e,t,n),o=new K.Vector3(r.x,r.y,r.z);return r.set(o.applyMatrix4(this.camera3js.matrixWorldInverse)),r}setShadowMap(e){this.renderer.shadowMap.enabled=e}}customElements.define("vr-view-a3",yr);const Br={camera:void 0,antialias:!1,optionalFeatures:[],requiredFeatures:[]};class wr extends HTMLElement{options;base;renderer;scene;camera;controller;camera3js;timer;arButton;currentSession=null;constructor(e){super(),this.options={...Br,...e},this.options.camera?(this.camera3js=this.options.camera.camera,this.camera=this.options.camera):(this.camera3js=new K.PerspectiveCamera(75,1,.01,1e3),this.camera=new kn(this.camera3js)),this.base=new Lt(this.camera),this.scene=this.base.scene,this.camera=this.base.camera,this.controller=this.base.controller,this.timer=new K.Timer,this.renderer=new K.WebGLRenderer({antialias:this.options.antialias,alpha:!0}),this.renderer.xr.enabled=!0,_t({renderer:this.renderer}),this.arButton=this.createARButton(),this.renderer.setAnimationLoop(this.renderingLoop)}connectedCallback(){this.appendChild(this.arButton)}createARButton(){const e=document.createElement("button");return e.textContent="AR非対応",e.disabled=!0,navigator.xr&&navigator.xr.isSessionSupported("immersive-ar").then(t=>{t?(e.textContent="ARに入る",e.disabled=!1,e.addEventListener("click",()=>this.onButtonClick())):e.textContent="AR非対応"}),e}async onButtonClick(){if(this.currentSession){await this.currentSession.end();return}const e={optionalFeatures:this.options.optionalFeatures,requiredFeatures:this.options.requiredFeatures},t=await navigator.xr.requestSession("immersive-ar",e);this.renderer.xr.setSession(t),this.currentSession=t,this.arButton.textContent="ARを終了",t.addEventListener("end",()=>{this.currentSession=null,this.arButton.textContent="ARに入る"})}disconnectedCallback(){this.renderer.setAnimationLoop(null),this.currentSession&&this.currentSession.end()}replaceScene(e){return this.scene=e,this.base.replaceScene(e)}setController(e){this.controller=e,this.base.setController(e)}renderingLoop=()=>{this.timer.update();const e=this.timer.getDelta();this.base.updateScene(e),this.renderer.render(this.scene.scene,this.camera3js),this.waitingRenderResolves.forEach(t=>{t(e)}),this.waitingRenderResolves=[]};waitingRenderResolves=[];waitForRender(){return new Promise(e=>{this.waitingRenderResolves.push(e)})}worldToScreen(e){const t=new K.Vector3(e.x,e.y,e.z);t.project(this.camera3js);const n=new K.Vector2;this.renderer.getSize(n);const r=(t.x+1)/2*n.x,o=(1-t.y)/2*n.y;return{x:r,y:o}}screenToWorld(e,t,n){const r=new K.Vector2;this.renderer.getSize(r);const o=new K.Vector3(e/r.x*2-1,-(t/r.y)*2+1,.5);o.unproject(this.camera3js);const s=o.sub(this.camera3js.position).normalize(),c=this.camera3js.position;return new ae(c.x+s.x*n,c.y+s.y*n,c.z+s.z*n)}cameraToScreen(e){const n=new K.Vector3(e.x,e.y,e.z).applyMatrix4(this.camera3js.matrixWorld);return x.v0.set(n),this.worldToScreen(x.v0)}screenToCamera(e,t,n){const r=this.screenToWorld(e,t,n),o=new K.Vector3(r.x,r.y,r.z);return r.set(o.applyMatrix4(this.camera3js.matrixWorldInverse)),r}setShadowMap(e){this.renderer.shadowMap.enabled=e}}customElements.define("ar-view-a3",wr);exports.ARView=wr;exports.Acerola3D=mi;exports.Action=bn;exports.ActionObject=bt;exports.AvatarPositionController=No;exports.AvatarVelocityController=Oo;exports.BaseController=zt;exports.BaseView=Lt;exports.BillboardTransformer=Zn;exports.Box=Xs;exports.Camera=vn;exports.Canvas=hr;exports.CarControl=ra;exports.CarMotion=br;exports.CarTransformer=Ir;exports.ClipMotion=Tn;exports.DefaultTransformer=vt;exports.DynamicCharacterTransformer=Ai;exports.FollowTransformer=ti;exports.GLTF=Os;exports.GameCanvas=mr;exports.Html3D=ia;exports.ImagePlane=na;exports.KinematicCharacterTransformer=si;exports.ObjectA3=Oe;exports.OrbitController=bi;exports.Quat=Me;exports.RapierPhysicsEngine=Rt;exports.RapierPhysicsWorld=In;exports.SampleObject=Hs;exports.Scene=Ii;exports.SmoothBillboardTransformer=$n;exports.SmoothTransformer=mn;exports.Sound=at;exports.Sphere=Zs;exports.StandardLights=ta;exports.StaticTransformer=Xn;exports.Text3D=Ys;exports.ThreeCamera=Qt;exports.ThreeObject=Js;exports.Transform=ze;exports.VRView=yr;exports.Vec3=ae;exports.Window=fr;exports.XRCamera=kn;exports.asyncSleep=Wr;exports.collisionMap=tt;exports.deepMerge=Pt;exports.defaultARViewOptions=Br;exports.defaultCanvasOptions=ur;exports.defaultCarControlOptions=Er;exports.defaultDynamicCharacterTransformerOptions=ai;exports.defaultFollowTransformerOptions=ei;exports.defaultGameCanvasOptions=gr;exports.defaultKinematicCharacterTransformerOptions=oi;exports.defaultSampleObjectOptions=gn;exports.defaultVRViewOptions=Cr;exports.defaultWindowOptions=dr;exports.eulerToQuaternion=ht;exports.getLookAtQuaternion=At;exports.initFont=Ws;exports.initPhysics=Kr;exports.initSound=_o;exports.recreateGLTFLoader=_t;
292
+ `,this.canvas=this.shadowRoot.querySelector("canvas-a3"),this.scene=this.canvas.scene,this.camera=this.canvas.camera,this.controller=this.canvas.controller,this._maxDistance=40,this._leftActive=!1,this._leftCenter={x:0,y:0},this.leftJoystick={x:0,y:0},this._rightActive=!1,this._rightCenter={x:0,y:0},this.rightJoystick={x:0,y:0},this.leftButton=!1,this.rightButton=!1,this.keys=new Set,this._leftButtonCount=0,this._rightButtonCount=0;const t=this.shadowRoot.querySelector(".joystick.left .stick");if(!t)return;t.addEventListener("pointerdown",s=>{this._leftActive=!0;const c=t.getBoundingClientRect();this._leftCenter.x=c.left+c.width/2,this._leftCenter.y=c.top+c.height/2,t.setPointerCapture(s.pointerId)}),t.addEventListener("pointermove",s=>{if(!this._leftActive)return;const c=s.clientX-this._leftCenter.x,A=s.clientY-this._leftCenter.y,a=Math.sqrt(c*c+A*A);let d=c,u=A;if(a>40){const m=Math.atan2(A,c);d=Math.cos(m)*this._maxDistance,u=Math.sin(m)*this._maxDistance}t.style.transform=`translate(calc(-50% + ${d}px), calc(-50% + ${u}px))`,this.leftJoystick.x=d/this._maxDistance,this.leftJoystick.y=-(u/this._maxDistance)}),t.addEventListener("pointerup",()=>{this._leftActive=!1,t.style.transform="translate(-50%, -50%)",this.leftJoystick.x=0,this.leftJoystick.y=0});const n=this.shadowRoot.querySelector(".joystick.right .stick");if(!n)return;n.addEventListener("pointerdown",s=>{this._rightActive=!0;const c=n.getBoundingClientRect();this._rightCenter.x=c.left+c.width/2,this._rightCenter.y=c.top+c.height/2,n.setPointerCapture(s.pointerId)}),n.addEventListener("pointermove",s=>{if(!this._rightActive)return;const c=s.clientX-this._rightCenter.x,A=s.clientY-this._rightCenter.y,a=Math.sqrt(c*c+A*A);let d=c,u=A;if(a>40){const m=Math.atan2(A,c);d=Math.cos(m)*this._maxDistance,u=Math.sin(m)*this._maxDistance}n.style.transform=`translate(calc(-50% + ${d}px), calc(-50% + ${u}px))`,this.rightJoystick.x=d/this._maxDistance,this.rightJoystick.y=-(u/this._maxDistance)}),n.addEventListener("pointerup",()=>{this._rightActive=!1,n.style.transform="translate(-50%, -50%)",this.rightJoystick.x=0,this.rightJoystick.y=0});const r=this.shadowRoot.querySelector(".btn.left");if(!r)return;r.addEventListener("pointerdown",()=>{this.leftButton=!0,this._leftButtonCount++}),r.addEventListener("pointerup",()=>{this.leftButton=!1});const o=this.shadowRoot.querySelector(".btn.right");o&&(o.addEventListener("pointerdown",()=>{this.rightButton=!0,this._rightButtonCount++}),o.addEventListener("pointerup",()=>{this.rightButton=!1}),window.addEventListener("keydown",this.keyDownListener),window.addEventListener("keyup",this.keyUpListener),this.options.touchDevice||(this.shadowRoot.querySelectorAll(".joystick").forEach(s=>{s.style.display="none"}),this.shadowRoot.querySelectorAll(".btn").forEach(s=>{s.style.display="none"})))}keyDownListener=e=>{this.keys.add(e.code),this.updateUIFromKeyInfo()};keyUpListener=e=>{this.keys.delete(e.code),this.updateUIFromKeyInfo()};connectedCallback(){this._ro=new ResizeObserver(e=>{const t=e[0],n=t.contentRect.width,r=t.contentRect.height;if(!(n===0||r===0))if(n>r){const o=this.shadowRoot.querySelector(".btn.left");o.style.bottom="50px",o.style.left="200px";const s=this.shadowRoot.querySelector(".btn.right");s.style.bottom="50px",s.style.right="200px"}else{const o=this.shadowRoot.querySelector(".btn.left");o.style.bottom="200px",o.style.left="50px";const s=this.shadowRoot.querySelector(".btn.right");s.style.bottom="200px",s.style.right="50px"}}),this._ro.observe(this)}disconnectedCallback(){this._ro?.disconnect(),window.removeEventListener("keydown",this.keyDownListener),window.removeEventListener("keyup",this.keyUpListener)}updateUIFromKeyInfo(){const e={x:0,y:0},t={x:0,y:0};this.keys.has("KeyW")&&(e.y+=1),this.keys.has("KeyA")&&(e.x-=1),this.keys.has("KeyS")&&(e.y-=1),this.keys.has("KeyD")&&(e.x+=1),this.keys.has("ArrowUp")&&(t.y+=1),this.keys.has("ArrowLeft")&&(t.x-=1),this.keys.has("ArrowDown")&&(t.y-=1),this.keys.has("ArrowRight")&&(t.x+=1);const n=Math.sqrt(e.x*e.x+e.y*e.y);n>0&&(e.x/=n,e.y/=n),this.leftJoystick=e;const r=Math.sqrt(t.x*t.x+t.y*t.y);r>0&&(t.x/=r,t.y/=r),this.rightJoystick=t,this.keys.has("Space")?(this.leftButton=!0,this._leftButtonCount++):this.leftButton=!1,this.keys.has("Enter")?(this.rightButton=!0,this._rightButtonCount++):this.rightButton=!1}getLeftButtonCount(){const e=this._leftButtonCount;return this._leftButtonCount=0,e}getRightButtonCount(){const e=this._rightButtonCount;return this._rightButtonCount=0,e}replaceScene(e){return this.canvas.replaceScene(e)}setController(e){this.canvas.setController(e)}worldToScreen(e){return this.canvas.worldToScreen(e)}screenToWorld(e,t,n){return this.canvas.screenToWorld(e,t,n)}cameraToScreen(e){return this.canvas.cameraToScreen(e)}screenToCamera(e,t,n){return this.canvas.screenToCamera(e,t,n)}waitForRender(){return this.canvas.waitForRender()}alert(e,t){return this.canvas.alert(e,t)}prompt(e,t){return this.canvas.prompt(e,t)}setShadowMap(e){this.canvas.setShadowMap(e)}}customElements.define("game-canvas-a3",mr);const Er={mass:10,defaultLocation:{x:0,y:1,z:0},defaultQuat:{x:0,y:0,z:0,w:1},chassisWidth:2,chassisHeight:1,chassisLength:4,chassisOffset:{x:0,y:-.5,z:0},chassisFriction:.1,wheelFrontYPosition:0,wheelFrontZPosition:1.5,wheelFrontAxleLength:2,wheelRearYPosition:0,wheelRearZPosition:-1.5,wheelRearAxleLength:2,wheelFrontRadius:.3,wheelRearRadius:.3,wheelFrontWidth:.4,wheelRearWidth:.4,wheelFrontSuspensionRestLength:.8,wheelRearSuspensionRestLength:.8,wheelFrontDirection:{x:0,y:-1,z:0},wheelRearDirection:{x:0,y:-1,z:0},wheelFrontAxle:{x:-1,y:0,z:0},wheelRearAxle:{x:-1,y:0,z:0},wheelFrontSuspensionStiffness:24,wheelRearSuspensionStiffness:24,wheelFrontSuspensionCompression:4,wheelRearSuspensionCompression:4,wheelFrontSuspensionRelaxation:3,wheelRearSuspensionRelaxation:3,wheelFrontWheelFrictionSlip:100,wheelRearWheelFrictionSlip:100,wheelFrontMaxSuspensionTravel:.25,wheelRearMaxSuspensionTravel:.25,aerodynamicDrag:0};class ra{opt;trans;motion;constructor(e){this.opt={...Er,...e},this.trans=new Ir(this),this.motion=new br(this)}steer(e){this.trans.controller&&(this.trans.controller.setWheelSteering(0,e),this.trans.controller.setWheelSteering(1,e))}accelerate(e){this.trans.controller&&(this.trans.controller.setWheelEngineForce(0,e),this.trans.controller.setWheelEngineForce(1,e),this.trans.controller.setWheelEngineForce(2,e),this.trans.controller.setWheelEngineForce(3,e))}brake(e){this.trans.controller&&(this.trans.controller.setWheelBrake(0,e),this.trans.controller.setWheelBrake(1,e),this.trans.controller.setWheelBrake(2,e),this.trans.controller.setWheelBrake(3,e))}reset(e,t){this.trans.chassisBody&&(e?this.trans.chassisBody.setTranslation({x:e.x,y:e.y,z:e.z},!0):this.trans.chassisBody.setTranslation(this.opt.defaultLocation,!0),t?this.trans.chassisBody.setRotation({x:t.x,y:t.y,z:t.z,w:t.w},!0):this.trans.chassisBody.setRotation(this.opt.defaultQuat,!0),this.trans.chassisBody.setLinvel({x:0,y:0,z:0},!0),this.trans.chassisBody.setAngvel({x:0,y:0,z:0},!0))}}class Ir{cc;transform;objectA3;controller;chassisBodyDesc;chassisBody;chassisColliderDesc;chassisCollider;constructor(e){this.cc=e,this.transform=new ze}init(e,t){this.transform.set(e),this.objectA3=t,this.chassisBodyDesc=new Pe.RigidBodyDesc(Pe.RigidBodyType.Dynamic),this.chassisColliderDesc=Pe.ColliderDesc.cuboid(this.cc.opt.chassisWidth/2,this.cc.opt.chassisHeight/2,this.cc.opt.chassisLength/2),this.chassisColliderDesc.setMass(this.cc.opt.mass),this.chassisColliderDesc.setFriction(this.cc.opt.chassisFriction)}addOneselfToPhysics(e){if(this.chassisBodyDesc&&(this.chassisBody=e.world.createRigidBody(this.chassisBodyDesc),this.chassisBody.setTranslation(this.cc.opt.defaultLocation,!0),this.chassisBody.setRotation(this.cc.opt.defaultQuat,!0)),this.chassisColliderDesc&&(this.chassisCollider=e.world.createCollider(this.chassisColliderDesc,this.chassisBody)),this.chassisCollider&&this.objectA3&&tt.set(this.chassisCollider.handle,this.objectA3),this.chassisBody&&(this.controller=e.world.createVehicleController(this.chassisBody)),this.controller){const t={x:0,y:0,z:0};t.x=-this.cc.opt.wheelFrontAxleLength/2,t.y=this.cc.opt.wheelFrontYPosition,t.z=this.cc.opt.wheelFrontZPosition,this.controller.addWheel(t,this.cc.opt.wheelFrontDirection,this.cc.opt.wheelFrontAxle,this.cc.opt.wheelFrontSuspensionRestLength,this.cc.opt.wheelFrontRadius),this.controller.setWheelSuspensionStiffness(0,this.cc.opt.wheelFrontSuspensionStiffness),this.controller.setWheelSuspensionCompression(0,this.cc.opt.wheelFrontSuspensionCompression),this.controller.setWheelSuspensionRelaxation(0,this.cc.opt.wheelFrontSuspensionRelaxation),this.controller.setWheelFrictionSlip(0,this.cc.opt.wheelFrontWheelFrictionSlip),this.controller.setWheelMaxSuspensionTravel(0,this.cc.opt.wheelFrontMaxSuspensionTravel),t.x=this.cc.opt.wheelFrontAxleLength/2,t.y=this.cc.opt.wheelFrontYPosition,t.z=this.cc.opt.wheelFrontZPosition,this.controller.addWheel(t,this.cc.opt.wheelFrontDirection,this.cc.opt.wheelFrontAxle,this.cc.opt.wheelFrontSuspensionRestLength,this.cc.opt.wheelFrontRadius),this.controller.setWheelSuspensionStiffness(1,this.cc.opt.wheelFrontSuspensionStiffness),this.controller.setWheelSuspensionCompression(1,this.cc.opt.wheelFrontSuspensionCompression),this.controller.setWheelSuspensionRelaxation(1,this.cc.opt.wheelFrontSuspensionRelaxation),this.controller.setWheelFrictionSlip(1,this.cc.opt.wheelFrontWheelFrictionSlip),this.controller.setWheelMaxSuspensionTravel(1,this.cc.opt.wheelFrontMaxSuspensionTravel),t.x=-this.cc.opt.wheelRearAxleLength/2,t.y=this.cc.opt.wheelRearYPosition,t.z=this.cc.opt.wheelRearZPosition,this.controller.addWheel(t,this.cc.opt.wheelRearDirection,this.cc.opt.wheelRearAxle,this.cc.opt.wheelRearSuspensionRestLength,this.cc.opt.wheelRearRadius),this.controller.setWheelSuspensionStiffness(2,this.cc.opt.wheelRearSuspensionStiffness),this.controller.setWheelSuspensionCompression(2,this.cc.opt.wheelRearSuspensionCompression),this.controller.setWheelSuspensionRelaxation(2,this.cc.opt.wheelRearSuspensionRelaxation),this.controller.setWheelFrictionSlip(2,this.cc.opt.wheelRearWheelFrictionSlip),this.controller.setWheelMaxSuspensionTravel(2,this.cc.opt.wheelRearMaxSuspensionTravel),t.x=this.cc.opt.wheelRearAxleLength/2,t.y=this.cc.opt.wheelRearYPosition,t.z=this.cc.opt.wheelRearZPosition,this.controller.addWheel(t,this.cc.opt.wheelRearDirection,this.cc.opt.wheelRearAxle,this.cc.opt.wheelRearSuspensionRestLength,this.cc.opt.wheelRearRadius),this.controller.setWheelSuspensionStiffness(3,this.cc.opt.wheelRearSuspensionStiffness),this.controller.setWheelSuspensionCompression(3,this.cc.opt.wheelRearSuspensionCompression),this.controller.setWheelSuspensionRelaxation(3,this.cc.opt.wheelRearSuspensionRelaxation),this.controller.setWheelFrictionSlip(3,this.cc.opt.wheelRearWheelFrictionSlip),this.controller.setWheelMaxSuspensionTravel(3,this.cc.opt.wheelRearMaxSuspensionTravel)}}removeOneselfFromPhysics(e){this.chassisCollider&&(e.world.removeCollider(this.chassisCollider,!0),tt.delete(this.chassisCollider.handle),this.chassisCollider=void 0),this.chassisBody&&e.world.removeRigidBody(this.chassisBody),this.chassisBody=void 0}setPosition(e){}setPositionNow(e){}setQuat(e){}setQuatNow(e){}setScale(e){}setScaleNow(e){}setLinearVelocity(e){}getLinearVelocity(e){return e||(e=new ae),this.chassisBody?e.set(this.chassisBody.linvel()):this.chassisBodyDesc&&e.set(this.chassisBodyDesc.linvel),e}setAngularVelocity(e){}getAngularVelocity(e){return e||(e=new ae),this.chassisBody?e.set(this.chassisBody.angvel()):this.chassisBodyDesc&&e.set(this.chassisBodyDesc.angvel),e}resetForce(){}addForce(e){}addForceAtPoint(e,t){}resetTorque(){}addTorque(e){}applyImpulse(e){}applyImpulseAtPoint(e,t){}applyTorqueImpulse(e){}isGrounded(){if(!this.controller)return!0;let e=!1;return e||=this.controller.wheelIsInContact(0),e||=this.controller.wheelIsInContact(1),e||=this.controller.wheelIsInContact(2),e||=this.controller.wheelIsInContact(3),e}vv=new ae;update(e){if(this.cc.opt.aerodynamicDrag>0&&this.chassisBody){const t=new ae(this.chassisBody.linvel());Math.abs(t.y)>3&&t.set(t.x,3*t.y/Math.abs(t.y),t.z),this.vv.lerp(this.vv,t,.9);const n=this.vv.length();n!==0&&(t.set(this.vv),t.normalize(),t.scale(-n*n*this.cc.opt.aerodynamicDrag),this.chassisBody.resetForces(!0),this.chassisBody.addForce({x:t.x,y:t.y,z:t.z},!0))}this.controller?.updateVehicle(e),this.chassisBody&&this.transform.loc.set(this.chassisBody.translation()),this.chassisBody&&this.transform.quat.set(this.chassisBody.rotation())}}class br{cm;name;playCount;time;finishListener;constructor(e){this.cm=e,this.name="default",this.playCount=0,this.time=0}addOneselfToPhysics(e){}removeOneselfFromPhysics(e){}setPause(e){}setTime(e){}setFinishListener(e){this.finishListener=e}update(e){if(!this.cm.trans.chassisBody)return{};if(!this.cm.trans.controller)return{};const t=new ae(this.cm.trans.chassisBody.translation()),n=new Me(this.cm.trans.chassisBody.rotation()),r=new Me(-n.x,-n.y,-n.z,n.w),o=new ae(this.cm.trans.chassisBody.translation());o.add(this.cm.opt.chassisOffset),o.sub(t);const s=new Me(this.cm.trans.chassisBody.rotation());s.mul(r);const c=new Me,A=new ae,a=new Me;{const l=this.cm.opt.wheelFrontAxle,h=this.cm.trans.controller.wheelSuspensionLength(0)||0,f=this.cm.trans.controller.wheelSteering(0)||0,C=this.cm.trans.controller.wheelRotation(0)||0;A.set(-this.cm.opt.wheelFrontAxleLength/2,this.cm.opt.wheelFrontYPosition,this.cm.opt.wheelFrontZPosition),A.sub(0,h,0),a.set(0,Math.sin(f/2),0,Math.cos(f/2)),c.set(l.x*Math.sin(C/2),l.y*Math.sin(C/2),l.z*Math.sin(C/2),Math.cos(C/2)),a.mul(c)}const d=new ae,u=new Me;{const l=this.cm.opt.wheelFrontAxle,h=this.cm.trans.controller.wheelSuspensionLength(1)||0,f=this.cm.trans.controller.wheelSteering(1)||0,C=this.cm.trans.controller.wheelRotation(1)||0;d.set(this.cm.opt.wheelFrontAxleLength/2,this.cm.opt.wheelFrontYPosition,this.cm.opt.wheelFrontZPosition),d.sub(0,h,0),u.set(0,Math.sin(f/2),0,Math.cos(f/2)),c.set(l.x*Math.sin(C/2),l.y*Math.sin(C/2),l.z*Math.sin(C/2),Math.cos(C/2)),u.mul(c)}const m=new ae,p=new Me;{const l=this.cm.opt.wheelRearAxle,h=this.cm.trans.controller.wheelSuspensionLength(2)||0,f=this.cm.trans.controller.wheelSteering(2)||0,C=this.cm.trans.controller.wheelRotation(2)||0;m.set(-this.cm.opt.wheelRearAxleLength/2,this.cm.opt.wheelRearYPosition,this.cm.opt.wheelRearZPosition),m.sub(0,h,0),p.set(0,Math.sin(f/2),0,Math.cos(f/2)),c.set(l.x*Math.sin(C/2),l.y*Math.sin(C/2),l.z*Math.sin(C/2),Math.cos(C/2)),p.mul(c)}const I=new ae,g=new Me;{const l=this.cm.opt.wheelRearAxle,h=this.cm.trans.controller.wheelSuspensionLength(3)||0,f=this.cm.trans.controller.wheelSteering(3)||0,C=this.cm.trans.controller.wheelRotation(3)||0;I.set(this.cm.opt.wheelRearAxleLength/2,this.cm.opt.wheelRearYPosition,this.cm.opt.wheelRearZPosition),I.sub(0,h,0),g.set(0,Math.sin(f/2),0,Math.cos(f/2)),c.set(l.x*Math.sin(C/2),l.y*Math.sin(C/2),l.z*Math.sin(C/2),Math.cos(C/2)),g.mul(c)}return{chassis:{loc:o,quat:s},frontRight:{loc:d,quat:u},frontLeft:{loc:A,quat:a},rearRight:{loc:I,quat:g},rearLeft:{loc:m,quat:p}}}}class kn extends vn{camera;headLight;constructor(e){super(),this.camera=e??new K.PerspectiveCamera(75,1,.01,1e3),this.headLight=new K.SpotLight(16777215,1,0,Math.PI/3,0,0),this.headLight.position.set(0,0,0);const t=new K.Object3D;t.position.set(0,0,-10),this.headLight.target=t,this.object3D.add(this.camera),this.object3D.add(this.headLight),this.object3D.add(t)}initObject(){return new K.Object3D}setAudioListener(e){this.camera.add(e)}setHeadLightEnable(e){this.headLight.intensity=e?1:0}calcNDC(e){const t=new K.Vector3(e.x,e.y,e.z);return t.project(this.camera),{x:t.x,y:t.y}}}const Cr={camera:void 0,antialias:!1,optionalFeatures:["local-floor"],requiredFeatures:[]};class yr extends HTMLElement{options;base;renderer;scene;camera;controller;camera3js;timer;vrButton;currentSession=null;constructor(e){super(),this.options={...Cr,...e},this.options.camera?(this.camera3js=this.options.camera.camera,this.camera=this.options.camera):(this.camera3js=new K.PerspectiveCamera(75,1,.01,1e3),this.camera=new kn(this.camera3js)),this.base=new Lt(this.camera),this.scene=this.base.scene,this.controller=this.base.controller,this.timer=new K.Timer,this.renderer=new K.WebGLRenderer({antialias:this.options.antialias}),this.renderer.xr.enabled=!0,_t({renderer:this.renderer}),this.vrButton=this.createVRButton(),this.renderer.setAnimationLoop(this.renderingLoop)}connectedCallback(){this.appendChild(this.vrButton)}createVRButton(){const e=document.createElement("button");return e.textContent="VR非対応",e.disabled=!0,navigator.xr&&navigator.xr.isSessionSupported("immersive-vr").then(t=>{t?(e.textContent="VRに入る",e.disabled=!1,e.addEventListener("click",()=>this.onButtonClick())):e.textContent="VR非対応"}),e}async onButtonClick(){if(this.currentSession){await this.currentSession.end();return}const e={optionalFeatures:this.options.optionalFeatures,requiredFeatures:this.options.requiredFeatures},t=await navigator.xr.requestSession("immersive-vr",e);this.renderer.xr.setSession(t),this.currentSession=t,this.vrButton.textContent="VRを終了",t.addEventListener("end",()=>{this.currentSession=null,this.vrButton.textContent="VRに入る"})}disconnectedCallback(){this.renderer.setAnimationLoop(null),this.currentSession&&this.currentSession.end()}replaceScene(e){return this.scene=e,this.base.replaceScene(e)}setController(e){this.controller=e,this.base.setController(e)}renderingLoop=()=>{this.timer.update();const e=this.timer.getDelta();this.base.updateScene(e),this.renderer.render(this.scene.scene,this.camera3js),this.waitingRenderResolves.forEach(t=>{t(e)}),this.waitingRenderResolves=[]};waitingRenderResolves=[];waitForRender(){return new Promise(e=>{this.waitingRenderResolves.push(e)})}worldToScreen(e){const t=new K.Vector3(e.x,e.y,e.z);t.project(this.camera3js);const n=new K.Vector2;this.renderer.getSize(n);const r=(t.x+1)/2*n.x,o=(1-t.y)/2*n.y;return{x:r,y:o}}screenToWorld(e,t,n){const r=new K.Vector2;this.renderer.getSize(r);const o=new K.Vector3(e/r.x*2-1,-(t/r.y)*2+1,.5);o.unproject(this.camera3js);const s=o.sub(this.camera3js.position).normalize(),c=this.camera3js.position;return new ae(c.x+s.x*n,c.y+s.y*n,c.z+s.z*n)}cameraToScreen(e){const n=new K.Vector3(e.x,e.y,e.z).applyMatrix4(this.camera3js.matrixWorld);return x.v0.set(n),this.worldToScreen(x.v0)}screenToCamera(e,t,n){const r=this.screenToWorld(e,t,n),o=new K.Vector3(r.x,r.y,r.z);return r.set(o.applyMatrix4(this.camera3js.matrixWorldInverse)),r}setShadowMap(e){this.renderer.shadowMap.enabled=e}}customElements.define("vr-view-a3",yr);const Br={camera:void 0,antialias:!1,optionalFeatures:["local-floor"],requiredFeatures:[]};class wr extends HTMLElement{options;base;renderer;scene;camera;controller;camera3js;timer;arButton;currentSession=null;constructor(e){super(),this.options={...Br,...e},this.options.camera?(this.camera3js=this.options.camera.camera,this.camera=this.options.camera):(this.camera3js=new K.PerspectiveCamera(75,1,.01,1e3),this.camera=new kn(this.camera3js)),this.base=new Lt(this.camera),this.scene=this.base.scene,this.controller=this.base.controller,this.timer=new K.Timer,this.renderer=new K.WebGLRenderer({antialias:this.options.antialias,alpha:!0}),this.renderer.xr.enabled=!0,_t({renderer:this.renderer}),this.arButton=this.createARButton(),this.renderer.setAnimationLoop(this.renderingLoop)}connectedCallback(){this.appendChild(this.arButton)}createARButton(){const e=document.createElement("button");return e.textContent="AR非対応",e.disabled=!0,navigator.xr&&navigator.xr.isSessionSupported("immersive-ar").then(t=>{t?(e.textContent="ARに入る",e.disabled=!1,e.addEventListener("click",()=>this.onButtonClick())):e.textContent="AR非対応"}),e}async onButtonClick(){if(this.currentSession){await this.currentSession.end();return}const e={optionalFeatures:this.options.optionalFeatures,requiredFeatures:this.options.requiredFeatures},t=await navigator.xr.requestSession("immersive-ar",e);this.renderer.xr.setSession(t),this.currentSession=t,this.arButton.textContent="ARを終了",t.addEventListener("end",()=>{this.currentSession=null,this.arButton.textContent="ARに入る"})}disconnectedCallback(){this.renderer.setAnimationLoop(null),this.currentSession&&this.currentSession.end()}replaceScene(e){return this.scene=e,this.base.replaceScene(e)}setController(e){this.controller=e,this.base.setController(e)}renderingLoop=()=>{this.timer.update();const e=this.timer.getDelta();this.base.updateScene(e),this.renderer.render(this.scene.scene,this.camera3js),this.waitingRenderResolves.forEach(t=>{t(e)}),this.waitingRenderResolves=[]};waitingRenderResolves=[];waitForRender(){return new Promise(e=>{this.waitingRenderResolves.push(e)})}worldToScreen(e){const t=new K.Vector3(e.x,e.y,e.z);t.project(this.camera3js);const n=new K.Vector2;this.renderer.getSize(n);const r=(t.x+1)/2*n.x,o=(1-t.y)/2*n.y;return{x:r,y:o}}screenToWorld(e,t,n){const r=new K.Vector2;this.renderer.getSize(r);const o=new K.Vector3(e/r.x*2-1,-(t/r.y)*2+1,.5);o.unproject(this.camera3js);const s=o.sub(this.camera3js.position).normalize(),c=this.camera3js.position;return new ae(c.x+s.x*n,c.y+s.y*n,c.z+s.z*n)}cameraToScreen(e){const n=new K.Vector3(e.x,e.y,e.z).applyMatrix4(this.camera3js.matrixWorld);return x.v0.set(n),this.worldToScreen(x.v0)}screenToCamera(e,t,n){const r=this.screenToWorld(e,t,n),o=new K.Vector3(r.x,r.y,r.z);return r.set(o.applyMatrix4(this.camera3js.matrixWorldInverse)),r}setShadowMap(e){this.renderer.shadowMap.enabled=e}}customElements.define("ar-view-a3",wr);exports.ARView=wr;exports.Acerola3D=mi;exports.Action=bn;exports.ActionObject=bt;exports.AvatarPositionController=No;exports.AvatarVelocityController=Oo;exports.BaseController=zt;exports.BaseView=Lt;exports.BillboardTransformer=Zn;exports.Box=Xs;exports.Camera=vn;exports.Canvas=hr;exports.CarControl=ra;exports.CarMotion=br;exports.CarTransformer=Ir;exports.ClipMotion=Tn;exports.DefaultTransformer=vt;exports.DynamicCharacterTransformer=Ai;exports.FollowTransformer=ti;exports.GLTF=Os;exports.GameCanvas=mr;exports.Html3D=ia;exports.ImagePlane=na;exports.KinematicCharacterTransformer=si;exports.ObjectA3=Oe;exports.OrbitController=bi;exports.Quat=Me;exports.RapierPhysicsEngine=Rt;exports.RapierPhysicsWorld=In;exports.SampleObject=Hs;exports.Scene=Ii;exports.SmoothBillboardTransformer=$n;exports.SmoothTransformer=mn;exports.Sound=at;exports.Sphere=Zs;exports.StandardLights=ta;exports.StaticTransformer=Xn;exports.Text3D=Ys;exports.ThreeCamera=Qt;exports.ThreeObject=Js;exports.Transform=ze;exports.VRView=yr;exports.Vec3=ae;exports.Window=fr;exports.XRCamera=kn;exports.asyncSleep=Wr;exports.collisionMap=tt;exports.deepMerge=Pt;exports.defaultARViewOptions=Br;exports.defaultCanvasOptions=ur;exports.defaultCarControlOptions=Er;exports.defaultDynamicCharacterTransformerOptions=ai;exports.defaultFollowTransformerOptions=ei;exports.defaultGameCanvasOptions=gr;exports.defaultKinematicCharacterTransformerOptions=oi;exports.defaultSampleObjectOptions=gn;exports.defaultVRViewOptions=Cr;exports.defaultWindowOptions=dr;exports.eulerToQuaternion=ht;exports.getLookAtQuaternion=At;exports.initFont=Ws;exports.initPhysics=Kr;exports.initSound=_o;exports.recreateGLTFLoader=_t;
293
293
  //# sourceMappingURL=a3js.cjs.js.map