@soonspacejs/plugin-drawing-shape 2.13.17 → 2.14.0
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 +3 -4
- package/dist/index.esm.js +258 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import SoonSpace from 'soonspacejs';
|
|
2
|
-
import
|
|
3
|
-
import type { Vector3, Object3D } from 'three';
|
|
1
|
+
import { default as SoonSpace, SetOptionsPointInfo, SetOptionsLineInfo, SetOptionsPolygonInfo, SetOptionsCircleInfo } from 'soonspacejs';
|
|
2
|
+
import { Vector3, Object3D } from 'three';
|
|
4
3
|
export type DrawingPointInfo = SetOptionsPointInfo;
|
|
5
4
|
export interface DrawingPointEvents {
|
|
6
5
|
onCancel?: () => void;
|
|
@@ -31,7 +30,7 @@ export default class DrawIngShapePlugin {
|
|
|
31
30
|
blankIntersect: boolean;
|
|
32
31
|
readonly viewport: SoonSpace['viewport'];
|
|
33
32
|
constructor(ssp: SoonSpace);
|
|
34
|
-
getFirstIntersect(event: MouseEvent, drawingObj?: (Object3D | null)[] | Object3D | null): import(
|
|
33
|
+
getFirstIntersect(event: MouseEvent, drawingObj?: (Object3D | null)[] | Object3D | null): import('three').Intersection<Object3D<import('three').Object3DEventMap>>;
|
|
35
34
|
/**
|
|
36
35
|
* 绘图时使用的临时 layer
|
|
37
36
|
*/
|
package/dist/index.esm.js
CHANGED
|
@@ -1 +1,258 @@
|
|
|
1
|
-
import
|
|
1
|
+
import C from "soonspacejs";
|
|
2
|
+
const { utils: m } = C, g = {
|
|
3
|
+
canvas: "drawingCanvas" + m.randomString(),
|
|
4
|
+
point: "drawingPoint" + m.randomString(),
|
|
5
|
+
line: "drawingLine" + m.randomString(),
|
|
6
|
+
polygon: "drawingPolygon" + m.randomString(),
|
|
7
|
+
circle: "drawingCircle" + m.randomString()
|
|
8
|
+
};
|
|
9
|
+
class P {
|
|
10
|
+
constructor(t) {
|
|
11
|
+
this.ssp = t, this.viewport = t.viewport;
|
|
12
|
+
}
|
|
13
|
+
// 是否允许点击空白处绘制
|
|
14
|
+
blankIntersect = !0;
|
|
15
|
+
viewport;
|
|
16
|
+
getFirstIntersect(t, a) {
|
|
17
|
+
const h = (Array.isArray(a) ? a : a ? [a] : []).filter((s) => s);
|
|
18
|
+
this.configLayer(h);
|
|
19
|
+
const r = this.ssp.viewport.getIntersects(t);
|
|
20
|
+
return this.recoverLayer(h), r[0];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 绘图时使用的临时 layer
|
|
24
|
+
*/
|
|
25
|
+
drawingLayer = 21;
|
|
26
|
+
configLayer(t) {
|
|
27
|
+
const a = this.drawingLayer ?? 21, l = this.ssp.viewport.camera;
|
|
28
|
+
l.oriMask = l.layers.mask, l.layers.enable(a);
|
|
29
|
+
const h = Array.isArray(t) ? t : [t];
|
|
30
|
+
for (const r of h)
|
|
31
|
+
r.oriMask = r.layers.mask, r.layers.set(a);
|
|
32
|
+
}
|
|
33
|
+
recoverLayer(t) {
|
|
34
|
+
const a = this.ssp.viewport.camera;
|
|
35
|
+
a.oriMask && (a.layers.mask = a.oriMask, a.oriMask = void 0);
|
|
36
|
+
const h = Array.isArray(t) ? t : [t];
|
|
37
|
+
for (const r of h) {
|
|
38
|
+
const s = r.oriMask;
|
|
39
|
+
s && (r.layers.mask = s, r.oriMask = void 0);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
drawingPoint(t, a) {
|
|
43
|
+
return new Promise((l, h) => {
|
|
44
|
+
this.clearDrawingCanvas3D();
|
|
45
|
+
const r = this.ssp.createCanvas3D({
|
|
46
|
+
id: g.canvas,
|
|
47
|
+
points: [
|
|
48
|
+
{
|
|
49
|
+
...t,
|
|
50
|
+
id: g.point
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
this.ssp.addObject(r);
|
|
55
|
+
const s = r.getPoint(g.point);
|
|
56
|
+
if (!s) return h();
|
|
57
|
+
const o = (p) => {
|
|
58
|
+
if (!s) return;
|
|
59
|
+
const d = this.getFirstIntersect(p, s), i = d ? d.point.clone() : this.blankIntersect && this.ssp.getPositionByOffset(p);
|
|
60
|
+
i && (s.position.copy(i), this.ssp.render());
|
|
61
|
+
}, c = (p) => {
|
|
62
|
+
if (y(), !s) return;
|
|
63
|
+
const d = this.getFirstIntersect(p, s), i = d ? d.point.clone() : this.blankIntersect && this.ssp.getPositionByOffset(p);
|
|
64
|
+
i && (s.position.copy(i), this.ssp.render(), l({
|
|
65
|
+
...t,
|
|
66
|
+
position: i.clone()
|
|
67
|
+
}));
|
|
68
|
+
}, k = () => {
|
|
69
|
+
this.clearDrawingCanvas3D(), y(), a?.onCancel?.();
|
|
70
|
+
}, v = (p) => {
|
|
71
|
+
switch (p.code) {
|
|
72
|
+
case "Escape":
|
|
73
|
+
k();
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}, y = () => {
|
|
77
|
+
this.ssp.signals.mouseMove.remove(o), this.ssp.signals.click.remove(c), this.ssp.signals.rightClick.remove(k), this.ssp.signals.keyUp.remove(v);
|
|
78
|
+
};
|
|
79
|
+
this.ssp.signals.mouseMove.add(o), this.ssp.signals.click.add(c), this.ssp.signals.rightClick.add(k), this.ssp.signals.keyUp.add(v);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
drawingLine(t, a) {
|
|
83
|
+
const { offsetY: l = 0.01 } = t;
|
|
84
|
+
return new Promise((h) => {
|
|
85
|
+
this.clearDrawingCanvas3D();
|
|
86
|
+
const r = this.ssp.createCanvas3D({
|
|
87
|
+
id: g.canvas,
|
|
88
|
+
lines: [
|
|
89
|
+
{
|
|
90
|
+
...t,
|
|
91
|
+
points: [],
|
|
92
|
+
id: g.line
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
});
|
|
96
|
+
this.ssp.addObject(r);
|
|
97
|
+
const s = r.getLine(g.line), o = [], c = (i) => {
|
|
98
|
+
const n = this.getFirstIntersect(i, s), e = n ? n.point.clone() : this.blankIntersect && this.ssp.getPositionByOffset(i);
|
|
99
|
+
e && s && (s.setOptions({
|
|
100
|
+
...t,
|
|
101
|
+
points: [...o, e.clone().setY(e.y + l)]
|
|
102
|
+
}), this.ssp.render());
|
|
103
|
+
}, k = (i) => {
|
|
104
|
+
const n = this.getFirstIntersect(i, s), e = n ? n.point.clone() : this.blankIntersect && this.ssp.getPositionByOffset(i);
|
|
105
|
+
e && (o.push(e.clone().setY(e.y + l)), s && s.setOptions({
|
|
106
|
+
...t,
|
|
107
|
+
points: o
|
|
108
|
+
}));
|
|
109
|
+
}, v = () => {
|
|
110
|
+
o.pop(), s && (s.setOptions({
|
|
111
|
+
...t,
|
|
112
|
+
points: o
|
|
113
|
+
}), a?.onCancelPrev?.());
|
|
114
|
+
}, y = (i) => {
|
|
115
|
+
const n = this.getFirstIntersect(i, s), e = n ? n.point.clone() : this.blankIntersect && this.ssp.getPositionByOffset(i);
|
|
116
|
+
e && (o.push(e.clone().setY(e.y + l)), d(), h({
|
|
117
|
+
...t,
|
|
118
|
+
points: o
|
|
119
|
+
}));
|
|
120
|
+
}, p = (i) => {
|
|
121
|
+
switch (i.code) {
|
|
122
|
+
case "Backspace":
|
|
123
|
+
v();
|
|
124
|
+
break;
|
|
125
|
+
case "Escape":
|
|
126
|
+
this.clearDrawingCanvas3D(), d(), a?.onCancel?.();
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}, d = () => {
|
|
130
|
+
this.ssp.signals.mouseMove.remove(c), this.ssp.signals.click.remove(k), this.ssp.signals.rightClick.remove(v), this.ssp.signals.dblClick.remove(y), this.ssp.signals.keyUp.remove(p);
|
|
131
|
+
};
|
|
132
|
+
this.ssp.signals.mouseMove.add(c), this.ssp.signals.click.add(k), this.ssp.signals.rightClick.add(v), this.ssp.signals.dblClick.add(y), this.ssp.signals.keyUp.add(p);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
drawingPolygon(t, a) {
|
|
136
|
+
const { offsetY: l = 0.01 } = t;
|
|
137
|
+
return new Promise((h) => {
|
|
138
|
+
this.clearDrawingCanvas3D();
|
|
139
|
+
const r = this.ssp.createCanvas3D({
|
|
140
|
+
id: g.canvas,
|
|
141
|
+
polygons: [
|
|
142
|
+
{
|
|
143
|
+
points: [],
|
|
144
|
+
yHeight: 0,
|
|
145
|
+
...t,
|
|
146
|
+
id: g.polygon
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
lines: [
|
|
150
|
+
{
|
|
151
|
+
points: [],
|
|
152
|
+
width: 2,
|
|
153
|
+
...t,
|
|
154
|
+
id: g.line
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
});
|
|
158
|
+
this.ssp.addObject(r);
|
|
159
|
+
const s = r.getPolygon(g.polygon), o = r.getLine(g.line), c = [], k = (n) => {
|
|
160
|
+
const e = this.getFirstIntersect(n, [o, s]), f = e ? e.point.clone() : this.blankIntersect && this.ssp.getPositionByOffset(n);
|
|
161
|
+
if (!f || !s) return;
|
|
162
|
+
const u = [...c, f];
|
|
163
|
+
u.length > 2 ? r.removeLine(g.line) : o?.setOptions({
|
|
164
|
+
points: u
|
|
165
|
+
}), s.setOptions({
|
|
166
|
+
yHeight: (c[0]?.y || f.y) + l,
|
|
167
|
+
points: u
|
|
168
|
+
});
|
|
169
|
+
}, v = (n) => {
|
|
170
|
+
const e = this.getFirstIntersect(n, [o, s]), f = e ? e.point.clone() : this.blankIntersect && this.ssp.getPositionByOffset(n);
|
|
171
|
+
f && (c.push(f.clone().setY(f.y + l)), s && s.setOptions({
|
|
172
|
+
...t,
|
|
173
|
+
yHeight: (c[0]?.y || 0) + l,
|
|
174
|
+
points: c
|
|
175
|
+
}));
|
|
176
|
+
}, y = () => {
|
|
177
|
+
c.pop(), s && (s.setOptions({
|
|
178
|
+
...t,
|
|
179
|
+
yHeight: (c[0]?.y || 0) + l,
|
|
180
|
+
points: c
|
|
181
|
+
}), a?.onCancelPrev?.());
|
|
182
|
+
}, p = (n) => {
|
|
183
|
+
const e = this.getFirstIntersect(n, [o, s]), f = e ? e.point.clone() : this.blankIntersect && this.ssp.getPositionByOffset(n);
|
|
184
|
+
f && (c.push(f.clone().setY(f.y + l)), i(), h({
|
|
185
|
+
...t,
|
|
186
|
+
yHeight: (c[0]?.y || 0) + l,
|
|
187
|
+
points: c
|
|
188
|
+
}));
|
|
189
|
+
}, d = (n) => {
|
|
190
|
+
switch (n.code) {
|
|
191
|
+
case "Backspace":
|
|
192
|
+
y();
|
|
193
|
+
break;
|
|
194
|
+
case "Escape":
|
|
195
|
+
this.clearDrawingCanvas3D(), i(), a?.onCancel?.();
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}, i = () => {
|
|
199
|
+
this.ssp.signals.mouseMove.remove(k), this.ssp.signals.click.remove(v), this.ssp.signals.rightClick.remove(y), this.ssp.signals.dblClick.remove(p), this.ssp.signals.keyUp.remove(d);
|
|
200
|
+
};
|
|
201
|
+
this.ssp.signals.mouseMove.add(k), this.ssp.signals.click.add(v), this.ssp.signals.rightClick.add(y), this.ssp.signals.dblClick.add(p), this.ssp.signals.keyUp.add(d);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
drawingCircle(t, a) {
|
|
205
|
+
const { offsetY: l = 0.01 } = t;
|
|
206
|
+
return new Promise((h) => {
|
|
207
|
+
this.clearDrawingCanvas3D();
|
|
208
|
+
const r = this.ssp.createCanvas3D({
|
|
209
|
+
id: g.canvas,
|
|
210
|
+
circles: [
|
|
211
|
+
{
|
|
212
|
+
...t,
|
|
213
|
+
id: g.circle
|
|
214
|
+
}
|
|
215
|
+
]
|
|
216
|
+
});
|
|
217
|
+
this.ssp.addObject(r);
|
|
218
|
+
const s = r.getCircle(g.circle);
|
|
219
|
+
let o, c = 100;
|
|
220
|
+
const k = (i) => {
|
|
221
|
+
if (!s || !o) return;
|
|
222
|
+
const n = this.getFirstIntersect(i, s), e = n ? n.point.clone() : this.blankIntersect && this.ssp.getPositionByOffset(i);
|
|
223
|
+
e && (c = e.distanceTo(o), s.setOptions({
|
|
224
|
+
radius: c
|
|
225
|
+
}), s.position.copy(o));
|
|
226
|
+
}, v = (i) => {
|
|
227
|
+
if (!s) return;
|
|
228
|
+
const n = this.getFirstIntersect(i, s), e = n ? n.point.clone() : this.blankIntersect && this.ssp.getPositionByOffset(i);
|
|
229
|
+
e && (o ? (d(), c = e.distanceTo(
|
|
230
|
+
this.ssp.utils.IVector3ToVector3(o)
|
|
231
|
+
), s.setOptions({
|
|
232
|
+
radius: c
|
|
233
|
+
}), s.position.copy(o), h({
|
|
234
|
+
...t,
|
|
235
|
+
position: o,
|
|
236
|
+
radius: c
|
|
237
|
+
})) : o = e.clone().setY(e.y + l));
|
|
238
|
+
}, y = () => {
|
|
239
|
+
this.clearDrawingCanvas3D(), d(), a?.onCancel?.();
|
|
240
|
+
}, p = (i) => {
|
|
241
|
+
switch (i.code) {
|
|
242
|
+
case "Escape":
|
|
243
|
+
y();
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}, d = () => {
|
|
247
|
+
this.ssp.signals.mouseMove.remove(k), this.ssp.signals.click.remove(v), this.ssp.signals.rightClick.remove(y), this.ssp.signals.keyUp.remove(p);
|
|
248
|
+
};
|
|
249
|
+
this.ssp.signals.mouseMove.add(k), this.ssp.signals.click.add(v), this.ssp.signals.rightClick.add(y), this.ssp.signals.keyUp.add(p);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
clearDrawingCanvas3D() {
|
|
253
|
+
this.ssp.removeObjectById(g.canvas);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
export {
|
|
257
|
+
P as default
|
|
258
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-drawing-shape",
|
|
3
3
|
"pluginName": "DrawingShapePlugin",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.14.0",
|
|
5
5
|
"description": "DrawingShapePlugin 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": "4c85e8b7b8ad24ccb9b42f3a1826bca377c42a6d",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"soonspacejs": "2.
|
|
18
|
+
"soonspacejs": "2.14.0"
|
|
19
19
|
}
|
|
20
20
|
}
|