@zeainc/gltf-loader
Version:
A plugin to load GLTF files in Zea Engine.
1 lines • 56.1 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@zeainc/zea-engine"),require("jpeg-js"),require("fast-png")):"function"==typeof define&&define.amd?define(["exports","@zeainc/zea-engine","jpeg-js","fast-png"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).gltfLoader={},e.zeaEngine,e.jpeg,e.png)}(this,(function(e,t,s,i){"use strict";function r(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(s){if("default"!==s){var i=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,i.get?i:{enumerable:!0,get:function(){return e[s]}})}})),t.default=e,Object.freeze(t)}var n=r(s),o=r(i),a={name:"@zeainc/gltf-loader",libraryName:"GLTFLoader",author:"Philip Taylor",description:"A plugin to load GLTF files in Zea Engine.",version:"4.0.7",license:"MIT",main:"dist/index.cjs.js",module:"dist/index.esm.js",browser:"dist/index.umd.js",files:["dist/"],keywords:["WebGL","ES6","Zea","GLTF","Draco"],repository:{type:"git",url:"https://github.com/ZeaInc/gltf-loader"},scripts:{build:"rollup -c","build:watch":"rollup -w -c",dev:"npm-run-all --parallel build:watch start:watch",dist:"yarn publish --access=public",generate:"plop",prepare:"yarn run build",release:"standard-version",start:"es-dev-server","start:watch":"es-dev-server --app-index testing-e2e/index.html --open --watch","test:e2e":"percy exec cypress run --browser chrome --headless","test:e2e:watch":"percy exec cypress open"},devDependencies:{"@percy/cypress":"^2.3.2","@rollup/plugin-json":"^4.1.0","@zeainc/zea-engine":"^4",cypress:"^5.4.0","es-dev-server":"^1.57.8",eslint:"^6.5.1","eslint-config-google":"^0.14.0","eslint-config-prettier":"^6.3.0","eslint-plugin-prettier":"^3.1.1","npm-run-all":"^4.1.5",plop:"^2.7.4",prettier:"^2.1.1",rollup:"^2.2.0","rollup-plugin-terser":"^5.3.0","rollup-plugin-web-worker-loader":"^0.9.0","standard-version":"^9.0.0",yargs:"12.0.2"},dependencies:{"fast-png":"^6.1.0","jpeg-js":"^0.4.3"}};const h={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,INT:5124,UNSIGNED_INT:5125,FLOAT:5126};function l(e,t,s){let i=new glMatrix.ARRAY_TYPE(s);for(let r=0;r<s;++r)i[r]=e[t+r];return i}function c(e,t,s){for(const i of Object.keys(e)){const r=e[i];if(null!=r&&"string"!=typeof a_string&&(void 0!==r.initGl&&r.initGl(t,s),Array.isArray(r)))for(const e of r)null!=e&&void 0!==e.initGl&&e.initGl(t,s)}}function u(e,t){if(void 0===e)return[];const s=[];for(const i of e)s.push(f(i,t));return s}function f(e,t){const s=new t;return s.fromJson(e),s}function d(e,t,s=[]){for(let i of Object.keys(e))if((!s||void 0===s.find((function(e){return e==i})))&&void 0!==t[i]){e[i.replace("^@","")]=t[i]}}function m(e,t,s){return Math.min(Math.max(e,t),s)}function p(e){return"glb"==function(e){const t=e.toLowerCase().split(".");if(1==t.length)return;return t[t.length-1]}(e)}function g(e){return e.substring(0,e.lastIndexOf("/")+1)}class y{constructor(){this.extensions=void 0,this.extras=void 0}fromJson(e){d(this,e)}initGl(e,t){c(this,e,t)}}class b extends y{constructor(){super(),this.bufferView=void 0,this.byteOffset=0,this.componentType=void 0,this.normalized=!1,this.count=void 0,this.type=void 0,this.max=void 0,this.min=void 0,this.sparse=void 0,this.name=void 0,this.glBuffer=void 0,this.typedView=void 0,this.filteredView=void 0,this.normalizedFilteredView=void 0,this.normalizedTypedView=void 0}getTypedView(e){if(void 0!==this.typedView)return this.typedView;if(void 0!==this.bufferView){const t=e.bufferViews[this.bufferView],s=e.buffers[t.buffer],i=this.byteOffset+t.byteOffset,r=this.getComponentSize(this.componentType);let n=this.getComponentCount(this.type),o=0;switch(0!==t.byteStride?0!==r?o=t.byteStride/r*(this.count-1)+n:console.warn("Invalid component type in accessor '"+(this.name?this.name:"")+"'"):o=this.count*n,o*r>s.buffer.byteLength-i&&(o=(s.buffer.byteLength-i)/r,console.warn("Count in accessor '"+(this.name?this.name:"")+"' is too large.")),this.componentType){case h.BYTE:this.typedView=new Int8Array(s.buffer,i,o);break;case h.UNSIGNED_BYTE:this.typedView=new Uint8Array(s.buffer,i,o);break;case h.SHORT:this.typedView=new Int16Array(s.buffer,i,o);break;case h.UNSIGNED_SHORT:this.typedView=new Uint16Array(s.buffer,i,o);break;case h.UNSIGNED_INT:this.typedView=new Uint32Array(s.buffer,i,o);break;case h.FLOAT:this.typedView=new Float32Array(s.buffer,i,o)}}return void 0===this.typedView?console.warn("Failed to convert buffer view to typed view!: "+this.bufferView):void 0!==this.sparse&&this.applySparse(e,this.typedView),this.typedView}getNormalizedTypedView(e){if(void 0!==this.normalizedTypedView)return this.normalizedTypedView;const t=this.getTypedView(e);return this.normalizedTypedView=this.normalized?b.dequantize(t,this.componentType):t,this.normalizedTypedView}getDeinterlacedView(e){if(void 0!==this.filteredView)return this.filteredView;if(void 0!==this.bufferView){const t=e.bufferViews[this.bufferView],s=e.buffers[t.buffer],i=this.byteOffset+t.byteOffset,r=this.getComponentSize(this.componentType),n=this.getComponentCount(this.type),o=this.count*n;let a=0!==t.byteStride?t.byteStride:n*r;const l=s.buffer.byteLength-i;let c=new DataView(s.buffer,i,Math.min(l,this.count*a)),u=c.getFloat32.bind(c);switch(this.componentType){case h.BYTE:this.filteredView=new Int8Array(o),u=c.getInt8.bind(c);break;case h.UNSIGNED_BYTE:this.filteredView=new Uint8Array(o),u=c.getUint8.bind(c);break;case h.SHORT:this.filteredView=new Int16Array(o),u=c.getInt16.bind(c);break;case h.UNSIGNED_SHORT:this.filteredView=new Uint16Array(o),u=c.getUint16.bind(c);break;case h.UNSIGNED_INT:this.filteredView=new Uint32Array(o),u=c.getUint32.bind(c);break;case h.FLOAT:this.filteredView=new Float32Array(o),u=c.getFloat32.bind(c)}for(let e=0;e<o;++e){let t=Math.floor(e/n)*a+e%n*r;this.filteredView[e]=u(t,!0)}}return void 0===this.filteredView?console.warn("Failed to convert buffer view to filtered view!: "+this.bufferView):void 0!==this.sparse&&this.applySparse(e,this.filteredView),this.filteredView}getNormalizedDeinterlacedView(e){if(void 0!==this.normalizedFilteredView)return this.normalizedFilteredView;const t=this.getDeinterlacedView(e);return this.normalizedFilteredView=this.normalized?b.dequantize(t,this.componentType):t,this.normalizedFilteredView}applySparse(e,t){const s=e.bufferViews[this.sparse.indices.bufferView],i=e.buffers[s.buffer],r=this.sparse.indices.byteOffset+s.byteOffset,n=this.getComponentSize(this.sparse.indices.componentType);let o=1;0!==s.byteStride&&(o=s.byteStride/n);const a=this.sparse.count*o;let l;switch(this.sparse.indices.componentType){case h.UNSIGNED_BYTE:l=new Uint8Array(i.buffer,r,a);break;case h.UNSIGNED_SHORT:l=new Uint16Array(i.buffer,r,a);break;case h.UNSIGNED_INT:l=new Uint32Array(i.buffer,r,a)}const c=e.bufferViews[this.sparse.values.bufferView],u=e.buffers[c.buffer],f=this.sparse.values.byteOffset+c.byteOffset,d=this.getComponentSize(this.componentType);let m=this.getComponentCount(this.type);0!==c.byteStride&&(m=c.byteStride/d);const p=this.sparse.count*m;let g;switch(this.componentType){case h.BYTE:g=new Int8Array(u.buffer,f,p);break;case h.UNSIGNED_BYTE:g=new Uint8Array(u.buffer,f,p);break;case h.SHORT:g=new Int16Array(u.buffer,f,p);break;case h.UNSIGNED_SHORT:g=new Uint16Array(u.buffer,f,p);break;case h.UNSIGNED_INT:g=new Uint32Array(u.buffer,f,p);break;case h.FLOAT:g=new Float32Array(u.buffer,f,p)}for(let e=0;e<this.sparse.count;++e)for(let s=0;s<m;++s)t[l[e]*m+s]=g[e*m+s]}static dequantize(e,t){switch(t){case h.BYTE:return new Float32Array(e).map(e=>Math.max(e/127,-1));case h.UNSIGNED_BYTE:return new Float32Array(e).map(e=>e/255);case h.SHORT:return new Float32Array(e).map(e=>Math.max(e/32767,-1));case h.UNSIGNED_SHORT:return new Float32Array(e).map(e=>e/65535);default:return e}}getComponentCount(e){return v.get(e)}getComponentSize(e){switch(e){case h.BYTE:case h.UNSIGNED_BYTE:return 1;case h.SHORT:case h.UNSIGNED_SHORT:return 2;case h.UNSIGNED_INT:case h.FLOAT:return 4;default:return 0}}destroy(){void 0!==this.glBuffer&&WebGl.context.deleteBuffer(this.glBuffer),this.glBuffer=void 0}}const v=new Map([["SCALAR",1],["VEC2",2],["VEC3",3],["VEC4",4],["MAT2",4],["MAT3",9],["MAT4",16]]);class T extends y{constructor(){super(),this.uri=void 0,this.byteLength=void 0,this.name=void 0,this.buffer=void 0}load(e,t){if(void 0!==this.buffer)return void console.error("buffer has already been loaded");const s=this;return new Promise((function(i){s.setBufferFromFiles(t,i)||s.setBufferFromUri(e,i)||(console.error("Was not able to resolve buffer with uri '%s'",s.uri),i())}))}setBufferFromUri(e,s){if(void 0===this.uri)return!1;const i=this;return this.uri.startsWith("data:application")?t.resourceLoader.loadFile("binary",this.uri).then((function(e){i.buffer=e,s()})):t.resourceLoader.loadFile("binary",g(e.path)+this.uri).then((function(e){i.buffer=e,s()})),!0}setBufferFromFiles(e,t){if(void 0===this.uri||void 0===e)return!1;const s=e.find((function(e){if(e.name===this.uri||e.fullPath===this.uri)return!0}),this);if(void 0===s)return!1;const i=this,r=new FileReader;return r.onloadend=function(e){i.buffer=e.target.result,t()},r.readAsArrayBuffer(s),!0}}class w extends y{constructor(){super(),this.buffer=void 0,this.byteOffset=0,this.byteLength=void 0,this.byteStride=0,this.target=void 0,this.name=void 0}}class A extends y{constructor(e="perspective",t=.01,s=1/0,i=45*Math.PI/180,r,n=1,o=1,a,h){super(),this.type=e,this.znear=t,this.zfar=s,this.yfov=i,this.xmag=n,this.ymag=o,this.aspectRatio=r,this.name=a,this.node=h}initGl(e,t){super.initGl(e,t);let s=void 0;for(let t=0;t<e.nodes.length;t++)if(s=e.nodes[t].camera,void 0!==s&&e.cameras[s]===this){this.node=t;break}void 0===this.node&&void 0!==s&&console.error("Invalid node for camera "+s)}fromJson(e){this.name=name,void 0!==e.perspective?(this.type="perspective",d(this,e.perspective)):void 0!==e.orthographic&&(this.type="orthographic",d(this,e.orthographic))}sortPrimitivesByDepth(e,t){for(const s of t){const t=mat4.create();mat4.multiply(t,this.getViewMatrix(e),s.node.worldTransform);const i=vec3.transformMat4(vec3.create(),vec3.clone(s.primitive.centroid),t);s.depth=i[2]}return t.filter(e=>e.depth<=0).sort((e,t)=>e.depth-t.depth)}getProjectionMatrix(){const e=mat4.create();return"perspective"===this.type?mat4.perspective(e,this.yfov,this.aspectRatio,this.znear,this.zfar):"orthographic"===this.type&&(e[0]=1/this.xmag,e[5]=1/this.ymag,e[10]=2/(this.znear-this.zfar),e[14]=(this.zfar+this.znear)/(this.znear-this.zfar)),e}getViewMatrix(e){const t=mat4.create(),s=this.getPosition(e),i=this.getTarget(e);return mat4.lookAt(t,s,i,vec3.fromValues(0,1,0)),t}getTarget(e){const t=vec3.create(),s=this.getPosition(e),i=this.getLookDirection(e);return vec3.add(t,i,s),t}getPosition(e){const t=vec3.create(),s=this.getNode(e);return mat4.getTranslation(t,s.worldTransform),t}getLookDirection(e){const t=vec3.create(),s=this.getRotation(e);return vec3.transformQuat(t,vec3.fromValues(0,0,-1),s),t}getRotation(e){const t=quat.create(),s=this.getNode(e);return mat4.getRotation(t,s.worldTransform),t}clone(){return new A(this.type,this.znear,this.zfar,this.yfov,this.aspectRatio,this.xmag,this.ymag,this.name,this.node)}getNode(e){return e.nodes[this.node]}getTransformMatrix(e){const t=this.getNode(e);return void 0!==t&&void 0!==t.worldTransform?t.worldTransform:mat4.create()}getDescription(e){const t={type:this.type};void 0!==this.name&&(t.name=this.name),"perspective"===this.type?(t.perspective={},void 0!==this.aspectRatio&&(t.perspective.aspectRatio=this.aspectRatio),t.perspective.yfov=this.yfov,this.zfar!=1/0&&(t.perspective.zfar=this.zfar),t.perspective.znear=this.znear):"orthographic"===this.type&&(t.orthographic={},t.orthographic.xmag=this.xmag,t.orthographic.ymag=this.ymag,t.orthographic.zfar=this.zfar,t.orthographic.znear=this.znear);const s=this.getTransformMatrix(e),i={camera:0,matrix:[s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9],s[10],s[11],s[12],s[13],s[14],s[15]]};return void 0!==this.nodeIndex&&void 0!==e.nodes[this.nodeIndex].name&&(i.name=e.nodes[this.nodeIndex].name),{asset:{generator:"gltf-sample-viewer",version:"2.0"},cameras:[t],nodes:[i]}}}class x{static async readAsArrayBuffer(e){return new Promise((t,s)=>{const i=new FileReader;i.onload=()=>t(i.result),i.onerror=s,i.readAsArrayBuffer(e)})}static async readAsText(e){return new Promise((t,s)=>{const i=new FileReader;i.onload=()=>t(i.result),i.onerror=s,i.readAsText(e)})}static async readAsDataURL(e){return new Promise((t,s)=>{const i=new FileReader;i.onload=()=>t(i.result),i.onerror=s,i.readAsDataURL(e)})}}const _="image/jpeg",I="image/png",R="image/ktx2",E="image/texture";class S extends y{constructor(e,t=h.TEXTURE_2D,s=0,i,r,n=_,o){super(),this.uri=e,this.bufferView=i,this.mimeType=n,this.image=o,this.name=r,this.type=t,this.miplevel=s}fromJson(e){super.fromJson(e)}resolveRelativePath(e){("string"==typeof this.uri||this.uri instanceof String)&&(this.uri.startsWith("./")&&(this.uri=this.uri.substr(2)),this.uri=e+this.uri)}async load(e,t){void 0===this.image?await this.setImageFromBufferView(e)||await this.setImageFromFiles(t,e)||await this.setImageFromUri(e)||console.error("Was not able to resolve image with uri '%s'",this.uri):this.mimeType!==E&&console.error("image has already been loaded")}static loadHTMLImage(e){return new Promise((s,i)=>{const r=new t.FileImage(this.name);r.load(e).then(()=>{s(r)},()=>{i()})})}async setImageFromUri(e){return void 0!==this.uri&&("undefined"==typeof Image||this.mimeType!==_&&this.mimeType!==I?(console.error("Unsupported image type "+this.mimeType),!1):(this.zeaImage=await S.loadHTMLImage(this.uri).catch(e=>{console.error(e)}),!0))}async setImageFromBufferView(e){const t=e.bufferViews[this.bufferView];if(void 0===t)return!1;const s=e.buffers[t.buffer].buffer,i=new Uint8Array(s,t.byteOffset,t.byteLength);if(this.mimeType===R)void 0!==e.ktxDecoder?this.image=await e.ktxDecoder.loadKtxFromBuffer(i):console.warn("Loading of ktx images failed: KtxDecoder not initalized");else if("undefined"==typeof Image||this.mimeType!==_&&this.mimeType!==I)if(this.mimeType===_)this.image=n.decode(i,{useTArray:!0});else{if(this.mimeType!==I)return console.error("Unsupported image type "+this.mimeType),!1;this.image=o.decode(i)}else{const e=new Blob([i],{type:this.mimeType}),t=URL.createObjectURL(e);this.image=await S.loadHTMLImage(t).catch(()=>{console.error("Could not load image from buffer view")})}return!0}async setImageFromFiles(e,t){if(void 0===this.uri||void 0===e)return!1;let s=e.find((function(e){const t=this.uri.split("\\").pop().split("/").pop();if(e.name===t)return!0}),this);if(void 0===s)return!1;if(this.mimeType===R)if(void 0!==t.ktxDecoder){const e=new Uint8Array(await s.arrayBuffer());this.image=await t.ktxDecoder.loadKtxFromBuffer(e)}else console.warn("Loading of ktx images failed: KtxDecoder not initalized");else{if("undefined"==typeof Image||this.mimeType!==_&&this.mimeType!==I)return console.error("Unsupported image type "+this.mimeType),!1;{const e=await x.readAsDataURL(s).catch(()=>{console.error("Could not load image with FileReader")});this.image=await S.loadHTMLImage(e).catch(()=>{console.error("Could not create image from FileReader image data")})}}return!0}}class M extends y{constructor(e="directional",t=[1,1,1],s=1,i=0,r=Math.PI/4,n=-1,o,a){super(),this.type=e,this.color=t,this.intensity=s,this.innerConeAngle=i,this.outerConeAngle=r,this.range=n,this.name=o,this.node=a,this.direction=void 0}initGl(e,t){super.initGl(e,t);for(let t=0;t<e.nodes.length;t++){const s=e.nodes[t].extensions;if(void 0===s)continue;const i=s.KHR_lights_punctual;if(void 0===i)continue;const r=i.light;if(e.lights[r]===this){this.node=t;break}}}fromJson(e){super.fromJson(e),void 0!==e.spot&&d(this,e.spot)}toUniform(e){const t=new B;if(void 0!==this.node){const n=e.nodes[this.node].worldTransform;var s=vec3.fromValues(1,1,1);mat4.getScaling(s,n);const o=mat4.create();for(const e of[0,1,2])o[e]=n[e]/s[0],o[e+4]=n[e+4]/s[1],o[e+8]=n[e+8]/s[2];var i=quat.create();mat4.getRotation(i,o),quat.normalize(i,i);const a=vec3.fromValues(0,0,-1);vec3.transformQuat(t.direction,a,i);var r=vec3.fromValues(0,0,0);mat4.getTranslation(r,n),t.position=r}switch(void 0!==this.direction&&(t.direction=this.direction),t.range=this.range,t.color=this.color,t.intensity=this.intensity,t.innerConeCos=Math.cos(this.innerConeAngle),t.outerConeCos=Math.cos(this.outerConeAngle),this.type){case"spot":t.type=N;break;case"point":t.type=O;break;case"directional":default:t.type=G}return t}}const G=0,O=1,N=2;class B extends class{}{constructor(){super();const e=vec3.fromValues(-.7399,-.6428,-.1983);this.direction=e,this.range=-1,this.color=[1,1,1],this.intensity=1,this.position=[0,0,0],this.innerConeCos=0,this.outerConeCos=Math.PI/4,this.type=G,this.padding1=0,this.padding2=0}}class C extends y{constructor(){super(),this.rotation=[0,0,0,1],this.brightnessFactor=1,this.brightnessOffset=0,this.specularEnvironmentTexture=void 0,this.diffuseEnvironmentTexture=void 0,this.sheenEnvironmentTexture=void 0,this.levelCount=1}fromJson(e){super.fromJson(e),void 0!==e.extensions&&this.fromJsonExtensions(e.extensions)}fromJsonExtensions(e){void 0!==e.KHR_materials_sheen&&(this.sheenEnvironmentTexture=e.KHR_materials_sheen.sheenEnvironmentTexture)}initGl(e,t){if(void 0!==this.diffuseEnvironmentTexture){e.textures[this.diffuseEnvironmentTexture].type=h.TEXTURE_CUBE_MAP}if(void 0!==this.specularEnvironmentTexture){const t=e.textures[this.specularEnvironmentTexture];t.type=h.TEXTURE_CUBE_MAP;const s=e.images[t.source];this.levelCount=s.image.levelCount}if(void 0!==this.sheenEnvironmentTexture){const t=e.textures[this.sheenEnvironmentTexture];t.type=h.TEXTURE_CUBE_MAP;const s=e.images[t.source];this.levelCount!==s.image.levelCount&&console.error("Specular and sheen do not have same level count")}}}class F extends y{constructor(e,t,s=h.TEXTURE_2D){super(),this.sampler=e,this.source=t,this.glTexture=void 0,this.type=s,this.initialized=!1,this.mipLevelCount=0}initGl(e,t){void 0===this.sampler&&(this.sampler=e.samplers.length-1),c(this,e,t)}fromJson(e){super.fromJson(e),void 0!==e.extensions&&void 0!==e.extensions.KHR_texture_basisu&&void 0!==e.extensions.KHR_texture_basisu.source&&(this.source=e.extensions.KHR_texture_basisu.source)}destroy(){}}class L{constructor(e,t=0,s=!0,i="",r=!0){this.index=e,this.texCoord=t,this.linear=s,this.samplerName=i,this.strength=1,this.scale=1,this.generateMips=r,this.extensions=void 0}initGl(e,t){c(this,e,t)}fromJson(e){d(this,e)}}class V extends y{constructor(){super(),this.name=void 0,this.pbrMetallicRoughness=void 0,this.normalTexture=void 0,this.occlusionTexture=void 0,this.emissiveTexture=void 0,this.emissiveFactor=[0,0,0],this.alphaMode="OPAQUE",this.alphaCutoff=.5,this.doubleSided=!1,this.hasClearcoat=!1,this.hasSheen=!1,this.hasTransmission=!1,this.hasIOR=!1,this.hasVolume=!1,this.type="unlit",this.textures=[],this.properties=new Map,this.defines=[]}static createDefault(){const e=new V;e.type="MR",e.name="Default Material",e.defines.push("MATERIAL_METALLICROUGHNESS 1");const s=new t.Vec4(1,1,1,1);return e.properties.set("u_BaseColorFactor",s),e.properties.set("u_MetallicFactor",1),e.properties.set("u_RoughnessFactor",1),e}getShaderIdentifier(){switch(this.type){default:case"SG":case"MR":return"pbr.frag"}}getDefines(e){const t=Array.from(this.defines);return this.hasClearcoat&&e.enabledExtensions.KHR_materials_clearcoat&&t.push("MATERIAL_CLEARCOAT 1"),this.hasSheen&&e.enabledExtensions.KHR_materials_sheen&&t.push("MATERIAL_SHEEN 1"),this.hasTransmission&&e.enabledExtensions.KHR_materials_transmission&&t.push("MATERIAL_TRANSMISSION 1"),this.hasVolume&&e.enabledExtensions.KHR_materials_volume&&t.push("MATERIAL_VOLUME 1"),this.hasIOR&&e.enabledExtensions.KHR_materials_ior&&t.push("MATERIAL_IOR 1"),this.hasSpecular&&e.enabledExtensions.KHR_materials_specular&&t.push("MATERIAL_SPECULAR 1"),t}getProperties(){return this.properties}getTextures(){return this.textures}parseTextureInfoExtensions(e,s){if(void 0!==e.extensions&&void 0!==e.extensions.KHR_texture_transform){const i=e.extensions.KHR_texture_transform;void 0!==i.texCoord&&(e.texCoord=i.texCoord);let r=new t.Mat3,n=new t.Mat3,o=new t.Mat3;if(void 0!==i.rotation){const e=Math.sin(i.rotation),s=Math.cos(i.rotation);r=new t.Mat3([s,e,0,-e,s,0,0,0,1])}void 0!==i.scale&&(n=new t.Mat3([i.scale[0],0,0,0,i.scale[1],0,0,0,1])),void 0!==i.offset&&(o=new t.Mat3([1,0,i.offset[0],0,1,i.offset[1],0,0,1]));const a=r.multiply(n);a.multiplyInPlace(o),this.defines.push("HAS_"+s.toUpperCase()+"_UV_TRANSFORM 1"),this.properties.set("u_"+s+"UVTransform",a)}}initGl(e,s){this.zeaMaterial=new t.Material(this.name,"StandardSurfaceShader");const i=(t,s)=>{const i=e.textures[t.index],r=e.samplers[i.sampler],n=e.images[i.source];n.zeaImage.wrapS=r.wrapS,n.zeaImage.wrapT=r.wrapT,s.setImage(n.zeaImage)};if(void 0!==this.normalTexture&&i(this.normalTexture,this.zeaMaterial.getParameter("Normal")),void 0!==this.occlusionTexture&&i(this.occlusionTexture,this.zeaMaterial.getParameter("AmbientOcclusion")),this.properties.set("u_EmissiveFactor",this.emissiveFactor),void 0!==this.emissiveTexture&&i(this.emissiveTexture,this.zeaMaterial.getParameter("EmissiveStrength")),void 0!==this.baseColorTexture&&i(this.baseColorTexture,this.zeaMaterial.getParameter("BaseColor")),void 0!==this.metallicRoughnessTexture&&i(this.metallicRoughnessTexture,this.zeaMaterial.getParameter("Metallic")),void 0!==this.diffuseTexture&&i(this.diffuseTexture,this.zeaMaterial.getParameter("BaseColor")),void 0!==this.specularGlossinessTexture&&i(this.specularGlossinessTexture,this.zeaMaterial.getParameter("Reflectance")),"MASK"===this.alphaMode?(this.defines.push("ALPHAMODE_MASK 1"),this.properties.set("u_AlphaCutoff",this.alphaCutoff)):"OPAQUE"===this.alphaMode&&this.defines.push("ALPHAMODE_OPAQUE 1"),void 0!==this.pbrMetallicRoughness&&"SG"!==this.type){this.defines.push("MATERIAL_METALLICROUGHNESS 1");let e=new t.Color(1,1,1,1),s=1,i=1;void 0!==this.pbrMetallicRoughness.baseColorFactor&&e.set(...this.pbrMetallicRoughness.baseColorFactor),void 0!==this.pbrMetallicRoughness.metallicFactor&&(s=this.pbrMetallicRoughness.metallicFactor),void 0!==this.pbrMetallicRoughness.roughnessFactor&&(i=this.pbrMetallicRoughness.roughnessFactor),this.properties.set("u_BaseColorFactor",e),this.properties.set("u_MetallicFactor",s),this.properties.set("u_RoughnessFactor",i),this.zeaMaterial.getParameter("BaseColor").setValue(e),this.zeaMaterial.getParameter("Metallic").setValue(s),this.zeaMaterial.getParameter("Roughness").setValue(i)}if(void 0!==this.extensions&&(void 0!==this.extensions.KHR_materials_unlit&&this.defines.push("MATERIAL_UNLIT 1"),void 0!==this.extensions.KHR_materials_pbrSpecularGlossiness)){this.defines.push("MATERIAL_SPECULARGLOSSINESS 1");let e=new t.Color(1,1,1,1),s=new t.Vec3(1,1,1),i=1;void 0!==this.extensions.KHR_materials_pbrSpecularGlossiness.diffuseFactor&&(e=this.extensions.KHR_materials_pbrSpecularGlossiness.diffuseFactor),void 0!==this.extensions.KHR_materials_pbrSpecularGlossiness.specularFactor&&(s=this.extensions.KHR_materials_pbrSpecularGlossiness.specularFactor),void 0!==this.extensions.KHR_materials_pbrSpecularGlossiness.glossinessFactor&&(i=this.extensions.KHR_materials_pbrSpecularGlossiness.glossinessFactor),this.properties.set("u_DiffuseFactor",e),this.properties.set("u_SpecularFactor",s),this.properties.set("u_GlossinessFactor",i)}c(this,e,s)}fromJson(e){if(super.fromJson(e),void 0!==e.emissiveFactor&&(this.emissiveFactor=e.emissiveFactor),void 0!==e.normalTexture){const t=new L;t.fromJson(e.normalTexture),this.normalTexture=t}if(void 0!==e.occlusionTexture){const t=new L;t.fromJson(e.occlusionTexture),this.occlusionTexture=t}if(void 0!==e.emissiveTexture){const t=new L(void 0,0,!1);t.fromJson(e.emissiveTexture),this.emissiveTexture=t}void 0!==e.extensions&&this.fromJsonMaterialExtensions(e.extensions),void 0!==e.pbrMetallicRoughness&&"SG"!==this.type&&(this.type="MR",this.fromJsonMetallicRoughness(e.pbrMetallicRoughness))}fromJsonMaterialExtensions(e){void 0!==e.KHR_materials_pbrSpecularGlossiness&&(this.type="SG",this.fromJsonSpecularGlossiness(e.KHR_materials_pbrSpecularGlossiness)),void 0!==e.KHR_materials_unlit&&(this.type="unlit"),void 0!==e.KHR_materials_clearcoat&&this.fromJsonClearcoat(e.KHR_materials_clearcoat),void 0!==e.KHR_materials_sheen&&this.fromJsonSheen(e.KHR_materials_sheen),void 0!==e.KHR_materials_transmission&&this.fromJsonTransmission(e.KHR_materials_transmission),void 0!==e.KHR_materials_specular&&this.fromJsonSpecular(e.KHR_materials_specular),void 0!==e.KHR_materials_volume&&this.fromJsonVolume(e.KHR_materials_volume)}fromJsonMetallicRoughness(e){if(void 0!==e.baseColorTexture){const t=new L(void 0,0,!1);t.fromJson(e.baseColorTexture),this.baseColorTexture=t}if(void 0!==e.metallicRoughnessTexture){const t=new L;t.fromJson(e.metallicRoughnessTexture),this.metallicRoughnessTexture=t}}fromJsonSpecularGlossiness(e){if(void 0!==e.diffuseTexture){const t=new L(void 0,0,!1);t.fromJson(e.diffuseTexture),this.diffuseTexture=t}if(void 0!==e.specularGlossinessTexture){const t=new L(void 0,0,!1);t.fromJson(e.specularGlossinessTexture),this.specularGlossinessTexture=t}}fromJsonClearcoat(e){if(void 0!==e.clearcoatTexture){const t=new L;t.fromJson(e.clearcoatTexture),this.clearcoatTexture=t}if(void 0!==e.clearcoatRoughnessTexture){const t=new L;t.fromJson(e.clearcoatRoughnessTexture),this.clearcoatRoughnessTexture=t}if(void 0!==e.clearcoatNormalTexture){const t=new L;t.fromJson(e.clearcoatNormalTexture),this.clearcoatNormalTexture=t}}fromJsonSheen(e){if(void 0!==e.sheenColorTexture){const t=new L(void 0,0,!1);t.fromJson(e.sheenColorTexture),this.sheenColorTexture=t}if(void 0!==e.sheenRoughnessTexture){const t=new L;t.fromJson(e.sheenRoughnessTexture),this.sheenRoughnessTexture=t}}fromJsonTransmission(e){if(void 0!==e.transmissionTexture){const t=new L;t.fromJson(e.transmissionTexture),this.transmissionTexture=t}}fromJsonSpecular(e){if(void 0!==e.specularTexture){const t=new L;t.fromJson(e.specularTexture),this.specularTexture=t}if(void 0!==e.specularTexture){const t=new L;t.fromJson(e.specularTexture),this.specularTexture=t}}fromJsonVolume(e){if(void 0!==e.thicknessTexture){const t=new L;t.fromJson(e.thicknessTexture),this.thicknessTexture=t}}}class U{constructor(e){if(!U.instance&&void 0===e){if(void 0===DracoDecoderModule)return void console.error("Failed to initalize DracoDecoder: draco library undefined");e=DracoDecoderModule}return U.instance||(U.instance=this,this.module=null,this.initializingPromise=new Promise(t=>{let s={};s.onModuleLoaded=e=>{this.module=e,t()},e(s)})),U.instance}async ready(){await this.initializingPromise,Object.freeze(U.instance)}}class D extends y{constructor(){super(),this.attributes=[],this.targets=[],this.indices=void 0,this.material=void 0,this.mode="TRIANGLES",this.glAttributes=[],this.defines=[],this.skip=!0,this.hasWeights=!1,this.hasJoints=!1,this.hasNormals=!1,this.hasTangents=!1,this.hasTexcoord=!1,this.hasColor=!1,this.centroid=void 0}initGl(e,s){if(void 0===this.material&&(this.material=e.materials.length-1),void 0!==this.extensions&&void 0!==this.extensions.KHR_draco_mesh_compression){const t=new U;if(void 0!==t&&Object.isFrozen(t)){let t=this.decodeDracoBufferToIntermediate(this.extensions.KHR_draco_mesh_compression,e);this.copyDataFromDecodedGeometry(e,t,this.attributes)}else console.warn("Failed to load draco compressed mesh: DracoDecoder not initialized")}for(const t of Object.keys(this.attributes)){const s=this.attributes[t];switch(t){case"POSITION":this.skip=!1,this.glAttributes.push({attribute:t,name:"a_Position",accessor:s});break;case"NORMAL":this.hasNormals=!0,this.defines.push("HAS_NORMALS 1"),this.glAttributes.push({attribute:t,name:"a_Normal",accessor:s});break;case"TANGENT":this.hasTangents=!0,this.defines.push("HAS_TANGENTS 1"),this.glAttributes.push({attribute:t,name:"a_Tangent",accessor:s});break;case"TEXCOORD_0":this.hasTexcoord=!0,this.defines.push("HAS_UV_SET1 1"),this.glAttributes.push({attribute:t,name:"a_UV1",accessor:s});break;case"TEXCOORD_1":this.hasTexcoord=!0,this.defines.push("HAS_UV_SET2 1"),this.glAttributes.push({attribute:t,name:"a_UV2",accessor:s});break;case"COLOR_0":this.hasColor=!0;const i=e.accessors[s];this.defines.push("HAS_VERTEX_COLOR_"+i.type+" 1"),this.glAttributes.push({attribute:t,name:"a_Color",accessor:s});break;case"JOINTS_0":this.hasJoints=!0,this.defines.push("HAS_JOINT_SET1 1"),this.glAttributes.push({attribute:t,name:"a_Joint1",accessor:s});break;case"WEIGHTS_0":this.hasWeights=!0,this.defines.push("HAS_WEIGHT_SET1 1"),this.glAttributes.push({attribute:t,name:"a_Weight1",accessor:s});break;case"JOINTS_1":this.hasJoints=!0,this.defines.push("HAS_JOINT_SET2 1"),this.glAttributes.push({attribute:t,name:"a_Joint2",accessor:s});break;case"WEIGHTS_1":this.hasWeights=!0,this.defines.push("HAS_WEIGHT_SET2 1"),this.glAttributes.push({attribute:t,name:"a_Weight2",accessor:s});break;default:console.log("Unknown attribute: "+t)}}const i=e.materials[this.material];let r=i.zeaMaterial;const n=e.accessors[this.attributes.POSITION],o={geomBuffers:{numVertices:n.count,attrBuffers:{}},bbox:new t.Box3(new t.Vec3(...n.min),new t.Vec3(...n.max))};if(void 0!==this.indices){const t=e.accessors[this.indices].getTypedView(e);o.geomBuffers.indices=t}for(const s of Object.keys(this.attributes)){const i=this.attributes[s],n=e.accessors[i],a=e.bufferViews[n.bufferView],h=n.getComponentSize(n.componentType),l=n.getComponentCount(n.type);let c;switch(c=0==a.byteStride||a.byteStride==h*l?n.getTypedView(e):n.getDeinterlacedView(e),s){case"POSITION":o.geomBuffers.attrBuffers.positions={dataType:"Vec3",normalized:!1,values:c};break;case"NORMAL":o.geomBuffers.attrBuffers.normals={dataType:"Vec3",normalized:!0,values:c};break;case"TEXCOORD_0":o.geomBuffers.attrBuffers.texCoords={dataType:"Vec2",normalized:!1,values:c};break;case"COLOR_0":let s=!0;for(let e=1;e<c.length/l;e++)for(let t=0;t<l;t++)c[t]!=c[e*l+t]&&(s=!1);if(s){const s=`Material [R=${c[0]}, G=${c[1]}, B=${c[2]}]`;if(e.materialsMap[s])r=e.materialsMap[s];else{const i=new t.Color;1==h?i.set(c[0]/256,c[1]/256,c[2]/256,4==l?c[3]/256:1):4==h&&i.set(c[0],c[1],c[2],4==l?c[3]:1),r=r.clone(),r.getParameter("BaseColor").setValue(i),e.materialsMap[s]=r}}else o.geomBuffers.attrBuffers.vertexColors={dataType:"Color",normalized:!1,values:c}}}let a;switch(this.mode){case"POINTS":case 0:{o.name="GLTFPoints",a=new t.PointsProxy(o);const s=r.getParameter("BaseColor").getValue(),i=`PointsMaterial [${s.r.toFixed(2)}, ${s.g.toFixed(2)}, ${s.b.toFixed(2)}]`;e.materialsMap[i]?r=e.materialsMap[i]:(r=r.clone(),r.setShaderName("PointsShader"),e.materialsMap[i]=r);break}case"LINES":case 1:{o.name="GLTFLines",a=new t.LinesProxy(o);const s=r.getParameter("BaseColor").getValue(),i=`LinesMaterial [R=${s.r.toFixed(2)}, G=${s.g.toFixed(2)}, B=${s.b.toFixed(2)}]`;e.materialsMap[i]?r=e.materialsMap[i]:(r=r.clone(),r.setShaderName("LinesShader"),e.materialsMap[i]=r);break}case"LINE_LOOP":case 2:{if(o.name="GLTFLineLoop",null==o.geomBuffers.indices){const e=new Uint32Array(2*o.geomBuffers.numVertices);for(let t=0;t<o.geomBuffers.numVertices;t++)e[2*t]=t,e[2*t+1]=(t+1)%e.length;o.geomBuffers.indices=e}else{const e=o.geomBuffers.indices,t=new Uint32Array(2*e.length);t[0]=e[0],t[1]=e[1];let s=1;for(let i=2;i<=e.length;i++)t[2*s]=e[i-1],t[2*s+1]=e[i%e.length],s++;1209==t[0]&&console.log(o.name,o.geomBuffers.indices.toString()),o.geomBuffers.indices=t}a=new t.LinesProxy(o);const s=r.getParameter("BaseColor").getValue(),i=`LinesMaterial [R=${s.r.toFixed(2)}, G=${s.g.toFixed(2)}, B=${s.b.toFixed(2)}]`;e.materialsMap[i]?r=e.materialsMap[i]:(r=r.clone(),r.setShaderName("LinesShader"),e.materialsMap[i]=r);break}case"LINE_STRIP":case 3:{if(o.name="GLTFLineStrip",null==o.geomBuffers.indices){const e=new Uint32Array(2*(o.geomBuffers.numVertices-1));for(let t=0;t<o.geomBuffers.numVertices-1;t++)e[2*t]=t,e[2*t+1]=t+1;o.geomBuffers.indices=e}else{const e=o.geomBuffers.indices,t=new Uint32Array(2*(e.length-1));t[0]=e[0],t[1]=e[1];let s=1;for(let i=2;i<e.length;i++)t[2*s]=e[i-1],t[2*s+1]=e[i],s++;1209==t[0]&&console.log(o.name,o.geomBuffers.indices.toString()),o.geomBuffers.indices=t}a=new t.LinesProxy(o);const s=r.getParameter("BaseColor").getValue(),i=`LinesMaterial [R=${s.r.toFixed(2)}, G=${s.g.toFixed(2)}, B=${s.b.toFixed(2)}]`;e.materialsMap[i]?r=e.materialsMap[i]:(r=r.clone(),r.setShaderName("LinesShader"),e.materialsMap[i]=r);break}case"TRIANGLES":case 4:if(o.name="GLTFMesh",null==o.geomBuffers.indices){const e=new Uint32Array(o.geomBuffers.numVertices);for(let t=0;t<o.geomBuffers.numVertices;t++)e[t]=t;o.geomBuffers.indices=e}a=new t.MeshProxy(o);break;case"TRIANGLE_STRIP":case 5:if(o.name="GLTFMesh",null==o.geomBuffers.indices){const e=new Uint32Array(3*o.geomBuffers.numVertices-2);e[0]=0,e[1]=1,e[2]=2;for(let t=3;t<e.length;t+=3)e[t-2]=e[t-1],e[t-1]=e[t-2],e[t]=t;o.geomBuffers.indices=e}else{const e=o.geomBuffers.indices,t=e.length-2,s=new Uint32Array(3*t);s[0]=e[0],s[1]=e[1],s[2]=e[2];let i=1;for(let t=3;t<e.length;t++)s[3*i]=e[t-2],s[3*i+1]=e[t-1],s[3*i+2]=e[t],i++;o.geomBuffers.indices=s}a=new t.MeshProxy(o);break;case"TRIANGLE_FAN":case 6:if(o.name="GLTFMesh",null==o.geomBuffers.indices){const e=new Uint32Array(3*o.geomBuffers.numVertices-2);e[0]=0,e[1]=1,e[2]=2;for(let t=3;t<e.length;t+=3)e[t-2]=e[0],e[t-1]=e[t-1],e[t]=t;o.geomBuffers.indices=e}else{const e=o.geomBuffers.indices,t=e.length-2,s=new Uint32Array(3*t);s[0]=e[0],s[1]=e[1],s[2]=e[2];let i=1;for(let t=3;t<e.length;t++)s[3*i]=e[0],s[3*i+1]=e[t-1],s[3*i+2]=e[t],i++;o.geomBuffers.indices=s}a=new t.MeshProxy(o)}if(a){if("OPAQUE"==i.alphaMode){const e=r.getParameter("BaseColor").getValue();e.a=1,r.getParameter("BaseColor").setValue(e)}const e=new t.GeomItem(o.name,a,r);s.addChild(e,!1)}}computeCentroid(e,t){const s=e.accessors[this.attributes.POSITION].getTypedView(e);if(void 0!==this.indices){const t=e.accessors[this.indices].getTypedView(e),i=new Float32Array(3);for(let e=0;e<t.length;e++){const r=3*t[e];i[0]+=s[r],i[1]+=s[r+1],i[2]+=s[r+2]}const r=new Float32Array([i[0]/t.length,i[1]/t.length,i[2]/t.length]);this.centroid=r}else{const e=new Float32Array(3);for(let t=0;t<s.length;t+=3)e[0]+=s[t],e[1]+=s[t+1],e[2]+=s[t+2];const t=s.length/3,i=new Float32Array([e[0]/t,e[1]/t,e[2]/t]);this.centroid=i}}getShaderIdentifier(){return"primitive.vert"}getDefines(){return this.defines}fromJson(e){super.fromJson(e),void 0!==e.extensions&&this.fromJsonPrimitiveExtensions(e.extensions)}fromJsonPrimitiveExtensions(e){void 0!==e.KHR_materials_variants&&this.fromJsonVariants(e.KHR_materials_variants)}fromJsonVariants(e){void 0!==e.mappings&&(this.mappings=e.mappings)}copyDataFromDecodedGeometry(e,t,s){let i=t.index.array;if(this.loadBufferIntoGltf(i,e,this.indices,34963,"index buffer view"),void 0!==t.attributes.POSITION){let i=this.loadArrayIntoArrayBuffer(t.attributes.POSITION.array,t.attributes.POSITION.componentType);this.loadBufferIntoGltf(i,e,s.POSITION,34962,"position buffer view")}if(void 0!==t.attributes.NORMAL){let i=this.loadArrayIntoArrayBuffer(t.attributes.NORMAL.array,t.attributes.NORMAL.componentType);this.loadBufferIntoGltf(i,e,s.NORMAL,34962,"normal buffer view")}if(void 0!==t.attributes.TEXCOORD_0){let i=this.loadArrayIntoArrayBuffer(t.attributes.TEXCOORD_0.array,t.attributes.TEXCOORD_0.componentType);this.loadBufferIntoGltf(i,e,s.TEXCOORD_0,34962,"TEXCOORD_0 buffer view")}if(void 0!==t.attributes.TEXCOORD_1){let i=this.loadArrayIntoArrayBuffer(t.attributes.TEXCOORD_1.array,t.attributes.TEXCOORD_1.componentType);this.loadBufferIntoGltf(i,e,s.TEXCOORD_1,34962,"TEXCOORD_1 buffer view")}if(void 0!==t.attributes.TANGENT){let i=this.loadArrayIntoArrayBuffer(t.attributes.TANGENT.array,t.attributes.TANGENT.componentType);this.loadBufferIntoGltf(i,e,s.TANGENT,34962,"Tangent buffer view")}if(void 0!==t.attributes.COLOR_0){let i=this.loadArrayIntoArrayBuffer(t.attributes.COLOR_0.array,t.attributes.COLOR_0.componentType);this.loadBufferIntoGltf(i,e,s.COLOR_0,34962,"color buffer view")}if(void 0!==t.attributes.JOINTS_0){let i=this.loadArrayIntoArrayBuffer(t.attributes.JOINTS_0.array,t.attributes.JOINTS_0.componentType);this.loadBufferIntoGltf(i,e,s.JOINTS_0,34963,"JOINTS_0 buffer view")}if(void 0!==t.attributes.WEIGHTS_0){let i=this.loadArrayIntoArrayBuffer(t.attributes.WEIGHTS_0.array,t.attributes.WEIGHTS_0.componentType);this.loadBufferIntoGltf(i,e,s.WEIGHTS_0,34963,"WEIGHTS_0 buffer view")}if(void 0!==t.attributes.JOINTS_1){let i=this.loadArrayIntoArrayBuffer(t.attributes.JOINTS_1.array,t.attributes.JOINTS_1.componentType);this.loadBufferIntoGltf(i,e,s.JOINTS_1,34963,"JOINTS_1 buffer view")}if(void 0!==t.attributes.WEIGHTS_1){let i=this.loadArrayIntoArrayBuffer(t.attributes.WEIGHTS_1.array,t.attributes.WEIGHTS_1.componentType);this.loadBufferIntoGltf(i,e,s.WEIGHTS_1,34963,"WEIGHTS_1 buffer view")}}loadBufferIntoGltf(e,t,s,i,r){const n=new T;n.byteLength=e.byteLength,n.buffer=e,t.buffers.push(n);const o=new w;o.buffer=t.buffers.length-1,o.byteLength=e.byteLength,void 0!==r&&(o.name=r),o.target=i,t.bufferViews.push(o),t.accessors[s].byteOffset=0,t.accessors[s].bufferView=t.bufferViews.length-1}loadArrayIntoArrayBuffer(e,t){let s;switch(t){case"Int8Array":s=new ArrayBuffer(e.length),new Int8Array(s).set(e);break;case"Uint8Array":s=new ArrayBuffer(e.length),new Uint8Array(s).set(e);break;case"Int16Array":s=new ArrayBuffer(2*e.length),new Int16Array(s).set(e);break;case"Uint16Array":s=new ArrayBuffer(2*e.length),new Uint16Array(s).set(e);break;case"Int32Array":s=new ArrayBuffer(4*e.length),new Int32Array(s).set(e);break;case"Uint32Array":s=new ArrayBuffer(4*e.length),new Uint32Array(s).set(e);break;default:case"Float32Array":s=new ArrayBuffer(4*e.length),new Float32Array(s).set(e)}return s}decodeDracoBufferToIntermediate(e,t){let s=e.bufferView;const i=t.bufferViews[s],r=t.buffers[i.buffer],n=new Int8Array(r.buffer).slice(i.byteOffset,i.byteOffset+i.byteLength);let o=(new U).module,a=new o.Decoder,h=new o.DecoderBuffer;h.Init(n,i.byteLength);let l=this.decodeGeometry(o,a,h,e.attributes,t);return o.destroy(h),l}getDracoArrayTypeFromComponentType(e){switch(e){case h.BYTE:return"Int8Array";case h.UNSIGNED_BYTE:return"Uint8Array";case h.SHORT:return"Int16Array";case h.UNSIGNED_SHORT:return"Uint16Array";case h.INT:return"Int32Array";case h.UNSIGNED_INT:return"Uint32Array";case h.FLOAT:default:return"Float32Array"}}decodeGeometry(e,t,s,i,r){let n,o,a=t.GetEncodedGeometryType(s);if(a!==e.TRIANGULAR_MESH)throw new Error("DRACOLoader: Unexpected geometry type.");if(n=new e.Mesh,o=t.DecodeBufferToMesh(s,n),!o.ok()||0===n.ptr)throw new Error("DRACOLoader: Decoding failed: "+o.error_msg());let l={index:null,attributes:{}},c=n.num_points();for(let s in i){let o,a=h.BYTE;for(const[e,t]of Object.entries(this.attributes))if(e===s){a=r.accessors[t].componentType,o=r.accessors[t].count;break}if(c!==o)throw new Error(`DRACOLoader: Accessor vertex count ${o} does not match draco decoder vertex count ${c}`);a=this.getDracoArrayTypeFromComponentType(a);let f=t.GetAttributeByUniqueId(n,i[s]);var u=this.decodeAttribute(e,t,n,s,f,a);l.attributes[u.name]=u}if(a===e.TRIANGULAR_MESH){let s=3*n.num_faces(),i=4*s,r=e._malloc(i);t.GetTrianglesUInt32Array(n,i,r);let o=new Uint32Array(e.HEAPU32.buffer,r,s).slice();e._free(r),l.index={array:o,itemSize:1}}return e.destroy(n),l}decodeAttribute(e,t,s,i,r,n){let o,a,h,l=r.num_components(),c=s.num_points()*l;switch(n){case"Float32Array":h=4*c,o=e._malloc(h),t.GetAttributeDataArrayForAllPoints(s,r,e.DT_FLOAT32,h,o),a=new Float32Array(e.HEAPF32.buffer,o,c).slice(),e._free(o);break;case"Int8Array":o=e._malloc(c),t.GetAttributeDataArrayForAllPoints(s,r,e.DT_INT8,c,o),a=new Int8Array(e.HEAP8.buffer,o,c).slice(),e._free(o);break;case"Int16Array":h=2*c,o=e._malloc(h),t.GetAttributeDataArrayForAllPoints(s,r,e.DT_INT16,h,o),a=new Int16Array(e.HEAP16.buffer,o,c).slice(),e._free(o);break;case"Int32Array":h=4*c,o=e._malloc(h),t.GetAttributeDataArrayForAllPoints(s,r,e.DT_INT32,h,o),a=new Int32Array(e.HEAP32.buffer,o,c).slice(),e._free(o);break;case"Uint8Array":o=e._malloc(c),t.GetAttributeDataArrayForAllPoints(s,r,e.DT_UINT8,c,o),a=new Uint8Array(e.HEAPU8.buffer,o,c).slice(),e._free(o);break;case"Uint16Array":h=2*c,o=e._malloc(h),t.GetAttributeDataArrayForAllPoints(s,r,e.DT_UINT16,h,o),a=new Uint16Array(e.HEAPU16.buffer,o,c).slice(),e._free(o);break;case"Uint32Array":h=4*c,o=e._malloc(h),t.GetAttributeDataArrayForAllPoints(s,r,e.DT_UINT32,h,o),a=new Uint32Array(e.HEAPU32.buffer,o,c).slice(),e._free(o);break;default:throw new Error("DRACOLoader: Unexpected attribute type.")}return{name:i,array:a,itemSize:l,componentType:n}}}class P extends y{constructor(){super(),this.primitives=[],this.name=void 0,this.weights=[],this.weightsAnimated=void 0}fromJson(e){super.fromJson(e),void 0!==e.name&&(this.name=e.name),this.primitives=u(e.primitives,D),void 0!==e.weights&&(this.weights=e.weights)}getWeightsAnimated(){return void 0!==this.weightsAnimated?this.weightsAnimated:this.weights}initGl(e,t){this.primitives.forEach(s=>{s.initGl(e,t)})}}class k extends y{constructor(){super(),this.camera=void 0,this.children=[],this.matrix=void 0,this.rotation=[0,0,0,1],this.scale=[1,1,1],this.translation=[0,0,0],this.name=void 0,this.mesh=void 0,this.skin=void 0,this.light=void 0,this.changed=!0,this.animationRotation=void 0,this.animationTranslation=void 0,this.animationScale=void 0}fromJson(e){super.fromJson(e)}initGl(e,s){let i;if(this.extras){if(window.zeaCad){const{CADBody:e}=zeaCad;i=new e(this.name)}else i=new t.TreeItem(this.name);for(let e in this.extras){const s=this.extras[e];"string"==typeof s?i.addParameter(new t.StringParameter(e,s)):"boolean"==typeof s?i.addParameter(new t.BooleanParameter(e,s)):"number"==typeof s?i.addParameter(new t.NumberParameter(e,s)):"object"==typeof s&&i.addParameter(new t.Parameter(e,s,"json"))}i.extras=this.extras}else i=new t.TreeItem(this.name);const r=new t.Xfo;if(void 0!==this.matrix){const e=new t.Mat4(Float32Array.from(this.matrix));r.setFromMat4(e)}else void 0!==this.scale&&r.sc.set(...this.scale),void 0!==this.rotation&&r.ori.set(...this.rotation),void 0!==this.translation&&r.tr.set(...this.translation);if(i.getParameter("LocalXfo").setValue(r),this.children.forEach(t=>{e.nodes[t].initGl(e,i)}),null!=this.mesh){e.meshes[this.mesh].initGl(e,i)}s.addChild(i,!1),t.resourceLoader.incrementWorkDone(1)}applyMatrix(e){this.matrix=e,mat4.getScaling(this.scale,this.matrix);const t=mat4.create();for(const e of[0,1,2])t[e]=this.matrix[e]/this.scale[0],t[e+4]=this.matrix[e+4]/this.scale[1],t[e+8]=this.matrix[e+8]/this.scale[2];mat4.getRotation(this.rotation,t),quat.normalize(this.rotation,this.rotation),mat4.getTranslation(this.translation,this.matrix),this.changed=!0}applyTranslationAnimation(e){this.animationTranslation=e,this.changed=!0}applyRotationAnimation(e){this.animationRotation=e,this.changed=!0}applyScaleAnimation(e){this.animationScale=e,this.changed=!0}resetTransform(){this.rotation=[0,0,0,1],this.scale=[1,1,1],this.translation=[0,0,0],this.changed=!0}getLocalTransform(){if(void 0===this.transform||this.changed){this.transform=mat4.create();const e=void 0!==this.animationTranslation?this.animationTranslation:this.translation,t=void 0!==this.animationRotation?this.animationRotation:this.rotation,s=void 0!==this.animationScale?this.animationScale:this.scale;mat4.fromRotationTranslationScale(this.transform,t,e,s),this.changed=!1}return mat4.clone(this.transform)}}class H extends y{constructor(e="LINEAR",t="LINEAR_MIPMAP_LINEAR",s="REPEAT",i="REPEAT"){super(),this.magFilter=e,this.minFilter=t,this.wrapS=s,this.wrapT=i,this.name=void 0}static createDefault(){return new H}}class z extends y{constructor(e=[],t){super(),this.nodes=e,this.name=t,this.imageBasedLight=void 0}initGl(e,t){if(void 0!==this.extensions&&void 0!==this.extensions.KHR_lights_image_based){const t=this.extensions.KHR_lights_image_based.imageBasedLight;this.imageBasedLight=e.imageBasedLights[t]}this.nodes.forEach(s=>{e.nodes[s].initGl(e,t)})}gatherNodes(e){const t=[];function s(i){const r=e.nodes[i];t.push(r);for(const e of r.children)s(e)}for(const e of this.nodes)s(e);return t}includesNode(e,t){let s=[...this.nodes];for(;s.length>0;){const i=s.pop();if(i===t)return!0;s=s.concat(e.nodes[i].children)}return!1}}class J extends y{constructor(){super(),this.copyright=void 0,this.generator=void 0,this.version=void 0,this.minVersion=void 0}}class K extends y{constructor(){super(),this.target={node:void 0,path:void 0},this.sampler=void 0}}const j="translation",W="rotation",q="scale",Y="weights";class X extends y{constructor(){super(),this.input=void 0,this.interpolation=void 0,this.output=void 0}}const $="LINEAR",Q="STEP",Z="CUBICSPLINE";class ee{constructor(){this.prevKey=0,this.prevT=0}slerpQuat(e,t,s){const i=quat.create(),r=quat.create();quat.normalize(i,e),quat.normalize(r,t);const n=quat.create();return quat.slerp(n,i,r,s),quat.normalize(n,n),n}step(e,t,s){const i=new glMatrix.ARRAY_TYPE(s);for(let r=0;r<s;++r)i[r]=t[e*s+r];return i}linear(e,t,s,i,r){const n=new glMatrix.ARRAY_TYPE(r);for(let o=0;o<r;++o)n[o]=s[e*r+o]*(1-i)+s[t*r+o]*i;return n}cubicSpline(e,t,s,i,r,n){const o=e*n*3,a=t*n*3,h=1*n,l=2*n,c=new glMatrix.ARRAY_TYPE(n),u=r**2,f=r**3;for(let e=0;e<n;++e){const t=s[o+e+h],n=i*s[a+e+0],d=i*s[o+e+l],m=s[a+e+h];c[e]=(2*f-3*u+1)*t+(f-2*u+r)*d+(-2*f+3*u)*m+(f-u)*n}return c}resetKey(){this.prevKey=0}interpolate(e,t,s,i,r,n){if(void 0===i)return;const o=e.accessors[s.input].getNormalizedDeinterlacedView(e),a=e.accessors[s.output].getNormalizedDeinterlacedView(e);if(a.length===r)return l(a,0,r);i=m(i%=n,o[0],o[o.length-1]),this.prevT>i&&(this.prevKey=0),this.prevT=i;let h=null;for(let e=this.prevKey;e<o.length;++e)if(i<=o[e]){h=m(e,1,o.length-1);break}this.prevKey=m(h-1,0,h);const c=o[h]-o[this.prevKey],u=(i-o[this.prevKey])/c;if(t.target.path===W){if(Z===s.interpolation){const e=this.cubicSpline(this.prevKey,h,a,c,u,4);return quat.normalize(e,e),e}if(s.interpolation===$){const e=this.getQuat(a,this.prevKey),t=this.getQuat(a,h);return this.slerpQuat(e,t,u)}if(s.interpolation===Q)return this.getQuat(a,this.prevKey)}switch(s.interpolation){case Q:return this.step(this.prevKey,a,r);case Z:return this.cubicSpline(this.prevKey,h,a,c,u,r);default:return this.linear(this.prevKey,h,a,u,r)}}getQuat(e,t){const s=e[4*t],i=e[4*t+1],r=e[4*t+2],n=e[4*t+3];return quat.fromValues(s,i,r,n)}}class te extends y{constructor(){super(),this.channels=[],this.samplers=[],this.name="",this.interpolators=[],this.maxTime=0,this.disjointAnimations=[]}fromJson(e){if(super.fromJson(e),this.channels=u(e.channels,K),this.samplers=u(e.samplers,X),this.name=e.name,void 0!==this.channels)for(let e=0;e<this.channels.length;++e)this.interpolators.push(new ee);else console.error("No channel data found for skin")}advance(e,t){if(void 0!==this.channels){if(0==this.maxTime)for(let t=0;t<this.channels.length;++t){const s=this.channels[t],i=this.samplers[s.sampler],r=e.accessors[i.input].getDeinterlacedView(e),n=r[r.length-1];n>this.maxTime&&(this.maxTime=n)}for(let s=0;s<this.interpolators.length;++s){const i=this.channels[s],r=this.samplers[i.sampler],n=this.interpolators[s],o=e.nodes[i.target.node];switch(i.target.path){case j:o.applyTranslationAnimation(n.interpolate(e,i,r,t,3,this.maxTime));break;case W:o.applyRotationAnimation(n.interpolate(e,i,r,t,4,this.maxTime));break;case q:o.applyScaleAnimation(n.interpolate(e,i,r,t,3,this.maxTime));break;case Y:{const s=e.meshes[o.mesh];s.weightsAnimated=n.interpolate(e,i,r,t,s.weights.length,this.maxTime);break}}}}}}class se extends y{constructor(){super(),this.name="",this.inverseBindMatrices=void 0,this.joints=[],this.skeleton=void 0,this.jointMatrices=[],this.jointNormalMatrices=[]}computeJoints(e,t){const s=e.accessors[this.inverseBindMatrices].getDeinterlacedView(e);this.jointMatrices=[],this.jointNormalMatrices=[];let i=0;for(const r of this.joints){const n=e.nodes[r];let o=mat4.create(),a=l(s,16*i++,16);mat4.mul(o,n.worldTransform,a),mat4.mul(o,t.inverseWorldTransform,o),this.jointMatrices.push(o);let h=mat4.create();mat4.invert(h,o),mat4.transpose(h,h),this.jointNormalMatrices.push(h)}}}class ie extends y{constructor(){super(),this.name=void 0}fromJson(e){void 0!==e.name&&(this.name=e.name)}}class re extends y{constructor(e){super(),this.asset=void 0,this.accessors=[],this.nodes=[],this.scene=void 0,this.scenes=[],this.cameras=[],this.lights=[],this.imageBasedLights=[],this.textures=[],this.images=[],this.samplers=[],this.meshes=[],this.buffers=[],this.bufferViews=[],this.materials=[],this.materialsMap={},this.animations=[],this.skins=[],this.path=e}initGl(e){const t=this;for(const s of this.images)null!=s&&void 0!==s.initGl&&s.initGl(t,e);for(const s of this.samplers)null!=s&&void 0!==s.initGl&&s.initGl(t,e);for(const s of this.textures)null!=s&&void 0!==s.initGl&&s.initGl(t,e);for(const s of this.materials)null!=s&&void 0!==s.initGl&&s.initGl(t,e);this.scenes[this.scene].initGl(this,e)}fromJson(e){super.fromJson(e),this.asset=f(e.asset,J),this.cameras=u(e.cameras,A),this.accessors=u(e.accessors,b),this.meshes=u(e.meshes,P),this.samplers=u(e.samplers,H),this.materials=u(e.materials,V),this.buffers=u(e.buffers,T),this.bufferViews=u(e.bufferViews,w),this.scenes=u(e.scenes,z),this.textures=u(e.textures,F),this.nodes=u(e.nodes,k),this.lights=u(function(e){if(void 0===e)return[];if(void 0===e.KHR_lights_punctual)return[];return e.KHR_lights_punctual.lights}(e.extensions),M),this.imageBasedLights=u(function(e){if(void 0===e)return[];if(void 0===e.KHR_lights_image_based)return[];return e.KHR_lights_image_based.imageBasedLights}(e.extensions),C),this.images=u(e.images,S),this.animations=u(e.animations,te),this.skins=u(e.skins,se),this.variants=u(function(e){if(void 0===e)return[];if(void 0===e.KHR_materials_variants)return[];return e.KHR_materials_variants.variants}(e.extensions),ie),this.variants=function(e){for(let t=0;t<e.length;t++){const s=e[t].name;for(let i=