u-space 0.0.31 → 0.0.32

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.
@@ -83,4 +83,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
83
83
  `+n.linebrk($.toString("base64"),70)+`
84
84
  `+t+`
85
85
  `},privateImport:function(o,s,r){r=r||{};var c;if(r.type!=="der")if(Buffer.isBuffer(s)&&(s=s.toString("utf8")),e.isString(s)){var d=n.trimSurroundingText(s,l,t).replace(/\s+|\n\r|\n|\r$/gm,"");c=Buffer.from(d,"base64")}else throw Error("Unsupported key format");else if(Buffer.isBuffer(s))c=s;else throw Error("Unsupported key format");const p={buf:c,off:0};if(c.slice(0,14).toString("ascii")!=="openssh-key-v1")throw"Invalid file format.";if(p.off+=15,h(p).toString("ascii")!=="none"||h(p).toString("ascii")!=="none"||h(p).toString("ascii")!==""||(p.off+=4,p.off+=4,h(p).toString("ascii")!=="ssh-rsa")||(h(p),h(p),p.off+=12,h(p).toString("ascii")!=="ssh-rsa"))throw Error("Unsupported key type");const v=h(p),m=h(p),B=h(p),E=h(p),x=h(p),P=h(p),D=new a(B),$=new a(P),H=new a(x),Y=D.mod(H.subtract(a.ONE)),ne=D.mod($.subtract(a.ONE));o.setPrivate(v,m,B,x,P,Y.toBuffer(),ne.toBuffer(),E),o.sshcomment=h(p).toString("ascii")},publicExport:function(o,s){let r=Buffer.alloc(4);for(r.writeUInt32BE(o.e,0);r[0]===0;)r=r.slice(1);const c=o.n.toBuffer(),d=Buffer.alloc(r.byteLength+4+c.byteLength+4+7+4),p={buf:d,off:0};u(p,Buffer.from("ssh-rsa")),u(p,r),u(p,c);let v=o.sshcomment||"";return s.type==="der"?p.buf:"ssh-rsa "+d.toString("base64")+" "+v+`
86
- `},publicImport:function(o,s,r){r=r||{};var c;if(r.type!=="der")if(Buffer.isBuffer(s)&&(s=s.toString("utf8")),e.isString(s)){if(s.substring(0,8)!=="ssh-rsa ")throw Error("Unsupported key format");let B=s.indexOf(" ",8);B===-1?B=s.length:o.sshcomment=s.substring(B+1).replace(/\s+|\n\r|\n|\r$/gm,"");const E=s.substring(8,B).replace(/\s+|\n\r|\n|\r$/gm,"");c=Buffer.from(E,"base64")}else throw Error("Unsupported key format");else if(Buffer.isBuffer(s))c=s;else throw Error("Unsupported key format");const d={buf:c,off:0},p=h(d).toString("ascii");if(p!=="ssh-rsa")throw Error("Invalid key type: "+p);const v=h(d),m=h(d);o.setPublic(m,v)},autoImport:function(o,s){return/^[\S\s]*-----BEGIN OPENSSH PRIVATE KEY-----\s*(?=(([A-Za-z0-9+/=]+\s*)+))\1-----END OPENSSH PRIVATE KEY-----[\S\s]*$/g.test(s)?(f.exports.privateImport(o,s),!0):/^[\S\s]*ssh-rsa \s*(?=(([A-Za-z0-9+/=]+\s*)+))\1[\S\s]*$/g.test(s)?(f.exports.publicImport(o,s),!0):!1}};function h(o){const s=o.buf.readInt32BE(o.off);o.off+=4;const r=o.buf.slice(o.off,o.off+s);return o.off+=s,r}function u(o,s){o.buf.writeInt32BE(s.byteLength,o.off),o.off+=4,o.off+=s.copy(o.buf,o.off)}})(openssh)),openssh.exports}var hasRequiredFormats;function requireFormats(){return hasRequiredFormats||(hasRequiredFormats=1,(function(f){requireUtils()._;function e(n){n=n.split("-");for(var a="private",l={type:"default"},t=1;t<n.length;t++)if(n[t])switch(n[t]){case"public":a=n[t];break;case"private":a=n[t];break;case"pem":l.type=n[t];break;case"der":l.type=n[t];break}return{scheme:n[0],keyType:a,keyOpt:l}}f.exports={pkcs1:requirePkcs1(),pkcs8:requirePkcs8(),components:requireComponents(),openssh:requireOpenssh(),isPrivateExport:function(n){return f.exports[n]&&typeof f.exports[n].privateExport=="function"},isPrivateImport:function(n){return f.exports[n]&&typeof f.exports[n].privateImport=="function"},isPublicExport:function(n){return f.exports[n]&&typeof f.exports[n].publicExport=="function"},isPublicImport:function(n){return f.exports[n]&&typeof f.exports[n].publicImport=="function"},detectAndImport:function(n,a,l){if(l===void 0){for(var t in f.exports)if(typeof f.exports[t].autoImport=="function"&&f.exports[t].autoImport(n,a))return!0}else if(l){var h=e(l);if(f.exports[h.scheme])h.keyType==="private"?f.exports[h.scheme].privateImport(n,a,h.keyOpt):f.exports[h.scheme].publicImport(n,a,h.keyOpt);else throw Error("Unsupported key format")}return!1},detectAndExport:function(n,a){if(a){var l=e(a);if(f.exports[l.scheme])if(l.keyType==="private"){if(!n.isPrivate())throw Error("This is not private key");return f.exports[l.scheme].privateExport(n,l.keyOpt)}else{if(!n.isPublic())throw Error("This is not public key");return f.exports[l.scheme].publicExport(n,l.keyOpt)}else throw Error("Unsupported key format")}}}})(formats)),formats.exports}var NodeRSA$1,hasRequiredNodeRSA;function requireNodeRSA(){if(hasRequiredNodeRSA)return NodeRSA$1;hasRequiredNodeRSA=1;var f=requireRsa();requireCryptoBrowserify(),requireLib().Ber;var e=requireUtils()._,n=requireUtils(),a=requireSchemes(),l=requireFormats();return NodeRSA$1=(function(){var t={node10:["md4","md5","ripemd160","sha1","sha224","sha256","sha384","sha512"],node:["md4","md5","ripemd160","sha1","sha224","sha256","sha384","sha512"],iojs:["md4","md5","ripemd160","sha1","sha224","sha256","sha384","sha512"],browser:["md5","ripemd160","sha1","sha256","sha512"]},h="pkcs1_oaep",u="pkcs1",o="private",s={private:"pkcs1-private-pem","private-der":"pkcs1-private-der",public:"pkcs8-public-pem","public-der":"pkcs8-public-der"};function r(c,d,p){if(!(this instanceof r))return new r(c,d,p);e.isObject(d)&&(p=d,d=void 0),this.$options={signingScheme:u,signingSchemeOptions:{hash:"sha256",saltLength:null},encryptionScheme:h,encryptionSchemeOptions:{hash:"sha1",label:null},environment:n.detectEnvironment(),rsaUtils:this},this.keyPair=new f.Key,this.$cache={},Buffer.isBuffer(c)||e.isString(c)?this.importKey(c,d):e.isObject(c)&&this.generateKeyPair(c.b,c.e),this.setOptions(p)}return r.prototype.setOptions=function(c){if(c=c||{},c.environment&&(this.$options.environment=c.environment),c.signingScheme){if(e.isString(c.signingScheme)){var d=c.signingScheme.toLowerCase().split("-");d.length==1?t.node.indexOf(d[0])>-1?(this.$options.signingSchemeOptions={hash:d[0]},this.$options.signingScheme=u):(this.$options.signingScheme=d[0],this.$options.signingSchemeOptions={hash:null}):(this.$options.signingSchemeOptions={hash:d[1]},this.$options.signingScheme=d[0])}else e.isObject(c.signingScheme)&&(this.$options.signingScheme=c.signingScheme.scheme||u,this.$options.signingSchemeOptions=e.omit(c.signingScheme,"scheme"));if(!a.isSignature(this.$options.signingScheme))throw Error("Unsupported signing scheme");if(this.$options.signingSchemeOptions.hash&&t[this.$options.environment].indexOf(this.$options.signingSchemeOptions.hash)===-1)throw Error("Unsupported hashing algorithm for "+this.$options.environment+" environment")}if(c.encryptionScheme){if(e.isString(c.encryptionScheme)?(this.$options.encryptionScheme=c.encryptionScheme.toLowerCase(),this.$options.encryptionSchemeOptions={}):e.isObject(c.encryptionScheme)&&(this.$options.encryptionScheme=c.encryptionScheme.scheme||h,this.$options.encryptionSchemeOptions=e.omit(c.encryptionScheme,"scheme")),!a.isEncryption(this.$options.encryptionScheme))throw Error("Unsupported encryption scheme");if(this.$options.encryptionSchemeOptions.hash&&t[this.$options.environment].indexOf(this.$options.encryptionSchemeOptions.hash)===-1)throw Error("Unsupported hashing algorithm for "+this.$options.environment+" environment")}this.keyPair.setOptions(this.$options)},r.prototype.generateKeyPair=function(c,d){if(c=c||2048,d=d||65537,c%8!==0)throw Error("Key size must be a multiple of 8.");return this.keyPair.generate(c,d.toString(16)),this.$cache={},this},r.prototype.importKey=function(c,d){if(!c)throw Error("Empty key given");if(d&&(d=s[d]||d),!l.detectAndImport(this.keyPair,c,d)&&d===void 0)throw Error("Key format must be specified");return this.$cache={},this},r.prototype.exportKey=function(c){return c=c||o,c=s[c]||c,this.$cache[c]||(this.$cache[c]=l.detectAndExport(this.keyPair,c)),this.$cache[c]},r.prototype.isPrivate=function(){return this.keyPair.isPrivate()},r.prototype.isPublic=function(c){return this.keyPair.isPublic(c)},r.prototype.isEmpty=function(c){return!(this.keyPair.n||this.keyPair.e||this.keyPair.d)},r.prototype.encrypt=function(c,d,p){return this.$$encryptKey(!1,c,d,p)},r.prototype.decrypt=function(c,d){return this.$$decryptKey(!1,c,d)},r.prototype.encryptPrivate=function(c,d,p){return this.$$encryptKey(!0,c,d,p)},r.prototype.decryptPublic=function(c,d){return this.$$decryptKey(!0,c,d)},r.prototype.$$encryptKey=function(c,d,p,v){try{var m=this.keyPair.encrypt(this.$getDataForEncrypt(d,v),c);return p=="buffer"||!p?m:m.toString(p)}catch(B){throw Error("Error during encryption. Original error: "+B)}},r.prototype.$$decryptKey=function(c,d,p){try{d=e.isString(d)?Buffer.from(d,"base64"):d;var v=this.keyPair.decrypt(d,c);if(v===null)throw Error("Key decrypt method returns null.");return this.$getDecryptedData(v,p)}catch(m){throw Error("Error during decryption (probably incorrect key). Original error: "+m)}},r.prototype.sign=function(c,d,p){if(!this.isPrivate())throw Error("This is not private key");var v=this.keyPair.sign(this.$getDataForEncrypt(c,p));return d&&d!="buffer"&&(v=v.toString(d)),v},r.prototype.verify=function(c,d,p,v){if(!this.isPublic())throw Error("This is not public key");return v=!v||v=="buffer"?null:v,this.keyPair.verify(this.$getDataForEncrypt(c,p),d,v)},r.prototype.getKeySize=function(){return this.keyPair.keySize},r.prototype.getMaxMessageSize=function(){return this.keyPair.maxMessageLength},r.prototype.$getDataForEncrypt=function(c,d){if(e.isString(c)||e.isNumber(c))return Buffer.from(""+c,d||"utf8");if(Buffer.isBuffer(c))return c;if(e.isObject(c))return Buffer.from(JSON.stringify(c));throw Error("Unexpected data type")},r.prototype.$getDecryptedData=function(c,d){return d=d||"buffer",d=="buffer"?c:d=="json"?JSON.parse(c.toString()):c.toString(d)},r})(),NodeRSA$1}var NodeRSAExports=requireNodeRSA();const NodeRSA=getDefaultExportFromCjs$1(NodeRSAExports),debugKey="NJHgNB1HDTrHTJc4ERFCBRVBB5HOBEDCjRLChRDIdn8K7EUJD,Vm4C6vC8BpZ6n6G,hxOjYZ{,wYhnJize2rlm9m,6bUcRVbP6sjNbKU8juOWUpukkcV6Cw,Bk2io7{YWJcPnG{1o3GUTpnO:z{kCYHL14HjO8noH1sp[J78k3Y3IcbOSSk97evccx0MdW2uR0f5qhZFQV8e2JCRxxJEBRBC";function decryptWithDebugKey(f){return decryptWithKey(f,decodeString(debugKey))}function decryptWithKey(f,e){const{content:n,sign:a}=f,l=new NodeRSA(e,"pkcs8-public",{environment:"browser",signingScheme:"pkcs1-md5",encryptionScheme:"pkcs1"});if(!l.verify(n,a,"utf8","base64"))throw new Error("u-space: license verify failed");const h=decryptInternal(n,l);return JSON.parse(h)}function decryptInternal(f,e){const n=f.charCodeAt(0),a=f.substring(1,n),l=f.substring(n),t=parseHeader(a);let h="";for(const u of t){const o=l.substring(u.start,u.end);let s;u.encrypt?s=e.decryptPublic(o,"utf8"):s=decodeString(o),h+=s}return h}function parseHeader(f){const e=decodeToBytes(f),a=new DataView(e.buffer).getInt16(0);if(a===1)return parseHeaderV1(e.buffer);throw new Error(`u-space: content version error, version=${a}`)}function parseHeaderV1(f){const e=new DataView(f);let n=2;const a=e.getInt16(n);n+=2;const l=[];for(let t=0;t<a;t++){const h=e.getInt16(n);n+=2;const u=e.getInt16(n);n+=2;const o=e.getInt32(n);n+=4;const s=e.getInt32(n);n+=4;const r={index:h,encrypt:u>0,start:o,end:s};l.push(r)}return l.sort((t,h)=>t.index<=h.index?-1:1),l}const _base64KeyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function decodeToBytes(f){const e=[];let n,a,l,t,h,u,o,s=0;for(f=f.replace(/[^A-Za-z0-9+/=]/g,"");s<f.length;)t=_base64KeyStr.indexOf(f.charAt(s++)),h=_base64KeyStr.indexOf(f.charAt(s++)),u=_base64KeyStr.indexOf(f.charAt(s++)),o=_base64KeyStr.indexOf(f.charAt(s++)),n=t<<2|h>>4,a=(h&15)<<4|u>>2,l=(u&3)<<6|o,e.push(n),u!==64&&e.push(a),o!==64&&e.push(l);return new Int8Array(e)}function decodeString(f){let e="";for(let n=0;n<f.length;n++){const l=f.charCodeAt(n)-1;e+=String.fromCharCode(l)}return e}const logo="data:image/webp;base64,UklGRswmAABXRUJQVlA4TMAmAAAvAIVnEA+imJEkqF4DtQTrz3QpKGjbhjHsQhiui4tMGGI1fJLp/2pgpmGafmQX+FcJCpbA5zH0qRRk4CBkwumBoU/XQR7YOg4Ctg2bWk7Mn3Pd/RAiYgLOrwIBqGKLe/j8QQ8k9LxcT5WABkhGMBpgnw8+SRIUpZ93E4h/br9UEHckCdBoBPs8hU9QViMEdtsrD6UAYqu2nufuZiZJxnecsVPL7pbjycwkYzu3E7sk1A+Z23Vsz4d3UTL5kiS2Ezjbz23buR+2Y4/tGW+rtmfNtm3bvsd1r/ZN+///7v5yvC3Lkhxb/ZYgc6gwi0H0gzQR/Z8Ab8+2121s29Zv6N095XZIr6T///9ZaLniGL2qPlHQCxH6IEgfJBAkSET0fwIou7ZVR5I+woqKfkRX5v9/aKcrOPeauB5h+cpXHlhmAEIgUET/J8C3a1t1bdu25W/q1/qEyv//Vu/j4ppTdqrt0Q+gJCHzYIEQFsIR/Z8AWs62120j72FOd7OIpAdPL4juf1uxpf8V2zndcQASP0KIQAUSAol/qIj+T4AkadujNpr2fYgQO8HIGHpadd//ZhJIgi/ZqUS39Tv1US5CJsoZIvo/Ab5d26pr27at8k213fqVXsf/f1a/OuI6hOsbD6AsIfNggRBWEo7o/wT89h99Pq6p+8OXvymldK/1hdHA4/vzu683+Zvq8O53tPR/l7/H/La3ngyG577Ob3jrycAYv/173RQZIrf9eJ9LDJbnd3qLK5lBM67l7W3aGDq37/zeNm0MoZf6xjZtDKS5vqtNG8Nprn7wn/+av1xpq3ktkX/9vX70/adF2RhU8+wB0//Uv91ood7L49/v8fGvQN1HiDdjHvu532T/V+SnPxUZWvdivsF0N3ZGKxeWTUT+CnAFzkA7W5JydfTwJzqGV3cz3kuwtxuTk3h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kMEnokX9AEg9NVtlyDx1Cmm1gzkGjeWANd1wc7z2kHPTFqFF/QxIGsHOkzeAUOhQerCD0gWLeCuwpw/lSraTEfPQrHJn18+BFK9moby/CyJTBXY1O8CzCRHxNsOkDjxfSzgzZuEa1br8PiaS7tq+V72iUBLtFtxsCUguMCy3GVZ9oYX6xg3rN0o1/MWUdOrPg6SYwne5n/UCKvdJXYBfUyjJBYOcnrDs+kA6zyvdUYh/YtTEsyRX6qHf9yMjqed0tn3q/RTbWakxujCnZgnAffG/ZklPmHd9JZwj/1PYUyYO8zEn0ZxP/e6PtH/27F9XTtcZ/1WPMT9l2A7PtP7KUb/h/U27ZwQo6+J8Lea0PvGLffn7ZIFxriktB5jblNJaK97wAQ==";class Watermarker extends webgpu.Scene{viewer;camera;mesh;overlayPass;#e=!1;#r=null;constructor(e){super(),this.viewer=e,this.camera=new webgpu.OrthographicCamera(-1,1,1,-1,0,1),this.camera.position.z=.5,this.mesh=new webgpu.Mesh(new webgpu.PlaneGeometry(1.8,1.8),new webgpu.MeshBasicNodeMaterial({color:16777215,opacity:.5,transparent:!0})),this.add(this.mesh),this.overlayPass=tsl.pass(this,this.camera)}enable(){this.#e=!0,this.#t().then(e=>{this.#e&&(this.mesh.material.map!==e&&(this.mesh.material.map=e,this.mesh.material.needsUpdate=!0),this.viewer.renderPipeline.addOverlayPass(this.overlayPass))}).catch(e=>{this.#r=null,console.warn("u-space Watermarker: failed to load watermark texture.",e)})}disable(){this.#e=!1,this.viewer.renderPipeline.removeOverlayPass(this.overlayPass)}dispose(){this.disable(),this.overlayPass.dispose(),this.mesh.geometry.dispose(),this.mesh.material.dispose(),this.mesh.material.map?.dispose()}#t(){return this.mesh.material.map?Promise.resolve(this.mesh.material.map):(this.#r??=uSpace.TextureLoaderManager.loadAsyncTexture(logo).then(e=>(e.colorSpace=webgpu.SRGBColorSpace,e)),this.#r)}}const _m4=new webgpu.Matrix4,SEMANTIC_ID_KEYS=["Buildings","Stories","Walls","Columns","Doors","Windows","Spaces","Staircases","Facilities","Elevators","Vents"];function collectSemanticIds(f){const e=new Set;return SEMANTIC_ID_KEYS.forEach(n=>{f[n]?.forEach(a=>{const l=a.ID;typeof l=="string"&&l&&e.add(l)})}),e}function collectScenePathCounts(f,e){const n=new Map,a=l=>{!e.has(l.id)&&l.renderType==="3D"&&l.path&&n.set(l.path,(n.get(l.path)??0)+1),l.children.forEach(a)};return f.forEach(a),n}class SceneGroup extends uSpace.BaseGroup{isSceneGroup=!0;type="SceneGroup";sceneLayer=null;constructor(){super(),this.name="SceneGroup"}setSceneLayer(e){return this.sceneLayer&&this.remove(this.sceneLayer),this.sceneLayer=e,e&&this.add(e),this}getDefaultSceneLayer(){return this.sceneLayer}}class SceneParser{viewer;path;semanticIds;pathCounts;loadModel;editableBatchOptions;#e=new Map;constructor(e,n,a,l,t,h){this.viewer=e,this.path=n,this.semanticIds=a,this.pathCounts=l,this.loadModel=t,this.editableBatchOptions=h}async parseAsync(e,n){const a=new SceneGroup,l=async(t,h)=>{if(this.semanticIds.has(t.id)){const o=this.#r(t);await Promise.all(t.children.map(s=>l(s,o))),o.children.length>0&&h.add(o);return}const u=await this.parseTreeNode(t);if(u){const{id:o,sid:s}=t;this.viewer.objectManager.add(o,u),this.viewer.objectManager.add(s,u),n.add(o),n.add(s),h.add(u)}await Promise.all(t.children.map(o=>l(o,u??h)))};return await Promise.all(e.map(t=>l(t,a))),await this.#a(a),a}#r(e){const n=new uSpace.BaseGroup;return n.name=e.name,n.visible=e.visible,_m4.fromArray(e.matrix).decompose(n.position,n.quaternion,n.scale),n}async parseTreeNode(e){const{name:n,renderType:a,path:l,visible:t,matrix:h,shape:u}=e;let o=null;if(a==="3D"&&l){const s=this.path+l;if(this.editableBatchOptions||(this.pathCounts.get(l)??0)>1){const r=new SceneInstanceObject;this.#t(s).instances.push(r),o=r}else o=await this.loadModel(s)}else if(a==="GROUP"||a==="STUB")o=new uSpace.BaseGroup;else if(a==="POLYGON"&&u?.points){const s=uSpace.ShapeMesh.createFromPoints(u.points);s.material.color.set("blue"),s.material.transparent=!0,s.material.opacity=.5,o=s}else if(a==="CIRCLE"&&u?.radius){const s=new uSpace.CircleMesh({geometryParameters:{radius:u.radius}});s.material.color.set("blue"),s.material.transparent=!0,s.material.opacity=.5,o=s}if(o){o.name=n,o.visible=t,_m4.fromArray(h).decompose(o.position,o.quaternion,o.scale);const r={...e};Reflect.deleteProperty(r,"children"),Object.assign(o.userData,r),o instanceof SceneInstanceObject&&l&&(o.setInstanceIdentity({id:e.id,kind:"SceneInstances",name:n}),o.userData.instanced=!0,o.userData.modelPath=l,o.userData.modelUrl=this.path+l)}return o}#t(e){let n=this.#e.get(e);return n||(n={url:e,instances:[]},this.#e.set(e,n)),n}async#a(e){if(this.#e.size===0)return;if(this.editableBatchOptions){const a=new SceneEditableBatchLayer(this.editableBatchOptions);e.setSceneLayer(a);for(const h of this.#e.values()){const u=await this.loadModel(h.url);a.addTemplate(h.url,u,h.instances)}e.updateMatrixWorld(!0);const l=a.build();e.userData.editableBatch=l.stats;const t=new SceneInstancedLayer;for(const h of l.unsupported){const u=h.instances.filter(c=>c.getInstanceRenderObject()===null);if(u.length===0||!h.reasons.includes("negative-scale")&&u.length>1&&t.addInstances(h.url,h.template,u))continue;const[s,...r]=u;s&&this.#i(s,h.template),await Promise.all(r.map(async c=>{const d=await this.loadModel(h.url);this.#i(c,d)}))}t.children.length>0?(t.name="SceneEditableBatchFallback",e.add(t),a.addEventListener("materialize",({instance:h})=>{t.removeInstance(h)})):t.clearBatches(),a.children.length===0&&(a.dispose(),e.setSceneLayer(null));return}const n=new SceneInstancedLayer;e.setSceneLayer(n);for(const a of this.#e.values()){const l=await this.loadModel(a.url);if(n.addInstances(a.url,l,a.instances))continue;const[h,...u]=a.instances;h&&this.#i(h,l),await Promise.all(u.map(async o=>{const s=await this.loadModel(a.url);this.#i(o,s)}))}n.children.length===0&&e.setSceneLayer(null)}#i(e,n){n.name=e.name,n.visible=!0,n.position.set(0,0,0),n.quaternion.identity(),n.scale.set(1,1,1),Object.assign(n.userData,e.userData,{instanced:!1}),Object.assign(e.userData,{instanced:!1}),e.setInstanceRenderObject(n)}}class SceneLoader extends webgpu.Loader{viewer;key="";cachedIds=new Set;editableBatchOptions=null;_resourceData=null;_treeData=[];#e;constructor(e){super(),this.viewer=e,this.#e=new Watermarker(e),this.manager=new webgpu.LoadingManager}setKey(e){return this.key=e,this}setEditableBatching(e=!0){return this.editableBatchOptions=e===!1?null:e===!0?{}:e,this}async loadModel(e){const n=new uSpace.Model;this.manager.itemStart(e);try{await n.loadAsync({url:e})}catch(a){throw this.manager.itemError(e),a}finally{this.manager.itemEnd(e)}return n}async _preareTreeData(){if(!this.path)throw new Error("u-space SceneLoader: path is not set");const e=new BaseFileLoader(this),n=await e.loadAsync(META_DATA_FILE_PATH);if(n.version<1.5)throw new Error("u-space SceneLoader: Only support version 1.5 and above");if(!this.key&&n.authority==="OFFICIAL")throw new Error("u-space SceneLoader: options.key is required when authority is OFFICIAL");this.key&&n.authority==="TRIAL"&&console.warn("u-space SceneLoader: options.key is not used when authority is TRIAL");const a=await e.loadAsync(n.resource),l=this._resourceData!==a;if(this._resourceData=a,l)if(n.encryptWith==="DEBUG")try{this._treeData=decryptWithDebugKey(a),this.#e.enable()}catch{throw new Error("u-space SceneLoader: decrypt with debug key failed")}else if(n.encryptWith==="SCENE"||n.encryptWith==="COMPANY")try{this._treeData=decryptWithKey(a,this.key)}catch{throw new Error("u-space SceneLoader: decrypt with authorized key failed")}else n.encryptWith||(this._treeData=a)}async _prepareSemanticIds(){try{const e=new webgpu.FileLoader(new webgpu.LoadingManager);e.setPath(this.path),e.setResponseType("json"),e.setRequestHeader(this.requestHeader),e.setWithCredentials(this.withCredentials);const n=await e.loadAsync(SEMANTIC_DATA_FILE_PATH);return collectSemanticIds(n)}catch{return new Set}}async loadAsync(){if(!this.path)throw new Error("u-space SceneLoader: path is not set");this.manager.itemStart(this.path);try{await this._preareTreeData();const e=await this._prepareSemanticIds(),n=collectScenePathCounts(this._treeData,e);return await new SceneParser(this.viewer,this.path,e,n,this.loadModel.bind(this),this.editableBatchOptions).parseAsync(this._treeData,this.cachedIds)}catch(e){throw this.manager.itemError(this.path),e}finally{this.manager.itemEnd(this.path)}}clearCache(){this.cachedIds.forEach(e=>{this.viewer.objectManager.removeById(e)}),this.cachedIds.clear()}dispose(){this.clearCache(),this.#e.dispose()}}class VerticalShaftMeshError extends Error{constructor(e){super(e),this.name="VerticalShaftMeshError"}}const VERTICAL_SHAFT_RENDER_OFFSET=-.006;function getValidPolygonShape$1(f,e,n){if(!Array.isArray(f)||f.length<4||f.length%2!==0)throw new VerticalShaftMeshError(`u-space SemanticLoader: invalid ${e} polygon shape for id ${n}.`);return f}function createShape(f){const e=[];for(let n=0;n<f.length;n+=2)e.push(new webgpu.Vector2(f[n],-f[n+1]));return new webgpu.Shape(e)}function getVerticalShaftRange(f){const e=Number(f.Elevation??0),n=Number(f.TotalHeight);if(!Number.isFinite(e)||!Number.isFinite(n)||n<=0)throw new VerticalShaftMeshError(`u-space SemanticLoader: invalid vertical shaft height range for id ${f.ID}.`);const a=e+n;return{bottom:e,top:a,height:n}}function createVerticalShaftMesh(f){try{return f()}catch(e){if(e instanceof VerticalShaftMeshError)return console.warn(e.message),null;throw e}}class VerticalShaftMesh extends uSpace.ExtrudeMesh{isVerticalShaftMesh=!0;type="VerticalShaftMesh";shaft;semanticId;semanticKind;semanticName;bottom;top;height;constructor({shaft:e,kind:n,material:a}){const l=getValidPolygonShape$1(e.Polygon?.shape,n,e.ID),t=getVerticalShaftRange(e);super({geometryParameters:{shape:createShape(l),options:{depth:t.height,bevelEnabled:!1}},materialParameters:{color:a.color,opacity:a.opacity,transparent:a.opacity<1,depthWrite:!0}}),this.shaft=e,this.semanticId=e.ID,this.semanticKind=n,this.semanticName=e.Name||"",this.bottom=t.bottom,this.top=t.top,this.height=t.height,this.name=this.semanticName,this.position.y=this.bottom,this.material.positionNode=tsl.positionLocal.add(tsl.normalLocal.mul(VERTICAL_SHAFT_RENDER_OFFSET)),this.userData.id=this.semanticId,this.userData.semanticKind=n,this.userData.beginFloorIndex=e.BeginFloorIndex,this.userData.endFloorIndex=e.EndFloorIndex,this.userData.bottom=this.bottom,this.userData.top=this.top}}const ELEVATOR_MATERIAL={color:7305093,opacity:.7};class ElevatorMesh extends VerticalShaftMesh{isElevatorMesh=!0;type="ElevatorMesh";constructor(e){super({shaft:e,kind:"Elevators",material:ELEVATOR_MATERIAL})}static create(e){return createVerticalShaftMesh(()=>new ElevatorMesh(e))}}const OPAQUE_MATERIAL_INDEX=0,TRANSPARENT_MATERIAL_INDEX=1,OPAQUE_OPACITY_THRESHOLD=.999;function markInstanceRenderDirty(f){f.markInstanceRenderDirty()}const PLANISH_SCALE_Y=.01,PLANISH_KIND_OFFSET_STEP=.002,PLANISH_INSTANCE_OFFSET_JITTER=8e-4,PLANISH_FACILITY_OFFSET=.014,SEMANTIC_RENDER_OFFSETS={Walls:0,Columns:.006,Spaces:-.006,Doors:.01,Windows:.01,Staircases:.012},SEMANTIC_DRAW_ORDER={Spaces:0,Staircases:1,Walls:2,Columns:3,Doors:4,Windows:5},SPACE_RENDER_OFFSET_JITTER_MIN=.001,SPACE_RENDER_OFFSET_JITTER=.006,_box=new webgpu.Box3,_pivot=new webgpu.Vector3,_raycastHits=[],_dummyPosition=new webgpu.Vector3,_dummyQuaternion=new webgpu.Quaternion,_dummyScale=new webgpu.Vector3,_boundsMatrix=new webgpu.Matrix4,_boundsSphere=new webgpu.Sphere,_facilityBounds=new webgpu.Box3,_floorMatrixInverse=new webgpu.Matrix4;function getStateTextureSize(f,e=1){return Math.max(1,Math.ceil(Math.sqrt(Math.max(1,f*e))))}function getMatrixTextureSize(f){const e=Math.sqrt(Math.max(1,f)*4);return Math.max(4,Math.ceil(e/4)*4)}function createStateTexture(f){const e=new webgpu.DataTexture(new Float32Array(f*f*4),f,f,webgpu.RGBAFormat,webgpu.FloatType);return e.magFilter=webgpu.NearestFilter,e.minFilter=webgpu.NearestFilter,e.generateMipmaps=!1,e.needsUpdate=!0,e}function getStableRenderOffsetUnit(f){let e=2166136261;for(let n=0;n<f.length;n++)e^=f.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0)/4294967295}function getSemanticRenderOffset(f){const e=SEMANTIC_RENDER_OFFSETS[f.kind];return f.kind!=="Spaces"?e:e-SPACE_RENDER_OFFSET_JITTER_MIN-getStableRenderOffsetUnit(`${f.id}:${f.index}`)*SPACE_RENDER_OFFSET_JITTER}function getPlanishInstanceOffset(f){return getStableRenderOffsetUnit(f)*PLANISH_INSTANCE_OFFSET_JITTER}function getSemanticPlanishOffset(f){return SEMANTIC_DRAW_ORDER[f.kind]*PLANISH_KIND_OFFSET_STEP+getPlanishInstanceOffset(`${f.id}:${f.index}:planish`)}function getFacilityPlanishOffset(f,e){const n=f.instanceId||`${f.uuid}:${e}`;return PLANISH_FACILITY_OFFSET+getPlanishInstanceOffset(`${n}:${e}:planish`)}function copyAttributeComponents(f,e,n,a){for(let l=0;l<n;l++)a.push(f?.getComponent(e,l)??0)}function createSemanticMaterial(f,e,n,a,l){const t=tsl.attribute("semanticIndex","float").toInt(),h=B=>tsl.int(tsl.textureSize(tsl.textureLoad(B),tsl.int(0)).x).toConst(),u=B=>{const E=h(B),x=t.mod(E).toConst(),P=t.div(E).toConst();return tsl.textureLoad(B,tsl.ivec2(x,P))},o=()=>{const B=h(n),E=t.mul(4).toConst(),x=E.mod(B).toConst(),P=E.div(B).toConst();return tsl.mat4(tsl.textureLoad(n,tsl.ivec2(x,P)),tsl.textureLoad(n,tsl.ivec2(x.add(1),P)),tsl.textureLoad(n,tsl.ivec2(x.add(2),P)),tsl.textureLoad(n,tsl.ivec2(x.add(3),P)))},s=u(f),r=u(e).x,c=u(a).x,d=o(),p=d.mul(tsl.vec4(tsl.positionLocal,1)).xyz,v=tsl.transformNormal(tsl.normalLocal,d).normalize(),m=new webgpu.MeshStandardNodeMaterial({transparent:l,depthWrite:!0});return m.colorNode=tsl.vec4(s.rgb,1),m.opacityNode=s.a.mul(r),m.maskNode=r.greaterThan(.5).and(s.a.greaterThan(.001)),m.positionNode=p.add(v.mul(c)),m}function createSemanticMaterials(f,e,n,a){return[createSemanticMaterial(f,e,n,a,!1),createSemanticMaterial(f,e,n,a,!0)]}function copySemanticColor(f,e){if(f instanceof webgpu.Color){e.x=f.r,e.y=f.g,e.z=f.b;return}e.x=f.x,e.y=f.y,e.z=f.z,f instanceof webgpu.Vector4&&(e.w=f.w)}function buildMergedSemanticGeometry(f){const e=[...f].sort((s,r)=>SEMANTIC_DRAW_ORDER[s.kind]-SEMANTIC_DRAW_ORDER[r.kind]),n=[],a=[],l=[],t=[],h=[],u=[];e.forEach((s,r)=>{const c=s.geometry,d=c.getAttribute("position"),p=c.getAttribute("normal"),v=c.getAttribute("uv"),m=c.getIndex();if(!d)return;c.computeBoundingBox(),_box.copy(c.boundingBox??_box.makeEmpty()),_box.getCenter(_pivot),_pivot.y=_box.min.y;const B=n.length/3,E=[],x=[],P=[],D=[];for(let te=0;te<d.count;te++){const de=d.getX(te)-_pivot.x,X=d.getY(te)-_pivot.y,b=d.getZ(te)-_pivot.z;n.push(de,X,b),E.push(de,X,b),t.push(r),copyAttributeComponents(p,te,3,a),copyAttributeComponents(p,te,3,x),copyAttributeComponents(v,te,2,l),copyAttributeComponents(v,te,2,P)}const $=h.length;if(m)for(let te=0;te<m.count;te++){const de=m.getX(te);h.push(B+de),D.push(de)}else for(let te=0;te<d.count;te++)h.push(B+te),D.push(te);const H=h.length-$,Y=new webgpu.BufferGeometry;Y.setAttribute("position",new webgpu.Float32BufferAttribute(E,3)),p&&Y.setAttribute("normal",new webgpu.Float32BufferAttribute(x,3)),v&&Y.setAttribute("uv",new webgpu.Float32BufferAttribute(P,2)),Y.setIndex(D),Y.computeBoundingBox(),Y.computeBoundingSphere();const ne=new webgpu.Matrix4().makeTranslation(_pivot.x,_pivot.y,_pivot.z);u.push({id:s.id,kind:s.kind,name:s.name,index:r,indexStart:$,indexCount:H,baseMatrix:ne,matrix:new webgpu.Matrix4,finalMatrix:ne.clone(),geometry:Y,initialColor:s.color.clone(),color:s.color.clone(),visible:!0})});const o=new webgpu.BufferGeometry;return o.setAttribute("position",new webgpu.Float32BufferAttribute(n,3)),a.length>0&&o.setAttribute("normal",new webgpu.Float32BufferAttribute(a,3)),l.length>0&&o.setAttribute("uv",new webgpu.Float32BufferAttribute(l,2)),o.setAttribute("semanticIndex",new webgpu.Float32BufferAttribute(t,1)),o.setIndex(h),o.computeBoundingBox(),o.computeBoundingSphere(),{geometry:o,states:u}}class FloorSemanticInstanceObject extends uSpace.InstanceObject{isFloorSemanticInstanceObject=!0;type="FloorSemanticInstanceObject";floorMesh;semanticIndex;#e=null;#r;#t=!1;constructor(e,n){super({boundsName:"FloorSemanticBounds"}),this.floorMesh=e,this.semanticIndex=n,this.#r=e.getOpacityAt(n)}setInstanceVisible(e){return this.floorMesh.setVisibleAt(this.semanticIndex,e),super.setInstanceVisible(e)}setInstanceColor(e){return this.#e=new webgpu.Color(e),super.setInstanceColor(e),this.#t||this.floorMesh.setColorAt(this.semanticIndex,this.#e),this}resetInstanceColor(){return this.#e=null,super.resetInstanceColor(),this.#t||this.floorMesh.resetColorAt(this.semanticIndex),this}setInstanceOpacity(e){return this.#r=Math.max(0,Math.min(1,e)),super.setInstanceOpacity(this.#r),this.#t||this.floorMesh.setOpacityAt(this.semanticIndex,this.#r),this}getInstanceOpacity(){return this.floorMesh.getOpacityAt(this.semanticIndex)}setInstanceHighlight(e,n,a=!1){const l=Math.max(0,Math.min(1,n));return this.#t=!0,super.setInstanceHighlight(e,l,a),this.floorMesh.setColorAt(this.semanticIndex,new webgpu.Color(e)),this.floorMesh.setOpacityAt(this.semanticIndex,l),this}clearInstanceHighlight(){return this.#t?(this.#t=!1,super.clearInstanceHighlight(),this.#a(),this):this}getInstanceBoundingBox(e=new webgpu.Box3,n=!1){return this.floorMesh.getBoundingBoxAt(this.semanticIndex,e,n)??e.makeEmpty()}#a(){this.#e?this.floorMesh.setColorAt(this.semanticIndex,this.#e):this.floorMesh.resetColorAt(this.semanticIndex),this.floorMesh.setOpacityAt(this.semanticIndex,this.#r)}}class FloorMesh extends uSpace.BaseMesh{isFloorMergedSemanticMesh=!0;type="FloorMesh";semanticId="";semanticKind="Floors";semanticName="";pivot=new webgpu.Vector3;boundingBox=null;boundingSphere=null;wallsInstances=new Map;columnsInstances=new Map;spacesInstances=new Map;doorsInstances=new Map;windowsInstances=new Map;staircasesInstances=new Map;semanticInstances=new Map;semanticEntities=new Map;facilityObjectsById=new Map;facilityObjects=[];facilityIndexVersion=0;#e;#r;#t=[];#a;#i;#o;#s;#u;#c=new Map;#f=new Map;#h=new WeakMap;constructor(e){const{geometry:n,states:a}=buildMergedSemanticGeometry(e),l=getStateTextureSize(a.length),t=getMatrixTextureSize(a.length),h=createStateTexture(l),u=createStateTexture(l),o=createStateTexture(t),s=createStateTexture(l),r=createSemanticMaterials(h,u,o,s);super(n,r),this.#r=a,this.#e={Walls:this.wallsInstances,Columns:this.columnsInstances,Spaces:this.spacesInstances,Doors:this.doorsInstances,Windows:this.windowsInstances,Staircases:this.staircasesInstances},this.#a=h,this.#i=u,this.#o=o,this.#s=s,this.#u=new webgpu.Mesh,this.#u.matrixAutoUpdate=!1,this.frustumCulled=!1,this.#r.forEach(c=>{const d=new FloorSemanticInstanceObject(this,c.index);d.name=c.name||c.id,d.visible=c.visible,d.setInstanceIdentity({id:c.id,kind:c.kind,name:c.name}),d.userData.id=c.id,d.userData.semanticIndex=c.index,this.#t[c.index]=d,this.add(d),this.semanticInstances.set(c.id,c.index),this.#e[c.kind].set(c.id,c.index),this.semanticEntities.set(c.id,{type:"geometry",kind:c.kind,id:c.id,name:c.name,index:c.index,object:d}),this.#d(c.index),this.#g(c.index),this.#p(c.index),this.#I(c.index)}),this.#l(),this.userData.semanticEntries=this.#r.map(({id:c,kind:d,name:p,index:v})=>({id:c,kind:d,name:p,index:v}))}setSemanticIdentity(e){return e.id!==void 0&&(this.semanticId=e.id??""),e.kind!==void 0&&(this.semanticKind=e.kind??""),e.name!==void 0&&(this.semanticName=e.name??""),this}planish(e){return e!=="Facilities"&&this.#b(e,n=>this.#B(n)),(e===void 0||e==="Facilities")&&this.#q(),this}unplanish(e){return e!=="Facilities"&&this.#b(e,n=>this.#A(n)),(e===void 0||e==="Facilities")&&this.#R(),this}get semanticCount(){return this.#r.length}get instanceCount(){return this.semanticCount}getSemanticIndexById(e){return this.semanticInstances.get(e)}getSemanticById(e){return this.semanticEntities.get(e)}getSemantics(){return[...new Set(this.semanticEntities.values())]}getSemanticsByKind(e){return this.getSemantics().filter(n=>n.kind===e)}getSemanticIdAt(e){return this.#n(e).id}getSemanticKindAt(e){return this.#n(e).kind}getSemanticNameAt(e){return this.#n(e).name}getSemanticObjectAt(e){return this.#t[e]}showAllFacilities(){return this.facilityObjects.forEach(e=>{e.setInstanceVisible(!0)}),this}hideAllFacilities(){return this.facilityObjects.forEach(e=>{e.setInstanceVisible(!1)}),this}addFacility(e,n){this.facilityObjects.includes(e)||(this.add(e),this.facilityObjects.push(e)),this.#v(e);const a=new Set;(Array.isArray(n)?n:[n]).forEach(u=>{u&&a.add(u)}),[e.instanceId].forEach(u=>{typeof u=="string"&&u&&a.add(u)});const h={type:"object",kind:"Facilities",id:this.#S(e,a),name:this.#x(e),index:this.facilityObjects.indexOf(e),object:e,aliases:[...a]};return this.#c.set(e,h),a.forEach(u=>{this.facilityObjectsById.set(u,e),this.semanticEntities.set(u,h)}),this.userData.facilities=this.facilityObjects.map(u=>u.instanceId||u.uuid),this.facilityIndexVersion++,this}getFacilityById(e){return this.facilityObjectsById.get(e)}getFacilityAt(e){return this.facilityObjects[e]}getFacilities(){return[...this.facilityObjects]}removeFacility(e){const n=this.#w(e);if(!n)return this;const a=this.facilityObjects.indexOf(n);return a!==-1&&this.facilityObjects.splice(a,1),this.#v(n),a!==-1&&this.#_(a),n.visible=!1,n.removeFromParent(),this.#h.delete(n),this.userData.facilities=this.facilityObjects.map(l=>l.instanceId||l.uuid),this.facilityIndexVersion++,this}#w(e){return typeof e=="string"?this.getFacilityById(e):e}setColorAt(e,n){const a=this.#n(e);return copySemanticColor(n,a.color),this.#d(e),this.#l(),this}resetColorAt(e){const n=this.#n(e),a=n.color.w;return n.color.copy(n.initialColor),n.color.w=a,this.#d(e),this.#l(),this}getColorAt(e,n=new webgpu.Vector4){const a=this.#n(e).color;return n.copy(a),n}setOpacityAt(e,n){const a=this.#n(e);return a.color.w=Math.max(0,Math.min(1,n)),this.#d(e),this.#l(),this}getOpacityAt(e){return this.#n(e).color.w}setVisibleAt(e,n){const a=this.#n(e);return a.visible=n,this.#g(e),this}getVisibleAt(e){return this.#n(e).visible}setMatrixAt(e,n){const a=this.#n(e);return a.matrix.copy(n),a.finalMatrix.multiplyMatrices(a.baseMatrix,a.matrix),this.#y(e),this.#p(e),this}setScaleAt(e,n,a,l){return this.#m(e,t=>{n instanceof webgpu.Vector3?t.copy(n):t.set(n,a??n,l??n)})}setScaleYAt(e,n){return this.#m(e,a=>{a.y=n})}getMatrixAt(e,n=new webgpu.Matrix4){return n.copy(this.#n(e).matrix),n}getFinalMatrixAt(e,n=new webgpu.Matrix4){return n.copy(this.#n(e).finalMatrix),n}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new webgpu.Box3),this.boundingBox.makeEmpty();for(const e of this.#r)this.getBoundingBoxAt(e.index,_box,!1)&&this.boundingBox.union(_box)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new webgpu.Sphere),this.boundingSphere.makeEmpty();for(const e of this.#r)this.getBoundingSphereAt(e.index,_boundsSphere,!1)&&this.boundingSphere.union(_boundsSphere)}getBoundingBoxAt(e,n=new webgpu.Box3,a=!0){const l=this.#n(e);return l.geometry.boundingBox||l.geometry.computeBoundingBox(),l.geometry.boundingBox?(n.copy(l.geometry.boundingBox).applyMatrix4(l.finalMatrix),a&&(this.updateWorldMatrix(!0,!1),n.applyMatrix4(this.matrixWorld)),n):null}getBoundingSphereAt(e,n=new webgpu.Sphere,a=!0){const l=this.#n(e);return l.geometry.boundingSphere||l.geometry.computeBoundingSphere(),l.geometry.boundingSphere?(n.copy(l.geometry.boundingSphere),a?(this.updateWorldMatrix(!0,!1),_boundsMatrix.multiplyMatrices(this.matrixWorld,l.finalMatrix),n.applyMatrix4(_boundsMatrix)):n.applyMatrix4(l.finalMatrix),n):null}raycast(e,n){if(this.visible===!1&&this.ignoreInvisibleWhenRaycast===!0)return!1;this.updateWorldMatrix(!0,!1),this.#u.material=Array.isArray(this.material)?this.material[OPAQUE_MATERIAL_INDEX]:this.material;for(const a of this.#r)if(!(!a.visible||a.color.w<=.001)){this.#u.geometry=a.geometry,this.#u.matrixWorld.multiplyMatrices(this.matrixWorld,a.finalMatrix),_raycastHits.length=0,this.#u.raycast(e,_raycastHits);for(const l of _raycastHits){const t=l,h=this.#t[a.index];t.object=h??this,t.semanticObject=h,t.semanticId=a.id,t.semanticKind=a.kind,t.semanticName=a.name,t.semanticIndex=a.index,n.push(t)}}}dispose(){this.geometry.dispose(),Array.isArray(this.material)?this.material.forEach(e=>e.dispose()):this.material.dispose(),this.#a.dispose(),this.#i.dispose(),this.#o.dispose(),this.#s.dispose(),this.#r.forEach(e=>e.geometry.dispose())}#v(e){for(const[n,a]of this.facilityObjectsById)a===e&&this.facilityObjectsById.delete(n);for(const[n,a]of this.semanticEntities)a.type==="object"&&a.object===e&&this.semanticEntities.delete(n);this.#c.delete(e)}#_(e=0){for(let n=e;n<this.facilityObjects.length;n++){const a=this.#c.get(this.facilityObjects[n]);a&&(a.index=n)}}#S(e,n){for(const l of[e.instanceId])if(typeof l=="string"&&l)return n.add(l),l;const[a]=n;return a||(n.add(e.uuid),e.uuid)}#x(e){const{facility:n}=e.userData;return e.instanceName?e.instanceName:n&&typeof n.Name=="string"&&n.Name?n.Name:e.name||void 0}#n(e){const n=this.#r[e];if(!n)throw new Error(`u-space FloorMesh: invalid semantic index ${e}.`);return n}#y(e){this.boundingBox=null,this.boundingSphere=null,(e===void 0?this.#t:[this.#t[e]]).forEach(a=>{a&&(a.boundingBox=null,a.boundingSphere=null)})}#E(e){return e.color.w>=OPAQUE_OPACITY_THRESHOLD?OPAQUE_MATERIAL_INDEX:TRANSPARENT_MATERIAL_INDEX}#l(){this.geometry.clearGroups();let e=-1,n=0,a=-1;const l=()=>{n<=0||this.geometry.addGroup(e,n,a)};this.#r.forEach(t=>{if(t.indexCount<=0)return;const h=this.#E(t),u=e+n===t.indexStart;if(e===-1){e=t.indexStart,n=t.indexCount,a=h;return}if(h===a&&u){n+=t.indexCount;return}l(),e=t.indexStart,n=t.indexCount,a=h}),l()}#b(e,n){if(e===void 0){this.#r.forEach(a=>n(a.index));return}for(const a of this.#e[e].values())n(a)}#B(e){const n=this.#n(e),a=this.#f.get(e)??n.matrix;this.#f.has(e)||this.#f.set(e,n.matrix.clone()),a.decompose(_dummyPosition,_dummyQuaternion,_dummyScale),_dummyScale.y*=PLANISH_SCALE_Y,n.matrix.compose(_dummyPosition,_dummyQuaternion,_dummyScale),n.finalMatrix.multiplyMatrices(n.baseMatrix,n.matrix),n.geometry.boundingBox||n.geometry.computeBoundingBox(),n.geometry.boundingBox&&(_box.copy(n.geometry.boundingBox).applyMatrix4(n.finalMatrix),_dummyPosition.y+=this.pivot.y+getSemanticPlanishOffset(n)-_box.min.y,n.matrix.compose(_dummyPosition,_dummyQuaternion,_dummyScale),n.finalMatrix.multiplyMatrices(n.baseMatrix,n.matrix)),this.#y(e),this.#p(e)}#A(e){const n=this.#f.get(e);n&&(this.setMatrixAt(e,n),this.#f.delete(e))}#q(){const e=this.pivot.y;this.facilityObjects.forEach((n,a)=>{this.#h.has(n)||this.#h.set(n,{positionY:n.position.y,scaleY:n.scale.y});const l=this.#h.get(n);n.scale.y=(l?.scaleY??n.scale.y)*PLANISH_SCALE_Y,n.updateMatrix();const t=e+getFacilityPlanishOffset(n,a);this.#M(n,_facilityBounds)?n.position.y+=t-_facilityBounds.min.y:n.position.y=t,n.updateMatrix(),markInstanceRenderDirty(n)})}#R(){this.facilityObjects.forEach(e=>{const n=this.#h.get(e);n&&(e.position.y=n.positionY,e.scale.y=n.scaleY,e.updateMatrix(),markInstanceRenderDirty(e),this.#h.delete(e))})}#M(e,n){return n.makeEmpty(),this.updateWorldMatrix(!0,!1),e.updateWorldMatrix(!0,!0),_floorMatrixInverse.copy(this.matrixWorld).invert(),e.traverse(a=>{const l=a.geometry;l&&(l.boundingBox||l.computeBoundingBox(),l.boundingBox&&(_box.copy(l.boundingBox).applyMatrix4(a.matrixWorld).applyMatrix4(_floorMatrixInverse),n.union(_box)))}),n.isEmpty()?null:n}#m(e,n){const a=this.#n(e);return a.matrix.decompose(_dummyPosition,_dummyQuaternion,_dummyScale),n(_dummyScale),a.matrix.compose(_dummyPosition,_dummyQuaternion,_dummyScale),a.finalMatrix.multiplyMatrices(a.baseMatrix,a.matrix),this.#y(e),this.#p(e),this}#d(e){this.#n(e).color.toArray(this.#a.image.data,e*4),this.#a.needsUpdate=!0}#g(e){const n=this.#n(e),a=this.#i.image.data;a[e*4]=n.visible?1:0,a[e*4+1]=0,a[e*4+2]=0,a[e*4+3]=1,this.#i.needsUpdate=!0}#p(e){this.#n(e).finalMatrix.toArray(this.#o.image.data,e*16),this.#o.needsUpdate=!0}#I(e){const n=this.#n(e),a=this.#s.image.data;a[e*4]=getSemanticRenderOffset(n),a[e*4+1]=0,a[e*4+2]=0,a[e*4+3]=1,this.#s.needsUpdate=!0}}const VENT_MATERIAL={color:6924429,opacity:.55};class VentMesh extends VerticalShaftMesh{isVentMesh=!0;type="VentMesh";constructor(e){super({shaft:e,kind:"Vents",material:VENT_MATERIAL})}static create(e){return createVerticalShaftMesh(()=>new VentMesh(e))}}function getSemanticObjectIds(f){const e=f.semanticId,n=f.instanceId;return[e,n].filter(a=>typeof a=="string"&&a.length>0)}function indexObject(f,e){getSemanticObjectIds(e).forEach(n=>{f.has(n)||f.set(n,e)})}function rebuildObjectIndex(f,e){f.clear(),e.forEach(n=>indexObject(f,n))}function getFloorReferences(f){return Array.isArray(f)?f:[f]}function resolveFloor(f,e){const n=typeof e=="number"?f.getFloorAt(e):e;if(!n||!f.hasFloor(n))throw new Error("u-space BuildingGroup: the floor is not in this building group.");return n}class BuildingGroup extends uSpace.BaseGroup{isBuildingGroup=!0;type="BuildingGroup";semanticId="";semanticKind="Buildings";semanticName="";floorMeshes=[];elevatorMeshes=[];ventMeshes=[];#e=new Set;#r=new Map;#t=new Map;#a=new Map;#i=new Map;#o=new Map;#s=new Map;#u=0;#c=!0;constructor(){super()}setSemanticIdentity(e){return e.id!==void 0&&(this.semanticId=e.id??""),e.kind!==void 0&&(this.semanticKind=e.kind??""),e.name!==void 0&&(this.semanticName=e.name??""),this}addFloor(e){return this.#e.has(e)||(this.add(e),this.floorMeshes.push(e),this.#e.add(e),indexObject(this.#r,e),this.#c=!0),this}hasFloor(e){return this.#e.has(e)}getFloorAt(e){return this.floorMeshes[e]}getFloorById(e){return this.#r.get(e)}removeFloor(e){const n=this.floorMeshes.indexOf(e);return n!==-1&&this.floorMeshes.splice(n,1),this.#e.delete(e),rebuildObjectIndex(this.#r,this.floorMeshes),this.#s.delete(e),this.#c=!0,this.remove(e),this}addElevator(e){return this.elevatorMeshes.includes(e)||(this.add(e),this.elevatorMeshes.push(e),indexObject(this.#t,e)),this}getElevatorAt(e){return this.elevatorMeshes[e]}getElevatorById(e){return this.#t.get(e)}removeElevator(e){const n=this.elevatorMeshes.indexOf(e);return n!==-1&&this.elevatorMeshes.splice(n,1),rebuildObjectIndex(this.#t,this.elevatorMeshes),this.remove(e),this}addVent(e){return this.ventMeshes.includes(e)||(this.add(e),this.ventMeshes.push(e),indexObject(this.#a,e)),this}getVentAt(e){return this.ventMeshes[e]}getVentById(e){return this.#a.get(e)}removeVent(e){const n=this.ventMeshes.indexOf(e);return n!==-1&&this.ventMeshes.splice(n,1),rebuildObjectIndex(this.#a,this.ventMeshes),this.remove(e),this}isolateFloor(e){return this.isolateFloors(getFloorReferences(e))}isolateFloors(e){if(e.length===0)throw new Error("u-space BuildingGroup: at least one floor is required to isolate floors.");const n=new Set(e.map(a=>resolveFloor(this,a)));return this.floorMeshes.forEach(a=>{a.visible=n.has(a)}),this}showAllFloors(){return this.floorMeshes.forEach(e=>{e.visible=!0}),this}showAllFacilities(){return this.floorMeshes.forEach(e=>e.showAllFacilities()),this}hideAllFacilities(){return this.floorMeshes.forEach(e=>e.hideAllFacilities()),this}getFacilityById(e){return this.#f(),this.#i.get(e)?.getFacilityById(e)}syncFacilityIndexes(){return this.#f(),this}get facilityIndexVersion(){return this.#f(),this.#u}getFacilityIndexIds(){return this.#f(),this.#i.keys()}getFacilityIndexObjects(){return this.#f(),this.#o.keys()}planishFloors(e){return this.floorMeshes.forEach(n=>n.planish(e)),this}unplanishFloors(e){return this.floorMeshes.forEach(n=>n.unplanish(e)),this}#f(){let e=this.#c||this.#s.size!==this.floorMeshes.length;for(const n of this.floorMeshes)if(this.#s.get(n)!==n.facilityIndexVersion){e=!0;break}e&&(this.#i.clear(),this.#o.clear(),this.#s.clear(),this.floorMeshes.forEach(n=>{this.#s.set(n,n.facilityIndexVersion),n.facilityObjectsById.forEach((a,l)=>{this.#i.has(l)||this.#i.set(l,n)}),n.getFacilities().forEach(a=>{this.#o.has(a)||this.#o.set(a,n)})}),this.#u++,this.#c=!1)}}class SemanticGroup extends uSpace.BaseGroup{isSemanticGroup=!0;type="SemanticGroup";buildings=[];facilityLayer=null;#e=new Set;#r=new Map;#t=new Map;#a=new Map;#i=new Map;#o=!0;constructor(){super()}addBuilding(e){return this.#e.has(e)||(this.add(e),this.buildings.push(e),this.#e.add(e),this.#s(e),this.#o=!0),this}getBuildingAt(e){return this.buildings[e]}getBuildingById(e){return this.#r.get(e)}getBuildings(){return[...this.buildings]}removeBuilding(e){const n=this.buildings.indexOf(e);return n!==-1&&this.buildings.splice(n,1),this.#e.delete(e),this.#u(),this.#i.delete(e),this.#o=!0,this.remove(e),this}get floorMeshes(){return this.buildings.flatMap(e=>e.floorMeshes)}setFacilityLayer(e){return this.facilityLayer&&this.remove(this.facilityLayer),this.facilityLayer=e,e&&this.add(e),this}getDefaultFacilityLayer(){return this.facilityLayer}showAllFacilities(){return this.buildings.forEach(e=>e.showAllFacilities()),this}hideAllFacilities(){return this.buildings.forEach(e=>e.hideAllFacilities()),this}getFacilityById(e){return this.#c(e)?.getFacilityById(e)}showAllFloors(){return this.buildings.forEach(e=>e.showAllFloors()),this}planishFloors(e){return this.buildings.forEach(n=>n.planishFloors(e)),this}unplanishFloors(e){return this.buildings.forEach(n=>n.unplanishFloors(e)),this}#s(e){const n=e.semanticId;typeof n=="string"&&n&&!this.#r.has(n)&&this.#r.set(n,e)}#u(){this.#r.clear(),this.buildings.forEach(e=>this.#s(e))}#c(e){return this.#f(),this.#t.get(e)}#f(){let e=this.#o||this.#i.size!==this.buildings.length;for(const n of this.buildings)n.syncFacilityIndexes(),this.#i.get(n)!==n.facilityIndexVersion&&(e=!0);e&&(this.#t.clear(),this.#a.clear(),this.#i.clear(),this.buildings.forEach(n=>{n.syncFacilityIndexes(),this.#i.set(n,n.facilityIndexVersion);for(const a of n.getFacilityIndexIds())this.#t.has(a)||this.#t.set(a,n);for(const a of n.getFacilityIndexObjects())this.#a.has(a)||this.#a.set(a,n)}),this.#o=!1)}}class FacilityInstanceObject extends uSpace.InstanceObject{isFacilityInstanceObject=!0;type="FacilityInstanceObject";constructor(){super({boundsName:"FacilityBounds"}),this.instanceKind="Facilities"}}class FacilityInstancedLayer extends uSpace.ModelInstancedLayer{isFacilityInstancedLayer=!0;type="FacilityInstancedLayer";constructor(){super({name:"Facilities",instanceKind:"Facilities",getHitUserData:(e,n)=>({semanticObject:e,semanticId:e.instanceId,semanticKind:e.instanceKind||"Facilities",semanticName:e.instanceName,semanticIndex:n,facility:e,facilityId:e.instanceId})})}}const SEMANTIC_INITIAL_COLORS={Walls:new webgpu.Vector4(.86,.86,.82,1),Columns:new webgpu.Vector4(.62,.65,.68,1),Spaces:new webgpu.Vector4(.36,.7,.5,.45),Doors:new webgpu.Vector4(.9,.52,.2,1),Windows:new webgpu.Vector4(.28,.62,.95,.65),Staircases:new webgpu.Vector4(.58,.55,.5,1)},STAIRCASE_WIDTH=1.2,STAIRCASE_STEP_HEIGHT=.16,STAIRCASE_LANDING_THICKNESS=.04,STAIRCASE_EPSILON=1e-5,STAIRCASE_MITER_LIMIT=3;function getInitialColor(f){return SEMANTIC_INITIAL_COLORS[f].clone()}function getValidPolygonShape(f,e,n){return!Array.isArray(f)||f.length<4||f.length%2!==0?(console.warn(`u-space SemanticLoader: invalid ${e} polygon shape for id ${n}.`),null):f}function convertToPlaneIVector2(f){const e=[];for(let n=0;n<f.length;n+=2)e.push({x:f[n],z:f[n+1]});return e}function parseStaircasePolyline(f){const e=f.Polyline;if(!Array.isArray(e)||e.length<6||e.length%3!==0)return console.warn(`u-space SemanticLoader: invalid Staircases polyline for id ${f.ID}.`),null;const n=[];for(let a=0;a<e.length;a+=3){const l={x:Number(e[a]),y:Number(e[a+1]),z:Number(e[a+2])};if(!Number.isFinite(l.x)||!Number.isFinite(l.y)||!Number.isFinite(l.z))return console.warn(`u-space SemanticLoader: invalid Staircases polyline point for id ${f.ID}.`),null;n.push(l)}return n}function createStaircaseSegments(f){const e=[];for(let n=0;n<f.length-1;n++){const a=f[n],l=f[n+1],t=l.x-a.x,h=l.z-a.z,u=Math.hypot(t,h);if(u<=STAIRCASE_EPSILON)continue;const o=t/u,s=h/u;e.push({start:a,end:l,length:u,dirX:o,dirZ:s,normalX:-s,normalZ:o})}return e}function createCapSection(f,e,n){return{leftX:e.x+f.normalX*n,leftZ:e.z+f.normalZ*n,rightX:e.x-f.normalX*n,rightZ:e.z-f.normalZ*n}}function cross2(f,e,n,a){return f*a-e*n}function getFallbackJoinPoint(f,e,n,a,l){let t=f.normalX+e.normalX,h=f.normalZ+e.normalZ,u=Math.hypot(t,h);u<=STAIRCASE_EPSILON&&(t=e.normalX,h=e.normalZ,u=1);const o=a*l/u;return{x:n.x+t*o,z:n.z+h*o}}function getMiterJoinPoint(f,e,n,a,l){const t=n.x+f.normalX*a*l,h=n.z+f.normalZ*a*l,u=n.x+e.normalX*a*l,o=n.z+e.normalZ*a*l,s=cross2(f.dirX,f.dirZ,e.dirX,e.dirZ);if(Math.abs(s)<=STAIRCASE_EPSILON)return{x:t,z:h};const r=cross2(u-t,o-h,e.dirX,e.dirZ)/s,c=t+f.dirX*r,d=h+f.dirZ*r,p=Math.hypot(c-n.x,d-n.z);return!Number.isFinite(p)||p>l*STAIRCASE_MITER_LIMIT?getFallbackJoinPoint(f,e,n,a,l):{x:c,z:d}}function createJoinSection(f,e,n,a){const l=getMiterJoinPoint(f,e,n,1,a),t=getMiterJoinPoint(f,e,n,-1,a);return{leftX:l.x,leftZ:l.z,rightX:t.x,rightZ:t.z}}function interpolateSection(f,e,n){return{leftX:f.leftX+(e.leftX-f.leftX)*n,leftZ:f.leftZ+(e.leftZ-f.leftZ)*n,rightX:f.rightX+(e.rightX-f.rightX)*n,rightZ:f.rightZ+(e.rightZ-f.rightZ)*n}}function addQuad(f,e,n,a,l){f.push(e,n,a,e,a,l)}function addStaircasePrism(f,e,n,a,l,t,h,u){if(a-n<=STAIRCASE_EPSILON)return;const o=l.length/3;l.push(f.leftX,n,f.leftZ,e.leftX,n,e.leftZ,e.rightX,n,e.rightZ,f.rightX,n,f.rightZ,f.leftX,a,f.leftZ,e.leftX,a,e.leftZ,e.rightX,a,e.rightZ,f.rightX,a,f.rightZ),addQuad(t,o+4,o+5,o+6,o+7),addQuad(t,o+0,o+3,o+2,o+1),addQuad(t,o+0,o+1,o+5,o+4),addQuad(t,o+2,o+3,o+7,o+6),h&&addQuad(t,o+3,o+0,o+4,o+7),u&&addQuad(t,o+1,o+2,o+6,o+5)}function createStaircaseGeometry(f){const e=parseStaircasePolyline(f),n=Number(f.Elevation??0);if(!e||!Number.isFinite(n))return Number.isFinite(n)||console.warn(`u-space SemanticLoader: invalid Staircases elevation for id ${f.ID}.`),null;const a=createStaircaseSegments(e);if(a.length===0)return console.warn(`u-space SemanticLoader: empty Staircases geometry for id ${f.ID}.`),null;const l=STAIRCASE_WIDTH/2,t=[],h=[];if(a.forEach((o,s)=>{const r=a[s-1],c=a[s+1],d=r?createJoinSection(r,o,o.start,l):createCapSection(o,o.start,l),p=c?createJoinSection(o,c,o.end,l):createCapSection(o,o.end,l),v=o.end.y-o.start.y;if(Math.abs(v)<=STAIRCASE_EPSILON){const x=n+o.start.y;addStaircasePrism(d,p,x-STAIRCASE_LANDING_THICKNESS,x,t,h,!r,!c);return}const B=Math.max(1,Math.round(Math.abs(v)/STAIRCASE_STEP_HEIGHT)),E=Math.abs(v)/B;for(let x=0;x<B;x++){const P=v>0,D=P?x/B:1-(x+1)/B,$=P?(x+1)/B:1-x/B,H=interpolateSection(d,p,D),Y=interpolateSection(d,p,$),ne=n+(P?o.start.y:o.end.y)+E*(x+1),te=ne-E;addStaircasePrism(H,Y,te,ne,t,h,!0,s===a.length-1&&x===B-1)}}),t.length===0)return console.warn(`u-space SemanticLoader: empty Staircases geometry for id ${f.ID}.`),null;const u=new webgpu.BufferGeometry;return u.setAttribute("position",new webgpu.Float32BufferAttribute(t,3)),u.setIndex(h),u.computeVertexNormals(),u.computeBoundingBox(),u.computeBoundingSphere(),u.userData.id=f.ID,u}function collectTreeNodesById(f){const e=new Map,n=(f??[]).map(a=>({node:a,parentWorldMatrix:new webgpu.Matrix4}));for(;n.length>0;){const a=n.pop(),l=a?.node;if(!l)continue;const t=getTreeNodeLocalMatrix(l);if(!t||!a)continue;const h=a.parentWorldMatrix.clone().multiply(t);e.set(l.id,{node:l,worldMatrix:h}),n.push(...(l.children??[]).map(u=>({node:u,parentWorldMatrix:h})))}return e}function getTreeNodeLocalMatrix(f){if(!Array.isArray(f.matrix)||f.matrix.length<16)return console.warn(`u-space SemanticLoader: invalid tree_models matrix for id ${f.id}.`),null;const e=f.matrix.slice(0,16).map(Number);return e.some(n=>!Number.isFinite(n))?(console.warn(`u-space SemanticLoader: invalid tree_models matrix value for id ${f.id}.`),null):new webgpu.Matrix4().fromArray(e)}function applyWorldMatrix(f,e,n){n.updateWorldMatrix(!0,!1);const a=e.clone();a.premultiply(new webgpu.Matrix4().copy(n.matrixWorld).invert()),a.decompose(f.position,f.quaternion,f.scale),f.updateMatrix()}function getModelUrl(f,e){return`${f??""}${e}`}function getTreeNodeUserData(f){return{id:f.id,pid:f.pid,name:f.name,path:f.path,renderType:f.renderType,deviceCode:f.deviceCode,matrix:f.matrix,familyId:f.familyId,visible:f.visible,shape:f.shape,boundingBox:f.boundingBox,extra:f.extra}}async function loadFacilityObject(f,e){const n=new uSpace.Model;e.manager?.itemStart(f);try{if(!await n.loadAsync({url:f}))return e.manager?.itemError(f),null}catch(a){throw e.manager?.itemError(f),a}finally{e.manager?.itemEnd(f)}return n}async function createFacilityModel(f,e,n){if(e.renderType!=="3D"||!e.path)return console.warn(`u-space SemanticLoader: invalid Facilities tree node for id ${f.ID}.`),null;const a=getModelUrl(n.path,e.path),l=await loadFacilityObject(a,n);return l?(l.name=f.Name||e.name||"",l.visible=e.visible,Object.assign(l.userData,getTreeNodeUserData(e),{facility:f,facilityId:f.ID,semanticId:f.ID,semanticKind:"Facilities",semanticName:f.Name,spaces:f.Spaces,twinsIdentifier:f.TwinsIdentifier}),l):null}class SemanticParser{parse(e){return this.#e(e).scene}async parseAsync(e,n={}){const a=this.#e(e,n);return await this.#r(e,a,n),a.scene}#e(e,n={}){const a=new SemanticGroup;a.name="SemanticGroup";const l=[],t=new Map;return e.Buildings?.forEach(h=>{const u=new BuildingGroup;u.name=h.Name||"",u.setSemanticIdentity({id:h.ID,kind:"Buildings",name:h.Name}),u.userData.id=h.ID,h.Stories.forEach(o=>{const s=e.Stories?.[o];if(s&&s.ID){const r=[];if(s.Walls?.forEach(d=>{const p=e.Walls?.[d];if(!p||!p.Polygon)return;const v=getValidPolygonShape(p.Polygon.shape,"Walls",p.ID);if(!v)return;const m=uSpace.ExtrudeMesh.createFromPoints(convertToPlaneIVector2(v),{geometryParameters:{options:{depth:p.Height,bevelEnabled:!1}}}).geometry;m.translate(0,p.Elevation,0),m.userData.id=p.ID,r.push({id:p.ID,kind:"Walls",geometry:m,color:getInitialColor("Walls")})}),s.Columns?.forEach(d=>{const p=e.Columns?.[d];if(!p||!p.Polygon)return;const v=getValidPolygonShape(p.Polygon.shape,"Columns",p.ID);if(!v)return;const m=uSpace.ExtrudeMesh.createFromPoints(convertToPlaneIVector2(v),{geometryParameters:{options:{depth:p.Height,bevelEnabled:!1}}}).geometry;m.translate(0,p.Elevation,0),m.userData.id=p.ID,r.push({id:p.ID,kind:"Columns",geometry:m,color:getInitialColor("Columns")})}),s.Doors?.forEach(d=>{const p=e.Doors?.[d];if(!p||!p.Polygon)return;const v=getValidPolygonShape(p.Polygon.shape,"Doors",p.ID);if(!v)return;const m=uSpace.ExtrudeMesh.createFromPoints(convertToPlaneIVector2(v),{geometryParameters:{options:{depth:p.Height,bevelEnabled:!1}}}).geometry;m.translate(0,p.Elevation,0),m.userData.id=p.ID,r.push({id:p.ID,kind:"Doors",geometry:m,color:getInitialColor("Doors")})}),s.Windows?.forEach(d=>{const p=e.Windows?.[d];if(!p||!p.Polygon)return;const v=getValidPolygonShape(p.Polygon.shape,"Windows",p.ID);if(!v)return;const m=uSpace.ExtrudeMesh.createFromPoints(convertToPlaneIVector2(v),{geometryParameters:{options:{depth:p.Height,bevelEnabled:!1}}}).geometry;m.translate(0,p.Elevation,0),m.userData.id=p.ID,r.push({id:p.ID,kind:"Windows",geometry:m,color:getInitialColor("Windows")})}),s.Spaces?.forEach(d=>{const p=e.Spaces?.[d];if(!p||!p.Polygon)return;const v=getValidPolygonShape(p.Polygon.shape,"Spaces",p.ID);if(!v)return;const m=p.CeilingHeight-p.GroundHeight,B=uSpace.ExtrudeMesh.createFromPoints(convertToPlaneIVector2(v),{geometryParameters:{options:{depth:m,bevelEnabled:!1}}}).geometry;B.translate(0,p.GroundHeight,0),B.userData.id=p.ID,r.push({id:p.ID,kind:"Spaces",name:p.Name,geometry:B,color:getInitialColor("Spaces")})}),s.Staircases?.forEach(d=>{const p=e.Staircases?.[d];if(!p)return;const v=createStaircaseGeometry(p);v&&(v.userData.storyId=s.ID,v.userData.floorIndex=s.FloorIndex,r.push({id:p.ID,kind:"Staircases",geometry:v,color:getInitialColor("Staircases")}))}),r.length===0&&!s.Facilities?.length)return;const c=new FloorMesh(r);c.name=s.Name||"",c.setSemanticIdentity({id:s.ID,kind:"Floors",name:s.Name}),c.userData.id=s.ID,c.userData.storyIndex=o,c.getSemantics().forEach(d=>{d.type==="geometry"&&n.registerObject?.(d.id,d.object)}),c.pivot=new webgpu.Vector3(0,s.Elevation||0,0),u.addFloor(c),t.set(o,c)}}),h.Elevators?.forEach(o=>{const s=e.Elevators?.[o];if(!s)return;const r=ElevatorMesh.create(s);r&&u.addElevator(r)}),h.Vents?.forEach(o=>{const s=e.Vents?.[o];if(!s)return;const r=VentMesh.create(s);r&&u.addVent(r)}),a.addBuilding(u),l.push(u)}),{scene:a,buildings:l,floorByStoryIndex:t}}async#r(e,n,a){const l=e.Facilities;if(!l?.length)return;const t=collectTreeNodesById(a.treeData);if(t.size===0){console.warn("u-space SemanticLoader: tree_models data is required to parse Facilities.");return}const h=[],u=new Set;e.Buildings?.forEach(o=>{o.Stories.forEach(s=>{const r=e.Stories?.[s];if(!r?.Facilities?.length)return;const c=n.floorByStoryIndex.get(s);if(!c){console.warn(`u-space SemanticLoader: Facilities floor not found for story id ${r.ID}.`);return}r.Facilities.forEach(d=>{const p=l[d];if(!p||u.has(p.ID))return;const v=t.get(p.ID);if(!v){console.warn(`u-space SemanticLoader: Facilities tree node not found for id ${p.ID}.`);return}const{node:m,worldMatrix:B}=v;if(m.renderType!=="3D"||!m.path){console.warn(`u-space SemanticLoader: invalid Facilities tree node for id ${p.ID}.`);return}u.add(p.ID),h.push({facility:p,story:r,floorMesh:c,treeNode:m,worldMatrix:B,url:getModelUrl(a.path,m.path)})})})}),await this.#t(h,n.scene,a)}async#t(e,n,a){if(e.length===0)return;const l=new FacilityInstancedLayer,t=new Map,h=[];e.forEach(u=>{const o=t.get(u.url);o?o.push(u):t.set(u.url,[u])});for(const[u,o]of t){const s=await loadFacilityObject(u,a);if(!s){h.push(...o);continue}const r=o.map(d=>this.#a(d));l.addInstances(u,s,r)?r.forEach((d,p)=>{const v=o[p];this.#o(d,v.facility,a)}):(r.forEach((d,p)=>{o[p].floorMesh.removeFacility(d)}),h.push(...o))}l.children.length>0&&n.setFacilityLayer(l),await Promise.all(h.map(u=>this.#i(u,a)))}#a(e){const{facility:n,story:a,floorMesh:l,treeNode:t,worldMatrix:h}=e,u=new FacilityInstanceObject;return u.name=n.Name||t.name||"",u.visible=t.visible,u.setInstanceIdentity({id:n.ID,kind:"Facilities",name:n.Name}),Object.assign(u.userData,getTreeNodeUserData(t),{facility:n,facilityId:n.ID,spaces:n.Spaces,twinsIdentifier:n.TwinsIdentifier,storyId:a.ID,floorIndex:a.FloorIndex,instanced:!0,modelUrl:e.url}),applyWorldMatrix(u,h,l),l.addFacility(u,n.ID),u}async#i(e,n){const{facility:a,story:l,treeNode:t}=e,h=await createFacilityModel(a,t,n);if(!h)return;const u=this.#a(e);u.userData.instanced=!1,Object.assign(h.userData,{storyId:l.ID,floorIndex:l.FloorIndex,instanced:!1}),h.position.set(0,0,0),h.quaternion.identity(),h.scale.set(1,1,1),u.setInstanceRenderObject(h),this.#o(u,a,n)}#o(e,n,a){a.registerObject?.(n.ID,e)}}class SemanticLoader extends webgpu.Loader{viewer;key="";cachedIds=new Set;constructor(e){super(),this.viewer=e,this.manager=new webgpu.LoadingManager}setKey(e){return this.key=e,this}async#e(e){const n=await e.loadAsync(META_DATA_FILE_PATH);if(n.version<1.5)throw new Error("u-space SemanticLoader: Only support version 1.5 and above");if(!this.key&&n.authority==="OFFICIAL")throw new Error("u-space SemanticLoader: options.key is required when authority is OFFICIAL");this.key&&n.authority==="TRIAL"&&console.warn("u-space SemanticLoader: options.key is not used when authority is TRIAL");const a=n.treeModel||n.resource,l=await e.loadAsync(a);if(n.encryptWith==="DEBUG")try{return decryptWithDebugKey(l)}catch{throw new Error("u-space SemanticLoader: decrypt with debug key failed")}if(n.encryptWith==="SCENE"||n.encryptWith==="COMPANY")try{return decryptWithKey(l,this.key)}catch{throw new Error("u-space SemanticLoader: decrypt with authorized key failed")}return l}#r(e,n){this.viewer.objectManager.add(e,n),this.cachedIds.add(e)}async loadAsync(){if(!this.path)throw new Error("u-space SemanticLoader: path is not set");this.manager.itemStart(this.path);let e=!1;try{const n=new BaseFileLoader(this),a=await n.loadAsync(SEMANTIC_DATA_FILE_PATH),l=a.Facilities?.length?await this.#e(n):void 0,t=new SemanticParser;return this.clearCache(),e=!0,t.parseAsync(a,{treeData:l,path:this.path,manager:this.manager,registerObject:(h,u)=>this.#r(h,u)})}catch(n){throw e&&this.clearCache(),this.manager.itemError(this.path),n}finally{this.manager.itemEnd(this.path)}}clearCache(){this.cachedIds.forEach(e=>{this.viewer.objectManager.removeById(e)}),this.cachedIds.clear()}dispose(){this.clearCache()}}class UManagerSceneGroup extends uSpace.BaseGroup{isUManagerSceneGroup=!0;type="UManagerSceneGroup";semanticGroup;sceneGroup;constructor(e,n){super(),this.name="UManagerScene",this.semanticGroup=e,this.sceneGroup=n,this.add(e),this.add(n)}}class UManagerLoader extends webgpu.Loader{viewer;key="";sceneLoader;semanticLoader;constructor(e){super(),this.viewer=e,this.manager=new webgpu.LoadingManager,this.sceneLoader=new SceneLoader(e),this.semanticLoader=new SemanticLoader(e)}setKey(e){return this.key=e,this.sceneLoader.setKey(e),this.semanticLoader.setKey(e),this}async loadAsync(){if(!this.path)throw new Error("u-space UManagerLoader: path is not set");this.#e(),this.manager.itemStart(this.path);try{const[e,n]=await Promise.allSettled([this.semanticLoader.loadAsync(),this.sceneLoader.loadAsync()]);if(e.status==="rejected")throw e.reason;if(n.status==="rejected")throw n.reason;const a=e.value,l=n.value;return new UManagerSceneGroup(a,l)}catch(e){throw this.clearCache(),this.manager.itemError(this.path),e}finally{this.manager.itemEnd(this.path)}}clearCache(){this.sceneLoader.clearCache(),this.semanticLoader.clearCache()}dispose(){this.sceneLoader.dispose(),this.semanticLoader.dispose()}#e(){for(const e of[this.sceneLoader,this.semanticLoader])e.setPath(this.path),e.setRequestHeader(this.requestHeader),e.setWithCredentials(this.withCredentials),e.manager=this.manager,this.key&&e.setKey(this.key)}}class AnimationsLoader extends webgpu.Loader{constructor(){super(),this.manager=new webgpu.LoadingManager}async loadAsync(){return await new BaseFileLoader(this).loadAsync(ANIMATIONS_DATA_FILE_PATH)}}class AnimationsParser extends webgpu.EventDispatcher{viewer;target;tweenSet;_initialTransformSymbol=Symbol("initialTransform");constructor(e,n){super(),this.viewer=e,this.target=n,this.tweenSet=new Set}initTransform(e){const{position:n,rotation:a,scale:l}=this.target,t=e??{x:n.x,y:n.y,z:n.z,rotationX:a.x,rotationY:a.y,rotationZ:a.z,scaleX:l.x,scaleY:l.y,scaleZ:l.z};return Reflect.set(this.target,this._initialTransformSymbol,t),t}getInitialTransform(){return Reflect.get(this.target,this._initialTransformSymbol)}async play(e){let n=this.getInitialTransform();n||(n=this.initTransform());for(let a=0;a<e.length;a++){let l=e[a-1];l||(l=n);const t=e[a],h=t.delay??0,u=t.duration??1e3,o=t.easing,s=t.repeat===-1?1/0:t.repeat??0,r=t.yoyo??!1;await uSpace.tweenAnimation(this.viewer,{...l},{...t},{delay:h,duration:u,mode:o,repeat:s,yoyo:r},(c,d)=>{const{x:p,y:v,z:m,rotationX:B,rotationY:E,rotationZ:x,scaleX:P,scaleY:D,scaleZ:$}=c;this.target.position.set(p,v,m),this.target.rotation.set(B,E,x),this.target.scale.set(P,D,$),this.dispatchEvent({type:"update",source:c,tween:d})},c=>{this.tweenSet.add(c),this.dispatchEvent({type:"start",tween:c})})}}stop(){this.tweenSet.forEach(e=>e.stop()),this.tweenSet.clear()}reset(){const e=this.getInitialTransform();if(e){const{x:n,y:a,z:l,rotationX:t,rotationY:h,rotationZ:u,scaleX:o,scaleY:s,scaleZ:r}=e;this.target.position.set(n,a,l),this.target.rotation.set(t,h,u),this.target.scale.set(o,s,r),this.viewer.invalidate()}}dispose(){this.stop(),this.reset(),Reflect.deleteProperty(this.target,this._initialTransformSymbol)}}class TopologyParser{parse(e){const{name:n,position:a,rotation:l,scale:t,nodes:h,nodeRadius:u=.2,nodeColor:o="#0000ff",linkWidth:s=.1,linkColor:r=["#00ff00"]}=e,c=new uSpace.Topology({nodeRadius:u,nodeColor:o,edgeRadius:s,edgeColor:r[0],pathRadius:s+.05});return c.name=n,c.position.set(a.x,a.y,a.z),c.rotation.set(l.x,l.y,l.z),c.scale.set(t.x,t.y,t.z),h.forEach(d=>{const p=new webgpu.Vector3().copy(d.position);c.addNode(d.id,p)}),h.forEach(d=>{d.graphs.forEach(p=>{c.addEdge(d.id,p.targetNodeId)})}),c.renderGraph(),Object.assign(c.userData,e),c}}class TopologiesLoader extends webgpu.Loader{constructor(){super(),this.manager=new webgpu.LoadingManager}async loadAsync(){if(!this.path)throw new Error("u-manager TopologiesLoader: path is not set");const n=await new BaseFileLoader(this).loadAsync(TOPOLOGY_DATA_FILE_PATH),a=new TopologyParser,l=[];return n.forEach(t=>{const h=a.parse(t);l.push(h)}),l}}class PropertiesLoader extends webgpu.Loader{constructor(){super(),this.manager=new webgpu.LoadingManager}async loadAsync(){return await new BaseFileLoader(this).loadAsync(PROPERTIES_DATA_FILE_PATH)}}class VisionsLoader extends webgpu.Loader{constructor(){super(),this.manager=new webgpu.LoadingManager}async loadAsync(){return await new BaseFileLoader(this).loadAsync(VISIONS_DATA_FILE_PATH)}}class VisionsParser{viewer;constructor(e){this.viewer=e}async flyToPrimary(e,n=!0){const a=e.find(l=>l.primary);return a?(await this.flyTo(a,n),!0):!1}async flyTo(e,n=!0){const{camera:a,position:l,target:t,zoom:h=this.viewer.camera.zoom}=e;a==="P"?this.viewer.setCameraByType("perspective"):a==="O"&&this.viewer.setCameraByType("orthographic");const{x:u,y:o,z:s}=l,{x:r,y:c,z:d}=t;await Promise.all([this.viewer.controls.setLookAt(u,o,s,r,c,d,n),this.viewer.controls.zoomTo(h,n)])}}class Edge{id;source;target;sourceHandle;constructor(e){this.id=e.id,this.source=e.source,this.target=e.target,this.sourceHandle=e.sourceHandle}}function objectHandle(f,e){return Array.isArray(f)?f.map(e):e(f)}function sleep(f){return new Promise(e=>setTimeout(e,f))}function parseNodeByType(f,e){switch(e.type){case"START":return new StartNode(f,e);case"COLOR":return new ColorNode(f,e);case"NUMBER":return new NumberNode(f,e);case"HIGHLIGHT":return new HighlightNode(f,e);case"UN_HIGHLIGHT":return new UnHighlightNode(f,e);case"OPACITY":return new OpacityNode(f,e);case"UN_OPACITY":return new UnOpacityNode(f,e);case"EMISSIVE":return new EmissiveNode(f,e);case"UN_EMISSIVE":return new UnEmissiveNode(f,e);case"MESH":return new MeshNode(f,e);case"MESHES":return new MeshesNode(f,e);case"MODEL":return new ModelNode(f,e);case"MODELS":return new ModelsNode(f,e);case"SPACE":return new SpaceNode(f,e);case"SPACES":return new SpacesNode(f,e);case"POIS":return new POIsNode(f,e);case"POI":return new POINode(f,e);case"PATH":return new PathNode(f,e);case"PATHS":return new PathsNode(f,e);case"DELAY":return new DelayNode(f,e);case"CONDITION_NODE":return new ConditionNode(f,e);case"SHOW":return new ShowNode(f,e);case"HIDE":return new HideNode(f,e);case"CLIP_ANIMATION":return new ClipAnimationNode(f,e);case"UN_CLIP_ANIMATION":return new UnClipAnimationNode(f,e);case"TWEEN_ANIMATION":return new TweenAnimationNode(f,e);case"UN_TWEEN_ANIMATION":return new UnTweenAnimationNode(f,e);case"COMPONENT_TWEEN_ANIMATION":return new ComponentTweenAnimationNode(f,e);case"UN_COMPONENT_TWEEN_ANIMATION":return new UnComponentTweenAnimationNode(f,e);case"TRANSLATE":return new TranslateNode(f,e);case"ROTATE":return new RotateNode(f,e);case"SCALE":return new ScaleNode(f,e);case"FLY_TO":return new FlyToNode(f,e);case"DATA_EXTRACTION":return new DataExtractionNode(f,e);case"DATA_FILTER":return new DataFilterNode(f,e);case"USER_DATA_NODE":return new UserDataNode(f,e);default:return new Node(f,e)}}function parseValue(f){return JSON.parse(f)}async function waitFor(f,e){e?await f():f()}function getObjectByIds(f,e){return e.map(n=>f.objectManager.getById(n)).filter(Boolean)}function getObjectById(f,e,n){const a=f.objectManager.getById(e);if(a)return a;{const l=f.scene;return getMeshByUserDataUuid(n??l,e)}}function getMeshByUserDataUuid(f,e){if(f.userData.key===e||f.uuid===e)return f;for(let n=0,a=f.children.length;n<a;n++){const l=f.children[n],t=getMeshByUserDataUuid(l,e);if(t!==null)return t}return null}let count=0;const preloadNodes=["MESH","MESHES","MODEL","MODELS","POI","POIS","SPACE","SPACES","PATH","PATHS","COLOR","NUMBER","DATA_EXTRACTION","DATA_FILTER","USER_DATA_NODE","CONDITION_NODE","START"];class Node{parser;viewer;id;type;props;prevNodes=[];postNodes=[];execOrder=0;ctx;promise;resolve;reject;cleanSets=new Set;onBefore=null;onAfter=null;rejected;constructor(e,n){this.parser=e,this.viewer=e.viewer,this.id=n.id,this.type=n.type,this.props=n.props,this.rejected=!1,this.init()}init(){this.ctx={},this.promise=new Promise((e,n)=>{this.resolve=e,this.reject=a=>{this.rejected=!0,n(a)}})}readContext(e){return this.ctx[e]}writeContext(e,n){this.ctx[e]=n}findProp(e,n){if(n instanceof Array)for(const a of n){const l=this.findProp(e,a);if(l)return l}else return this.props.find(a=>a.name===e&&a.type===n)}async waitForPrevNodes(){return await Promise.all(this.prevNodes.map(e=>e.promise))}mergeContext(){this.prevNodes.forEach(e=>{Object.assign(this.ctx,e.ctx)}),this._mergeUserDataMap()}async exec(e){}async run(e,n={preload:!1}){const{preload:a}=n;try{if(await this.waitForPrevNodes(),this.rejected)throw new Error;this.mergeContext(),await(this.onBefore??this.parser.onNodeBefore)?.(this);try{(!a||preloadNodes.includes(this.type))&&(this.execOrder=++count,await this.exec(e))}catch(l){throw this.reject(l),l}await(this.onAfter??this.parser.onNodeAfter)?.(this),this.resolve()}catch(l){this.reject(l)}}cleanup(){this.cleanSets.forEach(e=>e()),this.cleanSets.clear()}getValue(e,n){if(e.type==="READ_CTX")return this.readContext(parseValue(e.value));if(e.type==="LOCAL"){const{scene:a}=this.viewer;return e.name==="objects"||e.name==="models"||e.name==="meshs"?parseValue(e.value).map(l=>getObjectById(this.viewer,l,n??a)):e.name==="object"||e.name==="model"||e.name==="mesh"?getObjectById(this.viewer,parseValue(e.value),n??a):parseValue(e.value)}}_mergeUserDataMap(){if(this.prevNodes.some(e=>e.ctx._userDataMap))this.ctx._userDataMap=new Map;else return;this.prevNodes.forEach(e=>{e.ctx._userDataMap&&e.ctx._userDataMap.forEach((n,a)=>{this.ctx._userDataMap.set(a,Object.assign({},n))})})}}class StartNode extends Node{constructor(e,n){super(e,n)}}class ColorNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("color","LOCAL"),n=this.findProp("out","WRITE_CTX");e&&n&&this.writeContext(parseValue(n.value),parseValue(e.value))}}class NumberNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("number","LOCAL"),n=this.findProp("out","WRITE_CTX");e&&n&&this.writeContext(parseValue(n.value),parseValue(e.value))}}class HighlightNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=this.findProp("color",["READ_CTX","LOCAL"]),l=this.findProp("opacity",["READ_CTX","LOCAL"]),t=await e.getTarget?.(this);if(n&&a&&l){const h=this.getValue(n,t),u=this.getValue(a),o=this.getValue(l);h&&(index.MaterialEffects.highlightColor(h,{color:u,opacity:o}),this.cleanSets.add(()=>{index.MaterialEffects.removeHighlightColor(h)}))}}}class UnHighlightNode extends Node{constructor(e,n){super(e,n)}filterUnHighlightObject(e){const n=[];return objectHandle(e,a=>{n.push(a)}),n}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=await e.getTarget?.(this);if(n){const l=this.getValue(n,a);l&&uSpace.MaterialEffects.removeHighlightColor(l)}}}class OpacityNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=this.findProp("color",["READ_CTX","LOCAL"]),l=this.findProp("opacity",["READ_CTX","LOCAL"]),t=await e.getTarget?.(this);if(n&&a&&l){const h=this.getValue(n,t),u=this.getValue(a),o=this.getValue(l);if(h){const s=objectHandle(h,r=>r);index.MaterialEffects.highlightColor(s,{color:u,opacity:o,overwrite:!0}),this.cleanSets.add(()=>{index.MaterialEffects.removeHighlightColor(s)})}}}}class UnOpacityNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=await e.getTarget?.(this);if(n){const l=this.getValue(n,a);l&&uSpace.MaterialEffects.removeHighlightColor(l)}}}class EmissiveNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=this.findProp("color",["READ_CTX","LOCAL"]),l=this.findProp("baseColor",["READ_CTX","LOCAL"]),t=this.findProp("minOpacity",["READ_CTX","LOCAL"]),h=this.findProp("maxOpacity",["READ_CTX","LOCAL"]),u=this.findProp("duration",["READ_CTX","LOCAL"]),o=await e.getTarget?.(this);if(n&&a&&l&&t&&h&&u){const s=this.getValue(n,o),r=this.getValue(a),c=this.getValue(h);s&&(uSpace.MaterialEffects.breatheColor(s,{color:r,intensity:c}),this.cleanSets.add(()=>{uSpace.MaterialEffects.removeBreatheColor(s)}))}}}class UnEmissiveNode extends Node{constructor(e,n){super(e,n)}filterUnEmissiveObject(e){const n=[];return objectHandle(e,a=>{n.push(a)}),n}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=await e.getTarget?.(this);n&&this.getValue(n,a)}}const meshCacheSymbol=Symbol("meshCache");class MeshNode extends Node{constructor(e,n){super(e,n)}async exec(e){const{scene:n}=this.viewer,a=await e.getTarget?.(this)||n;e[meshCacheSymbol]||(e[meshCacheSymbol]={});const l=this.findProp("mesh","LOCAL"),t=this.findProp("out","WRITE_CTX");if(l&&t){let h=null;const u=parseValue(l.value),o=parseValue(t.value),s=e[meshCacheSymbol][u];if(s){h=s;return}const r=getMeshByUserDataUuid(a,u);r&&(h=r,e[meshCacheSymbol][u]=r),this.writeContext(o,h)}}}const meshesCacheSymbol=Symbol("meshesCache");class MeshesNode extends Node{constructor(e,n){super(e,n)}async exec(e){const{scene:n}=this.viewer,a=await e.getTarget?.(this)||n;e[meshesCacheSymbol]||(e[meshesCacheSymbol]={});const l=this.findProp("meshes","LOCAL"),t=this.findProp("out","WRITE_CTX");if(l&&t){const h=[],u=parseValue(l.value),o=parseValue(t.value);u.forEach(s=>{const r=e[meshesCacheSymbol][s];if(r){h.push(r);return}const c=getMeshByUserDataUuid(a,s);c&&(h.push(c),e[meshesCacheSymbol][s]=c)}),this.writeContext(o,h)}}}class ModelNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("model","LOCAL"),n=this.findProp("out","WRITE_CTX");if(e&&n){const a=parseValue(e.value),l=parseValue(n.value);this.writeContext(l,getObjectById(this.viewer,a))}}}class ModelsNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("models","LOCAL"),n=this.findProp("out","WRITE_CTX");if(e&&n){const a=parseValue(e.value),l=parseValue(n.value);this.writeContext(l,getObjectByIds(this.viewer,a))}}}class DelayNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("delay","LOCAL");if(e){const n=parseValue(e.value);await sleep(n)}}}class ConditionNode extends Node{constructor(e,n){super(e,n)}execFn(e){return new Function("sourceData",e)(this.ctx)}async exec(){const e=this.findProp("conditaion_node","LOCAL");if(e){const n=parseValue(e.value),a=this.parser.edges.filter(l=>l.source===this.id);n.forEach(l=>{try{if(this.execFn(l.value)!==!0)throw new Error}catch{const h=a.find(o=>o.sourceHandle==String(l.id));if(!h)return;this.postNodes.find(o=>o.id===h.target)?.reject()}})}}}class ShowNode extends Node{constructor(e,n){super(e,n)}filterShowObject(e){const n=[];return objectHandle(e,a=>{a.visible===!1&&n.push(a)}),n}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=await e.getTarget?.(this);if(n){const l=this.getValue(n,a);if(l){const t=this.filterShowObject(l),h=u=>{objectHandle(t,o=>{o.visible=u}),this.viewer.invalidate()};h(!0),this.cleanSets.add(()=>h(!1))}}}}class HideNode extends Node{constructor(e,n){super(e,n)}filterHideObject(e){const n=[];return objectHandle(e,a=>{a.visible===!0&&n.push(a)}),n}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=await e.getTarget?.(this);if(n){const l=this.getValue(n,a);if(l){const t=this.filterHideObject(l),h=u=>{objectHandle(t,o=>{o.visible=u}),this.viewer.invalidate()};h(!1),this.cleanSets.add(()=>h(!0))}}}}class TranslateNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=this.findProp("axis",["READ_CTX","LOCAL"]),l=this.findProp("translate",["READ_CTX","LOCAL"]),t=await e.getTarget?.(this);if(n&&a&&l){const h=this.getValue(n,t),u=this.getValue(a),o=this.getValue(l);if(h){const s=[];objectHandle(h,p=>{s.push(p.position.clone())});const c=(p,v)=>{switch(u){case"x":p.setX(v.x);break;case"y":p.setY(v.y);break;case"z":p.setZ(v.z);break}};await(async()=>{const p=objectHandle(h,async v=>{const m=v.position.clone();switch(u){case"x":await uSpace.tweenAnimation(this.viewer,m,new webgpu.Vector3().set(m.x+o,m.y,m.z),{duration:800},B=>c(v.position,B));break;case"y":await uSpace.tweenAnimation(this.viewer,m,new webgpu.Vector3().set(m.x,m.y+o,m.z),{duration:800},B=>c(v.position,B));break;case"z":await uSpace.tweenAnimation(this.viewer,m,new webgpu.Vector3().set(m.x,m.y,m.z+o),{duration:800},B=>c(v.position,B));break}});p instanceof Array?await Promise.all(p):await p,this.viewer.invalidate()})(),this.cleanSets.add(()=>{let p=0;objectHandle(h,v=>{v.position.copy(s[p++])})})}}}}class ScaleNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=this.findProp("axis",["READ_CTX","LOCAL"]),l=this.findProp("scale",["READ_CTX","LOCAL"]),t=await e.getTarget?.(this);if(n&&a&&l){const h=this.getValue(n,t),u=this.getValue(a),o=this.getValue(l);if(h){const s=[];objectHandle(h,p=>{s.push(p.scale.clone())});const c=(p,v)=>{switch(u){case"x":p.setX(v.x);break;case"y":p.setY(v.y);break;case"z":p.setZ(v.z);break}};await(async()=>{const p=objectHandle(h,async v=>{const m=v.scale.clone();switch(u){case"x":await uSpace.tweenAnimation(this.viewer,m,new webgpu.Vector3().set(m.x*o,m.y,m.z),{duration:800},B=>c(v.scale,B));break;case"y":await uSpace.tweenAnimation(this.viewer,m,new webgpu.Vector3().set(m.x,m.y*o,m.z),{duration:800},B=>c(v.scale,B));break;case"z":await uSpace.tweenAnimation(this.viewer,m,new webgpu.Vector3().set(m.x,m.y,m.z*o),{duration:800},B=>c(v.scale,B));break}});p instanceof Array?await Promise.all(p):await p,this.viewer.invalidate()})(),this.cleanSets.add(()=>{let p=0;objectHandle(h,v=>{v.scale.copy(s[p++])})})}}}}class RotateNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=this.findProp("axis",["READ_CTX","LOCAL"]),l=this.findProp("rotation",["READ_CTX","LOCAL"]),t=await e.getTarget?.(this);if(n&&a&&l){const h=this.getValue(n,t),u=this.getValue(a),o=this.getValue(l);if(h){const s=[];objectHandle(h,p=>{s.push(p.rotation.clone())});const c=(p,v)=>{switch(u){case"x":p.x=v.x;break;case"y":p.y=v.y;break;case"z":p.z=v.z;break}};await(async()=>{const p=o/180*Math.PI,v=objectHandle(h,async m=>{const B=m.rotation.clone();switch(u){case"x":await uSpace.tweenAnimation(this.viewer,B,new webgpu.Euler().set(B.x+p,B.y,B.z),{duration:800},E=>c(m.rotation,E));break;case"y":await uSpace.tweenAnimation(this.viewer,B,new webgpu.Euler().set(B.x,B.y+p,B.z),{duration:800},E=>c(m.rotation,E));break;case"z":await uSpace.tweenAnimation(this.viewer,B,new webgpu.Euler().set(B.x,B.y,B.z+p),{duration:800},E=>c(m.rotation,E));break}});v instanceof Array?await Promise.all(v):await v,this.viewer.invalidate()})(),this.cleanSets.add(()=>{let p=0;objectHandle(h,v=>{v.rotation.copy(s[p++])})})}}}}class FlyToNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("viewpoint",["READ_CTX","LOCAL"]);if(e){const n=parseValue(this.getValue(e));n&&this.viewer.controls.setCameraViewpoint(n,!0)}}}class SpaceNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("space","LOCAL"),n=this.findProp("out","WRITE_CTX");if(e&&n){const a=parseValue(e.value),l=parseValue(n.value);this.writeContext(l,getObjectById(this.viewer,a))}}}class SpacesNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("spaces","LOCAL"),n=this.findProp("out","WRITE_CTX");if(e&&n){const a=parseValue(e.value),l=parseValue(n.value),t=a.map(h=>getObjectById(this.viewer,h));this.writeContext(l,t)}}}class POINode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("poi","LOCAL"),a=this.findProp("out","WRITE_CTX");if(n&&a){const l=parseValue(n.value),t=parseValue(a.value);this.writeContext(t,getObjectById(this.viewer,l))}}}class POIsNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("pois","LOCAL"),a=this.findProp("out","WRITE_CTX");if(n&&a){const l=parseValue(n.value),t=parseValue(a.value),h=l.map(u=>getObjectById(this.viewer,u));this.writeContext(t,h)}}}class DataExtractionNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("value","LOCAL"),n=this.findProp("object","LOCAL"),a=this.findProp("out","WRITE_CTX"),l=this.findProp("extraction","LOCAL");if(e&&a&&l&&n){const t=parseValue(l.value),h=parseValue(a.value),u=parseValue(n.value),o=this.getValue(n);let s=parseValue(e.value);if(this.ctx._userDataMap){const r=this.ctx._userDataMap.get(u);r&&(s=r[t])}else if(o&&o.userData.properties){const r=o.userData.properties.find(c=>c.key===t);r&&r.value!==void 0&&(s=r.value)}this.writeContext(h,s)}}}class DataFilterNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("model","LOCAL");if(e){const n=parseValue(e.value),a=new Function("sourceData",n);for(const l in this.ctx){const t=a(this.ctx[l]);(t==null||t===!1)&&delete this.ctx[l]}}}}class PathNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("path","LOCAL"),n=this.findProp("out","WRITE_CTX");if(e&&n){const a=parseValue(e.value),l=parseValue(n.value);this.writeContext(l,getObjectById(this.viewer,a))}}}class PathsNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("paths","LOCAL"),n=this.findProp("out","WRITE_CTX");if(e&&n){const a=parseValue(e.value),l=parseValue(n.value),t=a.map(h=>getObjectById(this.viewer,h));this.writeContext(l,t)}}}class UserDataNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("object",["READ_CTX","LOCAL"]),n=this.findProp("data","LOCAL"),a=this.findProp("source","WRITE_CTX");if(e&&n&&a){let l=parseValue(e.value);const t=parseValue(n.value),h=parseValue(a.value);if(h&&(l=h),l&&t){this.ctx._userDataMap||(this.ctx._userDataMap=new Map);const u=this.ctx._userDataMap.get(l);u?Object.assign(u,t):this.ctx._userDataMap.set(l,t)}}}}class ClipAnimationNode extends Node{constructor(e,n){super(e,n)}async exec(e){let n=await e.getTarget?.(this);if(!n){const l=this.findProp("model",["READ_CTX","LOCAL"]);l&&(n=this.getValue(l))}const a=this.findProp("animation",["READ_CTX","LOCAL"]);if(n&&a){let l;if(a.type==="READ_CTX"){const u=this.parser.getVariableNameById(parseValue(a.value));l=this.readContext(u)}else l=parseValue(a.value);const t=n.playAnimation(l);if(!t)return;const h=({delta:u})=>{n.updateAnimation(u),this.viewer.invalidate(),t.isRunning()||this.viewer.removeEventListener("afterControlsUpdate",h)};this.viewer.addEventListener("afterControlsUpdate",h),this.cleanSets.add(()=>{n.stopAnimation(l),this.viewer.removeEventListener("afterControlsUpdate",h)})}}}class UnClipAnimationNode extends Node{constructor(e,n){super(e,n)}async exec(e){let n=await e.getTarget?.(this);if(!n){const l=this.findProp("model",["READ_CTX","LOCAL"]);l&&(n=this.getValue(l))}const a=this.findProp("animation",["READ_CTX","LOCAL"]);if(n&&a){let l;if(a.type==="READ_CTX"){const t=this.parser.getVariableNameById(parseValue(a.value));l=this.readContext(t)}else l=parseValue(a.value);n.stopAnimation(l)}}}const tweenCache$1=new Map;async function playTweenAnimation(f,e,n){const{id:a,keyframes:l}=n,t=new AnimationsParser(f,e);tweenCache$1.has(a)||tweenCache$1.set(a,new Set),tweenCache$1.get(a)?.add(t),await t.play(l)}function stopTweenAnimation(f){tweenCache$1.get(f)?.forEach(e=>e.stop()),tweenCache$1.get(f)?.clear()}class TweenAnimationNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("model",["READ_CTX","LOCAL"]),a=this.findProp("animation","LOCAL"),l=this.findProp("wait","LOCAL");if(n&&a&&l){const t=this.getValue(n),h=parseValue(a.value),u=parseValue(l.value);if(t){const o=await e.getAnimations?.(this,t,h);if(o){const s=o.find(r=>r.id===h);s&&await waitFor(async()=>{const r=t.matrix.clone();await playTweenAnimation(this.viewer,t,s),this.cleanSets.add(()=>{stopTweenAnimation(s.id),t&&r.decompose(t.position,t.quaternion,t.scale)})},u)}}}}}class UnTweenAnimationNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("animation","LOCAL");if(e){const n=parseValue(e.value);stopTweenAnimation(n)}}}const tweenCache=new Map;async function playComponentTweenAnimation(f,e,n){const{id:a,keyframes:l}=n,t=new AnimationsParser(f,e);tweenCache.has(a)||tweenCache.set(a,new Set),tweenCache.get(a)?.add(t),await t.play(l)}function stopComponentTweenAnimation(f){tweenCache.get(f)?.forEach(e=>e.stop()),tweenCache.get(f)?.clear()}class ComponentTweenAnimationNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("mesh",["READ_CTX","LOCAL"]),a=this.findProp("animation","LOCAL"),l=this.findProp("wait","LOCAL");if(n&&a&&l){const t=this.getValue(n),h=parseValue(a.value),u=parseValue(l.value);if(t){const o=await e.getComponentAnimations?.(this,t,h);if(o){const s=o.find(r=>r.id===h);if(s){let r=null;n.valueType==="Mesh"?r=t:n.valueType==="Model"&&(r=getMeshByUserDataUuid(t,s.refId)),r&&await waitFor(async()=>{if(r){const c=r.matrix.clone();await playComponentTweenAnimation(this.viewer,r,s),this.cleanSets.add(()=>{stopComponentTweenAnimation(s.id),r&&c.decompose(r.position,r.quaternion,r.scale)})}},u)}}}}}}class UnComponentTweenAnimationNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("animation","LOCAL");if(e){const n=parseValue(e.value);stopComponentTweenAnimation(n)}}}class FlowParser extends webgpu.EventDispatcher{viewer;flow;nodes;nodesMap;edges;edgesMap;onNodeBefore=null;onNodeAfter=null;constructor(e,n){super(),this.viewer=e,this.flow=n,this.nodes=[],this.nodesMap=new Map,this.edges=[],this.edgesMap=new Map}addNode(e){this.nodes.push(e),this.nodesMap.set(e.id,e)}addEdge(e){this.edges.push(e),this.edgesMap.set(e.id,e)}getNodeById(e){return this.nodesMap.get(e)}getEdgeById(e){return this.edgesMap.get(e)}clear(){this.nodes.length=0,this.nodesMap.clear(),this.edges.length=0,this.edgesMap.clear()}parse(){this.clear();const{nodes:e,edges:n}=this.flow;e.forEach(a=>{const l=parseNodeByType(this,a);this.addNode(l)}),n.forEach(a=>{const l=new Edge(a);this.addEdge(l);const t=this.getNodeById(a.source),h=this.getNodeById(a.target);t&&h&&(t.postNodes.push(h),h.prevNodes.push(t))})}async run(e={},n={preload:!1}){const{preload:a}=n,t=this.nodes.filter(h=>h.prevNodes.length||h.postNodes.length).map(h=>h.run(e,{preload:a}));await Promise.allSettled(t)}async debug(e={},n=1500){const a=this.onNodeAfter;this.onNodeAfter=async l=>{await sleep(n),a?.(l)},await this.run(e)}stop(){this.nodes.forEach(e=>e.reject(new Error("Flow stopped")))}cleanup(){this.nodes.sort((e,n)=>n.execOrder-e.execOrder).forEach(e=>e.cleanup())}getVariableNameById(e){const n=this.nodes.find(a=>a.id===e);if(n){const a=n.props.find(l=>l.name==="out");return a?parseValue(a.value):null}return null}dispose(){this.stop(),this.cleanup()}}class ComponentFlowParser extends FlowParser{flow;constructor(e,n){super(e,n),this.flow=n}}exports.AnimationsLoader=AnimationsLoader;exports.AnimationsParser=AnimationsParser;exports.BuildingGroup=BuildingGroup;exports.ComponentFlowParser=ComponentFlowParser;exports.ElevatorMesh=ElevatorMesh;exports.FacilityInstanceObject=FacilityInstanceObject;exports.FacilityInstancedLayer=FacilityInstancedLayer;exports.FloorMesh=FloorMesh;exports.FloorSemanticInstanceObject=FloorSemanticInstanceObject;exports.FlowParser=FlowParser;exports.Node=Node;exports.PropertiesLoader=PropertiesLoader;exports.SceneEditableBatchLayer=SceneEditableBatchLayer;exports.SceneGroup=SceneGroup;exports.SceneInstanceObject=SceneInstanceObject;exports.SceneInstancedLayer=SceneInstancedLayer;exports.SceneLoader=SceneLoader;exports.SemanticGroup=SemanticGroup;exports.SemanticLoader=SemanticLoader;exports.SemanticParser=SemanticParser;exports.TopologiesLoader=TopologiesLoader;exports.TopologyParser=TopologyParser;exports.UManagerLoader=UManagerLoader;exports.UManagerSceneGroup=UManagerSceneGroup;exports.VentMesh=VentMesh;exports.VerticalShaftMesh=VerticalShaftMesh;exports.VisionsLoader=VisionsLoader;exports.VisionsParser=VisionsParser;exports.createVerticalShaftMesh=createVerticalShaftMesh;
86
+ `},publicImport:function(o,s,r){r=r||{};var c;if(r.type!=="der")if(Buffer.isBuffer(s)&&(s=s.toString("utf8")),e.isString(s)){if(s.substring(0,8)!=="ssh-rsa ")throw Error("Unsupported key format");let B=s.indexOf(" ",8);B===-1?B=s.length:o.sshcomment=s.substring(B+1).replace(/\s+|\n\r|\n|\r$/gm,"");const E=s.substring(8,B).replace(/\s+|\n\r|\n|\r$/gm,"");c=Buffer.from(E,"base64")}else throw Error("Unsupported key format");else if(Buffer.isBuffer(s))c=s;else throw Error("Unsupported key format");const d={buf:c,off:0},p=h(d).toString("ascii");if(p!=="ssh-rsa")throw Error("Invalid key type: "+p);const v=h(d),m=h(d);o.setPublic(m,v)},autoImport:function(o,s){return/^[\S\s]*-----BEGIN OPENSSH PRIVATE KEY-----\s*(?=(([A-Za-z0-9+/=]+\s*)+))\1-----END OPENSSH PRIVATE KEY-----[\S\s]*$/g.test(s)?(f.exports.privateImport(o,s),!0):/^[\S\s]*ssh-rsa \s*(?=(([A-Za-z0-9+/=]+\s*)+))\1[\S\s]*$/g.test(s)?(f.exports.publicImport(o,s),!0):!1}};function h(o){const s=o.buf.readInt32BE(o.off);o.off+=4;const r=o.buf.slice(o.off,o.off+s);return o.off+=s,r}function u(o,s){o.buf.writeInt32BE(s.byteLength,o.off),o.off+=4,o.off+=s.copy(o.buf,o.off)}})(openssh)),openssh.exports}var hasRequiredFormats;function requireFormats(){return hasRequiredFormats||(hasRequiredFormats=1,(function(f){requireUtils()._;function e(n){n=n.split("-");for(var a="private",l={type:"default"},t=1;t<n.length;t++)if(n[t])switch(n[t]){case"public":a=n[t];break;case"private":a=n[t];break;case"pem":l.type=n[t];break;case"der":l.type=n[t];break}return{scheme:n[0],keyType:a,keyOpt:l}}f.exports={pkcs1:requirePkcs1(),pkcs8:requirePkcs8(),components:requireComponents(),openssh:requireOpenssh(),isPrivateExport:function(n){return f.exports[n]&&typeof f.exports[n].privateExport=="function"},isPrivateImport:function(n){return f.exports[n]&&typeof f.exports[n].privateImport=="function"},isPublicExport:function(n){return f.exports[n]&&typeof f.exports[n].publicExport=="function"},isPublicImport:function(n){return f.exports[n]&&typeof f.exports[n].publicImport=="function"},detectAndImport:function(n,a,l){if(l===void 0){for(var t in f.exports)if(typeof f.exports[t].autoImport=="function"&&f.exports[t].autoImport(n,a))return!0}else if(l){var h=e(l);if(f.exports[h.scheme])h.keyType==="private"?f.exports[h.scheme].privateImport(n,a,h.keyOpt):f.exports[h.scheme].publicImport(n,a,h.keyOpt);else throw Error("Unsupported key format")}return!1},detectAndExport:function(n,a){if(a){var l=e(a);if(f.exports[l.scheme])if(l.keyType==="private"){if(!n.isPrivate())throw Error("This is not private key");return f.exports[l.scheme].privateExport(n,l.keyOpt)}else{if(!n.isPublic())throw Error("This is not public key");return f.exports[l.scheme].publicExport(n,l.keyOpt)}else throw Error("Unsupported key format")}}}})(formats)),formats.exports}var NodeRSA$1,hasRequiredNodeRSA;function requireNodeRSA(){if(hasRequiredNodeRSA)return NodeRSA$1;hasRequiredNodeRSA=1;var f=requireRsa();requireCryptoBrowserify(),requireLib().Ber;var e=requireUtils()._,n=requireUtils(),a=requireSchemes(),l=requireFormats();return NodeRSA$1=(function(){var t={node10:["md4","md5","ripemd160","sha1","sha224","sha256","sha384","sha512"],node:["md4","md5","ripemd160","sha1","sha224","sha256","sha384","sha512"],iojs:["md4","md5","ripemd160","sha1","sha224","sha256","sha384","sha512"],browser:["md5","ripemd160","sha1","sha256","sha512"]},h="pkcs1_oaep",u="pkcs1",o="private",s={private:"pkcs1-private-pem","private-der":"pkcs1-private-der",public:"pkcs8-public-pem","public-der":"pkcs8-public-der"};function r(c,d,p){if(!(this instanceof r))return new r(c,d,p);e.isObject(d)&&(p=d,d=void 0),this.$options={signingScheme:u,signingSchemeOptions:{hash:"sha256",saltLength:null},encryptionScheme:h,encryptionSchemeOptions:{hash:"sha1",label:null},environment:n.detectEnvironment(),rsaUtils:this},this.keyPair=new f.Key,this.$cache={},Buffer.isBuffer(c)||e.isString(c)?this.importKey(c,d):e.isObject(c)&&this.generateKeyPair(c.b,c.e),this.setOptions(p)}return r.prototype.setOptions=function(c){if(c=c||{},c.environment&&(this.$options.environment=c.environment),c.signingScheme){if(e.isString(c.signingScheme)){var d=c.signingScheme.toLowerCase().split("-");d.length==1?t.node.indexOf(d[0])>-1?(this.$options.signingSchemeOptions={hash:d[0]},this.$options.signingScheme=u):(this.$options.signingScheme=d[0],this.$options.signingSchemeOptions={hash:null}):(this.$options.signingSchemeOptions={hash:d[1]},this.$options.signingScheme=d[0])}else e.isObject(c.signingScheme)&&(this.$options.signingScheme=c.signingScheme.scheme||u,this.$options.signingSchemeOptions=e.omit(c.signingScheme,"scheme"));if(!a.isSignature(this.$options.signingScheme))throw Error("Unsupported signing scheme");if(this.$options.signingSchemeOptions.hash&&t[this.$options.environment].indexOf(this.$options.signingSchemeOptions.hash)===-1)throw Error("Unsupported hashing algorithm for "+this.$options.environment+" environment")}if(c.encryptionScheme){if(e.isString(c.encryptionScheme)?(this.$options.encryptionScheme=c.encryptionScheme.toLowerCase(),this.$options.encryptionSchemeOptions={}):e.isObject(c.encryptionScheme)&&(this.$options.encryptionScheme=c.encryptionScheme.scheme||h,this.$options.encryptionSchemeOptions=e.omit(c.encryptionScheme,"scheme")),!a.isEncryption(this.$options.encryptionScheme))throw Error("Unsupported encryption scheme");if(this.$options.encryptionSchemeOptions.hash&&t[this.$options.environment].indexOf(this.$options.encryptionSchemeOptions.hash)===-1)throw Error("Unsupported hashing algorithm for "+this.$options.environment+" environment")}this.keyPair.setOptions(this.$options)},r.prototype.generateKeyPair=function(c,d){if(c=c||2048,d=d||65537,c%8!==0)throw Error("Key size must be a multiple of 8.");return this.keyPair.generate(c,d.toString(16)),this.$cache={},this},r.prototype.importKey=function(c,d){if(!c)throw Error("Empty key given");if(d&&(d=s[d]||d),!l.detectAndImport(this.keyPair,c,d)&&d===void 0)throw Error("Key format must be specified");return this.$cache={},this},r.prototype.exportKey=function(c){return c=c||o,c=s[c]||c,this.$cache[c]||(this.$cache[c]=l.detectAndExport(this.keyPair,c)),this.$cache[c]},r.prototype.isPrivate=function(){return this.keyPair.isPrivate()},r.prototype.isPublic=function(c){return this.keyPair.isPublic(c)},r.prototype.isEmpty=function(c){return!(this.keyPair.n||this.keyPair.e||this.keyPair.d)},r.prototype.encrypt=function(c,d,p){return this.$$encryptKey(!1,c,d,p)},r.prototype.decrypt=function(c,d){return this.$$decryptKey(!1,c,d)},r.prototype.encryptPrivate=function(c,d,p){return this.$$encryptKey(!0,c,d,p)},r.prototype.decryptPublic=function(c,d){return this.$$decryptKey(!0,c,d)},r.prototype.$$encryptKey=function(c,d,p,v){try{var m=this.keyPair.encrypt(this.$getDataForEncrypt(d,v),c);return p=="buffer"||!p?m:m.toString(p)}catch(B){throw Error("Error during encryption. Original error: "+B)}},r.prototype.$$decryptKey=function(c,d,p){try{d=e.isString(d)?Buffer.from(d,"base64"):d;var v=this.keyPair.decrypt(d,c);if(v===null)throw Error("Key decrypt method returns null.");return this.$getDecryptedData(v,p)}catch(m){throw Error("Error during decryption (probably incorrect key). Original error: "+m)}},r.prototype.sign=function(c,d,p){if(!this.isPrivate())throw Error("This is not private key");var v=this.keyPair.sign(this.$getDataForEncrypt(c,p));return d&&d!="buffer"&&(v=v.toString(d)),v},r.prototype.verify=function(c,d,p,v){if(!this.isPublic())throw Error("This is not public key");return v=!v||v=="buffer"?null:v,this.keyPair.verify(this.$getDataForEncrypt(c,p),d,v)},r.prototype.getKeySize=function(){return this.keyPair.keySize},r.prototype.getMaxMessageSize=function(){return this.keyPair.maxMessageLength},r.prototype.$getDataForEncrypt=function(c,d){if(e.isString(c)||e.isNumber(c))return Buffer.from(""+c,d||"utf8");if(Buffer.isBuffer(c))return c;if(e.isObject(c))return Buffer.from(JSON.stringify(c));throw Error("Unexpected data type")},r.prototype.$getDecryptedData=function(c,d){return d=d||"buffer",d=="buffer"?c:d=="json"?JSON.parse(c.toString()):c.toString(d)},r})(),NodeRSA$1}var NodeRSAExports=requireNodeRSA();const NodeRSA=getDefaultExportFromCjs$1(NodeRSAExports),debugKey="NJHgNB1HDTrHTJc4ERFCBRVBB5HOBEDCjRLChRDIdn8K7EUJD,Vm4C6vC8BpZ6n6G,hxOjYZ{,wYhnJize2rlm9m,6bUcRVbP6sjNbKU8juOWUpukkcV6Cw,Bk2io7{YWJcPnG{1o3GUTpnO:z{kCYHL14HjO8noH1sp[J78k3Y3IcbOSSk97evccx0MdW2uR0f5qhZFQV8e2JCRxxJEBRBC";function decryptWithDebugKey(f){return decryptWithKey(f,decodeString(debugKey))}function decryptWithKey(f,e){const{content:n,sign:a}=f,l=new NodeRSA(e,"pkcs8-public",{environment:"browser",signingScheme:"pkcs1-md5",encryptionScheme:"pkcs1"});if(!l.verify(n,a,"utf8","base64"))throw new Error("u-space: license verify failed");const h=decryptInternal(n,l);return JSON.parse(h)}function decryptInternal(f,e){const n=f.charCodeAt(0),a=f.substring(1,n),l=f.substring(n),t=parseHeader(a);let h="";for(const u of t){const o=l.substring(u.start,u.end);let s;u.encrypt?s=e.decryptPublic(o,"utf8"):s=decodeString(o),h+=s}return h}function parseHeader(f){const e=decodeToBytes(f),a=new DataView(e.buffer).getInt16(0);if(a===1)return parseHeaderV1(e.buffer);throw new Error(`u-space: content version error, version=${a}`)}function parseHeaderV1(f){const e=new DataView(f);let n=2;const a=e.getInt16(n);n+=2;const l=[];for(let t=0;t<a;t++){const h=e.getInt16(n);n+=2;const u=e.getInt16(n);n+=2;const o=e.getInt32(n);n+=4;const s=e.getInt32(n);n+=4;const r={index:h,encrypt:u>0,start:o,end:s};l.push(r)}return l.sort((t,h)=>t.index<=h.index?-1:1),l}const _base64KeyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function decodeToBytes(f){const e=[];let n,a,l,t,h,u,o,s=0;for(f=f.replace(/[^A-Za-z0-9+/=]/g,"");s<f.length;)t=_base64KeyStr.indexOf(f.charAt(s++)),h=_base64KeyStr.indexOf(f.charAt(s++)),u=_base64KeyStr.indexOf(f.charAt(s++)),o=_base64KeyStr.indexOf(f.charAt(s++)),n=t<<2|h>>4,a=(h&15)<<4|u>>2,l=(u&3)<<6|o,e.push(n),u!==64&&e.push(a),o!==64&&e.push(l);return new Int8Array(e)}function decodeString(f){let e="";for(let n=0;n<f.length;n++){const l=f.charCodeAt(n)-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HJn18+BFK9moby/CyJTBXY1O8CzCRHxNsOkDjxfSzgzZuEa1br8PiaS7tq+V72iUBLtFtxsCUguMCy3GVZ9oYX6xg3rN0o1/MWUdOrPg6SYwne5n/UCKvdJXYBfUyjJBYOcnrDs+kA6zyvdUYh/YtTEsyRX6qHf9yMjqed0tn3q/RTbWakxujCnZgnAffG/ZklPmHd9JZwj/1PYUyYO8zEn0ZxP/e6PtH/27F9XTtcZ/1WPMT9l2A7PtP7KUb/h/U27ZwQo6+J8Lea0PvGLffn7ZIFxriktB5jblNJaK97wAQ==";class Watermarker extends webgpu.Scene{viewer;camera;mesh;overlayPass;#e=!1;#r=null;constructor(e){super(),this.viewer=e,this.camera=new webgpu.OrthographicCamera(-1,1,1,-1,0,1),this.camera.position.z=.5,this.mesh=new webgpu.Mesh(new webgpu.PlaneGeometry(1.8,1.8),new webgpu.MeshBasicNodeMaterial({color:16777215,opacity:.5,transparent:!0})),this.add(this.mesh),this.overlayPass=tsl.pass(this,this.camera)}enable(){this.#e=!0,this.#t().then(e=>{this.#e&&(this.mesh.material.map!==e&&(this.mesh.material.map=e,this.mesh.material.needsUpdate=!0),this.viewer.renderPipeline.addOverlayPass(this.overlayPass))}).catch(e=>{this.#r=null,console.warn("u-space Watermarker: failed to load watermark texture.",e)})}disable(){this.#e=!1,this.viewer.renderPipeline.removeOverlayPass(this.overlayPass)}dispose(){this.disable(),this.overlayPass.dispose(),this.mesh.geometry.dispose(),this.mesh.material.dispose(),this.mesh.material.map?.dispose()}#t(){return this.mesh.material.map?Promise.resolve(this.mesh.material.map):(this.#r??=uSpace.TextureLoaderManager.loadAsyncTexture(logo).then(e=>(e.colorSpace=webgpu.SRGBColorSpace,e)),this.#r)}}const _m4=new webgpu.Matrix4,MAX_CONCURRENT_MODEL_LOADS=1,SEMANTIC_ID_KEYS=["Buildings","Stories","Walls","Columns","Doors","Windows","Spaces","Staircases","Facilities","Elevators","Vents"];function collectSemanticIds(f){const e=new Set;return SEMANTIC_ID_KEYS.forEach(n=>{f[n]?.forEach(a=>{const l=a.ID;typeof l=="string"&&l&&e.add(l)})}),e}function collectScenePathCounts(f,e){const n=new Map,a=l=>{!e.has(l.id)&&l.renderType==="3D"&&l.path&&n.set(l.path,(n.get(l.path)??0)+1),l.children.forEach(a)};return f.forEach(a),n}class SceneGroup extends uSpace.BaseGroup{isSceneGroup=!0;type="SceneGroup";sceneLayer=null;constructor(){super(),this.name="SceneGroup"}setSceneLayer(e){return this.sceneLayer&&this.remove(this.sceneLayer),this.sceneLayer=e,e&&this.add(e),this}getDefaultSceneLayer(){return this.sceneLayer}}class SceneParser{viewer;path;semanticIds;pathCounts;loadModel;editableBatchOptions;#e=new Map;constructor(e,n,a,l,t,h){this.viewer=e,this.path=n,this.semanticIds=a,this.pathCounts=l,this.loadModel=t,this.editableBatchOptions=h}async parseAsync(e,n){const a=new SceneGroup,l=async(t,h)=>{if(this.semanticIds.has(t.id)){const o=this.#r(t);await Promise.all(t.children.map(s=>l(s,o))),o.children.length>0&&h.add(o);return}const u=await this.parseTreeNode(t);if(u){const{id:o,sid:s}=t;this.viewer.objectManager.add(o,u),this.viewer.objectManager.add(s,u),n.add(o),n.add(s),h.add(u)}await Promise.all(t.children.map(o=>l(o,u??h)))};return await Promise.all(e.map(t=>l(t,a))),await this.#n(a),a}#r(e){const n=new uSpace.BaseGroup;return n.name=e.name,n.visible=e.visible,_m4.fromArray(e.matrix).decompose(n.position,n.quaternion,n.scale),n}async parseTreeNode(e){const{name:n,renderType:a,path:l,visible:t,matrix:h,shape:u}=e;let o=null;if(a==="3D"&&l){const s=this.path+l;if(this.editableBatchOptions||(this.pathCounts.get(l)??0)>1){const r=new SceneInstanceObject;this.#t(s).instances.push(r),o=r}else o=await this.loadModel(s)}else if(a==="GROUP"||a==="STUB")o=new uSpace.BaseGroup;else if(a==="POLYGON"&&u?.points){const s=uSpace.ShapeMesh.createFromPoints(u.points);s.material.color.set("blue"),s.material.transparent=!0,s.material.opacity=.5,o=s}else if(a==="CIRCLE"&&u?.radius){const s=new uSpace.CircleMesh({geometryParameters:{radius:u.radius}});s.material.color.set("blue"),s.material.transparent=!0,s.material.opacity=.5,o=s}if(o){o.name=n,o.visible=t,_m4.fromArray(h).decompose(o.position,o.quaternion,o.scale);const r={...e};Reflect.deleteProperty(r,"children"),Object.assign(o.userData,r),o instanceof SceneInstanceObject&&l&&(o.setInstanceIdentity({id:e.id,kind:"SceneInstances",name:n}),o.userData.instanced=!0,o.userData.modelPath=l,o.userData.modelUrl=this.path+l)}return o}#t(e){let n=this.#e.get(e);return n||(n={url:e,instances:[]},this.#e.set(e,n)),n}async#n(e){if(this.#e.size===0)return;if(this.editableBatchOptions){const a=new SceneEditableBatchLayer(this.editableBatchOptions);e.setSceneLayer(a);for(const h of this.#e.values()){const u=await this.loadModel(h.url);a.addTemplate(h.url,u,h.instances)}e.updateMatrixWorld(!0);const l=a.build();e.userData.editableBatch=l.stats;const t=new SceneInstancedLayer;for(const h of l.unsupported){const u=h.instances.filter(c=>c.getInstanceRenderObject()===null);if(u.length===0||!h.reasons.includes("negative-scale")&&u.length>1&&t.addInstances(h.url,h.template,u))continue;const[s,...r]=u;s&&this.#i(s,h.template),await Promise.all(r.map(async c=>{const d=await this.loadModel(h.url);this.#i(c,d)}))}t.children.length>0?(t.name="SceneEditableBatchFallback",e.add(t),a.addEventListener("materialize",({instance:h})=>{t.removeInstance(h)})):t.clearBatches(),a.children.length===0&&(a.dispose(),e.setSceneLayer(null));return}const n=new SceneInstancedLayer;e.setSceneLayer(n);for(const a of this.#e.values()){const l=await this.loadModel(a.url);if(n.addInstances(a.url,l,a.instances))continue;const[h,...u]=a.instances;h&&this.#i(h,l),await Promise.all(u.map(async o=>{const s=await this.loadModel(a.url);this.#i(o,s)}))}n.children.length===0&&e.setSceneLayer(null)}#i(e,n){n.name=e.name,n.visible=!0,n.position.set(0,0,0),n.quaternion.identity(),n.scale.set(1,1,1),Object.assign(n.userData,e.userData,{instanced:!1}),Object.assign(e.userData,{instanced:!1}),e.setInstanceRenderObject(n)}}class SceneLoader extends webgpu.Loader{viewer;key="";cachedIds=new Set;editableBatchOptions=null;_resourceData=null;_treeData=[];#e=0;#r=[];#t;constructor(e){super(),this.viewer=e,this.#t=new Watermarker(e),this.manager=new webgpu.LoadingManager}setKey(e){return this.key=e,this}setEditableBatching(e=!0){return this.editableBatchOptions=e===!1?null:e===!0?{}:e,this}async#n(){if(this.#e<MAX_CONCURRENT_MODEL_LOADS){this.#e++;return}await new Promise(e=>{this.#r.push(e)})}#i(){const e=this.#r.shift();e?e():this.#e--}async loadModel(e){await this.#n();try{const n=new uSpace.Model;this.manager.itemStart(e);try{await n.loadAsync({url:e})}catch(a){throw this.manager.itemError(e),a}finally{this.manager.itemEnd(e)}return n}finally{this.#i()}}async _preareTreeData(){if(!this.path)throw new Error("u-space SceneLoader: path is not set");const e=new BaseFileLoader(this),n=await e.loadAsync(META_DATA_FILE_PATH);if(n.version<1.5)throw new Error("u-space SceneLoader: Only support version 1.5 and above");if(!this.key&&n.authority==="OFFICIAL")throw new Error("u-space SceneLoader: options.key is required when authority is OFFICIAL");this.key&&n.authority==="TRIAL"&&console.warn("u-space SceneLoader: options.key is not used when authority is TRIAL");const a=await e.loadAsync(n.resource),l=this._resourceData!==a;if(this._resourceData=a,l)if(n.encryptWith==="DEBUG")try{this._treeData=decryptWithDebugKey(a),this.#t.enable()}catch{throw new Error("u-space SceneLoader: decrypt with debug key failed")}else if(n.encryptWith==="SCENE"||n.encryptWith==="COMPANY")try{this._treeData=decryptWithKey(a,this.key)}catch{throw new Error("u-space SceneLoader: decrypt with authorized key failed")}else n.encryptWith||(this._treeData=a)}async _prepareSemanticIds(){try{const e=new webgpu.FileLoader(new webgpu.LoadingManager);e.setPath(this.path),e.setResponseType("json"),e.setRequestHeader(this.requestHeader),e.setWithCredentials(this.withCredentials);const n=await e.loadAsync(SEMANTIC_DATA_FILE_PATH);return collectSemanticIds(n)}catch{return new Set}}async loadAsync(){if(!this.path)throw new Error("u-space SceneLoader: path is not set");this.manager.itemStart(this.path);try{await this._preareTreeData();const e=await this._prepareSemanticIds(),n=collectScenePathCounts(this._treeData,e);return await new SceneParser(this.viewer,this.path,e,n,this.loadModel.bind(this),this.editableBatchOptions).parseAsync(this._treeData,this.cachedIds)}catch(e){throw this.manager.itemError(this.path),e}finally{this.manager.itemEnd(this.path)}}clearCache(){this.cachedIds.forEach(e=>{this.viewer.objectManager.removeById(e)}),this.cachedIds.clear()}dispose(){this.clearCache(),this.#t.dispose()}}class VerticalShaftMeshError extends Error{constructor(e){super(e),this.name="VerticalShaftMeshError"}}const VERTICAL_SHAFT_RENDER_OFFSET=-.006;function getValidPolygonShape$1(f,e,n){if(!Array.isArray(f)||f.length<4||f.length%2!==0)throw new VerticalShaftMeshError(`u-space SemanticLoader: invalid ${e} polygon shape for id ${n}.`);return f}function createShape(f){const e=[];for(let n=0;n<f.length;n+=2)e.push(new webgpu.Vector2(f[n],-f[n+1]));return new webgpu.Shape(e)}function getVerticalShaftRange(f){const e=Number(f.Elevation??0),n=Number(f.TotalHeight);if(!Number.isFinite(e)||!Number.isFinite(n)||n<=0)throw new VerticalShaftMeshError(`u-space SemanticLoader: invalid vertical shaft height range for id ${f.ID}.`);const a=e+n;return{bottom:e,top:a,height:n}}function createVerticalShaftMesh(f){try{return f()}catch(e){if(e instanceof VerticalShaftMeshError)return console.warn(e.message),null;throw e}}class VerticalShaftMesh extends uSpace.ExtrudeMesh{isVerticalShaftMesh=!0;type="VerticalShaftMesh";shaft;semanticId;semanticKind;semanticName;bottom;top;height;constructor({shaft:e,kind:n,material:a}){const l=getValidPolygonShape$1(e.Polygon?.shape,n,e.ID),t=getVerticalShaftRange(e);super({geometryParameters:{shape:createShape(l),options:{depth:t.height,bevelEnabled:!1}},materialParameters:{color:a.color,opacity:a.opacity,transparent:a.opacity<1,depthWrite:!0}}),this.shaft=e,this.semanticId=e.ID,this.semanticKind=n,this.semanticName=e.Name||"",this.bottom=t.bottom,this.top=t.top,this.height=t.height,this.name=this.semanticName,this.position.y=this.bottom,this.material.positionNode=tsl.positionLocal.add(tsl.normalLocal.mul(VERTICAL_SHAFT_RENDER_OFFSET)),this.userData.id=this.semanticId,this.userData.semanticKind=n,this.userData.beginFloorIndex=e.BeginFloorIndex,this.userData.endFloorIndex=e.EndFloorIndex,this.userData.bottom=this.bottom,this.userData.top=this.top}}const ELEVATOR_MATERIAL={color:7305093,opacity:.7};class ElevatorMesh extends VerticalShaftMesh{isElevatorMesh=!0;type="ElevatorMesh";constructor(e){super({shaft:e,kind:"Elevators",material:ELEVATOR_MATERIAL})}static create(e){return createVerticalShaftMesh(()=>new ElevatorMesh(e))}}const OPAQUE_MATERIAL_INDEX=0,TRANSPARENT_MATERIAL_INDEX=1,OPAQUE_OPACITY_THRESHOLD=.999;function markInstanceRenderDirty(f){f.markInstanceRenderDirty()}const PLANISH_SCALE_Y=.01,PLANISH_KIND_OFFSET_STEP=.002,PLANISH_INSTANCE_OFFSET_JITTER=8e-4,PLANISH_FACILITY_OFFSET=.014,SEMANTIC_RENDER_OFFSETS={Walls:0,Columns:.006,Spaces:-.006,Doors:.01,Windows:.01,Staircases:.012},SEMANTIC_DRAW_ORDER={Spaces:0,Staircases:1,Walls:2,Columns:3,Doors:4,Windows:5},SPACE_RENDER_OFFSET_JITTER_MIN=.001,SPACE_RENDER_OFFSET_JITTER=.006,_box=new webgpu.Box3,_pivot=new webgpu.Vector3,_raycastHits=[],_dummyPosition=new webgpu.Vector3,_dummyQuaternion=new webgpu.Quaternion,_dummyScale=new webgpu.Vector3,_boundsMatrix=new webgpu.Matrix4,_boundsSphere=new webgpu.Sphere,_facilityBounds=new webgpu.Box3,_floorMatrixInverse=new webgpu.Matrix4;function getStateTextureSize(f,e=1){return Math.max(1,Math.ceil(Math.sqrt(Math.max(1,f*e))))}function getMatrixTextureSize(f){const e=Math.sqrt(Math.max(1,f)*4);return Math.max(4,Math.ceil(e/4)*4)}function createStateTexture(f){const e=new webgpu.DataTexture(new Float32Array(f*f*4),f,f,webgpu.RGBAFormat,webgpu.FloatType);return e.magFilter=webgpu.NearestFilter,e.minFilter=webgpu.NearestFilter,e.generateMipmaps=!1,e.needsUpdate=!0,e}function getStableRenderOffsetUnit(f){let e=2166136261;for(let n=0;n<f.length;n++)e^=f.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0)/4294967295}function getSemanticRenderOffset(f){const e=SEMANTIC_RENDER_OFFSETS[f.kind];return f.kind!=="Spaces"?e:e-SPACE_RENDER_OFFSET_JITTER_MIN-getStableRenderOffsetUnit(`${f.id}:${f.index}`)*SPACE_RENDER_OFFSET_JITTER}function getPlanishInstanceOffset(f){return getStableRenderOffsetUnit(f)*PLANISH_INSTANCE_OFFSET_JITTER}function getSemanticPlanishOffset(f){return SEMANTIC_DRAW_ORDER[f.kind]*PLANISH_KIND_OFFSET_STEP+getPlanishInstanceOffset(`${f.id}:${f.index}:planish`)}function getFacilityPlanishOffset(f,e){const n=f.instanceId||`${f.uuid}:${e}`;return PLANISH_FACILITY_OFFSET+getPlanishInstanceOffset(`${n}:${e}:planish`)}function copyAttributeComponents(f,e,n,a){for(let l=0;l<n;l++)a.push(f?.getComponent(e,l)??0)}function createSemanticMaterial(f,e,n,a,l){const t=tsl.attribute("semanticIndex","float").toInt(),h=B=>tsl.int(tsl.textureSize(tsl.textureLoad(B),tsl.int(0)).x).toConst(),u=B=>{const E=h(B),x=t.mod(E).toConst(),P=t.div(E).toConst();return tsl.textureLoad(B,tsl.ivec2(x,P))},o=()=>{const B=h(n),E=t.mul(4).toConst(),x=E.mod(B).toConst(),P=E.div(B).toConst();return tsl.mat4(tsl.textureLoad(n,tsl.ivec2(x,P)),tsl.textureLoad(n,tsl.ivec2(x.add(1),P)),tsl.textureLoad(n,tsl.ivec2(x.add(2),P)),tsl.textureLoad(n,tsl.ivec2(x.add(3),P)))},s=u(f),r=u(e).x,c=u(a).x,d=o(),p=d.mul(tsl.vec4(tsl.positionLocal,1)).xyz,v=tsl.transformNormal(tsl.normalLocal,d).normalize(),m=new webgpu.MeshStandardNodeMaterial({transparent:l,depthWrite:!0});return m.colorNode=tsl.vec4(s.rgb,1),m.opacityNode=s.a.mul(r),m.maskNode=r.greaterThan(.5).and(s.a.greaterThan(.001)),m.positionNode=p.add(v.mul(c)),m}function createSemanticMaterials(f,e,n,a){return[createSemanticMaterial(f,e,n,a,!1),createSemanticMaterial(f,e,n,a,!0)]}function copySemanticColor(f,e){if(f instanceof webgpu.Color){e.x=f.r,e.y=f.g,e.z=f.b;return}e.x=f.x,e.y=f.y,e.z=f.z,f instanceof webgpu.Vector4&&(e.w=f.w)}function buildMergedSemanticGeometry(f){const e=[...f].sort((s,r)=>SEMANTIC_DRAW_ORDER[s.kind]-SEMANTIC_DRAW_ORDER[r.kind]),n=[],a=[],l=[],t=[],h=[],u=[];e.forEach((s,r)=>{const c=s.geometry,d=c.getAttribute("position"),p=c.getAttribute("normal"),v=c.getAttribute("uv"),m=c.getIndex();if(!d)return;c.computeBoundingBox(),_box.copy(c.boundingBox??_box.makeEmpty()),_box.getCenter(_pivot),_pivot.y=_box.min.y;const B=n.length/3,E=[],x=[],P=[],D=[];for(let te=0;te<d.count;te++){const de=d.getX(te)-_pivot.x,X=d.getY(te)-_pivot.y,b=d.getZ(te)-_pivot.z;n.push(de,X,b),E.push(de,X,b),t.push(r),copyAttributeComponents(p,te,3,a),copyAttributeComponents(p,te,3,x),copyAttributeComponents(v,te,2,l),copyAttributeComponents(v,te,2,P)}const $=h.length;if(m)for(let te=0;te<m.count;te++){const de=m.getX(te);h.push(B+de),D.push(de)}else for(let te=0;te<d.count;te++)h.push(B+te),D.push(te);const H=h.length-$,Y=new webgpu.BufferGeometry;Y.setAttribute("position",new webgpu.Float32BufferAttribute(E,3)),p&&Y.setAttribute("normal",new webgpu.Float32BufferAttribute(x,3)),v&&Y.setAttribute("uv",new webgpu.Float32BufferAttribute(P,2)),Y.setIndex(D),Y.computeBoundingBox(),Y.computeBoundingSphere();const ne=new webgpu.Matrix4().makeTranslation(_pivot.x,_pivot.y,_pivot.z);u.push({id:s.id,kind:s.kind,name:s.name,index:r,indexStart:$,indexCount:H,baseMatrix:ne,matrix:new webgpu.Matrix4,finalMatrix:ne.clone(),geometry:Y,initialColor:s.color.clone(),color:s.color.clone(),visible:!0})});const o=new webgpu.BufferGeometry;return o.setAttribute("position",new webgpu.Float32BufferAttribute(n,3)),a.length>0&&o.setAttribute("normal",new webgpu.Float32BufferAttribute(a,3)),l.length>0&&o.setAttribute("uv",new webgpu.Float32BufferAttribute(l,2)),o.setAttribute("semanticIndex",new webgpu.Float32BufferAttribute(t,1)),o.setIndex(h),o.computeBoundingBox(),o.computeBoundingSphere(),{geometry:o,states:u}}class FloorSemanticInstanceObject extends uSpace.InstanceObject{isFloorSemanticInstanceObject=!0;type="FloorSemanticInstanceObject";floorMesh;semanticIndex;#e=null;#r;#t=!1;constructor(e,n){super({boundsName:"FloorSemanticBounds"}),this.floorMesh=e,this.semanticIndex=n,this.#r=e.getOpacityAt(n)}setInstanceVisible(e){return this.floorMesh.setVisibleAt(this.semanticIndex,e),super.setInstanceVisible(e)}setInstanceColor(e){return this.#e=new webgpu.Color(e),super.setInstanceColor(e),this.#t||this.floorMesh.setColorAt(this.semanticIndex,this.#e),this}resetInstanceColor(){return this.#e=null,super.resetInstanceColor(),this.#t||this.floorMesh.resetColorAt(this.semanticIndex),this}setInstanceOpacity(e){return this.#r=Math.max(0,Math.min(1,e)),super.setInstanceOpacity(this.#r),this.#t||this.floorMesh.setOpacityAt(this.semanticIndex,this.#r),this}getInstanceOpacity(){return this.floorMesh.getOpacityAt(this.semanticIndex)}setInstanceHighlight(e,n,a=!1){const l=Math.max(0,Math.min(1,n));return this.#t=!0,super.setInstanceHighlight(e,l,a),this.floorMesh.setColorAt(this.semanticIndex,new webgpu.Color(e)),this.floorMesh.setOpacityAt(this.semanticIndex,l),this}clearInstanceHighlight(){return this.#t?(this.#t=!1,super.clearInstanceHighlight(),this.#n(),this):this}getInstanceBoundingBox(e=new webgpu.Box3,n=!1){return this.floorMesh.getBoundingBoxAt(this.semanticIndex,e,n)??e.makeEmpty()}#n(){this.#e?this.floorMesh.setColorAt(this.semanticIndex,this.#e):this.floorMesh.resetColorAt(this.semanticIndex),this.floorMesh.setOpacityAt(this.semanticIndex,this.#r)}}class FloorMesh extends uSpace.BaseMesh{isFloorMergedSemanticMesh=!0;type="FloorMesh";semanticId="";semanticKind="Floors";semanticName="";pivot=new webgpu.Vector3;boundingBox=null;boundingSphere=null;wallsInstances=new Map;columnsInstances=new Map;spacesInstances=new Map;doorsInstances=new Map;windowsInstances=new Map;staircasesInstances=new Map;semanticInstances=new Map;semanticEntities=new Map;facilityObjectsById=new Map;facilityObjects=[];facilityIndexVersion=0;#e;#r;#t=[];#n;#i;#o;#s;#u;#c=new Map;#f=new Map;#h=new WeakMap;constructor(e){const{geometry:n,states:a}=buildMergedSemanticGeometry(e),l=getStateTextureSize(a.length),t=getMatrixTextureSize(a.length),h=createStateTexture(l),u=createStateTexture(l),o=createStateTexture(t),s=createStateTexture(l),r=createSemanticMaterials(h,u,o,s);super(n,r),this.#r=a,this.#e={Walls:this.wallsInstances,Columns:this.columnsInstances,Spaces:this.spacesInstances,Doors:this.doorsInstances,Windows:this.windowsInstances,Staircases:this.staircasesInstances},this.#n=h,this.#i=u,this.#o=o,this.#s=s,this.#u=new webgpu.Mesh,this.#u.matrixAutoUpdate=!1,this.frustumCulled=!1,this.#r.forEach(c=>{const d=new FloorSemanticInstanceObject(this,c.index);d.name=c.name||c.id,d.visible=c.visible,d.setInstanceIdentity({id:c.id,kind:c.kind,name:c.name}),d.userData.id=c.id,d.userData.semanticIndex=c.index,this.#t[c.index]=d,this.add(d),this.semanticInstances.set(c.id,c.index),this.#e[c.kind].set(c.id,c.index),this.semanticEntities.set(c.id,{type:"geometry",kind:c.kind,id:c.id,name:c.name,index:c.index,object:d}),this.#d(c.index),this.#g(c.index),this.#p(c.index),this.#I(c.index)}),this.#l(),this.userData.semanticEntries=this.#r.map(({id:c,kind:d,name:p,index:v})=>({id:c,kind:d,name:p,index:v}))}setSemanticIdentity(e){return e.id!==void 0&&(this.semanticId=e.id??""),e.kind!==void 0&&(this.semanticKind=e.kind??""),e.name!==void 0&&(this.semanticName=e.name??""),this}planish(e){return e!=="Facilities"&&this.#b(e,n=>this.#B(n)),(e===void 0||e==="Facilities")&&this.#q(),this}unplanish(e){return e!=="Facilities"&&this.#b(e,n=>this.#A(n)),(e===void 0||e==="Facilities")&&this.#R(),this}get semanticCount(){return this.#r.length}get instanceCount(){return this.semanticCount}getSemanticIndexById(e){return this.semanticInstances.get(e)}getSemanticById(e){return this.semanticEntities.get(e)}getSemantics(){return[...new Set(this.semanticEntities.values())]}getSemanticsByKind(e){return this.getSemantics().filter(n=>n.kind===e)}getSemanticIdAt(e){return this.#a(e).id}getSemanticKindAt(e){return this.#a(e).kind}getSemanticNameAt(e){return this.#a(e).name}getSemanticObjectAt(e){return this.#t[e]}showAllFacilities(){return this.facilityObjects.forEach(e=>{e.setInstanceVisible(!0)}),this}hideAllFacilities(){return this.facilityObjects.forEach(e=>{e.setInstanceVisible(!1)}),this}addFacility(e,n){this.facilityObjects.includes(e)||(this.add(e),this.facilityObjects.push(e)),this.#v(e);const a=new Set;(Array.isArray(n)?n:[n]).forEach(u=>{u&&a.add(u)}),[e.instanceId].forEach(u=>{typeof u=="string"&&u&&a.add(u)});const h={type:"object",kind:"Facilities",id:this.#S(e,a),name:this.#x(e),index:this.facilityObjects.indexOf(e),object:e,aliases:[...a]};return this.#c.set(e,h),a.forEach(u=>{this.facilityObjectsById.set(u,e),this.semanticEntities.set(u,h)}),this.userData.facilities=this.facilityObjects.map(u=>u.instanceId||u.uuid),this.facilityIndexVersion++,this}getFacilityById(e){return this.facilityObjectsById.get(e)}getFacilityAt(e){return this.facilityObjects[e]}getFacilities(){return[...this.facilityObjects]}removeFacility(e){const n=this.#w(e);if(!n)return this;const a=this.facilityObjects.indexOf(n);return a!==-1&&this.facilityObjects.splice(a,1),this.#v(n),a!==-1&&this.#_(a),n.visible=!1,n.removeFromParent(),this.#h.delete(n),this.userData.facilities=this.facilityObjects.map(l=>l.instanceId||l.uuid),this.facilityIndexVersion++,this}#w(e){return typeof e=="string"?this.getFacilityById(e):e}setColorAt(e,n){const a=this.#a(e);return copySemanticColor(n,a.color),this.#d(e),this.#l(),this}resetColorAt(e){const n=this.#a(e),a=n.color.w;return n.color.copy(n.initialColor),n.color.w=a,this.#d(e),this.#l(),this}getColorAt(e,n=new webgpu.Vector4){const a=this.#a(e).color;return n.copy(a),n}setOpacityAt(e,n){const a=this.#a(e);return a.color.w=Math.max(0,Math.min(1,n)),this.#d(e),this.#l(),this}getOpacityAt(e){return this.#a(e).color.w}setVisibleAt(e,n){const a=this.#a(e);return a.visible=n,this.#g(e),this}getVisibleAt(e){return this.#a(e).visible}setMatrixAt(e,n){const a=this.#a(e);return a.matrix.copy(n),a.finalMatrix.multiplyMatrices(a.baseMatrix,a.matrix),this.#y(e),this.#p(e),this}setScaleAt(e,n,a,l){return this.#m(e,t=>{n instanceof webgpu.Vector3?t.copy(n):t.set(n,a??n,l??n)})}setScaleYAt(e,n){return this.#m(e,a=>{a.y=n})}getMatrixAt(e,n=new webgpu.Matrix4){return n.copy(this.#a(e).matrix),n}getFinalMatrixAt(e,n=new webgpu.Matrix4){return n.copy(this.#a(e).finalMatrix),n}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new webgpu.Box3),this.boundingBox.makeEmpty();for(const e of this.#r)this.getBoundingBoxAt(e.index,_box,!1)&&this.boundingBox.union(_box)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new webgpu.Sphere),this.boundingSphere.makeEmpty();for(const e of this.#r)this.getBoundingSphereAt(e.index,_boundsSphere,!1)&&this.boundingSphere.union(_boundsSphere)}getBoundingBoxAt(e,n=new webgpu.Box3,a=!0){const l=this.#a(e);return l.geometry.boundingBox||l.geometry.computeBoundingBox(),l.geometry.boundingBox?(n.copy(l.geometry.boundingBox).applyMatrix4(l.finalMatrix),a&&(this.updateWorldMatrix(!0,!1),n.applyMatrix4(this.matrixWorld)),n):null}getBoundingSphereAt(e,n=new webgpu.Sphere,a=!0){const l=this.#a(e);return l.geometry.boundingSphere||l.geometry.computeBoundingSphere(),l.geometry.boundingSphere?(n.copy(l.geometry.boundingSphere),a?(this.updateWorldMatrix(!0,!1),_boundsMatrix.multiplyMatrices(this.matrixWorld,l.finalMatrix),n.applyMatrix4(_boundsMatrix)):n.applyMatrix4(l.finalMatrix),n):null}raycast(e,n){if(this.visible===!1&&this.ignoreInvisibleWhenRaycast===!0)return!1;this.updateWorldMatrix(!0,!1),this.#u.material=Array.isArray(this.material)?this.material[OPAQUE_MATERIAL_INDEX]:this.material;for(const a of this.#r)if(!(!a.visible||a.color.w<=.001)){this.#u.geometry=a.geometry,this.#u.matrixWorld.multiplyMatrices(this.matrixWorld,a.finalMatrix),_raycastHits.length=0,this.#u.raycast(e,_raycastHits);for(const l of _raycastHits){const t=l,h=this.#t[a.index];t.object=h??this,t.semanticObject=h,t.semanticId=a.id,t.semanticKind=a.kind,t.semanticName=a.name,t.semanticIndex=a.index,n.push(t)}}}dispose(){this.geometry.dispose(),Array.isArray(this.material)?this.material.forEach(e=>e.dispose()):this.material.dispose(),this.#n.dispose(),this.#i.dispose(),this.#o.dispose(),this.#s.dispose(),this.#r.forEach(e=>e.geometry.dispose())}#v(e){for(const[n,a]of this.facilityObjectsById)a===e&&this.facilityObjectsById.delete(n);for(const[n,a]of this.semanticEntities)a.type==="object"&&a.object===e&&this.semanticEntities.delete(n);this.#c.delete(e)}#_(e=0){for(let n=e;n<this.facilityObjects.length;n++){const a=this.#c.get(this.facilityObjects[n]);a&&(a.index=n)}}#S(e,n){for(const l of[e.instanceId])if(typeof l=="string"&&l)return n.add(l),l;const[a]=n;return a||(n.add(e.uuid),e.uuid)}#x(e){const{facility:n}=e.userData;return e.instanceName?e.instanceName:n&&typeof n.Name=="string"&&n.Name?n.Name:e.name||void 0}#a(e){const n=this.#r[e];if(!n)throw new Error(`u-space FloorMesh: invalid semantic index ${e}.`);return n}#y(e){this.boundingBox=null,this.boundingSphere=null,(e===void 0?this.#t:[this.#t[e]]).forEach(a=>{a&&(a.boundingBox=null,a.boundingSphere=null)})}#E(e){return e.color.w>=OPAQUE_OPACITY_THRESHOLD?OPAQUE_MATERIAL_INDEX:TRANSPARENT_MATERIAL_INDEX}#l(){this.geometry.clearGroups();let e=-1,n=0,a=-1;const l=()=>{n<=0||this.geometry.addGroup(e,n,a)};this.#r.forEach(t=>{if(t.indexCount<=0)return;const h=this.#E(t),u=e+n===t.indexStart;if(e===-1){e=t.indexStart,n=t.indexCount,a=h;return}if(h===a&&u){n+=t.indexCount;return}l(),e=t.indexStart,n=t.indexCount,a=h}),l()}#b(e,n){if(e===void 0){this.#r.forEach(a=>n(a.index));return}for(const a of this.#e[e].values())n(a)}#B(e){const n=this.#a(e),a=this.#f.get(e)??n.matrix;this.#f.has(e)||this.#f.set(e,n.matrix.clone()),a.decompose(_dummyPosition,_dummyQuaternion,_dummyScale),_dummyScale.y*=PLANISH_SCALE_Y,n.matrix.compose(_dummyPosition,_dummyQuaternion,_dummyScale),n.finalMatrix.multiplyMatrices(n.baseMatrix,n.matrix),n.geometry.boundingBox||n.geometry.computeBoundingBox(),n.geometry.boundingBox&&(_box.copy(n.geometry.boundingBox).applyMatrix4(n.finalMatrix),_dummyPosition.y+=this.pivot.y+getSemanticPlanishOffset(n)-_box.min.y,n.matrix.compose(_dummyPosition,_dummyQuaternion,_dummyScale),n.finalMatrix.multiplyMatrices(n.baseMatrix,n.matrix)),this.#y(e),this.#p(e)}#A(e){const n=this.#f.get(e);n&&(this.setMatrixAt(e,n),this.#f.delete(e))}#q(){const e=this.pivot.y;this.facilityObjects.forEach((n,a)=>{this.#h.has(n)||this.#h.set(n,{positionY:n.position.y,scaleY:n.scale.y});const l=this.#h.get(n);n.scale.y=(l?.scaleY??n.scale.y)*PLANISH_SCALE_Y,n.updateMatrix();const t=e+getFacilityPlanishOffset(n,a);this.#M(n,_facilityBounds)?n.position.y+=t-_facilityBounds.min.y:n.position.y=t,n.updateMatrix(),markInstanceRenderDirty(n)})}#R(){this.facilityObjects.forEach(e=>{const n=this.#h.get(e);n&&(e.position.y=n.positionY,e.scale.y=n.scaleY,e.updateMatrix(),markInstanceRenderDirty(e),this.#h.delete(e))})}#M(e,n){return n.makeEmpty(),this.updateWorldMatrix(!0,!1),e.updateWorldMatrix(!0,!0),_floorMatrixInverse.copy(this.matrixWorld).invert(),e.traverse(a=>{const l=a.geometry;l&&(l.boundingBox||l.computeBoundingBox(),l.boundingBox&&(_box.copy(l.boundingBox).applyMatrix4(a.matrixWorld).applyMatrix4(_floorMatrixInverse),n.union(_box)))}),n.isEmpty()?null:n}#m(e,n){const a=this.#a(e);return a.matrix.decompose(_dummyPosition,_dummyQuaternion,_dummyScale),n(_dummyScale),a.matrix.compose(_dummyPosition,_dummyQuaternion,_dummyScale),a.finalMatrix.multiplyMatrices(a.baseMatrix,a.matrix),this.#y(e),this.#p(e),this}#d(e){this.#a(e).color.toArray(this.#n.image.data,e*4),this.#n.needsUpdate=!0}#g(e){const n=this.#a(e),a=this.#i.image.data;a[e*4]=n.visible?1:0,a[e*4+1]=0,a[e*4+2]=0,a[e*4+3]=1,this.#i.needsUpdate=!0}#p(e){this.#a(e).finalMatrix.toArray(this.#o.image.data,e*16),this.#o.needsUpdate=!0}#I(e){const n=this.#a(e),a=this.#s.image.data;a[e*4]=getSemanticRenderOffset(n),a[e*4+1]=0,a[e*4+2]=0,a[e*4+3]=1,this.#s.needsUpdate=!0}}const VENT_MATERIAL={color:6924429,opacity:.55};class VentMesh extends VerticalShaftMesh{isVentMesh=!0;type="VentMesh";constructor(e){super({shaft:e,kind:"Vents",material:VENT_MATERIAL})}static create(e){return createVerticalShaftMesh(()=>new VentMesh(e))}}function getSemanticObjectIds(f){const e=f.semanticId,n=f.instanceId;return[e,n].filter(a=>typeof a=="string"&&a.length>0)}function indexObject(f,e){getSemanticObjectIds(e).forEach(n=>{f.has(n)||f.set(n,e)})}function rebuildObjectIndex(f,e){f.clear(),e.forEach(n=>indexObject(f,n))}function getFloorReferences(f){return Array.isArray(f)?f:[f]}function resolveFloor(f,e){const n=typeof e=="number"?f.getFloorAt(e):e;if(!n||!f.hasFloor(n))throw new Error("u-space BuildingGroup: the floor is not in this building group.");return n}class BuildingGroup extends uSpace.BaseGroup{isBuildingGroup=!0;type="BuildingGroup";semanticId="";semanticKind="Buildings";semanticName="";floorMeshes=[];elevatorMeshes=[];ventMeshes=[];#e=new Set;#r=new Map;#t=new Map;#n=new Map;#i=new Map;#o=new Map;#s=new Map;#u=0;#c=!0;constructor(){super()}setSemanticIdentity(e){return e.id!==void 0&&(this.semanticId=e.id??""),e.kind!==void 0&&(this.semanticKind=e.kind??""),e.name!==void 0&&(this.semanticName=e.name??""),this}addFloor(e){return this.#e.has(e)||(this.add(e),this.floorMeshes.push(e),this.#e.add(e),indexObject(this.#r,e),this.#c=!0),this}hasFloor(e){return this.#e.has(e)}getFloorAt(e){return this.floorMeshes[e]}getFloorById(e){return this.#r.get(e)}removeFloor(e){const n=this.floorMeshes.indexOf(e);return n!==-1&&this.floorMeshes.splice(n,1),this.#e.delete(e),rebuildObjectIndex(this.#r,this.floorMeshes),this.#s.delete(e),this.#c=!0,this.remove(e),this}addElevator(e){return this.elevatorMeshes.includes(e)||(this.add(e),this.elevatorMeshes.push(e),indexObject(this.#t,e)),this}getElevatorAt(e){return this.elevatorMeshes[e]}getElevatorById(e){return this.#t.get(e)}removeElevator(e){const n=this.elevatorMeshes.indexOf(e);return n!==-1&&this.elevatorMeshes.splice(n,1),rebuildObjectIndex(this.#t,this.elevatorMeshes),this.remove(e),this}addVent(e){return this.ventMeshes.includes(e)||(this.add(e),this.ventMeshes.push(e),indexObject(this.#n,e)),this}getVentAt(e){return this.ventMeshes[e]}getVentById(e){return this.#n.get(e)}removeVent(e){const n=this.ventMeshes.indexOf(e);return n!==-1&&this.ventMeshes.splice(n,1),rebuildObjectIndex(this.#n,this.ventMeshes),this.remove(e),this}isolateFloor(e){return this.isolateFloors(getFloorReferences(e))}isolateFloors(e){if(e.length===0)throw new Error("u-space BuildingGroup: at least one floor is required to isolate floors.");const n=new Set(e.map(a=>resolveFloor(this,a)));return this.floorMeshes.forEach(a=>{a.visible=n.has(a)}),this}showAllFloors(){return this.floorMeshes.forEach(e=>{e.visible=!0}),this}showAllFacilities(){return this.floorMeshes.forEach(e=>e.showAllFacilities()),this}hideAllFacilities(){return this.floorMeshes.forEach(e=>e.hideAllFacilities()),this}getFacilityById(e){return this.#f(),this.#i.get(e)?.getFacilityById(e)}syncFacilityIndexes(){return this.#f(),this}get facilityIndexVersion(){return this.#f(),this.#u}getFacilityIndexIds(){return this.#f(),this.#i.keys()}getFacilityIndexObjects(){return this.#f(),this.#o.keys()}planishFloors(e){return this.floorMeshes.forEach(n=>n.planish(e)),this}unplanishFloors(e){return this.floorMeshes.forEach(n=>n.unplanish(e)),this}#f(){let e=this.#c||this.#s.size!==this.floorMeshes.length;for(const n of this.floorMeshes)if(this.#s.get(n)!==n.facilityIndexVersion){e=!0;break}e&&(this.#i.clear(),this.#o.clear(),this.#s.clear(),this.floorMeshes.forEach(n=>{this.#s.set(n,n.facilityIndexVersion),n.facilityObjectsById.forEach((a,l)=>{this.#i.has(l)||this.#i.set(l,n)}),n.getFacilities().forEach(a=>{this.#o.has(a)||this.#o.set(a,n)})}),this.#u++,this.#c=!1)}}class SemanticGroup extends uSpace.BaseGroup{isSemanticGroup=!0;type="SemanticGroup";buildings=[];facilityLayer=null;#e=new Set;#r=new Map;#t=new Map;#n=new Map;#i=new Map;#o=!0;constructor(){super()}addBuilding(e){return this.#e.has(e)||(this.add(e),this.buildings.push(e),this.#e.add(e),this.#s(e),this.#o=!0),this}getBuildingAt(e){return this.buildings[e]}getBuildingById(e){return this.#r.get(e)}getBuildings(){return[...this.buildings]}removeBuilding(e){const n=this.buildings.indexOf(e);return n!==-1&&this.buildings.splice(n,1),this.#e.delete(e),this.#u(),this.#i.delete(e),this.#o=!0,this.remove(e),this}get floorMeshes(){return this.buildings.flatMap(e=>e.floorMeshes)}setFacilityLayer(e){return this.facilityLayer&&this.remove(this.facilityLayer),this.facilityLayer=e,e&&this.add(e),this}getDefaultFacilityLayer(){return this.facilityLayer}showAllFacilities(){return this.buildings.forEach(e=>e.showAllFacilities()),this}hideAllFacilities(){return this.buildings.forEach(e=>e.hideAllFacilities()),this}getFacilityById(e){return this.#c(e)?.getFacilityById(e)}showAllFloors(){return this.buildings.forEach(e=>e.showAllFloors()),this}planishFloors(e){return this.buildings.forEach(n=>n.planishFloors(e)),this}unplanishFloors(e){return this.buildings.forEach(n=>n.unplanishFloors(e)),this}#s(e){const n=e.semanticId;typeof n=="string"&&n&&!this.#r.has(n)&&this.#r.set(n,e)}#u(){this.#r.clear(),this.buildings.forEach(e=>this.#s(e))}#c(e){return this.#f(),this.#t.get(e)}#f(){let e=this.#o||this.#i.size!==this.buildings.length;for(const n of this.buildings)n.syncFacilityIndexes(),this.#i.get(n)!==n.facilityIndexVersion&&(e=!0);e&&(this.#t.clear(),this.#n.clear(),this.#i.clear(),this.buildings.forEach(n=>{n.syncFacilityIndexes(),this.#i.set(n,n.facilityIndexVersion);for(const a of n.getFacilityIndexIds())this.#t.has(a)||this.#t.set(a,n);for(const a of n.getFacilityIndexObjects())this.#n.has(a)||this.#n.set(a,n)}),this.#o=!1)}}class FacilityInstanceObject extends uSpace.InstanceObject{isFacilityInstanceObject=!0;type="FacilityInstanceObject";constructor(){super({boundsName:"FacilityBounds"}),this.instanceKind="Facilities"}}class FacilityInstancedLayer extends uSpace.ModelInstancedLayer{isFacilityInstancedLayer=!0;type="FacilityInstancedLayer";constructor(){super({name:"Facilities",instanceKind:"Facilities",getHitUserData:(e,n)=>({semanticObject:e,semanticId:e.instanceId,semanticKind:e.instanceKind||"Facilities",semanticName:e.instanceName,semanticIndex:n,facility:e,facilityId:e.instanceId})})}}const SEMANTIC_INITIAL_COLORS={Walls:new webgpu.Vector4(.86,.86,.82,1),Columns:new webgpu.Vector4(.62,.65,.68,1),Spaces:new webgpu.Vector4(.36,.7,.5,.45),Doors:new webgpu.Vector4(.9,.52,.2,1),Windows:new webgpu.Vector4(.28,.62,.95,.65),Staircases:new webgpu.Vector4(.58,.55,.5,1)},STAIRCASE_WIDTH=1.2,STAIRCASE_STEP_HEIGHT=.16,STAIRCASE_LANDING_THICKNESS=.04,STAIRCASE_EPSILON=1e-5,STAIRCASE_MITER_LIMIT=3;function getInitialColor(f){return SEMANTIC_INITIAL_COLORS[f].clone()}function getValidPolygonShape(f,e,n){return!Array.isArray(f)||f.length<4||f.length%2!==0?(console.warn(`u-space SemanticLoader: invalid ${e} polygon shape for id ${n}.`),null):f}function convertToPlaneIVector2(f){const e=[];for(let n=0;n<f.length;n+=2)e.push({x:f[n],z:f[n+1]});return e}function parseStaircasePolyline(f){const e=f.Polyline;if(!Array.isArray(e)||e.length<6||e.length%3!==0)return console.warn(`u-space SemanticLoader: invalid Staircases polyline for id ${f.ID}.`),null;const n=[];for(let a=0;a<e.length;a+=3){const l={x:Number(e[a]),y:Number(e[a+1]),z:Number(e[a+2])};if(!Number.isFinite(l.x)||!Number.isFinite(l.y)||!Number.isFinite(l.z))return console.warn(`u-space SemanticLoader: invalid Staircases polyline point for id ${f.ID}.`),null;n.push(l)}return n}function createStaircaseSegments(f){const e=[];for(let n=0;n<f.length-1;n++){const a=f[n],l=f[n+1],t=l.x-a.x,h=l.z-a.z,u=Math.hypot(t,h);if(u<=STAIRCASE_EPSILON)continue;const o=t/u,s=h/u;e.push({start:a,end:l,length:u,dirX:o,dirZ:s,normalX:-s,normalZ:o})}return e}function createCapSection(f,e,n){return{leftX:e.x+f.normalX*n,leftZ:e.z+f.normalZ*n,rightX:e.x-f.normalX*n,rightZ:e.z-f.normalZ*n}}function cross2(f,e,n,a){return f*a-e*n}function getFallbackJoinPoint(f,e,n,a,l){let t=f.normalX+e.normalX,h=f.normalZ+e.normalZ,u=Math.hypot(t,h);u<=STAIRCASE_EPSILON&&(t=e.normalX,h=e.normalZ,u=1);const o=a*l/u;return{x:n.x+t*o,z:n.z+h*o}}function getMiterJoinPoint(f,e,n,a,l){const t=n.x+f.normalX*a*l,h=n.z+f.normalZ*a*l,u=n.x+e.normalX*a*l,o=n.z+e.normalZ*a*l,s=cross2(f.dirX,f.dirZ,e.dirX,e.dirZ);if(Math.abs(s)<=STAIRCASE_EPSILON)return{x:t,z:h};const r=cross2(u-t,o-h,e.dirX,e.dirZ)/s,c=t+f.dirX*r,d=h+f.dirZ*r,p=Math.hypot(c-n.x,d-n.z);return!Number.isFinite(p)||p>l*STAIRCASE_MITER_LIMIT?getFallbackJoinPoint(f,e,n,a,l):{x:c,z:d}}function createJoinSection(f,e,n,a){const l=getMiterJoinPoint(f,e,n,1,a),t=getMiterJoinPoint(f,e,n,-1,a);return{leftX:l.x,leftZ:l.z,rightX:t.x,rightZ:t.z}}function interpolateSection(f,e,n){return{leftX:f.leftX+(e.leftX-f.leftX)*n,leftZ:f.leftZ+(e.leftZ-f.leftZ)*n,rightX:f.rightX+(e.rightX-f.rightX)*n,rightZ:f.rightZ+(e.rightZ-f.rightZ)*n}}function addQuad(f,e,n,a,l){f.push(e,n,a,e,a,l)}function addStaircasePrism(f,e,n,a,l,t,h,u){if(a-n<=STAIRCASE_EPSILON)return;const o=l.length/3;l.push(f.leftX,n,f.leftZ,e.leftX,n,e.leftZ,e.rightX,n,e.rightZ,f.rightX,n,f.rightZ,f.leftX,a,f.leftZ,e.leftX,a,e.leftZ,e.rightX,a,e.rightZ,f.rightX,a,f.rightZ),addQuad(t,o+4,o+5,o+6,o+7),addQuad(t,o+0,o+3,o+2,o+1),addQuad(t,o+0,o+1,o+5,o+4),addQuad(t,o+2,o+3,o+7,o+6),h&&addQuad(t,o+3,o+0,o+4,o+7),u&&addQuad(t,o+1,o+2,o+6,o+5)}function createStaircaseGeometry(f){const e=parseStaircasePolyline(f),n=Number(f.Elevation??0);if(!e||!Number.isFinite(n))return Number.isFinite(n)||console.warn(`u-space SemanticLoader: invalid Staircases elevation for id ${f.ID}.`),null;const a=createStaircaseSegments(e);if(a.length===0)return console.warn(`u-space SemanticLoader: empty Staircases geometry for id ${f.ID}.`),null;const l=STAIRCASE_WIDTH/2,t=[],h=[];if(a.forEach((o,s)=>{const r=a[s-1],c=a[s+1],d=r?createJoinSection(r,o,o.start,l):createCapSection(o,o.start,l),p=c?createJoinSection(o,c,o.end,l):createCapSection(o,o.end,l),v=o.end.y-o.start.y;if(Math.abs(v)<=STAIRCASE_EPSILON){const x=n+o.start.y;addStaircasePrism(d,p,x-STAIRCASE_LANDING_THICKNESS,x,t,h,!r,!c);return}const B=Math.max(1,Math.round(Math.abs(v)/STAIRCASE_STEP_HEIGHT)),E=Math.abs(v)/B;for(let x=0;x<B;x++){const P=v>0,D=P?x/B:1-(x+1)/B,$=P?(x+1)/B:1-x/B,H=interpolateSection(d,p,D),Y=interpolateSection(d,p,$),ne=n+(P?o.start.y:o.end.y)+E*(x+1),te=ne-E;addStaircasePrism(H,Y,te,ne,t,h,!0,s===a.length-1&&x===B-1)}}),t.length===0)return console.warn(`u-space SemanticLoader: empty Staircases geometry for id ${f.ID}.`),null;const u=new webgpu.BufferGeometry;return u.setAttribute("position",new webgpu.Float32BufferAttribute(t,3)),u.setIndex(h),u.computeVertexNormals(),u.computeBoundingBox(),u.computeBoundingSphere(),u.userData.id=f.ID,u}function collectTreeNodesById(f){const e=new Map,n=(f??[]).map(a=>({node:a,parentWorldMatrix:new webgpu.Matrix4}));for(;n.length>0;){const a=n.pop(),l=a?.node;if(!l)continue;const t=getTreeNodeLocalMatrix(l);if(!t||!a)continue;const h=a.parentWorldMatrix.clone().multiply(t);e.set(l.id,{node:l,worldMatrix:h}),n.push(...(l.children??[]).map(u=>({node:u,parentWorldMatrix:h})))}return e}function getTreeNodeLocalMatrix(f){if(!Array.isArray(f.matrix)||f.matrix.length<16)return console.warn(`u-space SemanticLoader: invalid tree_models matrix for id ${f.id}.`),null;const e=f.matrix.slice(0,16).map(Number);return e.some(n=>!Number.isFinite(n))?(console.warn(`u-space SemanticLoader: invalid tree_models matrix value for id ${f.id}.`),null):new webgpu.Matrix4().fromArray(e)}function applyWorldMatrix(f,e,n){n.updateWorldMatrix(!0,!1);const a=e.clone();a.premultiply(new webgpu.Matrix4().copy(n.matrixWorld).invert()),a.decompose(f.position,f.quaternion,f.scale),f.updateMatrix()}function getModelUrl(f,e){return`${f??""}${e}`}function getTreeNodeUserData(f){return{id:f.id,pid:f.pid,name:f.name,path:f.path,renderType:f.renderType,deviceCode:f.deviceCode,matrix:f.matrix,familyId:f.familyId,visible:f.visible,shape:f.shape,boundingBox:f.boundingBox,extra:f.extra}}async function loadFacilityObject(f,e){const n=new uSpace.Model;e.manager?.itemStart(f);try{if(!await n.loadAsync({url:f}))return e.manager?.itemError(f),null}catch(a){throw e.manager?.itemError(f),a}finally{e.manager?.itemEnd(f)}return n}async function createFacilityModel(f,e,n){if(e.renderType!=="3D"||!e.path)return console.warn(`u-space SemanticLoader: invalid Facilities tree node for id ${f.ID}.`),null;const a=getModelUrl(n.path,e.path),l=await loadFacilityObject(a,n);return l?(l.name=f.Name||e.name||"",l.visible=e.visible,Object.assign(l.userData,getTreeNodeUserData(e),{facility:f,facilityId:f.ID,semanticId:f.ID,semanticKind:"Facilities",semanticName:f.Name,spaces:f.Spaces,twinsIdentifier:f.TwinsIdentifier}),l):null}class SemanticParser{parse(e){return this.#e(e).scene}async parseAsync(e,n={}){const a=this.#e(e,n);return await this.#r(e,a,n),a.scene}#e(e,n={}){const a=new SemanticGroup;a.name="SemanticGroup";const l=[],t=new Map;return e.Buildings?.forEach(h=>{const u=new BuildingGroup;u.name=h.Name||"",u.setSemanticIdentity({id:h.ID,kind:"Buildings",name:h.Name}),u.userData.id=h.ID,h.Stories.forEach(o=>{const s=e.Stories?.[o];if(s&&s.ID){const r=[];if(s.Walls?.forEach(d=>{const p=e.Walls?.[d];if(!p||!p.Polygon)return;const v=getValidPolygonShape(p.Polygon.shape,"Walls",p.ID);if(!v)return;const m=uSpace.ExtrudeMesh.createFromPoints(convertToPlaneIVector2(v),{geometryParameters:{options:{depth:p.Height,bevelEnabled:!1}}}).geometry;m.translate(0,p.Elevation,0),m.userData.id=p.ID,r.push({id:p.ID,kind:"Walls",geometry:m,color:getInitialColor("Walls")})}),s.Columns?.forEach(d=>{const p=e.Columns?.[d];if(!p||!p.Polygon)return;const v=getValidPolygonShape(p.Polygon.shape,"Columns",p.ID);if(!v)return;const m=uSpace.ExtrudeMesh.createFromPoints(convertToPlaneIVector2(v),{geometryParameters:{options:{depth:p.Height,bevelEnabled:!1}}}).geometry;m.translate(0,p.Elevation,0),m.userData.id=p.ID,r.push({id:p.ID,kind:"Columns",geometry:m,color:getInitialColor("Columns")})}),s.Doors?.forEach(d=>{const p=e.Doors?.[d];if(!p||!p.Polygon)return;const v=getValidPolygonShape(p.Polygon.shape,"Doors",p.ID);if(!v)return;const m=uSpace.ExtrudeMesh.createFromPoints(convertToPlaneIVector2(v),{geometryParameters:{options:{depth:p.Height,bevelEnabled:!1}}}).geometry;m.translate(0,p.Elevation,0),m.userData.id=p.ID,r.push({id:p.ID,kind:"Doors",geometry:m,color:getInitialColor("Doors")})}),s.Windows?.forEach(d=>{const p=e.Windows?.[d];if(!p||!p.Polygon)return;const v=getValidPolygonShape(p.Polygon.shape,"Windows",p.ID);if(!v)return;const m=uSpace.ExtrudeMesh.createFromPoints(convertToPlaneIVector2(v),{geometryParameters:{options:{depth:p.Height,bevelEnabled:!1}}}).geometry;m.translate(0,p.Elevation,0),m.userData.id=p.ID,r.push({id:p.ID,kind:"Windows",geometry:m,color:getInitialColor("Windows")})}),s.Spaces?.forEach(d=>{const p=e.Spaces?.[d];if(!p||!p.Polygon)return;const v=getValidPolygonShape(p.Polygon.shape,"Spaces",p.ID);if(!v)return;const m=p.CeilingHeight-p.GroundHeight,B=uSpace.ExtrudeMesh.createFromPoints(convertToPlaneIVector2(v),{geometryParameters:{options:{depth:m,bevelEnabled:!1}}}).geometry;B.translate(0,p.GroundHeight,0),B.userData.id=p.ID,r.push({id:p.ID,kind:"Spaces",name:p.Name,geometry:B,color:getInitialColor("Spaces")})}),s.Staircases?.forEach(d=>{const p=e.Staircases?.[d];if(!p)return;const v=createStaircaseGeometry(p);v&&(v.userData.storyId=s.ID,v.userData.floorIndex=s.FloorIndex,r.push({id:p.ID,kind:"Staircases",geometry:v,color:getInitialColor("Staircases")}))}),r.length===0&&!s.Facilities?.length)return;const c=new FloorMesh(r);c.name=s.Name||"",c.setSemanticIdentity({id:s.ID,kind:"Floors",name:s.Name}),c.userData.id=s.ID,c.userData.storyIndex=o,c.getSemantics().forEach(d=>{d.type==="geometry"&&n.registerObject?.(d.id,d.object)}),c.pivot=new webgpu.Vector3(0,s.Elevation||0,0),u.addFloor(c),t.set(o,c)}}),h.Elevators?.forEach(o=>{const s=e.Elevators?.[o];if(!s)return;const r=ElevatorMesh.create(s);r&&u.addElevator(r)}),h.Vents?.forEach(o=>{const s=e.Vents?.[o];if(!s)return;const r=VentMesh.create(s);r&&u.addVent(r)}),a.addBuilding(u),l.push(u)}),{scene:a,buildings:l,floorByStoryIndex:t}}async#r(e,n,a){const l=e.Facilities;if(!l?.length)return;const t=collectTreeNodesById(a.treeData);if(t.size===0){console.warn("u-space SemanticLoader: tree_models data is required to parse Facilities.");return}const h=[],u=new Set;e.Buildings?.forEach(o=>{o.Stories.forEach(s=>{const r=e.Stories?.[s];if(!r?.Facilities?.length)return;const c=n.floorByStoryIndex.get(s);if(!c){console.warn(`u-space SemanticLoader: Facilities floor not found for story id ${r.ID}.`);return}r.Facilities.forEach(d=>{const p=l[d];if(!p||u.has(p.ID))return;const v=t.get(p.ID);if(!v){console.warn(`u-space SemanticLoader: Facilities tree node not found for id ${p.ID}.`);return}const{node:m,worldMatrix:B}=v;if(m.renderType!=="3D"||!m.path){console.warn(`u-space SemanticLoader: invalid Facilities tree node for id ${p.ID}.`);return}u.add(p.ID),h.push({facility:p,story:r,floorMesh:c,treeNode:m,worldMatrix:B,url:getModelUrl(a.path,m.path)})})})}),await this.#t(h,n.scene,a)}async#t(e,n,a){if(e.length===0)return;const l=new FacilityInstancedLayer,t=new Map,h=[];e.forEach(u=>{const o=t.get(u.url);o?o.push(u):t.set(u.url,[u])});for(const[u,o]of t){const s=await loadFacilityObject(u,a);if(!s){h.push(...o);continue}const r=o.map(d=>this.#n(d));l.addInstances(u,s,r)?r.forEach((d,p)=>{const v=o[p];this.#o(d,v.facility,a)}):(r.forEach((d,p)=>{o[p].floorMesh.removeFacility(d)}),h.push(...o))}l.children.length>0&&n.setFacilityLayer(l),await Promise.all(h.map(u=>this.#i(u,a)))}#n(e){const{facility:n,story:a,floorMesh:l,treeNode:t,worldMatrix:h}=e,u=new FacilityInstanceObject;return u.name=n.Name||t.name||"",u.visible=t.visible,u.setInstanceIdentity({id:n.ID,kind:"Facilities",name:n.Name}),Object.assign(u.userData,getTreeNodeUserData(t),{facility:n,facilityId:n.ID,spaces:n.Spaces,twinsIdentifier:n.TwinsIdentifier,storyId:a.ID,floorIndex:a.FloorIndex,instanced:!0,modelUrl:e.url}),applyWorldMatrix(u,h,l),l.addFacility(u,n.ID),u}async#i(e,n){const{facility:a,story:l,treeNode:t}=e,h=await createFacilityModel(a,t,n);if(!h)return;const u=this.#n(e);u.userData.instanced=!1,Object.assign(h.userData,{storyId:l.ID,floorIndex:l.FloorIndex,instanced:!1}),h.position.set(0,0,0),h.quaternion.identity(),h.scale.set(1,1,1),u.setInstanceRenderObject(h),this.#o(u,a,n)}#o(e,n,a){a.registerObject?.(n.ID,e)}}class SemanticLoader extends webgpu.Loader{viewer;key="";cachedIds=new Set;constructor(e){super(),this.viewer=e,this.manager=new webgpu.LoadingManager}setKey(e){return this.key=e,this}async#e(e){const n=await e.loadAsync(META_DATA_FILE_PATH);if(n.version<1.5)throw new Error("u-space SemanticLoader: Only support version 1.5 and above");if(!this.key&&n.authority==="OFFICIAL")throw new Error("u-space SemanticLoader: options.key is required when authority is OFFICIAL");this.key&&n.authority==="TRIAL"&&console.warn("u-space SemanticLoader: options.key is not used when authority is TRIAL");const a=n.treeModel||n.resource,l=await e.loadAsync(a);if(n.encryptWith==="DEBUG")try{return decryptWithDebugKey(l)}catch{throw new Error("u-space SemanticLoader: decrypt with debug key failed")}if(n.encryptWith==="SCENE"||n.encryptWith==="COMPANY")try{return decryptWithKey(l,this.key)}catch{throw new Error("u-space SemanticLoader: decrypt with authorized key failed")}return l}#r(e,n){this.viewer.objectManager.add(e,n),this.cachedIds.add(e)}async loadAsync(){if(!this.path)throw new Error("u-space SemanticLoader: path is not set");this.manager.itemStart(this.path);let e=!1;try{const n=new BaseFileLoader(this),a=await n.loadAsync(SEMANTIC_DATA_FILE_PATH),l=a.Facilities?.length?await this.#e(n):void 0,t=new SemanticParser;return this.clearCache(),e=!0,t.parseAsync(a,{treeData:l,path:this.path,manager:this.manager,registerObject:(h,u)=>this.#r(h,u)})}catch(n){throw e&&this.clearCache(),this.manager.itemError(this.path),n}finally{this.manager.itemEnd(this.path)}}clearCache(){this.cachedIds.forEach(e=>{this.viewer.objectManager.removeById(e)}),this.cachedIds.clear()}dispose(){this.clearCache()}}class UManagerSceneGroup extends uSpace.BaseGroup{isUManagerSceneGroup=!0;type="UManagerSceneGroup";semanticGroup;sceneGroup;constructor(e,n){super(),this.name="UManagerScene",this.semanticGroup=e,this.sceneGroup=n,this.add(e),this.add(n)}}class UManagerLoader extends webgpu.Loader{viewer;key="";sceneLoader;semanticLoader;constructor(e){super(),this.viewer=e,this.manager=new webgpu.LoadingManager,this.sceneLoader=new SceneLoader(e),this.semanticLoader=new SemanticLoader(e)}setKey(e){return this.key=e,this.sceneLoader.setKey(e),this.semanticLoader.setKey(e),this}async loadAsync(){if(!this.path)throw new Error("u-space UManagerLoader: path is not set");this.#e(),this.manager.itemStart(this.path);try{const[e,n]=await Promise.allSettled([this.semanticLoader.loadAsync(),this.sceneLoader.loadAsync()]);if(e.status==="rejected")throw e.reason;if(n.status==="rejected")throw n.reason;const a=e.value,l=n.value;return new UManagerSceneGroup(a,l)}catch(e){throw this.clearCache(),this.manager.itemError(this.path),e}finally{this.manager.itemEnd(this.path)}}clearCache(){this.sceneLoader.clearCache(),this.semanticLoader.clearCache()}dispose(){this.sceneLoader.dispose(),this.semanticLoader.dispose()}#e(){for(const e of[this.sceneLoader,this.semanticLoader])e.setPath(this.path),e.setRequestHeader(this.requestHeader),e.setWithCredentials(this.withCredentials),e.manager=this.manager,this.key&&e.setKey(this.key)}}class AnimationsLoader extends webgpu.Loader{constructor(){super(),this.manager=new webgpu.LoadingManager}async loadAsync(){return await new BaseFileLoader(this).loadAsync(ANIMATIONS_DATA_FILE_PATH)}}class AnimationsParser extends webgpu.EventDispatcher{viewer;target;tweenSet;_initialTransformSymbol=Symbol("initialTransform");constructor(e,n){super(),this.viewer=e,this.target=n,this.tweenSet=new Set}initTransform(e){const{position:n,rotation:a,scale:l}=this.target,t=e??{x:n.x,y:n.y,z:n.z,rotationX:a.x,rotationY:a.y,rotationZ:a.z,scaleX:l.x,scaleY:l.y,scaleZ:l.z};return Reflect.set(this.target,this._initialTransformSymbol,t),t}getInitialTransform(){return Reflect.get(this.target,this._initialTransformSymbol)}async play(e){let n=this.getInitialTransform();n||(n=this.initTransform());for(let a=0;a<e.length;a++){let l=e[a-1];l||(l=n);const t=e[a],h=t.delay??0,u=t.duration??1e3,o=t.easing,s=t.repeat===-1?1/0:t.repeat??0,r=t.yoyo??!1;await uSpace.tweenAnimation(this.viewer,{...l},{...t},{delay:h,duration:u,mode:o,repeat:s,yoyo:r},(c,d)=>{const{x:p,y:v,z:m,rotationX:B,rotationY:E,rotationZ:x,scaleX:P,scaleY:D,scaleZ:$}=c;this.target.position.set(p,v,m),this.target.rotation.set(B,E,x),this.target.scale.set(P,D,$),this.dispatchEvent({type:"update",source:c,tween:d})},c=>{this.tweenSet.add(c),this.dispatchEvent({type:"start",tween:c})})}}stop(){this.tweenSet.forEach(e=>e.stop()),this.tweenSet.clear()}reset(){const e=this.getInitialTransform();if(e){const{x:n,y:a,z:l,rotationX:t,rotationY:h,rotationZ:u,scaleX:o,scaleY:s,scaleZ:r}=e;this.target.position.set(n,a,l),this.target.rotation.set(t,h,u),this.target.scale.set(o,s,r),this.viewer.invalidate()}}dispose(){this.stop(),this.reset(),Reflect.deleteProperty(this.target,this._initialTransformSymbol)}}class TopologyParser{parse(e){const{name:n,position:a,rotation:l,scale:t,nodes:h,nodeRadius:u=.2,nodeColor:o="#0000ff",linkWidth:s=.1,linkColor:r=["#00ff00"]}=e,c=new uSpace.Topology({nodeRadius:u,nodeColor:o,edgeRadius:s,edgeColor:r[0],pathRadius:s+.05});return c.name=n,c.position.set(a.x,a.y,a.z),c.rotation.set(l.x,l.y,l.z),c.scale.set(t.x,t.y,t.z),h.forEach(d=>{const p=new webgpu.Vector3().copy(d.position);c.addNode(d.id,p)}),h.forEach(d=>{d.graphs.forEach(p=>{c.addEdge(d.id,p.targetNodeId)})}),c.renderGraph(),Object.assign(c.userData,e),c}}class TopologiesLoader extends webgpu.Loader{constructor(){super(),this.manager=new webgpu.LoadingManager}async loadAsync(){if(!this.path)throw new Error("u-manager TopologiesLoader: path is not set");const n=await new BaseFileLoader(this).loadAsync(TOPOLOGY_DATA_FILE_PATH),a=new TopologyParser,l=[];return n.forEach(t=>{const h=a.parse(t);l.push(h)}),l}}class PropertiesLoader extends webgpu.Loader{constructor(){super(),this.manager=new webgpu.LoadingManager}async loadAsync(){return await new BaseFileLoader(this).loadAsync(PROPERTIES_DATA_FILE_PATH)}}class VisionsLoader extends webgpu.Loader{constructor(){super(),this.manager=new webgpu.LoadingManager}async loadAsync(){return await new BaseFileLoader(this).loadAsync(VISIONS_DATA_FILE_PATH)}}class VisionsParser{viewer;constructor(e){this.viewer=e}async flyToPrimary(e,n=!0){const a=e.find(l=>l.primary);return a?(await this.flyTo(a,n),!0):!1}async flyTo(e,n=!0){const{camera:a,position:l,target:t,zoom:h=this.viewer.camera.zoom}=e;a==="P"?this.viewer.setCameraByType("perspective"):a==="O"&&this.viewer.setCameraByType("orthographic");const{x:u,y:o,z:s}=l,{x:r,y:c,z:d}=t;await Promise.all([this.viewer.controls.setLookAt(u,o,s,r,c,d,n),this.viewer.controls.zoomTo(h,n)])}}class Edge{id;source;target;sourceHandle;constructor(e){this.id=e.id,this.source=e.source,this.target=e.target,this.sourceHandle=e.sourceHandle}}function objectHandle(f,e){return Array.isArray(f)?f.map(e):e(f)}function sleep(f){return new Promise(e=>setTimeout(e,f))}function parseNodeByType(f,e){switch(e.type){case"START":return new StartNode(f,e);case"COLOR":return new ColorNode(f,e);case"NUMBER":return new NumberNode(f,e);case"HIGHLIGHT":return new HighlightNode(f,e);case"UN_HIGHLIGHT":return new UnHighlightNode(f,e);case"OPACITY":return new OpacityNode(f,e);case"UN_OPACITY":return new UnOpacityNode(f,e);case"EMISSIVE":return new EmissiveNode(f,e);case"UN_EMISSIVE":return new UnEmissiveNode(f,e);case"MESH":return new MeshNode(f,e);case"MESHES":return new MeshesNode(f,e);case"MODEL":return new ModelNode(f,e);case"MODELS":return new ModelsNode(f,e);case"SPACE":return new SpaceNode(f,e);case"SPACES":return new SpacesNode(f,e);case"POIS":return new POIsNode(f,e);case"POI":return new POINode(f,e);case"PATH":return new PathNode(f,e);case"PATHS":return new PathsNode(f,e);case"DELAY":return new DelayNode(f,e);case"CONDITION_NODE":return new ConditionNode(f,e);case"SHOW":return new ShowNode(f,e);case"HIDE":return new HideNode(f,e);case"CLIP_ANIMATION":return new ClipAnimationNode(f,e);case"UN_CLIP_ANIMATION":return new UnClipAnimationNode(f,e);case"TWEEN_ANIMATION":return new TweenAnimationNode(f,e);case"UN_TWEEN_ANIMATION":return new UnTweenAnimationNode(f,e);case"COMPONENT_TWEEN_ANIMATION":return new ComponentTweenAnimationNode(f,e);case"UN_COMPONENT_TWEEN_ANIMATION":return new UnComponentTweenAnimationNode(f,e);case"TRANSLATE":return new TranslateNode(f,e);case"ROTATE":return new RotateNode(f,e);case"SCALE":return new ScaleNode(f,e);case"FLY_TO":return new FlyToNode(f,e);case"DATA_EXTRACTION":return new DataExtractionNode(f,e);case"DATA_FILTER":return new DataFilterNode(f,e);case"USER_DATA_NODE":return new UserDataNode(f,e);default:return new Node(f,e)}}function parseValue(f){return JSON.parse(f)}async function waitFor(f,e){e?await f():f()}function getObjectByIds(f,e){return e.map(n=>f.objectManager.getById(n)).filter(Boolean)}function getObjectById(f,e,n){const a=f.objectManager.getById(e);if(a)return a;{const l=f.scene;return getMeshByUserDataUuid(n??l,e)}}function getMeshByUserDataUuid(f,e){if(f.userData.key===e||f.uuid===e)return f;for(let n=0,a=f.children.length;n<a;n++){const l=f.children[n],t=getMeshByUserDataUuid(l,e);if(t!==null)return t}return null}let count=0;const preloadNodes=["MESH","MESHES","MODEL","MODELS","POI","POIS","SPACE","SPACES","PATH","PATHS","COLOR","NUMBER","DATA_EXTRACTION","DATA_FILTER","USER_DATA_NODE","CONDITION_NODE","START"];class Node{parser;viewer;id;type;props;prevNodes=[];postNodes=[];execOrder=0;ctx;promise;resolve;reject;cleanSets=new Set;onBefore=null;onAfter=null;rejected;constructor(e,n){this.parser=e,this.viewer=e.viewer,this.id=n.id,this.type=n.type,this.props=n.props,this.rejected=!1,this.init()}init(){this.ctx={},this.promise=new Promise((e,n)=>{this.resolve=e,this.reject=a=>{this.rejected=!0,n(a)}})}readContext(e){return this.ctx[e]}writeContext(e,n){this.ctx[e]=n}findProp(e,n){if(n instanceof Array)for(const a of n){const l=this.findProp(e,a);if(l)return l}else return this.props.find(a=>a.name===e&&a.type===n)}async waitForPrevNodes(){return await Promise.all(this.prevNodes.map(e=>e.promise))}mergeContext(){this.prevNodes.forEach(e=>{Object.assign(this.ctx,e.ctx)}),this._mergeUserDataMap()}async exec(e){}async run(e,n={preload:!1}){const{preload:a}=n;try{if(await this.waitForPrevNodes(),this.rejected)throw new Error;this.mergeContext(),await(this.onBefore??this.parser.onNodeBefore)?.(this);try{(!a||preloadNodes.includes(this.type))&&(this.execOrder=++count,await this.exec(e))}catch(l){throw this.reject(l),l}await(this.onAfter??this.parser.onNodeAfter)?.(this),this.resolve()}catch(l){this.reject(l)}}cleanup(){this.cleanSets.forEach(e=>e()),this.cleanSets.clear()}getValue(e,n){if(e.type==="READ_CTX")return this.readContext(parseValue(e.value));if(e.type==="LOCAL"){const{scene:a}=this.viewer;return e.name==="objects"||e.name==="models"||e.name==="meshs"?parseValue(e.value).map(l=>getObjectById(this.viewer,l,n??a)):e.name==="object"||e.name==="model"||e.name==="mesh"?getObjectById(this.viewer,parseValue(e.value),n??a):parseValue(e.value)}}_mergeUserDataMap(){if(this.prevNodes.some(e=>e.ctx._userDataMap))this.ctx._userDataMap=new Map;else return;this.prevNodes.forEach(e=>{e.ctx._userDataMap&&e.ctx._userDataMap.forEach((n,a)=>{this.ctx._userDataMap.set(a,Object.assign({},n))})})}}class StartNode extends Node{constructor(e,n){super(e,n)}}class ColorNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("color","LOCAL"),n=this.findProp("out","WRITE_CTX");e&&n&&this.writeContext(parseValue(n.value),parseValue(e.value))}}class NumberNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("number","LOCAL"),n=this.findProp("out","WRITE_CTX");e&&n&&this.writeContext(parseValue(n.value),parseValue(e.value))}}class HighlightNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=this.findProp("color",["READ_CTX","LOCAL"]),l=this.findProp("opacity",["READ_CTX","LOCAL"]),t=await e.getTarget?.(this);if(n&&a&&l){const h=this.getValue(n,t),u=this.getValue(a),o=this.getValue(l);h&&(index.MaterialEffects.highlightColor(h,{color:u,opacity:o}),this.cleanSets.add(()=>{index.MaterialEffects.removeHighlightColor(h)}))}}}class UnHighlightNode extends Node{constructor(e,n){super(e,n)}filterUnHighlightObject(e){const n=[];return objectHandle(e,a=>{n.push(a)}),n}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=await e.getTarget?.(this);if(n){const l=this.getValue(n,a);l&&uSpace.MaterialEffects.removeHighlightColor(l)}}}class OpacityNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=this.findProp("color",["READ_CTX","LOCAL"]),l=this.findProp("opacity",["READ_CTX","LOCAL"]),t=await e.getTarget?.(this);if(n&&a&&l){const h=this.getValue(n,t),u=this.getValue(a),o=this.getValue(l);if(h){const s=objectHandle(h,r=>r);index.MaterialEffects.highlightColor(s,{color:u,opacity:o,overwrite:!0}),this.cleanSets.add(()=>{index.MaterialEffects.removeHighlightColor(s)})}}}}class UnOpacityNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=await e.getTarget?.(this);if(n){const l=this.getValue(n,a);l&&uSpace.MaterialEffects.removeHighlightColor(l)}}}class EmissiveNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=this.findProp("color",["READ_CTX","LOCAL"]),l=this.findProp("baseColor",["READ_CTX","LOCAL"]),t=this.findProp("minOpacity",["READ_CTX","LOCAL"]),h=this.findProp("maxOpacity",["READ_CTX","LOCAL"]),u=this.findProp("duration",["READ_CTX","LOCAL"]),o=await e.getTarget?.(this);if(n&&a&&l&&t&&h&&u){const s=this.getValue(n,o),r=this.getValue(a),c=this.getValue(h);s&&(uSpace.MaterialEffects.breatheColor(s,{color:r,intensity:c}),this.cleanSets.add(()=>{uSpace.MaterialEffects.removeBreatheColor(s)}))}}}class UnEmissiveNode extends Node{constructor(e,n){super(e,n)}filterUnEmissiveObject(e){const n=[];return objectHandle(e,a=>{n.push(a)}),n}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=await e.getTarget?.(this);n&&this.getValue(n,a)}}const meshCacheSymbol=Symbol("meshCache");class MeshNode extends Node{constructor(e,n){super(e,n)}async exec(e){const{scene:n}=this.viewer,a=await e.getTarget?.(this)||n;e[meshCacheSymbol]||(e[meshCacheSymbol]={});const l=this.findProp("mesh","LOCAL"),t=this.findProp("out","WRITE_CTX");if(l&&t){let h=null;const u=parseValue(l.value),o=parseValue(t.value),s=e[meshCacheSymbol][u];if(s){h=s;return}const r=getMeshByUserDataUuid(a,u);r&&(h=r,e[meshCacheSymbol][u]=r),this.writeContext(o,h)}}}const meshesCacheSymbol=Symbol("meshesCache");class MeshesNode extends Node{constructor(e,n){super(e,n)}async exec(e){const{scene:n}=this.viewer,a=await e.getTarget?.(this)||n;e[meshesCacheSymbol]||(e[meshesCacheSymbol]={});const l=this.findProp("meshes","LOCAL"),t=this.findProp("out","WRITE_CTX");if(l&&t){const h=[],u=parseValue(l.value),o=parseValue(t.value);u.forEach(s=>{const r=e[meshesCacheSymbol][s];if(r){h.push(r);return}const c=getMeshByUserDataUuid(a,s);c&&(h.push(c),e[meshesCacheSymbol][s]=c)}),this.writeContext(o,h)}}}class ModelNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("model","LOCAL"),n=this.findProp("out","WRITE_CTX");if(e&&n){const a=parseValue(e.value),l=parseValue(n.value);this.writeContext(l,getObjectById(this.viewer,a))}}}class ModelsNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("models","LOCAL"),n=this.findProp("out","WRITE_CTX");if(e&&n){const a=parseValue(e.value),l=parseValue(n.value);this.writeContext(l,getObjectByIds(this.viewer,a))}}}class DelayNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("delay","LOCAL");if(e){const n=parseValue(e.value);await sleep(n)}}}class ConditionNode extends Node{constructor(e,n){super(e,n)}execFn(e){return new Function("sourceData",e)(this.ctx)}async exec(){const e=this.findProp("conditaion_node","LOCAL");if(e){const n=parseValue(e.value),a=this.parser.edges.filter(l=>l.source===this.id);n.forEach(l=>{try{if(this.execFn(l.value)!==!0)throw new Error}catch{const h=a.find(o=>o.sourceHandle==String(l.id));if(!h)return;this.postNodes.find(o=>o.id===h.target)?.reject()}})}}}class ShowNode extends Node{constructor(e,n){super(e,n)}filterShowObject(e){const n=[];return objectHandle(e,a=>{a.visible===!1&&n.push(a)}),n}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=await e.getTarget?.(this);if(n){const l=this.getValue(n,a);if(l){const t=this.filterShowObject(l),h=u=>{objectHandle(t,o=>{o.visible=u}),this.viewer.invalidate()};h(!0),this.cleanSets.add(()=>h(!1))}}}}class HideNode extends Node{constructor(e,n){super(e,n)}filterHideObject(e){const n=[];return objectHandle(e,a=>{a.visible===!0&&n.push(a)}),n}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=await e.getTarget?.(this);if(n){const l=this.getValue(n,a);if(l){const t=this.filterHideObject(l),h=u=>{objectHandle(t,o=>{o.visible=u}),this.viewer.invalidate()};h(!1),this.cleanSets.add(()=>h(!0))}}}}class TranslateNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=this.findProp("axis",["READ_CTX","LOCAL"]),l=this.findProp("translate",["READ_CTX","LOCAL"]),t=await e.getTarget?.(this);if(n&&a&&l){const h=this.getValue(n,t),u=this.getValue(a),o=this.getValue(l);if(h){const s=[];objectHandle(h,p=>{s.push(p.position.clone())});const c=(p,v)=>{switch(u){case"x":p.setX(v.x);break;case"y":p.setY(v.y);break;case"z":p.setZ(v.z);break}};await(async()=>{const p=objectHandle(h,async v=>{const m=v.position.clone();switch(u){case"x":await uSpace.tweenAnimation(this.viewer,m,new webgpu.Vector3().set(m.x+o,m.y,m.z),{duration:800},B=>c(v.position,B));break;case"y":await uSpace.tweenAnimation(this.viewer,m,new webgpu.Vector3().set(m.x,m.y+o,m.z),{duration:800},B=>c(v.position,B));break;case"z":await uSpace.tweenAnimation(this.viewer,m,new webgpu.Vector3().set(m.x,m.y,m.z+o),{duration:800},B=>c(v.position,B));break}});p instanceof Array?await Promise.all(p):await p,this.viewer.invalidate()})(),this.cleanSets.add(()=>{let p=0;objectHandle(h,v=>{v.position.copy(s[p++])})})}}}}class ScaleNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=this.findProp("axis",["READ_CTX","LOCAL"]),l=this.findProp("scale",["READ_CTX","LOCAL"]),t=await e.getTarget?.(this);if(n&&a&&l){const h=this.getValue(n,t),u=this.getValue(a),o=this.getValue(l);if(h){const s=[];objectHandle(h,p=>{s.push(p.scale.clone())});const c=(p,v)=>{switch(u){case"x":p.setX(v.x);break;case"y":p.setY(v.y);break;case"z":p.setZ(v.z);break}};await(async()=>{const p=objectHandle(h,async v=>{const m=v.scale.clone();switch(u){case"x":await uSpace.tweenAnimation(this.viewer,m,new webgpu.Vector3().set(m.x*o,m.y,m.z),{duration:800},B=>c(v.scale,B));break;case"y":await uSpace.tweenAnimation(this.viewer,m,new webgpu.Vector3().set(m.x,m.y*o,m.z),{duration:800},B=>c(v.scale,B));break;case"z":await uSpace.tweenAnimation(this.viewer,m,new webgpu.Vector3().set(m.x,m.y,m.z*o),{duration:800},B=>c(v.scale,B));break}});p instanceof Array?await Promise.all(p):await p,this.viewer.invalidate()})(),this.cleanSets.add(()=>{let p=0;objectHandle(h,v=>{v.scale.copy(s[p++])})})}}}}class RotateNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("objects",["READ_CTX","LOCAL"]),a=this.findProp("axis",["READ_CTX","LOCAL"]),l=this.findProp("rotation",["READ_CTX","LOCAL"]),t=await e.getTarget?.(this);if(n&&a&&l){const h=this.getValue(n,t),u=this.getValue(a),o=this.getValue(l);if(h){const s=[];objectHandle(h,p=>{s.push(p.rotation.clone())});const c=(p,v)=>{switch(u){case"x":p.x=v.x;break;case"y":p.y=v.y;break;case"z":p.z=v.z;break}};await(async()=>{const p=o/180*Math.PI,v=objectHandle(h,async m=>{const B=m.rotation.clone();switch(u){case"x":await uSpace.tweenAnimation(this.viewer,B,new webgpu.Euler().set(B.x+p,B.y,B.z),{duration:800},E=>c(m.rotation,E));break;case"y":await uSpace.tweenAnimation(this.viewer,B,new webgpu.Euler().set(B.x,B.y+p,B.z),{duration:800},E=>c(m.rotation,E));break;case"z":await uSpace.tweenAnimation(this.viewer,B,new webgpu.Euler().set(B.x,B.y,B.z+p),{duration:800},E=>c(m.rotation,E));break}});v instanceof Array?await Promise.all(v):await v,this.viewer.invalidate()})(),this.cleanSets.add(()=>{let p=0;objectHandle(h,v=>{v.rotation.copy(s[p++])})})}}}}class FlyToNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("viewpoint",["READ_CTX","LOCAL"]);if(e){const n=parseValue(this.getValue(e));n&&this.viewer.controls.setCameraViewpoint(n,!0)}}}class SpaceNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("space","LOCAL"),n=this.findProp("out","WRITE_CTX");if(e&&n){const a=parseValue(e.value),l=parseValue(n.value);this.writeContext(l,getObjectById(this.viewer,a))}}}class SpacesNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("spaces","LOCAL"),n=this.findProp("out","WRITE_CTX");if(e&&n){const a=parseValue(e.value),l=parseValue(n.value),t=a.map(h=>getObjectById(this.viewer,h));this.writeContext(l,t)}}}class POINode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("poi","LOCAL"),a=this.findProp("out","WRITE_CTX");if(n&&a){const l=parseValue(n.value),t=parseValue(a.value);this.writeContext(t,getObjectById(this.viewer,l))}}}class POIsNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("pois","LOCAL"),a=this.findProp("out","WRITE_CTX");if(n&&a){const l=parseValue(n.value),t=parseValue(a.value),h=l.map(u=>getObjectById(this.viewer,u));this.writeContext(t,h)}}}class DataExtractionNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("value","LOCAL"),n=this.findProp("object","LOCAL"),a=this.findProp("out","WRITE_CTX"),l=this.findProp("extraction","LOCAL");if(e&&a&&l&&n){const t=parseValue(l.value),h=parseValue(a.value),u=parseValue(n.value),o=this.getValue(n);let s=parseValue(e.value);if(this.ctx._userDataMap){const r=this.ctx._userDataMap.get(u);r&&(s=r[t])}else if(o&&o.userData.properties){const r=o.userData.properties.find(c=>c.key===t);r&&r.value!==void 0&&(s=r.value)}this.writeContext(h,s)}}}class DataFilterNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("model","LOCAL");if(e){const n=parseValue(e.value),a=new Function("sourceData",n);for(const l in this.ctx){const t=a(this.ctx[l]);(t==null||t===!1)&&delete this.ctx[l]}}}}class PathNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("path","LOCAL"),n=this.findProp("out","WRITE_CTX");if(e&&n){const a=parseValue(e.value),l=parseValue(n.value);this.writeContext(l,getObjectById(this.viewer,a))}}}class PathsNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("paths","LOCAL"),n=this.findProp("out","WRITE_CTX");if(e&&n){const a=parseValue(e.value),l=parseValue(n.value),t=a.map(h=>getObjectById(this.viewer,h));this.writeContext(l,t)}}}class UserDataNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("object",["READ_CTX","LOCAL"]),n=this.findProp("data","LOCAL"),a=this.findProp("source","WRITE_CTX");if(e&&n&&a){let l=parseValue(e.value);const t=parseValue(n.value),h=parseValue(a.value);if(h&&(l=h),l&&t){this.ctx._userDataMap||(this.ctx._userDataMap=new Map);const u=this.ctx._userDataMap.get(l);u?Object.assign(u,t):this.ctx._userDataMap.set(l,t)}}}}class ClipAnimationNode extends Node{constructor(e,n){super(e,n)}async exec(e){let n=await e.getTarget?.(this);if(!n){const l=this.findProp("model",["READ_CTX","LOCAL"]);l&&(n=this.getValue(l))}const a=this.findProp("animation",["READ_CTX","LOCAL"]);if(n&&a){let l;if(a.type==="READ_CTX"){const u=this.parser.getVariableNameById(parseValue(a.value));l=this.readContext(u)}else l=parseValue(a.value);const t=n.playAnimation(l);if(!t)return;const h=({delta:u})=>{n.updateAnimation(u),this.viewer.invalidate(),t.isRunning()||this.viewer.removeEventListener("afterControlsUpdate",h)};this.viewer.addEventListener("afterControlsUpdate",h),this.cleanSets.add(()=>{n.stopAnimation(l),this.viewer.removeEventListener("afterControlsUpdate",h)})}}}class UnClipAnimationNode extends Node{constructor(e,n){super(e,n)}async exec(e){let n=await e.getTarget?.(this);if(!n){const l=this.findProp("model",["READ_CTX","LOCAL"]);l&&(n=this.getValue(l))}const a=this.findProp("animation",["READ_CTX","LOCAL"]);if(n&&a){let l;if(a.type==="READ_CTX"){const t=this.parser.getVariableNameById(parseValue(a.value));l=this.readContext(t)}else l=parseValue(a.value);n.stopAnimation(l)}}}const tweenCache$1=new Map;async function playTweenAnimation(f,e,n){const{id:a,keyframes:l}=n,t=new AnimationsParser(f,e);tweenCache$1.has(a)||tweenCache$1.set(a,new Set),tweenCache$1.get(a)?.add(t),await t.play(l)}function stopTweenAnimation(f){tweenCache$1.get(f)?.forEach(e=>e.stop()),tweenCache$1.get(f)?.clear()}class TweenAnimationNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("model",["READ_CTX","LOCAL"]),a=this.findProp("animation","LOCAL"),l=this.findProp("wait","LOCAL");if(n&&a&&l){const t=this.getValue(n),h=parseValue(a.value),u=parseValue(l.value);if(t){const o=await e.getAnimations?.(this,t,h);if(o){const s=o.find(r=>r.id===h);s&&await waitFor(async()=>{const r=t.matrix.clone();await playTweenAnimation(this.viewer,t,s),this.cleanSets.add(()=>{stopTweenAnimation(s.id),t&&r.decompose(t.position,t.quaternion,t.scale)})},u)}}}}}class UnTweenAnimationNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("animation","LOCAL");if(e){const n=parseValue(e.value);stopTweenAnimation(n)}}}const tweenCache=new Map;async function playComponentTweenAnimation(f,e,n){const{id:a,keyframes:l}=n,t=new AnimationsParser(f,e);tweenCache.has(a)||tweenCache.set(a,new Set),tweenCache.get(a)?.add(t),await t.play(l)}function stopComponentTweenAnimation(f){tweenCache.get(f)?.forEach(e=>e.stop()),tweenCache.get(f)?.clear()}class ComponentTweenAnimationNode extends Node{constructor(e,n){super(e,n)}async exec(e){const n=this.findProp("mesh",["READ_CTX","LOCAL"]),a=this.findProp("animation","LOCAL"),l=this.findProp("wait","LOCAL");if(n&&a&&l){const t=this.getValue(n),h=parseValue(a.value),u=parseValue(l.value);if(t){const o=await e.getComponentAnimations?.(this,t,h);if(o){const s=o.find(r=>r.id===h);if(s){let r=null;n.valueType==="Mesh"?r=t:n.valueType==="Model"&&(r=getMeshByUserDataUuid(t,s.refId)),r&&await waitFor(async()=>{if(r){const c=r.matrix.clone();await playComponentTweenAnimation(this.viewer,r,s),this.cleanSets.add(()=>{stopComponentTweenAnimation(s.id),r&&c.decompose(r.position,r.quaternion,r.scale)})}},u)}}}}}}class UnComponentTweenAnimationNode extends Node{constructor(e,n){super(e,n)}async exec(){const e=this.findProp("animation","LOCAL");if(e){const n=parseValue(e.value);stopComponentTweenAnimation(n)}}}class FlowParser extends webgpu.EventDispatcher{viewer;flow;nodes;nodesMap;edges;edgesMap;onNodeBefore=null;onNodeAfter=null;constructor(e,n){super(),this.viewer=e,this.flow=n,this.nodes=[],this.nodesMap=new Map,this.edges=[],this.edgesMap=new Map}addNode(e){this.nodes.push(e),this.nodesMap.set(e.id,e)}addEdge(e){this.edges.push(e),this.edgesMap.set(e.id,e)}getNodeById(e){return this.nodesMap.get(e)}getEdgeById(e){return this.edgesMap.get(e)}clear(){this.nodes.length=0,this.nodesMap.clear(),this.edges.length=0,this.edgesMap.clear()}parse(){this.clear();const{nodes:e,edges:n}=this.flow;e.forEach(a=>{const l=parseNodeByType(this,a);this.addNode(l)}),n.forEach(a=>{const l=new Edge(a);this.addEdge(l);const t=this.getNodeById(a.source),h=this.getNodeById(a.target);t&&h&&(t.postNodes.push(h),h.prevNodes.push(t))})}async run(e={},n={preload:!1}){const{preload:a}=n,t=this.nodes.filter(h=>h.prevNodes.length||h.postNodes.length).map(h=>h.run(e,{preload:a}));await Promise.allSettled(t)}async debug(e={},n=1500){const a=this.onNodeAfter;this.onNodeAfter=async l=>{await sleep(n),a?.(l)},await this.run(e)}stop(){this.nodes.forEach(e=>e.reject(new Error("Flow stopped")))}cleanup(){this.nodes.sort((e,n)=>n.execOrder-e.execOrder).forEach(e=>e.cleanup())}getVariableNameById(e){const n=this.nodes.find(a=>a.id===e);if(n){const a=n.props.find(l=>l.name==="out");return a?parseValue(a.value):null}return null}dispose(){this.stop(),this.cleanup()}}class ComponentFlowParser extends FlowParser{flow;constructor(e,n){super(e,n),this.flow=n}}exports.AnimationsLoader=AnimationsLoader;exports.AnimationsParser=AnimationsParser;exports.BuildingGroup=BuildingGroup;exports.ComponentFlowParser=ComponentFlowParser;exports.ElevatorMesh=ElevatorMesh;exports.FacilityInstanceObject=FacilityInstanceObject;exports.FacilityInstancedLayer=FacilityInstancedLayer;exports.FloorMesh=FloorMesh;exports.FloorSemanticInstanceObject=FloorSemanticInstanceObject;exports.FlowParser=FlowParser;exports.Node=Node;exports.PropertiesLoader=PropertiesLoader;exports.SceneEditableBatchLayer=SceneEditableBatchLayer;exports.SceneGroup=SceneGroup;exports.SceneInstanceObject=SceneInstanceObject;exports.SceneInstancedLayer=SceneInstancedLayer;exports.SceneLoader=SceneLoader;exports.SemanticGroup=SemanticGroup;exports.SemanticLoader=SemanticLoader;exports.SemanticParser=SemanticParser;exports.TopologiesLoader=TopologiesLoader;exports.TopologyParser=TopologyParser;exports.UManagerLoader=UManagerLoader;exports.UManagerSceneGroup=UManagerSceneGroup;exports.VentMesh=VentMesh;exports.VerticalShaftMesh=VerticalShaftMesh;exports.VisionsLoader=VisionsLoader;exports.VisionsParser=VisionsParser;exports.createVerticalShaftMesh=createVerticalShaftMesh;