@soonspacejs/plugin-patrol-controls 2.3.9 → 2.3.12
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 +4 -5
- package/dist/index.js +2 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import SoonSpace, { CameraViewpointData, Position
|
|
1
|
+
import SoonSpace, { CameraViewpointData, Position } from 'soonspacejs';
|
|
2
|
+
import { Topology } from 'soonspacejs/src/Library';
|
|
2
3
|
import { Tween } from '@tweenjs/tween.js';
|
|
3
4
|
import { PerspectiveCamera, Vector3, Euler } from 'three';
|
|
4
5
|
export interface DefaultOptions {
|
|
@@ -27,10 +28,8 @@ export interface DefaultOptions {
|
|
|
27
28
|
*/
|
|
28
29
|
onEnd: (endPosition: Position) => void;
|
|
29
30
|
}
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
export interface ResetOptions extends Pick<StartOptions, 'eyeHeight' | 'naviSpeed' | 'rotateSpeed'> {
|
|
33
|
-
}
|
|
31
|
+
export declare type StartOptions = Partial<DefaultOptions>;
|
|
32
|
+
export declare type ResetOptions = Pick<StartOptions, 'eyeHeight' | 'naviSpeed' | 'rotateSpeed'>;
|
|
34
33
|
export default class PatrolControls {
|
|
35
34
|
ssp: SoonSpace;
|
|
36
35
|
camera: PerspectiveCamera;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t="undefined"!=typeof globalThis?globalThis:t||self).PatrolControlsPlugin=i()}(this,(function(){"use strict";
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation.
|
|
4
4
|
|
|
@@ -12,4 +12,4 @@ var PatrolControlsPlugin=function(){"use strict";
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */function t(t,i,s
|
|
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())}))}return class{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.points=[],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.ssp.setCameraViewpoint(this._cameraViewpointData),this.ssp.setControlsOptions({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.setControlsOptions({enabled:!0})}init(t){const{cameraManager:i}=this.ssp.viewport;this.isPaused=!1,this.isStoped=!1,this._mainCameraViewpointData=i.getCameraViewpoint(),this.camera=i.createCamera("patrolControls"),i.setCurrentCamera(this.camera),t.nodes.forEach((t=>{this.points.push(t.getWorldPosition(new this.ssp.THREE.Vector3))}))}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){if(Math.abs(t.x-i.x)<=5&&Math.abs(t.z-i.z)<=5)return this.camera.rotation.clone();{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(){const t=this.points[this.nextPointIndex],i=this.points[this.nextPointIndex+1];return this.computedRotation(t,i)}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.points.length)null==e||e(this.camera.position.clone()),i(!0),this.isStoped=!0;else{const i=this.camera.position.clone(),e=this.points[this.nextPointIndex].clone().setY(this.points[this.nextPointIndex].y+this.options.eyeHeight),s=i.distanceTo(e);if(this.states.moveDuration=0===this.nextPointIndex?1e3:s/this.options.naviSpeed/.6,0!==this.nextPointIndex||this.options.flyToStartPoint?yield this.ssp.animation(this.camera.position,e,{duration:this.states.moveDuration},((i,e)=>{null==t||t(i),this.ssp.signals.cameraChange.dispatch()}),(t=>{this._positionTween=t})):this.camera.position.copy(e),this.nextPointIndex<this.points.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)=>{}),(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.points=[],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}}}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-patrol-controls",
|
|
3
3
|
"pluginName": "PatrolControlsPlugin",
|
|
4
|
-
"version": "2.3.
|
|
4
|
+
"version": "2.3.12",
|
|
5
5
|
"description": "Patrol-controls plugin for SoonSpace.js",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
],
|
|
14
14
|
"author": "xuek",
|
|
15
15
|
"license": "UNLICENSED",
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "0d78f16e23ccd4cfdd7edb730770febdbd83ffa1"
|
|
17
17
|
}
|