@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 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 t="/SceneMetadata.json",a="/db/sign",e="/db/tree_models.json",s="/db/topology_paths.json",o="/db/properties.json",i="/db/animations.json",n="/db/model_visions.json",r="properties";var l;!function(t){t[t.BIDIRECTION=0]="BIDIRECTION",t[t.POSITIVE=1]="POSITIVE",t[t.OPPOSITE=2]="OPPOSITE",t[t.FORBID=3]="FORBID"}(l||(l={}));class c{get path(){return this._path}set path(t){this._path=t}constructor(t){this.ssp=t,this._path="",this.metaData=null,this.treeData=null,this.topologyData=null,this.propertiesData=null,this.animationsData=null,this.modelVisionsData=null}_resolvePath(t){return`${this._path}${t}`}async _fetchData(t){const{utils:a}=this.ssp;return a.fetchFile(this._resolvePath(t),"json")}async fetchMetaData(){return this._fetchData(t)}async fetchTreeData(){return this._fetchData(e)}async fetchTopologyData(){return this._fetchData(s).then(t=>{const a={linkWidth:.1,linkColor:["#00ff00"],nodeRadius:.05,nodeColor:"#0000ff"};return t.map(t=>{const e=Object.assign(Object.assign({},a),t);return e.imgUrl&&(e.imgUrl=`${this.path}${e.imgUrl}`),e})})}async fetchPropertiesData(){return this._fetchData(o).then(t=>h(t,"modelId"))}async fetchAnimationsData(){return this._fetchData(i).then(t=>h(t,"modelId"))}async fetchModelVisionsData(){return this._fetchData(n).then(t=>new Map(Object.entries(t)))}async loadObjects(t){if(!this.treeData)return void console.error("treeData is null");const{syncProperties:a}=t,e=async(t,s)=>{const{ssp:o}=this,{THREE:{Matrix4:i}}=o,{id:n,name:l,renderType:c,path:h,matrix:d}=t,p=(new i).fromArray(d);let y=null;if("3D"===c)if(h)try{const a=Object.assign({},t);Reflect.deleteProperty(a,"children");const e=h.replaceAll(/#/g,"%23");y=await o.loadModel({id:n,name:l,url:this._resolvePath(e),userData:a})}catch(t){console.error(t)}else o.utils.warn(`id: ${n} path 为空`);else"GROUP"!==c&&"STUB"!==c||(y=o.createGroup({id:n,name:l,userData:Object.assign({},t)}));if(y&&(p.decompose(y.position,y.quaternion,y.scale),s&&o.addObject(y,s),a&&this.propertiesData)){const t=this.propertiesData.get(n);t&&(y.userData[r]=t)}t.children.length>0&&await Promise.allSettled(t.children.map(t=>e(t,y)))};await Promise.allSettled(this.treeData.map(t=>e(t,null)))}setPath(t){this.path=t}async loadScene(t={}){t=Object.assign({syncProperties:!0,syncModelVisions:!0,needsModelsBoundsTree:!0},t),await Promise.allSettled([(async()=>{t.syncProperties&&(this.propertiesData=await this.fetchPropertiesData())})(),(async()=>{t.syncModelVisions&&(this.modelVisionsData=await this.fetchModelVisionsData())})()]),this.treeData=await this.fetchTreeData(),await this.loadObjects(t),t.needsModelsBoundsTree&&this.ssp.computeModelsBoundsTree()}async getTopologies(){return this.topologyData=await this.fetchTopologyData(),this.topologyData}async playAnimationById(t,a=0,e={}){const{utils:{error:s},animation:o,THREE:i}=this.ssp,{onStart:n,onUpdate:r}=e;this.animationsData||(this.animationsData=await this.fetchAnimationsData());const l=this.ssp.getObjectById(t);if(!l)return void s(`playAnimationById: id 为 ${t} 场景对象未找到`);const c=this.animationsData.get(t);if(c){const e=c[a];if(e)for(let t=0,a=e.keyframes.length;t<a;t++){let a;if(e.keyframes[t-1]){const s=e.keyframes[t-1];a={x:s.x,y:s.y,z:s.z,rotationX:s.rotationX,rotationY:s.rotationY,rotationZ:s.rotationZ,scaleX:s.scaleX,scaleY:s.scaleY,scaleZ:s.scaleZ}}else{const t=new i.Object3D,e=(new i.Matrix4).fromArray(l.userData.matrix);t.applyMatrix4(e),a={x:t.position.x,y:t.position.y,z:t.position.z,rotationX:t.rotation.x,rotationY:t.rotation.y,rotationZ:t.rotation.z,scaleX:t.scale.x,scaleY:t.scale.y,scaleZ:t.scale.z}}const s=e.keyframes[t],{delay:c,duration:h,easing:d,repeat:p,yoyo:y}=s,u={x:s.x,y:s.y,z:s.z,rotationX:s.rotationX,rotationY:s.rotationY,rotationZ:s.rotationZ,scaleX:s.scaleX,scaleY:s.scaleY,scaleZ:s.scaleZ};await o(a,u,{delay:c,duration:h,mode:d,repeat:-1===p?1/0:p,yoyo:y},(t,a)=>{l.position.set(t.x,t.y,t.z),l.rotation.set(t.rotationX,t.rotationY,t.rotationZ),l.scale.set(t.scaleX,t.scaleY,t.scaleZ),null==r||r(t,a)},t=>{null==n||n(t)})}else s(`id: ${t} 未找到索引为 ${a} 的动画`)}else s(`id: ${t} 未找到动画`)}}function h(t,a){const e=new Map;return t.reduce((t,e)=>{const s=t.get(e[a]);return s?s.push(e):t.set(e[a],[e]),t},e),e}export{i as ANIMATIONS_DATA_FILE_PATH,t as META_DATA_FILE_PATH,n as MODEL_VISIONS_DATA_FILE_PATH,o as PROPERTIES_DATA_FLEE_PATH,r as PROPERTIES_KEY,a as SIGN_PATH,s as TOPOLOGY_DATA_FILE_PATH,e as TREE_DATA_FILE_PATH,c as default};
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.13.17",
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": "8afa5fda9a0ef2c080060e7d8e71a8bf168fd4d2",
16
+ "gitHead": "27d5e0bcd79ff71c8e2943a8420c39624ae6f8e6",
17
17
  "peerDependencies": {
18
- "soonspacejs": "2.13.17"
18
+ "soonspacejs": "2.14.1"
19
19
  }
20
20
  }