@inweb/viewer-three 26.9.1 → 26.9.3
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/plugins/components/AxesHelperComponent.js +8 -6
- package/dist/plugins/components/AxesHelperComponent.js.map +1 -1
- package/dist/plugins/components/AxesHelperComponent.min.js +1 -1
- package/dist/plugins/components/AxesHelperComponent.module.js +8 -6
- package/dist/plugins/components/AxesHelperComponent.module.js.map +1 -1
- package/dist/plugins/components/ExtentsHelperComponent.js.map +1 -1
- package/dist/plugins/components/ExtentsHelperComponent.min.js +1 -1
- package/dist/plugins/components/ExtentsHelperComponent.module.js +1 -1
- package/dist/plugins/components/ExtentsHelperComponent.module.js.map +1 -1
- package/dist/plugins/components/LightHelperComponent.js.map +1 -1
- package/dist/plugins/components/LightHelperComponent.min.js +1 -1
- package/dist/plugins/components/LightHelperComponent.module.js +7 -7
- package/dist/plugins/components/LightHelperComponent.module.js.map +1 -1
- package/dist/plugins/components/RoomEnvironmentComponent.js.map +1 -1
- package/dist/plugins/components/RoomEnvironmentComponent.min.js +1 -1
- package/dist/plugins/components/RoomEnvironmentComponent.module.js +1 -1
- package/dist/plugins/components/RoomEnvironmentComponent.module.js.map +1 -1
- package/dist/plugins/components/StatsPanelComponent.js.map +1 -1
- package/dist/plugins/components/StatsPanelComponent.min.js +1 -1
- package/dist/plugins/components/StatsPanelComponent.module.js +1 -1
- package/dist/plugins/components/StatsPanelComponent.module.js.map +1 -1
- package/dist/plugins/loaders/GLTFCloudLoader.js.map +1 -1
- package/dist/plugins/loaders/GLTFCloudLoader.min.js +1 -1
- package/dist/plugins/loaders/GLTFCloudLoader.module.js +1 -1
- package/dist/plugins/loaders/GLTFCloudLoader.module.js.map +1 -1
- package/dist/plugins/loaders/IFCXLoader.js +4 -4
- package/dist/plugins/loaders/IFCXLoader.js.map +1 -1
- package/dist/plugins/loaders/IFCXLoader.min.js +1 -1
- package/dist/plugins/loaders/IFCXLoader.module.js +92 -92
- package/dist/plugins/loaders/IFCXLoader.module.js.map +1 -1
- package/dist/plugins/loaders/PotreeLoader.js +160 -0
- package/dist/plugins/loaders/PotreeLoader.js.map +1 -0
- package/dist/plugins/loaders/PotreeLoader.min.js +1 -0
- package/dist/plugins/loaders/PotreeLoader.module.js +68 -0
- package/dist/plugins/loaders/PotreeLoader.module.js.map +1 -0
- package/dist/viewer-three.js +1180 -795
- package/dist/viewer-three.js.map +1 -1
- package/dist/viewer-three.min.js +3 -3
- package/dist/viewer-three.module.js +608 -301
- package/dist/viewer-three.module.js.map +1 -1
- package/lib/Viewer/Viewer.d.ts +3 -2
- package/lib/Viewer/controls/FlyControls.d.ts +34 -0
- package/lib/Viewer/controls/WalkControls.d.ts +19 -3
- package/lib/Viewer/draggers/FlyDragger.d.ts +14 -0
- package/package.json +6 -5
- package/plugins/components/AxesHelperComponent.ts +10 -6
- package/plugins/loaders/{IFCXCloudLoader.ts → IFCX/IFCXCloudLoader.ts} +1 -1
- package/plugins/loaders/{IFCXFileLoader.ts → IFCX/IFCXFileLoader.ts} +1 -1
- package/plugins/loaders/Potree/PotreeFileLoader.ts +106 -0
- package/plugins/loaders/Potree/PotreeModelImpl.ts +36 -0
- package/plugins/loaders/Potree/index.ts +28 -0
- package/src/Viewer/Viewer.ts +34 -10
- package/src/Viewer/components/ExtentsComponent.ts +1 -1
- package/src/Viewer/components/ResizeCanvasComponent.ts +1 -18
- package/src/Viewer/controls/FlyControls.ts +205 -0
- package/src/Viewer/controls/WalkControls.ts +129 -20
- package/src/Viewer/draggers/FlyDragger.ts +73 -0
- package/src/Viewer/draggers/OrbitDragger.ts +9 -0
- package/src/Viewer/draggers/WalkDragger.ts +11 -2
- package/src/Viewer/draggers/index.ts +2 -0
- package/src/Viewer/helpers/WCSHelper.ts +3 -3
- /package/plugins/loaders/{IFCXLoader.ts → IFCX/index.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("@inweb/viewer-three"),require("three")):"function"==typeof define&&define.amd?define(["@inweb/viewer-three","three"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ODA.Three,e.THREE)}(this,(function(e,t){"use strict";class r extends t.Loader{constructor(e){super(e),this.littleEndian=!0}load(e,r,i,n){const s=this,a=new t.FileLoader(s.manager);a.setPath(s.path),a.setResponseType("arraybuffer"),a.setRequestHeader(s.requestHeader),a.setWithCredentials(s.withCredentials),a.load(e,(function(t){try{r(s.parse(t))}catch(t){n?n(t):console.error(t),s.manager.itemError(e)}}),i,n)}_getDataView(e,t,r,i){switch(r){case"F":return 8===i?e.getFloat64(t,this.littleEndian):e.getFloat32(t,this.littleEndian);case"I":return 1===i?e.getInt8(t):2===i?e.getInt16(t,this.littleEndian):e.getInt32(t,this.littleEndian);case"U":return 1===i?e.getUint8(t):2===i?e.getUint16(t,this.littleEndian):e.getUint32(t,this.littleEndian)}}parse(e){const r=function(e){const t={},r=new Uint8Array(e);let i="",n="",s=0,a=!1;const o=r.length;for(;s<o&&!1===a;){const e=String.fromCharCode(r[s++]);"\n"===e||"\r"===e?(n.trim().toLowerCase().startsWith("data")&&(a=!0),n=""):n+=e,i+=e}const l=i.search(/[\r\n]DATA\s(\S*)\s/i),c=/[\r\n]DATA\s(\S*)\s/i.exec(i.slice(l-1));if(t.data=c[1],t.headerLen=c[0].length+l,t.str=i.slice(0,t.headerLen),t.str=t.str.replace(/#.*/gi,""),t.version=/^VERSION (.*)/im.exec(t.str),t.fields=/^FIELDS (.*)/im.exec(t.str),t.size=/^SIZE (.*)/im.exec(t.str),t.type=/^TYPE (.*)/im.exec(t.str),t.count=/^COUNT (.*)/im.exec(t.str),t.width=/^WIDTH (.*)/im.exec(t.str),t.height=/^HEIGHT (.*)/im.exec(t.str),t.viewpoint=/^VIEWPOINT (.*)/im.exec(t.str),t.points=/^POINTS (.*)/im.exec(t.str),null!==t.version&&(t.version=parseFloat(t.version[1])),t.fields=null!==t.fields?t.fields[1].split(" "):[],null!==t.type&&(t.type=t.type[1].split(" ")),null!==t.width&&(t.width=parseInt(t.width[1])),null!==t.height&&(t.height=parseInt(t.height[1])),null!==t.viewpoint&&(t.viewpoint=t.viewpoint[1]),null!==t.points&&(t.points=parseInt(t.points[1],10)),null===t.points&&(t.points=t.width*t.height),null!==t.size&&(t.size=t.size[1].split(" ").map((function(e){return parseInt(e,10)}))),null!==t.count)t.count=t.count[1].split(" ").map((function(e){return parseInt(e,10)}));else{t.count=[];for(let e=0,r=t.fields.length;e<r;e++)t.count.push(1)}t.offset={};let h=0;for(let e=0,r=t.fields.length;e<r;e++)"ascii"===t.data?t.offset[t.fields[e]]=e:(t.offset[t.fields[e]]=h,h+=t.size[e]*t.count[e]);return t.rowSize=h,t}(e),i=[],n=[],s=[],a=[],o=[],l=new t.Color;if("ascii"===r.data){const c=r.offset,h=(new TextDecoder).decode(e).slice(r.headerLen).split("\n");for(let e=0,u=h.length;e<u;e++){if(""===h[e])continue;const u=h[e].split(" ");if(void 0!==c.x&&(i.push(parseFloat(u[c.x])),i.push(parseFloat(u[c.y])),i.push(parseFloat(u[c.z]))),void 0!==c.rgb){const e=r.fields.findIndex((e=>"rgb"===e)),i=r.type[e],n=parseFloat(u[c.rgb]);let a=n;if("F"===i){const e=new Float32Array(1);e[0]=n,a=new Int32Array(e.buffer)[0]}const o=(a>>16&255)/255,h=(a>>8&255)/255,f=(255&a)/255;l.setRGB(o,h,f,t.SRGBColorSpace),s.push(l.r,l.g,l.b)}void 0!==c.normal_x&&(n.push(parseFloat(u[c.normal_x])),n.push(parseFloat(u[c.normal_y])),n.push(parseFloat(u[c.normal_z]))),void 0!==c.intensity&&a.push(parseFloat(u[c.intensity])),void 0!==c.label&&o.push(parseInt(u[c.label]))}}if("binary_compressed"===r.data){const c=new Uint32Array(e.slice(r.headerLen,r.headerLen+8)),h=c[0],u=c[1],f=function(e,t){const r=e.length,i=new Uint8Array(t);let n,s,a,o=0,l=0;do{if(n=e[o++],n<32){if(n++,l+n>t)throw new Error("Output buffer is not large enough");if(o+n>r)throw new Error("Invalid compressed data");do{i[l++]=e[o++]}while(--n)}else{if(s=n>>5,a=l-((31&n)<<8)-1,o>=r)throw new Error("Invalid compressed data");if(7===s&&(s+=e[o++],o>=r))throw new Error("Invalid compressed data");if(a-=e[o++],l+s+2>t)throw new Error("Output buffer is not large enough");if(a<0)throw new Error("Invalid compressed data");if(a>=l)throw new Error("Invalid compressed data");do{i[l++]=i[a++]}while(2+--s)}}while(o<r);return i}(new Uint8Array(e,r.headerLen+8,h),u),d=new DataView(f.buffer),p=r.offset;for(let e=0;e<r.points;e++){if(void 0!==p.x){const t=r.fields.indexOf("x"),n=r.fields.indexOf("y"),s=r.fields.indexOf("z");i.push(this._getDataView(d,r.points*p.x+r.size[t]*e,r.type[t],r.size[t])),i.push(this._getDataView(d,r.points*p.y+r.size[n]*e,r.type[n],r.size[n])),i.push(this._getDataView(d,r.points*p.z+r.size[s]*e,r.type[s],r.size[s]))}if(void 0!==p.rgb){const i=r.fields.indexOf("rgb"),n=d.getUint8(r.points*p.rgb+r.size[i]*e+2)/255,a=d.getUint8(r.points*p.rgb+r.size[i]*e+1)/255,o=d.getUint8(r.points*p.rgb+r.size[i]*e+0)/255;l.setRGB(n,a,o,t.SRGBColorSpace),s.push(l.r,l.g,l.b)}if(void 0!==p.normal_x){const t=r.fields.indexOf("normal_x"),i=r.fields.indexOf("normal_y"),s=r.fields.indexOf("normal_z");n.push(this._getDataView(d,r.points*p.normal_x+r.size[t]*e,r.type[t],r.size[t])),n.push(this._getDataView(d,r.points*p.normal_y+r.size[i]*e,r.type[i],r.size[i])),n.push(this._getDataView(d,r.points*p.normal_z+r.size[s]*e,r.type[s],r.size[s]))}if(void 0!==p.intensity){const t=r.fields.indexOf("intensity");a.push(this._getDataView(d,r.points*p.intensity+r.size[t]*e,r.type[t],r.size[t]))}if(void 0!==p.label){const t=r.fields.indexOf("label");o.push(d.getInt32(r.points*p.label+r.size[t]*e,this.littleEndian))}}}if("binary"===r.data){const c=new DataView(e,r.headerLen),h=r.offset;for(let e=0,u=0;e<r.points;e++,u+=r.rowSize){if(void 0!==h.x){const e=r.fields.indexOf("x"),t=r.fields.indexOf("y"),n=r.fields.indexOf("z");i.push(this._getDataView(c,u+h.x,r.type[e],r.size[e])),i.push(this._getDataView(c,u+h.y,r.type[t],r.size[t])),i.push(this._getDataView(c,u+h.z,r.type[n],r.size[n]))}if(void 0!==h.rgb){const e=c.getUint8(u+h.rgb+2)/255,r=c.getUint8(u+h.rgb+1)/255,i=c.getUint8(u+h.rgb+0)/255;l.setRGB(e,r,i,t.SRGBColorSpace),s.push(l.r,l.g,l.b)}if(void 0!==h.normal_x){const e=r.fields.indexOf("normal_x"),t=r.fields.indexOf("normal_y"),i=r.fields.indexOf("normal_z");n.push(this._getDataView(c,u+h.normal_x,r.type[e],r.size[e])),n.push(this._getDataView(c,u+h.normal_y,r.type[t],r.size[t])),n.push(this._getDataView(c,u+h.normal_z,r.type[i],r.size[i]))}if(void 0!==h.intensity){const e=r.fields.indexOf("intensity");a.push(this._getDataView(c,u+h.intensity,r.type[e],r.size[e]))}void 0!==h.label&&o.push(c.getInt32(u+h.label,this.littleEndian))}}const c=new t.BufferGeometry;i.length>0&&c.setAttribute("position",new t.Float32BufferAttribute(i,3)),n.length>0&&c.setAttribute("normal",new t.Float32BufferAttribute(n,3)),s.length>0&&c.setAttribute("color",new t.Float32BufferAttribute(s,3)),a.length>0&&c.setAttribute("intensity",new t.Float32BufferAttribute(a,1)),o.length>0&&c.setAttribute("label",new t.Int32BufferAttribute(o,1)),c.computeBoundingSphere();const h=new t.PointsMaterial({size:.005});return s.length>0&&(h.vertexColors=!0),new t.Points(c,h)}}const i={Box3:t.Box3,BufferAttribute:t.BufferAttribute,BufferGeometry:t.BufferGeometry,Color:t.Color,Euler:t.Euler,Float32BufferAttribute:t.Float32BufferAttribute,Group:t.Group,Line:t.Line,LineBasicMaterial:t.LineBasicMaterial,Matrix4:t.Matrix4,Mesh:t.Mesh,MeshLambertMaterial:t.MeshLambertMaterial,MeshStandardMaterial:t.MeshStandardMaterial,Points:t.Points,PointsMaterial:t.PointsMaterial,PerspectiveCamera:t.PerspectiveCamera,Scene:t.Scene,Vector3:t.Vector3};var n=class{providers;constructor(e){this.providers=e}async GetLayerByURI(e){let t=[];for(let r of this.providers){let i=await r.GetLayerByURI(e);if(!(i instanceof Error))return i;t.push(i)}return new Error(JSON.stringify(t))}},s=class{layers;constructor(){this.layers=new Map}GetLayerByURI(e){return this.layers.has(e)?Promise.resolve(this.layers.get(e)):new Error(`File with uri "${e}" not found`)}add(e){if(this.layers.has(e.header.id))throw new Error(`Inserting file with duplicate ID "${e.header.id}"`);return this.layers.set(e.header.id,e),this}AddAll(e){return e.forEach((e=>this.add(e))),this}};var a=class{layers;constructor(){this.layers=new Map}async FetchJson(e){let t=await fetch(e);if(!t.ok)return new Error(`Failed to fetch ${e}: ${t.status}`);try{return await t.json()}catch(t){return function(e){console.log(`${JSON.stringify(arguments)}`)}(e),new Error(`Failed to parse json at ${e}: ${t}`)}}async GetLayerByURI(e){if(!this.layers.has(e)){let t=await this.FetchJson(e);if(t instanceof Error)return new Error(`File with id "${e}" not found`);let r=t;return this.layers.set(e,r),r}return this.layers.get(e)}};function o(e,t,r){e.has(t)?e.get(t)?.push(r):e.set(t,[r])}var l=class extends Error{};function c(e){let t=new Map,r=new Map;e.forEach(((e,i)=>{Object.keys(e.inherits).forEach((n=>{o(t,i,e.inherits[n]),o(r,e.inherits[n],i)})),Object.keys(e.children).forEach((n=>{o(t,i,e.children[n]),o(r,e.children[n],i)}))}));let i=[...e.keys()],n={},s={};function a(e){if(n[e])return;if(s[e])throw new Error("CYCLE!");s[e]=!0;let r=t.get(e);r&&r.forEach((e=>a(e))),n[e]=!0}let l=new Set;try{i.forEach((e=>{r.has(e)||-1!==e.indexOf("/")||l.add(e),a(e)}))}catch(e){return null}return l}function h(e){return e.split("/")[0]}function u(e){let t=e.split("/");return t.shift(),t.join("/")}function f(e,t){if(""===t)return e;let r=t.split("/"),i=e.children.get(r[0]);return i?1===r.length?i:f(i,u(t)):null}function d(e,t){let r={path:e,children:{},inherits:{},attributes:{}};return t.forEach((e=>{Object.keys(e.children).forEach((t=>{r.children[t]=e.children[t]})),Object.keys(e.inherits).forEach((t=>{let i=e.inherits[t];null===i?delete r.inherits[t]:r.inherits[t]=i})),Object.keys(e.attributes).forEach((t=>{r.attributes[t]=e.attributes[t]}))})),r}function p(e,t){return w(e,{node:e,children:new Map,attributes:new Map},t)}function w(e,t,r){let i=r.get(e);var n,s,a;return i&&(n=i,s=t,a=r,Object.values(n.inherits).forEach((e=>{let t=f(p(h(e),a),u(e));if(!t)throw new Error(`Unknown node ${e}`);t.children.forEach(((e,t)=>{s.children.set(t,e)}));for(let[e,r]of t.attributes)s.attributes.set(e,r)})),Object.entries(n.children).forEach((([e,t])=>{if(null!==t){let r=f(p(h(t),a),u(t));if(!r)throw new Error(`Unknown node ${t}`);s.children.set(e,r)}else s.children.delete(e)})),Object.entries(n.attributes).forEach((([e,t])=>{s.attributes.set(e,t)}))),t.children.forEach(((t,i)=>{w(`${e}/${i}`,t,r)})),t}var y=class extends Error{};function b(e,t,r,i){if(!e.optional||void 0!==t)if(e.inherits&&e.inherits.forEach((n=>{let s=i[n];if(!s)throw new y(`Unknown inherited schema id "${e.inherits}"`);b(s.value,t,r,i)})),"Boolean"===e.dataType){if("boolean"!=typeof t)throw new y(`Expected "${t}" to be of type boolean`)}else if("String"===e.dataType){if("string"!=typeof t)throw new y(`Expected "${t}" to be of type string`)}else if("DateTime"===e.dataType){if("string"!=typeof t)throw new y(`Expected "${t}" to be of type date`)}else if("Enum"===e.dataType){if("string"!=typeof t)throw new y(`Expected "${t}" to be of type string`);if(!(1===e.enumRestrictions.options.filter((e=>e===t)).length))throw new y(`Expected "${t}" to be one of [${e.enumRestrictions.options.join(",")}]`)}else if("Integer"===e.dataType){if("number"!=typeof t)throw new y(`Expected "${t}" to be of type int`)}else if("Real"===e.dataType){if("number"!=typeof t)throw new y(`Expected "${t}" to be of type real`)}else if("Reference"===e.dataType){if("string"!=typeof t)throw new y(`Expected "${t}" to be of type string`)}else if("Object"===e.dataType){if("object"!=typeof t)throw new y(`Expected "${t}" to be of type object`);e.objectRestrictions&&Object.keys(e.objectRestrictions.values).forEach((n=>{let s=e.objectRestrictions.values[n].optional,a=Object.hasOwn(t,n);if(!s||a){if(!a)throw new y(`Expected "${t}" to have key ${n}`);b(e.objectRestrictions.values[n],t[n],r+"."+n,i)}}))}else{if("Array"!==e.dataType)throw new y(`Unexpected datatype ${e.dataType}`);if(!Array.isArray(t))throw new y(`Expected "${t}" to be of type array`);t.forEach((t=>{b(e.arrayRestrictions.value,t,r+".<array>.",i)}))}}function m(e,t){t.forEach((t=>{Object.keys(t.attributes).filter((e=>!e.startsWith("__internal"))).forEach((r=>{if(!e[r])throw new y(`Missing schema "${r}" referenced by ["${t.path}"].attributes`);let i=e[r],n=t.attributes[r];try{b(i.value,n,"",e)}catch(e){throw e instanceof y?new y(`Error validating ["${t.path}"].attributes["${r}"]: ${e.message}`):e}}))}))}function g(e){let t=new Map;return e.forEach((e=>{let r={path:e.path,children:e.children?e.children:{},inherits:e.inherits?e.inherits:{},attributes:e.attributes?e.attributes:{}};o(t,r.path,r)})),t}function E(e,t=!0,r=!0){let i=function(e){let t=new Map;for(let[r,i]of e)t.set(r,d(r,i));return t}(g(e.data));try{t&&m(e.schemas,i)}catch(e){throw e}return r?function(e){let t=c(e);if(!t)throw new l;let r={node:"",attributes:new Map,children:new Map};return t.forEach((t=>{r.children.set(t,p(t,e))})),r}(i):function(e){let t=c(e);if(!t)throw new l;return p([...t.values()][0],e)}(i)}function v(e){if(0===e.length)throw new Error("Trying to federate empty set of files");let t={header:e[0].header,schemas:{},data:[]};return e.forEach((e=>{Object.keys(e.schemas).forEach((r=>t.schemas[r]=e.schemas[r]))})),e.forEach((e=>{e.data.forEach((e=>t.data.push(e)))})),function(e,t=!1){let r={header:e.header,imports:[],schemas:e.schemas,data:[]};return g(e.data).forEach((e=>{let i=function(e,t=!1){let r={path:e[0].path,children:{},inherits:{},attributes:{}};if(e.forEach((e=>{Object.keys(e.children).forEach((t=>{r.children[t]=e.children[t]})),Object.keys(e.inherits).forEach((t=>{r.inherits[t]=e.inherits[t]})),Object.keys(e.attributes).forEach((t=>{r.attributes[t]=e.attributes[t]}))})),t){let e=!0;if(Object.keys(r.children).forEach((t=>{null!==r.children[t]&&(e=!1)})),Object.keys(r.inherits).forEach((t=>{null!==r.inherits[t]&&(e=!1)})),Object.keys(r.attributes).forEach((t=>{null!==r.attributes[t]&&(e=!1)})),e)return null}return r}(e,t);i&&r.data.push({path:i.path,children:i.children,inherits:i.inherits,attributes:i.attributes})})),r}(t)}var x,A,O=class{layers;tree;schemas;federated;constructor(e){this.layers=e,this.Compose()}GetLayerIds(){return this.layers.map((e=>e.header.id))}Compose(){this.federated=v(this.layers),this.schemas=this.federated.schemas,this.tree=E(this.federated)}GetFullTree(){return this.Compose(),this.tree}GetFederatedLayer(){return this.federated}GetSchemas(){return this.schemas}},F=class{provider;mainLayerId=null;constructor(e){this.provider=e}FromId(e){return this.mainLayerId=e,this}async Build(){if(!this.mainLayerId)throw new Error("no main layer ID specified");let e=await this.BuildLayerSet(this.mainLayerId);if(e instanceof Error)return e;try{return new O(e)}catch(e){return e}}async SatisfyDependencies(e,t,r){let i=[];for(const r of e.imports)if(!t.has(r.uri)){let e=await this.provider.GetLayerByURI(r.uri);if(e instanceof Error)return e;i.push(e),t.set(r.uri,!0)}let n=[];for(const e of i){n.push(e);let i=await this.SatisfyDependencies(e,t,r);if(i instanceof Error)return i;n.push(...i)}return n.forEach((e=>r.push(e))),n}async BuildLayerSet(e){let t=await this.provider.GetLayerByURI(e);if(t instanceof Error)return t;let r=[t],i=new Map;i.set(t.header.id,!0);let n=await this.SatisfyDependencies(t,i,r);return n instanceof Error?n:r}};function I(e,t,r){let i={name:e,attributes:{},children:[]};return t.children.forEach(((t,n)=>{i.children?.push(I(`${e}/${n}`,t,r))})),t.attributes.forEach(((e,t)=>{if(e&&"object"==typeof e&&!Array.isArray(e))Object.keys(e).forEach((r=>{i.attributes[`${t}::${r}`]=e[r]}));else{let n=r[t];if(n&&n.value.quantityKind){let r="",s=n.value.quantityKind;"Length"===s?r="m":"Volume"===s&&(r="m"+String.fromCodePoint(179)),i.attributes[t]=`${e} ${r}`}else i.attributes[t]=e}})),0===Object.keys(i.attributes).length&&delete i.attributes,i}async function z(e){let t={header:{...e[0].header},imports:e.map((e=>({uri:e.header.id}))),schemas:{},data:[]};t.header.id="USER_DEF";let r=new n([(new s).AddAll([t,...e]),new a]),i=await new F(r).FromId(t.header.id).Build();if(i instanceof Error)throw i;return i.GetFederatedLayer().data.forEach(((e,t)=>{e.attributes=e.attributes||{},e.attributes[`__internal_${t}`]=e.path})),I("",i.GetFullTree(),i.GetSchemas())}var B=[],L=!0,M={},S={};function _(e,t){return!(!e||!e.attributes)&&!!e.attributes[t]}function C(e){let t={color:new i.Color(.6,.6,.6),transparent:!1,opacity:1};for(let r of e){const e=r.attributes?r.attributes["bsi::ifc::presentation::diffuseColor"]:null;if(e){t.color=new i.Color(...e);const n=r.attributes["bsi::ifc::presentation::opacity"];n&&(t.transparent=!0,t.opacity=n);break}}return t}function $(e){let t=new Float32Array(e[0].attributes["usd::usdgeom::mesh::points"].flat()),r=new Uint16Array(e[0].attributes["usd::usdgeom::mesh::faceVertexIndices"]);const n=new i.BufferGeometry;var s;n.setAttribute("position",new i.BufferAttribute(t,3)),n.setIndex(new i.BufferAttribute(r,1)),n.computeVertexNormals();let a=function(e){for(let t of e){if(!t.attributes)continue;const e=t.attributes["gltf::material::pbrMetallicRoughness"],r=t.attributes["gltf::material::normalTexture"],n=t.attributes["gltf::material::occlusionTexture"],s=t.attributes["gltf::material::emissiveTexture"],a=t.attributes["gltf::material::emissiveFactor"],o=t.attributes["gltf::material::alphaMode"],l=t.attributes["gltf::material::alphaCutoff"],c=t.attributes["gltf::material::doubleSided"];if(!(e||r||n||s||a||o||l||c))continue;let h=new i.MeshStandardMaterial;if(h.color=new i.Color(1,1,1),h.metalness=1,h.roughness=1,e){let t=e.baseColorFactor;t&&(h.color=new i.Color(t[0],t[1],t[2]));let r=e.metallicFactor;void 0!==r&&(h.metalness=r);let n=e.roughnessFactor;void 0!==n&&(h.roughness=n)}return h.envMap=void 0,h.needsUpdate=!0,h.envMapRotation=new i.Euler(.5*Math.PI,0,0),h}}(e);if(a)s=a;else{const t=C(e);s=new i.MeshLambertMaterial({...t})}return new i.Mesh(n,s)}function j(e,t){const r=new i.PointsMaterial;return r.sizeAttenuation=!1,r.fog=!0,r.size=5,r.color=new i.Color(t?16777215:0),t&&(r.vertexColors=!0),new i.Points(e,r)}function D(e){let t;try{t=atob(e)}catch(e){throw new Error("base64 encoded string is invalid")}const r=new Uint8Array(t.length);for(let e=0;e<t.length;++e)r[e]=t.charCodeAt(e);return r.buffer}function T(e,t,n){const s=e[0];let a=new i.Group;if(_(s,"usd::usdgeom::visibility::visibility")){if("invisible"===s.attributes["usd::usdgeom::visibility::visibility"])return}else _(s,"usd::usdgeom::mesh::points")?a=$(e):_(s,"usd::usdgeom::basiscurves::points")?a=function(e){let t=new Float32Array(e[0].attributes["usd::usdgeom::basiscurves::points"].flat());const r=new i.BufferGeometry;r.setAttribute("position",new i.BufferAttribute(t,3));const n=C(e);let s=new i.LineBasicMaterial({...n});return s.color.multiplyScalar(.8),new i.Line(r,s)}(e):_(s,"pcd::base64")?a=function(e){const t=e[0].attributes["pcd::base64"],i=atob(t),n=i.length,s=new Uint8Array(n);for(let e=0;e<n;e++)s[e]=i.charCodeAt(e);const a=(new r).parse(s.buffer);return a.material.sizeAttenuation=!1,a.material.size=2,a}(e):_(s,"points::array::positions")?a=function(e){const t=new i.BufferGeometry,r=new Float32Array(e[0].attributes["points::array::positions"].flat());t.setAttribute("position",new i.Float32BufferAttribute(r,3));const n=e[0].attributes["points::array::colors"];if(n){const e=new Float32Array(n.flat());t.setAttribute("color",new i.Float32BufferAttribute(e,3))}return j(t,n)}(e):_(s,"points::base64::positions")&&(a=function(e){const t=new i.BufferGeometry,r=D(e[0].attributes["points::base64::positions"]);if(!r)return null;const n=new Float32Array(r);t.setAttribute("position",new i.Float32BufferAttribute(n,3));const s=e[0].attributes["points::base64::colors"];if(s){const e=D(s);if(e){const r=new Float32Array(e);t.setAttribute("color",new i.Float32BufferAttribute(r,3))}}return j(t,s)}(e));M[s.name]=a,S[s.name]=s,a.userData.path=s.name;for(let e of Object.entries(s.attributes||{}).filter((([e,t])=>e.startsWith("__internal_"))).map((([e,t])=>t)))(n[String(e)]=n[String(e)]||[]).push(s.name);if(t.add(a),e.length>1){a.matrixAutoUpdate=!1;let e=s.attributes&&s.attributes["usd::xformop::transform"]?s.attributes["usd::xformop::transform"].flat():null;if(e){let t=new i.Matrix4;t.set(...e),t.transpose(),a.matrix=t}}(s.children||[]).forEach((r=>T([r,...e],a||t,n)))}async function U(){if(x&&(x.children=[]),M={},S={},0===B.length)return;let e=null,t=B.map((e=>e[1]));if(e=await z(t),!e)return void console.error("No result from composition");x||(x=new i.Scene,(A=new i.PerspectiveCamera(75,window.innerWidth/window.innerHeight,.1,100)).up.set(0,0,1),A.position.set(50,50,50),A.lookAt(0,0,0),x.add(A));if(T([e],x,{}),L){const e=new i.Box3;if(e.setFromObject(x),!e.isEmpty()){let t=e.min.clone().add(e.max).multiplyScalar(.5),r=e.max.clone().sub(e.min).length();A.position.copy(t.clone().add(new i.Vector3(1,1,1).normalize().multiplyScalar(r))),A.far=3*r,A.updateProjectionMatrix(),L=!1}}}async function G(e,t){return B.push([t,e]),await U(),x}function R(){x=void 0,B.length=0,L=!0}class k extends t.Loader{load(e,r,i,n){const s=this.manager;s.itemStart(e);const a=t=>{r(t),s.itemEnd(e)},o=t=>{n?n(t):console.error(t),s.itemError(e),s.itemEnd(e)},l=new t.FileLoader(this.manager);l.setPath(this.path),l.setResponseType("json"),l.setRequestHeader(this.requestHeader),l.setWithCredentials(this.withCredentials),l.load(e,(e=>this.parse(e,a,o)),i,n)}parse(e,t,r){G(e).then((e=>t(e))).catch((e=>r(e))).finally((()=>R()))}}class V extends e.Loader{constructor(e){super(),this.viewer=e}isSupport(e,t){return("string"==typeof e||e instanceof globalThis.File||e instanceof ArrayBuffer)&&/(ifcx)$/i.test(t)}async load(t,r,i){const n=new e.GLTFLoadingManager(t,i),s=new k(n);s.setPath(n.path),s.setCrossOrigin(i.crossOrigin||s.crossOrigin),s.setWithCredentials(i.withCredentials||s.withCredentials);const a=await s.loadAsync(n.fileURL,(e=>{const{lengthComputable:r,loaded:i,total:n}=e,s=r?i/n:1;this.viewer.emitEvent({type:"geometryprogress",data:s,file:t})}));if(!this.viewer.scene)return this;let o=0;a.traverse((e=>{e.userData={handle:o,...e.userData},o++}));const l=new e.ModelImpl(a);return l.loader=this,l.viewer=this.viewer,this.viewer.scene.add(a),this.viewer.models.push(l),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.update(),this.viewer.emitEvent({type:"databasechunk",data:a,file:t}),this}}class P extends e.Loader{constructor(e){super(),this.viewer=e}isSupport(e){return"object"==typeof e&&"string"==typeof e.type&&"function"==typeof e.download&&/.ifcx$/i.test(e.type)}async load(t){const r=await t.download((e=>{this.viewer.emitEvent({type:"geometryprogress",data:e,file:t})}),this.abortController.signal);if(!this.viewer.scene)return this;const i=new TextDecoder,n=JSON.parse(i.decode(r)),s=await G(n);R();let a=0;s.traverse((e=>{e.userData={handle:a,...e.userData},a++}));const o=new e.ModelImpl(s);return o.loader=this,o.viewer=this.viewer,this.viewer.scene.add(s),this.viewer.models.push(o),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.update(),this.viewer.emitEvent({type:"databasechunk",data:s,file:t}),this}}e.loaders.registerLoader("ifcx-file",(e=>new V(e))),e.loaders.registerLoader("ifcx-cloud",(e=>new P(e)))}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("@inweb/viewer-three"),require("three")):"function"==typeof define&&define.amd?define(["@inweb/viewer-three","three"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ODA.Three,e.THREE)}(this,function(e,t){"use strict";class r extends t.Loader{constructor(e){super(e),this.littleEndian=!0}load(e,r,i,n){const s=this,a=new t.FileLoader(s.manager);a.setPath(s.path),a.setResponseType("arraybuffer"),a.setRequestHeader(s.requestHeader),a.setWithCredentials(s.withCredentials),a.load(e,function(t){try{r(s.parse(t))}catch(t){n?n(t):console.error(t),s.manager.itemError(e)}},i,n)}_getDataView(e,t,r,i){switch(r){case"F":return 8===i?e.getFloat64(t,this.littleEndian):e.getFloat32(t,this.littleEndian);case"I":return 1===i?e.getInt8(t):2===i?e.getInt16(t,this.littleEndian):e.getInt32(t,this.littleEndian);case"U":return 1===i?e.getUint8(t):2===i?e.getUint16(t,this.littleEndian):e.getUint32(t,this.littleEndian)}}parse(e){const r=function(e){const t={},r=new Uint8Array(e);let i="",n="",s=0,a=!1;const o=r.length;for(;s<o&&!1===a;){const e=String.fromCharCode(r[s++]);"\n"===e||"\r"===e?(n.trim().toLowerCase().startsWith("data")&&(a=!0),n=""):n+=e,i+=e}const l=i.search(/[\r\n]DATA\s(\S*)\s/i),c=/[\r\n]DATA\s(\S*)\s/i.exec(i.slice(l-1));if(t.data=c[1],t.headerLen=c[0].length+l,t.str=i.slice(0,t.headerLen),t.str=t.str.replace(/#.*/gi,""),t.version=/^VERSION (.*)/im.exec(t.str),t.fields=/^FIELDS (.*)/im.exec(t.str),t.size=/^SIZE (.*)/im.exec(t.str),t.type=/^TYPE (.*)/im.exec(t.str),t.count=/^COUNT (.*)/im.exec(t.str),t.width=/^WIDTH (.*)/im.exec(t.str),t.height=/^HEIGHT (.*)/im.exec(t.str),t.viewpoint=/^VIEWPOINT (.*)/im.exec(t.str),t.points=/^POINTS (.*)/im.exec(t.str),null!==t.version&&(t.version=parseFloat(t.version[1])),t.fields=null!==t.fields?t.fields[1].split(" "):[],null!==t.type&&(t.type=t.type[1].split(" ")),null!==t.width&&(t.width=parseInt(t.width[1])),null!==t.height&&(t.height=parseInt(t.height[1])),null!==t.viewpoint&&(t.viewpoint=t.viewpoint[1]),null!==t.points&&(t.points=parseInt(t.points[1],10)),null===t.points&&(t.points=t.width*t.height),null!==t.size&&(t.size=t.size[1].split(" ").map(function(e){return parseInt(e,10)})),null!==t.count)t.count=t.count[1].split(" ").map(function(e){return parseInt(e,10)});else{t.count=[];for(let e=0,r=t.fields.length;e<r;e++)t.count.push(1)}t.offset={};let h=0;for(let e=0,r=t.fields.length;e<r;e++)"ascii"===t.data?t.offset[t.fields[e]]=e:(t.offset[t.fields[e]]=h,h+=t.size[e]*t.count[e]);return t.rowSize=h,t}(e),i=[],n=[],s=[],a=[],o=[],l=new t.Color;if("ascii"===r.data){const c=r.offset,h=(new TextDecoder).decode(e).slice(r.headerLen).split("\n");for(let e=0,u=h.length;e<u;e++){if(""===h[e])continue;const u=h[e].split(" ");if(void 0!==c.x&&(i.push(parseFloat(u[c.x])),i.push(parseFloat(u[c.y])),i.push(parseFloat(u[c.z]))),void 0!==c.rgb){const e=r.fields.findIndex(e=>"rgb"===e),i=r.type[e],n=parseFloat(u[c.rgb]);let a=n;if("F"===i){const e=new Float32Array(1);e[0]=n,a=new Int32Array(e.buffer)[0]}const o=(a>>16&255)/255,h=(a>>8&255)/255,f=(255&a)/255;l.setRGB(o,h,f,t.SRGBColorSpace),s.push(l.r,l.g,l.b)}void 0!==c.normal_x&&(n.push(parseFloat(u[c.normal_x])),n.push(parseFloat(u[c.normal_y])),n.push(parseFloat(u[c.normal_z]))),void 0!==c.intensity&&a.push(parseFloat(u[c.intensity])),void 0!==c.label&&o.push(parseInt(u[c.label]))}}if("binary_compressed"===r.data){const c=new Uint32Array(e.slice(r.headerLen,r.headerLen+8)),h=c[0],u=c[1],f=function(e,t){const r=e.length,i=new Uint8Array(t);let n,s,a,o=0,l=0;do{if(n=e[o++],n<32){if(n++,l+n>t)throw new Error("Output buffer is not large enough");if(o+n>r)throw new Error("Invalid compressed data");do{i[l++]=e[o++]}while(--n)}else{if(s=n>>5,a=l-((31&n)<<8)-1,o>=r)throw new Error("Invalid compressed data");if(7===s&&(s+=e[o++],o>=r))throw new Error("Invalid compressed data");if(a-=e[o++],l+s+2>t)throw new Error("Output buffer is not large enough");if(a<0)throw new Error("Invalid compressed data");if(a>=l)throw new Error("Invalid compressed data");do{i[l++]=i[a++]}while(2+--s)}}while(o<r);return i}(new Uint8Array(e,r.headerLen+8,h),u),d=new DataView(f.buffer),p=r.offset;for(let e=0;e<r.points;e++){if(void 0!==p.x){const t=r.fields.indexOf("x"),n=r.fields.indexOf("y"),s=r.fields.indexOf("z");i.push(this._getDataView(d,r.points*p.x+r.size[t]*e,r.type[t],r.size[t])),i.push(this._getDataView(d,r.points*p.y+r.size[n]*e,r.type[n],r.size[n])),i.push(this._getDataView(d,r.points*p.z+r.size[s]*e,r.type[s],r.size[s]))}if(void 0!==p.rgb){const i=r.fields.indexOf("rgb"),n=d.getUint8(r.points*p.rgb+r.size[i]*e+2)/255,a=d.getUint8(r.points*p.rgb+r.size[i]*e+1)/255,o=d.getUint8(r.points*p.rgb+r.size[i]*e+0)/255;l.setRGB(n,a,o,t.SRGBColorSpace),s.push(l.r,l.g,l.b)}if(void 0!==p.normal_x){const t=r.fields.indexOf("normal_x"),i=r.fields.indexOf("normal_y"),s=r.fields.indexOf("normal_z");n.push(this._getDataView(d,r.points*p.normal_x+r.size[t]*e,r.type[t],r.size[t])),n.push(this._getDataView(d,r.points*p.normal_y+r.size[i]*e,r.type[i],r.size[i])),n.push(this._getDataView(d,r.points*p.normal_z+r.size[s]*e,r.type[s],r.size[s]))}if(void 0!==p.intensity){const t=r.fields.indexOf("intensity");a.push(this._getDataView(d,r.points*p.intensity+r.size[t]*e,r.type[t],r.size[t]))}if(void 0!==p.label){const t=r.fields.indexOf("label");o.push(d.getInt32(r.points*p.label+r.size[t]*e,this.littleEndian))}}}if("binary"===r.data){const c=new DataView(e,r.headerLen),h=r.offset;for(let e=0,u=0;e<r.points;e++,u+=r.rowSize){if(void 0!==h.x){const e=r.fields.indexOf("x"),t=r.fields.indexOf("y"),n=r.fields.indexOf("z");i.push(this._getDataView(c,u+h.x,r.type[e],r.size[e])),i.push(this._getDataView(c,u+h.y,r.type[t],r.size[t])),i.push(this._getDataView(c,u+h.z,r.type[n],r.size[n]))}if(void 0!==h.rgb){const e=c.getUint8(u+h.rgb+2)/255,r=c.getUint8(u+h.rgb+1)/255,i=c.getUint8(u+h.rgb+0)/255;l.setRGB(e,r,i,t.SRGBColorSpace),s.push(l.r,l.g,l.b)}if(void 0!==h.normal_x){const e=r.fields.indexOf("normal_x"),t=r.fields.indexOf("normal_y"),i=r.fields.indexOf("normal_z");n.push(this._getDataView(c,u+h.normal_x,r.type[e],r.size[e])),n.push(this._getDataView(c,u+h.normal_y,r.type[t],r.size[t])),n.push(this._getDataView(c,u+h.normal_z,r.type[i],r.size[i]))}if(void 0!==h.intensity){const e=r.fields.indexOf("intensity");a.push(this._getDataView(c,u+h.intensity,r.type[e],r.size[e]))}void 0!==h.label&&o.push(c.getInt32(u+h.label,this.littleEndian))}}const c=new t.BufferGeometry;i.length>0&&c.setAttribute("position",new t.Float32BufferAttribute(i,3)),n.length>0&&c.setAttribute("normal",new t.Float32BufferAttribute(n,3)),s.length>0&&c.setAttribute("color",new t.Float32BufferAttribute(s,3)),a.length>0&&c.setAttribute("intensity",new t.Float32BufferAttribute(a,1)),o.length>0&&c.setAttribute("label",new t.Int32BufferAttribute(o,1)),c.computeBoundingSphere();const h=new t.PointsMaterial({size:.005});return s.length>0&&(h.vertexColors=!0),new t.Points(c,h)}}const i={Box3:t.Box3,BufferAttribute:t.BufferAttribute,BufferGeometry:t.BufferGeometry,Color:t.Color,Euler:t.Euler,Float32BufferAttribute:t.Float32BufferAttribute,Group:t.Group,Line:t.Line,LineBasicMaterial:t.LineBasicMaterial,Matrix4:t.Matrix4,Mesh:t.Mesh,MeshLambertMaterial:t.MeshLambertMaterial,MeshStandardMaterial:t.MeshStandardMaterial,Points:t.Points,PointsMaterial:t.PointsMaterial,PerspectiveCamera:t.PerspectiveCamera,Scene:t.Scene,Vector3:t.Vector3};var n=class{providers;constructor(e){this.providers=e}async GetLayerByURI(e){let t=[];for(let r of this.providers){let i=await r.GetLayerByURI(e);if(!(i instanceof Error))return i;t.push(i)}return new Error(JSON.stringify(t))}},s=class{layers;constructor(){this.layers=new Map}GetLayerByURI(e){return this.layers.has(e)?Promise.resolve(this.layers.get(e)):new Error(`File with uri "${e}" not found`)}add(e){if(this.layers.has(e.header.id))throw new Error(`Inserting file with duplicate ID "${e.header.id}"`);return this.layers.set(e.header.id,e),this}AddAll(e){return e.forEach(e=>this.add(e)),this}};var a=class{layers;constructor(){this.layers=new Map}async FetchJson(e){let t=await fetch(e);if(!t.ok)return new Error(`Failed to fetch ${e}: ${t.status}`);try{return await t.json()}catch(t){return function(e){console.log(`${JSON.stringify(arguments)}`)}(e),new Error(`Failed to parse json at ${e}: ${t}`)}}async GetLayerByURI(e){if(!this.layers.has(e)){let t=await this.FetchJson(e);if(t instanceof Error)return new Error(`File with id "${e}" not found`);let r=t;return this.layers.set(e,r),r}return this.layers.get(e)}};function o(e,t,r){e.has(t)?e.get(t)?.push(r):e.set(t,[r])}var l=class extends Error{};function c(e){let t=new Map,r=new Map;e.forEach((e,i)=>{Object.keys(e.inherits).forEach(n=>{o(t,i,e.inherits[n]),o(r,e.inherits[n],i)}),Object.keys(e.children).forEach(n=>{o(t,i,e.children[n]),o(r,e.children[n],i)})});let i=[...e.keys()],n={},s={};function a(e){if(n[e])return;if(s[e])throw new Error("CYCLE!");s[e]=!0;let r=t.get(e);r&&r.forEach(e=>a(e)),n[e]=!0}let l=new Set;try{i.forEach(e=>{r.has(e)||-1!==e.indexOf("/")||l.add(e),a(e)})}catch(e){return null}return l}function h(e){return e.split("/")[0]}function u(e){let t=e.split("/");return t.shift(),t.join("/")}function f(e,t){if(""===t)return e;let r=t.split("/"),i=e.children.get(r[0]);return i?1===r.length?i:f(i,u(t)):null}function d(e,t){let r={path:e,children:{},inherits:{},attributes:{}};return t.forEach(e=>{Object.keys(e.children).forEach(t=>{r.children[t]=e.children[t]}),Object.keys(e.inherits).forEach(t=>{let i=e.inherits[t];null===i?delete r.inherits[t]:r.inherits[t]=i}),Object.keys(e.attributes).forEach(t=>{r.attributes[t]=e.attributes[t]})}),r}function p(e,t){return w(e,{node:e,children:new Map,attributes:new Map},t)}function w(e,t,r){let i=r.get(e);var n,s,a;return i&&(n=i,s=t,a=r,Object.values(n.inherits).forEach(e=>{let t=f(p(h(e),a),u(e));if(!t)throw new Error(`Unknown node ${e}`);t.children.forEach((e,t)=>{s.children.set(t,e)});for(let[e,r]of t.attributes)s.attributes.set(e,r)}),Object.entries(n.children).forEach(([e,t])=>{if(null!==t){let r=f(p(h(t),a),u(t));if(!r)throw new Error(`Unknown node ${t}`);s.children.set(e,r)}else s.children.delete(e)}),Object.entries(n.attributes).forEach(([e,t])=>{s.attributes.set(e,t)})),t.children.forEach((t,i)=>{w(`${e}/${i}`,t,r)}),t}var y=class extends Error{};function b(e,t,r,i){if(!e.optional||void 0!==t)if(e.inherits&&e.inherits.forEach(n=>{let s=i[n];if(!s)throw new y(`Unknown inherited schema id "${e.inherits}"`);b(s.value,t,r,i)}),"Boolean"===e.dataType){if("boolean"!=typeof t)throw new y(`Expected "${t}" to be of type boolean`)}else if("String"===e.dataType){if("string"!=typeof t)throw new y(`Expected "${t}" to be of type string`)}else if("DateTime"===e.dataType){if("string"!=typeof t)throw new y(`Expected "${t}" to be of type date`)}else if("Enum"===e.dataType){if("string"!=typeof t)throw new y(`Expected "${t}" to be of type string`);if(!(1===e.enumRestrictions.options.filter(e=>e===t).length))throw new y(`Expected "${t}" to be one of [${e.enumRestrictions.options.join(",")}]`)}else if("Integer"===e.dataType){if("number"!=typeof t)throw new y(`Expected "${t}" to be of type int`)}else if("Real"===e.dataType){if("number"!=typeof t)throw new y(`Expected "${t}" to be of type real`)}else if("Reference"===e.dataType){if("string"!=typeof t)throw new y(`Expected "${t}" to be of type string`)}else if("Object"===e.dataType){if("object"!=typeof t)throw new y(`Expected "${t}" to be of type object`);e.objectRestrictions&&Object.keys(e.objectRestrictions.values).forEach(n=>{let s=e.objectRestrictions.values[n].optional,a=Object.hasOwn(t,n);if(!s||a){if(!a)throw new y(`Expected "${t}" to have key ${n}`);b(e.objectRestrictions.values[n],t[n],r+"."+n,i)}})}else{if("Array"!==e.dataType)throw new y(`Unexpected datatype ${e.dataType}`);if(!Array.isArray(t))throw new y(`Expected "${t}" to be of type array`);t.forEach(t=>{b(e.arrayRestrictions.value,t,r+".<array>.",i)})}}function m(e,t){t.forEach(t=>{Object.keys(t.attributes).filter(e=>!e.startsWith("__internal")).forEach(r=>{if(!e[r])throw new y(`Missing schema "${r}" referenced by ["${t.path}"].attributes`);let i=e[r],n=t.attributes[r];try{b(i.value,n,"",e)}catch(e){throw e instanceof y?new y(`Error validating ["${t.path}"].attributes["${r}"]: ${e.message}`):e}})})}function g(e){let t=new Map;return e.forEach(e=>{let r={path:e.path,children:e.children?e.children:{},inherits:e.inherits?e.inherits:{},attributes:e.attributes?e.attributes:{}};o(t,r.path,r)}),t}function E(e,t=!0,r=!0){let i=function(e){let t=new Map;for(let[r,i]of e)t.set(r,d(r,i));return t}(g(e.data));try{t&&m(e.schemas,i)}catch(e){throw e}return r?function(e){let t=c(e);if(!t)throw new l;let r={node:"",attributes:new Map,children:new Map};return t.forEach(t=>{r.children.set(t,p(t,e))}),r}(i):function(e){let t=c(e);if(!t)throw new l;return p([...t.values()][0],e)}(i)}function v(e){if(0===e.length)throw new Error("Trying to federate empty set of files");let t={header:e[0].header,schemas:{},data:[]};return e.forEach(e=>{Object.keys(e.schemas).forEach(r=>t.schemas[r]=e.schemas[r])}),e.forEach(e=>{e.data.forEach(e=>t.data.push(e))}),function(e,t=!1){let r={header:e.header,imports:[],schemas:e.schemas,data:[]};return g(e.data).forEach(e=>{let i=function(e,t=!1){let r={path:e[0].path,children:{},inherits:{},attributes:{}};if(e.forEach(e=>{Object.keys(e.children).forEach(t=>{r.children[t]=e.children[t]}),Object.keys(e.inherits).forEach(t=>{r.inherits[t]=e.inherits[t]}),Object.keys(e.attributes).forEach(t=>{r.attributes[t]=e.attributes[t]})}),t){let e=!0;if(Object.keys(r.children).forEach(t=>{null!==r.children[t]&&(e=!1)}),Object.keys(r.inherits).forEach(t=>{null!==r.inherits[t]&&(e=!1)}),Object.keys(r.attributes).forEach(t=>{null!==r.attributes[t]&&(e=!1)}),e)return null}return r}(e,t);i&&r.data.push({path:i.path,children:i.children,inherits:i.inherits,attributes:i.attributes})}),r}(t)}var x,A,O=class{layers;tree;schemas;federated;constructor(e){this.layers=e,this.Compose()}GetLayerIds(){return this.layers.map(e=>e.header.id)}Compose(){this.federated=v(this.layers),this.schemas=this.federated.schemas,this.tree=E(this.federated)}GetFullTree(){return this.Compose(),this.tree}GetFederatedLayer(){return this.federated}GetSchemas(){return this.schemas}},F=class{provider;mainLayerId=null;constructor(e){this.provider=e}FromId(e){return this.mainLayerId=e,this}async Build(){if(!this.mainLayerId)throw new Error("no main layer ID specified");let e=await this.BuildLayerSet(this.mainLayerId);if(e instanceof Error)return e;try{return new O(e)}catch(e){return e}}async SatisfyDependencies(e,t,r){let i=[];for(const r of e.imports)if(!t.has(r.uri)){let e=await this.provider.GetLayerByURI(r.uri);if(e instanceof Error)return e;i.push(e),t.set(r.uri,!0)}let n=[];for(const e of i){n.push(e);let i=await this.SatisfyDependencies(e,t,r);if(i instanceof Error)return i;n.push(...i)}return n.forEach(e=>r.push(e)),n}async BuildLayerSet(e){let t=await this.provider.GetLayerByURI(e);if(t instanceof Error)return t;let r=[t],i=new Map;i.set(t.header.id,!0);let n=await this.SatisfyDependencies(t,i,r);return n instanceof Error?n:r}};function I(e,t,r){let i={name:e,attributes:{},children:[]};return t.children.forEach((t,n)=>{i.children?.push(I(`${e}/${n}`,t,r))}),t.attributes.forEach((e,t)=>{if(e&&"object"==typeof e&&!Array.isArray(e))Object.keys(e).forEach(r=>{i.attributes[`${t}::${r}`]=e[r]});else{let n=r[t];if(n&&n.value.quantityKind){let r="",s=n.value.quantityKind;"Length"===s?r="m":"Volume"===s&&(r="m"+String.fromCodePoint(179)),i.attributes[t]=`${e} ${r}`}else i.attributes[t]=e}}),0===Object.keys(i.attributes).length&&delete i.attributes,i}async function z(e){let t={header:{...e[0].header},imports:e.map(e=>({uri:e.header.id})),schemas:{},data:[]};t.header.id="USER_DEF";let r=new n([(new s).AddAll([t,...e]),new a]),i=await new F(r).FromId(t.header.id).Build();if(i instanceof Error)throw i;return i.GetFederatedLayer().data.forEach((e,t)=>{e.attributes=e.attributes||{},e.attributes[`__internal_${t}`]=e.path}),I("",i.GetFullTree(),i.GetSchemas())}var B=[],L=!0,M={},S={};function _(e,t){return!(!e||!e.attributes)&&!!e.attributes[t]}function C(e){let t={color:new i.Color(.6,.6,.6),transparent:!1,opacity:1};for(let r of e){const e=r.attributes?r.attributes["bsi::ifc::presentation::diffuseColor"]:null;if(e){t.color=new i.Color(...e);const n=r.attributes["bsi::ifc::presentation::opacity"];n&&(t.transparent=!0,t.opacity=n);break}}return t}function $(e){let t=new Float32Array(e[0].attributes["usd::usdgeom::mesh::points"].flat()),r=new Uint16Array(e[0].attributes["usd::usdgeom::mesh::faceVertexIndices"]);const n=new i.BufferGeometry;var s;n.setAttribute("position",new i.BufferAttribute(t,3)),n.setIndex(new i.BufferAttribute(r,1)),n.computeVertexNormals();let a=function(e){for(let t of e){if(!t.attributes)continue;const e=t.attributes["gltf::material::pbrMetallicRoughness"],r=t.attributes["gltf::material::normalTexture"],n=t.attributes["gltf::material::occlusionTexture"],s=t.attributes["gltf::material::emissiveTexture"],a=t.attributes["gltf::material::emissiveFactor"],o=t.attributes["gltf::material::alphaMode"],l=t.attributes["gltf::material::alphaCutoff"],c=t.attributes["gltf::material::doubleSided"];if(!(e||r||n||s||a||o||l||c))continue;let h=new i.MeshStandardMaterial;if(h.color=new i.Color(1,1,1),h.metalness=1,h.roughness=1,e){let t=e.baseColorFactor;t&&(h.color=new i.Color(t[0],t[1],t[2]));let r=e.metallicFactor;void 0!==r&&(h.metalness=r);let n=e.roughnessFactor;void 0!==n&&(h.roughness=n)}return h.envMap=void 0,h.needsUpdate=!0,h.envMapRotation=new i.Euler(.5*Math.PI,0,0),h}}(e);if(a)s=a;else{const t=C(e);s=new i.MeshLambertMaterial({...t})}return new i.Mesh(n,s)}function j(e,t){const r=new i.PointsMaterial;return r.sizeAttenuation=!1,r.fog=!0,r.size=5,r.color=new i.Color(t?16777215:0),t&&(r.vertexColors=!0),new i.Points(e,r)}function D(e){let t;try{t=atob(e)}catch(e){throw new Error("base64 encoded string is invalid")}const r=new Uint8Array(t.length);for(let e=0;e<t.length;++e)r[e]=t.charCodeAt(e);return r.buffer}function T(e,t,n){const s=e[0];let a=new i.Group;if(_(s,"usd::usdgeom::visibility::visibility")){if("invisible"===s.attributes["usd::usdgeom::visibility::visibility"])return}else _(s,"usd::usdgeom::mesh::points")?a=$(e):_(s,"usd::usdgeom::basiscurves::points")?a=function(e){let t=new Float32Array(e[0].attributes["usd::usdgeom::basiscurves::points"].flat());const r=new i.BufferGeometry;r.setAttribute("position",new i.BufferAttribute(t,3));const n=C(e);let s=new i.LineBasicMaterial({...n});return s.color.multiplyScalar(.8),new i.Line(r,s)}(e):_(s,"pcd::base64")?a=function(e){const t=e[0].attributes["pcd::base64"],i=atob(t),n=i.length,s=new Uint8Array(n);for(let e=0;e<n;e++)s[e]=i.charCodeAt(e);const a=(new r).parse(s.buffer);return a.material.sizeAttenuation=!1,a.material.size=2,a}(e):_(s,"points::array::positions")?a=function(e){const t=new i.BufferGeometry,r=new Float32Array(e[0].attributes["points::array::positions"].flat());t.setAttribute("position",new i.Float32BufferAttribute(r,3));const n=e[0].attributes["points::array::colors"];if(n){const e=new Float32Array(n.flat());t.setAttribute("color",new i.Float32BufferAttribute(e,3))}return j(t,n)}(e):_(s,"points::base64::positions")&&(a=function(e){const t=new i.BufferGeometry,r=D(e[0].attributes["points::base64::positions"]);if(!r)return null;const n=new Float32Array(r);t.setAttribute("position",new i.Float32BufferAttribute(n,3));const s=e[0].attributes["points::base64::colors"];if(s){const e=D(s);if(e){const r=new Float32Array(e);t.setAttribute("color",new i.Float32BufferAttribute(r,3))}}return j(t,s)}(e));M[s.name]=a,S[s.name]=s,a.userData.path=s.name;for(let e of Object.entries(s.attributes||{}).filter(([e,t])=>e.startsWith("__internal_")).map(([e,t])=>t))(n[String(e)]=n[String(e)]||[]).push(s.name);if(t.add(a),e.length>1){a.matrixAutoUpdate=!1;let e=s.attributes&&s.attributes["usd::xformop::transform"]?s.attributes["usd::xformop::transform"].flat():null;if(e){let t=new i.Matrix4;t.set(...e),t.transpose(),a.matrix=t}}(s.children||[]).forEach(r=>T([r,...e],a||t,n))}async function U(){if(x&&(x.children=[]),M={},S={},0===B.length)return;let e=null,t=B.map(e=>e[1]);if(e=await z(t),!e)return void console.error("No result from composition");x||(x=new i.Scene,(A=new i.PerspectiveCamera(75,window.innerWidth/window.innerHeight,.1,100)).up.set(0,0,1),A.position.set(50,50,50),A.lookAt(0,0,0),x.add(A));if(T([e],x,{}),L){const e=new i.Box3;if(e.setFromObject(x),!e.isEmpty()){let t=e.min.clone().add(e.max).multiplyScalar(.5),r=e.max.clone().sub(e.min).length();A.position.copy(t.clone().add(new i.Vector3(1,1,1).normalize().multiplyScalar(r))),A.far=3*r,A.updateProjectionMatrix(),L=!1}}}async function G(e,t){return B.push([t,e]),await U(),x}function R(){x=void 0,B.length=0,L=!0}class k extends t.Loader{load(e,r,i,n){const s=this.manager;s.itemStart(e);const a=t=>{r(t),s.itemEnd(e)},o=t=>{n?n(t):console.error(t),s.itemError(e),s.itemEnd(e)},l=new t.FileLoader(this.manager);l.setPath(this.path),l.setResponseType("json"),l.setRequestHeader(this.requestHeader),l.setWithCredentials(this.withCredentials),l.load(e,e=>this.parse(e,a,o),i,n)}parse(e,t,r){G(e).then(e=>t(e)).catch(e=>r(e)).finally(()=>R())}}class V extends e.Loader{constructor(e){super(),this.viewer=e}isSupport(e,t){return("string"==typeof e||e instanceof globalThis.File||e instanceof ArrayBuffer)&&/(ifcx)$/i.test(t)}async load(t,r,i){const n=new e.GLTFLoadingManager(t,i),s=new k(n);s.setPath(n.path),s.setCrossOrigin(i.crossOrigin||s.crossOrigin),s.setWithCredentials(i.withCredentials||s.withCredentials);const a=await s.loadAsync(n.fileURL,e=>{const{lengthComputable:r,loaded:i,total:n}=e,s=r?i/n:1;this.viewer.emitEvent({type:"geometryprogress",data:s,file:t})});if(!this.viewer.scene)return this;let o=0;a.traverse(e=>{e.userData={handle:o,...e.userData},o++});const l=new e.ModelImpl(a);return l.loader=this,l.viewer=this.viewer,this.viewer.scene.add(a),this.viewer.models.push(l),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.update(),this.viewer.emitEvent({type:"databasechunk",data:a,file:t}),this}}class P extends e.Loader{constructor(e){super(),this.viewer=e}isSupport(e){return"object"==typeof e&&"string"==typeof e.type&&"function"==typeof e.download&&/.ifcx$/i.test(e.type)}async load(t){const r=await t.download(e=>{this.viewer.emitEvent({type:"geometryprogress",data:e,file:t})},this.abortController.signal);if(!this.viewer.scene)return this;const i=new TextDecoder,n=JSON.parse(i.decode(r)),s=await G(n);R();let a=0;s.traverse(e=>{e.userData={handle:a,...e.userData},a++});const o=new e.ModelImpl(s);return o.loader=this,o.viewer=this.viewer,this.viewer.scene.add(s),this.viewer.models.push(o),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.update(),this.viewer.emitEvent({type:"databasechunk",data:s,file:t}),this}}e.loaders.registerLoader("ifcx-file",e=>new V(e)),e.loaders.registerLoader("ifcx-cloud",e=>new P(e))});
|
|
@@ -63,7 +63,7 @@ var InMemoryLayerProvider = class {
|
|
|
63
63
|
return this;
|
|
64
64
|
}
|
|
65
65
|
AddAll(files) {
|
|
66
|
-
files.forEach(
|
|
66
|
+
files.forEach(f => this.add(f));
|
|
67
67
|
return this;
|
|
68
68
|
}
|
|
69
69
|
};
|
|
@@ -118,16 +118,16 @@ var CycleError = class extends Error {};
|
|
|
118
118
|
function FindRootsOrCycles(nodes) {
|
|
119
119
|
let dependencies = new Map;
|
|
120
120
|
let dependents = new Map;
|
|
121
|
-
nodes.forEach((
|
|
122
|
-
Object.keys(node.inherits).forEach(
|
|
121
|
+
nodes.forEach((node, path) => {
|
|
122
|
+
Object.keys(node.inherits).forEach(inheritName => {
|
|
123
123
|
MMSet(dependencies, path, node.inherits[inheritName]);
|
|
124
124
|
MMSet(dependents, node.inherits[inheritName], path);
|
|
125
|
-
})
|
|
126
|
-
Object.keys(node.children).forEach(
|
|
125
|
+
});
|
|
126
|
+
Object.keys(node.children).forEach(childName => {
|
|
127
127
|
MMSet(dependencies, path, node.children[childName]);
|
|
128
128
|
MMSet(dependents, node.children[childName], path);
|
|
129
|
-
})
|
|
130
|
-
})
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
131
|
let paths = [ ...nodes.keys() ];
|
|
132
132
|
let perm = {};
|
|
133
133
|
let temp = {};
|
|
@@ -137,18 +137,18 @@ function FindRootsOrCycles(nodes) {
|
|
|
137
137
|
temp[path] = true;
|
|
138
138
|
let deps = dependencies.get(path);
|
|
139
139
|
if (deps) {
|
|
140
|
-
deps.forEach(
|
|
140
|
+
deps.forEach(dep => visit(dep));
|
|
141
141
|
}
|
|
142
142
|
perm[path] = true;
|
|
143
143
|
}
|
|
144
144
|
let roots = new Set;
|
|
145
145
|
try {
|
|
146
|
-
paths.forEach(
|
|
146
|
+
paths.forEach(path => {
|
|
147
147
|
if (!dependents.has(path) && path.indexOf("/") === -1) {
|
|
148
148
|
roots.add(path);
|
|
149
149
|
}
|
|
150
150
|
visit(path);
|
|
151
|
-
})
|
|
151
|
+
});
|
|
152
152
|
} catch (e) {
|
|
153
153
|
return null;
|
|
154
154
|
}
|
|
@@ -194,22 +194,22 @@ function FlattenPathToPreCompositionNode(path, inputNodes) {
|
|
|
194
194
|
inherits: {},
|
|
195
195
|
attributes: {}
|
|
196
196
|
};
|
|
197
|
-
inputNodes.forEach(
|
|
198
|
-
Object.keys(node.children).forEach(
|
|
197
|
+
inputNodes.forEach(node => {
|
|
198
|
+
Object.keys(node.children).forEach(childName => {
|
|
199
199
|
compositionNode.children[childName] = node.children[childName];
|
|
200
|
-
})
|
|
201
|
-
Object.keys(node.inherits).forEach(
|
|
200
|
+
});
|
|
201
|
+
Object.keys(node.inherits).forEach(inheritName => {
|
|
202
202
|
let ih = node.inherits[inheritName];
|
|
203
203
|
if (ih === null) {
|
|
204
204
|
delete compositionNode.inherits[inheritName];
|
|
205
205
|
} else {
|
|
206
206
|
compositionNode.inherits[inheritName] = ih;
|
|
207
207
|
}
|
|
208
|
-
})
|
|
209
|
-
Object.keys(node.attributes).forEach(
|
|
208
|
+
});
|
|
209
|
+
Object.keys(node.attributes).forEach(attrName => {
|
|
210
210
|
compositionNode.attributes[attrName] = node.attributes[attrName];
|
|
211
|
-
})
|
|
212
|
-
})
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
213
|
return compositionNode;
|
|
214
214
|
}
|
|
215
215
|
|
|
@@ -239,9 +239,9 @@ function CreateArtificialRoot(nodes) {
|
|
|
239
239
|
attributes: new Map,
|
|
240
240
|
children: new Map
|
|
241
241
|
};
|
|
242
|
-
roots.forEach(
|
|
242
|
+
roots.forEach(root => {
|
|
243
243
|
pseudoRoot.children.set(root, ComposeNodeFromPath(root, nodes));
|
|
244
|
-
})
|
|
244
|
+
});
|
|
245
245
|
return pseudoRoot;
|
|
246
246
|
}
|
|
247
247
|
|
|
@@ -254,25 +254,25 @@ function ComposeNode(path, postCompositionNode, preCompositionNodes) {
|
|
|
254
254
|
if (preCompositionNode) {
|
|
255
255
|
AddDataFromPreComposition(preCompositionNode, postCompositionNode, preCompositionNodes);
|
|
256
256
|
}
|
|
257
|
-
postCompositionNode.children.forEach((
|
|
257
|
+
postCompositionNode.children.forEach((child, name) => {
|
|
258
258
|
ComposeNode(`${path}/${name}`, child, preCompositionNodes);
|
|
259
|
-
})
|
|
259
|
+
});
|
|
260
260
|
return postCompositionNode;
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
function AddDataFromPreComposition(input, node, nodes) {
|
|
264
|
-
Object.values(input.inherits).forEach(
|
|
264
|
+
Object.values(input.inherits).forEach(inheritPath => {
|
|
265
265
|
let classNode = ComposeNodeFromPath(GetHead(inheritPath), nodes);
|
|
266
266
|
let subnode = GetChildNodeWithPath(classNode, GetTail(inheritPath));
|
|
267
267
|
if (!subnode) throw new Error(`Unknown node ${inheritPath}`);
|
|
268
|
-
subnode.children.forEach((
|
|
268
|
+
subnode.children.forEach((child, childName) => {
|
|
269
269
|
node.children.set(childName, child);
|
|
270
|
-
})
|
|
270
|
+
});
|
|
271
271
|
for (let [attrID, attr] of subnode.attributes) {
|
|
272
272
|
node.attributes.set(attrID, attr);
|
|
273
273
|
}
|
|
274
|
-
})
|
|
275
|
-
Object.entries(input.children).forEach((
|
|
274
|
+
});
|
|
275
|
+
Object.entries(input.children).forEach(([childName, child]) => {
|
|
276
276
|
if (child !== null) {
|
|
277
277
|
let classNode = ComposeNodeFromPath(GetHead(child), nodes);
|
|
278
278
|
let subnode = GetChildNodeWithPath(classNode, GetTail(child));
|
|
@@ -281,26 +281,26 @@ function AddDataFromPreComposition(input, node, nodes) {
|
|
|
281
281
|
} else {
|
|
282
282
|
node.children.delete(childName);
|
|
283
283
|
}
|
|
284
|
-
})
|
|
285
|
-
Object.entries(input.attributes).forEach((
|
|
284
|
+
});
|
|
285
|
+
Object.entries(input.attributes).forEach(([attrID, attr]) => {
|
|
286
286
|
node.attributes.set(attrID, attr);
|
|
287
|
-
})
|
|
287
|
+
});
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
var SchemaValidationError = class extends Error {};
|
|
291
291
|
|
|
292
292
|
function ValidateAttributeValue(desc, value, path, schemas) {
|
|
293
|
-
if (desc.optional && value ===
|
|
293
|
+
if (desc.optional && value === void 0) {
|
|
294
294
|
return;
|
|
295
295
|
}
|
|
296
296
|
if (desc.inherits) {
|
|
297
|
-
desc.inherits.forEach(
|
|
297
|
+
desc.inherits.forEach(inheritedSchemaID => {
|
|
298
298
|
let inheritedSchema = schemas[inheritedSchemaID];
|
|
299
299
|
if (!inheritedSchema) {
|
|
300
300
|
throw new SchemaValidationError(`Unknown inherited schema id "${desc.inherits}"`);
|
|
301
301
|
}
|
|
302
302
|
ValidateAttributeValue(inheritedSchema.value, value, path, schemas);
|
|
303
|
-
})
|
|
303
|
+
});
|
|
304
304
|
}
|
|
305
305
|
if (desc.dataType === "Boolean") {
|
|
306
306
|
if (typeof value !== "boolean") {
|
|
@@ -318,7 +318,7 @@ function ValidateAttributeValue(desc, value, path, schemas) {
|
|
|
318
318
|
if (typeof value !== "string") {
|
|
319
319
|
throw new SchemaValidationError(`Expected "${value}" to be of type string`);
|
|
320
320
|
}
|
|
321
|
-
let found = desc.enumRestrictions.options.filter(
|
|
321
|
+
let found = desc.enumRestrictions.options.filter(option => option === value).length === 1;
|
|
322
322
|
if (!found) {
|
|
323
323
|
throw new SchemaValidationError(`Expected "${value}" to be one of [${desc.enumRestrictions.options.join(",")}]`);
|
|
324
324
|
}
|
|
@@ -339,7 +339,7 @@ function ValidateAttributeValue(desc, value, path, schemas) {
|
|
|
339
339
|
throw new SchemaValidationError(`Expected "${value}" to be of type object`);
|
|
340
340
|
}
|
|
341
341
|
if (desc.objectRestrictions) {
|
|
342
|
-
Object.keys(desc.objectRestrictions.values).forEach(
|
|
342
|
+
Object.keys(desc.objectRestrictions.values).forEach(key => {
|
|
343
343
|
let optional = desc.objectRestrictions.values[key].optional;
|
|
344
344
|
let hasOwn = Object.hasOwn(value, key);
|
|
345
345
|
if (optional && !hasOwn) return;
|
|
@@ -347,23 +347,23 @@ function ValidateAttributeValue(desc, value, path, schemas) {
|
|
|
347
347
|
throw new SchemaValidationError(`Expected "${value}" to have key ${key}`);
|
|
348
348
|
}
|
|
349
349
|
ValidateAttributeValue(desc.objectRestrictions.values[key], value[key], path + "." + key, schemas);
|
|
350
|
-
})
|
|
350
|
+
});
|
|
351
351
|
}
|
|
352
352
|
} else if (desc.dataType === "Array") {
|
|
353
353
|
if (!Array.isArray(value)) {
|
|
354
354
|
throw new SchemaValidationError(`Expected "${value}" to be of type array`);
|
|
355
355
|
}
|
|
356
|
-
value.forEach(
|
|
356
|
+
value.forEach(entry => {
|
|
357
357
|
ValidateAttributeValue(desc.arrayRestrictions.value, entry, path + ".<array>.", schemas);
|
|
358
|
-
})
|
|
358
|
+
});
|
|
359
359
|
} else {
|
|
360
360
|
throw new SchemaValidationError(`Unexpected datatype ${desc.dataType}`);
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
|
|
364
364
|
function Validate(schemas, inputNodes) {
|
|
365
|
-
inputNodes.forEach(
|
|
366
|
-
Object.keys(node.attributes).filter(
|
|
365
|
+
inputNodes.forEach(node => {
|
|
366
|
+
Object.keys(node.attributes).filter(v => !v.startsWith("__internal")).forEach(schemaID => {
|
|
367
367
|
if (!schemas[schemaID]) {
|
|
368
368
|
throw new SchemaValidationError(`Missing schema "${schemaID}" referenced by ["${node.path}"].attributes`);
|
|
369
369
|
}
|
|
@@ -378,13 +378,13 @@ function Validate(schemas, inputNodes) {
|
|
|
378
378
|
throw e;
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
|
-
})
|
|
382
|
-
})
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
383
|
}
|
|
384
384
|
|
|
385
385
|
function ToInputNodes(data) {
|
|
386
386
|
let inputNodes = new Map;
|
|
387
|
-
data.forEach(
|
|
387
|
+
data.forEach(ifcxNode => {
|
|
388
388
|
let node = {
|
|
389
389
|
path: ifcxNode.path,
|
|
390
390
|
children: ifcxNode.children ? ifcxNode.children : {},
|
|
@@ -392,7 +392,7 @@ function ToInputNodes(data) {
|
|
|
392
392
|
attributes: ifcxNode.attributes ? ifcxNode.attributes : {}
|
|
393
393
|
};
|
|
394
394
|
MMSet(inputNodes, node.path, node);
|
|
395
|
-
})
|
|
395
|
+
});
|
|
396
396
|
return inputNodes;
|
|
397
397
|
}
|
|
398
398
|
|
|
@@ -422,12 +422,12 @@ function Federate(files) {
|
|
|
422
422
|
schemas: {},
|
|
423
423
|
data: []
|
|
424
424
|
};
|
|
425
|
-
files.forEach(
|
|
426
|
-
Object.keys(file.schemas).forEach(
|
|
427
|
-
})
|
|
428
|
-
files.forEach(
|
|
429
|
-
file.data.forEach(
|
|
430
|
-
})
|
|
425
|
+
files.forEach(file => {
|
|
426
|
+
Object.keys(file.schemas).forEach(schemaID => result.schemas[schemaID] = file.schemas[schemaID]);
|
|
427
|
+
});
|
|
428
|
+
files.forEach(file => {
|
|
429
|
+
file.data.forEach(node => result.data.push(node));
|
|
430
|
+
});
|
|
431
431
|
return Prune(result);
|
|
432
432
|
}
|
|
433
433
|
|
|
@@ -438,28 +438,28 @@ function Collapse(nodes, deleteEmpty = false) {
|
|
|
438
438
|
inherits: {},
|
|
439
439
|
attributes: {}
|
|
440
440
|
};
|
|
441
|
-
nodes.forEach(
|
|
442
|
-
Object.keys(node.children).forEach(
|
|
441
|
+
nodes.forEach(node => {
|
|
442
|
+
Object.keys(node.children).forEach(name => {
|
|
443
443
|
result.children[name] = node.children[name];
|
|
444
|
-
})
|
|
445
|
-
Object.keys(node.inherits).forEach(
|
|
444
|
+
});
|
|
445
|
+
Object.keys(node.inherits).forEach(name => {
|
|
446
446
|
result.inherits[name] = node.inherits[name];
|
|
447
|
-
})
|
|
448
|
-
Object.keys(node.attributes).forEach(
|
|
447
|
+
});
|
|
448
|
+
Object.keys(node.attributes).forEach(name => {
|
|
449
449
|
result.attributes[name] = node.attributes[name];
|
|
450
|
-
})
|
|
451
|
-
})
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
452
|
if (deleteEmpty) {
|
|
453
453
|
let empty = true;
|
|
454
|
-
Object.keys(result.children).forEach(
|
|
454
|
+
Object.keys(result.children).forEach(name => {
|
|
455
455
|
if (result.children[name] !== null) empty = false;
|
|
456
|
-
})
|
|
457
|
-
Object.keys(result.inherits).forEach(
|
|
456
|
+
});
|
|
457
|
+
Object.keys(result.inherits).forEach(name => {
|
|
458
458
|
if (result.inherits[name] !== null) empty = false;
|
|
459
|
-
})
|
|
460
|
-
Object.keys(result.attributes).forEach(
|
|
459
|
+
});
|
|
460
|
+
Object.keys(result.attributes).forEach(name => {
|
|
461
461
|
if (result.attributes[name] !== null) empty = false;
|
|
462
|
-
})
|
|
462
|
+
});
|
|
463
463
|
if (empty) return null;
|
|
464
464
|
}
|
|
465
465
|
return result;
|
|
@@ -473,7 +473,7 @@ function Prune(file, deleteEmpty = false) {
|
|
|
473
473
|
data: []
|
|
474
474
|
};
|
|
475
475
|
let inputNodes = ToInputNodes(file.data);
|
|
476
|
-
inputNodes.forEach(
|
|
476
|
+
inputNodes.forEach(nodes => {
|
|
477
477
|
let collapsed = Collapse(nodes, deleteEmpty);
|
|
478
478
|
if (collapsed) result.data.push({
|
|
479
479
|
path: collapsed.path,
|
|
@@ -481,7 +481,7 @@ function Prune(file, deleteEmpty = false) {
|
|
|
481
481
|
inherits: collapsed.inherits,
|
|
482
482
|
attributes: collapsed.attributes
|
|
483
483
|
});
|
|
484
|
-
})
|
|
484
|
+
});
|
|
485
485
|
return result;
|
|
486
486
|
}
|
|
487
487
|
|
|
@@ -495,7 +495,7 @@ var IfcxLayerStack = class {
|
|
|
495
495
|
this.Compose();
|
|
496
496
|
}
|
|
497
497
|
GetLayerIds() {
|
|
498
|
-
return this.layers.map(
|
|
498
|
+
return this.layers.map(l => l.header.id);
|
|
499
499
|
}
|
|
500
500
|
Compose() {
|
|
501
501
|
this.federated = Federate(this.layers);
|
|
@@ -557,7 +557,7 @@ var IfcxLayerStackBuilder = class {
|
|
|
557
557
|
}
|
|
558
558
|
temp.push(...layers);
|
|
559
559
|
}
|
|
560
|
-
temp.forEach(
|
|
560
|
+
temp.forEach(t => orderedLayers.push(t));
|
|
561
561
|
return temp;
|
|
562
562
|
}
|
|
563
563
|
async BuildLayerSet(activeLayerID) {
|
|
@@ -582,14 +582,14 @@ function TreeNodeToComposedObject(path, node, schemas) {
|
|
|
582
582
|
attributes: {},
|
|
583
583
|
children: []
|
|
584
584
|
};
|
|
585
|
-
node.children.forEach((
|
|
585
|
+
node.children.forEach((childNode, childName) => {
|
|
586
586
|
co.children?.push(TreeNodeToComposedObject(`${path}/${childName}`, childNode, schemas));
|
|
587
|
-
})
|
|
588
|
-
node.attributes.forEach((
|
|
587
|
+
});
|
|
588
|
+
node.attributes.forEach((attr, attrName) => {
|
|
589
589
|
if (attr && typeof attr === "object" && !Array.isArray(attr)) {
|
|
590
|
-
Object.keys(attr).forEach(
|
|
590
|
+
Object.keys(attr).forEach(compname => {
|
|
591
591
|
co.attributes[`${attrName}::${compname}`] = attr[compname];
|
|
592
|
-
})
|
|
592
|
+
});
|
|
593
593
|
} else {
|
|
594
594
|
let schema = schemas[attrName];
|
|
595
595
|
if (schema && schema.value.quantityKind) {
|
|
@@ -605,7 +605,7 @@ function TreeNodeToComposedObject(path, node, schemas) {
|
|
|
605
605
|
co.attributes[attrName] = attr;
|
|
606
606
|
}
|
|
607
607
|
}
|
|
608
|
-
})
|
|
608
|
+
});
|
|
609
609
|
if (Object.keys(co.attributes).length === 0) delete co.attributes;
|
|
610
610
|
return co;
|
|
611
611
|
}
|
|
@@ -615,9 +615,9 @@ async function compose3(files) {
|
|
|
615
615
|
header: {
|
|
616
616
|
...files[0].header
|
|
617
617
|
},
|
|
618
|
-
imports: files.map(
|
|
618
|
+
imports: files.map(f => ({
|
|
619
619
|
uri: f.header.id
|
|
620
|
-
}))
|
|
620
|
+
})),
|
|
621
621
|
schemas: {},
|
|
622
622
|
data: []
|
|
623
623
|
};
|
|
@@ -627,10 +627,10 @@ async function compose3(files) {
|
|
|
627
627
|
if (layerStack instanceof Error) {
|
|
628
628
|
throw layerStack;
|
|
629
629
|
}
|
|
630
|
-
layerStack.GetFederatedLayer().data.forEach((
|
|
630
|
+
layerStack.GetFederatedLayer().data.forEach((n, i) => {
|
|
631
631
|
n.attributes = n.attributes || {};
|
|
632
632
|
n.attributes[`__internal_${i}`] = n.path;
|
|
633
|
-
})
|
|
633
|
+
});
|
|
634
634
|
return TreeNodeToComposedObject("", layerStack.GetFullTree(), layerStack.GetSchemas());
|
|
635
635
|
}
|
|
636
636
|
|
|
@@ -689,11 +689,11 @@ function tryCreateMeshGltfMaterial(path) {
|
|
|
689
689
|
material.color = new THREE.Color(baseColorFactor[0], baseColorFactor[1], baseColorFactor[2]);
|
|
690
690
|
}
|
|
691
691
|
let metallicFactor = pbrMetallicRoughness["metallicFactor"];
|
|
692
|
-
if (metallicFactor !==
|
|
692
|
+
if (metallicFactor !== void 0) {
|
|
693
693
|
material.metalness = metallicFactor;
|
|
694
694
|
}
|
|
695
695
|
let roughnessFactor = pbrMetallicRoughness["roughnessFactor"];
|
|
696
|
-
if (roughnessFactor !==
|
|
696
|
+
if (roughnessFactor !== void 0) {
|
|
697
697
|
material.roughness = roughnessFactor;
|
|
698
698
|
}
|
|
699
699
|
}
|
|
@@ -702,7 +702,7 @@ function tryCreateMeshGltfMaterial(path) {
|
|
|
702
702
|
material.envMapRotation = new THREE.Euler(.5 * Math.PI, 0, 0);
|
|
703
703
|
return material;
|
|
704
704
|
}
|
|
705
|
-
return
|
|
705
|
+
return void 0;
|
|
706
706
|
}
|
|
707
707
|
|
|
708
708
|
function createMaterialFromParent(path) {
|
|
@@ -852,7 +852,7 @@ function traverseTree(path, parent, pathMapping) {
|
|
|
852
852
|
objectMap[node.name] = elem;
|
|
853
853
|
primMap[node.name] = node;
|
|
854
854
|
elem.userData.path = node.name;
|
|
855
|
-
for (let path2 of Object.entries(node.attributes || {}).filter((
|
|
855
|
+
for (let path2 of Object.entries(node.attributes || {}).filter(([k, _]) => k.startsWith("__internal_")).map(([_, v]) => v)) {
|
|
856
856
|
(pathMapping[String(path2)] = pathMapping[String(path2)] || []).push(node.name);
|
|
857
857
|
}
|
|
858
858
|
parent.add(elem);
|
|
@@ -866,7 +866,7 @@ function traverseTree(path, parent, pathMapping) {
|
|
|
866
866
|
elem.matrix = matrix;
|
|
867
867
|
}
|
|
868
868
|
}
|
|
869
|
-
(node.children || []).forEach(
|
|
869
|
+
(node.children || []).forEach(child => traverseTree([ child, ...path ], elem || parent, pathMapping));
|
|
870
870
|
}
|
|
871
871
|
|
|
872
872
|
async function composeAndRender() {
|
|
@@ -879,7 +879,7 @@ async function composeAndRender() {
|
|
|
879
879
|
return;
|
|
880
880
|
}
|
|
881
881
|
let tree = null;
|
|
882
|
-
let dataArray = datas.map(
|
|
882
|
+
let dataArray = datas.map(arr => arr[1]);
|
|
883
883
|
tree = await compose3(dataArray);
|
|
884
884
|
if (!tree) {
|
|
885
885
|
console.error("No result from composition");
|
|
@@ -934,10 +934,10 @@ class IFCXLoader extends Loader {
|
|
|
934
934
|
loader.setResponseType("json");
|
|
935
935
|
loader.setRequestHeader(this.requestHeader);
|
|
936
936
|
loader.setWithCredentials(this.withCredentials);
|
|
937
|
-
loader.load(url,
|
|
937
|
+
loader.load(url, json => this.parse(json, _onLoad, _onError), onProgress, onError);
|
|
938
938
|
}
|
|
939
939
|
parse(json, onLoad, onError) {
|
|
940
|
-
parse(json).then(
|
|
940
|
+
parse(json).then(scene => onLoad(scene)).catch(err => onError(err)).finally(() => clear());
|
|
941
941
|
}
|
|
942
942
|
}
|
|
943
943
|
|
|
@@ -967,13 +967,13 @@ class IFCXFileLoader extends Loader$1 {
|
|
|
967
967
|
const scene = await loader.loadAsync(manager.fileURL, progress);
|
|
968
968
|
if (!this.viewer.scene) return this;
|
|
969
969
|
let handle = 0;
|
|
970
|
-
scene.traverse(
|
|
970
|
+
scene.traverse(object => {
|
|
971
971
|
object.userData = {
|
|
972
972
|
handle: handle,
|
|
973
973
|
...object.userData
|
|
974
974
|
};
|
|
975
975
|
handle++;
|
|
976
|
-
})
|
|
976
|
+
});
|
|
977
977
|
const modelImpl = new ModelImpl(scene);
|
|
978
978
|
modelImpl.loader = this;
|
|
979
979
|
modelImpl.viewer = this.viewer;
|
|
@@ -1014,13 +1014,13 @@ class IFCXCloudLoader extends Loader$1 {
|
|
|
1014
1014
|
const scene = await parse(json);
|
|
1015
1015
|
clear();
|
|
1016
1016
|
let handle = 0;
|
|
1017
|
-
scene.traverse(
|
|
1017
|
+
scene.traverse(object => {
|
|
1018
1018
|
object.userData = {
|
|
1019
1019
|
handle: handle,
|
|
1020
1020
|
...object.userData
|
|
1021
1021
|
};
|
|
1022
1022
|
handle++;
|
|
1023
|
-
})
|
|
1023
|
+
});
|
|
1024
1024
|
const modelImpl = new ModelImpl(scene);
|
|
1025
1025
|
modelImpl.loader = this;
|
|
1026
1026
|
modelImpl.viewer = this.viewer;
|
|
@@ -1038,7 +1038,7 @@ class IFCXCloudLoader extends Loader$1 {
|
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
1040
|
|
|
1041
|
-
loaders.registerLoader("ifcx-file",
|
|
1041
|
+
loaders.registerLoader("ifcx-file", viewer => new IFCXFileLoader(viewer));
|
|
1042
1042
|
|
|
1043
|
-
loaders.registerLoader("ifcx-cloud",
|
|
1043
|
+
loaders.registerLoader("ifcx-cloud", viewer => new IFCXCloudLoader(viewer));
|
|
1044
1044
|
//# sourceMappingURL=IFCXLoader.module.js.map
|