@soonspacejs/plugin-follow-mouse 2.4.1 → 2.4.4
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/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
class s{constructor(s){this.ssp=s,this.object=null,this.objectBbox=new this.ssp.THREE.Box3(new this.ssp.THREE.Vector3,new this.ssp.THREE.Vector3),this.objectSourcePosition=new this.ssp.THREE.Vector3,this.sceneMesh=[],this.helper=null,this.placedObject=[],this.options={},this.mouseDownModelPosition=new this.ssp.THREE.Vector3,this.onMouseMove=this.onMouseMove.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onClick=this.onClick.bind(this),this.onRightClick=this.onRightClick.bind(this),this.onDblClick=this.onDblClick.bind(this),this.onKeyUp=this.onKeyUp.bind(this)}start(s,e={}){this.options=e,this.object=s,this.objectBbox.setFromObject(s),this.objectSourcePosition.copy(s.position.clone()),this.sceneMesh=this.ssp.viewport.scener.intersectsList.getAll().filter((s=>{let e=s.visible;return s.traverseAncestors((s=>{!1===s.visible&&(e=!1)})),e}));const{openHelper:t=!0,helperColor:o=16776960}=this.options;!t||"Sbm"!==this.object.stype&&"Model"!==this.object.stype||(s.updateWorldMatrix(!0,!0),this.helper=this.ssp.addBoxHelper({id:"followMouseBoxHelper",box:this.objectBbox,color:o}),this.ssp.signals.sceneChanged.dispatch()),s.traverse((s=>{const e=this.sceneMesh.findIndex((e=>e.uuid===s.uuid));-1!==e&&this.sceneMesh.splice(e,1)})),this.ssp.signals.mouseMove.add(this.onMouseMove),this.ssp.signals.mouseDown.add(this.onMouseDown),this.ssp.signals.click.add(this.onClick),this.ssp.signals.rightClick.add(this.onRightClick),this.ssp.signals.dblClick.add(this.onDblClick),this.ssp.signals.keyUp.add(this.onKeyUp)}stop(){var s;null===(s=this.object)||void 0===s||s.position.copy(this.objectSourcePosition.clone()),this.ssp.removeHelperById("followMouseBoxHelper"),this.object=null,this.objectBbox=new this.ssp.THREE.Box3(new this.ssp.THREE.Vector3,new this.ssp.THREE.Vector3),this.objectSourcePosition=new this.ssp.THREE.Vector3,this.sceneMesh=[],this.helper=null,this.placedObject=[],this.options={},this.mouseDownModelPosition=new this.ssp.THREE.Vector3,this.ssp.signals.mouseMove.remove(this.onMouseMove),this.ssp.signals.mouseDown.remove(this.onMouseDown),this.ssp.signals.click.remove(this.onClick),this.ssp.signals.dblClick.remove(this.onDblClick),this.ssp.signals.keyUp.remove(this.onKeyUp)}onMouseMove(s){if(s.preventDefault(),!this.object)return;const{offset:e=new this.ssp.THREE.Vector3(1,1,1)}=this.options,t=this.ssp.viewport.getIntersects(s,this.sceneMesh),o=this.object.getWorldPosition(new this.ssp.THREE.Vector3).sub(this.object.position),i=new this.ssp.THREE.Vector3;let n="y";if(t.length>0){const{point:s,face:e}=t[0];if(i.copy(s.clone()),e){const{normal:s}=e;0===s.y&&0===s.z&&(1===s.x?n="x":-1===s.x&&(n="-x")),0===s.x&&0===s.z&&(1===s.y?n="y":-1===s.y&&(n="-y")),0===s.x&&0===s.y&&(1===s.z?n="z":-1===s.z&&(n="-z"))}}else i.copy(this.ssp.getPositionByOffset(s,.1));const h=i.sub(o),c=this.objectBbox.getSize(new this.ssp.THREE.Vector3);switch(n){case"x":h.setX(h.x+c.x/2+e.x);break;case"-x":h.setX(h.x-c.x/2-e.x);break;case"y":h.setY(h.y+e.y);break;case"-y":h.setY(h.y-c.y-e.y);break;case"z":h.setZ(h.z+c.z/2+e.z);break;case"-z":h.setZ(h.z-c.z/2-e.z)}this.object.position.copy(h).setY(h.y),this.helper&&this.helper.box.copy(new this.ssp.THREE.Box3(new this.ssp.THREE.Vector3,new this.ssp.THREE.Vector3).setFromObject(this.object)),this.ssp.signals.sceneChanged.dispatch()}onMouseDown(s){this.object&&this.mouseDownModelPosition.copy(this.object.getWorldPosition(new this.ssp.THREE.Vector3))}onClick(s){this.onPlace()}onRightClick(s){this.onDelPrev()}async onDblClick(s){await this.onPlace(),this.options.onDone&&this.options.onDone(this.placedObject),this.stop()}onKeyUp(s){switch(s.code){case"Backspace":this.onDelPrev();break;case"Enter":this.options.onDone&&this.options.onDone(this.placedObject),this.stop();break;case"Escape":this.options.onCancel&&this.options.onCancel(),this.stop()}}onPlace(){var s,e,t;if("Sbm"===(null===(s=this.object)||void 0===s?void 0:s.stype))return this.ssp.cloneSbm(this.object,{id:`clone_${this.object.sid}_${this.placedObject.length+1}`,position:this.mouseDownModelPosition.clone()}).then((s=>(this.placedObject.push(s),this.options.onPlace&&this.options.onPlace(s),Promise.resolve())));if("Model"===(null===(e=this.object)||void 0===e?void 0:e.stype))return this.ssp.cloneModel(this.object,{id:`clone_${this.object.sid}_${this.placedObject.length+1}`,position:this.mouseDownModelPosition.clone()}).then((s=>(this.placedObject.push(s),this.options.onPlace&&this.options.onPlace(s),Promise.resolve())));if("Poi"===(null===(t=this.object)||void 0===t?void 0:t.stype)){const s=this.ssp.clonePoi(this.object,{id:`clone_${this.object.sid}_${this.placedObject.length+1}`,position:this.mouseDownModelPosition.clone()});return s?(this.placedObject.push(s),this.options.onPlace&&this.options.onPlace(s),Promise.resolve()):Promise.reject("In soonspacejs: 插件(plugin-follow-mouse)摆放 Poi 对象时错误!")}return Promise.reject("In soonspacejs: 插件(plugin-follow-mouse)传入对象类型错误,仅支持 sbm、model、poi !")}onDelPrev(){if(0===this.placedObject.length)return;const s=this.placedObject[this.placedObject.length-1];this.ssp.removeObject(s),this.placedObject.splice(this.placedObject.length-1,1),this.options.onBack&&this.options.onBack(s)}}export{s as default};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(s,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(s="undefined"!=typeof globalThis?globalThis:s||self).FollowMousePlugin=e()}(this,(function(){"use strict";const s="followMouseBoxHelper";return class{constructor(s){this.ssp=s,this.object=null,this.objectBbox=new this.ssp.THREE.Box3(new this.ssp.THREE.Vector3,new this.ssp.THREE.Vector3),this.objectSourcePosition=new this.ssp.THREE.Vector3,this.sceneMesh=[],this.helper=null,this.placedObject=[],this.options={},this.mouseDownModelPosition=new this.ssp.THREE.Vector3,this.onMouseMove=this.onMouseMove.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onClick=this.onClick.bind(this),this.onRightClick=this.onRightClick.bind(this),this.onDblClick=this.onDblClick.bind(this),this.onKeyUp=this.onKeyUp.bind(this)}start(e,t={}){this.options=t,this.object=e,this.objectBbox.setFromObject(e),this.objectSourcePosition.copy(e.position.clone()),this.sceneMesh=this.ssp.viewport.scener.intersectsList.getAll().filter((s=>{let e=s.visible;return s.traverseAncestors((s=>{!1===s.visible&&(e=!1)})),e}));const{openHelper:o=!0,helperColor:i=16776960}=this.options;!o||"Sbm"!==this.object.stype&&"Model"!==this.object.stype||(e.updateWorldMatrix(!0,!0),this.helper=this.ssp.addBoxHelper({id:s,box:this.objectBbox,color:i}),this.ssp.signals.sceneChanged.dispatch()),e.traverse((s=>{const e=this.sceneMesh.findIndex((e=>e.uuid===s.uuid));-1!==e&&this.sceneMesh.splice(e,1)})),this.ssp.signals.mouseMove.add(this.onMouseMove),this.ssp.signals.mouseDown.add(this.onMouseDown),this.ssp.signals.click.add(this.onClick),this.ssp.signals.rightClick.add(this.onRightClick),this.ssp.signals.dblClick.add(this.onDblClick),this.ssp.signals.keyUp.add(this.onKeyUp)}stop(){var e;null===(e=this.object)||void 0===e||e.position.copy(this.objectSourcePosition.clone()),this.ssp.removeHelperById(s),this.object=null,this.objectBbox=new this.ssp.THREE.Box3(new this.ssp.THREE.Vector3,new this.ssp.THREE.Vector3),this.objectSourcePosition=new this.ssp.THREE.Vector3,this.sceneMesh=[],this.helper=null,this.placedObject=[],this.options={},this.mouseDownModelPosition=new this.ssp.THREE.Vector3,this.ssp.signals.mouseMove.remove(this.onMouseMove),this.ssp.signals.mouseDown.remove(this.onMouseDown),this.ssp.signals.click.remove(this.onClick),this.ssp.signals.dblClick.remove(this.onDblClick),this.ssp.signals.keyUp.remove(this.onKeyUp)}onMouseMove(s){if(s.preventDefault(),!this.object)return;const{offset:e=new this.ssp.THREE.Vector3(1,1,1)}=this.options,t=this.ssp.viewport.getIntersects(s,this.sceneMesh),o=this.object.getWorldPosition(new this.ssp.THREE.Vector3).sub(this.object.position),i=new this.ssp.THREE.Vector3;let n="y";if(t.length>0){const{point:s,face:e}=t[0];if(i.copy(s.clone()),e){const{normal:s}=e;0===s.y&&0===s.z&&(1===s.x?n="x":-1===s.x&&(n="-x")),0===s.x&&0===s.z&&(1===s.y?n="y":-1===s.y&&(n="-y")),0===s.x&&0===s.y&&(1===s.z?n="z":-1===s.z&&(n="-z"))}}else i.copy(this.ssp.getPositionByOffset(s,.1));const h=i.sub(o),c=this.objectBbox.getSize(new this.ssp.THREE.Vector3);switch(n){case"x":h.setX(h.x+c.x/2+e.x);break;case"-x":h.setX(h.x-c.x/2-e.x);break;case"y":h.setY(h.y+e.y);break;case"-y":h.setY(h.y-c.y-e.y);break;case"z":h.setZ(h.z+c.z/2+e.z);break;case"-z":h.setZ(h.z-c.z/2-e.z)}this.object.position.copy(h).setY(h.y),this.helper&&this.helper.box.copy(new this.ssp.THREE.Box3(new this.ssp.THREE.Vector3,new this.ssp.THREE.Vector3).setFromObject(this.object)),this.ssp.signals.sceneChanged.dispatch()}onMouseDown(s){this.object&&this.mouseDownModelPosition.copy(this.object.getWorldPosition(new this.ssp.THREE.Vector3))}onClick(s){this.onPlace()}onRightClick(s){this.onDelPrev()}async onDblClick(s){await this.onPlace(),this.options.onDone&&this.options.onDone(this.placedObject),this.stop()}onKeyUp(s){switch(s.code){case"Backspace":this.onDelPrev();break;case"Enter":this.options.onDone&&this.options.onDone(this.placedObject),this.stop();break;case"Escape":this.options.onCancel&&this.options.onCancel(),this.stop()}}onPlace(){var s,e,t;if("Sbm"===(null===(s=this.object)||void 0===s?void 0:s.stype))return this.ssp.cloneSbm(this.object,{id:`clone_${this.object.sid}_${this.placedObject.length+1}`,position:this.mouseDownModelPosition.clone()}).then((s=>(this.placedObject.push(s),this.options.onPlace&&this.options.onPlace(s),Promise.resolve())));if("Model"===(null===(e=this.object)||void 0===e?void 0:e.stype))return this.ssp.cloneModel(this.object,{id:`clone_${this.object.sid}_${this.placedObject.length+1}`,position:this.mouseDownModelPosition.clone()}).then((s=>(this.placedObject.push(s),this.options.onPlace&&this.options.onPlace(s),Promise.resolve())));if("Poi"===(null===(t=this.object)||void 0===t?void 0:t.stype)){const s=this.ssp.clonePoi(this.object,{id:`clone_${this.object.sid}_${this.placedObject.length+1}`,position:this.mouseDownModelPosition.clone()});return s?(this.placedObject.push(s),this.options.onPlace&&this.options.onPlace(s),Promise.resolve()):Promise.reject("In soonspacejs: 插件(plugin-follow-mouse)摆放 Poi 对象时错误!")}return Promise.reject("In soonspacejs: 插件(plugin-follow-mouse)传入对象类型错误,仅支持 sbm、model、poi !")}onDelPrev(){if(0===this.placedObject.length)return;const s=this.placedObject[this.placedObject.length-1];this.ssp.
|
|
1
|
+
!function(s,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(s="undefined"!=typeof globalThis?globalThis:s||self).FollowMousePlugin=e()}(this,(function(){"use strict";const s="followMouseBoxHelper";return class{constructor(s){this.ssp=s,this.object=null,this.objectBbox=new this.ssp.THREE.Box3(new this.ssp.THREE.Vector3,new this.ssp.THREE.Vector3),this.objectSourcePosition=new this.ssp.THREE.Vector3,this.sceneMesh=[],this.helper=null,this.placedObject=[],this.options={},this.mouseDownModelPosition=new this.ssp.THREE.Vector3,this.onMouseMove=this.onMouseMove.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onClick=this.onClick.bind(this),this.onRightClick=this.onRightClick.bind(this),this.onDblClick=this.onDblClick.bind(this),this.onKeyUp=this.onKeyUp.bind(this)}start(e,t={}){this.options=t,this.object=e,this.objectBbox.setFromObject(e),this.objectSourcePosition.copy(e.position.clone()),this.sceneMesh=this.ssp.viewport.scener.intersectsList.getAll().filter((s=>{let e=s.visible;return s.traverseAncestors((s=>{!1===s.visible&&(e=!1)})),e}));const{openHelper:o=!0,helperColor:i=16776960}=this.options;!o||"Sbm"!==this.object.stype&&"Model"!==this.object.stype||(e.updateWorldMatrix(!0,!0),this.helper=this.ssp.addBoxHelper({id:s,box:this.objectBbox,color:i}),this.ssp.signals.sceneChanged.dispatch()),e.traverse((s=>{const e=this.sceneMesh.findIndex((e=>e.uuid===s.uuid));-1!==e&&this.sceneMesh.splice(e,1)})),this.ssp.signals.mouseMove.add(this.onMouseMove),this.ssp.signals.mouseDown.add(this.onMouseDown),this.ssp.signals.click.add(this.onClick),this.ssp.signals.rightClick.add(this.onRightClick),this.ssp.signals.dblClick.add(this.onDblClick),this.ssp.signals.keyUp.add(this.onKeyUp)}stop(){var e;null===(e=this.object)||void 0===e||e.position.copy(this.objectSourcePosition.clone()),this.ssp.removeHelperById(s),this.object=null,this.objectBbox=new this.ssp.THREE.Box3(new this.ssp.THREE.Vector3,new this.ssp.THREE.Vector3),this.objectSourcePosition=new this.ssp.THREE.Vector3,this.sceneMesh=[],this.helper=null,this.placedObject=[],this.options={},this.mouseDownModelPosition=new this.ssp.THREE.Vector3,this.ssp.signals.mouseMove.remove(this.onMouseMove),this.ssp.signals.mouseDown.remove(this.onMouseDown),this.ssp.signals.click.remove(this.onClick),this.ssp.signals.dblClick.remove(this.onDblClick),this.ssp.signals.keyUp.remove(this.onKeyUp)}onMouseMove(s){if(s.preventDefault(),!this.object)return;const{offset:e=new this.ssp.THREE.Vector3(1,1,1)}=this.options,t=this.ssp.viewport.getIntersects(s,this.sceneMesh),o=this.object.getWorldPosition(new this.ssp.THREE.Vector3).sub(this.object.position),i=new this.ssp.THREE.Vector3;let n="y";if(t.length>0){const{point:s,face:e}=t[0];if(i.copy(s.clone()),e){const{normal:s}=e;0===s.y&&0===s.z&&(1===s.x?n="x":-1===s.x&&(n="-x")),0===s.x&&0===s.z&&(1===s.y?n="y":-1===s.y&&(n="-y")),0===s.x&&0===s.y&&(1===s.z?n="z":-1===s.z&&(n="-z"))}}else i.copy(this.ssp.getPositionByOffset(s,.1));const h=i.sub(o),c=this.objectBbox.getSize(new this.ssp.THREE.Vector3);switch(n){case"x":h.setX(h.x+c.x/2+e.x);break;case"-x":h.setX(h.x-c.x/2-e.x);break;case"y":h.setY(h.y+e.y);break;case"-y":h.setY(h.y-c.y-e.y);break;case"z":h.setZ(h.z+c.z/2+e.z);break;case"-z":h.setZ(h.z-c.z/2-e.z)}this.object.position.copy(h).setY(h.y),this.helper&&this.helper.box.copy(new this.ssp.THREE.Box3(new this.ssp.THREE.Vector3,new this.ssp.THREE.Vector3).setFromObject(this.object)),this.ssp.signals.sceneChanged.dispatch()}onMouseDown(s){this.object&&this.mouseDownModelPosition.copy(this.object.getWorldPosition(new this.ssp.THREE.Vector3))}onClick(s){this.onPlace()}onRightClick(s){this.onDelPrev()}async onDblClick(s){await this.onPlace(),this.options.onDone&&this.options.onDone(this.placedObject),this.stop()}onKeyUp(s){switch(s.code){case"Backspace":this.onDelPrev();break;case"Enter":this.options.onDone&&this.options.onDone(this.placedObject),this.stop();break;case"Escape":this.options.onCancel&&this.options.onCancel(),this.stop()}}onPlace(){var s,e,t;if("Sbm"===(null===(s=this.object)||void 0===s?void 0:s.stype))return this.ssp.cloneSbm(this.object,{id:`clone_${this.object.sid}_${this.placedObject.length+1}`,position:this.mouseDownModelPosition.clone()}).then((s=>(this.placedObject.push(s),this.options.onPlace&&this.options.onPlace(s),Promise.resolve())));if("Model"===(null===(e=this.object)||void 0===e?void 0:e.stype))return this.ssp.cloneModel(this.object,{id:`clone_${this.object.sid}_${this.placedObject.length+1}`,position:this.mouseDownModelPosition.clone()}).then((s=>(this.placedObject.push(s),this.options.onPlace&&this.options.onPlace(s),Promise.resolve())));if("Poi"===(null===(t=this.object)||void 0===t?void 0:t.stype)){const s=this.ssp.clonePoi(this.object,{id:`clone_${this.object.sid}_${this.placedObject.length+1}`,position:this.mouseDownModelPosition.clone()});return s?(this.placedObject.push(s),this.options.onPlace&&this.options.onPlace(s),Promise.resolve()):Promise.reject("In soonspacejs: 插件(plugin-follow-mouse)摆放 Poi 对象时错误!")}return Promise.reject("In soonspacejs: 插件(plugin-follow-mouse)传入对象类型错误,仅支持 sbm、model、poi !")}onDelPrev(){if(0===this.placedObject.length)return;const s=this.placedObject[this.placedObject.length-1];this.ssp.removeObject(s),this.placedObject.splice(this.placedObject.length-1,1),this.options.onBack&&this.options.onBack(s)}}}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-follow-mouse",
|
|
3
3
|
"pluginName": "FollowMousePlugin",
|
|
4
|
-
"version": "2.4.
|
|
4
|
+
"version": "2.4.4",
|
|
5
5
|
"description": "Scene object follow mouse 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": "73b20b95e4b94f6634bfde269b1a983f3f2db6f9"
|
|
17
17
|
}
|