mbt-3d 0.3.6 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -279,6 +279,25 @@ declare interface DirectionalLightConfig extends BaseLightConfig {
279
279
  castShadow?: boolean;
280
280
  }
281
281
 
282
+ /**
283
+ * Environment (HDRI) configuration for realistic lighting and reflections
284
+ *
285
+ * @example
286
+ * ```tsx
287
+ * { files: '/scenes/studio.hdr', intensity: 1, background: false }
288
+ * ```
289
+ */
290
+ declare interface EnvironmentConfig {
291
+ /** URL to HDRI file (.hdr or .exr) */
292
+ files: string;
293
+ /** Environment intensity multiplier. Default: 1 */
294
+ intensity?: number;
295
+ /** Use HDRI as scene background. Default: false */
296
+ background?: boolean;
297
+ /** Blur amount for background (0-1). Default: 0 */
298
+ blur?: number;
299
+ }
300
+
282
301
  /**
283
302
  * Hemisphere light configuration - soft sky/ground lighting (no shadows)
284
303
  *
@@ -647,7 +666,7 @@ export declare function preloadModel(url: string): void;
647
666
  * </Scene3D>
648
667
  * ```
649
668
  */
650
- export declare function Scene3D({ children, camera, controls, background, shadows, lights, contactShadows, style, className, }: Scene3DProps): JSX_2.Element;
669
+ export declare function Scene3D({ children, camera, controls, background, shadows, lights, environment, contactShadows, showLoadingOverlay, style, className, }: Scene3DProps): JSX_2.Element;
651
670
 
652
671
  /**
653
672
  * Props for Scene3D component
@@ -707,6 +726,8 @@ export declare interface Scene3DProps {
707
726
  shadows?: boolean;
708
727
  /** Array of light configurations for multi-light setup */
709
728
  lights?: LightConfigUnion[];
729
+ /** Environment (HDRI) configuration for realistic lighting and reflections */
730
+ environment?: EnvironmentConfig;
710
731
  /** Contact shadows configuration (ground shadows under models) */
711
732
  contactShadows?: boolean | {
712
733
  /** Shadow position [x, y, z]. Default: [0, -1, 0] */
@@ -716,6 +737,8 @@ export declare interface Scene3DProps {
716
737
  /** Shadow blur amount. Default: 2 */
717
738
  blur?: number;
718
739
  };
740
+ /** Show full-scene loading overlay while models/textures are loading. Default: true */
741
+ showLoadingOverlay?: boolean;
719
742
  /** Container style (e.g., { width: 400, height: 500 }) */
720
743
  style?: React.CSSProperties;
721
744
  /** Container CSS class name */
package/dist/mbt-3d.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),O=require("@react-three/drei"),oe=require("three"),ae=require("three/examples/jsm/utils/SkeletonUtils.js"),B=require("@react-three/fiber"),ne=require("three/examples/jsm/loaders/KTX2Loader.js"),w=require("react/jsx-runtime");function J(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const r in s)if(r!=="default"){const l=Object.getOwnPropertyDescriptor(s,r);Object.defineProperty(t,r,l.get?l:{enumerable:!0,get:()=>s[r]})}}return t.default=s,Object.freeze(t)}const E=J(oe),Q=J(ae);function le({position:s,controlsConfig:t}){const{camera:r}=B.useThree(),l=e.useRef(null);return e.useEffect(()=>{s&&r&&(r.position.set(s[0],s[1],s[2]),r.updateProjectionMatrix(),l.current&&(l.current.target.set(0,0,0),l.current.update()))},[s,r]),w.jsx(O.OrbitControls,{ref:l,makeDefault:!0,enabled:t.enabled,enablePan:t.enablePan,enableZoom:t.enableZoom,enableRotate:t.enableRotate,minDistance:t.minDistance,maxDistance:t.maxDistance,minPolarAngle:t.minPolarAngle,maxPolarAngle:t.maxPolarAngle,autoRotate:t.autoRotate,autoRotateSpeed:t.autoRotateSpeed})}function ie({background:s}){const t=s==null?void 0:s.startsWith("#");return s?t?w.jsx("color",{attach:"background",args:[s]}):w.jsx(ce,{url:s}):null}function ce({url:s}){const t=O.useTexture(s);return e.useMemo(()=>{t.colorSpace=E.SRGBColorSpace},[t]),w.jsx("primitive",{attach:"background",object:t})}function ue({config:s}){switch(s.type){case"spot":{const{position:t=[5,10,5],intensity:r=50,castShadow:l=!0,angle:p=Math.PI/6,penumbra:g=.5,decay:T=2,distance:S=0,color:h="#ffffff"}=s;return w.jsx("spotLight",{position:t,intensity:r,castShadow:l,angle:p,penumbra:g,decay:T,distance:S,color:h})}case"point":{const{position:t=[0,5,0],intensity:r=20,color:l="#ffffff",distance:p=0,decay:g=2,castShadow:T=!1}=s;return w.jsx("pointLight",{position:t,intensity:r,color:l,distance:p,decay:g,castShadow:T})}case"directional":{const{position:t=[10,20,10],intensity:r=40,color:l="#ffffff",castShadow:p=!0}=s;return w.jsx("directionalLight",{position:t,intensity:r,color:l,castShadow:p})}case"hemisphere":{const{skyColor:t="#ffffff",groundColor:r="#444444",intensity:l=.5,position:p=[0,10,0]}=s,g=e.useMemo(()=>new E.Color(t),[t]),T=e.useMemo(()=>new E.Color(r),[r]);return w.jsx("hemisphereLight",{args:[g,T,l],position:p})}case"ambient":{const{intensity:t=.5,color:r="#ffffff"}=s;return w.jsx("ambientLight",{intensity:t,color:r})}default:return null}}function pe({children:s,camera:t={},controls:r={},background:l,shadows:p=!0,lights:g=[{type:"ambient",intensity:.5},{type:"spot",position:[5,10,5],intensity:50,castShadow:!0}],contactShadows:T=!0,style:S,className:h}){const o={position:t.position||[0,2,5],fov:t.fov||45},a={enabled:r.enabled??!0,enablePan:r.enablePan??!0,enableZoom:r.enableZoom??!0,enableRotate:r.enableRotate??!0,minDistance:r.minDistance,maxDistance:r.maxDistance,minPolarAngle:r.minPolarAngle,maxPolarAngle:r.maxPolarAngle,autoRotate:r.autoRotate??!1,autoRotateSpeed:r.autoRotateSpeed??2},c=typeof T=="object"?{position:T.position||[0,-1,0],opacity:T.opacity??.5,blur:T.blur??2}:T?{position:[0,-1,0],opacity:.5,blur:2}:null;return w.jsx("div",{style:S,className:h,children:w.jsxs(B.Canvas,{shadows:p,camera:{position:o.position,fov:o.fov},style:{width:"100%",height:"100%"},children:[w.jsx(e.Suspense,{fallback:null,children:w.jsx(ie,{background:l})}),g.map((m,b)=>w.jsx(ue,{config:m},`${m.type}-${b}`)),w.jsx(e.Suspense,{fallback:null,children:s}),w.jsx(le,{position:o.position,controlsConfig:a}),c&&w.jsx(O.ContactShadows,{position:c.position,opacity:c.opacity,blur:c.blur})]})})}function G(s,t){const r=e.useRef(new Map),l=e.useRef({}),p=e.useRef({});e.useEffect(()=>{t&&(l.current={...t})},[t]),e.useEffect(()=>{if(!s)return;const h=new Map;s.traverse(o=>{if(o.isMesh){const a=o;a.name&&h.set(a.name,a)}}),r.current=h},[s]),B.useFrame(()=>{const h=r.current;if(h.size===0)return;const o={...l.current,...p.current};for(const[a,c]of Object.entries(o)){const m=h.get(a);m&&m.visible!==c&&(m.visible=c)}});const g=e.useCallback((h,o)=>{p.current[h]=o;const a=r.current.get(h);a&&(a.visible=o)},[]),T=e.useCallback(()=>Array.from(r.current.keys()).sort(),[]),S=e.useCallback(()=>{const h={};return r.current.forEach((o,a)=>{h[a]=o.visible}),h},[]);return{setMeshVisibility:g,getMeshNames:T,getMeshVisibility:S}}function K(s,t){const r=e.useRef(new Map),l=e.useRef(new Map);e.useEffect(()=>{if(!s)return;const o=new Map;s.traverse(a=>{if(a.isMesh){const c=a;(Array.isArray(c.material)?c.material:[c.material]).forEach(b=>{b.name&&!o.has(b.name)&&o.set(b.name,b)})}}),r.current=o,t&&Object.entries(t).forEach(([a,c])=>{const m=o.get(a);if(m&&!Array.isArray(m)){const b=p(c);m.color&&m.color.copy(b),l.current.set(a,b)}})},[s,t]),B.useFrame(()=>{l.current.forEach((o,a)=>{const c=r.current.get(a);if(c&&!Array.isArray(c)){const m=c;m.color&&!m.color.equals(o)&&(m.color.copy(o),m.needsUpdate=!0)}})});const p=o=>typeof o=="string"?new E.Color(o):new E.Color(o[0],o[1],o[2]),g=e.useCallback((o,a)=>{const c=p(a);l.current.set(o,c);const m=r.current.get(o);if(m&&!Array.isArray(m)){const b=m;b.color&&(b.color.copy(c),b.needsUpdate=!0)}},[]),T=e.useCallback(()=>Array.from(r.current.keys()).sort(),[]),S=e.useCallback(o=>{const a=r.current.get(o);if(a&&!Array.isArray(a)){const c=a;if(c.color)return"#"+c.color.getHexString()}return null},[]),h=e.useCallback(()=>{const o={};return r.current.forEach((a,c)=>{if(!Array.isArray(a)){const m=a;m.color&&(o[c]="#"+m.color.getHexString())}}),o},[]);return{setMaterialColor:g,getMaterialNames:T,getMaterialColor:S,getAllMaterialColors:h}}function U(s,t){const{gl:r}=B.useThree(),l=e.useRef(new Map),p=e.useRef(new E.TextureLoader),g=e.useRef(null),T=e.useRef(new Map),S=e.useRef(new Set),h=e.useRef("");e.useEffect(()=>{if(!g.current)try{const n=typeof WebAssembly=="object"&&typeof WebAssembly.validate=="function";console.log("[useMaterialTexture] Browser features:"),console.log(` WebAssembly supported: ${n}`),console.log(` WebGL2: ${r.capabilities.isWebGL2}`);const i=new ne.KTX2Loader;i.setTranscoderPath("/basis/"),i.detectSupport(r),g.current=i,console.log("[useMaterialTexture] ✅ KTX2Loader initialized"),console.log("[useMaterialTexture] Transcoder path: /basis/"),fetch("/basis/basis_transcoder.wasm").then(f=>{f.ok?console.log("[useMaterialTexture] ✅ basis_transcoder.wasm is accessible"):console.error("[useMaterialTexture] ❌ basis_transcoder.wasm returned",f.status)}).catch(f=>{console.error("[useMaterialTexture] ❌ Failed to check basis_transcoder.wasm:",f)}),n||(console.warn("[useMaterialTexture] ⚠️ WebAssembly not supported! KTX2 will fallback to CPU decoding (slow)"),console.warn("[useMaterialTexture] ⚠️ Recommend using WebP instead of KTX2 for this browser"))}catch(n){console.error("[useMaterialTexture] ❌ Failed to initialize KTX2Loader:",n)}return()=>{g.current&&(g.current.dispose(),g.current=null)}},[r]),e.useEffect(()=>{if(!s)return;const n=new Map;s.traverse(i=>{if(i.isMesh){const f=i;(Array.isArray(f.material)?f.material:[f.material]).forEach(d=>{d.name&&!n.has(d.name)&&n.set(d.name,d)})}}),l.current=n},[s]);const o=e.useCallback(n=>n.toLowerCase().endsWith(".ktx2")?g.current?g.current:(console.warn("[useMaterialTexture] KTX2Loader not initialized, falling back to TextureLoader"),p.current):p.current,[]);e.useEffect(()=>{if(!t||!s)return;const n=l.current;if(n.size===0)return;const i=JSON.stringify(t);if(h.current===i){console.log("[useMaterialTexture] Textures unchanged, skipping reload");return}h.current=i;let f=!1;const x=new Map;Object.entries(t).forEach(([M,y])=>{x.set(M,typeof y=="string"?{map:y}:y)}),console.log("[useMaterialTexture] Starting texture load for",x.size,"materials");const d=[];x.forEach((M,y)=>{var A,k;const D=n.get(y);if(!D||!D.isMeshStandardMaterial){console.warn(`[useMaterialTexture] Material "${y}" not found or not MeshStandardMaterial`);return}const u=D;console.log(`[useMaterialTexture] 📋 Material "${y}" BEFORE reset:`),console.log(` - map: ${u.map?"EXISTS":"null"} ${u.map?`(uuid: ${u.map.uuid})`:""}`),console.log(` - normalMap: ${u.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${u.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${u.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${u.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${u.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(A=u.color)==null?void 0:A.getHexString()}`),console.log(` - emissive: ${(k=u.emissive)==null?void 0:k.getHexString()}`),console.log(` - material uuid: ${u.uuid}`),u.map&&(console.log(`[useMaterialTexture] 🗑️ Disposing old map (uuid: ${u.map.uuid})`),u.map.dispose()),u.normalMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old normalMap"),u.normalMap.dispose()),u.roughnessMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old roughnessMap"),u.roughnessMap.dispose()),u.metalnessMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old metalnessMap"),u.metalnessMap.dispose()),u.emissiveMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old emissiveMap"),u.emissiveMap.dispose()),u.aoMap&&(console.log("[useMaterialTexture] 🗑️ Disposing old aoMap"),u.aoMap.dispose()),u.map=null,u.normalMap=null,u.roughnessMap=null,u.metalnessMap=null,u.emissiveMap=null,u.emissive=new E.Color(0),u.emissiveIntensity=0,u.aoMap=null,u.needsUpdate=!0,u.color=new E.Color(16777215),console.log(`[useMaterialTexture] ✅ Material "${y}" AFTER reset: all maps cleared and disposed`),Object.entries(M).forEach(([$,C])=>{if(!C)return;const j=`${y}_${$}_${C}`,X=T.current.get(j);if(X){console.log(`[useMaterialTexture] Using cached texture: ${y}.${$}`),f||a(u,$,X);return}if(S.current.has(j)){console.log(`[useMaterialTexture] Skipping already loading: ${y}.${$}`);return}d.push({materialName:y,textureType:$,url:C,material:u})})}),console.log(`[useMaterialTexture] Queued ${d.length} textures to load`);let v=0;const R=()=>{if(f||v>=d.length){console.log("[useMaterialTexture] ✅ All textures loaded"),console.log("[useMaterialTexture] 📊 FINAL material states:"),n.forEach((A,k)=>{var C,j;const $=A;console.log(` Material "${k}":`),console.log(` - map: ${$.map?"EXISTS":"null"} ${$.map?`(colorSpace: ${$.map.colorSpace})`:""}`),console.log(` - normalMap: ${$.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${$.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${$.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${$.emissiveMap?"EXISTS":"null"}`),console.log(` - color: ${(C=$.color)==null?void 0:C.getHexString()}`),console.log(` - emissive: ${(j=$.emissive)==null?void 0:j.getHexString()}`),console.log(` - emissiveIntensity: ${$.emissiveIntensity}`),console.log(` - roughness: ${$.roughness}`),console.log(` - metalness: ${$.metalness}`)});return}const M=d[v++],y=`${M.materialName}_${M.textureType}_${M.url}`;console.log(`[useMaterialTexture] Loading (${v}/${d.length}): ${M.materialName}.${M.textureType} from ${M.url}`),S.current.add(y);const D=o(M.url),u=M.url.toLowerCase().endsWith(".ktx2")?"KTX2Loader":"TextureLoader";console.log(`[useMaterialTexture] Using ${u} for ${M.url}`),D.load(M.url,A=>{var j,X,P,I,L,W;if(S.current.delete(y),f){console.log(`[useMaterialTexture] Disposed, cleaning up texture: ${M.materialName}.${M.textureType}`),A.dispose();return}const k=((j=A.image)==null?void 0:j.width)||((P=(X=A.source)==null?void 0:X.data)==null?void 0:P.width)||"unknown",$=((I=A.image)==null?void 0:I.height)||((W=(L=A.source)==null?void 0:L.data)==null?void 0:W.height)||"unknown";console.log(`[useMaterialTexture] ✅ Loaded: ${M.materialName}.${M.textureType} (${k}x${$})`),A.colorSpace=M.textureType==="map"||M.textureType==="emissiveMap"?E.SRGBColorSpace:E.NoColorSpace,A.wrapS=E.RepeatWrapping,A.wrapT=E.RepeatWrapping,A.flipY=!1,T.current.set(y,A),a(M.material,M.textureType,A);const C=M.url.endsWith(".ktx2")?500:150;console.log(`[useMaterialTexture] Waiting111111 ${C}ms before next texture...`),setTimeout(R,0)},A=>{if(A.lengthComputable){const k=Math.round(A.loaded/A.total*100);k%25===0&&console.log(`[useMaterialTexture] Progress ${M.materialName}.${M.textureType}: ${k}%`)}},A=>{S.current.delete(y),f||(console.error(`[useMaterialTexture] ❌ Failed to load ${M.materialName}.${M.textureType} from ${M.url}`),console.error("[useMaterialTexture] Error details:",A),console.error("[useMaterialTexture] Loader type:",u),M.url.endsWith(".ktx2")&&(console.error("[useMaterialTexture] KTX2 error - file may not be in Basis Universal format!"),console.error("[useMaterialTexture] Make sure files are created with: gltf-transform etc1s input.png output.ktx2"))),setTimeout(R,100)})};return R(),()=>{console.log("[useMaterialTexture] Cleanup: disposed"),f=!0}},[s,t,o]);const a=(n,i,f)=>{var x,d;switch(console.log(`[useMaterialTexture] 🎨 Applying texture: ${n.name}.${i} (texture uuid: ${f.uuid})`),i){case"map":n.map=f;break;case"normalMap":n.normalMap=f;break;case"roughnessMap":n.roughnessMap=f;break;case"metalnessMap":n.metalnessMap=f;break;case"emissiveMap":n.emissiveMap=f,n.emissive=new E.Color(16777215),n.emissiveIntensity=1;break;case"alphaMap":console.log(`[useMaterialTexture] Skipping alphaMap for "${n.name}" to prevent disappearing`);break;case"aoMap":n.aoMap=f;break}n.needsUpdate=!0,console.log(`[useMaterialTexture] ✅ Applied ${i} to ${n.name}, needsUpdate=true`),console.log(`[useMaterialTexture] 📊 Material "${n.name}" FINAL state:`),console.log(` - map: ${n.map?"EXISTS":"null"} ${n.map?`(uuid: ${n.map.uuid}, colorSpace: ${n.map.colorSpace})`:""}`),console.log(` - normalMap: ${n.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${n.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${n.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${n.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${n.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(x=n.color)==null?void 0:x.getHexString()}`),console.log(` - emissive: ${(d=n.emissive)==null?void 0:d.getHexString()}`),console.log(` - emissiveIntensity: ${n.emissiveIntensity}`),console.log(` - roughness: ${n.roughness}`),console.log(` - metalness: ${n.metalness}`)},c=e.useCallback((n,i)=>{const f=typeof i=="string"?{map:i}:i,x=l.current.get(n);if(!x||!x.isMeshStandardMaterial){console.warn(`Material "${n}" not found or not MeshStandardMaterial`);return}const d=x;Object.entries(f).forEach(([v,R])=>{if(!R)return;const M=`${n}_${v}_${R}`,y=T.current.get(M);if(y){a(d,v,y);return}o(R).load(R,u=>{u.colorSpace=v==="map"||v==="emissiveMap"?E.SRGBColorSpace:E.NoColorSpace,u.wrapS=E.RepeatWrapping,u.wrapT=E.RepeatWrapping,T.current.set(M,u),a(d,v,u)},void 0,u=>{console.error(`Failed to load texture ${R}:`,u)})})},[o]),m=e.useCallback(()=>Array.from(l.current.keys()).sort(),[]),b=e.useCallback(n=>{const i=l.current.get(n);if(!i||!i.isMeshStandardMaterial)return;const f=i;f.map=null,f.normalMap=null,f.roughnessMap=null,f.metalnessMap=null,f.emissiveMap=null,f.alphaMap=null,f.aoMap=null,f.needsUpdate=!0},[]);return{setMaterialTextures:c,getMaterialNames:m,clearMaterialTextures:b}}function ee({url:s,position:t=[0,0,0],rotation:r=[0,0,0],scale:l=1,meshVisibility:p,materialColors:g,materialTextures:T,onLoad:S,onError:h}){const{scene:o}=O.useGLTF(s),a=e.useRef(S);a.current=S;const c=e.useMemo(()=>{const b=o.clone();console.log("[Model] 🔍 Scene clone created, checking materials...");const n=[],i=new Set,f=[];let x=0;return b.traverse(d=>{if(x++,d.type==="Bone"&&f.push(d.name),d.isMesh){const v=d;n.push(v.name),v.castShadow=!0,v.receiveShadow=!0,(Array.isArray(v.material)?v.material:[v.material]).forEach(M=>{i.add(M.name),console.log(`[Model] 📦 Material found: "${M.name}" (uuid: ${M.uuid})`);const y=M;console.log(` - Has map: ${y.map?"YES":"NO"}`),console.log(` - Has normalMap: ${y.normalMap?"YES":"NO"}`),console.log(` - Has roughnessMap: ${y.roughnessMap?"YES":"NO"}`),console.log(` - Has metalnessMap: ${y.metalnessMap?"YES":"NO"}`)})}}),console.log(`[Model] 📊 Clone summary: ${n.length} meshes, ${i.size} materials`),setTimeout(()=>{var d;(d=a.current)==null||d.call(a,{meshes:n.sort(),materials:Array.from(i).sort(),bones:f.sort(),nodeCount:x})},0),b},[o]);G(c,p),K(c,g),U(c,T);const m=typeof l=="number"?[l,l,l]:l;return w.jsx("group",{position:t,rotation:r,scale:m,children:w.jsx("primitive",{object:c})})}ee.preload=s=>{O.useGLTF.preload(s)};function te(s,t,r){const{actions:l,names:p}=O.useAnimations(s,t),g=e.useRef(null),T=e.useRef(r==null?void 0:r.defaultAnimation);e.useEffect(()=>{if(p.length===0)return;const a=T.current;let c=p[0];if(a){const b=p.find(n=>n===a||n.includes(a));b&&(c=b)}const m=l[c];m&&(m.reset().fadeIn(.5).play(),g.current=m)},[l,p]);const S=e.useCallback((a,c)=>{const{loop:m=!1,crossFadeDuration:b=.2,restoreDefault:n=!0}=c||{};let i=l[a];if(!i){const x=Object.keys(l).find(d=>d.toLowerCase().includes(a.toLowerCase())||a.toLowerCase().includes(d.toLowerCase()));x&&(i=l[x])}if(!i){console.warn(`Animation "${a}" not found. Available: ${p.join(", ")}`);return}const f=g.current;if(!(f===i&&i.isRunning())&&(f&&f!==i&&f.fadeOut(b),i.reset(),i.fadeIn(b),i.setLoop(m?E.LoopRepeat:E.LoopOnce,m?1/0:1),i.clampWhenFinished=!m,i.play(),m||i.getMixer().update(0),g.current=i,n&&!m&&T.current)){const x=i.getMixer(),d=v=>{if(v.action===i){x.removeEventListener("finished",d);const R=l[T.current];R&&(i.fadeOut(b),R.reset().fadeIn(b).play(),g.current=R)}};x.addEventListener("finished",d)}},[l,p]),h=e.useCallback(()=>{var a;(a=g.current)==null||a.fadeOut(.2),g.current=null},[]),o=e.useCallback(()=>p,[p]);return{playAnimation:S,stopAnimation:h,getAnimationNames:o,actions:l}}function z(s,t){const r=e.useRef(t||{}),l=e.useRef([]),p=e.useRef([]);e.useEffect(()=>{const h=new Set,o=[];s.traverse(a=>{a instanceof E.Mesh&&a.morphTargetDictionary&&a.morphTargetInfluences&&(o.push(a),Object.keys(a.morphTargetDictionary).forEach(c=>{h.add(c)}))}),l.current=Array.from(h).sort(),p.current=o},[s]),B.useFrame(()=>{const h=r.current;p.current.forEach(o=>{!o.morphTargetDictionary||!o.morphTargetInfluences||Object.entries(h).forEach(([a,c])=>{const m=o.morphTargetDictionary[a];m!==void 0&&(o.morphTargetInfluences[m]=c)})})}),e.useEffect(()=>{t&&(r.current={...t})},[t]);const g=e.useCallback((h,o)=>{r.current[h]=Math.max(0,Math.min(1,o))},[]),T=e.useCallback(()=>l.current,[]),S=e.useCallback(()=>({...r.current}),[]);return{setMorphTarget:g,getMorphTargetNames:T,getMorphTargetValues:S}}const re=e.createContext(null);function me(){const s=e.useContext(re);if(!s)throw new Error("BoneAttachment must be used within an AnimatedModel");return s}const q=e.forwardRef(({url:s,position:t=[0,0,0],rotation:r=[0,0,0],scale:l=1,defaultAnimation:p,morphTargets:g,meshVisibility:T,materialColors:S,materialTextures:h,onLoad:o,onError:a,children:c},m)=>{const b=e.useRef(null),n=e.useRef([]),i=e.useRef(o);i.current=o;const{scene:f,animations:x}=O.useGLTF(s),d=e.useMemo(()=>Q.clone(f),[f]),{playAnimation:v,stopAnimation:R,getAnimationNames:M}=te(x,d,{defaultAnimation:p}),{setMorphTarget:y}=z(d,g),{setMeshVisibility:D,getMeshNames:u}=G(d,T),{setMaterialColor:A,getMaterialNames:k,getMaterialColor:$}=K(d,S),{setMaterialTextures:C,clearMaterialTextures:j}=U(d,h);e.useEffect(()=>{if(!d)return;const I=setTimeout(()=>{var Z;const L=[],W=[],_=new Set,V=new Set;let Y=0;d.traverse(F=>{if(Y++,F.type==="Bone"&&L.push(F.name),F.isMesh){const N=F;W.push(N.name),N.castShadow=!0,N.receiveShadow=!0,(Array.isArray(N.material)?N.material:[N.material]).forEach(H=>{_.add(H.name),H.shadowSide=E.DoubleSide}),N.morphTargetDictionary&&Object.keys(N.morphTargetDictionary).forEach(H=>{V.add(H)})}}),n.current=Array.from(V).sort(),(Z=i.current)==null||Z.call(i,{meshes:W.sort(),materials:Array.from(_).sort(),bones:L.sort(),nodeCount:Y,animations:x.map(F=>F.name),morphTargetNames:n.current})},0);return()=>clearTimeout(I)},[d,x]),e.useImperativeHandle(m,()=>({playAnimation:v,stopAnimation:R,getAnimationNames:M,getGroup:()=>b.current,setMorphTarget:y,getMorphTargetNames:()=>n.current,setMeshVisibility:D,getMeshNames:u,setMaterialColor:A,getMaterialNames:k,getMaterialColor:$,setMaterialTextures:C,clearMaterialTextures:j}));const X=e.useMemo(()=>({scene:d,getBone:I=>d.getObjectByName(I)||null}),[d]),P=typeof l=="number"?[l,l,l]:l;return w.jsx(re.Provider,{value:X,children:w.jsxs("group",{ref:b,position:t,rotation:r,scale:P,children:[w.jsx("primitive",{object:d}),c]})})});q.displayName="AnimatedModel";q.preload=s=>{O.useGLTF.preload(s)};const se=e.forwardRef(({url:s,position:t=[0,0,0],rotation:r=[0,0,0],scale:l=1,morphTargets:p,meshVisibility:g,materialColors:T,materialTextures:S,onMorphTargetsFound:h,onLoad:o,onError:a},c)=>{const{scene:m}=O.useGLTF(s),b=e.useRef(o);b.current=o;const n=e.useRef(h);n.current=h;const i=e.useMemo(()=>m.clone(),[m]),{setMorphTarget:f,getMorphTargetNames:x,getMorphTargetValues:d}=z(i,p),{setMeshVisibility:v,getMeshNames:R}=G(i,g),{setMaterialColor:M,getMaterialNames:y,getMaterialColor:D}=K(i,T),{setMaterialTextures:u,clearMaterialTextures:A}=U(i,S);e.useEffect(()=>{var C;const $=x();$.length>0&&((C=n.current)==null||C.call(n,$))},[i,x]),e.useEffect(()=>{var P;if(!i)return;const $=[],C=new Set,j=[];let X=0;i.traverse(I=>{if(X++,I.type==="Bone"&&j.push(I.name),I.isMesh){const L=I;$.push(L.name),L.castShadow=!0,L.receiveShadow=!0,(Array.isArray(L.material)?L.material:[L.material]).forEach(_=>C.add(_.name))}}),(P=b.current)==null||P.call(b,{meshes:$.sort(),materials:Array.from(C).sort(),bones:j.sort(),nodeCount:X})},[i]),e.useImperativeHandle(c,()=>({setMorphTarget:f,getMorphTargetNames:x,getMorphTargetValues:d,setMeshVisibility:v,getMeshNames:R,setMaterialColor:M,getMaterialNames:y,getMaterialColor:D,setMaterialTextures:u,clearMaterialTextures:A}));const k=typeof l=="number"?[l,l,l]:l;return w.jsx("group",{position:t,rotation:r,scale:k,children:w.jsx("primitive",{object:i})})});se.displayName="MorphableModel";function fe({children:s,bone:t,position:r=[0,0,0],rotation:l=[0,0,0],scale:p=1}){const{getBone:g}=me(),[T,S]=e.useState(null);if(e.useEffect(()=>{const o=g(t);o?S(o):console.warn(`Bone "${t}" not found in model`)},[t,g]),!T)return null;const h=typeof p=="number"?[p,p,p]:p;return B.createPortal(w.jsx("group",{position:r,rotation:l,scale:h,children:s}),T)}function de(s,t){const{scene:r,animations:l}=O.useGLTF(s),p=e.useMemo(()=>Q.clone(r),[r]);return e.useEffect(()=>{var o;if(!p)return;const g=[],T=[],S=new Set;let h=0;p.traverse(a=>{if(h++,a.type==="Bone"&&g.push(a.name),a.isMesh){const c=a;T.push(c.name),c.castShadow=!0,c.receiveShadow=!0,(Array.isArray(c.material)?c.material:[c.material]).forEach(b=>{S.add(b.name),b.shadowSide=E.DoubleSide})}}),(o=t==null?void 0:t.onLoad)==null||o.call(t,{meshes:T.sort(),materials:Array.from(S).sort(),bones:g.sort(),nodeCount:h})},[p,t]),{scene:p,animations:l}}function Me(s){O.useGLTF.preload(s)}exports.AnimatedModel=q;exports.BoneAttachment=fe;exports.Model=ee;exports.MorphableModel=se;exports.Scene3D=pe;exports.preloadModel=Me;exports.useAnimationController=te;exports.useClonedModel=de;exports.useMaterialColor=K;exports.useMaterialTexture=U;exports.useMeshVisibility=G;exports.useMorphTargets=z;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),I=require("@react-three/drei"),ne=require("three"),ae=require("three/examples/jsm/utils/SkeletonUtils.js"),B=require("@react-three/fiber"),ie=require("three/examples/jsm/loaders/KTX2Loader.js"),M=require("react/jsx-runtime");function Q(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const o in t)if(o!=="default"){const a=Object.getOwnPropertyDescriptor(t,o);Object.defineProperty(r,o,a.get?a:{enumerable:!0,get:()=>t[o]})}}return r.default=t,Object.freeze(r)}const R=Q(ne),ee=Q(ae);function le({position:t,controlsConfig:r}){const{camera:o}=B.useThree(),a=e.useRef(null);return e.useEffect(()=>{t&&o&&(o.position.set(t[0],t[1],t[2]),o.updateProjectionMatrix(),a.current&&(a.current.target.set(0,0,0),a.current.update()))},[t,o]),M.jsx(I.OrbitControls,{ref:a,makeDefault:!0,enabled:r.enabled,enablePan:r.enablePan,enableZoom:r.enableZoom,enableRotate:r.enableRotate,minDistance:r.minDistance,maxDistance:r.maxDistance,minPolarAngle:r.minPolarAngle,maxPolarAngle:r.maxPolarAngle,autoRotate:r.autoRotate,autoRotateSpeed:r.autoRotateSpeed})}function ce({background:t}){const r=t==null?void 0:t.startsWith("#");return t?r?M.jsx("color",{attach:"background",args:[t]}):M.jsx(ue,{url:t}):null}function ue({url:t}){const r=I.useTexture(t);return e.useMemo(()=>{r.colorSpace=R.SRGBColorSpace},[r]),M.jsx("primitive",{attach:"background",object:r})}function fe({config:t}){return M.jsx(I.Environment,{files:t.files,background:t.background??!1,blur:t.blur??0,children:M.jsx("group",{scale:t.intensity??1,children:M.jsx("ambientLight",{intensity:0})})})}function me({config:t}){switch(t.type){case"spot":{const{position:r=[5,10,5],intensity:o=50,castShadow:a=!0,angle:c=Math.PI/6,penumbra:g=.5,decay:y=2,distance:T=0,color:h="#ffffff"}=t;return M.jsx("spotLight",{position:r,intensity:o,castShadow:a,angle:c,penumbra:g,decay:y,distance:T,color:h})}case"point":{const{position:r=[0,5,0],intensity:o=20,color:a="#ffffff",distance:c=0,decay:g=2,castShadow:y=!1}=t;return M.jsx("pointLight",{position:r,intensity:o,color:a,distance:c,decay:g,castShadow:y})}case"directional":{const{position:r=[10,20,10],intensity:o=40,color:a="#ffffff",castShadow:c=!0}=t;return M.jsx("directionalLight",{position:r,intensity:o,color:a,castShadow:c})}case"hemisphere":{const{skyColor:r="#ffffff",groundColor:o="#444444",intensity:a=.5,position:c=[0,10,0]}=t,g=e.useMemo(()=>new R.Color(r),[r]),y=e.useMemo(()=>new R.Color(o),[o]);return M.jsx("hemisphereLight",{args:[g,y,a],position:c})}case"ambient":{const{intensity:r=.5,color:o="#ffffff"}=t;return M.jsx("ambientLight",{intensity:r,color:o})}default:return null}}function pe({onChange:t}){const{active:r,progress:o}=I.useProgress();return e.useEffect(()=>{t(r,o)},[r,o,t]),null}function de({children:t,camera:r={},controls:o={},background:a,shadows:c=!0,lights:g=[{type:"ambient",intensity:.5},{type:"spot",position:[5,10,5],intensity:50,castShadow:!0}],environment:y,contactShadows:T=!0,showLoadingOverlay:h=!0,style:n,className:i}){const[u,m]=e.useState(!1),[b,s]=e.useState(0),l=e.useRef(null),f=e.useCallback((E,d)=>{if(E){l.current!==null&&(window.clearTimeout(l.current),l.current=null),m(!0),s(Math.max(0,Math.min(100,Math.round(d))));return}s(100),l.current=window.setTimeout(()=>{m(!1),s(0),l.current=null},200)},[]);e.useEffect(()=>()=>{l.current!==null&&window.clearTimeout(l.current)},[]);const S={position:r.position||[0,2,5],fov:r.fov||45},p={enabled:o.enabled??!0,enablePan:o.enablePan??!0,enableZoom:o.enableZoom??!0,enableRotate:o.enableRotate??!0,minDistance:o.minDistance,maxDistance:o.maxDistance,minPolarAngle:o.minPolarAngle,maxPolarAngle:o.maxPolarAngle,autoRotate:o.autoRotate??!1,autoRotateSpeed:o.autoRotateSpeed??2},A=typeof T=="object"?{position:T.position||[0,-1,0],opacity:T.opacity??.5,blur:T.blur??2}:T?{position:[0,-1,0],opacity:.5,blur:2}:null;return M.jsxs("div",{style:{...n||{},position:(n==null?void 0:n.position)??"relative"},className:i,children:[M.jsxs(B.Canvas,{shadows:c,camera:{position:S.position,fov:S.fov},style:{width:"100%",height:"100%"},children:[M.jsx(e.Suspense,{fallback:null,children:M.jsx(ce,{background:a})}),y&&M.jsx(e.Suspense,{fallback:null,children:M.jsx(fe,{config:y})}),g.map((E,d)=>M.jsx(me,{config:E},`${E.type}-${d}`)),M.jsx(e.Suspense,{fallback:null,children:t}),M.jsx(le,{position:S.position,controlsConfig:p}),A&&M.jsx(I.ContactShadows,{position:A.position,opacity:A.opacity,blur:A.blur}),M.jsx(pe,{onChange:f})]}),h&&u&&M.jsx("div",{style:{position:"absolute",inset:0,background:"rgba(8, 10, 16, 0.46)",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none",zIndex:10},children:M.jsxs("div",{style:{minWidth:220,padding:"16px 18px",borderRadius:14,border:"1px solid rgba(255,255,255,0.2)",background:"linear-gradient(180deg, rgba(18,24,36,0.9), rgba(13,17,27,0.9))",color:"#eef3ff",boxShadow:"0 10px 30px rgba(0,0,0,0.35)",fontFamily:"system-ui, -apple-system, Segoe UI, sans-serif",textAlign:"center"},children:[M.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:10},children:M.jsxs("svg",{width:"34",height:"34",viewBox:"0 0 34 34","aria-hidden":"true",children:[M.jsx("circle",{cx:"17",cy:"17",r:"14",fill:"none",stroke:"rgba(255,255,255,0.2)",strokeWidth:"4"}),M.jsx("path",{d:"M31 17a14 14 0 0 1-14 14",fill:"none",stroke:"#67b4ff",strokeWidth:"4",strokeLinecap:"round",children:M.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 17 17",to:"360 17 17",dur:"0.9s",repeatCount:"indefinite"})})]})}),M.jsxs("div",{style:{fontSize:12,opacity:.82,marginTop:4},children:[b,"%"]})]})})]})}function K(t,r){const o=e.useRef(new Map),a=e.useRef({}),c=e.useRef({});e.useEffect(()=>{r&&(a.current={...r})},[r]),e.useEffect(()=>{if(!t)return;const h=new Map;t.traverse(n=>{if(n.isMesh){const i=n;i.name&&h.set(i.name,i)}}),o.current=h},[t]),B.useFrame(()=>{const h=o.current;if(h.size===0)return;const n={...a.current,...c.current};for(const[i,u]of Object.entries(n)){const m=h.get(i);m&&m.visible!==u&&(m.visible=u)}});const g=e.useCallback((h,n)=>{c.current[h]=n;const i=o.current.get(h);i&&(i.visible=n)},[]),y=e.useCallback(()=>Array.from(o.current.keys()).sort(),[]),T=e.useCallback(()=>{const h={};return o.current.forEach((n,i)=>{h[i]=n.visible}),h},[]);return{setMeshVisibility:g,getMeshNames:y,getMeshVisibility:T}}function G(t,r){const o=e.useRef(new Map),a=e.useRef(new Map);e.useEffect(()=>{if(!t)return;const n=new Map;t.traverse(i=>{if(i.isMesh){const u=i;(Array.isArray(u.material)?u.material:[u.material]).forEach(b=>{b.name&&!n.has(b.name)&&n.set(b.name,b)})}}),o.current=n,r&&Object.entries(r).forEach(([i,u])=>{const m=n.get(i);if(m&&!Array.isArray(m)){const b=c(u);m.color&&m.color.copy(b),a.current.set(i,b)}})},[t,r]),B.useFrame(()=>{a.current.forEach((n,i)=>{const u=o.current.get(i);if(u&&!Array.isArray(u)){const m=u;m.color&&!m.color.equals(n)&&(m.color.copy(n),m.needsUpdate=!0)}})});const c=n=>typeof n=="string"?new R.Color(n):new R.Color(n[0],n[1],n[2]),g=e.useCallback((n,i)=>{const u=c(i);a.current.set(n,u);const m=o.current.get(n);if(m&&!Array.isArray(m)){const b=m;b.color&&(b.color.copy(u),b.needsUpdate=!0)}},[]),y=e.useCallback(()=>Array.from(o.current.keys()).sort(),[]),T=e.useCallback(n=>{const i=o.current.get(n);if(i&&!Array.isArray(i)){const u=i;if(u.color)return"#"+u.color.getHexString()}return null},[]),h=e.useCallback(()=>{const n={};return o.current.forEach((i,u)=>{if(!Array.isArray(i)){const m=i;m.color&&(n[u]="#"+m.color.getHexString())}}),n},[]);return{setMaterialColor:g,getMaterialNames:y,getMaterialColor:T,getAllMaterialColors:h}}function H(t){const r=t.toLowerCase();if(r.endsWith(".ktx2"))return!0;try{const o=new URL(t,window.location.origin),a=decodeURIComponent(o.hash.replace(/^#/,"")).toLowerCase(),c=decodeURIComponent(o.search).toLowerCase(),g=decodeURIComponent(o.pathname).toLowerCase();return a.endsWith(".ktx2")||c.includes(".ktx2")||g.endsWith(".ktx2")}catch{return r.includes(".ktx2")}}function z(t,r){const{gl:o}=B.useThree(),a=e.useRef(new Map),c=e.useRef(new R.TextureLoader),g=e.useRef(null),y=e.useRef(new Map),T=e.useRef(new Set),h=e.useRef("");e.useEffect(()=>{if(!g.current)try{const s=typeof WebAssembly=="object"&&typeof WebAssembly.validate=="function";console.log("[useMaterialTexture] Browser features:"),console.log(` WebAssembly supported: ${s}`),console.log(` WebGL2: ${o.capabilities.isWebGL2}`);const l=new ie.KTX2Loader;l.setTranscoderPath("/basis/"),l.detectSupport(o),g.current=l,console.log("[useMaterialTexture] ✅ KTX2Loader initialized"),console.log("[useMaterialTexture] Transcoder path: /basis/"),fetch("/basis/basis_transcoder.wasm").then(f=>{f.ok?console.log("[useMaterialTexture] ✅ basis_transcoder.wasm is accessible"):console.error("[useMaterialTexture] ❌ basis_transcoder.wasm returned",f.status)}).catch(f=>{console.error("[useMaterialTexture] ❌ Failed to check basis_transcoder.wasm:",f)}),s||(console.warn("[useMaterialTexture] ⚠️ WebAssembly not supported! KTX2 will fallback to CPU decoding (slow)"),console.warn("[useMaterialTexture] ⚠️ Recommend using WebP instead of KTX2 for this browser"))}catch(s){console.error("[useMaterialTexture] ❌ Failed to initialize KTX2Loader:",s)}return()=>{g.current&&(g.current.dispose(),g.current=null)}},[o]),e.useEffect(()=>{if(!t)return;const s=new Map;t.traverse(l=>{if(l.isMesh){const f=l;(Array.isArray(f.material)?f.material:[f.material]).forEach(p=>{p.name&&!s.has(p.name)&&s.set(p.name,p)})}}),a.current=s},[t]);const n=e.useCallback(s=>H(s)?g.current?g.current:(console.warn("[useMaterialTexture] KTX2Loader not initialized, falling back to TextureLoader"),c.current):c.current,[]);e.useEffect(()=>{if(!r||!t)return;const s=a.current;if(s.size===0)return;const l=JSON.stringify(r);if(h.current===l){console.log("[useMaterialTexture] Textures unchanged, skipping reload");return}h.current=l;let f=!1;const S=new Map;Object.entries(r).forEach(([d,w])=>{S.set(d,typeof w=="string"?{map:w}:w)}),console.log("[useMaterialTexture] Starting texture load for",S.size,"materials");const p=[];S.forEach((d,w)=>{var v,L;const N=s.get(w);if(!N||!N.isMeshStandardMaterial){console.warn(`[useMaterialTexture] Material "${w}" not found or not MeshStandardMaterial`);return}const x=N;console.log(`[useMaterialTexture] 📋 Material "${w}" BEFORE reset:`),console.log(` - map: ${x.map?"EXISTS":"null"} ${x.map?`(uuid: ${x.map.uuid})`:""}`),console.log(` - normalMap: ${x.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${x.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${x.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${x.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${x.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(v=x.color)==null?void 0:v.getHexString()}`),console.log(` - emissive: ${(L=x.emissive)==null?void 0:L.getHexString()}`),console.log(` - material uuid: ${x.uuid}`),Object.entries(d).forEach(([$,j])=>{if(!j)return;const C=$,k=x[C];k&&(console.log(`[useMaterialTexture] 🗑️ Disposing old ${C} (uuid: ${k.uuid})`),k.dispose(),x[C]=null)}),d.emissiveMap&&(x.emissive=new R.Color(0),x.emissiveIntensity=0),x.needsUpdate=!0,x.color=new R.Color(16777215),console.log(`[useMaterialTexture] ✅ Material "${w}" AFTER reset: only specified maps cleared`),Object.entries(d).forEach(([$,j])=>{if(!j)return;const C=`${w}_${$}_${j}`,k=y.current.get(C);if(k){console.log(`[useMaterialTexture] Using cached texture: ${w}.${$}`),f||i(x,$,k);return}if(T.current.has(C)){console.log(`[useMaterialTexture] Skipping already loading: ${w}.${$}`);return}p.push({materialName:w,textureType:$,url:j,material:x})})}),console.log(`[useMaterialTexture] Queued ${p.length} textures to load`);let A=0;const E=()=>{if(f||A>=p.length){console.log("[useMaterialTexture] ✅ All textures loaded"),console.log("[useMaterialTexture] 📊 FINAL material states:"),s.forEach((v,L)=>{var j,C;const $=v;console.log(` Material "${L}":`),console.log(` - map: ${$.map?"EXISTS":"null"} ${$.map?`(colorSpace: ${$.map.colorSpace})`:""}`),console.log(` - normalMap: ${$.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${$.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${$.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${$.emissiveMap?"EXISTS":"null"}`),console.log(` - color: ${(j=$.color)==null?void 0:j.getHexString()}`),console.log(` - emissive: ${(C=$.emissive)==null?void 0:C.getHexString()}`),console.log(` - emissiveIntensity: ${$.emissiveIntensity}`),console.log(` - roughness: ${$.roughness}`),console.log(` - metalness: ${$.metalness}`)});return}const d=p[A++],w=`${d.materialName}_${d.textureType}_${d.url}`;console.log(`[useMaterialTexture] Loading (${A}/${p.length}): ${d.materialName}.${d.textureType} from ${d.url}`),T.current.add(w);const N=n(d.url),x=H(d.url)?"KTX2Loader":"TextureLoader";console.log(`[useMaterialTexture] Using ${x} for ${d.url}`),N.load(d.url,v=>{var C,k,D,P,O,W;if(T.current.delete(w),f){console.log(`[useMaterialTexture] Disposed, cleaning up texture: ${d.materialName}.${d.textureType}`),v.dispose();return}const L=((C=v.image)==null?void 0:C.width)||((D=(k=v.source)==null?void 0:k.data)==null?void 0:D.width)||"unknown",$=((P=v.image)==null?void 0:P.height)||((W=(O=v.source)==null?void 0:O.data)==null?void 0:W.height)||"unknown";console.log(`[useMaterialTexture] ✅ Loaded: ${d.materialName}.${d.textureType} (${L}x${$})`),v.colorSpace=d.textureType==="map"||d.textureType==="emissiveMap"?R.SRGBColorSpace:R.NoColorSpace,v.wrapS=R.RepeatWrapping,v.wrapT=R.RepeatWrapping,v.flipY=!1,y.current.set(w,v),i(d.material,d.textureType,v);const j=H(d.url)?500:150;console.log(`[useMaterialTexture] Waiting111111 ${j}ms before next texture...`),setTimeout(E,0)},v=>{if(v.lengthComputable){const L=Math.round(v.loaded/v.total*100);L%25===0&&console.log(`[useMaterialTexture] Progress ${d.materialName}.${d.textureType}: ${L}%`)}},v=>{T.current.delete(w),f||(console.error(`[useMaterialTexture] ❌ Failed to load ${d.materialName}.${d.textureType} from ${d.url}`),console.error("[useMaterialTexture] Error details:",v),console.error("[useMaterialTexture] Loader type:",x),H(d.url)&&(console.error("[useMaterialTexture] KTX2 error - file may not be in Basis Universal format!"),console.error("[useMaterialTexture] Make sure files are created with: gltf-transform etc1s input.png output.ktx2"))),setTimeout(E,100)})};return E(),()=>{console.log("[useMaterialTexture] Cleanup: disposed"),f=!0}},[t,r,n]);const i=(s,l,f)=>{var S,p;switch(console.log(`[useMaterialTexture] 🎨 Applying texture: ${s.name}.${l} (texture uuid: ${f.uuid})`),l){case"map":s.map=f;break;case"normalMap":s.normalMap=f;break;case"roughnessMap":s.roughnessMap=f;break;case"metalnessMap":s.metalnessMap=f;break;case"emissiveMap":s.emissiveMap=f,s.emissive=new R.Color(16777215),s.emissiveIntensity=1;break;case"alphaMap":console.log(`[useMaterialTexture] Skipping alphaMap for "${s.name}" to prevent disappearing`);break;case"aoMap":s.aoMap=f;break}s.needsUpdate=!0,console.log(`[useMaterialTexture] ✅ Applied ${l} to ${s.name}, needsUpdate=true`),console.log(`[useMaterialTexture] 📊 Material "${s.name}" FINAL state:`),console.log(` - map: ${s.map?"EXISTS":"null"} ${s.map?`(uuid: ${s.map.uuid}, colorSpace: ${s.map.colorSpace})`:""}`),console.log(` - normalMap: ${s.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${s.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${s.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${s.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${s.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(S=s.color)==null?void 0:S.getHexString()}`),console.log(` - emissive: ${(p=s.emissive)==null?void 0:p.getHexString()}`),console.log(` - emissiveIntensity: ${s.emissiveIntensity}`),console.log(` - roughness: ${s.roughness}`),console.log(` - metalness: ${s.metalness}`)},u=e.useCallback((s,l)=>{const f=typeof l=="string"?{map:l}:l,S=a.current.get(s);if(!S||!S.isMeshStandardMaterial){console.warn(`Material "${s}" not found or not MeshStandardMaterial`);return}const p=S;Object.entries(f).forEach(([A,E])=>{if(!E)return;const d=`${s}_${A}_${E}`,w=y.current.get(d);if(w){i(p,A,w);return}n(E).load(E,x=>{x.colorSpace=A==="map"||A==="emissiveMap"?R.SRGBColorSpace:R.NoColorSpace,x.wrapS=R.RepeatWrapping,x.wrapT=R.RepeatWrapping,y.current.set(d,x),i(p,A,x)},void 0,x=>{console.error(`Failed to load texture ${E}:`,x)})})},[n]),m=e.useCallback(()=>Array.from(a.current.keys()).sort(),[]),b=e.useCallback(s=>{const l=a.current.get(s);if(!l||!l.isMeshStandardMaterial)return;const f=l;f.map=null,f.normalMap=null,f.roughnessMap=null,f.metalnessMap=null,f.emissiveMap=null,f.alphaMap=null,f.aoMap=null,f.needsUpdate=!0},[]);return{setMaterialTextures:u,getMaterialNames:m,clearMaterialTextures:b}}function te({url:t,position:r=[0,0,0],rotation:o=[0,0,0],scale:a=1,meshVisibility:c,materialColors:g,materialTextures:y,onLoad:T,onError:h}){const{scene:n}=I.useGLTF(t),i=e.useRef(T);i.current=T;const u=e.useMemo(()=>{const b=n.clone();console.log("[Model] 🔍 Scene clone created, checking materials...");const s=[],l=new Set,f=[];let S=0;return b.traverse(p=>{if(S++,p.type==="Bone"&&f.push(p.name),p.isMesh){const A=p;s.push(A.name),A.castShadow=!0,A.receiveShadow=!0,(Array.isArray(A.material)?A.material:[A.material]).forEach(d=>{l.add(d.name),console.log(`[Model] 📦 Material found: "${d.name}" (uuid: ${d.uuid})`);const w=d;console.log(` - Has map: ${w.map?"YES":"NO"}`),console.log(` - Has normalMap: ${w.normalMap?"YES":"NO"}`),console.log(` - Has roughnessMap: ${w.roughnessMap?"YES":"NO"}`),console.log(` - Has metalnessMap: ${w.metalnessMap?"YES":"NO"}`)})}}),console.log(`[Model] 📊 Clone summary: ${s.length} meshes, ${l.size} materials`),setTimeout(()=>{var p;(p=i.current)==null||p.call(i,{meshes:s.sort(),materials:Array.from(l).sort(),bones:f.sort(),nodeCount:S})},0),b},[n]);K(u,c),G(u,g),z(u,y);const m=typeof a=="number"?[a,a,a]:a;return M.jsx("group",{position:r,rotation:o,scale:m,children:M.jsx("primitive",{object:u})})}te.preload=t=>{I.useGLTF.preload(t)};function re(t,r,o){const{actions:a,names:c}=I.useAnimations(t,r),g=e.useRef(null),y=e.useRef(o==null?void 0:o.defaultAnimation);e.useEffect(()=>{if(c.length===0)return;const i=y.current;let u=c[0];if(i){const b=c.find(s=>s===i||s.includes(i));b&&(u=b)}const m=a[u];m&&(m.reset().fadeIn(.5).play(),g.current=m)},[a,c]);const T=e.useCallback((i,u)=>{const{loop:m=!1,crossFadeDuration:b=.2,restoreDefault:s=!0}=u||{};let l=a[i];if(!l){const S=Object.keys(a).find(p=>p.toLowerCase().includes(i.toLowerCase())||i.toLowerCase().includes(p.toLowerCase()));S&&(l=a[S])}if(!l){console.warn(`Animation "${i}" not found. Available: ${c.join(", ")}`);return}const f=g.current;if(!(f===l&&l.isRunning())&&(f&&f!==l&&f.fadeOut(b),l.reset(),l.fadeIn(b),l.setLoop(m?R.LoopRepeat:R.LoopOnce,m?1/0:1),l.clampWhenFinished=!m,l.play(),m||l.getMixer().update(0),g.current=l,s&&!m&&y.current)){const S=l.getMixer(),p=A=>{if(A.action===l){S.removeEventListener("finished",p);const E=a[y.current];E&&(l.fadeOut(b),E.reset().fadeIn(b).play(),g.current=E)}};S.addEventListener("finished",p)}},[a,c]),h=e.useCallback(()=>{var i;(i=g.current)==null||i.fadeOut(.2),g.current=null},[]),n=e.useCallback(()=>c,[c]);return{playAnimation:T,stopAnimation:h,getAnimationNames:n,actions:a}}function q(t,r){const o=e.useRef(r||{}),a=e.useRef([]),c=e.useRef([]);e.useEffect(()=>{const h=new Set,n=[];t.traverse(i=>{i instanceof R.Mesh&&i.morphTargetDictionary&&i.morphTargetInfluences&&(n.push(i),Object.keys(i.morphTargetDictionary).forEach(u=>{h.add(u)}))}),a.current=Array.from(h).sort(),c.current=n},[t]),B.useFrame(()=>{const h=o.current;c.current.forEach(n=>{!n.morphTargetDictionary||!n.morphTargetInfluences||Object.entries(h).forEach(([i,u])=>{const m=n.morphTargetDictionary[i];m!==void 0&&(n.morphTargetInfluences[m]=u)})})}),e.useEffect(()=>{r&&(o.current={...r})},[r]);const g=e.useCallback((h,n)=>{o.current[h]=Math.max(0,Math.min(1,n))},[]),y=e.useCallback(()=>a.current,[]),T=e.useCallback(()=>({...o.current}),[]);return{setMorphTarget:g,getMorphTargetNames:y,getMorphTargetValues:T}}const oe=e.createContext(null);function ge(){const t=e.useContext(oe);if(!t)throw new Error("BoneAttachment must be used within an AnimatedModel");return t}const V=e.forwardRef(({url:t,position:r=[0,0,0],rotation:o=[0,0,0],scale:a=1,defaultAnimation:c,morphTargets:g,meshVisibility:y,materialColors:T,materialTextures:h,onLoad:n,onError:i,children:u},m)=>{const b=e.useRef(null),s=e.useRef([]),l=e.useRef(n);l.current=n;const{scene:f,animations:S}=I.useGLTF(t),p=e.useMemo(()=>ee.clone(f),[f]),{playAnimation:A,stopAnimation:E,getAnimationNames:d}=re(S,p,{defaultAnimation:c}),{setMorphTarget:w}=q(p,g),{setMeshVisibility:N,getMeshNames:x}=K(p,y),{setMaterialColor:v,getMaterialNames:L,getMaterialColor:$}=G(p,T),{setMaterialTextures:j,clearMaterialTextures:C}=z(p,h);e.useEffect(()=>{if(!p)return;const P=setTimeout(()=>{var J;const O=[],W=[],_=new Set,Y=new Set;let Z=0;p.traverse(F=>{if(Z++,F.type==="Bone"&&O.push(F.name),F.isMesh){const X=F;W.push(X.name),X.castShadow=!0,X.receiveShadow=!0,(Array.isArray(X.material)?X.material:[X.material]).forEach(U=>{_.add(U.name),U.shadowSide=R.DoubleSide}),X.morphTargetDictionary&&Object.keys(X.morphTargetDictionary).forEach(U=>{Y.add(U)})}}),s.current=Array.from(Y).sort(),(J=l.current)==null||J.call(l,{meshes:W.sort(),materials:Array.from(_).sort(),bones:O.sort(),nodeCount:Z,animations:S.map(F=>F.name),morphTargetNames:s.current})},0);return()=>clearTimeout(P)},[p,S]),e.useImperativeHandle(m,()=>({playAnimation:A,stopAnimation:E,getAnimationNames:d,getGroup:()=>b.current,setMorphTarget:w,getMorphTargetNames:()=>s.current,setMeshVisibility:N,getMeshNames:x,setMaterialColor:v,getMaterialNames:L,getMaterialColor:$,setMaterialTextures:j,clearMaterialTextures:C}));const k=e.useMemo(()=>({scene:p,getBone:P=>p.getObjectByName(P)||null}),[p]),D=typeof a=="number"?[a,a,a]:a;return M.jsx(oe.Provider,{value:k,children:M.jsxs("group",{ref:b,position:r,rotation:o,scale:D,children:[M.jsx("primitive",{object:p}),u]})})});V.displayName="AnimatedModel";V.preload=t=>{I.useGLTF.preload(t)};const se=e.forwardRef(({url:t,position:r=[0,0,0],rotation:o=[0,0,0],scale:a=1,morphTargets:c,meshVisibility:g,materialColors:y,materialTextures:T,onMorphTargetsFound:h,onLoad:n,onError:i},u)=>{const{scene:m}=I.useGLTF(t),b=e.useRef(n);b.current=n;const s=e.useRef(h);s.current=h;const l=e.useMemo(()=>m.clone(),[m]),{setMorphTarget:f,getMorphTargetNames:S,getMorphTargetValues:p}=q(l,c),{setMeshVisibility:A,getMeshNames:E}=K(l,g),{setMaterialColor:d,getMaterialNames:w,getMaterialColor:N}=G(l,y),{setMaterialTextures:x,clearMaterialTextures:v}=z(l,T);e.useEffect(()=>{var j;const $=S();$.length>0&&((j=s.current)==null||j.call(s,$))},[l,S]),e.useEffect(()=>{var D;if(!l)return;const $=[],j=new Set,C=[];let k=0;l.traverse(P=>{if(k++,P.type==="Bone"&&C.push(P.name),P.isMesh){const O=P;$.push(O.name),O.castShadow=!0,O.receiveShadow=!0,(Array.isArray(O.material)?O.material:[O.material]).forEach(_=>j.add(_.name))}}),(D=b.current)==null||D.call(b,{meshes:$.sort(),materials:Array.from(j).sort(),bones:C.sort(),nodeCount:k})},[l]),e.useImperativeHandle(u,()=>({setMorphTarget:f,getMorphTargetNames:S,getMorphTargetValues:p,setMeshVisibility:A,getMeshNames:E,setMaterialColor:d,getMaterialNames:w,getMaterialColor:N,setMaterialTextures:x,clearMaterialTextures:v}));const L=typeof a=="number"?[a,a,a]:a;return M.jsx("group",{position:r,rotation:o,scale:L,children:M.jsx("primitive",{object:l})})});se.displayName="MorphableModel";function he({children:t,bone:r,position:o=[0,0,0],rotation:a=[0,0,0],scale:c=1}){const{getBone:g}=ge(),[y,T]=e.useState(null);if(e.useEffect(()=>{const n=g(r);n?T(n):console.warn(`Bone "${r}" not found in model`)},[r,g]),!y)return null;const h=typeof c=="number"?[c,c,c]:c;return B.createPortal(M.jsx("group",{position:o,rotation:a,scale:h,children:t}),y)}function Me(t,r){const{scene:o,animations:a}=I.useGLTF(t),c=e.useMemo(()=>ee.clone(o),[o]);return e.useEffect(()=>{var n;if(!c)return;const g=[],y=[],T=new Set;let h=0;c.traverse(i=>{if(h++,i.type==="Bone"&&g.push(i.name),i.isMesh){const u=i;y.push(u.name),u.castShadow=!0,u.receiveShadow=!0,(Array.isArray(u.material)?u.material:[u.material]).forEach(b=>{T.add(b.name),b.shadowSide=R.DoubleSide})}}),(n=r==null?void 0:r.onLoad)==null||n.call(r,{meshes:y.sort(),materials:Array.from(T).sort(),bones:g.sort(),nodeCount:h})},[c,r]),{scene:c,animations:a}}function be(t){I.useGLTF.preload(t)}exports.AnimatedModel=V;exports.BoneAttachment=he;exports.Model=te;exports.MorphableModel=se;exports.Scene3D=de;exports.preloadModel=be;exports.useAnimationController=re;exports.useClonedModel=Me;exports.useMaterialColor=G;exports.useMaterialTexture=z;exports.useMeshVisibility=K;exports.useMorphTargets=q;
2
2
  //# sourceMappingURL=mbt-3d.cjs.map