@soonspacejs/plugin-first-person-controls 2.11.63 → 2.11.65
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/index.esm.js +1 -1
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Vector2 as t,Vector3 as e,Sphere as s,Box3 as i,Raycaster as o,Matrix4 as n,Euler as a,Quaternion as r}from"three";import h from"soonspacejs";const{utils:{isObjectVisible:c}}=h;function l(t,e){const s=h.utils.getBoundingBox(e);return t.intersectsBox(s)}function d(t,e){t.disableAll();for(const s of e)t.enable(s)}function p(t,e){return t.intersectObjects(e).filter((({object:t})=>c(t)))}const{EPSILON:v,approxEquals:m}=h.utils,{utils:y}=h;class u{get rotate(){return this._rotate&&(this.horizontalRotate||this.verticalRotate)}set rotate(t){this._rotate=t}constructor(o){this.enabled=!1,this.keyCodeMap={moveForward:["ArrowUp","KeyW"],moveBackward:["ArrowDown","KeyS"],moveLeft:["ArrowLeft","KeyA"],moveRight:["ArrowRight","KeyD"],moveUp:["KeyQ"],moveDown:["KeyE"],rotateUp:["KeyI"],rotateDown:["KeyK"],rotateLeft:["KeyJ"],rotateRight:["KeyL"],jump:["Space"]},this.state={moveForward:!1,moveBackward:!1,moveLeft:!1,moveRight:!1,moveUp:!1,moveDown:!1,canJump:!1,canRotate:!1},this.moveSpeed=10,this.gravitySpeed=10,this.jumpOffset=0,this.clashCheckDistance=200,this.clashDistance=50,this.eyeHeight=160,this.kneeHeight=50,this.jumpHeight=110,this.enableClash=!0,this.enableGravity=!0,this.reverseRotate=!1,this._rotate=!0,this.rotateSpeed=1,this.horizontalRotate=!0,this.verticalRotate=!0,this.dblClickForward=!1,this.movement=new t,this._dblVector=new e,this._dblDeltaVector=new e,this._pointerId=null,this.lastDirection=new e,this.searchRadiusFactor=3,this.checkedSphere=new s,this.gravitySearchFactor=3,this.gravityCheckedObjects=null,this.gravityCheckedBox=new i,this.gravityInterObject=null,this.kneeInterObject=null,this.eyeInterObject=null,this.ssp=o,this.viewport=o.viewport,this.controls=o.controls,this.camera=o.controls.camera,this.container=o.viewport.container,this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onDblClick=this.onDblClick.bind(this),this.onPointerDown=this.onPointerDown.bind(this),this.onPointerMove=this.onPointerMove.bind(this),this.onPointerUp=this.onPointerUp.bind(this)}onKeyDown(t){if(!1!==this.enabled){t:for(const[e,s]of Object.entries(this.keyCodeMap))if(s.includes(t.code))switch(e){case"moveForward":this.state.moveForward=!0;break t;case"moveBackward":this.state.moveBackward=!0;break t;case"moveLeft":this.state.moveLeft=!0;break t;case"moveRight":this.state.moveRight=!0;break t;case"moveUp":this.state.moveUp=!0;break t;case"moveDown":this.state.moveDown=!0;break t;case"rotateUp":this.state.canRotate=!0,this.movement.x=0,this.movement.y=-10;break t;case"rotateDown":this.state.canRotate=!0,this.movement.x=0,this.movement.y=10;break t;case"rotateLeft":this.state.canRotate=!0,this.movement.x=-10,this.movement.y=0;break t;case"rotateRight":this.state.canRotate=!0,this.movement.x=10,this.movement.y=0;break t;case"jump":!0===this.state.canJump&&!1===t.repeat&&(this.jumpOffset=this.jumpHeight),this.state.canJump=!1;break t}(this.jumpOffset>0||Object.values(this.state).some((t=>t)))&&this.ssp.render()}}onKeyUp(t){t:for(const[e,s]of Object.entries(this.keyCodeMap))if(s.includes(t.code))switch(e){case"moveForward":this.state.moveForward=!1;break t;case"moveBackward":this.state.moveBackward=!1;break t;case"moveLeft":this.state.moveLeft=!1;break t;case"moveRight":this.state.moveRight=!1;break t;case"moveUp":this.state.moveUp=!1;break t;case"moveDown":this.state.moveDown=!1;break t;case"rotateUp":case"rotateDown":case"rotateLeft":case"rotateRight":this.state.canRotate=!1;break t}}onDblClick(t){if(!0===this.dblClickForward){const[e]=this.ssp.viewport.getIntersects(t);if(e){const{point:t}=e;t.y+=this.eyeHeight,t.sub(this.camera.position),this._dblVector.copy(t),this._dblDeltaVector.set(0,0,0),this.ssp.render()}}}onPointerDown(t){null===this._pointerId&&0===t.button&&(this.container.setPointerCapture(t.pointerId),this._pointerId=t.pointerId,this.state.canRotate=!0)}onPointerMove(t){if(this.enabled&&this.state.canRotate){t.preventDefault();let e=t.movementY,s=t.movementX;this.reverseRotate&&(s=-s,e=-e),this.movement.x=s,this.movement.y=e,this.ssp.render()}}onPointerUp(t){null!==this._pointerId&&(this.container.releasePointerCapture(t.pointerId),this._pointerId=null,this.state.canRotate=!1)}clearClashCache(){this.kneeInterObject=null,this.eyeInterObject=null}onClashCheck(t,e){const s=e.length(),i=e.clone().divideScalar(s);i.distanceToSquared(this.lastDirection)>1e-9&&this.clearClashCache(),this.lastDirection=i;const{eyeHeight:n,kneeHeight:a,camera:r,clashCheckDistance:h,clashDistance:c,clashLayers:l}=this;let{kneeInterObject:v,eyeInterObject:m}=this;if(!v){const e=t.clone().setY(t.y-n+a),s=new o(e,i,0,h);s.firstHitOnly=!0,null!=l&&d(s.layers,l),s.camera=r;const c=p(s,this.getCheckedObjects(e));this.kneeInterObject=v=c[0]}let y=-s;if(v&&(y+=v.distance,y<c))return!0;if(!m){const e=new o(t,i,0,h);e.firstHitOnly=!0,null!=l&&d(e.layers,l),e.camera=r;const s=p(e,this.getCheckedObjects(t));this.eyeInterObject=m=s[0]}let u=-s;if(m){if(u+=m.distance,u<c)return!0;m.distance=u}return v&&(v.distance=y),!1}getCheckedObjects(t){const{clashDistance:e,clashCheckDistance:s,searchRadiusFactor:i,clashFilter:o}=this,n=s*i,a=this.checkedSphere,r=n+e;a.set(t,r);const h=null!=o?o:function(){return!0};return this.viewport.scener.intersectsList.getAll().filter((t=>!!h(t)&&l(a,t)))}getGravityCheckedObjects(t,s){const i=this.gravityCheckedBox;let o=this.gravityCheckedObjects;if(o){const e=t.clone();e.y=s,i.containsPoint(t)&&i.containsPoint(e)||(o=null)}if(!o){const{eyeHeight:s,clashCheckDistance:n,gravitySearchFactor:a,clashDistance:r,clashFilter:h}=this,c=n+r,d=new e(c,c,0),p=t.clone().add(d),v=t.clone().sub(d);v.y-=s*a,i.set(v,p);const m=this.viewport.scener.intersectsList.getAll(),y=null!=h?h:function(){return!0};o=m.filter((t=>!!y(t)&&l(i,t)))}return o}gravityClashCheck(t,s){var i;let a=this.gravityInterObject;if(a){const{object:s,face:o,instanceId:r}=a,h=null===(i=s.geometry)||void 0===i?void 0:i.getAttribute("position");if(h&&o){let i=a.facePoints;if(!i){let t=s.matrixWorld;if(null!=r){const e=new n;s.getMatrixAt(r,e),t=e.premultiply(t)}const{a:c,b:l,c:d}=o,p=new e(h.getX(c),h.getY(c),h.getZ(c));p.applyMatrix4(t),p.setY(0);const v=new e(h.getX(l),h.getY(l),h.getZ(l));v.applyMatrix4(t),v.setY(0);const m=new e(h.getX(d),h.getY(d),h.getZ(d));m.applyMatrix4(t),m.setY(0),a.facePoints=i=[p,v,m]}let c=i[2],l=null;const d=t.clone();d.y=0;i.every((t=>{const e=t.clone();e.sub(c);const s=d.clone();if(s.sub(c),e.cross(s),l){if(e.dot(l)<=0)return!1}return l=e,c=t,!0}))||(this.gravityInterObject=a=null)}}if(!a){const i=new o(t,new e(0,-1,0));i.firstHitOnly=!0;const n=this.clashLayers;null!=n&&d(i.layers,n),i.camera=this.camera;const r=p(i,this.getGravityCheckedObjects(t,s));this.gravityInterObject=a=r[0]}return a}setOptions(t){const{position:s=new e,rotation:i=new a,moveSpeed:o,eyeHeight:n,kneeHeight:r,jumpHeight:h,enableClash:c,enableGravity:l,searchRadiusFactor:d,clashDistance:p,clashCheckDistance:m,gravitySpeed:u,gravitySearchFactor:b,reverseRotate:g,rotate:w,rotateSpeed:f,horizontalRotate:k,verticalRotate:C,dblClickForward:D,clashFilter:j,clashLayers:R}=t;if(n&&(this.eyeHeight=n),r&&(this.kneeHeight=r),h&&(this.jumpHeight=h),d&&(this.searchRadiusFactor=d),p&&(this.clashDistance=p),m&&(this.clashCheckDistance=m),u&&(this.gravitySpeed=u),b&&(this.gravitySearchFactor=b),null!=g&&(this.reverseRotate=g),null!=w&&(this.rotate=w),null!=k&&(this.horizontalRotate=k),null!=C&&(this.verticalRotate=C),y.isBoolean(D)&&(this.dblClickForward=D),y.isNumber(f)&&(this.rotateSpeed=f),null!=c&&(this.enableClash=c),null!=l&&(this.enableGravity=l),null!=j&&(this.clashFilter=j),null!=R&&(this.clashLayers=R),s&&(this.controls.setPosition(s.x,s.y+this.eyeHeight,s.z),this.gravityInterObject=null,this.clearClashCache()),i){const t=y.computeTargetByRotation(this.controls.getPosition(new e),i,v);this.controls.setTarget(t.x,t.y,t.z)}o&&(this.moveSpeed=o)}start(t){this.viewport.controls.saveState(),this.viewport.controls.enabled=!1,this.enabled=!0,this.setOptions(t),this.viewport.postRender.set("FirstPersonControls",this.update.bind(this)),this.ssp.signals.dblClick.add(this.onDblClick),this.ssp.signals.keyDown.add(this.onKeyDown),this.ssp.signals.keyUp.add(this.onKeyUp);const e=this.container;e.addEventListener("pointerdown",this.onPointerDown),e.addEventListener("pointermove",this.onPointerMove),e.addEventListener("pointerup",this.onPointerUp)}stop(){this.viewport.controls.reset(),this.viewport.controls.enabled=!0,this.enabled=!1,this.viewport.postRender.delete("FirstPersonControls"),this.ssp.signals.dblClick.remove(this.onDblClick),this.ssp.signals.keyDown.remove(this.onKeyDown),this.ssp.signals.keyUp.remove(this.onKeyUp);const t=this.container;t.removeEventListener("pointerdown",this.onPointerDown),t.removeEventListener("pointermove",this.onPointerMove),t.removeEventListener("pointerup",this.onPointerUp),this.ssp.render()}update(){if(!this.enabled)return;const{delta:t}=this.viewport.state,s=new e,{controls:i,state:o,camera:n,eyeHeight:h,kneeHeight:c}=this,l=i.getPosition(new e),d=20*this.moveSpeed,p=20*this.gravitySpeed;o.moveForward&&(s.z-=d),o.moveBackward&&(s.z+=d),o.moveLeft&&(s.x-=d),o.moveRight&&(s.x+=d),o.moveUp&&(s.y+=2*p),o.moveDown&&(s.y-=2*p),s.multiplyScalar(t);const{x:y,y:u}=this.movement,b=this.horizontalRotate&&0!==y,g=this.verticalRotate&&0!==u;if(this.rotate&&o.canRotate&&(b||g)){let{azimuthAngle:t,polarAngle:e}=i;g&&(e-=.003*u*this.rotateSpeed),b&&(t-=.003*y*this.rotateSpeed),i.rotateTo(t,e)}const w=new a(0,0,0,"YXZ");if(w.setFromQuaternion(n.quaternion),0!==w.y&&!s.equals(new e)){const t=new r;t.setFromAxisAngle(new e(0,1,0),w.y),s.applyQuaternion(t)}if(!this._dblVector.equals(new e)){const e=this._dblVector.clone().multiplyScalar(t);this._dblDeltaVector.add(e),this._dblDeltaVector.length()>this._dblVector.length()?(this._dblVector.set(0,0,0),this._dblDeltaVector.set(0,0,0)):s.add(e)}const f=l.clone();if((!this.enableClash||!this.onClashCheck(l,s))&&(f.add(s),this.gravityInterObject)){const t=this.gravityInterObject.point.clone().sub(f);t.y=0,t.length()>c&&(this.gravityInterObject=null)}let k=f.y;if(this.enableGravity){const e=k;this.jumpOffset>0&&(this.jumpOffset-=p*t,k+=2*p*t),k-=p*t,o.canJump=!1;const s=this.gravityClashCheck(f,k);if(s){const t=s.point.y+h;k<t&&(k=t,this.jumpOffset=0,o.canJump=!0)}e!==k&&this.clearClashCache()}f.y=k,m(l.x,f.x)&&m(l.y,f.y)&&m(l.z,f.z)||(i.moveTo(f.x,f.y,f.z),i.dollyTo(v))}}export{u as default};
|
|
1
|
+
import{Vector2 as t,Vector3 as e,Sphere as s,Box3 as i,Raycaster as o,Matrix4 as n,Euler as a,Quaternion as r}from"three";import h from"soonspacejs";const{utils:{isObjectVisible:c}}=h;function l(t,e){const s=h.utils.getBoundingBox(e);return t.intersectsBox(s)}function d(t,e){t.disableAll();for(const s of e)t.enable(s)}function p(t,e){return t.intersectObjects(e).filter((({object:t})=>c(t)))}const{EPSILON:v,approxEquals:m}=h.utils,{utils:y}=h;class u{get rotate(){return this._rotate&&(this.horizontalRotate||this.verticalRotate)}set rotate(t){this._rotate=t}constructor(o){this.enabled=!1,this.keyCodeMap={moveForward:["ArrowUp","KeyW"],moveBackward:["ArrowDown","KeyS"],moveLeft:["ArrowLeft","KeyA"],moveRight:["ArrowRight","KeyD"],moveUp:["KeyQ"],moveDown:["KeyE"],rotateUp:["KeyI"],rotateDown:["KeyK"],rotateLeft:["KeyJ"],rotateRight:["KeyL"],jump:["Space"]},this.state={moveForward:!1,moveBackward:!1,moveLeft:!1,moveRight:!1,moveUp:!1,moveDown:!1,canJump:!1,canRotate:!1},this.moveSpeed=10,this.gravitySpeed=10,this.jumpOffset=0,this.clashCheckDistance=200,this.clashDistance=50,this.eyeHeight=160,this.kneeHeight=50,this.jumpHeight=110,this.enableClash=!0,this.enableGravity=!0,this.reverseRotate=!1,this._rotate=!0,this.rotateSpeed=1,this.horizontalRotate=!0,this.verticalRotate=!0,this.dblClickForward=!1,this.movement=new t,this._dblVector=new e,this._dblDeltaVector=new e,this._pointerId=null,this.lastDirection=new e,this.searchRadiusFactor=3,this.checkedSphere=new s,this.gravitySearchFactor=3,this.gravityCheckedObjects=null,this.gravityCheckedBox=new i,this.gravityInterObject=null,this.kneeInterObject=null,this.eyeInterObject=null,this.ssp=o,this.viewport=o.viewport,this.controls=o.controls,this.camera=o.controls.camera,this.container=o.viewport.container,this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onDblClick=this.onDblClick.bind(this),this.onPointerDown=this.onPointerDown.bind(this),this.onPointerMove=this.onPointerMove.bind(this),this.onPointerUp=this.onPointerUp.bind(this)}onKeyDown(t){if(!1!==this.enabled){t:for(const[e,s]of Object.entries(this.keyCodeMap))if(s.includes(t.code))switch(e){case"moveForward":this.state.moveForward=!0;break t;case"moveBackward":this.state.moveBackward=!0;break t;case"moveLeft":this.state.moveLeft=!0;break t;case"moveRight":this.state.moveRight=!0;break t;case"moveUp":this.state.moveUp=!0;break t;case"moveDown":this.state.moveDown=!0;break t;case"rotateUp":this.state.canRotate=!0,this.movement.x=0,this.movement.y=-10;break t;case"rotateDown":this.state.canRotate=!0,this.movement.x=0,this.movement.y=10;break t;case"rotateLeft":this.state.canRotate=!0,this.movement.x=-10,this.movement.y=0;break t;case"rotateRight":this.state.canRotate=!0,this.movement.x=10,this.movement.y=0;break t;case"jump":!0===this.state.canJump&&!1===t.repeat&&(this.jumpOffset=this.jumpHeight),this.state.canJump=!1;break t}(this.jumpOffset>0||Object.values(this.state).some((t=>t)))&&this.ssp.render()}}onKeyUp(t){t:for(const[e,s]of Object.entries(this.keyCodeMap))if(s.includes(t.code))switch(e){case"moveForward":this.state.moveForward=!1;break t;case"moveBackward":this.state.moveBackward=!1;break t;case"moveLeft":this.state.moveLeft=!1;break t;case"moveRight":this.state.moveRight=!1;break t;case"moveUp":this.state.moveUp=!1;break t;case"moveDown":this.state.moveDown=!1;break t;case"rotateUp":case"rotateDown":case"rotateLeft":case"rotateRight":this.state.canRotate=!1;break t}}onDblClick(t){if(!0===this.dblClickForward){const[e]=this.ssp.viewport.getIntersects(t);if(e){const{point:t}=e;t.y+=this.eyeHeight,t.sub(this.camera.position),this._dblVector.copy(t),this._dblDeltaVector.set(0,0,0),this.ssp.render()}}}onPointerDown(t){null===this._pointerId&&0===t.button&&(this.container.setPointerCapture(t.pointerId),this._pointerId=t.pointerId,this.state.canRotate=!0)}onPointerMove(t){if(t.preventDefault(),this.enabled&&this.state.canRotate){let e=t.movementY,s=t.movementX;this.reverseRotate&&(s=-s,e=-e),this.movement.x=s,this.movement.y=e,this.ssp.render()}}onPointerUp(t){null!==this._pointerId&&(this.container.releasePointerCapture(t.pointerId),this._pointerId=null,this.state.canRotate=!1)}clearClashCache(){this.kneeInterObject=null,this.eyeInterObject=null}onClashCheck(t,e){const s=e.length(),i=e.clone().divideScalar(s);i.distanceToSquared(this.lastDirection)>1e-9&&this.clearClashCache(),this.lastDirection=i;const{eyeHeight:n,kneeHeight:a,camera:r,clashCheckDistance:h,clashDistance:c,clashLayers:l}=this;let{kneeInterObject:v,eyeInterObject:m}=this;if(!v){const e=t.clone().setY(t.y-n+a),s=new o(e,i,0,h);s.firstHitOnly=!0,null!=l&&d(s.layers,l),s.camera=r;const c=p(s,this.getCheckedObjects(e));this.kneeInterObject=v=c[0]}let y=-s;if(v&&(y+=v.distance,y<c))return!0;if(!m){const e=new o(t,i,0,h);e.firstHitOnly=!0,null!=l&&d(e.layers,l),e.camera=r;const s=p(e,this.getCheckedObjects(t));this.eyeInterObject=m=s[0]}let u=-s;if(m){if(u+=m.distance,u<c)return!0;m.distance=u}return v&&(v.distance=y),!1}getCheckedObjects(t){const{clashDistance:e,clashCheckDistance:s,searchRadiusFactor:i,clashFilter:o}=this,n=s*i,a=this.checkedSphere,r=n+e;a.set(t,r);const h=null!=o?o:function(){return!0};return this.viewport.scener.intersectsList.getAll().filter((t=>!!h(t)&&l(a,t)))}getGravityCheckedObjects(t,s){const i=this.gravityCheckedBox;let o=this.gravityCheckedObjects;if(o){const e=t.clone();e.y=s,i.containsPoint(t)&&i.containsPoint(e)||(o=null)}if(!o){const{eyeHeight:s,clashCheckDistance:n,gravitySearchFactor:a,clashDistance:r,clashFilter:h}=this,c=n+r,d=new e(c,c,0),p=t.clone().add(d),v=t.clone().sub(d);v.y-=s*a,i.set(v,p);const m=this.viewport.scener.intersectsList.getAll(),y=null!=h?h:function(){return!0};o=m.filter((t=>!!y(t)&&l(i,t)))}return o}gravityClashCheck(t,s){var i;let a=this.gravityInterObject;if(a){const{object:s,face:o,instanceId:r}=a,h=null===(i=s.geometry)||void 0===i?void 0:i.getAttribute("position");if(h&&o){let i=a.facePoints;if(!i){let t=s.matrixWorld;if(null!=r){const e=new n;s.getMatrixAt(r,e),t=e.premultiply(t)}const{a:c,b:l,c:d}=o,p=new e(h.getX(c),h.getY(c),h.getZ(c));p.applyMatrix4(t),p.setY(0);const v=new e(h.getX(l),h.getY(l),h.getZ(l));v.applyMatrix4(t),v.setY(0);const m=new e(h.getX(d),h.getY(d),h.getZ(d));m.applyMatrix4(t),m.setY(0),a.facePoints=i=[p,v,m]}let c=i[2],l=null;const d=t.clone();d.y=0;i.every((t=>{const e=t.clone();e.sub(c);const s=d.clone();if(s.sub(c),e.cross(s),l){if(e.dot(l)<=0)return!1}return l=e,c=t,!0}))||(this.gravityInterObject=a=null)}}if(!a){const i=new o(t,new e(0,-1,0));i.firstHitOnly=!0;const n=this.clashLayers;null!=n&&d(i.layers,n),i.camera=this.camera;const r=p(i,this.getGravityCheckedObjects(t,s));this.gravityInterObject=a=r[0]}return a}setOptions(t){const{position:s=new e,rotation:i=new a,moveSpeed:o,eyeHeight:n,kneeHeight:r,jumpHeight:h,enableClash:c,enableGravity:l,searchRadiusFactor:d,clashDistance:p,clashCheckDistance:m,gravitySpeed:u,gravitySearchFactor:b,reverseRotate:g,rotate:w,rotateSpeed:f,horizontalRotate:k,verticalRotate:C,dblClickForward:D,clashFilter:j,clashLayers:R}=t;if(n&&(this.eyeHeight=n),r&&(this.kneeHeight=r),h&&(this.jumpHeight=h),d&&(this.searchRadiusFactor=d),p&&(this.clashDistance=p),m&&(this.clashCheckDistance=m),u&&(this.gravitySpeed=u),b&&(this.gravitySearchFactor=b),null!=g&&(this.reverseRotate=g),null!=w&&(this.rotate=w),null!=k&&(this.horizontalRotate=k),null!=C&&(this.verticalRotate=C),y.isBoolean(D)&&(this.dblClickForward=D),y.isNumber(f)&&(this.rotateSpeed=f),null!=c&&(this.enableClash=c),null!=l&&(this.enableGravity=l),null!=j&&(this.clashFilter=j),null!=R&&(this.clashLayers=R),s&&(this.controls.setPosition(s.x,s.y+this.eyeHeight,s.z),this.gravityInterObject=null,this.clearClashCache()),i){const t=y.computeTargetByRotation(this.controls.getPosition(new e),i,v);this.controls.setTarget(t.x,t.y,t.z)}o&&(this.moveSpeed=o)}start(t){this.viewport.controls.saveState(),this.viewport.controls.enabled=!1,this.enabled=!0,this.setOptions(t),this.viewport.postRender.set("FirstPersonControls",this.update.bind(this)),this.ssp.signals.dblClick.add(this.onDblClick),this.ssp.signals.keyDown.add(this.onKeyDown),this.ssp.signals.keyUp.add(this.onKeyUp);const e=this.container;e.addEventListener("pointerdown",this.onPointerDown),e.addEventListener("pointermove",this.onPointerMove),e.addEventListener("pointerup",this.onPointerUp)}stop(){this.viewport.controls.reset(),this.viewport.controls.enabled=!0,this.enabled=!1,this.viewport.postRender.delete("FirstPersonControls"),this.ssp.signals.dblClick.remove(this.onDblClick),this.ssp.signals.keyDown.remove(this.onKeyDown),this.ssp.signals.keyUp.remove(this.onKeyUp);const t=this.container;t.removeEventListener("pointerdown",this.onPointerDown),t.removeEventListener("pointermove",this.onPointerMove),t.removeEventListener("pointerup",this.onPointerUp),this.ssp.render()}update(){if(!this.enabled)return;const{delta:t}=this.viewport.state,s=new e,{controls:i,state:o,camera:n,eyeHeight:h,kneeHeight:c}=this,l=i.getPosition(new e),d=20*this.moveSpeed,p=20*this.gravitySpeed;o.moveForward&&(s.z-=d),o.moveBackward&&(s.z+=d),o.moveLeft&&(s.x-=d),o.moveRight&&(s.x+=d),o.moveUp&&(s.y+=2*p),o.moveDown&&(s.y-=2*p),s.multiplyScalar(t);const{x:y,y:u}=this.movement,b=this.horizontalRotate&&0!==y,g=this.verticalRotate&&0!==u;if(this.rotate&&o.canRotate&&(b||g)){let{azimuthAngle:t,polarAngle:e}=i;g&&(e-=.003*u*this.rotateSpeed),b&&(t-=.003*y*this.rotateSpeed),i.rotateTo(t,e)}const w=new a(0,0,0,"YXZ");if(w.setFromQuaternion(n.quaternion),0!==w.y&&!s.equals(new e)){const t=new r;t.setFromAxisAngle(new e(0,1,0),w.y),s.applyQuaternion(t)}if(!this._dblVector.equals(new e)){const e=this._dblVector.clone().multiplyScalar(t);this._dblDeltaVector.add(e),this._dblDeltaVector.length()>this._dblVector.length()?(this._dblVector.set(0,0,0),this._dblDeltaVector.set(0,0,0)):s.add(e)}const f=l.clone();if((!this.enableClash||!this.onClashCheck(l,s))&&(f.add(s),this.gravityInterObject)){const t=this.gravityInterObject.point.clone().sub(f);t.y=0,t.length()>c&&(this.gravityInterObject=null)}let k=f.y;if(this.enableGravity){const e=k;this.jumpOffset>0&&(this.jumpOffset-=p*t,k+=2*p*t),k-=p*t,o.canJump=!1;const s=this.gravityClashCheck(f,k);if(s){const t=s.point.y+h;k<t&&(k=t,this.jumpOffset=0,o.canJump=!0)}e!==k&&this.clearClashCache()}f.y=k,m(l.x,f.x)&&m(l.y,f.y)&&m(l.z,f.z)||(i.moveTo(f.x,f.y,f.z),i.dollyTo(v))}}export{u as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-first-person-controls",
|
|
3
3
|
"pluginName": "FirstPersonControlsPlugin",
|
|
4
|
-
"version": "2.11.
|
|
4
|
+
"version": "2.11.65",
|
|
5
5
|
"description": "FirstPersonControls plugin for SoonSpace.js",
|
|
6
6
|
"main": "dist/index.esm.js",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
],
|
|
14
14
|
"author": "xunwei",
|
|
15
15
|
"license": "UNLICENSED",
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "5d1cb2d2594bc9518560592aaec513f0ddc16406",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"soonspacejs": "2.11.
|
|
18
|
+
"soonspacejs": "2.11.65"
|
|
19
19
|
}
|
|
20
20
|
}
|