mbt-3d 0.1.3 → 0.2.0

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
@@ -30,6 +30,8 @@ import * as THREE from 'three';
30
30
  * @param scale - Uniform scale (number) or per-axis scale [x, y, z]. Examples: `0.5` or `[1, 2, 1]`. Default: `1`
31
31
  * @param defaultAnimation - Name of animation to play on load. If not specified, plays first animation. Example: `"Idle"`
32
32
  * @param morphTargets - Morph target values as key-value pairs where value is 0-1. Example: `{ muscular: 0.5, thin: 0.2 }`
33
+ * @param meshVisibility - Mesh visibility as key-value pairs. Example: `{ "Hairgirl1": true, "Hairgirl2": false }`
34
+ * @param materialColors - Material colors as key-value pairs. Example: `{ "Hair_girl_1": "#ff0000" }`
33
35
  * @param children - Child components, typically BoneAttachment components for attaching items
34
36
  * @param onLoad - Callback when model loads. Receives AnimatedModelInfo object: `{ meshes, materials, bones, nodeCount, animations, morphTargetNames }`
35
37
  * @param onError - Callback when model fails to load. Receives Error object
@@ -43,6 +45,8 @@ import * as THREE from 'three';
43
45
  * url="/models/character.glb"
44
46
  * defaultAnimation="Idle"
45
47
  * morphTargets={{ muscular: 0.5 }}
48
+ * meshVisibility={{ "Hairgirl1": true, "Hairgirl2": false }}
49
+ * materialColors={{ "Hair_girl_1": "#ff0000" }}
46
50
  * position={[0, -1, 0]}
47
51
  * >
48
52
  * <BoneAttachment bone="hand_r">
@@ -93,6 +97,28 @@ export declare interface AnimatedModelHandle {
93
97
  setMorphTarget: (name: string, value: number) => void;
94
98
  /** Get array of all available morph target names */
95
99
  getMorphTargetNames: () => string[];
100
+ /**
101
+ * Set mesh visibility
102
+ * @param name - Mesh name
103
+ * @param visible - True to show, false to hide
104
+ */
105
+ setMeshVisibility: (name: string, visible: boolean) => void;
106
+ /** Get array of all mesh names */
107
+ getMeshNames: () => string[];
108
+ /**
109
+ * Set material color
110
+ * @param name - Material name
111
+ * @param color - Hex color string (e.g., "#ff0000") or RGB array [r, g, b] where values are 0-1
112
+ */
113
+ setMaterialColor: (name: string, color: string | [number, number, number]) => void;
114
+ /** Get array of all material names */
115
+ getMaterialNames: () => string[];
116
+ /**
117
+ * Get current color of a material
118
+ * @param name - Material name
119
+ * @returns Hex color string or null
120
+ */
121
+ getMaterialColor: (name: string) => string | null;
96
122
  }
97
123
 
98
124
  /**
@@ -132,6 +158,10 @@ export declare interface AnimatedModelProps extends Omit<ModelProps, 'onLoad'> {
132
158
  defaultAnimation?: string;
133
159
  /** Morph target values as key-value pairs { targetName: value } where value is 0-1 */
134
160
  morphTargets?: Record<string, number>;
161
+ /** Mesh visibility as key-value pairs { meshName: visible }. Example: { "Hairgirl1": true, "Hairgirl2": false } */
162
+ meshVisibility?: Record<string, boolean>;
163
+ /** Material colors as key-value pairs { materialName: color }. Example: { "Hair_girl_1": "#ff0000" } */
164
+ materialColors?: Record<string, string | [number, number, number]>;
135
165
  /** Callback when model loads with extended metadata including animations */
136
166
  onLoad?: (info: AnimatedModelInfo) => void;
137
167
  }
@@ -205,6 +235,8 @@ export declare interface BoneAttachmentProps {
205
235
  * @param position - Model position in 3D space as [x, y, z]. Example: `[0, 0, 0]`. Default: `[0, 0, 0]`
206
236
  * @param rotation - Model rotation in radians as [x, y, z]. Example: `[0, Math.PI/2, 0]`. Default: `[0, 0, 0]`
207
237
  * @param scale - Uniform scale (number) or per-axis scale [x, y, z]. Examples: `0.5` or `[1, 2, 1]`. Default: `1`
238
+ * @param meshVisibility - Mesh visibility as key-value pairs. Example: `{ "Part1": true, "Part2": false }`
239
+ * @param materialColors - Material colors as key-value pairs. Example: `{ "MaterialName": "#ff0000" }`
208
240
  * @param onLoad - Callback when model finishes loading. Receives ModelInfo object with metadata: `{ meshes, materials, bones, nodeCount }`
209
241
  * @param onError - Callback when model fails to load. Receives Error object
210
242
  *
@@ -215,11 +247,12 @@ export declare interface BoneAttachmentProps {
215
247
  * position={[0, 0, 0]}
216
248
  * rotation={[0, Math.PI/2, 0]}
217
249
  * scale={0.5}
250
+ * meshVisibility={{ "Blade": true, "Handle": false }}
218
251
  * onLoad={(info) => console.log('Loaded:', info)}
219
252
  * />
220
253
  * ```
221
254
  */
222
- export declare function Model({ url, position, rotation, scale, onLoad, onError: _onError, }: ModelProps): JSX_2.Element;
255
+ export declare function Model({ url, position, rotation, scale, meshVisibility, materialColors, onLoad, onError: _onError, }: ModelProps): JSX_2.Element;
223
256
 
224
257
  export declare namespace Model {
225
258
  var preload: (url: string) => void;
@@ -261,6 +294,10 @@ export declare interface ModelProps {
261
294
  rotation?: [number, number, number];
262
295
  /** Uniform scale (number) or per-axis scale [x, y, z]. Default: 1 */
263
296
  scale?: number | [number, number, number];
297
+ /** Mesh visibility as key-value pairs { meshName: visible }. Example: { "Hairgirl1": true, "Hairgirl2": false } */
298
+ meshVisibility?: Record<string, boolean>;
299
+ /** Material colors as key-value pairs { materialName: color }. Example: { "Hair_girl_1": "#ff0000" } */
300
+ materialColors?: Record<string, string | [number, number, number]>;
264
301
  /** Callback when model finishes loading with metadata */
265
302
  onLoad?: (info: ModelInfo) => void;
266
303
  /** Callback when model fails to load */
@@ -288,6 +325,8 @@ export declare interface ModelProps {
288
325
  * @param rotation - Model rotation in radians as [x, y, z]. Example: `[0, Math.PI, 0]`. Default: `[0, 0, 0]`
289
326
  * @param scale - Uniform scale (number) or per-axis scale [x, y, z]. Examples: `0.5` or `[1, 2, 1]`. Default: `1`
290
327
  * @param morphTargets - Morph target values as key-value pairs where value is 0-1. Example: `{ muscular: 0.5, thin: 0.2 }`
328
+ * @param meshVisibility - Mesh visibility as key-value pairs. Example: `{ "Hairgirl1": true, "Hairgirl2": false }`
329
+ * @param materialColors - Material colors as key-value pairs. Example: `{ "Hair_girl_1": "#ff0000" }`
291
330
  * @param onMorphTargetsFound - Callback when morph targets are discovered from the model. Receives array of morph target names: `["muscular", "thin", "fat"]`
292
331
  * @param onLoad - Callback when model finishes loading. Receives ModelInfo object with metadata: `{ meshes, materials, bones, nodeCount }`
293
332
  * @param onError - Callback when model fails to load. Receives Error object
@@ -301,6 +340,7 @@ export declare interface ModelProps {
301
340
  * ref={modelRef}
302
341
  * url="/models/character.glb"
303
342
  * morphTargets={morphs}
343
+ * meshVisibility={{ "Hairgirl1": true, "Hairgirl2": false }}
304
344
  * onMorphTargetsFound={(names) => console.log('Available:', names)}
305
345
  * position={[0, -1, 0]}
306
346
  * />
@@ -331,6 +371,28 @@ export declare interface MorphableModelHandle {
331
371
  getMorphTargetNames: () => string[];
332
372
  /** Get current values of all morph targets */
333
373
  getMorphTargetValues: () => Record<string, number>;
374
+ /**
375
+ * Set mesh visibility
376
+ * @param name - Mesh name
377
+ * @param visible - True to show, false to hide
378
+ */
379
+ setMeshVisibility: (name: string, visible: boolean) => void;
380
+ /** Get array of all mesh names */
381
+ getMeshNames: () => string[];
382
+ /**
383
+ * Set material color
384
+ * @param name - Material name
385
+ * @param color - Hex color string (e.g., "#ff0000") or RGB array [r, g, b] where values are 0-1
386
+ */
387
+ setMaterialColor: (name: string, color: string | [number, number, number]) => void;
388
+ /** Get array of all material names */
389
+ getMaterialNames: () => string[];
390
+ /**
391
+ * Get current color of a material
392
+ * @param name - Material name
393
+ * @returns Hex color string or null
394
+ */
395
+ getMaterialColor: (name: string) => string | null;
334
396
  }
335
397
 
336
398
  /**
@@ -348,6 +410,10 @@ export declare interface MorphableModelHandle {
348
410
  export declare interface MorphableModelProps extends ModelProps {
349
411
  /** Morph target values as key-value pairs { targetName: value } where value is 0-1 */
350
412
  morphTargets?: Record<string, number>;
413
+ /** Mesh visibility as key-value pairs { meshName: visible }. Example: { "Hairgirl1": true, "Hairgirl2": false } */
414
+ meshVisibility?: Record<string, boolean>;
415
+ /** Material colors as key-value pairs { materialName: color }. Example: { "Hair_girl_1": "#ff0000" } */
416
+ materialColors?: Record<string, string | [number, number, number]>;
351
417
  /** Callback when morph targets are discovered from the model */
352
418
  onMorphTargetsFound?: (names: string[]) => void;
353
419
  }
@@ -513,6 +579,33 @@ declare interface UseClonedModelOptions {
513
579
  onError?: (error: Error) => void;
514
580
  }
515
581
 
582
+ /**
583
+ * Hook for managing material colors in a 3D scene
584
+ *
585
+ * @param scene - The THREE.Object3D scene containing meshes with materials
586
+ * @param initialColors - Initial color values for materials { materialName: "#hexcolor" or [r, g, b] }
587
+ * @returns Methods to control material colors
588
+ */
589
+ export declare function useMaterialColor(scene: THREE.Object3D, initialColors?: Record<string, string | [number, number, number]>): {
590
+ setMaterialColor: (materialName: string, color: string | [number, number, number]) => void;
591
+ getMaterialNames: () => string[];
592
+ getMaterialColor: (materialName: string) => string | null;
593
+ getAllMaterialColors: () => Record<string, string>;
594
+ };
595
+
596
+ /**
597
+ * Hook for managing mesh visibility in a 3D scene
598
+ *
599
+ * @param scene - The THREE.Object3D scene containing meshes
600
+ * @param initialVisibility - Initial visibility state for meshes
601
+ * @returns Methods to control mesh visibility
602
+ */
603
+ export declare function useMeshVisibility(scene: THREE.Object3D, initialVisibility?: Record<string, boolean>): {
604
+ setMeshVisibility: (name: string, visible: boolean) => void;
605
+ getMeshNames: () => string[];
606
+ getMeshVisibility: () => Record<string, boolean>;
607
+ };
608
+
516
609
  export declare function useMorphTargets(scene: THREE.Object3D, initialValues?: Record<string, number>): {
517
610
  setMorphTarget: (name: string, value: number) => void;
518
611
  getMorphTargetNames: () => string[];
package/dist/mbt-3d.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),x=require("@react-three/drei"),Z=require("three"),W=require("three/examples/jsm/utils/SkeletonUtils.js"),D=require("@react-three/fiber"),b=require("react/jsx-runtime");function G(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const n=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(e,a,n.get?n:{enumerable:!0,get:()=>t[a]})}}return e.default=t,Object.freeze(e)}const T=G(Z),_=G(W);function $({position:t,controlsConfig:e}){const{camera:a}=D.useThree(),n=o.useRef(null);return o.useEffect(()=>{t&&a&&(a.position.set(t[0],t[1],t[2]),a.updateProjectionMatrix(),n.current&&(n.current.target.set(0,0,0),n.current.update()))},[t,a]),b.jsx(x.OrbitControls,{ref:n,makeDefault:!0,enabled:e.enabled,enablePan:e.enablePan,enableZoom:e.enableZoom,enableRotate:e.enableRotate,minDistance:e.minDistance,maxDistance:e.maxDistance,minPolarAngle:e.minPolarAngle,maxPolarAngle:e.maxPolarAngle,autoRotate:e.autoRotate,autoRotateSpeed:e.autoRotateSpeed})}function U({background:t}){const e=t==null?void 0:t.startsWith("#");return t?e?b.jsx("color",{attach:"background",args:[t]}):b.jsx(z,{url:t}):null}function z({url:t}){const e=x.useTexture(t);return o.useMemo(()=>{e.colorSpace=T.SRGBColorSpace},[e]),b.jsx("primitive",{attach:"background",object:e})}function V({children:t,camera:e={},controls:a={},background:n,shadows:s=!0,ambientIntensity:f=.5,spotLight:u={},contactShadows:y=!0,style:d,className:c}){const r={position:e.position||[0,2,5],fov:e.fov||45},m={enabled:a.enabled??!0,enablePan:a.enablePan??!0,enableZoom:a.enableZoom??!0,enableRotate:a.enableRotate??!0,minDistance:a.minDistance,maxDistance:a.maxDistance,minPolarAngle:a.minPolarAngle,maxPolarAngle:a.maxPolarAngle,autoRotate:a.autoRotate??!1,autoRotateSpeed:a.autoRotateSpeed??2},l={position:u.position||[5,10,5],intensity:u.intensity??50,castShadow:u.castShadow??!0},p=typeof y=="object"?{position:y.position||[0,-1,0],opacity:y.opacity??.5,blur:y.blur??2}:y?{position:[0,-1,0],opacity:.5,blur:2}:null;return b.jsx("div",{style:d,className:c,children:b.jsxs(D.Canvas,{shadows:s,camera:{position:r.position,fov:r.fov},style:{width:"100%",height:"100%"},children:[b.jsx(o.Suspense,{fallback:null,children:b.jsx(U,{background:n})}),b.jsx("ambientLight",{intensity:f}),b.jsx("spotLight",{position:l.position,intensity:l.intensity,castShadow:l.castShadow}),b.jsx(o.Suspense,{fallback:null,children:t}),b.jsx($,{position:r.position,controlsConfig:m}),p&&b.jsx(x.ContactShadows,{position:p.position,opacity:p.opacity,blur:p.blur})]})})}function q({url:t,position:e=[0,0,0],rotation:a=[0,0,0],scale:n=1,onLoad:s,onError:f}){const{scene:u}=x.useGLTF(t),y=o.useMemo(()=>{const c=u.clone(),r=[],m=new Set,l=[];let p=0;return c.traverse(h=>{if(p++,h.type==="Bone"&&l.push(h.name),h.isMesh){const i=h;r.push(i.name),i.castShadow=!0,i.receiveShadow=!0,(Array.isArray(i.material)?i.material:[i.material]).forEach(A=>m.add(A.name))}}),s&&setTimeout(()=>{s({meshes:r.sort(),materials:Array.from(m).sort(),bones:l.sort(),nodeCount:p})},0),c},[u,s]),d=typeof n=="number"?[n,n,n]:n;return b.jsx("group",{position:e,rotation:a,scale:d,children:b.jsx("primitive",{object:y})})}q.preload=t=>{x.useGLTF.preload(t)};function F(t,e,a){const{actions:n,names:s}=x.useAnimations(t,e),f=o.useRef(null),u=o.useRef(a==null?void 0:a.defaultAnimation);o.useEffect(()=>{if(s.length===0)return;const r=u.current;let m=s[0];if(r){const p=s.find(h=>h===r||h.includes(r));p&&(m=p)}const l=n[m];l&&(l.reset().fadeIn(.5).play(),f.current=l)},[n,s]);const y=o.useCallback((r,m)=>{const{loop:l=!1,crossFadeDuration:p=.2,restoreDefault:h=!0}=m||{};let i=n[r];if(!i){const A=Object.keys(n).find(S=>S.toLowerCase().includes(r.toLowerCase())||r.toLowerCase().includes(S.toLowerCase()));A&&(i=n[A])}if(!i){console.warn(`Animation "${r}" not found. Available: ${s.join(", ")}`);return}const M=f.current;if(!(M===i&&i.isRunning())&&(M&&M!==i&&M.fadeOut(p),i.reset(),i.fadeIn(p),i.setLoop(l?T.LoopRepeat:T.LoopOnce,l?1/0:1),i.clampWhenFinished=!l,i.play(),l||i.getMixer().update(0),f.current=i,h&&!l&&u.current)){const A=i.getMixer(),S=j=>{if(j.action===i){A.removeEventListener("finished",S);const g=n[u.current];g&&(i.fadeOut(p),g.reset().fadeIn(p).play(),f.current=g)}};A.addEventListener("finished",S)}},[n,s]),d=o.useCallback(()=>{var r;(r=f.current)==null||r.fadeOut(.2),f.current=null},[]),c=o.useCallback(()=>s,[s]);return{playAnimation:y,stopAnimation:d,getAnimationNames:c,actions:n}}function P(t,e){const a=o.useRef(e||{}),n=o.useRef([]),s=o.useRef([]);o.useEffect(()=>{const d=new Set,c=[];t.traverse(r=>{r instanceof T.Mesh&&r.morphTargetDictionary&&r.morphTargetInfluences&&(c.push(r),Object.keys(r.morphTargetDictionary).forEach(m=>{d.add(m)}))}),n.current=Array.from(d).sort(),s.current=c},[t]),D.useFrame(()=>{const d=a.current;s.current.forEach(c=>{!c.morphTargetDictionary||!c.morphTargetInfluences||Object.entries(d).forEach(([r,m])=>{const l=c.morphTargetDictionary[r];l!==void 0&&(c.morphTargetInfluences[l]=m)})})}),o.useEffect(()=>{e&&(a.current={...e})},[e]);const f=o.useCallback((d,c)=>{a.current[d]=Math.max(0,Math.min(1,c))},[]),u=o.useCallback(()=>n.current,[]),y=o.useCallback(()=>({...a.current}),[]);return{setMorphTarget:f,getMorphTargetNames:u,getMorphTargetValues:y}}const L=o.createContext(null);function J(){const t=o.useContext(L);if(!t)throw new Error("BoneAttachment must be used within an AnimatedModel");return t}const O=o.forwardRef(({url:t,position:e=[0,0,0],rotation:a=[0,0,0],scale:n=1,defaultAnimation:s,morphTargets:f,onLoad:u,onError:y,children:d},c)=>{const r=o.useRef(null),m=o.useRef([]),{scene:l,animations:p}=x.useGLTF(t),h=o.useMemo(()=>_.clone(l),[l]),{playAnimation:i,stopAnimation:M,getAnimationNames:A}=F(p,h,{defaultAnimation:s}),{setMorphTarget:S}=P(h,f);o.useEffect(()=>{if(!h)return;const w=setTimeout(()=>{const E=[],B=[],N=new Set,k=new Set;let I=0;h.traverse(v=>{if(I++,v.type==="Bone"&&E.push(v.name),v.isMesh){const R=v;B.push(R.name),R.castShadow=!0,R.receiveShadow=!0,(Array.isArray(R.material)?R.material:[R.material]).forEach(C=>{N.add(C.name),C.shadowSide=T.DoubleSide}),R.morphTargetDictionary&&Object.keys(R.morphTargetDictionary).forEach(C=>{k.add(C)})}}),m.current=Array.from(k).sort(),u==null||u({meshes:B.sort(),materials:Array.from(N).sort(),bones:E.sort(),nodeCount:I,animations:p.map(v=>v.name),morphTargetNames:m.current})},0);return()=>clearTimeout(w)},[h,p,u]),o.useImperativeHandle(c,()=>({playAnimation:i,stopAnimation:M,getAnimationNames:A,getGroup:()=>r.current,setMorphTarget:S,getMorphTargetNames:()=>m.current}));const j=o.useMemo(()=>({scene:h,getBone:w=>h.getObjectByName(w)||null}),[h]),g=typeof n=="number"?[n,n,n]:n;return b.jsx(L.Provider,{value:j,children:b.jsxs("group",{ref:r,position:e,rotation:a,scale:g,children:[b.jsx("primitive",{object:h}),d]})})});O.displayName="AnimatedModel";O.preload=t=>{x.useGLTF.preload(t)};const H=o.forwardRef(({url:t,position:e=[0,0,0],rotation:a=[0,0,0],scale:n=1,morphTargets:s,onMorphTargetsFound:f,onLoad:u,onError:y},d)=>{const{scene:c}=x.useGLTF(t),r=o.useMemo(()=>c.clone(),[c]),{setMorphTarget:m,getMorphTargetNames:l,getMorphTargetValues:p}=P(r,s);o.useEffect(()=>{const i=l();i.length>0&&(f==null||f(i))},[r,l,f]),o.useEffect(()=>{if(!r)return;const i=[],M=new Set,A=[];let S=0;r.traverse(j=>{if(S++,j.type==="Bone"&&A.push(j.name),j.isMesh){const g=j;i.push(g.name),g.castShadow=!0,g.receiveShadow=!0,(Array.isArray(g.material)?g.material:[g.material]).forEach(E=>M.add(E.name))}}),u==null||u({meshes:i.sort(),materials:Array.from(M).sort(),bones:A.sort(),nodeCount:S})},[r,u]),o.useImperativeHandle(d,()=>({setMorphTarget:m,getMorphTargetNames:l,getMorphTargetValues:p}));const h=typeof n=="number"?[n,n,n]:n;return b.jsx("group",{position:e,rotation:a,scale:h,children:b.jsx("primitive",{object:r})})});H.displayName="MorphableModel";function K({children:t,bone:e,position:a=[0,0,0],rotation:n=[0,0,0],scale:s=1}){const{getBone:f}=J(),[u,y]=o.useState(null);if(o.useEffect(()=>{const c=f(e);c?y(c):console.warn(`Bone "${e}" not found in model`)},[e,f]),!u)return null;const d=typeof s=="number"?[s,s,s]:s;return D.createPortal(b.jsx("group",{position:a,rotation:n,scale:d,children:t}),u)}function Q(t,e){const{scene:a,animations:n}=x.useGLTF(t),s=o.useMemo(()=>_.clone(a),[a]);return o.useEffect(()=>{var c;if(!s)return;const f=[],u=[],y=new Set;let d=0;s.traverse(r=>{if(d++,r.type==="Bone"&&f.push(r.name),r.isMesh){const m=r;u.push(m.name),m.castShadow=!0,m.receiveShadow=!0,(Array.isArray(m.material)?m.material:[m.material]).forEach(p=>{y.add(p.name),p.shadowSide=T.DoubleSide})}}),(c=e==null?void 0:e.onLoad)==null||c.call(e,{meshes:u.sort(),materials:Array.from(y).sort(),bones:f.sort(),nodeCount:d})},[s,e]),{scene:s,animations:n}}function X(t){x.useGLTF.preload(t)}exports.AnimatedModel=O;exports.BoneAttachment=K;exports.Model=q;exports.MorphableModel=H;exports.Scene3D=V;exports.preloadModel=X;exports.useAnimationController=F;exports.useClonedModel=Q;exports.useMorphTargets=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),A=require("@react-three/drei"),X=require("three"),Y=require("three/examples/jsm/utils/SkeletonUtils.js"),D=require("@react-three/fiber"),b=require("react/jsx-runtime");function W(n){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const s in n)if(s!=="default"){const o=Object.getOwnPropertyDescriptor(n,s);Object.defineProperty(r,s,o.get?o:{enumerable:!0,get:()=>n[s]})}}return r.default=n,Object.freeze(r)}const S=W(X),$=W(Y);function ee({position:n,controlsConfig:r}){const{camera:s}=D.useThree(),o=a.useRef(null);return a.useEffect(()=>{n&&s&&(s.position.set(n[0],n[1],n[2]),s.updateProjectionMatrix(),o.current&&(o.current.target.set(0,0,0),o.current.update()))},[n,s]),b.jsx(A.OrbitControls,{ref:o,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 te({background:n}){const r=n==null?void 0:n.startsWith("#");return n?r?b.jsx("color",{attach:"background",args:[n]}):b.jsx(re,{url:n}):null}function re({url:n}){const r=A.useTexture(n);return a.useMemo(()=>{r.colorSpace=S.SRGBColorSpace},[r]),b.jsx("primitive",{attach:"background",object:r})}function ne({children:n,camera:r={},controls:s={},background:o,shadows:f=!0,ambientIntensity:h=.5,spotLight:p={},contactShadows:l=!0,style:u,className:e}){const t={position:r.position||[0,2,5],fov:r.fov||45},c={enabled:s.enabled??!0,enablePan:s.enablePan??!0,enableZoom:s.enableZoom??!0,enableRotate:s.enableRotate??!0,minDistance:s.minDistance,maxDistance:s.maxDistance,minPolarAngle:s.minPolarAngle,maxPolarAngle:s.maxPolarAngle,autoRotate:s.autoRotate??!1,autoRotateSpeed:s.autoRotateSpeed??2},i={position:p.position||[5,10,5],intensity:p.intensity??50,castShadow:p.castShadow??!0},m=typeof l=="object"?{position:l.position||[0,-1,0],opacity:l.opacity??.5,blur:l.blur??2}:l?{position:[0,-1,0],opacity:.5,blur:2}:null;return b.jsx("div",{style:u,className:e,children:b.jsxs(D.Canvas,{shadows:f,camera:{position:t.position,fov:t.fov},style:{width:"100%",height:"100%"},children:[b.jsx(a.Suspense,{fallback:null,children:b.jsx(te,{background:o})}),b.jsx("ambientLight",{intensity:h}),b.jsx("spotLight",{position:i.position,intensity:i.intensity,castShadow:i.castShadow}),b.jsx(a.Suspense,{fallback:null,children:n}),b.jsx(ee,{position:t.position,controlsConfig:c}),m&&b.jsx(A.ContactShadows,{position:m.position,opacity:m.opacity,blur:m.blur})]})})}function G(n,r){const s=a.useRef(new Map),o=a.useRef(r||{});a.useEffect(()=>{if(!n)return;const l=new Map;n.traverse(u=>{if(u.isMesh){const e=u;e.name&&l.set(e.name,e)}}),s.current=l,r&&Object.entries(r).forEach(([u,e])=>{const t=l.get(u);t&&(t.visible=e)})},[n,r]),D.useFrame(()=>{const l=o.current,u=s.current;Object.entries(l).forEach(([e,t])=>{const c=u.get(e);c&&c.visible!==t&&(c.visible=t)})});const f=a.useCallback((l,u)=>{o.current[l]=u;const e=s.current.get(l);e&&(e.visible=u)},[]),h=a.useCallback(()=>Array.from(s.current.keys()).sort(),[]),p=a.useCallback(()=>{const l={};return s.current.forEach((u,e)=>{l[e]=u.visible}),l},[]);return{setMeshVisibility:f,getMeshNames:h,getMeshVisibility:p}}function F(n,r){const s=a.useRef(new Map),o=a.useRef(new Map);a.useEffect(()=>{if(!n)return;const e=new Map;n.traverse(t=>{if(t.isMesh){const c=t;(Array.isArray(c.material)?c.material:[c.material]).forEach(m=>{m.name&&!e.has(m.name)&&e.set(m.name,m)})}}),s.current=e,r&&Object.entries(r).forEach(([t,c])=>{const i=e.get(t);if(i&&!Array.isArray(i)){const m=f(c);i.color&&i.color.copy(m),o.current.set(t,m)}})},[n,r]),D.useFrame(()=>{o.current.forEach((e,t)=>{const c=s.current.get(t);if(c&&!Array.isArray(c)){const i=c;i.color&&!i.color.equals(e)&&(i.color.copy(e),i.needsUpdate=!0)}})});const f=e=>typeof e=="string"?new S.Color(e):new S.Color(e[0],e[1],e[2]),h=a.useCallback((e,t)=>{const c=f(t);o.current.set(e,c);const i=s.current.get(e);if(i&&!Array.isArray(i)){const m=i;m.color&&(m.color.copy(c),m.needsUpdate=!0)}},[]),p=a.useCallback(()=>Array.from(s.current.keys()).sort(),[]),l=a.useCallback(e=>{const t=s.current.get(e);if(t&&!Array.isArray(t)){const c=t;if(c.color)return"#"+c.color.getHexString()}return null},[]),u=a.useCallback(()=>{const e={};return s.current.forEach((t,c)=>{if(!Array.isArray(t)){const i=t;i.color&&(e[c]="#"+i.color.getHexString())}}),e},[]);return{setMaterialColor:h,getMaterialNames:p,getMaterialColor:l,getAllMaterialColors:u}}function z({url:n,position:r=[0,0,0],rotation:s=[0,0,0],scale:o=1,meshVisibility:f,materialColors:h,onLoad:p,onError:l}){const{scene:u}=A.useGLTF(n),e=a.useMemo(()=>{const c=u.clone(),i=[],m=new Set,g=[];let d=0;return c.traverse(y=>{if(d++,y.type==="Bone"&&g.push(y.name),y.isMesh){const M=y;i.push(M.name),M.castShadow=!0,M.receiveShadow=!0,(Array.isArray(M.material)?M.material:[M.material]).forEach(C=>m.add(C.name))}}),p&&setTimeout(()=>{p({meshes:i.sort(),materials:Array.from(m).sort(),bones:g.sort(),nodeCount:d})},0),c},[u,p]);G(e,f),F(e,h);const t=typeof o=="number"?[o,o,o]:o;return b.jsx("group",{position:r,rotation:s,scale:t,children:b.jsx("primitive",{object:e})})}z.preload=n=>{A.useGLTF.preload(n)};function J(n,r,s){const{actions:o,names:f}=A.useAnimations(n,r),h=a.useRef(null),p=a.useRef(s==null?void 0:s.defaultAnimation);a.useEffect(()=>{if(f.length===0)return;const t=p.current;let c=f[0];if(t){const m=f.find(g=>g===t||g.includes(t));m&&(c=m)}const i=o[c];i&&(i.reset().fadeIn(.5).play(),h.current=i)},[o,f]);const l=a.useCallback((t,c)=>{const{loop:i=!1,crossFadeDuration:m=.2,restoreDefault:g=!0}=c||{};let d=o[t];if(!d){const M=Object.keys(o).find(x=>x.toLowerCase().includes(t.toLowerCase())||t.toLowerCase().includes(x.toLowerCase()));M&&(d=o[M])}if(!d){console.warn(`Animation "${t}" not found. Available: ${f.join(", ")}`);return}const y=h.current;if(!(y===d&&d.isRunning())&&(y&&y!==d&&y.fadeOut(m),d.reset(),d.fadeIn(m),d.setLoop(i?S.LoopRepeat:S.LoopOnce,i?1/0:1),d.clampWhenFinished=!i,d.play(),i||d.getMixer().update(0),h.current=d,g&&!i&&p.current)){const M=d.getMixer(),x=C=>{if(C.action===d){M.removeEventListener("finished",x);const v=o[p.current];v&&(d.fadeOut(m),v.reset().fadeIn(m).play(),h.current=v)}};M.addEventListener("finished",x)}},[o,f]),u=a.useCallback(()=>{var t;(t=h.current)==null||t.fadeOut(.2),h.current=null},[]),e=a.useCallback(()=>f,[f]);return{playAnimation:l,stopAnimation:u,getAnimationNames:e,actions:o}}function q(n,r){const s=a.useRef(r||{}),o=a.useRef([]),f=a.useRef([]);a.useEffect(()=>{const u=new Set,e=[];n.traverse(t=>{t instanceof S.Mesh&&t.morphTargetDictionary&&t.morphTargetInfluences&&(e.push(t),Object.keys(t.morphTargetDictionary).forEach(c=>{u.add(c)}))}),o.current=Array.from(u).sort(),f.current=e},[n]),D.useFrame(()=>{const u=s.current;f.current.forEach(e=>{!e.morphTargetDictionary||!e.morphTargetInfluences||Object.entries(u).forEach(([t,c])=>{const i=e.morphTargetDictionary[t];i!==void 0&&(e.morphTargetInfluences[i]=c)})})}),a.useEffect(()=>{r&&(s.current={...r})},[r]);const h=a.useCallback((u,e)=>{s.current[u]=Math.max(0,Math.min(1,e))},[]),p=a.useCallback(()=>o.current,[]),l=a.useCallback(()=>({...s.current}),[]);return{setMorphTarget:h,getMorphTargetNames:p,getMorphTargetValues:l}}const K=a.createContext(null);function se(){const n=a.useContext(K);if(!n)throw new Error("BoneAttachment must be used within an AnimatedModel");return n}const H=a.forwardRef(({url:n,position:r=[0,0,0],rotation:s=[0,0,0],scale:o=1,defaultAnimation:f,morphTargets:h,meshVisibility:p,materialColors:l,onLoad:u,onError:e,children:t},c)=>{const i=a.useRef(null),m=a.useRef([]),{scene:g,animations:d}=A.useGLTF(n),y=a.useMemo(()=>$.clone(g),[g]),{playAnimation:M,stopAnimation:x,getAnimationNames:C}=J(d,y,{defaultAnimation:f}),{setMorphTarget:v}=q(y,h),{setMeshVisibility:_,getMeshNames:E}=G(y,p),{setMaterialColor:k,getMaterialNames:O,getMaterialColor:P}=F(y,l);a.useEffect(()=>{if(!y)return;const N=setTimeout(()=>{const B=[],L=[],U=new Set,V=new Set;let Z=0;y.traverse(T=>{if(Z++,T.type==="Bone"&&B.push(T.name),T.isMesh){const R=T;L.push(R.name),R.castShadow=!0,R.receiveShadow=!0,(Array.isArray(R.material)?R.material:[R.material]).forEach(I=>{U.add(I.name),I.shadowSide=S.DoubleSide}),R.morphTargetDictionary&&Object.keys(R.morphTargetDictionary).forEach(I=>{V.add(I)})}}),m.current=Array.from(V).sort(),u==null||u({meshes:L.sort(),materials:Array.from(U).sort(),bones:B.sort(),nodeCount:Z,animations:d.map(T=>T.name),morphTargetNames:m.current})},0);return()=>clearTimeout(N)},[y,d,u]),a.useImperativeHandle(c,()=>({playAnimation:M,stopAnimation:x,getAnimationNames:C,getGroup:()=>i.current,setMorphTarget:v,getMorphTargetNames:()=>m.current,setMeshVisibility:_,getMeshNames:E,setMaterialColor:k,getMaterialNames:O,getMaterialColor:P}));const w=a.useMemo(()=>({scene:y,getBone:N=>y.getObjectByName(N)||null}),[y]),j=typeof o=="number"?[o,o,o]:o;return b.jsx(K.Provider,{value:w,children:b.jsxs("group",{ref:i,position:r,rotation:s,scale:j,children:[b.jsx("primitive",{object:y}),t]})})});H.displayName="AnimatedModel";H.preload=n=>{A.useGLTF.preload(n)};const Q=a.forwardRef(({url:n,position:r=[0,0,0],rotation:s=[0,0,0],scale:o=1,morphTargets:f,meshVisibility:h,materialColors:p,onMorphTargetsFound:l,onLoad:u,onError:e},t)=>{const{scene:c}=A.useGLTF(n),i=a.useMemo(()=>c.clone(),[c]),{setMorphTarget:m,getMorphTargetNames:g,getMorphTargetValues:d}=q(i,f),{setMeshVisibility:y,getMeshNames:M}=G(i,h),{setMaterialColor:x,getMaterialNames:C,getMaterialColor:v}=F(i,p);a.useEffect(()=>{const E=g();E.length>0&&(l==null||l(E))},[i,g,l]),a.useEffect(()=>{if(!i)return;const E=[],k=new Set,O=[];let P=0;i.traverse(w=>{if(P++,w.type==="Bone"&&O.push(w.name),w.isMesh){const j=w;E.push(j.name),j.castShadow=!0,j.receiveShadow=!0,(Array.isArray(j.material)?j.material:[j.material]).forEach(B=>k.add(B.name))}}),u==null||u({meshes:E.sort(),materials:Array.from(k).sort(),bones:O.sort(),nodeCount:P})},[i,u]),a.useImperativeHandle(t,()=>({setMorphTarget:m,getMorphTargetNames:g,getMorphTargetValues:d,setMeshVisibility:y,getMeshNames:M,setMaterialColor:x,getMaterialNames:C,getMaterialColor:v}));const _=typeof o=="number"?[o,o,o]:o;return b.jsx("group",{position:r,rotation:s,scale:_,children:b.jsx("primitive",{object:i})})});Q.displayName="MorphableModel";function ae({children:n,bone:r,position:s=[0,0,0],rotation:o=[0,0,0],scale:f=1}){const{getBone:h}=se(),[p,l]=a.useState(null);if(a.useEffect(()=>{const e=h(r);e?l(e):console.warn(`Bone "${r}" not found in model`)},[r,h]),!p)return null;const u=typeof f=="number"?[f,f,f]:f;return D.createPortal(b.jsx("group",{position:s,rotation:o,scale:u,children:n}),p)}function oe(n,r){const{scene:s,animations:o}=A.useGLTF(n),f=a.useMemo(()=>$.clone(s),[s]);return a.useEffect(()=>{var e;if(!f)return;const h=[],p=[],l=new Set;let u=0;f.traverse(t=>{if(u++,t.type==="Bone"&&h.push(t.name),t.isMesh){const c=t;p.push(c.name),c.castShadow=!0,c.receiveShadow=!0,(Array.isArray(c.material)?c.material:[c.material]).forEach(m=>{l.add(m.name),m.shadowSide=S.DoubleSide})}}),(e=r==null?void 0:r.onLoad)==null||e.call(r,{meshes:p.sort(),materials:Array.from(l).sort(),bones:h.sort(),nodeCount:u})},[f,r]),{scene:f,animations:o}}function ie(n){A.useGLTF.preload(n)}exports.AnimatedModel=H;exports.BoneAttachment=ae;exports.Model=z;exports.MorphableModel=Q;exports.Scene3D=ne;exports.preloadModel=ie;exports.useAnimationController=J;exports.useClonedModel=oe;exports.useMaterialColor=F;exports.useMeshVisibility=G;exports.useMorphTargets=q;
2
2
  //# sourceMappingURL=mbt-3d.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"mbt-3d.cjs","sources":["../src/lib/components/Scene3D/Scene3D.tsx","../src/lib/components/Model/Model.tsx","../src/lib/hooks/useAnimationController.ts","../src/lib/hooks/useMorphTargets.ts","../src/lib/components/AnimatedModel/AnimatedModelContext.tsx","../src/lib/components/AnimatedModel/AnimatedModel.tsx","../src/lib/components/MorphableModel/MorphableModel.tsx","../src/lib/components/BoneAttachment/BoneAttachment.tsx","../src/lib/hooks/useClonedModel.ts"],"sourcesContent":["import { Suspense, useMemo, useRef, useEffect } from 'react';\r\nimport { Canvas, useThree } from '@react-three/fiber';\r\nimport { OrbitControls, ContactShadows, useTexture } from '@react-three/drei';\r\nimport * as THREE from 'three';\r\nimport type { Scene3DProps } from '../../types';\r\nimport type { OrbitControls as OrbitControlsType } from 'three-stdlib';\r\n\r\n/**\r\n * CameraController - Updates camera position when props change\r\n */\r\nfunction CameraController({ \r\n position,\r\n controlsConfig \r\n}: { \r\n position: [number, number, number];\r\n controlsConfig: any;\r\n}) {\r\n const { camera } = useThree();\r\n const controlsRef = useRef<OrbitControlsType | null>(null);\r\n\r\n useEffect(() => {\r\n if (position && camera) {\r\n camera.position.set(position[0], position[1], position[2]);\r\n camera.updateProjectionMatrix();\r\n \r\n // Reset OrbitControls target to origin\r\n if (controlsRef.current) {\r\n controlsRef.current.target.set(0, 0, 0);\r\n controlsRef.current.update();\r\n }\r\n }\r\n }, [position, camera]);\r\n\r\n return (\r\n <OrbitControls\r\n ref={controlsRef}\r\n makeDefault\r\n enabled={controlsConfig.enabled}\r\n enablePan={controlsConfig.enablePan}\r\n enableZoom={controlsConfig.enableZoom}\r\n enableRotate={controlsConfig.enableRotate}\r\n minDistance={controlsConfig.minDistance}\r\n maxDistance={controlsConfig.maxDistance}\r\n minPolarAngle={controlsConfig.minPolarAngle}\r\n maxPolarAngle={controlsConfig.maxPolarAngle}\r\n autoRotate={controlsConfig.autoRotate}\r\n autoRotateSpeed={controlsConfig.autoRotateSpeed}\r\n />\r\n );\r\n}\r\n\r\n/**\r\n * Background component that handles both image URLs and solid colors\r\n */\r\nfunction Background({ background }: { background?: string }) {\r\n // Check if it's a color (starts with #) or an image URL\r\n const isColor = background?.startsWith('#');\r\n \r\n if (!background) return null;\r\n \r\n if (isColor) {\r\n return <color attach=\"background\" args={[background]} />;\r\n }\r\n \r\n // It's an image URL\r\n return <BackgroundImage url={background} />;\r\n}\r\n\r\nfunction BackgroundImage({ url }: { url: string }) {\r\n const texture = useTexture(url);\r\n \r\n // Configure texture for background\r\n useMemo(() => {\r\n texture.colorSpace = THREE.SRGBColorSpace;\r\n }, [texture]);\r\n \r\n return <primitive attach=\"background\" object={texture} />;\r\n}\r\n\r\n/**\r\n * Scene3D - Main 3D scene container with built-in canvas, lighting, and controls\r\n * \r\n * @remarks\r\n * This component wraps React Three Fiber's Canvas and provides:\r\n * - OrbitControls for camera rotation (preserves state between model changes)\r\n * - Configurable lighting (ambient + spot light)\r\n * - Optional background (image URL or hex color like \"#1a1a2e\")\r\n * - Optional contact shadows under models\r\n * - Shadow support\r\n * \r\n * @param children - React children to render inside the 3D scene\r\n * @param camera - Camera configuration object. Example: `{ position: [0, 2, 5], fov: 45 }`\r\n * @param camera.position - Camera position as [x, y, z]. Example: `[0, 2, 5]`. Default: `[0, 2, 5]`\r\n * @param camera.fov - Field of view in degrees. Example: `45`. Default: `45`\r\n * @param controls - OrbitControls configuration object. Example: `{ enablePan: false, minDistance: 2, maxDistance: 10 }`\r\n * @param controls.enabled - Enable/disable all controls. Default: `true`\r\n * @param controls.enablePan - Enable camera panning with middle mouse. Default: `true`\r\n * @param controls.enableZoom - Enable camera zoom with scroll wheel. Default: `true`\r\n * @param controls.enableRotate - Enable camera rotation with left mouse. Default: `true`\r\n * @param controls.minDistance - Minimum zoom distance. Example: `2`\r\n * @param controls.maxDistance - Maximum zoom distance. Example: `10`\r\n * @param controls.minPolarAngle - Minimum vertical rotation angle in radians. Example: `Math.PI / 4`\r\n * @param controls.maxPolarAngle - Maximum vertical rotation angle in radians. Example: `Math.PI / 1.8`\r\n * @param controls.autoRotate - Auto-rotate camera around the center. Default: `false`\r\n * @param controls.autoRotateSpeed - Auto-rotation speed. Default: `2`\r\n * @param background - Background: image URL (e.g., `\"/bg.jpg\"`) or hex color (e.g., `\"#1a1a2e\"`)\r\n * @param shadows - Enable shadow rendering. Default: `true`\r\n * @param ambientIntensity - Ambient light intensity (0-1). Example: `0.5`. Default: `0.5`\r\n * @param spotLight - Spot light configuration object. Example: `{ position: [5, 10, 5], intensity: 50 }`\r\n * @param spotLight.position - Light position as [x, y, z]. Example: `[5, 10, 5]`. Default: `[5, 10, 5]`\r\n * @param spotLight.intensity - Light intensity. Example: `50`. Default: `50`\r\n * @param spotLight.castShadow - Enable shadow casting. Default: `true`\r\n * @param contactShadows - Contact shadows configuration. Can be `true` for default settings or object with custom settings. Example: `{ position: [0, -1, 0], opacity: 0.5, blur: 2 }`\r\n * @param contactShadows.position - Shadow position as [x, y, z]. Example: `[0, -1, 0]`. Default: `[0, -1, 0]`\r\n * @param contactShadows.opacity - Shadow opacity (0-1). Example: `0.5`. Default: `0.5`\r\n * @param contactShadows.blur - Shadow blur amount. Example: `2`. Default: `2`\r\n * @param style - Container style object. Example: `{ width: 400, height: 500 }`\r\n * @param className - Container CSS class name\r\n * \r\n * @example\r\n * ```tsx\r\n * <Scene3D\r\n * camera={{ position: [0, 2, 5], fov: 45 }}\r\n * background=\"#1a1a2e\"\r\n * shadows\r\n * style={{ width: 400, height: 500 }}\r\n * >\r\n * <AnimatedModel url=\"/model.glb\" position={[0, -1, 0]} />\r\n * </Scene3D>\r\n * ```\r\n */\r\nexport function Scene3D({\r\n children,\r\n camera = {},\r\n controls = {},\r\n background,\r\n shadows = true,\r\n ambientIntensity = 0.5,\r\n spotLight = {},\r\n contactShadows = true,\r\n style,\r\n className,\r\n}: Scene3DProps) {\r\n const cameraConfig = {\r\n position: camera.position || [0, 2, 5],\r\n fov: camera.fov || 45,\r\n };\r\n\r\n const controlsConfig = {\r\n enabled: controls.enabled ?? true,\r\n enablePan: controls.enablePan ?? true,\r\n enableZoom: controls.enableZoom ?? true,\r\n enableRotate: controls.enableRotate ?? true,\r\n minDistance: controls.minDistance,\r\n maxDistance: controls.maxDistance,\r\n minPolarAngle: controls.minPolarAngle,\r\n maxPolarAngle: controls.maxPolarAngle,\r\n autoRotate: controls.autoRotate ?? false,\r\n autoRotateSpeed: controls.autoRotateSpeed ?? 2,\r\n };\r\n\r\n const spotLightConfig = {\r\n position: spotLight.position || [5, 10, 5],\r\n intensity: spotLight.intensity ?? 50,\r\n castShadow: spotLight.castShadow ?? true,\r\n };\r\n\r\n const contactShadowsConfig =\r\n typeof contactShadows === 'object'\r\n ? {\r\n position: contactShadows.position || [0, -1, 0],\r\n opacity: contactShadows.opacity ?? 0.5,\r\n blur: contactShadows.blur ?? 2,\r\n }\r\n : contactShadows\r\n ? { position: [0, -1, 0] as [number, number, number], opacity: 0.5, blur: 2 }\r\n : null;\r\n\r\n return (\r\n <div style={style} className={className}>\r\n <Canvas\r\n shadows={shadows}\r\n camera={{\r\n position: cameraConfig.position as [number, number, number],\r\n fov: cameraConfig.fov,\r\n }}\r\n style={{ width: '100%', height: '100%' }}\r\n >\r\n {/* Background */}\r\n <Suspense fallback={null}>\r\n <Background background={background} />\r\n </Suspense>\r\n\r\n {/* Lighting */}\r\n <ambientLight intensity={ambientIntensity} />\r\n <spotLight\r\n position={spotLightConfig.position}\r\n intensity={spotLightConfig.intensity}\r\n castShadow={spotLightConfig.castShadow}\r\n />\r\n\r\n {/* Content */}\r\n <Suspense fallback={null}>{children}</Suspense>\r\n\r\n {/* Controls - updates camera when props change */}\r\n <CameraController \r\n position={cameraConfig.position as [number, number, number]} \r\n controlsConfig={controlsConfig}\r\n />\r\n\r\n {/* Contact Shadows */}\r\n {contactShadowsConfig && (\r\n <ContactShadows\r\n position={contactShadowsConfig.position}\r\n opacity={contactShadowsConfig.opacity}\r\n blur={contactShadowsConfig.blur}\r\n />\r\n )}\r\n </Canvas>\r\n </div>\r\n );\r\n}\r\n","import { useMemo } from 'react';\r\nimport { useGLTF } from '@react-three/drei';\r\nimport * as THREE from 'three';\r\nimport type { ModelProps } from '../../types';\r\n\r\n/**\r\n * Model - Simple 3D model component for loading and displaying GLB/GLTF files\r\n * \r\n * @remarks\r\n * This component:\r\n * - Loads GLB/GLTF models using drei's useGLTF hook\r\n * - Automatically clones the scene for independent instances\r\n * - Configures shadows on all meshes\r\n * - Supports position, rotation, and scale transforms\r\n * - Provides onLoad callback with model metadata\r\n * \r\n * @param url - URL or path to GLB/GLTF model file. Example: `\"/models/sword.glb\"`\r\n * @param position - Model position in 3D space as [x, y, z]. Example: `[0, 0, 0]`. Default: `[0, 0, 0]`\r\n * @param rotation - Model rotation in radians as [x, y, z]. Example: `[0, Math.PI/2, 0]`. Default: `[0, 0, 0]`\r\n * @param scale - Uniform scale (number) or per-axis scale [x, y, z]. Examples: `0.5` or `[1, 2, 1]`. Default: `1`\r\n * @param onLoad - Callback when model finishes loading. Receives ModelInfo object with metadata: `{ meshes, materials, bones, nodeCount }`\r\n * @param onError - Callback when model fails to load. Receives Error object\r\n * \r\n * @example\r\n * ```tsx\r\n * <Model \r\n * url=\"/models/sword.glb\"\r\n * position={[0, 0, 0]}\r\n * rotation={[0, Math.PI/2, 0]}\r\n * scale={0.5}\r\n * onLoad={(info) => console.log('Loaded:', info)}\r\n * />\r\n * ```\r\n */\r\nexport function Model({\r\n url,\r\n position = [0, 0, 0],\r\n rotation = [0, 0, 0],\r\n scale = 1,\r\n onLoad,\r\n onError: _onError,\r\n}: ModelProps) {\r\n const { scene } = useGLTF(url);\r\n\r\n // Clone scene for independent instance\r\n const clonedScene = useMemo(() => {\r\n const clone = scene.clone();\r\n \r\n // Setup shadows and collect info\r\n const meshes: string[] = [];\r\n const materials = new Set<string>();\r\n const bones: string[] = [];\r\n let nodeCount = 0;\r\n\r\n clone.traverse((child) => {\r\n nodeCount++;\r\n \r\n if (child.type === 'Bone') {\r\n bones.push(child.name);\r\n }\r\n \r\n if ((child as THREE.Mesh).isMesh) {\r\n const mesh = child as THREE.Mesh;\r\n meshes.push(mesh.name);\r\n mesh.castShadow = true;\r\n mesh.receiveShadow = true;\r\n \r\n const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];\r\n mats.forEach((mat) => materials.add(mat.name));\r\n }\r\n });\r\n\r\n // Defer callback to avoid state update during render\r\n if (onLoad) {\r\n setTimeout(() => {\r\n onLoad({\r\n meshes: meshes.sort(),\r\n materials: Array.from(materials).sort(),\r\n bones: bones.sort(),\r\n nodeCount,\r\n });\r\n }, 0);\r\n }\r\n\r\n return clone;\r\n }, [scene, onLoad]);\r\n\r\n const scaleArray = typeof scale === 'number' ? [scale, scale, scale] : scale;\r\n\r\n return (\r\n <group position={position} rotation={rotation} scale={scaleArray as [number, number, number]}>\r\n <primitive object={clonedScene} />\r\n </group>\r\n );\r\n}\r\n\r\n// Preload helper\r\nModel.preload = (url: string) => {\r\n useGLTF.preload(url);\r\n};\r\n","import { useRef, useCallback, useEffect } from 'react';\r\nimport { useAnimations } from '@react-three/drei';\r\nimport * as THREE from 'three';\r\n\r\ninterface UseAnimationControllerOptions {\r\n defaultAnimation?: string;\r\n}\r\n\r\nexport function useAnimationController(\r\n animations: THREE.AnimationClip[],\r\n scene: THREE.Object3D,\r\n options?: UseAnimationControllerOptions\r\n) {\r\n const { actions, names } = useAnimations(animations, scene);\r\n const currentActionRef = useRef<THREE.AnimationAction | null>(null);\r\n const defaultAnimationRef = useRef<string | undefined>(options?.defaultAnimation);\r\n\r\n // Play default animation on mount\r\n useEffect(() => {\r\n if (names.length === 0) return;\r\n\r\n const defaultAnim = defaultAnimationRef.current;\r\n let animToPlay = names[0];\r\n\r\n if (defaultAnim) {\r\n const match = names.find((n) => n === defaultAnim || n.includes(defaultAnim));\r\n if (match) animToPlay = match;\r\n }\r\n\r\n const action = actions[animToPlay];\r\n if (action) {\r\n action.reset().fadeIn(0.5).play();\r\n currentActionRef.current = action;\r\n }\r\n }, [actions, names]);\r\n\r\n const playAnimation = useCallback(\r\n (\r\n name: string,\r\n opts?: {\r\n loop?: boolean;\r\n crossFadeDuration?: number;\r\n restoreDefault?: boolean;\r\n }\r\n ) => {\r\n const {\r\n loop = false,\r\n crossFadeDuration = 0.2,\r\n restoreDefault = true,\r\n } = opts || {};\r\n\r\n // Find animation (exact match or partial)\r\n let targetAction = actions[name];\r\n\r\n if (!targetAction) {\r\n const match = Object.keys(actions).find(\r\n (a) =>\r\n a.toLowerCase().includes(name.toLowerCase()) ||\r\n name.toLowerCase().includes(a.toLowerCase())\r\n );\r\n if (match) {\r\n targetAction = actions[match];\r\n }\r\n }\r\n\r\n if (!targetAction) {\r\n console.warn(`Animation \"${name}\" not found. Available: ${names.join(', ')}`);\r\n return;\r\n }\r\n\r\n // Don't restart if already playing\r\n const prev = currentActionRef.current;\r\n if (prev === targetAction && targetAction.isRunning()) {\r\n return;\r\n }\r\n\r\n // Crossfade from previous\r\n if (prev && prev !== targetAction) {\r\n prev.fadeOut(crossFadeDuration);\r\n }\r\n\r\n // Setup new action\r\n targetAction.reset();\r\n targetAction.fadeIn(crossFadeDuration);\r\n targetAction.setLoop(\r\n loop ? THREE.LoopRepeat : THREE.LoopOnce,\r\n loop ? Infinity : 1\r\n );\r\n targetAction.clampWhenFinished = !loop;\r\n targetAction.play();\r\n\r\n // Force immediate update for non-looping animations\r\n if (!loop) {\r\n targetAction.getMixer().update(0);\r\n }\r\n\r\n currentActionRef.current = targetAction;\r\n\r\n // Restore default animation after one-shot completes\r\n if (restoreDefault && !loop && defaultAnimationRef.current) {\r\n const mixer = targetAction.getMixer();\r\n const onFinished = (e: { action: THREE.AnimationAction }) => {\r\n if (e.action === targetAction) {\r\n mixer.removeEventListener('finished', onFinished);\r\n \r\n const defaultAction = actions[defaultAnimationRef.current!];\r\n if (defaultAction) {\r\n targetAction.fadeOut(crossFadeDuration);\r\n defaultAction.reset().fadeIn(crossFadeDuration).play();\r\n currentActionRef.current = defaultAction;\r\n }\r\n }\r\n };\r\n mixer.addEventListener('finished', onFinished);\r\n }\r\n },\r\n [actions, names]\r\n );\r\n\r\n const stopAnimation = useCallback(() => {\r\n currentActionRef.current?.fadeOut(0.2);\r\n currentActionRef.current = null;\r\n }, []);\r\n\r\n const getAnimationNames = useCallback(() => names, [names]);\r\n\r\n return {\r\n playAnimation,\r\n stopAnimation,\r\n getAnimationNames,\r\n actions,\r\n };\r\n}\r\n","import { useRef, useCallback, useEffect } from 'react';\r\nimport { useFrame } from '@react-three/fiber';\r\nimport * as THREE from 'three';\r\n\r\nexport function useMorphTargets(\r\n scene: THREE.Object3D,\r\n initialValues?: Record<string, number>\r\n) {\r\n const morphValuesRef = useRef<Record<string, number>>(initialValues || {});\r\n const morphNamesRef = useRef<string[]>([]);\r\n const meshesWithMorphsRef = useRef<THREE.Mesh[]>([]);\r\n\r\n // Discover morph targets\r\n useEffect(() => {\r\n const names = new Set<string>();\r\n const meshes: THREE.Mesh[] = [];\r\n\r\n scene.traverse((child) => {\r\n if (\r\n child instanceof THREE.Mesh &&\r\n child.morphTargetDictionary &&\r\n child.morphTargetInfluences\r\n ) {\r\n meshes.push(child);\r\n Object.keys(child.morphTargetDictionary).forEach((name) => {\r\n names.add(name);\r\n });\r\n }\r\n });\r\n\r\n morphNamesRef.current = Array.from(names).sort();\r\n meshesWithMorphsRef.current = meshes;\r\n }, [scene]);\r\n\r\n // Apply morph targets every frame\r\n useFrame(() => {\r\n const values = morphValuesRef.current;\r\n \r\n meshesWithMorphsRef.current.forEach((mesh) => {\r\n if (!mesh.morphTargetDictionary || !mesh.morphTargetInfluences) return;\r\n \r\n Object.entries(values).forEach(([name, value]) => {\r\n const index = mesh.morphTargetDictionary![name];\r\n if (index !== undefined) {\r\n mesh.morphTargetInfluences![index] = value;\r\n }\r\n });\r\n });\r\n });\r\n\r\n // Update values when props change\r\n useEffect(() => {\r\n if (initialValues) {\r\n morphValuesRef.current = { ...initialValues };\r\n }\r\n }, [initialValues]);\r\n\r\n const setMorphTarget = useCallback((name: string, value: number) => {\r\n morphValuesRef.current[name] = Math.max(0, Math.min(1, value));\r\n }, []);\r\n\r\n const getMorphTargetNames = useCallback(() => morphNamesRef.current, []);\r\n\r\n const getMorphTargetValues = useCallback(() => ({ ...morphValuesRef.current }), []);\r\n\r\n return {\r\n setMorphTarget,\r\n getMorphTargetNames,\r\n getMorphTargetValues,\r\n };\r\n}\r\n","import { createContext, useContext } from 'react';\r\nimport type { AnimatedModelContextValue } from '../../types';\r\n\r\nexport const AnimatedModelContext = createContext<AnimatedModelContextValue | null>(null);\r\n\r\nexport function useAnimatedModelContext() {\r\n const context = useContext(AnimatedModelContext);\r\n if (!context) {\r\n throw new Error('BoneAttachment must be used within an AnimatedModel');\r\n }\r\n return context;\r\n}\r\n","import {\r\n forwardRef,\r\n useImperativeHandle,\r\n useRef,\r\n useMemo,\r\n useEffect,\r\n} from 'react';\r\nimport * as THREE from 'three';\r\nimport { useGLTF } from '@react-three/drei';\r\nimport * as SkeletonUtils from 'three/examples/jsm/utils/SkeletonUtils.js';\r\nimport { useAnimationController } from '../../hooks/useAnimationController';\r\nimport { useMorphTargets } from '../../hooks/useMorphTargets';\r\nimport { AnimatedModelContext } from './AnimatedModelContext';\r\nimport type { AnimatedModelProps, AnimatedModelHandle } from '../../types';\r\n\r\n/**\r\n * AnimatedModel - 3D model with animation support and bone attachment capability\r\n * \r\n * @remarks\r\n * This component:\r\n * - Loads GLB/GLTF models with animations using useGLTF\r\n * - Properly clones skinned meshes using SkeletonUtils for multiple instances\r\n * - Plays animations with automatic crossfading\r\n * - Supports morph targets for character customization\r\n * - Provides context for BoneAttachment children\r\n * - Exposes imperative API via ref for external animation control\r\n * \r\n * The ref provides these methods:\r\n * - `playAnimation(name, options)` - Play an animation with optional loop/restore\r\n * - `stopAnimation()` - Stop current animation\r\n * - `getAnimationNames()` - Get list of available animations\r\n * - `getGroup()` - Get the THREE.Group for advanced manipulation\r\n * - `setMorphTarget(name, value)` - Set morph target value\r\n * - `getMorphTargetNames()` - Get available morph target names\r\n * \r\n * @param ref - React ref for imperative API access\r\n * @param url - URL or path to GLB/GLTF model file with animations. Example: `\"/models/character.glb\"`\r\n * @param position - Model position in 3D space as [x, y, z]. Example: `[0, -1, 0]`. Default: `[0, 0, 0]`\r\n * @param rotation - Model rotation in radians as [x, y, z]. Example: `[0, Math.PI, 0]`. Default: `[0, 0, 0]`\r\n * @param scale - Uniform scale (number) or per-axis scale [x, y, z]. Examples: `0.5` or `[1, 2, 1]`. Default: `1`\r\n * @param defaultAnimation - Name of animation to play on load. If not specified, plays first animation. Example: `\"Idle\"`\r\n * @param morphTargets - Morph target values as key-value pairs where value is 0-1. Example: `{ muscular: 0.5, thin: 0.2 }`\r\n * @param children - Child components, typically BoneAttachment components for attaching items\r\n * @param onLoad - Callback when model loads. Receives AnimatedModelInfo object: `{ meshes, materials, bones, nodeCount, animations, morphTargetNames }`\r\n * @param onError - Callback when model fails to load. Receives Error object\r\n * \r\n * @example\r\n * ```tsx\r\n * const modelRef = useRef<AnimatedModelHandle>(null);\r\n * \r\n * <AnimatedModel\r\n * ref={modelRef}\r\n * url=\"/models/character.glb\"\r\n * defaultAnimation=\"Idle\"\r\n * morphTargets={{ muscular: 0.5 }}\r\n * position={[0, -1, 0]}\r\n * >\r\n * <BoneAttachment bone=\"hand_r\">\r\n * <Model url=\"/models/sword.glb\" />\r\n * </BoneAttachment>\r\n * </AnimatedModel>\r\n * \r\n * // Control animations from outside\r\n * modelRef.current?.playAnimation('Attack', { loop: false });\r\n * ```\r\n */\r\nexport const AnimatedModel = forwardRef<AnimatedModelHandle, AnimatedModelProps>(\r\n (\r\n {\r\n url,\r\n position = [0, 0, 0],\r\n rotation = [0, 0, 0],\r\n scale = 1,\r\n defaultAnimation,\r\n morphTargets,\r\n onLoad,\r\n onError: _onError,\r\n children,\r\n },\r\n ref\r\n ) => {\r\n const groupRef = useRef<THREE.Group>(null);\r\n const morphNamesRef = useRef<string[]>([]);\r\n\r\n // Load and clone model\r\n const { scene: gltfScene, animations } = useGLTF(url);\r\n const scene = useMemo(() => SkeletonUtils.clone(gltfScene), [gltfScene]);\r\n\r\n // Animation controller\r\n const { playAnimation, stopAnimation, getAnimationNames } = useAnimationController(\r\n animations,\r\n scene,\r\n { defaultAnimation }\r\n );\r\n\r\n // Morph targets\r\n const { setMorphTarget } = useMorphTargets(\r\n scene,\r\n morphTargets\r\n );\r\n\r\n // Discover morph targets and call onLoad\r\n useEffect(() => {\r\n if (!scene) return;\r\n\r\n const timer = setTimeout(() => {\r\n const bones: string[] = [];\r\n const meshes: string[] = [];\r\n const materials = new Set<string>();\r\n const morphNames = new Set<string>();\r\n let nodeCount = 0;\r\n\r\n scene.traverse((child) => {\r\n nodeCount++;\r\n \r\n if (child.type === 'Bone') {\r\n bones.push(child.name);\r\n }\r\n \r\n if ((child as THREE.Mesh).isMesh) {\r\n const mesh = child as THREE.Mesh;\r\n meshes.push(mesh.name);\r\n \r\n // Setup shadows\r\n mesh.castShadow = true;\r\n mesh.receiveShadow = true;\r\n \r\n const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];\r\n mats.forEach((mat) => {\r\n materials.add(mat.name);\r\n mat.shadowSide = THREE.DoubleSide;\r\n });\r\n\r\n if (mesh.morphTargetDictionary) {\r\n Object.keys(mesh.morphTargetDictionary).forEach((name) => {\r\n morphNames.add(name);\r\n });\r\n }\r\n }\r\n });\r\n\r\n morphNamesRef.current = Array.from(morphNames).sort();\r\n\r\n onLoad?.({\r\n meshes: meshes.sort(),\r\n materials: Array.from(materials).sort(),\r\n bones: bones.sort(),\r\n nodeCount,\r\n animations: animations.map((a) => a.name),\r\n morphTargetNames: morphNamesRef.current,\r\n });\r\n }, 0);\r\n\r\n return () => clearTimeout(timer);\r\n }, [scene, animations, onLoad]);\r\n\r\n // Expose imperative handle\r\n useImperativeHandle(ref, () => ({\r\n playAnimation,\r\n stopAnimation,\r\n getAnimationNames,\r\n getGroup: () => groupRef.current,\r\n setMorphTarget,\r\n getMorphTargetNames: () => morphNamesRef.current,\r\n }));\r\n\r\n // Context for BoneAttachment children\r\n const contextValue = useMemo(\r\n () => ({\r\n scene,\r\n getBone: (name: string) => scene.getObjectByName(name) || null,\r\n }),\r\n [scene]\r\n );\r\n\r\n const scaleArray = typeof scale === 'number' ? [scale, scale, scale] : scale;\r\n\r\n return (\r\n <AnimatedModelContext.Provider value={contextValue}>\r\n <group\r\n ref={groupRef}\r\n position={position}\r\n rotation={rotation}\r\n scale={scaleArray as [number, number, number]}\r\n >\r\n <primitive object={scene} />\r\n {children}\r\n </group>\r\n </AnimatedModelContext.Provider>\r\n );\r\n }\r\n);\r\n\r\nAnimatedModel.displayName = 'AnimatedModel';\r\n\r\n// Preload helper\r\n(AnimatedModel as any).preload = (url: string) => {\r\n useGLTF.preload(url);\r\n};\r\n","import { forwardRef, useImperativeHandle, useMemo, useEffect } from 'react';\r\nimport { useGLTF } from '@react-three/drei';\r\nimport * as THREE from 'three';\r\nimport { useMorphTargets } from '../../hooks/useMorphTargets';\r\nimport type { MorphableModelProps, MorphableModelHandle } from '../../types';\r\n\r\n/**\r\n * MorphableModel - 3D model with morph targets for shape customization\r\n * \r\n * @remarks\r\n * This component:\r\n * - Loads GLB/GLTF models with morph targets (blend shapes)\r\n * - Dynamically discovers available morph targets from the model\r\n * - Applies morph target values in real-time\r\n * - Provides imperative API via ref for programmatic control\r\n * \r\n * Morph targets are commonly used for:\r\n * - Character customization (muscular, thin, fat)\r\n * - Facial expressions (smile, frown, blink)\r\n * - Clothing fit adjustments\r\n * \r\n * @param ref - React ref for imperative API access\r\n * @param url - URL or path to GLB/GLTF model file with morph targets. Example: `\"/models/character.glb\"`\r\n * @param position - Model position in 3D space as [x, y, z]. Example: `[0, -1, 0]`. Default: `[0, 0, 0]`\r\n * @param rotation - Model rotation in radians as [x, y, z]. Example: `[0, Math.PI, 0]`. Default: `[0, 0, 0]`\r\n * @param scale - Uniform scale (number) or per-axis scale [x, y, z]. Examples: `0.5` or `[1, 2, 1]`. Default: `1`\r\n * @param morphTargets - Morph target values as key-value pairs where value is 0-1. Example: `{ muscular: 0.5, thin: 0.2 }`\r\n * @param onMorphTargetsFound - Callback when morph targets are discovered from the model. Receives array of morph target names: `[\"muscular\", \"thin\", \"fat\"]`\r\n * @param onLoad - Callback when model finishes loading. Receives ModelInfo object with metadata: `{ meshes, materials, bones, nodeCount }`\r\n * @param onError - Callback when model fails to load. Receives Error object\r\n * \r\n * @example\r\n * ```tsx\r\n * const modelRef = useRef<MorphableModelHandle>(null);\r\n * const [morphs, setMorphs] = useState({ muscular: 0.5, thin: 0.2 });\r\n * \r\n * <MorphableModel\r\n * ref={modelRef}\r\n * url=\"/models/character.glb\"\r\n * morphTargets={morphs}\r\n * onMorphTargetsFound={(names) => console.log('Available:', names)}\r\n * position={[0, -1, 0]}\r\n * />\r\n * \r\n * // Control programmatically\r\n * modelRef.current?.setMorphTarget('muscular', 0.8);\r\n * ```\r\n */\r\nexport const MorphableModel = forwardRef<MorphableModelHandle, MorphableModelProps>(\r\n (\r\n {\r\n url,\r\n position = [0, 0, 0],\r\n rotation = [0, 0, 0],\r\n scale = 1,\r\n morphTargets,\r\n onMorphTargetsFound,\r\n onLoad,\r\n onError: _onError,\r\n },\r\n ref\r\n ) => {\r\n const { scene } = useGLTF(url);\r\n\r\n // Clone scene\r\n const clonedScene = useMemo(() => scene.clone(), [scene]);\r\n\r\n // Morph targets hook\r\n const { setMorphTarget, getMorphTargetNames, getMorphTargetValues } = useMorphTargets(\r\n clonedScene,\r\n morphTargets\r\n );\r\n\r\n // Discover morph targets and notify\r\n useEffect(() => {\r\n const names = getMorphTargetNames();\r\n if (names.length > 0) {\r\n onMorphTargetsFound?.(names);\r\n }\r\n }, [clonedScene, getMorphTargetNames, onMorphTargetsFound]);\r\n\r\n // Setup shadows and call onLoad\r\n useEffect(() => {\r\n if (!clonedScene) return;\r\n\r\n const meshes: string[] = [];\r\n const materials = new Set<string>();\r\n const bones: string[] = [];\r\n let nodeCount = 0;\r\n\r\n clonedScene.traverse((child) => {\r\n nodeCount++;\r\n \r\n if (child.type === 'Bone') {\r\n bones.push(child.name);\r\n }\r\n \r\n if ((child as THREE.Mesh).isMesh) {\r\n const mesh = child as THREE.Mesh;\r\n meshes.push(mesh.name);\r\n mesh.castShadow = true;\r\n mesh.receiveShadow = true;\r\n \r\n const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];\r\n mats.forEach((mat) => materials.add(mat.name));\r\n }\r\n });\r\n\r\n onLoad?.({\r\n meshes: meshes.sort(),\r\n materials: Array.from(materials).sort(),\r\n bones: bones.sort(),\r\n nodeCount,\r\n });\r\n }, [clonedScene, onLoad]);\r\n\r\n // Expose handle\r\n useImperativeHandle(ref, () => ({\r\n setMorphTarget,\r\n getMorphTargetNames,\r\n getMorphTargetValues,\r\n }));\r\n\r\n const scaleArray = typeof scale === 'number' ? [scale, scale, scale] : scale;\r\n\r\n return (\r\n <group position={position} rotation={rotation} scale={scaleArray as [number, number, number]}>\r\n <primitive object={clonedScene} />\r\n </group>\r\n );\r\n }\r\n);\r\n\r\nMorphableModel.displayName = 'MorphableModel';\r\n","import { useState, useEffect } from 'react';\r\nimport { createPortal } from '@react-three/fiber';\r\nimport * as THREE from 'three';\r\nimport { useAnimatedModelContext } from '../AnimatedModel/AnimatedModelContext';\r\nimport type { BoneAttachmentProps } from '../../types';\r\n\r\n/**\r\n * BoneAttachment - Attach models to bones of an AnimatedModel parent\r\n * \r\n * @remarks\r\n * This component:\r\n * - Must be used as a child of AnimatedModel\r\n * - Uses React Three Fiber's createPortal to attach to a bone\r\n * - Automatically follows bone transformations during animations\r\n * - Supports position/rotation/scale offsets relative to the bone\r\n * \r\n * Common bone names:\r\n * - Hand bones: \"hand_r\", \"hand_l\", \"DEF-handR\", \"DEF-handL\"\r\n * - Spine/Back: \"spine\", \"spine_upper\", \"back\"\r\n * - Head: \"head\", \"neck\"\r\n * \r\n * @param children - Child components to attach to the bone (typically Model components)\r\n * @param bone - Bone name to attach to. Must match bone name in the parent AnimatedModel. Example: `\"hand_r\"` or `\"DEF-handR\"`\r\n * @param position - Position offset relative to the bone as [x, y, z]. Example: `[0.1, 0, 0]`. Default: `[0, 0, 0]`\r\n * @param rotation - Rotation offset relative to the bone in radians as [x, y, z]. Example: `[0, Math.PI/2, 0]`. Default: `[0, 0, 0]`\r\n * @param scale - Uniform scale (number) or per-axis scale [x, y, z]. Examples: `0.7` or `[1, 2, 1]`. Default: `1`\r\n * \r\n * @example\r\n * ```tsx\r\n * <AnimatedModel url=\"/character.glb\">\r\n * // Sword in right hand\r\n * <BoneAttachment \r\n * bone=\"hand_r\"\r\n * position={[0.1, 0, 0]}\r\n * rotation={[0, Math.PI/2, 0]}\r\n * >\r\n * <Model url=\"/sword.glb\" scale={0.7} />\r\n * </BoneAttachment>\r\n * \r\n * // Shield on back\r\n * <BoneAttachment bone=\"spine_upper\">\r\n * <Model url=\"/shield.glb\" />\r\n * </BoneAttachment>\r\n * </AnimatedModel>\r\n * ```\r\n */\r\nexport function BoneAttachment({\r\n children,\r\n bone,\r\n position = [0, 0, 0],\r\n rotation = [0, 0, 0],\r\n scale = 1,\r\n}: BoneAttachmentProps) {\r\n const { getBone } = useAnimatedModelContext();\r\n const [boneObject, setBoneObject] = useState<THREE.Object3D | null>(null);\r\n\r\n useEffect(() => {\r\n const found = getBone(bone);\r\n if (found) {\r\n setBoneObject(found);\r\n } else {\r\n console.warn(`Bone \"${bone}\" not found in model`);\r\n }\r\n }, [bone, getBone]);\r\n\r\n if (!boneObject) {\r\n return null;\r\n }\r\n\r\n const scaleArray = typeof scale === 'number' ? [scale, scale, scale] : scale;\r\n\r\n return createPortal(\r\n <group\r\n position={position}\r\n rotation={rotation}\r\n scale={scaleArray as [number, number, number]}\r\n >\r\n {children}\r\n </group>,\r\n boneObject\r\n );\r\n}\r\n","import { useMemo, useEffect } from 'react';\r\nimport { useGLTF } from '@react-three/drei';\r\nimport * as THREE from 'three';\r\nimport * as SkeletonUtils from 'three/examples/jsm/utils/SkeletonUtils.js';\r\nimport type { ModelInfo } from '../types';\r\n\r\ninterface UseClonedModelOptions {\r\n onLoad?: (info: ModelInfo) => void;\r\n onError?: (error: Error) => void;\r\n}\r\n\r\nexport function useClonedModel(url: string, options?: UseClonedModelOptions) {\r\n const { scene, animations } = useGLTF(url);\r\n \r\n // Clone scene using SkeletonUtils for proper skinned mesh handling\r\n const clonedScene = useMemo(() => {\r\n return SkeletonUtils.clone(scene);\r\n }, [scene]);\r\n\r\n // Extract model info and setup shadows\r\n useEffect(() => {\r\n if (!clonedScene) return;\r\n\r\n const bones: string[] = [];\r\n const meshes: string[] = [];\r\n const materials = new Set<string>();\r\n let nodeCount = 0;\r\n\r\n clonedScene.traverse((child) => {\r\n nodeCount++;\r\n \r\n if (child.type === 'Bone') {\r\n bones.push(child.name);\r\n }\r\n \r\n if ((child as THREE.Mesh).isMesh) {\r\n const mesh = child as THREE.Mesh;\r\n meshes.push(mesh.name);\r\n \r\n // Setup shadows\r\n mesh.castShadow = true;\r\n mesh.receiveShadow = true;\r\n \r\n // Collect material names\r\n const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];\r\n mats.forEach((mat) => {\r\n materials.add(mat.name);\r\n mat.shadowSide = THREE.DoubleSide;\r\n });\r\n }\r\n });\r\n\r\n options?.onLoad?.({\r\n meshes: meshes.sort(),\r\n materials: Array.from(materials).sort(),\r\n bones: bones.sort(),\r\n nodeCount,\r\n });\r\n }, [clonedScene, options]);\r\n\r\n return { scene: clonedScene, animations };\r\n}\r\n\r\n// Preload helper\r\nexport function preloadModel(url: string) {\r\n useGLTF.preload(url);\r\n}\r\n"],"names":["CameraController","position","controlsConfig","camera","useThree","controlsRef","useRef","useEffect","jsx","OrbitControls","Background","background","isColor","BackgroundImage","url","texture","useTexture","useMemo","THREE","Scene3D","children","controls","shadows","ambientIntensity","spotLight","contactShadows","style","className","cameraConfig","spotLightConfig","contactShadowsConfig","jsxs","Canvas","Suspense","ContactShadows","Model","rotation","scale","onLoad","_onError","scene","useGLTF","clonedScene","clone","meshes","materials","bones","nodeCount","child","mesh","mat","scaleArray","useAnimationController","animations","options","actions","names","useAnimations","currentActionRef","defaultAnimationRef","defaultAnim","animToPlay","match","n","action","playAnimation","useCallback","name","opts","loop","crossFadeDuration","restoreDefault","targetAction","a","prev","mixer","onFinished","e","defaultAction","stopAnimation","_a","getAnimationNames","useMorphTargets","initialValues","morphValuesRef","morphNamesRef","meshesWithMorphsRef","useFrame","values","value","index","setMorphTarget","getMorphTargetNames","getMorphTargetValues","AnimatedModelContext","createContext","useAnimatedModelContext","context","useContext","AnimatedModel","forwardRef","defaultAnimation","morphTargets","ref","groupRef","gltfScene","SkeletonUtils","timer","morphNames","useImperativeHandle","contextValue","MorphableModel","onMorphTargetsFound","BoneAttachment","bone","getBone","boneObject","setBoneObject","useState","found","createPortal","useClonedModel","preloadModel"],"mappings":"kjBAUA,SAASA,EAAiB,CACxB,SAAAC,EACA,eAAAC,CACF,EAGG,CACD,KAAM,CAAE,OAAAC,CAAA,EAAWC,WAAA,EACbC,EAAcC,EAAAA,OAAiC,IAAI,EAEzDC,OAAAA,EAAAA,UAAU,IAAM,CACVN,GAAYE,IACdA,EAAO,SAAS,IAAIF,EAAS,CAAC,EAAGA,EAAS,CAAC,EAAGA,EAAS,CAAC,CAAC,EACzDE,EAAO,uBAAA,EAGHE,EAAY,UACdA,EAAY,QAAQ,OAAO,IAAI,EAAG,EAAG,CAAC,EACtCA,EAAY,QAAQ,OAAA,GAG1B,EAAG,CAACJ,EAAUE,CAAM,CAAC,EAGnBK,EAAAA,IAACC,EAAAA,cAAA,CACC,IAAKJ,EACL,YAAW,GACX,QAASH,EAAe,QACxB,UAAWA,EAAe,UAC1B,WAAYA,EAAe,WAC3B,aAAcA,EAAe,aAC7B,YAAaA,EAAe,YAC5B,YAAaA,EAAe,YAC5B,cAAeA,EAAe,cAC9B,cAAeA,EAAe,cAC9B,WAAYA,EAAe,WAC3B,gBAAiBA,EAAe,eAAA,CAAA,CAGtC,CAKA,SAASQ,EAAW,CAAE,WAAAC,GAAuC,CAE3D,MAAMC,EAAUD,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,SAAW,CAACA,EAAK,QAAQ,GACrE,QAASC,GAAQ,CACpBL,EAAU,IAAIK,EAAI,IAAI,EACtBA,EAAI,WAAahC,EAAM,UACzB,CAAC,CACH,CACF,CAAC,GAED8D,EAAA1B,GAAA,YAAAA,EAAS,SAAT,MAAA0B,EAAA,KAAA1B,EAAkB,CAChB,OAAQV,EAAO,KAAA,EACf,UAAW,MAAM,KAAKC,CAAS,EAAE,KAAA,EACjC,MAAOC,EAAM,KAAA,EACb,UAAAC,CAAA,EAEJ,EAAG,CAACL,EAAaY,CAAO,CAAC,EAElB,CAAE,MAAOZ,EAAa,WAAAW,CAAA,CAC/B,CAGO,SAASqE,EAAa5G,EAAa,CACxC2B,EAAAA,QAAQ,QAAQ3B,CAAG,CACrB"}
1
+ {"version":3,"file":"mbt-3d.cjs","sources":["../src/lib/components/Scene3D/Scene3D.tsx","../src/lib/hooks/useMeshVisibility.ts","../src/lib/hooks/useMaterialColor.ts","../src/lib/components/Model/Model.tsx","../src/lib/hooks/useAnimationController.ts","../src/lib/hooks/useMorphTargets.ts","../src/lib/components/AnimatedModel/AnimatedModelContext.tsx","../src/lib/components/AnimatedModel/AnimatedModel.tsx","../src/lib/components/MorphableModel/MorphableModel.tsx","../src/lib/components/BoneAttachment/BoneAttachment.tsx","../src/lib/hooks/useClonedModel.ts"],"sourcesContent":["import { Suspense, useMemo, useRef, useEffect } from 'react';\r\nimport { Canvas, useThree } from '@react-three/fiber';\r\nimport { OrbitControls, ContactShadows, useTexture } from '@react-three/drei';\r\nimport * as THREE from 'three';\r\nimport type { Scene3DProps } from '../../types';\r\nimport type { OrbitControls as OrbitControlsType } from 'three-stdlib';\r\n\r\n/**\r\n * CameraController - Updates camera position when props change\r\n */\r\nfunction CameraController({ \r\n position,\r\n controlsConfig \r\n}: { \r\n position: [number, number, number];\r\n controlsConfig: any;\r\n}) {\r\n const { camera } = useThree();\r\n const controlsRef = useRef<OrbitControlsType | null>(null);\r\n\r\n useEffect(() => {\r\n if (position && camera) {\r\n camera.position.set(position[0], position[1], position[2]);\r\n camera.updateProjectionMatrix();\r\n \r\n // Reset OrbitControls target to origin\r\n if (controlsRef.current) {\r\n controlsRef.current.target.set(0, 0, 0);\r\n controlsRef.current.update();\r\n }\r\n }\r\n }, [position, camera]);\r\n\r\n return (\r\n <OrbitControls\r\n ref={controlsRef}\r\n makeDefault\r\n enabled={controlsConfig.enabled}\r\n enablePan={controlsConfig.enablePan}\r\n enableZoom={controlsConfig.enableZoom}\r\n enableRotate={controlsConfig.enableRotate}\r\n minDistance={controlsConfig.minDistance}\r\n maxDistance={controlsConfig.maxDistance}\r\n minPolarAngle={controlsConfig.minPolarAngle}\r\n maxPolarAngle={controlsConfig.maxPolarAngle}\r\n autoRotate={controlsConfig.autoRotate}\r\n autoRotateSpeed={controlsConfig.autoRotateSpeed}\r\n />\r\n );\r\n}\r\n\r\n/**\r\n * Background component that handles both image URLs and solid colors\r\n */\r\nfunction Background({ background }: { background?: string }) {\r\n // Check if it's a color (starts with #) or an image URL\r\n const isColor = background?.startsWith('#');\r\n \r\n if (!background) return null;\r\n \r\n if (isColor) {\r\n return <color attach=\"background\" args={[background]} />;\r\n }\r\n \r\n // It's an image URL\r\n return <BackgroundImage url={background} />;\r\n}\r\n\r\nfunction BackgroundImage({ url }: { url: string }) {\r\n const texture = useTexture(url);\r\n \r\n // Configure texture for background\r\n useMemo(() => {\r\n texture.colorSpace = THREE.SRGBColorSpace;\r\n }, [texture]);\r\n \r\n return <primitive attach=\"background\" object={texture} />;\r\n}\r\n\r\n/**\r\n * Scene3D - Main 3D scene container with built-in canvas, lighting, and controls\r\n * \r\n * @remarks\r\n * This component wraps React Three Fiber's Canvas and provides:\r\n * - OrbitControls for camera rotation (preserves state between model changes)\r\n * - Configurable lighting (ambient + spot light)\r\n * - Optional background (image URL or hex color like \"#1a1a2e\")\r\n * - Optional contact shadows under models\r\n * - Shadow support\r\n * \r\n * @param children - React children to render inside the 3D scene\r\n * @param camera - Camera configuration object. Example: `{ position: [0, 2, 5], fov: 45 }`\r\n * @param camera.position - Camera position as [x, y, z]. Example: `[0, 2, 5]`. Default: `[0, 2, 5]`\r\n * @param camera.fov - Field of view in degrees. Example: `45`. Default: `45`\r\n * @param controls - OrbitControls configuration object. Example: `{ enablePan: false, minDistance: 2, maxDistance: 10 }`\r\n * @param controls.enabled - Enable/disable all controls. Default: `true`\r\n * @param controls.enablePan - Enable camera panning with middle mouse. Default: `true`\r\n * @param controls.enableZoom - Enable camera zoom with scroll wheel. Default: `true`\r\n * @param controls.enableRotate - Enable camera rotation with left mouse. Default: `true`\r\n * @param controls.minDistance - Minimum zoom distance. Example: `2`\r\n * @param controls.maxDistance - Maximum zoom distance. Example: `10`\r\n * @param controls.minPolarAngle - Minimum vertical rotation angle in radians. Example: `Math.PI / 4`\r\n * @param controls.maxPolarAngle - Maximum vertical rotation angle in radians. Example: `Math.PI / 1.8`\r\n * @param controls.autoRotate - Auto-rotate camera around the center. Default: `false`\r\n * @param controls.autoRotateSpeed - Auto-rotation speed. Default: `2`\r\n * @param background - Background: image URL (e.g., `\"/bg.jpg\"`) or hex color (e.g., `\"#1a1a2e\"`)\r\n * @param shadows - Enable shadow rendering. Default: `true`\r\n * @param ambientIntensity - Ambient light intensity (0-1). Example: `0.5`. Default: `0.5`\r\n * @param spotLight - Spot light configuration object. Example: `{ position: [5, 10, 5], intensity: 50 }`\r\n * @param spotLight.position - Light position as [x, y, z]. Example: `[5, 10, 5]`. Default: `[5, 10, 5]`\r\n * @param spotLight.intensity - Light intensity. Example: `50`. Default: `50`\r\n * @param spotLight.castShadow - Enable shadow casting. Default: `true`\r\n * @param contactShadows - Contact shadows configuration. Can be `true` for default settings or object with custom settings. Example: `{ position: [0, -1, 0], opacity: 0.5, blur: 2 }`\r\n * @param contactShadows.position - Shadow position as [x, y, z]. Example: `[0, -1, 0]`. Default: `[0, -1, 0]`\r\n * @param contactShadows.opacity - Shadow opacity (0-1). Example: `0.5`. Default: `0.5`\r\n * @param contactShadows.blur - Shadow blur amount. Example: `2`. Default: `2`\r\n * @param style - Container style object. Example: `{ width: 400, height: 500 }`\r\n * @param className - Container CSS class name\r\n * \r\n * @example\r\n * ```tsx\r\n * <Scene3D\r\n * camera={{ position: [0, 2, 5], fov: 45 }}\r\n * background=\"#1a1a2e\"\r\n * shadows\r\n * style={{ width: 400, height: 500 }}\r\n * >\r\n * <AnimatedModel url=\"/model.glb\" position={[0, -1, 0]} />\r\n * </Scene3D>\r\n * ```\r\n */\r\nexport function Scene3D({\r\n children,\r\n camera = {},\r\n controls = {},\r\n background,\r\n shadows = true,\r\n ambientIntensity = 0.5,\r\n spotLight = {},\r\n contactShadows = true,\r\n style,\r\n className,\r\n}: Scene3DProps) {\r\n const cameraConfig = {\r\n position: camera.position || [0, 2, 5],\r\n fov: camera.fov || 45,\r\n };\r\n\r\n const controlsConfig = {\r\n enabled: controls.enabled ?? true,\r\n enablePan: controls.enablePan ?? true,\r\n enableZoom: controls.enableZoom ?? true,\r\n enableRotate: controls.enableRotate ?? true,\r\n minDistance: controls.minDistance,\r\n maxDistance: controls.maxDistance,\r\n minPolarAngle: controls.minPolarAngle,\r\n maxPolarAngle: controls.maxPolarAngle,\r\n autoRotate: controls.autoRotate ?? false,\r\n autoRotateSpeed: controls.autoRotateSpeed ?? 2,\r\n };\r\n\r\n const spotLightConfig = {\r\n position: spotLight.position || [5, 10, 5],\r\n intensity: spotLight.intensity ?? 50,\r\n castShadow: spotLight.castShadow ?? true,\r\n };\r\n\r\n const contactShadowsConfig =\r\n typeof contactShadows === 'object'\r\n ? {\r\n position: contactShadows.position || [0, -1, 0],\r\n opacity: contactShadows.opacity ?? 0.5,\r\n blur: contactShadows.blur ?? 2,\r\n }\r\n : contactShadows\r\n ? { position: [0, -1, 0] as [number, number, number], opacity: 0.5, blur: 2 }\r\n : null;\r\n\r\n return (\r\n <div style={style} className={className}>\r\n <Canvas\r\n shadows={shadows}\r\n camera={{\r\n position: cameraConfig.position as [number, number, number],\r\n fov: cameraConfig.fov,\r\n }}\r\n style={{ width: '100%', height: '100%' }}\r\n >\r\n {/* Background */}\r\n <Suspense fallback={null}>\r\n <Background background={background} />\r\n </Suspense>\r\n\r\n {/* Lighting */}\r\n <ambientLight intensity={ambientIntensity} />\r\n <spotLight\r\n position={spotLightConfig.position}\r\n intensity={spotLightConfig.intensity}\r\n castShadow={spotLightConfig.castShadow}\r\n />\r\n\r\n {/* Content */}\r\n <Suspense fallback={null}>{children}</Suspense>\r\n\r\n {/* Controls - updates camera when props change */}\r\n <CameraController \r\n position={cameraConfig.position as [number, number, number]} \r\n controlsConfig={controlsConfig}\r\n />\r\n\r\n {/* Contact Shadows */}\r\n {contactShadowsConfig && (\r\n <ContactShadows\r\n position={contactShadowsConfig.position}\r\n opacity={contactShadowsConfig.opacity}\r\n blur={contactShadowsConfig.blur}\r\n />\r\n )}\r\n </Canvas>\r\n </div>\r\n );\r\n}\r\n","import { useEffect, useCallback, useRef } from 'react';\nimport { useFrame } from '@react-three/fiber';\nimport * as THREE from 'three';\n\n/**\n * Hook for managing mesh visibility in a 3D scene\n * \n * @param scene - The THREE.Object3D scene containing meshes\n * @param initialVisibility - Initial visibility state for meshes\n * @returns Methods to control mesh visibility\n */\nexport function useMeshVisibility(\n scene: THREE.Object3D,\n initialVisibility?: Record<string, boolean>\n) {\n const meshMapRef = useRef<Map<string, THREE.Mesh>>(new Map());\n const visibilityRef = useRef<Record<string, boolean>>(initialVisibility || {});\n\n // Discover all meshes in the scene\n useEffect(() => {\n if (!scene) return;\n\n const meshMap = new Map<string, THREE.Mesh>();\n \n scene.traverse((child) => {\n if ((child as THREE.Mesh).isMesh) {\n const mesh = child as THREE.Mesh;\n if (mesh.name) {\n meshMap.set(mesh.name, mesh);\n }\n }\n });\n\n meshMapRef.current = meshMap;\n\n // Apply initial visibility\n if (initialVisibility) {\n Object.entries(initialVisibility).forEach(([name, visible]) => {\n const mesh = meshMap.get(name);\n if (mesh) {\n mesh.visible = visible;\n }\n });\n }\n }, [scene, initialVisibility]);\n\n // Apply visibility changes on every frame\n useFrame(() => {\n const visibility = visibilityRef.current;\n const meshMap = meshMapRef.current;\n\n Object.entries(visibility).forEach(([name, visible]) => {\n const mesh = meshMap.get(name);\n if (mesh && mesh.visible !== visible) {\n mesh.visible = visible;\n }\n });\n });\n\n /**\n * Set visibility of a specific mesh\n */\n const setMeshVisibility = useCallback((name: string, visible: boolean) => {\n visibilityRef.current[name] = visible;\n \n const mesh = meshMapRef.current.get(name);\n if (mesh) {\n mesh.visible = visible;\n }\n }, []);\n\n /**\n * Get all mesh names in the scene\n */\n const getMeshNames = useCallback(() => {\n return Array.from(meshMapRef.current.keys()).sort();\n }, []);\n\n /**\n * Get current visibility state of all meshes\n */\n const getMeshVisibility = useCallback(() => {\n const visibility: Record<string, boolean> = {};\n meshMapRef.current.forEach((mesh, name) => {\n visibility[name] = mesh.visible;\n });\n return visibility;\n }, []);\n\n return {\n setMeshVisibility,\n getMeshNames,\n getMeshVisibility,\n };\n}\n","import { useEffect, useCallback, useRef } from 'react';\r\nimport { useFrame } from '@react-three/fiber';\r\nimport * as THREE from 'three';\r\n\r\n/**\r\n * Hook for managing material colors in a 3D scene\r\n * \r\n * @param scene - The THREE.Object3D scene containing meshes with materials\r\n * @param initialColors - Initial color values for materials { materialName: \"#hexcolor\" or [r, g, b] }\r\n * @returns Methods to control material colors\r\n */\r\nexport function useMaterialColor(\r\n scene: THREE.Object3D,\r\n initialColors?: Record<string, string | [number, number, number]>\r\n) {\r\n const materialMapRef = useRef<Map<string, THREE.Material | THREE.Material[]>>(new Map());\r\n const colorMapRef = useRef<Map<string, THREE.Color>>(new Map());\r\n\r\n // Discover all materials in the scene\r\n useEffect(() => {\r\n if (!scene) return;\r\n\r\n const materialMap = new Map<string, THREE.Material | THREE.Material[]>();\r\n \r\n scene.traverse((child) => {\r\n if ((child as THREE.Mesh).isMesh) {\r\n const mesh = child as THREE.Mesh;\r\n const materials = Array.isArray(mesh.material) ? mesh.material : [mesh.material];\r\n \r\n materials.forEach((material) => {\r\n if (material.name && !materialMap.has(material.name)) {\r\n materialMap.set(material.name, material);\r\n }\r\n });\r\n }\r\n });\r\n\r\n materialMapRef.current = materialMap;\r\n\r\n // Apply initial colors\r\n if (initialColors) {\r\n Object.entries(initialColors).forEach(([materialName, color]) => {\r\n const material = materialMap.get(materialName);\r\n if (material && !Array.isArray(material)) {\r\n const threeColor = parseColor(color);\r\n if ((material as any).color) {\r\n (material as any).color.copy(threeColor);\r\n }\r\n colorMapRef.current.set(materialName, threeColor);\r\n }\r\n });\r\n }\r\n }, [scene, initialColors]);\r\n\r\n // Apply color changes on every frame (for smooth transitions)\r\n useFrame(() => {\r\n colorMapRef.current.forEach((targetColor, materialName) => {\r\n const material = materialMapRef.current.get(materialName);\r\n if (material && !Array.isArray(material)) {\r\n const mat = material as any;\r\n if (mat.color && !mat.color.equals(targetColor)) {\r\n mat.color.copy(targetColor);\r\n mat.needsUpdate = true;\r\n }\r\n }\r\n });\r\n });\r\n\r\n /**\r\n * Parse color from hex string or RGB array\r\n */\r\n const parseColor = (color: string | [number, number, number]): THREE.Color => {\r\n if (typeof color === 'string') {\r\n return new THREE.Color(color);\r\n } else {\r\n return new THREE.Color(color[0], color[1], color[2]);\r\n }\r\n };\r\n\r\n /**\r\n * Set color of a specific material\r\n * @param materialName - Material name\r\n * @param color - Hex color string (e.g., \"#ff0000\") or RGB array [r, g, b] where values are 0-1\r\n */\r\n const setMaterialColor = useCallback((\r\n materialName: string, \r\n color: string | [number, number, number]\r\n ) => {\r\n const threeColor = parseColor(color);\r\n colorMapRef.current.set(materialName, threeColor);\r\n \r\n const material = materialMapRef.current.get(materialName);\r\n if (material && !Array.isArray(material)) {\r\n const mat = material as any;\r\n if (mat.color) {\r\n mat.color.copy(threeColor);\r\n mat.needsUpdate = true;\r\n }\r\n }\r\n }, []);\r\n\r\n /**\r\n * Get all material names in the scene\r\n */\r\n const getMaterialNames = useCallback(() => {\r\n return Array.from(materialMapRef.current.keys()).sort();\r\n }, []);\r\n\r\n /**\r\n * Get current color of a material\r\n * @returns Hex color string (e.g., \"#ff0000\")\r\n */\r\n const getMaterialColor = useCallback((materialName: string): string | null => {\r\n const material = materialMapRef.current.get(materialName);\r\n if (material && !Array.isArray(material)) {\r\n const mat = material as any;\r\n if (mat.color) {\r\n return '#' + mat.color.getHexString();\r\n }\r\n }\r\n return null;\r\n }, []);\r\n\r\n /**\r\n * Get all material colors\r\n * @returns Object mapping material names to hex colors\r\n */\r\n const getAllMaterialColors = useCallback((): Record<string, string> => {\r\n const colors: Record<string, string> = {};\r\n materialMapRef.current.forEach((material, name) => {\r\n if (!Array.isArray(material)) {\r\n const mat = material as any;\r\n if (mat.color) {\r\n colors[name] = '#' + mat.color.getHexString();\r\n }\r\n }\r\n });\r\n return colors;\r\n }, []);\r\n\r\n return {\r\n setMaterialColor,\r\n getMaterialNames,\r\n getMaterialColor,\r\n getAllMaterialColors,\r\n };\r\n}\r\n","import { useMemo } from 'react';\nimport { useGLTF } from '@react-three/drei';\nimport * as THREE from 'three';\nimport { useMeshVisibility } from '../../hooks/useMeshVisibility';\nimport { useMaterialColor } from '../../hooks/useMaterialColor';\nimport type { ModelProps } from '../../types';\n\n/**\n * Model - Simple 3D model component for loading and displaying GLB/GLTF files\n * \n * @remarks\n * This component:\n * - Loads GLB/GLTF models using drei's useGLTF hook\n * - Automatically clones the scene for independent instances\n * - Configures shadows on all meshes\n * - Supports position, rotation, and scale transforms\n * - Provides onLoad callback with model metadata\n * \n * @param url - URL or path to GLB/GLTF model file. Example: `\"/models/sword.glb\"`\n * @param position - Model position in 3D space as [x, y, z]. Example: `[0, 0, 0]`. Default: `[0, 0, 0]`\n * @param rotation - Model rotation in radians as [x, y, z]. Example: `[0, Math.PI/2, 0]`. Default: `[0, 0, 0]`\n * @param scale - Uniform scale (number) or per-axis scale [x, y, z]. Examples: `0.5` or `[1, 2, 1]`. Default: `1`\n * @param meshVisibility - Mesh visibility as key-value pairs. Example: `{ \"Part1\": true, \"Part2\": false }`\n * @param materialColors - Material colors as key-value pairs. Example: `{ \"MaterialName\": \"#ff0000\" }`\n * @param onLoad - Callback when model finishes loading. Receives ModelInfo object with metadata: `{ meshes, materials, bones, nodeCount }`\n * @param onError - Callback when model fails to load. Receives Error object\n * \n * @example\n * ```tsx\n * <Model \n * url=\"/models/sword.glb\"\n * position={[0, 0, 0]}\n * rotation={[0, Math.PI/2, 0]}\n * scale={0.5}\n * meshVisibility={{ \"Blade\": true, \"Handle\": false }}\n * onLoad={(info) => console.log('Loaded:', info)}\n * />\n * ```\n */\nexport function Model({\n url,\n position = [0, 0, 0],\n rotation = [0, 0, 0],\n scale = 1,\n meshVisibility,\n materialColors,\n onLoad,\n onError: _onError,\n}: ModelProps) {\n const { scene } = useGLTF(url);\n\n // Clone scene for independent instance\n const clonedScene = useMemo(() => {\n const clone = scene.clone();\n \n // Setup shadows and collect info\n const meshes: string[] = [];\n const materials = new Set<string>();\n const bones: string[] = [];\n let nodeCount = 0;\n\n clone.traverse((child) => {\n nodeCount++;\n \n if (child.type === 'Bone') {\n bones.push(child.name);\n }\n \n if ((child as THREE.Mesh).isMesh) {\n const mesh = child as THREE.Mesh;\n meshes.push(mesh.name);\n mesh.castShadow = true;\n mesh.receiveShadow = true;\n \n const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];\n mats.forEach((mat) => materials.add(mat.name));\n }\n });\n\n // Defer callback to avoid state update during render\n if (onLoad) {\n setTimeout(() => {\n onLoad({\n meshes: meshes.sort(),\n materials: Array.from(materials).sort(),\n bones: bones.sort(),\n nodeCount,\n });\n }, 0);\n }\n\n return clone;\n }, [scene, onLoad]);\n\n // Mesh visibility hook\n useMeshVisibility(clonedScene, meshVisibility);\n\n // Material colors hook\n useMaterialColor(clonedScene, materialColors);\n\n const scaleArray = typeof scale === 'number' ? [scale, scale, scale] : scale;\n\n return (\n <group position={position} rotation={rotation} scale={scaleArray as [number, number, number]}>\n <primitive object={clonedScene} />\n </group>\n );\n}\n\n// Preload helper\nModel.preload = (url: string) => {\n useGLTF.preload(url);\n};\n","import { useRef, useCallback, useEffect } from 'react';\r\nimport { useAnimations } from '@react-three/drei';\r\nimport * as THREE from 'three';\r\n\r\ninterface UseAnimationControllerOptions {\r\n defaultAnimation?: string;\r\n}\r\n\r\nexport function useAnimationController(\r\n animations: THREE.AnimationClip[],\r\n scene: THREE.Object3D,\r\n options?: UseAnimationControllerOptions\r\n) {\r\n const { actions, names } = useAnimations(animations, scene);\r\n const currentActionRef = useRef<THREE.AnimationAction | null>(null);\r\n const defaultAnimationRef = useRef<string | undefined>(options?.defaultAnimation);\r\n\r\n // Play default animation on mount\r\n useEffect(() => {\r\n if (names.length === 0) return;\r\n\r\n const defaultAnim = defaultAnimationRef.current;\r\n let animToPlay = names[0];\r\n\r\n if (defaultAnim) {\r\n const match = names.find((n) => n === defaultAnim || n.includes(defaultAnim));\r\n if (match) animToPlay = match;\r\n }\r\n\r\n const action = actions[animToPlay];\r\n if (action) {\r\n action.reset().fadeIn(0.5).play();\r\n currentActionRef.current = action;\r\n }\r\n }, [actions, names]);\r\n\r\n const playAnimation = useCallback(\r\n (\r\n name: string,\r\n opts?: {\r\n loop?: boolean;\r\n crossFadeDuration?: number;\r\n restoreDefault?: boolean;\r\n }\r\n ) => {\r\n const {\r\n loop = false,\r\n crossFadeDuration = 0.2,\r\n restoreDefault = true,\r\n } = opts || {};\r\n\r\n // Find animation (exact match or partial)\r\n let targetAction = actions[name];\r\n\r\n if (!targetAction) {\r\n const match = Object.keys(actions).find(\r\n (a) =>\r\n a.toLowerCase().includes(name.toLowerCase()) ||\r\n name.toLowerCase().includes(a.toLowerCase())\r\n );\r\n if (match) {\r\n targetAction = actions[match];\r\n }\r\n }\r\n\r\n if (!targetAction) {\r\n console.warn(`Animation \"${name}\" not found. Available: ${names.join(', ')}`);\r\n return;\r\n }\r\n\r\n // Don't restart if already playing\r\n const prev = currentActionRef.current;\r\n if (prev === targetAction && targetAction.isRunning()) {\r\n return;\r\n }\r\n\r\n // Crossfade from previous\r\n if (prev && prev !== targetAction) {\r\n prev.fadeOut(crossFadeDuration);\r\n }\r\n\r\n // Setup new action\r\n targetAction.reset();\r\n targetAction.fadeIn(crossFadeDuration);\r\n targetAction.setLoop(\r\n loop ? THREE.LoopRepeat : THREE.LoopOnce,\r\n loop ? Infinity : 1\r\n );\r\n targetAction.clampWhenFinished = !loop;\r\n targetAction.play();\r\n\r\n // Force immediate update for non-looping animations\r\n if (!loop) {\r\n targetAction.getMixer().update(0);\r\n }\r\n\r\n currentActionRef.current = targetAction;\r\n\r\n // Restore default animation after one-shot completes\r\n if (restoreDefault && !loop && defaultAnimationRef.current) {\r\n const mixer = targetAction.getMixer();\r\n const onFinished = (e: { action: THREE.AnimationAction }) => {\r\n if (e.action === targetAction) {\r\n mixer.removeEventListener('finished', onFinished);\r\n \r\n const defaultAction = actions[defaultAnimationRef.current!];\r\n if (defaultAction) {\r\n targetAction.fadeOut(crossFadeDuration);\r\n defaultAction.reset().fadeIn(crossFadeDuration).play();\r\n currentActionRef.current = defaultAction;\r\n }\r\n }\r\n };\r\n mixer.addEventListener('finished', onFinished);\r\n }\r\n },\r\n [actions, names]\r\n );\r\n\r\n const stopAnimation = useCallback(() => {\r\n currentActionRef.current?.fadeOut(0.2);\r\n currentActionRef.current = null;\r\n }, []);\r\n\r\n const getAnimationNames = useCallback(() => names, [names]);\r\n\r\n return {\r\n playAnimation,\r\n stopAnimation,\r\n getAnimationNames,\r\n actions,\r\n };\r\n}\r\n","import { useRef, useCallback, useEffect } from 'react';\r\nimport { useFrame } from '@react-three/fiber';\r\nimport * as THREE from 'three';\r\n\r\nexport function useMorphTargets(\r\n scene: THREE.Object3D,\r\n initialValues?: Record<string, number>\r\n) {\r\n const morphValuesRef = useRef<Record<string, number>>(initialValues || {});\r\n const morphNamesRef = useRef<string[]>([]);\r\n const meshesWithMorphsRef = useRef<THREE.Mesh[]>([]);\r\n\r\n // Discover morph targets\r\n useEffect(() => {\r\n const names = new Set<string>();\r\n const meshes: THREE.Mesh[] = [];\r\n\r\n scene.traverse((child) => {\r\n if (\r\n child instanceof THREE.Mesh &&\r\n child.morphTargetDictionary &&\r\n child.morphTargetInfluences\r\n ) {\r\n meshes.push(child);\r\n Object.keys(child.morphTargetDictionary).forEach((name) => {\r\n names.add(name);\r\n });\r\n }\r\n });\r\n\r\n morphNamesRef.current = Array.from(names).sort();\r\n meshesWithMorphsRef.current = meshes;\r\n }, [scene]);\r\n\r\n // Apply morph targets every frame\r\n useFrame(() => {\r\n const values = morphValuesRef.current;\r\n \r\n meshesWithMorphsRef.current.forEach((mesh) => {\r\n if (!mesh.morphTargetDictionary || !mesh.morphTargetInfluences) return;\r\n \r\n Object.entries(values).forEach(([name, value]) => {\r\n const index = mesh.morphTargetDictionary![name];\r\n if (index !== undefined) {\r\n mesh.morphTargetInfluences![index] = value;\r\n }\r\n });\r\n });\r\n });\r\n\r\n // Update values when props change\r\n useEffect(() => {\r\n if (initialValues) {\r\n morphValuesRef.current = { ...initialValues };\r\n }\r\n }, [initialValues]);\r\n\r\n const setMorphTarget = useCallback((name: string, value: number) => {\r\n morphValuesRef.current[name] = Math.max(0, Math.min(1, value));\r\n }, []);\r\n\r\n const getMorphTargetNames = useCallback(() => morphNamesRef.current, []);\r\n\r\n const getMorphTargetValues = useCallback(() => ({ ...morphValuesRef.current }), []);\r\n\r\n return {\r\n setMorphTarget,\r\n getMorphTargetNames,\r\n getMorphTargetValues,\r\n };\r\n}\r\n","import { createContext, useContext } from 'react';\r\nimport type { AnimatedModelContextValue } from '../../types';\r\n\r\nexport const AnimatedModelContext = createContext<AnimatedModelContextValue | null>(null);\r\n\r\nexport function useAnimatedModelContext() {\r\n const context = useContext(AnimatedModelContext);\r\n if (!context) {\r\n throw new Error('BoneAttachment must be used within an AnimatedModel');\r\n }\r\n return context;\r\n}\r\n","import {\n forwardRef,\n useImperativeHandle,\n useRef,\n useMemo,\n useEffect,\n} from 'react';\nimport * as THREE from 'three';\nimport { useGLTF } from '@react-three/drei';\nimport * as SkeletonUtils from 'three/examples/jsm/utils/SkeletonUtils.js';\nimport { useAnimationController } from '../../hooks/useAnimationController';\nimport { useMorphTargets } from '../../hooks/useMorphTargets';\nimport { useMeshVisibility } from '../../hooks/useMeshVisibility';\nimport { useMaterialColor } from '../../hooks/useMaterialColor';\nimport { AnimatedModelContext } from './AnimatedModelContext';\nimport type { AnimatedModelProps, AnimatedModelHandle } from '../../types';\n\n/**\n * AnimatedModel - 3D model with animation support and bone attachment capability\n * \n * @remarks\n * This component:\n * - Loads GLB/GLTF models with animations using useGLTF\n * - Properly clones skinned meshes using SkeletonUtils for multiple instances\n * - Plays animations with automatic crossfading\n * - Supports morph targets for character customization\n * - Provides context for BoneAttachment children\n * - Exposes imperative API via ref for external animation control\n * \n * The ref provides these methods:\n * - `playAnimation(name, options)` - Play an animation with optional loop/restore\n * - `stopAnimation()` - Stop current animation\n * - `getAnimationNames()` - Get list of available animations\n * - `getGroup()` - Get the THREE.Group for advanced manipulation\n * - `setMorphTarget(name, value)` - Set morph target value\n * - `getMorphTargetNames()` - Get available morph target names\n * \n * @param ref - React ref for imperative API access\n * @param url - URL or path to GLB/GLTF model file with animations. Example: `\"/models/character.glb\"`\n * @param position - Model position in 3D space as [x, y, z]. Example: `[0, -1, 0]`. Default: `[0, 0, 0]`\n * @param rotation - Model rotation in radians as [x, y, z]. Example: `[0, Math.PI, 0]`. Default: `[0, 0, 0]`\n * @param scale - Uniform scale (number) or per-axis scale [x, y, z]. Examples: `0.5` or `[1, 2, 1]`. Default: `1`\n * @param defaultAnimation - Name of animation to play on load. If not specified, plays first animation. Example: `\"Idle\"`\n * @param morphTargets - Morph target values as key-value pairs where value is 0-1. Example: `{ muscular: 0.5, thin: 0.2 }`\n * @param meshVisibility - Mesh visibility as key-value pairs. Example: `{ \"Hairgirl1\": true, \"Hairgirl2\": false }`\n * @param materialColors - Material colors as key-value pairs. Example: `{ \"Hair_girl_1\": \"#ff0000\" }`\n * @param children - Child components, typically BoneAttachment components for attaching items\n * @param onLoad - Callback when model loads. Receives AnimatedModelInfo object: `{ meshes, materials, bones, nodeCount, animations, morphTargetNames }`\n * @param onError - Callback when model fails to load. Receives Error object\n * \n * @example\n * ```tsx\n * const modelRef = useRef<AnimatedModelHandle>(null);\n * \n * <AnimatedModel\n * ref={modelRef}\n * url=\"/models/character.glb\"\n * defaultAnimation=\"Idle\"\n * morphTargets={{ muscular: 0.5 }}\n * meshVisibility={{ \"Hairgirl1\": true, \"Hairgirl2\": false }}\n * materialColors={{ \"Hair_girl_1\": \"#ff0000\" }}\n * position={[0, -1, 0]}\n * >\n * <BoneAttachment bone=\"hand_r\">\n * <Model url=\"/models/sword.glb\" />\n * </BoneAttachment>\n * </AnimatedModel>\n * \n * // Control animations from outside\n * modelRef.current?.playAnimation('Attack', { loop: false });\n * ```\n */\nexport const AnimatedModel = forwardRef<AnimatedModelHandle, AnimatedModelProps>(\n (\n {\n url,\n position = [0, 0, 0],\n rotation = [0, 0, 0],\n scale = 1,\n defaultAnimation,\n morphTargets,\n meshVisibility,\n materialColors,\n onLoad,\n onError: _onError,\n children,\n },\n ref\n ) => {\n const groupRef = useRef<THREE.Group>(null);\n const morphNamesRef = useRef<string[]>([]);\n\n // Load and clone model\n const { scene: gltfScene, animations } = useGLTF(url);\n const scene = useMemo(() => SkeletonUtils.clone(gltfScene), [gltfScene]);\n\n // Animation controller\n const { playAnimation, stopAnimation, getAnimationNames } = useAnimationController(\n animations,\n scene,\n { defaultAnimation }\n );\n\n // Morph targets\n const { setMorphTarget } = useMorphTargets(\n scene,\n morphTargets\n );\n\n // Mesh visibility\n const { setMeshVisibility, getMeshNames } = useMeshVisibility(\n scene,\n meshVisibility\n );\n\n // Material colors\n const { setMaterialColor, getMaterialNames, getMaterialColor } = useMaterialColor(\n scene,\n materialColors\n );\n\n // Discover morph targets and call onLoad\n useEffect(() => {\n if (!scene) return;\n\n const timer = setTimeout(() => {\n const bones: string[] = [];\n const meshes: string[] = [];\n const materials = new Set<string>();\n const morphNames = new Set<string>();\n let nodeCount = 0;\n\n scene.traverse((child) => {\n nodeCount++;\n \n if (child.type === 'Bone') {\n bones.push(child.name);\n }\n \n if ((child as THREE.Mesh).isMesh) {\n const mesh = child as THREE.Mesh;\n meshes.push(mesh.name);\n \n // Setup shadows\n mesh.castShadow = true;\n mesh.receiveShadow = true;\n \n const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];\n mats.forEach((mat) => {\n materials.add(mat.name);\n mat.shadowSide = THREE.DoubleSide;\n });\n\n if (mesh.morphTargetDictionary) {\n Object.keys(mesh.morphTargetDictionary).forEach((name) => {\n morphNames.add(name);\n });\n }\n }\n });\n\n morphNamesRef.current = Array.from(morphNames).sort();\n\n onLoad?.({\n meshes: meshes.sort(),\n materials: Array.from(materials).sort(),\n bones: bones.sort(),\n nodeCount,\n animations: animations.map((a) => a.name),\n morphTargetNames: morphNamesRef.current,\n });\n }, 0);\n\n return () => clearTimeout(timer);\n }, [scene, animations, onLoad]);\n\n // Expose imperative handle\n useImperativeHandle(ref, () => ({\n playAnimation,\n stopAnimation,\n getAnimationNames,\n getGroup: () => groupRef.current,\n setMorphTarget,\n getMorphTargetNames: () => morphNamesRef.current,\n setMeshVisibility,\n getMeshNames,\n setMaterialColor,\n getMaterialNames,\n getMaterialColor,\n }));\n\n // Context for BoneAttachment children\n const contextValue = useMemo(\n () => ({\n scene,\n getBone: (name: string) => scene.getObjectByName(name) || null,\n }),\n [scene]\n );\n\n const scaleArray = typeof scale === 'number' ? [scale, scale, scale] : scale;\n\n return (\n <AnimatedModelContext.Provider value={contextValue}>\n <group\n ref={groupRef}\n position={position}\n rotation={rotation}\n scale={scaleArray as [number, number, number]}\n >\n <primitive object={scene} />\n {children}\n </group>\n </AnimatedModelContext.Provider>\n );\n }\n);\n\nAnimatedModel.displayName = 'AnimatedModel';\n\n// Preload helper\n(AnimatedModel as any).preload = (url: string) => {\n useGLTF.preload(url);\n};\n","import { forwardRef, useImperativeHandle, useMemo, useEffect } from 'react';\nimport { useGLTF } from '@react-three/drei';\nimport * as THREE from 'three';\nimport { useMorphTargets } from '../../hooks/useMorphTargets';\nimport { useMeshVisibility } from '../../hooks/useMeshVisibility';\nimport { useMaterialColor } from '../../hooks/useMaterialColor';\nimport type { MorphableModelProps, MorphableModelHandle } from '../../types';\n\n/**\n * MorphableModel - 3D model with morph targets for shape customization\n * \n * @remarks\n * This component:\n * - Loads GLB/GLTF models with morph targets (blend shapes)\n * - Dynamically discovers available morph targets from the model\n * - Applies morph target values in real-time\n * - Provides imperative API via ref for programmatic control\n * \n * Morph targets are commonly used for:\n * - Character customization (muscular, thin, fat)\n * - Facial expressions (smile, frown, blink)\n * - Clothing fit adjustments\n * \n * @param ref - React ref for imperative API access\n * @param url - URL or path to GLB/GLTF model file with morph targets. Example: `\"/models/character.glb\"`\n * @param position - Model position in 3D space as [x, y, z]. Example: `[0, -1, 0]`. Default: `[0, 0, 0]`\n * @param rotation - Model rotation in radians as [x, y, z]. Example: `[0, Math.PI, 0]`. Default: `[0, 0, 0]`\n * @param scale - Uniform scale (number) or per-axis scale [x, y, z]. Examples: `0.5` or `[1, 2, 1]`. Default: `1`\n * @param morphTargets - Morph target values as key-value pairs where value is 0-1. Example: `{ muscular: 0.5, thin: 0.2 }`\n * @param meshVisibility - Mesh visibility as key-value pairs. Example: `{ \"Hairgirl1\": true, \"Hairgirl2\": false }`\n * @param materialColors - Material colors as key-value pairs. Example: `{ \"Hair_girl_1\": \"#ff0000\" }`\n * @param onMorphTargetsFound - Callback when morph targets are discovered from the model. Receives array of morph target names: `[\"muscular\", \"thin\", \"fat\"]`\n * @param onLoad - Callback when model finishes loading. Receives ModelInfo object with metadata: `{ meshes, materials, bones, nodeCount }`\n * @param onError - Callback when model fails to load. Receives Error object\n * \n * @example\n * ```tsx\n * const modelRef = useRef<MorphableModelHandle>(null);\n * const [morphs, setMorphs] = useState({ muscular: 0.5, thin: 0.2 });\n * \n * <MorphableModel\n * ref={modelRef}\n * url=\"/models/character.glb\"\n * morphTargets={morphs}\n * meshVisibility={{ \"Hairgirl1\": true, \"Hairgirl2\": false }}\n * onMorphTargetsFound={(names) => console.log('Available:', names)}\n * position={[0, -1, 0]}\n * />\n * \n * // Control programmatically\n * modelRef.current?.setMorphTarget('muscular', 0.8);\n * ```\n */\nexport const MorphableModel = forwardRef<MorphableModelHandle, MorphableModelProps>(\n (\n {\n url,\n position = [0, 0, 0],\n rotation = [0, 0, 0],\n scale = 1,\n morphTargets,\n meshVisibility,\n materialColors,\n onMorphTargetsFound,\n onLoad,\n onError: _onError,\n },\n ref\n ) => {\n const { scene } = useGLTF(url);\n\n // Clone scene\n const clonedScene = useMemo(() => scene.clone(), [scene]);\n\n // Morph targets hook\n const { setMorphTarget, getMorphTargetNames, getMorphTargetValues } = useMorphTargets(\n clonedScene,\n morphTargets\n );\n\n // Mesh visibility hook\n const { setMeshVisibility, getMeshNames } = useMeshVisibility(\n clonedScene,\n meshVisibility\n );\n\n // Material colors hook\n const { setMaterialColor, getMaterialNames, getMaterialColor } = useMaterialColor(\n clonedScene,\n materialColors\n );\n\n // Discover morph targets and notify\n useEffect(() => {\n const names = getMorphTargetNames();\n if (names.length > 0) {\n onMorphTargetsFound?.(names);\n }\n }, [clonedScene, getMorphTargetNames, onMorphTargetsFound]);\n\n // Setup shadows and call onLoad\n useEffect(() => {\n if (!clonedScene) return;\n\n const meshes: string[] = [];\n const materials = new Set<string>();\n const bones: string[] = [];\n let nodeCount = 0;\n\n clonedScene.traverse((child) => {\n nodeCount++;\n \n if (child.type === 'Bone') {\n bones.push(child.name);\n }\n \n if ((child as THREE.Mesh).isMesh) {\n const mesh = child as THREE.Mesh;\n meshes.push(mesh.name);\n mesh.castShadow = true;\n mesh.receiveShadow = true;\n \n const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];\n mats.forEach((mat) => materials.add(mat.name));\n }\n });\n\n onLoad?.({\n meshes: meshes.sort(),\n materials: Array.from(materials).sort(),\n bones: bones.sort(),\n nodeCount,\n });\n }, [clonedScene, onLoad]);\n\n // Expose handle\n useImperativeHandle(ref, () => ({\n setMorphTarget,\n getMorphTargetNames,\n getMorphTargetValues,\n setMeshVisibility,\n getMeshNames,\n setMaterialColor,\n getMaterialNames,\n getMaterialColor,\n }));\n\n const scaleArray = typeof scale === 'number' ? [scale, scale, scale] : scale;\n\n return (\n <group position={position} rotation={rotation} scale={scaleArray as [number, number, number]}>\n <primitive object={clonedScene} />\n </group>\n );\n }\n);\n\nMorphableModel.displayName = 'MorphableModel';\n","import { useState, useEffect } from 'react';\r\nimport { createPortal } from '@react-three/fiber';\r\nimport * as THREE from 'three';\r\nimport { useAnimatedModelContext } from '../AnimatedModel/AnimatedModelContext';\r\nimport type { BoneAttachmentProps } from '../../types';\r\n\r\n/**\r\n * BoneAttachment - Attach models to bones of an AnimatedModel parent\r\n * \r\n * @remarks\r\n * This component:\r\n * - Must be used as a child of AnimatedModel\r\n * - Uses React Three Fiber's createPortal to attach to a bone\r\n * - Automatically follows bone transformations during animations\r\n * - Supports position/rotation/scale offsets relative to the bone\r\n * \r\n * Common bone names:\r\n * - Hand bones: \"hand_r\", \"hand_l\", \"DEF-handR\", \"DEF-handL\"\r\n * - Spine/Back: \"spine\", \"spine_upper\", \"back\"\r\n * - Head: \"head\", \"neck\"\r\n * \r\n * @param children - Child components to attach to the bone (typically Model components)\r\n * @param bone - Bone name to attach to. Must match bone name in the parent AnimatedModel. Example: `\"hand_r\"` or `\"DEF-handR\"`\r\n * @param position - Position offset relative to the bone as [x, y, z]. Example: `[0.1, 0, 0]`. Default: `[0, 0, 0]`\r\n * @param rotation - Rotation offset relative to the bone in radians as [x, y, z]. Example: `[0, Math.PI/2, 0]`. Default: `[0, 0, 0]`\r\n * @param scale - Uniform scale (number) or per-axis scale [x, y, z]. Examples: `0.7` or `[1, 2, 1]`. Default: `1`\r\n * \r\n * @example\r\n * ```tsx\r\n * <AnimatedModel url=\"/character.glb\">\r\n * // Sword in right hand\r\n * <BoneAttachment \r\n * bone=\"hand_r\"\r\n * position={[0.1, 0, 0]}\r\n * rotation={[0, Math.PI/2, 0]}\r\n * >\r\n * <Model url=\"/sword.glb\" scale={0.7} />\r\n * </BoneAttachment>\r\n * \r\n * // Shield on back\r\n * <BoneAttachment bone=\"spine_upper\">\r\n * <Model url=\"/shield.glb\" />\r\n * </BoneAttachment>\r\n * </AnimatedModel>\r\n * ```\r\n */\r\nexport function BoneAttachment({\r\n children,\r\n bone,\r\n position = [0, 0, 0],\r\n rotation = [0, 0, 0],\r\n scale = 1,\r\n}: BoneAttachmentProps) {\r\n const { getBone } = useAnimatedModelContext();\r\n const [boneObject, setBoneObject] = useState<THREE.Object3D | null>(null);\r\n\r\n useEffect(() => {\r\n const found = getBone(bone);\r\n if (found) {\r\n setBoneObject(found);\r\n } else {\r\n console.warn(`Bone \"${bone}\" not found in model`);\r\n }\r\n }, [bone, getBone]);\r\n\r\n if (!boneObject) {\r\n return null;\r\n }\r\n\r\n const scaleArray = typeof scale === 'number' ? [scale, scale, scale] : scale;\r\n\r\n return createPortal(\r\n <group\r\n position={position}\r\n rotation={rotation}\r\n scale={scaleArray as [number, number, number]}\r\n >\r\n {children}\r\n </group>,\r\n boneObject\r\n );\r\n}\r\n","import { useMemo, useEffect } from 'react';\r\nimport { useGLTF } from '@react-three/drei';\r\nimport * as THREE from 'three';\r\nimport * as SkeletonUtils from 'three/examples/jsm/utils/SkeletonUtils.js';\r\nimport type { ModelInfo } from '../types';\r\n\r\ninterface UseClonedModelOptions {\r\n onLoad?: (info: ModelInfo) => void;\r\n onError?: (error: Error) => void;\r\n}\r\n\r\nexport function useClonedModel(url: string, options?: UseClonedModelOptions) {\r\n const { scene, animations } = useGLTF(url);\r\n \r\n // Clone scene using SkeletonUtils for proper skinned mesh handling\r\n const clonedScene = useMemo(() => {\r\n return SkeletonUtils.clone(scene);\r\n }, [scene]);\r\n\r\n // Extract model info and setup shadows\r\n useEffect(() => {\r\n if (!clonedScene) return;\r\n\r\n const bones: string[] = [];\r\n const meshes: string[] = [];\r\n const materials = new Set<string>();\r\n let nodeCount = 0;\r\n\r\n clonedScene.traverse((child) => {\r\n nodeCount++;\r\n \r\n if (child.type === 'Bone') {\r\n bones.push(child.name);\r\n }\r\n \r\n if ((child as THREE.Mesh).isMesh) {\r\n const mesh = child as THREE.Mesh;\r\n meshes.push(mesh.name);\r\n \r\n // Setup shadows\r\n mesh.castShadow = true;\r\n mesh.receiveShadow = true;\r\n \r\n // Collect material names\r\n const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];\r\n mats.forEach((mat) => {\r\n materials.add(mat.name);\r\n mat.shadowSide = THREE.DoubleSide;\r\n });\r\n }\r\n });\r\n\r\n options?.onLoad?.({\r\n meshes: meshes.sort(),\r\n materials: Array.from(materials).sort(),\r\n bones: bones.sort(),\r\n nodeCount,\r\n });\r\n }, [clonedScene, options]);\r\n\r\n return { scene: clonedScene, animations };\r\n}\r\n\r\n// Preload helper\r\nexport function preloadModel(url: string) {\r\n useGLTF.preload(url);\r\n}\r\n"],"names":["CameraController","position","controlsConfig","camera","useThree","controlsRef","useRef","useEffect","jsx","OrbitControls","Background","background","isColor","BackgroundImage","url","texture","useTexture","useMemo","THREE","Scene3D","children","controls","shadows","ambientIntensity","spotLight","contactShadows","style","className","cameraConfig","spotLightConfig","contactShadowsConfig","jsxs","Canvas","Suspense","ContactShadows","useMeshVisibility","scene","initialVisibility","meshMapRef","visibilityRef","meshMap","child","mesh","name","visible","useFrame","visibility","setMeshVisibility","useCallback","getMeshNames","getMeshVisibility","useMaterialColor","initialColors","materialMapRef","colorMapRef","materialMap","material","materialName","color","threeColor","parseColor","targetColor","mat","setMaterialColor","getMaterialNames","getMaterialColor","getAllMaterialColors","colors","Model","rotation","scale","meshVisibility","materialColors","onLoad","_onError","useGLTF","clonedScene","clone","meshes","materials","bones","nodeCount","scaleArray","useAnimationController","animations","options","actions","names","useAnimations","currentActionRef","defaultAnimationRef","defaultAnim","animToPlay","match","n","action","playAnimation","opts","loop","crossFadeDuration","restoreDefault","targetAction","a","prev","mixer","onFinished","e","defaultAction","stopAnimation","_a","getAnimationNames","useMorphTargets","initialValues","morphValuesRef","morphNamesRef","meshesWithMorphsRef","values","value","index","setMorphTarget","getMorphTargetNames","getMorphTargetValues","AnimatedModelContext","createContext","useAnimatedModelContext","context","useContext","AnimatedModel","forwardRef","defaultAnimation","morphTargets","ref","groupRef","gltfScene","SkeletonUtils","timer","morphNames","useImperativeHandle","contextValue","MorphableModel","onMorphTargetsFound","BoneAttachment","bone","getBone","boneObject","setBoneObject","useState","found","createPortal","useClonedModel","preloadModel"],"mappings":"kjBAUA,SAASA,GAAiB,CACxB,SAAAC,EACA,eAAAC,CACF,EAGG,CACD,KAAM,CAAE,OAAAC,CAAA,EAAWC,WAAA,EACbC,EAAcC,EAAAA,OAAiC,IAAI,EAEzDC,OAAAA,EAAAA,UAAU,IAAM,CACVN,GAAYE,IACdA,EAAO,SAAS,IAAIF,EAAS,CAAC,EAAGA,EAAS,CAAC,EAAGA,EAAS,CAAC,CAAC,EACzDE,EAAO,uBAAA,EAGHE,EAAY,UACdA,EAAY,QAAQ,OAAO,IAAI,EAAG,EAAG,CAAC,EACtCA,EAAY,QAAQ,OAAA,GAG1B,EAAG,CAACJ,EAAUE,CAAM,CAAC,EAGnBK,EAAAA,IAACC,EAAAA,cAAA,CACC,IAAKJ,EACL,YAAW,GACX,QAASH,EAAe,QACxB,UAAWA,EAAe,UAC1B,WAAYA,EAAe,WAC3B,aAAcA,EAAe,aAC7B,YAAaA,EAAe,YAC5B,YAAaA,EAAe,YAC5B,cAAeA,EAAe,cAC9B,cAAeA,EAAe,cAC9B,WAAYA,EAAe,WAC3B,gBAAiBA,EAAe,eAAA,CAAA,CAGtC,CAKA,SAASQ,GAAW,CAAE,WAAAC,GAAuC,CAE3D,MAAMC,EAAUD,GAAA,YAAAA,EAAY,WAAW,KAEvC,OAAKA,EAEDC,QACM,QAAA,CAAM,OAAO,aAAa,KAAM,CAACD,CAAU,EAAG,EAIjDH,EAAAA,IAACK,GA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