@soonspacejs/plugin-model-blast 2.5.52 → 2.5.54

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soonspacejs/plugin-model-blast",
3
3
  "pluginName": "ModelBlastPlugin",
4
- "version": "2.5.52",
4
+ "version": "2.5.54",
5
5
  "description": "Model blast plugin for SoonSpace.js",
6
6
  "main": "dist/index.esm.js",
7
7
  "module": "dist/index.esm.js",
@@ -13,5 +13,8 @@
13
13
  ],
14
14
  "author": "xuek",
15
15
  "license": "UNLICENSED",
16
- "gitHead": "23dac225ca5572236615bd98110d906606ca4e27"
16
+ "gitHead": "e65c1d193de1b285780a1c6aebc6cb25d2d2d50c",
17
+ "peerDependencies": {
18
+ "soonspacejs": "2.5.54"
19
+ }
17
20
  }
@@ -0,0 +1,98 @@
1
+ import SoonSpace, { CameraViewpointData, Position } from 'soonspacejs';
2
+ import { Topology } from 'soonspacejs/types/Library';
3
+ import { Tween } from '@tweenjs/tween.js';
4
+ import { PerspectiveCamera, Vector3, Euler } from 'three';
5
+ export interface DefaultOptions {
6
+ /**
7
+ * 眼睛高度
8
+ */
9
+ eyeHeight: number;
10
+ /**
11
+ * 巡检速度
12
+ */
13
+ naviSpeed: number;
14
+ /**
15
+ * 相机转向速度
16
+ */
17
+ rotateSpeed: number;
18
+ /**
19
+ * 是否飞向起始点位置
20
+ */
21
+ flyToStartPoint: boolean;
22
+ /**
23
+ * 更新回调
24
+ */
25
+ onUpdate: (realTimePosition: Position) => void;
26
+ /**
27
+ * 结束回调
28
+ */
29
+ onEnd: (endPosition: Position) => void;
30
+ }
31
+ export declare type StartOptions = Partial<DefaultOptions>;
32
+ export declare type ResetOptions = Pick<StartOptions, 'eyeHeight' | 'naviSpeed' | 'rotateSpeed'>;
33
+ export default class PatrolControls {
34
+ ssp: SoonSpace;
35
+ camera: PerspectiveCamera;
36
+ options: DefaultOptions;
37
+ states: {
38
+ moveDuration: number;
39
+ rotateDuration: number;
40
+ };
41
+ points: Vector3[];
42
+ nextPointIndex: number;
43
+ isPaused: boolean;
44
+ isStoped: boolean;
45
+ _positionTween: Tween<Vector3> | null;
46
+ _rotationTween: Tween<Euler> | null;
47
+ _cameraViewpointData: CameraViewpointData | null;
48
+ /**
49
+ * 主相机视角数据
50
+ */
51
+ _mainCameraViewpointData: CameraViewpointData | null;
52
+ constructor(ssp: SoonSpace);
53
+ /**
54
+ * 开始巡检
55
+ *
56
+ * @param path
57
+ * @param options
58
+ */
59
+ start(path: Topology, options: StartOptions): void;
60
+ /**
61
+ * 设置巡检参数
62
+ * @param options
63
+ * @returns
64
+ */
65
+ setOptions(options: ResetOptions): void;
66
+ /**
67
+ * 暂停巡检
68
+ */
69
+ pause(): void;
70
+ /**
71
+ * 恢复巡检
72
+ */
73
+ resume(): void;
74
+ /**
75
+ * 中断巡检
76
+ */
77
+ stop(): void;
78
+ private init;
79
+ private initOptions;
80
+ /**
81
+ * 计算两点之间的弧度
82
+ * @param sourcePoint
83
+ * @param targetPoint
84
+ * @returns
85
+ */
86
+ private computedRotation;
87
+ /**
88
+ * 计算下一弧度
89
+ * @returns
90
+ */
91
+ private computedNextRotation;
92
+ /**
93
+ * 开始巡检
94
+ * @returns
95
+ */
96
+ private patrolStart;
97
+ private patrolStop;
98
+ }
@@ -0,0 +1,15 @@
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,s,e){return new(s||(s=Promise))((function(o,n){function a(t){try{h(e.next(t))}catch(t){n(t)}}function r(t){try{h(e.throw(t))}catch(t){n(t)}}function h(t){var i;t.done?o(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(a,r)}h((e=e.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.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: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)return;this._cameraViewpointData=this.ssp.getCameraViewpoint();const{cameraManager:s}=this.ssp.viewport,e=s.getMainCamera();s.setCurrentCamera(e),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:s,rotateSpeed:e,flyToStartPoint:o=!0,onUpdate:n,onEnd:a}=t;i&&(this.options.eyeHeight=i),s&&(this.options.naviSpeed=s),e&&(this.options.rotateSpeed=e),this.options.flyToStartPoint=o,n&&(this.options.onUpdate=n),a&&(this.options.onEnd=a)}computedRotation(t,i){const s=new this.ssp.THREE.Matrix4;s.lookAt(t,i,this.camera.up);const e=(new this.ssp.THREE.Euler).setFromRotationMatrix(s,"YXZ");return e.copy(this.ssp.utils.rotationAFix(this.camera.rotation,e.clone())),0===e.y&&(0===e.z?e.x=0:0===e.x&&(e.z=0)),e}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:s}=this.options;if(this.nextPointIndex===this.points.length)null==s||s(this.camera.position.clone()),i(!0),this.isStoped=!0;else{const i=this.camera.position.clone(),s=this.points[this.nextPointIndex].clone().setY(this.points[this.nextPointIndex].y+this.options.eyeHeight),e=i.distanceTo(s);if(this.states.moveDuration=0===this.nextPointIndex?1e3:e/this.options.naviSpeed/.6,0!==this.nextPointIndex||this.options.flyToStartPoint?yield this.ssp.animation(this.camera.position,s,{duration:this.states.moveDuration},((i,s)=>{null==t||t(i),this.ssp.signals.cameraChange.dispatch()}),(t=>{this._positionTween=t})):this.camera.position.copy(s),this.nextPointIndex<this.points.length-1){const t=this.camera.rotation.clone(),i=this.computedNextRotation(),s=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*s/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}}export{i as default};
@@ -0,0 +1,15 @@
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
+ /*! *****************************************************************************
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
+ PERFORMANCE OF THIS SOFTWARE.
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){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}}}));