Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
cov/c3 ▾

Modern-Apps.git / library / avatar / AGENTS.md

AGENTS.md3.4 KiBRenderedCodeRaw
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<!-- last-reviewed: 2026-10-19 -->
7- Gradle: :library:avatar / dir: library/avatar/
8- Package roots present: `com.vayunmathur.library.avatar` (bridge), `...avatar.components` (surface/composable), `...avatar.yuu` (pose contract)
9- Entry files: YuuAvatarNative.kt (JNI bridge), components/YuuAvatar3D.kt (hero composable)
10- Deps: :library:ui (permission-free since #884), :library:log, androidx.lifecycle.runtime.compose
11- Rust: yes (`src/main/rust/`, crate `yuu_avatar`, glTF + skinning)
12- Metadata: none (library, no listing)
13
14## Overview
15**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.
16**Key features:** 13-joint upper-body rig, 5 preset poses, per-surface multi-renderer engine, procedural fallback mesh, turntable preview camera.
17**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`).
18**Entry points:** `YuuAvatar3D(configJson, poseId, surfaceId, modifier, fallback)` → `YuuAvatarNative` → Rust `lib.rs`.
19## Gotchas
20- Rust `preset_poses` is authoritative; `yuu/YuuPose.kt` `YUU_POSES` is the hand-kept mirror — update both.
21- Vulkan `new()` brings up the swapchain; GLES is the fallback via `Renderer::select`. Layoutlib can't render either — previews must be 2D/HUD-only.
22- Surface ids are Kotlin-owned ints; the engine routes config/pose/lifecycle per id. Dispose must call `surfaceDestroyed(id)`.
23
24## Base mesh asset (`src/main/assets/models/base_upperbody.glb`)
25- Handoff: `YuuAvatarAssets.adoptBundledMesh` (detached fd, `noCompress ".glb"`)
26 → `nativeSetBundledMesh` → `Engine::set_bundled_mesh` → parsed on next
27 surface creation. Absent asset keeps the procedural fallback.
28- Authoring contract: ~13–15 joints named per `joint_name()` in `avatar.rs`
29 (`root/spine/chest/neck/head`, `clavicle_L/R`, `upperArm_L/R`,
30 `forearm_L/R`, `hand_L/R`); 4-weight skinning (`JOINTS_0`/`WEIGHTS_0`
31 required); distinct `glasses` / `beard` / hair nodes for attachments; 2K
32 albedo honoring the skin `[0,.25]` / shirt `[.5,1]` UV split from `mesh.rs`;
33 ≤65536 verts (tighter cap for grid cells).
34
35## Key files
36### Kotlin — bridge + surface
37- com/vayunmathur/library/avatar/YuuAvatarNative.kt
38- com/vayunmathur/library/avatar/components/YuuAvatarSurfaceView.kt
39- com/vayunmathur/library/avatar/components/YuuAvatar3D.kt
40- com/vayunmathur/library/avatar/yuu/YuuPose.kt
41### Rust — engine crate (see src/main/rust/AGENTS.md for the skeleton contract)
42- src/main/rust/src/avatar.rs — joints, traits, poses, FK
43- src/main/rust/src/engine.rs — per-surface lifecycle + camera
44- src/main/rust/src/mesh.rs — procedural fallback + glTF loader
45- src/main/rust/src/lib.rs — JNI entry points
46- src/main/rust/src/vulkan/ + src/main/rust/src/gles/ — backends
47
48## Verify (this module only)
49```
50./gradlew :library:avatar:compileDevKotlin
51./gradlew :library:avatar:lint
52```
53Plus `cargo test -p yuu_avatar` in `src/main/rust/`.