text: import{C as R,r as i,bp as h,ki as v,kd as A,b9 as M,A as k,eu as B,b as q}from"./vendor.1906794a.js";import{a as T}from"./quat.7e55d593.js";import{b as V,a as I,d as w,r as N,o as z,e as D,t as j,g as G,q as K,i as P,j as Q,v as _,k as H,m as J,p as U,w as W}from"./DefaultMaterial_COLOR_GAMMA.5a20ddf8.js";import{m as X,c as Y,y as Z,f as tt}from"./meshFeatureSet.f637f7e1.js";import{T as et,i as F,c as S,x as E,u as ot,L as nt,O,E as rt}from"./BufferView.57bc1dec.js";import{a as st,f as at,g as it,r as ct,c as ut,h as lt}from"./vec33.fe9621f1.js";import{b as ft}from"./georeference.86c4bee8.js";import"./types.0d6a11a5.js";import"./Version.abdcd6f4.js";import"./earcut.f20dd8d8.js";import"./deduplicate.c63f6fac.js";async function kt(t,e,n){const s=new V(mt(n)),o=(await I(s,e,n,!0)).model,f=o.lods.shift(),u=new Map,c=new Map;o.textures.forEach((b,C)=>u.set(C,gt(b))),o.materials.forEach((b,C)=>c.set(C,xt(b,u)));const a=dt(f);for(const b of a.parts)bt(a,b,c);const{position:d,normal:l,tangent:r,color:m,texCoord0:p}=a.vertexAttributes,x={position:d.typedBuffer,normal:i(l)?l.typedBuffer:null,tangent:i(r)?r.typedBuffer:null,uv:i(p)?p.typedBuffer:null,color:i(m)?m.typedBuffer:null},$=ft(x,t,n);return{transform:$.transform,components:a.components,spatialReference:t.spatialReference,vertexAttributes:new Z({position:$.vertexAttributes.position,normal:$.vertexAttributes.normal,tangent:$.vertexAttributes.tangent,color:x.color,uv:x.uv})}}function mt(t){return t!=null&&t.resolveFile?{busy:!1,request:async(e,n,s)=>{const o=t.resolveFile(e);return(await R(o,{responseType:n==="image"?"image":n==="binary"?"array-buffer":"json",signal:i(s)?s.signal:null})).data}}:null}function y(t,e){if(q(t))return"-";const n=t.typedBuffer;return`${A(e,n.buffer,()=>e.size)}/${n.byteOffset}/${n.byteLength}`}function pt(t){return i(t)?t.toString():"-"}function dt(t){let e=0;const n={color:!1,tangent:!1,normal:!1,texCoord0:!1},s=new Map,o=new Map,f=[];for(const u of t.parts){const{attributes:{position:c,normal:a,color:d,tangent:l,texCoord0:r}}=u,m=`
        ${y(c,s)}/
        ${y(a,s)}/
        ${y(d,s)}/
        ${y(l,s)}/
        ${y(r,s)}/
        ${pt(u.transform)}
      `;let p=!1;const x=A(o,m,()=>(p=!0,{start:e,length:c.count}));p&&(e+=c.count),a&&(n.normal=!0),d&&(n.color=!0),l&&(n.tangent=!0),r&&(n.texCoord0=!0),f.push({gltf:u,writeVertices:p,region:x})}return{vertexAttributes:{position:w(et,e),normal:n.normal?w(F,e):null,tangent:n.tangent?w(S,e):null,color:n.color?w(E,e):null,texCoord0:n.texCoord0?w(ot,e):null},parts:f,components:[]}}function gt(t){return new X({data:t.data,wrap:yt(t.parameters.wrap)})}function xt(t,e){const n=new M($t(t.color,t.opacity)),s=t.emissiveFactor?new M(Ct(t.emissiveFactor)):null;return new Y({color:n,colorTexture:h(v(t.textureColor,o=>e.get(o))),normalTexture:h(v(t.textureNormal,o=>e.get(o))),emissiveColor:s,emissiveTexture:h(v(t.textureEmissive,o=>e.get(o))),occlusionTexture:h(v(t.textureOcclusion,o=>e.get(o))),alphaMode:wt(t.alphaMode),alphaCutoff:t.alphaCutoff,doubleSided:t.doubleSided,metallic:t.metallicFactor,roughness:t.roughnessFactor,metallicRoughnessTexture:h(v(t.textureMetallicRoughness,o=>e.get(o)))})}function bt(t,e,n){e.writeVertices&&ht(t,e);const s=e.gltf,o=vt(s.indices||s.attributes.position.count,s.primitiveType),f=e.region.start;if(f)for(let u=0;u<o.length;u++)o[u]+=f;t.components.push(new tt({faces:o,material:n.get(s.material),trustSourceNormals:!0}))}function ht(t,e){const{position:n,normal:s,tangent:o,color:f,texCoord0:u}=t.vertexAttributes,c=e.region.start,{attributes:a,transform:d}=e.gltf,l=a.position.count;if(st(n.slice(c,l),a.position,d),i(a.normal)&&i(s)){const r=B(T(),d);at(s.slice(c,l),a.normal,r)}else i(s)&&it(s,0,0,1,{dstIndex:c,count:l});if(i(a.tangent)&&i(o)){const r=B(T(),d);D(o.slice(c,l),a.tangent,r)}else i(o)&&j(o,0,0,1,1,{dstIndex:c,count:l});if(i(a.texCoord0)&&i(u)?G(u.slice(c,l),a.texCoord0):i(u)&&K(u,0,0,{dstIndex:c,count:l}),i(a.color)&&i(f)){const r=a.color,m=f.slice(c,l);if(r.elementCount===4)r instanceof S?P(m,r,255):r instanceof E?Q(m,r):r instanceof nt&&_(m,r,8);else{j(m,255,255,255,255);const p=O.fromTypedArray(m.typedBuffer,m.typedBufferStride);r instanceof F?ct(p,r,255):r instanceof O?ut(p,r):r instanceof rt&&lt(p,r,8)}}else i(f)&&j(f.slice(c,l),255,255,255,255)}function vt(t,e){switch(e){case 4:return U(t,W);case 5:return J(t);case 6:return H(t)}}function wt(t){switch(t){case"OPAQUE":return"opaque";case"MASK":return"mask";case"BLEND":return"blend"}}function yt(t){return{horizontal:L(t.s),vertical:L(t.t)}}function L(t){switch(t){case 33071:return"clamp";case 33648:return"mirror";case 10497:return"repeat"}}function g(t){return t**(1/z)*255}function $t(t,e){return N(g(t[0]),g(t[1]),g(t[2]),e)}function Ct(t){return k(g(t[0]),g(t[1]),g(t[2]))}export{kt as loadGLTFMesh};
  