@soonspacejs/plugin-drag-controls 2.13.17 → 2.14.1
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/DragControls.d.ts +33 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +108 -1
- package/package.json +3 -3
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Controls, Raycaster, MOUSE, TOUCH } from 'three';
|
|
2
|
+
export class DragControls extends Controls<any> {
|
|
3
|
+
constructor(objects: any, camera: any, domElement?: null);
|
|
4
|
+
objects: any;
|
|
5
|
+
objectSet: WeakSet<WeakKey>;
|
|
6
|
+
poiNodeSet: Set<any>;
|
|
7
|
+
recursive: boolean;
|
|
8
|
+
transformGroup: boolean;
|
|
9
|
+
rotateSpeed: number;
|
|
10
|
+
raycaster: Raycaster;
|
|
11
|
+
mouseButtons: {
|
|
12
|
+
LEFT: MOUSE;
|
|
13
|
+
MIDDLE: MOUSE;
|
|
14
|
+
RIGHT: MOUSE;
|
|
15
|
+
};
|
|
16
|
+
touches: {
|
|
17
|
+
ONE: TOUCH;
|
|
18
|
+
};
|
|
19
|
+
_onPointerMove: typeof onPointerMove;
|
|
20
|
+
_onPointerDown: typeof onPointerDown;
|
|
21
|
+
_onPointerCancel: typeof onPointerCancel;
|
|
22
|
+
connect(): void;
|
|
23
|
+
_updatePointer(event: any): void;
|
|
24
|
+
_updateState(event: any): void;
|
|
25
|
+
state: number | undefined;
|
|
26
|
+
}
|
|
27
|
+
declare function onPointerMove(event: any): void;
|
|
28
|
+
declare function onPointerDown(event: any): void;
|
|
29
|
+
declare function onPointerCancel(): void;
|
|
30
|
+
declare class onPointerCancel {
|
|
31
|
+
state: number | undefined;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -1 +1,108 @@
|
|
|
1
|
-
import{Plane as
|
|
1
|
+
import { Plane as N, Vector2 as P, Vector3 as h, Matrix4 as g, Controls as O, Raycaster as x, MOUSE as l, TOUCH as f } from "three";
|
|
2
|
+
const m = new N(), r = new P(), y = new h(), v = new P(), p = new P(), E = new h(), w = new h(), _ = new g(), b = new h(), A = new h();
|
|
3
|
+
let n = null;
|
|
4
|
+
const u = [], a = {
|
|
5
|
+
NONE: -1,
|
|
6
|
+
PAN: 0,
|
|
7
|
+
ROTATE: 1
|
|
8
|
+
};
|
|
9
|
+
class L extends O {
|
|
10
|
+
constructor(t, e, i = null) {
|
|
11
|
+
super(e, i), this.objects = t, this.objectSet = new WeakSet(t), this.poiNodeSet = /* @__PURE__ */ new Set(), t.forEach((s) => {
|
|
12
|
+
s.stype === "PoiNode" && this.poiNodeSet.add(s);
|
|
13
|
+
}), this.recursive = !0, this.transformGroup = !1, this.rotateSpeed = 1, this.raycaster = new x(), this.mouseButtons = { LEFT: l.PAN, MIDDLE: l.PAN, RIGHT: l.ROTATE }, this.touches = { ONE: f.PAN }, this._onPointerMove = C.bind(this), this._onPointerDown = S.bind(this), this._onPointerCancel = M.bind(this), i !== null && this.connect();
|
|
14
|
+
}
|
|
15
|
+
connect() {
|
|
16
|
+
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", this.domElement.style.userSelect = "none";
|
|
17
|
+
}
|
|
18
|
+
disconnect() {
|
|
19
|
+
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.userSelect = "auto", this.domElement.style.cursor = "";
|
|
20
|
+
}
|
|
21
|
+
dispose() {
|
|
22
|
+
this.disconnect();
|
|
23
|
+
}
|
|
24
|
+
_updatePointer(t) {
|
|
25
|
+
const e = this.domElement.getBoundingClientRect();
|
|
26
|
+
r.x = (t.clientX - e.left) / e.width * 2 - 1, r.y = -(t.clientY - e.top) / e.height * 2 + 1;
|
|
27
|
+
}
|
|
28
|
+
_updateState(t) {
|
|
29
|
+
let e;
|
|
30
|
+
if (t.pointerType === "touch")
|
|
31
|
+
e = this.touches.ONE;
|
|
32
|
+
else
|
|
33
|
+
switch (t.button) {
|
|
34
|
+
case 0:
|
|
35
|
+
e = this.mouseButtons.LEFT;
|
|
36
|
+
break;
|
|
37
|
+
case 1:
|
|
38
|
+
e = this.mouseButtons.MIDDLE;
|
|
39
|
+
break;
|
|
40
|
+
case 2:
|
|
41
|
+
e = this.mouseButtons.RIGHT;
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
e = null;
|
|
45
|
+
}
|
|
46
|
+
switch (e) {
|
|
47
|
+
case l.PAN:
|
|
48
|
+
case f.PAN:
|
|
49
|
+
this.state = a.PAN;
|
|
50
|
+
break;
|
|
51
|
+
case l.ROTATE:
|
|
52
|
+
case f.ROTATE:
|
|
53
|
+
this.state = a.ROTATE;
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
this.state = a.NONE;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function C(o) {
|
|
61
|
+
const t = this.object;
|
|
62
|
+
this.domElement;
|
|
63
|
+
const e = this.raycaster;
|
|
64
|
+
this.enabled !== !1 && (this._updatePointer(o), e.setFromCamera(r, t), n && (this.state === a.PAN ? e.ray.intersectPlane(m, E) && n.position.copy(E.sub(y).applyMatrix4(_)) : this.state === a.ROTATE && (v.subVectors(r, p).multiplyScalar(this.rotateSpeed), n.rotateOnWorldAxis(b, v.x), n.rotateOnWorldAxis(A.normalize(), -v.y)), this.dispatchEvent({ type: "drag", object: n }), p.copy(r)), p.copy(r));
|
|
65
|
+
}
|
|
66
|
+
function S(o) {
|
|
67
|
+
const t = this.object, e = this.domElement, i = this.raycaster;
|
|
68
|
+
if (this.enabled === !1) return;
|
|
69
|
+
this._updatePointer(o), this._updateState(o), u.length = 0;
|
|
70
|
+
let s = null;
|
|
71
|
+
this.poiNodeSet.forEach((d) => {
|
|
72
|
+
d.element.contains(o.target) && (s = d);
|
|
73
|
+
}), s || (i.setFromCamera(r, t), i.intersectObjects(this.objects, this.recursive, u), s = u[0] ? u[0].object : null), s && (n = T(s, this.objectSet) ?? s, m.setFromNormalAndCoplanarPoint(
|
|
74
|
+
t.getWorldDirection(m.normal),
|
|
75
|
+
w.setFromMatrixPosition(n.matrixWorld)
|
|
76
|
+
), i.ray.intersectPlane(m, E) && (this.state === a.PAN ? (_.copy(n.parent.matrixWorld).invert(), y.copy(E).sub(w.setFromMatrixPosition(n.matrixWorld))) : this.state === a.ROTATE && (b.set(0, 1, 0).applyQuaternion(t.quaternion).normalize(), A.set(1, 0, 0).applyQuaternion(t.quaternion).normalize())), e.style.cursor = "move", this.dispatchEvent({ type: "dragstart", object: n })), p.copy(r);
|
|
77
|
+
}
|
|
78
|
+
function M() {
|
|
79
|
+
this.enabled !== !1 && (n && (this.dispatchEvent({ type: "dragend", object: n }), n = null), this.domElement.style.cursor = "auto", this.state = a.NONE);
|
|
80
|
+
}
|
|
81
|
+
function T(o, t) {
|
|
82
|
+
return t.has(o) ? o : o.parent === null ? null : T(o.parent, t);
|
|
83
|
+
}
|
|
84
|
+
class R {
|
|
85
|
+
controls = null;
|
|
86
|
+
viewport;
|
|
87
|
+
constructor(t) {
|
|
88
|
+
this.viewport = t.viewport;
|
|
89
|
+
}
|
|
90
|
+
start(t, e = {}) {
|
|
91
|
+
if (!this.controls) {
|
|
92
|
+
const { dragStart: i, drag: s, dragEnd: d } = e;
|
|
93
|
+
this.controls = new L(t, this.viewport.camera, this.viewport.container), this.controls?.addEventListener("dragstart", (c) => {
|
|
94
|
+
this.viewport.controls.enabled = !1, i?.(c.object);
|
|
95
|
+
}), this.controls?.addEventListener("drag", (c) => {
|
|
96
|
+
this.viewport.render(), s?.(c.object);
|
|
97
|
+
}), this.controls?.addEventListener("dragend", (c) => {
|
|
98
|
+
this.viewport.controls.enabled = !0, d?.(c.object);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
stop() {
|
|
103
|
+
this.controls && (this.controls.dispose(), this.controls = null);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
R as default
|
|
108
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-drag-controls",
|
|
3
3
|
"pluginName": "Drag Controls Plugin",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.14.1",
|
|
5
5
|
"description": "Drag Controls Plugin plugin for SoonSpace.js",
|
|
6
6
|
"main": "dist/index.esm.js",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
],
|
|
14
14
|
"author": "xunwei",
|
|
15
15
|
"license": "UNLICENSED",
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "27d5e0bcd79ff71c8e2943a8420c39624ae6f8e6",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"soonspacejs": "2.
|
|
18
|
+
"soonspacejs": "2.14.1"
|
|
19
19
|
}
|
|
20
20
|
}
|