@gltf-transform/extensions
Advanced tools
Comparing version 3.7.5 to 3.8.0
@@ -15,5 +15,9 @@ import type { GLTF, TypedArray } from '@gltf-transform/core'; | ||
export declare enum MeshoptFilter { | ||
/** No filter — quantize only. */ | ||
NONE = "NONE", | ||
/** Four 8- or 16-bit normalized values. */ | ||
OCTAHEDRAL = "OCTAHEDRAL", | ||
/** Four 16-bit normalized values. */ | ||
QUATERNION = "QUATERNION", | ||
/** K single-precision floating point values. */ | ||
EXPONENTIAL = "EXPONENTIAL" | ||
@@ -20,0 +24,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import{ExtensionProperty as e,PropertyType as t,Extension as s,BufferUtils as n,WriterContext as r,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="EXT_mesh_gpu_instancing",N="EXT_meshopt_compression",R="KHR_draco_mesh_compression",y="KHR_lights_punctual",A="KHR_materials_anisotropy",S="KHR_materials_clearcoat",C="KHR_materials_emissive_strength",M="KHR_materials_ior",O="KHR_materials_iridescence",_="KHR_materials_pbrSpecularGlossiness",D="KHR_materials_sheen",w="KHR_materials_specular",b="KHR_materials_transmission",F="KHR_materials_unlit",j="KHR_materials_volume",v="KHR_materials_variants",k="KHR_texture_transform",B="KHR_xmp_json_ld",L="INSTANCE_ATTRIBUTE";class G extends e{init(){this.extensionName=I,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:L})}listAttributes(){return this.listRefMapValues("attributes")}listSemantics(){return this.listRefMapKeys("attributes")}}G.EXTENSION_NAME=I;const U=I;class V extends s{constructor(...e){super(...e),this.extensionName=U,this.provideTypes=[t.NODE],this.prewriteTypes=[t.ACCESSOR]}createInstancedMesh(){return new G(this.document.getGraph())}read(e){return(e.jsonDoc.json.nodes||[]).forEach((t,s)=>{if(!t.extensions||!t.extensions[U])return;const n=t.extensions[U],r=this.createInstancedMesh();for(const t in n.attributes)r.setAttribute(t,e.accessors[n.attributes[t]]);e.nodes[s].setExtension(U,r)}),this}prewrite(e){e.accessorUsageGroupedByParent.add(L);for(const t of this.properties)for(const s of t.listAttributes())e.addAccessorToUsageGroup(s,L);return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listNodes().forEach(s=>{const n=s.getExtension(U);if(n){const r=e.nodeIndexMap.get(s),o=t.json.nodes[r],i={attributes:{}};n.listSemantics().forEach(t=>{const s=n.getAttribute(t);i.attributes[t]=e.accessorIndexMap.get(s)}),o.extensions=o.extensions||{},o.extensions[U]=i}}),this}}function P(){return P=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(e[n]=s[n])}return e},P.apply(this,arguments)}var X,H,z;V.EXTENSION_NAME=U,function(e){e.QUANTIZE="quantize",e.FILTER="filter"}(X||(X={})),function(e){e.ATTRIBUTES="ATTRIBUTES",e.TRIANGLES="TRIANGLES",e.INDICES="INDICES"}(H||(H={})),function(e){e.NONE="NONE",e.OCTAHEDRAL="OCTAHEDRAL",e.QUATERNION="QUATERNION",e.EXPONENTIAL="EXPONENTIAL"}(z||(z={}));const{BYTE:$,SHORT:q,FLOAT:K}=u.ComponentType,{encodeNormalizedInt:Y,decodeNormalizedInt:Q}=l;function W(e,t,s,r){const{filter:o,bits:i}=r,a={array:e.getArray(),byteStride:e.getElementSize()*e.getComponentSize(),componentType:e.getComponentType(),normalized:e.getNormalized()};if(s!==H.ATTRIBUTES)return a;if(o!==z.NONE){let s=e.getNormalized()?function(e){const t=e.getComponentType(),s=e.getArray(),n=new Float32Array(s.length);for(let e=0;e<s.length;e++)n[e]=Q(s[e],t);return n}(e):new Float32Array(a.array);switch(o){case z.EXPONENTIAL:a.byteStride=4*e.getElementSize(),a.componentType=K,a.normalized=!1,a.array=t.encodeFilterExp(s,e.getCount(),a.byteStride,i);break;case z.OCTAHEDRAL:a.byteStride=i>8?8:4,a.componentType=i>8?q:$,a.normalized=!0,s=3===e.getElementSize()?function(e){const t=new Float32Array(4*e.length/3);for(let s=0,n=e.length/3;s<n;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 z.QUATERNION:a.byteStride=8,a.componentType=q,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=>Q(t,e.getComponentType())),a.max=a.max.map(t=>Q(t,e.getComponentType()))),a.normalized&&(a.min=a.min.map(e=>Y(e,a.componentType)),a.max=a.max.map(e=>Y(e,a.componentType)))}else a.byteStride%4&&(a.array=function(e,t){const s=n.padNumber(e.BYTES_PER_ELEMENT*t)/e.BYTES_PER_ELEMENT,r=new e.constructor(e.length/t*s);for(let n=0;n*t<e.length;n++)for(let o=0;o<t;o++)r[n*s+o]=e[n*t+o];return r}(a.array,e.getElementSize()),a.byteStride=a.array.byteLength/e.getCount());return a}function J(e,t){return t===r.BufferViewUsage.ELEMENT_ARRAY_BUFFER?e.listParents().some(e=>e instanceof o&&e.getMode()===o.Mode.TRIANGLES)?H.TRIANGLES:H.INDICES:H.ATTRIBUTES}function Z(e,t){const s=t.getGraph().listParentEdges(e).filter(e=>!(e.getParent()instanceof i));for(const t of s){const s=t.getName(),n=t.getAttributes().key||"";if("indices"===s)return{filter:z.NONE};if("attributes"===s){if("POSITION"===n)return{filter:z.NONE};if("TEXCOORD_0"===n)return{filter:z.NONE};if("NORMAL"===n)return{filter:z.OCTAHEDRAL,bits:8};if("TANGENT"===n)return{filter:z.OCTAHEDRAL,bits:8};if(n.startsWith("JOINTS_"))return{filter:z.NONE};if(n.startsWith("WEIGHTS_"))return{filter:z.NONE}}if("output"===s){const t=ee(e);return"rotation"===t?{filter:z.QUATERNION,bits:16}:"translation"===t||"scale"===t?{filter:z.EXPONENTIAL,bits:12}:{filter:z.NONE}}if("input"===s)return{filter:z.NONE};if("inverseBindMatrices"===s)return{filter:z.NONE}}return{filter:z.NONE}}function ee(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 te=N,se={method:X.QUANTIZE};class ne extends s{constructor(...e){super(...e),this.extensionName=te,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=se,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=P({},se,e),this}preread(e,s){if(!this._decoder){if(!this.isRequired())return this;throw new Error(`[${te}] Please install extension dependency, "meshopt.decoder".`)}if(!this._decoder.supported){if(!this.isRequired())return this;throw new Error(`[${te}]: 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,r)=>{if(!s.extensions||!s.extensions[te])return;const o=s.extensions[te],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=n.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[r]=l})}_prereadPrimitives(e){const t=e.jsonDoc;(t.json.bufferViews||[]).forEach(s=>{var n;s.extensions&&s.extensions[te]&&(n=t.json.buffers[s.buffer]).extensions&&n.extensions[N]&&n.extensions[N].fallback&&this._decoderFallbackBufferMap.set(e.buffers[s.buffer],e.buffers[s.extensions[te].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,n=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"===ee(o))continue;if(o.getSparse())continue;const a=e.getAccessorUsage(o),c=J(o,a),u=n.method===X.FILTER?Z(o,this.document):{filter:z.NONE},l=W(o,s,c,u),{array:h,byteStride:f}=l,g=o.getBuffer();if(!g)throw new Error(`${te}: 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:r.USAGE_TO_TARGET[a],byteOffset:0,byteLength:0,byteStride:a===r.BufferViewUsage.ARRAY_BUFFER?f:void 0,extensions:{[te]:{buffer:p,byteOffset:0,byteLength:0,mode:c,filter:u.filter!==z.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 r=this._encoderBufferViews[s],o=this._encoderBufferViewData[s],i=this.document.getRoot().listBuffers()[r.extensions[te].buffer],a=e.otherBufferViews.get(i)||[],{count:c,byteStride:u,mode:l}=r.extensions[te],h=n.concat(o),f=t.encodeGltfBuffer(h,c,u,l),g=n.pad(f);r.extensions[te].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 r=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,r),a.byteOffset=t,a.extensions[te].byteOffset=c,t+=n.padNumber(r.byteLength)}const s=this._encoderFallbackBuffer,r=e.bufferIndexMap.get(s),o=e.jsonDoc.json.buffers[r];return o.byteLength=t,o.extensions={[te]:{fallback:!0}},s.dispose(),this}}ne.EXTENSION_NAME=te,ne.EncoderMethod=X;const re="EXT_texture_avif";class oe{match(e){return e.length>=12&&"ftypavif"===n.decodeText(e.slice(4,12))}getSize(e){if(!this.match(e))return null;const t=new DataView(e.buffer,e.byteOffset,e.byteLength);let s=ae(t,0);if(!s)return null;let n=s.end;for(;s=ae(t,n);)if("meta"===s.type)n=s.start+4;else if("iprp"===s.type||"ipco"===s.type)n=s.start;else{if("ispe"===s.type)return[t.getUint32(s.start+4),t.getUint32(s.start+8)];if("mdat"===s.type)break;n=s.end}return null}getChannels(e){return 4}}class ie extends s{constructor(...e){super(...e),this.extensionName=re,this.prereadTypes=[t.TEXTURE]}static register(){f.registerFormat("image/avif",new oe)}preread(e){return(e.jsonDoc.json.textures||[]).forEach(e=>{e.extensions&&e.extensions[re]&&(e.source=e.extensions[re].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 n=e.imageIndexMap.get(s);(t.json.textures||[]).forEach(e=>{e.source===n&&(e.extensions=e.extensions||{},e.extensions[re]={source:e.source},delete e.source)})}}),this}}function ae(e,t){if(e.byteLength<4+t)return null;const s=e.getUint32(t);return e.byteLength<s+t||s<8?null:{type:n.decodeText(new Uint8Array(e.buffer,e.byteOffset+t+4,4)),start:t+8,end:t+s}}ie.EXTENSION_NAME=re;const ce="EXT_texture_webp";class ue{match(e){return e.length>=12&&87===e[8]&&69===e[9]&&66===e[10]&&80===e[11]}getSize(e){const t=n.decodeText(e.slice(0,4)),s=n.decodeText(e.slice(8,12));if("RIFF"!==t||"WEBP"!==s)return null;const r=new DataView(e.buffer,e.byteOffset);let o=12;for(;o<r.byteLength;){const e=n.decodeText(new Uint8Array([r.getUint8(o),r.getUint8(o+1),r.getUint8(o+2),r.getUint8(o+3)])),t=r.getUint32(o+4,!0);if("VP8 "===e)return[16383&r.getInt16(o+14,!0),16383&r.getInt16(o+16,!0)];if("VP8L"===e){const e=r.getUint8(o+9),t=r.getUint8(o+10),s=r.getUint8(o+11);return[1+((63&t)<<8|e),1+((15&r.getUint8(o+12))<<10|s<<2|(192&t)>>6)]}o+=8+t+t%2}return null}getChannels(e){return 4}}class le extends s{constructor(...e){super(...e),this.extensionName=ce,this.prereadTypes=[t.TEXTURE]}static register(){f.registerFormat("image/webp",new ue)}preread(e){return(e.jsonDoc.json.textures||[]).forEach(e=>{e.extensions&&e.extensions[ce]&&(e.source=e.extensions[ce].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 n=e.imageIndexMap.get(s);(t.json.textures||[]).forEach(e=>{e.source===n&&(e.extensions=e.extensions||{},e.extensions[ce]={source:e.source},delete e.source)})}}),this}}le.EXTENSION_NAME=ce;const he=R;let fe,ge,pe,xe;function de(e,t){const s=new fe.DecoderBuffer;try{if(s.Init(t,t.length),e.GetEncodedGeometryType(s)!==fe.TRIANGULAR_MESH)throw new Error(`[${he}] Unknown geometry type.`);const n=new fe.Mesh;if(!e.DecodeBufferToMesh(s,n).ok()||0===n.ptr)throw new Error(`[${he}] Decoding failure.`);return n}finally{fe.destroy(s)}}function Te(e,t){const s=3*t.num_faces();let n,r;if(t.num_points()<=65534){const o=s*Uint16Array.BYTES_PER_ELEMENT;n=fe._malloc(o),e.GetTrianglesUInt16Array(t,o,n),r=new Uint16Array(fe.HEAPU16.buffer,n,s).slice()}else{const o=s*Uint32Array.BYTES_PER_ELEMENT;n=fe._malloc(o),e.GetTrianglesUInt32Array(t,o,n),r=new Uint32Array(fe.HEAPU32.buffer,n,s).slice()}return fe._free(n),r}function me(e,t,s,n){const r=pe[n.componentType],o=ge[n.componentType],i=s.num_components(),a=t.num_points()*i,c=a*o.BYTES_PER_ELEMENT,u=fe._malloc(c);e.GetAttributeDataArrayForAllPoints(t,s,r,c,u);const l=new o(fe.HEAPF32.buffer,u,a).slice();return fe._free(u),l}var Ee,Ie;!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"}(Ie||(Ie={}));const Ne={[Ie.POSITION]:14,[Ie.NORMAL]:10,[Ie.COLOR]:8,[Ie.TEX_COORD]:12,[Ie.GENERIC]:12},Re={decodeSpeed:5,encodeSpeed:5,method:Ee.EDGEBREAKER,quantizationBits:Ne,quantizationVolume:"mesh"};function ye(e,t=Re){const s=P({},Re,t);s.quantizationBits=P({},Ne,t.quantizationBits);const n=new xe.MeshBuilder,r=new xe.Mesh,o=new xe.ExpertEncoder(r),i={},a=new xe.DracoInt8Array,c=e.listTargets().length>0;let u=!1;for(const t of e.listSemantics()){const a=e.getAttribute(t);if(a.getSparse()){u=!0;continue}const c=Ae(t),l=Se(n,a.getComponentType(),r,xe[c],a.getCount(),a.getElementSize(),a.getArray());if(-1===l)throw new Error(`Error compressing "${t}" attribute.`);if(i[t]=l,"mesh"===s.quantizationVolume||"POSITION"!==t)o.SetAttributeQuantization(l,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]);o.SetAttributeExplicitQuantization(l,s.quantizationBits[c],a.getElementSize(),e.min,t)}}}const l=e.getIndices();if(!l)throw new Ce("Primitive must have indices.");n.AddFacesToMesh(r,l.getCount()/3,l.getArray()),o.SetSpeedOptions(s.encodeSpeed,s.decodeSpeed),o.SetTrackEncodedProperties(!0),o.SetEncodingMethod(s.method===Ee.SEQUENTIAL||c||u?xe.MESH_SEQUENTIAL_ENCODING:xe.MESH_EDGEBREAKER_ENCODING);const h=o.EncodeToDracoBuffer(!(c||u),a);if(h<=0)throw new Ce("Error applying Draco compression.");const f=new Uint8Array(h);for(let e=0;e<h;++e)f[e]=a.GetValue(e);const g=o.GetNumberOfEncodedPoints(),p=3*o.GetNumberOfEncodedFaces();return xe.destroy(a),xe.destroy(r),xe.destroy(n),xe.destroy(o),{numVertices:g,numIndices:p,data:f,attributeIDs:i}}function Ae(e){return"POSITION"===e?Ie.POSITION:"NORMAL"===e?Ie.NORMAL:e.startsWith("COLOR_")?Ie.COLOR:e.startsWith("TEXCOORD_")?Ie.TEX_COORD:Ie.GENERIC}function Se(e,t,s,n,r,o,i){switch(t){case u.ComponentType.UNSIGNED_BYTE:return e.AddUInt8Attribute(s,n,r,o,i);case u.ComponentType.BYTE:return e.AddInt8Attribute(s,n,r,o,i);case u.ComponentType.UNSIGNED_SHORT:return e.AddUInt16Attribute(s,n,r,o,i);case u.ComponentType.SHORT:return e.AddInt16Attribute(s,n,r,o,i);case u.ComponentType.UNSIGNED_INT:return e.AddUInt32Attribute(s,n,r,o,i);case u.ComponentType.FLOAT:return e.AddFloatAttribute(s,n,r,o,i);default:throw new Error(`Unexpected component type, "${t}".`)}}class Ce extends Error{}const Me=R;class Oe extends s{constructor(...e){super(...e),this.extensionName=Me,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,fe=this._decoderModule,ge={[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},pe={[u.ComponentType.FLOAT]:fe.DT_FLOAT32,[u.ComponentType.UNSIGNED_INT]:fe.DT_UINT32,[u.ComponentType.UNSIGNED_SHORT]:fe.DT_UINT16,[u.ComponentType.UNSIGNED_BYTE]:fe.DT_UINT8,[u.ComponentType.SHORT]:fe.DT_INT16,[u.ComponentType.BYTE]:fe.DT_INT8}),"draco3d.encoder"===e&&(this._encoderModule=t,xe=this._encoderModule),this}setEncoderOptions(e){return this._encoderOptions=e,this}preread(e){if(!this._decoderModule)throw new Error(`[${Me}] Please install extension dependency, "draco3d.decoder".`);const t=this.document.getLogger(),s=e.jsonDoc,r=new Map;try{const o=s.json.meshes||[];for(const i of o)for(const o of i.primitives){if(!o.extensions||!o.extensions[Me])continue;const i=o.extensions[Me];let[a,c]=r.get(i.bufferView)||[];if(!c||!a){const e=s.json.bufferViews[i.bufferView],o=s.json.buffers[e.buffer],u=n.toView(o.uri?s.resources[o.uri]:s.resources[h],e.byteOffset||0,e.byteLength);a=new this._decoderModule.Decoder,c=de(a,u),r.set(i.bufferView,[a,c]),t.debug(`[${Me}] Decompressed ${u.byteLength} bytes.`)}for(const t in o.attributes){const s=e.jsonDoc.json.accessors[o.attributes[t]],n=a.GetAttributeByUniqueId(c,i.attributes[t]),r=me(a,c,n,s);e.accessors[o.attributes[t]].setArray(r)}void 0!==o.indices&&e.accessors[o.indices].setArray(Te(a,c))}}finally{for(const[e,t]of Array.from(r.values()))this._decoderModule.destroy(e),this._decoderModule.destroy(t)}return this}read(e){return this}prewrite(e,s){if(!this._encoderModule)throw new Error(`[${Me}] Please install extension dependency, "draco3d.encoder".`);const n=this.document.getLogger();n.debug(`[${Me}] Compression options: ${JSON.stringify(this._encoderOptions)}`);const r=function(e){const s=e.getLogger(),n=new Set,r=new Set;for(const t of e.getRoot().listMeshes())for(const e of t.listPrimitives())e.getIndices()?e.getMode()!==o.Mode.TRIANGLES?(r.add(e),s.warn(`[${Me}] Skipping Draco compression on non-TRIANGLES primitive.`)):n.add(e):(r.add(e),s.warn(`[${Me}] 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(n)){let s=_e(t,a);if(u.has(s))l.set(t,s);else{if(c.has(t.getIndices())){const s=t.getIndices(),n=s.clone();a.set(n,e.getRoot().listAccessors().length-1),t.swap(s,n)}for(const s of t.listAttributes())if(c.has(s)){const n=s.clone();a.set(n,e.getRoot().listAccessors().length-1),t.swap(s,n)}s=_e(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(`[${Me}] Compressed accessors must only be used as indices or vertex attributes.`)}for(const e of Array.from(n)){const t=l.get(e),s=e.getIndices();if(c.get(s)!==t||e.listAttributes().some(e=>c.get(e)!==t))throw new Error(`[${Me}] Draco primitives must share all, or no, accessors.`)}for(const e of Array.from(r)){const t=e.getIndices();if(c.has(t)||e.listAttributes().some(e=>c.has(e)))throw new Error(`[${Me}] 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?n.warn(`[${Me}]: quantizationVolume=scene requires exactly 1 scene.`):a=g(this.document.getRoot().listScenes().pop()));for(const t of Array.from(r.keys())){const s=r.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=ye(t,P({},this._encoderOptions,{quantizationVolume:a}))}catch(e){if(e instanceof Ce){n.warn(`[${Me}]: ${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 n=t.getAttribute(s);if(void 0===u.attributeIDs[s])continue;const r=e.createAccessorDef(n);r.count=u.numVertices,e.accessorIndexMap.set(n,c.length),c.push(r)}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 n.debug(`[${Me}] Compressed ${r.size} primitives.`),e.extensionData[Me]={primitiveHashMap:r,primitiveEncodingMap:i},this}write(e){const t=e.extensionData[Me];for(const s of this.document.getRoot().listMeshes()){const n=e.jsonDoc.json.meshes[e.meshIndexMap.get(s)];for(let r=0;r<s.listPrimitives().length;r++){const o=s.listPrimitives()[r],i=n.primitives[r],a=t.primitiveHashMap.get(o);if(!a)continue;const c=t.primitiveEncodingMap.get(a);c&&(i.extensions=i.extensions||{},i.extensions[Me]={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!==Me),t.extensionsRequired=(t.extensionsRequired||[]).filter(e=>e!==Me)}return this}}function _e(e,t){const s=[],n=e.getIndices();s.push(t.get(n));for(const n of e.listAttributes())s.push(t.get(n));return s.sort().join("|")}Oe.EXTENSION_NAME=Me,Oe.EncoderMethod=Ee;class De extends e{init(){this.extensionName=y,this.propertyType="Light",this.parentTypes=[t.NODE]}getDefaults(){return Object.assign(super.getDefaults(),{color:[1,1,1],intensity:1,type:De.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)}}De.EXTENSION_NAME=y,De.Type={POINT:"point",SPOT:"spot",DIRECTIONAL:"directional"};const we=y;class be extends s{constructor(...e){super(...e),this.extensionName=we}createLight(e=""){return new De(this.document.getGraph(),e)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[we])return this;const s=(t.json.extensions[we].lights||[]).map(e=>{var t,s;const n=this.createLight().setName(e.name||"").setType(e.type);return void 0!==e.color&&n.setColor(e.color),void 0!==e.intensity&&n.setIntensity(e.intensity),void 0!==e.range&&n.setRange(e.range),void 0!==(null==(t=e.spot)?void 0:t.innerConeAngle)&&n.setInnerConeAngle(e.spot.innerConeAngle),void 0!==(null==(s=e.spot)?void 0:s.outerConeAngle)&&n.setOuterConeAngle(e.spot.outerConeAngle),n});return t.json.nodes.forEach((t,n)=>{t.extensions&&t.extensions[we]&&e.nodes[n].setExtension(we,s[t.extensions[we].light])}),this}write(e){const t=e.jsonDoc;if(0===this.properties.size)return this;const s=[],n=new Map;for(const e of this.properties){const t=e,r={type:t.getType()};l.eq(t.getColor(),[1,1,1])||(r.color=t.getColor()),1!==t.getIntensity()&&(r.intensity=t.getIntensity()),null!=t.getRange()&&(r.range=t.getRange()),t.getName()&&(r.name=t.getName()),t.getType()===De.Type.SPOT&&(r.spot={innerConeAngle:t.getInnerConeAngle(),outerConeAngle:t.getOuterConeAngle()}),s.push(r),n.set(t,s.length-1)}return this.document.getRoot().listNodes().forEach(s=>{const r=s.getExtension(we);if(r){const o=e.nodeIndexMap.get(s),i=t.json.nodes[o];i.extensions=i.extensions||{},i.extensions[we]={light:n.get(r)}}}),t.json.extensions=t.json.extensions||{},t.json.extensions[we]={lights:s},this}}be.EXTENSION_NAME=we;const{R:Fe,G:je,B:ve}=d;class ke extends e{init(){this.extensionName=A,this.propertyType="Anisotropy",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{anisotropyStrength:0,anisotropyRotation:0,anisotropyTexture:null,anisotropyTextureInfo:new x(this.graph,"anisotropyTextureInfo")})}getAnisotropyStrength(){return this.get("anisotropyStrength")}setAnisotropyStrength(e){return this.set("anisotropyStrength",e)}getAnisotropyRotation(){return this.get("anisotropyRotation")}setAnisotropyRotation(e){return this.set("anisotropyRotation",e)}getAnisotropyTexture(){return this.getRef("anisotropyTexture")}getAnisotropyTextureInfo(){return this.getRef("anisotropyTexture")?this.getRef("anisotropyTextureInfo"):null}setAnisotropyTexture(e){return this.setRef("anisotropyTexture",e,{channels:Fe|je|ve})}}ke.EXTENSION_NAME=A;const Be=A;class Le extends s{constructor(...e){super(...e),this.extensionName=Be}createAnisotropy(){return new ke(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[Be]){const r=this.createAnisotropy();e.materials[n].setExtension(Be,r);const o=t.extensions[Be];if(void 0!==o.anisotropyStrength&&r.setAnisotropyStrength(o.anisotropyStrength),void 0!==o.anisotropyRotation&&r.setAnisotropyRotation(o.anisotropyRotation),void 0!==o.anisotropyTexture){const t=o.anisotropyTexture;r.setAnisotropyTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getAnisotropyTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(Be);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[Be]={};if(n.getAnisotropyStrength()>0&&(i.anisotropyStrength=n.getAnisotropyStrength()),0!==n.getAnisotropyRotation()&&(i.anisotropyRotation=n.getAnisotropyRotation()),n.getAnisotropyTexture()){const t=n.getAnisotropyTexture(),s=n.getAnisotropyTextureInfo();i.anisotropyTexture=e.createTextureInfoDef(t,s)}}}),this}}Le.EXTENSION_NAME=Be;const{R:Ge,G:Ue,B:Ve}=d;class Pe extends e{init(){this.extensionName=S,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:Ge})}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:Ue})}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:Ge|Ue|Ve})}}Pe.EXTENSION_NAME=S;const Xe=S;class He 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,n)=>{if(t.extensions&&t.extensions[Xe]){const r=this.createClearcoat();e.materials[n].setExtension(Xe,r);const o=t.extensions[Xe];if(void 0!==o.clearcoatFactor&&r.setClearcoatFactor(o.clearcoatFactor),void 0!==o.clearcoatRoughnessFactor&&r.setClearcoatRoughnessFactor(o.clearcoatRoughnessFactor),void 0!==o.clearcoatTexture){const t=o.clearcoatTexture;r.setClearcoatTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getClearcoatTextureInfo(),t)}if(void 0!==o.clearcoatRoughnessTexture){const t=o.clearcoatRoughnessTexture;r.setClearcoatRoughnessTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getClearcoatRoughnessTextureInfo(),t)}if(void 0!==o.clearcoatNormalTexture){const t=o.clearcoatNormalTexture;r.setClearcoatNormalTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getClearcoatNormalTextureInfo(),t),void 0!==t.scale&&r.setClearcoatNormalScale(t.scale)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(Xe);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[Xe]={clearcoatFactor:n.getClearcoatFactor(),clearcoatRoughnessFactor:n.getClearcoatRoughnessFactor()};if(n.getClearcoatTexture()){const t=n.getClearcoatTexture(),s=n.getClearcoatTextureInfo();i.clearcoatTexture=e.createTextureInfoDef(t,s)}if(n.getClearcoatRoughnessTexture()){const t=n.getClearcoatRoughnessTexture(),s=n.getClearcoatRoughnessTextureInfo();i.clearcoatRoughnessTexture=e.createTextureInfoDef(t,s)}if(n.getClearcoatNormalTexture()){const t=n.getClearcoatNormalTexture(),s=n.getClearcoatNormalTextureInfo();i.clearcoatNormalTexture=e.createTextureInfoDef(t,s),1!==n.getClearcoatNormalScale()&&(i.clearcoatNormalTexture.scale=n.getClearcoatNormalScale())}}}),this}}He.EXTENSION_NAME=Xe;class ze extends e{init(){this.extensionName=C,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)}}ze.EXTENSION_NAME=C;const $e=C;class qe extends s{constructor(...e){super(...e),this.extensionName=$e}createEmissiveStrength(){return new ze(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[$e]){const n=this.createEmissiveStrength();e.materials[s].setExtension($e,n);const r=t.extensions[$e];void 0!==r.emissiveStrength&&n.setEmissiveStrength(r.emissiveStrength)}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension($e);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{},o.extensions[$e]={emissiveStrength:n.getEmissiveStrength()}}}),this}}qe.EXTENSION_NAME=$e;class Ke extends e{init(){this.extensionName=M,this.propertyType="IOR",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{ior:1.5})}getIOR(){return this.get("ior")}setIOR(e){return this.set("ior",e)}}Ke.EXTENSION_NAME=M;const Ye=M;class Qe extends s{constructor(...e){super(...e),this.extensionName=Ye}createIOR(){return new Ke(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[Ye]){const n=this.createIOR();e.materials[s].setExtension(Ye,n);const r=t.extensions[Ye];void 0!==r.ior&&n.setIOR(r.ior)}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(Ye);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{},o.extensions[Ye]={ior:n.getIOR()}}}),this}}Qe.EXTENSION_NAME=Ye;const{R:We,G:Je}=d;class Ze extends e{init(){this.extensionName=O,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:We})}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:Je})}}Ze.EXTENSION_NAME=O;const et=O;class tt extends s{constructor(...e){super(...e),this.extensionName=et}createIridescence(){return new Ze(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[et]){const r=this.createIridescence();e.materials[n].setExtension(et,r);const o=t.extensions[et];if(void 0!==o.iridescenceFactor&&r.setIridescenceFactor(o.iridescenceFactor),void 0!==o.iridescenceIor&&r.setIridescenceIOR(o.iridescenceIor),void 0!==o.iridescenceThicknessMinimum&&r.setIridescenceThicknessMinimum(o.iridescenceThicknessMinimum),void 0!==o.iridescenceThicknessMaximum&&r.setIridescenceThicknessMaximum(o.iridescenceThicknessMaximum),void 0!==o.iridescenceTexture){const t=o.iridescenceTexture;r.setIridescenceTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getIridescenceTextureInfo(),t)}if(void 0!==o.iridescenceThicknessTexture){const t=o.iridescenceThicknessTexture;r.setIridescenceThicknessTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getIridescenceThicknessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(et);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[et]={};if(n.getIridescenceFactor()>0&&(i.iridescenceFactor=n.getIridescenceFactor()),1.3!==n.getIridescenceIOR()&&(i.iridescenceIor=n.getIridescenceIOR()),100!==n.getIridescenceThicknessMinimum()&&(i.iridescenceThicknessMinimum=n.getIridescenceThicknessMinimum()),400!==n.getIridescenceThicknessMaximum()&&(i.iridescenceThicknessMaximum=n.getIridescenceThicknessMaximum()),n.getIridescenceTexture()){const t=n.getIridescenceTexture(),s=n.getIridescenceTextureInfo();i.iridescenceTexture=e.createTextureInfoDef(t,s)}if(n.getIridescenceThicknessTexture()){const t=n.getIridescenceThicknessTexture(),s=n.getIridescenceThicknessTextureInfo();i.iridescenceThicknessTexture=e.createTextureInfoDef(t,s)}}}),this}}tt.EXTENSION_NAME=et;const{R:st,G:nt,B:rt,A:ot}=d;class it extends e{init(){this.extensionName=_,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:st|nt|rt|ot,isColor:!0})}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:st|nt|rt|ot})}}it.EXTENSION_NAME=_;const at=_;class ct extends s{constructor(...e){super(...e),this.extensionName=at}createPBRSpecularGlossiness(){return new it(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[at]){const r=this.createPBRSpecularGlossiness();e.materials[n].setExtension(at,r);const o=t.extensions[at];if(void 0!==o.diffuseFactor&&r.setDiffuseFactor(o.diffuseFactor),void 0!==o.specularFactor&&r.setSpecularFactor(o.specularFactor),void 0!==o.glossinessFactor&&r.setGlossinessFactor(o.glossinessFactor),void 0!==o.diffuseTexture){const t=o.diffuseTexture;r.setDiffuseTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getDiffuseTextureInfo(),t)}if(void 0!==o.specularGlossinessTexture){const t=o.specularGlossinessTexture;r.setSpecularGlossinessTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getSpecularGlossinessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(at);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[at]={diffuseFactor:n.getDiffuseFactor(),specularFactor:n.getSpecularFactor(),glossinessFactor:n.getGlossinessFactor()};if(n.getDiffuseTexture()){const t=n.getDiffuseTexture(),s=n.getDiffuseTextureInfo();i.diffuseTexture=e.createTextureInfoDef(t,s)}if(n.getSpecularGlossinessTexture()){const t=n.getSpecularGlossinessTexture(),s=n.getSpecularGlossinessTextureInfo();i.specularGlossinessTexture=e.createTextureInfoDef(t,s)}}}),this}}ct.EXTENSION_NAME=at;const{R:ut,G:lt,B:ht,A:ft}=d;class gt extends e{init(){this.extensionName=D,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:ut|lt|ht,isColor:!0})}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:ft})}}gt.EXTENSION_NAME=D;const pt=D;class xt extends s{constructor(...e){super(...e),this.extensionName=pt}createSheen(){return new gt(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[pt]){const r=this.createSheen();e.materials[n].setExtension(pt,r);const o=t.extensions[pt];if(void 0!==o.sheenColorFactor&&r.setSheenColorFactor(o.sheenColorFactor),void 0!==o.sheenRoughnessFactor&&r.setSheenRoughnessFactor(o.sheenRoughnessFactor),void 0!==o.sheenColorTexture){const t=o.sheenColorTexture;r.setSheenColorTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getSheenColorTextureInfo(),t)}if(void 0!==o.sheenRoughnessTexture){const t=o.sheenRoughnessTexture;r.setSheenRoughnessTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getSheenRoughnessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(pt);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[pt]={sheenColorFactor:n.getSheenColorFactor(),sheenRoughnessFactor:n.getSheenRoughnessFactor()};if(n.getSheenColorTexture()){const t=n.getSheenColorTexture(),s=n.getSheenColorTextureInfo();i.sheenColorTexture=e.createTextureInfoDef(t,s)}if(n.getSheenRoughnessTexture()){const t=n.getSheenRoughnessTexture(),s=n.getSheenRoughnessTextureInfo();i.sheenRoughnessTexture=e.createTextureInfoDef(t,s)}}}),this}}xt.EXTENSION_NAME=pt;const{R:dt,G:Tt,B:mt,A:Et}=d;class It extends e{init(){this.extensionName=w,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:Et})}getSpecularColorTexture(){return this.getRef("specularColorTexture")}getSpecularColorTextureInfo(){return this.getRef("specularColorTexture")?this.getRef("specularColorTextureInfo"):null}setSpecularColorTexture(e){return this.setRef("specularColorTexture",e,{channels:dt|Tt|mt,isColor:!0})}}It.EXTENSION_NAME=w;const Nt=w;class Rt extends s{constructor(...e){super(...e),this.extensionName=Nt}createSpecular(){return new It(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[Nt]){const r=this.createSpecular();e.materials[n].setExtension(Nt,r);const o=t.extensions[Nt];if(void 0!==o.specularFactor&&r.setSpecularFactor(o.specularFactor),void 0!==o.specularColorFactor&&r.setSpecularColorFactor(o.specularColorFactor),void 0!==o.specularTexture){const t=o.specularTexture;r.setSpecularTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getSpecularTextureInfo(),t)}if(void 0!==o.specularColorTexture){const t=o.specularColorTexture;r.setSpecularColorTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getSpecularColorTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(Nt);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[Nt]={};if(1!==n.getSpecularFactor()&&(i.specularFactor=n.getSpecularFactor()),l.eq(n.getSpecularColorFactor(),[1,1,1])||(i.specularColorFactor=n.getSpecularColorFactor()),n.getSpecularTexture()){const t=n.getSpecularTexture(),s=n.getSpecularTextureInfo();i.specularTexture=e.createTextureInfoDef(t,s)}if(n.getSpecularColorTexture()){const t=n.getSpecularColorTexture(),s=n.getSpecularColorTextureInfo();i.specularColorTexture=e.createTextureInfoDef(t,s)}}}),this}}Rt.EXTENSION_NAME=Nt;const{R:yt}=d;class At extends e{init(){this.extensionName=b,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:yt})}}At.EXTENSION_NAME=b;const St=b;class Ct extends s{constructor(...e){super(...e),this.extensionName=St}createTransmission(){return new At(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[St]){const r=this.createTransmission();e.materials[n].setExtension(St,r);const o=t.extensions[St];if(void 0!==o.transmissionFactor&&r.setTransmissionFactor(o.transmissionFactor),void 0!==o.transmissionTexture){const t=o.transmissionTexture;r.setTransmissionTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getTransmissionTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(St);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[St]={transmissionFactor:n.getTransmissionFactor()};if(n.getTransmissionTexture()){const t=n.getTransmissionTexture(),s=n.getTransmissionTextureInfo();i.transmissionTexture=e.createTextureInfoDef(t,s)}}}),this}}Ct.EXTENSION_NAME=St;class Mt extends e{init(){this.extensionName=F,this.propertyType="Unlit",this.parentTypes=[t.MATERIAL]}}Mt.EXTENSION_NAME=F;const Ot=F;class _t extends s{constructor(...e){super(...e),this.extensionName=Ot}createUnlit(){return new Mt(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{t.extensions&&t.extensions[Ot]&&e.materials[s].setExtension(Ot,this.createUnlit())}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{if(s.getExtension(Ot)){const n=e.materialIndexMap.get(s),r=t.json.materials[n];r.extensions=r.extensions||{},r.extensions[Ot]={}}}),this}}_t.EXTENSION_NAME=Ot;class Dt extends e{init(){this.extensionName=v,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")}}Dt.EXTENSION_NAME=v;class wt extends e{init(){this.extensionName=v,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")}}wt.EXTENSION_NAME=v;class bt extends e{init(){this.extensionName=v,this.propertyType="Variant",this.parentTypes=["MappingList"]}}bt.EXTENSION_NAME=v;const Ft=v;class jt extends s{constructor(...e){super(...e),this.extensionName=Ft}createMappingList(){return new wt(this.document.getGraph())}createVariant(e=""){return new bt(this.document.getGraph(),e)}createMapping(){return new Dt(this.document.getGraph())}listVariants(){return Array.from(this.properties).filter(e=>e instanceof bt)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[Ft])return this;const s=(t.json.extensions[Ft].variants||[]).map(e=>this.createVariant().setName(e.name||""));return(t.json.meshes||[]).forEach((t,n)=>{const r=e.meshes[n];(t.primitives||[]).forEach((t,n)=>{if(!t.extensions||!t.extensions[Ft])return;const o=this.createMappingList(),i=t.extensions[Ft];for(const t of i.mappings){const n=this.createMapping();void 0!==t.material&&n.setMaterial(e.materials[t.material]);for(const e of t.variants||[])n.addVariant(s[e]);o.addMapping(n)}r.listPrimitives()[n].setExtension(Ft,o)})}),this}write(e){const t=e.jsonDoc,s=this.listVariants();if(!s.length)return this;const n=[],r=new Map;for(const t of s)r.set(t,n.length),n.push(e.createPropertyDef(t));for(const t of this.document.getRoot().listMeshes()){const s=e.meshIndexMap.get(t);t.listPrimitives().forEach((t,n)=>{const o=t.getExtension(Ft);if(!o)return;const i=e.jsonDoc.json.meshes[s].primitives[n],a=o.listMappings().map(t=>{const s=e.createPropertyDef(t),n=t.getMaterial();return n&&(s.material=e.materialIndexMap.get(n)),s.variants=t.listVariants().map(e=>r.get(e)),s});i.extensions=i.extensions||{},i.extensions[Ft]={mappings:a}})}return t.json.extensions=t.json.extensions||{},t.json.extensions[Ft]={variants:n},this}}jt.EXTENSION_NAME=Ft;const{G:vt}=d;class kt extends e{init(){this.extensionName=j,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:vt})}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))}}kt.EXTENSION_NAME=j;const Bt=j;class Lt extends s{constructor(...e){super(...e),this.extensionName=Bt}createVolume(){return new kt(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[Bt]){const r=this.createVolume();e.materials[n].setExtension(Bt,r);const o=t.extensions[Bt];if(void 0!==o.thicknessFactor&&r.setThicknessFactor(o.thicknessFactor),void 0!==o.attenuationDistance&&r.setAttenuationDistance(o.attenuationDistance),void 0!==o.attenuationColor&&r.setAttenuationColor(o.attenuationColor),void 0!==o.thicknessTexture){const t=o.thicknessTexture;r.setThicknessTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getThicknessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(Bt);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[Bt]={};if(n.getThicknessFactor()>0&&(i.thicknessFactor=n.getThicknessFactor()),Number.isFinite(n.getAttenuationDistance())&&(i.attenuationDistance=n.getAttenuationDistance()),l.eq(n.getAttenuationColor(),[1,1,1])||(i.attenuationColor=n.getAttenuationColor()),n.getThicknessTexture()){const t=n.getThicknessTexture(),s=n.getThicknessTextureInfo();i.thicknessTexture=e.createTextureInfoDef(t,s)}}}),this}}Lt.EXTENSION_NAME=Bt;const Gt="KHR_mesh_quantization";class Ut extends s{constructor(...e){super(...e),this.extensionName=Gt}read(e){return this}write(e){return this}}Ut.EXTENSION_NAME=Gt;const Vt="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}".`)}getVRAMByteLength(e){const t=T(e),s=this.getChannels(e)>3;let n=0;for(let e=0;e<t.levels.length;e++){const r=t.levels[e];n+=r.uncompressedByteLength?r.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 n}}class Xt extends s{constructor(...e){super(...e),this.extensionName=Vt,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[Vt]&&(e.source=e.extensions[Vt].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 n=e.imageIndexMap.get(s);t.json.textures.forEach(e=>{e.source===n&&(e.extensions=e.extensions||{},e.extensions[Vt]={source:e.source},delete e.source)})}}),this}}Xt.EXTENSION_NAME=Vt;class Ht extends e{init(){this.extensionName=k,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)}}Ht.EXTENSION_NAME=k;const zt=k;class $t extends s{constructor(...e){super(...e),this.extensionName=zt}createTransform(){return new Ht(this.document.getGraph())}read(e){for(const[t,s]of Array.from(e.textureInfos.entries())){if(!s.extensions||!s.extensions[zt])continue;const e=this.createTransform(),n=s.extensions[zt];void 0!==n.offset&&e.setOffset(n.offset),void 0!==n.rotation&&e.setRotation(n.rotation),void 0!==n.scale&&e.setScale(n.scale),void 0!==n.texCoord&&e.setTexCoord(n.texCoord),t.setExtension(zt,e)}return this}write(e){const t=Array.from(e.textureInfoDefMap.entries());for(const[e,s]of t){const t=e.getExtension(zt);if(!t)continue;s.extensions=s.extensions||{};const n={},r=l.eq;r(t.getOffset(),[0,0])||(n.offset=t.getOffset()),0!==t.getRotation()&&(n.rotation=t.getRotation()),r(t.getScale(),[1,1])||(n.scale=t.getScale()),null!=t.getTexCoord()&&(n.texCoord=t.getTexCoord()),s.extensions[zt]=n}return this}}$t.EXTENSION_NAME=zt;const qt=[t.ROOT,t.SCENE,t.NODE,t.MESH,t.MATERIAL,t.TEXTURE,t.ANIMATION];class Kt extends e{init(){this.extensionName=B,this.propertyType="Packet",this.parentTypes=qt}getDefaults(){return Object.assign(super.getDefaults(),{context:{},properties:{}})}getContext(){return this.get("context")}setContext(e){return this.set("context",P({},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=P({},this.get("properties"));return t?s[e]=t:delete s[e],this.set("properties",s)}toJSONLD(){return P({"@context":Yt(this.get("context"))},Yt(this.get("properties")))}fromJSONLD(e){const t=(e=Yt(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(`${B}: Missing context for term, "${e}".`)}}function Yt(e){return JSON.parse(JSON.stringify(e))}Kt.EXTENSION_NAME=B;const Qt=B;class Wt extends s{constructor(...e){super(...e),this.extensionName=Qt}createPacket(){return new Kt(this.document.getGraph())}listPackets(){return Array.from(this.properties)}read(e){var t;const s=null==(t=e.jsonDoc.json.extensions)?void 0:t[Qt];if(!s||!s.packets)return this;const n=e.jsonDoc.json,r=this.document.getRoot(),o=s.packets.map(e=>this.createPacket().fromJSONLD(e)),i=[[n.asset],n.scenes,n.nodes,n.meshes,n.materials,n.images,n.animations],a=[[r],r.listScenes(),r.listNodes(),r.listMeshes(),r.listMaterials(),r.listTextures(),r.listAnimations()];for(let e=0;e<i.length;e++){const t=i[e]||[];for(let s=0;s<t.length;s++){const n=t[s];n.extensions&&n.extensions[Qt]&&a[e][s].setExtension(Qt,o[n.extensions[Qt].packet])}}return this}write(e){const{json:s}=e.jsonDoc,n=[];for(const r of this.properties){n.push(r.toJSONLD());for(const o of r.listParents()){let r;switch(o.propertyType){case t.ROOT:r=s.asset;break;case t.SCENE:r=s.scenes[e.sceneIndexMap.get(o)];break;case t.NODE:r=s.nodes[e.nodeIndexMap.get(o)];break;case t.MESH:r=s.meshes[e.meshIndexMap.get(o)];break;case t.MATERIAL:r=s.materials[e.materialIndexMap.get(o)];break;case t.TEXTURE:r=s.images[e.imageIndexMap.get(o)];break;case t.ANIMATION:r=s.animations[e.animationIndexMap.get(o)];break;default:r=null,this.document.getLogger().warn(`[${Qt}]: Unsupported parent property, "${o.propertyType}"`)}r&&(r.extensions=r.extensions||{},r.extensions[Qt]={packet:n.length-1})}}return n.length>0&&(s.extensions=s.extensions||{},s.extensions[Qt]={packets:n}),this}}Wt.EXTENSION_NAME=Qt;const Jt=[Oe,be,Le,He,qe,Qe,tt,ct,Rt,xt,Ct,_t,jt,Lt,Ut,Xt,$t,Wt],Zt=[V,ne,ie,le,...Jt];export{Zt as ALL_EXTENSIONS,ke as Anisotropy,Pe as Clearcoat,V as EXTMeshGPUInstancing,ne as EXTMeshoptCompression,ie as EXTTextureAVIF,le as EXTTextureWebP,ze as EmissiveStrength,L as INSTANCE_ATTRIBUTE,Ke as IOR,G as InstancedMesh,Ze as Iridescence,Oe as KHRDracoMeshCompression,be as KHRLightsPunctual,Le as KHRMaterialsAnisotropy,He as KHRMaterialsClearcoat,qe as KHRMaterialsEmissiveStrength,Qe as KHRMaterialsIOR,tt as KHRMaterialsIridescence,ct as KHRMaterialsPBRSpecularGlossiness,xt as KHRMaterialsSheen,Rt as KHRMaterialsSpecular,Ct as KHRMaterialsTransmission,_t as KHRMaterialsUnlit,jt as KHRMaterialsVariants,Lt as KHRMaterialsVolume,Ut as KHRMeshQuantization,Jt as KHRONOS_EXTENSIONS,Xt as KHRTextureBasisu,$t as KHRTextureTransform,Wt as KHRXMP,De as Light,Dt as Mapping,wt as MappingList,it as PBRSpecularGlossiness,Kt as Packet,gt as Sheen,It as Specular,Ht as Transform,At as Transmission,Mt as Unlit,bt as Variant,kt as Volume}; | ||
import{ExtensionProperty as e,PropertyType as t,Extension as s,BufferUtils as n,WriterContext as r,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="EXT_mesh_gpu_instancing",N="EXT_meshopt_compression",R="KHR_draco_mesh_compression",y="KHR_lights_punctual",A="KHR_materials_anisotropy",S="KHR_materials_clearcoat",C="KHR_materials_emissive_strength",M="KHR_materials_ior",O="KHR_materials_iridescence",_="KHR_materials_pbrSpecularGlossiness",w="KHR_materials_sheen",D="KHR_materials_specular",b="KHR_materials_transmission",F="KHR_materials_unlit",j="KHR_materials_volume",v="KHR_materials_variants",k="KHR_texture_transform",B="KHR_xmp_json_ld",G="INSTANCE_ATTRIBUTE";class L extends e{init(){this.extensionName=I,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:G})}listAttributes(){return this.listRefMapValues("attributes")}listSemantics(){return this.listRefMapKeys("attributes")}}L.EXTENSION_NAME=I;const U=I;class V extends s{constructor(...e){super(...e),this.extensionName=U,this.provideTypes=[t.NODE],this.prewriteTypes=[t.ACCESSOR]}createInstancedMesh(){return new L(this.document.getGraph())}read(e){return(e.jsonDoc.json.nodes||[]).forEach((t,s)=>{if(!t.extensions||!t.extensions[U])return;const n=t.extensions[U],r=this.createInstancedMesh();for(const t in n.attributes)r.setAttribute(t,e.accessors[n.attributes[t]]);e.nodes[s].setExtension(U,r)}),this}prewrite(e){e.accessorUsageGroupedByParent.add(G);for(const t of this.properties)for(const s of t.listAttributes())e.addAccessorToUsageGroup(s,G);return this}write(e){const t=e.jsonDoc;return this.document.getRoot().listNodes().forEach(s=>{const n=s.getExtension(U);if(n){const r=e.nodeIndexMap.get(s),o=t.json.nodes[r],i={attributes:{}};n.listSemantics().forEach(t=>{const s=n.getAttribute(t);i.attributes[t]=e.accessorIndexMap.get(s)}),o.extensions=o.extensions||{},o.extensions[U]=i}}),this}}function P(){return P=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(e[n]=s[n])}return e},P.apply(this,arguments)}var X,H,z;V.EXTENSION_NAME=U,function(e){e.QUANTIZE="quantize",e.FILTER="filter"}(X||(X={})),function(e){e.ATTRIBUTES="ATTRIBUTES",e.TRIANGLES="TRIANGLES",e.INDICES="INDICES"}(H||(H={})),function(e){e.NONE="NONE",e.OCTAHEDRAL="OCTAHEDRAL",e.QUATERNION="QUATERNION",e.EXPONENTIAL="EXPONENTIAL"}(z||(z={}));const{BYTE:$,SHORT:q,FLOAT:K}=u.ComponentType,{encodeNormalizedInt:Y,decodeNormalizedInt:Q}=l;function W(e,t,s,r){const{filter:o,bits:i}=r,a={array:e.getArray(),byteStride:e.getElementSize()*e.getComponentSize(),componentType:e.getComponentType(),normalized:e.getNormalized()};if(s!==H.ATTRIBUTES)return a;if(o!==z.NONE){let s=e.getNormalized()?function(e){const t=e.getComponentType(),s=e.getArray(),n=new Float32Array(s.length);for(let e=0;e<s.length;e++)n[e]=Q(s[e],t);return n}(e):new Float32Array(a.array);switch(o){case z.EXPONENTIAL:a.byteStride=4*e.getElementSize(),a.componentType=K,a.normalized=!1,a.array=t.encodeFilterExp(s,e.getCount(),a.byteStride,i);break;case z.OCTAHEDRAL:a.byteStride=i>8?8:4,a.componentType=i>8?q:$,a.normalized=!0,s=3===e.getElementSize()?function(e){const t=new Float32Array(4*e.length/3);for(let s=0,n=e.length/3;s<n;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 z.QUATERNION:a.byteStride=8,a.componentType=q,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=>Q(t,e.getComponentType())),a.max=a.max.map(t=>Q(t,e.getComponentType()))),a.normalized&&(a.min=a.min.map(e=>Y(e,a.componentType)),a.max=a.max.map(e=>Y(e,a.componentType)))}else a.byteStride%4&&(a.array=function(e,t){const s=n.padNumber(e.BYTES_PER_ELEMENT*t)/e.BYTES_PER_ELEMENT,r=new e.constructor(e.length/t*s);for(let n=0;n*t<e.length;n++)for(let o=0;o<t;o++)r[n*s+o]=e[n*t+o];return r}(a.array,e.getElementSize()),a.byteStride=a.array.byteLength/e.getCount());return a}function J(e,t){return t===r.BufferViewUsage.ELEMENT_ARRAY_BUFFER?e.listParents().some(e=>e instanceof o&&e.getMode()===o.Mode.TRIANGLES)?H.TRIANGLES:H.INDICES:H.ATTRIBUTES}function Z(e,s){const n=s.getGraph().listParentEdges(e).filter(e=>!(e.getParent()instanceof i));for(const s of n){const n=s.getName(),r=s.getAttributes().key||"",o=s.getParent().propertyType===t.PRIMITIVE_TARGET;if("indices"===n)return{filter:z.NONE};if("attributes"===n){if("POSITION"===r)return{filter:z.NONE};if("TEXCOORD_0"===r)return{filter:z.NONE};if(r.startsWith("JOINTS_"))return{filter:z.NONE};if(r.startsWith("WEIGHTS_"))return{filter:z.NONE};if("NORMAL"===r||"TANGENT"===r)return o?{filter:z.NONE}:{filter:z.OCTAHEDRAL,bits:8}}if("output"===n){const t=ee(e);return"rotation"===t?{filter:z.QUATERNION,bits:16}:"translation"===t||"scale"===t?{filter:z.EXPONENTIAL,bits:12}:{filter:z.NONE}}if("input"===n)return{filter:z.NONE};if("inverseBindMatrices"===n)return{filter:z.NONE}}return{filter:z.NONE}}function ee(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 te=N,se={method:X.QUANTIZE};class ne extends s{constructor(...e){super(...e),this.extensionName=te,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=se,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=P({},se,e),this}preread(e,s){if(!this._decoder){if(!this.isRequired())return this;throw new Error(`[${te}] Please install extension dependency, "meshopt.decoder".`)}if(!this._decoder.supported){if(!this.isRequired())return this;throw new Error(`[${te}]: 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,r)=>{if(!s.extensions||!s.extensions[te])return;const o=s.extensions[te],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=n.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[r]=l})}_prereadPrimitives(e){const t=e.jsonDoc;(t.json.bufferViews||[]).forEach(s=>{var n;s.extensions&&s.extensions[te]&&(n=t.json.buffers[s.buffer]).extensions&&n.extensions[N]&&n.extensions[N].fallback&&this._decoderFallbackBufferMap.set(e.buffers[s.buffer],e.buffers[s.extensions[te].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,n=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"===ee(o))continue;if(o.getSparse())continue;const a=e.getAccessorUsage(o),c=J(o,a),u=n.method===X.FILTER?Z(o,this.document):{filter:z.NONE},l=W(o,s,c,u),{array:h,byteStride:f}=l,g=o.getBuffer();if(!g)throw new Error(`${te}: 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:r.USAGE_TO_TARGET[a],byteOffset:0,byteLength:0,byteStride:a===r.BufferViewUsage.ARRAY_BUFFER?f:void 0,extensions:{[te]:{buffer:p,byteOffset:0,byteLength:0,mode:c,filter:u.filter!==z.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 r=this._encoderBufferViews[s],o=this._encoderBufferViewData[s],i=this.document.getRoot().listBuffers()[r.extensions[te].buffer],a=e.otherBufferViews.get(i)||[],{count:c,byteStride:u,mode:l}=r.extensions[te],h=n.concat(o),f=t.encodeGltfBuffer(h,c,u,l),g=n.pad(f);r.extensions[te].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 r=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,r),a.byteOffset=t,a.extensions[te].byteOffset=c,t+=n.padNumber(r.byteLength)}const s=this._encoderFallbackBuffer,r=e.bufferIndexMap.get(s),o=e.jsonDoc.json.buffers[r];return o.byteLength=t,o.extensions={[te]:{fallback:!0}},s.dispose(),this}}ne.EXTENSION_NAME=te,ne.EncoderMethod=X;const re="EXT_texture_avif";class oe{match(e){return e.length>=12&&"ftypavif"===n.decodeText(e.slice(4,12))}getSize(e){if(!this.match(e))return null;const t=new DataView(e.buffer,e.byteOffset,e.byteLength);let s=ae(t,0);if(!s)return null;let n=s.end;for(;s=ae(t,n);)if("meta"===s.type)n=s.start+4;else if("iprp"===s.type||"ipco"===s.type)n=s.start;else{if("ispe"===s.type)return[t.getUint32(s.start+4),t.getUint32(s.start+8)];if("mdat"===s.type)break;n=s.end}return null}getChannels(e){return 4}}class ie extends s{constructor(...e){super(...e),this.extensionName=re,this.prereadTypes=[t.TEXTURE]}static register(){f.registerFormat("image/avif",new oe)}preread(e){return(e.jsonDoc.json.textures||[]).forEach(e=>{e.extensions&&e.extensions[re]&&(e.source=e.extensions[re].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 n=e.imageIndexMap.get(s);(t.json.textures||[]).forEach(e=>{e.source===n&&(e.extensions=e.extensions||{},e.extensions[re]={source:e.source},delete e.source)})}}),this}}function ae(e,t){if(e.byteLength<4+t)return null;const s=e.getUint32(t);return e.byteLength<s+t||s<8?null:{type:n.decodeText(new Uint8Array(e.buffer,e.byteOffset+t+4,4)),start:t+8,end:t+s}}ie.EXTENSION_NAME=re;const ce="EXT_texture_webp";class ue{match(e){return e.length>=12&&87===e[8]&&69===e[9]&&66===e[10]&&80===e[11]}getSize(e){const t=n.decodeText(e.slice(0,4)),s=n.decodeText(e.slice(8,12));if("RIFF"!==t||"WEBP"!==s)return null;const r=new DataView(e.buffer,e.byteOffset);let o=12;for(;o<r.byteLength;){const e=n.decodeText(new Uint8Array([r.getUint8(o),r.getUint8(o+1),r.getUint8(o+2),r.getUint8(o+3)])),t=r.getUint32(o+4,!0);if("VP8 "===e)return[16383&r.getInt16(o+14,!0),16383&r.getInt16(o+16,!0)];if("VP8L"===e){const e=r.getUint8(o+9),t=r.getUint8(o+10),s=r.getUint8(o+11);return[1+((63&t)<<8|e),1+((15&r.getUint8(o+12))<<10|s<<2|(192&t)>>6)]}o+=8+t+t%2}return null}getChannels(e){return 4}}class le extends s{constructor(...e){super(...e),this.extensionName=ce,this.prereadTypes=[t.TEXTURE]}static register(){f.registerFormat("image/webp",new ue)}preread(e){return(e.jsonDoc.json.textures||[]).forEach(e=>{e.extensions&&e.extensions[ce]&&(e.source=e.extensions[ce].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 n=e.imageIndexMap.get(s);(t.json.textures||[]).forEach(e=>{e.source===n&&(e.extensions=e.extensions||{},e.extensions[ce]={source:e.source},delete e.source)})}}),this}}le.EXTENSION_NAME=ce;const he=R;let fe,ge,pe,xe;function de(e,t){const s=new fe.DecoderBuffer;try{if(s.Init(t,t.length),e.GetEncodedGeometryType(s)!==fe.TRIANGULAR_MESH)throw new Error(`[${he}] Unknown geometry type.`);const n=new fe.Mesh;if(!e.DecodeBufferToMesh(s,n).ok()||0===n.ptr)throw new Error(`[${he}] Decoding failure.`);return n}finally{fe.destroy(s)}}function Te(e,t){const s=3*t.num_faces();let n,r;if(t.num_points()<=65534){const o=s*Uint16Array.BYTES_PER_ELEMENT;n=fe._malloc(o),e.GetTrianglesUInt16Array(t,o,n),r=new Uint16Array(fe.HEAPU16.buffer,n,s).slice()}else{const o=s*Uint32Array.BYTES_PER_ELEMENT;n=fe._malloc(o),e.GetTrianglesUInt32Array(t,o,n),r=new Uint32Array(fe.HEAPU32.buffer,n,s).slice()}return fe._free(n),r}function me(e,t,s,n){const r=pe[n.componentType],o=ge[n.componentType],i=s.num_components(),a=t.num_points()*i,c=a*o.BYTES_PER_ELEMENT,u=fe._malloc(c);e.GetAttributeDataArrayForAllPoints(t,s,r,c,u);const l=new o(fe.HEAPF32.buffer,u,a).slice();return fe._free(u),l}var Ee,Ie;!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"}(Ie||(Ie={}));const Ne={[Ie.POSITION]:14,[Ie.NORMAL]:10,[Ie.COLOR]:8,[Ie.TEX_COORD]:12,[Ie.GENERIC]:12},Re={decodeSpeed:5,encodeSpeed:5,method:Ee.EDGEBREAKER,quantizationBits:Ne,quantizationVolume:"mesh"};function ye(e,t=Re){const s=P({},Re,t);s.quantizationBits=P({},Ne,t.quantizationBits);const n=new xe.MeshBuilder,r=new xe.Mesh,o=new xe.ExpertEncoder(r),i={},a=new xe.DracoInt8Array,c=e.listTargets().length>0;let u=!1;for(const t of e.listSemantics()){const a=e.getAttribute(t);if(a.getSparse()){u=!0;continue}const c=Ae(t),l=Se(n,a.getComponentType(),r,xe[c],a.getCount(),a.getElementSize(),a.getArray());if(-1===l)throw new Error(`Error compressing "${t}" attribute.`);if(i[t]=l,"mesh"===s.quantizationVolume||"POSITION"!==t)o.SetAttributeQuantization(l,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]);o.SetAttributeExplicitQuantization(l,s.quantizationBits[c],a.getElementSize(),e.min,t)}}}const l=e.getIndices();if(!l)throw new Ce("Primitive must have indices.");n.AddFacesToMesh(r,l.getCount()/3,l.getArray()),o.SetSpeedOptions(s.encodeSpeed,s.decodeSpeed),o.SetTrackEncodedProperties(!0),o.SetEncodingMethod(s.method===Ee.SEQUENTIAL||c||u?xe.MESH_SEQUENTIAL_ENCODING:xe.MESH_EDGEBREAKER_ENCODING);const h=o.EncodeToDracoBuffer(!(c||u),a);if(h<=0)throw new Ce("Error applying Draco compression.");const f=new Uint8Array(h);for(let e=0;e<h;++e)f[e]=a.GetValue(e);const g=o.GetNumberOfEncodedPoints(),p=3*o.GetNumberOfEncodedFaces();return xe.destroy(a),xe.destroy(r),xe.destroy(n),xe.destroy(o),{numVertices:g,numIndices:p,data:f,attributeIDs:i}}function Ae(e){return"POSITION"===e?Ie.POSITION:"NORMAL"===e?Ie.NORMAL:e.startsWith("COLOR_")?Ie.COLOR:e.startsWith("TEXCOORD_")?Ie.TEX_COORD:Ie.GENERIC}function Se(e,t,s,n,r,o,i){switch(t){case u.ComponentType.UNSIGNED_BYTE:return e.AddUInt8Attribute(s,n,r,o,i);case u.ComponentType.BYTE:return e.AddInt8Attribute(s,n,r,o,i);case u.ComponentType.UNSIGNED_SHORT:return e.AddUInt16Attribute(s,n,r,o,i);case u.ComponentType.SHORT:return e.AddInt16Attribute(s,n,r,o,i);case u.ComponentType.UNSIGNED_INT:return e.AddUInt32Attribute(s,n,r,o,i);case u.ComponentType.FLOAT:return e.AddFloatAttribute(s,n,r,o,i);default:throw new Error(`Unexpected component type, "${t}".`)}}class Ce extends Error{}const Me=R;class Oe extends s{constructor(...e){super(...e),this.extensionName=Me,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,fe=this._decoderModule,ge={[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},pe={[u.ComponentType.FLOAT]:fe.DT_FLOAT32,[u.ComponentType.UNSIGNED_INT]:fe.DT_UINT32,[u.ComponentType.UNSIGNED_SHORT]:fe.DT_UINT16,[u.ComponentType.UNSIGNED_BYTE]:fe.DT_UINT8,[u.ComponentType.SHORT]:fe.DT_INT16,[u.ComponentType.BYTE]:fe.DT_INT8}),"draco3d.encoder"===e&&(this._encoderModule=t,xe=this._encoderModule),this}setEncoderOptions(e){return this._encoderOptions=e,this}preread(e){if(!this._decoderModule)throw new Error(`[${Me}] Please install extension dependency, "draco3d.decoder".`);const t=this.document.getLogger(),s=e.jsonDoc,r=new Map;try{const o=s.json.meshes||[];for(const i of o)for(const o of i.primitives){if(!o.extensions||!o.extensions[Me])continue;const i=o.extensions[Me];let[a,c]=r.get(i.bufferView)||[];if(!c||!a){const e=s.json.bufferViews[i.bufferView],o=s.json.buffers[e.buffer],u=n.toView(o.uri?s.resources[o.uri]:s.resources[h],e.byteOffset||0,e.byteLength);a=new this._decoderModule.Decoder,c=de(a,u),r.set(i.bufferView,[a,c]),t.debug(`[${Me}] Decompressed ${u.byteLength} bytes.`)}for(const t in o.attributes){const s=e.jsonDoc.json.accessors[o.attributes[t]],n=a.GetAttributeByUniqueId(c,i.attributes[t]),r=me(a,c,n,s);e.accessors[o.attributes[t]].setArray(r)}void 0!==o.indices&&e.accessors[o.indices].setArray(Te(a,c))}}finally{for(const[e,t]of Array.from(r.values()))this._decoderModule.destroy(e),this._decoderModule.destroy(t)}return this}read(e){return this}prewrite(e,s){if(!this._encoderModule)throw new Error(`[${Me}] Please install extension dependency, "draco3d.encoder".`);const n=this.document.getLogger();n.debug(`[${Me}] Compression options: ${JSON.stringify(this._encoderOptions)}`);const r=function(e){const s=e.getLogger(),n=new Set,r=new Set;for(const t of e.getRoot().listMeshes())for(const e of t.listPrimitives())e.getIndices()?e.getMode()!==o.Mode.TRIANGLES?(r.add(e),s.warn(`[${Me}] Skipping Draco compression on non-TRIANGLES primitive.`)):n.add(e):(r.add(e),s.warn(`[${Me}] 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(n)){let s=_e(t,a);if(u.has(s))l.set(t,s);else{if(c.has(t.getIndices())){const s=t.getIndices(),n=s.clone();a.set(n,e.getRoot().listAccessors().length-1),t.swap(s,n)}for(const s of t.listAttributes())if(c.has(s)){const n=s.clone();a.set(n,e.getRoot().listAccessors().length-1),t.swap(s,n)}s=_e(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(`[${Me}] Compressed accessors must only be used as indices or vertex attributes.`)}for(const e of Array.from(n)){const t=l.get(e),s=e.getIndices();if(c.get(s)!==t||e.listAttributes().some(e=>c.get(e)!==t))throw new Error(`[${Me}] Draco primitives must share all, or no, accessors.`)}for(const e of Array.from(r)){const t=e.getIndices();if(c.has(t)||e.listAttributes().some(e=>c.has(e)))throw new Error(`[${Me}] 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?n.warn(`[${Me}]: quantizationVolume=scene requires exactly 1 scene.`):a=g(this.document.getRoot().listScenes().pop()));for(const t of Array.from(r.keys())){const s=r.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=ye(t,P({},this._encoderOptions,{quantizationVolume:a}))}catch(e){if(e instanceof Ce){n.warn(`[${Me}]: ${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 n=t.getAttribute(s);if(void 0===u.attributeIDs[s])continue;const r=e.createAccessorDef(n);r.count=u.numVertices,e.accessorIndexMap.set(n,c.length),c.push(r)}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 n.debug(`[${Me}] Compressed ${r.size} primitives.`),e.extensionData[Me]={primitiveHashMap:r,primitiveEncodingMap:i},this}write(e){const t=e.extensionData[Me];for(const s of this.document.getRoot().listMeshes()){const n=e.jsonDoc.json.meshes[e.meshIndexMap.get(s)];for(let r=0;r<s.listPrimitives().length;r++){const o=s.listPrimitives()[r],i=n.primitives[r],a=t.primitiveHashMap.get(o);if(!a)continue;const c=t.primitiveEncodingMap.get(a);c&&(i.extensions=i.extensions||{},i.extensions[Me]={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!==Me),t.extensionsRequired=(t.extensionsRequired||[]).filter(e=>e!==Me)}return this}}function _e(e,t){const s=[],n=e.getIndices();s.push(t.get(n));for(const n of e.listAttributes())s.push(t.get(n));return s.sort().join("|")}Oe.EXTENSION_NAME=Me,Oe.EncoderMethod=Ee;class we extends e{init(){this.extensionName=y,this.propertyType="Light",this.parentTypes=[t.NODE]}getDefaults(){return Object.assign(super.getDefaults(),{color:[1,1,1],intensity:1,type:we.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)}}we.EXTENSION_NAME=y,we.Type={POINT:"point",SPOT:"spot",DIRECTIONAL:"directional"};const De=y;class be extends s{constructor(...e){super(...e),this.extensionName=De}createLight(e=""){return new we(this.document.getGraph(),e)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[De])return this;const s=(t.json.extensions[De].lights||[]).map(e=>{var t,s;const n=this.createLight().setName(e.name||"").setType(e.type);return void 0!==e.color&&n.setColor(e.color),void 0!==e.intensity&&n.setIntensity(e.intensity),void 0!==e.range&&n.setRange(e.range),void 0!==(null==(t=e.spot)?void 0:t.innerConeAngle)&&n.setInnerConeAngle(e.spot.innerConeAngle),void 0!==(null==(s=e.spot)?void 0:s.outerConeAngle)&&n.setOuterConeAngle(e.spot.outerConeAngle),n});return t.json.nodes.forEach((t,n)=>{t.extensions&&t.extensions[De]&&e.nodes[n].setExtension(De,s[t.extensions[De].light])}),this}write(e){const t=e.jsonDoc;if(0===this.properties.size)return this;const s=[],n=new Map;for(const e of this.properties){const t=e,r={type:t.getType()};l.eq(t.getColor(),[1,1,1])||(r.color=t.getColor()),1!==t.getIntensity()&&(r.intensity=t.getIntensity()),null!=t.getRange()&&(r.range=t.getRange()),t.getName()&&(r.name=t.getName()),t.getType()===we.Type.SPOT&&(r.spot={innerConeAngle:t.getInnerConeAngle(),outerConeAngle:t.getOuterConeAngle()}),s.push(r),n.set(t,s.length-1)}return this.document.getRoot().listNodes().forEach(s=>{const r=s.getExtension(De);if(r){const o=e.nodeIndexMap.get(s),i=t.json.nodes[o];i.extensions=i.extensions||{},i.extensions[De]={light:n.get(r)}}}),t.json.extensions=t.json.extensions||{},t.json.extensions[De]={lights:s},this}}be.EXTENSION_NAME=De;const{R:Fe,G:je,B:ve}=d;class ke extends e{init(){this.extensionName=A,this.propertyType="Anisotropy",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{anisotropyStrength:0,anisotropyRotation:0,anisotropyTexture:null,anisotropyTextureInfo:new x(this.graph,"anisotropyTextureInfo")})}getAnisotropyStrength(){return this.get("anisotropyStrength")}setAnisotropyStrength(e){return this.set("anisotropyStrength",e)}getAnisotropyRotation(){return this.get("anisotropyRotation")}setAnisotropyRotation(e){return this.set("anisotropyRotation",e)}getAnisotropyTexture(){return this.getRef("anisotropyTexture")}getAnisotropyTextureInfo(){return this.getRef("anisotropyTexture")?this.getRef("anisotropyTextureInfo"):null}setAnisotropyTexture(e){return this.setRef("anisotropyTexture",e,{channels:Fe|je|ve})}}ke.EXTENSION_NAME=A;const Be=A;class Ge extends s{constructor(...e){super(...e),this.extensionName=Be}createAnisotropy(){return new ke(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[Be]){const r=this.createAnisotropy();e.materials[n].setExtension(Be,r);const o=t.extensions[Be];if(void 0!==o.anisotropyStrength&&r.setAnisotropyStrength(o.anisotropyStrength),void 0!==o.anisotropyRotation&&r.setAnisotropyRotation(o.anisotropyRotation),void 0!==o.anisotropyTexture){const t=o.anisotropyTexture;r.setAnisotropyTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getAnisotropyTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(Be);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[Be]={};if(n.getAnisotropyStrength()>0&&(i.anisotropyStrength=n.getAnisotropyStrength()),0!==n.getAnisotropyRotation()&&(i.anisotropyRotation=n.getAnisotropyRotation()),n.getAnisotropyTexture()){const t=n.getAnisotropyTexture(),s=n.getAnisotropyTextureInfo();i.anisotropyTexture=e.createTextureInfoDef(t,s)}}}),this}}Ge.EXTENSION_NAME=Be;const{R:Le,G:Ue,B:Ve}=d;class Pe extends e{init(){this.extensionName=S,this.propertyType="Clearcoat",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{clearcoatFactor:0,clearcoatTexture:null,clearcoatTextureInfo:new x(this.graph,"clearcoatTextureInfo"),clearcoatRoughnessFactor:0,clearcoatRoughnessTexture:null,clearcoatRoughnessTextureInfo:new x(this.graph,"clearcoatRoughnessTextureInfo"),clearcoatNormalScale:1,clearcoatNormalTexture:null,clearcoatNormalTextureInfo:new x(this.graph,"clearcoatNormalTextureInfo")})}getClearcoatFactor(){return this.get("clearcoatFactor")}setClearcoatFactor(e){return this.set("clearcoatFactor",e)}getClearcoatTexture(){return this.getRef("clearcoatTexture")}getClearcoatTextureInfo(){return this.getRef("clearcoatTexture")?this.getRef("clearcoatTextureInfo"):null}setClearcoatTexture(e){return this.setRef("clearcoatTexture",e,{channels:Le})}getClearcoatRoughnessFactor(){return this.get("clearcoatRoughnessFactor")}setClearcoatRoughnessFactor(e){return this.set("clearcoatRoughnessFactor",e)}getClearcoatRoughnessTexture(){return this.getRef("clearcoatRoughnessTexture")}getClearcoatRoughnessTextureInfo(){return this.getRef("clearcoatRoughnessTexture")?this.getRef("clearcoatRoughnessTextureInfo"):null}setClearcoatRoughnessTexture(e){return this.setRef("clearcoatRoughnessTexture",e,{channels:Ue})}getClearcoatNormalScale(){return this.get("clearcoatNormalScale")}setClearcoatNormalScale(e){return this.set("clearcoatNormalScale",e)}getClearcoatNormalTexture(){return this.getRef("clearcoatNormalTexture")}getClearcoatNormalTextureInfo(){return this.getRef("clearcoatNormalTexture")?this.getRef("clearcoatNormalTextureInfo"):null}setClearcoatNormalTexture(e){return this.setRef("clearcoatNormalTexture",e,{channels:Le|Ue|Ve})}}Pe.EXTENSION_NAME=S;const Xe=S;class He 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,n)=>{if(t.extensions&&t.extensions[Xe]){const r=this.createClearcoat();e.materials[n].setExtension(Xe,r);const o=t.extensions[Xe];if(void 0!==o.clearcoatFactor&&r.setClearcoatFactor(o.clearcoatFactor),void 0!==o.clearcoatRoughnessFactor&&r.setClearcoatRoughnessFactor(o.clearcoatRoughnessFactor),void 0!==o.clearcoatTexture){const t=o.clearcoatTexture;r.setClearcoatTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getClearcoatTextureInfo(),t)}if(void 0!==o.clearcoatRoughnessTexture){const t=o.clearcoatRoughnessTexture;r.setClearcoatRoughnessTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getClearcoatRoughnessTextureInfo(),t)}if(void 0!==o.clearcoatNormalTexture){const t=o.clearcoatNormalTexture;r.setClearcoatNormalTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getClearcoatNormalTextureInfo(),t),void 0!==t.scale&&r.setClearcoatNormalScale(t.scale)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(Xe);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[Xe]={clearcoatFactor:n.getClearcoatFactor(),clearcoatRoughnessFactor:n.getClearcoatRoughnessFactor()};if(n.getClearcoatTexture()){const t=n.getClearcoatTexture(),s=n.getClearcoatTextureInfo();i.clearcoatTexture=e.createTextureInfoDef(t,s)}if(n.getClearcoatRoughnessTexture()){const t=n.getClearcoatRoughnessTexture(),s=n.getClearcoatRoughnessTextureInfo();i.clearcoatRoughnessTexture=e.createTextureInfoDef(t,s)}if(n.getClearcoatNormalTexture()){const t=n.getClearcoatNormalTexture(),s=n.getClearcoatNormalTextureInfo();i.clearcoatNormalTexture=e.createTextureInfoDef(t,s),1!==n.getClearcoatNormalScale()&&(i.clearcoatNormalTexture.scale=n.getClearcoatNormalScale())}}}),this}}He.EXTENSION_NAME=Xe;class ze extends e{init(){this.extensionName=C,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)}}ze.EXTENSION_NAME=C;const $e=C;class qe extends s{constructor(...e){super(...e),this.extensionName=$e}createEmissiveStrength(){return new ze(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[$e]){const n=this.createEmissiveStrength();e.materials[s].setExtension($e,n);const r=t.extensions[$e];void 0!==r.emissiveStrength&&n.setEmissiveStrength(r.emissiveStrength)}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension($e);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{},o.extensions[$e]={emissiveStrength:n.getEmissiveStrength()}}}),this}}qe.EXTENSION_NAME=$e;class Ke extends e{init(){this.extensionName=M,this.propertyType="IOR",this.parentTypes=[t.MATERIAL]}getDefaults(){return Object.assign(super.getDefaults(),{ior:1.5})}getIOR(){return this.get("ior")}setIOR(e){return this.set("ior",e)}}Ke.EXTENSION_NAME=M;const Ye=M;class Qe extends s{constructor(...e){super(...e),this.extensionName=Ye}createIOR(){return new Ke(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{if(t.extensions&&t.extensions[Ye]){const n=this.createIOR();e.materials[s].setExtension(Ye,n);const r=t.extensions[Ye];void 0!==r.ior&&n.setIOR(r.ior)}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(Ye);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{},o.extensions[Ye]={ior:n.getIOR()}}}),this}}Qe.EXTENSION_NAME=Ye;const{R:We,G:Je}=d;class Ze extends e{init(){this.extensionName=O,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:We})}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:Je})}}Ze.EXTENSION_NAME=O;const et=O;class tt extends s{constructor(...e){super(...e),this.extensionName=et}createIridescence(){return new Ze(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[et]){const r=this.createIridescence();e.materials[n].setExtension(et,r);const o=t.extensions[et];if(void 0!==o.iridescenceFactor&&r.setIridescenceFactor(o.iridescenceFactor),void 0!==o.iridescenceIor&&r.setIridescenceIOR(o.iridescenceIor),void 0!==o.iridescenceThicknessMinimum&&r.setIridescenceThicknessMinimum(o.iridescenceThicknessMinimum),void 0!==o.iridescenceThicknessMaximum&&r.setIridescenceThicknessMaximum(o.iridescenceThicknessMaximum),void 0!==o.iridescenceTexture){const t=o.iridescenceTexture;r.setIridescenceTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getIridescenceTextureInfo(),t)}if(void 0!==o.iridescenceThicknessTexture){const t=o.iridescenceThicknessTexture;r.setIridescenceThicknessTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getIridescenceThicknessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(et);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[et]={};if(n.getIridescenceFactor()>0&&(i.iridescenceFactor=n.getIridescenceFactor()),1.3!==n.getIridescenceIOR()&&(i.iridescenceIor=n.getIridescenceIOR()),100!==n.getIridescenceThicknessMinimum()&&(i.iridescenceThicknessMinimum=n.getIridescenceThicknessMinimum()),400!==n.getIridescenceThicknessMaximum()&&(i.iridescenceThicknessMaximum=n.getIridescenceThicknessMaximum()),n.getIridescenceTexture()){const t=n.getIridescenceTexture(),s=n.getIridescenceTextureInfo();i.iridescenceTexture=e.createTextureInfoDef(t,s)}if(n.getIridescenceThicknessTexture()){const t=n.getIridescenceThicknessTexture(),s=n.getIridescenceThicknessTextureInfo();i.iridescenceThicknessTexture=e.createTextureInfoDef(t,s)}}}),this}}tt.EXTENSION_NAME=et;const{R:st,G:nt,B:rt,A:ot}=d;class it extends e{init(){this.extensionName=_,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:st|nt|rt|ot,isColor:!0})}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:st|nt|rt|ot})}}it.EXTENSION_NAME=_;const at=_;class ct extends s{constructor(...e){super(...e),this.extensionName=at}createPBRSpecularGlossiness(){return new it(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[at]){const r=this.createPBRSpecularGlossiness();e.materials[n].setExtension(at,r);const o=t.extensions[at];if(void 0!==o.diffuseFactor&&r.setDiffuseFactor(o.diffuseFactor),void 0!==o.specularFactor&&r.setSpecularFactor(o.specularFactor),void 0!==o.glossinessFactor&&r.setGlossinessFactor(o.glossinessFactor),void 0!==o.diffuseTexture){const t=o.diffuseTexture;r.setDiffuseTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getDiffuseTextureInfo(),t)}if(void 0!==o.specularGlossinessTexture){const t=o.specularGlossinessTexture;r.setSpecularGlossinessTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getSpecularGlossinessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(at);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[at]={diffuseFactor:n.getDiffuseFactor(),specularFactor:n.getSpecularFactor(),glossinessFactor:n.getGlossinessFactor()};if(n.getDiffuseTexture()){const t=n.getDiffuseTexture(),s=n.getDiffuseTextureInfo();i.diffuseTexture=e.createTextureInfoDef(t,s)}if(n.getSpecularGlossinessTexture()){const t=n.getSpecularGlossinessTexture(),s=n.getSpecularGlossinessTextureInfo();i.specularGlossinessTexture=e.createTextureInfoDef(t,s)}}}),this}}ct.EXTENSION_NAME=at;const{R:ut,G:lt,B:ht,A:ft}=d;class gt extends e{init(){this.extensionName=w,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:ut|lt|ht,isColor:!0})}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:ft})}}gt.EXTENSION_NAME=w;const pt=w;class xt extends s{constructor(...e){super(...e),this.extensionName=pt}createSheen(){return new gt(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[pt]){const r=this.createSheen();e.materials[n].setExtension(pt,r);const o=t.extensions[pt];if(void 0!==o.sheenColorFactor&&r.setSheenColorFactor(o.sheenColorFactor),void 0!==o.sheenRoughnessFactor&&r.setSheenRoughnessFactor(o.sheenRoughnessFactor),void 0!==o.sheenColorTexture){const t=o.sheenColorTexture;r.setSheenColorTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getSheenColorTextureInfo(),t)}if(void 0!==o.sheenRoughnessTexture){const t=o.sheenRoughnessTexture;r.setSheenRoughnessTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getSheenRoughnessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(pt);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[pt]={sheenColorFactor:n.getSheenColorFactor(),sheenRoughnessFactor:n.getSheenRoughnessFactor()};if(n.getSheenColorTexture()){const t=n.getSheenColorTexture(),s=n.getSheenColorTextureInfo();i.sheenColorTexture=e.createTextureInfoDef(t,s)}if(n.getSheenRoughnessTexture()){const t=n.getSheenRoughnessTexture(),s=n.getSheenRoughnessTextureInfo();i.sheenRoughnessTexture=e.createTextureInfoDef(t,s)}}}),this}}xt.EXTENSION_NAME=pt;const{R:dt,G:Tt,B:mt,A:Et}=d;class It extends e{init(){this.extensionName=D,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:Et})}getSpecularColorTexture(){return this.getRef("specularColorTexture")}getSpecularColorTextureInfo(){return this.getRef("specularColorTexture")?this.getRef("specularColorTextureInfo"):null}setSpecularColorTexture(e){return this.setRef("specularColorTexture",e,{channels:dt|Tt|mt,isColor:!0})}}It.EXTENSION_NAME=D;const Nt=D;class Rt extends s{constructor(...e){super(...e),this.extensionName=Nt}createSpecular(){return new It(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[Nt]){const r=this.createSpecular();e.materials[n].setExtension(Nt,r);const o=t.extensions[Nt];if(void 0!==o.specularFactor&&r.setSpecularFactor(o.specularFactor),void 0!==o.specularColorFactor&&r.setSpecularColorFactor(o.specularColorFactor),void 0!==o.specularTexture){const t=o.specularTexture;r.setSpecularTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getSpecularTextureInfo(),t)}if(void 0!==o.specularColorTexture){const t=o.specularColorTexture;r.setSpecularColorTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getSpecularColorTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(Nt);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[Nt]={};if(1!==n.getSpecularFactor()&&(i.specularFactor=n.getSpecularFactor()),l.eq(n.getSpecularColorFactor(),[1,1,1])||(i.specularColorFactor=n.getSpecularColorFactor()),n.getSpecularTexture()){const t=n.getSpecularTexture(),s=n.getSpecularTextureInfo();i.specularTexture=e.createTextureInfoDef(t,s)}if(n.getSpecularColorTexture()){const t=n.getSpecularColorTexture(),s=n.getSpecularColorTextureInfo();i.specularColorTexture=e.createTextureInfoDef(t,s)}}}),this}}Rt.EXTENSION_NAME=Nt;const{R:yt}=d;class At extends e{init(){this.extensionName=b,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:yt})}}At.EXTENSION_NAME=b;const St=b;class Ct extends s{constructor(...e){super(...e),this.extensionName=St}createTransmission(){return new At(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[St]){const r=this.createTransmission();e.materials[n].setExtension(St,r);const o=t.extensions[St];if(void 0!==o.transmissionFactor&&r.setTransmissionFactor(o.transmissionFactor),void 0!==o.transmissionTexture){const t=o.transmissionTexture;r.setTransmissionTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getTransmissionTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(St);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[St]={transmissionFactor:n.getTransmissionFactor()};if(n.getTransmissionTexture()){const t=n.getTransmissionTexture(),s=n.getTransmissionTextureInfo();i.transmissionTexture=e.createTextureInfoDef(t,s)}}}),this}}Ct.EXTENSION_NAME=St;class Mt extends e{init(){this.extensionName=F,this.propertyType="Unlit",this.parentTypes=[t.MATERIAL]}}Mt.EXTENSION_NAME=F;const Ot=F;class _t extends s{constructor(...e){super(...e),this.extensionName=Ot}createUnlit(){return new Mt(this.document.getGraph())}read(e){return(e.jsonDoc.json.materials||[]).forEach((t,s)=>{t.extensions&&t.extensions[Ot]&&e.materials[s].setExtension(Ot,this.createUnlit())}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{if(s.getExtension(Ot)){const n=e.materialIndexMap.get(s),r=t.json.materials[n];r.extensions=r.extensions||{},r.extensions[Ot]={}}}),this}}_t.EXTENSION_NAME=Ot;class wt extends e{init(){this.extensionName=v,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")}}wt.EXTENSION_NAME=v;class Dt extends e{init(){this.extensionName=v,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")}}Dt.EXTENSION_NAME=v;class bt extends e{init(){this.extensionName=v,this.propertyType="Variant",this.parentTypes=["MappingList"]}}bt.EXTENSION_NAME=v;const Ft=v;class jt extends s{constructor(...e){super(...e),this.extensionName=Ft}createMappingList(){return new Dt(this.document.getGraph())}createVariant(e=""){return new bt(this.document.getGraph(),e)}createMapping(){return new wt(this.document.getGraph())}listVariants(){return Array.from(this.properties).filter(e=>e instanceof bt)}read(e){const t=e.jsonDoc;if(!t.json.extensions||!t.json.extensions[Ft])return this;const s=(t.json.extensions[Ft].variants||[]).map(e=>this.createVariant().setName(e.name||""));return(t.json.meshes||[]).forEach((t,n)=>{const r=e.meshes[n];(t.primitives||[]).forEach((t,n)=>{if(!t.extensions||!t.extensions[Ft])return;const o=this.createMappingList(),i=t.extensions[Ft];for(const t of i.mappings){const n=this.createMapping();void 0!==t.material&&n.setMaterial(e.materials[t.material]);for(const e of t.variants||[])n.addVariant(s[e]);o.addMapping(n)}r.listPrimitives()[n].setExtension(Ft,o)})}),this}write(e){const t=e.jsonDoc,s=this.listVariants();if(!s.length)return this;const n=[],r=new Map;for(const t of s)r.set(t,n.length),n.push(e.createPropertyDef(t));for(const t of this.document.getRoot().listMeshes()){const s=e.meshIndexMap.get(t);t.listPrimitives().forEach((t,n)=>{const o=t.getExtension(Ft);if(!o)return;const i=e.jsonDoc.json.meshes[s].primitives[n],a=o.listMappings().map(t=>{const s=e.createPropertyDef(t),n=t.getMaterial();return n&&(s.material=e.materialIndexMap.get(n)),s.variants=t.listVariants().map(e=>r.get(e)),s});i.extensions=i.extensions||{},i.extensions[Ft]={mappings:a}})}return t.json.extensions=t.json.extensions||{},t.json.extensions[Ft]={variants:n},this}}jt.EXTENSION_NAME=Ft;const{G:vt}=d;class kt extends e{init(){this.extensionName=j,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:vt})}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))}}kt.EXTENSION_NAME=j;const Bt=j;class Gt extends s{constructor(...e){super(...e),this.extensionName=Bt}createVolume(){return new kt(this.document.getGraph())}read(e){const t=e.jsonDoc,s=t.json.textures||[];return(t.json.materials||[]).forEach((t,n)=>{if(t.extensions&&t.extensions[Bt]){const r=this.createVolume();e.materials[n].setExtension(Bt,r);const o=t.extensions[Bt];if(void 0!==o.thicknessFactor&&r.setThicknessFactor(o.thicknessFactor),void 0!==o.attenuationDistance&&r.setAttenuationDistance(o.attenuationDistance),void 0!==o.attenuationColor&&r.setAttenuationColor(o.attenuationColor),void 0!==o.thicknessTexture){const t=o.thicknessTexture;r.setThicknessTexture(e.textures[s[t.index].source]),e.setTextureInfo(r.getThicknessTextureInfo(),t)}}}),this}write(e){const t=e.jsonDoc;return this.document.getRoot().listMaterials().forEach(s=>{const n=s.getExtension(Bt);if(n){const r=e.materialIndexMap.get(s),o=t.json.materials[r];o.extensions=o.extensions||{};const i=o.extensions[Bt]={};if(n.getThicknessFactor()>0&&(i.thicknessFactor=n.getThicknessFactor()),Number.isFinite(n.getAttenuationDistance())&&(i.attenuationDistance=n.getAttenuationDistance()),l.eq(n.getAttenuationColor(),[1,1,1])||(i.attenuationColor=n.getAttenuationColor()),n.getThicknessTexture()){const t=n.getThicknessTexture(),s=n.getThicknessTextureInfo();i.thicknessTexture=e.createTextureInfoDef(t,s)}}}),this}}Gt.EXTENSION_NAME=Bt;const Lt="KHR_mesh_quantization";class Ut extends s{constructor(...e){super(...e),this.extensionName=Lt}read(e){return this}write(e){return this}}Ut.EXTENSION_NAME=Lt;const Vt="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}".`)}getVRAMByteLength(e){const t=T(e),s=this.getChannels(e)>3;let n=0;for(let e=0;e<t.levels.length;e++){const r=t.levels[e];n+=r.uncompressedByteLength?r.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 n}}class Xt extends s{constructor(...e){super(...e),this.extensionName=Vt,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[Vt]&&(e.source=e.extensions[Vt].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 n=e.imageIndexMap.get(s);t.json.textures.forEach(e=>{e.source===n&&(e.extensions=e.extensions||{},e.extensions[Vt]={source:e.source},delete e.source)})}}),this}}Xt.EXTENSION_NAME=Vt;class Ht extends e{init(){this.extensionName=k,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)}}Ht.EXTENSION_NAME=k;const zt=k;class $t extends s{constructor(...e){super(...e),this.extensionName=zt}createTransform(){return new Ht(this.document.getGraph())}read(e){for(const[t,s]of Array.from(e.textureInfos.entries())){if(!s.extensions||!s.extensions[zt])continue;const e=this.createTransform(),n=s.extensions[zt];void 0!==n.offset&&e.setOffset(n.offset),void 0!==n.rotation&&e.setRotation(n.rotation),void 0!==n.scale&&e.setScale(n.scale),void 0!==n.texCoord&&e.setTexCoord(n.texCoord),t.setExtension(zt,e)}return this}write(e){const t=Array.from(e.textureInfoDefMap.entries());for(const[e,s]of t){const t=e.getExtension(zt);if(!t)continue;s.extensions=s.extensions||{};const n={},r=l.eq;r(t.getOffset(),[0,0])||(n.offset=t.getOffset()),0!==t.getRotation()&&(n.rotation=t.getRotation()),r(t.getScale(),[1,1])||(n.scale=t.getScale()),null!=t.getTexCoord()&&(n.texCoord=t.getTexCoord()),s.extensions[zt]=n}return this}}$t.EXTENSION_NAME=zt;const qt=[t.ROOT,t.SCENE,t.NODE,t.MESH,t.MATERIAL,t.TEXTURE,t.ANIMATION];class Kt extends e{init(){this.extensionName=B,this.propertyType="Packet",this.parentTypes=qt}getDefaults(){return Object.assign(super.getDefaults(),{context:{},properties:{}})}getContext(){return this.get("context")}setContext(e){return this.set("context",P({},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=P({},this.get("properties"));return t?s[e]=t:delete s[e],this.set("properties",s)}toJSONLD(){return P({"@context":Yt(this.get("context"))},Yt(this.get("properties")))}fromJSONLD(e){const t=(e=Yt(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(`${B}: Missing context for term, "${e}".`)}}function Yt(e){return JSON.parse(JSON.stringify(e))}Kt.EXTENSION_NAME=B;const Qt=B;class Wt extends s{constructor(...e){super(...e),this.extensionName=Qt}createPacket(){return new Kt(this.document.getGraph())}listPackets(){return Array.from(this.properties)}read(e){var t;const s=null==(t=e.jsonDoc.json.extensions)?void 0:t[Qt];if(!s||!s.packets)return this;const n=e.jsonDoc.json,r=this.document.getRoot(),o=s.packets.map(e=>this.createPacket().fromJSONLD(e)),i=[[n.asset],n.scenes,n.nodes,n.meshes,n.materials,n.images,n.animations],a=[[r],r.listScenes(),r.listNodes(),r.listMeshes(),r.listMaterials(),r.listTextures(),r.listAnimations()];for(let e=0;e<i.length;e++){const t=i[e]||[];for(let s=0;s<t.length;s++){const n=t[s];n.extensions&&n.extensions[Qt]&&a[e][s].setExtension(Qt,o[n.extensions[Qt].packet])}}return this}write(e){const{json:s}=e.jsonDoc,n=[];for(const r of this.properties){n.push(r.toJSONLD());for(const o of r.listParents()){let r;switch(o.propertyType){case t.ROOT:r=s.asset;break;case t.SCENE:r=s.scenes[e.sceneIndexMap.get(o)];break;case t.NODE:r=s.nodes[e.nodeIndexMap.get(o)];break;case t.MESH:r=s.meshes[e.meshIndexMap.get(o)];break;case t.MATERIAL:r=s.materials[e.materialIndexMap.get(o)];break;case t.TEXTURE:r=s.images[e.imageIndexMap.get(o)];break;case t.ANIMATION:r=s.animations[e.animationIndexMap.get(o)];break;default:r=null,this.document.getLogger().warn(`[${Qt}]: Unsupported parent property, "${o.propertyType}"`)}r&&(r.extensions=r.extensions||{},r.extensions[Qt]={packet:n.length-1})}}return n.length>0&&(s.extensions=s.extensions||{},s.extensions[Qt]={packets:n}),this}}Wt.EXTENSION_NAME=Qt;const Jt=[Oe,be,Ge,He,qe,Qe,tt,ct,Rt,xt,Ct,_t,jt,Gt,Ut,Xt,$t,Wt],Zt=[V,ne,ie,le,...Jt];export{Zt as ALL_EXTENSIONS,ke as Anisotropy,Pe as Clearcoat,V as EXTMeshGPUInstancing,ne as EXTMeshoptCompression,ie as EXTTextureAVIF,le as EXTTextureWebP,ze as EmissiveStrength,G as INSTANCE_ATTRIBUTE,Ke as IOR,L as InstancedMesh,Ze as Iridescence,Oe as KHRDracoMeshCompression,be as KHRLightsPunctual,Ge as KHRMaterialsAnisotropy,He as KHRMaterialsClearcoat,qe as KHRMaterialsEmissiveStrength,Qe as KHRMaterialsIOR,tt as KHRMaterialsIridescence,ct as KHRMaterialsPBRSpecularGlossiness,xt as KHRMaterialsSheen,Rt as KHRMaterialsSpecular,Ct as KHRMaterialsTransmission,_t as KHRMaterialsUnlit,jt as KHRMaterialsVariants,Gt as KHRMaterialsVolume,Ut as KHRMeshQuantization,Jt as KHRONOS_EXTENSIONS,Xt as KHRTextureBasisu,$t as KHRTextureTransform,Wt as KHRXMP,we as Light,wt as Mapping,Dt as MappingList,it as PBRSpecularGlossiness,Kt as Packet,gt as Sheen,It as Specular,Ht as Transform,At as Transmission,Mt as Unlit,bt as Variant,kt as Volume}; | ||
//# sourceMappingURL=extensions.modern.js.map |
{ | ||
"name": "@gltf-transform/extensions", | ||
"version": "3.7.5", | ||
"version": "3.8.0", | ||
"repository": "github:donmccurdy/glTF-Transform", | ||
@@ -39,3 +39,3 @@ "homepage": "https://gltf-transform.dev/extensions.html", | ||
"dependencies": { | ||
"@gltf-transform/core": "^3.7.5", | ||
"@gltf-transform/core": "^3.8.0", | ||
"ktx-parse": "^0.6.0" | ||
@@ -49,3 +49,3 @@ }, | ||
], | ||
"gitHead": "bf05150bcaa3df7add9c86ba8ffaffae3fdd94a7" | ||
"gitHead": "94ea01f4c998c85cb25d56a057f7326d36a81786" | ||
} |
@@ -19,5 +19,9 @@ import type { GLTF, TypedArray } from '@gltf-transform/core'; | ||
export enum MeshoptFilter { | ||
/** No filter — quantize only. */ | ||
NONE = 'NONE', | ||
/** Four 8- or 16-bit normalized values. */ | ||
OCTAHEDRAL = 'OCTAHEDRAL', | ||
/** Four 16-bit normalized values. */ | ||
QUATERNION = 'QUATERNION', | ||
/** K single-precision floating point values. */ | ||
EXPONENTIAL = 'EXPONENTIAL', | ||
@@ -24,0 +28,0 @@ } |
@@ -11,2 +11,3 @@ import { PreparedAccessor, MeshoptFilter, MeshoptMode } from './constants.js'; | ||
Primitive, | ||
PropertyType, | ||
Root, | ||
@@ -27,3 +28,3 @@ TypedArray, | ||
mode: MeshoptMode, | ||
filterOptions: { filter: MeshoptFilter; bits?: number } | ||
filterOptions: { filter: MeshoptFilter; bits?: number }, | ||
): PreparedAccessor { | ||
@@ -41,3 +42,3 @@ const { filter, bits } = filterOptions as { filter: MeshoptFilter; bits: number }; | ||
if (filter !== MeshoptFilter.NONE) { | ||
let array = accessor.getNormalized() ? denormalizeArray(accessor) : new Float32Array(result.array); | ||
let array = accessor.getNormalized() ? decodeNormalizedIntArray(accessor) : new Float32Array(result.array); | ||
@@ -89,3 +90,3 @@ switch (filter) { | ||
function denormalizeArray(attribute: Accessor): Float32Array { | ||
function decodeNormalizedIntArray(attribute: Accessor): Float32Array { | ||
const componentType = attribute.getComponentType(); | ||
@@ -148,2 +149,3 @@ const srcArray = attribute.getArray()!; | ||
const refKey = (ref.getAttributes().key || '') as string; | ||
const isDelta = ref.getParent().propertyType === PropertyType.PRIMITIVE_TARGET; | ||
@@ -161,9 +163,13 @@ // Indices. | ||
// quantization for these attributes. | ||
// - NORMAL and TANGENT attributes use Octahedral filters, but deltas in morphs do not. | ||
// - When specifying bit depth for vertex attributes, check the defaults in `quantize.ts` | ||
// and overrides in `meshopt.ts`. Don't store deltas at higher precision than base. | ||
if (refName === 'attributes') { | ||
if (refKey === 'POSITION') return { filter: MeshoptFilter.NONE }; | ||
if (refKey === 'TEXCOORD_0') return { filter: MeshoptFilter.NONE }; | ||
if (refKey === 'NORMAL') return { filter: MeshoptFilter.OCTAHEDRAL, bits: 8 }; | ||
if (refKey === 'TANGENT') return { filter: MeshoptFilter.OCTAHEDRAL, bits: 8 }; | ||
if (refKey.startsWith('JOINTS_')) return { filter: MeshoptFilter.NONE }; | ||
if (refKey.startsWith('WEIGHTS_')) return { filter: MeshoptFilter.NONE }; | ||
if (refKey === 'NORMAL' || refKey === 'TANGENT') { | ||
return isDelta ? { filter: MeshoptFilter.NONE } : { filter: MeshoptFilter.OCTAHEDRAL, bits: 8 }; | ||
} | ||
} | ||
@@ -170,0 +176,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1114716
8506
Updated@gltf-transform/core@^3.8.0