@soonspacejs/plugin-navigation 2.13.17 → 2.14.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.
@@ -1,5 +1,5 @@
1
1
  import { OrthographicCamera } from 'three';
2
- import SoonSpace from 'soonspacejs';
2
+ import { default as SoonSpace } from 'soonspacejs';
3
3
  import { SoonSpaceCamera } from './ssp-camera';
4
4
  export declare class MapCamera extends SoonSpaceCamera<OrthographicCamera> {
5
5
  readonly ssp: SoonSpace;
@@ -1,4 +1,4 @@
1
- import SoonSpace from 'soonspacejs';
1
+ import { default as SoonSpace } from 'soonspacejs';
2
2
  import { Camera, Euler, Object3D, Quaternion, Vector3 } from 'three';
3
3
  import { GyroListener } from '../utils/gyro';
4
4
  import { SoonSpaceCamera } from './ssp-camera';
@@ -49,7 +49,7 @@ export declare class NavigateCamera extends SoonSpaceCamera<Camera> {
49
49
  private _positionTween;
50
50
  private autoFollowRender;
51
51
  /** 相机位置记录用的对象,用于恢复相机位置和朝向使用 */
52
- protected _cameraPlaceholder: Object3D<import("three").Object3DEventMap>;
52
+ protected _cameraPlaceholder: Object3D<import('three').Object3DEventMap>;
53
53
  /** 取消飞向动画 */
54
54
  disabledAnimate: boolean;
55
55
  /** 第三人称相机距离跟踪目标距离 */
@@ -111,7 +111,7 @@ export declare class NavigateCamera extends SoonSpaceCamera<Camera> {
111
111
  /** 陀螺仪的旋转欧拉角 */
112
112
  protected _gyroRotation: Euler;
113
113
  get targetRotationAfterFix(): EulerArray;
114
- get targetPositionAfterFix(): import("./types").VectorArray;
114
+ get targetPositionAfterFix(): import('./types').VectorArray;
115
115
  get realDistanceToTarget(): number;
116
116
  get realRotationToTarget(): Vector3;
117
117
  protected _orientationType: NAVIGATE_ORIENTATION_TYPE;
@@ -1,5 +1,5 @@
1
1
  import { Camera } from 'three';
2
- import SoonSpace from 'soonspacejs';
2
+ import { default as SoonSpace } from 'soonspacejs';
3
3
  export declare abstract class SoonSpaceCamera<C extends Camera = Camera> {
4
4
  readonly ssp: SoonSpace;
5
5
  nativeCamera: C;
@@ -7,5 +7,5 @@ export declare function eulerToVector3(e: Euler): Vector3;
7
7
  * @param e 欧拉角
8
8
  */
9
9
  export declare function normalizeEuler(e: Euler): Vector3;
10
- export declare function getFixVector(v: FixVector, target?: Object3DLike): import("./types").VectorArray;
11
- export declare function getFixEuler(e: FixEuler, target?: Object3DLike): import("./types").EulerArray;
10
+ export declare function getFixVector(v: FixVector, target?: Object3DLike): import('./types').VectorArray;
11
+ export declare function getFixEuler(e: FixEuler, target?: Object3DLike): import('./types').EulerArray;
package/dist/index.esm.js CHANGED
@@ -1 +1,885 @@
1
- import{OrthographicCamera as t,Matrix4 as e,Quaternion as i,Euler as o,Vector3 as n,PerspectiveCamera as s,Object3D as r,MathUtils as a,Matrix3 as h}from"three";class l{constructor(t,e){this.ssp=t,this.nativeCamera=e,this._isActive=!1,this.ssp.signals.cameraObjectChange.add(()=>{const t=this.ssp.viewport.cameraManager.currentCamera;this._isActive&&t===this.nativeCamera||(t===this.nativeCamera?(this._onBeforeEnter(),this.onEnter()):this._isActive&&t!==this.nativeCamera&&(this._onBeforeQuit(),this.onQuit()))})}active(){this.ssp.viewport.cameraManager.setCurrentCamera(this.nativeCamera)}_onBeforeEnter(){this._isActive=!0}_onBeforeQuit(){this._isActive=!1}onEnter(){}onQuit(){}}class u extends l{get zoom(){return this._zoom}set zoom(t){this._zoom=t,this.resizeCamera()}constructor(e){const i=new t;super(e,i),this.ssp=e,this.resizeObserver=new ResizeObserver(()=>{this.resizeCamera()}),this._zoom=.01,i.far=2e5}resizeCamera(){if(this._isActive){const{clientWidth:t,clientHeight:e}=this.ssp.viewport.renderer.domElement,i=t*this.zoom/2,o=e*this.zoom/2;this.nativeCamera.left=-i,this.nativeCamera.right=i,this.nativeCamera.top=o,this.nativeCamera.bottom=-o,this.nativeCamera.updateProjectionMatrix()}}onEnter(){console.log("map camera enter"),this.ssp.domElement&&(this.resizeObserver.observe(this.ssp.domElement),this.resizeCamera())}onQuit(){this.ssp.domElement&&(this.resizeObserver.unobserve(this.ssp.domElement),console.log("map camera quit"))}}class c{constructor(t,e,i,o){this.gyroEvent=null,this.onChange=()=>{},this._isActive=!1,this.defaultBeta=null,this.defaultAlpha=null,this.defaultGamma=null,this.cache=null,this.beta=null,this.alpha=null,this.gamma=null,this.gyroX=null==t||t,this.gyroY=null==e||e,this.gyroZ=null==i||i,this.absolute=null==o||o}requestPermisson(){return new Promise((t,e)=>{var i;window.DeviceOrientationEvent.requestPermission||t(!0),null===(i=window.DeviceOrientationEvent)||void 0===i||i.requestPermission().then(i=>{"granted"===i?t(!0):e("用户拒绝使用陀螺仪权限")})})}async active(){await this.requestPermisson(),this._isActive=!0,this.gyroEvent&&this.inActive(),this.gyroEvent=t=>{const{defaultAlpha:e,defaultBeta:i,defaultGamma:o,gyroX:n,gyroY:s,gyroZ:r}=this,{alpha:a,beta:h,gamma:l}=t,u=s&&null!=a?a:e,c=n&&null!=h?h:i,p=r&&null!=l?l:o;if(this.absolute)this.alpha=u,this.beta=c,this.gamma=p;else if(this.cache){const{alpha:t,beta:e,gamma:i}=this.cache;this.alpha=null===u?null:null===t?u:u-t,this.beta=null===c?null:null===e?c:c-e,this.gamma=null===p?null:null===i?p:p-i}else this.cache={alpha:u,beta:c,gamma:p};this.onChange(this.alpha,this.beta,this.gamma)},window.addEventListener("deviceorientation",this.gyroEvent)}inActive(){this._isActive=!1,this.gyroEvent&&(window.removeEventListener("deviceorientation",this.gyroEvent),this.gyroEvent=null)}}var p,g;function d(t){const s=new e,r=new i,a=new o;return s.lookAt(new n,t,new n(0,1,0)),r.setFromRotationMatrix(s),a.setFromQuaternion(r),a}function m(t){return new n(0,0,-1).applyQuaternion((new i).setFromEuler(t))}function v(t){return m(t).normalize()}function y(t,e){return"function"==typeof t?t(e):t}function T(t,e){return"function"==typeof t?t(e):t}!function(t){t.FIRST_VISION="first",t.THIRD_VISION="third",t.UP_VISION="up",t.LEFT_VISION="left"}(p||(p={})),function(t){t.RELATIVE_ORIENTATION="relative",t.FIXED_ORIENTATION="fixed",t.GYRO_ORIENTATION="gyro"}(g||(g={}));const f=Object.freeze({disabledAnimate:!1,fixedOrientation:!1,autoRestoreOrientation:1500,oppositeCamera:!1,oppositeType:{x:!1,y:!0,z:!1},orientationTarget:"main",vision:p.THIRD_VISION,orientationType:g.RELATIVE_ORIENTATION,rotationToTarget:new n(0,4,-10),distanceToTarget:1,targetRotationFix:[0,0,0,"XYZ"],isFixRotationRelativeTarget:!0,targetPositionFix:[0,2,0],isFixPositionRelativeTarget:!1,enableGyro:!1,gyroX:!1,gyroY:!0,gyroZ:!1,gyroAbsolute:!0,onControlStart:null,onControlRender:null,onControlEnd:null});function _(t){const e=(new i).setFromEuler((new o).fromArray(t));this.quaternion.multiply(e)}class w extends l{get position(){return this.nativeCamera.position}get rotation(){return this.nativeCamera.rotation}get quaternion(){return this.nativeCamera.quaternion}_lookAt(...t){this.nativeCamera.lookAt(...t),this.isFixRotationRelativeTarget||_.call(this.nativeCamera,this.targetRotationAfterFix)}get enableGyro(){return this._enableGyro}set enableGyro(t){this._enableGyro=t,t?this._gyroListener.active():this._gyroListener.inActive()}get gyroX(){return this._gyroListener.gyroX}set gyroX(t){this._gyroListener.gyroX=t}get gyroY(){return this._gyroListener.gyroY}set gyroY(t){this._gyroListener.gyroY=t}get gyroZ(){return this._gyroListener.gyroZ}set gyroZ(t){this._gyroListener.gyroZ=t}get gyroAbsolute(){return this._gyroListener.absolute}set gyroAbsolute(t){this._gyroListener.absolute=t}get targetRotationAfterFix(){return T(this.targetRotationFix)}get targetPositionAfterFix(){return y(this.targetPositionFix)}get realDistanceToTarget(){return"first"===this.vision?1:this.distanceToTarget}get realRotationToTarget(){switch(this.vision){case"first":return new n(0,0,-1);case"up":return new n(0,1,-.01);case"left":return new n(1,0,0);default:return this.rotationToTarget}}get orientationType(){return this._orientationType}set orientationType(t){this._orientationType=t,t===g.GYRO_ORIENTATION?this._gyroListener.active():this._gyroListener.inActive(),t===g.FIXED_ORIENTATION&&this._fixedOrientationRotation.copy(this.followRotation),this.restoreOrientation()}get orientationTarget(){return this._orientationTarget}set orientationTarget(t){this._orientationTarget=t,this.restoreOrientation()}get vision(){return this._vision}set vision(t){this._vision=t,this.followTarget.visible=t!==p.FIRST_VISION,this.restoreOrientation()}get followTarget(){return this._followTarget}set followTarget(t){this._followTarget=t,this.restoreOrientation()}get followPosition(){const t=new n;return t.fromArray(this.targetPositionAfterFix),this.isFixPositionRelativeTarget&&t.applyEuler(this.followRotation),this.followTarget.position.clone().add(t)}get followRotation(){const t=this.followTarget.rotation;if(this.isFixRotationRelativeTarget){const e=(new o).copy(t),n=(new i).setFromEuler(e),s=(new i).setFromEuler((new o).fromArray(this.targetRotationAfterFix));return n.multiply(s),(new o).setFromQuaternion(n)}return this.followTarget.rotation}get fixedOrientation(){return this._fixedOrientation}set fixedOrientation(t){this._fixedOrientation=t,t||this.restoreOrientation()}constructor(t,e,i){const n=null!=e?e:new s(80,1,.1,100);super(t,n),this.ssp=t,this.initOptions=f,this.cameraKey="navigatorCamera"+~~(1e4*Math.random()),this._events={onRender:()=>{},onMouseDown:t=>{}},this._restoreTimer=void 0,this._positionTween=null,this.autoFollowRender=!0,this._cameraPlaceholder=new r,this.disabledAnimate=f.disabledAnimate,this.distanceToTarget=f.distanceToTarget,this.rotationToTarget=f.rotationToTarget,this.oppositeCamera=f.oppositeCamera,this.oppositeType=f.oppositeType,this.isFixRotationRelativeTarget=f.isFixRotationRelativeTarget,this.targetRotationFix=f.targetRotationFix,this.isFixPositionRelativeTarget=f.isFixPositionRelativeTarget,this.targetPositionFix=f.targetPositionFix,this.autoRestoreOrientation=f.autoRestoreOrientation,this.onControlStart=null,this.onControlRender=null,this.onControlEnd=null,this._enableGyro=!1,this._gyroRotation=new o,this._orientationType=f.orientationType,this._fixedOrientationRotation=new o,this._orientationTarget=f.orientationTarget,this._vision=f.vision,this._followTarget=new r,this._fixedOrientation=f.fixedOrientation,this.initGyroListener();const a=Object.freeze(Object.assign(Object.assign({},f),null!=i?i:{}));this.initOptions=a,this.setOptions(a),this.setCamera(n)}initGyroListener(){const t=this.initOptions;this._gyroListener=new c(t.gyroX,t.gyroY,t.gyroZ,t.gyroAbsolute),this._gyroListener.onChange=(t,e,i)=>{const n=null===t?0:a.degToRad(t),s=null===e?0:a.degToRad(e),r=null===i?0:a.degToRad(i);this._gyroRotation=new o(s,n,r)}}setCameraOrientationOnControl(){const{rotation:t}=this.ssp.viewport.cameraManager.mainCamera,{realDistanceToTarget:e,followPosition:i}=this,o=v(t);this.position.copy(i.clone().add(o.multiplyScalar(-e))),this._lookAt(this.followPosition)}updateCameraPlaceholder(){const t=this.getRenderCameraPosition();this._cameraPlaceholder.position.copy(t)}setCameraOrientationOnRender(){this.position.copy(this._cameraPlaceholder.position),this._lookAt(this.followPosition)}getRenderCameraOrientation(){const{_fixedOrientationRotation:t,_orientationType:e,_orientationTarget:i}=this,s=new o;switch(e===g.GYRO_ORIENTATION&&s.copy(this._gyroRotation),!0){case"main"===i:s.copy(e===g.FIXED_ORIENTATION?t:this.followRotation);break;case i instanceof n:{const t=this.orientationTarget.clone().sub(this.followPosition);s.copy(d(t));break}case i instanceof r:{const t=i;switch(e){case g.RELATIVE_ORIENTATION:s.copy(t.rotation);break;case g.FIXED_ORIENTATION:s.copy(d(t.position.clone().sub(this.followPosition)))}break}case i instanceof o:s.copy(i)}return s}getRenderCameraPosition(){const t=new n,e=this.getRenderCameraOrientation(),{realDistanceToTarget:i,realRotationToTarget:o}=this;if(t.copy(this.followPosition.clone().add(o.clone().applyEuler(e).normalize().multiplyScalar(i))),this.oppositeCamera){const e=this.followPosition.clone().sub(t).multiplyScalar(2),{x:i,y:o,z:n}=this.oppositeType;[i,o,n].includes(!1)&&[i,o,n].includes(!0)?(i&&(e.x=0),o&&(e.y=0),n&&(e.z=0),t.add(e)):i&&t.add(e)}return t}onRender(){this.followTarget&&(this.updateCameraPlaceholder(),this._positionTween||(this.autoFollowRender||this.fixedOrientation?this.setCameraOrientationOnRender():this.onControlRender?this.onControlRender(this.nativeCamera,this.followTarget):this.setCameraOrientationOnControl()))}initEvents(){var t;const e=this.ssp.viewport.renderer.domElement,n=this.ssp.viewport.cameraManager.mainCamera,s=this.onRender.bind(this),r=t=>{var e,s;const r=!1===this.autoFollowRender;if(this.autoFollowRender=!1,null===(e=this._positionTween)||void 0===e||e.stop(),window.clearTimeout(this._restoreTimer),document.removeEventListener("mouseup",a),document.removeEventListener("touchend",a),document.addEventListener("mouseup",a,!0),document.addEventListener("touchend",a,!0),!r){if(this.isFixRotationRelativeTarget)n.quaternion.copy(this.quaternion);else{const t=(new i).setFromEuler((new o).fromArray(this.targetRotationAfterFix)).invert();n.quaternion.copy((new i).copy(this.quaternion).multiply(t))}null===(s=this.onControlStart)||void 0===s||s.call(this,this.nativeCamera,this.followTarget,t)}},a=t=>{const e=()=>{var e;this.restoreOrientation(),this.autoFollowRender=!0,null===(e=this.onControlEnd)||void 0===e||e.call(this,this.nativeCamera,this.followTarget,t),document.removeEventListener("mouseup",a,!0),document.removeEventListener("touchend",a,!0)};"number"==typeof this.autoRestoreOrientation?(window.clearTimeout(this._restoreTimer),this._restoreTimer=window.setTimeout(e,this.autoRestoreOrientation)):this.autoRestoreOrientation&&e()};this._events.onRender=s,this._events.onMouseDown=r;const h=this.ssp.signals;h.beforeRender.add(s),h.mouseDown.add(r),null===(t=e.parentElement)||void 0===t||t.addEventListener("touchstart",r,!0)}clearEvents(){var t;const{onRender:e,onMouseDown:i}=this._events,o=this.ssp.signals,n=this.ssp.viewport.renderer.domElement;o.beforeRender.remove(e),o.mouseDown.remove(i),null===(t=n.parentElement)||void 0===t||t.removeEventListener("touchstart",i,!0)}onEnter(){console.log("onenter"),this.initEvents()}onQuit(){console.log("onquit"),this.clearEvents(),this._gyroListener.inActive()}resetOptions(){this.setOptions(Object.assign({},this.initOptions))}setOptions(t){const e=this.disabledAnimate;this.disabledAnimate=!0,void 0!==t.isFixPositionRelativeTarget&&(this.isFixPositionRelativeTarget=t.isFixPositionRelativeTarget),void 0!==t.targetPositionFix&&(this.targetPositionFix=t.targetPositionFix),void 0!==t.isFixRotationRelativeTarget&&(this.isFixRotationRelativeTarget=t.isFixRotationRelativeTarget),void 0!==t.targetRotationFix&&(this.targetRotationFix=t.targetRotationFix),void 0!==t.rotationToTarget&&(this.rotationToTarget=t.rotationToTarget),void 0!==t.distanceToTarget&&(this.distanceToTarget=t.distanceToTarget),void 0!==t.fixedOrientation&&(this.fixedOrientation=t.fixedOrientation),void 0!==t.oppositeCamera&&(this.oppositeCamera=t.oppositeCamera),void 0!==t.oppositeType&&(this.oppositeType=t.oppositeType),void 0!==t.orientationTarget&&(this.orientationTarget=t.orientationTarget),void 0!==t.orientationType&&(this.orientationType=t.orientationType),void 0!==t.vision&&(this.vision=t.vision),void 0!==t.autoRestoreOrientation&&(this.autoRestoreOrientation=t.autoRestoreOrientation),void 0!==t.gyroX&&(this.gyroX=t.gyroX),void 0!==t.gyroY&&(this.gyroY=t.gyroY),void 0!==t.gyroZ&&(this.gyroZ=t.gyroZ),void 0!==t.gyroAbsolute&&(this.gyroAbsolute=t.gyroAbsolute),void 0!==t.enableGyro&&(this.enableGyro=t.enableGyro),void 0!==t.onControlStart&&(this.onControlStart=t.onControlStart),void 0!==t.onControlRender&&(this.onControlRender=t.onControlRender),void 0!==t.onControlEnd&&(this.onControlEnd=t.onControlEnd),this.disabledAnimate=e,void 0!==t.disabledAnimate&&(this.disabledAnimate=t.disabledAnimate)}setCamera(t){return this._isActive&&this.ssp.viewport.cameraManager.removeCamera(this.cameraKey),this.nativeCamera=t,this.ssp.viewport.cameraManager.cameras[this.cameraKey]=t,this._isActive&&this.ssp.viewport.cameraManager.setCurrentCamera(t),this}restoreOrientation(){if(this.followTarget&&!this.fixedOrientation){if(this._positionTween&&(this._positionTween.stop(),this._positionTween=null),this.disabledAnimate)return this.position.copy(this._cameraPlaceholder.position),void this._lookAt(this.followPosition);this.ssp.animation(this.position,this._cameraPlaceholder.position,{duration:1e3},t=>{this._lookAt(this.followPosition)},t=>this._positionTween=t).finally(()=>{this._positionTween=null})}}}var O;!function(t){t.PENDING="pending",t.STOP="stop",t.PLAYING="playing",t.PAUSE="pause",t.FINISHED="finished"}(O||(O={}));var R=Object.defineProperty,A=(t,e,i)=>(((t,e,i)=>{e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i})(t,"symbol"!=typeof e?e+"":e,i),i);function E(t,e,i){let o=function(t,e){const i=Math.sqrt(t.lengthSq()*e.lengthSq());if(0===i)return 0;let o=t.dot(e)/i;return o=Math.max(-1,Math.min(1,o)),Math.acos(o)}(t,e);return 0===o?o:t.clone().cross(e).dot(i)<0?-o:o}const C=180/Math.PI,b={yaw:[{name:"前",range:[-15,15]},{name:"左",range:[15,165]},{name:"右",range:[-165,-15]},{name:"后",range:[-180.1,-165]},{name:"后",range:[165,180.1]}],pitch:[{name:"前",range:[-15,15]},{name:"上",range:[15,165]},{name:"下",range:[-165,-15]},{name:"后",range:[-180.1,-165]},{name:"后",range:[165,180.1]}],roll:[{name:"上",range:[-15,15]},{name:"左",range:[15,165]},{name:"右",range:[-165,-15]},{name:"下",range:[-180.1,-165]},{name:"下",range:[165,180.1]}]};const x={degrees:!0,map:b,front:{x:0,y:0,z:1},up:{x:0,y:1,z:0}};class P{constructor(t){A(this,"_options"),A(this,"_listMap"),A(this,"_front"),A(this,"_up"),t&&(this.options=t)}static get options(){return this._options??(this.options=x)}static set options(t){this._options=Object.assign({},structuredClone(b),t)}get defaultOptions(){return this.constructor.options}get options(){return this._options??(this.options=this.defaultOptions)}set options(t){this._options=Object.assign({},structuredClone(this.defaultOptions),t),this._listMap=null,this._front=null,this._up=null}get degrees(){return this.options.degrees??(this.options.degrees=this.defaultOptions.degrees??!0)}set degrees(t){this.options.degrees=t}get map(){return this.options.map||(this.map=this.defaultOptions.map),this.options.map}set map(t){const e=structuredClone(this.defaultOptions.map),i=structuredClone(b);t=t?{yaw:t.yaw??e.yaw??i.yaw,pitch:t.pitch??e.pitch??i.pitch,roll:t.roll??e.roll??i.roll}:e,this.options.map=t,this._listMap=null}get listMap(){return this._listMap??(this._listMap=function(t){const e={};for(const[i,o]of Object.entries(t))e[i]=Array.isArray(o)?o:Object.entries(o).map(([t,e])=>({name:t,range:e}));return e}(this.map??{}))}get front(){return this._front||(this.front=this.options.front??this.defaultOptions.front??x.front),this._front}set front(t){this._front=(new n).copy(t)}get up(){return this._up||(this.up=this.options.up??this.defaultOptions.up??x.up),this._up}set up(t){this._up=(new n).copy(t)}computeAzimuth(t,e,i){const o=(new n).copy(t),s=(new n).copy(e??this.front),r=(new n).copy(i??this.up);let{yaw:a,pitch:h,roll:l}=function(t,e,i){const o=e.clone().negate(),n=i.clone().projectOnPlane(e),s=E(e,t.clone().projectOnPlane(n),n),r=e.clone().cross(n);return{yaw:s,pitch:E(e,t.clone().projectOnPlane(r),r),roll:E(n,t.clone().projectOnPlane(o),o)}}(o,s,r);return this.degrees&&(a*=C,h*=C,l*=C),{yaw:{angle:a,name:this.findAzimuthNames("yaw",a)},pitch:{angle:h,name:this.findAzimuthNames("pitch",h)},roll:{angle:l,name:this.findAzimuthNames("roll",l)}}}findAzimuthNames(t,e){const i=[],o=this.listMap[t];if(!o)return i;for(const{name:t,range:[n,s]}of o)(e>=n&&e<s||e<=n&&e>s)&&i.push(t);return i}}A(P,"_options");const F=new P;function I(t,e){F.map={yaw:{left:[20,170],right:[-170,-20]},pitch:{up:[20,170],down:[-170,-20]}};const{yaw:i,pitch:o}=F.computeAzimuth(t,e),n=i.name,s=o.name;return n&&s?s?n?`${n}-${s}`:s:n:"straight"}function N(t,e){return e.reverse().map(e=>{t.removeObjectById(e.sid);const i=e.nodes.reverse().map(t=>({id:t.sid,position:t.position,graphs:t.graphs}));return t.createTopology(Object.assign(Object.assign({},e.info),{nodes:i}))})}function S(t,e,i){if(!e||!i)return"straight";return I(e.position.clone().sub(t.position),i.position.clone().sub(e.position))}function L(t){const e=t.nodes,i=t.getLength();let o=0,n=0;return e.reduce((t,s,r)=>{const a=e[r+1],h=e[r+2],l=a?a.position.clone().distanceTo(s.position):0,u=S(s,a,h),c=o+l,p=c/i,g={progressArea:[n,p],distanceArea:[o,c],node:s,nextNode:a,distanceToStart:o,distanceToEnd:i-o,distanceToNext:l,frontDirection:u};return o=c,n=p,t.push(g),t},[])}function z(t,e){return 0===t?e[0]:100===t?e[e.length-1]:e.find(e=>{const[i,o]=e.progressArea;return t>=i&&t<o})}function M(t,e){if(!e)return{distanceToStartNode:0,distanceToEndNode:0,distanceToStart:0,distanceToEnd:0};const[i,o]=e.progressArea,{distanceToNext:n,distanceToEnd:s,distanceToStart:r}=e,a=(t-i)/(o-i),h=n*a,l=n*(1-a);return{distanceToStartNode:h,distanceToEndNode:l,distanceToStart:h+r,distanceToEnd:s-l}}new h;class D{get model(){return this._model}set model(t){this._model=t}get speed(){return this._speed}set speed(t){this._speed=t}get pathProgress(){return this._pathProgress}set pathProgress(t){this._pathProgress=t}get totalProgress(){return this._pathProgress}set totalProgress(t){this._pathProgress=t}get currentPath(){return this.paths[this.currentPathIndex]}get currentPathIndex(){return this._currentPathIndex}get currentRotationVector(){return this._nextNode&&this._currentNode?this._nextNode.clone().sub(this._currentNode):new n}constructor(t,e){this.ssp=t,this.paths=e,this.onPlay=()=>{},this.onStatusChange=()=>{},this.loop=!1,this.autoNext=!0,this.playAfterStart=!1,this.flyToModelAfterStart=!0,this.backStartPointWhenStop=!0,this._model=new r,this._speed=1,this._pathProgress=0,this._totalProgress=0,this._currentPathIndex=0,this._currentNode=null,this._nextNode=null,this._playStatus=O.PENDING}changeStatus(t){this._playStatus=t,this.onStatusChange(t)}start(){}restart(){this.stop(),this.start()}play(t=0,e){this.changeStatus(O.PLAYING),this.paths[t]}pause(){this.changeStatus(O.PAUSE)}stop(){this.changeStatus(O.STOP)}flip(){}over(){this.changeStatus(O.PENDING)}}const G=new P;export{P as Azimuth,c as GyroListener,u as MapCamera,g as NAVIGATE_ORIENTATION_TYPE,p as NAVIGATE_VISION_TYPE,w as NavigateCamera,D as Navigator,O as PLAY_STATUS,l as SoonSpaceCamera,d as Vector3ToEuler,G as azimuth,m as eulerToVector3,I as getDirection,S as getDirectionByNodes,M as getDistanceInfoByProgress,T as getFixEuler,y as getFixVector,z as getNavigatorNodeInfoByProgress,L as getNavigatorNodeInfosByTopology,v as normalizeEuler,N as reverseTopologies};
1
+ import { OrthographicCamera as S, Matrix4 as M, Quaternion as y, Euler as g, Vector3 as u, PerspectiveCamera as D, Object3D as R, MathUtils as O, Matrix3 as j } from "three";
2
+ class L {
3
+ constructor(t, e) {
4
+ this.ssp = t, this.nativeCamera = e, this.ssp.signals.cameraObjectChange.add(() => {
5
+ const i = this.ssp.viewport.cameraManager.currentCamera;
6
+ this._isActive && i === this.nativeCamera || (i === this.nativeCamera ? (this._onBeforeEnter(), this.onEnter()) : this._isActive && i !== this.nativeCamera && (this._onBeforeQuit(), this.onQuit()));
7
+ });
8
+ }
9
+ _isActive = !1;
10
+ active() {
11
+ this.ssp.viewport.cameraManager.setCurrentCamera(this.nativeCamera);
12
+ }
13
+ _onBeforeEnter() {
14
+ this._isActive = !0;
15
+ }
16
+ _onBeforeQuit() {
17
+ this._isActive = !1;
18
+ }
19
+ onEnter() {
20
+ }
21
+ onQuit() {
22
+ }
23
+ }
24
+ class J extends L {
25
+ constructor(t) {
26
+ const e = new S();
27
+ super(t, e), this.ssp = t, e.far = 2e5;
28
+ }
29
+ resizeObserver = new ResizeObserver(() => {
30
+ this.resizeCamera();
31
+ });
32
+ _zoom = 0.01;
33
+ get zoom() {
34
+ return this._zoom;
35
+ }
36
+ set zoom(t) {
37
+ this._zoom = t, this.resizeCamera();
38
+ }
39
+ resizeCamera() {
40
+ if (this._isActive) {
41
+ const { clientWidth: t, clientHeight: e } = this.ssp.viewport.renderer.domElement, i = t * this.zoom / 2, n = e * this.zoom / 2;
42
+ this.nativeCamera.left = -i, this.nativeCamera.right = i, this.nativeCamera.top = n, this.nativeCamera.bottom = -n, this.nativeCamera.updateProjectionMatrix();
43
+ }
44
+ }
45
+ onEnter() {
46
+ console.log("map camera enter"), this.ssp.domElement && (this.resizeObserver.observe(this.ssp.domElement), this.resizeCamera());
47
+ }
48
+ onQuit() {
49
+ this.ssp.domElement && (this.resizeObserver.unobserve(this.ssp.domElement), console.log("map camera quit"));
50
+ }
51
+ }
52
+ class q {
53
+ gyroEvent = null;
54
+ onChange = () => {
55
+ };
56
+ _isActive = !1;
57
+ defaultBeta = null;
58
+ defaultAlpha = null;
59
+ defaultGamma = null;
60
+ cache = null;
61
+ beta = null;
62
+ alpha = null;
63
+ gamma = null;
64
+ gyroX;
65
+ gyroY;
66
+ gyroZ;
67
+ absolute;
68
+ constructor(t, e, i, n) {
69
+ this.gyroX = t ?? !0, this.gyroY = e ?? !0, this.gyroZ = i ?? !0, this.absolute = n ?? !0;
70
+ }
71
+ requestPermisson() {
72
+ return new Promise((t, e) => {
73
+ window.DeviceOrientationEvent.requestPermission || t(!0), window.DeviceOrientationEvent?.requestPermission().then((i) => {
74
+ i === "granted" ? t(!0) : e("用户拒绝使用陀螺仪权限");
75
+ });
76
+ });
77
+ }
78
+ /** 监听陀螺仪事件 */
79
+ async active() {
80
+ await this.requestPermisson(), this._isActive = !0, this.gyroEvent && this.inActive(), this.gyroEvent = (t) => {
81
+ const { defaultAlpha: e, defaultBeta: i, defaultGamma: n, gyroX: r, gyroY: a, gyroZ: s } = this, { alpha: l, beta: c, gamma: v } = t, d = a ? l ?? e : e, p = r ? c ?? i : i, m = s ? v ?? n : n;
82
+ if (this.absolute)
83
+ this.alpha = d, this.beta = p, this.gamma = m;
84
+ else if (!this.cache)
85
+ this.cache = {
86
+ alpha: d,
87
+ beta: p,
88
+ gamma: m
89
+ };
90
+ else {
91
+ const { alpha: w, beta: F, gamma: N } = this.cache;
92
+ this.alpha = d === null ? null : w === null ? d : d - w, this.beta = p === null ? null : F === null ? p : p - F, this.gamma = m === null ? null : N === null ? m : m - N;
93
+ }
94
+ this.onChange(this.alpha, this.beta, this.gamma);
95
+ }, window.addEventListener("deviceorientation", this.gyroEvent);
96
+ }
97
+ /** 销毁陀螺仪事件 */
98
+ inActive() {
99
+ this._isActive = !1, this.gyroEvent && (window.removeEventListener("deviceorientation", this.gyroEvent), this.gyroEvent = null);
100
+ }
101
+ }
102
+ var A = /* @__PURE__ */ ((o) => (o.FIRST_VISION = "first", o.THIRD_VISION = "third", o.UP_VISION = "up", o.LEFT_VISION = "left", o))(A || {}), f = /* @__PURE__ */ ((o) => (o.RELATIVE_ORIENTATION = "relative", o.FIXED_ORIENTATION = "fixed", o.GYRO_ORIENTATION = "gyro", o))(f || {});
103
+ function I(o) {
104
+ const t = new M(), e = new y(), i = new g();
105
+ return t.lookAt(new u(), o, new u(0, 1, 0)), e.setFromRotationMatrix(t), i.setFromQuaternion(e), i;
106
+ }
107
+ function G(o) {
108
+ return new u(0, 0, -1).applyQuaternion(
109
+ new y().setFromEuler(o)
110
+ );
111
+ }
112
+ function X(o) {
113
+ return G(o).normalize();
114
+ }
115
+ function k(o, t) {
116
+ return typeof o == "function" ? o(t) : o;
117
+ }
118
+ function B(o, t) {
119
+ return typeof o == "function" ? o(t) : o;
120
+ }
121
+ const h = Object.freeze({
122
+ disabledAnimate: !1,
123
+ fixedOrientation: !1,
124
+ autoRestoreOrientation: 1500,
125
+ oppositeCamera: !1,
126
+ oppositeType: {
127
+ x: !1,
128
+ y: !0,
129
+ z: !1
130
+ },
131
+ orientationTarget: "main",
132
+ vision: A.THIRD_VISION,
133
+ orientationType: f.RELATIVE_ORIENTATION,
134
+ rotationToTarget: new u(0, 4, -10),
135
+ distanceToTarget: 1,
136
+ targetRotationFix: [0, 0, 0, "XYZ"],
137
+ isFixRotationRelativeTarget: !0,
138
+ targetPositionFix: [0, 2, 0],
139
+ isFixPositionRelativeTarget: !1,
140
+ enableGyro: !1,
141
+ gyroX: !1,
142
+ gyroY: !0,
143
+ gyroZ: !1,
144
+ gyroAbsolute: !0,
145
+ onControlStart: null,
146
+ onControlRender: null,
147
+ onControlEnd: null
148
+ });
149
+ function Z(o) {
150
+ const t = new y().setFromEuler(new g().fromArray(o));
151
+ this.quaternion.multiply(t);
152
+ }
153
+ class tt extends L {
154
+ constructor(t, e, i) {
155
+ const n = e ?? new D(80, 1, 0.1, 100);
156
+ super(t, n), this.ssp = t, this.initGyroListener();
157
+ const r = Object.freeze({
158
+ ...h,
159
+ ...i ?? {}
160
+ });
161
+ this.initOptions = r, this.setOptions(r), this.setCamera(n);
162
+ }
163
+ initOptions = h;
164
+ cameraKey = "navigatorCamera" + ~~(Math.random() * 1e4);
165
+ _events = {
166
+ onRender: () => {
167
+ },
168
+ onMouseDown: (t) => {
169
+ }
170
+ };
171
+ get position() {
172
+ return this.nativeCamera.position;
173
+ }
174
+ get rotation() {
175
+ return this.nativeCamera.rotation;
176
+ }
177
+ get quaternion() {
178
+ return this.nativeCamera.quaternion;
179
+ }
180
+ _lookAt(...t) {
181
+ this.nativeCamera.lookAt(...t), this.isFixRotationRelativeTarget || Z.call(this.nativeCamera, this.targetRotationAfterFix);
182
+ }
183
+ _restoreTimer = void 0;
184
+ _positionTween = null;
185
+ autoFollowRender = !0;
186
+ /** 相机位置记录用的对象,用于恢复相机位置和朝向使用 */
187
+ _cameraPlaceholder = new R();
188
+ /** 取消飞向动画 */
189
+ disabledAnimate = h.disabledAnimate;
190
+ /** 第三人称相机距离跟踪目标距离 */
191
+ distanceToTarget = h.distanceToTarget;
192
+ /** 第三人称相机相对模型视角 */
193
+ rotationToTarget = h.rotationToTarget;
194
+ /** 相机反转 */
195
+ oppositeCamera = h.oppositeCamera;
196
+ /** 相机反转类型, 默认为 Y 轴对称 */
197
+ oppositeType = h.oppositeType;
198
+ /** 是否相对模型修正角度 */
199
+ isFixRotationRelativeTarget = h.isFixRotationRelativeTarget;
200
+ /**
201
+ * 目标角度修正
202
+ *
203
+ * 支持传入 getter 函数
204
+ */
205
+ targetRotationFix = h.targetRotationFix;
206
+ /** 是否相对模型修正偏移 */
207
+ isFixPositionRelativeTarget = h.isFixPositionRelativeTarget;
208
+ /**
209
+ * 目标位置修正
210
+ *
211
+ * 支持传入 getter 函数
212
+ */
213
+ targetPositionFix = h.targetPositionFix;
214
+ /**
215
+ * 自动恢复朝向
216
+ *
217
+ * boolean 是否恢复朝向
218
+ *
219
+ * number 间隔多少秒后恢复朝向
220
+ */
221
+ autoRestoreOrientation = h.autoRestoreOrientation;
222
+ /** 当控制器控制相机时允许外部自定义控制,控制开始时触发 */
223
+ onControlStart = null;
224
+ /** 当控制器控制相机时允许外部自定义控制,控制进行时回调 */
225
+ onControlRender = null;
226
+ /** 当控制器控制相机时允许外部自定义控制,控制结束时回调 */
227
+ onControlEnd = null;
228
+ /** 陀螺仪 */
229
+ _gyroListener;
230
+ _enableGyro = !1;
231
+ /** 开启 */
232
+ get enableGyro() {
233
+ return this._enableGyro;
234
+ }
235
+ set enableGyro(t) {
236
+ this._enableGyro = t, t ? this._gyroListener.active() : this._gyroListener.inActive();
237
+ }
238
+ /** 是否应用陀螺仪 X 轴,默认不启动 */
239
+ get gyroX() {
240
+ return this._gyroListener.gyroX;
241
+ }
242
+ set gyroX(t) {
243
+ this._gyroListener.gyroX = t;
244
+ }
245
+ /** 是否应用陀螺仪 Y 轴,默认启动 */
246
+ get gyroY() {
247
+ return this._gyroListener.gyroY;
248
+ }
249
+ set gyroY(t) {
250
+ this._gyroListener.gyroY = t;
251
+ }
252
+ /** 是否应用陀螺仪 Z 轴,默认不启动 */
253
+ get gyroZ() {
254
+ return this._gyroListener.gyroZ;
255
+ }
256
+ set gyroZ(t) {
257
+ this._gyroListener.gyroZ = t;
258
+ }
259
+ /** 陀螺仪是否使用绝对值,默认使用 */
260
+ get gyroAbsolute() {
261
+ return this._gyroListener.absolute;
262
+ }
263
+ set gyroAbsolute(t) {
264
+ this._gyroListener.absolute = t;
265
+ }
266
+ /** 陀螺仪的旋转欧拉角 */
267
+ _gyroRotation = new g();
268
+ get targetRotationAfterFix() {
269
+ return B(this.targetRotationFix);
270
+ }
271
+ get targetPositionAfterFix() {
272
+ return k(this.targetPositionFix);
273
+ }
274
+ get realDistanceToTarget() {
275
+ return this.vision === "first" ? 1 : this.distanceToTarget;
276
+ }
277
+ get realRotationToTarget() {
278
+ switch (this.vision) {
279
+ case "first":
280
+ return new u(0, 0, -1);
281
+ case "up":
282
+ return new u(0, 1, -0.01);
283
+ case "left":
284
+ return new u(1, 0, 0);
285
+ default:
286
+ return this.rotationToTarget;
287
+ }
288
+ }
289
+ _orientationType = h.orientationType;
290
+ /** 绝对朝向的缓存值 */
291
+ _fixedOrientationRotation = new g();
292
+ /**
293
+ * 相机朝向类型
294
+ *
295
+ * NAVIGATE_ORIENTATION_TYPE.RELATIVE_ORIENTATION 相对朝向
296
+ *
297
+ * NAVIGATE_ORIENTATION_TYPE.FIXED_ORIENTATION 绝对朝向
298
+ *
299
+ * NAVIGATE_ORIENTATION_TYPE.GYRO_ORIENTATION 陀螺仪朝向
300
+ */
301
+ get orientationType() {
302
+ return this._orientationType;
303
+ }
304
+ set orientationType(t) {
305
+ this._orientationType = t, t === f.GYRO_ORIENTATION ? this._gyroListener.active() : this._gyroListener.inActive(), t === f.FIXED_ORIENTATION && this._fixedOrientationRotation.copy(this.followRotation), this.restoreOrientation();
306
+ }
307
+ _orientationTarget = h.orientationTarget;
308
+ /**
309
+ * 相机朝向目标
310
+ *
311
+ * “main” 朝向跟踪目标
312
+ *
313
+ * Vector3 朝向点
314
+ *
315
+ * Object3D 朝向目标对象
316
+ *
317
+ * Euler 固定朝向
318
+ */
319
+ get orientationTarget() {
320
+ return this._orientationTarget;
321
+ }
322
+ set orientationTarget(t) {
323
+ this._orientationTarget = t, this.restoreOrientation();
324
+ }
325
+ _vision = h.vision;
326
+ /**
327
+ * 视角配置
328
+ *
329
+ * NAVIGATE_VISION_TYPE.FIRST_VISION 第一人称
330
+ *
331
+ * NAVIGATE_VISION_TYPE.THIRD_VISION 第三人称
332
+ *
333
+ * NAVIGATE_VISION_TYPE.UP_VISION 俯视图
334
+ *
335
+ * NAVIGATE_VISION_TYPE.LEFT_VISION 左视图
336
+ *
337
+ * 默认为第三人称
338
+ */
339
+ get vision() {
340
+ return this._vision;
341
+ }
342
+ set vision(t) {
343
+ this._vision = t, this.followTarget.visible = t !== A.FIRST_VISION, this.restoreOrientation();
344
+ }
345
+ _followTarget = new R();
346
+ /** 相机跟随目标 */
347
+ get followTarget() {
348
+ return this._followTarget;
349
+ }
350
+ set followTarget(t) {
351
+ this._followTarget = t, this.restoreOrientation();
352
+ }
353
+ /** 相机跟踪点(相对跟随目标以及偏移参数获取的点) */
354
+ get followPosition() {
355
+ const t = new u();
356
+ return t.fromArray(this.targetPositionAfterFix), this.isFixPositionRelativeTarget && t.applyEuler(this.followRotation), this.followTarget.position.clone().add(t);
357
+ }
358
+ /** 跟踪目标的方向(相对跟随目标以及偏移参数获取的朝向) */
359
+ get followRotation() {
360
+ const t = this.followTarget.rotation;
361
+ if (this.isFixRotationRelativeTarget) {
362
+ const e = new g().copy(t), i = new y().setFromEuler(e), n = new y().setFromEuler(
363
+ new g().fromArray(this.targetRotationAfterFix)
364
+ );
365
+ return i.multiply(n), new g().setFromQuaternion(i);
366
+ }
367
+ return this.followTarget.rotation;
368
+ }
369
+ _fixedOrientation = h.fixedOrientation;
370
+ /** 固定朝向,朝向不受控制器影响 */
371
+ get fixedOrientation() {
372
+ return this._fixedOrientation;
373
+ }
374
+ set fixedOrientation(t) {
375
+ this._fixedOrientation = t, t || this.restoreOrientation();
376
+ }
377
+ initGyroListener() {
378
+ const t = this.initOptions;
379
+ this._gyroListener = new q(
380
+ t.gyroX,
381
+ t.gyroY,
382
+ t.gyroZ,
383
+ t.gyroAbsolute
384
+ ), this._gyroListener.onChange = (e, i, n) => {
385
+ const r = e === null ? 0 : O.degToRad(e), a = i === null ? 0 : O.degToRad(i), s = n === null ? 0 : O.degToRad(n);
386
+ this._gyroRotation = new g(
387
+ a,
388
+ r,
389
+ s
390
+ );
391
+ };
392
+ }
393
+ /** 控制器操作时处理 */
394
+ setCameraOrientationOnControl() {
395
+ const { rotation: t } = this.ssp.viewport.cameraManager.mainCamera, { realDistanceToTarget: e, followPosition: i } = this, n = X(t);
396
+ this.position.copy(
397
+ i.clone().add(n.multiplyScalar(-e))
398
+ ), this._lookAt(this.followPosition);
399
+ }
400
+ /** 更新相机占位符的方位 */
401
+ updateCameraPlaceholder() {
402
+ const t = this.getRenderCameraPosition();
403
+ this._cameraPlaceholder.position.copy(t);
404
+ }
405
+ /** 设置相机的方位 */
406
+ setCameraOrientationOnRender() {
407
+ this.position.copy(this._cameraPlaceholder.position), this._lookAt(this.followPosition);
408
+ }
409
+ /** 获取相机点相对跟踪点的欧拉角 */
410
+ getRenderCameraOrientation() {
411
+ const { _fixedOrientationRotation: t, _orientationType: e, _orientationTarget: i } = this, n = new g();
412
+ switch (e === f.GYRO_ORIENTATION && n.copy(this._gyroRotation), !0) {
413
+ case i === "main": {
414
+ n.copy(
415
+ e === f.FIXED_ORIENTATION ? t : this.followRotation
416
+ );
417
+ break;
418
+ }
419
+ case i instanceof u: {
420
+ const r = this.orientationTarget.clone().sub(this.followPosition);
421
+ n.copy(I(r));
422
+ break;
423
+ }
424
+ case i instanceof R: {
425
+ const r = i;
426
+ switch (e) {
427
+ case f.RELATIVE_ORIENTATION:
428
+ n.copy(r.rotation);
429
+ break;
430
+ case f.FIXED_ORIENTATION:
431
+ n.copy(
432
+ I(r.position.clone().sub(this.followPosition))
433
+ );
434
+ break;
435
+ }
436
+ break;
437
+ }
438
+ case i instanceof g: {
439
+ n.copy(i);
440
+ break;
441
+ }
442
+ }
443
+ return n;
444
+ }
445
+ /** 获取相机落点(相对跟踪点的方向归一化 * 距离) */
446
+ getRenderCameraPosition() {
447
+ const t = new u(), e = this.getRenderCameraOrientation(), { realDistanceToTarget: i, realRotationToTarget: n } = this;
448
+ if (t.copy(
449
+ this.followPosition.clone().add(
450
+ n.clone().applyEuler(e).normalize().multiplyScalar(i)
451
+ )
452
+ ), this.oppositeCamera) {
453
+ const r = this.followPosition.clone().sub(t).multiplyScalar(2), { x: a, y: s, z: l } = this.oppositeType;
454
+ [a, s, l].includes(!1) && [a, s, l].includes(!0) ? (a && (r.x = 0), s && (r.y = 0), l && (r.z = 0), t.add(r)) : a && t.add(r);
455
+ }
456
+ return t;
457
+ }
458
+ onRender() {
459
+ if (this.followTarget && (this.updateCameraPlaceholder(), !this._positionTween)) {
460
+ if (this.autoFollowRender || this.fixedOrientation) {
461
+ this.setCameraOrientationOnRender();
462
+ return;
463
+ }
464
+ this.onControlRender ? this.onControlRender(this.nativeCamera, this.followTarget) : this.setCameraOrientationOnControl();
465
+ }
466
+ }
467
+ /** 初始化事件 */
468
+ initEvents() {
469
+ const t = this.ssp.viewport.renderer.domElement, e = this.ssp.viewport.cameraManager.mainCamera, i = this.onRender.bind(this), n = (s) => {
470
+ const l = this.autoFollowRender === !1;
471
+ if (this.autoFollowRender = !1, this._positionTween?.stop(), window.clearTimeout(this._restoreTimer), document.removeEventListener("mouseup", r), document.removeEventListener("touchend", r), document.addEventListener("mouseup", r, !0), document.addEventListener("touchend", r, !0), !l) {
472
+ if (this.isFixRotationRelativeTarget)
473
+ e.quaternion.copy(this.quaternion);
474
+ else {
475
+ const c = new y().setFromEuler(new g().fromArray(this.targetRotationAfterFix)).invert();
476
+ e.quaternion.copy(
477
+ new y().copy(this.quaternion).multiply(c)
478
+ );
479
+ }
480
+ this.onControlStart?.(this.nativeCamera, this.followTarget, s);
481
+ }
482
+ }, r = (s) => {
483
+ const l = () => {
484
+ this.restoreOrientation(), this.autoFollowRender = !0, this.onControlEnd?.(this.nativeCamera, this.followTarget, s), document.removeEventListener("mouseup", r, !0), document.removeEventListener("touchend", r, !0);
485
+ };
486
+ typeof this.autoRestoreOrientation == "number" ? (window.clearTimeout(this._restoreTimer), this._restoreTimer = window.setTimeout(l, this.autoRestoreOrientation)) : this.autoRestoreOrientation && l();
487
+ };
488
+ this._events.onRender = i, this._events.onMouseDown = n;
489
+ const a = this.ssp.signals;
490
+ a.beforeRender.add(i), a.mouseDown.add(n), t.parentElement?.addEventListener("touchstart", n, !0);
491
+ }
492
+ /** 清除事件 */
493
+ clearEvents() {
494
+ const { onRender: t, onMouseDown: e } = this._events, i = this.ssp.signals, n = this.ssp.viewport.renderer.domElement;
495
+ i.beforeRender.remove(t), i.mouseDown.remove(e), n.parentElement?.removeEventListener("touchstart", e, !0);
496
+ }
497
+ onEnter() {
498
+ console.log("onenter"), this.initEvents();
499
+ }
500
+ onQuit() {
501
+ console.log("onquit"), this.clearEvents(), this._gyroListener.inActive();
502
+ }
503
+ /** 参数重置 */
504
+ resetOptions() {
505
+ this.setOptions({ ...this.initOptions });
506
+ }
507
+ /** 设置参数 */
508
+ setOptions(t) {
509
+ const e = this.disabledAnimate;
510
+ this.disabledAnimate = !0, t.isFixPositionRelativeTarget !== void 0 && (this.isFixPositionRelativeTarget = t.isFixPositionRelativeTarget), t.targetPositionFix !== void 0 && (this.targetPositionFix = t.targetPositionFix), t.isFixRotationRelativeTarget !== void 0 && (this.isFixRotationRelativeTarget = t.isFixRotationRelativeTarget), t.targetRotationFix !== void 0 && (this.targetRotationFix = t.targetRotationFix), t.rotationToTarget !== void 0 && (this.rotationToTarget = t.rotationToTarget), t.distanceToTarget !== void 0 && (this.distanceToTarget = t.distanceToTarget), t.fixedOrientation !== void 0 && (this.fixedOrientation = t.fixedOrientation), t.oppositeCamera !== void 0 && (this.oppositeCamera = t.oppositeCamera), t.oppositeType !== void 0 && (this.oppositeType = t.oppositeType), t.orientationTarget !== void 0 && (this.orientationTarget = t.orientationTarget), t.orientationType !== void 0 && (this.orientationType = t.orientationType), t.vision !== void 0 && (this.vision = t.vision), t.autoRestoreOrientation !== void 0 && (this.autoRestoreOrientation = t.autoRestoreOrientation), t.gyroX !== void 0 && (this.gyroX = t.gyroX), t.gyroY !== void 0 && (this.gyroY = t.gyroY), t.gyroZ !== void 0 && (this.gyroZ = t.gyroZ), t.gyroAbsolute !== void 0 && (this.gyroAbsolute = t.gyroAbsolute), t.enableGyro !== void 0 && (this.enableGyro = t.enableGyro), t.onControlStart !== void 0 && (this.onControlStart = t.onControlStart), t.onControlRender !== void 0 && (this.onControlRender = t.onControlRender), t.onControlEnd !== void 0 && (this.onControlEnd = t.onControlEnd), this.disabledAnimate = e, t.disabledAnimate !== void 0 && (this.disabledAnimate = t.disabledAnimate);
511
+ }
512
+ /**
513
+ * 设置相机,若导航相机正在使用中,则会立即切换为设置的相机
514
+ */
515
+ setCamera(t) {
516
+ return this._isActive && this.ssp.viewport.cameraManager.removeCamera(this.cameraKey), this.nativeCamera = t, this.ssp.viewport.cameraManager.cameras[this.cameraKey] = t, this._isActive && this.ssp.viewport.cameraManager.setCurrentCamera(t), this;
517
+ }
518
+ /** 重置相机坐标 */
519
+ restoreOrientation() {
520
+ if (this.followTarget && !this.fixedOrientation) {
521
+ if (this._positionTween && (this._positionTween.stop(), this._positionTween = null), this.disabledAnimate) {
522
+ this.position.copy(this._cameraPlaceholder.position), this._lookAt(this.followPosition);
523
+ return;
524
+ }
525
+ this.ssp.animation(
526
+ this.position,
527
+ this._cameraPlaceholder.position,
528
+ { duration: 1e3 },
529
+ (t) => {
530
+ this._lookAt(this.followPosition);
531
+ },
532
+ (t) => this._positionTween = t
533
+ ).finally(() => {
534
+ this._positionTween = null;
535
+ });
536
+ }
537
+ }
538
+ }
539
+ var T = /* @__PURE__ */ ((o) => (o.PENDING = "pending", o.STOP = "stop", o.PLAYING = "playing", o.PAUSE = "pause", o.FINISHED = "finished", o))(T || {}), Q = Object.defineProperty, V = (o, t, e) => t in o ? Q(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e, _ = (o, t, e) => (V(o, typeof t != "symbol" ? t + "" : t, e), e);
540
+ function Y(o, t) {
541
+ const e = Math.sqrt(o.lengthSq() * t.lengthSq());
542
+ if (e === 0)
543
+ return 0;
544
+ let i = o.dot(t) / e;
545
+ return i = Math.max(-1, Math.min(1, i)), Math.acos(i);
546
+ }
547
+ function C(o, t, e) {
548
+ let i = Y(o, t);
549
+ return i === 0 ? i : o.clone().cross(t).dot(e) < 0 ? -i : i;
550
+ }
551
+ function H(o, t, e) {
552
+ const i = t.clone().negate(), n = e.clone().projectOnPlane(t), r = o.clone().projectOnPlane(n), a = C(t, r, n), s = t.clone().cross(n), l = o.clone().projectOnPlane(s), c = C(t, l, s), v = o.clone().projectOnPlane(i), d = C(n, v, i);
553
+ return { yaw: a, pitch: c, roll: d };
554
+ }
555
+ const E = 180 / Math.PI, b = {
556
+ yaw: [
557
+ { name: "前", range: [-15, 15] },
558
+ { name: "左", range: [15, 165] },
559
+ { name: "右", range: [-165, -15] },
560
+ { name: "后", range: [-180.1, -165] },
561
+ { name: "后", range: [165, 180.1] }
562
+ ],
563
+ pitch: [
564
+ { name: "前", range: [-15, 15] },
565
+ { name: "上", range: [15, 165] },
566
+ { name: "下", range: [-165, -15] },
567
+ { name: "后", range: [-180.1, -165] },
568
+ { name: "后", range: [165, 180.1] }
569
+ ],
570
+ roll: [
571
+ { name: "上", range: [-15, 15] },
572
+ { name: "左", range: [15, 165] },
573
+ { name: "右", range: [-165, -15] },
574
+ { name: "下", range: [-180.1, -165] },
575
+ { name: "下", range: [165, 180.1] }
576
+ ]
577
+ };
578
+ function K(o) {
579
+ const t = {};
580
+ for (const [e, i] of Object.entries(o))
581
+ t[e] = Array.isArray(i) ? i : Object.entries(i).map(([n, r]) => ({ name: n, range: r }));
582
+ return t;
583
+ }
584
+ const x = {
585
+ degrees: !0,
586
+ map: b,
587
+ front: { x: 0, y: 0, z: 1 },
588
+ up: { x: 0, y: 1, z: 0 }
589
+ };
590
+ class P {
591
+ constructor(t) {
592
+ _(this, "_options"), _(this, "_listMap"), _(this, "_front"), _(this, "_up"), t && (this.options = t);
593
+ }
594
+ static get options() {
595
+ return this._options ?? (this.options = x);
596
+ }
597
+ static set options(t) {
598
+ this._options = Object.assign({}, structuredClone(b), t);
599
+ }
600
+ /**
601
+ * 默认选项
602
+ */
603
+ get defaultOptions() {
604
+ return this.constructor.options;
605
+ }
606
+ get options() {
607
+ return this._options ?? (this.options = this.defaultOptions);
608
+ }
609
+ set options(t) {
610
+ this._options = Object.assign({}, structuredClone(this.defaultOptions), t), this._listMap = null, this._front = null, this._up = null;
611
+ }
612
+ /**
613
+ * 是否使用角度,而非弧度
614
+ */
615
+ get degrees() {
616
+ return this.options.degrees ?? (this.options.degrees = this.defaultOptions.degrees ?? !0);
617
+ }
618
+ set degrees(t) {
619
+ this.options.degrees = t;
620
+ }
621
+ get map() {
622
+ return this.options.map || (this.map = this.defaultOptions.map), this.options.map;
623
+ }
624
+ set map(t) {
625
+ const e = structuredClone(this.defaultOptions.map), i = structuredClone(b);
626
+ t = t ? {
627
+ yaw: t.yaw ?? e.yaw ?? i.yaw,
628
+ pitch: t.pitch ?? e.pitch ?? i.pitch,
629
+ roll: t.roll ?? e.roll ?? i.roll
630
+ } : e, this.options.map = t, this._listMap = null;
631
+ }
632
+ get listMap() {
633
+ return this._listMap ?? (this._listMap = K(this.map ?? {}));
634
+ }
635
+ get front() {
636
+ return this._front || (this.front = this.options.front ?? this.defaultOptions.front ?? x.front), this._front;
637
+ }
638
+ set front(t) {
639
+ this._front = new u().copy(t);
640
+ }
641
+ get up() {
642
+ return this._up || (this.up = this.options.up ?? this.defaultOptions.up ?? x.up), this._up;
643
+ }
644
+ set up(t) {
645
+ this._up = new u().copy(t);
646
+ }
647
+ /**
648
+ * 计算方位
649
+ * @param target
650
+ * @param front
651
+ * @param up
652
+ */
653
+ computeAzimuth(t, e, i) {
654
+ const n = new u().copy(t), r = new u().copy(e ?? this.front), a = new u().copy(i ?? this.up);
655
+ let { yaw: s, pitch: l, roll: c } = H(n, r, a);
656
+ return this.degrees && (s *= E, l *= E, c *= E), {
657
+ yaw: {
658
+ angle: s,
659
+ name: this.findAzimuthNames("yaw", s)
660
+ },
661
+ pitch: {
662
+ angle: l,
663
+ name: this.findAzimuthNames("pitch", l)
664
+ },
665
+ roll: {
666
+ angle: c,
667
+ name: this.findAzimuthNames("roll", c)
668
+ }
669
+ };
670
+ }
671
+ /**
672
+ * 查找匹配的方位名字
673
+ * @param type - 类型
674
+ * @param angle - 角度
675
+ * @returns 匹配的名字列表
676
+ */
677
+ findAzimuthNames(t, e) {
678
+ const i = [], n = this.listMap[t];
679
+ if (!n)
680
+ return i;
681
+ for (const { name: r, range: [a, s] } of n)
682
+ (e >= a && e < s || e <= a && e > s) && i.push(r);
683
+ return i;
684
+ }
685
+ }
686
+ _(P, "_options");
687
+ const z = new P();
688
+ new j();
689
+ function U(o, t) {
690
+ z.map = {
691
+ yaw: {
692
+ left: [20, 170],
693
+ right: [-170, -20]
694
+ },
695
+ pitch: {
696
+ up: [20, 170],
697
+ down: [-170, -20]
698
+ }
699
+ };
700
+ const { yaw: e, pitch: i } = z.computeAzimuth(o, t), n = e.name, r = i.name;
701
+ return !n || !r ? "straight" : r ? n ? `${n}-${r}` : r : n;
702
+ }
703
+ function et(o, t) {
704
+ return t.reverse().map((e) => {
705
+ o.removeObjectById(e.sid);
706
+ const i = e.nodes.reverse().map(
707
+ (n) => ({
708
+ id: n.sid,
709
+ position: n.position,
710
+ graphs: n.graphs
711
+ })
712
+ );
713
+ return o.createTopology({
714
+ ...e.info,
715
+ nodes: i
716
+ });
717
+ });
718
+ }
719
+ function W(o, t, e) {
720
+ if (!t || !e)
721
+ return "straight";
722
+ const i = t.position.clone().sub(o.position), n = e.position.clone().sub(t.position);
723
+ return U(i, n);
724
+ }
725
+ function it(o) {
726
+ const t = o.nodes, e = o.getLength();
727
+ let i = 0, n = 0;
728
+ return t.reduce((r, a, s) => {
729
+ const l = t[s + 1], c = t[s + 2], v = l ? l.position.clone().distanceTo(a.position) : 0, d = W(a, l, c), p = i + v, m = p / e, w = {
730
+ progressArea: [n, m],
731
+ distanceArea: [i, p],
732
+ node: a,
733
+ nextNode: l,
734
+ distanceToStart: i,
735
+ distanceToEnd: e - i,
736
+ distanceToNext: v,
737
+ frontDirection: d
738
+ };
739
+ return i = p, n = m, r.push(w), r;
740
+ }, []);
741
+ }
742
+ function ot(o, t) {
743
+ return o === 0 ? t[0] : o === 100 ? t[t.length - 1] : t.find((e) => {
744
+ const [i, n] = e.progressArea;
745
+ return o >= i && o < n;
746
+ });
747
+ }
748
+ function nt(o, t) {
749
+ if (!t) return {
750
+ distanceToStartNode: 0,
751
+ distanceToEndNode: 0,
752
+ distanceToStart: 0,
753
+ distanceToEnd: 0
754
+ };
755
+ const [e, i] = t.progressArea, { distanceToNext: n, distanceToEnd: r, distanceToStart: a } = t, s = (o - e) / (i - e), l = n * s, c = n * (1 - s);
756
+ return {
757
+ distanceToStartNode: l,
758
+ distanceToEndNode: c,
759
+ distanceToStart: l + a,
760
+ distanceToEnd: r - c
761
+ };
762
+ }
763
+ class rt {
764
+ constructor(t, e) {
765
+ this.ssp = t, this.paths = e;
766
+ }
767
+ onPlay = () => {
768
+ };
769
+ onStatusChange = () => {
770
+ };
771
+ /** 是否循环播放,默认为否 */
772
+ loop = !1;
773
+ /** 是否自动开始下一段路径播放,默认为是 */
774
+ autoNext = !0;
775
+ /** 开始或者重新开始后自动播放路径动画,默认为否 */
776
+ playAfterStart = !1;
777
+ /** 开始时飞向模型,默认为是 */
778
+ flyToModelAfterStart = !0;
779
+ /** 停止时是否返回起点,默认为是 */
780
+ backStartPointWhenStop = !0;
781
+ /** 路径动画主体模型 */
782
+ _model = new R();
783
+ get model() {
784
+ return this._model;
785
+ }
786
+ set model(t) {
787
+ this._model = t;
788
+ }
789
+ _speed = 1;
790
+ /** 播放速度 */
791
+ get speed() {
792
+ return this._speed;
793
+ }
794
+ set speed(t) {
795
+ this._speed = t;
796
+ }
797
+ _pathProgress = 0;
798
+ /** 当前段进度 */
799
+ get pathProgress() {
800
+ return this._pathProgress;
801
+ }
802
+ set pathProgress(t) {
803
+ this._pathProgress = t;
804
+ }
805
+ _totalProgress = 0;
806
+ /** 总进度 */
807
+ get totalProgress() {
808
+ return this._pathProgress;
809
+ }
810
+ set totalProgress(t) {
811
+ this._pathProgress = t;
812
+ }
813
+ /** 当前播放的动画路径索引 */
814
+ _currentPathIndex = 0;
815
+ /** 当前节点 */
816
+ _currentNode = null;
817
+ /** 下个路径节点 */
818
+ _nextNode = null;
819
+ /** 当前状态 */
820
+ _playStatus = T.PENDING;
821
+ get currentPath() {
822
+ return this.paths[this.currentPathIndex];
823
+ }
824
+ /** 对外只读 当前路径索引 */
825
+ get currentPathIndex() {
826
+ return this._currentPathIndex;
827
+ }
828
+ /** 对外只读 当前朝向方向向量 */
829
+ get currentRotationVector() {
830
+ return !this._nextNode || !this._currentNode ? new u() : this._nextNode.clone().sub(this._currentNode);
831
+ }
832
+ changeStatus(t) {
833
+ this._playStatus = t, this.onStatusChange(t);
834
+ }
835
+ /** 开始导航 */
836
+ start() {
837
+ }
838
+ /** 重新开始导航 */
839
+ restart() {
840
+ this.stop(), this.start();
841
+ }
842
+ /** 播放动画 */
843
+ play(t = 0, e) {
844
+ this.changeStatus(T.PLAYING), this.paths[t];
845
+ }
846
+ /** 暂停动画 */
847
+ pause() {
848
+ this.changeStatus(T.PAUSE);
849
+ }
850
+ /** 停止动画 */
851
+ stop() {
852
+ this.changeStatus(T.STOP);
853
+ }
854
+ /** 路径反转 */
855
+ flip() {
856
+ }
857
+ /** 结束导航 */
858
+ over() {
859
+ this.changeStatus(T.PENDING);
860
+ }
861
+ }
862
+ const st = new P();
863
+ export {
864
+ P as Azimuth,
865
+ q as GyroListener,
866
+ J as MapCamera,
867
+ f as NAVIGATE_ORIENTATION_TYPE,
868
+ A as NAVIGATE_VISION_TYPE,
869
+ tt as NavigateCamera,
870
+ rt as Navigator,
871
+ T as PLAY_STATUS,
872
+ L as SoonSpaceCamera,
873
+ I as Vector3ToEuler,
874
+ st as azimuth,
875
+ G as eulerToVector3,
876
+ U as getDirection,
877
+ W as getDirectionByNodes,
878
+ nt as getDistanceInfoByProgress,
879
+ B as getFixEuler,
880
+ k as getFixVector,
881
+ ot as getNavigatorNodeInfoByProgress,
882
+ it as getNavigatorNodeInfosByTopology,
883
+ X as normalizeEuler,
884
+ et as reverseTopologies
885
+ };
@@ -1,6 +1,5 @@
1
1
  import { Object3D, Vector3 } from 'three';
2
- import SoonSpace from 'soonspacejs';
3
- import { Topology } from 'soonspacejs';
2
+ import { default as SoonSpace, Topology } from 'soonspacejs';
4
3
  import { PLAY_STATUS, playInfo } from './types';
5
4
  export * from './navigator-nodes';
6
5
  export * from './types';
@@ -21,7 +20,7 @@ export declare class Navigator {
21
20
  /** 停止时是否返回起点,默认为是 */
22
21
  backStartPointWhenStop: boolean;
23
22
  /** 路径动画主体模型 */
24
- _model: Object3D<import("three").Object3DEventMap>;
23
+ _model: Object3D<import('three').Object3DEventMap>;
25
24
  get model(): Object3D;
26
25
  set model(obj: Object3D);
27
26
  protected _speed: number;
@@ -1,4 +1,4 @@
1
- import type { Node, Topology } from 'soonspacejs';
1
+ import { Node, Topology } from 'soonspacejs';
2
2
  import { Direction } from './types';
3
3
  interface NavigatorNodeInfo {
4
4
  progressArea: [number, number];
@@ -1,5 +1,4 @@
1
- import SoonSpace from 'soonspacejs';
2
- import { Topology } from 'soonspacejs';
1
+ import { default as SoonSpace, Topology } from 'soonspacejs';
3
2
  import { Vector3 } from 'three';
4
3
  import { Direction } from './types';
5
4
  export declare function getDirection(target: Vector3, front: Vector3): Direction;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soonspacejs/plugin-navigation",
3
3
  "pluginName": "NavigationPlugin",
4
- "version": "2.13.17",
4
+ "version": "2.14.0",
5
5
  "description": "Navigation plugin for SoonSpace.js",
6
6
  "main": "dist/index.esm.js",
7
7
  "module": "dist/index.esm.js",
@@ -13,9 +13,9 @@
13
13
  ],
14
14
  "author": "zhuojian",
15
15
  "license": "UNLICENSED",
16
- "gitHead": "8afa5fda9a0ef2c080060e7d8e71a8bf168fd4d2",
16
+ "gitHead": "4c85e8b7b8ad24ccb9b42f3a1826bca377c42a6d",
17
17
  "peerDependencies": {
18
- "soonspacejs": "2.13.17"
18
+ "soonspacejs": "2.14.0"
19
19
  },
20
20
  "dependencies": {
21
21
  "@three3d/tools": "^1.6.0"