@soonspacejs/plugin-soonmanager2-sync 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 -5
- package/dist/index.esm.js +258 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* @deprecated 使用 plugin-cps-soonmanager 替代
|
|
3
|
-
*/
|
|
4
|
-
import SoonSpace from 'soonspacejs';
|
|
5
|
-
import type { TopologyInfo } from 'soonspacejs';
|
|
1
|
+
import { default as SoonSpace, TopologyInfo } from 'soonspacejs';
|
|
6
2
|
import { IMetadata, ITreeData, ITopologyPath, ILoadSceneOptions, TPropertiesMap, TAnimationsMap, IPlayAnimationByIdOptions, TModelVisionsMap } from './types';
|
|
7
3
|
declare class Soonmanager2SyncPlugin {
|
|
8
4
|
readonly ssp: SoonSpace;
|
package/dist/index.esm.js
CHANGED
|
@@ -1 +1,258 @@
|
|
|
1
|
-
const
|
|
1
|
+
const I = "/SceneMetadata.json", Y = "/db/sign", w = "/db/tree_models.json", x = "/db/topology_paths.json", j = "/db/properties.json", O = "/db/animations.json", b = "/db/model_visions.json", S = "properties";
|
|
2
|
+
class X {
|
|
3
|
+
constructor(t) {
|
|
4
|
+
this.ssp = t;
|
|
5
|
+
}
|
|
6
|
+
_path = "";
|
|
7
|
+
get path() {
|
|
8
|
+
return this._path;
|
|
9
|
+
}
|
|
10
|
+
set path(t) {
|
|
11
|
+
this._path = t;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 场景元数据
|
|
15
|
+
*/
|
|
16
|
+
metaData = null;
|
|
17
|
+
/**
|
|
18
|
+
* 模型树
|
|
19
|
+
*/
|
|
20
|
+
treeData = null;
|
|
21
|
+
/**
|
|
22
|
+
* 拓扑路径
|
|
23
|
+
*/
|
|
24
|
+
topologyData = null;
|
|
25
|
+
/**
|
|
26
|
+
* 自定义属性
|
|
27
|
+
*/
|
|
28
|
+
propertiesData = null;
|
|
29
|
+
/**
|
|
30
|
+
* 动画
|
|
31
|
+
*/
|
|
32
|
+
animationsData = null;
|
|
33
|
+
/**
|
|
34
|
+
* 模型视角
|
|
35
|
+
*/
|
|
36
|
+
modelVisionsData = null;
|
|
37
|
+
_resolvePath(t) {
|
|
38
|
+
return `${this._path}${t}`;
|
|
39
|
+
}
|
|
40
|
+
async _fetchData(t) {
|
|
41
|
+
const { utils: i } = this.ssp;
|
|
42
|
+
return i.fetchFile(this._resolvePath(t), "json");
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 获取场景元数据
|
|
46
|
+
*/
|
|
47
|
+
async fetchMetaData() {
|
|
48
|
+
return this._fetchData(I);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 获取场景树
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
async fetchTreeData() {
|
|
55
|
+
return this._fetchData(w);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 获取拓扑路径
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
async fetchTopologyData() {
|
|
62
|
+
return this._fetchData(x).then((t) => {
|
|
63
|
+
const i = {
|
|
64
|
+
linkWidth: 0.1,
|
|
65
|
+
linkColor: ["#00ff00"],
|
|
66
|
+
nodeRadius: 0.05,
|
|
67
|
+
nodeColor: "#0000ff"
|
|
68
|
+
};
|
|
69
|
+
return t.map((n) => {
|
|
70
|
+
const e = { ...i, ...n };
|
|
71
|
+
return e.imgUrl && (e.imgUrl = `${this.path}${e.imgUrl}`), e;
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 获取自定义属性
|
|
77
|
+
* @returns
|
|
78
|
+
*/
|
|
79
|
+
async fetchPropertiesData() {
|
|
80
|
+
return this._fetchData(j).then((t) => A(t, "modelId"));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 获取动画
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
async fetchAnimationsData() {
|
|
87
|
+
return this._fetchData(O).then((t) => A(t, "modelId"));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 获取模型视角
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
async fetchModelVisionsData() {
|
|
94
|
+
return this._fetchData(b).then((t) => new Map(Object.entries(t)));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 加载场景树中的对象
|
|
98
|
+
*/
|
|
99
|
+
async loadObjects(t) {
|
|
100
|
+
if (!this.treeData) {
|
|
101
|
+
console.error("treeData is null");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const { syncProperties: i } = t, n = async (e, h) => {
|
|
105
|
+
const { ssp: r } = this, { THREE: { Matrix4: f } } = r, { id: d, name: l, renderType: y, path: c, matrix: p } = e, D = new f().fromArray(p);
|
|
106
|
+
let o = null;
|
|
107
|
+
if (y === "3D")
|
|
108
|
+
if (c)
|
|
109
|
+
try {
|
|
110
|
+
const s = { ...e };
|
|
111
|
+
Reflect.deleteProperty(s, "children");
|
|
112
|
+
const m = c.replaceAll(/#/g, "%23");
|
|
113
|
+
o = await r.loadModel({
|
|
114
|
+
id: d,
|
|
115
|
+
name: l,
|
|
116
|
+
url: this._resolvePath(m),
|
|
117
|
+
userData: s
|
|
118
|
+
});
|
|
119
|
+
} catch (s) {
|
|
120
|
+
console.error(s);
|
|
121
|
+
}
|
|
122
|
+
else
|
|
123
|
+
r.utils.warn(`id: ${d} path 为空`);
|
|
124
|
+
else (y === "GROUP" || y === "STUB") && (o = r.createGroup({
|
|
125
|
+
id: d,
|
|
126
|
+
name: l,
|
|
127
|
+
userData: { ...e }
|
|
128
|
+
}));
|
|
129
|
+
if (o && (D.decompose(o.position, o.quaternion, o.scale), h && r.addObject(o, h), i && this.propertiesData)) {
|
|
130
|
+
const s = this.propertiesData.get(d);
|
|
131
|
+
s && (o.userData[S] = s);
|
|
132
|
+
}
|
|
133
|
+
e.children.length > 0 && await Promise.allSettled(e.children.map((s) => n(s, o)));
|
|
134
|
+
};
|
|
135
|
+
await Promise.allSettled(this.treeData.map((e) => n(e, null)));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 设置 path
|
|
139
|
+
* @param path
|
|
140
|
+
*/
|
|
141
|
+
setPath(t) {
|
|
142
|
+
this.path = t;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* 同步场景树
|
|
146
|
+
*/
|
|
147
|
+
async loadScene(t = {}) {
|
|
148
|
+
t = {
|
|
149
|
+
syncProperties: !0,
|
|
150
|
+
syncModelVisions: !0,
|
|
151
|
+
needsModelsBoundsTree: !0,
|
|
152
|
+
...t
|
|
153
|
+
}, await Promise.allSettled([
|
|
154
|
+
(async () => {
|
|
155
|
+
t.syncProperties && (this.propertiesData = await this.fetchPropertiesData());
|
|
156
|
+
})(),
|
|
157
|
+
(async () => {
|
|
158
|
+
t.syncModelVisions && (this.modelVisionsData = await this.fetchModelVisionsData());
|
|
159
|
+
})()
|
|
160
|
+
]), this.treeData = await this.fetchTreeData(), await this.loadObjects(t), t.needsModelsBoundsTree && this.ssp.computeModelsBoundsTree();
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 获取拓扑路径列表
|
|
164
|
+
*/
|
|
165
|
+
async getTopologies() {
|
|
166
|
+
return this.topologyData = await this.fetchTopologyData(), this.topologyData;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* 播放动画
|
|
170
|
+
*/
|
|
171
|
+
async playAnimationById(t, i = 0, n = {}) {
|
|
172
|
+
const { utils: { error: e }, animation: h, THREE: r } = this.ssp, { onStart: f, onUpdate: d } = n;
|
|
173
|
+
this.animationsData || (this.animationsData = await this.fetchAnimationsData());
|
|
174
|
+
const l = this.ssp.getObjectById(t);
|
|
175
|
+
if (!l) {
|
|
176
|
+
e(`playAnimationById: id 为 ${t} 场景对象未找到`);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const y = this.animationsData.get(t);
|
|
180
|
+
if (y) {
|
|
181
|
+
const c = y[i];
|
|
182
|
+
if (c)
|
|
183
|
+
for (let p = 0, D = c.keyframes.length; p < D; p++) {
|
|
184
|
+
let o;
|
|
185
|
+
if (c.keyframes[p - 1]) {
|
|
186
|
+
const a = c.keyframes[p - 1];
|
|
187
|
+
o = {
|
|
188
|
+
x: a.x,
|
|
189
|
+
y: a.y,
|
|
190
|
+
z: a.z,
|
|
191
|
+
rotationX: a.rotationX,
|
|
192
|
+
rotationY: a.rotationY,
|
|
193
|
+
rotationZ: a.rotationZ,
|
|
194
|
+
scaleX: a.scaleX,
|
|
195
|
+
scaleY: a.scaleY,
|
|
196
|
+
scaleZ: a.scaleZ
|
|
197
|
+
};
|
|
198
|
+
} else {
|
|
199
|
+
const a = new r.Object3D(), u = new r.Matrix4().fromArray(l.userData.matrix);
|
|
200
|
+
a.applyMatrix4(u), o = {
|
|
201
|
+
x: a.position.x,
|
|
202
|
+
y: a.position.y,
|
|
203
|
+
z: a.position.z,
|
|
204
|
+
rotationX: a.rotation.x,
|
|
205
|
+
rotationY: a.rotation.y,
|
|
206
|
+
rotationZ: a.rotation.z,
|
|
207
|
+
scaleX: a.scale.x,
|
|
208
|
+
scaleY: a.scale.y,
|
|
209
|
+
scaleZ: a.scale.z
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const s = c.keyframes[p], { delay: m, duration: P, easing: g, repeat: T, yoyo: E } = s, M = {
|
|
213
|
+
x: s.x,
|
|
214
|
+
y: s.y,
|
|
215
|
+
z: s.z,
|
|
216
|
+
rotationX: s.rotationX,
|
|
217
|
+
rotationY: s.rotationY,
|
|
218
|
+
rotationZ: s.rotationZ,
|
|
219
|
+
scaleX: s.scaleX,
|
|
220
|
+
scaleY: s.scaleY,
|
|
221
|
+
scaleZ: s.scaleZ
|
|
222
|
+
};
|
|
223
|
+
await h(
|
|
224
|
+
o,
|
|
225
|
+
M,
|
|
226
|
+
{ delay: m, duration: P, mode: g, repeat: T === -1 ? 1 / 0 : T, yoyo: E },
|
|
227
|
+
(a, u) => {
|
|
228
|
+
l.position.set(a.x, a.y, a.z), l.rotation.set(a.rotationX, a.rotationY, a.rotationZ), l.scale.set(a.scaleX, a.scaleY, a.scaleZ), d?.(a, u);
|
|
229
|
+
},
|
|
230
|
+
(a) => {
|
|
231
|
+
f?.(a);
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
else
|
|
236
|
+
e(`id: ${t} 未找到索引为 ${i} 的动画`);
|
|
237
|
+
} else
|
|
238
|
+
e(`id: ${t} 未找到动画`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function A(_, t) {
|
|
242
|
+
const i = /* @__PURE__ */ new Map();
|
|
243
|
+
return _.reduce((n, e) => {
|
|
244
|
+
const h = n.get(e[t]);
|
|
245
|
+
return h ? h.push(e) : n.set(e[t], [e]), n;
|
|
246
|
+
}, i), i;
|
|
247
|
+
}
|
|
248
|
+
export {
|
|
249
|
+
O as ANIMATIONS_DATA_FILE_PATH,
|
|
250
|
+
I as META_DATA_FILE_PATH,
|
|
251
|
+
b as MODEL_VISIONS_DATA_FILE_PATH,
|
|
252
|
+
j as PROPERTIES_DATA_FLEE_PATH,
|
|
253
|
+
S as PROPERTIES_KEY,
|
|
254
|
+
Y as SIGN_PATH,
|
|
255
|
+
x as TOPOLOGY_DATA_FILE_PATH,
|
|
256
|
+
w as TREE_DATA_FILE_PATH,
|
|
257
|
+
X as default
|
|
258
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-soonmanager2-sync",
|
|
3
3
|
"pluginName": "Soonmanager2SyncPlugin",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.14.1",
|
|
5
5
|
"description": "Sync soonmanager 2.x data 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
|
}
|