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 3.0.0-alpha.2 to 3.0.0-alpha.3

1

dist/constants.d.ts
export declare const EXT_MESH_GPU_INSTANCING = "EXT_mesh_gpu_instancing";
export declare const EXT_MESHOPT_COMPRESSION = "EXT_meshopt_compression";
export declare const EXT_TEXTURE_WEBP = "EXT_texture_webp";
export declare const EXT_TEXTURE_AVIF = "EXT_texture_avif";
export declare const KHR_DRACO_MESH_COMPRESSION = "KHR_draco_mesh_compression";

@@ -6,0 +5,0 @@ export declare const KHR_LIGHTS_PUNCTUAL = "KHR_lights_punctual";

4

dist/extensions.d.ts
/** @module extensions */
import { MeshGPUInstancing } from './ext-mesh-gpu-instancing';
import { MeshoptCompression } from './ext-meshopt-compression';
import { TextureAVIF } from './ext-texture-avif';
import { TextureWebP } from './ext-texture-webp';

@@ -24,6 +23,5 @@ import { DracoMeshCompression } from './khr-draco-mesh-compression';

export declare const KHRONOS_EXTENSIONS: (typeof DracoMeshCompression | typeof LightsPunctual | typeof MaterialsClearcoat | typeof MaterialsEmissiveStrength | typeof MaterialsIOR | typeof MaterialsIridescence | typeof MaterialsPBRSpecularGlossiness | typeof MaterialsSpecular | typeof MaterialsSheen | typeof MaterialsTransmission | typeof MaterialsUnlit | typeof MaterialsVariants | typeof MaterialsVolume | typeof MeshQuantization | typeof TextureBasisu | typeof TextureTransform | typeof XMP)[];
export declare const ALL_EXTENSIONS: (typeof DracoMeshCompression | typeof LightsPunctual | typeof MaterialsClearcoat | typeof MaterialsEmissiveStrength | typeof MaterialsIOR | typeof MaterialsIridescence | typeof MaterialsPBRSpecularGlossiness | typeof MaterialsSpecular | typeof MaterialsSheen | typeof MaterialsTransmission | typeof MaterialsUnlit | typeof MaterialsVariants | typeof MaterialsVolume | typeof MeshQuantization | typeof TextureBasisu | typeof TextureTransform | typeof XMP | typeof MeshGPUInstancing | typeof MeshoptCompression | typeof TextureAVIF | typeof TextureWebP)[];
export declare const ALL_EXTENSIONS: (typeof DracoMeshCompression | typeof LightsPunctual | typeof MaterialsClearcoat | typeof MaterialsEmissiveStrength | typeof MaterialsIOR | typeof MaterialsIridescence | typeof MaterialsPBRSpecularGlossiness | typeof MaterialsSpecular | typeof MaterialsSheen | typeof MaterialsTransmission | typeof MaterialsUnlit | typeof MaterialsVariants | typeof MaterialsVolume | typeof MeshQuantization | typeof TextureBasisu | typeof TextureTransform | typeof XMP | typeof MeshGPUInstancing | typeof MeshoptCompression | typeof TextureWebP)[];
export * from './ext-mesh-gpu-instancing';
export * from './ext-meshopt-compression';
export * from './ext-texture-avif';
export * from './ext-texture-webp';

@@ -30,0 +28,0 @@ export * from './khr-draco-mesh-compression';

@@ -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[o.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_avif";class y{match(t){return t.length>=12&&"ftypavif"===e.BufferUtils.decodeText(t.slice(4,12))}getSize(e){return this.match(e),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/avif",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/avif"===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="EXT_texture_webp";class _{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 A extends e.Extension{constructor(...t){super(...t),this.extensionName=N,this.prereadTypes=[e.PropertyType.TEXTURE]}static register(){e.ImageUtils.registerFormat("image/webp",new _)}preread(e){return(e.jsonDoc.json.textures||[]).forEach(e=>{e.extensions&&e.extensions[N]&&(e.source=e.extensions[N].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[N]={source:e.source},delete e.source)})}}),this}}A.EXTENSION_NAME=N;const S="KHR_draco_mesh_compression";let C,M,O,D;function w(e,t){const s=new C.DecoderBuffer;try{if(s.Init(t,t.length),e.GetEncodedGeometryType(s)!==C.TRIANGULAR_MESH)throw new Error(`[${S}] Unknown geometry type.`);const r=new C.Mesh;if(!e.DecodeBufferToMesh(s,r).ok()||0===r.ptr)throw new Error(`[${S}] Decoding failure.`);return r}finally{C.destroy(s)}}function F(e,t){const s=3*t.num_faces();let r,n;if(t.num_points()<=65534){const o=s*Uint16Array.BYTES_PER_ELEMENT;r=C._malloc(o),e.GetTrianglesUInt16Array(t,o,r),n=new Uint16Array(C.HEAPU16.buffer,r,s).slice()}else{const o=s*Uint32Array.BYTES_PER_ELEMENT;r=C._malloc(o),e.GetTrianglesUInt32Array(t,o,r),n=new Uint32Array(C.HEAPU32.buffer,r,s).slice()}return C._free(r),n}function b(e,t,s,r){const n=O[r.componentType],o=M[r.componentType],i=s.num_components(),a=t.num_points()*i,c=a*o.BYTES_PER_ELEMENT,u=C._malloc(c);e.GetAttributeDataArrayForAllPoints(t,s,n,c,u);const l=new o(C.HEAPF32.buffer,u,a).slice();return C._free(u),l}var P,j;!function(e){e[e.EDGEBREAKER=1]="EDGEBREAKER",e[e.SEQUENTIAL=0]="SEQUENTIAL"}(P||(P={})),function(e){e.POSITION="POSITION",e.NORMAL="NORMAL",e.COLOR="COLOR",e.TEX_COORD="TEX_COORD",e.GENERIC="GENERIC"}(j||(j={}));const v={[j.POSITION]:14,[j.NORMAL]:10,[j.COLOR]:8,[j.TEX_COORD]:12,[j.GENERIC]:12},U={decodeSpeed:5,encodeSpeed:5,method:P.EDGEBREAKER,quantizationBits:v,quantizationVolume:"mesh"};function B(e,t=U){const s={...U,...t};s.quantizationBits={...v,...t.quantizationBits};const r=new D.Encoder,n=new D.MeshBuilder,o=new D.Mesh,i={},a=new D.DracoInt8Array;for(const t of e.listSemantics()){const a=e.getAttribute(t),c=k(t),u=G(n,a.getComponentType(),o,D[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(D[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(D[c],s.quantizationBits[c],a.getElementSize(),e.min,t)}}}const c=e.getIndices();if(!c)throw new L("Primitive must have indices.");n.AddFacesToMesh(o,c.getCount()/3,c.getArray()),r.SetSpeedOptions(s.encodeSpeed,s.decodeSpeed),r.SetTrackEncodedProperties(!0),s.method===P.SEQUENTIAL||e.listTargets().length>0?r.SetEncodingMethod(D.MESH_SEQUENTIAL_ENCODING):r.SetEncodingMethod(D.MESH_EDGEBREAKER_ENCODING);const u=r.EncodeMeshToDracoBuffer(o,a);if(u<=0)throw new L("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 L('Compression reduced vertex count unexpectedly, corrupting morph targets. Applying the "weld" function before compression may resolve the issue.');return D.destroy(a),D.destroy(o),D.destroy(n),D.destroy(r),{numVertices:f,numIndices:p,data:l,attributeIDs:i}}function k(e){return"POSITION"===e?j.POSITION:"NORMAL"===e?j.NORMAL:e.startsWith("COLOR_")?j.COLOR:e.startsWith("TEXCOORD_")?j.TEX_COORD:j.GENERIC}function G(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 L extends Error{}const H="KHR_draco_mesh_compression";class V extends e.Extension{constructor(...t){super(...t),this.extensionName=H,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,C=this._decoderModule,M={[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},O={[e.Accessor.ComponentType.FLOAT]:C.DT_FLOAT32,[e.Accessor.ComponentType.UNSIGNED_INT]:C.DT_UINT32,[e.Accessor.ComponentType.UNSIGNED_SHORT]:C.DT_UINT16,[e.Accessor.ComponentType.UNSIGNED_BYTE]:C.DT_UINT8,[e.Accessor.ComponentType.SHORT]:C.DT_INT16,[e.Accessor.ComponentType.BYTE]:C.DT_INT8}),"draco3d.encoder"===t&&(this._encoderModule=s,D=this._encoderModule),this}setEncoderOptions(e){return this._encoderOptions=e,this}preread(t){if(!this._decoderModule)throw new Error(`[${H}] 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[H])continue;const i=o.extensions[H];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=w(a,u),n.set(i.bufferView,[a,c]),s.debug(`[${H}] 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=b(a,c,r,s);t.accessors[o.attributes[e]].setArray(n)}void 0!==o.indices&&t.accessors[o.indices].setArray(F(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(`[${H}] Please install extension dependency, "draco3d.encoder".`);const r=this.document.getLogger();r.debug(`[${H}] 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(`[${H}] Skipping Draco compression on non-TRIANGLES primitive.`)):r.add(t):(n.add(t),s.warn(`[${H}] 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=X(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=X(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(`[${H}] 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(`[${H}] 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(`[${H}] 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(`[${H}]: 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=B(e,{...this._encoderOptions,quantizationVolume:i})}catch(e){if(e instanceof L){r.warn(`[${H}]: ${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(`[${H}] Compressed ${n.size} primitives.`),t.extensionData[H]={primitiveHashMap:n,primitiveEncodingMap:o},this}write(e){const t=e.extensionData[H];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[H]={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!==H),t.extensionsRequired=(t.extensionsRequired||[]).filter(e=>e!==H)}return this}}function X(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("|")}V.EXTENSION_NAME=H,V.EncoderMethod=P;class K 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:K.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)}}K.EXTENSION_NAME="KHR_lights_punctual",K.Type={POINT:"point",SPOT:"spot",DIRECTIONAL:"directional"};const z="KHR_lights_punctual";class q extends e.Extension{constructor(...e){super(...e),this.extensionName=z}createLight(e=""){return new K(this.document.getGraph(),e)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[z])return this;const s=(t.json.extensions[z].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[z]&&e.nodes[r].setExtension(z,s[t.extensions[z].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()===K.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(z);if(r){const o=t.nodeIndexMap.get(e),i=s.json.nodes[o];i.extensions=i.extensions||{},i.extensions[z]={light:n.get(r)}}}),s.json.extensions=s.json.extensions||{},s.json.extensions[z]={lights:r},this}}q.EXTENSION_NAME=z;const{R:$,G:Q,B:Y}=e.TextureChannel;class W 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:$})}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:Q})}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:$|Q|Y})}}W.EXTENSION_NAME="KHR_materials_clearcoat";const J="KHR_materials_clearcoat";class Z extends e.Extension{constructor(...e){super(...e),this.extensionName=J}createClearcoat(){return new W(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[J]){const n=this.createClearcoat();e.materials[r].setExtension(J,n);const o=t.extensions[J];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(J);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[J]={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}}Z.EXTENSION_NAME=J;class ee 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)}}ee.EXTENSION_NAME="KHR_materials_emissive_strength";const te="KHR_materials_emissive_strength";class se extends e.Extension{constructor(...e){super(...e),this.extensionName=te}createEmissiveStrength(){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.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}}se.EXTENSION_NAME=te;class re 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)}}re.EXTENSION_NAME="KHR_materials_ior";const ne="KHR_materials_ior";class oe extends e.Extension{constructor(...e){super(...e),this.extensionName=ne}createIOR(){return new re(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[ne]){const r=this.createIOR();e.materials[s].setExtension(ne,r);const n=t.extensions[ne];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(ne);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{},o.extensions[ne]={ior:r.getIOR()}}}),this}}oe.EXTENSION_NAME=ne;const{R:ie,G:ae}=e.TextureChannel;class ce 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:ie})}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:ae})}}ce.EXTENSION_NAME="KHR_materials_iridescence";const ue="KHR_materials_iridescence";class le extends e.Extension{constructor(...e){super(...e),this.extensionName=ue}createIridescence(){return new ce(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[ue]){const n=this.createIridescence();e.materials[r].setExtension(ue,n);const o=t.extensions[ue];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(ue);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[ue]={};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}}le.EXTENSION_NAME=ue;const{R:he,G:fe,B:pe,A:xe}=e.TextureChannel;class ge 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:he|fe|pe|xe})}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:he|fe|pe|xe})}}ge.EXTENSION_NAME="KHR_materials_pbrSpecularGlossiness";const Te="KHR_materials_pbrSpecularGlossiness";class de extends e.Extension{constructor(...e){super(...e),this.extensionName=Te}createPBRSpecularGlossiness(){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[Te]){const n=this.createPBRSpecularGlossiness();e.materials[r].setExtension(Te,n);const o=t.extensions[Te];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(Te);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[Te]={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}}de.EXTENSION_NAME=Te;const{R:me,G:Ee,B:Ie,A:ye}=e.TextureChannel;class Re 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:me|Ee|Ie})}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:ye})}}Re.EXTENSION_NAME="KHR_materials_sheen";const Ne="KHR_materials_sheen";class _e extends e.Extension{constructor(...e){super(...e),this.extensionName=Ne}createSheen(){return new Re(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[Ne]){const n=this.createSheen();e.materials[r].setExtension(Ne,n);const o=t.extensions[Ne];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(Ne);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[Ne]={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}}_e.EXTENSION_NAME=Ne;const{R:Ae,G:Se,B:Ce,A:Me}=e.TextureChannel;class Oe 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:Me})}getSpecularColorTexture(){return this.getRef("specularColorTexture")}getSpecularColorTextureInfo(){return this.getRef("specularColorTexture")?this.getRef("specularColorTextureInfo"):null}setSpecularColorTexture(e){return this.setRef("specularColorTexture",e,{channels:Ae|Se|Ce})}}Oe.EXTENSION_NAME="KHR_materials_specular";const De="KHR_materials_specular";class we extends e.Extension{constructor(...e){super(...e),this.extensionName=De}createSpecular(){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.createSpecular();e.materials[r].setExtension(De,n);const o=t.extensions[De];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(De);if(n){const o=t.materialIndexMap.get(r),i=s.json.materials[o];i.extensions=i.extensions||{};const a=i.extensions[De]={};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}}we.EXTENSION_NAME=De;const{R:Fe}=e.TextureChannel;class be 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:Fe})}}be.EXTENSION_NAME="KHR_materials_transmission";const Pe="KHR_materials_transmission";class je extends e.Extension{constructor(...e){super(...e),this.extensionName=Pe}createTransmission(){return new be(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.createTransmission();e.materials[r].setExtension(Pe,n);const o=t.extensions[Pe];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(Pe);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[Pe]={transmissionFactor:r.getTransmissionFactor()};if(r.getTransmissionTexture()){const t=r.getTransmissionTexture(),s=r.getTransmissionTextureInfo();i.transmissionTexture=e.createTextureInfoDef(t,s)}}}),this}}je.EXTENSION_NAME=Pe;class ve extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_unlit",this.propertyType="Unlit",this.parentTypes=[e.PropertyType.MATERIAL]}}ve.EXTENSION_NAME="KHR_materials_unlit";const Ue="KHR_materials_unlit";class Be extends e.Extension{constructor(...e){super(...e),this.extensionName=Ue}createUnlit(){return new ve(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{t.extensions&&t.extensions[Ue]&&e.materials[s].setExtension(Ue,this.createUnlit())}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{if(s.getExtension(Ue)){const r=e.materialIndexMap.get(s),n=t.json.materials[r];n.extensions=n.extensions||{},n.extensions[Ue]={}}}),this}}Be.EXTENSION_NAME=Ue;class ke 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")}}ke.EXTENSION_NAME="KHR_materials_variants";class Ge 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")}}Ge.EXTENSION_NAME="KHR_materials_variants";class Le extends e.ExtensionProperty{init(){this.extensionName="KHR_materials_variants",this.propertyType="Variant",this.parentTypes=["MappingList"]}}Le.EXTENSION_NAME="KHR_materials_variants";const He="KHR_materials_variants";class Ve extends e.Extension{constructor(...e){super(...e),this.extensionName=He}createMappingList(){return new Ge(this.document.getGraph())}createVariant(e=""){return new Le(this.document.getGraph(),e)}createMapping(){return new ke(this.document.getGraph())}listVariants(){return Array.from(this.properties).filter(e=>e instanceof Le)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[He])return this;const s=(t.json.extensions[He].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[He])return;const o=this.createMappingList(),i=t.extensions[He];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(He,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(He);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[He]={mappings:a}})}return t.json.extensions=t.json.extensions||{},t.json.extensions[He]={variants:r},this}}Ve.EXTENSION_NAME=He;const{G:Xe}=e.TextureChannel;class Ke 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:Xe})}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))}}Ke.EXTENSION_NAME="KHR_materials_volume";const ze="KHR_materials_volume";class qe extends e.Extension{constructor(...e){super(...e),this.extensionName=ze}createVolume(){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.createVolume();e.materials[r].setExtension(ze,n);const o=t.extensions[ze];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(ze);if(n){const o=t.materialIndexMap.get(r),i=s.json.materials[o];i.extensions=i.extensions||{};const a=i.extensions[ze]={};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}}qe.EXTENSION_NAME=ze;const $e="KHR_mesh_quantization";class Qe extends e.Extension{constructor(...e){super(...e),this.extensionName=$e}read(e){return this}write(e){return this}}Qe.EXTENSION_NAME=$e;const Ye="KHR_texture_basisu";class We{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 Je extends e.Extension{constructor(...t){super(...t),this.extensionName=Ye,this.prereadTypes=[e.PropertyType.TEXTURE]}static register(){e.ImageUtils.registerFormat("image/ktx2",new We)}preread(e){return e.jsonDoc.json.textures.forEach(e=>{e.extensions&&e.extensions[Ye]&&(e.source=e.extensions[Ye].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[Ye]={source:e.source},delete e.source)})}}),this}}Je.EXTENSION_NAME=Ye;class Ze 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)}}Ze.EXTENSION_NAME="KHR_texture_transform";const et="KHR_texture_transform";class tt extends e.Extension{constructor(...e){super(...e),this.extensionName=et}createTransform(){return new Ze(this.document.getGraph())}read(e){for(const[t,s]of Array.from(e.textureInfos.entries())){if(!s.extensions||!s.extensions[et])continue;const e=this.createTransform(),r=s.extensions[et];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(et,e)}return this}write(t){const s=Array.from(t.textureInfoDefMap.entries());for(const[t,r]of s){const s=t.getExtension(et);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[et]=n}return this}}tt.EXTENSION_NAME=et;const st=[e.PropertyType.ROOT,e.PropertyType.SCENE,e.PropertyType.NODE,e.PropertyType.MESH,e.PropertyType.MATERIAL,e.PropertyType.TEXTURE,e.PropertyType.ANIMATION];class rt extends e.ExtensionProperty{init(){this.extensionName="KHR_xmp_json_ld",this.propertyType="Packet",this.parentTypes=st}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":nt(this.get("context")),...nt(this.get("properties"))}}fromJSONLD(e){const t=(e=nt(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 nt(e){return JSON.parse(JSON.stringify(e))}rt.EXTENSION_NAME="KHR_xmp_json_ld";const ot="KHR_xmp_json_ld";class it extends e.Extension{constructor(...e){super(...e),this.extensionName=ot}createPacket(){return new rt(this.document.getGraph())}listPackets(){return Array.from(this.properties)}read(e){const t=e.jsonDoc.json.extensions?.[ot];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[ot]&&i[e][s].setExtension(ot,n[r.extensions[ot].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(`[${ot}]: Unsupported parent property, "${o.propertyType}"`)}n&&(n.extensions=n.extensions||{},n.extensions[ot]={packet:r.length-1})}}return r.length>0&&(s.extensions=s.extensions||{},s.extensions[ot]={packets:r}),this}}it.EXTENSION_NAME=ot;const at=[V,q,Z,se,oe,le,de,we,_e,je,Be,Ve,qe,Qe,Je,tt,it],ct=[n,E,R,A,...at];exports.ALL_EXTENSIONS=ct,exports.Clearcoat=W,exports.DracoMeshCompression=V,exports.EmissiveStrength=ee,exports.INSTANCE_ATTRIBUTE="INSTANCE_ATTRIBUTE",exports.IOR=re,exports.InstancedMesh=s,exports.Iridescence=ce,exports.KHRONOS_EXTENSIONS=at,exports.Light=K,exports.LightsPunctual=q,exports.Mapping=ke,exports.MappingList=Ge,exports.MaterialsClearcoat=Z,exports.MaterialsEmissiveStrength=se,exports.MaterialsIOR=oe,exports.MaterialsIridescence=le,exports.MaterialsPBRSpecularGlossiness=de,exports.MaterialsSheen=_e,exports.MaterialsSpecular=we,exports.MaterialsTransmission=je,exports.MaterialsUnlit=Be,exports.MaterialsVariants=Ve,exports.MaterialsVolume=qe,exports.MeshGPUInstancing=n,exports.MeshQuantization=Qe,exports.MeshoptCompression=E,exports.PBRSpecularGlossiness=ge,exports.Packet=rt,exports.Sheen=Re,exports.Specular=Oe,exports.TextureAVIF=R,exports.TextureBasisu=Je,exports.TextureTransform=tt,exports.TextureWebP=A,exports.Transform=Ze,exports.Transmission=be,exports.Unlit=ve,exports.Variant=Le,exports.Volume=Ke,exports.XMP=it;
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[o.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.getBounds(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 x,TextureInfo as p,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[o.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 x=this.document.getRoot().listBuffers().indexOf(g),p=[a,c,u.filter,f,x].join(":");let d=this._encoderBufferViews[p],T=this._encoderBufferViewData[p],m=this._encoderBufferViewAccessors[p];d&&T||(m=this._encoderBufferViewAccessors[p]=[],T=this._encoderBufferViewData[p]=[],d=this._encoderBufferViews[p]={buffer:i,target:n.USAGE_TO_TARGET[a],byteOffset:0,byteLength:0,byteStride:a===n.BufferViewUsage.ARRAY_BUFFER?f:void 0,extensions:{[B]:{buffer:x,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_avif";class U{match(e){return e.length>=12&&"ftypavif"===r.decodeText(e.slice(4,12))}getSize(e){return this.match(e),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/avif",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/avif"===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="EXT_texture_webp";class X{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 K extends s{constructor(...e){super(...e),this.extensionName=V,this.prereadTypes=[t.TEXTURE]}static register(){f.registerFormat("image/webp",new X)}preread(e){return(e.jsonDoc.json.textures||[]).forEach(e=>{e.extensions&&e.extensions[V]&&(e.source=e.extensions[V].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[V]={source:e.source},delete e.source)})}}),this}}K.EXTENSION_NAME=V;const z="KHR_draco_mesh_compression";let $,q,Y,Q;function W(e,t){const s=new $.DecoderBuffer;try{if(s.Init(t,t.length),e.GetEncodedGeometryType(s)!==$.TRIANGULAR_MESH)throw new Error(`[${z}] Unknown geometry type.`);const r=new $.Mesh;if(!e.DecodeBufferToMesh(s,r).ok()||0===r.ptr)throw new Error(`[${z}] Decoding failure.`);return r}finally{$.destroy(s)}}function J(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 Z(e,t,s,r){const n=Y[r.componentType],o=q[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 ee,te;!function(e){e[e.EDGEBREAKER=1]="EDGEBREAKER",e[e.SEQUENTIAL=0]="SEQUENTIAL"}(ee||(ee={})),function(e){e.POSITION="POSITION",e.NORMAL="NORMAL",e.COLOR="COLOR",e.TEX_COORD="TEX_COORD",e.GENERIC="GENERIC"}(te||(te={}));const se={[te.POSITION]:14,[te.NORMAL]:10,[te.COLOR]:8,[te.TEX_COORD]:12,[te.GENERIC]:12},re={decodeSpeed:5,encodeSpeed:5,method:ee.EDGEBREAKER,quantizationBits:se,quantizationVolume:"mesh"};function ne(e,t=re){const s=S({},re,t);s.quantizationBits=S({},se,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=oe(t),u=ie(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 ae("Primitive must have indices.");n.AddFacesToMesh(o,c.getCount()/3,c.getArray()),r.SetSpeedOptions(s.encodeSpeed,s.decodeSpeed),r.SetTrackEncodedProperties(!0),s.method===ee.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 ae("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 ae('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 oe(e){return"POSITION"===e?te.POSITION:"NORMAL"===e?te.NORMAL:e.startsWith("COLOR_")?te.COLOR:e.startsWith("TEXCOORD_")?te.TEX_COORD:te.GENERIC}function ie(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 ae extends Error{}const ce="KHR_draco_mesh_compression";class ue extends s{constructor(...e){super(...e),this.extensionName=ce,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,$=this._decoderModule,q={[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},Y={[u.ComponentType.FLOAT]:$.DT_FLOAT32,[u.ComponentType.UNSIGNED_INT]:$.DT_UINT32,[u.ComponentType.UNSIGNED_SHORT]:$.DT_UINT16,[u.ComponentType.UNSIGNED_BYTE]:$.DT_UINT8,[u.ComponentType.SHORT]:$.DT_INT16,[u.ComponentType.BYTE]:$.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(`[${ce}] 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[ce])continue;const i=o.extensions[ce];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=W(a,u),n.set(i.bufferView,[a,c]),t.debug(`[${ce}] 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=Z(a,c,r,s);e.accessors[o.attributes[t]].setArray(n)}void 0!==o.indices&&e.accessors[o.indices].setArray(J(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(`[${ce}] Please install extension dependency, "draco3d.encoder".`);const r=this.document.getLogger();r.debug(`[${ce}] 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(`[${ce}] Skipping Draco compression on non-TRIANGLES primitive.`)):r.add(e):(n.add(e),s.warn(`[${ce}] 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=le(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=le(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(`[${ce}] 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(`[${ce}] 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(`[${ce}] 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(`[${ce}]: 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=ne(t,S({},this._encoderOptions,{quantizationVolume:a}))}catch(e){if(e instanceof ae){r.warn(`[${ce}]: ${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(`[${ce}] Compressed ${n.size} primitives.`),e.extensionData[ce]={primitiveHashMap:n,primitiveEncodingMap:i},this}write(e){const t=e.extensionData[ce];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[ce]={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!==ce),t.extensionsRequired=(t.extensionsRequired||[]).filter(e=>e!==ce)}return this}}function le(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("|")}ue.EXTENSION_NAME=ce,ue.EncoderMethod=ee;class he 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:he.Type.POINT,range:null,innerConeAngle:0,outerConeAngle:Math.PI/4})}getColor(){return this.get("color")}setColor(e){return this.set("color",e)}getColorHex(){return x.factorToHex(this.getColor())}setColorHex(e){const t=this.getColor().slice();return x.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)}}he.EXTENSION_NAME="KHR_lights_punctual",he.Type={POINT:"point",SPOT:"spot",DIRECTIONAL:"directional"};const fe="KHR_lights_punctual";class ge extends s{constructor(...e){super(...e),this.extensionName=fe}createLight(e=""){return new he(this.document.getGraph(),e)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[fe])return this;const s=(t.json.extensions[fe].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[fe]&&e.nodes[r].setExtension(fe,s[t.extensions[fe].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()===he.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(fe);if(n){const o=e.nodeIndexMap.get(s),i=t.json.nodes[o];i.extensions=i.extensions||{},i.extensions[fe]={light:r.get(n)}}}),t.json.extensions=t.json.extensions||{},t.json.extensions[fe]={lights:s},this}}ge.EXTENSION_NAME=fe;const{R:xe,G:pe,B:de}=d;class Te 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 p(this.graph,"clearcoatTextureInfo"),clearcoatRoughnessFactor:0,clearcoatRoughnessTexture:null,clearcoatRoughnessTextureInfo:new p(this.graph,"clearcoatRoughnessTextureInfo"),clearcoatNormalScale:1,clearcoatNormalTexture:null,clearcoatNormalTextureInfo:new p(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:xe})}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:pe})}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:xe|pe|de})}}Te.EXTENSION_NAME="KHR_materials_clearcoat";const me="KHR_materials_clearcoat";class Ee extends s{constructor(...e){super(...e),this.extensionName=me}createClearcoat(){return new Te(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[me]){const n=this.createClearcoat();e.materials[r].setExtension(me,n);const o=t.extensions[me];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(me);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[me]={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}}Ee.EXTENSION_NAME=me;class Ie 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)}}Ie.EXTENSION_NAME="KHR_materials_emissive_strength";const Re="KHR_materials_emissive_strength";class Ne extends s{constructor(...e){super(...e),this.extensionName=Re}createEmissiveStrength(){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.createEmissiveStrength();e.materials[s].setExtension(Re,r);const n=t.extensions[Re];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(Re);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{},o.extensions[Re]={emissiveStrength:r.getEmissiveStrength()}}}),this}}Ne.EXTENSION_NAME=Re;class _e 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)}}_e.EXTENSION_NAME="KHR_materials_ior";const Se="KHR_materials_ior";class Ae extends s{constructor(...e){super(...e),this.extensionName=Se}createIOR(){return new _e(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[Se]){const r=this.createIOR();e.materials[s].setExtension(Se,r);const n=t.extensions[Se];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(Se);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{},o.extensions[Se]={ior:r.getIOR()}}}),this}}Ae.EXTENSION_NAME=Se;const{R:ye,G:Ce}=d;class Me 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 p(this.graph,"iridescenceTextureInfo"),iridescenceIOR:1.3,iridescenceThicknessMinimum:100,iridescenceThicknessMaximum:400,iridescenceThicknessTexture:null,iridescenceThicknessTextureInfo:new p(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:ye})}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:Ce})}}Me.EXTENSION_NAME="KHR_materials_iridescence";const Oe="KHR_materials_iridescence";class we extends s{constructor(...e){super(...e),this.extensionName=Oe}createIridescence(){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[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}}we.EXTENSION_NAME=Oe;const{R:De,G:Fe,B:be,A:je}=d;class ve 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 p(this.graph,"diffuseTextureInfo"),specularFactor:[1,1,1],glossinessFactor:1,specularGlossinessTexture:null,specularGlossinessTextureInfo:new p(this.graph,"specularGlossinessTextureInfo")})}getDiffuseFactor(){return this.get("diffuseFactor")}setDiffuseFactor(e){return this.set("diffuseFactor",e)}getDiffuseHex(){return x.factorToHex(this.getDiffuseFactor())}setDiffuseHex(e){const t=this.getDiffuseFactor().slice();return this.setDiffuseFactor(x.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:De|Fe|be|je})}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:De|Fe|be|je})}}ve.EXTENSION_NAME="KHR_materials_pbrSpecularGlossiness";const ke="KHR_materials_pbrSpecularGlossiness";class Be extends s{constructor(...e){super(...e),this.extensionName=ke}createPBRSpecularGlossiness(){return new ve(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[ke]){const n=this.createPBRSpecularGlossiness();e.materials[r].setExtension(ke,n);const o=t.extensions[ke];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(ke);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[ke]={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=ke;const{R:Ge,G:He,B:Le,A:Ue}=d;class Pe 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 p(this.graph,"sheenColorTextureInfo"),sheenRoughnessFactor:0,sheenRoughnessTexture:null,sheenRoughnessTextureInfo:new p(this.graph,"sheenRoughnessTextureInfo")})}getSheenColorFactor(){return this.get("sheenColorFactor")}getSheenColorHex(){return x.factorToHex(this.getSheenColorFactor())}setSheenColorFactor(e){return this.set("sheenColorFactor",e)}setSheenColorHex(e){const t=this.getSheenColorFactor().slice();return this.set("sheenColorFactor",x.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:Ge|He|Le})}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:Ue})}}Pe.EXTENSION_NAME="KHR_materials_sheen";const Ve="KHR_materials_sheen";class Xe extends s{constructor(...e){super(...e),this.extensionName=Ve}createSheen(){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[Ve]){const n=this.createSheen();e.materials[r].setExtension(Ve,n);const o=t.extensions[Ve];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(Ve);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[Ve]={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}}Xe.EXTENSION_NAME=Ve;const{R:Ke,G:ze,B:$e,A:qe}=d;class Ye 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 p(this.graph,"specularTextureInfo"),specularColorFactor:[1,1,1],specularColorTexture:null,specularColorTextureInfo:new p(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 x.factorToHex(this.getSpecularColorFactor())}setSpecularColorHex(e){const t=this.getSpecularColorFactor().slice();return this.set("specularColorFactor",x.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:qe})}getSpecularColorTexture(){return this.getRef("specularColorTexture")}getSpecularColorTextureInfo(){return this.getRef("specularColorTexture")?this.getRef("specularColorTextureInfo"):null}setSpecularColorTexture(e){return this.setRef("specularColorTexture",e,{channels:Ke|ze|$e})}}Ye.EXTENSION_NAME="KHR_materials_specular";const Qe="KHR_materials_specular";class We extends s{constructor(...e){super(...e),this.extensionName=Qe}createSpecular(){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.createSpecular();e.materials[r].setExtension(Qe,n);const o=t.extensions[Qe];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(Qe);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[Qe]={};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}}We.EXTENSION_NAME=Qe;const{R:Je}=d;class Ze 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 p(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:Je})}}Ze.EXTENSION_NAME="KHR_materials_transmission";const et="KHR_materials_transmission";class tt extends s{constructor(...e){super(...e),this.extensionName=et}createTransmission(){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[et]){const n=this.createTransmission();e.materials[r].setExtension(et,n);const o=t.extensions[et];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(et);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[et]={transmissionFactor:r.getTransmissionFactor()};if(r.getTransmissionTexture()){const t=r.getTransmissionTexture(),s=r.getTransmissionTextureInfo();i.transmissionTexture=e.createTextureInfoDef(t,s)}}}),this}}tt.EXTENSION_NAME=et;class st extends e{init(){this.extensionName="KHR_materials_unlit",this.propertyType="Unlit",this.parentTypes=[t.MATERIAL]}}st.EXTENSION_NAME="KHR_materials_unlit";const rt="KHR_materials_unlit";class nt extends s{constructor(...e){super(...e),this.extensionName=rt}createUnlit(){return new st(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{t.extensions&&t.extensions[rt]&&e.materials[s].setExtension(rt,this.createUnlit())}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{if(s.getExtension(rt)){const r=e.materialIndexMap.get(s),n=t.json.materials[r];n.extensions=n.extensions||{},n.extensions[rt]={}}}),this}}nt.EXTENSION_NAME=rt;class ot 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")}}ot.EXTENSION_NAME="KHR_materials_variants";class it 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")}}it.EXTENSION_NAME="KHR_materials_variants";class at extends e{init(){this.extensionName="KHR_materials_variants",this.propertyType="Variant",this.parentTypes=["MappingList"]}}at.EXTENSION_NAME="KHR_materials_variants";const ct="KHR_materials_variants";class ut extends s{constructor(...e){super(...e),this.extensionName=ct}createMappingList(){return new it(this.document.getGraph())}createVariant(e=""){return new at(this.document.getGraph(),e)}createMapping(){return new ot(this.document.getGraph())}listVariants(){return Array.from(this.properties).filter(e=>e instanceof at)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[ct])return this;const s=(t.json.extensions[ct].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[ct])return;const o=this.createMappingList(),i=t.extensions[ct];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(ct,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(ct);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[ct]={mappings:a}})}return t.json.extensions=t.json.extensions||{},t.json.extensions[ct]={variants:r},this}}ut.EXTENSION_NAME=ct;const{G:lt}=d;class ht 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 p(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:lt})}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 x.factorToHex(this.getAttenuationColor())}setAttenuationColorHex(e){const t=this.getAttenuationColor().slice();return this.set("attenuationColor",x.hexToFactor(e,t))}}ht.EXTENSION_NAME="KHR_materials_volume";const ft="KHR_materials_volume";class gt extends s{constructor(...e){super(...e),this.extensionName=ft}createVolume(){return new ht(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[ft]){const n=this.createVolume();e.materials[r].setExtension(ft,n);const o=t.extensions[ft];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(ft);if(r){const n=e.materialIndexMap.get(s),o=t.json.materials[n];o.extensions=o.extensions||{};const i=o.extensions[ft]={};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}}gt.EXTENSION_NAME=ft;const xt="KHR_mesh_quantization";class pt extends s{constructor(...e){super(...e),this.extensionName=xt}read(e){return this}write(e){return this}}pt.EXTENSION_NAME=xt;const dt="KHR_texture_basisu";class Tt{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 mt extends s{constructor(...e){super(...e),this.extensionName=dt,this.prereadTypes=[t.TEXTURE]}static register(){f.registerFormat("image/ktx2",new Tt)}preread(e){return e.jsonDoc.json.textures.forEach(e=>{e.extensions&&e.extensions[dt]&&(e.source=e.extensions[dt].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[dt]={source:e.source},delete e.source)})}}),this}}mt.EXTENSION_NAME=dt;class Et 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)}}Et.EXTENSION_NAME="KHR_texture_transform";const It="KHR_texture_transform";class Rt extends s{constructor(...e){super(...e),this.extensionName=It}createTransform(){return new Et(this.document.getGraph())}read(e){for(const[t,s]of Array.from(e.textureInfos.entries())){if(!s.extensions||!s.extensions[It])continue;const e=this.createTransform(),r=s.extensions[It];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(It,e)}return this}write(e){const t=Array.from(e.textureInfoDefMap.entries());for(const[e,s]of t){const t=e.getExtension(It);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[It]=r}return this}}Rt.EXTENSION_NAME=It;const Nt=[t.ROOT,t.SCENE,t.NODE,t.MESH,t.MATERIAL,t.TEXTURE,t.ANIMATION];class _t extends e{init(){this.extensionName="KHR_xmp_json_ld",this.propertyType="Packet",this.parentTypes=Nt}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":St(this.get("context"))},St(this.get("properties")))}fromJSONLD(e){const t=(e=St(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 St(e){return JSON.parse(JSON.stringify(e))}_t.EXTENSION_NAME="KHR_xmp_json_ld";const At="KHR_xmp_json_ld";class yt extends s{constructor(...e){super(...e),this.extensionName=At}createPacket(){return new _t(this.document.getGraph())}listPackets(){return Array.from(this.properties)}read(e){var t;const s=null==(t=e.jsonDoc.json.extensions)?void 0:t[At];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[At]&&a[e][s].setExtension(At,o[r.extensions[At].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(`[${At}]: Unsupported parent property, "${o.propertyType}"`)}n&&(n.extensions=n.extensions||{},n.extensions[At]={packet:r.length-1})}}return r.length>0&&(s.extensions=s.extensions||{},s.extensions[At]={packets:r}),this}}yt.EXTENSION_NAME=At;const Ct=[ue,ge,Ee,Ne,Ae,we,Be,We,Xe,tt,nt,ut,gt,pt,mt,Rt,yt],Mt=[_,H,P,K,...Ct];export{Mt as ALL_EXTENSIONS,Te as Clearcoat,ue as DracoMeshCompression,Ie as EmissiveStrength,I as INSTANCE_ATTRIBUTE,_e as IOR,R as InstancedMesh,Me as Iridescence,Ct as KHRONOS_EXTENSIONS,he as Light,ge as LightsPunctual,ot as Mapping,it as MappingList,Ee as MaterialsClearcoat,Ne as MaterialsEmissiveStrength,Ae as MaterialsIOR,we as MaterialsIridescence,Be as MaterialsPBRSpecularGlossiness,Xe as MaterialsSheen,We as MaterialsSpecular,tt as MaterialsTransmission,nt as MaterialsUnlit,ut as MaterialsVariants,gt as MaterialsVolume,_ as MeshGPUInstancing,pt as MeshQuantization,H as MeshoptCompression,ve as PBRSpecularGlossiness,_t as Packet,Pe as Sheen,Ye as Specular,P as TextureAVIF,mt as TextureBasisu,Rt as TextureTransform,K as TextureWebP,Et as Transform,Ze as Transmission,st as Unlit,at as Variant,ht as Volume,yt 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,getBounds 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[o.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
{
"name": "@gltf-transform/extensions",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.3",
"repository": "github:donmccurdy/glTF-Transform",

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

"dependencies": {
"@gltf-transform/core": "^3.0.0-alpha.2",
"@gltf-transform/core": "^3.0.0-alpha.3",
"ktx-parse": "^0.4.5"

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

],
"gitHead": "aea6259a028ea31668fbd46924b16a4997200696"
"gitHead": "707b40c87b2145b881377f1d1667deebb4a1e45a"
}
export const EXT_MESH_GPU_INSTANCING = 'EXT_mesh_gpu_instancing';
export const EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';
export const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
export const EXT_TEXTURE_AVIF = 'EXT_texture_avif';
export const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';

@@ -6,0 +5,0 @@ export const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';

@@ -5,3 +5,2 @@ /** @module extensions */

import { MeshoptCompression } from './ext-meshopt-compression';
import { TextureAVIF } from './ext-texture-avif';
import { TextureWebP } from './ext-texture-webp';

@@ -46,7 +45,6 @@ import { DracoMeshCompression } from './khr-draco-mesh-compression';

export const ALL_EXTENSIONS = [MeshGPUInstancing, MeshoptCompression, TextureAVIF, TextureWebP, ...KHRONOS_EXTENSIONS];
export const ALL_EXTENSIONS = [MeshGPUInstancing, MeshoptCompression, TextureWebP, ...KHRONOS_EXTENSIONS];
export * from './ext-mesh-gpu-instancing';
export * from './ext-meshopt-compression';
export * from './ext-texture-avif';
export * from './ext-texture-webp';

@@ -53,0 +51,0 @@ export * from './khr-draco-mesh-compression';

import {
Accessor,
bbox,
bounds,
getBounds,
BufferUtils,

@@ -247,3 +247,3 @@ Document,

} else {
quantizationVolume = bounds(this.document.getRoot().listScenes().pop()!);
quantizationVolume = getBounds(this.document.getRoot().listScenes().pop()!);
}

@@ -250,0 +250,0 @@ }

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