@soonspacejs/plugin-follow-mouse 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 +1 -2
- package/dist/index.esm.js +131 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Vector3 } from 'three';
|
|
2
|
-
import SoonSpace,
|
|
3
|
-
import type { BaseObject3D } from 'soonspacejs';
|
|
2
|
+
import { default as SoonSpace, IColor, BaseObject3D } from 'soonspacejs';
|
|
4
3
|
export interface StartOptions {
|
|
5
4
|
offset?: Vector3;
|
|
6
5
|
openHelper?: boolean;
|
package/dist/index.esm.js
CHANGED
|
@@ -1 +1,131 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { Box3 as r, Vector3 as e } from "three";
|
|
2
|
+
const d = "followMouseBoxHelper";
|
|
3
|
+
class f {
|
|
4
|
+
constructor(s) {
|
|
5
|
+
this.ssp = s, this.object = null, this.objectBbox = new r(new e(), new e()), this.objectSourcePosition = new e(), this.sceneMesh = [], this.helper = null, this.placedObject = [], this.options = {}, this.onMouseMove = this.onMouseMove.bind(this), this.onMouseDown = this.onMouseDown.bind(this), this.onClick = this.onClick.bind(this), this.onRightClick = this.onRightClick.bind(this), this.onDblClick = this.onDblClick.bind(this), this.onKeyUp = this.onKeyUp.bind(this);
|
|
6
|
+
}
|
|
7
|
+
object;
|
|
8
|
+
objectBbox;
|
|
9
|
+
objectSourcePosition;
|
|
10
|
+
sceneMesh;
|
|
11
|
+
helper;
|
|
12
|
+
placedObject;
|
|
13
|
+
options;
|
|
14
|
+
mouseDownModelPosition = new e();
|
|
15
|
+
start(s, c = {}) {
|
|
16
|
+
this.options = c, this.object = s, this.objectBbox.setFromObject(s), this.objectSourcePosition.copy(s.position.clone()), this.sceneMesh = this.ssp.viewport.scener.intersectsList.getAll().filter((h) => {
|
|
17
|
+
let n = h.visible;
|
|
18
|
+
return h.traverseAncestors((i) => {
|
|
19
|
+
i.visible === !1 && (n = !1);
|
|
20
|
+
}), n;
|
|
21
|
+
});
|
|
22
|
+
const {
|
|
23
|
+
openHelper: p = !0,
|
|
24
|
+
helperColor: a = 16776960
|
|
25
|
+
} = this.options;
|
|
26
|
+
p && this.object.stype === "Model" && (s.updateWorldMatrix(!0, !0), this.helper = this.ssp.addBoxHelper({
|
|
27
|
+
id: d,
|
|
28
|
+
box: this.objectBbox,
|
|
29
|
+
color: a
|
|
30
|
+
}), this.ssp.signals.sceneChanged.dispatch()), s.traverse((h) => {
|
|
31
|
+
const n = this.sceneMesh.findIndex((i) => i.uuid === h.uuid);
|
|
32
|
+
n !== -1 && this.sceneMesh.splice(n, 1);
|
|
33
|
+
}), this.ssp.signals.mouseMove.add(this.onMouseMove), this.ssp.signals.mouseDown.add(this.onMouseDown), this.ssp.signals.click.add(this.onClick), this.ssp.signals.rightClick.add(this.onRightClick), this.ssp.signals.dblClick.add(this.onDblClick), this.ssp.signals.keyUp.add(this.onKeyUp);
|
|
34
|
+
}
|
|
35
|
+
stop() {
|
|
36
|
+
this.object?.position.copy(this.objectSourcePosition.clone()), this.ssp.removeObjectById(d), this.object = null, this.objectBbox = new r(new e(), new e()), this.objectSourcePosition = new e(), this.sceneMesh = [], this.helper = null, this.placedObject = [], this.options = {}, this.mouseDownModelPosition = new e(), this.ssp.signals.mouseMove.remove(this.onMouseMove), this.ssp.signals.mouseDown.remove(this.onMouseDown), this.ssp.signals.click.remove(this.onClick), this.ssp.signals.dblClick.remove(this.onDblClick), this.ssp.signals.keyUp.remove(this.onKeyUp);
|
|
37
|
+
}
|
|
38
|
+
onMouseMove(s) {
|
|
39
|
+
if (s.preventDefault(), !this.object) return;
|
|
40
|
+
const {
|
|
41
|
+
offset: c = new e(1, 1, 1)
|
|
42
|
+
} = this.options, p = this.ssp.viewport.getIntersects(s, this.sceneMesh), h = this.object.getWorldPosition(new e()).sub(this.object.position), n = new e();
|
|
43
|
+
let i = "y";
|
|
44
|
+
if (p.length > 0) {
|
|
45
|
+
const { point: u, face: b } = p[0];
|
|
46
|
+
if (n.copy(u.clone()), b) {
|
|
47
|
+
const { normal: o } = b;
|
|
48
|
+
o.y === 0 && o.z === 0 && (o.x === 1 ? i = "x" : o.x === -1 && (i = "-x")), o.x === 0 && o.z === 0 && (o.y === 1 ? i = "y" : o.y === -1 && (i = "-y")), o.x === 0 && o.y === 0 && (o.z === 1 ? i = "z" : o.z === -1 && (i = "-z"));
|
|
49
|
+
}
|
|
50
|
+
} else
|
|
51
|
+
n.copy(this.ssp.getPositionByOffset(s, 0.1));
|
|
52
|
+
const t = n.sub(h), l = this.objectBbox.getSize(new e());
|
|
53
|
+
switch (i) {
|
|
54
|
+
case "x":
|
|
55
|
+
t.setX(t.x + l.x / 2 + c.x);
|
|
56
|
+
break;
|
|
57
|
+
case "-x":
|
|
58
|
+
t.setX(t.x - l.x / 2 - c.x);
|
|
59
|
+
break;
|
|
60
|
+
case "y":
|
|
61
|
+
t.setY(t.y + c.y);
|
|
62
|
+
break;
|
|
63
|
+
case "-y":
|
|
64
|
+
t.setY(t.y - l.y - c.y);
|
|
65
|
+
break;
|
|
66
|
+
case "z":
|
|
67
|
+
t.setZ(t.z + l.z / 2 + c.z);
|
|
68
|
+
break;
|
|
69
|
+
case "-z":
|
|
70
|
+
t.setZ(t.z - l.z / 2 - c.z);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
this.object.position.copy(t).setY(t.y), this.helper && this.helper.box.copy(new r(new e(), new e()).setFromObject(this.object)), this.ssp.signals.sceneChanged.dispatch();
|
|
74
|
+
}
|
|
75
|
+
onMouseDown(s) {
|
|
76
|
+
this.object && this.mouseDownModelPosition.copy(this.object.getWorldPosition(new e()));
|
|
77
|
+
}
|
|
78
|
+
onClick(s) {
|
|
79
|
+
this.onPlace();
|
|
80
|
+
}
|
|
81
|
+
onRightClick(s) {
|
|
82
|
+
this.onDelPrev();
|
|
83
|
+
}
|
|
84
|
+
async onDblClick(s) {
|
|
85
|
+
await this.onPlace(), this.options.onDone && this.options.onDone(this.placedObject), this.stop();
|
|
86
|
+
}
|
|
87
|
+
onKeyUp(s) {
|
|
88
|
+
switch (s.code) {
|
|
89
|
+
case "Backspace":
|
|
90
|
+
this.onDelPrev();
|
|
91
|
+
break;
|
|
92
|
+
case "Enter":
|
|
93
|
+
this.options.onDone && this.options.onDone(this.placedObject), this.stop();
|
|
94
|
+
break;
|
|
95
|
+
case "Escape":
|
|
96
|
+
this.options.onCancel && this.options.onCancel(), this.stop();
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async onPlace() {
|
|
101
|
+
if (this.object?.stype === "Model")
|
|
102
|
+
return this.ssp.cloneModel(
|
|
103
|
+
this.object,
|
|
104
|
+
{
|
|
105
|
+
id: `clone_${this.object.sid}_${this.placedObject.length + 1}`,
|
|
106
|
+
position: this.mouseDownModelPosition.clone()
|
|
107
|
+
}
|
|
108
|
+
).then((s) => {
|
|
109
|
+
this.placedObject.push(s), this.options.onPlace?.(s);
|
|
110
|
+
});
|
|
111
|
+
if (this.object?.stype === "Poi") {
|
|
112
|
+
const s = this.ssp.clonePoi(this.object, {
|
|
113
|
+
id: `clone_${this.object.sid}_${this.placedObject.length + 1}`,
|
|
114
|
+
position: this.mouseDownModelPosition.clone()
|
|
115
|
+
});
|
|
116
|
+
if (s)
|
|
117
|
+
this.placedObject.push(s), this.options.onPlace?.(s);
|
|
118
|
+
else
|
|
119
|
+
return Promise.reject("In soonspacejs: 插件(plugin-follow-mouse)摆放 Poi 对象时错误!");
|
|
120
|
+
} else
|
|
121
|
+
return Promise.reject("In soonspacejs: 插件(plugin-follow-mouse)传入对象类型错误,仅支持 sbm、model、poi !");
|
|
122
|
+
}
|
|
123
|
+
onDelPrev() {
|
|
124
|
+
if (this.placedObject.length === 0) return;
|
|
125
|
+
const s = this.placedObject[this.placedObject.length - 1];
|
|
126
|
+
this.ssp.removeObject(s), this.placedObject.splice(this.placedObject.length - 1, 1), this.options.onBack && this.options.onBack(s);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export {
|
|
130
|
+
f as default
|
|
131
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-follow-mouse",
|
|
3
3
|
"pluginName": "FollowMousePlugin",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.14.0",
|
|
5
5
|
"description": "Scene object follow mouse 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
|
}
|