@soonspacejs/plugin-transform-controls 2.15.4 → 2.15.5
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 +31 -22
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -1,32 +1,41 @@
|
|
|
1
|
-
import { Box3 as
|
|
1
|
+
import { Box3 as v, Vector3 as p, Matrix4 as P, Mesh as O } from "three";
|
|
2
2
|
import { TransformControls as S } from "three/examples/jsm/controls/TransformControls.js";
|
|
3
|
-
const
|
|
4
|
-
function
|
|
5
|
-
|
|
3
|
+
const x = new v(), i = new v(), w = new v(), g = new p(), y = new p(), r = new p(), a = new p(), B = new p(), l = new p(), c = new P(), f = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
function z(s, e, t) {
|
|
5
|
+
if (e === t) return;
|
|
6
|
+
e.updateWorldMatrix(!1, !1);
|
|
7
|
+
const n = e.geometry;
|
|
8
|
+
n && (n.boundingBox || n.computeBoundingBox(), w.copy(n.boundingBox).applyMatrix4(e.matrixWorld), s.union(w));
|
|
9
|
+
const u = e.children;
|
|
10
|
+
for (let m = 0, h = u.length; m < h; m++)
|
|
11
|
+
z(s, u[m], t);
|
|
6
12
|
}
|
|
7
|
-
function
|
|
8
|
-
|
|
13
|
+
function C(s, e, t = null) {
|
|
14
|
+
return t && s !== t ? (e.makeEmpty(), s.updateWorldMatrix(!0, !1), z(e, s, t)) : e.setFromObject(s), e.isEmpty() && (s.getWorldPosition(e.min), e.max.copy(e.min)), e;
|
|
9
15
|
}
|
|
10
|
-
|
|
16
|
+
function M(s, e) {
|
|
17
|
+
C(e, i, s), C(s, x), x.getCenter(g), x.getSize(y).multiplyScalar(0.5), r.addVectors(i.min, y), a.subVectors(i.max, y), r.x > a.x && (r.x = a.x = (i.min.x + i.max.x) * 0.5), r.y > a.y && (r.y = a.y = (i.min.y + i.max.y) * 0.5), r.z > a.z && (r.z = a.z = (i.min.z + i.max.z) * 0.5), B.copy(g).clamp(r, a), l.subVectors(B, g), !(l.x === 0 && l.y === 0 && l.z === 0) && (s.parent && (s.parent.updateWorldMatrix(!0, !1), c.copy(s.parent.matrixWorld).invert(), c.elements[12] = 0, c.elements[13] = 0, c.elements[14] = 0, l.applyMatrix4(c)), s.position.add(l));
|
|
18
|
+
}
|
|
19
|
+
class L {
|
|
11
20
|
constructor(e) {
|
|
12
21
|
this.ssp = e;
|
|
13
22
|
}
|
|
14
23
|
controls = /* @__PURE__ */ new Set();
|
|
15
24
|
start(e, t = {}) {
|
|
16
|
-
const { mode:
|
|
25
|
+
const { mode: n = "translate", bounds: u, onUpdate: m, onDragStart: h, onDragEnd: W, onClose: E } = t, o = new S(
|
|
17
26
|
this.ssp.viewport.camera,
|
|
18
27
|
this.ssp.viewport.rendererManager.interactiveContainer
|
|
19
28
|
);
|
|
20
|
-
|
|
21
|
-
this.ssp.controls.enabled = !
|
|
22
|
-
}),
|
|
23
|
-
const
|
|
24
|
-
|
|
29
|
+
f.set(o, u ?? null), this.controls.add(o), o.attach(e), o.mode = n, o.addEventListener("dragging-changed", (d) => {
|
|
30
|
+
this.ssp.controls.enabled = !d.value, d.value ? h?.(e) : W?.(e);
|
|
31
|
+
}), o.addEventListener("objectChange", () => {
|
|
32
|
+
const d = f.get(o) ?? null;
|
|
33
|
+
d && M(e, d), m?.(e), this.ssp.signals.objectChanged.dispatch(e);
|
|
25
34
|
});
|
|
26
|
-
const
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
}), this.ssp.viewport.scene.add(
|
|
35
|
+
const _ = o.getHelper();
|
|
36
|
+
return _.addEventListener("removed", () => {
|
|
37
|
+
E?.();
|
|
38
|
+
}), this.ssp.viewport.scene.add(_), this.ssp.render(), o;
|
|
30
39
|
}
|
|
31
40
|
_getPreviousControl() {
|
|
32
41
|
return [...this.controls].at(-1);
|
|
@@ -35,9 +44,9 @@ class V {
|
|
|
35
44
|
if (e) {
|
|
36
45
|
e.detach(), e.disconnect();
|
|
37
46
|
const t = e.getHelper();
|
|
38
|
-
t.traverse(function(
|
|
39
|
-
|
|
40
|
-
}), this.ssp.removeObject(t),
|
|
47
|
+
t.traverse(function(n) {
|
|
48
|
+
n instanceof O && (n.geometry && n.geometry.dispose(), n.material && n.material.dispose());
|
|
49
|
+
}), this.ssp.removeObject(t), f.delete(e), this.controls.delete(e);
|
|
41
50
|
}
|
|
42
51
|
}
|
|
43
52
|
closeAll() {
|
|
@@ -47,12 +56,12 @@ class V {
|
|
|
47
56
|
* 动态更新指定控制器的移动范围来源对象(传 null 取消限制)
|
|
48
57
|
*/
|
|
49
58
|
setBounds(e = this._getPreviousControl(), t = null) {
|
|
50
|
-
e && (
|
|
59
|
+
e && (f.set(e, t), t && M(e.object, t));
|
|
51
60
|
}
|
|
52
61
|
changeMode(e = this._getPreviousControl(), t = "translate") {
|
|
53
62
|
e && e.mode !== t && (e.mode = t, this.ssp.signals.objectChanged.dispatch());
|
|
54
63
|
}
|
|
55
64
|
}
|
|
56
65
|
export {
|
|
57
|
-
|
|
66
|
+
L as default
|
|
58
67
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-transform-controls",
|
|
3
3
|
"pluginName": "TransformControlsPlugin",
|
|
4
|
-
"version": "2.15.
|
|
4
|
+
"version": "2.15.5",
|
|
5
5
|
"description": "Transform-controls plugin for SoonSpace.js",
|
|
6
6
|
"main": "dist/index.esm.js",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
"license": "UNLICENSED",
|
|
16
16
|
"gitHead": "4a87dd85050651088e11c3da777c49fab3db7e5d",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"soonspacejs": "2.15.
|
|
18
|
+
"soonspacejs": "2.15.5"
|
|
19
19
|
}
|
|
20
20
|
}
|