avatar: camelCase serde bridge, full 29-field traits, slider controls
- Commit
276450e56c7b0cb28b2da0e28b5341c9ea895f51- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-20 05:56 UTC (1 month ago)
- Parents
0e29b9b
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 80c94b9951..caaf7cf69b 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@@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items@@ -53,18 +54,11 @@ import com.vayunmathur.games.hub.ui.yuu.YuuEditorUiState import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.FilterChip-import com.vayunmathur.library.ui.IconArrowDownward-import com.vayunmathur.library.ui.IconArrowUpward import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.IconRotateLeft-import com.vayunmathur.library.ui.IconRotateRight import com.vayunmathur.library.ui.IconSave-import com.vayunmathur.library.ui.IconUnfoldLess-import com.vayunmathur.library.ui.IconUnfoldMore-import com.vayunmathur.library.ui.IconZoomIn-import com.vayunmathur.library.ui.IconZoomOut import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.OutlinedTextField+import com.vayunmathur.library.ui.Slider import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.library.ui.R as UiR@@ -304,15 +298,10 @@ private class YuuDraft private constructor( } } -/** Step size for every icon stepper tap. */-private const val STEP = 0.1f--private fun Float.stepped(delta: Float): Float = (this + delta).coerceIn(0f, 1f)- /**- * Icon steppers overlaid on the preview, one pair per numeric tweak of the active- * category. Rotation uses rotate L/R icons, size uses zoom out/in, spacing uses- * unfold less/more, vertical moves use up/down arrows.+ * Tweak sliders overlaid on the preview, one per numeric tweak of the active+ * category. Sliders bind directly to the draft field (0..1), replacing the+ * old icon steppers — continuous control instead of ±0.1 taps. */ @Composable private fun PreviewSteppers(@@ -320,31 +309,31 @@ private fun PreviewSteppers( draft: YuuDraft, modifier: Modifier = Modifier, ) {- val rows: List<StepperSpec> = when (category) {+ val rows: List<TweakSpec> = when (category) { YuuCategory.Face -> listOf(- StepperSpec(R.string.yuu_ear_size, { IconZoomOut() }, { draft.earSize = draft.earSize.stepped(-STEP) }, { IconZoomIn() }, { draft.earSize = draft.earSize.stepped(STEP) }),+ TweakSpec(R.string.yuu_ear_size, { draft.earSize }, { draft.earSize = it }), ) YuuCategory.Body -> listOf(- StepperSpec(R.string.yuu_body_height, { IconArrowDownward() }, { draft.bodyHeight = draft.bodyHeight.stepped(-STEP) }, { IconArrowUpward() }, { draft.bodyHeight = draft.bodyHeight.stepped(STEP) }),- StepperSpec(R.string.yuu_body_weight, { IconUnfoldLess() }, { draft.bodyWeight = draft.bodyWeight.stepped(-STEP) }, { IconUnfoldMore() }, { draft.bodyWeight = draft.bodyWeight.stepped(STEP) }),+ TweakSpec(R.string.yuu_body_height, { draft.bodyHeight }, { draft.bodyHeight = it }),+ TweakSpec(R.string.yuu_body_weight, { draft.bodyWeight }, { draft.bodyWeight = it }), ) YuuCategory.Hair -> emptyList() YuuCategory.Eyes -> listOf(- StepperSpec(R.string.yuu_eye_size, { IconZoomOut() }, { draft.eyeSize = draft.eyeSize.stepped(-STEP) }, { IconZoomIn() }, { draft.eyeSize = draft.eyeSize.stepped(STEP) }),- StepperSpec(R.string.yuu_eye_spacing, { IconUnfoldLess() }, { draft.eyeSpacing = draft.eyeSpacing.stepped(-STEP) }, { IconUnfoldMore() }, { draft.eyeSpacing = draft.eyeSpacing.stepped(STEP) }),- StepperSpec(R.string.yuu_eye_height, { IconArrowDownward() }, { draft.eyeHeight = draft.eyeHeight.stepped(-STEP) }, { IconArrowUpward() }, { draft.eyeHeight = draft.eyeHeight.stepped(STEP) }),- StepperSpec(R.string.yuu_eye_rotation, { IconRotateLeft() }, { draft.eyeRotation = draft.eyeRotation.stepped(-STEP) }, { IconRotateRight() }, { draft.eyeRotation = draft.eyeRotation.stepped(STEP) }),+ TweakSpec(R.string.yuu_eye_size, { draft.eyeSize }, { draft.eyeSize = it }),+ TweakSpec(R.string.yuu_eye_spacing, { draft.eyeSpacing }, { draft.eyeSpacing = it }),+ TweakSpec(R.string.yuu_eye_height, { draft.eyeHeight }, { draft.eyeHeight = it }),+ TweakSpec(R.string.yuu_eye_rotation, { draft.eyeRotation }, { draft.eyeRotation = it }), ) YuuCategory.Brows -> listOf(- StepperSpec(R.string.yuu_brow_height, { IconArrowDownward() }, { draft.browHeight = draft.browHeight.stepped(-STEP) }, { IconArrowUpward() }, { draft.browHeight = draft.browHeight.stepped(STEP) }),- StepperSpec(R.string.yuu_brow_rotation, { IconRotateLeft() }, { draft.browRotation = draft.browRotation.stepped(-STEP) }, { IconRotateRight() }, { draft.browRotation = draft.browRotation.stepped(STEP) }),+ TweakSpec(R.string.yuu_brow_height, { draft.browHeight }, { draft.browHeight = it }),+ TweakSpec(R.string.yuu_brow_rotation, { draft.browRotation }, { draft.browRotation = it }), ) YuuCategory.Nose -> listOf(- StepperSpec(R.string.yuu_nose_height, { IconArrowDownward() }, { draft.noseHeight = draft.noseHeight.stepped(-STEP) }, { IconArrowUpward() }, { draft.noseHeight = draft.noseHeight.stepped(STEP) }),+ TweakSpec(R.string.yuu_nose_height, { draft.noseHeight }, { draft.noseHeight = it }), ) YuuCategory.Mouth -> listOf(- StepperSpec(R.string.yuu_mouth_size, { IconZoomOut() }, { draft.mouthSize = draft.mouthSize.stepped(-STEP) }, { IconZoomIn() }, { draft.mouthSize = draft.mouthSize.stepped(STEP) }),- StepperSpec(R.string.yuu_mouth_height, { IconArrowDownward() }, { draft.mouthHeight = draft.mouthHeight.stepped(-STEP) }, { IconArrowUpward() }, { draft.mouthHeight = draft.mouthHeight.stepped(STEP) }),+ TweakSpec(R.string.yuu_mouth_size, { draft.mouthSize }, { draft.mouthSize = it }),+ TweakSpec(R.string.yuu_mouth_height, { draft.mouthHeight }, { draft.mouthHeight = it }), ) YuuCategory.Extras -> emptyList() }@@ -356,28 +345,30 @@ private fun PreviewSteppers( rows.forEach { spec -> Row( modifier = Modifier.fillMaxWidth(),- horizontalArrangement = Arrangement.SpaceBetween,+ horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically, ) {- IconButton(onClick = spec.onDecrease) { spec.decreaseIcon() } Text( stringResource(spec.labelRes), style = MaterialTheme.typography.labelSmall, textAlign = TextAlign.Center,+ modifier = Modifier.width(72.dp),+ )+ Slider(+ value = spec.get(),+ onValueChange = { spec.set(it.coerceIn(0f, 1f)) },+ valueRange = 0f..1f, modifier = Modifier.weight(1f), )- IconButton(onClick = spec.onIncrease) { spec.increaseIcon() } } } } } -private class StepperSpec(+private class TweakSpec( val labelRes: Int,- val decreaseIcon: @Composable () -> Unit,- val onDecrease: () -> Unit,- val increaseIcon: @Composable () -> Unit,- val onIncrease: () -> Unit,+ val get: () -> Float,+ val set: (Float) -> Unit, ) @Composable
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 f0ebc02034..42575fcff8 100644--- a/library/avatar/src/main/rust/src/avatar.rs+++ b/library/avatar/src/main/rust/src/avatar.rs@@ -11,8 +11,8 @@ //! attachment/texture variants, and mole/wrinkle/blush are v1-skipped. use crate::pose::{JointRotation, YuuPose};+use crate::traits::YuuTraits; use glam::{Mat4, Quat, Vec3};-use serde::{Deserialize, Serialize}; /// Bone-matrix UBO capacity: 13 v1 joints fit with headroom for attachments. pub const MAX_BONES: usize = 32;@@ -150,103 +150,6 @@ pub fn joint_by_name(name: &str) -> Option<Joint> { ALL_JOINTS.iter().copied().find(|j| joint_name(*j) == name) } -/// Coarse trait mapping from `YuuFaceConfig` JSON.-///-/// Only the fields that affect the 3D body are read here; face-detail fields-/// (eyes/brows/nose/mouth styles, glasses, beard, mole, wrinkles, blush) map-/// to texture regions or attachments in a later phase and are ignored for now.-#[derive(Clone, Debug, Serialize, Deserialize)]-pub struct YuuTraits {- /// ARGB long from the fixed skin palette.- #[serde(default)]- pub skin_tone: u64,- /// Normalized body height 0..1.- #[serde(default = "half")]- pub body_height: f32,- /// Normalized body weight 0..1.- #[serde(default = "half")]- pub body_weight: f32,- /// Face shape index 0..7 (drives head scale approximation).- #[serde(default)]- pub face_shape: i32,- /// Hair style index (drives hair attachment variant).- #[serde(default)]- pub hair_style: i32,- /// ARGB long from the fixed hair palette.- #[serde(default)]- pub hair_color: u64,-}--fn half() -> f32 {- 0.5-}--impl Default for YuuTraits {- fn default() -> Self {- Self {- skin_tone: 0,- body_height: 0.5,- body_weight: 0.5,- face_shape: 0,- hair_style: 0,- hair_color: 0,- }- }-}--impl YuuTraits {- /// Parse from the `YuuFaceConfig` JSON string; unknown/missing fields fall- /// back to defaults (mirrors the Kotlin `ignoreUnknownKeys` behavior).- pub fn from_config_json(json: &str) -> Self {- serde_json::from_str(json).unwrap_or_default()- }-- /// Skin albedo as linear-ish RGB 0..1 (sRGB bytes unpacked, no transfer).- pub fn skin_rgb(&self) -> [f32; 3] {- argb_to_rgb(self.skin_tone, [0.91, 0.71, 0.54])- }-- /// Hair albedo as RGB 0..1.- pub fn hair_rgb(&self) -> [f32; 3] {- argb_to_rgb(self.hair_color, [0.17, 0.17, 0.17])- }-- /// Spine-chain height scale from `body_height`.- pub fn height_scale(&self) -> f32 {- 0.9 + self.body_height.clamp(0.0, 1.0) * 0.2- }-- /// Chest/arm width scale from `body_weight`.- pub fn weight_scale(&self) -> f32 {- 0.85 + self.body_weight.clamp(0.0, 1.0) * 0.3- }-- /// Head non-uniform scale approximation from `face_shape`.- pub fn head_scale(&self) -> Vec3 {- match self.face_shape.rem_euclid(8) {- 1 => Vec3::new(0.95, 1.0, 0.95),- 2 => Vec3::new(1.08, 0.96, 0.96),- 3 => Vec3::new(1.05, 1.0, 1.0),- 4 => Vec3::new(0.92, 1.08, 0.94),- 5 => Vec3::new(1.1, 1.0, 1.0),- 6 => Vec3::new(1.02, 0.98, 1.0),- 7 => Vec3::new(1.12, 0.94, 1.0),- _ => Vec3::ONE,- }- }-}--/// Unpack an ARGB long to RGB floats, with a fallback.-fn argb_to_rgb(argb: u64, fallback: [f32; 3]) -> [f32; 3] {- if argb == 0 {- return fallback;- }- let r = ((argb >> 16) & 0xFF) as f32 / 255.0;- let g = ((argb >> 8) & 0xFF) as f32 / 255.0;- let b = (argb & 0xFF) as f32 / 255.0;- [r, g, b]-}- /// Compute world-space bone matrices for a pose over the rest skeleton. /// /// Applies trait scales (height on spine/chest, weight on chest/arms, head@@ -353,6 +256,7 @@ fn rest_world_matrices() -> [Mat4; MAX_BONES] { mod tests { use super::*; use crate::pose::YuuPose;+ use crate::traits::YuuTraits; use std::collections::HashMap; #[test]@@ -401,5 +305,60 @@ mod tests { let bad = YuuTraits::from_config_json("not json"); assert_eq!(bad.body_height, 0.5); }++ #[test]+ fn traits_parse_kotlin_camel_case() {+ // Regression: Kotlin emits camelCase keys (YuuFaceConfig.encode()).+ // Before the alias bridge these all silently defaulted, so no slider+ // or selection ever reached the engine.+ let json = r#"{"faceShape":5,"skinTone":4293457546,"bodyHeight":0.8,"bodyWeight":0.2,"hairStyle":3,"hairColor":4284510252}"#;+ let t = YuuTraits::from_config_json(json);+ assert_eq!(t.face_shape, 5);+ assert_eq!(t.skin_tone, 4293457546);+ assert!((t.body_height - 0.8).abs() < 1e-6);+ assert!((t.body_weight - 0.2).abs() < 1e-6);+ assert_eq!(t.hair_style, 3);+ assert_eq!(t.hair_color, 4284510252);+ }++ #[test]+ fn traits_parse_full_kotlin_config() {+ // Full 29-field Kotlin-shaped fixture: every field must parse (no+ // silent drops), and the bone-driving subset must affect matrices.+ let json = r#"{"faceShape":2,"skinTone":4293457546,"earSize":0.7,"bodyHeight":0.8,"bodyWeight":0.2,"hairStyle":3,"hairColor":4284510252,"eyeStyle":4,"eyeColor":4284510253,"eyeSize":0.6,"eyeSpacing":0.4,"eyeHeight":0.7,"eyeRotation":0.3,"browStyle":2,"browColor":4284510254,"browHeight":0.6,"browRotation":0.4,"noseStyle":3,"noseHeight":0.8,"mouthStyle":5,"mouthColor":4284510255,"mouthSize":0.7,"mouthHeight":0.3,"glassesStyle":2,"beardStyle":1,"moleStyle":1,"wrinkleStyle":2,"blushStyle":1,"poseId":"wave"}"#;+ let t = YuuTraits::from_config_json(json);+ assert_eq!(t.face_shape, 2);+ assert_eq!(t.skin_tone, 4293457546);+ assert!((t.ear_size - 0.7).abs() < 1e-6);+ assert!((t.body_height - 0.8).abs() < 1e-6);+ assert!((t.body_weight - 0.2).abs() < 1e-6);+ assert_eq!(t.hair_style, 3);+ assert_eq!(t.hair_color, 4284510252);+ assert_eq!(t.eye_style, 4);+ assert_eq!(t.eye_color, 4284510253);+ assert!((t.eye_size - 0.6).abs() < 1e-6);+ assert!((t.eye_spacing - 0.4).abs() < 1e-6);+ assert!((t.eye_height - 0.7).abs() < 1e-6);+ assert!((t.eye_rotation - 0.3).abs() < 1e-6);+ assert_eq!(t.brow_style, 2);+ assert_eq!(t.brow_color, 4284510254);+ assert!((t.brow_height - 0.6).abs() < 1e-6);+ assert!((t.brow_rotation - 0.4).abs() < 1e-6);+ assert_eq!(t.nose_style, 3);+ assert!((t.nose_height - 0.8).abs() < 1e-6);+ assert_eq!(t.mouth_style, 5);+ assert_eq!(t.mouth_color, 4284510255);+ assert!((t.mouth_size - 0.7).abs() < 1e-6);+ assert!((t.mouth_height - 0.3).abs() < 1e-6);+ assert_eq!(t.glasses_style, 2);+ assert_eq!(t.beard_style, 1);+ assert_eq!(t.mole_style, 1);+ assert_eq!(t.wrinkle_style, 2);+ assert_eq!(t.blush_style, 1);+ assert_eq!(t.pose_id.as_deref(), Some("wave"));+ // Bone-driving subset spot-check: bodyHeight 0.8 → taller spine.+ assert!((t.height_scale() - 1.06).abs() < 1e-6);+ assert!((t.weight_scale() - 0.91).abs() < 1e-6);+ } }
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 e6f9ced59b..1ec41eba6d 100644--- a/library/avatar/src/main/rust/src/engine.rs+++ b/library/avatar/src/main/rust/src/engine.rs@@ -6,8 +6,9 @@ //! 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, YuuTraits, MAX_BONES};+use crate::avatar::{compute_bone_matrices, MAX_BONES}; use crate::pose::{preset_by_id, preset_poses, YuuPose};+use crate::traits::YuuTraits; use crate::mesh::{build_avatar_mesh, load_gltf_mesh, YuuVertex}; use crate::renderer::Renderer; use glam::Mat4;
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 73c699a76b..fa3907c5bc 100644--- a/library/avatar/src/main/rust/src/lib.rs+++ b/library/avatar/src/main/rust/src/lib.rs@@ -11,6 +11,7 @@ pub mod gles; pub mod mesh; pub mod pose; pub mod renderer;+pub mod traits; pub mod vulkan; use jni::objects::{JClass, JObject, JString};
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 cef5afe4b5..4b4e7f920d 100644--- a/library/avatar/src/main/rust/src/mesh.rs+++ b/library/avatar/src/main/rust/src/mesh.rs@@ -355,7 +355,8 @@ mod tests { // 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::avatar::compute_bone_matrices;+ use crate::traits::YuuTraits; use crate::pose::preset_by_id; use glam::Vec3; let mesh = build_avatar_mesh();
library/avatar/src/main/rust/src/traits.rs
diff --git a/library/avatar/src/main/rust/src/traits.rs b/library/avatar/src/main/rust/src/traits.rsnew file mode 100644index 0000000000..6d8a8a9ba5--- /dev/null+++ b/library/avatar/src/main/rust/src/traits.rs@@ -0,0 +1,202 @@+//! Yuu trait mapping: full YuuFaceConfig JSON bridge + derived scales.+//!+//! Split from `avatar.rs` along module lines (repo `rustFileLength` gate).+//! Parses all 29 Kotlin camelCase fields (via serde aliases); the bone-driving+//! subset feeds `compute_bone_matrices`, texture params feed face decals,+//! mesh indices feed attachments.++use glam::Vec3;+use serde::{Deserialize, Serialize};++/// Coarse trait mapping from `YuuFaceConfig` JSON.+///+/// Parses the full 29-field Kotlin config (camelCase via aliases). The+/// bone-driving subset (body/face) feeds forward kinematics; face-detail+/// fields feed texture regions (decals) or attachments in later phases —+/// all parse+store with serde defaults so nothing silently drops.+#[derive(Clone, Debug, Serialize, Deserialize)]+pub struct YuuTraits {+ /// Face shape index 0..7 (drives head scale approximation).+ #[serde(default, alias = "faceShape")]+ pub face_shape: i32,+ /// ARGB long from the fixed skin palette.+ /// `alias` accepts the Kotlin camelCase key; the snake_case name keeps+ /// existing test fixtures working.+ #[serde(default, alias = "skinTone")]+ pub skin_tone: u64,+ /// Ear size 0..1 (drives ear offset — ears attach to the head sides).+ #[serde(default = "half", alias = "earSize")]+ pub ear_size: f32,+ /// Normalized body height 0..1.+ #[serde(default = "half", alias = "bodyHeight")]+ pub body_height: f32,+ /// Normalized body weight 0..1.+ #[serde(default = "half", alias = "bodyWeight")]+ pub body_weight: f32,+ /// Hair style index (selects hair attachment node, Phase 4).+ #[serde(default, alias = "hairStyle")]+ pub hair_style: i32,+ /// ARGB long from the fixed hair palette.+ #[serde(default, alias = "hairColor")]+ pub hair_color: u64,+ /// Eye style index (selects face-atlas region, Phase 3).+ #[serde(default, alias = "eyeStyle")]+ pub eye_style: i32,+ /// ARGB long from the fixed eye palette.+ #[serde(default, alias = "eyeColor")]+ pub eye_color: u64,+ /// Eye size 0..1 (drives eye decal scale, Phase 3).+ #[serde(default = "half", alias = "eyeSize")]+ pub eye_size: f32,+ /// Eye spacing 0..1 (drives eye decal offsets, Phase 3).+ #[serde(default = "half", alias = "eyeSpacing")]+ pub eye_spacing: f32,+ /// Eye height 0..1 (drives eye decal offsets, Phase 3).+ #[serde(default = "half", alias = "eyeHeight")]+ pub eye_height: f32,+ /// Eye rotation 0..1 (stored; decal rotation lands with the atlas).+ #[serde(default = "half", alias = "eyeRotation")]+ pub eye_rotation: f32,+ /// Brow style index (selects face-atlas region, Phase 3).+ #[serde(default, alias = "browStyle")]+ pub brow_style: i32,+ /// ARGB long (brow palette = hair palette).+ #[serde(default, alias = "browColor")]+ pub brow_color: u64,+ /// Brow height 0..1 (drives brow decal offset, Phase 3).+ #[serde(default = "half", alias = "browHeight")]+ pub brow_height: f32,+ /// Brow rotation 0..1 (stored; decal rotation lands with the atlas).+ #[serde(default = "half", alias = "browRotation")]+ pub brow_rotation: f32,+ /// Nose style index (selects face-atlas region, Phase 3).+ #[serde(default, alias = "noseStyle")]+ pub nose_style: i32,+ /// Nose height 0..1 (drives nose decal offset, Phase 3).+ #[serde(default = "half", alias = "noseHeight")]+ pub nose_height: f32,+ /// Mouth style index (selects face-atlas region, Phase 3).+ #[serde(default, alias = "mouthStyle")]+ pub mouth_style: i32,+ /// ARGB long from the fixed mouth palette.+ #[serde(default, alias = "mouthColor")]+ pub mouth_color: u64,+ /// Mouth size 0..1 (drives mouth decal scale, Phase 3).+ #[serde(default = "half", alias = "mouthSize")]+ pub mouth_size: f32,+ /// Mouth height 0..1 (drives mouth decal offset, Phase 3).+ #[serde(default = "half", alias = "mouthHeight")]+ pub mouth_height: f32,+ /// Glasses style index (selects attachment node, Phase 4; 0 = none).+ #[serde(default, alias = "glassesStyle")]+ pub glasses_style: i32,+ /// Beard style index (selects attachment node, Phase 4; 0 = none).+ #[serde(default, alias = "beardStyle")]+ pub beard_style: i32,+ /// Mole style index (selects decal, Phase 3; 0 = none).+ #[serde(default, alias = "moleStyle")]+ pub mole_style: i32,+ /// Wrinkle style index (selects decal, Phase 3; 0 = none).+ #[serde(default, alias = "wrinkleStyle")]+ pub wrinkle_style: i32,+ /// Blush style index (selects decal, Phase 3; 0 = none).+ #[serde(default, alias = "blushStyle")]+ pub blush_style: i32,+ /// Pose id passthrough (engine keeps using the `set_pose_id` path;+ /// stored here for fixture parity, not consumed).+ #[serde(default, alias = "poseId")]+ pub pose_id: Option<String>,+}++fn half() -> f32 {+ 0.5+}++impl Default for YuuTraits {+ fn default() -> Self {+ Self {+ face_shape: 0,+ skin_tone: 0,+ ear_size: 0.5,+ body_height: 0.5,+ body_weight: 0.5,+ hair_style: 0,+ hair_color: 0,+ eye_style: 0,+ eye_color: 0,+ eye_size: 0.5,+ eye_spacing: 0.5,+ eye_height: 0.5,+ eye_rotation: 0.5,+ brow_style: 0,+ brow_color: 0,+ brow_height: 0.5,+ brow_rotation: 0.5,+ nose_style: 0,+ nose_height: 0.5,+ mouth_style: 0,+ mouth_color: 0,+ mouth_size: 0.5,+ mouth_height: 0.5,+ glasses_style: 0,+ beard_style: 0,+ mole_style: 0,+ wrinkle_style: 0,+ blush_style: 0,+ pose_id: None,+ }+ }+}++impl YuuTraits {+ /// Parse from the `YuuFaceConfig` JSON string; unknown/missing fields fall+ /// back to defaults (mirrors the Kotlin `ignoreUnknownKeys` behavior).+ pub fn from_config_json(json: &str) -> Self {+ serde_json::from_str(json).unwrap_or_default()+ }++ /// Skin albedo as linear-ish RGB 0..1 (sRGB bytes unpacked, no transfer).+ pub fn skin_rgb(&self) -> [f32; 3] {+ argb_to_rgb(self.skin_tone, [0.91, 0.71, 0.54])+ }++ /// Hair albedo as RGB 0..1.+ pub fn hair_rgb(&self) -> [f32; 3] {+ argb_to_rgb(self.hair_color, [0.17, 0.17, 0.17])+ }++ /// Spine-chain height scale from `body_height`.+ pub fn height_scale(&self) -> f32 {+ 0.9 + self.body_height.clamp(0.0, 1.0) * 0.2+ }++ /// Chest/arm width scale from `body_weight`.+ pub fn weight_scale(&self) -> f32 {+ 0.85 + self.body_weight.clamp(0.0, 1.0) * 0.3+ }++ /// Head non-uniform scale approximation from `face_shape`.+ pub fn head_scale(&self) -> Vec3 {+ match self.face_shape.rem_euclid(8) {+ 1 => Vec3::new(0.95, 1.0, 0.95),+ 2 => Vec3::new(1.08, 0.96, 0.96),+ 3 => Vec3::new(1.05, 1.0, 1.0),+ 4 => Vec3::new(0.92, 1.08, 0.94),+ 5 => Vec3::new(1.1, 1.0, 1.0),+ 6 => Vec3::new(1.02, 0.98, 1.0),+ 7 => Vec3::new(1.12, 0.94, 1.0),+ _ => Vec3::ONE,+ }+ }+}++/// Unpack an ARGB long to RGB floats, with a fallback.+fn argb_to_rgb(argb: u64, fallback: [f32; 3]) -> [f32; 3] {+ if argb == 0 {+ return fallback;+ }+ let r = ((argb >> 16) & 0xFF) as f32 / 255.0;+ let g = ((argb >> 8) & 0xFF) as f32 / 255.0;+ let b = (argb & 0xFF) as f32 / 255.0;+ [r, g, b]+}