@soonspacejs/plugin-clipping-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/index.d.ts +1 -2
- package/dist/index.esm.js +186 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import SoonSpace,
|
|
2
|
-
import type { BaseObject3D, BaseMesh } from 'soonspacejs';
|
|
1
|
+
import { default as SoonSpace, IColor, AxisType, Position, Rotation, BaseObject3D, BaseMesh } from 'soonspacejs';
|
|
3
2
|
export type ClipPlaneName = AxisType | `-${AxisType}`;
|
|
4
3
|
export interface SceneClippingOptions {
|
|
5
4
|
axis: AxisType;
|
package/dist/index.esm.js
CHANGED
|
@@ -1 +1,186 @@
|
|
|
1
|
-
import
|
|
1
|
+
import F from "soonspacejs";
|
|
2
|
+
import { Vector3 as a, Plane as b, Box3 as v } from "three";
|
|
3
|
+
class N {
|
|
4
|
+
constructor(r) {
|
|
5
|
+
this.ssp = r, this.scenePlaneHelpers = {
|
|
6
|
+
x: null,
|
|
7
|
+
y: null,
|
|
8
|
+
z: null,
|
|
9
|
+
"-x": null,
|
|
10
|
+
"-y": null,
|
|
11
|
+
"-z": null
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
scenePlaneHelpers;
|
|
15
|
+
addPlaneHelper(r, l, n) {
|
|
16
|
+
const t = this.ssp.addPlaneHelper({
|
|
17
|
+
...l,
|
|
18
|
+
opacity: 0.3
|
|
19
|
+
});
|
|
20
|
+
this.scenePlaneHelpers[r] = t, n && this.ssp.addObject(t, n);
|
|
21
|
+
}
|
|
22
|
+
sceneClipping(r) {
|
|
23
|
+
const {
|
|
24
|
+
axis: l,
|
|
25
|
+
clipPoint: n,
|
|
26
|
+
isForward: t = !0,
|
|
27
|
+
openHelper: c = !0
|
|
28
|
+
} = r, e = t ? l : `-${l}`, s = t ? n - 1 : -n + 1, i = `scene_clippingPlaneHelper_${e}`;
|
|
29
|
+
if (c)
|
|
30
|
+
if (this.scenePlaneHelpers[e])
|
|
31
|
+
switch (e) {
|
|
32
|
+
case "x":
|
|
33
|
+
case "-x":
|
|
34
|
+
this.scenePlaneHelpers[e]?.position.setX(s);
|
|
35
|
+
break;
|
|
36
|
+
case "y":
|
|
37
|
+
case "-y":
|
|
38
|
+
this.scenePlaneHelpers[e]?.position.setY(s);
|
|
39
|
+
break;
|
|
40
|
+
case "z":
|
|
41
|
+
case "-z":
|
|
42
|
+
this.scenePlaneHelpers[e]?.position.setZ(s);
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const P = F.utils.getBoundingBox(this.ssp.viewport.scene), d = P.getSize(new a()), z = P.getCenter(new a());
|
|
47
|
+
let u = 0, p = 0, g = "green";
|
|
48
|
+
const x = z.clone(), o = { x: 0, y: 0, z: 0 };
|
|
49
|
+
switch (l) {
|
|
50
|
+
case "x":
|
|
51
|
+
u = d.z, p = d.y, g = "green", x.x = s, o.y = Math.PI / 2;
|
|
52
|
+
break;
|
|
53
|
+
case "y":
|
|
54
|
+
u = d.x, p = d.z, g = "blue", x.y = s, o.x = Math.PI / 2;
|
|
55
|
+
break;
|
|
56
|
+
case "z":
|
|
57
|
+
u = d.x, p = d.y, x.z = s, g = "red";
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
this.addPlaneHelper(e, {
|
|
61
|
+
id: i,
|
|
62
|
+
width: u,
|
|
63
|
+
height: p,
|
|
64
|
+
color: g,
|
|
65
|
+
position: x,
|
|
66
|
+
rotation: o
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else this.scenePlaneHelpers[e] && (this.ssp.removeHelperById(i), this.scenePlaneHelpers[e] = null);
|
|
70
|
+
const w = {
|
|
71
|
+
x: new a(-1, 0, 0),
|
|
72
|
+
"-x": new a(1, 0, 0),
|
|
73
|
+
y: new a(0, -1, 0),
|
|
74
|
+
"-y": new a(0, 1, 0),
|
|
75
|
+
z: new a(0, 0, -1),
|
|
76
|
+
"-z": new a(0, 0, 1)
|
|
77
|
+
}, y = w[e][l], h = this.ssp.viewport.renderer.clippingPlanes.find((P) => P.normal[l] === y);
|
|
78
|
+
h ? h.constant = n : this.ssp.viewport.renderer.clippingPlanes.push(new b(w[e], n)), this.ssp.signals.sceneChanged.dispatch();
|
|
79
|
+
}
|
|
80
|
+
removeSceneClipping(r, l = !0) {
|
|
81
|
+
const n = r ? [{ axis: r, isForward: l }] : [{ axis: "x", isForward: !0 }, { axis: "x", isForward: !1 }, { axis: "y", isForward: !0 }, { axis: "y", isForward: !1 }, { axis: "z", isForward: !0 }, { axis: "z", isForward: !1 }];
|
|
82
|
+
for (const { axis: t, isForward: c } of n) {
|
|
83
|
+
const e = c ? -1 : 1, s = c ? t : `-${t}`, i = this.ssp.viewport.renderer.clippingPlanes, w = i.findIndex((h) => h.normal[t] === e);
|
|
84
|
+
i.splice(w, 1);
|
|
85
|
+
const y = `scene_clippingPlaneHelper_${s}`;
|
|
86
|
+
this.ssp.removeHelperById(y), this.scenePlaneHelpers[s] = null;
|
|
87
|
+
}
|
|
88
|
+
this.ssp.signals.sceneChanged.dispatch();
|
|
89
|
+
}
|
|
90
|
+
modelClipping(r, l) {
|
|
91
|
+
const {
|
|
92
|
+
axis: n,
|
|
93
|
+
clipPercent: t,
|
|
94
|
+
isForward: c = !0,
|
|
95
|
+
openHelper: e = !0
|
|
96
|
+
} = l, s = c ? n : `-${n}`, i = new v().setFromObject(r);
|
|
97
|
+
i.max.add(new a(2, 2, 2)), i.min.sub(new a(2, 2, 2));
|
|
98
|
+
const w = i.getSize(new a()), y = c ? i.max[n] - t / 100 * w[n] + 1 : i.min[n] + t / 100 * w[n] - 1, h = c ? y + 1 : y - 1, P = `model_${r.sid}_clippingPlaneHelper_${s}`, d = this.ssp.getObjectById(P);
|
|
99
|
+
if (e)
|
|
100
|
+
if (d)
|
|
101
|
+
switch (n) {
|
|
102
|
+
case "x":
|
|
103
|
+
d?.position.setX(h);
|
|
104
|
+
break;
|
|
105
|
+
case "y":
|
|
106
|
+
d?.position.setY(h);
|
|
107
|
+
break;
|
|
108
|
+
case "z":
|
|
109
|
+
d?.position.setZ(h);
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const p = i.getSize(new a()), g = i.getCenter(new a());
|
|
114
|
+
let x = 0, o = 0, f = "green";
|
|
115
|
+
const m = g.clone(), H = { x: 0, y: 0, z: 0 };
|
|
116
|
+
switch (n) {
|
|
117
|
+
case "x":
|
|
118
|
+
x = p.z, o = p.y, f = "green", m.x = h, H.y = Math.PI / 2;
|
|
119
|
+
break;
|
|
120
|
+
case "y":
|
|
121
|
+
x = p.x, o = p.z, f = "blue", m.y = h, H.x = Math.PI / 2;
|
|
122
|
+
break;
|
|
123
|
+
case "z":
|
|
124
|
+
x = p.x, o = p.y, m.z = h, f = "red";
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
this.addPlaneHelper(s, {
|
|
128
|
+
id: P,
|
|
129
|
+
width: x,
|
|
130
|
+
height: o,
|
|
131
|
+
color: f,
|
|
132
|
+
position: m,
|
|
133
|
+
rotation: H
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
else d && this.ssp.removeObjectById(P);
|
|
137
|
+
const z = {
|
|
138
|
+
x: new a(-1, 0, 0),
|
|
139
|
+
y: new a(0, -1, 0),
|
|
140
|
+
z: new a(0, 0, -1),
|
|
141
|
+
"-x": new a(1, 0, 0),
|
|
142
|
+
"-y": new a(0, 1, 0),
|
|
143
|
+
"-z": new a(0, 0, 1)
|
|
144
|
+
}, u = z[s][n];
|
|
145
|
+
r.traverse((p) => {
|
|
146
|
+
if (p.material) {
|
|
147
|
+
const g = p, x = (o) => {
|
|
148
|
+
o.clippingPlanes || (o.clippingPlanes = []);
|
|
149
|
+
const f = o.clippingPlanes.find((m) => m.normal[n] === u);
|
|
150
|
+
if (f)
|
|
151
|
+
f.normal = z[s], f.constant = y, c || f.negate();
|
|
152
|
+
else {
|
|
153
|
+
const m = new b(z[s], y);
|
|
154
|
+
c || m.negate(), o.clippingPlanes.push(m);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
Array.isArray(g.material) ? g.material.forEach((o) => x(o)) : x(g.material);
|
|
158
|
+
}
|
|
159
|
+
}), this.ssp.signals.sceneChanged.dispatch();
|
|
160
|
+
}
|
|
161
|
+
removeModelClipping(r, l, n = !0) {
|
|
162
|
+
const t = (e) => {
|
|
163
|
+
if (!l)
|
|
164
|
+
e.clippingPlanes = [];
|
|
165
|
+
else if (e.clippingPlanes) {
|
|
166
|
+
const s = e.clippingPlanes.findIndex((i) => Math.abs(i.normal[l]) === 1);
|
|
167
|
+
e.clippingPlanes.splice(s, 1);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
r.traverse((e) => {
|
|
171
|
+
if (e.material) {
|
|
172
|
+
const s = e;
|
|
173
|
+
Array.isArray(s.material) ? s.material.forEach((i) => t(i)) : t(s.material);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
const c = l ? [{ axis: l, isForward: n }] : [{ axis: "x", isForward: !0 }, { axis: "x", isForward: !1 }, { axis: "y", isForward: !0 }, { axis: "y", isForward: !1 }, { axis: "z", isForward: !0 }, { axis: "z", isForward: !1 }];
|
|
177
|
+
for (const { axis: e, isForward: s } of c) {
|
|
178
|
+
const i = s ? e : `-${e}`, w = `model_${r.sid}_clippingPlaneHelper_${i}`;
|
|
179
|
+
this.ssp.removeHelperById(w);
|
|
180
|
+
}
|
|
181
|
+
this.ssp.signals.sceneChanged.dispatch();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
export {
|
|
185
|
+
N as default
|
|
186
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-clipping-controls",
|
|
3
3
|
"pluginName": "ClippingControlsPlugin",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.14.1",
|
|
5
5
|
"description": "Clipping controls 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
|
}
|