mbt-3d 0.4.9 → 0.4.11

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.
@@ -0,0 +1,166 @@
1
+ # Agent Examples
2
+
3
+ Use these examples when a consumer app needs package-level usage patterns for `mbt-3d`.
4
+
5
+ ## Basic Scene
6
+
7
+ ```tsx
8
+ import { Model, Scene3D } from 'mbt-3d';
9
+
10
+ function WeaponPreview({ modelUrl }: { modelUrl: string }) {
11
+ return (
12
+ <Scene3D
13
+ camera={{ position: [0, 1.5, 4], fov: 45 }}
14
+ style={{ width: 420, height: 420 }}
15
+ >
16
+ <Model url={modelUrl} />
17
+ </Scene3D>
18
+ );
19
+ }
20
+ ```
21
+
22
+ ## Scene With HDRI And Custom Lights
23
+
24
+ ```tsx
25
+ <Scene3D
26
+ camera={{ position: [0, 2, 5], fov: 45 }}
27
+ lights={[
28
+ { type: 'ambient', intensity: 0.35 },
29
+ {
30
+ type: 'spot',
31
+ position: [5, 8, 5],
32
+ intensity: 120,
33
+ castShadow: true,
34
+ shadowMapSize: 2048,
35
+ },
36
+ ]}
37
+ environment={{
38
+ files: '/hdri/studio.hdr',
39
+ intensity: 1.2,
40
+ blur: 0.15,
41
+ background: false,
42
+ }}
43
+ renderer={{
44
+ physicallyCorrectLights: true,
45
+ outputColorSpace: 'srgb',
46
+ toneMapping: 'ACESFilmicToneMapping',
47
+ toneMappingExposure: 1,
48
+ }}
49
+ style={{ width: 600, height: 800 }}
50
+ >
51
+ {children}
52
+ </Scene3D>
53
+ ```
54
+
55
+ ## Animated Character
56
+
57
+ ```tsx
58
+ import { AnimatedModel, Scene3D } from 'mbt-3d';
59
+
60
+ function CharacterPreview({ modelUrl }: { modelUrl: string }) {
61
+ return (
62
+ <Scene3D
63
+ camera={{ position: [0, 1.5, 4], fov: 45 }}
64
+ style={{ width: 500, height: 700 }}
65
+ >
66
+ <AnimatedModel
67
+ url={modelUrl}
68
+ defaultAnimation="Idle"
69
+ position={[0, -1, 0]}
70
+ />
71
+ </Scene3D>
72
+ );
73
+ }
74
+ ```
75
+
76
+ ## Bone Attachment
77
+
78
+ ```tsx
79
+ import { AnimatedModel, BoneAttachment, Model } from 'mbt-3d';
80
+
81
+ <AnimatedModel url={characterUrl} defaultAnimation="Idle">
82
+ <BoneAttachment bone="hand_r">
83
+ <Model url={weaponUrl} scale={0.7} />
84
+ </BoneAttachment>
85
+ </AnimatedModel>;
86
+ ```
87
+
88
+ ## Morph Targets
89
+
90
+ ```tsx
91
+ import { MorphableModel } from 'mbt-3d';
92
+
93
+ <MorphableModel
94
+ url={characterUrl}
95
+ morphTargets={{
96
+ muscular: 0.5,
97
+ thin: 0.2,
98
+ }}
99
+ />;
100
+ ```
101
+
102
+ ## Imperative Animation Control
103
+
104
+ ```tsx
105
+ import { AnimatedModel } from 'mbt-3d';
106
+ import { useRef } from 'react';
107
+ import type { AnimatedModelHandle } from 'mbt-3d';
108
+
109
+ const characterRef = useRef<AnimatedModelHandle>(null);
110
+
111
+ <AnimatedModel ref={characterRef} url={characterUrl} defaultAnimation="Idle" />;
112
+
113
+ characterRef.current?.playAnimation('Attack', { loop: false });
114
+ ```
115
+
116
+ ## Advanced Hook
117
+
118
+ ```tsx
119
+ import { preloadModel } from 'mbt-3d';
120
+
121
+ void preloadModel(modelUrl);
122
+ ```
123
+
124
+ ## Texture Preload
125
+
126
+ ```tsx
127
+ import { preloadTextures } from 'mbt-3d';
128
+
129
+ preloadTextures({
130
+ Metal: {
131
+ map: resolvedMetalMap,
132
+ normalMap: resolvedMetalNormalMap,
133
+ },
134
+ });
135
+ ```
136
+
137
+ ## Multiple Character Slots
138
+
139
+ ```tsx
140
+ <Scene3D
141
+ camera={{ position: [0, 2, 8] }}
142
+ background="#1a1a2e"
143
+ style={{ width: '100%', height: '100vh' }}
144
+ >
145
+ <AnimatedModel
146
+ url={heroAUrl}
147
+ defaultAnimation="Idle"
148
+ position={[-2, -1, 0]}
149
+ />
150
+
151
+ <AnimatedModel url={heroBUrl} defaultAnimation="Idle" position={[0, -1, 0]}>
152
+ <BoneAttachment bone="hand_r">
153
+ <Model url={swordUrl} />
154
+ </BoneAttachment>
155
+ </AnimatedModel>
156
+
157
+ <AnimatedModel url={heroCUrl} defaultAnimation="Idle" position={[2, -1, 0]} />
158
+ </Scene3D>
159
+ ```
160
+
161
+ ## Important Notes
162
+
163
+ - These examples assume the consumer has already resolved or prepared the asset URL.
164
+ - Consumer-specific CDN resolution, local asset servers, and preload orchestration belong in the consumer app docs, not in `mbt-3d`.
165
+ - Prefer package-level examples here over demo-only repo paths like `/models/...` when writing guidance for consumers.
166
+ - Supported source assets are GLB/GLTF, with embedded animations or morph targets when the consumer needs those features.
@@ -0,0 +1,74 @@
1
+ # Agent Reference
2
+
3
+ This folder holds factual package reference for `mbt-3d`.
4
+
5
+ ## Public Components
6
+
7
+ - `Scene3D`
8
+ - `Model`
9
+ - `AnimatedModel`
10
+ - `MorphableModel`
11
+ - `BoneAttachment`
12
+
13
+ ## Advanced Hooks
14
+
15
+ - `useClonedModel`
16
+ - `preloadModel`
17
+ - `useAnimationController`
18
+ - `useMorphTargets`
19
+ - `useMeshVisibility`
20
+ - `useMaterialColor`
21
+ - `useMaterialTexture`
22
+ - `preloadTextures`
23
+ - `useEyeAnimation`
24
+
25
+ ## Exported Types
26
+
27
+ - `Scene3DProps`
28
+ - `RendererConfig`
29
+ - `ToneMappingMode`
30
+ - `ModelProps`
31
+ - `ModelInfo`
32
+ - `AnimatedModelProps`
33
+ - `AnimatedModelInfo`
34
+ - `AnimatedModelHandle`
35
+ - `AnimatedModelAnimationMask`
36
+ - `AnimatedModelAnimationLayer`
37
+ - `AnimatedModelAnimationLayerInput`
38
+ - `MorphableModelProps`
39
+ - `MorphableModelHandle`
40
+ - `BoneAttachmentProps`
41
+ - `MaterialTextures`
42
+
43
+ ## Peer Dependencies
44
+
45
+ - `react`
46
+ - `react-dom`
47
+ - `three`
48
+ - `@react-three/fiber`
49
+ - `@react-three/drei`
50
+
51
+ ## Important Public Patterns
52
+
53
+ - `Scene3D` supports `lights`, `environment`, and `renderer` together.
54
+ - `Scene3D` preserves camera state while the same scene stays mounted.
55
+ - `AnimatedModel` supports controlled animation, layered animation, morph targets, and `BoneAttachment` children.
56
+ - `AnimatedModel` auto-plays the first available animation when `defaultAnimation` is omitted.
57
+ - `AnimatedModelHandle.playAnimation()` uses matching logic that can resolve partial animation names.
58
+ - `MorphableModel` exposes morph target discovery and imperative morph updates through its handle.
59
+ - `BoneAttachment` expects a real bone name from the animated parent model.
60
+
61
+ ## Model Requirements
62
+
63
+ - Source assets must be GLB or GLTF.
64
+ - Embedded animations must be present in the model file for `AnimatedModel` behavior.
65
+ - Morph targets must exist in the source asset for `MorphableModel` features.
66
+ - Bone names must exist in the model for `BoneAttachment` to work.
67
+
68
+ ## Common Bone Name Families
69
+
70
+ - Blender Rigify: `DEF-handR`, `DEF-handL`, `DEF-spine`
71
+ - Mixamo: `RightHand`, `LeftHand`, `Spine`
72
+ - Custom rigs: `hand_r`, `hand_l`, `spine_upper`
73
+
74
+ Reference docs should stay factual. Policy and maintenance rules belong in `.ai/agent-rules/`.
@@ -0,0 +1,50 @@
1
+ # Agent Rules
2
+
3
+ These files are the canonical package-owned rules for `mbt-3d`.
4
+
5
+ ## Rule Map
6
+
7
+ - `.ai/agent-rules/README.md` - normative usage rules for exported components and hooks.
8
+ - `.ai/agent-rules/maintenance.md` - required rule for keeping package docs in sync with public changes.
9
+
10
+ ## Usage Rules
11
+
12
+ - Prefer higher-level exported components before using lower-level hooks directly.
13
+ - Use `Scene3D` as the normal scene container for package consumers.
14
+ - Use `Model` for static models, `AnimatedModel` for animation-capable models, and `MorphableModel` when morph targets are required.
15
+ - Use `BoneAttachment` only as a child of `AnimatedModel`.
16
+ - Pass ready-to-use asset URLs into package components; asset downloading, path resolution, and cache orchestration are consumer concerns.
17
+ - Prefer stable props and memoized configuration objects when scenes become configuration-heavy.
18
+ - Use advanced hooks only when the consumer truly needs lower-level control.
19
+ - Use `pnpm` as the package manager for this repo and keep a single lockfile.
20
+
21
+ ## Boundaries
22
+
23
+ - This package owns scene and model behavior.
24
+ - Consumer apps own where assets come from, how remote URLs are resolved, and when app-specific preload flows run.
25
+ - Do not put app-owned IPC, CDN, asset-server, or resolver workflow rules into package docs.
26
+
27
+ ## Scene Guidance
28
+
29
+ - `Scene3D` supports mixed lighting through `lights` and `environment` together.
30
+ - `Scene3D` preserves camera state between model changes inside the same mounted scene.
31
+ - Keep `renderer`, `lights`, and `controls` props stable when a consumer already memoizes or stores them outside render.
32
+ - Prefer explicit camera and control configuration in examples instead of relying on implicit defaults when teaching usage.
33
+
34
+ ## Model Guidance
35
+
36
+ - Resolve model and texture URLs before rendering a component when the asset source is external or dynamic.
37
+ - Use `Model.preload()` or `preloadModel()` only when the consumer already has a real preload step.
38
+ - Use `preloadTextures()` only when the consumer already has a preload stage and texture URLs are known before render.
39
+ - For texture-driven materials, resolve model and texture data together before render to avoid mixed old/new asset states.
40
+
41
+ ## Animation Guidance
42
+
43
+ - If `AnimatedModel.defaultAnimation` is omitted, the library falls back to the first available animation.
44
+ - `playAnimation(name)` uses name matching that tolerates partial or case-insensitive matches when possible.
45
+ - Prefer explicit animation names in consumer code even though partial matching exists.
46
+
47
+ ## Bone Guidance
48
+
49
+ - Match bone names to the actual model data; do not guess names.
50
+ - Common families include custom names like `hand_r`, Mixamo-style names like `RightHand`, and Rigify-style names like `DEF-handR`.
@@ -0,0 +1,22 @@
1
+ # Maintenance Rule
2
+
3
+ Agents working in `mbt-3d` must review and update package guidance whenever a change affects public behavior.
4
+
5
+ ## Update The Docs When
6
+
7
+ - exported components, hooks, or types change
8
+ - component props or defaults change
9
+ - animation control expectations change
10
+ - morph-target usage changes
11
+ - attachment behavior changes
12
+ - environment, lighting, or renderer configuration changes
13
+ - canonical examples need to change to stay correct
14
+
15
+ ## Required Files To Review
16
+
17
+ - `AGENTS.md`
18
+ - `.ai/agent-rules/README.md`
19
+ - `.ai/agent-reference/README.md`
20
+ - `.ai/agent-examples/README.md`
21
+
22
+ Do not finish public package work without reviewing these files.
package/AGENTS.md ADDED
@@ -0,0 +1,36 @@
1
+ # AGENTS.md
2
+
3
+ ## Purpose
4
+
5
+ - `mbt-3d` is the shared React package for 3D scenes, models, animations, morph targets, and bone attachments.
6
+ - This repo owns the canonical agent guidance for package usage.
7
+ - Consumer apps should read the installed package docs from `node_modules/mbt-3d/...`.
8
+
9
+ ## Package Name
10
+
11
+ - npm package: `mbt-3d`
12
+
13
+ ## Read This First
14
+
15
+ 1. `.ai/agent-rules/README.md`
16
+ 2. `.ai/agent-rules/maintenance.md`
17
+ 3. `.ai/agent-reference/README.md`
18
+ 4. `.ai/agent-examples/README.md`
19
+
20
+ ## Guidance Map
21
+
22
+ - `.ai/agent-rules/README.md` - package-owned usage rules and boundaries.
23
+ - `.ai/agent-rules/maintenance.md` - required doc-sync rule.
24
+ - `.ai/agent-reference/README.md` - exported surfaces and peer dependency map.
25
+ - `.ai/agent-examples/README.md` - package-safe usage examples.
26
+
27
+ ## Maintenance Rule
28
+
29
+ - If a change affects exported components, props, hooks, types, or expected usage patterns, update the guidance docs before considering the work complete.
30
+
31
+ ## Guardrails
32
+
33
+ - Keep package docs focused on public library behavior.
34
+ - Consumer-specific asset downloading, CDN resolution, or preload orchestration rules belong in the consumer app, not here.
35
+ - Prefer package-safe examples over repo-demo-only examples.
36
+ - Use `pnpm` as the package manager for this repo.
package/README.md CHANGED
@@ -1,56 +1,67 @@
1
- # mbt-3d
2
-
3
- React components for 3D character viewing with animations and morph targets.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install mbt-3d
9
- ```
10
-
11
- ### Peer Dependencies
12
-
13
- ```bash
14
- npm install react react-dom three @react-three/fiber @react-three/drei
15
- ```
16
-
17
- ## Requirements
18
-
19
- - React >= 18.0.0
20
- - Three.js >= 0.150.0
21
- - @react-three/fiber >= 8.0.0
22
- - @react-three/drei >= 9.0.0
23
-
1
+ # mbt-3d
2
+
3
+ React components for 3D character viewing with animations and morph targets.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add mbt-3d
9
+ ```
10
+
11
+ ## Agent Guidance
12
+
13
+ - `AGENTS.md` is the package entrypoint for coding agents.
14
+ - Canonical rules live in `.ai/agent-rules/`.
15
+ - Factual reference lives in `.ai/agent-reference/`.
16
+ - Package-safe examples live in `.ai/agent-examples/`.
17
+
18
+ ### Peer Dependencies
19
+
20
+ ```bash
21
+ pnpm add react react-dom three @react-three/fiber @react-three/drei
22
+ ```
23
+
24
+ ## Requirements
25
+
26
+ - React >= 18.0.0
27
+ - Three.js >= 0.150.0
28
+ - @react-three/fiber >= 8.0.0
29
+ - @react-three/drei >= 9.0.0
30
+
24
31
  ## Local Development
25
-
26
- For local development and testing with another project:
27
-
28
- **1. Link the library:**
29
- ```bash
30
- # In mbt-3d directory
31
- npm link
32
-
33
- # Start watch mode for auto-rebuild on changes
34
- npm run build:lib:watch
35
- ```
36
-
37
- **2. Use in your project:**
38
- ```bash
39
- # In your project directory
40
- npm link mbt-3d
41
- ```
42
-
43
- **3. When done, unlink:**
44
- ```bash
45
- # In your project directory
46
- npm unlink mbt-3d
47
-
48
- # In mbt-3d directory
49
- npm unlink
50
- ```
51
-
52
- **Alternative: Use file: protocol**
53
- ```json
32
+
33
+ For local development and testing with another project:
34
+
35
+ **1. Link the library:**
36
+
37
+ ```bash
38
+ # In mbt-3d directory
39
+ pnpm link --global
40
+
41
+ # Start watch mode for auto-rebuild on changes
42
+ pnpm build:lib:watch
43
+ ```
44
+
45
+ **2. Use in your project:**
46
+
47
+ ```bash
48
+ # In your project directory
49
+ pnpm link --global mbt-3d
50
+ ```
51
+
52
+ **3. When done, unlink:**
53
+
54
+ ```bash
55
+ # In your project directory
56
+ pnpm unlink --global mbt-3d
57
+
58
+ # In mbt-3d directory
59
+ pnpm unlink --global
60
+ ```
61
+
62
+ **Alternative: Use file: protocol**
63
+
64
+ ```json
54
65
  {
55
66
  "dependencies": {
56
67
  "mbt-3d": "file:../path/to/mbt-3d"
@@ -58,6 +69,8 @@ npm unlink
58
69
  }
59
70
  ```
60
71
 
72
+ This repo standardizes on `pnpm` only.
73
+
61
74
  ## Lighting and HDRI
62
75
 
63
76
  `Scene3D` supports mixed lighting:
@@ -72,19 +85,25 @@ npm unlink
72
85
  <Scene3D
73
86
  lights={[
74
87
  { type: 'ambient', intensity: 0.4 },
75
- { type: 'spot', position: [5, 8, 5], intensity: 120, castShadow: true, shadowMapSize: 2048 }
88
+ {
89
+ type: 'spot',
90
+ position: [5, 8, 5],
91
+ intensity: 120,
92
+ castShadow: true,
93
+ shadowMapSize: 2048,
94
+ },
76
95
  ]}
77
96
  environment={{
78
97
  files: '/hdri/studio.hdr',
79
98
  intensity: 1.2,
80
99
  blur: 0.15,
81
- background: false
100
+ background: false,
82
101
  }}
83
102
  renderer={{
84
103
  physicallyCorrectLights: true,
85
104
  outputColorSpace: 'srgb',
86
105
  toneMapping: 'ACESFilmicToneMapping',
87
- toneMappingExposure: 1
106
+ toneMappingExposure: 1,
88
107
  }}
89
108
  >
90
109
  {children}
package/dist/index.d.ts CHANGED
@@ -458,7 +458,7 @@ declare interface MaterialTextures_2 {
458
458
  * />
459
459
  * ```
460
460
  */
461
- export declare function Model({ url, position, rotation, scale, meshVisibility, materialColors, materialTextures, materialTextureLogging, onLoad, onError: _onError, }: ModelProps): JSX_2.Element;
461
+ export declare function Model({ url, position, rotation, scale, meshVisibility, materialColors, materialTextures, materialTextureLogging, onLoad, onTexturesLoaded, onError: _onError, }: ModelProps): JSX_2.Element;
462
462
 
463
463
  export declare namespace Model {
464
464
  var preload: (url: string) => void;
@@ -512,6 +512,8 @@ export declare interface ModelProps {
512
512
  onLoad?: (info: ModelInfo) => void;
513
513
  /** Callback when model fails to load */
514
514
  onError?: (error: Error) => void;
515
+ /** Callback when textures have finished loading and applying */
516
+ onTexturesLoaded?: () => void;
515
517
  }
516
518
 
517
519
  /**
@@ -927,7 +929,7 @@ declare interface UseClonedModelOptions {
927
929
  /**
928
930
  * Animates eye bones to follow the mouse cursor.
929
931
  *
930
- * @param scene - The THREE.Group scene containing the eye bones
932
+ * @param scene - The THREE.Object3D scene subtree containing the eye bones
931
933
  * @param eyeNames - Names of eye bone objects to animate. Pass an empty array to disable.
932
934
  *
933
935
  * @example
@@ -973,6 +975,10 @@ declare interface UseMaterialTextureOptions {
973
975
  * Enable verbose texture lifecycle logs (disabled by default).
974
976
  */
975
977
  enableLogging?: boolean;
978
+ /**
979
+ * Callback fired when all textures for the material have finished downloading and applying.
980
+ */
981
+ onTexturesLoaded?: () => void;
976
982
  }
977
983
 
978
984
  /**