Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gltf-transform/extensions

Package Overview
Dependencies
Maintainers
1
Versions
192
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gltf-transform/extensions - npm Package Compare versions

Comparing version 2.4.3 to 2.4.4

2

dist/extensions.js

@@ -1,2 +0,2 @@

var e=require("@gltf-transform/core"),t=require("ktx-parse");class s extends e.ExtensionProperty{init(){this.extensionName="EXT_mesh_gpu_instancing",this.propertyType="InstancedMesh",this.parentTypes=[e.PropertyType.NODE]}getDefaults(){return Object.assign(super.getDefaults(),{attributes:{}})}getAttribute(e){return this.getRefMap("attributes",e)}setAttribute(e,t){return this.setRefMap("attributes",e,t,{usage:"INSTANCE_ATTRIBUTE"})}listAttributes(){return this.listRefMapValues("attributes")}listSemantics(){return this.listRefMapKeys("attributes")}}s.EXTENSION_NAME="EXT_mesh_gpu_instancing";const r="EXT_mesh_gpu_instancing";class n extends e.Extension{constructor(...t){super(...t),this.extensionName=r,this.provideTypes=[e.PropertyType.NODE],this.prewriteTypes=[e.PropertyType.ACCESSOR]}createInstancedMesh(){return new s(this.document.getGraph())}read(e){return(e.jsonDoc.json.nodes||[]).forEach((t,s)=>{if(!t.extensions||!t.extensions[r])return;const n=t.extensions[r],o=this.createInstancedMesh();for(const t in n.attributes)o.setAttribute(t,e.accessors[n.attributes[t]]);e.nodes[s].setExtension(r,o)}),this}prewrite(e){e.accessorUsageGroupedByParent.add("INSTANCE_ATTRIBUTE");for(const t of this.properties)for(const s of t.listAttributes())e.addAccessorToUsageGroup(s,"INSTANCE_ATTRIBUTE");return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listNodes().forEach(s=>{const n=s.getExtension(r);if(n){const o=e.nodeIndexMap.get(s),i=t.json.nodes[o],a={attributes:{}};n.listSemantics().forEach(t=>{const s=n.getAttribute(t);a.attributes[t]=e.accessorIndexMap.get(s)}),i.extensions=i.extensions||{},i.extensions[r]=a}}),this}}var o,i,a;n.EXTENSION_NAME=r,function(e){e.QUANTIZE="quantize",e.FILTER="filter"}(o||(o={})),function(e){e.ATTRIBUTES="ATTRIBUTES",e.TRIANGLES="TRIANGLES",e.INDICES="INDICES"}(i||(i={})),function(e){e.NONE="NONE",e.OCTAHEDRAL="OCTAHEDRAL",e.QUATERNION="QUATERNION",e.EXPONENTIAL="EXPONENTIAL"}(a||(a={}));const{BYTE:c,SHORT:u,FLOAT:l}=e.Accessor.ComponentType,{normalize:h,denormalize:f}=e.MathUtils;function p(t,s,r,n){const{filter:o,bits:p}=n,x={array:t.getArray(),byteStride:t.getElementSize()*t.getComponentSize(),componentType:t.getComponentType(),normalized:t.getNormalized()};if(r!==i.ATTRIBUTES)return x;if(o!==a.NONE){let e=t.getNormalized()?function(e){const t=e.getComponentType(),s=e.getArray(),r=new Float32Array(s.length);for(let e=0;e<s.length;e++)r[e]=f(s[e],t);return r}(t):new Float32Array(x.array);switch(o){case a.EXPONENTIAL:x.byteStride=4*t.getElementSize(),x.componentType=l,x.normalized=!1,x.array=s.encodeFilterExp(e,t.getCount(),x.byteStride,p);break;case a.OCTAHEDRAL:x.byteStride=p>8?8:4,x.componentType=p>8?u:c,x.normalized=!0,e=3===t.getElementSize()?function(e){const t=new Float32Array(4*e.length/3);for(let s=0,r=e.length/3;s<r;s++)t[4*s]=e[3*s],t[4*s+1]=e[3*s+1],t[4*s+2]=e[3*s+2];return t}(e):e,x.array=s.encodeFilterOct(e,t.getCount(),x.byteStride,p);break;case a.QUATERNION:x.byteStride=8,x.componentType=u,x.normalized=!0,x.array=s.encodeFilterQuat(e,t.getCount(),x.byteStride,p);break;default:throw new Error("Invalid filter.")}x.min=t.getMin([]),x.max=t.getMax([]),t.getNormalized()&&(x.min=x.min.map(e=>f(e,t.getComponentType())),x.max=x.max.map(e=>f(e,t.getComponentType()))),x.normalized&&(x.min=x.min.map(e=>h(e,x.componentType)),x.max=x.max.map(e=>h(e,x.componentType)))}else x.byteStride%4&&(x.array=function(t,s){const r=e.BufferUtils.padNumber(t.BYTES_PER_ELEMENT*s)/t.BYTES_PER_ELEMENT,n=new t.constructor(t.length/s*r);for(let e=0;e*s<t.length;e++)for(let o=0;o<s;o++)n[e*r+o]=t[e*s+o];return n}(x.array,t.getElementSize()),x.byteStride=x.array.byteLength/t.getCount());return x}function x(t,s){return s===e.WriterContext.BufferViewUsage.ELEMENT_ARRAY_BUFFER?t.listParents().some(t=>t instanceof e.Primitive&&t.getMode()===e.Primitive.Mode.TRIANGLES)?i.TRIANGLES:i.INDICES:i.ATTRIBUTES}function g(t,s){const r=s.getGraph().listParentEdges(t).filter(t=>!(t.getParent()instanceof e.Root));for(const e of r){const s=e.getName(),r=e.getAttributes().key||"";if("indices"===s)return{filter:a.NONE};if("attributes"===s){if("POSITION"===r)return{filter:a.NONE};if("TEXCOORD_0"===r)return{filter:a.NONE};if("NORMAL"===r)return{filter:a.OCTAHEDRAL,bits:8};if("TANGENT"===r)return{filter:a.OCTAHEDRAL,bits:8};if(r.startsWith("JOINTS_"))return{filter:a.NONE};if(r.startsWith("WEIGHTS_"))return{filter:a.NONE}}if("output"===s){const e=T(t);return"rotation"===e?{filter:a.QUATERNION,bits:16}:"translation"===e||"scale"===e?{filter:a.EXPONENTIAL,bits:12}:{filter:a.NONE}}if("input"===s)return{filter:a.NONE};if("inverseBindMatrices"===s)return{filter:a.NONE}}return{filter:a.NONE}}function T(t){for(const s of t.listParents())if(s instanceof e.AnimationSampler)for(const t of s.listParents())if(t instanceof e.AnimationChannel)return t.getTargetPath();return null}const d="EXT_meshopt_compression",m={method:o.QUANTIZE};class E extends e.Extension{constructor(...t){super(...t),this.extensionName=d,this.prereadTypes=[e.PropertyType.BUFFER,e.PropertyType.PRIMITIVE],this.prewriteTypes=[e.PropertyType.BUFFER,e.PropertyType.ACCESSOR],this.readDependencies=["meshopt.decoder"],this.writeDependencies=["meshopt.encoder"],this._decoder=null,this._decoderFallbackBufferMap=new Map,this._encoder=null,this._encoderOptions=m,this._encoderFallbackBuffer=null,this._encoderBufferViews={},this._encoderBufferViewData={},this._encoderBufferViewAccessors={}}install(e,t){return"meshopt.decoder"===e&&(this._decoder=t),"meshopt.encoder"===e&&(this._encoder=t),this}setEncoderOptions(e){return this._encoderOptions={...m,...e},this}preread(t,s){if(!this._decoder){if(!this.isRequired())return this;throw new Error(`[${d}] Please install extension dependency, "meshopt.decoder".`)}if(!this._decoder.supported){if(!this.isRequired())return this;throw new Error(`[${d}]: Missing WASM support.`)}return s===e.PropertyType.BUFFER?this._prereadBuffers(t):s===e.PropertyType.PRIMITIVE&&this._prereadPrimitives(t),this}_prereadBuffers(t){const s=t.jsonDoc;(s.json.bufferViews||[]).forEach((r,n)=>{if(!r.extensions||!r.extensions[d])return;const o=r.extensions[d],i=o.byteOffset||0,a=o.byteLength||0,c=o.count,u=o.byteStride,l=new Uint8Array(c*u),h=s.json.buffers[r.buffer],f=e.BufferUtils.toView(h.uri?s.resources[h.uri]:s.resources[e.GLB_BUFFER],i,a);this._decoder.decodeGltfBuffer(l,c,u,f,o.mode,o.filter),t.bufferViews[n]=l})}_prereadPrimitives(e){const t=e.jsonDoc;(t.json.bufferViews||[]).forEach(s=>{var r;s.extensions&&s.extensions[d]&&(r=t.json.buffers[s.buffer]).extensions&&r.extensions.EXT_meshopt_compression&&r.extensions.EXT_meshopt_compression.fallback&&this._decoderFallbackBufferMap.set(e.buffers[s.buffer],e.buffers[s.extensions[d].buffer])})}read(t){if(!this.isRequired())return this;for(const[t,s]of this._decoderFallbackBufferMap){for(const r of t.listParents())r instanceof e.Accessor&&r.swap(t,s);t.dispose()}return this}prewrite(t,s){return s===e.PropertyType.ACCESSOR?this._prewriteAccessors(t):s===e.PropertyType.BUFFER&&this._prewriteBuffers(t),this}_prewriteAccessors(t){const s=t.jsonDoc.json,r=this._encoder,n=this._encoderOptions,i=this.document.createBuffer(),c=this.document.getRoot().listBuffers().indexOf(i);this._encoderFallbackBuffer=i,this._encoderBufferViews={},this._encoderBufferViewData={},this._encoderBufferViewAccessors={};for(const i of this.document.getRoot().listAccessors()){if("weights"===T(i))continue;const u=t.getAccessorUsage(i),l=x(i,u),h=n.method===o.FILTER?g(i,this.document):{filter:a.NONE},f=p(i,r,l,h),{array:m,byteStride:E}=f,I=i.getBuffer();if(!I)throw new Error(`${d}: Missing buffer for accessor.`);const y=this.document.getRoot().listBuffers().indexOf(I),R=[u,l,h.filter,E,y].join(":");let N=this._encoderBufferViews[R],_=this._encoderBufferViewData[R],A=this._encoderBufferViewAccessors[R];N&&_||(A=this._encoderBufferViewAccessors[R]=[],_=this._encoderBufferViewData[R]=[],N=this._encoderBufferViews[R]={buffer:c,target:e.WriterContext.USAGE_TO_TARGET[u],byteOffset:0,byteLength:0,byteStride:u===e.WriterContext.BufferViewUsage.ARRAY_BUFFER?E:void 0,extensions:{[d]:{buffer:y,byteOffset:0,byteLength:0,mode:l,filter:h.filter!==a.NONE?h.filter:void 0,byteStride:E,count:0}}});const S=t.createAccessorDef(i);S.componentType=f.componentType,S.normalized=f.normalized,S.byteOffset=N.byteLength,S.min&&f.min&&(S.min=f.min),S.max&&f.max&&(S.max=f.max),t.accessorIndexMap.set(i,s.accessors.length),s.accessors.push(S),A.push(S),_.push(new Uint8Array(m.buffer,m.byteOffset,m.byteLength)),N.byteLength+=m.byteLength,N.extensions.EXT_meshopt_compression.count+=i.getCount()}}_prewriteBuffers(t){const s=this._encoder;for(const r in this._encoderBufferViews){const n=this._encoderBufferViews[r],o=this._encoderBufferViewData[r],i=this.document.getRoot().listBuffers()[n.extensions[d].buffer],a=t.otherBufferViews.get(i)||[],{count:c,byteStride:u,mode:l}=n.extensions[d],h=e.BufferUtils.concat(o),f=s.encodeGltfBuffer(h,c,u,l),p=e.BufferUtils.pad(f);n.extensions[d].byteLength=f.byteLength,o.length=0,o.push(p),a.push(p),t.otherBufferViews.set(i,a)}}write(t){let s=0;for(const r in this._encoderBufferViews){const n=this._encoderBufferViews[r],o=t.otherBufferViewsIndexMap.get(this._encoderBufferViewData[r][0]),i=this._encoderBufferViewAccessors[r];for(const e of i)e.bufferView=o;const a=t.jsonDoc.json.bufferViews[o],c=a.byteOffset||0;Object.assign(a,n),a.byteOffset=s,a.extensions[d].byteOffset=c,s+=e.BufferUtils.padNumber(n.byteLength)}const r=this._encoderFallbackBuffer,n=t.bufferIndexMap.get(r),o=t.jsonDoc.json.buffers[n];return o.byteLength=s,o.extensions={[d]:{fallback:!0}},r.dispose(),this}}E.EXTENSION_NAME=d,E.EncoderMethod=o;const I="EXT_texture_webp";class y{match(e){return e.length>=12&&87===e[8]&&69===e[9]&&66===e[10]&&80===e[11]}getSize(t){const s=e.BufferUtils.decodeText(t.slice(0,4)),r=e.BufferUtils.decodeText(t.slice(8,12));if("RIFF"!==s||"WEBP"!==r)return null;const n=new DataView(t.buffer,t.byteOffset);let o=12;for(;o<n.byteLength;){const t=e.BufferUtils.decodeText(new Uint8Array([n.getUint8(o),n.getUint8(o+1),n.getUint8(o+2),n.getUint8(o+3)])),s=n.getUint32(o+4,!0);if("VP8 "===t)return[16383&n.getInt16(o+14,!0),16383&n.getInt16(o+16,!0)];if("VP8L"===t){const e=n.getUint8(o+9),t=n.getUint8(o+10),s=n.getUint8(o+11);return[1+((63&t)<<8|e),1+((15&n.getUint8(o+12))<<10|s<<2|(192&t)>>6)]}o+=8+s+s%2}return null}getChannels(e){return 4}}class R extends e.Extension{constructor(...t){super(...t),this.extensionName=I,this.prereadTypes=[e.PropertyType.TEXTURE]}static register(){e.ImageUtils.registerFormat("image/webp",new y)}preread(e){return(e.jsonDoc.json.textures||[]).forEach(e=>{e.extensions&&e.extensions[I]&&(e.source=e.extensions[I].source)}),this}read(e){return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listTextures().forEach(s=>{if("image/webp"===s.getMimeType()){const r=e.imageIndexMap.get(s);(t.json.textures||[]).forEach(e=>{e.source===r&&(e.extensions=e.extensions||{},e.extensions[I]={source:e.source},delete e.source)})}}),this}}R.EXTENSION_NAME=I;const N="KHR_draco_mesh_compression";let _,A,S,C;function M(e,t){const s=new _.DecoderBuffer;try{if(s.Init(t,t.length),e.GetEncodedGeometryType(s)!==_.TRIANGULAR_MESH)throw new Error(`[${N}] Unknown geometry type.`);const r=new _.Mesh;if(!e.DecodeBufferToMesh(s,r).ok()||0===r.ptr)throw new Error(`[${N}] Decoding failure.`);return r}finally{_.destroy(s)}}function O(e,t){const s=3*t.num_faces();let r,n;if(t.num_points()<=65534){const o=s*Uint16Array.BYTES_PER_ELEMENT;r=_._malloc(o),e.GetTrianglesUInt16Array(t,o,r),n=new Uint16Array(_.HEAPU16.buffer,r,s).slice()}else{const o=s*Uint32Array.BYTES_PER_ELEMENT;r=_._malloc(o),e.GetTrianglesUInt32Array(t,o,r),n=new Uint32Array(_.HEAPU32.buffer,r,s).slice()}return _._free(r),n}function D(e,t,s,r){const n=S[r.componentType],o=A[r.componentType],i=s.num_components(),a=t.num_points()*i,c=a*o.BYTES_PER_ELEMENT,u=_._malloc(c);e.GetAttributeDataArrayForAllPoints(t,s,n,c,u);const l=new o(_.HEAPF32.buffer,u,a).slice();return _._free(u),l}var w,F;!function(e){e[e.EDGEBREAKER=1]="EDGEBREAKER",e[e.SEQUENTIAL=0]="SEQUENTIAL"}(w||(w={})),function(e){e.POSITION="POSITION",e.NORMAL="NORMAL",e.COLOR="COLOR",e.TEX_COORD="TEX_COORD",e.GENERIC="GENERIC"}(F||(F={}));const b={[F.POSITION]:14,[F.NORMAL]:10,[F.COLOR]:8,[F.TEX_COORD]:12,[F.GENERIC]:12},P={decodeSpeed:5,encodeSpeed:5,method:w.EDGEBREAKER,quantizationBits:b,quantizationVolume:"mesh"};function j(e,t=P){const s={...P,...t};s.quantizationBits={...b,...t.quantizationBits};const r=new C.Encoder,n=new C.MeshBuilder,o=new C.Mesh,i={},a=new C.DracoInt8Array;for(const t of e.listSemantics()){const a=e.getAttribute(t),c=v(t),u=U(n,a.getComponentType(),o,C[c],a.getCount(),a.getElementSize(),a.getArray());if(-1===u)throw new Error(`Error compressing "${t}" attribute.`);if(i[t]=u,"mesh"===s.quantizationVolume||"POSITION"!==t)r.SetAttributeQuantization(C[c],s.quantizationBits[c]);else{if("object"!=typeof s.quantizationVolume)throw new Error("Invalid quantization volume state.");{const{quantizationVolume:e}=s,t=Math.max(e.max[0]-e.min[0],e.max[1]-e.min[1],e.max[2]-e.min[2]);r.SetAttributeExplicitQuantization(C[c],s.quantizationBits[c],a.getElementSize(),e.min,t)}}}const c=e.getIndices();if(!c)throw new Error("Primitive must have indices.");n.AddFacesToMesh(o,c.getCount()/3,c.getArray()),r.SetSpeedOptions(s.encodeSpeed,s.decodeSpeed),r.SetTrackEncodedProperties(!0),s.method===w.SEQUENTIAL||e.listTargets().length>0?r.SetEncodingMethod(C.MESH_SEQUENTIAL_ENCODING):r.SetEncodingMethod(C.MESH_EDGEBREAKER_ENCODING);const u=r.EncodeMeshToDracoBuffer(o,a);if(u<=0)throw new Error("Error applying Draco compression.");const l=new Uint8Array(u);for(let e=0;e<u;++e)l[e]=a.GetValue(e);const h=e.getAttribute("POSITION").getCount(),f=r.GetNumberOfEncodedPoints(),p=3*r.GetNumberOfEncodedFaces();if(e.listTargets().length>0&&f!==h)throw new Error('Compression reduced vertex count unexpectedly, corrupting morph targets. Applying the "weld" function before compression may resolve the issue.');return C.destroy(a),C.destroy(o),C.destroy(n),C.destroy(r),{numVertices:f,numIndices:p,data:l,attributeIDs:i}}function v(e){return"POSITION"===e?F.POSITION:"NORMAL"===e?F.NORMAL:e.startsWith("COLOR_")?F.COLOR:e.startsWith("TEXCOORD_")?F.TEX_COORD:F.GENERIC}function U(t,s,r,n,o,i,a){switch(s){case e.Accessor.ComponentType.UNSIGNED_BYTE:return t.AddUInt8Attribute(r,n,o,i,a);case e.Accessor.ComponentType.BYTE:return t.AddInt8Attribute(r,n,o,i,a);case e.Accessor.ComponentType.UNSIGNED_SHORT:return t.AddUInt16Attribute(r,n,o,i,a);case e.Accessor.ComponentType.SHORT:return t.AddInt16Attribute(r,n,o,i,a);case e.Accessor.ComponentType.UNSIGNED_INT:return t.AddUInt32Attribute(r,n,o,i,a);case e.Accessor.ComponentType.FLOAT:return t.AddFloatAttribute(r,n,o,i,a);default:throw new Error(`Unexpected component type, "${s}".`)}}const B="KHR_draco_mesh_compression";class k extends e.Extension{constructor(...t){super(...t),this.extensionName=B,this.prereadTypes=[e.PropertyType.PRIMITIVE],this.prewriteTypes=[e.PropertyType.ACCESSOR],this.readDependencies=["draco3d.decoder"],this.writeDependencies=["draco3d.encoder"],this._decoderModule=null,this._encoderModule=null,this._encoderOptions={}}install(t,s){return"draco3d.decoder"===t&&(this._decoderModule=s,_=this._decoderModule,A={[e.Accessor.ComponentType.FLOAT]:Float32Array,[e.Accessor.ComponentType.UNSIGNED_INT]:Uint32Array,[e.Accessor.ComponentType.UNSIGNED_SHORT]:Uint16Array,[e.Accessor.ComponentType.UNSIGNED_BYTE]:Uint8Array,[e.Accessor.ComponentType.SHORT]:Int16Array,[e.Accessor.ComponentType.BYTE]:Int8Array},S={[e.Accessor.ComponentType.FLOAT]:_.DT_FLOAT32,[e.Accessor.ComponentType.UNSIGNED_INT]:_.DT_UINT32,[e.Accessor.ComponentType.UNSIGNED_SHORT]:_.DT_UINT16,[e.Accessor.ComponentType.UNSIGNED_BYTE]:_.DT_UINT8,[e.Accessor.ComponentType.SHORT]:_.DT_INT16,[e.Accessor.ComponentType.BYTE]:_.DT_INT8}),"draco3d.encoder"===t&&(this._encoderModule=s,C=this._encoderModule),this}setEncoderOptions(e){return this._encoderOptions=e,this}preread(t){if(!this._decoderModule)throw new Error(`[${B}] Please install extension dependency, "draco3d.decoder".`);const s=this.document.getLogger(),r=t.jsonDoc,n=new Map;try{const o=r.json.meshes||[];for(const i of o)for(const o of i.primitives){if(!o.extensions||!o.extensions[B])continue;const i=o.extensions[B];let[a,c]=n.get(i.bufferView)||[];if(!c||!a){const t=r.json.bufferViews[i.bufferView],o=r.json.buffers[t.buffer],u=e.BufferUtils.toView(o.uri?r.resources[o.uri]:r.resources[e.GLB_BUFFER],t.byteOffset||0,t.byteLength);a=new this._decoderModule.Decoder,c=M(a,u),n.set(i.bufferView,[a,c]),s.debug(`[${B}] Decompressed ${u.byteLength} bytes.`)}for(const e in o.attributes){const s=t.jsonDoc.json.accessors[o.attributes[e]],r=a.GetAttributeByUniqueId(c,i.attributes[e]),n=D(a,c,r,s);t.accessors[o.attributes[e]].setArray(n)}void 0!==o.indices&&t.accessors[o.indices].setArray(O(a,c))}}finally{for(const[e,t]of Array.from(n.values()))this._decoderModule.destroy(e),this._decoderModule.destroy(t)}return this}read(e){return this}prewrite(t,s){if(!this._encoderModule)throw new Error(`[${B}] Please install extension dependency, "draco3d.encoder".`);const r=this.document.getLogger();r.debug(`[${B}] Compression options: ${JSON.stringify(this._encoderOptions)}`);const n=function(t){const s=t.getLogger(),r=new Set,n=new Set;for(const o of t.getRoot().listMeshes())for(const t of o.listPrimitives())t.getIndices()?t.getMode()!==e.Primitive.Mode.TRIANGLES?(n.add(t),s.warn(`[${B}] Skipping Draco compression on non-TRIANGLES primitive.`)):r.add(t):(n.add(t),s.warn(`[${B}] Skipping Draco compression on non-indexed primitive.`));const o=t.getRoot().listAccessors(),i=new Map;for(let e=0;e<o.length;e++)i.set(o[e],e);const a=new Map,c=new Set,u=new Map;for(const e of Array.from(r)){let s=G(e,i);if(c.has(s))u.set(e,s);else{if(a.has(e.getIndices())){const s=e.getIndices(),r=s.clone();i.set(r,t.getRoot().listAccessors().length-1),e.swap(s,r)}for(const s of e.listAttributes())if(a.has(s)){const r=s.clone();i.set(r,t.getRoot().listAccessors().length-1),e.swap(s,r)}s=G(e,i),c.add(s),u.set(e,s),a.set(e.getIndices(),s);for(const t of e.listAttributes())a.set(t,s)}}for(const t of Array.from(a.keys())){const s=new Set(t.listParents().map(e=>e.propertyType));if(2!==s.size||!s.has(e.PropertyType.PRIMITIVE)||!s.has(e.PropertyType.ROOT))throw new Error(`[${B}] Compressed accessors must only be used as indices or vertex attributes.`)}for(const e of Array.from(r)){const t=u.get(e),s=e.getIndices();if(a.get(s)!==t||e.listAttributes().some(e=>a.get(e)!==t))throw new Error(`[${B}] Draco primitives must share all, or no, accessors.`)}for(const e of Array.from(n)){const t=e.getIndices();if(a.has(t)||e.listAttributes().some(e=>a.has(e)))throw new Error(`[${B}] Accessor cannot be shared by compressed and uncompressed primitives.`)}return u}(this.document),o=new Map;let i="mesh";"scene"===this._encoderOptions.quantizationVolume&&(1!==this.document.getRoot().listScenes().length?r.warn(`[${B}]: quantizationVolume=scene requires exactly 1 scene.`):i=e.bounds(this.document.getRoot().listScenes().pop()));for(const e of Array.from(n.keys())){const s=n.get(e);if(!s)throw new Error("Unexpected primitive.");if(o.has(s)){o.set(s,o.get(s));continue}const r=e.getIndices(),a=t.jsonDoc.json.accessors,c=j(e,{...this._encoderOptions,quantizationVolume:i});o.set(s,c);const u=t.createAccessorDef(r);u.count=c.numIndices,t.accessorIndexMap.set(r,a.length),a.push(u);for(const s of e.listSemantics()){const r=e.getAttribute(s),n=t.createAccessorDef(r);n.count=c.numVertices,t.accessorIndexMap.set(r,a.length),a.push(n)}const l=e.getAttribute("POSITION").getBuffer()||this.document.getRoot().listBuffers()[0];t.otherBufferViews.has(l)||t.otherBufferViews.set(l,[]),t.otherBufferViews.get(l).push(c.data)}return r.debug(`[${B}] Compressed ${n.size} primitives.`),t.extensionData[B]={primitiveHashMap:n,primitiveEncodingMap:o},this}write(e){const t=e.extensionData[B];for(const s of this.document.getRoot().listMeshes()){const r=e.jsonDoc.json.meshes[e.meshIndexMap.get(s)];for(let n=0;n<s.listPrimitives().length;n++){const o=s.listPrimitives()[n],i=r.primitives[n],a=t.primitiveHashMap.get(o);if(!a)continue;const c=t.primitiveEncodingMap.get(a);i.extensions=i.extensions||{},i.extensions[B]={bufferView:e.otherBufferViewsIndexMap.get(c.data),attributes:c.attributeIDs}}}if(!t.primitiveHashMap.size){const t=e.jsonDoc.json;t.extensionsUsed=(t.extensionsUsed||[]).filter(e=>e!==B),t.extensionsRequired=(t.extensionsRequired||[]).filter(e=>e!==B)}return this}}function G(e,t){const s=[],r=e.getIndices();s.push(t.get(r));for(const r of e.listAttributes())s.push(t.get(r));return s.sort().join("|")}k.EXTENSION_NAME=B,k.EncoderMethod=w;class L extends e.ExtensionProperty{init(){this.extensionName="KHR_lights_punctual",this.propertyType="Light",this.parentTypes=[e.PropertyType.NODE]}getDefaults(){return Object.assign(super.getDefaults(),{color:[1,1,1],intensity:1,type:L.Type.POINT,range:null,innerConeAngle:0,outerConeAngle:Math.PI/4})}getColor(){return this.get("color")}setColor(e){return this.set("color",e)}getColorHex(){return e.ColorUtils.factorToHex(this.getColor())}setColorHex(t){const s=this.getColor().slice();return e.ColorUtils.hexToFactor(t,s),this.setColor(s)}getIntensity(){return this.get("intensity")}setIntensity(e){return this.set("intensity",e)}getType(){return this.get("type")}setType(e){return this.set("type",e)}getRange(){return this.get("range")}setRange(e){return this.set("range",e)}getInnerConeAngle(){return this.get("innerConeAngle")}setInnerConeAngle(e){return this.set("innerConeAngle",e)}getOuterConeAngle(){return this.get("outerConeAngle")}setOuterConeAngle(e){return this.set("outerConeAngle",e)}}L.EXTENSION_NAME="KHR_lights_punctual",L.Type={POINT:"point",SPOT:"spot",DIRECTIONAL:"directional"};const H="KHR_lights_punctual";class V extends e.Extension{constructor(...e){super(...e),this.extensionName=H}createLight(e=""){return new L(this.document.getGraph(),e)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[H])return this;const s=(t.json.extensions[H].lights||[]).map(e=>{const t=this.createLight().setName(e.name||"").setType(e.type);return void 0!==e.color&&t.setColor(e.color),void 0!==e.intensity&&t.setIntensity(e.intensity),void 0!==e.range&&t.setRange(e.range),void 0!==e.spot?.innerConeAngle&&t.setInnerConeAngle(e.spot.innerConeAngle),void 0!==e.spot?.outerConeAngle&&t.setOuterConeAngle(e.spot.outerConeAngle),t});return t.json.nodes.forEach((t,r)=>{t.extensions&&t.extensions[H]&&e.nodes[r].setExtension(H,s[t.extensions[H].light])}),this}write(t){const s=t.jsonDoc;if(0===this.properties.size)return this;const r=[],n=new Map;for(const t of this.properties){const s=t,o={type:s.getType()};e.MathUtils.eq(s.getColor(),[1,1,1])||(o.color=s.getColor()),1!==s.getIntensity()&&(o.intensity=s.getIntensity()),null!=s.getRange()&&(o.range=s.getRange()),s.getName()&&(o.name=s.getName()),s.getType()===L.Type.SPOT&&(o.spot={innerConeAngle:s.getInnerConeAngle(),outerConeAngle:s.getOuterConeAngle()}),r.push(o),n.set(s,r.length-1)}return this.document.getRoot().listNodes().forEach(e=>{const r=e.getExtension(H);if(r){const o=t.nodeIndexMap.get(e),i=s.json.nodes[o];i.extensions=i.extensions||{},i.extensions[H]={light:n.get(r)}}}),s.json.extensions=s.json.extensions||{},s.json.extensions[H]={lights:r},this}}V.EXTENSION_NAME=H;const{R:X,G:K,B:z}=e.TextureChannel;class q extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_clearcoat",this.propertyType="Clearcoat",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{clearcoatFactor:0,clearcoatTexture:null,clearcoatTextureInfo:new e.TextureInfo(this.graph,"clearcoatTextureInfo"),clearcoatRoughnessFactor:0,clearcoatRoughnessTexture:null,clearcoatRoughnessTextureInfo:new e.TextureInfo(this.graph,"clearcoatRoughnessTextureInfo"),clearcoatNormalScale:1,clearcoatNormalTexture:null,clearcoatNormalTextureInfo:new e.TextureInfo(this.graph,"clearcoatNormalTextureInfo")})}getClearcoatFactor(){return this.get("clearcoatFactor")}setClearcoatFactor(e){return this.set("clearcoatFactor",e)}getClearcoatTexture(){return this.getRef("clearcoatTexture")}getClearcoatTextureInfo(){return this.getRef("clearcoatTexture")?this.getRef("clearcoatTextureInfo"):null}setClearcoatTexture(e){return this.setRef("clearcoatTexture",e,{channels:X})}getClearcoatRoughnessFactor(){return this.get("clearcoatRoughnessFactor")}setClearcoatRoughnessFactor(e){return this.set("clearcoatRoughnessFactor",e)}getClearcoatRoughnessTexture(){return this.getRef("clearcoatRoughnessTexture")}getClearcoatRoughnessTextureInfo(){return this.getRef("clearcoatRoughnessTexture")?this.getRef("clearcoatRoughnessTextureInfo"):null}setClearcoatRoughnessTexture(e){return this.setRef("clearcoatRoughnessTexture",e,{channels:K})}getClearcoatNormalScale(){return this.get("clearcoatNormalScale")}setClearcoatNormalScale(e){return this.set("clearcoatNormalScale",e)}getClearcoatNormalTexture(){return this.getRef("clearcoatNormalTexture")}getClearcoatNormalTextureInfo(){return this.getRef("clearcoatNormalTexture")?this.getRef("clearcoatNormalTextureInfo"):null}setClearcoatNormalTexture(e){return this.setRef("clearcoatNormalTexture",e,{channels:X|K|z})}}q.EXTENSION_NAME="KHR_materials_clearcoat";const $="KHR_materials_clearcoat";class Q extends e.Extension{constructor(...e){super(...e),this.extensionName=$}createClearcoat(){return new q(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[$]){const n=this.createClearcoat();e.materials[r].setExtension($,n);const o=t.extensions[$];if(void 0!==o.clearcoatFactor&&n.setClearcoatFactor(o.clearcoatFactor),void 0!==o.clearcoatRoughnessFactor&&n.setClearcoatRoughnessFactor(o.clearcoatRoughnessFactor),void 0!==o.clearcoatTexture){const t=o.clearcoatTexture;n.setClearcoatTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getClearcoatTextureInfo(),t)}if(void 0!==o.clearcoatRoughnessTexture){const t=o.clearcoatRoughnessTexture;n.setClearcoatRoughnessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getClearcoatRoughnessTextureInfo(),t)}if(void 0!==o.clearcoatNormalTexture){const t=o.clearcoatNormalTexture;n.setClearcoatNormalTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getClearcoatNormalTextureInfo(),t),void 0!==t.scale&&n.setClearcoatNormalScale(t.scale)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension($);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[$]={clearcoatFactor:r.getClearcoatFactor(),clearcoatRoughnessFactor:r.getClearcoatRoughnessFactor()};if(r.getClearcoatTexture()){const t=r.getClearcoatTexture(),s=r.getClearcoatTextureInfo();i.clearcoatTexture=e.createTextureInfoDef(t,s)}if(r.getClearcoatRoughnessTexture()){const t=r.getClearcoatRoughnessTexture(),s=r.getClearcoatRoughnessTextureInfo();i.clearcoatRoughnessTexture=e.createTextureInfoDef(t,s)}if(r.getClearcoatNormalTexture()){const t=r.getClearcoatNormalTexture(),s=r.getClearcoatNormalTextureInfo();i.clearcoatNormalTexture=e.createTextureInfoDef(t,s),1!==r.getClearcoatNormalScale()&&(i.clearcoatNormalTexture.scale=r.getClearcoatNormalScale())}}}),this}}Q.EXTENSION_NAME=$;class Y extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_emissive_strength",this.propertyType="EmissiveStrength",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{emissiveStrength:1})}getEmissiveStrength(){return this.get("emissiveStrength")}setEmissiveStrength(e){return this.set("emissiveStrength",e)}}Y.EXTENSION_NAME="KHR_materials_emissive_strength";const W="KHR_materials_emissive_strength";class J extends e.Extension{constructor(...e){super(...e),this.extensionName=W}createEmissiveStrength(){return new Y(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[W]){const r=this.createEmissiveStrength();e.materials[s].setExtension(W,r);const n=t.extensions[W];void 0!==n.emissiveStrength&&r.setEmissiveStrength(n.emissiveStrength)}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(W);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{},o.extensions[W]={emissiveStrength:r.getEmissiveStrength()}}}),this}}J.EXTENSION_NAME=W;class Z extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_ior",this.propertyType="IOR",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{ior:0})}getIOR(){return this.get("ior")}setIOR(e){return this.set("ior",e)}}Z.EXTENSION_NAME="KHR_materials_ior";const ee="KHR_materials_ior";class te extends e.Extension{constructor(...e){super(...e),this.extensionName=ee}createIOR(){return new Z(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[ee]){const r=this.createIOR();e.materials[s].setExtension(ee,r);const n=t.extensions[ee];void 0!==n.ior&&r.setIOR(n.ior)}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(ee);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{},o.extensions[ee]={ior:r.getIOR()}}}),this}}te.EXTENSION_NAME=ee;const{R:se,G:re}=e.TextureChannel;class ne extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_iridescence",this.propertyType="Iridescence",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{iridescenceFactor:0,iridescenceTexture:null,iridescenceTextureInfo:new e.TextureInfo(this.graph,"iridescenceTextureInfo"),iridescenceIOR:1.3,iridescenceThicknessMinimum:100,iridescenceThicknessMaximum:400,iridescenceThicknessTexture:null,iridescenceThicknessTextureInfo:new e.TextureInfo(this.graph,"iridescenceThicknessTextureInfo")})}getIridescenceFactor(){return this.get("iridescenceFactor")}setIridescenceFactor(e){return this.set("iridescenceFactor",e)}getIridescenceTexture(){return this.getRef("iridescenceTexture")}getIridescenceTextureInfo(){return this.getRef("iridescenceTexture")?this.getRef("iridescenceTextureInfo"):null}setIridescenceTexture(e){return this.setRef("iridescenceTexture",e,{channels:se})}getIridescenceIOR(){return this.get("iridescenceIOR")}setIridescenceIOR(e){return this.set("iridescenceIOR",e)}getIridescenceThicknessMinimum(){return this.get("iridescenceThicknessMinimum")}setIridescenceThicknessMinimum(e){return this.set("iridescenceThicknessMinimum",e)}getIridescenceThicknessMaximum(){return this.get("iridescenceThicknessMaximum")}setIridescenceThicknessMaximum(e){return this.set("iridescenceThicknessMaximum",e)}getIridescenceThicknessTexture(){return this.getRef("iridescenceThicknessTexture")}getIridescenceThicknessTextureInfo(){return this.getRef("iridescenceThicknessTexture")?this.getRef("iridescenceThicknessTextureInfo"):null}setIridescenceThicknessTexture(e){return this.setRef("iridescenceThicknessTexture",e,{channels:re})}}ne.EXTENSION_NAME="KHR_materials_iridescence";const oe="KHR_materials_iridescence";class ie extends e.Extension{constructor(...e){super(...e),this.extensionName=oe}createIridescence(){return new ne(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[oe]){const n=this.createIridescence();e.materials[r].setExtension(oe,n);const o=t.extensions[oe];if(void 0!==o.iridescenceFactor&&n.setIridescenceFactor(o.iridescenceFactor),void 0!==o.iridescenceIor&&n.setIridescenceIOR(o.iridescenceIor),void 0!==o.iridescenceThicknessMinimum&&n.setIridescenceThicknessMinimum(o.iridescenceThicknessMinimum),void 0!==o.iridescenceThicknessMaximum&&n.setIridescenceThicknessMaximum(o.iridescenceThicknessMaximum),void 0!==o.iridescenceTexture){const t=o.iridescenceTexture;n.setIridescenceTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getIridescenceTextureInfo(),t)}if(void 0!==o.iridescenceThicknessTexture){const t=o.iridescenceThicknessTexture;n.setIridescenceThicknessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getIridescenceThicknessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(oe);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[oe]={};if(r.getIridescenceFactor()>0&&(i.iridescenceFactor=r.getIridescenceFactor()),1.3!==r.getIridescenceIOR()&&(i.iridescenceIor=r.getIridescenceIOR()),100!==r.getIridescenceThicknessMinimum()&&(i.iridescenceThicknessMinimum=r.getIridescenceThicknessMinimum()),400!==r.getIridescenceThicknessMaximum()&&(i.iridescenceThicknessMaximum=r.getIridescenceThicknessMaximum()),r.getIridescenceTexture()){const t=r.getIridescenceTexture(),s=r.getIridescenceTextureInfo();i.iridescenceTexture=e.createTextureInfoDef(t,s)}if(r.getIridescenceThicknessTexture()){const t=r.getIridescenceThicknessTexture(),s=r.getIridescenceThicknessTextureInfo();i.iridescenceThicknessTexture=e.createTextureInfoDef(t,s)}}}),this}}ie.EXTENSION_NAME=oe;const{R:ae,G:ce,B:ue,A:le}=e.TextureChannel;class he extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_pbrSpecularGlossiness",this.propertyType="PBRSpecularGlossiness",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{diffuseFactor:[1,1,1,1],diffuseTexture:null,diffuseTextureInfo:new e.TextureInfo(this.graph,"diffuseTextureInfo"),specularFactor:[1,1,1],glossinessFactor:1,specularGlossinessTexture:null,specularGlossinessTextureInfo:new e.TextureInfo(this.graph,"specularGlossinessTextureInfo")})}getDiffuseFactor(){return this.get("diffuseFactor")}setDiffuseFactor(e){return this.set("diffuseFactor",e)}getDiffuseHex(){return e.ColorUtils.factorToHex(this.getDiffuseFactor())}setDiffuseHex(t){const s=this.getDiffuseFactor().slice();return this.setDiffuseFactor(e.ColorUtils.hexToFactor(t,s))}getDiffuseTexture(){return this.getRef("diffuseTexture")}getDiffuseTextureInfo(){return this.getRef("diffuseTexture")?this.getRef("diffuseTextureInfo"):null}setDiffuseTexture(e){return this.setRef("diffuseTexture",e,{channels:ae|ce|ue|le})}getSpecularFactor(){return this.get("specularFactor")}setSpecularFactor(e){return this.set("specularFactor",e)}getGlossinessFactor(){return this.get("glossinessFactor")}setGlossinessFactor(e){return this.set("glossinessFactor",e)}getSpecularGlossinessTexture(){return this.getRef("specularGlossinessTexture")}getSpecularGlossinessTextureInfo(){return this.getRef("specularGlossinessTexture")?this.getRef("specularGlossinessTextureInfo"):null}setSpecularGlossinessTexture(e){return this.setRef("specularGlossinessTexture",e,{channels:ae|ce|ue|le})}}he.EXTENSION_NAME="KHR_materials_pbrSpecularGlossiness";const fe="KHR_materials_pbrSpecularGlossiness";class pe extends e.Extension{constructor(...e){super(...e),this.extensionName=fe}createPBRSpecularGlossiness(){return new he(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[fe]){const n=this.createPBRSpecularGlossiness();e.materials[r].setExtension(fe,n);const o=t.extensions[fe];if(void 0!==o.diffuseFactor&&n.setDiffuseFactor(o.diffuseFactor),void 0!==o.specularFactor&&n.setSpecularFactor(o.specularFactor),void 0!==o.glossinessFactor&&n.setGlossinessFactor(o.glossinessFactor),void 0!==o.diffuseTexture){const t=o.diffuseTexture;n.setDiffuseTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getDiffuseTextureInfo(),t)}if(void 0!==o.specularGlossinessTexture){const t=o.specularGlossinessTexture;n.setSpecularGlossinessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSpecularGlossinessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(fe);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[fe]={diffuseFactor:r.getDiffuseFactor(),specularFactor:r.getSpecularFactor(),glossinessFactor:r.getGlossinessFactor()};if(r.getDiffuseTexture()){const t=r.getDiffuseTexture(),s=r.getDiffuseTextureInfo();i.diffuseTexture=e.createTextureInfoDef(t,s)}if(r.getSpecularGlossinessTexture()){const t=r.getSpecularGlossinessTexture(),s=r.getSpecularGlossinessTextureInfo();i.specularGlossinessTexture=e.createTextureInfoDef(t,s)}}}),this}}pe.EXTENSION_NAME=fe;const{R:xe,G:ge,B:Te,A:de}=e.TextureChannel;class me extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_sheen",this.propertyType="Sheen",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{sheenColorFactor:[0,0,0],sheenColorTexture:null,sheenColorTextureInfo:new e.TextureInfo(this.graph,"sheenColorTextureInfo"),sheenRoughnessFactor:0,sheenRoughnessTexture:null,sheenRoughnessTextureInfo:new e.TextureInfo(this.graph,"sheenRoughnessTextureInfo")})}getSheenColorFactor(){return this.get("sheenColorFactor")}getSheenColorHex(){return e.ColorUtils.factorToHex(this.getSheenColorFactor())}setSheenColorFactor(e){return this.set("sheenColorFactor",e)}setSheenColorHex(t){const s=this.getSheenColorFactor().slice();return this.set("sheenColorFactor",e.ColorUtils.hexToFactor(t,s))}getSheenColorTexture(){return this.getRef("sheenColorTexture")}getSheenColorTextureInfo(){return this.getRef("sheenColorTexture")?this.getRef("sheenColorTextureInfo"):null}setSheenColorTexture(e){return this.setRef("sheenColorTexture",e,{channels:xe|ge|Te})}getSheenRoughnessFactor(){return this.get("sheenRoughnessFactor")}setSheenRoughnessFactor(e){return this.set("sheenRoughnessFactor",e)}getSheenRoughnessTexture(){return this.getRef("sheenRoughnessTexture")}getSheenRoughnessTextureInfo(){return this.getRef("sheenRoughnessTexture")?this.getRef("sheenRoughnessTextureInfo"):null}setSheenRoughnessTexture(e){return this.setRef("sheenRoughnessTexture",e,{channels:de})}}me.EXTENSION_NAME="KHR_materials_sheen";const Ee="KHR_materials_sheen";class Ie extends e.Extension{constructor(...e){super(...e),this.extensionName=Ee}createSheen(){return new me(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[Ee]){const n=this.createSheen();e.materials[r].setExtension(Ee,n);const o=t.extensions[Ee];if(void 0!==o.sheenColorFactor&&n.setSheenColorFactor(o.sheenColorFactor),void 0!==o.sheenRoughnessFactor&&n.setSheenRoughnessFactor(o.sheenRoughnessFactor),void 0!==o.sheenColorTexture){const t=o.sheenColorTexture;n.setSheenColorTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSheenColorTextureInfo(),t)}if(void 0!==o.sheenRoughnessTexture){const t=o.sheenRoughnessTexture;n.setSheenRoughnessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSheenRoughnessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(Ee);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[Ee]={sheenColorFactor:r.getSheenColorFactor(),sheenRoughnessFactor:r.getSheenRoughnessFactor()};if(r.getSheenColorTexture()){const t=r.getSheenColorTexture(),s=r.getSheenColorTextureInfo();i.sheenColorTexture=e.createTextureInfoDef(t,s)}if(r.getSheenRoughnessTexture()){const t=r.getSheenRoughnessTexture(),s=r.getSheenRoughnessTextureInfo();i.sheenRoughnessTexture=e.createTextureInfoDef(t,s)}}}),this}}Ie.EXTENSION_NAME=Ee;const{R:ye,G:Re,B:Ne,A:_e}=e.TextureChannel;class Ae extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_specular",this.propertyType="Specular",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{specularFactor:1,specularTexture:null,specularTextureInfo:new e.TextureInfo(this.graph,"specularTextureInfo"),specularColorFactor:[1,1,1],specularColorTexture:null,specularColorTextureInfo:new e.TextureInfo(this.graph,"specularColorTextureInfo")})}getSpecularFactor(){return this.get("specularFactor")}setSpecularFactor(e){return this.set("specularFactor",e)}getSpecularColorFactor(){return this.get("specularColorFactor")}setSpecularColorFactor(e){return this.set("specularColorFactor",e)}getSpecularColorHex(){return e.ColorUtils.factorToHex(this.getSpecularColorFactor())}setSpecularColorHex(t){const s=this.getSpecularColorFactor().slice();return this.set("specularColorFactor",e.ColorUtils.hexToFactor(t,s))}getSpecularTexture(){return this.getRef("specularTexture")}getSpecularTextureInfo(){return this.getRef("specularTexture")?this.getRef("specularTextureInfo"):null}setSpecularTexture(e){return this.setRef("specularTexture",e,{channels:_e})}getSpecularColorTexture(){return this.getRef("specularColorTexture")}getSpecularColorTextureInfo(){return this.getRef("specularColorTexture")?this.getRef("specularColorTextureInfo"):null}setSpecularColorTexture(e){return this.setRef("specularColorTexture",e,{channels:ye|Re|Ne})}}Ae.EXTENSION_NAME="KHR_materials_specular";const Se="KHR_materials_specular";class Ce extends e.Extension{constructor(...e){super(...e),this.extensionName=Se}createSpecular(){return new Ae(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[Se]){const n=this.createSpecular();e.materials[r].setExtension(Se,n);const o=t.extensions[Se];if(void 0!==o.specularFactor&&n.setSpecularFactor(o.specularFactor),void 0!==o.specularColorFactor&&n.setSpecularColorFactor(o.specularColorFactor),void 0!==o.specularTexture){const t=o.specularTexture;n.setSpecularTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSpecularTextureInfo(),t)}if(void 0!==o.specularColorTexture){const t=o.specularColorTexture;n.setSpecularColorTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSpecularColorTextureInfo(),t)}}}),this}write(t){const s=t.jsonDoc;return this.document.getRoot().listMaterials().forEach(r=>{const n=r.getExtension(Se);if(n){const o=t.materialIndexMap.get(r),i=s.json.materials[o];i.extensions=i.extensions||{};const a=i.extensions[Se]={};if(1!==n.getSpecularFactor()&&(a.specularFactor=n.getSpecularFactor()),e.MathUtils.eq(n.getSpecularColorFactor(),[1,1,1])||(a.specularColorFactor=n.getSpecularColorFactor()),n.getSpecularTexture()){const e=n.getSpecularTexture(),s=n.getSpecularTextureInfo();a.specularTexture=t.createTextureInfoDef(e,s)}if(n.getSpecularColorTexture()){const e=n.getSpecularColorTexture(),s=n.getSpecularColorTextureInfo();a.specularColorTexture=t.createTextureInfoDef(e,s)}}}),this}}Ce.EXTENSION_NAME=Se;const{R:Me}=e.TextureChannel;class Oe extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_transmission",this.propertyType="Transmission",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{transmissionFactor:0,transmissionTexture:null,transmissionTextureInfo:new e.TextureInfo(this.graph,"transmissionTextureInfo")})}getTransmissionFactor(){return this.get("transmissionFactor")}setTransmissionFactor(e){return this.set("transmissionFactor",e)}getTransmissionTexture(){return this.getRef("transmissionTexture")}getTransmissionTextureInfo(){return this.getRef("transmissionTexture")?this.getRef("transmissionTextureInfo"):null}setTransmissionTexture(e){return this.setRef("transmissionTexture",e,{channels:Me})}}Oe.EXTENSION_NAME="KHR_materials_transmission";const De="KHR_materials_transmission";class we extends e.Extension{constructor(...e){super(...e),this.extensionName=De}createTransmission(){return new Oe(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[De]){const n=this.createTransmission();e.materials[r].setExtension(De,n);const o=t.extensions[De];if(void 0!==o.transmissionFactor&&n.setTransmissionFactor(o.transmissionFactor),void 0!==o.transmissionTexture){const t=o.transmissionTexture;n.setTransmissionTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getTransmissionTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(De);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[De]={transmissionFactor:r.getTransmissionFactor()};if(r.getTransmissionTexture()){const t=r.getTransmissionTexture(),s=r.getTransmissionTextureInfo();i.transmissionTexture=e.createTextureInfoDef(t,s)}}}),this}}we.EXTENSION_NAME=De;class Fe extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_unlit",this.propertyType="Unlit",this.parentTypes=[e.PropertyType.MATERIAL]}}Fe.EXTENSION_NAME="KHR_materials_unlit";const be="KHR_materials_unlit";class Pe extends e.Extension{constructor(...e){super(...e),this.extensionName=be}createUnlit(){return new Fe(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{t.extensions&&t.extensions[be]&&e.materials[s].setExtension(be,this.createUnlit())}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{if(s.getExtension(be)){const r=e.materialIndexMap.get(s),n=t.json.materials[r];n.extensions=n.extensions||{},n.extensions[be]={}}}),this}}Pe.EXTENSION_NAME=be;class je extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_variants",this.propertyType="Mapping",this.parentTypes=["MappingList"]}getDefaults(){return Object.assign(super.getDefaults(),{material:null,variants:[]})}getMaterial(){return this.getRef("material")}setMaterial(e){return this.setRef("material",e)}addVariant(e){return this.addRef("variants",e)}removeVariant(e){return this.removeRef("variants",e)}listVariants(){return this.listRefs("variants")}}je.EXTENSION_NAME="KHR_materials_variants";class ve extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_variants",this.propertyType="MappingList",this.parentTypes=[e.PropertyType.PRIMITIVE]}getDefaults(){return Object.assign(super.getDefaults(),{mappings:[]})}addMapping(e){return this.addRef("mappings",e)}removeMapping(e){return this.removeRef("mappings",e)}listMappings(){return this.listRefs("mappings")}}ve.EXTENSION_NAME="KHR_materials_variants";class Ue extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_variants",this.propertyType="Variant",this.parentTypes=["MappingList"]}}Ue.EXTENSION_NAME="KHR_materials_variants";const Be="KHR_materials_variants";class ke extends e.Extension{constructor(...e){super(...e),this.extensionName=Be}createMappingList(){return new ve(this.document.getGraph())}createVariant(e=""){return new Ue(this.document.getGraph(),e)}createMapping(){return new je(this.document.getGraph())}listVariants(){return Array.from(this.properties).filter(e=>e instanceof Ue)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[Be])return this;const s=(t.json.extensions[Be].variants||[]).map(e=>this.createVariant().setName(e.name||""));return(t.json.meshes||[]).forEach((t,r)=>{const n=e.meshes[r];(t.primitives||[]).forEach((t,r)=>{if(!t.extensions||!t.extensions[Be])return;const o=this.createMappingList(),i=t.extensions[Be];for(const t of i.mappings){const r=this.createMapping();void 0!==t.material&&r.setMaterial(e.materials[t.material]);for(const e of t.variants||[])r.addVariant(s[e]);o.addMapping(r)}n.listPrimitives()[r].setExtension(Be,o)})}),this}write(e){const t=e.jsonDoc,s=this.listVariants();if(!s.length)return this;const r=[],n=new Map;for(const t of s)n.set(t,r.length),r.push(e.createPropertyDef(t));for(const t of this.document.getRoot().listMeshes()){const s=e.meshIndexMap.get(t);t.listPrimitives().forEach((t,r)=>{const o=t.getExtension(Be);if(!o)return;const i=e.jsonDoc.json.meshes[s].primitives[r],a=o.listMappings().map(t=>{const s=e.createPropertyDef(t),r=t.getMaterial();return r&&(s.material=e.materialIndexMap.get(r)),s.variants=t.listVariants().map(e=>n.get(e)),s});i.extensions=i.extensions||{},i.extensions[Be]={mappings:a}})}return t.json.extensions=t.json.extensions||{},t.json.extensions[Be]={variants:r},this}}ke.EXTENSION_NAME=Be;const{G:Ge}=e.TextureChannel;class Le extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_volume",this.propertyType="Volume",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{thicknessFactor:0,thicknessTexture:null,thicknessTextureInfo:new e.TextureInfo(this.graph,"thicknessTexture"),attenuationDistance:Infinity,attenuationColor:[1,1,1]})}getThicknessFactor(){return this.get("thicknessFactor")}setThicknessFactor(e){return this.set("thicknessFactor",e)}getThicknessTexture(){return this.getRef("thicknessTexture")}getThicknessTextureInfo(){return this.getRef("thicknessTexture")?this.getRef("thicknessTextureInfo"):null}setThicknessTexture(e){return this.setRef("thicknessTexture",e,{channels:Ge})}getAttenuationDistance(){return this.get("attenuationDistance")}setAttenuationDistance(e){return this.set("attenuationDistance",e)}getAttenuationColor(){return this.get("attenuationColor")}setAttenuationColor(e){return this.set("attenuationColor",e)}getAttenuationColorHex(){return e.ColorUtils.factorToHex(this.getAttenuationColor())}setAttenuationColorHex(t){const s=this.getAttenuationColor().slice();return this.set("attenuationColor",e.ColorUtils.hexToFactor(t,s))}}Le.EXTENSION_NAME="KHR_materials_volume";const He="KHR_materials_volume";class Ve extends e.Extension{constructor(...e){super(...e),this.extensionName=He}createVolume(){return new Le(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[He]){const n=this.createVolume();e.materials[r].setExtension(He,n);const o=t.extensions[He];if(void 0!==o.thicknessFactor&&n.setThicknessFactor(o.thicknessFactor),void 0!==o.attenuationDistance&&n.setAttenuationDistance(o.attenuationDistance),void 0!==o.attenuationColor&&n.setAttenuationColor(o.attenuationColor),void 0!==o.thicknessTexture){const t=o.thicknessTexture;n.setThicknessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getThicknessTextureInfo(),t)}}}),this}write(t){const s=t.jsonDoc;return this.document.getRoot().listMaterials().forEach(r=>{const n=r.getExtension(He);if(n){const o=t.materialIndexMap.get(r),i=s.json.materials[o];i.extensions=i.extensions||{};const a=i.extensions[He]={};if(n.getThicknessFactor()>0&&(a.thicknessFactor=n.getThicknessFactor()),Number.isFinite(n.getAttenuationDistance())&&(a.attenuationDistance=n.getAttenuationDistance()),e.MathUtils.eq(n.getAttenuationColor(),[1,1,1])||(a.attenuationColor=n.getAttenuationColor()),n.getThicknessTexture()){const e=n.getThicknessTexture(),s=n.getThicknessTextureInfo();a.thicknessTexture=t.createTextureInfoDef(e,s)}}}),this}}Ve.EXTENSION_NAME=He;const Xe="KHR_mesh_quantization";class Ke extends e.Extension{constructor(...e){super(...e),this.extensionName=Xe}read(e){return this}write(e){return this}}Ke.EXTENSION_NAME=Xe;const ze="KHR_texture_basisu";class qe{match(e){return 171===e[0]&&75===e[1]&&84===e[2]&&88===e[3]&&32===e[4]&&50===e[5]&&48===e[6]&&187===e[7]&&13===e[8]&&10===e[9]&&26===e[10]&&10===e[11]}getSize(e){const s=t.read(e);return[s.pixelWidth,s.pixelHeight]}getChannels(e){const s=t.read(e).dataFormatDescriptor[0];if(s.colorModel===t.KHR_DF_MODEL_ETC1S)return 2===s.samples.length&&15==(15&s.samples[1].channelType)?4:3;if(s.colorModel===t.KHR_DF_MODEL_UASTC)return 3==(15&s.samples[0].channelType)?4:3;throw new Error(`Unexpected KTX2 colorModel, "${s.colorModel}".`)}getGPUByteLength(e){const s=t.read(e),r=this.getChannels(e)>3;let n=0;for(let e=0;e<s.levels.length;e++){const t=s.levels[e];n+=t.uncompressedByteLength?t.uncompressedByteLength:Math.max(1,Math.floor(s.pixelWidth/Math.pow(2,e)))/4*(Math.max(1,Math.floor(s.pixelHeight/Math.pow(2,e)))/4)*(r?16:8)}return n}}class $e extends e.Extension{constructor(...t){super(...t),this.extensionName=ze,this.prereadTypes=[e.PropertyType.TEXTURE]}static register(){e.ImageUtils.registerFormat("image/ktx2",new qe)}preread(e){return e.jsonDoc.json.textures.forEach(e=>{e.extensions&&e.extensions[ze]&&(e.source=e.extensions[ze].source)}),this}read(e){return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listTextures().forEach(s=>{if("image/ktx2"===s.getMimeType()){const r=e.imageIndexMap.get(s);t.json.textures.forEach(e=>{e.source===r&&(e.extensions=e.extensions||{},e.extensions[ze]={source:e.source},delete e.source)})}}),this}}$e.EXTENSION_NAME=ze;class Qe extends e.ExtensionProperty{init(){this.extensionName="KHR_texture_transform",this.propertyType="Transform",this.parentTypes=[e.PropertyType.TEXTURE_INFO]}getDefaults(){return Object.assign(super.getDefaults(),{offset:[0,0],rotation:0,scale:[1,1],texCoord:null})}getOffset(){return this.get("offset")}setOffset(e){return this.set("offset",e)}getRotation(){return this.get("rotation")}setRotation(e){return this.set("rotation",e)}getScale(){return this.get("scale")}setScale(e){return this.set("scale",e)}getTexCoord(){return this.get("texCoord")}setTexCoord(e){return this.set("texCoord",e)}}Qe.EXTENSION_NAME="KHR_texture_transform";const Ye="KHR_texture_transform";class We extends e.Extension{constructor(...e){super(...e),this.extensionName=Ye}createTransform(){return new Qe(this.document.getGraph())}read(e){for(const[t,s]of Array.from(e.textureInfos.entries())){if(!s.extensions||!s.extensions[Ye])continue;const e=this.createTransform(),r=s.extensions[Ye];void 0!==r.offset&&e.setOffset(r.offset),void 0!==r.rotation&&e.setRotation(r.rotation),void 0!==r.scale&&e.setScale(r.scale),void 0!==r.texCoord&&e.setTexCoord(r.texCoord),t.setExtension(Ye,e)}return this}write(t){const s=Array.from(t.textureInfoDefMap.entries());for(const[t,r]of s){const s=t.getExtension(Ye);if(!s)continue;r.extensions=r.extensions||{};const n={},o=e.MathUtils.eq;o(s.getOffset(),[0,0])||(n.offset=s.getOffset()),0!==s.getRotation()&&(n.rotation=s.getRotation()),o(s.getScale(),[1,1])||(n.scale=s.getScale()),null!=s.getTexCoord()&&(n.texCoord=s.getTexCoord()),r.extensions[Ye]=n}return this}}We.EXTENSION_NAME=Ye;const Je=[e.PropertyType.ROOT,e.PropertyType.SCENE,e.PropertyType.NODE,e.PropertyType.MESH,e.PropertyType.MATERIAL,e.PropertyType.TEXTURE,e.PropertyType.ANIMATION];class Ze extends e.ExtensionProperty{init(){this.extensionName="KHR_xmp_json_ld",this.propertyType="Packet",this.parentTypes=Je}getDefaults(){return Object.assign(super.getDefaults(),{context:{},properties:{}})}getContext(){return this.get("context")}setContext(e){return this.set("context",{...e})}listProperties(){return Object.keys(this.get("properties"))}getProperty(e){const t=this.get("properties");return e in t?t[e]:null}setProperty(e,t){this._assertContext(e);const s={...this.get("properties")};return t?s[e]=t:delete s[e],this.set("properties",s)}toJSONLD(){return{"@context":et(this.get("context")),...et(this.get("properties"))}}fromJSONLD(e){const t=(e=et(e))["@context"];return t&&this.set("context",t),delete e["@context"],this.set("properties",e)}_assertContext(e){if(!(e.split(":")[0]in this.get("context")))throw new Error(`KHR_xmp_json_ld: Missing context for term, "${e}".`)}}function et(e){return JSON.parse(JSON.stringify(e))}Ze.EXTENSION_NAME="KHR_xmp_json_ld";const tt="KHR_xmp_json_ld";class st extends e.Extension{constructor(...e){super(...e),this.extensionName=tt}createPacket(){return new Ze(this.document.getGraph())}listPackets(){return Array.from(this.properties)}read(e){const t=e.jsonDoc.json.extensions?.[tt];if(!t||!t.packets)return this;const s=e.jsonDoc.json,r=this.document.getRoot(),n=t.packets.map(e=>this.createPacket().fromJSONLD(e)),o=[[s.asset],s.scenes,s.nodes,s.meshes,s.materials,s.images,s.animations],i=[[r],r.listScenes(),r.listNodes(),r.listMeshes(),r.listMaterials(),r.listTextures(),r.listAnimations()];for(let e=0;e<o.length;e++){const t=o[e]||[];for(let s=0;s<t.length;s++){const r=t[s];r.extensions&&r.extensions[tt]&&i[e][s].setExtension(tt,n[r.extensions[tt].packet])}}return this}write(t){const{json:s}=t.jsonDoc,r=[];for(const n of this.properties){r.push(n.toJSONLD());for(const o of n.listParents()){let n;switch(o.propertyType){case e.PropertyType.ROOT:n=s.asset;break;case e.PropertyType.SCENE:n=s.scenes[t.sceneIndexMap.get(o)];break;case e.PropertyType.NODE:n=s.nodes[t.nodeIndexMap.get(o)];break;case e.PropertyType.MESH:n=s.meshes[t.meshIndexMap.get(o)];break;case e.PropertyType.MATERIAL:n=s.materials[t.materialIndexMap.get(o)];break;case e.PropertyType.TEXTURE:n=s.images[t.imageIndexMap.get(o)];break;case e.PropertyType.ANIMATION:n=s.animations[t.animationIndexMap.get(o)];break;default:n=null,this.document.getLogger().warn(`[${tt}]: Unsupported parent property, "${o.propertyType}"`)}n&&(n.extensions=n.extensions||{},n.extensions[tt]={packet:r.length-1})}}return r.length>0&&(s.extensions=s.extensions||{},s.extensions[tt]={packets:r}),this}}st.EXTENSION_NAME=tt;const rt=[k,V,Q,J,te,ie,pe,Ce,Ie,we,Pe,ke,Ve,Ke,$e,We,st],nt=[n,E,R,...rt];exports.ALL_EXTENSIONS=nt,exports.Clearcoat=q,exports.DracoMeshCompression=k,exports.EmissiveStrength=Y,exports.INSTANCE_ATTRIBUTE="INSTANCE_ATTRIBUTE",exports.IOR=Z,exports.InstancedMesh=s,exports.Iridescence=ne,exports.KHRONOS_EXTENSIONS=rt,exports.Light=L,exports.LightsPunctual=V,exports.Mapping=je,exports.MappingList=ve,exports.MaterialsClearcoat=Q,exports.MaterialsEmissiveStrength=J,exports.MaterialsIOR=te,exports.MaterialsIridescence=ie,exports.MaterialsPBRSpecularGlossiness=pe,exports.MaterialsSheen=Ie,exports.MaterialsSpecular=Ce,exports.MaterialsTransmission=we,exports.MaterialsUnlit=Pe,exports.MaterialsVariants=ke,exports.MaterialsVolume=Ve,exports.MeshGPUInstancing=n,exports.MeshQuantization=Ke,exports.MeshoptCompression=E,exports.PBRSpecularGlossiness=he,exports.Packet=Ze,exports.Sheen=me,exports.Specular=Ae,exports.TextureBasisu=$e,exports.TextureTransform=We,exports.TextureWebP=R,exports.Transform=Qe,exports.Transmission=Oe,exports.Unlit=Fe,exports.Variant=Ue,exports.Volume=Le,exports.XMP=st;
var e=require("@gltf-transform/core"),t=require("ktx-parse");class s extends e.ExtensionProperty{init(){this.extensionName="EXT_mesh_gpu_instancing",this.propertyType="InstancedMesh",this.parentTypes=[e.PropertyType.NODE]}getDefaults(){return Object.assign(super.getDefaults(),{attributes:{}})}getAttribute(e){return this.getRefMap("attributes",e)}setAttribute(e,t){return this.setRefMap("attributes",e,t,{usage:"INSTANCE_ATTRIBUTE"})}listAttributes(){return this.listRefMapValues("attributes")}listSemantics(){return this.listRefMapKeys("attributes")}}s.EXTENSION_NAME="EXT_mesh_gpu_instancing";const r="EXT_mesh_gpu_instancing";class n extends e.Extension{constructor(...t){super(...t),this.extensionName=r,this.provideTypes=[e.PropertyType.NODE],this.prewriteTypes=[e.PropertyType.ACCESSOR]}createInstancedMesh(){return new s(this.document.getGraph())}read(e){return(e.jsonDoc.json.nodes||[]).forEach((t,s)=>{if(!t.extensions||!t.extensions[r])return;const n=t.extensions[r],o=this.createInstancedMesh();for(const t in n.attributes)o.setAttribute(t,e.accessors[n.attributes[t]]);e.nodes[s].setExtension(r,o)}),this}prewrite(e){e.accessorUsageGroupedByParent.add("INSTANCE_ATTRIBUTE");for(const t of this.properties)for(const s of t.listAttributes())e.addAccessorToUsageGroup(s,"INSTANCE_ATTRIBUTE");return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listNodes().forEach(s=>{const n=s.getExtension(r);if(n){const o=e.nodeIndexMap.get(s),i=t.json.nodes[o],a={attributes:{}};n.listSemantics().forEach(t=>{const s=n.getAttribute(t);a.attributes[t]=e.accessorIndexMap.get(s)}),i.extensions=i.extensions||{},i.extensions[r]=a}}),this}}var o,i,a;n.EXTENSION_NAME=r,function(e){e.QUANTIZE="quantize",e.FILTER="filter"}(o||(o={})),function(e){e.ATTRIBUTES="ATTRIBUTES",e.TRIANGLES="TRIANGLES",e.INDICES="INDICES"}(i||(i={})),function(e){e.NONE="NONE",e.OCTAHEDRAL="OCTAHEDRAL",e.QUATERNION="QUATERNION",e.EXPONENTIAL="EXPONENTIAL"}(a||(a={}));const{BYTE:c,SHORT:u,FLOAT:l}=e.Accessor.ComponentType,{normalize:h,denormalize:f}=e.MathUtils;function p(t,s,r,n){const{filter:o,bits:p}=n,x={array:t.getArray(),byteStride:t.getElementSize()*t.getComponentSize(),componentType:t.getComponentType(),normalized:t.getNormalized()};if(r!==i.ATTRIBUTES)return x;if(o!==a.NONE){let e=t.getNormalized()?function(e){const t=e.getComponentType(),s=e.getArray(),r=new Float32Array(s.length);for(let e=0;e<s.length;e++)r[e]=f(s[e],t);return r}(t):new Float32Array(x.array);switch(o){case a.EXPONENTIAL:x.byteStride=4*t.getElementSize(),x.componentType=l,x.normalized=!1,x.array=s.encodeFilterExp(e,t.getCount(),x.byteStride,p);break;case a.OCTAHEDRAL:x.byteStride=p>8?8:4,x.componentType=p>8?u:c,x.normalized=!0,e=3===t.getElementSize()?function(e){const t=new Float32Array(4*e.length/3);for(let s=0,r=e.length/3;s<r;s++)t[4*s]=e[3*s],t[4*s+1]=e[3*s+1],t[4*s+2]=e[3*s+2];return t}(e):e,x.array=s.encodeFilterOct(e,t.getCount(),x.byteStride,p);break;case a.QUATERNION:x.byteStride=8,x.componentType=u,x.normalized=!0,x.array=s.encodeFilterQuat(e,t.getCount(),x.byteStride,p);break;default:throw new Error("Invalid filter.")}x.min=t.getMin([]),x.max=t.getMax([]),t.getNormalized()&&(x.min=x.min.map(e=>f(e,t.getComponentType())),x.max=x.max.map(e=>f(e,t.getComponentType()))),x.normalized&&(x.min=x.min.map(e=>h(e,x.componentType)),x.max=x.max.map(e=>h(e,x.componentType)))}else x.byteStride%4&&(x.array=function(t,s){const r=e.BufferUtils.padNumber(t.BYTES_PER_ELEMENT*s)/t.BYTES_PER_ELEMENT,n=new t.constructor(t.length/s*r);for(let e=0;e*s<t.length;e++)for(let o=0;o<s;o++)n[e*r+o]=t[e*s+o];return n}(x.array,t.getElementSize()),x.byteStride=x.array.byteLength/t.getCount());return x}function x(t,s){return s===e.WriterContext.BufferViewUsage.ELEMENT_ARRAY_BUFFER?t.listParents().some(t=>t instanceof e.Primitive&&t.getMode()===e.Primitive.Mode.TRIANGLES)?i.TRIANGLES:i.INDICES:i.ATTRIBUTES}function g(t,s){const r=s.getGraph().listParentEdges(t).filter(t=>!(t.getParent()instanceof e.Root));for(const e of r){const s=e.getName(),r=e.getAttributes().key||"";if("indices"===s)return{filter:a.NONE};if("attributes"===s){if("POSITION"===r)return{filter:a.NONE};if("TEXCOORD_0"===r)return{filter:a.NONE};if("NORMAL"===r)return{filter:a.OCTAHEDRAL,bits:8};if("TANGENT"===r)return{filter:a.OCTAHEDRAL,bits:8};if(r.startsWith("JOINTS_"))return{filter:a.NONE};if(r.startsWith("WEIGHTS_"))return{filter:a.NONE}}if("output"===s){const e=T(t);return"rotation"===e?{filter:a.QUATERNION,bits:16}:"translation"===e||"scale"===e?{filter:a.EXPONENTIAL,bits:12}:{filter:a.NONE}}if("input"===s)return{filter:a.NONE};if("inverseBindMatrices"===s)return{filter:a.NONE}}return{filter:a.NONE}}function T(t){for(const s of t.listParents())if(s instanceof e.AnimationSampler)for(const t of s.listParents())if(t instanceof e.AnimationChannel)return t.getTargetPath();return null}const d="EXT_meshopt_compression",m={method:o.QUANTIZE};class E extends e.Extension{constructor(...t){super(...t),this.extensionName=d,this.prereadTypes=[e.PropertyType.BUFFER,e.PropertyType.PRIMITIVE],this.prewriteTypes=[e.PropertyType.BUFFER,e.PropertyType.ACCESSOR],this.readDependencies=["meshopt.decoder"],this.writeDependencies=["meshopt.encoder"],this._decoder=null,this._decoderFallbackBufferMap=new Map,this._encoder=null,this._encoderOptions=m,this._encoderFallbackBuffer=null,this._encoderBufferViews={},this._encoderBufferViewData={},this._encoderBufferViewAccessors={}}install(e,t){return"meshopt.decoder"===e&&(this._decoder=t),"meshopt.encoder"===e&&(this._encoder=t),this}setEncoderOptions(e){return this._encoderOptions={...m,...e},this}preread(t,s){if(!this._decoder){if(!this.isRequired())return this;throw new Error(`[${d}] Please install extension dependency, "meshopt.decoder".`)}if(!this._decoder.supported){if(!this.isRequired())return this;throw new Error(`[${d}]: Missing WASM support.`)}return s===e.PropertyType.BUFFER?this._prereadBuffers(t):s===e.PropertyType.PRIMITIVE&&this._prereadPrimitives(t),this}_prereadBuffers(t){const s=t.jsonDoc;(s.json.bufferViews||[]).forEach((r,n)=>{if(!r.extensions||!r.extensions[d])return;const o=r.extensions[d],i=o.byteOffset||0,a=o.byteLength||0,c=o.count,u=o.byteStride,l=new Uint8Array(c*u),h=s.json.buffers[r.buffer],f=e.BufferUtils.toView(h.uri?s.resources[h.uri]:s.resources[e.GLB_BUFFER],i,a);this._decoder.decodeGltfBuffer(l,c,u,f,o.mode,o.filter),t.bufferViews[n]=l})}_prereadPrimitives(e){const t=e.jsonDoc;(t.json.bufferViews||[]).forEach(s=>{var r;s.extensions&&s.extensions[d]&&(r=t.json.buffers[s.buffer]).extensions&&r.extensions.EXT_meshopt_compression&&r.extensions.EXT_meshopt_compression.fallback&&this._decoderFallbackBufferMap.set(e.buffers[s.buffer],e.buffers[s.extensions[d].buffer])})}read(t){if(!this.isRequired())return this;for(const[t,s]of this._decoderFallbackBufferMap){for(const r of t.listParents())r instanceof e.Accessor&&r.swap(t,s);t.dispose()}return this}prewrite(t,s){return s===e.PropertyType.ACCESSOR?this._prewriteAccessors(t):s===e.PropertyType.BUFFER&&this._prewriteBuffers(t),this}_prewriteAccessors(t){const s=t.jsonDoc.json,r=this._encoder,n=this._encoderOptions,i=this.document.createBuffer(),c=this.document.getRoot().listBuffers().indexOf(i);this._encoderFallbackBuffer=i,this._encoderBufferViews={},this._encoderBufferViewData={},this._encoderBufferViewAccessors={};for(const i of this.document.getRoot().listAccessors()){if("weights"===T(i))continue;const u=t.getAccessorUsage(i),l=x(i,u),h=n.method===o.FILTER?g(i,this.document):{filter:a.NONE},f=p(i,r,l,h),{array:m,byteStride:E}=f,I=i.getBuffer();if(!I)throw new Error(`${d}: Missing buffer for accessor.`);const y=this.document.getRoot().listBuffers().indexOf(I),R=[u,l,h.filter,E,y].join(":");let N=this._encoderBufferViews[R],_=this._encoderBufferViewData[R],A=this._encoderBufferViewAccessors[R];N&&_||(A=this._encoderBufferViewAccessors[R]=[],_=this._encoderBufferViewData[R]=[],N=this._encoderBufferViews[R]={buffer:c,target:e.WriterContext.USAGE_TO_TARGET[u],byteOffset:0,byteLength:0,byteStride:u===e.WriterContext.BufferViewUsage.ARRAY_BUFFER?E:void 0,extensions:{[d]:{buffer:y,byteOffset:0,byteLength:0,mode:l,filter:h.filter!==a.NONE?h.filter:void 0,byteStride:E,count:0}}});const S=t.createAccessorDef(i);S.componentType=f.componentType,S.normalized=f.normalized,S.byteOffset=N.byteLength,S.min&&f.min&&(S.min=f.min),S.max&&f.max&&(S.max=f.max),t.accessorIndexMap.set(i,s.accessors.length),s.accessors.push(S),A.push(S),_.push(new Uint8Array(m.buffer,m.byteOffset,m.byteLength)),N.byteLength+=m.byteLength,N.extensions.EXT_meshopt_compression.count+=i.getCount()}}_prewriteBuffers(t){const s=this._encoder;for(const r in this._encoderBufferViews){const n=this._encoderBufferViews[r],o=this._encoderBufferViewData[r],i=this.document.getRoot().listBuffers()[n.extensions[d].buffer],a=t.otherBufferViews.get(i)||[],{count:c,byteStride:u,mode:l}=n.extensions[d],h=e.BufferUtils.concat(o),f=s.encodeGltfBuffer(h,c,u,l),p=e.BufferUtils.pad(f);n.extensions[d].byteLength=f.byteLength,o.length=0,o.push(p),a.push(p),t.otherBufferViews.set(i,a)}}write(t){let s=0;for(const r in this._encoderBufferViews){const n=this._encoderBufferViews[r],o=t.otherBufferViewsIndexMap.get(this._encoderBufferViewData[r][0]),i=this._encoderBufferViewAccessors[r];for(const e of i)e.bufferView=o;const a=t.jsonDoc.json.bufferViews[o],c=a.byteOffset||0;Object.assign(a,n),a.byteOffset=s,a.extensions[d].byteOffset=c,s+=e.BufferUtils.padNumber(n.byteLength)}const r=this._encoderFallbackBuffer,n=t.bufferIndexMap.get(r),o=t.jsonDoc.json.buffers[n];return o.byteLength=s,o.extensions={[d]:{fallback:!0}},r.dispose(),this}}E.EXTENSION_NAME=d,E.EncoderMethod=o;const I="EXT_texture_webp";class y{match(e){return e.length>=12&&87===e[8]&&69===e[9]&&66===e[10]&&80===e[11]}getSize(t){const s=e.BufferUtils.decodeText(t.slice(0,4)),r=e.BufferUtils.decodeText(t.slice(8,12));if("RIFF"!==s||"WEBP"!==r)return null;const n=new DataView(t.buffer,t.byteOffset);let o=12;for(;o<n.byteLength;){const t=e.BufferUtils.decodeText(new Uint8Array([n.getUint8(o),n.getUint8(o+1),n.getUint8(o+2),n.getUint8(o+3)])),s=n.getUint32(o+4,!0);if("VP8 "===t)return[16383&n.getInt16(o+14,!0),16383&n.getInt16(o+16,!0)];if("VP8L"===t){const e=n.getUint8(o+9),t=n.getUint8(o+10),s=n.getUint8(o+11);return[1+((63&t)<<8|e),1+((15&n.getUint8(o+12))<<10|s<<2|(192&t)>>6)]}o+=8+s+s%2}return null}getChannels(e){return 4}}class R extends e.Extension{constructor(...t){super(...t),this.extensionName=I,this.prereadTypes=[e.PropertyType.TEXTURE]}static register(){e.ImageUtils.registerFormat("image/webp",new y)}preread(e){return(e.jsonDoc.json.textures||[]).forEach(e=>{e.extensions&&e.extensions[I]&&(e.source=e.extensions[I].source)}),this}read(e){return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listTextures().forEach(s=>{if("image/webp"===s.getMimeType()){const r=e.imageIndexMap.get(s);(t.json.textures||[]).forEach(e=>{e.source===r&&(e.extensions=e.extensions||{},e.extensions[I]={source:e.source},delete e.source)})}}),this}}R.EXTENSION_NAME=I;const N="KHR_draco_mesh_compression";let _,A,S,C;function M(e,t){const s=new _.DecoderBuffer;try{if(s.Init(t,t.length),e.GetEncodedGeometryType(s)!==_.TRIANGULAR_MESH)throw new Error(`[${N}] Unknown geometry type.`);const r=new _.Mesh;if(!e.DecodeBufferToMesh(s,r).ok()||0===r.ptr)throw new Error(`[${N}] Decoding failure.`);return r}finally{_.destroy(s)}}function O(e,t){const s=3*t.num_faces();let r,n;if(t.num_points()<=65534){const o=s*Uint16Array.BYTES_PER_ELEMENT;r=_._malloc(o),e.GetTrianglesUInt16Array(t,o,r),n=new Uint16Array(_.HEAPU16.buffer,r,s).slice()}else{const o=s*Uint32Array.BYTES_PER_ELEMENT;r=_._malloc(o),e.GetTrianglesUInt32Array(t,o,r),n=new Uint32Array(_.HEAPU32.buffer,r,s).slice()}return _._free(r),n}function D(e,t,s,r){const n=S[r.componentType],o=A[r.componentType],i=s.num_components(),a=t.num_points()*i,c=a*o.BYTES_PER_ELEMENT,u=_._malloc(c);e.GetAttributeDataArrayForAllPoints(t,s,n,c,u);const l=new o(_.HEAPF32.buffer,u,a).slice();return _._free(u),l}var w,F;!function(e){e[e.EDGEBREAKER=1]="EDGEBREAKER",e[e.SEQUENTIAL=0]="SEQUENTIAL"}(w||(w={})),function(e){e.POSITION="POSITION",e.NORMAL="NORMAL",e.COLOR="COLOR",e.TEX_COORD="TEX_COORD",e.GENERIC="GENERIC"}(F||(F={}));const b={[F.POSITION]:14,[F.NORMAL]:10,[F.COLOR]:8,[F.TEX_COORD]:12,[F.GENERIC]:12},P={decodeSpeed:5,encodeSpeed:5,method:w.EDGEBREAKER,quantizationBits:b,quantizationVolume:"mesh"};function j(e,t=P){const s={...P,...t};s.quantizationBits={...b,...t.quantizationBits};const r=new C.Encoder,n=new C.MeshBuilder,o=new C.Mesh,i={},a=new C.DracoInt8Array;for(const t of e.listSemantics()){const a=e.getAttribute(t),c=v(t),u=U(n,a.getComponentType(),o,C[c],a.getCount(),a.getElementSize(),a.getArray());if(-1===u)throw new Error(`Error compressing "${t}" attribute.`);if(i[t]=u,"mesh"===s.quantizationVolume||"POSITION"!==t)r.SetAttributeQuantization(C[c],s.quantizationBits[c]);else{if("object"!=typeof s.quantizationVolume)throw new Error("Invalid quantization volume state.");{const{quantizationVolume:e}=s,t=Math.max(e.max[0]-e.min[0],e.max[1]-e.min[1],e.max[2]-e.min[2]);r.SetAttributeExplicitQuantization(C[c],s.quantizationBits[c],a.getElementSize(),e.min,t)}}}const c=e.getIndices();if(!c)throw new B("Primitive must have indices.");n.AddFacesToMesh(o,c.getCount()/3,c.getArray()),r.SetSpeedOptions(s.encodeSpeed,s.decodeSpeed),r.SetTrackEncodedProperties(!0),s.method===w.SEQUENTIAL||e.listTargets().length>0?r.SetEncodingMethod(C.MESH_SEQUENTIAL_ENCODING):r.SetEncodingMethod(C.MESH_EDGEBREAKER_ENCODING);const u=r.EncodeMeshToDracoBuffer(o,a);if(u<=0)throw new B("Error applying Draco compression.");const l=new Uint8Array(u);for(let e=0;e<u;++e)l[e]=a.GetValue(e);const h=e.getAttribute("POSITION").getCount(),f=r.GetNumberOfEncodedPoints(),p=3*r.GetNumberOfEncodedFaces();if(e.listTargets().length>0&&f!==h)throw new B('Compression reduced vertex count unexpectedly, corrupting morph targets. Applying the "weld" function before compression may resolve the issue.');return C.destroy(a),C.destroy(o),C.destroy(n),C.destroy(r),{numVertices:f,numIndices:p,data:l,attributeIDs:i}}function v(e){return"POSITION"===e?F.POSITION:"NORMAL"===e?F.NORMAL:e.startsWith("COLOR_")?F.COLOR:e.startsWith("TEXCOORD_")?F.TEX_COORD:F.GENERIC}function U(t,s,r,n,o,i,a){switch(s){case e.Accessor.ComponentType.UNSIGNED_BYTE:return t.AddUInt8Attribute(r,n,o,i,a);case e.Accessor.ComponentType.BYTE:return t.AddInt8Attribute(r,n,o,i,a);case e.Accessor.ComponentType.UNSIGNED_SHORT:return t.AddUInt16Attribute(r,n,o,i,a);case e.Accessor.ComponentType.SHORT:return t.AddInt16Attribute(r,n,o,i,a);case e.Accessor.ComponentType.UNSIGNED_INT:return t.AddUInt32Attribute(r,n,o,i,a);case e.Accessor.ComponentType.FLOAT:return t.AddFloatAttribute(r,n,o,i,a);default:throw new Error(`Unexpected component type, "${s}".`)}}class B extends Error{}const k="KHR_draco_mesh_compression";class G extends e.Extension{constructor(...t){super(...t),this.extensionName=k,this.prereadTypes=[e.PropertyType.PRIMITIVE],this.prewriteTypes=[e.PropertyType.ACCESSOR],this.readDependencies=["draco3d.decoder"],this.writeDependencies=["draco3d.encoder"],this._decoderModule=null,this._encoderModule=null,this._encoderOptions={}}install(t,s){return"draco3d.decoder"===t&&(this._decoderModule=s,_=this._decoderModule,A={[e.Accessor.ComponentType.FLOAT]:Float32Array,[e.Accessor.ComponentType.UNSIGNED_INT]:Uint32Array,[e.Accessor.ComponentType.UNSIGNED_SHORT]:Uint16Array,[e.Accessor.ComponentType.UNSIGNED_BYTE]:Uint8Array,[e.Accessor.ComponentType.SHORT]:Int16Array,[e.Accessor.ComponentType.BYTE]:Int8Array},S={[e.Accessor.ComponentType.FLOAT]:_.DT_FLOAT32,[e.Accessor.ComponentType.UNSIGNED_INT]:_.DT_UINT32,[e.Accessor.ComponentType.UNSIGNED_SHORT]:_.DT_UINT16,[e.Accessor.ComponentType.UNSIGNED_BYTE]:_.DT_UINT8,[e.Accessor.ComponentType.SHORT]:_.DT_INT16,[e.Accessor.ComponentType.BYTE]:_.DT_INT8}),"draco3d.encoder"===t&&(this._encoderModule=s,C=this._encoderModule),this}setEncoderOptions(e){return this._encoderOptions=e,this}preread(t){if(!this._decoderModule)throw new Error(`[${k}] Please install extension dependency, "draco3d.decoder".`);const s=this.document.getLogger(),r=t.jsonDoc,n=new Map;try{const o=r.json.meshes||[];for(const i of o)for(const o of i.primitives){if(!o.extensions||!o.extensions[k])continue;const i=o.extensions[k];let[a,c]=n.get(i.bufferView)||[];if(!c||!a){const t=r.json.bufferViews[i.bufferView],o=r.json.buffers[t.buffer],u=e.BufferUtils.toView(o.uri?r.resources[o.uri]:r.resources[e.GLB_BUFFER],t.byteOffset||0,t.byteLength);a=new this._decoderModule.Decoder,c=M(a,u),n.set(i.bufferView,[a,c]),s.debug(`[${k}] Decompressed ${u.byteLength} bytes.`)}for(const e in o.attributes){const s=t.jsonDoc.json.accessors[o.attributes[e]],r=a.GetAttributeByUniqueId(c,i.attributes[e]),n=D(a,c,r,s);t.accessors[o.attributes[e]].setArray(n)}void 0!==o.indices&&t.accessors[o.indices].setArray(O(a,c))}}finally{for(const[e,t]of Array.from(n.values()))this._decoderModule.destroy(e),this._decoderModule.destroy(t)}return this}read(e){return this}prewrite(t,s){if(!this._encoderModule)throw new Error(`[${k}] Please install extension dependency, "draco3d.encoder".`);const r=this.document.getLogger();r.debug(`[${k}] Compression options: ${JSON.stringify(this._encoderOptions)}`);const n=function(t){const s=t.getLogger(),r=new Set,n=new Set;for(const o of t.getRoot().listMeshes())for(const t of o.listPrimitives())t.getIndices()?t.getMode()!==e.Primitive.Mode.TRIANGLES?(n.add(t),s.warn(`[${k}] Skipping Draco compression on non-TRIANGLES primitive.`)):r.add(t):(n.add(t),s.warn(`[${k}] Skipping Draco compression on non-indexed primitive.`));const o=t.getRoot().listAccessors(),i=new Map;for(let e=0;e<o.length;e++)i.set(o[e],e);const a=new Map,c=new Set,u=new Map;for(const e of Array.from(r)){let s=L(e,i);if(c.has(s))u.set(e,s);else{if(a.has(e.getIndices())){const s=e.getIndices(),r=s.clone();i.set(r,t.getRoot().listAccessors().length-1),e.swap(s,r)}for(const s of e.listAttributes())if(a.has(s)){const r=s.clone();i.set(r,t.getRoot().listAccessors().length-1),e.swap(s,r)}s=L(e,i),c.add(s),u.set(e,s),a.set(e.getIndices(),s);for(const t of e.listAttributes())a.set(t,s)}}for(const t of Array.from(a.keys())){const s=new Set(t.listParents().map(e=>e.propertyType));if(2!==s.size||!s.has(e.PropertyType.PRIMITIVE)||!s.has(e.PropertyType.ROOT))throw new Error(`[${k}] Compressed accessors must only be used as indices or vertex attributes.`)}for(const e of Array.from(r)){const t=u.get(e),s=e.getIndices();if(a.get(s)!==t||e.listAttributes().some(e=>a.get(e)!==t))throw new Error(`[${k}] Draco primitives must share all, or no, accessors.`)}for(const e of Array.from(n)){const t=e.getIndices();if(a.has(t)||e.listAttributes().some(e=>a.has(e)))throw new Error(`[${k}] Accessor cannot be shared by compressed and uncompressed primitives.`)}return u}(this.document),o=new Map;let i="mesh";"scene"===this._encoderOptions.quantizationVolume&&(1!==this.document.getRoot().listScenes().length?r.warn(`[${k}]: quantizationVolume=scene requires exactly 1 scene.`):i=e.bounds(this.document.getRoot().listScenes().pop()));for(const e of Array.from(n.keys())){const s=n.get(e);if(!s)throw new Error("Unexpected primitive.");if(o.has(s)){o.set(s,o.get(s));continue}const a=e.getIndices(),c=t.jsonDoc.json.accessors;let u;try{u=j(e,{...this._encoderOptions,quantizationVolume:i})}catch(e){if(e instanceof B){r.warn(`[${k}]: ${e.message} Skipping primitive compression.`);continue}throw e}o.set(s,u);const l=t.createAccessorDef(a);l.count=u.numIndices,t.accessorIndexMap.set(a,c.length),c.push(l);for(const s of e.listSemantics()){const r=e.getAttribute(s),n=t.createAccessorDef(r);n.count=u.numVertices,t.accessorIndexMap.set(r,c.length),c.push(n)}const h=e.getAttribute("POSITION").getBuffer()||this.document.getRoot().listBuffers()[0];t.otherBufferViews.has(h)||t.otherBufferViews.set(h,[]),t.otherBufferViews.get(h).push(u.data)}return r.debug(`[${k}] Compressed ${n.size} primitives.`),t.extensionData[k]={primitiveHashMap:n,primitiveEncodingMap:o},this}write(e){const t=e.extensionData[k];for(const s of this.document.getRoot().listMeshes()){const r=e.jsonDoc.json.meshes[e.meshIndexMap.get(s)];for(let n=0;n<s.listPrimitives().length;n++){const o=s.listPrimitives()[n],i=r.primitives[n],a=t.primitiveHashMap.get(o);if(!a)continue;const c=t.primitiveEncodingMap.get(a);c&&(i.extensions=i.extensions||{},i.extensions[k]={bufferView:e.otherBufferViewsIndexMap.get(c.data),attributes:c.attributeIDs})}}if(!t.primitiveHashMap.size){const t=e.jsonDoc.json;t.extensionsUsed=(t.extensionsUsed||[]).filter(e=>e!==k),t.extensionsRequired=(t.extensionsRequired||[]).filter(e=>e!==k)}return this}}function L(e,t){const s=[],r=e.getIndices();s.push(t.get(r));for(const r of e.listAttributes())s.push(t.get(r));return s.sort().join("|")}G.EXTENSION_NAME=k,G.EncoderMethod=w;class H extends e.ExtensionProperty{init(){this.extensionName="KHR_lights_punctual",this.propertyType="Light",this.parentTypes=[e.PropertyType.NODE]}getDefaults(){return Object.assign(super.getDefaults(),{color:[1,1,1],intensity:1,type:H.Type.POINT,range:null,innerConeAngle:0,outerConeAngle:Math.PI/4})}getColor(){return this.get("color")}setColor(e){return this.set("color",e)}getColorHex(){return e.ColorUtils.factorToHex(this.getColor())}setColorHex(t){const s=this.getColor().slice();return e.ColorUtils.hexToFactor(t,s),this.setColor(s)}getIntensity(){return this.get("intensity")}setIntensity(e){return this.set("intensity",e)}getType(){return this.get("type")}setType(e){return this.set("type",e)}getRange(){return this.get("range")}setRange(e){return this.set("range",e)}getInnerConeAngle(){return this.get("innerConeAngle")}setInnerConeAngle(e){return this.set("innerConeAngle",e)}getOuterConeAngle(){return this.get("outerConeAngle")}setOuterConeAngle(e){return this.set("outerConeAngle",e)}}H.EXTENSION_NAME="KHR_lights_punctual",H.Type={POINT:"point",SPOT:"spot",DIRECTIONAL:"directional"};const V="KHR_lights_punctual";class X extends e.Extension{constructor(...e){super(...e),this.extensionName=V}createLight(e=""){return new H(this.document.getGraph(),e)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[V])return this;const s=(t.json.extensions[V].lights||[]).map(e=>{const t=this.createLight().setName(e.name||"").setType(e.type);return void 0!==e.color&&t.setColor(e.color),void 0!==e.intensity&&t.setIntensity(e.intensity),void 0!==e.range&&t.setRange(e.range),void 0!==e.spot?.innerConeAngle&&t.setInnerConeAngle(e.spot.innerConeAngle),void 0!==e.spot?.outerConeAngle&&t.setOuterConeAngle(e.spot.outerConeAngle),t});return t.json.nodes.forEach((t,r)=>{t.extensions&&t.extensions[V]&&e.nodes[r].setExtension(V,s[t.extensions[V].light])}),this}write(t){const s=t.jsonDoc;if(0===this.properties.size)return this;const r=[],n=new Map;for(const t of this.properties){const s=t,o={type:s.getType()};e.MathUtils.eq(s.getColor(),[1,1,1])||(o.color=s.getColor()),1!==s.getIntensity()&&(o.intensity=s.getIntensity()),null!=s.getRange()&&(o.range=s.getRange()),s.getName()&&(o.name=s.getName()),s.getType()===H.Type.SPOT&&(o.spot={innerConeAngle:s.getInnerConeAngle(),outerConeAngle:s.getOuterConeAngle()}),r.push(o),n.set(s,r.length-1)}return this.document.getRoot().listNodes().forEach(e=>{const r=e.getExtension(V);if(r){const o=t.nodeIndexMap.get(e),i=s.json.nodes[o];i.extensions=i.extensions||{},i.extensions[V]={light:n.get(r)}}}),s.json.extensions=s.json.extensions||{},s.json.extensions[V]={lights:r},this}}X.EXTENSION_NAME=V;const{R:K,G:z,B:q}=e.TextureChannel;class $ extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_clearcoat",this.propertyType="Clearcoat",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{clearcoatFactor:0,clearcoatTexture:null,clearcoatTextureInfo:new e.TextureInfo(this.graph,"clearcoatTextureInfo"),clearcoatRoughnessFactor:0,clearcoatRoughnessTexture:null,clearcoatRoughnessTextureInfo:new e.TextureInfo(this.graph,"clearcoatRoughnessTextureInfo"),clearcoatNormalScale:1,clearcoatNormalTexture:null,clearcoatNormalTextureInfo:new e.TextureInfo(this.graph,"clearcoatNormalTextureInfo")})}getClearcoatFactor(){return this.get("clearcoatFactor")}setClearcoatFactor(e){return this.set("clearcoatFactor",e)}getClearcoatTexture(){return this.getRef("clearcoatTexture")}getClearcoatTextureInfo(){return this.getRef("clearcoatTexture")?this.getRef("clearcoatTextureInfo"):null}setClearcoatTexture(e){return this.setRef("clearcoatTexture",e,{channels:K})}getClearcoatRoughnessFactor(){return this.get("clearcoatRoughnessFactor")}setClearcoatRoughnessFactor(e){return this.set("clearcoatRoughnessFactor",e)}getClearcoatRoughnessTexture(){return this.getRef("clearcoatRoughnessTexture")}getClearcoatRoughnessTextureInfo(){return this.getRef("clearcoatRoughnessTexture")?this.getRef("clearcoatRoughnessTextureInfo"):null}setClearcoatRoughnessTexture(e){return this.setRef("clearcoatRoughnessTexture",e,{channels:z})}getClearcoatNormalScale(){return this.get("clearcoatNormalScale")}setClearcoatNormalScale(e){return this.set("clearcoatNormalScale",e)}getClearcoatNormalTexture(){return this.getRef("clearcoatNormalTexture")}getClearcoatNormalTextureInfo(){return this.getRef("clearcoatNormalTexture")?this.getRef("clearcoatNormalTextureInfo"):null}setClearcoatNormalTexture(e){return this.setRef("clearcoatNormalTexture",e,{channels:K|z|q})}}$.EXTENSION_NAME="KHR_materials_clearcoat";const Q="KHR_materials_clearcoat";class Y extends e.Extension{constructor(...e){super(...e),this.extensionName=Q}createClearcoat(){return new $(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[Q]){const n=this.createClearcoat();e.materials[r].setExtension(Q,n);const o=t.extensions[Q];if(void 0!==o.clearcoatFactor&&n.setClearcoatFactor(o.clearcoatFactor),void 0!==o.clearcoatRoughnessFactor&&n.setClearcoatRoughnessFactor(o.clearcoatRoughnessFactor),void 0!==o.clearcoatTexture){const t=o.clearcoatTexture;n.setClearcoatTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getClearcoatTextureInfo(),t)}if(void 0!==o.clearcoatRoughnessTexture){const t=o.clearcoatRoughnessTexture;n.setClearcoatRoughnessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getClearcoatRoughnessTextureInfo(),t)}if(void 0!==o.clearcoatNormalTexture){const t=o.clearcoatNormalTexture;n.setClearcoatNormalTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getClearcoatNormalTextureInfo(),t),void 0!==t.scale&&n.setClearcoatNormalScale(t.scale)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(Q);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[Q]={clearcoatFactor:r.getClearcoatFactor(),clearcoatRoughnessFactor:r.getClearcoatRoughnessFactor()};if(r.getClearcoatTexture()){const t=r.getClearcoatTexture(),s=r.getClearcoatTextureInfo();i.clearcoatTexture=e.createTextureInfoDef(t,s)}if(r.getClearcoatRoughnessTexture()){const t=r.getClearcoatRoughnessTexture(),s=r.getClearcoatRoughnessTextureInfo();i.clearcoatRoughnessTexture=e.createTextureInfoDef(t,s)}if(r.getClearcoatNormalTexture()){const t=r.getClearcoatNormalTexture(),s=r.getClearcoatNormalTextureInfo();i.clearcoatNormalTexture=e.createTextureInfoDef(t,s),1!==r.getClearcoatNormalScale()&&(i.clearcoatNormalTexture.scale=r.getClearcoatNormalScale())}}}),this}}Y.EXTENSION_NAME=Q;class W extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_emissive_strength",this.propertyType="EmissiveStrength",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{emissiveStrength:1})}getEmissiveStrength(){return this.get("emissiveStrength")}setEmissiveStrength(e){return this.set("emissiveStrength",e)}}W.EXTENSION_NAME="KHR_materials_emissive_strength";const J="KHR_materials_emissive_strength";class Z extends e.Extension{constructor(...e){super(...e),this.extensionName=J}createEmissiveStrength(){return new W(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[J]){const r=this.createEmissiveStrength();e.materials[s].setExtension(J,r);const n=t.extensions[J];void 0!==n.emissiveStrength&&r.setEmissiveStrength(n.emissiveStrength)}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(J);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{},o.extensions[J]={emissiveStrength:r.getEmissiveStrength()}}}),this}}Z.EXTENSION_NAME=J;class ee extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_ior",this.propertyType="IOR",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{ior:0})}getIOR(){return this.get("ior")}setIOR(e){return this.set("ior",e)}}ee.EXTENSION_NAME="KHR_materials_ior";const te="KHR_materials_ior";class se extends e.Extension{constructor(...e){super(...e),this.extensionName=te}createIOR(){return new ee(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[te]){const r=this.createIOR();e.materials[s].setExtension(te,r);const n=t.extensions[te];void 0!==n.ior&&r.setIOR(n.ior)}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(te);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{},o.extensions[te]={ior:r.getIOR()}}}),this}}se.EXTENSION_NAME=te;const{R:re,G:ne}=e.TextureChannel;class oe extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_iridescence",this.propertyType="Iridescence",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{iridescenceFactor:0,iridescenceTexture:null,iridescenceTextureInfo:new e.TextureInfo(this.graph,"iridescenceTextureInfo"),iridescenceIOR:1.3,iridescenceThicknessMinimum:100,iridescenceThicknessMaximum:400,iridescenceThicknessTexture:null,iridescenceThicknessTextureInfo:new e.TextureInfo(this.graph,"iridescenceThicknessTextureInfo")})}getIridescenceFactor(){return this.get("iridescenceFactor")}setIridescenceFactor(e){return this.set("iridescenceFactor",e)}getIridescenceTexture(){return this.getRef("iridescenceTexture")}getIridescenceTextureInfo(){return this.getRef("iridescenceTexture")?this.getRef("iridescenceTextureInfo"):null}setIridescenceTexture(e){return this.setRef("iridescenceTexture",e,{channels:re})}getIridescenceIOR(){return this.get("iridescenceIOR")}setIridescenceIOR(e){return this.set("iridescenceIOR",e)}getIridescenceThicknessMinimum(){return this.get("iridescenceThicknessMinimum")}setIridescenceThicknessMinimum(e){return this.set("iridescenceThicknessMinimum",e)}getIridescenceThicknessMaximum(){return this.get("iridescenceThicknessMaximum")}setIridescenceThicknessMaximum(e){return this.set("iridescenceThicknessMaximum",e)}getIridescenceThicknessTexture(){return this.getRef("iridescenceThicknessTexture")}getIridescenceThicknessTextureInfo(){return this.getRef("iridescenceThicknessTexture")?this.getRef("iridescenceThicknessTextureInfo"):null}setIridescenceThicknessTexture(e){return this.setRef("iridescenceThicknessTexture",e,{channels:ne})}}oe.EXTENSION_NAME="KHR_materials_iridescence";const ie="KHR_materials_iridescence";class ae extends e.Extension{constructor(...e){super(...e),this.extensionName=ie}createIridescence(){return new oe(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[ie]){const n=this.createIridescence();e.materials[r].setExtension(ie,n);const o=t.extensions[ie];if(void 0!==o.iridescenceFactor&&n.setIridescenceFactor(o.iridescenceFactor),void 0!==o.iridescenceIor&&n.setIridescenceIOR(o.iridescenceIor),void 0!==o.iridescenceThicknessMinimum&&n.setIridescenceThicknessMinimum(o.iridescenceThicknessMinimum),void 0!==o.iridescenceThicknessMaximum&&n.setIridescenceThicknessMaximum(o.iridescenceThicknessMaximum),void 0!==o.iridescenceTexture){const t=o.iridescenceTexture;n.setIridescenceTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getIridescenceTextureInfo(),t)}if(void 0!==o.iridescenceThicknessTexture){const t=o.iridescenceThicknessTexture;n.setIridescenceThicknessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getIridescenceThicknessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(ie);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[ie]={};if(r.getIridescenceFactor()>0&&(i.iridescenceFactor=r.getIridescenceFactor()),1.3!==r.getIridescenceIOR()&&(i.iridescenceIor=r.getIridescenceIOR()),100!==r.getIridescenceThicknessMinimum()&&(i.iridescenceThicknessMinimum=r.getIridescenceThicknessMinimum()),400!==r.getIridescenceThicknessMaximum()&&(i.iridescenceThicknessMaximum=r.getIridescenceThicknessMaximum()),r.getIridescenceTexture()){const t=r.getIridescenceTexture(),s=r.getIridescenceTextureInfo();i.iridescenceTexture=e.createTextureInfoDef(t,s)}if(r.getIridescenceThicknessTexture()){const t=r.getIridescenceThicknessTexture(),s=r.getIridescenceThicknessTextureInfo();i.iridescenceThicknessTexture=e.createTextureInfoDef(t,s)}}}),this}}ae.EXTENSION_NAME=ie;const{R:ce,G:ue,B:le,A:he}=e.TextureChannel;class fe extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_pbrSpecularGlossiness",this.propertyType="PBRSpecularGlossiness",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{diffuseFactor:[1,1,1,1],diffuseTexture:null,diffuseTextureInfo:new e.TextureInfo(this.graph,"diffuseTextureInfo"),specularFactor:[1,1,1],glossinessFactor:1,specularGlossinessTexture:null,specularGlossinessTextureInfo:new e.TextureInfo(this.graph,"specularGlossinessTextureInfo")})}getDiffuseFactor(){return this.get("diffuseFactor")}setDiffuseFactor(e){return this.set("diffuseFactor",e)}getDiffuseHex(){return e.ColorUtils.factorToHex(this.getDiffuseFactor())}setDiffuseHex(t){const s=this.getDiffuseFactor().slice();return this.setDiffuseFactor(e.ColorUtils.hexToFactor(t,s))}getDiffuseTexture(){return this.getRef("diffuseTexture")}getDiffuseTextureInfo(){return this.getRef("diffuseTexture")?this.getRef("diffuseTextureInfo"):null}setDiffuseTexture(e){return this.setRef("diffuseTexture",e,{channels:ce|ue|le|he})}getSpecularFactor(){return this.get("specularFactor")}setSpecularFactor(e){return this.set("specularFactor",e)}getGlossinessFactor(){return this.get("glossinessFactor")}setGlossinessFactor(e){return this.set("glossinessFactor",e)}getSpecularGlossinessTexture(){return this.getRef("specularGlossinessTexture")}getSpecularGlossinessTextureInfo(){return this.getRef("specularGlossinessTexture")?this.getRef("specularGlossinessTextureInfo"):null}setSpecularGlossinessTexture(e){return this.setRef("specularGlossinessTexture",e,{channels:ce|ue|le|he})}}fe.EXTENSION_NAME="KHR_materials_pbrSpecularGlossiness";const pe="KHR_materials_pbrSpecularGlossiness";class xe extends e.Extension{constructor(...e){super(...e),this.extensionName=pe}createPBRSpecularGlossiness(){return new fe(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[pe]){const n=this.createPBRSpecularGlossiness();e.materials[r].setExtension(pe,n);const o=t.extensions[pe];if(void 0!==o.diffuseFactor&&n.setDiffuseFactor(o.diffuseFactor),void 0!==o.specularFactor&&n.setSpecularFactor(o.specularFactor),void 0!==o.glossinessFactor&&n.setGlossinessFactor(o.glossinessFactor),void 0!==o.diffuseTexture){const t=o.diffuseTexture;n.setDiffuseTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getDiffuseTextureInfo(),t)}if(void 0!==o.specularGlossinessTexture){const t=o.specularGlossinessTexture;n.setSpecularGlossinessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSpecularGlossinessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(pe);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[pe]={diffuseFactor:r.getDiffuseFactor(),specularFactor:r.getSpecularFactor(),glossinessFactor:r.getGlossinessFactor()};if(r.getDiffuseTexture()){const t=r.getDiffuseTexture(),s=r.getDiffuseTextureInfo();i.diffuseTexture=e.createTextureInfoDef(t,s)}if(r.getSpecularGlossinessTexture()){const t=r.getSpecularGlossinessTexture(),s=r.getSpecularGlossinessTextureInfo();i.specularGlossinessTexture=e.createTextureInfoDef(t,s)}}}),this}}xe.EXTENSION_NAME=pe;const{R:ge,G:Te,B:de,A:me}=e.TextureChannel;class Ee extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_sheen",this.propertyType="Sheen",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{sheenColorFactor:[0,0,0],sheenColorTexture:null,sheenColorTextureInfo:new e.TextureInfo(this.graph,"sheenColorTextureInfo"),sheenRoughnessFactor:0,sheenRoughnessTexture:null,sheenRoughnessTextureInfo:new e.TextureInfo(this.graph,"sheenRoughnessTextureInfo")})}getSheenColorFactor(){return this.get("sheenColorFactor")}getSheenColorHex(){return e.ColorUtils.factorToHex(this.getSheenColorFactor())}setSheenColorFactor(e){return this.set("sheenColorFactor",e)}setSheenColorHex(t){const s=this.getSheenColorFactor().slice();return this.set("sheenColorFactor",e.ColorUtils.hexToFactor(t,s))}getSheenColorTexture(){return this.getRef("sheenColorTexture")}getSheenColorTextureInfo(){return this.getRef("sheenColorTexture")?this.getRef("sheenColorTextureInfo"):null}setSheenColorTexture(e){return this.setRef("sheenColorTexture",e,{channels:ge|Te|de})}getSheenRoughnessFactor(){return this.get("sheenRoughnessFactor")}setSheenRoughnessFactor(e){return this.set("sheenRoughnessFactor",e)}getSheenRoughnessTexture(){return this.getRef("sheenRoughnessTexture")}getSheenRoughnessTextureInfo(){return this.getRef("sheenRoughnessTexture")?this.getRef("sheenRoughnessTextureInfo"):null}setSheenRoughnessTexture(e){return this.setRef("sheenRoughnessTexture",e,{channels:me})}}Ee.EXTENSION_NAME="KHR_materials_sheen";const Ie="KHR_materials_sheen";class ye extends e.Extension{constructor(...e){super(...e),this.extensionName=Ie}createSheen(){return new Ee(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[Ie]){const n=this.createSheen();e.materials[r].setExtension(Ie,n);const o=t.extensions[Ie];if(void 0!==o.sheenColorFactor&&n.setSheenColorFactor(o.sheenColorFactor),void 0!==o.sheenRoughnessFactor&&n.setSheenRoughnessFactor(o.sheenRoughnessFactor),void 0!==o.sheenColorTexture){const t=o.sheenColorTexture;n.setSheenColorTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSheenColorTextureInfo(),t)}if(void 0!==o.sheenRoughnessTexture){const t=o.sheenRoughnessTexture;n.setSheenRoughnessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSheenRoughnessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(Ie);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[Ie]={sheenColorFactor:r.getSheenColorFactor(),sheenRoughnessFactor:r.getSheenRoughnessFactor()};if(r.getSheenColorTexture()){const t=r.getSheenColorTexture(),s=r.getSheenColorTextureInfo();i.sheenColorTexture=e.createTextureInfoDef(t,s)}if(r.getSheenRoughnessTexture()){const t=r.getSheenRoughnessTexture(),s=r.getSheenRoughnessTextureInfo();i.sheenRoughnessTexture=e.createTextureInfoDef(t,s)}}}),this}}ye.EXTENSION_NAME=Ie;const{R:Re,G:Ne,B:_e,A:Ae}=e.TextureChannel;class Se extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_specular",this.propertyType="Specular",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{specularFactor:1,specularTexture:null,specularTextureInfo:new e.TextureInfo(this.graph,"specularTextureInfo"),specularColorFactor:[1,1,1],specularColorTexture:null,specularColorTextureInfo:new e.TextureInfo(this.graph,"specularColorTextureInfo")})}getSpecularFactor(){return this.get("specularFactor")}setSpecularFactor(e){return this.set("specularFactor",e)}getSpecularColorFactor(){return this.get("specularColorFactor")}setSpecularColorFactor(e){return this.set("specularColorFactor",e)}getSpecularColorHex(){return e.ColorUtils.factorToHex(this.getSpecularColorFactor())}setSpecularColorHex(t){const s=this.getSpecularColorFactor().slice();return this.set("specularColorFactor",e.ColorUtils.hexToFactor(t,s))}getSpecularTexture(){return this.getRef("specularTexture")}getSpecularTextureInfo(){return this.getRef("specularTexture")?this.getRef("specularTextureInfo"):null}setSpecularTexture(e){return this.setRef("specularTexture",e,{channels:Ae})}getSpecularColorTexture(){return this.getRef("specularColorTexture")}getSpecularColorTextureInfo(){return this.getRef("specularColorTexture")?this.getRef("specularColorTextureInfo"):null}setSpecularColorTexture(e){return this.setRef("specularColorTexture",e,{channels:Re|Ne|_e})}}Se.EXTENSION_NAME="KHR_materials_specular";const Ce="KHR_materials_specular";class Me extends e.Extension{constructor(...e){super(...e),this.extensionName=Ce}createSpecular(){return new Se(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[Ce]){const n=this.createSpecular();e.materials[r].setExtension(Ce,n);const o=t.extensions[Ce];if(void 0!==o.specularFactor&&n.setSpecularFactor(o.specularFactor),void 0!==o.specularColorFactor&&n.setSpecularColorFactor(o.specularColorFactor),void 0!==o.specularTexture){const t=o.specularTexture;n.setSpecularTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSpecularTextureInfo(),t)}if(void 0!==o.specularColorTexture){const t=o.specularColorTexture;n.setSpecularColorTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSpecularColorTextureInfo(),t)}}}),this}write(t){const s=t.jsonDoc;return this.document.getRoot().listMaterials().forEach(r=>{const n=r.getExtension(Ce);if(n){const o=t.materialIndexMap.get(r),i=s.json.materials[o];i.extensions=i.extensions||{};const a=i.extensions[Ce]={};if(1!==n.getSpecularFactor()&&(a.specularFactor=n.getSpecularFactor()),e.MathUtils.eq(n.getSpecularColorFactor(),[1,1,1])||(a.specularColorFactor=n.getSpecularColorFactor()),n.getSpecularTexture()){const e=n.getSpecularTexture(),s=n.getSpecularTextureInfo();a.specularTexture=t.createTextureInfoDef(e,s)}if(n.getSpecularColorTexture()){const e=n.getSpecularColorTexture(),s=n.getSpecularColorTextureInfo();a.specularColorTexture=t.createTextureInfoDef(e,s)}}}),this}}Me.EXTENSION_NAME=Ce;const{R:Oe}=e.TextureChannel;class De extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_transmission",this.propertyType="Transmission",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{transmissionFactor:0,transmissionTexture:null,transmissionTextureInfo:new e.TextureInfo(this.graph,"transmissionTextureInfo")})}getTransmissionFactor(){return this.get("transmissionFactor")}setTransmissionFactor(e){return this.set("transmissionFactor",e)}getTransmissionTexture(){return this.getRef("transmissionTexture")}getTransmissionTextureInfo(){return this.getRef("transmissionTexture")?this.getRef("transmissionTextureInfo"):null}setTransmissionTexture(e){return this.setRef("transmissionTexture",e,{channels:Oe})}}De.EXTENSION_NAME="KHR_materials_transmission";const we="KHR_materials_transmission";class Fe extends e.Extension{constructor(...e){super(...e),this.extensionName=we}createTransmission(){return new De(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[we]){const n=this.createTransmission();e.materials[r].setExtension(we,n);const o=t.extensions[we];if(void 0!==o.transmissionFactor&&n.setTransmissionFactor(o.transmissionFactor),void 0!==o.transmissionTexture){const t=o.transmissionTexture;n.setTransmissionTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getTransmissionTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(we);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[we]={transmissionFactor:r.getTransmissionFactor()};if(r.getTransmissionTexture()){const t=r.getTransmissionTexture(),s=r.getTransmissionTextureInfo();i.transmissionTexture=e.createTextureInfoDef(t,s)}}}),this}}Fe.EXTENSION_NAME=we;class be extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_unlit",this.propertyType="Unlit",this.parentTypes=[e.PropertyType.MATERIAL]}}be.EXTENSION_NAME="KHR_materials_unlit";const Pe="KHR_materials_unlit";class je extends e.Extension{constructor(...e){super(...e),this.extensionName=Pe}createUnlit(){return new be(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{t.extensions&&t.extensions[Pe]&&e.materials[s].setExtension(Pe,this.createUnlit())}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{if(s.getExtension(Pe)){const r=e.materialIndexMap.get(s),n=t.json.materials[r];n.extensions=n.extensions||{},n.extensions[Pe]={}}}),this}}je.EXTENSION_NAME=Pe;class ve extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_variants",this.propertyType="Mapping",this.parentTypes=["MappingList"]}getDefaults(){return Object.assign(super.getDefaults(),{material:null,variants:[]})}getMaterial(){return this.getRef("material")}setMaterial(e){return this.setRef("material",e)}addVariant(e){return this.addRef("variants",e)}removeVariant(e){return this.removeRef("variants",e)}listVariants(){return this.listRefs("variants")}}ve.EXTENSION_NAME="KHR_materials_variants";class Ue extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_variants",this.propertyType="MappingList",this.parentTypes=[e.PropertyType.PRIMITIVE]}getDefaults(){return Object.assign(super.getDefaults(),{mappings:[]})}addMapping(e){return this.addRef("mappings",e)}removeMapping(e){return this.removeRef("mappings",e)}listMappings(){return this.listRefs("mappings")}}Ue.EXTENSION_NAME="KHR_materials_variants";class Be extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_variants",this.propertyType="Variant",this.parentTypes=["MappingList"]}}Be.EXTENSION_NAME="KHR_materials_variants";const ke="KHR_materials_variants";class Ge extends e.Extension{constructor(...e){super(...e),this.extensionName=ke}createMappingList(){return new Ue(this.document.getGraph())}createVariant(e=""){return new Be(this.document.getGraph(),e)}createMapping(){return new ve(this.document.getGraph())}listVariants(){return Array.from(this.properties).filter(e=>e instanceof Be)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[ke])return this;const s=(t.json.extensions[ke].variants||[]).map(e=>this.createVariant().setName(e.name||""));return(t.json.meshes||[]).forEach((t,r)=>{const n=e.meshes[r];(t.primitives||[]).forEach((t,r)=>{if(!t.extensions||!t.extensions[ke])return;const o=this.createMappingList(),i=t.extensions[ke];for(const t of i.mappings){const r=this.createMapping();void 0!==t.material&&r.setMaterial(e.materials[t.material]);for(const e of t.variants||[])r.addVariant(s[e]);o.addMapping(r)}n.listPrimitives()[r].setExtension(ke,o)})}),this}write(e){const t=e.jsonDoc,s=this.listVariants();if(!s.length)return this;const r=[],n=new Map;for(const t of s)n.set(t,r.length),r.push(e.createPropertyDef(t));for(const t of this.document.getRoot().listMeshes()){const s=e.meshIndexMap.get(t);t.listPrimitives().forEach((t,r)=>{const o=t.getExtension(ke);if(!o)return;const i=e.jsonDoc.json.meshes[s].primitives[r],a=o.listMappings().map(t=>{const s=e.createPropertyDef(t),r=t.getMaterial();return r&&(s.material=e.materialIndexMap.get(r)),s.variants=t.listVariants().map(e=>n.get(e)),s});i.extensions=i.extensions||{},i.extensions[ke]={mappings:a}})}return t.json.extensions=t.json.extensions||{},t.json.extensions[ke]={variants:r},this}}Ge.EXTENSION_NAME=ke;const{G:Le}=e.TextureChannel;class He extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_volume",this.propertyType="Volume",this.parentTypes=[e.PropertyType.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{thicknessFactor:0,thicknessTexture:null,thicknessTextureInfo:new e.TextureInfo(this.graph,"thicknessTexture"),attenuationDistance:Infinity,attenuationColor:[1,1,1]})}getThicknessFactor(){return this.get("thicknessFactor")}setThicknessFactor(e){return this.set("thicknessFactor",e)}getThicknessTexture(){return this.getRef("thicknessTexture")}getThicknessTextureInfo(){return this.getRef("thicknessTexture")?this.getRef("thicknessTextureInfo"):null}setThicknessTexture(e){return this.setRef("thicknessTexture",e,{channels:Le})}getAttenuationDistance(){return this.get("attenuationDistance")}setAttenuationDistance(e){return this.set("attenuationDistance",e)}getAttenuationColor(){return this.get("attenuationColor")}setAttenuationColor(e){return this.set("attenuationColor",e)}getAttenuationColorHex(){return e.ColorUtils.factorToHex(this.getAttenuationColor())}setAttenuationColorHex(t){const s=this.getAttenuationColor().slice();return this.set("attenuationColor",e.ColorUtils.hexToFactor(t,s))}}He.EXTENSION_NAME="KHR_materials_volume";const Ve="KHR_materials_volume";class Xe extends e.Extension{constructor(...e){super(...e),this.extensionName=Ve}createVolume(){return new He(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[Ve]){const n=this.createVolume();e.materials[r].setExtension(Ve,n);const o=t.extensions[Ve];if(void 0!==o.thicknessFactor&&n.setThicknessFactor(o.thicknessFactor),void 0!==o.attenuationDistance&&n.setAttenuationDistance(o.attenuationDistance),void 0!==o.attenuationColor&&n.setAttenuationColor(o.attenuationColor),void 0!==o.thicknessTexture){const t=o.thicknessTexture;n.setThicknessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getThicknessTextureInfo(),t)}}}),this}write(t){const s=t.jsonDoc;return this.document.getRoot().listMaterials().forEach(r=>{const n=r.getExtension(Ve);if(n){const o=t.materialIndexMap.get(r),i=s.json.materials[o];i.extensions=i.extensions||{};const a=i.extensions[Ve]={};if(n.getThicknessFactor()>0&&(a.thicknessFactor=n.getThicknessFactor()),Number.isFinite(n.getAttenuationDistance())&&(a.attenuationDistance=n.getAttenuationDistance()),e.MathUtils.eq(n.getAttenuationColor(),[1,1,1])||(a.attenuationColor=n.getAttenuationColor()),n.getThicknessTexture()){const e=n.getThicknessTexture(),s=n.getThicknessTextureInfo();a.thicknessTexture=t.createTextureInfoDef(e,s)}}}),this}}Xe.EXTENSION_NAME=Ve;const Ke="KHR_mesh_quantization";class ze extends e.Extension{constructor(...e){super(...e),this.extensionName=Ke}read(e){return this}write(e){return this}}ze.EXTENSION_NAME=Ke;const qe="KHR_texture_basisu";class $e{match(e){return 171===e[0]&&75===e[1]&&84===e[2]&&88===e[3]&&32===e[4]&&50===e[5]&&48===e[6]&&187===e[7]&&13===e[8]&&10===e[9]&&26===e[10]&&10===e[11]}getSize(e){const s=t.read(e);return[s.pixelWidth,s.pixelHeight]}getChannels(e){const s=t.read(e).dataFormatDescriptor[0];if(s.colorModel===t.KHR_DF_MODEL_ETC1S)return 2===s.samples.length&&15==(15&s.samples[1].channelType)?4:3;if(s.colorModel===t.KHR_DF_MODEL_UASTC)return 3==(15&s.samples[0].channelType)?4:3;throw new Error(`Unexpected KTX2 colorModel, "${s.colorModel}".`)}getGPUByteLength(e){const s=t.read(e),r=this.getChannels(e)>3;let n=0;for(let e=0;e<s.levels.length;e++){const t=s.levels[e];n+=t.uncompressedByteLength?t.uncompressedByteLength:Math.max(1,Math.floor(s.pixelWidth/Math.pow(2,e)))/4*(Math.max(1,Math.floor(s.pixelHeight/Math.pow(2,e)))/4)*(r?16:8)}return n}}class Qe extends e.Extension{constructor(...t){super(...t),this.extensionName=qe,this.prereadTypes=[e.PropertyType.TEXTURE]}static register(){e.ImageUtils.registerFormat("image/ktx2",new $e)}preread(e){return e.jsonDoc.json.textures.forEach(e=>{e.extensions&&e.extensions[qe]&&(e.source=e.extensions[qe].source)}),this}read(e){return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listTextures().forEach(s=>{if("image/ktx2"===s.getMimeType()){const r=e.imageIndexMap.get(s);t.json.textures.forEach(e=>{e.source===r&&(e.extensions=e.extensions||{},e.extensions[qe]={source:e.source},delete e.source)})}}),this}}Qe.EXTENSION_NAME=qe;class Ye extends e.ExtensionProperty{init(){this.extensionName="KHR_texture_transform",this.propertyType="Transform",this.parentTypes=[e.PropertyType.TEXTURE_INFO]}getDefaults(){return Object.assign(super.getDefaults(),{offset:[0,0],rotation:0,scale:[1,1],texCoord:null})}getOffset(){return this.get("offset")}setOffset(e){return this.set("offset",e)}getRotation(){return this.get("rotation")}setRotation(e){return this.set("rotation",e)}getScale(){return this.get("scale")}setScale(e){return this.set("scale",e)}getTexCoord(){return this.get("texCoord")}setTexCoord(e){return this.set("texCoord",e)}}Ye.EXTENSION_NAME="KHR_texture_transform";const We="KHR_texture_transform";class Je extends e.Extension{constructor(...e){super(...e),this.extensionName=We}createTransform(){return new Ye(this.document.getGraph())}read(e){for(const[t,s]of Array.from(e.textureInfos.entries())){if(!s.extensions||!s.extensions[We])continue;const e=this.createTransform(),r=s.extensions[We];void 0!==r.offset&&e.setOffset(r.offset),void 0!==r.rotation&&e.setRotation(r.rotation),void 0!==r.scale&&e.setScale(r.scale),void 0!==r.texCoord&&e.setTexCoord(r.texCoord),t.setExtension(We,e)}return this}write(t){const s=Array.from(t.textureInfoDefMap.entries());for(const[t,r]of s){const s=t.getExtension(We);if(!s)continue;r.extensions=r.extensions||{};const n={},o=e.MathUtils.eq;o(s.getOffset(),[0,0])||(n.offset=s.getOffset()),0!==s.getRotation()&&(n.rotation=s.getRotation()),o(s.getScale(),[1,1])||(n.scale=s.getScale()),null!=s.getTexCoord()&&(n.texCoord=s.getTexCoord()),r.extensions[We]=n}return this}}Je.EXTENSION_NAME=We;const Ze=[e.PropertyType.ROOT,e.PropertyType.SCENE,e.PropertyType.NODE,e.PropertyType.MESH,e.PropertyType.MATERIAL,e.PropertyType.TEXTURE,e.PropertyType.ANIMATION];class et extends e.ExtensionProperty{init(){this.extensionName="KHR_xmp_json_ld",this.propertyType="Packet",this.parentTypes=Ze}getDefaults(){return Object.assign(super.getDefaults(),{context:{},properties:{}})}getContext(){return this.get("context")}setContext(e){return this.set("context",{...e})}listProperties(){return Object.keys(this.get("properties"))}getProperty(e){const t=this.get("properties");return e in t?t[e]:null}setProperty(e,t){this._assertContext(e);const s={...this.get("properties")};return t?s[e]=t:delete s[e],this.set("properties",s)}toJSONLD(){return{"@context":tt(this.get("context")),...tt(this.get("properties"))}}fromJSONLD(e){const t=(e=tt(e))["@context"];return t&&this.set("context",t),delete e["@context"],this.set("properties",e)}_assertContext(e){if(!(e.split(":")[0]in this.get("context")))throw new Error(`KHR_xmp_json_ld: Missing context for term, "${e}".`)}}function tt(e){return JSON.parse(JSON.stringify(e))}et.EXTENSION_NAME="KHR_xmp_json_ld";const st="KHR_xmp_json_ld";class rt extends e.Extension{constructor(...e){super(...e),this.extensionName=st}createPacket(){return new et(this.document.getGraph())}listPackets(){return Array.from(this.properties)}read(e){const t=e.jsonDoc.json.extensions?.[st];if(!t||!t.packets)return this;const s=e.jsonDoc.json,r=this.document.getRoot(),n=t.packets.map(e=>this.createPacket().fromJSONLD(e)),o=[[s.asset],s.scenes,s.nodes,s.meshes,s.materials,s.images,s.animations],i=[[r],r.listScenes(),r.listNodes(),r.listMeshes(),r.listMaterials(),r.listTextures(),r.listAnimations()];for(let e=0;e<o.length;e++){const t=o[e]||[];for(let s=0;s<t.length;s++){const r=t[s];r.extensions&&r.extensions[st]&&i[e][s].setExtension(st,n[r.extensions[st].packet])}}return this}write(t){const{json:s}=t.jsonDoc,r=[];for(const n of this.properties){r.push(n.toJSONLD());for(const o of n.listParents()){let n;switch(o.propertyType){case e.PropertyType.ROOT:n=s.asset;break;case e.PropertyType.SCENE:n=s.scenes[t.sceneIndexMap.get(o)];break;case e.PropertyType.NODE:n=s.nodes[t.nodeIndexMap.get(o)];break;case e.PropertyType.MESH:n=s.meshes[t.meshIndexMap.get(o)];break;case e.PropertyType.MATERIAL:n=s.materials[t.materialIndexMap.get(o)];break;case e.PropertyType.TEXTURE:n=s.images[t.imageIndexMap.get(o)];break;case e.PropertyType.ANIMATION:n=s.animations[t.animationIndexMap.get(o)];break;default:n=null,this.document.getLogger().warn(`[${st}]: Unsupported parent property, "${o.propertyType}"`)}n&&(n.extensions=n.extensions||{},n.extensions[st]={packet:r.length-1})}}return r.length>0&&(s.extensions=s.extensions||{},s.extensions[st]={packets:r}),this}}rt.EXTENSION_NAME=st;const nt=[G,X,Y,Z,se,ae,xe,Me,ye,Fe,je,Ge,Xe,ze,Qe,Je,rt],ot=[n,E,R,...nt];exports.ALL_EXTENSIONS=ot,exports.Clearcoat=$,exports.DracoMeshCompression=G,exports.EmissiveStrength=W,exports.INSTANCE_ATTRIBUTE="INSTANCE_ATTRIBUTE",exports.IOR=ee,exports.InstancedMesh=s,exports.Iridescence=oe,exports.KHRONOS_EXTENSIONS=nt,exports.Light=H,exports.LightsPunctual=X,exports.Mapping=ve,exports.MappingList=Ue,exports.MaterialsClearcoat=Y,exports.MaterialsEmissiveStrength=Z,exports.MaterialsIOR=se,exports.MaterialsIridescence=ae,exports.MaterialsPBRSpecularGlossiness=xe,exports.MaterialsSheen=ye,exports.MaterialsSpecular=Me,exports.MaterialsTransmission=Fe,exports.MaterialsUnlit=je,exports.MaterialsVariants=Ge,exports.MaterialsVolume=Xe,exports.MeshGPUInstancing=n,exports.MeshQuantization=ze,exports.MeshoptCompression=E,exports.PBRSpecularGlossiness=fe,exports.Packet=et,exports.Sheen=Ee,exports.Specular=Se,exports.TextureBasisu=Qe,exports.TextureTransform=Je,exports.TextureWebP=R,exports.Transform=Ye,exports.Transmission=De,exports.Unlit=be,exports.Variant=Be,exports.Volume=He,exports.XMP=rt;
//# sourceMappingURL=extensions.js.map

@@ -1,2 +0,2 @@

import{ExtensionProperty as e,PropertyType as t,Extension as s,BufferUtils as r,WriterContext as n,Primitive as o,Root as i,AnimationSampler as a,AnimationChannel as c,Accessor as u,MathUtils as l,GLB_BUFFER as h,ImageUtils as f,bounds as g,ColorUtils as p,TextureInfo as x,TextureChannel as d}from"@gltf-transform/core";import{read as T,KHR_DF_MODEL_ETC1S as m,KHR_DF_MODEL_UASTC as E}from"ktx-parse";const I="INSTANCE_ATTRIBUTE";class R extends e{init(){this.extensionName="EXT_mesh_gpu_instancing",this.propertyType="InstancedMesh",this.parentTypes=[t.NODE]}getDefaults(){return Object.assign(super.getDefaults(),{attributes:{}})}getAttribute(e){return this.getRefMap("attributes",e)}setAttribute(e,t){return this.setRefMap("attributes",e,t,{usage:"INSTANCE_ATTRIBUTE"})}listAttributes(){return this.listRefMapValues("attributes")}listSemantics(){return this.listRefMapKeys("attributes")}}R.EXTENSION_NAME="EXT_mesh_gpu_instancing";const N="EXT_mesh_gpu_instancing";class _ extends s{constructor(...e){super(...e),this.extensionName=N,this.provideTypes=[t.NODE],this.prewriteTypes=[t.ACCESSOR]}createInstancedMesh(){return new R(this.document.getGraph())}read(e){return(e.jsonDoc.json.nodes||[]).forEach((t,s)=>{if(!t.extensions||!t.extensions[N])return;const r=t.extensions[N],n=this.createInstancedMesh();for(const t in r.attributes)n.setAttribute(t,e.accessors[r.attributes[t]]);e.nodes[s].setExtension(N,n)}),this}prewrite(e){e.accessorUsageGroupedByParent.add("INSTANCE_ATTRIBUTE");for(const t of this.properties)for(const s of t.listAttributes())e.addAccessorToUsageGroup(s,"INSTANCE_ATTRIBUTE");return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listNodes().forEach(s=>{const r=s.getExtension(N);if(r){const n=e.nodeIndexMap.get(s),o=t.json.nodes[n],i={attributes:{}};r.listSemantics().forEach(t=>{const s=r.getAttribute(t);i.attributes[t]=e.accessorIndexMap.get(s)}),o.extensions=o.extensions||{},o.extensions[N]=i}}),this}}function S(){return(S=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(e[r]=s[r])}return e}).apply(this,arguments)}var A,y,C;_.EXTENSION_NAME=N,function(e){e.QUANTIZE="quantize",e.FILTER="filter"}(A||(A={})),function(e){e.ATTRIBUTES="ATTRIBUTES",e.TRIANGLES="TRIANGLES",e.INDICES="INDICES"}(y||(y={})),function(e){e.NONE="NONE",e.OCTAHEDRAL="OCTAHEDRAL",e.QUATERNION="QUATERNION",e.EXPONENTIAL="EXPONENTIAL"}(C||(C={}));const{BYTE:M,SHORT:O,FLOAT:w}=u.ComponentType,{normalize:D,denormalize:F}=l;function b(e,t,s,n){const{filter:o,bits:i}=n,a={array:e.getArray(),byteStride:e.getElementSize()*e.getComponentSize(),componentType:e.getComponentType(),normalized:e.getNormalized()};if(s!==y.ATTRIBUTES)return a;if(o!==C.NONE){let s=e.getNormalized()?function(e){const t=e.getComponentType(),s=e.getArray(),r=new Float32Array(s.length);for(let e=0;e<s.length;e++)r[e]=F(s[e],t);return r}(e):new Float32Array(a.array);switch(o){case C.EXPONENTIAL:a.byteStride=4*e.getElementSize(),a.componentType=w,a.normalized=!1,a.array=t.encodeFilterExp(s,e.getCount(),a.byteStride,i);break;case C.OCTAHEDRAL:a.byteStride=i>8?8:4,a.componentType=i>8?O:M,a.normalized=!0,s=3===e.getElementSize()?function(e){const t=new Float32Array(4*e.length/3);for(let s=0,r=e.length/3;s<r;s++)t[4*s]=e[3*s],t[4*s+1]=e[3*s+1],t[4*s+2]=e[3*s+2];return t}(s):s,a.array=t.encodeFilterOct(s,e.getCount(),a.byteStride,i);break;case C.QUATERNION:a.byteStride=8,a.componentType=O,a.normalized=!0,a.array=t.encodeFilterQuat(s,e.getCount(),a.byteStride,i);break;default:throw new Error("Invalid filter.")}a.min=e.getMin([]),a.max=e.getMax([]),e.getNormalized()&&(a.min=a.min.map(t=>F(t,e.getComponentType())),a.max=a.max.map(t=>F(t,e.getComponentType()))),a.normalized&&(a.min=a.min.map(e=>D(e,a.componentType)),a.max=a.max.map(e=>D(e,a.componentType)))}else a.byteStride%4&&(a.array=function(e,t){const s=r.padNumber(e.BYTES_PER_ELEMENT*t)/e.BYTES_PER_ELEMENT,n=new e.constructor(e.length/t*s);for(let r=0;r*t<e.length;r++)for(let o=0;o<t;o++)n[r*s+o]=e[r*t+o];return n}(a.array,e.getElementSize()),a.byteStride=a.array.byteLength/e.getCount());return a}function j(e,t){return t===n.BufferViewUsage.ELEMENT_ARRAY_BUFFER?e.listParents().some(e=>e instanceof o&&e.getMode()===o.Mode.TRIANGLES)?y.TRIANGLES:y.INDICES:y.ATTRIBUTES}function v(e,t){const s=t.getGraph().listParentEdges(e).filter(e=>!(e.getParent()instanceof i));for(const t of s){const s=t.getName(),r=t.getAttributes().key||"";if("indices"===s)return{filter:C.NONE};if("attributes"===s){if("POSITION"===r)return{filter:C.NONE};if("TEXCOORD_0"===r)return{filter:C.NONE};if("NORMAL"===r)return{filter:C.OCTAHEDRAL,bits:8};if("TANGENT"===r)return{filter:C.OCTAHEDRAL,bits:8};if(r.startsWith("JOINTS_"))return{filter:C.NONE};if(r.startsWith("WEIGHTS_"))return{filter:C.NONE}}if("output"===s){const t=k(e);return"rotation"===t?{filter:C.QUATERNION,bits:16}:"translation"===t||"scale"===t?{filter:C.EXPONENTIAL,bits:12}:{filter:C.NONE}}if("input"===s)return{filter:C.NONE};if("inverseBindMatrices"===s)return{filter:C.NONE}}return{filter:C.NONE}}function k(e){for(const t of e.listParents())if(t instanceof a)for(const e of t.listParents())if(e instanceof c)return e.getTargetPath();return null}const B="EXT_meshopt_compression",G={method:A.QUANTIZE};class H extends s{constructor(...e){super(...e),this.extensionName=B,this.prereadTypes=[t.BUFFER,t.PRIMITIVE],this.prewriteTypes=[t.BUFFER,t.ACCESSOR],this.readDependencies=["meshopt.decoder"],this.writeDependencies=["meshopt.encoder"],this._decoder=null,this._decoderFallbackBufferMap=new Map,this._encoder=null,this._encoderOptions=G,this._encoderFallbackBuffer=null,this._encoderBufferViews={},this._encoderBufferViewData={},this._encoderBufferViewAccessors={}}install(e,t){return"meshopt.decoder"===e&&(this._decoder=t),"meshopt.encoder"===e&&(this._encoder=t),this}setEncoderOptions(e){return this._encoderOptions=S({},G,e),this}preread(e,s){if(!this._decoder){if(!this.isRequired())return this;throw new Error(`[${B}] Please install extension dependency, "meshopt.decoder".`)}if(!this._decoder.supported){if(!this.isRequired())return this;throw new Error(`[${B}]: Missing WASM support.`)}return s===t.BUFFER?this._prereadBuffers(e):s===t.PRIMITIVE&&this._prereadPrimitives(e),this}_prereadBuffers(e){const t=e.jsonDoc;(t.json.bufferViews||[]).forEach((s,n)=>{if(!s.extensions||!s.extensions[B])return;const o=s.extensions[B],i=o.byteOffset||0,a=o.byteLength||0,c=o.count,u=o.byteStride,l=new Uint8Array(c*u),f=t.json.buffers[s.buffer],g=r.toView(f.uri?t.resources[f.uri]:t.resources[h],i,a);this._decoder.decodeGltfBuffer(l,c,u,g,o.mode,o.filter),e.bufferViews[n]=l})}_prereadPrimitives(e){const t=e.jsonDoc;(t.json.bufferViews||[]).forEach(s=>{var r;s.extensions&&s.extensions[B]&&(r=t.json.buffers[s.buffer]).extensions&&r.extensions.EXT_meshopt_compression&&r.extensions.EXT_meshopt_compression.fallback&&this._decoderFallbackBufferMap.set(e.buffers[s.buffer],e.buffers[s.extensions[B].buffer])})}read(e){if(!this.isRequired())return this;for(const[e,t]of this._decoderFallbackBufferMap){for(const s of e.listParents())s instanceof u&&s.swap(e,t);e.dispose()}return this}prewrite(e,s){return s===t.ACCESSOR?this._prewriteAccessors(e):s===t.BUFFER&&this._prewriteBuffers(e),this}_prewriteAccessors(e){const t=e.jsonDoc.json,s=this._encoder,r=this._encoderOptions,o=this.document.createBuffer(),i=this.document.getRoot().listBuffers().indexOf(o);this._encoderFallbackBuffer=o,this._encoderBufferViews={},this._encoderBufferViewData={},this._encoderBufferViewAccessors={};for(const o of this.document.getRoot().listAccessors()){if("weights"===k(o))continue;const a=e.getAccessorUsage(o),c=j(o,a),u=r.method===A.FILTER?v(o,this.document):{filter:C.NONE},l=b(o,s,c,u),{array:h,byteStride:f}=l,g=o.getBuffer();if(!g)throw new Error(`${B}: Missing buffer for accessor.`);const p=this.document.getRoot().listBuffers().indexOf(g),x=[a,c,u.filter,f,p].join(":");let d=this._encoderBufferViews[x],T=this._encoderBufferViewData[x],m=this._encoderBufferViewAccessors[x];d&&T||(m=this._encoderBufferViewAccessors[x]=[],T=this._encoderBufferViewData[x]=[],d=this._encoderBufferViews[x]={buffer:i,target:n.USAGE_TO_TARGET[a],byteOffset:0,byteLength:0,byteStride:a===n.BufferViewUsage.ARRAY_BUFFER?f:void 0,extensions:{[B]:{buffer:p,byteOffset:0,byteLength:0,mode:c,filter:u.filter!==C.NONE?u.filter:void 0,byteStride:f,count:0}}});const E=e.createAccessorDef(o);E.componentType=l.componentType,E.normalized=l.normalized,E.byteOffset=d.byteLength,E.min&&l.min&&(E.min=l.min),E.max&&l.max&&(E.max=l.max),e.accessorIndexMap.set(o,t.accessors.length),t.accessors.push(E),m.push(E),T.push(new Uint8Array(h.buffer,h.byteOffset,h.byteLength)),d.byteLength+=h.byteLength,d.extensions.EXT_meshopt_compression.count+=o.getCount()}}_prewriteBuffers(e){const t=this._encoder;for(const s in this._encoderBufferViews){const n=this._encoderBufferViews[s],o=this._encoderBufferViewData[s],i=this.document.getRoot().listBuffers()[n.extensions[B].buffer],a=e.otherBufferViews.get(i)||[],{count:c,byteStride:u,mode:l}=n.extensions[B],h=r.concat(o),f=t.encodeGltfBuffer(h,c,u,l),g=r.pad(f);n.extensions[B].byteLength=f.byteLength,o.length=0,o.push(g),a.push(g),e.otherBufferViews.set(i,a)}}write(e){let t=0;for(const s in this._encoderBufferViews){const n=this._encoderBufferViews[s],o=e.otherBufferViewsIndexMap.get(this._encoderBufferViewData[s][0]),i=this._encoderBufferViewAccessors[s];for(const e of i)e.bufferView=o;const a=e.jsonDoc.json.bufferViews[o],c=a.byteOffset||0;Object.assign(a,n),a.byteOffset=t,a.extensions[B].byteOffset=c,t+=r.padNumber(n.byteLength)}const s=this._encoderFallbackBuffer,n=e.bufferIndexMap.get(s),o=e.jsonDoc.json.buffers[n];return o.byteLength=t,o.extensions={[B]:{fallback:!0}},s.dispose(),this}}H.EXTENSION_NAME=B,H.EncoderMethod=A;const L="EXT_texture_webp";class U{match(e){return e.length>=12&&87===e[8]&&69===e[9]&&66===e[10]&&80===e[11]}getSize(e){const t=r.decodeText(e.slice(0,4)),s=r.decodeText(e.slice(8,12));if("RIFF"!==t||"WEBP"!==s)return null;const n=new DataView(e.buffer,e.byteOffset);let o=12;for(;o<n.byteLength;){const e=r.decodeText(new Uint8Array([n.getUint8(o),n.getUint8(o+1),n.getUint8(o+2),n.getUint8(o+3)])),t=n.getUint32(o+4,!0);if("VP8 "===e)return[16383&n.getInt16(o+14,!0),16383&n.getInt16(o+16,!0)];if("VP8L"===e){const e=n.getUint8(o+9),t=n.getUint8(o+10),s=n.getUint8(o+11);return[1+((63&t)<<8|e),1+((15&n.getUint8(o+12))<<10|s<<2|(192&t)>>6)]}o+=8+t+t%2}return null}getChannels(e){return 4}}class P extends s{constructor(...e){super(...e),this.extensionName=L,this.prereadTypes=[t.TEXTURE]}static register(){f.registerFormat("image/webp",new U)}preread(e){return(e.jsonDoc.json.textures||[]).forEach(e=>{e.extensions&&e.extensions[L]&&(e.source=e.extensions[L].source)}),this}read(e){return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listTextures().forEach(s=>{if("image/webp"===s.getMimeType()){const r=e.imageIndexMap.get(s);(t.json.textures||[]).forEach(e=>{e.source===r&&(e.extensions=e.extensions||{},e.extensions[L]={source:e.source},delete e.source)})}}),this}}P.EXTENSION_NAME=L;const V="KHR_draco_mesh_compression";let X,K,z,q;function $(e,t){const s=new X.DecoderBuffer;try{if(s.Init(t,t.length),e.GetEncodedGeometryType(s)!==X.TRIANGULAR_MESH)throw new Error(`[${V}] Unknown geometry type.`);const r=new X.Mesh;if(!e.DecodeBufferToMesh(s,r).ok()||0===r.ptr)throw new Error(`[${V}] Decoding failure.`);return r}finally{X.destroy(s)}}function Y(e,t){const s=3*t.num_faces();let r,n;if(t.num_points()<=65534){const o=s*Uint16Array.BYTES_PER_ELEMENT;r=X._malloc(o),e.GetTrianglesUInt16Array(t,o,r),n=new Uint16Array(X.HEAPU16.buffer,r,s).slice()}else{const o=s*Uint32Array.BYTES_PER_ELEMENT;r=X._malloc(o),e.GetTrianglesUInt32Array(t,o,r),n=new Uint32Array(X.HEAPU32.buffer,r,s).slice()}return X._free(r),n}function Q(e,t,s,r){const n=z[r.componentType],o=K[r.componentType],i=s.num_components(),a=t.num_points()*i,c=a*o.BYTES_PER_ELEMENT,u=X._malloc(c);e.GetAttributeDataArrayForAllPoints(t,s,n,c,u);const l=new o(X.HEAPF32.buffer,u,a).slice();return X._free(u),l}var W,J;!function(e){e[e.EDGEBREAKER=1]="EDGEBREAKER",e[e.SEQUENTIAL=0]="SEQUENTIAL"}(W||(W={})),function(e){e.POSITION="POSITION",e.NORMAL="NORMAL",e.COLOR="COLOR",e.TEX_COORD="TEX_COORD",e.GENERIC="GENERIC"}(J||(J={}));const Z={[J.POSITION]:14,[J.NORMAL]:10,[J.COLOR]:8,[J.TEX_COORD]:12,[J.GENERIC]:12},ee={decodeSpeed:5,encodeSpeed:5,method:W.EDGEBREAKER,quantizationBits:Z,quantizationVolume:"mesh"};function te(e,t=ee){const s=S({},ee,t);s.quantizationBits=S({},Z,t.quantizationBits);const r=new q.Encoder,n=new q.MeshBuilder,o=new q.Mesh,i={},a=new q.DracoInt8Array;for(const t of e.listSemantics()){const a=e.getAttribute(t),c=se(t),u=re(n,a.getComponentType(),o,q[c],a.getCount(),a.getElementSize(),a.getArray());if(-1===u)throw new Error(`Error compressing "${t}" attribute.`);if(i[t]=u,"mesh"===s.quantizationVolume||"POSITION"!==t)r.SetAttributeQuantization(q[c],s.quantizationBits[c]);else{if("object"!=typeof s.quantizationVolume)throw new Error("Invalid quantization volume state.");{const{quantizationVolume:e}=s,t=Math.max(e.max[0]-e.min[0],e.max[1]-e.min[1],e.max[2]-e.min[2]);r.SetAttributeExplicitQuantization(q[c],s.quantizationBits[c],a.getElementSize(),e.min,t)}}}const c=e.getIndices();if(!c)throw new Error("Primitive must have indices.");n.AddFacesToMesh(o,c.getCount()/3,c.getArray()),r.SetSpeedOptions(s.encodeSpeed,s.decodeSpeed),r.SetTrackEncodedProperties(!0),s.method===W.SEQUENTIAL||e.listTargets().length>0?r.SetEncodingMethod(q.MESH_SEQUENTIAL_ENCODING):r.SetEncodingMethod(q.MESH_EDGEBREAKER_ENCODING);const u=r.EncodeMeshToDracoBuffer(o,a);if(u<=0)throw new Error("Error applying Draco compression.");const l=new Uint8Array(u);for(let e=0;e<u;++e)l[e]=a.GetValue(e);const h=e.getAttribute("POSITION").getCount(),f=r.GetNumberOfEncodedPoints(),g=3*r.GetNumberOfEncodedFaces();if(e.listTargets().length>0&&f!==h)throw new Error('Compression reduced vertex count unexpectedly, corrupting morph targets. Applying the "weld" function before compression may resolve the issue.');return q.destroy(a),q.destroy(o),q.destroy(n),q.destroy(r),{numVertices:f,numIndices:g,data:l,attributeIDs:i}}function se(e){return"POSITION"===e?J.POSITION:"NORMAL"===e?J.NORMAL:e.startsWith("COLOR_")?J.COLOR:e.startsWith("TEXCOORD_")?J.TEX_COORD:J.GENERIC}function re(e,t,s,r,n,o,i){switch(t){case u.ComponentType.UNSIGNED_BYTE:return e.AddUInt8Attribute(s,r,n,o,i);case u.ComponentType.BYTE:return e.AddInt8Attribute(s,r,n,o,i);case u.ComponentType.UNSIGNED_SHORT:return e.AddUInt16Attribute(s,r,n,o,i);case u.ComponentType.SHORT:return e.AddInt16Attribute(s,r,n,o,i);case u.ComponentType.UNSIGNED_INT:return e.AddUInt32Attribute(s,r,n,o,i);case u.ComponentType.FLOAT:return e.AddFloatAttribute(s,r,n,o,i);default:throw new Error(`Unexpected component type, "${t}".`)}}const ne="KHR_draco_mesh_compression";class oe extends s{constructor(...e){super(...e),this.extensionName=ne,this.prereadTypes=[t.PRIMITIVE],this.prewriteTypes=[t.ACCESSOR],this.readDependencies=["draco3d.decoder"],this.writeDependencies=["draco3d.encoder"],this._decoderModule=null,this._encoderModule=null,this._encoderOptions={}}install(e,t){return"draco3d.decoder"===e&&(this._decoderModule=t,X=this._decoderModule,K={[u.ComponentType.FLOAT]:Float32Array,[u.ComponentType.UNSIGNED_INT]:Uint32Array,[u.ComponentType.UNSIGNED_SHORT]:Uint16Array,[u.ComponentType.UNSIGNED_BYTE]:Uint8Array,[u.ComponentType.SHORT]:Int16Array,[u.ComponentType.BYTE]:Int8Array},z={[u.ComponentType.FLOAT]:X.DT_FLOAT32,[u.ComponentType.UNSIGNED_INT]:X.DT_UINT32,[u.ComponentType.UNSIGNED_SHORT]:X.DT_UINT16,[u.ComponentType.UNSIGNED_BYTE]:X.DT_UINT8,[u.ComponentType.SHORT]:X.DT_INT16,[u.ComponentType.BYTE]:X.DT_INT8}),"draco3d.encoder"===e&&(this._encoderModule=t,q=this._encoderModule),this}setEncoderOptions(e){return this._encoderOptions=e,this}preread(e){if(!this._decoderModule)throw new Error(`[${ne}] Please install extension dependency, "draco3d.decoder".`);const t=this.document.getLogger(),s=e.jsonDoc,n=new Map;try{const o=s.json.meshes||[];for(const i of o)for(const o of i.primitives){if(!o.extensions||!o.extensions[ne])continue;const i=o.extensions[ne];let[a,c]=n.get(i.bufferView)||[];if(!c||!a){const e=s.json.bufferViews[i.bufferView],o=s.json.buffers[e.buffer],u=r.toView(o.uri?s.resources[o.uri]:s.resources[h],e.byteOffset||0,e.byteLength);a=new this._decoderModule.Decoder,c=$(a,u),n.set(i.bufferView,[a,c]),t.debug(`[${ne}] Decompressed ${u.byteLength} bytes.`)}for(const t in o.attributes){const s=e.jsonDoc.json.accessors[o.attributes[t]],r=a.GetAttributeByUniqueId(c,i.attributes[t]),n=Q(a,c,r,s);e.accessors[o.attributes[t]].setArray(n)}void 0!==o.indices&&e.accessors[o.indices].setArray(Y(a,c))}}finally{for(const[e,t]of Array.from(n.values()))this._decoderModule.destroy(e),this._decoderModule.destroy(t)}return this}read(e){return this}prewrite(e,s){if(!this._encoderModule)throw new Error(`[${ne}] Please install extension dependency, "draco3d.encoder".`);const r=this.document.getLogger();r.debug(`[${ne}] Compression options: ${JSON.stringify(this._encoderOptions)}`);const n=function(e){const s=e.getLogger(),r=new Set,n=new Set;for(const t of e.getRoot().listMeshes())for(const e of t.listPrimitives())e.getIndices()?e.getMode()!==o.Mode.TRIANGLES?(n.add(e),s.warn(`[${ne}] Skipping Draco compression on non-TRIANGLES primitive.`)):r.add(e):(n.add(e),s.warn(`[${ne}] Skipping Draco compression on non-indexed primitive.`));const i=e.getRoot().listAccessors(),a=new Map;for(let e=0;e<i.length;e++)a.set(i[e],e);const c=new Map,u=new Set,l=new Map;for(const t of Array.from(r)){let s=ie(t,a);if(u.has(s))l.set(t,s);else{if(c.has(t.getIndices())){const s=t.getIndices(),r=s.clone();a.set(r,e.getRoot().listAccessors().length-1),t.swap(s,r)}for(const s of t.listAttributes())if(c.has(s)){const r=s.clone();a.set(r,e.getRoot().listAccessors().length-1),t.swap(s,r)}s=ie(t,a),u.add(s),l.set(t,s),c.set(t.getIndices(),s);for(const e of t.listAttributes())c.set(e,s)}}for(const e of Array.from(c.keys())){const s=new Set(e.listParents().map(e=>e.propertyType));if(2!==s.size||!s.has(t.PRIMITIVE)||!s.has(t.ROOT))throw new Error(`[${ne}] Compressed accessors must only be used as indices or vertex attributes.`)}for(const e of Array.from(r)){const t=l.get(e),s=e.getIndices();if(c.get(s)!==t||e.listAttributes().some(e=>c.get(e)!==t))throw new Error(`[${ne}] Draco primitives must share all, or no, accessors.`)}for(const e of Array.from(n)){const t=e.getIndices();if(c.has(t)||e.listAttributes().some(e=>c.has(e)))throw new Error(`[${ne}] Accessor cannot be shared by compressed and uncompressed primitives.`)}return l}(this.document),i=new Map;let a="mesh";"scene"===this._encoderOptions.quantizationVolume&&(1!==this.document.getRoot().listScenes().length?r.warn(`[${ne}]: quantizationVolume=scene requires exactly 1 scene.`):a=g(this.document.getRoot().listScenes().pop()));for(const t of Array.from(n.keys())){const s=n.get(t);if(!s)throw new Error("Unexpected primitive.");if(i.has(s)){i.set(s,i.get(s));continue}const r=t.getIndices(),o=e.jsonDoc.json.accessors,c=te(t,S({},this._encoderOptions,{quantizationVolume:a}));i.set(s,c);const u=e.createAccessorDef(r);u.count=c.numIndices,e.accessorIndexMap.set(r,o.length),o.push(u);for(const s of t.listSemantics()){const r=t.getAttribute(s),n=e.createAccessorDef(r);n.count=c.numVertices,e.accessorIndexMap.set(r,o.length),o.push(n)}const l=t.getAttribute("POSITION").getBuffer()||this.document.getRoot().listBuffers()[0];e.otherBufferViews.has(l)||e.otherBufferViews.set(l,[]),e.otherBufferViews.get(l).push(c.data)}return r.debug(`[${ne}] Compressed ${n.size} primitives.`),e.extensionData[ne]={primitiveHashMap:n,primitiveEncodingMap:i},this}write(e){const t=e.extensionData[ne];for(const s of this.document.getRoot().listMeshes()){const r=e.jsonDoc.json.meshes[e.meshIndexMap.get(s)];for(let n=0;n<s.listPrimitives().length;n++){const o=s.listPrimitives()[n],i=r.primitives[n],a=t.primitiveHashMap.get(o);if(!a)continue;const c=t.primitiveEncodingMap.get(a);i.extensions=i.extensions||{},i.extensions[ne]={bufferView:e.otherBufferViewsIndexMap.get(c.data),attributes:c.attributeIDs}}}if(!t.primitiveHashMap.size){const t=e.jsonDoc.json;t.extensionsUsed=(t.extensionsUsed||[]).filter(e=>e!==ne),t.extensionsRequired=(t.extensionsRequired||[]).filter(e=>e!==ne)}return this}}function ie(e,t){const s=[],r=e.getIndices();s.push(t.get(r));for(const r of e.listAttributes())s.push(t.get(r));return s.sort().join("|")}oe.EXTENSION_NAME=ne,oe.EncoderMethod=W;class ae extends e{init(){this.extensionName="KHR_lights_punctual",this.propertyType="Light",this.parentTypes=[t.NODE]}getDefaults(){return Object.assign(super.getDefaults(),{color:[1,1,1],intensity:1,type:ae.Type.POINT,range:null,innerConeAngle:0,outerConeAngle:Math.PI/4})}getColor(){return this.get("color")}setColor(e){return this.set("color",e)}getColorHex(){return p.factorToHex(this.getColor())}setColorHex(e){const t=this.getColor().slice();return p.hexToFactor(e,t),this.setColor(t)}getIntensity(){return this.get("intensity")}setIntensity(e){return this.set("intensity",e)}getType(){return this.get("type")}setType(e){return this.set("type",e)}getRange(){return this.get("range")}setRange(e){return this.set("range",e)}getInnerConeAngle(){return this.get("innerConeAngle")}setInnerConeAngle(e){return this.set("innerConeAngle",e)}getOuterConeAngle(){return this.get("outerConeAngle")}setOuterConeAngle(e){return this.set("outerConeAngle",e)}}ae.EXTENSION_NAME="KHR_lights_punctual",ae.Type={POINT:"point",SPOT:"spot",DIRECTIONAL:"directional"};const ce="KHR_lights_punctual";class ue extends s{constructor(...e){super(...e),this.extensionName=ce}createLight(e=""){return new ae(this.document.getGraph(),e)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[ce])return this;const s=(t.json.extensions[ce].lights||[]).map(e=>{var t,s;const r=this.createLight().setName(e.name||"").setType(e.type);return void 0!==e.color&&r.setColor(e.color),void 0!==e.intensity&&r.setIntensity(e.intensity),void 0!==e.range&&r.setRange(e.range),void 0!==(null==(t=e.spot)?void 0:t.innerConeAngle)&&r.setInnerConeAngle(e.spot.innerConeAngle),void 0!==(null==(s=e.spot)?void 0:s.outerConeAngle)&&r.setOuterConeAngle(e.spot.outerConeAngle),r});return t.json.nodes.forEach((t,r)=>{t.extensions&&t.extensions[ce]&&e.nodes[r].setExtension(ce,s[t.extensions[ce].light])}),this}write(e){const t=e.jsonDoc;if(0===this.properties.size)return this;const s=[],r=new Map;for(const e of this.properties){const t=e,n={type:t.getType()};l.eq(t.getColor(),[1,1,1])||(n.color=t.getColor()),1!==t.getIntensity()&&(n.intensity=t.getIntensity()),null!=t.getRange()&&(n.range=t.getRange()),t.getName()&&(n.name=t.getName()),t.getType()===ae.Type.SPOT&&(n.spot={innerConeAngle:t.getInnerConeAngle(),outerConeAngle:t.getOuterConeAngle()}),s.push(n),r.set(t,s.length-1)}return this.document.getRoot().listNodes().forEach(s=>{const n=s.getExtension(ce);if(n){const o=e.nodeIndexMap.get(s),i=t.json.nodes[o];i.extensions=i.extensions||{},i.extensions[ce]={light:r.get(n)}}}),t.json.extensions=t.json.extensions||{},t.json.extensions[ce]={lights:s},this}}ue.EXTENSION_NAME=ce;const{R:le,G:he,B:fe}=d;class ge extends e{init(){this.extensionName="KHR_materials_clearcoat",this.propertyType="Clearcoat",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{clearcoatFactor:0,clearcoatTexture:null,clearcoatTextureInfo:new x(this.graph,"clearcoatTextureInfo"),clearcoatRoughnessFactor:0,clearcoatRoughnessTexture:null,clearcoatRoughnessTextureInfo:new x(this.graph,"clearcoatRoughnessTextureInfo"),clearcoatNormalScale:1,clearcoatNormalTexture:null,clearcoatNormalTextureInfo:new x(this.graph,"clearcoatNormalTextureInfo")})}getClearcoatFactor(){return this.get("clearcoatFactor")}setClearcoatFactor(e){return this.set("clearcoatFactor",e)}getClearcoatTexture(){return this.getRef("clearcoatTexture")}getClearcoatTextureInfo(){return this.getRef("clearcoatTexture")?this.getRef("clearcoatTextureInfo"):null}setClearcoatTexture(e){return this.setRef("clearcoatTexture",e,{channels:le})}getClearcoatRoughnessFactor(){return this.get("clearcoatRoughnessFactor")}setClearcoatRoughnessFactor(e){return this.set("clearcoatRoughnessFactor",e)}getClearcoatRoughnessTexture(){return this.getRef("clearcoatRoughnessTexture")}getClearcoatRoughnessTextureInfo(){return this.getRef("clearcoatRoughnessTexture")?this.getRef("clearcoatRoughnessTextureInfo"):null}setClearcoatRoughnessTexture(e){return this.setRef("clearcoatRoughnessTexture",e,{channels:he})}getClearcoatNormalScale(){return this.get("clearcoatNormalScale")}setClearcoatNormalScale(e){return this.set("clearcoatNormalScale",e)}getClearcoatNormalTexture(){return this.getRef("clearcoatNormalTexture")}getClearcoatNormalTextureInfo(){return this.getRef("clearcoatNormalTexture")?this.getRef("clearcoatNormalTextureInfo"):null}setClearcoatNormalTexture(e){return this.setRef("clearcoatNormalTexture",e,{channels:le|he|fe})}}ge.EXTENSION_NAME="KHR_materials_clearcoat";const pe="KHR_materials_clearcoat";class xe extends s{constructor(...e){super(...e),this.extensionName=pe}createClearcoat(){return new ge(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[pe]){const n=this.createClearcoat();e.materials[r].setExtension(pe,n);const o=t.extensions[pe];if(void 0!==o.clearcoatFactor&&n.setClearcoatFactor(o.clearcoatFactor),void 0!==o.clearcoatRoughnessFactor&&n.setClearcoatRoughnessFactor(o.clearcoatRoughnessFactor),void 0!==o.clearcoatTexture){const t=o.clearcoatTexture;n.setClearcoatTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getClearcoatTextureInfo(),t)}if(void 0!==o.clearcoatRoughnessTexture){const t=o.clearcoatRoughnessTexture;n.setClearcoatRoughnessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getClearcoatRoughnessTextureInfo(),t)}if(void 0!==o.clearcoatNormalTexture){const t=o.clearcoatNormalTexture;n.setClearcoatNormalTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getClearcoatNormalTextureInfo(),t),void 0!==t.scale&&n.setClearcoatNormalScale(t.scale)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(pe);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[pe]={clearcoatFactor:r.getClearcoatFactor(),clearcoatRoughnessFactor:r.getClearcoatRoughnessFactor()};if(r.getClearcoatTexture()){const t=r.getClearcoatTexture(),s=r.getClearcoatTextureInfo();i.clearcoatTexture=e.createTextureInfoDef(t,s)}if(r.getClearcoatRoughnessTexture()){const t=r.getClearcoatRoughnessTexture(),s=r.getClearcoatRoughnessTextureInfo();i.clearcoatRoughnessTexture=e.createTextureInfoDef(t,s)}if(r.getClearcoatNormalTexture()){const t=r.getClearcoatNormalTexture(),s=r.getClearcoatNormalTextureInfo();i.clearcoatNormalTexture=e.createTextureInfoDef(t,s),1!==r.getClearcoatNormalScale()&&(i.clearcoatNormalTexture.scale=r.getClearcoatNormalScale())}}}),this}}xe.EXTENSION_NAME=pe;class de extends e{init(){this.extensionName="KHR_materials_emissive_strength",this.propertyType="EmissiveStrength",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{emissiveStrength:1})}getEmissiveStrength(){return this.get("emissiveStrength")}setEmissiveStrength(e){return this.set("emissiveStrength",e)}}de.EXTENSION_NAME="KHR_materials_emissive_strength";const Te="KHR_materials_emissive_strength";class me extends s{constructor(...e){super(...e),this.extensionName=Te}createEmissiveStrength(){return new de(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[Te]){const r=this.createEmissiveStrength();e.materials[s].setExtension(Te,r);const n=t.extensions[Te];void 0!==n.emissiveStrength&&r.setEmissiveStrength(n.emissiveStrength)}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(Te);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{},o.extensions[Te]={emissiveStrength:r.getEmissiveStrength()}}}),this}}me.EXTENSION_NAME=Te;class Ee extends e{init(){this.extensionName="KHR_materials_ior",this.propertyType="IOR",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{ior:0})}getIOR(){return this.get("ior")}setIOR(e){return this.set("ior",e)}}Ee.EXTENSION_NAME="KHR_materials_ior";const Ie="KHR_materials_ior";class Re extends s{constructor(...e){super(...e),this.extensionName=Ie}createIOR(){return new Ee(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[Ie]){const r=this.createIOR();e.materials[s].setExtension(Ie,r);const n=t.extensions[Ie];void 0!==n.ior&&r.setIOR(n.ior)}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(Ie);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{},o.extensions[Ie]={ior:r.getIOR()}}}),this}}Re.EXTENSION_NAME=Ie;const{R:Ne,G:_e}=d;class Se extends e{init(){this.extensionName="KHR_materials_iridescence",this.propertyType="Iridescence",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{iridescenceFactor:0,iridescenceTexture:null,iridescenceTextureInfo:new x(this.graph,"iridescenceTextureInfo"),iridescenceIOR:1.3,iridescenceThicknessMinimum:100,iridescenceThicknessMaximum:400,iridescenceThicknessTexture:null,iridescenceThicknessTextureInfo:new x(this.graph,"iridescenceThicknessTextureInfo")})}getIridescenceFactor(){return this.get("iridescenceFactor")}setIridescenceFactor(e){return this.set("iridescenceFactor",e)}getIridescenceTexture(){return this.getRef("iridescenceTexture")}getIridescenceTextureInfo(){return this.getRef("iridescenceTexture")?this.getRef("iridescenceTextureInfo"):null}setIridescenceTexture(e){return this.setRef("iridescenceTexture",e,{channels:Ne})}getIridescenceIOR(){return this.get("iridescenceIOR")}setIridescenceIOR(e){return this.set("iridescenceIOR",e)}getIridescenceThicknessMinimum(){return this.get("iridescenceThicknessMinimum")}setIridescenceThicknessMinimum(e){return this.set("iridescenceThicknessMinimum",e)}getIridescenceThicknessMaximum(){return this.get("iridescenceThicknessMaximum")}setIridescenceThicknessMaximum(e){return this.set("iridescenceThicknessMaximum",e)}getIridescenceThicknessTexture(){return this.getRef("iridescenceThicknessTexture")}getIridescenceThicknessTextureInfo(){return this.getRef("iridescenceThicknessTexture")?this.getRef("iridescenceThicknessTextureInfo"):null}setIridescenceThicknessTexture(e){return this.setRef("iridescenceThicknessTexture",e,{channels:_e})}}Se.EXTENSION_NAME="KHR_materials_iridescence";const Ae="KHR_materials_iridescence";class ye extends s{constructor(...e){super(...e),this.extensionName=Ae}createIridescence(){return new Se(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[Ae]){const n=this.createIridescence();e.materials[r].setExtension(Ae,n);const o=t.extensions[Ae];if(void 0!==o.iridescenceFactor&&n.setIridescenceFactor(o.iridescenceFactor),void 0!==o.iridescenceIor&&n.setIridescenceIOR(o.iridescenceIor),void 0!==o.iridescenceThicknessMinimum&&n.setIridescenceThicknessMinimum(o.iridescenceThicknessMinimum),void 0!==o.iridescenceThicknessMaximum&&n.setIridescenceThicknessMaximum(o.iridescenceThicknessMaximum),void 0!==o.iridescenceTexture){const t=o.iridescenceTexture;n.setIridescenceTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getIridescenceTextureInfo(),t)}if(void 0!==o.iridescenceThicknessTexture){const t=o.iridescenceThicknessTexture;n.setIridescenceThicknessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getIridescenceThicknessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(Ae);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[Ae]={};if(r.getIridescenceFactor()>0&&(i.iridescenceFactor=r.getIridescenceFactor()),1.3!==r.getIridescenceIOR()&&(i.iridescenceIor=r.getIridescenceIOR()),100!==r.getIridescenceThicknessMinimum()&&(i.iridescenceThicknessMinimum=r.getIridescenceThicknessMinimum()),400!==r.getIridescenceThicknessMaximum()&&(i.iridescenceThicknessMaximum=r.getIridescenceThicknessMaximum()),r.getIridescenceTexture()){const t=r.getIridescenceTexture(),s=r.getIridescenceTextureInfo();i.iridescenceTexture=e.createTextureInfoDef(t,s)}if(r.getIridescenceThicknessTexture()){const t=r.getIridescenceThicknessTexture(),s=r.getIridescenceThicknessTextureInfo();i.iridescenceThicknessTexture=e.createTextureInfoDef(t,s)}}}),this}}ye.EXTENSION_NAME=Ae;const{R:Ce,G:Me,B:Oe,A:we}=d;class De extends e{init(){this.extensionName="KHR_materials_pbrSpecularGlossiness",this.propertyType="PBRSpecularGlossiness",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{diffuseFactor:[1,1,1,1],diffuseTexture:null,diffuseTextureInfo:new x(this.graph,"diffuseTextureInfo"),specularFactor:[1,1,1],glossinessFactor:1,specularGlossinessTexture:null,specularGlossinessTextureInfo:new x(this.graph,"specularGlossinessTextureInfo")})}getDiffuseFactor(){return this.get("diffuseFactor")}setDiffuseFactor(e){return this.set("diffuseFactor",e)}getDiffuseHex(){return p.factorToHex(this.getDiffuseFactor())}setDiffuseHex(e){const t=this.getDiffuseFactor().slice();return this.setDiffuseFactor(p.hexToFactor(e,t))}getDiffuseTexture(){return this.getRef("diffuseTexture")}getDiffuseTextureInfo(){return this.getRef("diffuseTexture")?this.getRef("diffuseTextureInfo"):null}setDiffuseTexture(e){return this.setRef("diffuseTexture",e,{channels:Ce|Me|Oe|we})}getSpecularFactor(){return this.get("specularFactor")}setSpecularFactor(e){return this.set("specularFactor",e)}getGlossinessFactor(){return this.get("glossinessFactor")}setGlossinessFactor(e){return this.set("glossinessFactor",e)}getSpecularGlossinessTexture(){return this.getRef("specularGlossinessTexture")}getSpecularGlossinessTextureInfo(){return this.getRef("specularGlossinessTexture")?this.getRef("specularGlossinessTextureInfo"):null}setSpecularGlossinessTexture(e){return this.setRef("specularGlossinessTexture",e,{channels:Ce|Me|Oe|we})}}De.EXTENSION_NAME="KHR_materials_pbrSpecularGlossiness";const Fe="KHR_materials_pbrSpecularGlossiness";class be extends s{constructor(...e){super(...e),this.extensionName=Fe}createPBRSpecularGlossiness(){return new De(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[Fe]){const n=this.createPBRSpecularGlossiness();e.materials[r].setExtension(Fe,n);const o=t.extensions[Fe];if(void 0!==o.diffuseFactor&&n.setDiffuseFactor(o.diffuseFactor),void 0!==o.specularFactor&&n.setSpecularFactor(o.specularFactor),void 0!==o.glossinessFactor&&n.setGlossinessFactor(o.glossinessFactor),void 0!==o.diffuseTexture){const t=o.diffuseTexture;n.setDiffuseTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getDiffuseTextureInfo(),t)}if(void 0!==o.specularGlossinessTexture){const t=o.specularGlossinessTexture;n.setSpecularGlossinessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSpecularGlossinessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(Fe);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[Fe]={diffuseFactor:r.getDiffuseFactor(),specularFactor:r.getSpecularFactor(),glossinessFactor:r.getGlossinessFactor()};if(r.getDiffuseTexture()){const t=r.getDiffuseTexture(),s=r.getDiffuseTextureInfo();i.diffuseTexture=e.createTextureInfoDef(t,s)}if(r.getSpecularGlossinessTexture()){const t=r.getSpecularGlossinessTexture(),s=r.getSpecularGlossinessTextureInfo();i.specularGlossinessTexture=e.createTextureInfoDef(t,s)}}}),this}}be.EXTENSION_NAME=Fe;const{R:je,G:ve,B:ke,A:Be}=d;class Ge extends e{init(){this.extensionName="KHR_materials_sheen",this.propertyType="Sheen",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{sheenColorFactor:[0,0,0],sheenColorTexture:null,sheenColorTextureInfo:new x(this.graph,"sheenColorTextureInfo"),sheenRoughnessFactor:0,sheenRoughnessTexture:null,sheenRoughnessTextureInfo:new x(this.graph,"sheenRoughnessTextureInfo")})}getSheenColorFactor(){return this.get("sheenColorFactor")}getSheenColorHex(){return p.factorToHex(this.getSheenColorFactor())}setSheenColorFactor(e){return this.set("sheenColorFactor",e)}setSheenColorHex(e){const t=this.getSheenColorFactor().slice();return this.set("sheenColorFactor",p.hexToFactor(e,t))}getSheenColorTexture(){return this.getRef("sheenColorTexture")}getSheenColorTextureInfo(){return this.getRef("sheenColorTexture")?this.getRef("sheenColorTextureInfo"):null}setSheenColorTexture(e){return this.setRef("sheenColorTexture",e,{channels:je|ve|ke})}getSheenRoughnessFactor(){return this.get("sheenRoughnessFactor")}setSheenRoughnessFactor(e){return this.set("sheenRoughnessFactor",e)}getSheenRoughnessTexture(){return this.getRef("sheenRoughnessTexture")}getSheenRoughnessTextureInfo(){return this.getRef("sheenRoughnessTexture")?this.getRef("sheenRoughnessTextureInfo"):null}setSheenRoughnessTexture(e){return this.setRef("sheenRoughnessTexture",e,{channels:Be})}}Ge.EXTENSION_NAME="KHR_materials_sheen";const He="KHR_materials_sheen";class Le extends s{constructor(...e){super(...e),this.extensionName=He}createSheen(){return new Ge(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[He]){const n=this.createSheen();e.materials[r].setExtension(He,n);const o=t.extensions[He];if(void 0!==o.sheenColorFactor&&n.setSheenColorFactor(o.sheenColorFactor),void 0!==o.sheenRoughnessFactor&&n.setSheenRoughnessFactor(o.sheenRoughnessFactor),void 0!==o.sheenColorTexture){const t=o.sheenColorTexture;n.setSheenColorTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSheenColorTextureInfo(),t)}if(void 0!==o.sheenRoughnessTexture){const t=o.sheenRoughnessTexture;n.setSheenRoughnessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSheenRoughnessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(He);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[He]={sheenColorFactor:r.getSheenColorFactor(),sheenRoughnessFactor:r.getSheenRoughnessFactor()};if(r.getSheenColorTexture()){const t=r.getSheenColorTexture(),s=r.getSheenColorTextureInfo();i.sheenColorTexture=e.createTextureInfoDef(t,s)}if(r.getSheenRoughnessTexture()){const t=r.getSheenRoughnessTexture(),s=r.getSheenRoughnessTextureInfo();i.sheenRoughnessTexture=e.createTextureInfoDef(t,s)}}}),this}}Le.EXTENSION_NAME=He;const{R:Ue,G:Pe,B:Ve,A:Xe}=d;class Ke extends e{init(){this.extensionName="KHR_materials_specular",this.propertyType="Specular",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{specularFactor:1,specularTexture:null,specularTextureInfo:new x(this.graph,"specularTextureInfo"),specularColorFactor:[1,1,1],specularColorTexture:null,specularColorTextureInfo:new x(this.graph,"specularColorTextureInfo")})}getSpecularFactor(){return this.get("specularFactor")}setSpecularFactor(e){return this.set("specularFactor",e)}getSpecularColorFactor(){return this.get("specularColorFactor")}setSpecularColorFactor(e){return this.set("specularColorFactor",e)}getSpecularColorHex(){return p.factorToHex(this.getSpecularColorFactor())}setSpecularColorHex(e){const t=this.getSpecularColorFactor().slice();return this.set("specularColorFactor",p.hexToFactor(e,t))}getSpecularTexture(){return this.getRef("specularTexture")}getSpecularTextureInfo(){return this.getRef("specularTexture")?this.getRef("specularTextureInfo"):null}setSpecularTexture(e){return this.setRef("specularTexture",e,{channels:Xe})}getSpecularColorTexture(){return this.getRef("specularColorTexture")}getSpecularColorTextureInfo(){return this.getRef("specularColorTexture")?this.getRef("specularColorTextureInfo"):null}setSpecularColorTexture(e){return this.setRef("specularColorTexture",e,{channels:Ue|Pe|Ve})}}Ke.EXTENSION_NAME="KHR_materials_specular";const ze="KHR_materials_specular";class qe extends s{constructor(...e){super(...e),this.extensionName=ze}createSpecular(){return new Ke(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[ze]){const n=this.createSpecular();e.materials[r].setExtension(ze,n);const o=t.extensions[ze];if(void 0!==o.specularFactor&&n.setSpecularFactor(o.specularFactor),void 0!==o.specularColorFactor&&n.setSpecularColorFactor(o.specularColorFactor),void 0!==o.specularTexture){const t=o.specularTexture;n.setSpecularTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSpecularTextureInfo(),t)}if(void 0!==o.specularColorTexture){const t=o.specularColorTexture;n.setSpecularColorTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSpecularColorTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(ze);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[ze]={};if(1!==r.getSpecularFactor()&&(i.specularFactor=r.getSpecularFactor()),l.eq(r.getSpecularColorFactor(),[1,1,1])||(i.specularColorFactor=r.getSpecularColorFactor()),r.getSpecularTexture()){const t=r.getSpecularTexture(),s=r.getSpecularTextureInfo();i.specularTexture=e.createTextureInfoDef(t,s)}if(r.getSpecularColorTexture()){const t=r.getSpecularColorTexture(),s=r.getSpecularColorTextureInfo();i.specularColorTexture=e.createTextureInfoDef(t,s)}}}),this}}qe.EXTENSION_NAME=ze;const{R:$e}=d;class Ye extends e{init(){this.extensionName="KHR_materials_transmission",this.propertyType="Transmission",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{transmissionFactor:0,transmissionTexture:null,transmissionTextureInfo:new x(this.graph,"transmissionTextureInfo")})}getTransmissionFactor(){return this.get("transmissionFactor")}setTransmissionFactor(e){return this.set("transmissionFactor",e)}getTransmissionTexture(){return this.getRef("transmissionTexture")}getTransmissionTextureInfo(){return this.getRef("transmissionTexture")?this.getRef("transmissionTextureInfo"):null}setTransmissionTexture(e){return this.setRef("transmissionTexture",e,{channels:$e})}}Ye.EXTENSION_NAME="KHR_materials_transmission";const Qe="KHR_materials_transmission";class We extends s{constructor(...e){super(...e),this.extensionName=Qe}createTransmission(){return new Ye(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[Qe]){const n=this.createTransmission();e.materials[r].setExtension(Qe,n);const o=t.extensions[Qe];if(void 0!==o.transmissionFactor&&n.setTransmissionFactor(o.transmissionFactor),void 0!==o.transmissionTexture){const t=o.transmissionTexture;n.setTransmissionTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getTransmissionTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(Qe);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[Qe]={transmissionFactor:r.getTransmissionFactor()};if(r.getTransmissionTexture()){const t=r.getTransmissionTexture(),s=r.getTransmissionTextureInfo();i.transmissionTexture=e.createTextureInfoDef(t,s)}}}),this}}We.EXTENSION_NAME=Qe;class Je extends e{init(){this.extensionName="KHR_materials_unlit",this.propertyType="Unlit",this.parentTypes=[t.MATERIAL]}}Je.EXTENSION_NAME="KHR_materials_unlit";const Ze="KHR_materials_unlit";class et extends s{constructor(...e){super(...e),this.extensionName=Ze}createUnlit(){return new Je(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{t.extensions&&t.extensions[Ze]&&e.materials[s].setExtension(Ze,this.createUnlit())}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{if(s.getExtension(Ze)){const r=e.materialIndexMap.get(s),n=t.json.materials[r];n.extensions=n.extensions||{},n.extensions[Ze]={}}}),this}}et.EXTENSION_NAME=Ze;class tt extends e{init(){this.extensionName="KHR_materials_variants",this.propertyType="Mapping",this.parentTypes=["MappingList"]}getDefaults(){return Object.assign(super.getDefaults(),{material:null,variants:[]})}getMaterial(){return this.getRef("material")}setMaterial(e){return this.setRef("material",e)}addVariant(e){return this.addRef("variants",e)}removeVariant(e){return this.removeRef("variants",e)}listVariants(){return this.listRefs("variants")}}tt.EXTENSION_NAME="KHR_materials_variants";class st extends e{init(){this.extensionName="KHR_materials_variants",this.propertyType="MappingList",this.parentTypes=[t.PRIMITIVE]}getDefaults(){return Object.assign(super.getDefaults(),{mappings:[]})}addMapping(e){return this.addRef("mappings",e)}removeMapping(e){return this.removeRef("mappings",e)}listMappings(){return this.listRefs("mappings")}}st.EXTENSION_NAME="KHR_materials_variants";class rt extends e{init(){this.extensionName="KHR_materials_variants",this.propertyType="Variant",this.parentTypes=["MappingList"]}}rt.EXTENSION_NAME="KHR_materials_variants";const nt="KHR_materials_variants";class ot extends s{constructor(...e){super(...e),this.extensionName=nt}createMappingList(){return new st(this.document.getGraph())}createVariant(e=""){return new rt(this.document.getGraph(),e)}createMapping(){return new tt(this.document.getGraph())}listVariants(){return Array.from(this.properties).filter(e=>e instanceof rt)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[nt])return this;const s=(t.json.extensions[nt].variants||[]).map(e=>this.createVariant().setName(e.name||""));return(t.json.meshes||[]).forEach((t,r)=>{const n=e.meshes[r];(t.primitives||[]).forEach((t,r)=>{if(!t.extensions||!t.extensions[nt])return;const o=this.createMappingList(),i=t.extensions[nt];for(const t of i.mappings){const r=this.createMapping();void 0!==t.material&&r.setMaterial(e.materials[t.material]);for(const e of t.variants||[])r.addVariant(s[e]);o.addMapping(r)}n.listPrimitives()[r].setExtension(nt,o)})}),this}write(e){const t=e.jsonDoc,s=this.listVariants();if(!s.length)return this;const r=[],n=new Map;for(const t of s)n.set(t,r.length),r.push(e.createPropertyDef(t));for(const t of this.document.getRoot().listMeshes()){const s=e.meshIndexMap.get(t);t.listPrimitives().forEach((t,r)=>{const o=t.getExtension(nt);if(!o)return;const i=e.jsonDoc.json.meshes[s].primitives[r],a=o.listMappings().map(t=>{const s=e.createPropertyDef(t),r=t.getMaterial();return r&&(s.material=e.materialIndexMap.get(r)),s.variants=t.listVariants().map(e=>n.get(e)),s});i.extensions=i.extensions||{},i.extensions[nt]={mappings:a}})}return t.json.extensions=t.json.extensions||{},t.json.extensions[nt]={variants:r},this}}ot.EXTENSION_NAME=nt;const{G:it}=d;class at extends e{init(){this.extensionName="KHR_materials_volume",this.propertyType="Volume",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{thicknessFactor:0,thicknessTexture:null,thicknessTextureInfo:new x(this.graph,"thicknessTexture"),attenuationDistance:Infinity,attenuationColor:[1,1,1]})}getThicknessFactor(){return this.get("thicknessFactor")}setThicknessFactor(e){return this.set("thicknessFactor",e)}getThicknessTexture(){return this.getRef("thicknessTexture")}getThicknessTextureInfo(){return this.getRef("thicknessTexture")?this.getRef("thicknessTextureInfo"):null}setThicknessTexture(e){return this.setRef("thicknessTexture",e,{channels:it})}getAttenuationDistance(){return this.get("attenuationDistance")}setAttenuationDistance(e){return this.set("attenuationDistance",e)}getAttenuationColor(){return this.get("attenuationColor")}setAttenuationColor(e){return this.set("attenuationColor",e)}getAttenuationColorHex(){return p.factorToHex(this.getAttenuationColor())}setAttenuationColorHex(e){const t=this.getAttenuationColor().slice();return this.set("attenuationColor",p.hexToFactor(e,t))}}at.EXTENSION_NAME="KHR_materials_volume";const ct="KHR_materials_volume";class ut extends s{constructor(...e){super(...e),this.extensionName=ct}createVolume(){return new at(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[ct]){const n=this.createVolume();e.materials[r].setExtension(ct,n);const o=t.extensions[ct];if(void 0!==o.thicknessFactor&&n.setThicknessFactor(o.thicknessFactor),void 0!==o.attenuationDistance&&n.setAttenuationDistance(o.attenuationDistance),void 0!==o.attenuationColor&&n.setAttenuationColor(o.attenuationColor),void 0!==o.thicknessTexture){const t=o.thicknessTexture;n.setThicknessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getThicknessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(ct);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[ct]={};if(r.getThicknessFactor()>0&&(i.thicknessFactor=r.getThicknessFactor()),Number.isFinite(r.getAttenuationDistance())&&(i.attenuationDistance=r.getAttenuationDistance()),l.eq(r.getAttenuationColor(),[1,1,1])||(i.attenuationColor=r.getAttenuationColor()),r.getThicknessTexture()){const t=r.getThicknessTexture(),s=r.getThicknessTextureInfo();i.thicknessTexture=e.createTextureInfoDef(t,s)}}}),this}}ut.EXTENSION_NAME=ct;const lt="KHR_mesh_quantization";class ht extends s{constructor(...e){super(...e),this.extensionName=lt}read(e){return this}write(e){return this}}ht.EXTENSION_NAME=lt;const ft="KHR_texture_basisu";class gt{match(e){return 171===e[0]&&75===e[1]&&84===e[2]&&88===e[3]&&32===e[4]&&50===e[5]&&48===e[6]&&187===e[7]&&13===e[8]&&10===e[9]&&26===e[10]&&10===e[11]}getSize(e){const t=T(e);return[t.pixelWidth,t.pixelHeight]}getChannels(e){const t=T(e).dataFormatDescriptor[0];if(t.colorModel===m)return 2===t.samples.length&&15==(15&t.samples[1].channelType)?4:3;if(t.colorModel===E)return 3==(15&t.samples[0].channelType)?4:3;throw new Error(`Unexpected KTX2 colorModel, "${t.colorModel}".`)}getGPUByteLength(e){const t=T(e),s=this.getChannels(e)>3;let r=0;for(let e=0;e<t.levels.length;e++){const n=t.levels[e];r+=n.uncompressedByteLength?n.uncompressedByteLength:Math.max(1,Math.floor(t.pixelWidth/Math.pow(2,e)))/4*(Math.max(1,Math.floor(t.pixelHeight/Math.pow(2,e)))/4)*(s?16:8)}return r}}class pt extends s{constructor(...e){super(...e),this.extensionName=ft,this.prereadTypes=[t.TEXTURE]}static register(){f.registerFormat("image/ktx2",new gt)}preread(e){return e.jsonDoc.json.textures.forEach(e=>{e.extensions&&e.extensions[ft]&&(e.source=e.extensions[ft].source)}),this}read(e){return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listTextures().forEach(s=>{if("image/ktx2"===s.getMimeType()){const r=e.imageIndexMap.get(s);t.json.textures.forEach(e=>{e.source===r&&(e.extensions=e.extensions||{},e.extensions[ft]={source:e.source},delete e.source)})}}),this}}pt.EXTENSION_NAME=ft;class xt extends e{init(){this.extensionName="KHR_texture_transform",this.propertyType="Transform",this.parentTypes=[t.TEXTURE_INFO]}getDefaults(){return Object.assign(super.getDefaults(),{offset:[0,0],rotation:0,scale:[1,1],texCoord:null})}getOffset(){return this.get("offset")}setOffset(e){return this.set("offset",e)}getRotation(){return this.get("rotation")}setRotation(e){return this.set("rotation",e)}getScale(){return this.get("scale")}setScale(e){return this.set("scale",e)}getTexCoord(){return this.get("texCoord")}setTexCoord(e){return this.set("texCoord",e)}}xt.EXTENSION_NAME="KHR_texture_transform";const dt="KHR_texture_transform";class Tt extends s{constructor(...e){super(...e),this.extensionName=dt}createTransform(){return new xt(this.document.getGraph())}read(e){for(const[t,s]of Array.from(e.textureInfos.entries())){if(!s.extensions||!s.extensions[dt])continue;const e=this.createTransform(),r=s.extensions[dt];void 0!==r.offset&&e.setOffset(r.offset),void 0!==r.rotation&&e.setRotation(r.rotation),void 0!==r.scale&&e.setScale(r.scale),void 0!==r.texCoord&&e.setTexCoord(r.texCoord),t.setExtension(dt,e)}return this}write(e){const t=Array.from(e.textureInfoDefMap.entries());for(const[e,s]of t){const t=e.getExtension(dt);if(!t)continue;s.extensions=s.extensions||{};const r={},n=l.eq;n(t.getOffset(),[0,0])||(r.offset=t.getOffset()),0!==t.getRotation()&&(r.rotation=t.getRotation()),n(t.getScale(),[1,1])||(r.scale=t.getScale()),null!=t.getTexCoord()&&(r.texCoord=t.getTexCoord()),s.extensions[dt]=r}return this}}Tt.EXTENSION_NAME=dt;const mt=[t.ROOT,t.SCENE,t.NODE,t.MESH,t.MATERIAL,t.TEXTURE,t.ANIMATION];class Et extends e{init(){this.extensionName="KHR_xmp_json_ld",this.propertyType="Packet",this.parentTypes=mt}getDefaults(){return Object.assign(super.getDefaults(),{context:{},properties:{}})}getContext(){return this.get("context")}setContext(e){return this.set("context",S({},e))}listProperties(){return Object.keys(this.get("properties"))}getProperty(e){const t=this.get("properties");return e in t?t[e]:null}setProperty(e,t){this._assertContext(e);const s=S({},this.get("properties"));return t?s[e]=t:delete s[e],this.set("properties",s)}toJSONLD(){return S({"@context":It(this.get("context"))},It(this.get("properties")))}fromJSONLD(e){const t=(e=It(e))["@context"];return t&&this.set("context",t),delete e["@context"],this.set("properties",e)}_assertContext(e){if(!(e.split(":")[0]in this.get("context")))throw new Error(`KHR_xmp_json_ld: Missing context for term, "${e}".`)}}function It(e){return JSON.parse(JSON.stringify(e))}Et.EXTENSION_NAME="KHR_xmp_json_ld";const Rt="KHR_xmp_json_ld";class Nt extends s{constructor(...e){super(...e),this.extensionName=Rt}createPacket(){return new Et(this.document.getGraph())}listPackets(){return Array.from(this.properties)}read(e){var t;const s=null==(t=e.jsonDoc.json.extensions)?void 0:t[Rt];if(!s||!s.packets)return this;const r=e.jsonDoc.json,n=this.document.getRoot(),o=s.packets.map(e=>this.createPacket().fromJSONLD(e)),i=[[r.asset],r.scenes,r.nodes,r.meshes,r.materials,r.images,r.animations],a=[[n],n.listScenes(),n.listNodes(),n.listMeshes(),n.listMaterials(),n.listTextures(),n.listAnimations()];for(let e=0;e<i.length;e++){const t=i[e]||[];for(let s=0;s<t.length;s++){const r=t[s];r.extensions&&r.extensions[Rt]&&a[e][s].setExtension(Rt,o[r.extensions[Rt].packet])}}return this}write(e){const{json:s}=e.jsonDoc,r=[];for(const n of this.properties){r.push(n.toJSONLD());for(const o of n.listParents()){let n;switch(o.propertyType){case t.ROOT:n=s.asset;break;case t.SCENE:n=s.scenes[e.sceneIndexMap.get(o)];break;case t.NODE:n=s.nodes[e.nodeIndexMap.get(o)];break;case t.MESH:n=s.meshes[e.meshIndexMap.get(o)];break;case t.MATERIAL:n=s.materials[e.materialIndexMap.get(o)];break;case t.TEXTURE:n=s.images[e.imageIndexMap.get(o)];break;case t.ANIMATION:n=s.animations[e.animationIndexMap.get(o)];break;default:n=null,this.document.getLogger().warn(`[${Rt}]: Unsupported parent property, "${o.propertyType}"`)}n&&(n.extensions=n.extensions||{},n.extensions[Rt]={packet:r.length-1})}}return r.length>0&&(s.extensions=s.extensions||{},s.extensions[Rt]={packets:r}),this}}Nt.EXTENSION_NAME=Rt;const _t=[oe,ue,xe,me,Re,ye,be,qe,Le,We,et,ot,ut,ht,pt,Tt,Nt],St=[_,H,P,..._t];export{St as ALL_EXTENSIONS,ge as Clearcoat,oe as DracoMeshCompression,de as EmissiveStrength,I as INSTANCE_ATTRIBUTE,Ee as IOR,R as InstancedMesh,Se as Iridescence,_t as KHRONOS_EXTENSIONS,ae as Light,ue as LightsPunctual,tt as Mapping,st as MappingList,xe as MaterialsClearcoat,me as MaterialsEmissiveStrength,Re as MaterialsIOR,ye as MaterialsIridescence,be as MaterialsPBRSpecularGlossiness,Le as MaterialsSheen,qe as MaterialsSpecular,We as MaterialsTransmission,et as MaterialsUnlit,ot as MaterialsVariants,ut as MaterialsVolume,_ as MeshGPUInstancing,ht as MeshQuantization,H as MeshoptCompression,De as PBRSpecularGlossiness,Et as Packet,Ge as Sheen,Ke as Specular,pt as TextureBasisu,Tt as TextureTransform,P as TextureWebP,xt as Transform,Ye as Transmission,Je as Unlit,rt as Variant,at as Volume,Nt as XMP};
import{ExtensionProperty as e,PropertyType as t,Extension as s,BufferUtils as r,WriterContext as n,Primitive as o,Root as i,AnimationSampler as a,AnimationChannel as c,Accessor as u,MathUtils as l,GLB_BUFFER as h,ImageUtils as f,bounds as g,ColorUtils as p,TextureInfo as x,TextureChannel as d}from"@gltf-transform/core";import{read as T,KHR_DF_MODEL_ETC1S as m,KHR_DF_MODEL_UASTC as E}from"ktx-parse";const I="INSTANCE_ATTRIBUTE";class R extends e{init(){this.extensionName="EXT_mesh_gpu_instancing",this.propertyType="InstancedMesh",this.parentTypes=[t.NODE]}getDefaults(){return Object.assign(super.getDefaults(),{attributes:{}})}getAttribute(e){return this.getRefMap("attributes",e)}setAttribute(e,t){return this.setRefMap("attributes",e,t,{usage:"INSTANCE_ATTRIBUTE"})}listAttributes(){return this.listRefMapValues("attributes")}listSemantics(){return this.listRefMapKeys("attributes")}}R.EXTENSION_NAME="EXT_mesh_gpu_instancing";const N="EXT_mesh_gpu_instancing";class _ extends s{constructor(...e){super(...e),this.extensionName=N,this.provideTypes=[t.NODE],this.prewriteTypes=[t.ACCESSOR]}createInstancedMesh(){return new R(this.document.getGraph())}read(e){return(e.jsonDoc.json.nodes||[]).forEach((t,s)=>{if(!t.extensions||!t.extensions[N])return;const r=t.extensions[N],n=this.createInstancedMesh();for(const t in r.attributes)n.setAttribute(t,e.accessors[r.attributes[t]]);e.nodes[s].setExtension(N,n)}),this}prewrite(e){e.accessorUsageGroupedByParent.add("INSTANCE_ATTRIBUTE");for(const t of this.properties)for(const s of t.listAttributes())e.addAccessorToUsageGroup(s,"INSTANCE_ATTRIBUTE");return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listNodes().forEach(s=>{const r=s.getExtension(N);if(r){const n=e.nodeIndexMap.get(s),o=t.json.nodes[n],i={attributes:{}};r.listSemantics().forEach(t=>{const s=r.getAttribute(t);i.attributes[t]=e.accessorIndexMap.get(s)}),o.extensions=o.extensions||{},o.extensions[N]=i}}),this}}function S(){return(S=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(e[r]=s[r])}return e}).apply(this,arguments)}var A,y,C;_.EXTENSION_NAME=N,function(e){e.QUANTIZE="quantize",e.FILTER="filter"}(A||(A={})),function(e){e.ATTRIBUTES="ATTRIBUTES",e.TRIANGLES="TRIANGLES",e.INDICES="INDICES"}(y||(y={})),function(e){e.NONE="NONE",e.OCTAHEDRAL="OCTAHEDRAL",e.QUATERNION="QUATERNION",e.EXPONENTIAL="EXPONENTIAL"}(C||(C={}));const{BYTE:M,SHORT:O,FLOAT:w}=u.ComponentType,{normalize:D,denormalize:F}=l;function b(e,t,s,n){const{filter:o,bits:i}=n,a={array:e.getArray(),byteStride:e.getElementSize()*e.getComponentSize(),componentType:e.getComponentType(),normalized:e.getNormalized()};if(s!==y.ATTRIBUTES)return a;if(o!==C.NONE){let s=e.getNormalized()?function(e){const t=e.getComponentType(),s=e.getArray(),r=new Float32Array(s.length);for(let e=0;e<s.length;e++)r[e]=F(s[e],t);return r}(e):new Float32Array(a.array);switch(o){case C.EXPONENTIAL:a.byteStride=4*e.getElementSize(),a.componentType=w,a.normalized=!1,a.array=t.encodeFilterExp(s,e.getCount(),a.byteStride,i);break;case C.OCTAHEDRAL:a.byteStride=i>8?8:4,a.componentType=i>8?O:M,a.normalized=!0,s=3===e.getElementSize()?function(e){const t=new Float32Array(4*e.length/3);for(let s=0,r=e.length/3;s<r;s++)t[4*s]=e[3*s],t[4*s+1]=e[3*s+1],t[4*s+2]=e[3*s+2];return t}(s):s,a.array=t.encodeFilterOct(s,e.getCount(),a.byteStride,i);break;case C.QUATERNION:a.byteStride=8,a.componentType=O,a.normalized=!0,a.array=t.encodeFilterQuat(s,e.getCount(),a.byteStride,i);break;default:throw new Error("Invalid filter.")}a.min=e.getMin([]),a.max=e.getMax([]),e.getNormalized()&&(a.min=a.min.map(t=>F(t,e.getComponentType())),a.max=a.max.map(t=>F(t,e.getComponentType()))),a.normalized&&(a.min=a.min.map(e=>D(e,a.componentType)),a.max=a.max.map(e=>D(e,a.componentType)))}else a.byteStride%4&&(a.array=function(e,t){const s=r.padNumber(e.BYTES_PER_ELEMENT*t)/e.BYTES_PER_ELEMENT,n=new e.constructor(e.length/t*s);for(let r=0;r*t<e.length;r++)for(let o=0;o<t;o++)n[r*s+o]=e[r*t+o];return n}(a.array,e.getElementSize()),a.byteStride=a.array.byteLength/e.getCount());return a}function j(e,t){return t===n.BufferViewUsage.ELEMENT_ARRAY_BUFFER?e.listParents().some(e=>e instanceof o&&e.getMode()===o.Mode.TRIANGLES)?y.TRIANGLES:y.INDICES:y.ATTRIBUTES}function v(e,t){const s=t.getGraph().listParentEdges(e).filter(e=>!(e.getParent()instanceof i));for(const t of s){const s=t.getName(),r=t.getAttributes().key||"";if("indices"===s)return{filter:C.NONE};if("attributes"===s){if("POSITION"===r)return{filter:C.NONE};if("TEXCOORD_0"===r)return{filter:C.NONE};if("NORMAL"===r)return{filter:C.OCTAHEDRAL,bits:8};if("TANGENT"===r)return{filter:C.OCTAHEDRAL,bits:8};if(r.startsWith("JOINTS_"))return{filter:C.NONE};if(r.startsWith("WEIGHTS_"))return{filter:C.NONE}}if("output"===s){const t=k(e);return"rotation"===t?{filter:C.QUATERNION,bits:16}:"translation"===t||"scale"===t?{filter:C.EXPONENTIAL,bits:12}:{filter:C.NONE}}if("input"===s)return{filter:C.NONE};if("inverseBindMatrices"===s)return{filter:C.NONE}}return{filter:C.NONE}}function k(e){for(const t of e.listParents())if(t instanceof a)for(const e of t.listParents())if(e instanceof c)return e.getTargetPath();return null}const B="EXT_meshopt_compression",G={method:A.QUANTIZE};class H extends s{constructor(...e){super(...e),this.extensionName=B,this.prereadTypes=[t.BUFFER,t.PRIMITIVE],this.prewriteTypes=[t.BUFFER,t.ACCESSOR],this.readDependencies=["meshopt.decoder"],this.writeDependencies=["meshopt.encoder"],this._decoder=null,this._decoderFallbackBufferMap=new Map,this._encoder=null,this._encoderOptions=G,this._encoderFallbackBuffer=null,this._encoderBufferViews={},this._encoderBufferViewData={},this._encoderBufferViewAccessors={}}install(e,t){return"meshopt.decoder"===e&&(this._decoder=t),"meshopt.encoder"===e&&(this._encoder=t),this}setEncoderOptions(e){return this._encoderOptions=S({},G,e),this}preread(e,s){if(!this._decoder){if(!this.isRequired())return this;throw new Error(`[${B}] Please install extension dependency, "meshopt.decoder".`)}if(!this._decoder.supported){if(!this.isRequired())return this;throw new Error(`[${B}]: Missing WASM support.`)}return s===t.BUFFER?this._prereadBuffers(e):s===t.PRIMITIVE&&this._prereadPrimitives(e),this}_prereadBuffers(e){const t=e.jsonDoc;(t.json.bufferViews||[]).forEach((s,n)=>{if(!s.extensions||!s.extensions[B])return;const o=s.extensions[B],i=o.byteOffset||0,a=o.byteLength||0,c=o.count,u=o.byteStride,l=new Uint8Array(c*u),f=t.json.buffers[s.buffer],g=r.toView(f.uri?t.resources[f.uri]:t.resources[h],i,a);this._decoder.decodeGltfBuffer(l,c,u,g,o.mode,o.filter),e.bufferViews[n]=l})}_prereadPrimitives(e){const t=e.jsonDoc;(t.json.bufferViews||[]).forEach(s=>{var r;s.extensions&&s.extensions[B]&&(r=t.json.buffers[s.buffer]).extensions&&r.extensions.EXT_meshopt_compression&&r.extensions.EXT_meshopt_compression.fallback&&this._decoderFallbackBufferMap.set(e.buffers[s.buffer],e.buffers[s.extensions[B].buffer])})}read(e){if(!this.isRequired())return this;for(const[e,t]of this._decoderFallbackBufferMap){for(const s of e.listParents())s instanceof u&&s.swap(e,t);e.dispose()}return this}prewrite(e,s){return s===t.ACCESSOR?this._prewriteAccessors(e):s===t.BUFFER&&this._prewriteBuffers(e),this}_prewriteAccessors(e){const t=e.jsonDoc.json,s=this._encoder,r=this._encoderOptions,o=this.document.createBuffer(),i=this.document.getRoot().listBuffers().indexOf(o);this._encoderFallbackBuffer=o,this._encoderBufferViews={},this._encoderBufferViewData={},this._encoderBufferViewAccessors={};for(const o of this.document.getRoot().listAccessors()){if("weights"===k(o))continue;const a=e.getAccessorUsage(o),c=j(o,a),u=r.method===A.FILTER?v(o,this.document):{filter:C.NONE},l=b(o,s,c,u),{array:h,byteStride:f}=l,g=o.getBuffer();if(!g)throw new Error(`${B}: Missing buffer for accessor.`);const p=this.document.getRoot().listBuffers().indexOf(g),x=[a,c,u.filter,f,p].join(":");let d=this._encoderBufferViews[x],T=this._encoderBufferViewData[x],m=this._encoderBufferViewAccessors[x];d&&T||(m=this._encoderBufferViewAccessors[x]=[],T=this._encoderBufferViewData[x]=[],d=this._encoderBufferViews[x]={buffer:i,target:n.USAGE_TO_TARGET[a],byteOffset:0,byteLength:0,byteStride:a===n.BufferViewUsage.ARRAY_BUFFER?f:void 0,extensions:{[B]:{buffer:p,byteOffset:0,byteLength:0,mode:c,filter:u.filter!==C.NONE?u.filter:void 0,byteStride:f,count:0}}});const E=e.createAccessorDef(o);E.componentType=l.componentType,E.normalized=l.normalized,E.byteOffset=d.byteLength,E.min&&l.min&&(E.min=l.min),E.max&&l.max&&(E.max=l.max),e.accessorIndexMap.set(o,t.accessors.length),t.accessors.push(E),m.push(E),T.push(new Uint8Array(h.buffer,h.byteOffset,h.byteLength)),d.byteLength+=h.byteLength,d.extensions.EXT_meshopt_compression.count+=o.getCount()}}_prewriteBuffers(e){const t=this._encoder;for(const s in this._encoderBufferViews){const n=this._encoderBufferViews[s],o=this._encoderBufferViewData[s],i=this.document.getRoot().listBuffers()[n.extensions[B].buffer],a=e.otherBufferViews.get(i)||[],{count:c,byteStride:u,mode:l}=n.extensions[B],h=r.concat(o),f=t.encodeGltfBuffer(h,c,u,l),g=r.pad(f);n.extensions[B].byteLength=f.byteLength,o.length=0,o.push(g),a.push(g),e.otherBufferViews.set(i,a)}}write(e){let t=0;for(const s in this._encoderBufferViews){const n=this._encoderBufferViews[s],o=e.otherBufferViewsIndexMap.get(this._encoderBufferViewData[s][0]),i=this._encoderBufferViewAccessors[s];for(const e of i)e.bufferView=o;const a=e.jsonDoc.json.bufferViews[o],c=a.byteOffset||0;Object.assign(a,n),a.byteOffset=t,a.extensions[B].byteOffset=c,t+=r.padNumber(n.byteLength)}const s=this._encoderFallbackBuffer,n=e.bufferIndexMap.get(s),o=e.jsonDoc.json.buffers[n];return o.byteLength=t,o.extensions={[B]:{fallback:!0}},s.dispose(),this}}H.EXTENSION_NAME=B,H.EncoderMethod=A;const L="EXT_texture_webp";class U{match(e){return e.length>=12&&87===e[8]&&69===e[9]&&66===e[10]&&80===e[11]}getSize(e){const t=r.decodeText(e.slice(0,4)),s=r.decodeText(e.slice(8,12));if("RIFF"!==t||"WEBP"!==s)return null;const n=new DataView(e.buffer,e.byteOffset);let o=12;for(;o<n.byteLength;){const e=r.decodeText(new Uint8Array([n.getUint8(o),n.getUint8(o+1),n.getUint8(o+2),n.getUint8(o+3)])),t=n.getUint32(o+4,!0);if("VP8 "===e)return[16383&n.getInt16(o+14,!0),16383&n.getInt16(o+16,!0)];if("VP8L"===e){const e=n.getUint8(o+9),t=n.getUint8(o+10),s=n.getUint8(o+11);return[1+((63&t)<<8|e),1+((15&n.getUint8(o+12))<<10|s<<2|(192&t)>>6)]}o+=8+t+t%2}return null}getChannels(e){return 4}}class P extends s{constructor(...e){super(...e),this.extensionName=L,this.prereadTypes=[t.TEXTURE]}static register(){f.registerFormat("image/webp",new U)}preread(e){return(e.jsonDoc.json.textures||[]).forEach(e=>{e.extensions&&e.extensions[L]&&(e.source=e.extensions[L].source)}),this}read(e){return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listTextures().forEach(s=>{if("image/webp"===s.getMimeType()){const r=e.imageIndexMap.get(s);(t.json.textures||[]).forEach(e=>{e.source===r&&(e.extensions=e.extensions||{},e.extensions[L]={source:e.source},delete e.source)})}}),this}}P.EXTENSION_NAME=L;const V="KHR_draco_mesh_compression";let X,K,z,$;function q(e,t){const s=new X.DecoderBuffer;try{if(s.Init(t,t.length),e.GetEncodedGeometryType(s)!==X.TRIANGULAR_MESH)throw new Error(`[${V}] Unknown geometry type.`);const r=new X.Mesh;if(!e.DecodeBufferToMesh(s,r).ok()||0===r.ptr)throw new Error(`[${V}] Decoding failure.`);return r}finally{X.destroy(s)}}function Y(e,t){const s=3*t.num_faces();let r,n;if(t.num_points()<=65534){const o=s*Uint16Array.BYTES_PER_ELEMENT;r=X._malloc(o),e.GetTrianglesUInt16Array(t,o,r),n=new Uint16Array(X.HEAPU16.buffer,r,s).slice()}else{const o=s*Uint32Array.BYTES_PER_ELEMENT;r=X._malloc(o),e.GetTrianglesUInt32Array(t,o,r),n=new Uint32Array(X.HEAPU32.buffer,r,s).slice()}return X._free(r),n}function Q(e,t,s,r){const n=z[r.componentType],o=K[r.componentType],i=s.num_components(),a=t.num_points()*i,c=a*o.BYTES_PER_ELEMENT,u=X._malloc(c);e.GetAttributeDataArrayForAllPoints(t,s,n,c,u);const l=new o(X.HEAPF32.buffer,u,a).slice();return X._free(u),l}var W,J;!function(e){e[e.EDGEBREAKER=1]="EDGEBREAKER",e[e.SEQUENTIAL=0]="SEQUENTIAL"}(W||(W={})),function(e){e.POSITION="POSITION",e.NORMAL="NORMAL",e.COLOR="COLOR",e.TEX_COORD="TEX_COORD",e.GENERIC="GENERIC"}(J||(J={}));const Z={[J.POSITION]:14,[J.NORMAL]:10,[J.COLOR]:8,[J.TEX_COORD]:12,[J.GENERIC]:12},ee={decodeSpeed:5,encodeSpeed:5,method:W.EDGEBREAKER,quantizationBits:Z,quantizationVolume:"mesh"};function te(e,t=ee){const s=S({},ee,t);s.quantizationBits=S({},Z,t.quantizationBits);const r=new $.Encoder,n=new $.MeshBuilder,o=new $.Mesh,i={},a=new $.DracoInt8Array;for(const t of e.listSemantics()){const a=e.getAttribute(t),c=se(t),u=re(n,a.getComponentType(),o,$[c],a.getCount(),a.getElementSize(),a.getArray());if(-1===u)throw new Error(`Error compressing "${t}" attribute.`);if(i[t]=u,"mesh"===s.quantizationVolume||"POSITION"!==t)r.SetAttributeQuantization($[c],s.quantizationBits[c]);else{if("object"!=typeof s.quantizationVolume)throw new Error("Invalid quantization volume state.");{const{quantizationVolume:e}=s,t=Math.max(e.max[0]-e.min[0],e.max[1]-e.min[1],e.max[2]-e.min[2]);r.SetAttributeExplicitQuantization($[c],s.quantizationBits[c],a.getElementSize(),e.min,t)}}}const c=e.getIndices();if(!c)throw new ne("Primitive must have indices.");n.AddFacesToMesh(o,c.getCount()/3,c.getArray()),r.SetSpeedOptions(s.encodeSpeed,s.decodeSpeed),r.SetTrackEncodedProperties(!0),s.method===W.SEQUENTIAL||e.listTargets().length>0?r.SetEncodingMethod($.MESH_SEQUENTIAL_ENCODING):r.SetEncodingMethod($.MESH_EDGEBREAKER_ENCODING);const u=r.EncodeMeshToDracoBuffer(o,a);if(u<=0)throw new ne("Error applying Draco compression.");const l=new Uint8Array(u);for(let e=0;e<u;++e)l[e]=a.GetValue(e);const h=e.getAttribute("POSITION").getCount(),f=r.GetNumberOfEncodedPoints(),g=3*r.GetNumberOfEncodedFaces();if(e.listTargets().length>0&&f!==h)throw new ne('Compression reduced vertex count unexpectedly, corrupting morph targets. Applying the "weld" function before compression may resolve the issue.');return $.destroy(a),$.destroy(o),$.destroy(n),$.destroy(r),{numVertices:f,numIndices:g,data:l,attributeIDs:i}}function se(e){return"POSITION"===e?J.POSITION:"NORMAL"===e?J.NORMAL:e.startsWith("COLOR_")?J.COLOR:e.startsWith("TEXCOORD_")?J.TEX_COORD:J.GENERIC}function re(e,t,s,r,n,o,i){switch(t){case u.ComponentType.UNSIGNED_BYTE:return e.AddUInt8Attribute(s,r,n,o,i);case u.ComponentType.BYTE:return e.AddInt8Attribute(s,r,n,o,i);case u.ComponentType.UNSIGNED_SHORT:return e.AddUInt16Attribute(s,r,n,o,i);case u.ComponentType.SHORT:return e.AddInt16Attribute(s,r,n,o,i);case u.ComponentType.UNSIGNED_INT:return e.AddUInt32Attribute(s,r,n,o,i);case u.ComponentType.FLOAT:return e.AddFloatAttribute(s,r,n,o,i);default:throw new Error(`Unexpected component type, "${t}".`)}}class ne extends Error{}const oe="KHR_draco_mesh_compression";class ie extends s{constructor(...e){super(...e),this.extensionName=oe,this.prereadTypes=[t.PRIMITIVE],this.prewriteTypes=[t.ACCESSOR],this.readDependencies=["draco3d.decoder"],this.writeDependencies=["draco3d.encoder"],this._decoderModule=null,this._encoderModule=null,this._encoderOptions={}}install(e,t){return"draco3d.decoder"===e&&(this._decoderModule=t,X=this._decoderModule,K={[u.ComponentType.FLOAT]:Float32Array,[u.ComponentType.UNSIGNED_INT]:Uint32Array,[u.ComponentType.UNSIGNED_SHORT]:Uint16Array,[u.ComponentType.UNSIGNED_BYTE]:Uint8Array,[u.ComponentType.SHORT]:Int16Array,[u.ComponentType.BYTE]:Int8Array},z={[u.ComponentType.FLOAT]:X.DT_FLOAT32,[u.ComponentType.UNSIGNED_INT]:X.DT_UINT32,[u.ComponentType.UNSIGNED_SHORT]:X.DT_UINT16,[u.ComponentType.UNSIGNED_BYTE]:X.DT_UINT8,[u.ComponentType.SHORT]:X.DT_INT16,[u.ComponentType.BYTE]:X.DT_INT8}),"draco3d.encoder"===e&&(this._encoderModule=t,$=this._encoderModule),this}setEncoderOptions(e){return this._encoderOptions=e,this}preread(e){if(!this._decoderModule)throw new Error(`[${oe}] Please install extension dependency, "draco3d.decoder".`);const t=this.document.getLogger(),s=e.jsonDoc,n=new Map;try{const o=s.json.meshes||[];for(const i of o)for(const o of i.primitives){if(!o.extensions||!o.extensions[oe])continue;const i=o.extensions[oe];let[a,c]=n.get(i.bufferView)||[];if(!c||!a){const e=s.json.bufferViews[i.bufferView],o=s.json.buffers[e.buffer],u=r.toView(o.uri?s.resources[o.uri]:s.resources[h],e.byteOffset||0,e.byteLength);a=new this._decoderModule.Decoder,c=q(a,u),n.set(i.bufferView,[a,c]),t.debug(`[${oe}] Decompressed ${u.byteLength} bytes.`)}for(const t in o.attributes){const s=e.jsonDoc.json.accessors[o.attributes[t]],r=a.GetAttributeByUniqueId(c,i.attributes[t]),n=Q(a,c,r,s);e.accessors[o.attributes[t]].setArray(n)}void 0!==o.indices&&e.accessors[o.indices].setArray(Y(a,c))}}finally{for(const[e,t]of Array.from(n.values()))this._decoderModule.destroy(e),this._decoderModule.destroy(t)}return this}read(e){return this}prewrite(e,s){if(!this._encoderModule)throw new Error(`[${oe}] Please install extension dependency, "draco3d.encoder".`);const r=this.document.getLogger();r.debug(`[${oe}] Compression options: ${JSON.stringify(this._encoderOptions)}`);const n=function(e){const s=e.getLogger(),r=new Set,n=new Set;for(const t of e.getRoot().listMeshes())for(const e of t.listPrimitives())e.getIndices()?e.getMode()!==o.Mode.TRIANGLES?(n.add(e),s.warn(`[${oe}] Skipping Draco compression on non-TRIANGLES primitive.`)):r.add(e):(n.add(e),s.warn(`[${oe}] Skipping Draco compression on non-indexed primitive.`));const i=e.getRoot().listAccessors(),a=new Map;for(let e=0;e<i.length;e++)a.set(i[e],e);const c=new Map,u=new Set,l=new Map;for(const t of Array.from(r)){let s=ae(t,a);if(u.has(s))l.set(t,s);else{if(c.has(t.getIndices())){const s=t.getIndices(),r=s.clone();a.set(r,e.getRoot().listAccessors().length-1),t.swap(s,r)}for(const s of t.listAttributes())if(c.has(s)){const r=s.clone();a.set(r,e.getRoot().listAccessors().length-1),t.swap(s,r)}s=ae(t,a),u.add(s),l.set(t,s),c.set(t.getIndices(),s);for(const e of t.listAttributes())c.set(e,s)}}for(const e of Array.from(c.keys())){const s=new Set(e.listParents().map(e=>e.propertyType));if(2!==s.size||!s.has(t.PRIMITIVE)||!s.has(t.ROOT))throw new Error(`[${oe}] Compressed accessors must only be used as indices or vertex attributes.`)}for(const e of Array.from(r)){const t=l.get(e),s=e.getIndices();if(c.get(s)!==t||e.listAttributes().some(e=>c.get(e)!==t))throw new Error(`[${oe}] Draco primitives must share all, or no, accessors.`)}for(const e of Array.from(n)){const t=e.getIndices();if(c.has(t)||e.listAttributes().some(e=>c.has(e)))throw new Error(`[${oe}] Accessor cannot be shared by compressed and uncompressed primitives.`)}return l}(this.document),i=new Map;let a="mesh";"scene"===this._encoderOptions.quantizationVolume&&(1!==this.document.getRoot().listScenes().length?r.warn(`[${oe}]: quantizationVolume=scene requires exactly 1 scene.`):a=g(this.document.getRoot().listScenes().pop()));for(const t of Array.from(n.keys())){const s=n.get(t);if(!s)throw new Error("Unexpected primitive.");if(i.has(s)){i.set(s,i.get(s));continue}const o=t.getIndices(),c=e.jsonDoc.json.accessors;let u;try{u=te(t,S({},this._encoderOptions,{quantizationVolume:a}))}catch(e){if(e instanceof ne){r.warn(`[${oe}]: ${e.message} Skipping primitive compression.`);continue}throw e}i.set(s,u);const l=e.createAccessorDef(o);l.count=u.numIndices,e.accessorIndexMap.set(o,c.length),c.push(l);for(const s of t.listSemantics()){const r=t.getAttribute(s),n=e.createAccessorDef(r);n.count=u.numVertices,e.accessorIndexMap.set(r,c.length),c.push(n)}const h=t.getAttribute("POSITION").getBuffer()||this.document.getRoot().listBuffers()[0];e.otherBufferViews.has(h)||e.otherBufferViews.set(h,[]),e.otherBufferViews.get(h).push(u.data)}return r.debug(`[${oe}] Compressed ${n.size} primitives.`),e.extensionData[oe]={primitiveHashMap:n,primitiveEncodingMap:i},this}write(e){const t=e.extensionData[oe];for(const s of this.document.getRoot().listMeshes()){const r=e.jsonDoc.json.meshes[e.meshIndexMap.get(s)];for(let n=0;n<s.listPrimitives().length;n++){const o=s.listPrimitives()[n],i=r.primitives[n],a=t.primitiveHashMap.get(o);if(!a)continue;const c=t.primitiveEncodingMap.get(a);c&&(i.extensions=i.extensions||{},i.extensions[oe]={bufferView:e.otherBufferViewsIndexMap.get(c.data),attributes:c.attributeIDs})}}if(!t.primitiveHashMap.size){const t=e.jsonDoc.json;t.extensionsUsed=(t.extensionsUsed||[]).filter(e=>e!==oe),t.extensionsRequired=(t.extensionsRequired||[]).filter(e=>e!==oe)}return this}}function ae(e,t){const s=[],r=e.getIndices();s.push(t.get(r));for(const r of e.listAttributes())s.push(t.get(r));return s.sort().join("|")}ie.EXTENSION_NAME=oe,ie.EncoderMethod=W;class ce extends e{init(){this.extensionName="KHR_lights_punctual",this.propertyType="Light",this.parentTypes=[t.NODE]}getDefaults(){return Object.assign(super.getDefaults(),{color:[1,1,1],intensity:1,type:ce.Type.POINT,range:null,innerConeAngle:0,outerConeAngle:Math.PI/4})}getColor(){return this.get("color")}setColor(e){return this.set("color",e)}getColorHex(){return p.factorToHex(this.getColor())}setColorHex(e){const t=this.getColor().slice();return p.hexToFactor(e,t),this.setColor(t)}getIntensity(){return this.get("intensity")}setIntensity(e){return this.set("intensity",e)}getType(){return this.get("type")}setType(e){return this.set("type",e)}getRange(){return this.get("range")}setRange(e){return this.set("range",e)}getInnerConeAngle(){return this.get("innerConeAngle")}setInnerConeAngle(e){return this.set("innerConeAngle",e)}getOuterConeAngle(){return this.get("outerConeAngle")}setOuterConeAngle(e){return this.set("outerConeAngle",e)}}ce.EXTENSION_NAME="KHR_lights_punctual",ce.Type={POINT:"point",SPOT:"spot",DIRECTIONAL:"directional"};const ue="KHR_lights_punctual";class le extends s{constructor(...e){super(...e),this.extensionName=ue}createLight(e=""){return new ce(this.document.getGraph(),e)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[ue])return this;const s=(t.json.extensions[ue].lights||[]).map(e=>{var t,s;const r=this.createLight().setName(e.name||"").setType(e.type);return void 0!==e.color&&r.setColor(e.color),void 0!==e.intensity&&r.setIntensity(e.intensity),void 0!==e.range&&r.setRange(e.range),void 0!==(null==(t=e.spot)?void 0:t.innerConeAngle)&&r.setInnerConeAngle(e.spot.innerConeAngle),void 0!==(null==(s=e.spot)?void 0:s.outerConeAngle)&&r.setOuterConeAngle(e.spot.outerConeAngle),r});return t.json.nodes.forEach((t,r)=>{t.extensions&&t.extensions[ue]&&e.nodes[r].setExtension(ue,s[t.extensions[ue].light])}),this}write(e){const t=e.jsonDoc;if(0===this.properties.size)return this;const s=[],r=new Map;for(const e of this.properties){const t=e,n={type:t.getType()};l.eq(t.getColor(),[1,1,1])||(n.color=t.getColor()),1!==t.getIntensity()&&(n.intensity=t.getIntensity()),null!=t.getRange()&&(n.range=t.getRange()),t.getName()&&(n.name=t.getName()),t.getType()===ce.Type.SPOT&&(n.spot={innerConeAngle:t.getInnerConeAngle(),outerConeAngle:t.getOuterConeAngle()}),s.push(n),r.set(t,s.length-1)}return this.document.getRoot().listNodes().forEach(s=>{const n=s.getExtension(ue);if(n){const o=e.nodeIndexMap.get(s),i=t.json.nodes[o];i.extensions=i.extensions||{},i.extensions[ue]={light:r.get(n)}}}),t.json.extensions=t.json.extensions||{},t.json.extensions[ue]={lights:s},this}}le.EXTENSION_NAME=ue;const{R:he,G:fe,B:ge}=d;class pe extends e{init(){this.extensionName="KHR_materials_clearcoat",this.propertyType="Clearcoat",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{clearcoatFactor:0,clearcoatTexture:null,clearcoatTextureInfo:new x(this.graph,"clearcoatTextureInfo"),clearcoatRoughnessFactor:0,clearcoatRoughnessTexture:null,clearcoatRoughnessTextureInfo:new x(this.graph,"clearcoatRoughnessTextureInfo"),clearcoatNormalScale:1,clearcoatNormalTexture:null,clearcoatNormalTextureInfo:new x(this.graph,"clearcoatNormalTextureInfo")})}getClearcoatFactor(){return this.get("clearcoatFactor")}setClearcoatFactor(e){return this.set("clearcoatFactor",e)}getClearcoatTexture(){return this.getRef("clearcoatTexture")}getClearcoatTextureInfo(){return this.getRef("clearcoatTexture")?this.getRef("clearcoatTextureInfo"):null}setClearcoatTexture(e){return this.setRef("clearcoatTexture",e,{channels:he})}getClearcoatRoughnessFactor(){return this.get("clearcoatRoughnessFactor")}setClearcoatRoughnessFactor(e){return this.set("clearcoatRoughnessFactor",e)}getClearcoatRoughnessTexture(){return this.getRef("clearcoatRoughnessTexture")}getClearcoatRoughnessTextureInfo(){return this.getRef("clearcoatRoughnessTexture")?this.getRef("clearcoatRoughnessTextureInfo"):null}setClearcoatRoughnessTexture(e){return this.setRef("clearcoatRoughnessTexture",e,{channels:fe})}getClearcoatNormalScale(){return this.get("clearcoatNormalScale")}setClearcoatNormalScale(e){return this.set("clearcoatNormalScale",e)}getClearcoatNormalTexture(){return this.getRef("clearcoatNormalTexture")}getClearcoatNormalTextureInfo(){return this.getRef("clearcoatNormalTexture")?this.getRef("clearcoatNormalTextureInfo"):null}setClearcoatNormalTexture(e){return this.setRef("clearcoatNormalTexture",e,{channels:he|fe|ge})}}pe.EXTENSION_NAME="KHR_materials_clearcoat";const xe="KHR_materials_clearcoat";class de extends s{constructor(...e){super(...e),this.extensionName=xe}createClearcoat(){return new pe(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[xe]){const n=this.createClearcoat();e.materials[r].setExtension(xe,n);const o=t.extensions[xe];if(void 0!==o.clearcoatFactor&&n.setClearcoatFactor(o.clearcoatFactor),void 0!==o.clearcoatRoughnessFactor&&n.setClearcoatRoughnessFactor(o.clearcoatRoughnessFactor),void 0!==o.clearcoatTexture){const t=o.clearcoatTexture;n.setClearcoatTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getClearcoatTextureInfo(),t)}if(void 0!==o.clearcoatRoughnessTexture){const t=o.clearcoatRoughnessTexture;n.setClearcoatRoughnessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getClearcoatRoughnessTextureInfo(),t)}if(void 0!==o.clearcoatNormalTexture){const t=o.clearcoatNormalTexture;n.setClearcoatNormalTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getClearcoatNormalTextureInfo(),t),void 0!==t.scale&&n.setClearcoatNormalScale(t.scale)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(xe);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[xe]={clearcoatFactor:r.getClearcoatFactor(),clearcoatRoughnessFactor:r.getClearcoatRoughnessFactor()};if(r.getClearcoatTexture()){const t=r.getClearcoatTexture(),s=r.getClearcoatTextureInfo();i.clearcoatTexture=e.createTextureInfoDef(t,s)}if(r.getClearcoatRoughnessTexture()){const t=r.getClearcoatRoughnessTexture(),s=r.getClearcoatRoughnessTextureInfo();i.clearcoatRoughnessTexture=e.createTextureInfoDef(t,s)}if(r.getClearcoatNormalTexture()){const t=r.getClearcoatNormalTexture(),s=r.getClearcoatNormalTextureInfo();i.clearcoatNormalTexture=e.createTextureInfoDef(t,s),1!==r.getClearcoatNormalScale()&&(i.clearcoatNormalTexture.scale=r.getClearcoatNormalScale())}}}),this}}de.EXTENSION_NAME=xe;class Te extends e{init(){this.extensionName="KHR_materials_emissive_strength",this.propertyType="EmissiveStrength",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{emissiveStrength:1})}getEmissiveStrength(){return this.get("emissiveStrength")}setEmissiveStrength(e){return this.set("emissiveStrength",e)}}Te.EXTENSION_NAME="KHR_materials_emissive_strength";const me="KHR_materials_emissive_strength";class Ee extends s{constructor(...e){super(...e),this.extensionName=me}createEmissiveStrength(){return new Te(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[me]){const r=this.createEmissiveStrength();e.materials[s].setExtension(me,r);const n=t.extensions[me];void 0!==n.emissiveStrength&&r.setEmissiveStrength(n.emissiveStrength)}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(me);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{},o.extensions[me]={emissiveStrength:r.getEmissiveStrength()}}}),this}}Ee.EXTENSION_NAME=me;class Ie extends e{init(){this.extensionName="KHR_materials_ior",this.propertyType="IOR",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{ior:0})}getIOR(){return this.get("ior")}setIOR(e){return this.set("ior",e)}}Ie.EXTENSION_NAME="KHR_materials_ior";const Re="KHR_materials_ior";class Ne extends s{constructor(...e){super(...e),this.extensionName=Re}createIOR(){return new Ie(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[Re]){const r=this.createIOR();e.materials[s].setExtension(Re,r);const n=t.extensions[Re];void 0!==n.ior&&r.setIOR(n.ior)}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(Re);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{},o.extensions[Re]={ior:r.getIOR()}}}),this}}Ne.EXTENSION_NAME=Re;const{R:_e,G:Se}=d;class Ae extends e{init(){this.extensionName="KHR_materials_iridescence",this.propertyType="Iridescence",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{iridescenceFactor:0,iridescenceTexture:null,iridescenceTextureInfo:new x(this.graph,"iridescenceTextureInfo"),iridescenceIOR:1.3,iridescenceThicknessMinimum:100,iridescenceThicknessMaximum:400,iridescenceThicknessTexture:null,iridescenceThicknessTextureInfo:new x(this.graph,"iridescenceThicknessTextureInfo")})}getIridescenceFactor(){return this.get("iridescenceFactor")}setIridescenceFactor(e){return this.set("iridescenceFactor",e)}getIridescenceTexture(){return this.getRef("iridescenceTexture")}getIridescenceTextureInfo(){return this.getRef("iridescenceTexture")?this.getRef("iridescenceTextureInfo"):null}setIridescenceTexture(e){return this.setRef("iridescenceTexture",e,{channels:_e})}getIridescenceIOR(){return this.get("iridescenceIOR")}setIridescenceIOR(e){return this.set("iridescenceIOR",e)}getIridescenceThicknessMinimum(){return this.get("iridescenceThicknessMinimum")}setIridescenceThicknessMinimum(e){return this.set("iridescenceThicknessMinimum",e)}getIridescenceThicknessMaximum(){return this.get("iridescenceThicknessMaximum")}setIridescenceThicknessMaximum(e){return this.set("iridescenceThicknessMaximum",e)}getIridescenceThicknessTexture(){return this.getRef("iridescenceThicknessTexture")}getIridescenceThicknessTextureInfo(){return this.getRef("iridescenceThicknessTexture")?this.getRef("iridescenceThicknessTextureInfo"):null}setIridescenceThicknessTexture(e){return this.setRef("iridescenceThicknessTexture",e,{channels:Se})}}Ae.EXTENSION_NAME="KHR_materials_iridescence";const ye="KHR_materials_iridescence";class Ce extends s{constructor(...e){super(...e),this.extensionName=ye}createIridescence(){return new Ae(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[ye]){const n=this.createIridescence();e.materials[r].setExtension(ye,n);const o=t.extensions[ye];if(void 0!==o.iridescenceFactor&&n.setIridescenceFactor(o.iridescenceFactor),void 0!==o.iridescenceIor&&n.setIridescenceIOR(o.iridescenceIor),void 0!==o.iridescenceThicknessMinimum&&n.setIridescenceThicknessMinimum(o.iridescenceThicknessMinimum),void 0!==o.iridescenceThicknessMaximum&&n.setIridescenceThicknessMaximum(o.iridescenceThicknessMaximum),void 0!==o.iridescenceTexture){const t=o.iridescenceTexture;n.setIridescenceTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getIridescenceTextureInfo(),t)}if(void 0!==o.iridescenceThicknessTexture){const t=o.iridescenceThicknessTexture;n.setIridescenceThicknessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getIridescenceThicknessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(ye);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[ye]={};if(r.getIridescenceFactor()>0&&(i.iridescenceFactor=r.getIridescenceFactor()),1.3!==r.getIridescenceIOR()&&(i.iridescenceIor=r.getIridescenceIOR()),100!==r.getIridescenceThicknessMinimum()&&(i.iridescenceThicknessMinimum=r.getIridescenceThicknessMinimum()),400!==r.getIridescenceThicknessMaximum()&&(i.iridescenceThicknessMaximum=r.getIridescenceThicknessMaximum()),r.getIridescenceTexture()){const t=r.getIridescenceTexture(),s=r.getIridescenceTextureInfo();i.iridescenceTexture=e.createTextureInfoDef(t,s)}if(r.getIridescenceThicknessTexture()){const t=r.getIridescenceThicknessTexture(),s=r.getIridescenceThicknessTextureInfo();i.iridescenceThicknessTexture=e.createTextureInfoDef(t,s)}}}),this}}Ce.EXTENSION_NAME=ye;const{R:Me,G:Oe,B:we,A:De}=d;class Fe extends e{init(){this.extensionName="KHR_materials_pbrSpecularGlossiness",this.propertyType="PBRSpecularGlossiness",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{diffuseFactor:[1,1,1,1],diffuseTexture:null,diffuseTextureInfo:new x(this.graph,"diffuseTextureInfo"),specularFactor:[1,1,1],glossinessFactor:1,specularGlossinessTexture:null,specularGlossinessTextureInfo:new x(this.graph,"specularGlossinessTextureInfo")})}getDiffuseFactor(){return this.get("diffuseFactor")}setDiffuseFactor(e){return this.set("diffuseFactor",e)}getDiffuseHex(){return p.factorToHex(this.getDiffuseFactor())}setDiffuseHex(e){const t=this.getDiffuseFactor().slice();return this.setDiffuseFactor(p.hexToFactor(e,t))}getDiffuseTexture(){return this.getRef("diffuseTexture")}getDiffuseTextureInfo(){return this.getRef("diffuseTexture")?this.getRef("diffuseTextureInfo"):null}setDiffuseTexture(e){return this.setRef("diffuseTexture",e,{channels:Me|Oe|we|De})}getSpecularFactor(){return this.get("specularFactor")}setSpecularFactor(e){return this.set("specularFactor",e)}getGlossinessFactor(){return this.get("glossinessFactor")}setGlossinessFactor(e){return this.set("glossinessFactor",e)}getSpecularGlossinessTexture(){return this.getRef("specularGlossinessTexture")}getSpecularGlossinessTextureInfo(){return this.getRef("specularGlossinessTexture")?this.getRef("specularGlossinessTextureInfo"):null}setSpecularGlossinessTexture(e){return this.setRef("specularGlossinessTexture",e,{channels:Me|Oe|we|De})}}Fe.EXTENSION_NAME="KHR_materials_pbrSpecularGlossiness";const be="KHR_materials_pbrSpecularGlossiness";class je extends s{constructor(...e){super(...e),this.extensionName=be}createPBRSpecularGlossiness(){return new Fe(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[be]){const n=this.createPBRSpecularGlossiness();e.materials[r].setExtension(be,n);const o=t.extensions[be];if(void 0!==o.diffuseFactor&&n.setDiffuseFactor(o.diffuseFactor),void 0!==o.specularFactor&&n.setSpecularFactor(o.specularFactor),void 0!==o.glossinessFactor&&n.setGlossinessFactor(o.glossinessFactor),void 0!==o.diffuseTexture){const t=o.diffuseTexture;n.setDiffuseTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getDiffuseTextureInfo(),t)}if(void 0!==o.specularGlossinessTexture){const t=o.specularGlossinessTexture;n.setSpecularGlossinessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSpecularGlossinessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(be);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[be]={diffuseFactor:r.getDiffuseFactor(),specularFactor:r.getSpecularFactor(),glossinessFactor:r.getGlossinessFactor()};if(r.getDiffuseTexture()){const t=r.getDiffuseTexture(),s=r.getDiffuseTextureInfo();i.diffuseTexture=e.createTextureInfoDef(t,s)}if(r.getSpecularGlossinessTexture()){const t=r.getSpecularGlossinessTexture(),s=r.getSpecularGlossinessTextureInfo();i.specularGlossinessTexture=e.createTextureInfoDef(t,s)}}}),this}}je.EXTENSION_NAME=be;const{R:ve,G:ke,B:Be,A:Ge}=d;class He extends e{init(){this.extensionName="KHR_materials_sheen",this.propertyType="Sheen",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{sheenColorFactor:[0,0,0],sheenColorTexture:null,sheenColorTextureInfo:new x(this.graph,"sheenColorTextureInfo"),sheenRoughnessFactor:0,sheenRoughnessTexture:null,sheenRoughnessTextureInfo:new x(this.graph,"sheenRoughnessTextureInfo")})}getSheenColorFactor(){return this.get("sheenColorFactor")}getSheenColorHex(){return p.factorToHex(this.getSheenColorFactor())}setSheenColorFactor(e){return this.set("sheenColorFactor",e)}setSheenColorHex(e){const t=this.getSheenColorFactor().slice();return this.set("sheenColorFactor",p.hexToFactor(e,t))}getSheenColorTexture(){return this.getRef("sheenColorTexture")}getSheenColorTextureInfo(){return this.getRef("sheenColorTexture")?this.getRef("sheenColorTextureInfo"):null}setSheenColorTexture(e){return this.setRef("sheenColorTexture",e,{channels:ve|ke|Be})}getSheenRoughnessFactor(){return this.get("sheenRoughnessFactor")}setSheenRoughnessFactor(e){return this.set("sheenRoughnessFactor",e)}getSheenRoughnessTexture(){return this.getRef("sheenRoughnessTexture")}getSheenRoughnessTextureInfo(){return this.getRef("sheenRoughnessTexture")?this.getRef("sheenRoughnessTextureInfo"):null}setSheenRoughnessTexture(e){return this.setRef("sheenRoughnessTexture",e,{channels:Ge})}}He.EXTENSION_NAME="KHR_materials_sheen";const Le="KHR_materials_sheen";class Ue extends s{constructor(...e){super(...e),this.extensionName=Le}createSheen(){return new He(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[Le]){const n=this.createSheen();e.materials[r].setExtension(Le,n);const o=t.extensions[Le];if(void 0!==o.sheenColorFactor&&n.setSheenColorFactor(o.sheenColorFactor),void 0!==o.sheenRoughnessFactor&&n.setSheenRoughnessFactor(o.sheenRoughnessFactor),void 0!==o.sheenColorTexture){const t=o.sheenColorTexture;n.setSheenColorTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSheenColorTextureInfo(),t)}if(void 0!==o.sheenRoughnessTexture){const t=o.sheenRoughnessTexture;n.setSheenRoughnessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSheenRoughnessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(Le);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[Le]={sheenColorFactor:r.getSheenColorFactor(),sheenRoughnessFactor:r.getSheenRoughnessFactor()};if(r.getSheenColorTexture()){const t=r.getSheenColorTexture(),s=r.getSheenColorTextureInfo();i.sheenColorTexture=e.createTextureInfoDef(t,s)}if(r.getSheenRoughnessTexture()){const t=r.getSheenRoughnessTexture(),s=r.getSheenRoughnessTextureInfo();i.sheenRoughnessTexture=e.createTextureInfoDef(t,s)}}}),this}}Ue.EXTENSION_NAME=Le;const{R:Pe,G:Ve,B:Xe,A:Ke}=d;class ze extends e{init(){this.extensionName="KHR_materials_specular",this.propertyType="Specular",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{specularFactor:1,specularTexture:null,specularTextureInfo:new x(this.graph,"specularTextureInfo"),specularColorFactor:[1,1,1],specularColorTexture:null,specularColorTextureInfo:new x(this.graph,"specularColorTextureInfo")})}getSpecularFactor(){return this.get("specularFactor")}setSpecularFactor(e){return this.set("specularFactor",e)}getSpecularColorFactor(){return this.get("specularColorFactor")}setSpecularColorFactor(e){return this.set("specularColorFactor",e)}getSpecularColorHex(){return p.factorToHex(this.getSpecularColorFactor())}setSpecularColorHex(e){const t=this.getSpecularColorFactor().slice();return this.set("specularColorFactor",p.hexToFactor(e,t))}getSpecularTexture(){return this.getRef("specularTexture")}getSpecularTextureInfo(){return this.getRef("specularTexture")?this.getRef("specularTextureInfo"):null}setSpecularTexture(e){return this.setRef("specularTexture",e,{channels:Ke})}getSpecularColorTexture(){return this.getRef("specularColorTexture")}getSpecularColorTextureInfo(){return this.getRef("specularColorTexture")?this.getRef("specularColorTextureInfo"):null}setSpecularColorTexture(e){return this.setRef("specularColorTexture",e,{channels:Pe|Ve|Xe})}}ze.EXTENSION_NAME="KHR_materials_specular";const $e="KHR_materials_specular";class qe extends s{constructor(...e){super(...e),this.extensionName=$e}createSpecular(){return new ze(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[$e]){const n=this.createSpecular();e.materials[r].setExtension($e,n);const o=t.extensions[$e];if(void 0!==o.specularFactor&&n.setSpecularFactor(o.specularFactor),void 0!==o.specularColorFactor&&n.setSpecularColorFactor(o.specularColorFactor),void 0!==o.specularTexture){const t=o.specularTexture;n.setSpecularTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSpecularTextureInfo(),t)}if(void 0!==o.specularColorTexture){const t=o.specularColorTexture;n.setSpecularColorTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getSpecularColorTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension($e);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[$e]={};if(1!==r.getSpecularFactor()&&(i.specularFactor=r.getSpecularFactor()),l.eq(r.getSpecularColorFactor(),[1,1,1])||(i.specularColorFactor=r.getSpecularColorFactor()),r.getSpecularTexture()){const t=r.getSpecularTexture(),s=r.getSpecularTextureInfo();i.specularTexture=e.createTextureInfoDef(t,s)}if(r.getSpecularColorTexture()){const t=r.getSpecularColorTexture(),s=r.getSpecularColorTextureInfo();i.specularColorTexture=e.createTextureInfoDef(t,s)}}}),this}}qe.EXTENSION_NAME=$e;const{R:Ye}=d;class Qe extends e{init(){this.extensionName="KHR_materials_transmission",this.propertyType="Transmission",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{transmissionFactor:0,transmissionTexture:null,transmissionTextureInfo:new x(this.graph,"transmissionTextureInfo")})}getTransmissionFactor(){return this.get("transmissionFactor")}setTransmissionFactor(e){return this.set("transmissionFactor",e)}getTransmissionTexture(){return this.getRef("transmissionTexture")}getTransmissionTextureInfo(){return this.getRef("transmissionTexture")?this.getRef("transmissionTextureInfo"):null}setTransmissionTexture(e){return this.setRef("transmissionTexture",e,{channels:Ye})}}Qe.EXTENSION_NAME="KHR_materials_transmission";const We="KHR_materials_transmission";class Je extends s{constructor(...e){super(...e),this.extensionName=We}createTransmission(){return new Qe(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[We]){const n=this.createTransmission();e.materials[r].setExtension(We,n);const o=t.extensions[We];if(void 0!==o.transmissionFactor&&n.setTransmissionFactor(o.transmissionFactor),void 0!==o.transmissionTexture){const t=o.transmissionTexture;n.setTransmissionTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getTransmissionTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(We);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[We]={transmissionFactor:r.getTransmissionFactor()};if(r.getTransmissionTexture()){const t=r.getTransmissionTexture(),s=r.getTransmissionTextureInfo();i.transmissionTexture=e.createTextureInfoDef(t,s)}}}),this}}Je.EXTENSION_NAME=We;class Ze extends e{init(){this.extensionName="KHR_materials_unlit",this.propertyType="Unlit",this.parentTypes=[t.MATERIAL]}}Ze.EXTENSION_NAME="KHR_materials_unlit";const et="KHR_materials_unlit";class tt extends s{constructor(...e){super(...e),this.extensionName=et}createUnlit(){return new Ze(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{t.extensions&&t.extensions[et]&&e.materials[s].setExtension(et,this.createUnlit())}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{if(s.getExtension(et)){const r=e.materialIndexMap.get(s),n=t.json.materials[r];n.extensions=n.extensions||{},n.extensions[et]={}}}),this}}tt.EXTENSION_NAME=et;class st extends e{init(){this.extensionName="KHR_materials_variants",this.propertyType="Mapping",this.parentTypes=["MappingList"]}getDefaults(){return Object.assign(super.getDefaults(),{material:null,variants:[]})}getMaterial(){return this.getRef("material")}setMaterial(e){return this.setRef("material",e)}addVariant(e){return this.addRef("variants",e)}removeVariant(e){return this.removeRef("variants",e)}listVariants(){return this.listRefs("variants")}}st.EXTENSION_NAME="KHR_materials_variants";class rt extends e{init(){this.extensionName="KHR_materials_variants",this.propertyType="MappingList",this.parentTypes=[t.PRIMITIVE]}getDefaults(){return Object.assign(super.getDefaults(),{mappings:[]})}addMapping(e){return this.addRef("mappings",e)}removeMapping(e){return this.removeRef("mappings",e)}listMappings(){return this.listRefs("mappings")}}rt.EXTENSION_NAME="KHR_materials_variants";class nt extends e{init(){this.extensionName="KHR_materials_variants",this.propertyType="Variant",this.parentTypes=["MappingList"]}}nt.EXTENSION_NAME="KHR_materials_variants";const ot="KHR_materials_variants";class it extends s{constructor(...e){super(...e),this.extensionName=ot}createMappingList(){return new rt(this.document.getGraph())}createVariant(e=""){return new nt(this.document.getGraph(),e)}createMapping(){return new st(this.document.getGraph())}listVariants(){return Array.from(this.properties).filter(e=>e instanceof nt)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[ot])return this;const s=(t.json.extensions[ot].variants||[]).map(e=>this.createVariant().setName(e.name||""));return(t.json.meshes||[]).forEach((t,r)=>{const n=e.meshes[r];(t.primitives||[]).forEach((t,r)=>{if(!t.extensions||!t.extensions[ot])return;const o=this.createMappingList(),i=t.extensions[ot];for(const t of i.mappings){const r=this.createMapping();void 0!==t.material&&r.setMaterial(e.materials[t.material]);for(const e of t.variants||[])r.addVariant(s[e]);o.addMapping(r)}n.listPrimitives()[r].setExtension(ot,o)})}),this}write(e){const t=e.jsonDoc,s=this.listVariants();if(!s.length)return this;const r=[],n=new Map;for(const t of s)n.set(t,r.length),r.push(e.createPropertyDef(t));for(const t of this.document.getRoot().listMeshes()){const s=e.meshIndexMap.get(t);t.listPrimitives().forEach((t,r)=>{const o=t.getExtension(ot);if(!o)return;const i=e.jsonDoc.json.meshes[s].primitives[r],a=o.listMappings().map(t=>{const s=e.createPropertyDef(t),r=t.getMaterial();return r&&(s.material=e.materialIndexMap.get(r)),s.variants=t.listVariants().map(e=>n.get(e)),s});i.extensions=i.extensions||{},i.extensions[ot]={mappings:a}})}return t.json.extensions=t.json.extensions||{},t.json.extensions[ot]={variants:r},this}}it.EXTENSION_NAME=ot;const{G:at}=d;class ct extends e{init(){this.extensionName="KHR_materials_volume",this.propertyType="Volume",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{thicknessFactor:0,thicknessTexture:null,thicknessTextureInfo:new x(this.graph,"thicknessTexture"),attenuationDistance:Infinity,attenuationColor:[1,1,1]})}getThicknessFactor(){return this.get("thicknessFactor")}setThicknessFactor(e){return this.set("thicknessFactor",e)}getThicknessTexture(){return this.getRef("thicknessTexture")}getThicknessTextureInfo(){return this.getRef("thicknessTexture")?this.getRef("thicknessTextureInfo"):null}setThicknessTexture(e){return this.setRef("thicknessTexture",e,{channels:at})}getAttenuationDistance(){return this.get("attenuationDistance")}setAttenuationDistance(e){return this.set("attenuationDistance",e)}getAttenuationColor(){return this.get("attenuationColor")}setAttenuationColor(e){return this.set("attenuationColor",e)}getAttenuationColorHex(){return p.factorToHex(this.getAttenuationColor())}setAttenuationColorHex(e){const t=this.getAttenuationColor().slice();return this.set("attenuationColor",p.hexToFactor(e,t))}}ct.EXTENSION_NAME="KHR_materials_volume";const ut="KHR_materials_volume";class lt extends s{constructor(...e){super(...e),this.extensionName=ut}createVolume(){return new ct(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,r)=>{if(t.extensions&&t.extensions[ut]){const n=this.createVolume();e.materials[r].setExtension(ut,n);const o=t.extensions[ut];if(void 0!==o.thicknessFactor&&n.setThicknessFactor(o.thicknessFactor),void 0!==o.attenuationDistance&&n.setAttenuationDistance(o.attenuationDistance),void 0!==o.attenuationColor&&n.setAttenuationColor(o.attenuationColor),void 0!==o.thicknessTexture){const t=o.thicknessTexture;n.setThicknessTexture(e.textures[s[t.index].source]),e.setTextureInfo(n.getThicknessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const r=s.getExtension(ut);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[ut]={};if(r.getThicknessFactor()>0&&(i.thicknessFactor=r.getThicknessFactor()),Number.isFinite(r.getAttenuationDistance())&&(i.attenuationDistance=r.getAttenuationDistance()),l.eq(r.getAttenuationColor(),[1,1,1])||(i.attenuationColor=r.getAttenuationColor()),r.getThicknessTexture()){const t=r.getThicknessTexture(),s=r.getThicknessTextureInfo();i.thicknessTexture=e.createTextureInfoDef(t,s)}}}),this}}lt.EXTENSION_NAME=ut;const ht="KHR_mesh_quantization";class ft extends s{constructor(...e){super(...e),this.extensionName=ht}read(e){return this}write(e){return this}}ft.EXTENSION_NAME=ht;const gt="KHR_texture_basisu";class pt{match(e){return 171===e[0]&&75===e[1]&&84===e[2]&&88===e[3]&&32===e[4]&&50===e[5]&&48===e[6]&&187===e[7]&&13===e[8]&&10===e[9]&&26===e[10]&&10===e[11]}getSize(e){const t=T(e);return[t.pixelWidth,t.pixelHeight]}getChannels(e){const t=T(e).dataFormatDescriptor[0];if(t.colorModel===m)return 2===t.samples.length&&15==(15&t.samples[1].channelType)?4:3;if(t.colorModel===E)return 3==(15&t.samples[0].channelType)?4:3;throw new Error(`Unexpected KTX2 colorModel, "${t.colorModel}".`)}getGPUByteLength(e){const t=T(e),s=this.getChannels(e)>3;let r=0;for(let e=0;e<t.levels.length;e++){const n=t.levels[e];r+=n.uncompressedByteLength?n.uncompressedByteLength:Math.max(1,Math.floor(t.pixelWidth/Math.pow(2,e)))/4*(Math.max(1,Math.floor(t.pixelHeight/Math.pow(2,e)))/4)*(s?16:8)}return r}}class xt extends s{constructor(...e){super(...e),this.extensionName=gt,this.prereadTypes=[t.TEXTURE]}static register(){f.registerFormat("image/ktx2",new pt)}preread(e){return e.jsonDoc.json.textures.forEach(e=>{e.extensions&&e.extensions[gt]&&(e.source=e.extensions[gt].source)}),this}read(e){return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listTextures().forEach(s=>{if("image/ktx2"===s.getMimeType()){const r=e.imageIndexMap.get(s);t.json.textures.forEach(e=>{e.source===r&&(e.extensions=e.extensions||{},e.extensions[gt]={source:e.source},delete e.source)})}}),this}}xt.EXTENSION_NAME=gt;class dt extends e{init(){this.extensionName="KHR_texture_transform",this.propertyType="Transform",this.parentTypes=[t.TEXTURE_INFO]}getDefaults(){return Object.assign(super.getDefaults(),{offset:[0,0],rotation:0,scale:[1,1],texCoord:null})}getOffset(){return this.get("offset")}setOffset(e){return this.set("offset",e)}getRotation(){return this.get("rotation")}setRotation(e){return this.set("rotation",e)}getScale(){return this.get("scale")}setScale(e){return this.set("scale",e)}getTexCoord(){return this.get("texCoord")}setTexCoord(e){return this.set("texCoord",e)}}dt.EXTENSION_NAME="KHR_texture_transform";const Tt="KHR_texture_transform";class mt extends s{constructor(...e){super(...e),this.extensionName=Tt}createTransform(){return new dt(this.document.getGraph())}read(e){for(const[t,s]of Array.from(e.textureInfos.entries())){if(!s.extensions||!s.extensions[Tt])continue;const e=this.createTransform(),r=s.extensions[Tt];void 0!==r.offset&&e.setOffset(r.offset),void 0!==r.rotation&&e.setRotation(r.rotation),void 0!==r.scale&&e.setScale(r.scale),void 0!==r.texCoord&&e.setTexCoord(r.texCoord),t.setExtension(Tt,e)}return this}write(e){const t=Array.from(e.textureInfoDefMap.entries());for(const[e,s]of t){const t=e.getExtension(Tt);if(!t)continue;s.extensions=s.extensions||{};const r={},n=l.eq;n(t.getOffset(),[0,0])||(r.offset=t.getOffset()),0!==t.getRotation()&&(r.rotation=t.getRotation()),n(t.getScale(),[1,1])||(r.scale=t.getScale()),null!=t.getTexCoord()&&(r.texCoord=t.getTexCoord()),s.extensions[Tt]=r}return this}}mt.EXTENSION_NAME=Tt;const Et=[t.ROOT,t.SCENE,t.NODE,t.MESH,t.MATERIAL,t.TEXTURE,t.ANIMATION];class It extends e{init(){this.extensionName="KHR_xmp_json_ld",this.propertyType="Packet",this.parentTypes=Et}getDefaults(){return Object.assign(super.getDefaults(),{context:{},properties:{}})}getContext(){return this.get("context")}setContext(e){return this.set("context",S({},e))}listProperties(){return Object.keys(this.get("properties"))}getProperty(e){const t=this.get("properties");return e in t?t[e]:null}setProperty(e,t){this._assertContext(e);const s=S({},this.get("properties"));return t?s[e]=t:delete s[e],this.set("properties",s)}toJSONLD(){return S({"@context":Rt(this.get("context"))},Rt(this.get("properties")))}fromJSONLD(e){const t=(e=Rt(e))["@context"];return t&&this.set("context",t),delete e["@context"],this.set("properties",e)}_assertContext(e){if(!(e.split(":")[0]in this.get("context")))throw new Error(`KHR_xmp_json_ld: Missing context for term, "${e}".`)}}function Rt(e){return JSON.parse(JSON.stringify(e))}It.EXTENSION_NAME="KHR_xmp_json_ld";const Nt="KHR_xmp_json_ld";class _t extends s{constructor(...e){super(...e),this.extensionName=Nt}createPacket(){return new It(this.document.getGraph())}listPackets(){return Array.from(this.properties)}read(e){var t;const s=null==(t=e.jsonDoc.json.extensions)?void 0:t[Nt];if(!s||!s.packets)return this;const r=e.jsonDoc.json,n=this.document.getRoot(),o=s.packets.map(e=>this.createPacket().fromJSONLD(e)),i=[[r.asset],r.scenes,r.nodes,r.meshes,r.materials,r.images,r.animations],a=[[n],n.listScenes(),n.listNodes(),n.listMeshes(),n.listMaterials(),n.listTextures(),n.listAnimations()];for(let e=0;e<i.length;e++){const t=i[e]||[];for(let s=0;s<t.length;s++){const r=t[s];r.extensions&&r.extensions[Nt]&&a[e][s].setExtension(Nt,o[r.extensions[Nt].packet])}}return this}write(e){const{json:s}=e.jsonDoc,r=[];for(const n of this.properties){r.push(n.toJSONLD());for(const o of n.listParents()){let n;switch(o.propertyType){case t.ROOT:n=s.asset;break;case t.SCENE:n=s.scenes[e.sceneIndexMap.get(o)];break;case t.NODE:n=s.nodes[e.nodeIndexMap.get(o)];break;case t.MESH:n=s.meshes[e.meshIndexMap.get(o)];break;case t.MATERIAL:n=s.materials[e.materialIndexMap.get(o)];break;case t.TEXTURE:n=s.images[e.imageIndexMap.get(o)];break;case t.ANIMATION:n=s.animations[e.animationIndexMap.get(o)];break;default:n=null,this.document.getLogger().warn(`[${Nt}]: Unsupported parent property, "${o.propertyType}"`)}n&&(n.extensions=n.extensions||{},n.extensions[Nt]={packet:r.length-1})}}return r.length>0&&(s.extensions=s.extensions||{},s.extensions[Nt]={packets:r}),this}}_t.EXTENSION_NAME=Nt;const St=[ie,le,de,Ee,Ne,Ce,je,qe,Ue,Je,tt,it,lt,ft,xt,mt,_t],At=[_,H,P,...St];export{At as ALL_EXTENSIONS,pe as Clearcoat,ie as DracoMeshCompression,Te as EmissiveStrength,I as INSTANCE_ATTRIBUTE,Ie as IOR,R as InstancedMesh,Ae as Iridescence,St as KHRONOS_EXTENSIONS,ce as Light,le as LightsPunctual,st as Mapping,rt as MappingList,de as MaterialsClearcoat,Ee as MaterialsEmissiveStrength,Ne as MaterialsIOR,Ce as MaterialsIridescence,je as MaterialsPBRSpecularGlossiness,Ue as MaterialsSheen,qe as MaterialsSpecular,Je as MaterialsTransmission,tt as MaterialsUnlit,it as MaterialsVariants,lt as MaterialsVolume,_ as MeshGPUInstancing,ft as MeshQuantization,H as MeshoptCompression,Fe as PBRSpecularGlossiness,It as Packet,He as Sheen,ze as Specular,xt as TextureBasisu,mt as TextureTransform,P as TextureWebP,dt as Transform,Qe as Transmission,Ze as Unlit,nt as Variant,ct as Volume,_t as XMP};
//# sourceMappingURL=extensions.modern.js.map

@@ -32,1 +32,3 @@ import { bbox, Primitive } from '@gltf-transform/core';

export declare function encodeGeometry(prim: Primitive, _options?: EncoderOptions): EncodedPrimitive;
export declare class EncodingError extends Error {
}
{
"name": "@gltf-transform/extensions",
"version": "2.4.3",
"version": "2.4.4",
"repository": "github:donmccurdy/glTF-Transform",

@@ -32,3 +32,3 @@ "homepage": "https://gltf-transform.donmccurdy.com/extensions.html",

"dependencies": {
"@gltf-transform/core": "^2.4.3",
"@gltf-transform/core": "^2.4.4",
"ktx-parse": "^0.4.5"

@@ -42,3 +42,3 @@ },

],
"gitHead": "8dd601845270686279dbf0b79f4e646bf6b89394"
"gitHead": "440b86336e8c07d6c78eebed524638b3ae4198c5"
}

@@ -15,3 +15,10 @@ import {

import { decodeAttribute, decodeGeometry, decodeIndex, initDecoderModule } from './decoder';
import { EncodedPrimitive, encodeGeometry, EncoderMethod, EncoderOptions, initEncoderModule } from './encoder';
import {
EncodedPrimitive,
encodeGeometry,
EncoderMethod,
EncoderOptions,
EncodingError,
initEncoderModule,
} from './encoder';
import { KHR_DRACO_MESH_COMPRESSION } from '../constants';

@@ -259,3 +266,13 @@ import type { Decoder, DecoderModule, EncoderModule, Mesh } from 'draco3dgltf';

// Create a new EncodedPrimitive.
const encodedPrim = encodeGeometry(prim, { ...this._encoderOptions, quantizationVolume });
let encodedPrim: EncodedPrimitive;
try {
encodedPrim = encodeGeometry(prim, { ...this._encoderOptions, quantizationVolume });
} catch (e) {
if (e instanceof EncodingError) {
logger.warn(`[${NAME}]: ${e.message} Skipping primitive compression.`);
continue;
}
throw e;
}
primitiveEncodingMap.set(primHash, encodedPrim);

@@ -308,2 +325,4 @@

const encodedPrim = dracoContext.primitiveEncodingMap.get(primHash)!;
if (!encodedPrim) continue;
primDef.extensions = primDef.extensions || {};

@@ -310,0 +329,0 @@ primDef.extensions[NAME] = {

@@ -108,3 +108,3 @@ import { Accessor, bbox, GLTF, Primitive, TypedArray } from '@gltf-transform/core';

const indices = prim.getIndices();
if (!indices) throw new Error('Primitive must have indices.');
if (!indices) throw new EncodingError('Primitive must have indices.');

@@ -124,3 +124,3 @@ builder.AddFacesToMesh(mesh, indices.getCount() / 3, indices.getArray() as unknown as Uint32Array);

const byteLength = encoder.EncodeMeshToDracoBuffer(mesh, dracoBuffer);
if (byteLength <= 0) throw new Error('Error applying Draco compression.');
if (byteLength <= 0) throw new EncodingError('Error applying Draco compression.');

@@ -137,3 +137,3 @@ const data = new Uint8Array(byteLength);

if (prim.listTargets().length > 0 && numVertices !== prevNumVertices) {
throw new Error(
throw new EncodingError(
'Compression reduced vertex count unexpectedly, corrupting morph targets.' +

@@ -191,1 +191,3 @@ ' Applying the "weld" function before compression may resolve the issue.'

}
export class EncodingError extends Error {}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc