@soonspacejs/plugin-patrol-controls 2.5.59 → 2.6.0
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.d.ts +8 -7
- package/dist/index.esm.js +1 -15
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import SoonSpace, { CameraViewpointData, CameraTargetViewData, Position } from 'soonspacejs';
|
|
2
|
-
import { Node } from 'soonspacejs/types/Library';
|
|
3
|
-
import { Topology } from 'soonspacejs/types/Library';
|
|
4
|
-
import { Tween } from '@tweenjs/tween.js';
|
|
5
1
|
import { PerspectiveCamera, Vector3, Euler } from 'three';
|
|
2
|
+
import SoonSpace from 'soonspacejs';
|
|
3
|
+
import type { CameraViewpointData, CameraTargetViewData, Position } from 'soonspacejs';
|
|
4
|
+
import type { Node } from 'soonspacejs/types/Library';
|
|
5
|
+
import type { Topology } from 'soonspacejs/types/Library';
|
|
6
|
+
import type { Tween } from '@tweenjs/tween.js';
|
|
6
7
|
export interface DefaultOptions {
|
|
7
8
|
eyeHeight: number;
|
|
8
9
|
/**
|
|
@@ -26,8 +27,8 @@ export interface DefaultOptions {
|
|
|
26
27
|
*/
|
|
27
28
|
onEnd: (endPosition: Position) => void;
|
|
28
29
|
}
|
|
29
|
-
export
|
|
30
|
-
export
|
|
30
|
+
export type StartOptions = Partial<DefaultOptions>;
|
|
31
|
+
export type ResetOptions = Pick<StartOptions, 'eyeHeight' | 'naviSpeed' | 'rotateSpeed'>;
|
|
31
32
|
export default class PatrolControlsPlugin {
|
|
32
33
|
ssp: SoonSpace;
|
|
33
34
|
camera: PerspectiveCamera;
|
|
@@ -86,7 +87,7 @@ export default class PatrolControlsPlugin {
|
|
|
86
87
|
* 计算下一弧度
|
|
87
88
|
* @returns
|
|
88
89
|
*/
|
|
89
|
-
private
|
|
90
|
+
private computeNextRotation;
|
|
90
91
|
/**
|
|
91
92
|
* 开始巡检
|
|
92
93
|
* @returns
|
package/dist/index.esm.js
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) Microsoft Corporation.
|
|
3
|
-
|
|
4
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
-
purpose with or without fee is hereby granted.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
-
***************************************************************************** */
|
|
15
|
-
function t(t,i,e,s){return new(e||(e=Promise))((function(o,n){function a(t){try{h(s.next(t))}catch(t){n(t)}}function r(t){try{h(s.throw(t))}catch(t){n(t)}}function h(t){var i;t.done?o(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(a,r)}h((s=s.apply(t,i||[])).next())}))}class i{constructor(t){this._mainCameraViewpointData=null,this.ssp=t,this.camera=t.viewport.camera,this.options={naviSpeed:1,rotateSpeed:1,eyeHeight:150,flyToStartPoint:!0,onUpdate:()=>{},onEnd:()=>{}},this.states={moveDuration:0,rotateDuration:0},this.nodes=[],this.nextPointIndex=0,this.isPaused=!1,this.isStoped=!1,this._positionTween=null,this._rotationTween=null,this._cameraViewpointData=null}start(t,i){this.initOptions(i),this.init(t),this.patrolStart()}setOptions(t){if(this.isStoped)return;const{naviSpeed:i,rotateSpeed:e}=t;if(i&&this._positionTween){const t=this.states.moveDuration*this.options.naviSpeed/i;this._positionTween.duration(t),this.states.moveDuration=t}if(e&&this._rotationTween){const t=this.states.rotateDuration*this.options.rotateSpeed/e;this._rotationTween.duration(t),this.states.rotateDuration=t}this.initOptions(t)}pause(){var t,i;if(this.isPaused)return;this._cameraViewpointData=this.ssp.getCameraViewpoint();const{cameraManager:e}=this.ssp.viewport,s=e.getMainCamera();e.setCurrentCamera(s),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){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(){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(),this.camera=i.cameras.patrolControls||i.createCamera("patrolControls"),i.setCurrentCamera(this.camera),this.ssp.setCameraViewpoint(this._mainCameraViewpointData),this.nodes=[...t.nodes]}initOptions(t){const{eyeHeight:i,naviSpeed:e,rotateSpeed:s,flyToStartPoint:o=!0,onUpdate:n,onEnd:a}=t;i&&(this.options.eyeHeight=i),e&&(this.options.naviSpeed=e),s&&(this.options.rotateSpeed=s),this.options.flyToStartPoint=o,n&&(this.options.onUpdate=n),a&&(this.options.onEnd=a)}computedRotation(t,i){const e=new this.ssp.THREE.Matrix4;e.lookAt(t,i,this.camera.up);const s=(new this.ssp.THREE.Euler).setFromRotationMatrix(e,"YXZ");return s.copy(this.ssp.utils.rotationAFix(this.camera.rotation,s.clone())),0===s.y&&(0===s.z?s.x=0:0===s.x&&(s.z=0)),s}computedNextRotation(){var t;const i=this.nodes[this.nextPointIndex].getWorldPosition(new this.ssp.THREE.Vector3),e=null===(t=this.nodes[this.nextPointIndex+1])||void 0===t?void 0:t.getWorldPosition(new this.ssp.THREE.Vector3);return e?this.computedRotation(i,e):new this.ssp.THREE.Euler}patrolStart(){return t(this,void 0,void 0,(function*(){return new Promise((i=>t(this,void 0,void 0,(function*(){const{onUpdate:t,onEnd:e}=this.options;if(this.nextPointIndex===this.nodes.length)null==e||e(this.camera.position.clone()),i(!0),this.isStoped=!0;else{const i=this.camera.position.clone(),e=this.computedNextRotation(),s=this.nodes[this.nextPointIndex],o=s.getWorldPosition(new this.ssp.THREE.Vector3);o.setY(o.y+this.options.eyeHeight);const n=i.distanceTo(o);if(this.states.moveDuration=0===this.nextPointIndex?1e3:n/this.options.naviSpeed/.6,0!==this.nextPointIndex||this.options.flyToStartPoint?yield this.ssp.animation(this.camera.position,o,{duration:this.states.moveDuration},((i,n)=>{var a;this.isPaused&&(null===(a=this._positionTween)||void 0===a||a.pause()),null==t||t(i,e,s,this.camera.position.clone().distanceTo(o))}),(t=>{this._positionTween=t})):this.camera.position.copy(o),this.nextPointIndex<this.nodes.length-1){const t=this.camera.rotation.clone(),i=this.computedNextRotation(),e=Math.abs(t.x-i.x)+Math.abs(t.y-i.y)+Math.abs(t.y-i.y);this.states.rotateDuration=0===this.nextPointIndex?1e3:100*e/this.options.rotateSpeed,0!==this.nextPointIndex||this.options.flyToStartPoint?yield this.ssp.animation(this.camera.rotation,i,{duration:this.states.rotateDuration},((t,i)=>{var e;this.isPaused&&(null===(e=this._rotationTween)||void 0===e||e.pause())}),(t=>{this._rotationTween=t})):this.camera.rotation.copy(i)}this.nextPointIndex++,yield this.patrolStart()}}))))}))}patrolStop(){var t,i;this.options={naviSpeed:1,rotateSpeed:1,eyeHeight:150,flyToStartPoint:!0,onUpdate:()=>{},onEnd:()=>{}},this.nodes=[],this.nextPointIndex=0,this.isPaused=!1,this.isStoped=!0,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{i as default};
|
|
1
|
+
import{Matrix4 as t,Euler as i,Vector3 as e}from"three";function s(t,i,e,s){return new(e||(e=Promise))((function(o,n){function a(t){try{h(s.next(t))}catch(t){n(t)}}function r(t){try{h(s.throw(t))}catch(t){n(t)}}function h(t){var i;t.done?o(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(a,r)}h((s=s.apply(t,i||[])).next())}))}const o="patrolControls";class n{constructor(t){this.isPaused=!1,this.isStoped=!0,this._mainCameraViewpointData=null,this.ssp=t,this.camera=t.viewport.camera,this.options={naviSpeed:1,rotateSpeed:1,eyeHeight:150,flyToStartPoint:!0,onUpdate:()=>{},onEnd:()=>{}},this.states={moveDuration:0,rotateDuration:0},this.nodes=[],this.nextPointIndex=0,this._positionTween=null,this._rotationTween=null,this._cameraViewpointData=null}start(t,i){this.isStoped?(this.initOptions(i),this.init(t),this.patrolStart()):this.ssp.utils.warn("巡检已经开始!")}setOptions(t){if(this.isStoped)return;const{naviSpeed:i,rotateSpeed:e}=t;if(i&&this._positionTween){const t=this.states.moveDuration*this.options.naviSpeed/i;this._positionTween.duration(t),this.states.moveDuration=t}if(e&&this._rotationTween){const t=this.states.rotateDuration*this.options.rotateSpeed/e;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:e}=this.ssp.viewport,s=e.getMainCamera();e.setCurrentCamera(s),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(),this.camera=i.cameras[o]||i.createCamera(o),i.setCurrentCamera(this.camera),this.ssp.setCameraViewpoint(this._mainCameraViewpointData),this.nodes=[...t.nodes]}initOptions(t){const{eyeHeight:i,naviSpeed:e,rotateSpeed:s,flyToStartPoint:o=!0,onUpdate:n,onEnd:a}=t;i&&(this.options.eyeHeight=i),e&&(this.options.naviSpeed=e),s&&(this.options.rotateSpeed=s),this.options.flyToStartPoint=o,n&&(this.options.onUpdate=n),a&&(this.options.onEnd=a)}computedRotation(e,s){const o=new t;o.lookAt(e,s,this.camera.up);const n=(new i).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(){var t;const s=this.nodes[this.nextPointIndex].getWorldPosition(new e),o=null===(t=this.nodes[this.nextPointIndex+1])||void 0===t?void 0:t.getWorldPosition(new e);return o?this.computedRotation(s,o):new i}patrolStart(){return s(this,void 0,void 0,(function*(){return new Promise((t=>s(this,void 0,void 0,(function*(){const{onUpdate:i,onEnd:s}=this.options;if(this.nextPointIndex===this.nodes.length)null==s||s(this.camera.position.clone()),t(!0),this.isStoped=!0;else{const t=this.camera.position.clone(),s=this.computeNextRotation(),o=this.nodes[this.nextPointIndex],n=o.getWorldPosition(new e);n.setY(n.y+this.options.eyeHeight);const a=t.distanceTo(n);if(this.states.moveDuration=0===this.nextPointIndex?1e3:a/this.options.naviSpeed/.6,0!==this.nextPointIndex||this.options.flyToStartPoint?yield this.ssp.animation(this.camera.position,n,{duration:this.states.moveDuration},(t=>{var e;this.isPaused&&(null===(e=this._positionTween)||void 0===e||e.pause()),null==i||i(t,s,o,this.camera.position.clone().distanceTo(n))}),(t=>{this._positionTween=t})):this.camera.position.copy(n),this.nextPointIndex<this.nodes.length-1){const t=this.camera.rotation.clone(),i=this.computeNextRotation(),e=Math.abs(t.x-i.x)+Math.abs(t.y-i.y)+Math.abs(t.y-i.y);this.states.rotateDuration=0===this.nextPointIndex?1e3:100*e/this.options.rotateSpeed,0!==this.nextPointIndex||this.options.flyToStartPoint?yield this.ssp.animation(this.camera.rotation,i,{duration:this.states.rotateDuration},((t,i)=>{var e;this.isPaused&&(null===(e=this._rotationTween)||void 0===e||e.pause())}),(t=>{this._rotationTween=t})):this.camera.rotation.copy(i)}this.nextPointIndex++,yield this.patrolStart()}}))))}))}patrolStop(){var t,i;this.options={naviSpeed:1,rotateSpeed:1,eyeHeight:150,flyToStartPoint:!0,onUpdate:()=>{},onEnd:()=>{}},this.nodes=[],this.nextPointIndex=0,this.isPaused=!1,this.isStoped=!0,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{n 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.
|
|
4
|
+
"version": "2.6.0",
|
|
5
5
|
"description": "Patrol-controls 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": "xuek",
|
|
15
15
|
"license": "UNLICENSED",
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "d0dc74ef0ec37c5792bc8063fba0adadcdf39852",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"soonspacejs": "2.
|
|
18
|
+
"soonspacejs": "2.6.0"
|
|
19
19
|
}
|
|
20
20
|
}
|