@soonspacejs/plugin-soonbuilder-loader 2.13.16 → 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 CHANGED
@@ -1,5 +1,4 @@
1
- import SoonSpace from 'soonspacejs';
2
- import { ModelInfo } from 'soonspacejs';
1
+ import { default as SoonSpace, ModelInfo } from 'soonspacejs';
3
2
  export interface TModelInfo extends ModelInfo {
4
3
  children?: TModelInfo[];
5
4
  }
package/dist/index.esm.js CHANGED
@@ -1 +1,108 @@
1
- class t{constructor(t){this.ssp=t,this.treeData=[],this.modelData=[]}async load(t,e=!1){const{xmlToJson:i,isArray:s,isObject:o}=this.ssp.utils,l=e?`${t}/FileInfo.xml`:t;this.fileInfo=await i(l);const r=this._getFileExtensionFc(this.fileInfo),n=l.split("FileInfo.xml")[0],a=this.fileInfo.folder._attributes.name;this.sceneInfo=await i(`${n}${a}.xml`);const{Project:{Building:{Floors:u,ObjectHierarchy:d}}}=this.sceneInfo,c=async t=>{var e,i,l;const{_attributes:a,FileSource:u}=t,{id:c,name:h}=a,{name:p}=u._attributes,f={id:c,name:h,url:this._pathModeChange(n,p),children:[],userData:t};this._pushModelData(f);const _=await this.ssp.loadModelToGroup({id:`${f.id}_group`},[f]);if(!_)return;let b=null;if(s(d.Entity))b=d.Entity.find(({_attributes:{id:t,type:e}})=>"Floor"===e&&t===c);else if(o(d.Entity)){const{id:t,type:e}=d.Entity._attributes;t===c&&"Floor"===e&&(b=d.Entity)}if(!b)return;let y=null;if(s(b.Entity)?y=b.Entity.filter(({_attributes:{type:t}})=>"FACILITY"===t):o(b.Entity)&&"FACILITY"===b.Entity._attributes.type&&(y=b.Entity),y){for(let t=0;t<y.length;t++){const{id:s,longname:o,visible:a,position:u,eular:d,scale:c}=Object.assign(Object.assign({},y[t]._attributes),null!==(i=null===(e=y[t].Properties)||void 0===e?void 0:e._attributes)&&void 0!==i?i:{}),h={id:s,name:o,url:this._pathModeChange(n,`/${r(o)}`),visible:this._text2Bool(a),position:this._text2IVector3(u),rotation:this._text2IVector3(d),scale:this._text2IVector3(c),userData:y[t]},p=await this.ssp.loadModel(h);p&&(this.ssp.addObject(p,_),this._pushModelData(h),null===(l=f.children)||void 0===l||l.push(h))}this.treeData.push(f)}};if(s(u.Floor))for(let t=0;t<u.Floor.length;t++)await c(u.Floor[t]);else o(u.Floor)&&await c(u.Floor)}_pushModelData(t){this.modelData.find(({url:e})=>e===t.url)||this.modelData.push(t)}_text2IVector3(t){const e=t.split(", ");return{x:Number(e[0]),y:Number(e[1]),z:Number(e[2])}}_text2Bool(t){return"True"===t}_pathModeChange(t,e){const i=t+e;if(i.includes("://")){const t=i.split("://");return t[0]+"://"+t[1].replace("\\","/").replace("./","/").replace("//","/")}return i.replace("\\","/").replace("./","/").replace("//","/")}_getFileExtensionFc(t){var e;const i=null===(e=null==t?void 0:t.folder)||void 0===e?void 0:e.file;let s=[];return i&&Array.isArray(i)&&(s=i.filter(t=>{const{Extension:e}=t._attributes;return".sbm"===e||".sbmx"===e})),t=>{var e;const i=null===(e=s.find(e=>{var i;return null===(i=null==e?void 0:e._attributes)||void 0===i?void 0:i.name.startsWith(t)}))||void 0===e?void 0:e._attributes;return`${t}${(null==i?void 0:i.Extension)||".sbm"}`}}}export{t as default};
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.13.16",
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": "aaf0c46565c740277fad34bc3a3ba9fa61d48278",
16
+ "gitHead": "4c85e8b7b8ad24ccb9b42f3a1826bca377c42a6d",
17
17
  "peerDependencies": {
18
- "soonspacejs": "2.13.16"
18
+ "soonspacejs": "2.14.0"
19
19
  }
20
20
  }