@soonspacejs/plugin-soonbuilder-loader 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 +108 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -1 +1,108 @@
|
|
|
1
|
-
class
|
|
1
|
+
class T {
|
|
2
|
+
constructor(t) {
|
|
3
|
+
this.ssp = t, this.treeData = [], this.modelData = [];
|
|
4
|
+
}
|
|
5
|
+
fileInfo;
|
|
6
|
+
sceneInfo;
|
|
7
|
+
treeData;
|
|
8
|
+
modelData;
|
|
9
|
+
async load(t, e = !1) {
|
|
10
|
+
const { xmlToJson: i, isArray: s, isObject: r } = this.ssp.utils, d = e ? `${t}/FileInfo.xml` : t;
|
|
11
|
+
this.fileInfo = await i(d);
|
|
12
|
+
const x = this._getFileExtensionFc(this.fileInfo), p = d.split("FileInfo.xml")[0], E = this.fileInfo.folder._attributes.name;
|
|
13
|
+
this.sceneInfo = await i(`${p}${E}.xml`);
|
|
14
|
+
const {
|
|
15
|
+
Project: {
|
|
16
|
+
Building: { Floors: c, ObjectHierarchy: u }
|
|
17
|
+
}
|
|
18
|
+
} = this.sceneInfo, y = async (a) => {
|
|
19
|
+
const { _attributes: g, FileSource: D } = a, { id: _, name: M } = g, { name: P } = D._attributes, f = {
|
|
20
|
+
id: _,
|
|
21
|
+
name: M,
|
|
22
|
+
url: this._pathModeChange(p, P),
|
|
23
|
+
children: [],
|
|
24
|
+
userData: a
|
|
25
|
+
};
|
|
26
|
+
this._pushModelData(f);
|
|
27
|
+
const F = await this.ssp.loadModelToGroup(
|
|
28
|
+
{
|
|
29
|
+
id: `${f.id}_group`
|
|
30
|
+
},
|
|
31
|
+
[f]
|
|
32
|
+
);
|
|
33
|
+
if (!F) return;
|
|
34
|
+
let l = null;
|
|
35
|
+
if (s(u.Entity))
|
|
36
|
+
l = u.Entity.find(
|
|
37
|
+
({ _attributes: { id: o, type: h } }) => h === "Floor" && o === _
|
|
38
|
+
);
|
|
39
|
+
else if (r(u.Entity)) {
|
|
40
|
+
const { id: o, type: h } = u.Entity._attributes;
|
|
41
|
+
o === _ && h === "Floor" && (l = u.Entity);
|
|
42
|
+
}
|
|
43
|
+
if (!l) return;
|
|
44
|
+
let n = null;
|
|
45
|
+
if (s(l.Entity) ? n = l.Entity.filter(
|
|
46
|
+
({ _attributes: { type: o } }) => o === "FACILITY"
|
|
47
|
+
) : r(l.Entity) && l.Entity._attributes.type === "FACILITY" && (n = l.Entity), !!n) {
|
|
48
|
+
for (let o = 0; o < n.length; o++) {
|
|
49
|
+
const { id: h, longname: I, visible: $, position: w, eular: A, scale: C } = {
|
|
50
|
+
...n[o]._attributes,
|
|
51
|
+
...n[o].Properties?._attributes ?? {}
|
|
52
|
+
}, b = {
|
|
53
|
+
id: h,
|
|
54
|
+
name: I,
|
|
55
|
+
url: this._pathModeChange(p, `/${x(I)}`),
|
|
56
|
+
visible: this._text2Bool($),
|
|
57
|
+
position: this._text2IVector3(w),
|
|
58
|
+
rotation: this._text2IVector3(A),
|
|
59
|
+
scale: this._text2IVector3(C),
|
|
60
|
+
userData: n[o]
|
|
61
|
+
}, m = await this.ssp.loadModel(b);
|
|
62
|
+
m && (this.ssp.addObject(m, F), this._pushModelData(b), f.children?.push(b));
|
|
63
|
+
}
|
|
64
|
+
this.treeData.push(f);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
if (s(c.Floor))
|
|
68
|
+
for (let a = 0; a < c.Floor.length; a++)
|
|
69
|
+
await y(c.Floor[a]);
|
|
70
|
+
else r(c.Floor) && await y(c.Floor);
|
|
71
|
+
}
|
|
72
|
+
_pushModelData(t) {
|
|
73
|
+
this.modelData.find(({ url: i }) => i === t.url) || this.modelData.push(t);
|
|
74
|
+
}
|
|
75
|
+
_text2IVector3(t) {
|
|
76
|
+
const e = t.split(", ");
|
|
77
|
+
return {
|
|
78
|
+
x: Number(e[0]),
|
|
79
|
+
y: Number(e[1]),
|
|
80
|
+
z: Number(e[2])
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
_text2Bool(t) {
|
|
84
|
+
return t === "True";
|
|
85
|
+
}
|
|
86
|
+
_pathModeChange(t, e) {
|
|
87
|
+
const i = t + e;
|
|
88
|
+
if (i.includes("://")) {
|
|
89
|
+
const s = i.split("://");
|
|
90
|
+
return s[0] + "://" + s[1].replace("\\", "/").replace("./", "/").replace("//", "/");
|
|
91
|
+
} else
|
|
92
|
+
return i.replace("\\", "/").replace("./", "/").replace("//", "/");
|
|
93
|
+
}
|
|
94
|
+
_getFileExtensionFc(t) {
|
|
95
|
+
const e = t?.folder?.file;
|
|
96
|
+
let i = [];
|
|
97
|
+
return e && Array.isArray(e) && (i = e.filter(((s) => {
|
|
98
|
+
const { Extension: r } = s._attributes;
|
|
99
|
+
return r === ".sbm" || r === ".sbmx";
|
|
100
|
+
}))), (s) => {
|
|
101
|
+
const r = i.find((d) => d?._attributes?.name.startsWith(s))?._attributes;
|
|
102
|
+
return `${s}${r?.Extension || ".sbm"}`;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
T as default
|
|
108
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-soonbuilder-loader",
|
|
3
3
|
"pluginName": "SoonbuilderLoaderPlugin",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.14.0",
|
|
5
5
|
"description": "soonbuilder-loader 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
|
}
|