@soonspacejs/plugin-transform-controls 2.15.4 → 2.15.6

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.
Files changed (2) hide show
  1. package/dist/index.esm.js +31 -22
  2. package/package.json +2 -2
package/dist/index.esm.js CHANGED
@@ -1,32 +1,41 @@
1
- import { Box3 as y, Vector3 as p, Matrix4 as E, Mesh as P } from "three";
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 u = new y(), o = new y(), h = new p(), f = new p(), r = new p(), i = new p(), x = new p(), l = new p(), d = new E(), c = /* @__PURE__ */ new WeakMap();
4
- function v(s, e) {
5
- return e.setFromObject(s), e.isEmpty() && (s.getWorldPosition(e.min), e.max.copy(e.min)), e;
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 w(s, e) {
8
- v(e, o), v(s, u), u.getCenter(h), u.getSize(f).multiplyScalar(0.5), r.addVectors(o.min, f), i.subVectors(o.max, f), r.x > i.x && (r.x = i.x = (o.min.x + o.max.x) * 0.5), r.y > i.y && (r.y = i.y = (o.min.y + o.max.y) * 0.5), r.z > i.z && (r.z = i.z = (o.min.z + o.max.z) * 0.5), x.copy(h).clamp(r, i), l.subVectors(x, h), !(l.x === 0 && l.y === 0 && l.z === 0) && (s.parent && (s.parent.updateWorldMatrix(!0, !1), d.copy(s.parent.matrixWorld).invert(), d.elements[12] = 0, d.elements[13] = 0, d.elements[14] = 0, l.applyMatrix4(d)), s.position.add(l));
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
- class V {
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: a = "translate", bounds: _, onUpdate: C, onDragStart: M, onDragEnd: z, onClose: B } = t, n = new S(
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
- c.set(n, _ ?? null), this.controls.add(n), n.attach(e), n.mode = a, n.addEventListener("dragging-changed", (m) => {
21
- this.ssp.controls.enabled = !m.value, m.value ? M?.(e) : z?.(e);
22
- }), n.addEventListener("objectChange", () => {
23
- const m = c.get(n) ?? null;
24
- m && w(e, m), C?.(e), this.ssp.signals.objectChanged.dispatch(e);
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 g = n.getHelper();
27
- return g.addEventListener("removed", () => {
28
- B?.();
29
- }), this.ssp.viewport.scene.add(g), this.ssp.render(), n;
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(a) {
39
- a instanceof P && (a.geometry && a.geometry.dispose(), a.material && a.material.dispose());
40
- }), this.ssp.removeObject(t), c.delete(e), this.controls.delete(e);
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 && (c.set(e, t), t && w(e.object, t));
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
- V as default
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",
4
+ "version": "2.15.6",
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.4"
18
+ "soonspacejs": "2.15.5"
19
19
  }
20
20
  }