@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 +2 -2
- package/dist/index.esm.js +99 -1
- package/package.json +3 -3
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(
|
|
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
|
|
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.
|
|
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": "
|
|
16
|
+
"gitHead": "27d5e0bcd79ff71c8e2943a8420c39624ae6f8e6",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"soonspacejs": "2.
|
|
18
|
+
"soonspacejs": "2.14.1"
|
|
19
19
|
}
|
|
20
20
|
}
|