@soonspacejs/plugin-soonmanager2-sync 2.4.14 → 2.5.0-alpha.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,36 +1,28 @@
1
1
  import SoonSpace from 'soonspacejs';
2
- import { Space, SpaceTree } from './types';
3
- export default class Soonmanager2SyncPlugin {
2
+ import { TreeData } from './types';
3
+ declare class Soonmanager2SyncPlugin {
4
4
  readonly ssp: SoonSpace;
5
- baseUrl: string;
6
- spaceData: Space[] | null;
7
- lightData: Space[] | null;
8
- spaceTreeData: SpaceTree[] | null;
5
+ path: string;
6
+ treeData: TreeData[] | null;
9
7
  constructor(ssp: SoonSpace);
8
+ private resolvePath;
9
+ private fetchData;
10
10
  /**
11
- * 设置公共资源路径
11
+ * 获取场景树
12
12
  */
13
- setBaseUrl(url: string): void;
13
+ private fetchTreeData;
14
14
  /**
15
- * 同步灯光
15
+ * 设置 path
16
+ * @param path
16
17
  */
17
- syncLight(): Promise<void>;
18
+ setPath(path: string): void;
18
19
  /**
19
- * 加载场景
20
+ * 加载场景树中的对象
20
21
  */
21
- loadScene(spaceData?: Space[]): Promise<void>;
22
+ private loadObjects;
22
23
  /**
23
- * 获取空间数据、灯光
24
+ * 同步场景树
24
25
  */
25
- private getData;
26
- /**
27
- * 将空间数据转换为树结构数据
28
- */
29
- private spaceData2SpaceTreeData;
30
- /**
31
- * 根据类型格式化数据
32
- * @param baseUrl
33
- * @param spaceTree
34
- */
35
- private formatSpaceDataByType;
26
+ loadScene(): Promise<void>;
36
27
  }
28
+ export default Soonmanager2SyncPlugin;
package/dist/index.esm.js CHANGED
@@ -12,4 +12,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
12
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
13
  PERFORMANCE OF THIS SOFTWARE.
14
14
  ***************************************************************************** */
15
- function t(t,e,i,s){return new(i||(i=Promise))((function(o,a){function n(t){try{l(s.next(t))}catch(t){a(t)}}function r(t){try{l(s.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,r)}l((s=s.apply(t,e||[])).next())}))}var e,i,s;!function(t){t.Sbm="Sbm",t.Model="Model",t.Poi="Poi",t.Point="Point",t.Line="Line",t.Polygon="Polygon",t.Circle="Circle",t.Grid="Grid",t.Ground="Ground",t.Light="Light"}(e||(e={})),function(t){t.Model="model",t.MarkPoint="markPoint",t.BaseObject="baseObject",t.Topology="topology",t.Light="light",t.Effect="effect"}(i||(i={})),function(t){t.SimpleModel="simpleModel",t.GroupModel="groupModel",t.Point="point",t.Line="line",t.Polygon="polygon",t.AmbientLight="ambientLight",t.DirectionalLight="directionalLight",t.HemisphereLight="hemisphereLight"}(s||(s={}));const o=t=>{var e;if(!t)return{};try{return null!==(e=JSON.parse(t))&&void 0!==e?e:{}}catch(t){return{}}};class a{constructor(t){this.ssp=t,this.baseUrl="",this.spaceData=null,this.lightData=null,this.spaceTreeData=null}setBaseUrl(t){this.baseUrl=t}syncLight(){return t(this,void 0,void 0,(function*(){if(this.lightData=yield this.getData("/data/light.json"),!this.lightData||!this.lightData.length)return;const t=this.ssp;t.removeLightById("defaultAmbientLight"),t.removeLightById("defaultDirectionalLight"),t.removeLightById("defaultHemisphereLight");const e=this.lightData;null==e||e.forEach((e=>{const a=e.spaceObjectDto;if(a&&a.templateAggregateDto.firstClassify===i.Light){const i=o(a.attribute);if(i.id=e.id,i.position&&(i.position=o(i.position)),i.target&&(i.target=o(i.target)),a.templateAggregateDto.secondClassify===s.AmbientLight){t.getLightById(i.id)?t.setAmbientLight(i):t.createAmbientLight(i)}else if(a.templateAggregateDto.secondClassify===s.DirectionalLight){t.getLightById(i.id)?t.setDirectionalLight(i):t.createDirectionalLight(i)}else if(a.templateAggregateDto.secondClassify===s.HemisphereLight){t.getLightById(i.id)?t.setHemisphereLight(i):t.createHemisphereLight(i)}}}))}))}loadScene(i){var s;return t(this,void 0,void 0,(function*(){if(this.spaceData=i||(yield this.getData()),this.spaceTreeData=this.spaceData2SpaceTreeData(this.spaceData),!(null===(s=this.spaceTreeData)||void 0===s?void 0:s.length))return;const o=this.spaceTreeData,a=i=>t(this,void 0,void 0,(function*(){var t;const{pid:s,sceneType:o}=i,n=this.formatSpaceDataByType(i);if(n)if(o===e.Sbm){this.ssp.getSbmGroupById(s)?yield this.ssp.addSbmForGroup(s,[n]):yield this.ssp.loadSbmToGroup({id:s},[n])}else if(o===e.Model){this.ssp.getModelGroupById(s)?yield this.ssp.addModelForGroup(s,[n]):yield this.ssp.loadModelToGroup({id:s},[n])}else if(o===e.Poi){this.ssp.getPoiGroupById(s)?yield this.ssp.addPoiForGroup(s,[n]):yield this.ssp.createPoiToGroup({id:s},[n])}else if(o===e.Point||o===e.Line||o===e.Polygon){this.ssp.getCanvas3DGroupById(s)?yield this.ssp.addCanvas3DForGroup(s,[n]):yield this.ssp.createCanvas3DToGroup({id:s},[n])}(null===(t=i.children)||void 0===t?void 0:t.length)&&(yield Promise.allSettled(i.children.map((t=>a(t)))))}));yield Promise.allSettled(o.map((t=>a(t))))}))}getData(e="/data/space.json"){return fetch(`${this.baseUrl}${e}`).then((t=>t.json())).then((e=>t(this,void 0,void 0,(function*(){return e}))))}spaceData2SpaceTreeData(t=this.spaceData){const e=[],i=[];if(t){const s=[...t];s.forEach((t=>{i.includes(t.id)||i.push(t.id)})),s.forEach((t=>{i.includes(t.pid)||e.push(Object.assign({},t))})),e.forEach((t=>{const e=s.findIndex((e=>e.id===t.id));-1!==e&&s.splice(e,1)}));const o=(t,e)=>{const i=[];t.forEach((t=>{t.pid===e.id&&i.push(t)})),i.length>0&&(e.children=i,i.forEach((e=>o(t,e))))};e.forEach((t=>o(s,t)))}return e}formatSpaceDataByType(t){var i;if(!t.sceneType)return;const{id:s,name:a,sceneType:n,spaceObjectDto:r,position:{coordinates:l}={}}=t,{deg2Euler:d}=this.ssp.utils,{attribute:c,templateAggregateDto:h}=null!=r?r:{},{fileResourceBaseDto:p}=null!=h?h:{},[g=0,u=0,y=0]=null!=l?l:[],{rotation:f={},scale:m={},configAttribute:D={}}=o(c),{x:L=0,y:b=0,z:v=0}=f,{x:P=1,y:x=1,z:G=1}=m,S=null!==(i=null==p?void 0:p.path)&&void 0!==i?i:"";return n===e.Sbm||n===e.Model||n===e.Poi?{id:s,name:a,url:`${this.baseUrl}${S}`,position:{x:g,y:u,z:y},rotation:{x:d(L),y:d(b),z:d(v)},scale:{x:P,y:x,z:G},userData:Object.assign({},t)}:n===e.Point?{id:s,name:a,points:[Object.assign({id:s,position:{x:g,y:u,z:y},rotation:{x:d(L),y:d(b),z:d(v)},scale:{x:P,y:x,z:G}},D)],userData:Object.assign({},t)}:n===e.Line?{id:s,name:a,lines:[Object.assign({id:s,position:{x:g,y:u,z:y},rotation:{x:d(L),y:d(b),z:d(v)},scale:{x:P,y:x,z:G}},D)],userData:Object.assign({},t)}:n===e.Polygon?{id:s,name:a,polygons:[Object.assign({id:s,position:{x:g,y:u,z:y},rotation:{x:d(L),y:d(b),z:d(v)},scale:{x:P,y:x,z:G}},D)],userData:Object.assign({},t)}:void e.Circle}}export{a as default};
15
+ function t(t,e,i,a){return new(i||(i=Promise))((function(n,r){function s(t){try{l(a.next(t))}catch(t){r(t)}}function o(t){try{l(a.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,o)}l((a=a.apply(t,e||[])).next())}))}class e{constructor(t){this.ssp=t,this.path="",this.treeData=null}resolvePath(t){return`${this.path}${t}`}fetchData(e){return t(this,void 0,void 0,(function*(){const{utils:t}=this.ssp;return yield t.fetchFile(this.resolvePath(e)).then((t=>t.json()))}))}fetchTreeData(){return t(this,void 0,void 0,(function*(){this.treeData=yield this.fetchData("/db/tree_models.json")}))}setPath(t){this.path=t}loadObjects(){return t(this,void 0,void 0,(function*(){if(!this.treeData)return void console.error("treeData is null");const e=(i,a)=>t(this,void 0,void 0,(function*(){const{ssp:t}=this,{THREE:{Matrix4:n}}=t,{id:r,name:s,renderType:o,path:l,matrix:h,pid:d}=i,c=(new n).fromArray(h);let u=null;if("3D"===o&&l)try{u=yield t.loadModel({id:r,name:s,url:this.resolvePath(l),userData:{pid:d}})}catch(t){console.error(t)}else"GROUP"===o&&(u=t.createGroup({id:r,name:s,userData:{pid:d}}));u&&(u.applyMatrix4(c),a&&t.addObject(u,a)),i.children.length>0&&(yield Promise.allSettled(i.children.map((t=>e(t,u)))))}));yield Promise.allSettled(this.treeData.map((t=>e(t,null))))}))}loadScene(){return t(this,void 0,void 0,(function*(){this.treeData||(yield this.fetchTreeData()),yield this.loadObjects()}))}}export{e as default};
package/dist/index.js CHANGED
@@ -12,4 +12,4 @@
12
12
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */function t(t,e,i,o){return new(i||(i=Promise))((function(s,a){function n(t){try{l(o.next(t))}catch(t){a(t)}}function r(t){try{l(o.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,r)}l((o=o.apply(t,e||[])).next())}))}var e,i,o;!function(t){t.Sbm="Sbm",t.Model="Model",t.Poi="Poi",t.Point="Point",t.Line="Line",t.Polygon="Polygon",t.Circle="Circle",t.Grid="Grid",t.Ground="Ground",t.Light="Light"}(e||(e={})),function(t){t.Model="model",t.MarkPoint="markPoint",t.BaseObject="baseObject",t.Topology="topology",t.Light="light",t.Effect="effect"}(i||(i={})),function(t){t.SimpleModel="simpleModel",t.GroupModel="groupModel",t.Point="point",t.Line="line",t.Polygon="polygon",t.AmbientLight="ambientLight",t.DirectionalLight="directionalLight",t.HemisphereLight="hemisphereLight"}(o||(o={}));const s=t=>{var e;if(!t)return{};try{return null!==(e=JSON.parse(t))&&void 0!==e?e:{}}catch(t){return{}}};return class{constructor(t){this.ssp=t,this.baseUrl="",this.spaceData=null,this.lightData=null,this.spaceTreeData=null}setBaseUrl(t){this.baseUrl=t}syncLight(){return t(this,void 0,void 0,(function*(){if(this.lightData=yield this.getData("/data/light.json"),!this.lightData||!this.lightData.length)return;const t=this.ssp;t.removeLightById("defaultAmbientLight"),t.removeLightById("defaultDirectionalLight"),t.removeLightById("defaultHemisphereLight");const e=this.lightData;null==e||e.forEach((e=>{const a=e.spaceObjectDto;if(a&&a.templateAggregateDto.firstClassify===i.Light){const i=s(a.attribute);if(i.id=e.id,i.position&&(i.position=s(i.position)),i.target&&(i.target=s(i.target)),a.templateAggregateDto.secondClassify===o.AmbientLight){t.getLightById(i.id)?t.setAmbientLight(i):t.createAmbientLight(i)}else if(a.templateAggregateDto.secondClassify===o.DirectionalLight){t.getLightById(i.id)?t.setDirectionalLight(i):t.createDirectionalLight(i)}else if(a.templateAggregateDto.secondClassify===o.HemisphereLight){t.getLightById(i.id)?t.setHemisphereLight(i):t.createHemisphereLight(i)}}}))}))}loadScene(i){var o;return t(this,void 0,void 0,(function*(){if(this.spaceData=i||(yield this.getData()),this.spaceTreeData=this.spaceData2SpaceTreeData(this.spaceData),!(null===(o=this.spaceTreeData)||void 0===o?void 0:o.length))return;const s=this.spaceTreeData,a=i=>t(this,void 0,void 0,(function*(){var t;const{pid:o,sceneType:s}=i,n=this.formatSpaceDataByType(i);if(n)if(s===e.Sbm){this.ssp.getSbmGroupById(o)?yield this.ssp.addSbmForGroup(o,[n]):yield this.ssp.loadSbmToGroup({id:o},[n])}else if(s===e.Model){this.ssp.getModelGroupById(o)?yield this.ssp.addModelForGroup(o,[n]):yield this.ssp.loadModelToGroup({id:o},[n])}else if(s===e.Poi){this.ssp.getPoiGroupById(o)?yield this.ssp.addPoiForGroup(o,[n]):yield this.ssp.createPoiToGroup({id:o},[n])}else if(s===e.Point||s===e.Line||s===e.Polygon){this.ssp.getCanvas3DGroupById(o)?yield this.ssp.addCanvas3DForGroup(o,[n]):yield this.ssp.createCanvas3DToGroup({id:o},[n])}(null===(t=i.children)||void 0===t?void 0:t.length)&&(yield Promise.allSettled(i.children.map((t=>a(t)))))}));yield Promise.allSettled(s.map((t=>a(t))))}))}getData(e="/data/space.json"){return fetch(`${this.baseUrl}${e}`).then((t=>t.json())).then((e=>t(this,void 0,void 0,(function*(){return e}))))}spaceData2SpaceTreeData(t=this.spaceData){const e=[],i=[];if(t){const o=[...t];o.forEach((t=>{i.includes(t.id)||i.push(t.id)})),o.forEach((t=>{i.includes(t.pid)||e.push(Object.assign({},t))})),e.forEach((t=>{const e=o.findIndex((e=>e.id===t.id));-1!==e&&o.splice(e,1)}));const s=(t,e)=>{const i=[];t.forEach((t=>{t.pid===e.id&&i.push(t)})),i.length>0&&(e.children=i,i.forEach((e=>s(t,e))))};e.forEach((t=>s(o,t)))}return e}formatSpaceDataByType(t){var i;if(!t.sceneType)return;const{id:o,name:a,sceneType:n,spaceObjectDto:r,position:{coordinates:l}={}}=t,{deg2Euler:d}=this.ssp.utils,{attribute:c,templateAggregateDto:h}=null!=r?r:{},{fileResourceBaseDto:p}=null!=h?h:{},[g=0,u=0,f=0]=null!=l?l:[],{rotation:y={},scale:m={},configAttribute:D={}}=s(c),{x:b=0,y:L=0,z:v=0}=y,{x:P=1,y:x=1,z:S=1}=m,T=null!==(i=null==p?void 0:p.path)&&void 0!==i?i:"";return n===e.Sbm||n===e.Model||n===e.Poi?{id:o,name:a,url:`${this.baseUrl}${T}`,position:{x:g,y:u,z:f},rotation:{x:d(b),y:d(L),z:d(v)},scale:{x:P,y:x,z:S},userData:Object.assign({},t)}:n===e.Point?{id:o,name:a,points:[Object.assign({id:o,position:{x:g,y:u,z:f},rotation:{x:d(b),y:d(L),z:d(v)},scale:{x:P,y:x,z:S}},D)],userData:Object.assign({},t)}:n===e.Line?{id:o,name:a,lines:[Object.assign({id:o,position:{x:g,y:u,z:f},rotation:{x:d(b),y:d(L),z:d(v)},scale:{x:P,y:x,z:S}},D)],userData:Object.assign({},t)}:n===e.Polygon?{id:o,name:a,polygons:[Object.assign({id:o,position:{x:g,y:u,z:f},rotation:{x:d(b),y:d(L),z:d(v)},scale:{x:P,y:x,z:S}},D)],userData:Object.assign({},t)}:void e.Circle}}}));
15
+ ***************************************************************************** */function t(t,e,i,n){return new(i||(i=Promise))((function(o,r){function a(t){try{l(n.next(t))}catch(t){r(t)}}function s(t){try{l(n.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}l((n=n.apply(t,e||[])).next())}))}return class{constructor(t){this.ssp=t,this.path="",this.treeData=null}resolvePath(t){return`${this.path}${t}`}fetchData(e){return t(this,void 0,void 0,(function*(){const{utils:t}=this.ssp;return yield t.fetchFile(this.resolvePath(e)).then((t=>t.json()))}))}fetchTreeData(){return t(this,void 0,void 0,(function*(){this.treeData=yield this.fetchData("/db/tree_models.json")}))}setPath(t){this.path=t}loadObjects(){return t(this,void 0,void 0,(function*(){if(!this.treeData)return void console.error("treeData is null");const e=(i,n)=>t(this,void 0,void 0,(function*(){const{ssp:t}=this,{THREE:{Matrix4:o}}=t,{id:r,name:a,renderType:s,path:l,matrix:d,pid:h}=i,c=(new o).fromArray(d);let u=null;if("3D"===s&&l)try{u=yield t.loadModel({id:r,name:a,url:this.resolvePath(l),userData:{pid:h}})}catch(t){console.error(t)}else"GROUP"===s&&(u=t.createGroup({id:r,name:a,userData:{pid:h}}));u&&(u.applyMatrix4(c),n&&t.addObject(u,n)),i.children.length>0&&(yield Promise.allSettled(i.children.map((t=>e(t,u)))))}));yield Promise.allSettled(this.treeData.map((t=>e(t,null))))}))}loadScene(){return t(this,void 0,void 0,(function*(){this.treeData||(yield this.fetchTreeData()),yield this.loadObjects()}))}}}));
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.14",
4
+ "version": "2.5.0-alpha.1",
5
5
  "description": "Sync soonmanager 2.x data plugin for SoonSpace.js",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.esm.js",
@@ -13,5 +13,5 @@
13
13
  ],
14
14
  "author": "xuek",
15
15
  "license": "UNLICENSED",
16
- "gitHead": "d2709bfc1b944eadf850207f43a56e3e848a5d27"
16
+ "gitHead": "0718030c70fef431833f4f3d46829009f8d9d2be"
17
17
  }