@soonspacejs/plugin-drag-controls 2.11.60
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/README.md +5 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.esm.js +1 -0
- package/package.json +20 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import SoonSpace from 'soonspacejs';
|
|
2
|
+
import { DragControls } from 'three/examples/jsm/controls/DragControls.js';
|
|
3
|
+
import { Object3D } from 'three';
|
|
4
|
+
export interface StartOptions {
|
|
5
|
+
objects: Object3D[];
|
|
6
|
+
dragStart?: (object: Object3D) => void;
|
|
7
|
+
drag?: (object: Object3D) => void;
|
|
8
|
+
dragEnd?: (object: Object3D) => void;
|
|
9
|
+
}
|
|
10
|
+
declare class DragControlsPlugin {
|
|
11
|
+
controls: DragControls | null;
|
|
12
|
+
viewport: SoonSpace['viewport'];
|
|
13
|
+
constructor(ssp: SoonSpace);
|
|
14
|
+
start(options: StartOptions): void;
|
|
15
|
+
stop(): void;
|
|
16
|
+
}
|
|
17
|
+
export default DragControlsPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Plane as t,Vector2 as e,Vector3 as n,Matrix4 as o,Controls as s,Raycaster as i,MOUSE as r,TOUCH as a}from"three";const l=new t,c=new e,h=new n,d=new e,u=new e,m=new n,p=new n,v=new o,E=new n,b=new n;let w=null;const y=[],P=-1,_=0,j=1;class L extends s{constructor(t,e,n=null){super(e,n),this.objects=t,this.objectSet=new WeakSet(Object.values(t)),this.recursive=!0,this.transformGroup=!1,this.rotateSpeed=1,this.raycaster=new i,this.mouseButtons={LEFT:r.PAN,MIDDLE:r.PAN,RIGHT:r.ROTATE},this.touches={ONE:a.PAN},this._onPointerMove=x.bind(this),this._onPointerDown=g.bind(this),this._onPointerCancel=f.bind(this),null!==n&&this.connect()}connect(){this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointerup",this._onPointerCancel),this.domElement.addEventListener("pointerleave",this._onPointerCancel),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointerup",this._onPointerCancel),this.domElement.removeEventListener("pointerleave",this._onPointerCancel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="auto",this.domElement.style.cursor=""}dispose(){this.disconnect()}_updatePointer(t){const e=this.domElement.getBoundingClientRect();c.x=(t.clientX-e.left)/e.width*2-1,c.y=-(t.clientY-e.top)/e.height*2+1}_updateState(t){let e;if("touch"===t.pointerType)e=this.touches.ONE;else switch(t.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=null}switch(e){case r.PAN:case a.PAN:this.state=_;break;case r.ROTATE:case a.ROTATE:this.state=j;break;default:this.state=P}}}function x(t){const e=this.object;this.domElement;const n=this.raycaster;!1!==this.enabled&&(this._updatePointer(t),n.setFromCamera(c,e),w&&(this.state===_?n.ray.intersectPlane(l,m)&&w.position.copy(m.sub(h).applyMatrix4(v)):this.state===j&&(d.subVectors(c,u).multiplyScalar(this.rotateSpeed),w.rotateOnWorldAxis(E,d.x),w.rotateOnWorldAxis(b.normalize(),-d.y)),this.dispatchEvent({type:"drag",object:w}),u.copy(c)),u.copy(c))}function g(t){const e=this.object,n=this.domElement,o=this.raycaster;if(!1!==this.enabled){var s;if(this._updatePointer(t),this._updateState(t),y.length=0,o.setFromCamera(c,e),o.intersectObjects(this.objects,this.recursive,y),y.length>0)w=null!==(s=A(y[0].object,this.objectSet))&&void 0!==s?s:y[0].object,l.setFromNormalAndCoplanarPoint(e.getWorldDirection(l.normal),p.setFromMatrixPosition(w.matrixWorld)),o.ray.intersectPlane(l,m)&&(this.state===_?(v.copy(w.parent.matrixWorld).invert(),h.copy(m).sub(p.setFromMatrixPosition(w.matrixWorld))):this.state===j&&(E.set(0,1,0).applyQuaternion(e.quaternion).normalize(),b.set(1,0,0).applyQuaternion(e.quaternion).normalize())),n.style.cursor="move",this.dispatchEvent({type:"dragstart",object:w});u.copy(c)}}function f(){!1!==this.enabled&&(w&&(this.dispatchEvent({type:"dragend",object:w}),w=null),this.domElement.style.cursor="auto",this.state=P)}function A(t,e){return e.has(t)?t:null===t.parent?null:A(t.parent,e)}class C{constructor(t){this.controls=null,this.viewport=t.viewport}start(t){var e,n,o;if(!this.controls){const{objects:s,dragStart:i,drag:r,dragEnd:a}=t;this.controls=new L(s,this.viewport.camera,this.viewport.container),null===(e=this.controls)||void 0===e||e.addEventListener("dragstart",(t=>{this.viewport.controls.enabled=!1,null==i||i(t.object)})),null===(n=this.controls)||void 0===n||n.addEventListener("drag",(t=>{this.viewport.render(),null==r||r(t.object)})),null===(o=this.controls)||void 0===o||o.addEventListener("dragend",(t=>{this.viewport.controls.enabled=!0,null==a||a(t.object)}))}}stop(){this.controls&&(this.controls.dispose(),this.controls=null)}}export{C as default};
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@soonspacejs/plugin-drag-controls",
|
|
3
|
+
"pluginName": "Drag Controls Plugin",
|
|
4
|
+
"version": "2.11.60",
|
|
5
|
+
"description": "Drag Controls Plugin plugin for SoonSpace.js",
|
|
6
|
+
"main": "dist/index.esm.js",
|
|
7
|
+
"module": "dist/index.esm.js",
|
|
8
|
+
"unpkg": "dist/index.esm.js",
|
|
9
|
+
"typings": "dist/index.d.ts",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"soonspacejs",
|
|
12
|
+
"drag-controls"
|
|
13
|
+
],
|
|
14
|
+
"author": "xunwei",
|
|
15
|
+
"license": "UNLICENSED",
|
|
16
|
+
"gitHead": "615dd40516eb5d02aede1c5423298592bfb51987",
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"soonspacejs": "2.11.60"
|
|
19
|
+
}
|
|
20
|
+
}
|