Files
fad_oa/ruoyi-ui/public/file-viewer/assets/USDLoader-BovI5HgZ.js
王文昊 d53ac1db32 build(ruoyi-ui): 新增文件预览依赖包并更新依赖版本
- 新增了完整的文件预览器前端资源包,包含各类文件格式的解析、渲染依赖
- 更新@openim/wasm-client-sdk依赖版本为宽松匹配
- 删除了旧的紧急联系人菜单清理SQL脚本
2026-07-04 19:15:06 +08:00

6 lines
64 KiB
JavaScript

import{$ as e,At as t,Bt as n,C as r,Ct as i,Dt as a,E as o,Et as s,Ht as c,K as l,Mt as u,Ot as d,Pt as f,S as p,St as m,bt as h,c as g,d as _,dt as v,et as y,f as b,ft as x,h as S,ht as C,it as w,l as T,o as E,ot as D,p as O,pt as k,r as A,u as j,v as M,wt as N,x as P,yt as F,zt as I}from"./three.module-BFsVh7r1.js";import{t as L}from"./fflate.module-BIQmJeC9.js";var R=/^def\s+(?:(\w+)\s+)?"?([^"]+)"?$/,z=/^string\s+(\w+)$/,B=/^(?:uniform\s+)?(\w+(?:\[\])?)\s+(.+)$/,V=class{parseText(e){e=this._preprocess(e);let t={},n=e.split(`
`),r=null,i=t,a=[t];for(let e of n)if(e.includes(`=`)){let t=this._findAssignmentOperator(e);if(t===-1){r=e.trim();continue}let n=e.slice(0,t).trim(),o=e.slice(t+1).trim();if(o.endsWith(`{`)){let e={};a.push(e),i[n]=e,i=e}else if(o.endsWith(`(`)){let e=o.slice(0,-1);i[n]=e;let t={};a.push(t),i=t}else i[n]=o}else if(e.includes(`:`)&&!e.includes(`=`)){let t=e.indexOf(`:`),n=e.slice(0,t).trim(),r=e.slice(t+1).trim();/^[\d.]+$/.test(n)&&(i[n]=r)}else if(e.endsWith(`{`)){let e=i[r]||{};a.push(e),i[r]=e,i=e}else if(e.endsWith(`}`)){if(a.pop(),a.length===0)continue;i=a[a.length-1]}else if(e.endsWith(`(`)){let t={};a.push(t),r=e.split(`(`)[0].trim()||r,i[r]=t,i=t}else e.endsWith(`)`)?(a.pop(),i=a[a.length-1]):e.trim()&&(r=e.trim());return t}_preprocess(e){e=this._stripBlockComments(e),e=this._collapseTripleQuotedStrings(e);let t=e.split(`
`),n=[],r=!1,i=0,a=0,o=``;for(let e=0;e<t.length;e++){let s=t[e];s=this._stripInlineComment(s);let c=s.trim();if(r){o+=` `+c;for(let e of c)e===`[`?i++:e===`]`?i--:e===`(`&&i>0?a++:e===`)`&&i>0&&a--;i===0&&a===0&&(n.push(o),o=``,r=!1)}else{if(c.includes(`=`)){let e=this._findAssignmentOperator(c);if(e!==-1){let t=c.slice(e+1).trim(),n=0,s=0;for(let e of t)e===`[`?n++:e===`]`&&s++;if(n>s){r=!0,i=n-s,a=0,o=c;continue}}}n.push(c)}}return n.join(`
`)}_stripBlockComments(e){let t=``,n=0;for(;n<e.length;)if(e[n]===`/`&&n+1<e.length&&e[n+1]===`*`){let t=n+2;for(;t<e.length;){if(e[t]===`*`&&t+1<e.length&&e[t+1]===`/`){t+=2;break}t++}n=t}else t+=e[n],n++;return t}_collapseTripleQuotedStrings(e){let t=``,n=0;for(;n<e.length;){if(n+2<e.length){let r=e.slice(n,n+3);if(r===`'''`||r===`"""`){let i=r;for(t+=i,n+=3;n<e.length;)if(n+2<e.length&&e.slice(n,n+3)===i){t+=i,n+=3;break}else e[n]===`
`?t+=`\\n`:e[n]!==`\r`&&(t+=e[n]),n++;continue}}t+=e[n],n++}return t}_stripInlineComment(e){if(e.trim().startsWith(`#usda`))return e;let t=!1,n=null,r=!1;for(let i=0;i<e.length;i++){let a=e[i];if(r){r=!1;continue}if(a===`\\`){r=!0;continue}if(!t&&(a===`"`||a===`'`))t=!0,n=a;else if(t&&a===n)t=!1,n=null;else if(!t&&a===`#`)return e.slice(0,i).trimEnd()}return e}_findAssignmentOperator(e){let t=!1,n=null,r=!1;for(let i=0;i<e.length;i++){let a=e[i];if(r){r=!1;continue}if(a===`\\`){r=!0;continue}if(!t&&(a===`"`||a===`'`))t=!0,n=a;else if(t&&a===n)t=!1,n=null;else if(!t&&a===`=`)return i}return-1}parseData(e){let t=this.parseText(e),n={},r={Attribute:1,Prim:6,Relationship:8},i={};if(`#usda 1.0`in t){let e=t[`#usda 1.0`];e.upAxis&&(i.upAxis=e.upAxis.replace(/"/g,``)),e.defaultPrim&&(i.defaultPrim=e.defaultPrim.replace(/"/g,``)),e.metersPerUnit!==void 0&&(i.metersPerUnit=parseFloat(e.metersPerUnit))}n[`/`]={specType:r.Prim,fields:i};let a=(e,t)=>{let i=[];for(let o in e){if(o===`#usda 1.0`||o===`variants`)continue;let s=o.match(R);if(s){let c=s[1]||``,l=s[2],u=t===`/`?`/`+l:t+`/`+l;i.push(l);let d={typeName:c},f=e[o];this._extractPrimData(f,u,d,n,r),n[u]={specType:r.Prim,fields:d},a(f,u)}}i.length>0&&n[t]&&(n[t].fields.primChildren=i)};return a(t,`/`),{specsByPath:n}}_extractPrimData(e,t,n,r,i){if(!(!e||typeof e!=`object`))for(let a in e){if(a.startsWith(`def `))continue;if(a===`prepend references`){n.references=[e[a]];continue}if(a===`payload`){n.payload=e[a];continue}if(a===`variants`){let t={},r=e[a];for(let e in r){let n=e.match(z);if(n){let i=n[1];t[i]=r[e].replace(/"/g,``)}}Object.keys(t).length>0&&(n.variantSelection=t);continue}if(a.startsWith(`rel `)){let n=a.slice(4),o=t+`.`+n,s=e[a].replace(/[<>]/g,``);r[o]={specType:i.Relationship,fields:{targetPaths:[s]}};continue}if(a.includes(`xformOpOrder`)){n.xformOpOrder=e[a].replace(/[\[\]]/g,``).split(`,`).map(e=>e.trim().replace(/"/g,``));continue}let o=a.match(B);if(o){let n=o[1],s=o[2],c=e[a];if(s.endsWith(`.connect`)){let e=s.slice(0,-8),a=t+`.`+e,o=String(c).trim();o.startsWith(`<`)&&(o=o.slice(1)),o.endsWith(`>`)&&(o=o.slice(0,-1)),r[a]||(r[a]={specType:i.Attribute,fields:{typeName:n}}),r[a].fields.connectionPaths=[o];continue}if(s.endsWith(`.timeSamples`)&&typeof c==`object`){let e=s.slice(0,-12),a=t+`.`+e,o=[],l=[];for(let e in c){let t=parseFloat(e);isNaN(t)||(o.push(t),l.push(this._parseAttributeValue(n,c[e])))}let u=o.map((e,t)=>({t:e,v:l[t]})).sort((e,t)=>e.t-t.t);r[a]={specType:i.Attribute,fields:{timeSamples:{times:u.map(e=>e.t),values:u.map(e=>e.v)},typeName:n}}}else{let e=this._parseAttributeValue(n,c),a=t+`.`+s;r[a]={specType:i.Attribute,fields:{default:e,typeName:n}}}}}}_parseAttributeValue(e,t){if(t==null)return;let n=String(t).trim();if(e.endsWith(`[]`))try{let e=n.replace(/\(/g,`[`).replace(/\)/g,`]`);e.endsWith(`,`)&&(e=e.slice(0,-1));let t=JSON.parse(e);return Array.isArray(t)&&Array.isArray(t[0])?t.flat():t}catch{return n.replace(/[\[\]]/g,``).split(`,`).map(e=>{let t=e.trim(),n=parseFloat(t);return isNaN(n)?t.replace(/"/g,``):n})}if(e.includes(`3`)||e.includes(`2`)||e.includes(`4`))return n.replace(/[()]/g,``).split(`,`).map(e=>parseFloat(e.trim()));if(e.startsWith(`quat`)){let e=n.replace(/[()]/g,``).split(`,`).map(e=>parseFloat(e.trim()));return[e[1],e[2],e[3],e[0]]}return e.includes(`matrix`)?n.replace(/[()]/g,``).split(`,`).map(e=>parseFloat(e.trim())):e===`float`||e===`double`||e===`int`?parseFloat(n):e===`string`||e===`token`?this._parseString(n):e===`asset`?n.replace(/@/g,``).replace(/"/g,``):this._parseString(n)}_parseString(e){(e.startsWith(`"`)&&e.endsWith(`"`)||e.startsWith(`'`)&&e.endsWith(`'`))&&(e=e.slice(1,-1));let t=``,n=0;for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length){let r=e[n+1];switch(r){case`n`:t+=`
`;break;case`t`:t+=` `;break;case`r`:t+=`\r`;break;case`\\`:t+=`\\`;break;case`"`:t+=`"`;break;case`'`:t+=`'`;break;default:t+=r;break}n+=2}else t+=e[n],n++;return t}},H=new TextDecoder,U=new Float32Array(32);for(let e=0;e<32;e++)U[e]=2**(e-15);var W=2**-14,G={Invalid:0,Bool:1,UChar:2,Int:3,UInt:4,Int64:5,UInt64:6,Half:7,Float:8,Double:9,String:10,Token:11,AssetPath:12,Matrix2d:13,Matrix3d:14,Matrix4d:15,Quatd:16,Quatf:17,Quath:18,Vec2d:19,Vec2f:20,Vec2h:21,Vec2i:22,Vec3d:23,Vec3f:24,Vec3h:25,Vec3i:26,Vec4d:27,Vec4f:28,Vec4h:29,Vec4i:30,Dictionary:31,TokenListOp:32,StringListOp:33,PathListOp:34,ReferenceListOp:35,IntListOp:36,Int64ListOp:37,UIntListOp:38,UInt64ListOp:39,PathVector:40,TokenVector:41,Specifier:42,Permission:43,Variability:44,VariantSelectionMap:45,TimeSamples:46,Payload:47,DoubleVector:48,LayerOffsetVector:49,StringVector:50,ValueBlock:51,Value:52,UnregisteredValue:53,UnregisteredValueListOp:54,PayloadListOp:55,TimeCode:56,PathExpression:57,Relocates:58,Spline:59,AnimationBlock:60},K=4294967295,ee=105,te=116;function q(e,t,n,r,i,a){for(;t<n;){let o=e[t++];if(t>n)break;let s=o>>4;if(s===15){let r;do{if(t>=n)break;r=e[t++],s+=r}while(r===255&&t<n)}if(s>0){t+s>n&&(s=n-t);for(let n=0;n<s&&!(i>=a);n++)r[i++]=e[t++]}if(t>=n||t+2>n)break;let c=e[t++]|e[t++]<<8;if(c===0)break;let l=(o&15)+4;if(l===19){let r;do{if(t>=n)break;r=e[t++],l+=r}while(r===255&&t<n)}let u=i-c;if(u<0)break;for(let e=0;e<l&&!(i>=a);e++)r[i++]=r[u+e]}return i}function J(e,t){let n=new Uint8Array(t),r=e[0];if(r===0)return q(e,1,e.length,n,0,t),n;{let i=1,a=[];for(let t=0;t<r;t++){let t=(e[i]|e[i+1]<<8|e[i+2]<<16|e[i+3]<<24)>>>0;a.push(t),i+=4}let o=i,s=0;for(let i=0;i<r;i++){let r=a[i],c=Math.min(65536,t-s);q(e,o,o+r,n,s,s+c),o+=r,s+=c}return n}}function Y(e,t){let n=t*4+(t*2+7>>3)+4;return ne(J(new Uint8Array(e),n),t)}function ne(e,t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=0,i=n.getInt32(r,!0);r+=4;let a=t*2+7>>3,o=r,s=r+a,c=new Int32Array(t),l=0,u=o,d=s;for(let r=0;r<t;){let a=e[u++];for(let e=0;e<4&&r<t;e++,r++){let t=a>>e*2&3,o=0;switch(t){case 0:o=i;break;case 1:o=n.getInt8(d),d+=1;break;case 2:o=n.getInt16(d,!0),d+=2;break;case 3:o=n.getInt32(d,!0),d+=4;break}l+=o,c[r]=l}}return c}var re=class{constructor(e){this.buffer=e,this.view=new DataView(e),this.offset=0}seek(e){this.offset=e}tell(){return this.offset}readUint8(){let e=this.view.getUint8(this.offset);return this.offset+=1,e}readInt8(){let e=this.view.getInt8(this.offset);return this.offset+=1,e}readUint16(){let e=this.view.getUint16(this.offset,!0);return this.offset+=2,e}readInt16(){let e=this.view.getInt16(this.offset,!0);return this.offset+=2,e}readUint32(){let e=this.view.getUint32(this.offset,!0);return this.offset+=4,e}readInt32(){let e=this.view.getInt32(this.offset,!0);return this.offset+=4,e}readUint64(){let e=this.view.getUint32(this.offset,!0),t=this.view.getUint32(this.offset+4,!0);return this.offset+=8,t*4294967296+e}readInt64(){let e=this.view.getUint32(this.offset,!0),t=this.view.getInt32(this.offset+4,!0);return this.offset+=8,t*4294967296+e}readFloat32(){let e=this.view.getFloat32(this.offset,!0);return this.offset+=4,e}readFloat64(){let e=this.view.getFloat64(this.offset,!0);return this.offset+=8,e}readBytes(e){let t=new Uint8Array(this.buffer,this.offset,e);return this.offset+=e,t}readString(e){let t=this.readBytes(e),n=0;for(;n<e&&t[n]!==0;)n++;return H.decode(t.subarray(0,n))}},X=class{constructor(e,t){this.lo=e,this.hi=t}get isArray(){return(this.hi&2147483648)!=0}get isInlined(){return(this.hi&1073741824)!=0}get isCompressed(){return(this.hi&536870912)!=0}get typeEnum(){return this.hi>>16&255}get payload(){return this.lo+(this.hi&65535)*4294967296}getInlinedValue(){return this.lo}},ie=class{parseData(e){this.buffer=e instanceof ArrayBuffer?e:e.buffer,this.reader=new re(this.buffer),this.version={major:0,minor:0,patch:0},this._conversionBuffer=new ArrayBuffer(4),this._conversionView=new DataView(this._conversionBuffer),this._readBootstrap(),this._readTOC(),this._readTokens(),this._readStrings(),this._readFields(),this._readFieldSets(),this._readPaths(),this._readSpecs(),this.specsByPath={};for(let e of this.specs){let t=this.paths[e.pathIndex];if(!t)continue;let n=this._getFieldsForSpec(e);this.specsByPath[t]={specType:e.specType,fields:n}}return{specsByPath:this.specsByPath}}_readBootstrap(){let e=this.reader;if(e.seek(0),e.readString(8)!==`PXR-USDC`)throw Error(`Not a valid USDC file`);this.version.major=e.readUint8(),this.version.minor=e.readUint8(),this.version.patch=e.readUint8(),e.readBytes(5),this.tocOffset=e.readUint64()}_readTOC(){let e=this.reader;e.seek(this.tocOffset);let t=e.readUint64();this.sections={};for(let n=0;n<t;n++){let t=e.readString(16),n=e.readUint64(),r=e.readUint64();this.sections[t]={start:n,size:r}}}_readTokens(){let e=this.sections.TOKENS;if(!e)return;let t=this.reader;t.seek(e.start);let n=t.readUint64();if(this.tokens=[],this.version.major===0&&this.version.minor<4){let e=t.readUint64(),r=t.readBytes(e),i=0;for(let e=0;e<n;e++){let e=i;for(;e<r.length&&r[e]!==0;)e++;this.tokens.push(H.decode(r.subarray(i,e))),i=e+1}}else{let e=t.readUint64(),r=t.readUint64(),i=J(t.readBytes(r),e),a=0;for(let e=0;e<n;e++){let e=a;for(;e<i.length&&i[e]!==0;)e++;this.tokens.push(H.decode(i.subarray(a,e))),a=e+1}}}_readStrings(){let e=this.sections.STRINGS;if(!e){this.strings=[];return}let t=this.reader;t.seek(e.start);let n=Math.floor(e.size/4);this.strings=[];for(let e=0;e<n;e++)this.strings.push(t.readUint32())}_readFields(){let e=this.sections.FIELDS;if(!e)return;let t=this.reader;if(t.seek(e.start),this.fields=[],this.version.major===0&&this.version.minor<4){let n=Math.floor(e.size/12);for(let e=0;e<n;e++){let e=t.readUint32(),n=t.readUint32(),r=t.readUint32();this.fields.push({tokenIndex:e,valueRep:new X(n,r)})}}else{let e=t.readUint64(),n=t.readUint64(),r=t.readBytes(n),i=Y(r.buffer.slice(r.byteOffset,r.byteOffset+n),e),a=t.readUint64(),o=J(t.readBytes(a),e*8),s=new DataView(o.buffer,o.byteOffset,o.byteLength);for(let t=0;t<e;t++){let e=s.getUint32(t*8,!0),n=s.getUint32(t*8+4,!0);this.fields.push({tokenIndex:i[t],valueRep:new X(e,n)})}}}_readFieldSets(){let e=this.sections.FIELDSETS;if(!e)return;let t=this.reader;if(t.seek(e.start),this.fieldSets=[],this.version.major===0&&this.version.minor<4){let n=Math.floor(e.size/4);for(let e=0;e<n;e++)this.fieldSets.push(t.readUint32())}else{let e=t.readUint64(),n=t.readUint64(),r=t.readBytes(n),i=Y(r.buffer.slice(r.byteOffset,r.byteOffset+n),e);for(let t=0;t<e;t++)this.fieldSets.push(i[t])}}_readPaths(){let e=this.sections.PATHS;if(!e)return;let t=this.reader;t.seek(e.start);let n=t.readUint64();if(this.paths=Array(n).fill(``),this.version.major===0&&this.version.minor<4)this._readPathsRecursive(``);else{t.readUint64();let e=t.readUint64(),r=t.readBytes(e),i=Y(r.buffer.slice(r.byteOffset,r.byteOffset+e),n),a=t.readUint64(),o=t.readBytes(a),s=Y(o.buffer.slice(o.byteOffset,o.byteOffset+a),n),c=t.readUint64(),l=t.readBytes(c),u=Y(l.buffer.slice(l.byteOffset,l.byteOffset+c),n);this._buildPathsFromCompressed(i,s,u)}}_readPathsRecursive(e,t=0){let n=this.reader;if(t>1e3)return;let r=n.readUint32(),i=n.readUint32(),a=n.readUint8(),o=(a&1)!=0,s=(a&2)!=0,c=(a&4)!=0,l;if(e===``)l=`/`;else{let t=this.tokens[i]||``;l=c?e+`.`+t:e===`/`?`/`+t:e+`/`+t}if(this.paths[r]=l,o&&s){let r=n.readUint64();this._readPathsRecursive(l,t+1),n.seek(r),this._readPathsRecursive(e,t+1)}else o?this._readPathsRecursive(l,t+1):s&&this._readPathsRecursive(e,t+1)}_buildPathsFromCompressed(e,t,n){let r=(i,a)=>{let o=i;for(;o<e.length;){let i=o++,s=e[i],c=t[i],l=n[i],u;if(a===``)u=`/`,a=u;else{let e=this.tokens[Math.abs(c)]||``;u=c<0?a+`.`+e:a===`/`?`/`+e:a+`/`+e}this.paths[s]=u;let d=l>0||l===-1,f=l>=0;if(d)f&&r(i+l,a),a=u;else if(!f)break}};r(0,``)}_readSpecs(){let e=this.sections.SPECS;if(!e)return;let t=this.reader;if(t.seek(e.start),this.specs=[],this.version.major===0&&this.version.minor<4){let n=this.version.minor===0&&this.version.patch===1?16:12,r=Math.floor(e.size/n);for(let e=0;e<r;e++){let e=t.readUint32(),r=t.readUint32(),i=t.readUint32();n===16&&t.readUint32(),this.specs.push({pathIndex:e,fieldSetIndex:r,specType:i})}}else{let e=t.readUint64(),n=t.readUint64(),r=t.readBytes(n),i=Y(r.buffer.slice(r.byteOffset,r.byteOffset+n),e),a=t.readUint64(),o=t.readBytes(a),s=Y(o.buffer.slice(o.byteOffset,o.byteOffset+a),e),c=t.readUint64(),l=t.readBytes(c),u=Y(l.buffer.slice(l.byteOffset,l.byteOffset+c),e);for(let t=0;t<e;t++)this.specs.push({pathIndex:i[t],fieldSetIndex:s[t],specType:u[t]})}}_readValue(e){let t=e.typeEnum,n=e.isArray,r=e.isInlined;if(t===G.TimeSamples)return this._readTimeSamples(e);if(r)return this._readInlinedValue(e);let i=e.payload;if(i===0&&n)return[];if(i<0||i>=this.buffer.byteLength)throw RangeError(`USDCParser: Invalid payload offset `+i+` for type `+t+`.`);let a=this.reader.tell();this.reader.seek(i);let o;return o=n?this._readArrayValue(e):this._readScalarValue(t),this.reader.seek(a),o}_readInlinedValue(e){let t=e.typeEnum,n=e.getInlinedValue(),r=this._conversionView;switch(t){case G.Bool:return n!==0;case G.UChar:return n&255;case G.Int:case G.UInt:return n;case G.Float:return r.setUint32(0,n,!0),r.getFloat32(0,!0);case G.Double:return r.setUint32(0,n,!0),r.getFloat32(0,!0);case G.Token:return this.tokens[n]||``;case G.String:return this.tokens[this.strings[n]]||``;case G.AssetPath:return this.tokens[n]||``;case G.Specifier:return n;case G.Permission:case G.Variability:return n;case G.Vec2h:return r.setUint32(0,n,!0),[this._halfToFloat(r.getUint16(0,!0)),this._halfToFloat(r.getUint16(2,!0))];case G.Vec2f:case G.Vec2i:return r.setUint32(0,n,!0),[r.getInt8(0),r.getInt8(1)];case G.Vec3f:case G.Vec3i:return r.setUint32(0,n,!0),[r.getInt8(0),r.getInt8(1),r.getInt8(2)];case G.Vec4f:case G.Vec4i:return r.setUint32(0,n,!0),[r.getInt8(0),r.getInt8(1),r.getInt8(2),r.getInt8(3)];case G.Matrix2d:return r.setUint32(0,n,!0),[r.getInt8(0),0,0,r.getInt8(1)];case G.Matrix3d:return r.setUint32(0,n,!0),[r.getInt8(0),0,0,0,r.getInt8(1),0,0,0,r.getInt8(2)];case G.Matrix4d:return r.setUint32(0,n,!0),[r.getInt8(0),0,0,0,0,r.getInt8(1),0,0,0,0,r.getInt8(2),0,0,0,0,r.getInt8(3)];default:return n}}_readTimeSamples(e){let t=this.reader,n=e.payload,r=t.tell();t.seek(n);let i=t.tell(),a=t.readInt64();t.seek(i+a);let o=new X(t.readUint32(),t.readUint32()),s=this._readValue(o),c=i+a+8;t.seek(c);let l=t.tell(),u=t.readInt64();t.seek(l+u);let d=t.readUint64(),f=[];for(let e=0;e<d;e++){let e=t.readUint32(),n=t.readUint32();f.push(new X(e,n))}let p=[];for(let e=0;e<d;e++)p.push(this._readValue(f[e]));return t.seek(r),{times:s instanceof Float64Array?Array.from(s):Array.isArray(s)?s:[s],values:p}}_readScalarValue(e){let t=this.reader;switch(e){case G.Invalid:return null;case G.Bool:return t.readUint8()!==0;case G.UChar:return t.readUint8();case G.Int:return t.readInt32();case G.UInt:return t.readUint32();case G.Int64:return t.readInt64();case G.UInt64:return t.readUint64();case G.Half:return this._readHalf();case G.Float:return t.readFloat32();case G.Double:return t.readFloat64();case G.String:case G.Token:{let e=t.readUint32();return this.tokens[e]||``}case G.AssetPath:{let e=t.readUint32();return this.tokens[e]||``}case G.Vec2f:return[t.readFloat32(),t.readFloat32()];case G.Vec2d:return[t.readFloat64(),t.readFloat64()];case G.Vec2i:return[t.readInt32(),t.readInt32()];case G.Vec3f:return[t.readFloat32(),t.readFloat32(),t.readFloat32()];case G.Vec3d:return[t.readFloat64(),t.readFloat64(),t.readFloat64()];case G.Vec3i:return[t.readInt32(),t.readInt32(),t.readInt32()];case G.Vec4f:return[t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32()];case G.Vec4d:return[t.readFloat64(),t.readFloat64(),t.readFloat64(),t.readFloat64()];case G.Quatf:return[t.readFloat32(),t.readFloat32(),t.readFloat32(),t.readFloat32()];case G.Quatd:return[t.readFloat64(),t.readFloat64(),t.readFloat64(),t.readFloat64()];case G.Matrix4d:{let e=[];for(let n=0;n<16;n++)e.push(t.readFloat64());return e}case G.TokenVector:{let e=t.readUint64(),n=[];for(let r=0;r<e;r++){let e=t.readUint32();n.push(this.tokens[e]||``)}return n}case G.PathVector:{let e=t.readUint64(),n=[];for(let r=0;r<e;r++){let e=t.readUint32();n.push(this.paths[e]||``)}return n}case G.DoubleVector:{let e=t.readUint64(),n=new Float64Array(e);for(let r=0;r<e;r++)n[r]=t.readFloat64();return n}case G.Dictionary:{let e=t.readUint64(),n={};for(let r=0;r<e;r++){let e=t.readUint32(),r=this.tokens[e],i=t.position+t.readInt64(),a=t.position;t.position=i;let o=new X(t.readUint64()),s=null;o.isInlined?s=this._readInlinedValue(o):o.isArray?(t.position=o.payload,s=this._readArrayValue(o)):(t.position=o.payload,s=this._readScalarValue(o.typeEnum)),t.position=a,r!==void 0&&s!==null&&(n[r]=s)}return n}case G.TokenListOp:case G.StringListOp:case G.IntListOp:case G.Int64ListOp:case G.UIntListOp:case G.UInt64ListOp:return null;case G.PathListOp:{let e=t.readUint8(),n=(e&2)!=0,r=(e&4)!=0,i=(e&8)!=0,a=(e&16)!=0,o=(e&32)!=0,s=(e&64)!=0,c=()=>{let e=t.readUint64(),n=[];for(let r=0;r<e;r++){let e=t.readUint32();n.push(this.paths[e])}return n},l=null,u=null,d=null,f=null;return n&&(l=c()),r&&(u=c()),o&&(d=c()),s&&(f=c()),i&&c(),a&&c(),d&&d.length>0?d:l&&l.length>0?l:f&&f.length>0?f:u&&u.length>0?u:null}case G.VariantSelectionMap:{let e=t.readUint64(),n={};for(let r=0;r<e;r++){let e=t.readUint32(),r=t.readUint32(),i=this.tokens[this.strings[e]],a=this.tokens[this.strings[r]];i&&a&&(n[i]=a)}return n}default:return console.warn(`USDCParser: Unsupported scalar type`,e),null}}_readArrayValue(e){let t=this.reader,n=e.typeEnum,r=e.isCompressed,i;if(i=this.version.major===0&&this.version.minor<7?t.readUint32():t.readUint64(),!Number.isSafeInteger(i)||i<0)throw RangeError(`USDCParser: Invalid array size `+i+` for type `+n+`.`);if(i>2147483647)throw RangeError(`USDCParser: Array size `+i+` exceeds implementation limits.`);if(i===0)return[];if(r)return this._readCompressedArray(n,i);switch(n){case G.Int:{let e=new Int32Array(i);for(let n=0;n<i;n++)e[n]=t.readInt32();return e}case G.UInt:{let e=new Uint32Array(i);for(let n=0;n<i;n++)e[n]=t.readUint32();return e}case G.Float:{let e=new Float32Array(i);for(let n=0;n<i;n++)e[n]=t.readFloat32();return e}case G.Double:{let e=new Float64Array(i);for(let n=0;n<i;n++)e[n]=t.readFloat64();return e}case G.Vec2f:{let e=new Float32Array(i*2);for(let n=0;n<i*2;n++)e[n]=t.readFloat32();return e}case G.Vec3f:{let e=new Float32Array(i*3);for(let n=0;n<i*3;n++)e[n]=t.readFloat32();return e}case G.Vec4f:{let e=new Float32Array(i*4);for(let n=0;n<i*4;n++)e[n]=t.readFloat32();return e}case G.Vec3h:{let e=new Float32Array(i*3);for(let t=0;t<i*3;t++)e[t]=this._readHalf();return e}case G.Quatf:{let e=new Float32Array(i*4);for(let n=0;n<i*4;n++)e[n]=t.readFloat32();return e}case G.Quath:{let e=new Float32Array(i*4);for(let t=0;t<i*4;t++)e[t]=this._readHalf();return e}case G.Matrix4d:{let e=new Float64Array(i*16);for(let n=0;n<i*16;n++)e[n]=t.readFloat64();return e}case G.Token:{let e=[];for(let n=0;n<i;n++){let n=t.readUint32();e.push(this.tokens[n]||``)}return e}case G.Half:{let e=new Float32Array(i);for(let t=0;t<i;t++)e[t]=this._readHalf();return e}default:return console.warn(`USDCParser: Unsupported array type`,n),[]}}_readCompressedArray(e,t){let n=this.reader;switch(e){case G.Int:case G.UInt:{let e=n.readUint64(),r=n.readBytes(e);return Y(r.buffer.slice(r.byteOffset,r.byteOffset+e),t)}case G.Float:{let e=n.readInt8();if(e===ee){let e=n.readUint64(),r=n.readBytes(e),i=Y(r.buffer.slice(r.byteOffset,r.byteOffset+e),t),a=new Float32Array(t);for(let e=0;e<t;e++)a[e]=i[e];return a}else if(e===te){let e=n.readUint32(),r=new Float32Array(e);for(let t=0;t<e;t++)r[t]=n.readFloat32();let i=n.readUint64(),a=n.readBytes(i),o=Y(a.buffer.slice(a.byteOffset,a.byteOffset+i),t),s=new Float32Array(t);for(let e=0;e<t;e++)s[e]=r[o[e]];return s}return console.warn(`USDCParser: Unknown float compression code`,e),new Float32Array(t)}default:return console.warn(`USDCParser: Unsupported compressed array type`,e),[]}}_readHalf(){return this._halfToFloat(this.reader.readUint16())}_halfToFloat(e){let t=(e&32768)>>15,n=(e&31744)>>10,r=e&1023;return n===0?r===0?t?-0:0:(t?-1:1)*W*(r/1024):n===31?r?NaN:t?-1/0:1/0:(t?-1:1)*U[n]*(1+r/1024)}_getFieldsForSpec(e){let t={},n=e.fieldSetIndex,r=0;for(;n<this.fieldSets.length&&r<1e4;){let e=this.fieldSets[n];if(e===K||e===-1)break;let i=this.fields[e];if(i){let e=this.tokens[i.tokenIndex];t[e]=this._readValue(i.valueRep)}n++,r++}return t}},ae=/^(.+?)\/\{(\w+)=(\w+)\}\/(.+)$/,Z={Unknown:0,Attribute:1,Connection:2,Expression:3,Mapper:4,MapperArg:5,Prim:6,PseudoRoot:7,Relationship:8,RelationshipTarget:9,Variant:10,VariantSet:11},Q={projection:`perspective`,clippingRange:[1,1e6],horizontalAperture:20.955,verticalAperture:15.2908,horizontalApertureOffset:0,verticalApertureOffset:0,focalLength:50,focusDistance:0,fStop:0},$=class r{constructor(e=null){this.textureCache={},this.skinnedMeshes=[],this.manager=e}compose(e,t={},n={},r=``){this.specsByPath=e.specsByPath,this.assets=t,this.externalVariantSelections=n,this.basePath=r,this.skinnedMeshes=[],this.skeletons={},this._buildIndexes();let i=this.specsByPath[`/`],a=i?i.fields:{};this.fps=a.framesPerSecond||a.timeCodesPerSecond||30;let s=new o;this._buildHierarchy(s,`/`),this._bindSkeletons();let c=Object.keys(this.skeletons);c.length===1&&(s.skeleton=this.skeletons[c[0]].skeleton),s.animations=this._buildAnimations();let l=a.metersPerUnit;return l!==void 0&&l!==1&&s.scale.setScalar(l),i&&i.fields&&i.fields.upAxis===`Z`&&(s.rotation.x=-Math.PI/2),s}applyTransform(t,r,i={}){let a={...r,...i},o=a.xformOpOrder;if(o&&o.length>0){let n=new e,r=new e,i=null;for(let e=0;e<o.length;e++){let t=o[e],s=t.startsWith(`!invert!`),c=s?t.slice(8):t;if(c===`xformOp:transform`){let e=a[`xformOp:transform`];e&&e.length===16&&(r.set(e[0],e[4],e[8],e[12],e[1],e[5],e[9],e[13],e[2],e[6],e[10],e[14],e[3],e[7],e[11],e[15]),s&&r.invert(),n.multiply(r))}else if(c===`xformOp:translate`){let e=a[`xformOp:translate`];e&&(r.makeTranslation(e[0],e[1],e[2]),s&&r.invert(),n.multiply(r))}else if(c===`xformOp:translate:pivot`){let e=a[`xformOp:translate:pivot`];e&&(r.makeTranslation(e[0],e[1],e[2]),s&&r.invert(),n.multiply(r))}else if(c===`xformOp:scale`){let e=a[`xformOp:scale`];e&&(Array.isArray(e)?(r.makeScale(e[0],e[1],e[2]),i=[e[0],e[1],e[2]]):(r.makeScale(e,e,e),i=[e,e,e]),s&&r.invert(),n.multiply(r))}else if(c===`xformOp:rotateXYZ`){let e=a[`xformOp:rotateXYZ`];if(e){let t=new p(e[0]*Math.PI/180,e[1]*Math.PI/180,e[2]*Math.PI/180,`ZYX`);r.makeRotationFromEuler(t),s&&r.invert(),n.multiply(r)}}else if(c===`xformOp:rotateX`){let e=a[`xformOp:rotateX`];e!==void 0&&(r.makeRotationX(e*Math.PI/180),s&&r.invert(),n.multiply(r))}else if(c===`xformOp:rotateY`){let e=a[`xformOp:rotateY`];e!==void 0&&(r.makeRotationY(e*Math.PI/180),s&&r.invert(),n.multiply(r))}else if(c===`xformOp:rotateZ`){let e=a[`xformOp:rotateZ`];e!==void 0&&(r.makeRotationZ(e*Math.PI/180),s&&r.invert(),n.multiply(r))}else if(c===`xformOp:orient`){let e=a[`xformOp:orient`];if(e&&e.length===4){let t=new F(e[0],e[1],e[2],e[3]);r.makeRotationFromQuaternion(t),s&&r.invert(),n.multiply(r)}}}if(t.matrix.copy(n),t.matrix.decompose(t.position,t.quaternion,t.scale),i){let e=i[0]<0,n=i[1]<0,r=i[2]<0;+!!e+ +!!n+ +!!r==3&&(t.scale.set(i[0],i[1],i[2]),t.quaternion.set(t.quaternion.x,-t.quaternion.y,t.quaternion.z,-t.quaternion.w))}return}if(a[`xformOp:translate`]){let e=a[`xformOp:translate`];t.position.set(e[0],e[1],e[2])}if(a[`xformOp:translate:pivot`]){let e=a[`xformOp:translate:pivot`];t.pivot=new n(e[0],e[1],e[2])}if(a[`xformOp:scale`]){let e=a[`xformOp:scale`];Array.isArray(e)?t.scale.set(e[0],e[1],e[2]):t.scale.set(e,e,e)}if(a[`xformOp:rotateXYZ`]){let e=a[`xformOp:rotateXYZ`];t.rotation.set(e[0]*Math.PI/180,e[1]*Math.PI/180,e[2]*Math.PI/180)}if(a[`xformOp:orient`]){let e=a[`xformOp:orient`];e.length===4&&t.quaternion.set(e[0],e[1],e[2],e[3])}}_buildIndexes(){this.childrenByPath=new Map,this.attributesByPrimPath=new Map,this.materialsByRoot=new Map,this.shadersByMaterialPath=new Map,this.geomSubsetsByMeshPath=new Map;for(let e in this.specsByPath){let t=this.specsByPath[e];if(t.specType===Z.Prim){let n=e.lastIndexOf(`/`);if(n>0){let t=e.slice(0,n),r=e.slice(n+1);this.childrenByPath.has(t)||this.childrenByPath.set(t,[]),this.childrenByPath.get(t).push({name:r,path:e})}else if(n===0&&e.length>1){let t=e.slice(1);this.childrenByPath.has(`/`)||this.childrenByPath.set(`/`,[]),this.childrenByPath.get(`/`).push({name:t,path:e})}let r=t.fields.typeName;if(r===`Material`){let t=e.split(`/`),n=t.length>1?`/`+t[1]:`/`;this.materialsByRoot.has(n)||this.materialsByRoot.set(n,[]),this.materialsByRoot.get(n).push(e)}if(r===`Shader`&&n>0){let t=e.slice(0,n);for(;t.length>0;){let n=this.specsByPath[t];if(n&&n.specType===Z.Prim&&n.fields.typeName===`Material`){this.shadersByMaterialPath.has(t)||this.shadersByMaterialPath.set(t,[]),this.shadersByMaterialPath.get(t).push(e);break}let r=t.lastIndexOf(`/`);if(r<=0)break;t=t.slice(0,r)}}if(r===`GeomSubset`&&n>0){let t=e.slice(0,n);this.geomSubsetsByMeshPath.has(t)||this.geomSubsetsByMeshPath.set(t,[]),this.geomSubsetsByMeshPath.get(t).push(e)}}else if(t.specType===Z.Attribute||t.specType===Z.Relationship){let n=e.lastIndexOf(`.`);if(n>0){let r=e.slice(0,n),i=e.slice(n+1);this.attributesByPrimPath.has(r)||this.attributesByPrimPath.set(r,new Map),this.attributesByPrimPath.get(r).set(i,t)}}}}_isDirectChild(e,t,n){if(!t.startsWith(n))return!1;let r=t.slice(n.length);return r.length===0||r.startsWith(`{`)?!1:!r.includes(`/`)}_buildHierarchy(e,t){let n=[],r=new Set,i=this.childrenByPath.get(t);if(i)for(let e of i)r.has(e.path)||(r.add(e.path),n.push(e));let a=this._getVariantPaths(t);for(let e of a){let t=this.childrenByPath.get(e);if(t)for(let e of t)r.has(e.path)||(r.add(e.path),n.push(e))}for(let{name:t,path:r}of n){let n=this.specsByPath[r];if(!n||n.specType!==Z.Prim)continue;let i=n.fields.typeName,a=this._getReferences(n);if(a.length>0){let o=this._getLocalVariantSelections(n.fields),s=[];for(let e of a){let t=this._resolveReference(e,o);t&&s.push(t)}if(s.length>0){let a=this._getAttributes(r);if(s.length===1){let o=this._findSingleMesh(s[0]);if(o&&(i===`Xform`||!i)){o.name=t,this.applyTransform(o,n.fields,a),this._applyMaterialBinding(o,r),e.add(o),this._buildHierarchy(o,r);continue}}let o=new v;o.name=t,this.applyTransform(o,n.fields,a);for(let e of s)for(;e.children.length>0;)o.add(e.children[0]);e.add(o),this._buildHierarchy(o,r);continue}}if(i===`SkelRoot`){let i=new v;i.name=t,i.userData.isSkelRoot=!0;let a=this._getAttributes(r);this.applyTransform(i,n.fields,a),e.add(i),this._buildHierarchy(i,r)}else if(i===`Skeleton`){let t=this._buildSkeleton(r);t&&(this.skeletons[r]=t),this._buildHierarchy(e,r)}else if(i!==`SkelAnimation`){if(i===`Mesh`){let t=this._buildMesh(r,n);t&&(e.add(t),this._buildHierarchy(t,r))}else if(i===`Camera`){let i=this._buildCamera(r);i.name=t;let a=this._getAttributes(r);this.applyTransform(i,n.fields,a),e.add(i),this._buildHierarchy(i,r)}else if(i===`DistantLight`||i===`SphereLight`||i===`RectLight`||i===`DiskLight`){let a=this._buildLight(r,i);a.name=t;let o=this._getAttributes(r);this.applyTransform(a,n.fields,o),e.add(a),this._buildHierarchy(a,r)}else if(i===`Cube`||i===`Sphere`||i===`Cylinder`||i===`Cone`||i===`Capsule`){let t=this._buildGeomPrimitive(r,n,i);t&&(e.add(t),this._buildHierarchy(t,r))}else if(!(i===`Material`||i===`Shader`||i===`GeomSubset`)){let i=new v;i.name=t;let a=this._getAttributes(r);this.applyTransform(i,n.fields,a),e.add(i),this._buildHierarchy(i,r)}}}}_getVariantPaths(e){let t=this.specsByPath[e],n=t?.fields?.variantSetChildren,r=[];if(!n||n.length===0)return r;for(let i of n){let n=this.externalVariantSelections[i]||null;if(!n){let e=t.fields.variantSelection;n=e?e[i]:null}if(!n){let t=e+`/{`+i+`=}`,r=this.specsByPath[t];r?.fields?.variantChildren&&(n=r.fields.variantChildren[0])}if(n){let t=e+`/{`+i+`=`+n+`}`;r.push(t)}}return r}_resolveFilePath(e){let t=e;return t.startsWith(`./`)&&(t=t.slice(2)),this.basePath?this.basePath+`/`+t:t}_resolveReference(e,t={}){if(!e)return null;let n=e.match(/@([^@]+)@(?:<([^>]+)>)?/);if(!n)return null;let i=n[1],a=n[2],s=this._resolveFilePath(i),c={...t,...this.externalVariantSelections},l=this.assets[s];if(!l)return null;if(l.specsByPath){let e=new r(this.manager),t=this._getBasePath(s),n=e.compose(l,this.assets,c,t);if(a){let e=a.split(`/`).pop(),t=null;for(let r of n.children)if(r.name===e){t=r;break}if(t){n.remove(t);let e=new o;return e.add(t),e}}return n}return l.isGroup||l.isObject3D?l.clone():null}_findSingleMesh(e){for(let t of e.children)if(t.isMesh)return e.remove(t),t;if(e.children.length===1){let t=e.children[0];if(t.children&&t.children.length===1){let e=t.children[0];if(e.isMesh&&!this._hasNonIdentityTransform(t))return t.remove(e),e}}return null}_hasNonIdentityTransform(e){let t=e.position,n=e.rotation,r=e.scale,i=t.x!==0||t.y!==0||t.z!==0,a=n.x!==0||n.y!==0||n.z!==0,o=r.x!==1||r.y!==1||r.z!==1;return i||a||o}_getBasePath(e){let t=e.lastIndexOf(`/`);return t>=0?e.slice(0,t):``}_getLocalVariantSelections(e){let t={};if(e.variantSelection)for(let n in e.variantSelection)t[n]=e.variantSelection[n];return t}_getReferences(e){let t=[];if(e.fields.references&&e.fields.references.length>0){let n=e.fields.references[0];if(typeof n==`string`){let e=n.matchAll(/@([^@]+)@(?:<([^>]+)>)?/g);for(let n of e)t.push(n[0])}else n.assetPath&&t.push(`@`+n.assetPath+`@`)}if(t.length===0&&e.fields.payload){let n=e.fields.payload;typeof n==`string`?t.push(n):n.assetPath&&t.push(`@`+n.assetPath+`@`)}return t}_getAttributes(e){let t={};this._collectAttributesFromPath(e,t);let n=e.match(ae);if(n){let r=n[1],i=n[4],a=this._getVariantPaths(r);for(let n of a){if(e.startsWith(n))continue;let r=n+`/`+i;this._collectAttributesFromPath(r,t)}}else{let n=e.split(`/`);for(let e=1;e<n.length-1;e++){let r=n.slice(0,e+1).join(`/`),i=n.slice(e+1).join(`/`),a=this._getVariantPaths(r);for(let e of a){let n=e+`/`+i;this._collectAttributesFromPath(n,t)}}}return t}_collectAttributesFromPath(e,t){let n=this.attributesByPrimPath.get(e);if(n)for(let[e,r]of n){if(r.fields?.default!==void 0)t[e]=r.fields.default;else if(r.fields?.timeSamples){let{times:n,values:i}=r.fields.timeSamples;if(n&&i&&n.length>0){let r=n.indexOf(0);t[e]=r>=0?i[r]:i[0]}}r.fields?.elementSize!==void 0&&(t[e+`:elementSize`]=r.fields.elementSize),e.startsWith(`primvars:`)&&r.fields?.typeName!==void 0&&(t[e+`:typeName`]=r.fields.typeName)}}_buildGeomPrimitive(e,n,r){let i=this._getAttributes(e),a=e.split(`/`).pop(),o;switch(r){case`Cube`:{let e=i.size||2;o=new g(e,e,e);break}case`Sphere`:o=new t(i.radius||1,32,16);break;case`Cylinder`:{let e=i.height||2,t=i.radius||1;o=new M(t,t,e,32);break}case`Cone`:{let e=i.height||2;o=new S(i.radius||1,e,32);break}case`Capsule`:{let e=i.height||1;o=new _(i.radius||.5,e,16,32);break}}let s=i.axis||`Z`;s===`X`?o.rotateZ(-Math.PI/2):s===`Z`&&o.rotateX(Math.PI/2);let c=this._buildMaterial(e,n.fields),l=new y(o,c);return l.name=a,this.applyTransform(l,n.fields,i),l}_buildMesh(e,t){let n=this._getAttributes(e),r=n[`primvars:skel:jointIndices`],i=n[`primvars:skel:jointWeights`],a=r&&i&&r.length>0&&i.length>0,o=this._getGeomSubsets(e),s,c;if(o.length>0){s=this._buildGeometryWithSubsets(n,o,a);let r=this._getMaterialPath(e,t.fields);c=o.map(e=>{let t=e.materialPath||r;return this._buildMaterialForPath(t)})}else s=this._buildGeometry(e,n,a),c=this._buildMaterial(e,t.fields);let l=n[`primvars:displayColor`];if(l&&l.length>=3){let e=e=>{e.color&&e.color.r===1&&e.color.g===1&&e.color.b===1&&!e.map&&e.color.setRGB(l[0],l[1],l[2],N)};Array.isArray(c)?c.forEach(e):e(c)}let u=n[`primvars:displayOpacity`];if(u&&u.length===1&&o.length===0){let e=u[0],t=t=>{e<1&&t.opacity===1&&t.transparent===!1&&(t.opacity=e,t.transparent=!0)};Array.isArray(c)?c.forEach(t):t(c)}let f;if(a){f=new d(s,c);let t=this.specsByPath[e+`.skel:skeleton`];t||=this.specsByPath[e+`.rel skel:skeleton`];let r=null;t&&(t.fields.targetPaths&&t.fields.targetPaths.length>0?r=t.fields.targetPaths[0]:t.fields.default&&(r=t.fields.default.replace(/<|>/g,``)));let i=n[`skel:joints`],a=n[`primvars:skel:geomBindTransform`];this.skinnedMeshes.push({mesh:f,skeletonPath:r,path:e,localJoints:i,geomBindTransform:a})}else f=new y(s,c);return f.name=e.split(`/`).pop(),this.applyTransform(f,t.fields,n),f}_buildCamera(e){let t=this._getAttributes(e),n=t.projection,r=typeof n==`string`?n.toLowerCase():Q.projection,i=t.clippingRange||Q.clippingRange,a=Math.max(2**-52,this._parseNumber(i[0],Q.clippingRange[0])),o=Math.max(a+2**-52,this._parseNumber(i[1],Q.clippingRange[1])),s=this._parseNumber(t.horizontalAperture,Q.horizontalAperture),c=this._parseNumber(t.verticalAperture,Q.verticalAperture),l=this._parseNumber(t.horizontalApertureOffset,Q.horizontalApertureOffset),u=this._parseNumber(t.verticalApertureOffset,Q.verticalApertureOffset),d=this._parseNumber(t.focalLength,Q.focalLength),f=this._parseNumber(t.focusDistance,Q.focusDistance),p=this._parseNumber(t.fStop,Q.fStop),m;if(r===`orthographic`){let e=s/10,t=c/10,n=l/10,r=u/10;m=new x(n-e*.5,n+e*.5,r+t*.5,r-t*.5,a,o)}else{let e=Math.max(2**-52,c),t=Math.max(2**-52,d),n=s/e;m=new k(2*Math.atan(e/(2*t))*180/Math.PI,n,a,o),m.filmGauge=Math.max(s,c),m.filmOffset=l,m.focus=f,m.setFocalLength(t),u!==0&&(m.userData.verticalApertureOffset=u)}return m.userData.fStop=p,m.userData.usdProjection=r,m}_buildLight(e,t){let n=this._getAttributes(e),r=this._parseNumber(n[`inputs:intensity`],1),i=n[`inputs:color`]||[1,1,1],a=n[`inputs:enableColorTemperature`]===!0,o=this._parseNumber(n[`inputs:colorTemperature`],6500),s=new O(i[0],i[1],i[2]);if(a){let e=this._colorTemperature(o);s.multiply(e)}let c;switch(t){case`DistantLight`:c=new P(s,r);break;case`SphereLight`:{let e=this._parseNumber(n[`shaping:cone:angle`],0);c=e>0?new u(s,r,0,e*Math.PI/180,this._parseNumber(n[`shaping:cone:softness`],0)):new C(s,r);break}case`RectLight`:c=new m(s,r,this._parseNumber(n[`inputs:width`],1),this._parseNumber(n[`inputs:height`],1));break;case`DiskLight`:{let e=this._parseNumber(n[`inputs:radius`],.5)*2;c=new m(s,r,e,e);break}}return c}_colorTemperature(e){let t=e/100,n,r,i;return t<=66?(n=1,r=.3900815787690196*Math.log(t)-.6318414437886275):(n=1.292936186062745*(t-60)**-.1332047592,r=1.1298908608952942*(t-60)**-.0755148492),i=t>=66?1:t<=19?0:.543206789110196*Math.log(t-10)-1.19625408914,new O(Math.min(Math.max(n,0),1),Math.min(Math.max(r,0),1),Math.min(Math.max(i,0),1))}_parseNumber(e,t){let n=Number(e);return Number.isFinite(n)?n:t}_getGeomSubsets(e){let t=[],n=this.geomSubsetsByMeshPath.get(e);if(!n)return t;for(let e of n){let n=this._getAttributes(e).indices;if(!n||n.length===0)continue;let r=this._getMaterialBindingTarget(e);t.push({name:e.split(`/`).pop(),indices:n,materialPath:r})}return t}_getMaterialBindingTarget(e){let t=e+`.material:binding`,n=this.specsByPath[t];if(n?.fields?.targetPaths?.length>0)return n.fields.targetPaths[0];let r=e.split(`/`);for(let e=1;e<r.length;e++){let t=r.slice(0,e+1).join(`/`),n=r.slice(e+1).join(`/`),i=this._getVariantPaths(t);for(let e of i){let t=n?e+`/`+n+`.material:binding`:e+`.material:binding`,r=this.specsByPath[t];if(r?.fields?.targetPaths?.length>0)return r.fields.targetPaths[0]}}return null}_buildGeometry(e,t,n=!1){let r=new j,i=t.points;if(!i||i.length===0)return r;let a=t.faceVertexIndices,o=t.faceVertexCounts,s=t[`primvars:arnold:polygon_holes`],c=this._buildHoleMap(s),l=a,u=null;if(o&&o.length>0){let e=this._triangulateIndicesWithPattern(a,o,i,c);l=e.indices,u=e.pattern}let d=i;l&&l.length>0&&(d=this._expandAttribute(i,l,3)),r.setAttribute(`position`,new T(new Float32Array(d),3));let f=t.normals||t[`primvars:normals`],p=t[`normals:indices`]||t[`primvars:normals:indices`];if(f&&f.length>0){let e=f;if(p&&p.length>0&&u){let t=this._applyTriangulationPattern(p,u);e=this._expandAttribute(f,t,3)}else if(f.length===i.length)l&&l.length>0&&(e=this._expandAttribute(f,l,3));else if(u){let t=this._applyTriangulationPattern(Array.from({length:f.length/3},(e,t)=>t),u);e=this._expandAttribute(f,t,3)}r.setAttribute(`normal`,new T(new Float32Array(e),3))}else{let e=this._computeVertexNormals(i,l);r.setAttribute(`normal`,new T(new Float32Array(this._expandAttribute(e,l,3)),3))}let{uvs:m,uvIndices:h}=this._findUVPrimvar(t),g=a?a.length:0;if(m&&m.length>0){let e=m;if(h&&h.length>0&&u){let t=this._applyTriangulationPattern(h,u);e=this._expandAttribute(m,t,2)}else if(l&&m.length/2==i.length/3)e=this._expandAttribute(m,l,2);else if(u&&m.length/2===g){let t=this._applyTriangulationPattern(Array.from({length:g},(e,t)=>t),u);e=this._expandAttribute(m,t,2)}r.setAttribute(`uv`,new T(new Float32Array(e),2))}let{uvs2:_,uv2Indices:v}=this._findUV2Primvar(t);if(_&&_.length>0){let e=_;if(v&&v.length>0&&u){let t=this._applyTriangulationPattern(v,u);e=this._expandAttribute(_,t,2)}else if(l&&_.length/2==i.length/3)e=this._expandAttribute(_,l,2);else if(u&&_.length/2===g){let t=this._applyTriangulationPattern(Array.from({length:g},(e,t)=>t),u);e=this._expandAttribute(_,t,2)}r.setAttribute(`uv1`,new T(new Float32Array(e),2))}if(n){let e=t[`primvars:skel:jointIndices`],n=t[`primvars:skel:jointWeights`],i=t[`primvars:skel:jointIndices:elementSize`]||4;if(e&&n){let t=d.length/3,a,o;l&&l.length>0?(a=this._expandAttribute(e,l,i),o=this._expandAttribute(n,l,i)):(a=e,o=n);let s=new Uint16Array(t*4),c=new Float32Array(t*4);this._selectTopWeights(a,o,i,t,s,c),r.setAttribute(`skinIndex`,new T(s,4)),r.setAttribute(`skinWeight`,new T(c,4))}}return r}_buildGeometryWithSubsets(e,t,n=!1){let r=new j,i=e.points;if(!i||i.length===0)return r;let a=e.faceVertexIndices,o=e.faceVertexCounts;if(!o||o.length===0)return r;let s=e[`primvars:arnold:polygon_holes`],c=this._buildHoleMap(s),l=c.holeFaces,u=c.parentToHoles,{uvs:d,uvIndices:f}=this._findUVPrimvar(e),{uvs2:p,uv2Indices:m}=this._findUV2Primvar(e),h=e.normals||e[`primvars:normals`],g=e[`normals:indices`]||e[`primvars:normals:indices`],_=n?e[`primvars:skel:jointIndices`]:null,v=n?e[`primvars:skel:jointWeights`]:null,y=e[`primvars:skel:jointIndices:elementSize`]||4,b=[],x=0;for(let e=0;e<o.length;e++){if(b.push(x),l.has(e))continue;let t=o[e],n=u.get(e);if(n&&n.length>0){let e=t;for(let t of n)e+=o[t];x+=e-2}else t>=3&&(x+=t-2)}let S=new Int32Array(x).fill(-1);for(let e=0;e<t.length;e++){let n=t[e];for(let t=0;t<n.indices.length;t++){let r=n.indices[t];if(r>=o.length)continue;let i=b[r],a=o[r]-2;for(let t=0;t<a;t++)S[i+t]=e}}let C=[];for(let e=0;e<x;e++)C.push({original:e,subset:S[e]});C.sort((e,t)=>e.subset-t.subset);let w=[],E=C.length>0?C[0].subset:-1,D=0;for(let e=0;e<C.length;e++)C[e].subset!==E&&(E>=0&&w.push({start:D*3,count:(e-D)*3,materialIndex:E}),E=C[e].subset,D=e);E>=0&&C.length>D&&w.push({start:D*3,count:(C.length-D)*3,materialIndex:E});for(let e of w)r.addGroup(e.start,e.count,e.materialIndex);let{indices:O,pattern:k}=this._triangulateIndicesWithPattern(a,o,i,c),A=o.reduce((e,t)=>e+t,0),M=d&&!f&&d.length/2===A||p&&!m&&p.length/2===A?this._applyTriangulationPattern(Array.from({length:A},(e,t)=>t),k):null,N=f?this._applyTriangulationPattern(f,k):d&&d.length/2===A?M:null,P=m?this._applyTriangulationPattern(m,k):p&&p.length/2===A?M:null,F=h&&g&&g.length>0,I=h&&h.length/3===A,L=F?this._applyTriangulationPattern(g,k):I?this._applyTriangulationPattern(Array.from({length:A},(e,t)=>t),k):null,R=!h&&O.length>0?this._computeVertexNormals(i,O):null,z=x*3,B=new Float32Array(z*3),V=d?new Float32Array(z*2):null,H=p?new Float32Array(z*2):null,U=h||R?new Float32Array(z*3):null,W=_?new Uint16Array(z*y):null,G=v?new Float32Array(z*y):null;for(let e=0;e<C.length;e++){let t=C[e].original;for(let n=0;n<3;n++){let r=t*3+n,a=e*3+n,o=O[r];if(B[a*3]=i[o*3],B[a*3+1]=i[o*3+1],B[a*3+2]=i[o*3+2],V&&d)if(N){let e=N[r];V[a*2]=d[e*2],V[a*2+1]=d[e*2+1]}else d.length/2==i.length/3&&(V[a*2]=d[o*2],V[a*2+1]=d[o*2+1]);if(H&&p)if(P){let e=P[r];H[a*2]=p[e*2],H[a*2+1]=p[e*2+1]}else p.length/2==i.length/3&&(H[a*2]=p[o*2],H[a*2+1]=p[o*2+1]);if(U)if(h&&L){let e=L[r];U[a*3]=h[e*3],U[a*3+1]=h[e*3+1],U[a*3+2]=h[e*3+2]}else h&&h.length===i.length?(U[a*3]=h[o*3],U[a*3+1]=h[o*3+1],U[a*3+2]=h[o*3+2]):R&&(U[a*3]=R[o*3],U[a*3+1]=R[o*3+1],U[a*3+2]=R[o*3+2]);if(W&&G&&_&&v)for(let e=0;e<y;e++)W[a*y+e]=_[o*y+e]||0,G[a*y+e]=v[o*y+e]||0}}if(r.setAttribute(`position`,new T(B,3)),V&&r.setAttribute(`uv`,new T(V,2)),H&&r.setAttribute(`uv1`,new T(H,2)),r.setAttribute(`normal`,new T(U,3)),W&&G){let e=new Uint16Array(z*4),t=new Float32Array(z*4);this._selectTopWeights(W,G,y,z,e,t),r.setAttribute(`skinIndex`,new T(e,4)),r.setAttribute(`skinWeight`,new T(t,4))}return r}_selectTopWeights(e,t,n,r,i,a){if(n<=4){for(let o=0;o<r;o++)for(let r=0;r<4;r++)r<n?(i[o*4+r]=e[o*n+r]||0,a[o*4+r]=t[o*n+r]||0):(i[o*4+r]=0,a[o*4+r]=0);return}let o=new Uint32Array(n);for(let s=0;s<r;s++){let r=s*n;for(let e=0;e<n;e++)o[e]=e;for(let e=0;e<4;e++){let i=e,a=t[r+o[e]]||0;for(let s=e+1;s<n;s++){let e=t[r+o[s]]||0;e>a&&(a=e,i=s)}if(i!==e){let t=o[e];o[e]=o[i],o[i]=t}}let c=0;for(let e=0;e<4;e++)c+=t[r+o[e]]||0;for(let n=0;n<4;n++){let l=o[n];c>0?(i[s*4+n]=e[r+l]||0,a[s*4+n]=(t[r+l]||0)/c):(i[s*4+n]=0,a[s*4+n]=0)}}}_findUVPrimvar(e){for(let t in e){if(!t.startsWith(`primvars:`)||t.endsWith(`:typeName`)||t.endsWith(`:elementSize`)||t.endsWith(`:indices`)||t.includes(`skel:`))continue;let n=e[t+`:typeName`];if(n&&n.includes(`texCoord`))return{uvs:e[t],uvIndices:e[t+`:indices`]}}return{uvs:e[`primvars:st`]||e[`primvars:UVMap`],uvIndices:e[`primvars:st:indices`]}}_findUV2Primvar(e){return{uvs2:e[`primvars:st1`],uv2Indices:e[`primvars:st1:indices`]}}_buildHoleMap(e){if(!e||e.length===0)return{parentToHoles:new Map,holeFaces:new Set};let t=new Map,n=new Set;for(let r=0;r<e.length;r+=2){let i=e[r],a=e[r+1];n.add(i),t.has(a)||t.set(a,[]),t.get(a).push(i)}return{parentToHoles:t,holeFaces:n}}_triangulateIndicesWithPattern(e,t,n=null,r=null){let i=[],a=[],o=[],s=0;for(let e=0;e<t.length;e++)o.push(s),s+=t[e];let c=r?.parentToHoles||new Map,l=r?.holeFaces||new Set,u=0;for(let r=0;r<t.length;r++){let s=t[r];if(l.has(r)){u+=s;continue}let d=c.get(r);if(d&&d.length>0&&n&&n.length>0){let r=new Map,c=[];for(let t=0;t<s;t++){let n=e[u+t];c.push(n),r.set(n,u+t)}let l=[];for(let n of d){let i=o[n],a=t[n],s=[];for(let t=0;t<a;t++){let n=e[i+t];s.push(n),r.set(n,i+t)}l.push(s)}let f=this._triangulateNGonWithHoles(c,l,n);for(let e of f)i.push(e[0],e[1],e[2]),a.push(r.get(e[0]),r.get(e[1]),r.get(e[2]))}else if(s===3)i.push(e[u],e[u+1],e[u+2]),a.push(u,u+1,u+2);else if(s===4)i.push(e[u],e[u+1],e[u+2],e[u],e[u+2],e[u+3]),a.push(u,u+1,u+2,u,u+2,u+3);else if(s>4)if(n&&n.length>0){let t=[];for(let n=0;n<s;n++)t.push(e[u+n]);let r=this._triangulateNGon(t,n);for(let e of r)i.push(e[0],e[1],e[2]),a.push(u+t.indexOf(e[0]),u+t.indexOf(e[1]),u+t.indexOf(e[2]))}else for(let t=1;t<s-1;t++)i.push(e[u],e[u+t],e[u+t+1]),a.push(u,u+t,u+t+1);u+=s}return{indices:i,pattern:a}}_applyTriangulationPattern(e,t){let n=[];for(let r=0;r<t.length;r++)n.push(e[t[r]]);return n}_triangulateNGon(e,t){let r=[],i=[];for(let r of e)i.push(new n(t[r*3],t[r*3+1],t[r*3+2]));let a=new n;for(let e=0;e<i.length;e++){let t=i[e],n=i[(e+1)%i.length];a.x+=(t.y-n.y)*(t.z+n.z),a.y+=(t.z-n.z)*(t.x+n.x),a.z+=(t.x-n.x)*(t.y+n.y)}a.normalize();let o=new n,c=new n;Math.abs(a.y)>.9?o.set(1,0,0):o.set(0,1,0),c.crossVectors(a,o).normalize(),o.crossVectors(c,a).normalize();for(let e of i)r.push(new I(e.dot(o),e.dot(c)));let l=s.triangulateShape(r,[]),u=[];for(let t of l)u.push([e[t[0]],e[t[1]],e[t[2]]]);return u}_triangulateNGonWithHoles(e,t,r){let i=[];for(let t of e)i.push(new n(r[t*3],r[t*3+1],r[t*3+2]));let a=new n;for(let e=0;e<i.length;e++){let t=i[e],n=i[(e+1)%i.length];a.x+=(t.y-n.y)*(t.z+n.z),a.y+=(t.z-n.z)*(t.x+n.x),a.z+=(t.x-n.x)*(t.y+n.y)}a.normalize();let o=new n,c=new n;Math.abs(a.y)>.9?o.set(1,0,0):o.set(0,1,0),c.crossVectors(a,o).normalize(),o.crossVectors(c,a).normalize();let l=[];for(let e of i)l.push(new I(e.dot(o),e.dot(c)));let u=[];for(let e of t){let t=[];for(let i of e){let e=new n(r[i*3],r[i*3+1],r[i*3+2]);t.push(new I(e.dot(o),e.dot(c)))}u.push(t)}let d=[...e];for(let e of t)d.push(...e);let f=s.triangulateShape(l,u),p=[];for(let e of f)p.push([d[e[0]],d[e[1]],d[e[2]]]);return p}_triangulateIndices(e,t){let n=[],r=0;for(let i=0;i<t.length;i++){let a=t[i];if(a===3)n.push(e[r],e[r+1],e[r+2]);else if(a===4)n.push(e[r],e[r+1],e[r+2],e[r],e[r+2],e[r+3]);else if(a>4)for(let t=1;t<a-1;t++)n.push(e[r],e[r+t],e[r+t+1]);r+=a}return n}_expandAttribute(e,t,n){let r=Array(t.length*n);for(let i=0;i<t.length;i++){let a=t[i];for(let t=0;t<n;t++)r[i*n+t]=e[a*n+t]}return r}_computeVertexNormals(e,t){let n=e.length/3,r=new Float32Array(n*3);for(let n=0;n<t.length;n+=3){let i=t[n],a=t[n+1],o=t[n+2],s=e[i*3],c=e[i*3+1],l=e[i*3+2],u=e[a*3],d=e[a*3+1],f=e[a*3+2],p=e[o*3],m=e[o*3+1],h=e[o*3+2],g=u-s,_=d-c,v=f-l,y=p-s,b=m-c,x=h-l,S=_*x-v*b,C=v*y-g*x,w=g*b-_*y;r[i*3]+=S,r[i*3+1]+=C,r[i*3+2]+=w,r[a*3]+=S,r[a*3+1]+=C,r[a*3+2]+=w,r[o*3]+=S,r[o*3+1]+=C,r[o*3+2]+=w}for(let e=0;e<n;e++){let t=r[e*3],n=r[e*3+1],i=r[e*3+2],a=Math.sqrt(t*t+n*n+i*i);a>0&&(r[e*3]/=a,r[e*3+1]/=a,r[e*3+2]/=a)}return r}_getMaterialPath(e,t){let n=null,r=t[`material:binding`];return r&&(n=Array.isArray(r)?r[0]:r),n||=this._getMaterialBindingTarget(e),n}_buildMaterial(e,t){let n=new w,r=null,i=t[`material:binding`];if(i&&(r=Array.isArray(i)?i[0]:i),r||=this._getMaterialBindingTarget(e),!r){let t=[],n=e+`/`;for(let e in this.specsByPath){if(!e.startsWith(n)||!e.endsWith(`.material:binding`))continue;let r=this.specsByPath[e];if(!r)continue;let i=r.fields.targetPaths;i&&i.length>0&&t.push(i[0])}t.length>0&&(r=this._pickBestMaterial(t))}if(!r){let t=`/`+e.split(`/`)[1],n=this.materialsByRoot.get(t);if(n){for(let e of n)if(e.startsWith(t+`/Looks/`)||e.startsWith(t+`/Materials/`)){r=e;break}}}return r&&this._applyMaterial(n,r),n}_buildMaterialForPath(e){let t=new w;return e&&this._applyMaterial(t,e),t}_applyMaterialBinding(e,t){let n=t+`.material:binding`,r=this.specsByPath[n];if(!r)return;let i=null,a=r.fields?.targetPaths||r.fields?.default;if(a&&(i=Array.isArray(a)?a[0]:a),!i)return;i=String(i).replace(/^<|>$/g,``);let o=new w;this._applyMaterial(o,i),e.material=o}_pickBestMaterial(e){for(let t of e){let e=this.shadersByMaterialPath.get(t);if(e)for(let n of e){let e=this._getAttributes(n);if(e[`info:id`]===`UsdUVTexture`&&e[`inputs:file`])return t}}return e[0]}_applyMaterial(e,t){if(!this.specsByPath[t])return;let n=this.shadersByMaterialPath.get(t);if(n)for(let t of n){let n=this.specsByPath[t];if(!n)continue;let r=this._getAttributes(t)[`info:id`]||n.fields[`info:id`];r===`UsdPreviewSurface`||r===`ND_UsdPreviewSurface_surfaceshader`?this._applyPreviewSurface(e,t):r===`arnold:openpbr_surface`&&this._applyOpenPBRSurface(e,t)}}_applyTextureOrValue(e,t,n,r,i,a,o,s){let c=t+`.`+r,l=this.specsByPath[c];if(l&&l.fields.connectionPaths&&l.fields.connectionPaths.length>0){let t=s===this._getTextureFromOpenPBRConnection?l.fields.connectionPaths:[l.fields.connectionPaths[0]];for(let n of t){let t=s.call(this,n);if(t)return t.colorSpace=a,e[i]=t,!0}}return n[r]!==void 0&&o&&o(n[r]),!1}_applyPreviewSurface(e,t){let n=this._getAttributes(t),r=(r,i,a,o)=>this._applyTextureOrValue(e,t,n,r,i,a,o,this._getTextureFromConnection),i=e=>{let n=t+`.`+e;return this.specsByPath[n]};if(r(`inputs:diffuseColor`,`map`,N,t=>{Array.isArray(t)&&t.length>=3&&e.color.setRGB(t[0],t[1],t[2],N)}),e.map&&e.map.userData.scale){let t=e.map.userData.scale;Array.isArray(t)&&t.length>=3&&e.color.setRGB(t[0],t[1],t[2],N)}if(r(`inputs:emissiveColor`,`emissiveMap`,N,t=>{Array.isArray(t)&&t.length>=3&&e.emissive.setRGB(t[0],t[1],t[2],N)}),e.emissiveMap)if(e.emissiveMap.userData.scale){let t=e.emissiveMap.userData.scale;Array.isArray(t)&&t.length>=3&&e.emissive.setRGB(t[0],t[1],t[2],N)}else e.emissive.set(16777215);if(r(`inputs:normal`,`normalMap`,``,null),e.normalMap&&e.normalMap.userData.scale){let t=e.normalMap.userData.scale;e.normalScale=new I(t[0],t[1])}if(r(`inputs:roughness`,`roughnessMap`,``,t=>{e.roughness=t})&&(e.roughness=1),r(`inputs:metallic`,`metalnessMap`,``,t=>{e.metalness=t})&&(e.metalness=1),r(`inputs:occlusion`,`aoMap`,``,null),n[`inputs:ior`]!==void 0&&(e.ior=n[`inputs:ior`]),r(`inputs:specularColor`,`specularColorMap`,N,t=>{Array.isArray(t)&&t.length>=3&&e.specularColor.setRGB(t[0],t[1],t[2],N)}),e.specularColorMap&&e.specularColorMap.userData.scale){let t=e.specularColorMap.userData.scale;Array.isArray(t)&&t.length>=3&&e.specularColor.setRGB(t[0],t[1],t[2],N)}n[`inputs:clearcoat`]!==void 0&&(e.clearcoat=n[`inputs:clearcoat`]),n[`inputs:clearcoatRoughness`]!==void 0&&(e.clearcoatRoughness=n[`inputs:clearcoatRoughness`]);let a=n[`inputs:opacityThreshold`]===void 0?0:n[`inputs:opacityThreshold`];if(i(`inputs:opacity`)?.fields?.connectionPaths?.length>0)a>0?(e.alphaTest=a,e.transparent=!1):e.transparent=!0;else{let t=n[`inputs:opacity`]===void 0?1:n[`inputs:opacity`];t<1&&(e.transparent=!0,e.opacity=t)}}_applyOpenPBRSurface(e,t){let n=this._getAttributes(t),r=(r,i,a,o)=>this._applyTextureOrValue(e,t,n,r,i,a,o,this._getTextureFromOpenPBRConnection);if(r(`inputs:base_color`,`map`,N,t=>{Array.isArray(t)&&t.length>=3&&e.color.setRGB(t[0],t[1],t[2],N)}),e.map&&e.map.userData.scale){let t=e.map.userData.scale;Array.isArray(t)&&t.length>=3&&e.color.setRGB(t[0],t[1],t[2],N)}r(`inputs:base_metalness`,`metalnessMap`,``,t=>{typeof t==`number`&&(e.metalness=t)}),r(`inputs:specular_roughness`,`roughnessMap`,``,t=>{typeof t==`number`&&(e.roughness=t)});let i=r(`inputs:emission_color`,`emissiveMap`,N,t=>{Array.isArray(t)&&t.length>=3&&e.emissive.setRGB(t[0],t[1],t[2],N)}),a=n[`inputs:emission_luminance`];a!==void 0&&a>0&&(i?e.emissiveIntensity=a:e.emissive.multiplyScalar(a));let o=n[`inputs:transmission_weight`];if(o!==void 0&&o>0){e.transmission=o;let t=n[`inputs:transmission_depth`];t!==void 0&&(e.thickness=t);let r=n[`inputs:transmission_color`];r!==void 0&&Array.isArray(r)&&(e.attenuationColor.setRGB(r[0],r[1],r[2]),e.attenuationDistance=t||1)}let s=n[`inputs:geometry_opacity`];s!==void 0&&s<1&&(e.opacity=s,e.transparent=!0);let c=n[`inputs:specular_ior`];c!==void 0&&(e.ior=c);let l=n[`inputs:coat_weight`];if(l!==void 0&&l>0){e.clearcoat=l;let t=n[`inputs:coat_roughness`];t!==void 0&&(e.clearcoatRoughness=t)}let u=n[`inputs:thin_film_weight`];if(u!==void 0&&u>0){e.iridescence=u;let t=n[`inputs:thin_film_ior`];t!==void 0&&(e.iridescenceIOR=t);let r=n[`inputs:thin_film_thickness`];if(r!==void 0){let t=r*1e3;e.iridescenceThicknessRange=[t,t]}}let d=n[`inputs:specular_weight`];d!==void 0&&(e.specularIntensity=d);let f=n[`inputs:specular_color`];f!==void 0&&Array.isArray(f)&&e.specularColor.setRGB(f[0],f[1],f[2]);let p=n[`inputs:specular_roughness_anisotropy`];p!==void 0&&p>0&&(e.anisotropy=p),r(`inputs:geometry_normal`,`normalMap`,``,null)}_getTextureFromOpenPBRConnection(e){let t=e.replace(/<|>/g,``),n=t.split(`.`)[0],r=this.specsByPath[n];if(!r)return null;let i=this._getAttributes(n),a=i[`info:id`]||r.fields[`info:id`];if(r.fields.typeName===`NodeGraph`){let e=t.split(`.`)[1],r=n+`.`+e,i=this.specsByPath[r];return i?.fields?.connectionPaths?.length>0?this._getTextureFromOpenPBRConnection(i.fields.connectionPaths[0]):null}if(a===`arnold:image`){let e=i[`inputs:filename`];return e?this._loadTextureFromPath(e):null}if(a&&a.startsWith(`ND_image_`)){let e=i[`inputs:file`];return e?this._loadTextureFromPath(e):null}if(a===`MayaND_fileTexture_color4`){let e=n+`.inputs:inColor`,t=this.specsByPath[e];return t?.fields?.connectionPaths?.length>0?this._getTextureFromOpenPBRConnection(t.fields.connectionPaths[0]):null}if(a&&a.startsWith(`ND_convert_`)){let e=n+`.inputs:in`,t=this.specsByPath[e];return t?.fields?.connectionPaths?.length>0?this._getTextureFromOpenPBRConnection(t.fields.connectionPaths[0]):null}if(a===`arnold:bump2d`){let e=n+`.inputs:bump_map`,t=this.specsByPath[e];return t?.fields?.connectionPaths?.length>0?this._getTextureFromOpenPBRConnection(t.fields.connectionPaths[0]):null}if(a===`arnold:color_correct`){let e=n+`.inputs:input`,t=this.specsByPath[e];return t?.fields?.connectionPaths?.length>0?this._getTextureFromOpenPBRConnection(t.fields.connectionPaths[0]):null}let o=n.substring(0,n.lastIndexOf(`/`));if(o){let e=this.specsByPath[o];if(e){let t=this._getAttributes(o);if((t[`info:id`]||e.fields[`info:id`])===`arnold:image`){let e=t[`inputs:filename`];if(e)return this._loadTextureFromPath(e)}}}return null}_loadTextureFromPath(e){if(!e)return null;if(this.textureCache[e])return this.textureCache[e];let t=this._loadTexture(e,null,null);return t&&(this.textureCache[e]=t),t}_getTextureFromConnection(e){let t=e.split(`.`)[0],n=this.specsByPath[t];if(!n)return null;let r=this._getAttributes(t);if((r[`info:id`]||n.fields[`info:id`])!==`UsdUVTexture`)return null;let i=r[`inputs:file`];if(!i)return null;let a=null,o=0,s=t+`.inputs:st`,c=this.specsByPath[s];if(c?.fields?.connectionPaths?.length>0){let e=c.fields.connectionPaths[0].replace(/<|>/g,``).split(`.`)[0],t=this.specsByPath[e];if(t){let n=this._getAttributes(e),r=n[`info:id`]||t.fields[`info:id`];if(r===`UsdTransform2d`){a=n;let t=e+`.inputs:in`,r=this.specsByPath[t];if(r?.fields?.connectionPaths?.length>0){let e=r.fields.connectionPaths[0].replace(/<|>/g,``).split(`.`)[0],t=this._getAttributes(e)[`inputs:varname`];t===`st1`?o=1:t===`st2`&&(o=2)}}else if(r===`UsdPrimvarReader_float2`){let e=n[`inputs:varname`];e===`st1`?o=1:e===`st2`&&(o=2)}}}let l=r[`inputs:scale`],u=r[`inputs:bias`],d=i;if(l&&(d+=`:s`+l.join(`,`)),u&&(d+=`:b`+u.join(`,`)),this.textureCache[d])return this.textureCache[d];let f=this._loadTexture(i,r,a);return f&&(l&&(f.userData.scale=l),u&&(f.userData.bias=u),o!==0&&(f.channel=o),this.textureCache[d]=f),f}_applyTextureTransforms(e,t){if(!t)return;let n=t[`inputs:scale`];n&&Array.isArray(n)&&n.length>=2&&e.repeat.set(n[0],n[1]);let r=t[`inputs:translation`];r&&Array.isArray(r)&&r.length>=2&&e.offset.set(r[0],r[1]);let i=t[`inputs:rotation`];typeof i==`number`&&(e.rotation=i*Math.PI/180)}_loadTexture(e,t,n){let r=e;r.startsWith(`@`)&&(r=r.slice(1)),r.endsWith(`@`)&&(r=r.slice(0,-1));let i=this._resolveFilePath(r),a=this.assets[i];if(a||=this.assets[r],!a){let e=r.split(`/`).pop();for(let r in this.assets)if(r.endsWith(e)||r.endsWith(`/`+e))return this._createTextureFromData(this.assets[r],t,n);if(this.manager){let r=this.manager.resolveURL(e);if(r!==e)return this._createTextureFromData(r,t,n)}return console.warn(`USDLoader: Texture not found:`,r),null}return this._createTextureFromData(a,t,n)}_createTextureFromData(e,t,n){if(!e)return null;let r=this,i=new f,a;if(typeof e==`string`)a=e;else if(e instanceof Uint8Array||e instanceof ArrayBuffer){let t=new Blob([e]);a=URL.createObjectURL(t)}else return null;let o=new Image;return o.onload=function(){i.image=o,t&&(i.wrapS=r._getWrapMode(t[`inputs:wrapS`]),i.wrapT=r._getWrapMode(t[`inputs:wrapT`])),r._applyTextureTransforms(i,n),i.needsUpdate=!0,typeof e!=`string`&&URL.revokeObjectURL(a)},o.src=a,i}_getWrapMode(e){return e===`repeat`?i:e===`mirror`?D:e===`clamp`?b:i}_buildSkeleton(t){let n=this._getAttributes(t),r=n.joints;if(!r||r.length===0)return null;let i=n.bindTransforms,o=n.restTransforms,s=this._flattenMatrixArray(i,r.length),c=this._flattenMatrixArray(o,r.length),l=[],u={},d=[];for(let t=0;t<r.length;t++){let n=r[t],i=n.split(`/`).pop(),a=new E;if(a.name=i,l.push(a),u[n]={bone:a,index:t},s&&s.length>=(t+1)*16){let n=new e,r=s.slice(t*16,(t+1)*16);n.set(r[0],r[4],r[8],r[12],r[1],r[5],r[9],r[13],r[2],r[6],r[10],r[14],r[3],r[7],r[11],r[15]);let i=n.clone().invert();d.push(i)}else d.push(new e)}for(let e=0;e<r.length;e++){let t=r[e].split(`/`);if(t.length>1){let n=u[t.slice(0,-1).join(`/`)];n&&n.bone.add(l[e])}}if(c&&c.length>=r.length*16)for(let t=0;t<r.length;t++){let n=new e,r=c.slice(t*16,(t+1)*16);n.set(r[0],r[4],r[8],r[12],r[1],r[5],r[9],r[13],r[2],r[6],r[10],r[14],r[3],r[7],r[11],r[15]),n.decompose(l[t].position,l[t].quaternion,l[t].scale)}let f=l.filter(e=>!e.parent||!e.parent.isBone),p=this.specsByPath[t+`.skel:animationSource`],m=null;return p&&p.fields.targetPaths&&p.fields.targetPaths.length>0&&(m=p.fields.targetPaths[0]),{skeleton:new a(l,d),joints:r,rootBones:f,animationPath:m,path:t}}_bindSkeletons(){for(let t of this.skinnedMeshes){let{mesh:n,skeletonPath:r,localJoints:i,geomBindTransform:a}=t,o=null;if(r&&this.skeletons[r]&&(o=this.skeletons[r]),!o){for(let e in this.skeletons)if(r&&(r.includes(e)||e.includes(r))){o=this.skeletons[e];break}}if(!o){let e=Object.keys(this.skeletons);e.length>0&&(o=this.skeletons[e[0]])}if(!o){console.warn(`USDComposer: No skeleton found for skinned mesh`,n.name);continue}let{skeleton:s,rootBones:c,joints:l}=o;if(i&&i.length>0){let e=n.geometry.attributes.skinIndex;if(e){let t=[];for(let e=0;e<i.length;e++){let n=i[e],r=l.indexOf(n);t[e]=r>=0?r:0}let n=e.array;for(let e=0;e<n.length;e++){let r=n[e];r<t.length&&(n[e]=t[r])}}}for(let e of c)n.add(e);let u=new e;if(a&&a.length===16){let e=a;u.set(e[0],e[4],e[8],e[12],e[1],e[5],e[9],e[13],e[2],e[6],e[10],e[14],e[3],e[7],e[11],e[15])}n.bind(s,u)}}_buildAnimations(){let e=[];for(let t in this.specsByPath){let n=this.specsByPath[t];if(n.specType!==Z.Prim||n.fields.typeName!==`SkelAnimation`)continue;let r=this._buildAnimationClip(t);r&&e.push(r)}let t=this._buildTransformAnimations();return t.length>0&&e.push(new A(`TransformAnimation`,-1,t)),e}_buildTransformAnimations(){let t=[];for(let r in this.specsByPath){let i=this.specsByPath[r];if(i.specType!==Z.Prim)continue;let a=i.fields?.typeName;if(a!==`Xform`&&a!==`Scope`&&a!==`Mesh`)continue;let o=r.split(`/`).pop(),s=r+`.xformOp:orient`,l=this.specsByPath[s];if(l?.fields?.timeSamples){let{times:e,values:n}=l.fields.timeSamples,r=[],i=[];for(let t=0;t<e.length;t++){r.push(e[t]/this.fps);let a=n[t];i.push(a[0],a[1],a[2],a[3])}r.length>0&&t.push(new h(o+`.quaternion`,new Float32Array(r),new Float32Array(i)))}let u=r+`.xformOp:rotateXYZ`,d=this.specsByPath[u];if(d?.fields?.timeSamples){let{times:e,values:n}=d.fields.timeSamples,r=[],i=[],a=new p,s=new F;for(let t=0;t<e.length;t++){r.push(e[t]/this.fps);let o=n[t];a.set(o[0]*Math.PI/180,o[1]*Math.PI/180,o[2]*Math.PI/180,`ZYX`),s.setFromEuler(a),i.push(s.x,s.y,s.z,s.w)}r.length>0&&t.push(new h(o+`.quaternion`,new Float32Array(r),new Float32Array(i)))}let f=r+`.xformOp:translate`,m=this.specsByPath[f];if(m?.fields?.timeSamples){let{times:e,values:n}=m.fields.timeSamples,r=[],i=[];for(let t=0;t<e.length;t++){r.push(e[t]/this.fps);let a=n[t];i.push(a[0],a[1],a[2])}r.length>0&&t.push(new c(o+`.position`,new Float32Array(r),new Float32Array(i)))}let g=r+`.xformOp:scale`,_=this.specsByPath[g];if(_?.fields?.timeSamples){let{times:e,values:n}=_.fields.timeSamples,r=[],i=[];for(let t=0;t<e.length;t++){r.push(e[t]/this.fps);let a=n[t];i.push(a[0],a[1],a[2])}r.length>0&&t.push(new c(o+`.scale`,new Float32Array(r),new Float32Array(i)))}let v=i.fields?.properties||[];for(let i of v){if(!i.startsWith(`xformOp:transform`))continue;let a=r+`.`+i,s=this.specsByPath[a];if(!s?.fields?.timeSamples)continue;let{times:l,values:u}=s.fields.timeSamples,d=[],f=[],p=[],m=[],g=[],_=[],v=new e,y=new n,b=new F,x=new n;for(let e=0;e<l.length;e++){let t=u[e];if(!t||t.length<16)continue;let n=l[e]/this.fps;v.set(t[0],t[4],t[8],t[12],t[1],t[5],t[9],t[13],t[2],t[6],t[10],t[14],t[3],t[7],t[11],t[15]),v.decompose(y,b,x),d.push(n),f.push(y.x,y.y,y.z),p.push(n),m.push(b.x,b.y,b.z,b.w),g.push(n),_.push(x.x,x.y,x.z)}d.length>0&&(t.push(new c(o+`.position`,new Float32Array(d),new Float32Array(f))),t.push(new h(o+`.quaternion`,new Float32Array(p),new Float32Array(m))),t.push(new c(o+`.scale`,new Float32Array(g),new Float32Array(_))));break}}return t}_buildAnimationClip(e){let t=this._getAttributes(e).joints;if(!t||t.length===0)return null;let n=[],r=this._getTimeSampledAttribute(e,`rotations`);if(r&&r.times&&r.values){let{times:e,values:i}=r;for(let r=0;r<t.length;r++){let a=t[r].split(`/`).pop(),o=[],s=[];for(let t=0;t<e.length;t++){let n=i[t];if(!n||n.length<(r+1)*4)continue;o.push(e[t]/this.fps);let a=n[r*4+0],c=n[r*4+1],l=n[r*4+2],u=n[r*4+3];s.push(a,c,l,u)}o.length>0&&n.push(new h(a+`.quaternion`,new Float32Array(o),new Float32Array(s)))}}let i=this._getTimeSampledAttribute(e,`translations`);if(i&&i.times&&i.values){let{times:e,values:r}=i;for(let i=0;i<t.length;i++){let a=t[i].split(`/`).pop(),o=[],s=[];for(let t=0;t<e.length;t++){let n=r[t];!n||n.length<(i+1)*3||(o.push(e[t]/this.fps),s.push(n[i*3+0],n[i*3+1],n[i*3+2]))}o.length>0&&n.push(new c(a+`.position`,new Float32Array(o),new Float32Array(s)))}}let a=this._getTimeSampledAttribute(e,`scales`);if(a&&a.times&&a.values){let{times:e,values:r}=a;for(let i=0;i<t.length;i++){let a=t[i].split(`/`).pop(),o=[],s=[];for(let t=0;t<e.length;t++){let n=r[t];!n||n.length<(i+1)*3||(o.push(e[t]/this.fps),s.push(n[i*3+0],n[i*3+1],n[i*3+2]))}o.length>0&&n.push(new c(a+`.scale`,new Float32Array(o),new Float32Array(s)))}}return n.length===0?null:new A(e.split(`/`).pop(),-1,n)}_getTimeSampledAttribute(e,t){let n=e+`.`+t,r=this.specsByPath[n];if(r&&r.fields.timeSamples){let e=r.fields.timeSamples;if(e.times&&e.values)return e}return null}_flattenMatrixArray(e,t){if(!e||e.length===0)return null;if(typeof e[0]==`number`)return e;let n=[];for(let r=0;r<t;r++)for(let t=0;t<4;t++){let i=e[r*4+t];i&&i.length===4?n.push(i[0],i[1],i[2],i[3]):n.push(+(t===0),+(t===1),+(t===2),+(t===3))}return n}},oe=class extends l{constructor(e){super(e)}load(e,t,n,i){let a=this,o=new r(a.manager);o.setPath(a.path),o.setResponseType(`arraybuffer`),o.setRequestHeader(a.requestHeader),o.setWithCredentials(a.withCredentials),o.load(e,function(n){try{t(a.parse(n))}catch(t){i?i(t):console.error(t),a.manager.itemError(e)}},n,i)}parse(e){let t=new V,n=new ie,r=new TextDecoder;function i(e){return e instanceof ArrayBuffer?e:e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}function a(e){let t=e.lastIndexOf(`.`);return t<0||e.lastIndexOf(`/`)>t?``:e.slice(t+1).toLowerCase()}function o(e){let o={};for(let c in e){let l=e[c],u=a(c);if(u===`png`||u===`jpg`||u===`jpeg`||u===`avif`){o[c]=l;continue}u!==`usd`&&u!==`usda`&&u!==`usdc`||(s(l)?o[c]=n.parseData(i(l)):o[c]=t.parseData(r.decode(l)))}return o}function s(e){let t=new Uint8Array([80,88,82,45,85,83,68,67]),n=e instanceof Uint8Array?e:new Uint8Array(e);if(n.byteLength<t.length)return!1;for(let e=0;e<t.length;e++)if(n[e]!==t[e])return!1;return!0}function c(e){let t=Object.keys(e);if(t.length<1)return{file:void 0,filename:``,basePath:``};let n=t[0],r=a(n),i=!1,o=n.lastIndexOf(`/`),c=o>=0?n.slice(0,o):``;if(r===`usda`)return{file:e[n],filename:n,basePath:c};if(r===`usdc`)i=!0;else if(r===`usd`)if(s(e[n]))i=!0;else return{file:e[n],filename:n,basePath:c};return i?{file:e[n],filename:n,basePath:c}:{file:void 0,filename:``,basePath:``}}let l=this;if(typeof e==`string`){let n=new $(l.manager),r=t.parseData(e);return n.compose(r,{})}if(s(e)){let t=new $(l.manager),r=n.parseData(i(e));return t.compose(r,{})}let u=new Uint8Array(e);if(u[0]===80&&u[1]===75){let e=L(u),t=o(e),{file:n,filename:r,basePath:i}=c(e);if(!n)throw Error(`USDLoader: Invalid USDZ package. The first ZIP entry must be a USD layer (.usd/.usda/.usdc).`);let a=new $(l.manager),s=t[r];if(!s)throw Error(`USDLoader: Failed to parse root layer "`+r+`".`);return a.compose(s,t,{},i)}let d=new $(l.manager),f=r.decode(u),p=t.parseData(f);return d.compose(p,{})}};export{oe as USDLoader};