avatar: fix skinning bind pose, Mali-safe joints, brighter light, framing
- Commit
307f0a2ed24f364d6d2cc51b906e8836c738f816- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-20 00:02 UTC (1 month ago)
- Parents
7632534
Diff
games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/YuuEditorScreen.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/YuuEditorScreen.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/YuuEditorScreen.ktindex 6c4d2b6276..faed004cd7 100644--- a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/YuuEditorScreen.kt+++ b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/YuuEditorScreen.kt@@ -126,7 +126,7 @@ fun YuuEditorScreen( YuuFace( config = draft.toConfig(), withBody = true,- modifier = Modifier.fillMaxWidth(0.72f).aspectRatio(0.9f).padding(8.dp),+ modifier = Modifier.fillMaxSize(), ) }, )@@ -689,3 +689,4 @@ private fun ExtrasPanel(d: YuuDraft) { } } }+
games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/YuuScreen.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/YuuScreen.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/YuuScreen.ktindex 3bf0f0aaf7..64fd481554 100644--- a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/YuuScreen.kt+++ b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/YuuScreen.kt@@ -132,7 +132,7 @@ private fun YuuCard( fallback = { YuuFace( config = yuu.config,- modifier = Modifier.fillMaxWidth().aspectRatio(1f),+ modifier = Modifier.fillMaxSize(), ) }, )@@ -186,3 +186,4 @@ private fun YuuCard( } } }+
library/avatar/src/main/rust/build.rs
diff --git a/library/avatar/src/main/rust/build.rs b/library/avatar/src/main/rust/build.rsindex 3715758f03..c71dd43550 100644--- a/library/avatar/src/main/rust/build.rs+++ b/library/avatar/src/main/rust/build.rs@@ -95,6 +95,29 @@ fn find_glslc() -> Option<PathBuf> { ] { candidates.push(PathBuf::from(mac_linux)); }+ // Common Windows SDK locations (local.properties is Gradle-only; cargo+ // builds outside Gradle need these or they silently fall to the minimal+ // SPV stub — which Mali drivers SIGSEGV parsing).+ for windows_sdk in [+ "C:\\Android\\Sdk",+ "C:\\Users\\Vayun\\AppData\\Local\\Android\\Sdk",+ ] {+ for tag in ["windows-x86_64", "linux-x86_64", "darwin-x86_64"] {+ if let Ok(ndk_dir) = std::fs::read_dir(PathBuf::from(windows_sdk).join("ndk")) {+ let mut versions: Vec<_> = ndk_dir.filter_map(|e| e.ok().map(|e| e.path())).collect();+ versions.sort();+ for ndk in versions.iter().rev() {+ candidates.push(+ ndk.join("shader-tools").join(tag).join(if tag.starts_with("windows") {+ "glslc.exe"+ } else {+ "glslc"+ }),+ );+ }+ }+ }+ } for c in candidates { if c.exists() { return Some(c);
library/avatar/src/main/rust/shaders/yuu_avatar.frag
diff --git a/library/avatar/src/main/rust/shaders/yuu_avatar.frag b/library/avatar/src/main/rust/shaders/yuu_avatar.fragindex 9233398c53..1d1bc386bb 100644--- a/library/avatar/src/main/rust/shaders/yuu_avatar.frag+++ b/library/avatar/src/main/rust/shaders/yuu_avatar.frag@@ -23,9 +23,12 @@ void main() { vec3 albedoCol = texture(albedo, vUv).rgb; vec3 n = normalize(vNormal); vec3 sun = normalize(ubo.sunDir);+ // Front faces get little direct sun (sun points down-back), so carry them+ // with a strong hemisphere ambient + fill — heroes must read brightly+ // from the turntable's front view. float ndl = clamp(dot(n, -sun), 0.0, 1.0);- float fill = 0.45 + 0.25 * clamp(n.y * 0.5 + 0.5, 0.0, 1.0);- vec3 col = albedoCol * (0.35 + 0.65 * ndl) * fill + albedoCol * 0.12;+ float hemi = 0.65 + 0.35 * clamp(n.y * 0.5 + 0.5, 0.0, 1.0);+ vec3 col = albedoCol * (0.55 + 0.45 * ndl) * hemi + albedoCol * 0.25; float dist = length(vWorld - ubo.camPos); float fog = 1.0 - exp(-dist * 0.02); outColor = vec4(mix(col, SKY, clamp(fog, 0.0, 1.0)), 1.0);
library/avatar/src/main/rust/shaders/yuu_avatar.frag.spv
diff --git a/library/avatar/src/main/rust/shaders/yuu_avatar.frag.spv b/library/avatar/src/main/rust/shaders/yuu_avatar.frag.spvindex d27f8d838e..0246464f28 100644Binary files a/library/avatar/src/main/rust/shaders/yuu_avatar.frag.spv and b/library/avatar/src/main/rust/shaders/yuu_avatar.frag.spv differ
library/avatar/src/main/rust/shaders/yuu_avatar.vert
diff --git a/library/avatar/src/main/rust/shaders/yuu_avatar.vert b/library/avatar/src/main/rust/shaders/yuu_avatar.vertindex 0de9803813..a1e4f0ef17 100644--- a/library/avatar/src/main/rust/shaders/yuu_avatar.vert+++ b/library/avatar/src/main/rust/shaders/yuu_avatar.vert@@ -2,10 +2,15 @@ // Skinned Yuu avatar vertex shader: 4-bone linear-blend skinning against the // bone-matrix UBO, then the shared view-projection. Matches YuuVkVertex // locations 0..4 in vulkan/buffers.rs.+//+// NOTE(Mali): joints arrive as vec4, NOT uvec4 — the Mali SPIR-V frontend+// SIGSEGVs parsing integer vertex inputs (fault inside vkCreateGraphics-+// Pipelines, uncatchable). int() conversion at index time is exact for our+// small joint ids. layout(location = 0) in vec3 inPos; layout(location = 1) in vec3 inNormal; layout(location = 2) in vec2 inUv;-layout(location = 3) in uvec4 inJoints;+layout(location = 3) in vec4 inJoints; layout(location = 4) in vec4 inWeights; layout(location = 0) out vec3 vNormal;@@ -21,10 +26,10 @@ layout(set = 0, binding = 0) uniform Ubo { void main() { mat4 skin =- inWeights.x * ubo.bones[inJoints.x] +- inWeights.y * ubo.bones[inJoints.y] +- inWeights.z * ubo.bones[inJoints.z] +- inWeights.w * ubo.bones[inJoints.w];+ inWeights.x * ubo.bones[int(inJoints.x)] ++ inWeights.y * ubo.bones[int(inJoints.y)] ++ inWeights.z * ubo.bones[int(inJoints.z)] ++ inWeights.w * ubo.bones[int(inJoints.w)]; vec4 world = skin * vec4(inPos, 1.0); vWorld = world.xyz; vNormal = normalize(mat3(skin) * inNormal);
library/avatar/src/main/rust/shaders/yuu_avatar.vert.spv
diff --git a/library/avatar/src/main/rust/shaders/yuu_avatar.vert.spv b/library/avatar/src/main/rust/shaders/yuu_avatar.vert.spvindex 9f20d208d4..6fea242e2f 100644Binary files a/library/avatar/src/main/rust/shaders/yuu_avatar.vert.spv and b/library/avatar/src/main/rust/shaders/yuu_avatar.vert.spv differ
library/avatar/src/main/rust/shaders/yuu_avatar_gles.frag
diff --git a/library/avatar/src/main/rust/shaders/yuu_avatar_gles.frag b/library/avatar/src/main/rust/shaders/yuu_avatar_gles.fragindex 5628967f70..139dd7650e 100644--- a/library/avatar/src/main/rust/shaders/yuu_avatar_gles.frag+++ b/library/avatar/src/main/rust/shaders/yuu_avatar_gles.frag@@ -22,8 +22,8 @@ void main() { vec3 n = normalize(vNormal); vec3 sun = normalize(uSunDir); float ndl = clamp(dot(n, -sun), 0.0, 1.0);- float fill = 0.45 + 0.25 * clamp(n.y * 0.5 + 0.5, 0.0, 1.0);- vec3 col = albedoCol * (0.35 + 0.65 * ndl) * fill + albedoCol * 0.12;+ float hemi = 0.65 + 0.35 * clamp(n.y * 0.5 + 0.5, 0.0, 1.0);+ vec3 col = albedoCol * (0.55 + 0.45 * ndl) * hemi + albedoCol * 0.25; float dist = length(vWorld - uCamPos); float fog = 1.0 - exp(-dist * 0.02); outColor = vec4(mix(col, SKY, clamp(fog, 0.0, 1.0)), 1.0);
library/avatar/src/main/rust/shaders/yuu_avatar_gles.vert
diff --git a/library/avatar/src/main/rust/shaders/yuu_avatar_gles.vert b/library/avatar/src/main/rust/shaders/yuu_avatar_gles.vertindex a1666207cf..a0bf309838 100644--- a/library/avatar/src/main/rust/shaders/yuu_avatar_gles.vert+++ b/library/avatar/src/main/rust/shaders/yuu_avatar_gles.vert@@ -3,10 +3,12 @@ // 4-bone linear-blend skinning against the uBones array, then the shared // view-projection. The Vulkan `clip.y` flip is removed — OpenGL NDC Y already // points up — so winding stays as authored (cull off either way).+// NOTE(Mali): joints are vec4 (see yuu_avatar.vert) — integer attributes+// crash Mali drivers. layout(location = 0) in vec3 inPos; layout(location = 1) in vec3 inNormal; layout(location = 2) in vec2 inUv;-layout(location = 3) in uvec4 inJoints;+layout(location = 3) in vec4 inJoints; layout(location = 4) in vec4 inWeights; out vec3 vNormal;@@ -18,10 +20,10 @@ uniform mat4 uBones[32]; void main() { mat4 skin =- inWeights.x * uBones[inJoints.x] +- inWeights.y * uBones[inJoints.y] +- inWeights.z * uBones[inJoints.z] +- inWeights.w * uBones[inJoints.w];+ inWeights.x * uBones[int(inJoints.x)] ++ inWeights.y * uBones[int(inJoints.y)] ++ inWeights.z * uBones[int(inJoints.z)] ++ inWeights.w * uBones[int(inJoints.w)]; vec4 world = skin * vec4(inPos, 1.0); vWorld = world.xyz; vNormal = normalize(mat3(skin) * inNormal);
library/avatar/src/main/rust/src/avatar.rs
diff --git a/library/avatar/src/main/rust/src/avatar.rs b/library/avatar/src/main/rust/src/avatar.rsindex d4215eaa84..f0ebc02034 100644--- a/library/avatar/src/main/rust/src/avatar.rs+++ b/library/avatar/src/main/rust/src/avatar.rs@@ -1,18 +1,18 @@-//! Yuu avatar model: joint hierarchy, trait mapping, preset poses.+//! Yuu avatar model: joint hierarchy, trait mapping, forward kinematics. //! //! The skeleton is the v1 upper-body rig: `root -> spine -> chest -> neck -> //! head`, plus `clavicle_L/R -> upperArm -> forearm -> hand` on each side //! (~13 joints, no hips/legs/feet). Joint order here is the bone-matrix UBO //! order, so it must match the skinning shader's `bones[]` indexing. //!-//! Trait mapping from `YuuFaceConfig` JSON is coarse by design (see the plan):-//! skin tone tints the material, body height/weight scale bones, face shape-//! scales the head, style indices pick attachment/texture variants, and-//! mole/wrinkle/blush are v1-skipped.+//! Poses live in [`crate::pose`]. Trait mapping from `YuuFaceConfig` JSON is+//! coarse by design (see the plan): skin tone tints the material, body+//! height/weight scale bones, face shape scales the head, style indices pick+//! attachment/texture variants, and mole/wrinkle/blush are v1-skipped. +use crate::pose::{JointRotation, YuuPose}; use glam::{Mat4, Quat, Vec3}; use serde::{Deserialize, Serialize};-use std::collections::HashMap; /// Bone-matrix UBO capacity: 13 v1 joints fit with headroom for attachments. pub const MAX_BONES: usize = 32;@@ -126,50 +126,7 @@ pub const ALL_JOINTS: [Joint; JOINT_COUNT] = [ Joint::HandR, ]; -/// Serializable joint rotation (Euler degrees, XYZ order) for one joint.-#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]-pub struct JointRotation {- /// Pitch degrees.- #[serde(default)]- pub x: f32,- /// Yaw degrees.- #[serde(default)]- pub y: f32,- /// Roll degrees.- #[serde(default)]- pub z: f32,-}--impl JointRotation {- /// Identity rotation.- pub const fn identity() -> Self {- Self { x: 0.0, y: 0.0, z: 0.0 }- }-- /// Convert to a quaternion.- pub fn to_quat(self) -> Quat {- Quat::from_euler(- glam::EulerRot::XYZ,- self.x.to_radians(),- self.y.to_radians(),- self.z.to_radians(),- )- }-}--/// A named preset pose: per-joint rotations over the rest pose.-#[derive(Clone, Debug, Serialize, Deserialize)]-pub struct YuuPose {- /// Stable id (matches the Kotlin `poseId`).- pub id: String,- /// Display name.- pub name: String,- /// Joint rotations; joints absent from the map stay at rest.- #[serde(default)]- pub joints: HashMap<String, JointRotation>,-}--/// Joint name key used in [`YuuPose::joints`].+/// Joint name key used in pose joint maps. pub fn joint_name(joint: Joint) -> &'static str { match joint { Joint::Root => "root",@@ -193,70 +150,6 @@ pub fn joint_by_name(name: &str) -> Option<Joint> { ALL_JOINTS.iter().copied().find(|j| joint_name(*j) == name) } -/// Preset gallery ids, in gallery order.-pub const POSE_IDLE: &str = "idle";-/// Friendly wave with the right hand.-pub const POSE_WAVE: &str = "wave";-/// Right-hand thumbs-up.-pub const POSE_THUMBS_UP: &str = "thumbs_up";-/// Chin resting on the right hand.-pub const POSE_THINKING: &str = "thinking";-/// Both arms raised in celebration.-pub const POSE_CHEERING: &str = "cheering";--/// Build the v1 preset gallery.-pub fn preset_poses() -> Vec<YuuPose> {- vec![- YuuPose { id: POSE_IDLE.into(), name: "Idle".into(), joints: HashMap::new() },- YuuPose {- id: POSE_WAVE.into(),- name: "Wave".into(),- joints: HashMap::from([- ("upperArm_R".into(), JointRotation { x: 0.0, y: 0.0, z: -140.0 }),- ("forearm_R".into(), JointRotation { x: 0.0, y: 0.0, z: -20.0 }),- ("hand_R".into(), JointRotation { x: 0.0, y: 25.0, z: 0.0 }),- ("head".into(), JointRotation { x: 0.0, y: -8.0, z: 4.0 }),- ]),- },- YuuPose {- id: POSE_THUMBS_UP.into(),- name: "Thumbs up".into(),- joints: HashMap::from([- ("upperArm_R".into(), JointRotation { x: -50.0, y: 0.0, z: -30.0 }),- ("forearm_R".into(), JointRotation { x: -40.0, y: 0.0, z: 0.0 }),- ("hand_R".into(), JointRotation { x: -10.0, y: 0.0, z: 90.0 }),- ("head".into(), JointRotation { x: -4.0, y: 0.0, z: 0.0 }),- ]),- },- YuuPose {- id: POSE_THINKING.into(),- name: "Thinking".into(),- joints: HashMap::from([- ("upperArm_R".into(), JointRotation { x: -30.0, y: 0.0, z: -45.0 }),- ("forearm_R".into(), JointRotation { x: -95.0, y: 0.0, z: 15.0 }),- ("hand_R".into(), JointRotation { x: -20.0, y: 0.0, z: 0.0 }),- ("head".into(), JointRotation { x: 8.0, y: 12.0, z: -6.0 }),- ]),- },- YuuPose {- id: POSE_CHEERING.into(),- name: "Cheering".into(),- joints: HashMap::from([- ("upperArm_L".into(), JointRotation { x: 0.0, y: 0.0, z: 140.0 }),- ("forearm_L".into(), JointRotation { x: 0.0, y: 0.0, z: 20.0 }),- ("upperArm_R".into(), JointRotation { x: 0.0, y: 0.0, z: -140.0 }),- ("forearm_R".into(), JointRotation { x: 0.0, y: 0.0, z: -20.0 }),- ("head".into(), JointRotation { x: -10.0, y: 0.0, z: 0.0 }),- ]),- },- ]-}--/// Find a preset by id.-pub fn preset_by_id(id: &str) -> Option<YuuPose> {- preset_poses().into_iter().find(|p| p.id == id)-}- /// Coarse trait mapping from `YuuFaceConfig` JSON. /// /// Only the fields that affect the 3D body are read here; face-detail fields@@ -358,8 +251,12 @@ fn argb_to_rgb(argb: u64, fallback: [f32; 3]) -> [f32; 3] { /// /// Applies trait scales (height on spine/chest, weight on chest/arms, head /// scale on head), then forward kinematics through [`ALL_JOINTS`]. Output is-/// `MAX_BONES` matrices; unused slots are identity.+/// `MAX_BONES` skinning matrices (`world * inverse_bind`): mesh vertices are+/// authored in model space, so each bone must first un-apply its rest pose+/// before applying the posed transform — without the inverse bind, parts+/// render scattered/exploded (double-transformed). pub fn compute_bone_matrices(traits: &YuuTraits, pose: &YuuPose, time_s: f32) -> [Mat4; MAX_BONES] {+ let inverse_bind = rest_world_matrices(); let mut out = [Mat4::IDENTITY; MAX_BONES]; // Gentle idle sway on the root so heroes never look frozen. let sway = (time_s * 1.2).sin() * 0.02;@@ -412,7 +309,42 @@ pub fn compute_bone_matrices(traits: &YuuTraits, pose: &YuuPose, time_s: f32) -> if ji != usize::MAX { world[ji] = parent_world * local; }- out[joint as usize] = parent_world * local;+ // Skinning matrix: un-apply the rest pose, then apply the posed world+ // transform. Vertices are authored in model space.+ out[joint as usize] = parent_world * local * inverse_bind[joint as usize];+ }+ out+}++/// Inverse bind-pose matrices: inverse of each joint's rest-pose world matrix+/// (identity rotations, unit scales, unscaled offsets). Precomputed per call+/// (13 joints — negligible) so `compute_bone_matrices` stays pure.+fn rest_world_matrices() -> [Mat4; MAX_BONES] {+ let mut world = [Mat4::IDENTITY; JOINT_COUNT];+ for joint in ALL_JOINTS.iter().copied() {+ let local = Mat4::from_translation(rest_offset(joint));+ let parent_world = match parent_of(joint) {+ Some(p) => {+ let pi = ALL_JOINTS.iter().position(|jj| *jj == p).unwrap_or(usize::MAX);+ if pi == usize::MAX {+ Mat4::IDENTITY+ } else {+ world[pi]+ }+ }+ None => Mat4::IDENTITY,+ };+ let ji = ALL_JOINTS.iter().position(|jj| *jj == joint).unwrap_or(usize::MAX);+ if ji != usize::MAX {+ world[ji] = parent_world * local;+ }+ }+ let mut out = [Mat4::IDENTITY; MAX_BONES];+ for joint in ALL_JOINTS.iter().copied() {+ let ji = ALL_JOINTS.iter().position(|jj| *jj == joint).unwrap_or(usize::MAX);+ if ji != usize::MAX {+ out[joint as usize] = world[ji].inverse();+ } } out }@@ -420,6 +352,8 @@ pub fn compute_bone_matrices(traits: &YuuTraits, pose: &YuuPose, time_s: f32) -> #[cfg(test)] mod tests { use super::*;+ use crate::pose::YuuPose;+ use std::collections::HashMap; #[test] fn skeleton_order_is_topological() {@@ -441,6 +375,25 @@ mod tests { assert!(t.length() < 1e-5); } + #[test]+ fn idle_bones_hold_model_space_points() {+ // Regression: bone matrices must include the inverse bind pose, so an+ // idle skeleton leaves model-space vertices where authored. (Without+ // it, every part renders double-transformed — scattered/exploded.)+ let traits = YuuTraits::default();+ let pose = YuuPose { id: "idle".into(), name: "Idle".into(), joints: HashMap::new() };+ let bones = compute_bone_matrices(&traits, &pose, 0.0);+ // Head-center vertex (bound fully to head) must stay at its authored+ // position under the idle pose.+ let head_m = bones[Joint::Head as usize];+ let p = head_m.transform_point3(glam::Vec3::new(0.0, 1.28, 0.0));+ assert!((p - glam::Vec3::new(0.0, 1.28, 0.0)).length() < 1e-3, "head drifted to {p:?}");+ // Hand-center vertex (bound fully to hand) likewise.+ let hand_m = bones[Joint::HandR as usize];+ let q = hand_m.transform_point3(glam::Vec3::new(0.31, 0.34, 0.0));+ assert!((q - glam::Vec3::new(0.31, 0.34, 0.0)).length() < 1e-3, "hand drifted to {q:?}");+ }+ #[test] fn traits_parse_leniently() { let t = YuuTraits::from_config_json("{}");@@ -449,3 +402,4 @@ mod tests { assert_eq!(bad.body_height, 0.5); } }+
library/avatar/src/main/rust/src/engine.rs
diff --git a/library/avatar/src/main/rust/src/engine.rs b/library/avatar/src/main/rust/src/engine.rsindex 3d041522a4..cc92ecf87f 100644--- a/library/avatar/src/main/rust/src/engine.rs+++ b/library/avatar/src/main/rust/src/engine.rs@@ -6,7 +6,8 @@ //! GPU buffers + UBO/pose stay per-surface. The render threads tick here; //! [`tick_surface`] uploads the bone-matrix UBO and draws one surface per call. -use crate::avatar::{compute_bone_matrices, preset_by_id, preset_poses, YuuPose, YuuTraits, MAX_BONES};+use crate::avatar::{compute_bone_matrices, YuuTraits, MAX_BONES};+use crate::pose::{preset_by_id, preset_poses, YuuPose}; use crate::mesh::{build_avatar_mesh, load_gltf_mesh, YuuVertex}; use crate::renderer::Renderer; use glam::Mat4;@@ -204,12 +205,14 @@ fn android_log(_msg: &str) {} pub fn view_proj_for(width: u32, height: u32, time_s: f32) -> ([[f32; 4]; 4], [f32; 3]) { let aspect = width.max(1) as f32 / height.max(1) as f32; let angle = time_s * 0.25;- let radius = 2.6;- let eye = glam::Vec3::new(angle.sin() * radius, 1.15, angle.cos() * radius);- let center = glam::Vec3::new(0.0, 0.85, 0.0);+ // Framing: avatar spans y 0.47..1.43 (~1m); radius 3.4 + 44° FOV keeps+ // the head inside small square surfaces (plaza cells, badges) with margin.+ let radius = 3.4;+ let eye = glam::Vec3::new(angle.sin() * radius, 1.25, angle.cos() * radius);+ let center = glam::Vec3::new(0.0, 0.9, 0.0); let up = glam::Vec3::Y; let view = Mat4::look_at_rh(eye, center, up);- let proj = Mat4::perspective_rh_gl(38.0f32.to_radians(), aspect, 0.1, 20.0);+ let proj = Mat4::perspective_rh_gl(44.0f32.to_radians(), aspect, 0.1, 20.0); let view_proj = proj * view; (view_proj.to_cols_array_2d(), eye.to_array()) }
library/avatar/src/main/rust/src/gles/buffers.rs
diff --git a/library/avatar/src/main/rust/src/gles/buffers.rs b/library/avatar/src/main/rust/src/gles/buffers.rsindex ee7279aec6..2f696dcf9e 100644--- a/library/avatar/src/main/rust/src/gles/buffers.rs+++ b/library/avatar/src/main/rust/src/gles/buffers.rs@@ -43,7 +43,7 @@ impl MeshBuffer { unsafe { gl.bind_vertex_array(Some(vao)); gl.bind_buffer(glow::ARRAY_BUFFER, Some(vbo));- // pos@0 (3f) + normal@1 (3f) + uv@2 (2f) + joints@3 (4u) + weights@4 (4f).+ // pos@0 (3f) + normal@1 (3f) + uv@2 (2f) + joints@3 (4f) + weights@4 (4f). gl.enable_vertex_attrib_array(0); gl.vertex_attrib_pointer_f32(0, 3, glow::FLOAT, false, stride, off_pos); gl.enable_vertex_attrib_array(1);@@ -51,7 +51,7 @@ impl MeshBuffer { gl.enable_vertex_attrib_array(2); gl.vertex_attrib_pointer_f32(2, 2, glow::FLOAT, false, stride, off_uv); gl.enable_vertex_attrib_array(3);- gl.vertex_attrib_pointer_i32(3, 4, glow::UNSIGNED_INT, stride, off_joints);+ gl.vertex_attrib_pointer_f32(3, 4, glow::FLOAT, false, stride, off_joints); gl.enable_vertex_attrib_array(4); gl.vertex_attrib_pointer_f32(4, 4, glow::FLOAT, false, stride, off_weights); gl.bind_buffer(glow::ARRAY_BUFFER, None);
library/avatar/src/main/rust/src/lib.rs
diff --git a/library/avatar/src/main/rust/src/lib.rs b/library/avatar/src/main/rust/src/lib.rsindex 3437a6ce6d..4873e5f2c1 100644--- a/library/avatar/src/main/rust/src/lib.rs+++ b/library/avatar/src/main/rust/src/lib.rs@@ -9,6 +9,7 @@ pub mod avatar; pub mod engine; pub mod gles; pub mod mesh;+pub mod pose; pub mod renderer; pub mod vulkan; @@ -109,7 +110,7 @@ pub extern "system" fn Java_com_vayunmathur_library_avatar_YuuAvatarNative_nativ } #[cfg(not(target_os = "android"))] {- let _ = (env, surface);+ let _ = (env, surface, surface_id); } } @@ -209,7 +210,7 @@ pub extern "system" fn Java_com_vayunmathur_library_avatar_YuuAvatarNative_nativ _class: JClass<'l>, ) -> jstring { let json = serde_json::to_string(- &avatar::preset_poses().iter().map(|p| &p.id).collect::<Vec<_>>(),+ &pose::preset_poses().iter().map(|p| &p.id).collect::<Vec<_>>(), ) .unwrap_or_else(|_| "[]".to_string()); env.with_env(|env| -> jni::errors::Result<jstring> {@@ -239,7 +240,7 @@ mod tests { fn engine_smoke() { let mesh = build_avatar_mesh(); assert!(!mesh.is_empty());- let poses = crate::avatar::preset_poses();+ let poses = crate::pose::preset_poses(); assert!(poses.iter().any(|p| p.id == "wave")); } @@ -258,3 +259,4 @@ mod tests { } } +
library/avatar/src/main/rust/src/mesh.rs
diff --git a/library/avatar/src/main/rust/src/mesh.rs b/library/avatar/src/main/rust/src/mesh.rsindex 3bf6be6c03..1b510039bc 100644--- a/library/avatar/src/main/rust/src/mesh.rs+++ b/library/avatar/src/main/rust/src/mesh.rs@@ -9,6 +9,10 @@ use crate::avatar::{joint_by_name, ALL_JOINTS, JOINT_COUNT}; /// One skinned vertex. Matches `yuu_avatar.vert` locations 0..4.+///+/// NOTE(Mali): `joints` is `[f32; 4]`, not `[u32; 4]` — integer vertex+/// attributes crash the Mali SPIR-V frontend (see the shader note). Exact+/// for our small joint ids; converted with `int()` in-shader. #[derive(Clone, Copy, Debug, Default)] #[repr(C)] pub struct YuuVertex {@@ -18,8 +22,8 @@ pub struct YuuVertex { pub normal: [f32; 3], /// Albedo UV. pub uv: [f32; 2],- /// Bone indices into the UBO order.- pub joints: [u32; 4],+ /// Bone indices into the UBO order (as floats — see note above).+ pub joints: [f32; 4], /// Bone weights (normalized). pub weights: [f32; 4], }@@ -31,9 +35,9 @@ struct Part { /// Full size of the box. size: [f32; 3], /// Primary bone index.- joint: u32,+ joint: f32, /// Secondary bone index (blends toward the parent at the seam).- blend_joint: u32,+ blend_joint: f32, /// Blend factor 0..1 toward the secondary bone. blend: f32, /// Skin-tone albedo flag (true = skin, false = shirt).@@ -75,7 +79,7 @@ fn box_skinned(out: &mut Vec<YuuVertex>, part: &Part) { pos: c[idx[k]], normal, uv: if part.skin { [uvs[uv_idx[k]][0] * 0.25, uvs[uv_idx[k]][1] * 0.25] } else { [0.5 + uvs[uv_idx[k]][0] * 0.5, uvs[uv_idx[k]][1] * 0.5] },- joints: [part.joint, part.blend_joint, 0, 0],+ joints: [part.joint, part.blend_joint, 0.0, 0.0], weights: [w0, part.blend, 0.0, 0.0], }); }@@ -83,8 +87,8 @@ fn box_skinned(out: &mut Vec<YuuVertex>, part: &Part) { } /// Joint index helper by name (0 when unknown — weighted to root).-fn j(name: &str) -> u32 {- joint_by_name(name).map(|jj| jj as u32).unwrap_or(0)+fn j(name: &str) -> f32 {+ joint_by_name(name).map(|jj| jj as u32 as f32).unwrap_or(0.0) } /// Build the procedural fallback upper-body mesh bound to the v1 skeleton.@@ -156,8 +160,9 @@ fn parse_gltf(bytes: &[u8]) -> Option<Vec<YuuVertex>> { let weights_raw: Vec<[f32; 4]> = reader.read_weights(0).map(|it| it.into_f32().collect()).unwrap_or_default(); // Skin-joint-slot -> UBO order remap via node names. JOINTS_0 indexes // `skin.joints` (an indirection into nodes), NOT global node order, so- // resolve through the skin's joint list.- let mut remap = vec![0u32; 256];+ // resolve through the skin's joint list. Stored as floats (Mali note on+ // `YuuVertex::joints`).+ let mut remap = vec![0.0f32; 256]; if let Some(skin) = doc.skins().next() { for (slot, node) in skin.joints().enumerate() { if slot >= remap.len() {@@ -165,7 +170,7 @@ fn parse_gltf(bytes: &[u8]) -> Option<Vec<YuuVertex>> { } if let Some(name) = node.name() { if let Some(jj) = joint_by_name(name) {- remap[slot] = jj as u32;+ remap[slot] = jj as u32 as f32; } } }@@ -179,10 +184,10 @@ fn parse_gltf(bytes: &[u8]) -> Option<Vec<YuuVertex>> { normal: *normals.get(i).unwrap_or(&[0.0, 1.0, 0.0]), uv: *uvs.get(i).unwrap_or(&[0.0, 0.0]), joints: [- *remap.get(js[0] as usize).unwrap_or(&0),- *remap.get(js[1] as usize).unwrap_or(&0),- *remap.get(js[2] as usize).unwrap_or(&0),- *remap.get(js[3] as usize).unwrap_or(&0),+ *remap.get(js[0] as usize).unwrap_or(&0.0),+ *remap.get(js[1] as usize).unwrap_or(&0.0),+ *remap.get(js[2] as usize).unwrap_or(&0.0),+ *remap.get(js[3] as usize).unwrap_or(&0.0), ], weights: ws, });@@ -247,4 +252,46 @@ mod tests { let mesh = load_gltf_mesh(b"not a glb"); assert!(!mesh.is_empty()); }++ #[test]+ fn wave_pose_lifts_right_hand() {+ // End-to-end CPU skinning: mesh verts x bone matrices must move the+ // waving hand UP. Catches FK/weight/remap breakage that unit tests on+ // bones alone would miss.+ use crate::avatar::{compute_bone_matrices, YuuTraits};+ use crate::pose::preset_by_id;+ use glam::Vec3;+ let mesh = build_avatar_mesh();+ let traits = YuuTraits::default();+ let wave = preset_by_id("wave").expect("wave preset");+ let bones = compute_bone_matrices(&traits, &wave, 0.0);+ // Skin the hand-box verts (fully hand-weighted region near x=0.31).+ let mut hand_max_y = f32::MIN;+ let mut hand_count = 0;+ for v in &mesh {+ // Hand verts: authored near the right hand center.+ let dx = v.pos[0] - 0.31;+ let dy = v.pos[1] - 0.34;+ let dz = v.pos[2];+ if dx.abs() < 0.06 && dy.abs() < 0.06 && dz.abs() < 0.06 {+ let p = Vec3::from_array(v.pos);+ let mut skinned = Vec3::ZERO;+ for k in 0..4 {+ let j = v.joints[k] as usize;+ let w = v.weights[k];+ if w > 0.0 && j < 32 {+ let m = glam::Mat4::from_cols_array_2d(&bones[j].to_cols_array_2d());+ skinned += (m * glam::Vec4::new(p.x, p.y, p.z, 1.0)).truncate() * w;+ }+ }+ hand_max_y = hand_max_y.max(skinned.y);+ hand_count += 1;+ }+ }+ assert!(hand_count > 0, "no hand verts found");+ assert!(+ hand_max_y > 1.0,+ "waving hand should rise above y=1.0, got max {hand_max_y}"+ );+ } }
library/avatar/src/main/rust/src/pose.rs
diff --git a/library/avatar/src/main/rust/src/pose.rs b/library/avatar/src/main/rust/src/pose.rsnew file mode 100644index 0000000000..9a061169ac--- /dev/null+++ b/library/avatar/src/main/rust/src/pose.rs@@ -0,0 +1,116 @@+//! Preset 3D poses: joint rotations over the rest skeleton.+//!+//! Split from `avatar.rs` along module lines (repo `rustFileLength` gate).+//! The engine owns the authoritative preset list; the Kotlin gallery mirrors+//! it (`YUU_POSES` — update both).++use glam::Quat;+use serde::{Deserialize, Serialize};+use std::collections::HashMap;++/// Serializable joint rotation (Euler degrees, XYZ order) for one joint.+#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]+pub struct JointRotation {+ /// Pitch degrees.+ #[serde(default)]+ pub x: f32,+ /// Yaw degrees.+ #[serde(default)]+ pub y: f32,+ /// Roll degrees.+ #[serde(default)]+ pub z: f32,+}++impl JointRotation {+ /// Identity rotation.+ pub const fn identity() -> Self {+ Self { x: 0.0, y: 0.0, z: 0.0 }+ }++ /// Convert to a quaternion.+ pub fn to_quat(self) -> Quat {+ Quat::from_euler(+ glam::EulerRot::XYZ,+ self.x.to_radians(),+ self.y.to_radians(),+ self.z.to_radians(),+ )+ }+}++/// A named preset pose: per-joint rotations over the rest pose.+#[derive(Clone, Debug, Serialize, Deserialize)]+pub struct YuuPose {+ /// Stable id (matches the Kotlin `poseId`).+ pub id: String,+ /// Display name.+ pub name: String,+ /// Joint rotations; joints absent from the map stay at rest.+ #[serde(default)]+ pub joints: HashMap<String, JointRotation>,+}++/// Preset gallery ids, in gallery order.+pub const POSE_IDLE: &str = "idle";+/// Friendly wave with the right hand.+pub const POSE_WAVE: &str = "wave";+/// Right-hand thumbs-up.+pub const POSE_THUMBS_UP: &str = "thumbs_up";+/// Chin resting on the right hand.+pub const POSE_THINKING: &str = "thinking";+/// Both arms raised in celebration.+pub const POSE_CHEERING: &str = "cheering";++/// Build the v1 preset gallery.+pub fn preset_poses() -> Vec<YuuPose> {+ vec![+ YuuPose { id: POSE_IDLE.into(), name: "Idle".into(), joints: HashMap::new() },+ YuuPose {+ id: POSE_WAVE.into(),+ name: "Wave".into(),+ joints: HashMap::from([+ ("upperArm_R".into(), JointRotation { x: 0.0, y: 0.0, z: -140.0 }),+ ("forearm_R".into(), JointRotation { x: 0.0, y: 0.0, z: -20.0 }),+ ("hand_R".into(), JointRotation { x: 0.0, y: 25.0, z: 0.0 }),+ ("head".into(), JointRotation { x: 0.0, y: -8.0, z: 4.0 }),+ ]),+ },+ YuuPose {+ id: POSE_THUMBS_UP.into(),+ name: "Thumbs up".into(),+ joints: HashMap::from([+ ("upperArm_R".into(), JointRotation { x: -50.0, y: 0.0, z: -30.0 }),+ ("forearm_R".into(), JointRotation { x: -40.0, y: 0.0, z: 0.0 }),+ ("hand_R".into(), JointRotation { x: -10.0, y: 0.0, z: 90.0 }),+ ("head".into(), JointRotation { x: -4.0, y: 0.0, z: 0.0 }),+ ]),+ },+ YuuPose {+ id: POSE_THINKING.into(),+ name: "Thinking".into(),+ joints: HashMap::from([+ ("upperArm_R".into(), JointRotation { x: -30.0, y: 0.0, z: -45.0 }),+ ("forearm_R".into(), JointRotation { x: -95.0, y: 0.0, z: 15.0 }),+ ("hand_R".into(), JointRotation { x: -20.0, y: 0.0, z: 0.0 }),+ ("head".into(), JointRotation { x: 8.0, y: 12.0, z: -6.0 }),+ ]),+ },+ YuuPose {+ id: POSE_CHEERING.into(),+ name: "Cheering".into(),+ joints: HashMap::from([+ ("upperArm_L".into(), JointRotation { x: 0.0, y: 0.0, z: 140.0 }),+ ("forearm_L".into(), JointRotation { x: 0.0, y: 0.0, z: 20.0 }),+ ("upperArm_R".into(), JointRotation { x: 0.0, y: 0.0, z: -140.0 }),+ ("forearm_R".into(), JointRotation { x: 0.0, y: 0.0, z: -20.0 }),+ ("head".into(), JointRotation { x: -10.0, y: 0.0, z: 0.0 }),+ ]),+ },+ ]+}++/// Find a preset by id.+pub fn preset_by_id(id: &str) -> Option<YuuPose> {+ preset_poses().into_iter().find(|p| p.id == id)+}
library/avatar/src/main/rust/src/vulkan/buffers.rs
diff --git a/library/avatar/src/main/rust/src/vulkan/buffers.rs b/library/avatar/src/main/rust/src/vulkan/buffers.rsindex 33c20a194c..afc9147c4a 100644--- a/library/avatar/src/main/rust/src/vulkan/buffers.rs+++ b/library/avatar/src/main/rust/src/vulkan/buffers.rs@@ -21,8 +21,8 @@ pub struct YuuVkVertex { pub normal: [f32; 3], /// Albedo UV. pub uv: [f32; 2],- /// Bone indices into the UBO order.- pub joints: [u32; 4],+ /// Bone indices into the UBO order (floats — Mali note on YuuVertex).+ pub joints: [f32; 4], /// Bone weights (normalized). pub weights: [f32; 4], }@@ -49,7 +49,7 @@ impl YuuVkVertex { } /// Five attributes: `vec3 pos` at 0, `vec3 normal` at 1, `vec2 uv` at 2,- /// `uvec4 joints` at 3, `vec4 weights` at 4.+ /// `vec4 joints` at 3, `vec4 weights` at 4 (floats — Mali note). pub fn attribute_descriptions() -> [vk::VertexInputAttributeDescription; 5] { [ vk::VertexInputAttributeDescription::default()@@ -70,7 +70,7 @@ impl YuuVkVertex { vk::VertexInputAttributeDescription::default() .binding(0) .location(3)- .format(vk::Format::R32G32B32A32_UINT)+ .format(vk::Format::R32G32B32A32_SFLOAT) .offset(mem::offset_of!(YuuVkVertex, joints) as u32), vk::VertexInputAttributeDescription::default() .binding(0)
metadata_data/photos/games-hub/5.png
diff --git a/metadata_data/photos/games-hub/5.png b/metadata_data/photos/games-hub/5.pngindex 8cecdc93fa..e8b2c8330b 100644Binary files a/metadata_data/photos/games-hub/5.png and b/metadata_data/photos/games-hub/5.png differ
metadata_data/photos/games-hub/7.png
diff --git a/metadata_data/photos/games-hub/7.png b/metadata_data/photos/games-hub/7.pngindex 6c4d9201ac..17f5b621df 100644Binary files a/metadata_data/photos/games-hub/7.png and b/metadata_data/photos/games-hub/7.png differ