@soonspacejs/plugin-patrol-controls 2.8.7 → 2.8.9
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 +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Vector3 as t,Matrix4 as i,Euler as s}from"three";const e="patrolControls";class o{constructor(t){this.ssp=t,this.options={naviSpeed:1,rotateSpeed:1,eyeHeight:150,flyToStartPoint:!0,onUpdate:()=>{},onProgress:()=>{},onEnd:()=>{}},this.states={moveDuration:0,rotateDuration:0},this.nodes=[],this.nextPointIndex=0,this._nodeDistances=[],this._totalDistance=0,this._updatePercent=0,this._needsUpdateProgress=!1,this.isPaused=!1,this.isStoped=!0,this._positionTween=null,this._rotationTween=null,this._cameraViewpointData=null,this._mainCameraViewpointData=null
|
|
1
|
+
import{Vector3 as t,Matrix4 as i,Euler as s}from"three";const e="patrolControls";class o{constructor(t){this.ssp=t,this.options={naviSpeed:1,rotateSpeed:1,eyeHeight:150,flyToStartPoint:!0,onUpdate:()=>{},onProgress:()=>{},onEnd:()=>{}},this.states={moveDuration:0,rotateDuration:0},this.nodes=[],this.nextPointIndex=0,this._nodeDistances=[],this._totalDistance=0,this._updatePercent=0,this._needsUpdateProgress=!1,this.isPaused=!1,this.isStoped=!0,this._positionTween=null,this._rotationTween=null,this._cameraViewpointData=null,this._mainCameraViewpointData=null;const{cameraManager:i}=this.ssp.viewport;this.camera=i.cameras[e]||i.createCamera(e)}start(t,i){this.isStoped?(this.init(t),this.initOptions(i),this.patrolStart()):this.ssp.utils.warn("巡检已经开始!")}setProgress(t){var i,s;this._updatePercent=Math.min(Math.max(t,0),1),this._needsUpdateProgress=!0,null===(i=this._positionTween)||void 0===i||i.stop(),null===(s=this._rotationTween)||void 0===s||s.stop()}setOptions(t){if(this.isStoped)return;const{naviSpeed:i,rotateSpeed:s}=t;if(i&&this._positionTween){const t=this.states.moveDuration*this.options.naviSpeed/i;this._positionTween.duration(t),this.states.moveDuration=t}if(s&&this._rotationTween){const t=this.states.rotateDuration*this.options.rotateSpeed/s;this._rotationTween.duration(t),this.states.rotateDuration=t}this.initOptions(t)}pause(){var t,i;if(this.isPaused||this.isStoped)return;this._cameraViewpointData=this.ssp.getCameraViewpoint();const{cameraManager:s}=this.ssp.viewport,e=s.getMainCamera();s.setCurrentCamera(e),this._cameraViewpointData&&this.ssp.setCameraViewpoint(this._cameraViewpointData),this.ssp.viewport.controls.currentControls.enabled=!1,this.isPaused=!0,null===(t=this._positionTween)||void 0===t||t.pause(),null===(i=this._rotationTween)||void 0===i||i.pause()}resume(){var t,i;if(this.isPaused&&!this.isStoped){if(this._cameraViewpointData){const{cameraManager:t}=this.ssp.viewport;t.setCurrentCamera(this.camera),this.ssp.setCameraViewpoint(this._cameraViewpointData)}this.isPaused=!1,null===(t=this._positionTween)||void 0===t||t.resume(),null===(i=this._rotationTween)||void 0===i||i.resume()}}stop(){if(this.isStoped)return;this.patrolStop();const{cameraManager:t}=this.ssp.viewport,i=t.getMainCamera();t.setCurrentCamera(i),this._mainCameraViewpointData&&this.ssp.setCameraViewpoint(this._mainCameraViewpointData),this.ssp.viewport.controls.currentControls.enabled=!0}init(t){const{cameraManager:i}=this.ssp.viewport;this.isPaused=!1,this.isStoped=!1,this.nextPointIndex=0,this._mainCameraViewpointData=this.ssp.getCameraViewpoint(),i.setCurrentCamera(this.camera),this.ssp.setCameraViewpoint(this._mainCameraViewpointData),this.nodes=[...t.nodes]}initOptions(i){const{eyeHeight:s,naviSpeed:e,rotateSpeed:o,flyToStartPoint:n=!0,onUpdate:a,onProgress:r,onEnd:h}=i;s&&(this.options.eyeHeight=s),e&&(this.options.naviSpeed=e),o&&(this.options.rotateSpeed=o),this.options.flyToStartPoint=n,a&&(this.options.onUpdate=a),r&&(this.options.onProgress=r),h&&(this.options.onEnd=h),this._nodeDistances.length=0,this._nodeDistances.push(0),this._totalDistance=0;for(let i=0,s=this.nodes.length;i<s-1;i++){const s=this.nodes[i],e=this.nodes[i+1];if(s&&e){const i=s.getWorldPosition(new t),o=e.getWorldPosition(new t);i.y+=this.options.eyeHeight,o.y+=this.options.eyeHeight;const n=i.distanceTo(o);this._nodeDistances.push(n),this._totalDistance+=n}}}computedRotation(t,e){const o=new i;o.lookAt(t,e,this.camera.up);const n=(new s).setFromRotationMatrix(o,"YXZ");return n.copy(this.ssp.utils.rotationAFix(this.camera.rotation,n.clone())),0===n.y&&(0===n.z?n.x=0:0===n.x&&(n.z=0)),n}computeNextRotation(){let i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.nextPointIndex;var e,o;const n=null===(e=this.nodes[i])||void 0===e?void 0:e.getWorldPosition(new t),a=null===(o=this.nodes[i+1])||void 0===o?void 0:o.getWorldPosition(new t);return n&&a?this.computedRotation(n,a):new s}async patrolStart(){return new Promise((async i=>{const{onUpdate:s,onProgress:e,onEnd:o}=this.options;if(this.nextPointIndex>=this.nodes.length)null==o||o(this.camera.position.clone()),i(!0);else{if(this._needsUpdateProgress){let i=this._totalDistance*this._updatePercent;for(let s=0,e=this._nodeDistances.length;s<e;s++)if(i-=this._nodeDistances[s],i<0){this.nextPointIndex=s,i+=this._nodeDistances[s];const e=i/this._nodeDistances[s]||0,o=this.nodes[s-1],n=this.nodes[s],a=new t,r=o.getWorldPosition(new t),h=n.getWorldPosition(new t);r.y+=this.options.eyeHeight,h.y+=this.options.eyeHeight;const p=(new t).subVectors(h,r).multiplyScalar(e);a.copy(r).add(p),this.camera.position.copy(a),this.camera.rotation.copy(this.computeNextRotation(s-1));break}this._needsUpdateProgress=!1}const i=this.camera.position.clone(),o=this.computeNextRotation(),n=this.nodes[this.nextPointIndex],a=n.getWorldPosition(new t);a.setY(a.y+this.options.eyeHeight);const r=i.distanceTo(a);if(this.states.moveDuration=0===this.nextPointIndex?1e3:r/this.options.naviSpeed/.6,0!==this.nextPointIndex||this.options.flyToStartPoint)try{await this.ssp.animation(this.camera.position,a,{duration:this.states.moveDuration},(t=>{var i;this.isPaused&&(null===(i=this._positionTween)||void 0===i||i.pause());const r=this.camera.position.distanceTo(a);if(null==s||s(t,o,n,r),this._nodeDistances[this.nextPointIndex]>0){let t=this._nodeDistances.slice(0,this.nextPointIndex+1).reduce(((t,i)=>t+i),0);t-=r,null==e||e({patrolled:t,total:this._totalDistance,percent:t/this._totalDistance})}}),(t=>{this._positionTween=t}))}catch(t){}else this.camera.position.copy(a);if(this.nextPointIndex<this.nodes.length-1){const t=this.camera.rotation.clone(),i=this.computeNextRotation(),s=Math.abs(t.x-i.x)+Math.abs(t.y-i.y)+Math.abs(t.y-i.y);if(this.states.rotateDuration=0===this.nextPointIndex?1e3:100*s/this.options.rotateSpeed,0!==this.nextPointIndex||this.options.flyToStartPoint)try{await this.ssp.animation(this.camera.rotation,i,{duration:this.states.rotateDuration},((t,i)=>{var s;this.isPaused&&(null===(s=this._rotationTween)||void 0===s||s.pause())}),(t=>{this._rotationTween=t}))}catch(t){}else this.camera.rotation.copy(i)}this._needsUpdateProgress||this.nextPointIndex++,this.isStoped||await this.patrolStart()}}))}patrolStop(){var t,i;this.options={naviSpeed:1,rotateSpeed:1,eyeHeight:150,flyToStartPoint:!0,onUpdate:()=>{},onProgress:()=>{},onEnd:()=>{}},this.nodes=[],this.nextPointIndex=0,this.isPaused=!1,this.isStoped=!0,this._needsUpdateProgress=!1,null===(t=this._positionTween)||void 0===t||t.stop(),null===(i=this._rotationTween)||void 0===i||i.stop(),this._positionTween=null,this._rotationTween=null}}export{o as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-patrol-controls",
|
|
3
3
|
"pluginName": "PatrolControlsPlugin",
|
|
4
|
-
"version": "2.8.
|
|
4
|
+
"version": "2.8.9",
|
|
5
5
|
"description": "Patrol-controls plugin for SoonSpace.js",
|
|
6
6
|
"main": "dist/index.esm.js",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"soonspacejs",
|
|
12
12
|
"patrol-controls"
|
|
13
13
|
],
|
|
14
|
-
"author": "
|
|
14
|
+
"author": "xunwei",
|
|
15
15
|
"license": "UNLICENSED",
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "fc652524e758f22153c960b872dd15aac7b492ac",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"soonspacejs": "2.8.
|
|
18
|
+
"soonspacejs": "2.8.9"
|
|
19
19
|
}
|
|
20
20
|
}
|