@soonspacejs/plugin-model-blast 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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import SoonSpace from 'soonspacejs';
1
+ import { default as SoonSpace } from 'soonspacejs';
2
2
  import { Object3D, Vector3 } from 'three';
3
3
  export default class ModelBlastPlugin {
4
4
  readonly ssp: SoonSpace;
@@ -8,7 +8,7 @@ export default class ModelBlastPlugin {
8
8
  constructor(ssp: SoonSpace);
9
9
  start(object: Object3D, scalar?: number): void;
10
10
  stop(object?: Object3D): void;
11
- objectActionMap: Map<Object3D<import("three").Object3DEventMap>[], {
11
+ objectActionMap: Map<Object3D<import('three').Object3DEventMap>[], {
12
12
  setTime: (time?: number) => void;
13
13
  stop: () => void;
14
14
  }>;
package/dist/index.esm.js CHANGED
@@ -1 +1,99 @@
1
- import{Vector3 as t,Quaternion as i,Box3 as s}from"three";class e{constructor(t){this.ssp=t,this.prevObjects=new Set,this.childDirs=new Map,this.childPositions=new Map,this.objectActionMap=new Map}start(s,e){this.prevObjects.add(s);const{ssp:o}=this,n=o.utils.getBoundingBox(s),c=n.getSize(new t),r=n.getCenter(new t),u=null!=e?e:Math.max(c.x,c.y,c.z);s.traverse(s=>{if("Mesh"===s.type){if(!this.childDirs.has(s.uuid)||!this.childPositions.has(s.uuid)){const e=o.utils.getBoundingBox(s).getCenter(new t),n=(new t).subVectors(e,r).normalize();if(s.parent){const t=s.parent.getWorldQuaternion(new i);t.invert(),n.applyQuaternion(t)}this.childDirs.set(s.uuid,n),this.childPositions.set(s.uuid,s.position.clone())}s.position.copy((new t).copy(this.childPositions.get(s.uuid)).add((new t).copy(this.childDirs.get(s.uuid)).multiplyScalar(u))),this.ssp.render()}})}stop(t){let i=t;if(!i){const t=[...this.prevObjects].at(-1);t&&(this.prevObjects.delete(t),i=t)}null==i||i.traverse(t=>{"Mesh"===t.type&&this.childDirs.has(t.uuid)&&this.childPositions.has(t.uuid)&&(t.position.copy(this.childPositions.get(t.uuid)),this.childDirs.delete(t.uuid),this.childPositions.delete(t.uuid))}),this.ssp.render()}startForObjects(t,i){var s;const{ssp:e,objectActionMap:n}=this;if(!n.has(t)){const i=o(t,e);n.set(t,i)}null===(s=n.get(t))||void 0===s||s.setTime(i)}stopForObjects(t){var i;const{objectActionMap:s}=this;t||(t=[...s.keys()].at(-1)),t&&(null===(i=s.get(t))||void 0===i||i.stop(),s.delete(t))}}function o(e,o){const n=o.utils.getBoundingBox,c={},r={};let u={};const d=new s;for(const t of e){const i=n(t);u[t.uuid]=i,d.union(i)}const l=d.getCenter(new t),h=d.getSize(new t),a=Math.max(h.x,h.y,h.z),p=new t;for(const s of e){const{uuid:e,position:o,parent:n}=s;r[e]=o.clone(),u[e].getCenter(p);const d=new t;if(d.subVectors(p,l),n){const t=n.getWorldQuaternion(new i);t.invert(),d.applyQuaternion(t)}d.normalize(),c[e]=d}return u=null,{setTime:function(t=a){for(const i of e){const{uuid:s,position:e}=i,o=c[s],n=r[s];e.copy(o).multiplyScalar(t).add(n)}o.render()},stop:function(){for(const t of e){const{uuid:i,position:s}=t,e=r[i];s.copy(e)}o.render()}}}export{o as blastObjects,e as default};
1
+ import { Vector3 as r, Quaternion as B, Box3 as m } from "three";
2
+ class P {
3
+ constructor(t) {
4
+ this.ssp = t;
5
+ }
6
+ prevObjects = /* @__PURE__ */ new Set();
7
+ childDirs = /* @__PURE__ */ new Map();
8
+ childPositions = /* @__PURE__ */ new Map();
9
+ start(t, n) {
10
+ this.prevObjects.add(t);
11
+ const { ssp: o } = this, s = o.utils.getBoundingBox(t), c = s.getSize(new r()), h = s.getCenter(new r()), b = n ?? Math.max(c.x, c.y, c.z);
12
+ t.traverse((e) => {
13
+ if (e.type === "Mesh") {
14
+ if (!this.childDirs.has(e.uuid) || !this.childPositions.has(e.uuid)) {
15
+ const g = o.utils.getBoundingBox(e).getCenter(new r()), f = new r().subVectors(g, h).normalize();
16
+ if (e.parent) {
17
+ const x = e.parent.getWorldQuaternion(new B());
18
+ x.invert(), f.applyQuaternion(x);
19
+ }
20
+ this.childDirs.set(
21
+ e.uuid,
22
+ f
23
+ ), this.childPositions.set(
24
+ e.uuid,
25
+ e.position.clone()
26
+ );
27
+ }
28
+ e.position.copy(
29
+ new r().copy(this.childPositions.get(e.uuid)).add(
30
+ new r().copy(this.childDirs.get(e.uuid)).multiplyScalar(b)
31
+ )
32
+ ), this.ssp.render();
33
+ }
34
+ });
35
+ }
36
+ stop(t) {
37
+ let n = t;
38
+ if (!n) {
39
+ const o = [...this.prevObjects].at(-1);
40
+ o && (this.prevObjects.delete(o), n = o);
41
+ }
42
+ n?.traverse((o) => {
43
+ o.type === "Mesh" && this.childDirs.has(o.uuid) && this.childPositions.has(o.uuid) && (o.position.copy(this.childPositions.get(o.uuid)), this.childDirs.delete(o.uuid), this.childPositions.delete(o.uuid));
44
+ }), this.ssp.render();
45
+ }
46
+ objectActionMap = /* @__PURE__ */ new Map();
47
+ startForObjects(t, n) {
48
+ const { ssp: o, objectActionMap: s } = this;
49
+ if (!s.has(t)) {
50
+ const c = M(t, o);
51
+ s.set(t, c);
52
+ }
53
+ s.get(t)?.setTime(n);
54
+ }
55
+ stopForObjects(t) {
56
+ const { objectActionMap: n } = this;
57
+ t || (t = [...n.keys()].at(-1)), t && (n.get(t)?.stop(), n.delete(t));
58
+ }
59
+ }
60
+ function M(l, t) {
61
+ const n = t.utils.getBoundingBox, o = {}, s = {};
62
+ let c = {};
63
+ const h = new m();
64
+ for (const u of l) {
65
+ const i = n(u);
66
+ c[u.uuid] = i, h.union(i);
67
+ }
68
+ const b = h.getCenter(new r()), e = h.getSize(new r()), y = Math.max(e.x, e.y, e.z), g = new r();
69
+ for (const u of l) {
70
+ const { uuid: i, position: a, parent: p } = u;
71
+ s[i] = a.clone(), c[i].getCenter(g);
72
+ const d = new r();
73
+ if (d.subVectors(g, b), p) {
74
+ const w = p.getWorldQuaternion(new B());
75
+ w.invert(), d.applyQuaternion(w);
76
+ }
77
+ d.normalize(), o[i] = d;
78
+ }
79
+ c = null;
80
+ function f(u = y) {
81
+ for (const i of l) {
82
+ const { uuid: a, position: p } = i, d = o[a], w = s[a];
83
+ p.copy(d).multiplyScalar(u).add(w);
84
+ }
85
+ t.render();
86
+ }
87
+ function x() {
88
+ for (const u of l) {
89
+ const { uuid: i, position: a } = u, p = s[i];
90
+ a.copy(p);
91
+ }
92
+ t.render();
93
+ }
94
+ return { setTime: f, stop: x };
95
+ }
96
+ export {
97
+ M as blastObjects,
98
+ P as default
99
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soonspacejs/plugin-model-blast",
3
3
  "pluginName": "ModelBlastPlugin",
4
- "version": "2.13.17",
4
+ "version": "2.14.1",
5
5
  "description": "Model blast 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": "8afa5fda9a0ef2c080060e7d8e71a8bf168fd4d2",
16
+ "gitHead": "27d5e0bcd79ff71c8e2943a8420c39624ae6f8e6",
17
17
  "peerDependencies": {
18
- "soonspacejs": "2.13.17"
18
+ "soonspacejs": "2.14.1"
19
19
  }
20
20
  }