mbt-3d 0.3.7 → 0.3.9

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
@@ -185,6 +185,8 @@ export declare interface AnimatedModelProps extends Omit<ModelProps, 'onLoad'> {
185
185
  children?: React.ReactNode;
186
186
  /** Name of animation to play on load (auto-plays first if not specified) */
187
187
  defaultAnimation?: string;
188
+ /** Controlled animation name. When changed, AnimatedModel switches to this animation */
189
+ animation?: string;
188
190
  /** Morph target values as key-value pairs { targetName: value } where value is 0-1 */
189
191
  morphTargets?: Record<string, number>;
190
192
  /** Mesh visibility as key-value pairs { meshName: visible }. Example: { "Hairgirl1": true, "Hairgirl2": false } */
@@ -666,7 +668,7 @@ export declare function preloadModel(url: string): void;
666
668
  * </Scene3D>
667
669
  * ```
668
670
  */
669
- export declare function Scene3D({ children, camera, controls, background, shadows, lights, environment, contactShadows, style, className, }: Scene3DProps): JSX_2.Element;
671
+ export declare function Scene3D({ children, camera, controls, background, shadows, lights, environment, contactShadows, showLoadingOverlay, style, className, }: Scene3DProps): JSX_2.Element;
670
672
 
671
673
  /**
672
674
  * Props for Scene3D component
@@ -737,6 +739,8 @@ export declare interface Scene3DProps {
737
739
  /** Shadow blur amount. Default: 2 */
738
740
  blur?: number;
739
741
  };
742
+ /** Show full-scene loading overlay while models/textures are loading. Default: true */
743
+ showLoadingOverlay?: boolean;
740
744
  /** Container style (e.g., { width: 400, height: 500 }) */
741
745
  style?: React.CSSProperties;
742
746
  /** 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 r=require("react"),O=require("@react-three/drei"),ne=require("three"),ae=require("three/examples/jsm/utils/SkeletonUtils.js"),B=require("@react-three/fiber"),le=require("three/examples/jsm/loaders/KTX2Loader.js"),S=require("react/jsx-runtime");function Q(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const a=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,a.get?a:{enumerable:!0,get:()=>e[o]})}}return t.default=e,Object.freeze(t)}const R=Q(ne),ee=Q(ae);function ie({position:e,controlsConfig:t}){const{camera:o}=B.useThree(),a=r.useRef(null);return r.useEffect(()=>{e&&o&&(o.position.set(e[0],e[1],e[2]),o.updateProjectionMatrix(),a.current&&(a.current.target.set(0,0,0),a.current.update()))},[e,o]),S.jsx(O.OrbitControls,{ref:a,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 ce({background:e}){const t=e==null?void 0:e.startsWith("#");return e?t?S.jsx("color",{attach:"background",args:[e]}):S.jsx(ue,{url:e}):null}function ue({url:e}){const t=O.useTexture(e);return r.useMemo(()=>{t.colorSpace=R.SRGBColorSpace},[t]),S.jsx("primitive",{attach:"background",object:t})}function me({config:e}){return S.jsx(O.Environment,{files:e.files,background:e.background??!1,blur:e.blur??0,children:S.jsx("group",{scale:e.intensity??1,children:S.jsx("ambientLight",{intensity:0})})})}function pe({config:e}){switch(e.type){case"spot":{const{position:t=[5,10,5],intensity:o=50,castShadow:a=!0,angle:c=Math.PI/6,penumbra:M=.5,decay:b=2,distance:T=0,color:g="#ffffff"}=e;return S.jsx("spotLight",{position:t,intensity:o,castShadow:a,angle:c,penumbra:M,decay:b,distance:T,color:g})}case"point":{const{position:t=[0,5,0],intensity:o=20,color:a="#ffffff",distance:c=0,decay:M=2,castShadow:b=!1}=e;return S.jsx("pointLight",{position:t,intensity:o,color:a,distance:c,decay:M,castShadow:b})}case"directional":{const{position:t=[10,20,10],intensity:o=40,color:a="#ffffff",castShadow:c=!0}=e;return S.jsx("directionalLight",{position:t,intensity:o,color:a,castShadow:c})}case"hemisphere":{const{skyColor:t="#ffffff",groundColor:o="#444444",intensity:a=.5,position:c=[0,10,0]}=e,M=r.useMemo(()=>new R.Color(t),[t]),b=r.useMemo(()=>new R.Color(o),[o]);return S.jsx("hemisphereLight",{args:[M,b,a],position:c})}case"ambient":{const{intensity:t=.5,color:o="#ffffff"}=e;return S.jsx("ambientLight",{intensity:t,color:o})}default:return null}}function fe({children:e,camera:t={},controls:o={},background:a,shadows:c=!0,lights:M=[{type:"ambient",intensity:.5},{type:"spot",position:[5,10,5],intensity:50,castShadow:!0}],environment:b,contactShadows:T=!0,style:g,className:l}){const s={position:t.position||[0,2,5],fov:t.fov||45},u={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},m=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 S.jsx("div",{style:g,className:l,children:S.jsxs(B.Canvas,{shadows:c,camera:{position:s.position,fov:s.fov},style:{width:"100%",height:"100%"},children:[S.jsx(r.Suspense,{fallback:null,children:S.jsx(ce,{background:a})}),b&&S.jsx(r.Suspense,{fallback:null,children:S.jsx(me,{config:b})}),M.map((h,n)=>S.jsx(pe,{config:h},`${h.type}-${n}`)),S.jsx(r.Suspense,{fallback:null,children:e}),S.jsx(ie,{position:s.position,controlsConfig:u}),m&&S.jsx(O.ContactShadows,{position:m.position,opacity:m.opacity,blur:m.blur})]})})}function K(e,t){const o=r.useRef(new Map),a=r.useRef({}),c=r.useRef({});r.useEffect(()=>{t&&(a.current={...t})},[t]),r.useEffect(()=>{if(!e)return;const g=new Map;e.traverse(l=>{if(l.isMesh){const s=l;s.name&&g.set(s.name,s)}}),o.current=g},[e]),B.useFrame(()=>{const g=o.current;if(g.size===0)return;const l={...a.current,...c.current};for(const[s,u]of Object.entries(l)){const m=g.get(s);m&&m.visible!==u&&(m.visible=u)}});const M=r.useCallback((g,l)=>{c.current[g]=l;const s=o.current.get(g);s&&(s.visible=l)},[]),b=r.useCallback(()=>Array.from(o.current.keys()).sort(),[]),T=r.useCallback(()=>{const g={};return o.current.forEach((l,s)=>{g[s]=l.visible}),g},[]);return{setMeshVisibility:M,getMeshNames:b,getMeshVisibility:T}}function G(e,t){const o=r.useRef(new Map),a=r.useRef(new Map);r.useEffect(()=>{if(!e)return;const l=new Map;e.traverse(s=>{if(s.isMesh){const u=s;(Array.isArray(u.material)?u.material:[u.material]).forEach(h=>{h.name&&!l.has(h.name)&&l.set(h.name,h)})}}),o.current=l,t&&Object.entries(t).forEach(([s,u])=>{const m=l.get(s);if(m&&!Array.isArray(m)){const h=c(u);m.color&&m.color.copy(h),a.current.set(s,h)}})},[e,t]),B.useFrame(()=>{a.current.forEach((l,s)=>{const u=o.current.get(s);if(u&&!Array.isArray(u)){const m=u;m.color&&!m.color.equals(l)&&(m.color.copy(l),m.needsUpdate=!0)}})});const c=l=>typeof l=="string"?new R.Color(l):new R.Color(l[0],l[1],l[2]),M=r.useCallback((l,s)=>{const u=c(s);a.current.set(l,u);const m=o.current.get(l);if(m&&!Array.isArray(m)){const h=m;h.color&&(h.color.copy(u),h.needsUpdate=!0)}},[]),b=r.useCallback(()=>Array.from(o.current.keys()).sort(),[]),T=r.useCallback(l=>{const s=o.current.get(l);if(s&&!Array.isArray(s)){const u=s;if(u.color)return"#"+u.color.getHexString()}return null},[]),g=r.useCallback(()=>{const l={};return o.current.forEach((s,u)=>{if(!Array.isArray(s)){const m=s;m.color&&(l[u]="#"+m.color.getHexString())}}),l},[]);return{setMaterialColor:M,getMaterialNames:b,getMaterialColor:T,getAllMaterialColors:g}}function H(e){const t=e.toLowerCase();if(t.endsWith(".ktx2"))return!0;try{const o=new URL(e,window.location.origin),a=decodeURIComponent(o.hash.replace(/^#/,"")).toLowerCase(),c=decodeURIComponent(o.search).toLowerCase(),M=decodeURIComponent(o.pathname).toLowerCase();return a.endsWith(".ktx2")||c.includes(".ktx2")||M.endsWith(".ktx2")}catch{return t.includes(".ktx2")}}function z(e,t){const{gl:o}=B.useThree(),a=r.useRef(new Map),c=r.useRef(new R.TextureLoader),M=r.useRef(null),b=r.useRef(new Map),T=r.useRef(new Set),g=r.useRef("");r.useEffect(()=>{if(!M.current)try{const n=typeof WebAssembly=="object"&&typeof WebAssembly.validate=="function";console.log("[useMaterialTexture] Browser features:"),console.log(` WebAssembly supported: ${n}`),console.log(` WebGL2: ${o.capabilities.isWebGL2}`);const i=new le.KTX2Loader;i.setTranscoderPath("/basis/"),i.detectSupport(o),M.current=i,console.log("[useMaterialTexture] ✅ KTX2Loader initialized"),console.log("[useMaterialTexture] Transcoder path: /basis/"),fetch("/basis/basis_transcoder.wasm").then(p=>{p.ok?console.log("[useMaterialTexture] ✅ basis_transcoder.wasm is accessible"):console.error("[useMaterialTexture] ❌ basis_transcoder.wasm returned",p.status)}).catch(p=>{console.error("[useMaterialTexture] ❌ Failed to check basis_transcoder.wasm:",p)}),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()=>{M.current&&(M.current.dispose(),M.current=null)}},[o]),r.useEffect(()=>{if(!e)return;const n=new Map;e.traverse(i=>{if(i.isMesh){const p=i;(Array.isArray(p.material)?p.material:[p.material]).forEach(f=>{f.name&&!n.has(f.name)&&n.set(f.name,f)})}}),a.current=n},[e]);const l=r.useCallback(n=>H(n)?M.current?M.current:(console.warn("[useMaterialTexture] KTX2Loader not initialized, falling back to TextureLoader"),c.current):c.current,[]);r.useEffect(()=>{if(!t||!e)return;const n=a.current;if(n.size===0)return;const i=JSON.stringify(t);if(g.current===i){console.log("[useMaterialTexture] Textures unchanged, skipping reload");return}g.current=i;let p=!1;const w=new Map;Object.entries(t).forEach(([d,$])=>{w.set(d,typeof $=="string"?{map:$}:$)}),console.log("[useMaterialTexture] Starting texture load for",w.size,"materials");const f=[];w.forEach((d,$)=>{var A,L;const D=n.get($);if(!D||!D.isMeshStandardMaterial){console.warn(`[useMaterialTexture] Material "${$}" not found or not MeshStandardMaterial`);return}const y=D;console.log(`[useMaterialTexture] 📋 Material "${$}" BEFORE reset:`),console.log(` - map: ${y.map?"EXISTS":"null"} ${y.map?`(uuid: ${y.map.uuid})`:""}`),console.log(` - normalMap: ${y.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${y.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${y.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${y.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${y.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(A=y.color)==null?void 0:A.getHexString()}`),console.log(` - emissive: ${(L=y.emissive)==null?void 0:L.getHexString()}`),console.log(` - material uuid: ${y.uuid}`),Object.entries(d).forEach(([x,C])=>{if(!C)return;const j=x,k=y[j];k&&(console.log(`[useMaterialTexture] 🗑️ Disposing old ${j} (uuid: ${k.uuid})`),k.dispose(),y[j]=null)}),d.emissiveMap&&(y.emissive=new R.Color(0),y.emissiveIntensity=0),y.needsUpdate=!0,y.color=new R.Color(16777215),console.log(`[useMaterialTexture] ✅ Material "${$}" AFTER reset: only specified maps cleared`),Object.entries(d).forEach(([x,C])=>{if(!C)return;const j=`${$}_${x}_${C}`,k=b.current.get(j);if(k){console.log(`[useMaterialTexture] Using cached texture: ${$}.${x}`),p||s(y,x,k);return}if(T.current.has(j)){console.log(`[useMaterialTexture] Skipping already loading: ${$}.${x}`);return}f.push({materialName:$,textureType:x,url:C,material:y})})}),console.log(`[useMaterialTexture] Queued ${f.length} textures to load`);let E=0;const v=()=>{if(p||E>=f.length){console.log("[useMaterialTexture] ✅ All textures loaded"),console.log("[useMaterialTexture] 📊 FINAL material states:"),n.forEach((A,L)=>{var C,j;const x=A;console.log(` Material "${L}":`),console.log(` - map: ${x.map?"EXISTS":"null"} ${x.map?`(colorSpace: ${x.map.colorSpace})`:""}`),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(` - color: ${(C=x.color)==null?void 0:C.getHexString()}`),console.log(` - emissive: ${(j=x.emissive)==null?void 0:j.getHexString()}`),console.log(` - emissiveIntensity: ${x.emissiveIntensity}`),console.log(` - roughness: ${x.roughness}`),console.log(` - metalness: ${x.metalness}`)});return}const d=f[E++],$=`${d.materialName}_${d.textureType}_${d.url}`;console.log(`[useMaterialTexture] Loading (${E}/${f.length}): ${d.materialName}.${d.textureType} from ${d.url}`),T.current.add($);const D=l(d.url),y=H(d.url)?"KTX2Loader":"TextureLoader";console.log(`[useMaterialTexture] Using ${y} for ${d.url}`),D.load(d.url,A=>{var j,k,P,X,I,F;if(T.current.delete($),p){console.log(`[useMaterialTexture] Disposed, cleaning up texture: ${d.materialName}.${d.textureType}`),A.dispose();return}const L=((j=A.image)==null?void 0:j.width)||((P=(k=A.source)==null?void 0:k.data)==null?void 0:P.width)||"unknown",x=((X=A.image)==null?void 0:X.height)||((F=(I=A.source)==null?void 0:I.data)==null?void 0:F.height)||"unknown";console.log(`[useMaterialTexture] ✅ Loaded: ${d.materialName}.${d.textureType} (${L}x${x})`),A.colorSpace=d.textureType==="map"||d.textureType==="emissiveMap"?R.SRGBColorSpace:R.NoColorSpace,A.wrapS=R.RepeatWrapping,A.wrapT=R.RepeatWrapping,A.flipY=!1,b.current.set($,A),s(d.material,d.textureType,A);const C=H(d.url)?500:150;console.log(`[useMaterialTexture] Waiting111111 ${C}ms before next texture...`),setTimeout(v,0)},A=>{if(A.lengthComputable){const L=Math.round(A.loaded/A.total*100);L%25===0&&console.log(`[useMaterialTexture] Progress ${d.materialName}.${d.textureType}: ${L}%`)}},A=>{T.current.delete($),p||(console.error(`[useMaterialTexture] ❌ Failed to load ${d.materialName}.${d.textureType} from ${d.url}`),console.error("[useMaterialTexture] Error details:",A),console.error("[useMaterialTexture] Loader type:",y),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(v,100)})};return v(),()=>{console.log("[useMaterialTexture] Cleanup: disposed"),p=!0}},[e,t,l]);const s=(n,i,p)=>{var w,f;switch(console.log(`[useMaterialTexture] 🎨 Applying texture: ${n.name}.${i} (texture uuid: ${p.uuid})`),i){case"map":n.map=p;break;case"normalMap":n.normalMap=p;break;case"roughnessMap":n.roughnessMap=p;break;case"metalnessMap":n.metalnessMap=p;break;case"emissiveMap":n.emissiveMap=p,n.emissive=new R.Color(16777215),n.emissiveIntensity=1;break;case"alphaMap":console.log(`[useMaterialTexture] Skipping alphaMap for "${n.name}" to prevent disappearing`);break;case"aoMap":n.aoMap=p;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: ${(w=n.color)==null?void 0:w.getHexString()}`),console.log(` - emissive: ${(f=n.emissive)==null?void 0:f.getHexString()}`),console.log(` - emissiveIntensity: ${n.emissiveIntensity}`),console.log(` - roughness: ${n.roughness}`),console.log(` - metalness: ${n.metalness}`)},u=r.useCallback((n,i)=>{const p=typeof i=="string"?{map:i}:i,w=a.current.get(n);if(!w||!w.isMeshStandardMaterial){console.warn(`Material "${n}" not found or not MeshStandardMaterial`);return}const f=w;Object.entries(p).forEach(([E,v])=>{if(!v)return;const d=`${n}_${E}_${v}`,$=b.current.get(d);if($){s(f,E,$);return}l(v).load(v,y=>{y.colorSpace=E==="map"||E==="emissiveMap"?R.SRGBColorSpace:R.NoColorSpace,y.wrapS=R.RepeatWrapping,y.wrapT=R.RepeatWrapping,b.current.set(d,y),s(f,E,y)},void 0,y=>{console.error(`Failed to load texture ${v}:`,y)})})},[l]),m=r.useCallback(()=>Array.from(a.current.keys()).sort(),[]),h=r.useCallback(n=>{const i=a.current.get(n);if(!i||!i.isMeshStandardMaterial)return;const p=i;p.map=null,p.normalMap=null,p.roughnessMap=null,p.metalnessMap=null,p.emissiveMap=null,p.alphaMap=null,p.aoMap=null,p.needsUpdate=!0},[]);return{setMaterialTextures:u,getMaterialNames:m,clearMaterialTextures:h}}function te({url:e,position:t=[0,0,0],rotation:o=[0,0,0],scale:a=1,meshVisibility:c,materialColors:M,materialTextures:b,onLoad:T,onError:g}){const{scene:l}=O.useGLTF(e),s=r.useRef(T);s.current=T;const u=r.useMemo(()=>{const h=l.clone();console.log("[Model] 🔍 Scene clone created, checking materials...");const n=[],i=new Set,p=[];let w=0;return h.traverse(f=>{if(w++,f.type==="Bone"&&p.push(f.name),f.isMesh){const E=f;n.push(E.name),E.castShadow=!0,E.receiveShadow=!0,(Array.isArray(E.material)?E.material:[E.material]).forEach(d=>{i.add(d.name),console.log(`[Model] 📦 Material found: "${d.name}" (uuid: ${d.uuid})`);const $=d;console.log(` - Has map: ${$.map?"YES":"NO"}`),console.log(` - Has normalMap: ${$.normalMap?"YES":"NO"}`),console.log(` - Has roughnessMap: ${$.roughnessMap?"YES":"NO"}`),console.log(` - Has metalnessMap: ${$.metalnessMap?"YES":"NO"}`)})}}),console.log(`[Model] 📊 Clone summary: ${n.length} meshes, ${i.size} materials`),setTimeout(()=>{var f;(f=s.current)==null||f.call(s,{meshes:n.sort(),materials:Array.from(i).sort(),bones:p.sort(),nodeCount:w})},0),h},[l]);K(u,c),G(u,M),z(u,b);const m=typeof a=="number"?[a,a,a]:a;return S.jsx("group",{position:t,rotation:o,scale:m,children:S.jsx("primitive",{object:u})})}te.preload=e=>{O.useGLTF.preload(e)};function re(e,t,o){const{actions:a,names:c}=O.useAnimations(e,t),M=r.useRef(null),b=r.useRef(o==null?void 0:o.defaultAnimation);r.useEffect(()=>{if(c.length===0)return;const s=b.current;let u=c[0];if(s){const h=c.find(n=>n===s||n.includes(s));h&&(u=h)}const m=a[u];m&&(m.reset().fadeIn(.5).play(),M.current=m)},[a,c]);const T=r.useCallback((s,u)=>{const{loop:m=!1,crossFadeDuration:h=.2,restoreDefault:n=!0}=u||{};let i=a[s];if(!i){const w=Object.keys(a).find(f=>f.toLowerCase().includes(s.toLowerCase())||s.toLowerCase().includes(f.toLowerCase()));w&&(i=a[w])}if(!i){console.warn(`Animation "${s}" not found. Available: ${c.join(", ")}`);return}const p=M.current;if(!(p===i&&i.isRunning())&&(p&&p!==i&&p.fadeOut(h),i.reset(),i.fadeIn(h),i.setLoop(m?R.LoopRepeat:R.LoopOnce,m?1/0:1),i.clampWhenFinished=!m,i.play(),m||i.getMixer().update(0),M.current=i,n&&!m&&b.current)){const w=i.getMixer(),f=E=>{if(E.action===i){w.removeEventListener("finished",f);const v=a[b.current];v&&(i.fadeOut(h),v.reset().fadeIn(h).play(),M.current=v)}};w.addEventListener("finished",f)}},[a,c]),g=r.useCallback(()=>{var s;(s=M.current)==null||s.fadeOut(.2),M.current=null},[]),l=r.useCallback(()=>c,[c]);return{playAnimation:T,stopAnimation:g,getAnimationNames:l,actions:a}}function q(e,t){const o=r.useRef(t||{}),a=r.useRef([]),c=r.useRef([]);r.useEffect(()=>{const g=new Set,l=[];e.traverse(s=>{s instanceof R.Mesh&&s.morphTargetDictionary&&s.morphTargetInfluences&&(l.push(s),Object.keys(s.morphTargetDictionary).forEach(u=>{g.add(u)}))}),a.current=Array.from(g).sort(),c.current=l},[e]),B.useFrame(()=>{const g=o.current;c.current.forEach(l=>{!l.morphTargetDictionary||!l.morphTargetInfluences||Object.entries(g).forEach(([s,u])=>{const m=l.morphTargetDictionary[s];m!==void 0&&(l.morphTargetInfluences[m]=u)})})}),r.useEffect(()=>{t&&(o.current={...t})},[t]);const M=r.useCallback((g,l)=>{o.current[g]=Math.max(0,Math.min(1,l))},[]),b=r.useCallback(()=>a.current,[]),T=r.useCallback(()=>({...o.current}),[]);return{setMorphTarget:M,getMorphTargetNames:b,getMorphTargetValues:T}}const oe=r.createContext(null);function de(){const e=r.useContext(oe);if(!e)throw new Error("BoneAttachment must be used within an AnimatedModel");return e}const V=r.forwardRef(({url:e,position:t=[0,0,0],rotation:o=[0,0,0],scale:a=1,defaultAnimation:c,morphTargets:M,meshVisibility:b,materialColors:T,materialTextures:g,onLoad:l,onError:s,children:u},m)=>{const h=r.useRef(null),n=r.useRef([]),i=r.useRef(l);i.current=l;const{scene:p,animations:w}=O.useGLTF(e),f=r.useMemo(()=>ee.clone(p),[p]),{playAnimation:E,stopAnimation:v,getAnimationNames:d}=re(w,f,{defaultAnimation:c}),{setMorphTarget:$}=q(f,M),{setMeshVisibility:D,getMeshNames:y}=K(f,b),{setMaterialColor:A,getMaterialNames:L,getMaterialColor:x}=G(f,T),{setMaterialTextures:C,clearMaterialTextures:j}=z(f,g);r.useEffect(()=>{if(!f)return;const X=setTimeout(()=>{var J;const I=[],F=[],_=new Set,Y=new Set;let Z=0;f.traverse(W=>{if(Z++,W.type==="Bone"&&I.push(W.name),W.isMesh){const N=W;F.push(N.name),N.castShadow=!0,N.receiveShadow=!0,(Array.isArray(N.material)?N.material:[N.material]).forEach(U=>{_.add(U.name),U.shadowSide=R.DoubleSide}),N.morphTargetDictionary&&Object.keys(N.morphTargetDictionary).forEach(U=>{Y.add(U)})}}),n.current=Array.from(Y).sort(),(J=i.current)==null||J.call(i,{meshes:F.sort(),materials:Array.from(_).sort(),bones:I.sort(),nodeCount:Z,animations:w.map(W=>W.name),morphTargetNames:n.current})},0);return()=>clearTimeout(X)},[f,w]),r.useImperativeHandle(m,()=>({playAnimation:E,stopAnimation:v,getAnimationNames:d,getGroup:()=>h.current,setMorphTarget:$,getMorphTargetNames:()=>n.current,setMeshVisibility:D,getMeshNames:y,setMaterialColor:A,getMaterialNames:L,getMaterialColor:x,setMaterialTextures:C,clearMaterialTextures:j}));const k=r.useMemo(()=>({scene:f,getBone:X=>f.getObjectByName(X)||null}),[f]),P=typeof a=="number"?[a,a,a]:a;return S.jsx(oe.Provider,{value:k,children:S.jsxs("group",{ref:h,position:t,rotation:o,scale:P,children:[S.jsx("primitive",{object:f}),u]})})});V.displayName="AnimatedModel";V.preload=e=>{O.useGLTF.preload(e)};const se=r.forwardRef(({url:e,position:t=[0,0,0],rotation:o=[0,0,0],scale:a=1,morphTargets:c,meshVisibility:M,materialColors:b,materialTextures:T,onMorphTargetsFound:g,onLoad:l,onError:s},u)=>{const{scene:m}=O.useGLTF(e),h=r.useRef(l);h.current=l;const n=r.useRef(g);n.current=g;const i=r.useMemo(()=>m.clone(),[m]),{setMorphTarget:p,getMorphTargetNames:w,getMorphTargetValues:f}=q(i,c),{setMeshVisibility:E,getMeshNames:v}=K(i,M),{setMaterialColor:d,getMaterialNames:$,getMaterialColor:D}=G(i,b),{setMaterialTextures:y,clearMaterialTextures:A}=z(i,T);r.useEffect(()=>{var C;const x=w();x.length>0&&((C=n.current)==null||C.call(n,x))},[i,w]),r.useEffect(()=>{var P;if(!i)return;const x=[],C=new Set,j=[];let k=0;i.traverse(X=>{if(k++,X.type==="Bone"&&j.push(X.name),X.isMesh){const I=X;x.push(I.name),I.castShadow=!0,I.receiveShadow=!0,(Array.isArray(I.material)?I.material:[I.material]).forEach(_=>C.add(_.name))}}),(P=h.current)==null||P.call(h,{meshes:x.sort(),materials:Array.from(C).sort(),bones:j.sort(),nodeCount:k})},[i]),r.useImperativeHandle(u,()=>({setMorphTarget:p,getMorphTargetNames:w,getMorphTargetValues:f,setMeshVisibility:E,getMeshNames:v,setMaterialColor:d,getMaterialNames:$,getMaterialColor:D,setMaterialTextures:y,clearMaterialTextures:A}));const L=typeof a=="number"?[a,a,a]:a;return S.jsx("group",{position:t,rotation:o,scale:L,children:S.jsx("primitive",{object:i})})});se.displayName="MorphableModel";function Me({children:e,bone:t,position:o=[0,0,0],rotation:a=[0,0,0],scale:c=1}){const{getBone:M}=de(),[b,T]=r.useState(null);if(r.useEffect(()=>{const l=M(t);l?T(l):console.warn(`Bone "${t}" not found in model`)},[t,M]),!b)return null;const g=typeof c=="number"?[c,c,c]:c;return B.createPortal(S.jsx("group",{position:o,rotation:a,scale:g,children:e}),b)}function ge(e,t){const{scene:o,animations:a}=O.useGLTF(e),c=r.useMemo(()=>ee.clone(o),[o]);return r.useEffect(()=>{var l;if(!c)return;const M=[],b=[],T=new Set;let g=0;c.traverse(s=>{if(g++,s.type==="Bone"&&M.push(s.name),s.isMesh){const u=s;b.push(u.name),u.castShadow=!0,u.receiveShadow=!0,(Array.isArray(u.material)?u.material:[u.material]).forEach(h=>{T.add(h.name),h.shadowSide=R.DoubleSide})}}),(l=t==null?void 0:t.onLoad)==null||l.call(t,{meshes:b.sort(),materials:Array.from(T).sort(),bones:M.sort(),nodeCount:g})},[c,t]),{scene:c,animations:a}}function he(e){O.useGLTF.preload(e)}exports.AnimatedModel=V;exports.BoneAttachment=Me;exports.Model=te;exports.MorphableModel=se;exports.Scene3D=fe;exports.preloadModel=he;exports.useAnimationController=re;exports.useClonedModel=ge;exports.useMaterialColor=G;exports.useMaterialTexture=z;exports.useMeshVisibility=K;exports.useMorphTargets=q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),O=require("@react-three/drei"),ae=require("three"),le=require("three/examples/jsm/utils/SkeletonUtils.js"),B=require("@react-three/fiber"),ie=require("three/examples/jsm/loaders/KTX2Loader.js"),h=require("react/jsx-runtime");function ee(r){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const e in r)if(e!=="default"){const l=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(s,e,l.get?l:{enumerable:!0,get:()=>r[e]})}}return s.default=r,Object.freeze(s)}const R=ee(ae),te=ee(le);function ce({position:r,controlsConfig:s}){const{camera:e}=B.useThree(),l=t.useRef(null);return t.useEffect(()=>{r&&e&&(e.position.set(r[0],r[1],r[2]),e.updateProjectionMatrix(),l.current&&(l.current.target.set(0,0,0),l.current.update()))},[r,e]),h.jsx(O.OrbitControls,{ref:l,makeDefault:!0,enabled:s.enabled,enablePan:s.enablePan,enableZoom:s.enableZoom,enableRotate:s.enableRotate,minDistance:s.minDistance,maxDistance:s.maxDistance,minPolarAngle:s.minPolarAngle,maxPolarAngle:s.maxPolarAngle,autoRotate:s.autoRotate,autoRotateSpeed:s.autoRotateSpeed})}function ue({background:r}){const s=r==null?void 0:r.startsWith("#");return r?s?h.jsx("color",{attach:"background",args:[r]}):h.jsx(fe,{url:r}):null}function fe({url:r}){const s=O.useTexture(r);return t.useMemo(()=>{s.colorSpace=R.SRGBColorSpace},[s]),h.jsx("primitive",{attach:"background",object:s})}function me({config:r}){return h.jsx(O.Environment,{files:r.files,background:r.background??!1,blur:r.blur??0,children:h.jsx("group",{scale:r.intensity??1,children:h.jsx("ambientLight",{intensity:0})})})}function pe({config:r}){switch(r.type){case"spot":{const{position:s=[5,10,5],intensity:e=50,castShadow:l=!0,angle:u=Math.PI/6,penumbra:d=.5,decay:y=2,distance:S=0,color:g="#ffffff"}=r;return h.jsx("spotLight",{position:s,intensity:e,castShadow:l,angle:u,penumbra:d,decay:y,distance:S,color:g})}case"point":{const{position:s=[0,5,0],intensity:e=20,color:l="#ffffff",distance:u=0,decay:d=2,castShadow:y=!1}=r;return h.jsx("pointLight",{position:s,intensity:e,color:l,distance:u,decay:d,castShadow:y})}case"directional":{const{position:s=[10,20,10],intensity:e=40,color:l="#ffffff",castShadow:u=!0}=r;return h.jsx("directionalLight",{position:s,intensity:e,color:l,castShadow:u})}case"hemisphere":{const{skyColor:s="#ffffff",groundColor:e="#444444",intensity:l=.5,position:u=[0,10,0]}=r,d=t.useMemo(()=>new R.Color(s),[s]),y=t.useMemo(()=>new R.Color(e),[e]);return h.jsx("hemisphereLight",{args:[d,y,l],position:u})}case"ambient":{const{intensity:s=.5,color:e="#ffffff"}=r;return h.jsx("ambientLight",{intensity:s,color:e})}default:return null}}function de({onChange:r}){const{active:s,progress:e}=O.useProgress();return t.useEffect(()=>{r(s,e)},[s,e,r]),null}function ge({children:r,camera:s={},controls:e={},background:l,shadows:u=!0,lights:d=[{type:"ambient",intensity:.5},{type:"spot",position:[5,10,5],intensity:50,castShadow:!0}],environment:y,contactShadows:S=!0,showLoadingOverlay:g=!0,style:a,className:n}){const[f,m]=t.useState(!1),[x,o]=t.useState(0),i=t.useRef(null),c=t.useCallback((v,p)=>{if(v){i.current!==null&&(window.clearTimeout(i.current),i.current=null),m(!0),o(Math.max(0,Math.min(100,Math.round(p))));return}o(100),i.current=window.setTimeout(()=>{m(!1),o(0),i.current=null},200)},[]);t.useEffect(()=>()=>{i.current!==null&&window.clearTimeout(i.current)},[]);const $={position:s.position||[0,2,5],fov:s.fov||45},M={enabled:e.enabled??!0,enablePan:e.enablePan??!0,enableZoom:e.enableZoom??!0,enableRotate:e.enableRotate??!0,minDistance:e.minDistance,maxDistance:e.maxDistance,minPolarAngle:e.minPolarAngle,maxPolarAngle:e.maxPolarAngle,autoRotate:e.autoRotate??!1,autoRotateSpeed:e.autoRotateSpeed??2},b=typeof S=="object"?{position:S.position||[0,-1,0],opacity:S.opacity??.5,blur:S.blur??2}:S?{position:[0,-1,0],opacity:.5,blur:2}:null;return h.jsxs("div",{style:{...a||{},position:(a==null?void 0:a.position)??"relative"},className:n,children:[h.jsxs(B.Canvas,{shadows:u,camera:{position:$.position,fov:$.fov},style:{width:"100%",height:"100%"},children:[h.jsx(t.Suspense,{fallback:null,children:h.jsx(ue,{background:l})}),y&&h.jsx(t.Suspense,{fallback:null,children:h.jsx(me,{config:y})}),d.map((v,p)=>h.jsx(pe,{config:v},`${v.type}-${p}`)),h.jsx(t.Suspense,{fallback:null,children:r}),h.jsx(ce,{position:$.position,controlsConfig:M}),b&&h.jsx(O.ContactShadows,{position:b.position,opacity:b.opacity,blur:b.blur}),h.jsx(de,{onChange:c})]}),g&&f&&h.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:h.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:[h.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:10},children:h.jsxs("svg",{width:"34",height:"34",viewBox:"0 0 34 34","aria-hidden":"true",children:[h.jsx("circle",{cx:"17",cy:"17",r:"14",fill:"none",stroke:"rgba(255,255,255,0.2)",strokeWidth:"4"}),h.jsx("path",{d:"M31 17a14 14 0 0 1-14 14",fill:"none",stroke:"#67b4ff",strokeWidth:"4",strokeLinecap:"round",children:h.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 17 17",to:"360 17 17",dur:"0.9s",repeatCount:"indefinite"})})]})}),h.jsxs("div",{style:{fontSize:12,opacity:.82,marginTop:4},children:[x,"%"]})]})})]})}function K(r,s){const e=t.useRef(new Map),l=t.useRef({}),u=t.useRef({});t.useEffect(()=>{s&&(l.current={...s})},[s]),t.useEffect(()=>{if(!r)return;const g=new Map;r.traverse(a=>{if(a.isMesh){const n=a;n.name&&g.set(n.name,n)}}),e.current=g},[r]),B.useFrame(()=>{const g=e.current;if(g.size===0)return;const a={...l.current,...u.current};for(const[n,f]of Object.entries(a)){const m=g.get(n);m&&m.visible!==f&&(m.visible=f)}});const d=t.useCallback((g,a)=>{u.current[g]=a;const n=e.current.get(g);n&&(n.visible=a)},[]),y=t.useCallback(()=>Array.from(e.current.keys()).sort(),[]),S=t.useCallback(()=>{const g={};return e.current.forEach((a,n)=>{g[n]=a.visible}),g},[]);return{setMeshVisibility:d,getMeshNames:y,getMeshVisibility:S}}function G(r,s){const e=t.useRef(new Map),l=t.useRef(new Map);t.useEffect(()=>{if(!r)return;const a=new Map;r.traverse(n=>{if(n.isMesh){const f=n;(Array.isArray(f.material)?f.material:[f.material]).forEach(x=>{x.name&&!a.has(x.name)&&a.set(x.name,x)})}}),e.current=a,s&&Object.entries(s).forEach(([n,f])=>{const m=a.get(n);if(m&&!Array.isArray(m)){const x=u(f);m.color&&m.color.copy(x),l.current.set(n,x)}})},[r,s]),B.useFrame(()=>{l.current.forEach((a,n)=>{const f=e.current.get(n);if(f&&!Array.isArray(f)){const m=f;m.color&&!m.color.equals(a)&&(m.color.copy(a),m.needsUpdate=!0)}})});const u=a=>typeof a=="string"?new R.Color(a):new R.Color(a[0],a[1],a[2]),d=t.useCallback((a,n)=>{const f=u(n);l.current.set(a,f);const m=e.current.get(a);if(m&&!Array.isArray(m)){const x=m;x.color&&(x.color.copy(f),x.needsUpdate=!0)}},[]),y=t.useCallback(()=>Array.from(e.current.keys()).sort(),[]),S=t.useCallback(a=>{const n=e.current.get(a);if(n&&!Array.isArray(n)){const f=n;if(f.color)return"#"+f.color.getHexString()}return null},[]),g=t.useCallback(()=>{const a={};return e.current.forEach((n,f)=>{if(!Array.isArray(n)){const m=n;m.color&&(a[f]="#"+m.color.getHexString())}}),a},[]);return{setMaterialColor:d,getMaterialNames:y,getMaterialColor:S,getAllMaterialColors:g}}function H(r){const s=r.toLowerCase();if(s.endsWith(".ktx2"))return!0;try{const e=new URL(r,window.location.origin),l=decodeURIComponent(e.hash.replace(/^#/,"")).toLowerCase(),u=decodeURIComponent(e.search).toLowerCase(),d=decodeURIComponent(e.pathname).toLowerCase();return l.endsWith(".ktx2")||u.includes(".ktx2")||d.endsWith(".ktx2")}catch{return s.includes(".ktx2")}}function z(r,s){const{gl:e}=B.useThree(),l=t.useRef(new Map),u=t.useRef(new R.TextureLoader),d=t.useRef(null),y=t.useRef(new Map),S=t.useRef(new Set),g=t.useRef("");t.useEffect(()=>{if(!d.current)try{const o=typeof WebAssembly=="object"&&typeof WebAssembly.validate=="function";console.log("[useMaterialTexture] Browser features:"),console.log(` WebAssembly supported: ${o}`),console.log(` WebGL2: ${e.capabilities.isWebGL2}`);const i=new ie.KTX2Loader;i.setTranscoderPath("/basis/"),i.detectSupport(e),d.current=i,console.log("[useMaterialTexture] ✅ KTX2Loader initialized"),console.log("[useMaterialTexture] Transcoder path: /basis/"),fetch("/basis/basis_transcoder.wasm").then(c=>{c.ok?console.log("[useMaterialTexture] ✅ basis_transcoder.wasm is accessible"):console.error("[useMaterialTexture] ❌ basis_transcoder.wasm returned",c.status)}).catch(c=>{console.error("[useMaterialTexture] ❌ Failed to check basis_transcoder.wasm:",c)}),o||(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(o){console.error("[useMaterialTexture] ❌ Failed to initialize KTX2Loader:",o)}return()=>{d.current&&(d.current.dispose(),d.current=null)}},[e]),t.useEffect(()=>{if(!r)return;const o=new Map;r.traverse(i=>{if(i.isMesh){const c=i;(Array.isArray(c.material)?c.material:[c.material]).forEach(M=>{M.name&&!o.has(M.name)&&o.set(M.name,M)})}}),l.current=o},[r]);const a=t.useCallback(o=>H(o)?d.current?d.current:(console.warn("[useMaterialTexture] KTX2Loader not initialized, falling back to TextureLoader"),u.current):u.current,[]);t.useEffect(()=>{if(!s||!r)return;const o=l.current;if(o.size===0)return;const i=JSON.stringify(s);if(g.current===i){console.log("[useMaterialTexture] Textures unchanged, skipping reload");return}g.current=i;let c=!1;const $=new Map;Object.entries(s).forEach(([p,A])=>{$.set(p,typeof A=="string"?{map:A}:A)}),console.log("[useMaterialTexture] Starting texture load for",$.size,"materials");const M=[];$.forEach((p,A)=>{var E,L;const P=o.get(A);if(!P||!P.isMeshStandardMaterial){console.warn(`[useMaterialTexture] Material "${A}" not found or not MeshStandardMaterial`);return}const T=P;console.log(`[useMaterialTexture] 📋 Material "${A}" BEFORE reset:`),console.log(` - map: ${T.map?"EXISTS":"null"} ${T.map?`(uuid: ${T.map.uuid})`:""}`),console.log(` - normalMap: ${T.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${T.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${T.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${T.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${T.aoMap?"EXISTS":"null"}`),console.log(` - color: ${(E=T.color)==null?void 0:E.getHexString()}`),console.log(` - emissive: ${(L=T.emissive)==null?void 0:L.getHexString()}`),console.log(` - material uuid: ${T.uuid}`),Object.entries(p).forEach(([w,j])=>{if(!j)return;const C=w,k=T[C];k&&(console.log(`[useMaterialTexture] 🗑️ Disposing old ${C} (uuid: ${k.uuid})`),k.dispose(),T[C]=null)}),p.emissiveMap&&(T.emissive=new R.Color(0),T.emissiveIntensity=0),T.needsUpdate=!0,T.color=new R.Color(16777215),console.log(`[useMaterialTexture] ✅ Material "${A}" AFTER reset: only specified maps cleared`),Object.entries(p).forEach(([w,j])=>{if(!j)return;const C=`${A}_${w}_${j}`,k=y.current.get(C);if(k){console.log(`[useMaterialTexture] Using cached texture: ${A}.${w}`),c||n(T,w,k);return}if(S.current.has(C)){console.log(`[useMaterialTexture] Skipping already loading: ${A}.${w}`);return}M.push({materialName:A,textureType:w,url:j,material:T})})}),console.log(`[useMaterialTexture] Queued ${M.length} textures to load`);let b=0;const v=()=>{if(c||b>=M.length){console.log("[useMaterialTexture] ✅ All textures loaded"),console.log("[useMaterialTexture] 📊 FINAL material states:"),o.forEach((E,L)=>{var j,C;const w=E;console.log(` Material "${L}":`),console.log(` - map: ${w.map?"EXISTS":"null"} ${w.map?`(colorSpace: ${w.map.colorSpace})`:""}`),console.log(` - normalMap: ${w.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${w.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${w.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${w.emissiveMap?"EXISTS":"null"}`),console.log(` - color: ${(j=w.color)==null?void 0:j.getHexString()}`),console.log(` - emissive: ${(C=w.emissive)==null?void 0:C.getHexString()}`),console.log(` - emissiveIntensity: ${w.emissiveIntensity}`),console.log(` - roughness: ${w.roughness}`),console.log(` - metalness: ${w.metalness}`)});return}const p=M[b++],A=`${p.materialName}_${p.textureType}_${p.url}`;console.log(`[useMaterialTexture] Loading (${b}/${M.length}): ${p.materialName}.${p.textureType} from ${p.url}`),S.current.add(A);const P=a(p.url),T=H(p.url)?"KTX2Loader":"TextureLoader";console.log(`[useMaterialTexture] Using ${T} for ${p.url}`),P.load(p.url,E=>{var C,k,X,D,I,W;if(S.current.delete(A),c){console.log(`[useMaterialTexture] Disposed, cleaning up texture: ${p.materialName}.${p.textureType}`),E.dispose();return}const L=((C=E.image)==null?void 0:C.width)||((X=(k=E.source)==null?void 0:k.data)==null?void 0:X.width)||"unknown",w=((D=E.image)==null?void 0:D.height)||((W=(I=E.source)==null?void 0:I.data)==null?void 0:W.height)||"unknown";console.log(`[useMaterialTexture] ✅ Loaded: ${p.materialName}.${p.textureType} (${L}x${w})`),E.colorSpace=p.textureType==="map"||p.textureType==="emissiveMap"?R.SRGBColorSpace:R.NoColorSpace,E.wrapS=R.RepeatWrapping,E.wrapT=R.RepeatWrapping,E.flipY=!1,y.current.set(A,E),n(p.material,p.textureType,E);const j=H(p.url)?500:150;console.log(`[useMaterialTexture] Waiting111111 ${j}ms before next texture...`),setTimeout(v,0)},E=>{if(E.lengthComputable){const L=Math.round(E.loaded/E.total*100);L%25===0&&console.log(`[useMaterialTexture] Progress ${p.materialName}.${p.textureType}: ${L}%`)}},E=>{S.current.delete(A),c||(console.error(`[useMaterialTexture] ❌ Failed to load ${p.materialName}.${p.textureType} from ${p.url}`),console.error("[useMaterialTexture] Error details:",E),console.error("[useMaterialTexture] Loader type:",T),H(p.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(v,100)})};return v(),()=>{console.log("[useMaterialTexture] Cleanup: disposed"),c=!0}},[r,s,a]);const n=(o,i,c)=>{var $,M;switch(console.log(`[useMaterialTexture] 🎨 Applying texture: ${o.name}.${i} (texture uuid: ${c.uuid})`),i){case"map":o.map=c;break;case"normalMap":o.normalMap=c;break;case"roughnessMap":o.roughnessMap=c;break;case"metalnessMap":o.metalnessMap=c;break;case"emissiveMap":o.emissiveMap=c,o.emissive=new R.Color(16777215),o.emissiveIntensity=1;break;case"alphaMap":console.log(`[useMaterialTexture] Skipping alphaMap for "${o.name}" to prevent disappearing`);break;case"aoMap":o.aoMap=c;break}o.needsUpdate=!0,console.log(`[useMaterialTexture] ✅ Applied ${i} to ${o.name}, needsUpdate=true`),console.log(`[useMaterialTexture] 📊 Material "${o.name}" FINAL state:`),console.log(` - map: ${o.map?"EXISTS":"null"} ${o.map?`(uuid: ${o.map.uuid}, colorSpace: ${o.map.colorSpace})`:""}`),console.log(` - normalMap: ${o.normalMap?"EXISTS":"null"}`),console.log(` - roughnessMap: ${o.roughnessMap?"EXISTS":"null"}`),console.log(` - metalnessMap: ${o.metalnessMap?"EXISTS":"null"}`),console.log(` - emissiveMap: ${o.emissiveMap?"EXISTS":"null"}`),console.log(` - aoMap: ${o.aoMap?"EXISTS":"null"}`),console.log(` - color: ${($=o.color)==null?void 0:$.getHexString()}`),console.log(` - emissive: ${(M=o.emissive)==null?void 0:M.getHexString()}`),console.log(` - emissiveIntensity: ${o.emissiveIntensity}`),console.log(` - roughness: ${o.roughness}`),console.log(` - metalness: ${o.metalness}`)},f=t.useCallback((o,i)=>{const c=typeof i=="string"?{map:i}:i,$=l.current.get(o);if(!$||!$.isMeshStandardMaterial){console.warn(`Material "${o}" not found or not MeshStandardMaterial`);return}const M=$;Object.entries(c).forEach(([b,v])=>{if(!v)return;const p=`${o}_${b}_${v}`,A=y.current.get(p);if(A){n(M,b,A);return}a(v).load(v,T=>{T.colorSpace=b==="map"||b==="emissiveMap"?R.SRGBColorSpace:R.NoColorSpace,T.wrapS=R.RepeatWrapping,T.wrapT=R.RepeatWrapping,y.current.set(p,T),n(M,b,T)},void 0,T=>{console.error(`Failed to load texture ${v}:`,T)})})},[a]),m=t.useCallback(()=>Array.from(l.current.keys()).sort(),[]),x=t.useCallback(o=>{const i=l.current.get(o);if(!i||!i.isMeshStandardMaterial)return;const c=i;c.map=null,c.normalMap=null,c.roughnessMap=null,c.metalnessMap=null,c.emissiveMap=null,c.alphaMap=null,c.aoMap=null,c.needsUpdate=!0},[]);return{setMaterialTextures:f,getMaterialNames:m,clearMaterialTextures:x}}function re({url:r,position:s=[0,0,0],rotation:e=[0,0,0],scale:l=1,meshVisibility:u,materialColors:d,materialTextures:y,onLoad:S,onError:g}){const{scene:a}=O.useGLTF(r),n=t.useRef(S);n.current=S;const f=t.useMemo(()=>{const x=a.clone();console.log("[Model] 🔍 Scene clone created, checking materials...");const o=[],i=new Set,c=[];let $=0;return x.traverse(M=>{if($++,M.type==="Bone"&&c.push(M.name),M.isMesh){const b=M;o.push(b.name),b.castShadow=!0,b.receiveShadow=!0,(Array.isArray(b.material)?b.material:[b.material]).forEach(p=>{i.add(p.name),console.log(`[Model] 📦 Material found: "${p.name}" (uuid: ${p.uuid})`);const A=p;console.log(` - Has map: ${A.map?"YES":"NO"}`),console.log(` - Has normalMap: ${A.normalMap?"YES":"NO"}`),console.log(` - Has roughnessMap: ${A.roughnessMap?"YES":"NO"}`),console.log(` - Has metalnessMap: ${A.metalnessMap?"YES":"NO"}`)})}}),console.log(`[Model] 📊 Clone summary: ${o.length} meshes, ${i.size} materials`),setTimeout(()=>{var M;(M=n.current)==null||M.call(n,{meshes:o.sort(),materials:Array.from(i).sort(),bones:c.sort(),nodeCount:$})},0),x},[a]);K(f,u),G(f,d),z(f,y);const m=typeof l=="number"?[l,l,l]:l;return h.jsx("group",{position:s,rotation:e,scale:m,children:h.jsx("primitive",{object:f})})}re.preload=r=>{O.useGLTF.preload(r)};function se(r,s,e){const{actions:l,names:u}=O.useAnimations(r,s),d=t.useRef(null),y=t.useRef(e==null?void 0:e.defaultAnimation);t.useEffect(()=>{y.current=e==null?void 0:e.defaultAnimation},[e==null?void 0:e.defaultAnimation]),t.useEffect(()=>{if(u.length===0)return;const n=y.current;let f=u[0];if(n){const x=u.find(o=>o===n||o.includes(n));x&&(f=x)}const m=l[f];m&&(m.reset().fadeIn(.5).play(),d.current=m)},[l,u]);const S=t.useCallback((n,f)=>{const{loop:m=!1,crossFadeDuration:x=.2,restoreDefault:o=!0}=f||{};let i=l[n];if(!i){const $=Object.keys(l).find(M=>M.toLowerCase().includes(n.toLowerCase())||n.toLowerCase().includes(M.toLowerCase()));$&&(i=l[$])}if(!i){console.warn(`Animation "${n}" not found. Available: ${u.join(", ")}`);return}const c=d.current;if(!(c===i&&i.isRunning())&&(c&&c!==i&&c.fadeOut(x),i.reset(),i.fadeIn(x),i.setLoop(m?R.LoopRepeat:R.LoopOnce,m?1/0:1),i.clampWhenFinished=!m,i.play(),m||i.getMixer().update(0),d.current=i,o&&!m&&y.current)){const $=i.getMixer(),M=b=>{if(b.action===i){$.removeEventListener("finished",M);const v=l[y.current];v&&(i.fadeOut(x),v.reset().fadeIn(x).play(),d.current=v)}};$.addEventListener("finished",M)}},[l,u]),g=t.useCallback(()=>{var n;(n=d.current)==null||n.fadeOut(.2),d.current=null},[]),a=t.useCallback(()=>u,[u]);return{playAnimation:S,stopAnimation:g,getAnimationNames:a,actions:l}}function q(r,s){const e=t.useRef(s||{}),l=t.useRef([]),u=t.useRef([]);t.useEffect(()=>{const g=new Set,a=[];r.traverse(n=>{n instanceof R.Mesh&&n.morphTargetDictionary&&n.morphTargetInfluences&&(a.push(n),Object.keys(n.morphTargetDictionary).forEach(f=>{g.add(f)}))}),l.current=Array.from(g).sort(),u.current=a},[r]),B.useFrame(()=>{const g=e.current;u.current.forEach(a=>{!a.morphTargetDictionary||!a.morphTargetInfluences||Object.entries(g).forEach(([n,f])=>{const m=a.morphTargetDictionary[n];m!==void 0&&(a.morphTargetInfluences[m]=f)})})}),t.useEffect(()=>{s&&(e.current={...s})},[s]);const d=t.useCallback((g,a)=>{e.current[g]=Math.max(0,Math.min(1,a))},[]),y=t.useCallback(()=>l.current,[]),S=t.useCallback(()=>({...e.current}),[]);return{setMorphTarget:d,getMorphTargetNames:y,getMorphTargetValues:S}}const oe=t.createContext(null);function he(){const r=t.useContext(oe);if(!r)throw new Error("BoneAttachment must be used within an AnimatedModel");return r}const V=t.forwardRef(({url:r,position:s=[0,0,0],rotation:e=[0,0,0],scale:l=1,defaultAnimation:u,animation:d,morphTargets:y,meshVisibility:S,materialColors:g,materialTextures:a,onLoad:n,onError:f,children:m},x)=>{const o=t.useRef(null),i=t.useRef([]),c=t.useRef(n);c.current=n;const{scene:$,animations:M}=O.useGLTF(r),b=t.useMemo(()=>te.clone($),[$]),{playAnimation:v,stopAnimation:p,getAnimationNames:A}=se(M,b,{defaultAnimation:u});t.useEffect(()=>{d&&v(d,{loop:!0,restoreDefault:!1})},[d,v]);const{setMorphTarget:P}=q(b,y),{setMeshVisibility:T,getMeshNames:E}=K(b,S),{setMaterialColor:L,getMaterialNames:w,getMaterialColor:j}=G(b,g),{setMaterialTextures:C,clearMaterialTextures:k}=z(b,a);t.useEffect(()=>{if(!b)return;const I=setTimeout(()=>{var Q;const W=[],_=[],Y=new Set,Z=new Set;let J=0;b.traverse(F=>{if(J++,F.type==="Bone"&&W.push(F.name),F.isMesh){const N=F;_.push(N.name),N.castShadow=!0,N.receiveShadow=!0,(Array.isArray(N.material)?N.material:[N.material]).forEach(U=>{Y.add(U.name),U.shadowSide=R.DoubleSide}),N.morphTargetDictionary&&Object.keys(N.morphTargetDictionary).forEach(U=>{Z.add(U)})}}),i.current=Array.from(Z).sort(),(Q=c.current)==null||Q.call(c,{meshes:_.sort(),materials:Array.from(Y).sort(),bones:W.sort(),nodeCount:J,animations:M.map(F=>F.name),morphTargetNames:i.current})},0);return()=>clearTimeout(I)},[b,M]),t.useImperativeHandle(x,()=>({playAnimation:v,stopAnimation:p,getAnimationNames:A,getGroup:()=>o.current,setMorphTarget:P,getMorphTargetNames:()=>i.current,setMeshVisibility:T,getMeshNames:E,setMaterialColor:L,getMaterialNames:w,getMaterialColor:j,setMaterialTextures:C,clearMaterialTextures:k}));const X=t.useMemo(()=>({scene:b,getBone:I=>b.getObjectByName(I)||null}),[b]),D=typeof l=="number"?[l,l,l]:l;return h.jsx(oe.Provider,{value:X,children:h.jsxs("group",{ref:o,position:s,rotation:e,scale:D,children:[h.jsx("primitive",{object:b}),m]})})});V.displayName="AnimatedModel";V.preload=r=>{O.useGLTF.preload(r)};const ne=t.forwardRef(({url:r,position:s=[0,0,0],rotation:e=[0,0,0],scale:l=1,morphTargets:u,meshVisibility:d,materialColors:y,materialTextures:S,onMorphTargetsFound:g,onLoad:a,onError:n},f)=>{const{scene:m}=O.useGLTF(r),x=t.useRef(a);x.current=a;const o=t.useRef(g);o.current=g;const i=t.useMemo(()=>m.clone(),[m]),{setMorphTarget:c,getMorphTargetNames:$,getMorphTargetValues:M}=q(i,u),{setMeshVisibility:b,getMeshNames:v}=K(i,d),{setMaterialColor:p,getMaterialNames:A,getMaterialColor:P}=G(i,y),{setMaterialTextures:T,clearMaterialTextures:E}=z(i,S);t.useEffect(()=>{var j;const w=$();w.length>0&&((j=o.current)==null||j.call(o,w))},[i,$]),t.useEffect(()=>{var X;if(!i)return;const w=[],j=new Set,C=[];let k=0;i.traverse(D=>{if(k++,D.type==="Bone"&&C.push(D.name),D.isMesh){const I=D;w.push(I.name),I.castShadow=!0,I.receiveShadow=!0,(Array.isArray(I.material)?I.material:[I.material]).forEach(_=>j.add(_.name))}}),(X=x.current)==null||X.call(x,{meshes:w.sort(),materials:Array.from(j).sort(),bones:C.sort(),nodeCount:k})},[i]),t.useImperativeHandle(f,()=>({setMorphTarget:c,getMorphTargetNames:$,getMorphTargetValues:M,setMeshVisibility:b,getMeshNames:v,setMaterialColor:p,getMaterialNames:A,getMaterialColor:P,setMaterialTextures:T,clearMaterialTextures:E}));const L=typeof l=="number"?[l,l,l]:l;return h.jsx("group",{position:s,rotation:e,scale:L,children:h.jsx("primitive",{object:i})})});ne.displayName="MorphableModel";function Me({children:r,bone:s,position:e=[0,0,0],rotation:l=[0,0,0],scale:u=1}){const{getBone:d}=he(),[y,S]=t.useState(null);if(t.useEffect(()=>{const a=d(s);a?S(a):console.warn(`Bone "${s}" not found in model`)},[s,d]),!y)return null;const g=typeof u=="number"?[u,u,u]:u;return B.createPortal(h.jsx("group",{position:e,rotation:l,scale:g,children:r}),y)}function be(r,s){const{scene:e,animations:l}=O.useGLTF(r),u=t.useMemo(()=>te.clone(e),[e]);return t.useEffect(()=>{var a;if(!u)return;const d=[],y=[],S=new Set;let g=0;u.traverse(n=>{if(g++,n.type==="Bone"&&d.push(n.name),n.isMesh){const f=n;y.push(f.name),f.castShadow=!0,f.receiveShadow=!0,(Array.isArray(f.material)?f.material:[f.material]).forEach(x=>{S.add(x.name),x.shadowSide=R.DoubleSide})}}),(a=s==null?void 0:s.onLoad)==null||a.call(s,{meshes:y.sort(),materials:Array.from(S).sort(),bones:d.sort(),nodeCount:g})},[u,s]),{scene:u,animations:l}}function ye(r){O.useGLTF.preload(r)}exports.AnimatedModel=V;exports.BoneAttachment=Me;exports.Model=re;exports.MorphableModel=ne;exports.Scene3D=ge;exports.preloadModel=ye;exports.useAnimationController=se;exports.useClonedModel=be;exports.useMaterialColor=G;exports.useMaterialTexture=z;exports.useMeshVisibility=K;exports.useMorphTargets=q;
2
2
  //# sourceMappingURL=mbt-3d.cjs.map