Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / avatar / AGENTS.md
| 1 | # AGENTS.md — library/avatar/ (':library:avatar') |
| 2 | |
| 3 | > Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `library/avatar/` + allowed shared modules. Do not root-scan. |
| 4 | |
| 5 | _Install: dev by default (library, no launcher)._ |
| 6 | - Gradle: :library:avatar / dir: library/avatar/ |
| 7 | - Package roots present: `com.vayunmathur.library.avatar` (bridge), `...avatar.components` (surface/composable), `...avatar.yuu` (pose contract) |
| 8 | - Entry files: YuuAvatarNative.kt (JNI bridge), components/YuuAvatar3D.kt (hero composable) |
| 9 | - Deps: :library:ui (permission-free), :library:log, androidx.lifecycle.runtime.compose |
| 10 | - Rust: yes (`src/main/rust/`, crate `yuu_avatar`, glTF + skinning) |
| 11 | - Metadata: none (library, no listing) |
| 12 | |
| 13 | ## Overview |
| 14 | **Purpose:** Shared 3D Yuu avatar engine: glTF upper-body base mesh, skeletal skinning, preset poses, Vulkan-first + GLES fallback. First consumer: `:games:hub` hero surfaces; future 3D games reuse the same bridge. |
| 15 | **Key features:** 13-joint upper-body rig, 5 preset poses, per-surface multi-renderer engine, procedural fallback mesh, turntable preview camera. |
| 16 | **Architecture:** Rust crate (`src/main/rust/`: `avatar.rs` skeleton/traits/poses → `engine.rs` per-surface lifecycle → `renderer.rs` dispatch → `vulkan/` + `gles/`) ↔ JNI (`YuuAvatarNative`, `internal object`, package matches directory) ↔ Compose (`YuuAvatar3D` + `YuuAvatarSurfaceView`). |
| 17 | **Entry points:** `YuuAvatar3D(configJson, poseId, surfaceId, modifier, fallback)` → `YuuAvatarNative` → Rust `lib.rs`. |
| 18 | ## Gotchas |
| 19 | - Rust `preset_poses` is authoritative; `yuu/YuuPose.kt` `YUU_POSES` is the hand-kept mirror — update both. |
| 20 | - Vulkan `new()` brings up the swapchain; GLES is the fallback via `Renderer::select`. Layoutlib can't render either — previews must be 2D/HUD-only. |
| 21 | - Surface ids are Kotlin-owned ints; the engine routes config/pose/lifecycle per id. Dispose must call `surfaceDestroyed(id)`. |
| 22 | |
| 23 | ## Base mesh asset (`src/main/assets/models/base_upperbody.glb`) |
| 24 | - Handoff: `YuuAvatarAssets.adoptBundledMesh` (detached fd, `noCompress ".glb"`) |
| 25 | → `nativeSetBundledMesh` → `Engine::set_bundled_mesh` → parsed on next |
| 26 | surface creation. Absent asset keeps the procedural fallback. |
| 27 | - Authoring contract: ~13–15 joints named per `joint_name()` in `avatar.rs` |
| 28 | (`root/spine/chest/neck/head`, `clavicle_L/R`, `upperArm_L/R`, |
| 29 | `forearm_L/R`, `hand_L/R`); 4-weight skinning (`JOINTS_0`/`WEIGHTS_0` |
| 30 | required); distinct `glasses` / `beard` / hair nodes for attachments; 2K |
| 31 | albedo honoring the skin `[0,.25]` / shirt `[.5,1]` UV split from `mesh.rs`; |
| 32 | ≤65536 verts (tighter cap for grid cells). |
| 33 | |
| 34 | ## Key files |
| 35 | ### Kotlin — bridge + surface |
| 36 | - com/vayunmathur/library/avatar/YuuAvatarNative.kt |
| 37 | - com/vayunmathur/library/avatar/components/YuuAvatarSurfaceView.kt |
| 38 | - com/vayunmathur/library/avatar/components/YuuAvatar3D.kt |
| 39 | - com/vayunmathur/library/avatar/yuu/YuuPose.kt |
| 40 | ### Rust — engine crate (see src/main/rust/AGENTS.md for the skeleton contract) |
| 41 | - src/main/rust/src/avatar.rs — joints, traits, poses, FK (tests in `avatar_tests.rs` / `avatar_tests_extra.rs`, same `avatar::tests` / `avatar::tests_extra` modules via `#[path]`) |
| 42 | - src/main/rust/src/engine.rs — per-surface lifecycle + camera |
| 43 | - src/main/rust/src/mesh.rs — procedural fallback + glTF loader |
| 44 | - src/main/rust/src/lib.rs — JNI entry points |
| 45 | - src/main/rust/src/vulkan/ + src/main/rust/src/gles/ — backends |
| 46 | |
| 47 | ## Verify (this module only) |
| 48 | ``` |
| 49 | ./gradlew :library:avatar:compileDevKotlin |
| 50 | ./gradlew :library:avatar:lint |
| 51 | ``` |
| 52 | Plus `cargo test -p yuu_avatar` in `src/main/rust/`. |