Modern Apps git

← Modern-Apps.git

avatar: drag-rotate editor, rounded mesh, drop 2D, compact preview

Commit
1d30093f2cd4ed10b325b3585f9275d904a41cb1
Author
vayun-mathur <[email protected]>
When
2026-10-20 01:52 UTC (1 month ago)
Parents
307f0a2

Diff

games/hub/src/main/java/com/vayunmathur/games/hub/ui/components/YuuBadge.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/components/YuuBadge.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/components/YuuBadge.ktdeleted file mode 100644index 0ace363861..0000000000--- a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/components/YuuBadge.kt+++ /dev/null@@ -1,35 +0,0 @@-package com.vayunmathur.games.hub.ui.components--import androidx.compose.foundation.background-import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size-import androidx.compose.foundation.shape.CircleShape-import androidx.compose.runtime.Composable-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.draw.clip-import androidx.compose.ui.unit.dp-import com.vayunmathur.games.hub.data.entities.YuuFaceConfig-import com.vayunmathur.library.ui.MaterialTheme--/**- * Circular Yuu miniature for profile headers and the plaza grid. Same sizing and- * surface as [AvatarBadge] so the two are interchangeable in header rows.- */-@Composable-fun YuuBadge(config: YuuFaceConfig, modifier: Modifier = Modifier, large: Boolean = false) {-    val size = if (large) 56.dp else 36.dp-    Box(-        modifier = modifier-            .size(size)-            .clip(CircleShape)-            .background(MaterialTheme.colorScheme.primaryContainer),-        contentAlignment = Alignment.Center-    ) {-        YuuFace(-            config = config,-            modifier = Modifier.size(size - 8.dp).padding(2.dp),-        )-    }-}
games/hub/src/main/java/com/vayunmathur/games/hub/ui/components/YuuFace.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/components/YuuFace.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/components/YuuFace.ktdeleted file mode 100644index fc06791414..0000000000--- a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/components/YuuFace.kt+++ /dev/null@@ -1,495 +0,0 @@-package com.vayunmathur.games.hub.ui.components--import androidx.compose.foundation.Canvas-import androidx.compose.runtime.Composable-import androidx.compose.runtime.remember-import androidx.compose.ui.Modifier-import androidx.compose.ui.geometry.CornerRadius-import androidx.compose.ui.geometry.Offset-import androidx.compose.ui.geometry.Size-import androidx.compose.ui.graphics.Color-import androidx.compose.ui.graphics.Path-import androidx.compose.ui.graphics.drawscope.DrawScope-import androidx.compose.ui.graphics.drawscope.Stroke-import com.vayunmathur.games.hub.data.entities.YuuFaceConfig--/**- * Deterministic vector renderer for a [YuuFaceConfig]: every part is drawn from the- * config with size-relative math, so the same config renders identically at any size.- * Pure — no ViewModel, no resources — so previews and the plaza grid can use it freely.- *- * Paint order: body -> ears -> face shape -> hair back -> eyes -> brows -> nose ->- * mouth -> blush/wrinkles/mole -> glasses -> facial hair -> hair front.- *- * When [withBody] is true (editor preview), a simple Mii-like torso is drawn under- * the head whose height/width follow bodyHeight/bodyWeight. Plaza badges and profile- * headers keep the head-only form.- */-@Composable-fun YuuFace(-    config: YuuFaceConfig,-    modifier: Modifier = Modifier,-    withBody: Boolean = false,-) {-    val spec = remember(config, withBody) { YuuDrawSpec(config, withBody) }-    Canvas(modifier = modifier) {-        spec.draw(this)-    }-}--private fun Long.toColor(): Color = Color(this)--/** Precomputed, denormalized draw parameters for one config. */-private class YuuDrawSpec(config: YuuFaceConfig, val withBody: Boolean = false) {-    val faceShape = config.faceShape.mod(YuuFaceConfig.FACE_SHAPES)-    val skin = config.skinTone.toColor()-    val skinShade = config.skinTone.toColor().copy(alpha = 1f).darken(0.12f)-    val earR = 0.06f + config.earSize * 0.07f-    val bodyH = 0.28f + config.bodyHeight * 0.30f-    val bodyW = 0.30f + config.bodyWeight * 0.35f-    val hairStyle = config.hairStyle.mod(YuuFaceConfig.HAIR_STYLES)-    val hair = config.hairColor.toColor()-    val eyeStyle = config.eyeStyle.mod(YuuFaceConfig.EYE_STYLES)-    val eyeColor = config.eyeColor.toColor()-    val eyeR = 0.045f + config.eyeSize * 0.05f-    val eyeDx = 0.10f + config.eyeSpacing * 0.12f-    val eyeDy = -0.02f + config.eyeHeight * 0.10f - 0.05f-    val eyeTilt = (config.eyeRotation - 0.5f) * 0.6f-    val browStyle = config.browStyle.mod(YuuFaceConfig.BROW_STYLES)-    val browColor = config.browColor.toColor()-    val browDy = -0.16f - config.browHeight * 0.08f-    val browTilt = (config.browRotation - 0.5f) * 0.9f-    val noseStyle = config.noseStyle.mod(YuuFaceConfig.NOSE_STYLES)-    val noseDy = (config.noseHeight - 0.5f) * 0.12f-    val mouthStyle = config.mouthStyle.mod(YuuFaceConfig.MOUTH_STYLES)-    val mouthColor = config.mouthColor.toColor()-    val mouthW = 0.10f + config.mouthSize * 0.14f-    val mouthDy = (config.mouthHeight - 0.5f) * 0.12f-    val glasses = config.glassesStyle.mod(YuuFaceConfig.GLASSES_STYLES + 1)-    val beard = config.beardStyle.mod(YuuFaceConfig.BEARD_STYLES + 1)-    val mole = config.moleStyle.mod(YuuFaceConfig.MOLE_STYLES + 1)-    val wrinkles = config.wrinkleStyle.mod(YuuFaceConfig.WRINKLE_STYLES + 1)-    val blush = config.blushStyle.mod(YuuFaceConfig.BLUSH_STYLES + 1)--    fun draw(scope: DrawScope) = with(scope) {-        // With a body the head sits higher so the torso fits below.-        val s = if (withBody) size.minDimension * 0.72f else size.minDimension-        val c = if (withBody) center + Offset(0f, -size.minDimension * 0.14f) else center-        if (withBody) drawBody(c, size.minDimension)-        drawEars(c, s)-        drawFaceShape(c, s)-        drawHairBack(c, s)-        drawEyes(c, s)-        drawBrows(c, s)-        drawNose(c, s)-        drawMouth(c, s)-        drawSkinDetails(c, s)-        drawGlasses(c, s)-        drawBeard(c, s)-        drawHairFront(c, s)-    }--    private fun DrawScope.drawBody(headC: Offset, full: Float) {-        val neckW = bodyW * full * 0.28f-        val neckTop = headC.y + faceHalfHeight() * full * 0.72f - full * 0.02f-        // Neck.-        drawOval(-            skin,-            topLeft = Offset(headC.x - neckW / 2, neckTop - full * 0.06f),-            size = Size(neckW, full * 0.12f),-        )-        // Torso: rounded shoulders widening with weight, lengthening with height.-        val torsoTop = neckTop + full * 0.04f-        val torsoH = bodyH * full-        val torsoW = bodyW * full-        val p = Path().apply {-            moveTo(headC.x - torsoW * 0.45f, torsoTop + torsoH * 0.18f)-            quadraticTo(headC.x - torsoW * 0.55f, torsoTop, headC.x - torsoW * 0.30f, torsoTop)-            lineTo(headC.x + torsoW * 0.30f, torsoTop)-            quadraticTo(headC.x + torsoW * 0.55f, torsoTop, headC.x + torsoW * 0.45f, torsoTop + torsoH * 0.18f)-            lineTo(headC.x + torsoW * 0.50f, torsoTop + torsoH)-            lineTo(headC.x - torsoW * 0.50f, torsoTop + torsoH)-            close()-        }-        drawPath(p, skinShade)-    }--    private fun DrawScope.drawEars(c: Offset, s: Float) {-        val faceW = faceHalfWidth() * s-        val ey = c.y - s * 0.02f-        drawCircle(skin, radius = earR * s, center = Offset(c.x - faceW, ey))-        drawCircle(skin, radius = earR * s, center = Offset(c.x + faceW, ey))-    }--    private fun faceHalfWidth(): Float = when (faceShape) {-        1 -> 0.30f-        2 -> 0.27f-        3 -> 0.32f-        4 -> 0.26f-        5 -> 0.34f-        6 -> 0.29f-        7 -> 0.31f-        else -> 0.30f-    }--    private fun faceHalfHeight(): Float = when (faceShape) {-        1 -> 0.36f-        2 -> 0.40f-        3 -> 0.34f-        4 -> 0.42f-        5 -> 0.35f-        6 -> 0.38f-        7 -> 0.33f-        else -> 0.37f-    }--    private fun DrawScope.drawFaceShape(c: Offset, s: Float) {-        val w = faceHalfWidth() * s-        val h = faceHalfHeight() * s-        val cy = c.y - s * 0.02f-        when (faceShape) {-            // 1: square jaw — rounded rect.-            1 -> drawRoundRectPath(c, w, h, 0.18f * s)-            // 2: heart — wider top via two overlapping ovals.-            2 -> {-                drawOvalPath(c + Offset(0f, -h * 0.18f), w, h * 0.85f)-                drawOvalPath(c + Offset(0f, h * 0.28f), w * 0.72f, h * 0.62f)-            }-            // 4: long oval.-            4 -> drawOvalPath(c.copy(y = cy), w * 0.92f, h)-            // 6: round cheeks — main oval plus cheek circles.-            6 -> {-                drawOvalPath(c.copy(y = cy), w, h)-                drawCircle(skin, w * 0.42f, c + Offset(-w * 0.62f, h * 0.35f))-                drawCircle(skin, w * 0.42f, c + Offset(w * 0.62f, h * 0.35f))-            }-            // 7: wide — flattened oval.-            7 -> drawOvalPath(c.copy(y = cy), w, h * 0.88f)-            // 0, 3, 5: ovals with varying width (covered by faceHalfWidth).-            else -> drawOvalPath(c.copy(y = cy), w, h)-        }-    }--    private fun DrawScope.drawOvalPath(c: Offset, hw: Float, hh: Float) {-        drawOval(skin, topLeft = Offset(c.x - hw, c.y - hh), size = Size(hw * 2, hh * 2))-    }--    private fun DrawScope.drawRoundRectPath(c: Offset, hw: Float, hh: Float, r: Float) {-        drawRoundRect(-            skin,-            topLeft = Offset(c.x - hw, c.y - hh),-            size = Size(hw * 2, hh * 2),-            cornerRadius = CornerRadius(r, r),-        )-    }--    private fun DrawScope.drawHairBack(c: Offset, s: Float) {-        if (hairStyle == 0) return-        val w = faceHalfWidth() * s-        val topY = c.y - faceHalfHeight() * s - s * 0.02f-        when (hairStyle % 4) {-            // Long back hair: side panels behind the face.-            1 -> {-                drawOval(hair, Offset(c.x - w * 0.95f, topY + s * 0.30f), Size(w * 0.45f, s * 0.55f))-                drawOval(hair, Offset(c.x + w * 0.50f, topY + s * 0.30f), Size(w * 0.45f, s * 0.55f))-            }-            // Tied / bun sides.-            2 -> {-                drawCircle(hair, s * 0.09f, Offset(c.x - w - s * 0.05f, topY + s * 0.10f))-                drawCircle(hair, s * 0.09f, Offset(c.x + w + s * 0.05f, topY + s * 0.10f))-            }-            // Afro halo behind everything.-            3 -> drawCircle(hair, w * 1.25f, Offset(c.x, topY + s * 0.08f))-        }-    }--    private fun eyeCenters(c: Offset, s: Float): Pair<Offset, Offset> {-        val y = c.y + eyeDy * s-        return Offset(c.x - eyeDx * s, y) to Offset(c.x + eyeDx * s, y)-    }--    private fun DrawScope.drawEyes(c: Offset, s: Float) {-        val (l, r) = eyeCenters(c, s)-        val whiteRx = eyeR * s * 1.25f-        val whiteRy = eyeR * s * (if (eyeStyle % 3 == 2) 1.35f else 1.0f)-        for (ec in listOf(l, r)) {-            when (eyeStyle % 4) {-                // 0: classic white + iris.-                0, 1 -> {-                    drawOval(Color.White, Offset(ec.x - whiteRx, ec.y - whiteRy), Size(whiteRx * 2, whiteRy * 2))-                    drawCircle(eyeColor, eyeR * s * 0.62f, ec)-                    drawCircle(Color.Black, eyeR * s * 0.30f, ec)-                    drawCircle(Color.White, eyeR * s * 0.12f, ec + Offset(-eyeR * s * 0.15f, -eyeR * s * 0.15f))-                }-                // 2: tall oval eyes.-                2 -> {-                    drawOval(Color.White, Offset(ec.x - whiteRx, ec.y - whiteRy), Size(whiteRx * 2, whiteRy * 2))-                    drawOval(eyeColor, Offset(ec.x - whiteRx * 0.5f, ec.y - whiteRy * 0.5f), Size(whiteRx, whiteRy))-                    drawCircle(Color.Black, eyeR * s * 0.28f, ec)-                }-                // 3: simple dot eyes (Mii-like minimal).-                else -> drawCircle(eyeColor, eyeR * s * 0.55f, ec)-            }-            // Upper lash line, tilted by eyeRotation.-            val tilt = eyeTilt * s * 0.1f-            drawLine(-                Color.Black,-                Offset(ec.x - whiteRx, ec.y - whiteRy * 0.55f + tilt),-                Offset(ec.x + whiteRx, ec.y - whiteRy * 0.55f - tilt),-                strokeWidth = s * 0.012f,-            )-        }-    }--    private fun DrawScope.drawBrows(c: Offset, s: Float) {-        val (l, r) = eyeCenters(c, s)-        val y = c.y + browDy * s-        for (ec in listOf(l, r)) {-            val w2 = eyeR * s * 1.2f-            val yOff = (ec.x - c.x) * eyeTilt * 0.3f-            // Brow rotation: tilt each brow around its own center.-            val rot = browTilt * s * 0.35f-            when (browStyle % 4) {-                0 -> drawLine(browColor, Offset(ec.x - w2, y + yOff + rot), Offset(ec.x + w2, y + yOff - rot), s * 0.03f)-                1 -> {-                    val p = Path().apply {-                        moveTo(ec.x - w2, y + s * 0.02f + yOff + rot)-                        quadraticTo(ec.x, y - s * 0.045f + yOff, ec.x + w2, y + yOff - rot)-                    }-                    drawPath(p, browColor, style = Stroke(s * 0.028f))-                }-                2 -> drawLine(browColor, Offset(ec.x - w2, y + s * 0.02f + yOff + rot), Offset(ec.x + w2, y - s * 0.02f + yOff - rot), s * 0.035f)-                else -> {-                    drawLine(browColor, Offset(ec.x - w2, y + yOff + rot), Offset(ec.x + w2 * 0.4f, y - s * 0.03f + yOff), s * 0.03f)-                    drawLine(browColor, Offset(ec.x + w2 * 0.4f, y - s * 0.03f + yOff), Offset(ec.x + w2, y + yOff - rot), s * 0.03f)-                }-            }-        }-    }--    private fun DrawScope.drawNose(c: Offset, s: Float) {-        val ny = c.y + s * 0.06f + noseDy * s-        val ink = skinShade-        when (noseStyle % 4) {-            0 -> drawLine(ink, Offset(c.x + s * 0.01f, ny - s * 0.03f), Offset(c.x + s * 0.01f, ny + s * 0.03f), s * 0.014f)-            1 -> {-                val p = Path().apply {-                    moveTo(c.x - s * 0.02f, ny - s * 0.03f)-                    quadraticTo(c.x + s * 0.03f, ny, c.x - s * 0.005f, ny + s * 0.03f)-                }-                drawPath(p, ink, style = Stroke(s * 0.014f))-            }-            2 -> drawCircle(ink, s * 0.018f, Offset(c.x, ny + s * 0.01f))-            else -> drawLine(ink, Offset(c.x - s * 0.03f, ny + s * 0.02f), Offset(c.x + s * 0.03f, ny + s * 0.02f), s * 0.016f)-        }-    }--    private fun DrawScope.drawMouth(c: Offset, s: Float) {-        val my = c.y + s * 0.16f + mouthDy * s-        val w2 = mouthW * s-        when (mouthStyle % 6) {-            0 -> drawLine(mouthColor, Offset(c.x - w2 * 0.8f, my), Offset(c.x + w2 * 0.8f, my), s * 0.018f)-            1 -> {-                val p = Path().apply {-                    moveTo(c.x - w2, my - s * 0.01f)-                    quadraticTo(c.x, my + s * 0.09f, c.x + w2, my - s * 0.01f)-                }-                drawPath(p, mouthColor, style = Stroke(s * 0.018f))-            }-            2 -> drawOval(mouthColor, Offset(c.x - w2 * 0.55f, my - s * 0.035f), Size(w2 * 1.1f, s * 0.09f))-            3 -> {-                drawOval(Color.White, Offset(c.x - w2 * 0.7f, my - s * 0.02f), Size(w2 * 1.4f, s * 0.10f))-                drawLine(Color.Black, Offset(c.x - w2 * 0.7f, my + s * 0.015f), Offset(c.x + w2 * 0.7f, my + s * 0.015f), s * 0.010f)-            }-            4 -> {-                val p = Path().apply {-                    moveTo(c.x - w2, my + s * 0.02f)-                    quadraticTo(c.x, my - s * 0.05f, c.x + w2, my + s * 0.02f)-                }-                drawPath(p, mouthColor, style = Stroke(s * 0.016f))-            }-            else -> {-                val p = Path().apply {-                    moveTo(c.x - w2, my)-                    lineTo(c.x - w2 * 0.3f, my + s * 0.02f)-                    lineTo(c.x + w2 * 0.3f, my + s * 0.02f)-                    lineTo(c.x + w2, my)-                    lineTo(c.x + w2 * 0.5f, my + s * 0.055f)-                    lineTo(c.x - w2 * 0.5f, my + s * 0.055f)-                    close()-                }-                drawPath(p, Color.White)-                drawPath(p, mouthColor, style = Stroke(s * 0.012f))-            }-        }-    }--    private fun DrawScope.drawSkinDetails(c: Offset, s: Float) {-        // Blush.-        if (blush != 0) {-            val bc = mouthColor.copy(alpha = 0.45f)-            val (l, r) = eyeCenters(c, s)-            val by = c.y + s * 0.12f-            val bw = s * (0.05f + blush * 0.012f)-            drawCircle(bc, bw, Offset(l.x - s * 0.05f, by))-            drawCircle(bc, bw, Offset(r.x + s * 0.05f, by))-            if (blush == 3) {-                drawCircle(bc, bw * 0.7f, Offset(l.x - s * 0.05f, by - bw))-                drawCircle(bc, bw * 0.7f, Offset(r.x + s * 0.05f, by - bw))-            }-        }-        // Wrinkles: forehead lines + crow's feet.-        if (wrinkles != 0) {-            val ink = skinShade.copy(alpha = 0.8f)-            val fy = c.y - faceHalfHeight() * s * 0.55f-            repeat(wrinkles) { i ->-                val yy = fy + i * s * 0.035f-                val wob = s * 0.10f * (1f - i * 0.15f)-                drawLine(ink, Offset(c.x - wob, yy), Offset(c.x + wob, yy), s * 0.008f)-            }-            val (l, r) = eyeCenters(c, s)-            drawLine(ink, Offset(l.x - eyeR * s * 1.7f, l.y), Offset(l.x - eyeR * s * 1.2f, l.y - s * 0.02f), s * 0.008f)-            drawLine(ink, Offset(r.x + eyeR * s * 1.7f, r.y), Offset(r.x + eyeR * s * 1.2f, r.y - s * 0.02f), s * 0.008f)-        }-        // Mole / beauty mark.-        if (mole != 0) {-            val mp = when (mole % 4) {-                1 -> Offset(c.x - s * 0.12f, c.y + s * 0.10f)-                2 -> Offset(c.x + s * 0.12f, c.y + s * 0.10f)-                3 -> Offset(c.x + s * 0.05f, c.y + s * 0.22f)-                else -> Offset(c.x - s * 0.05f, c.y + s * 0.02f)-            }-            drawCircle(Color(0xFF4A2B2B), s * 0.014f, mp)-        }-    }--    private fun DrawScope.drawGlasses(c: Offset, s: Float) {-        if (glasses == 0) return-        val (l, r) = eyeCenters(c, s)-        val frame = Color(0xFF2B2B2B)-        val rw = eyeR * s * 1.7f-        val rh = eyeR * s * 1.4f-        when (glasses % 3) {-            // 1: round frames + bridge.-            1 -> {-                for (ec in listOf(l, r)) drawCircle(frame, rw, ec, style = Stroke(s * 0.018f))-                drawLine(frame, Offset(l.x + rw, l.y - rh * 0.3f), Offset(r.x - rw, r.y - rh * 0.3f), s * 0.016f)-            }-            // 2: square frames.-            2 -> {-                for (ec in listOf(l, r)) {-                    drawRoundRectPath(ec, rw, rh, s * 0.02f, frame, s * 0.018f)-                }-                drawLine(frame, Offset(l.x + rw, l.y), Offset(r.x - rw, r.y), s * 0.016f)-            }-            // 0 (mod 3): shades.-            else -> {-                for (ec in listOf(l, r)) drawOval(frame, Offset(ec.x - rw, ec.y - rh), Size(rw * 2, rh * 2))-                drawRoundRect(frame, Offset(c.x - rw * 0.4f, l.y - rh * 0.4f), Size(rw * 0.8f, rh * 0.5f))-            }-        }-    }--    private fun DrawScope.drawRoundRectPath(c: Offset, hw: Float, hh: Float, r: Float, color: Color, width: Float) {-        drawRoundRect(-            color,-            topLeft = Offset(c.x - hw, c.y - hh),-            size = Size(hw * 2, hh * 2),-            cornerRadius = CornerRadius(r, r),-            style = Stroke(width),-        )-    }--    private fun DrawScope.drawBeard(c: Offset, s: Float) {-        if (beard == 0) return-        val w = faceHalfWidth() * s-        val my = c.y + s * 0.16f-        when (beard % 3) {-            // 1: moustache above the mouth.-            1 -> {-                drawOval(hair, Offset(c.x - mouthW * s * 1.1f, my - s * 0.045f), Size(mouthW * s * 1.1f, s * 0.035f))-                drawOval(hair, Offset(c.x - s * 0.01f, my - s * 0.045f), Size(mouthW * s * 1.1f, s * 0.035f))-            }-            // 2: goatee below the mouth.-            2 -> drawOval(hair, Offset(c.x - w * 0.28f, my + s * 0.03f), Size(w * 0.56f, s * 0.16f))-            // 0 (mod 3): full beard framing the jaw.-            else -> {-                val p = Path().apply {-                    moveTo(c.x - w * 0.95f, my - s * 0.06f)-                    quadraticTo(c.x - w * 0.7f, my + s * 0.30f, c.x, my + s * 0.32f)-                    quadraticTo(c.x + w * 0.7f, my + s * 0.30f, c.x + w * 0.95f, my - s * 0.06f)-                    quadraticTo(c.x + w * 0.5f, my + s * 0.10f, c.x, my + s * 0.10f)-                    quadraticTo(c.x - w * 0.5f, my + s * 0.10f, c.x - w * 0.95f, my - s * 0.06f)-                    close()-                }-                drawPath(p, hair)-            }-        }-    }--    private fun DrawScope.drawHairFront(c: Offset, s: Float) {-        if (hairStyle == 0) return-        val w = faceHalfWidth() * s-        val topY = c.y - faceHalfHeight() * s - s * 0.02f-        when (hairStyle % 6) {-            // 1: side part sweep.-            1 -> {-                val p = Path().apply {-                    moveTo(c.x - w * 1.05f, topY + s * 0.12f)-                    quadraticTo(c.x - w * 0.4f, topY - s * 0.10f, c.x + w * 1.05f, topY + s * 0.06f)-                    quadraticTo(c.x + w * 0.6f, topY - s * 0.02f, c.x + w * 0.2f, topY + s * 0.10f)-                    quadraticTo(c.x - w * 0.5f, topY + s * 0.02f, c.x - w * 1.05f, topY + s * 0.12f)-                    close()-                }-                drawPath(p, hair)-            }-            // 2: straight fringe.-            2 -> drawOval(hair, Offset(c.x - w * 1.02f, topY - s * 0.06f), Size(w * 2.04f, s * 0.20f))-            // 3: afro cap.-            3 -> {-                drawCircle(hair, w * 1.25f, Offset(c.x, topY + s * 0.08f))-                drawCircle(skin, w * 0.98f, Offset(c.x, topY + s * 0.22f))-            }-            // 4: spiky top.-            4 -> {-                val p = Path().apply {-                    val n = 7-                    moveTo(c.x - w * 1.05f, topY + s * 0.10f)-                    repeat(n) { i ->-                        val x0 = c.x - w * 1.05f + i * (w * 2.1f / n)-                        val x1 = x0 + w * 2.1f / n / 2-                        val x2 = x0 + w * 2.1f / n-                        lineTo(x1, topY - s * (0.08f + (i % 2) * 0.05f))-                        lineTo(x2, topY + s * 0.10f)-                    }-                    quadraticTo(c.x, topY + s * 0.16f, c.x - w * 1.05f, topY + s * 0.10f)-                    close()-                }-                drawPath(p, hair)-            }-            // 5: bald with side wisps.-            5 -> {-                drawOval(hair, Offset(c.x - w * 1.02f, topY + s * 0.02f), Size(w * 0.28f, s * 0.16f))-                drawOval(hair, Offset(c.x + w * 0.74f, topY + s * 0.02f), Size(w * 0.28f, s * 0.16f))-            }-            // 0 (mod 6): neat cap.-            else -> {-                val p = Path().apply {-                    moveTo(c.x - w * 1.02f, topY + s * 0.14f)-                    quadraticTo(c.x, topY - s * 0.14f, c.x + w * 1.02f, topY + s * 0.14f)-                    quadraticTo(c.x + w * 0.9f, topY + s * 0.02f, c.x + w * 0.55f, topY + s * 0.10f)-                    quadraticTo(c.x, topY - s * 0.02f, c.x - w * 0.55f, topY + s * 0.10f)-                    quadraticTo(c.x - w * 0.9f, topY + s * 0.02f, c.x - w * 1.02f, topY + s * 0.14f)-                    close()-                }-                drawPath(p, hair)-            }-        }-    }--    private fun Color.darken(fraction: Float): Color {-        // Simple RGB scaling via cosine-free linear darkening; alpha preserved.-        fun Float.d() = (this * (1f - fraction)).coerceIn(0f, 1f)-        return copy(red = red.d(), green = green.d(), blue = blue.d())-    }-}
games/hub/src/main/java/com/vayunmathur/games/hub/ui/components/YuuPlaceholder.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/components/YuuPlaceholder.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/components/YuuPlaceholder.ktnew file mode 100644index 0000000000..cf991fb284--- /dev/null+++ b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/components/YuuPlaceholder.kt@@ -0,0 +1,43 @@+package com.vayunmathur.games.hub.ui.components++import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.text.style.TextAlign+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text++/**+ * Neutral stand-in shown where a 3D Yuu surface cannot draw (native library+ * absent, both GPU backends failed, over the live-surface budget, or+ * Layoutlib previews which cannot render Vulkan). Blank box + the Yuu's+ * initial — 3D is the only avatar renderer.+ *+ * Sizing belongs to the caller: no fill modifier here, so aspect ratios set+ * outside (e.g. plaza cells) are honored.+ */+@Composable+fun YuuPlaceholder(+    name: String,+    modifier: Modifier = Modifier,+) {+    Box(+        modifier = modifier+            .background(MaterialTheme.colorScheme.surfaceContainerLowest)+            .padding(8.dp),+        contentAlignment = Alignment.Center,+    ) {+        Text(+            text = name.firstOrNull()?.uppercase() ?: "…",+            style = MaterialTheme.typography.displaySmall,+            fontWeight = FontWeight.Bold,+            textAlign = TextAlign.Center,+            color = MaterialTheme.colorScheme.onSurfaceVariant,+        )+    }+}
games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/DashboardScreen.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/DashboardScreen.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/DashboardScreen.ktindex 4f7c1548f3..8483e39c7c 100644--- a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/DashboardScreen.kt+++ b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/DashboardScreen.kt@@ -29,7 +29,6 @@ import com.vayunmathur.games.hub.ui.components.StatCard import com.vayunmathur.games.hub.ui.components.StreakCard import com.vayunmathur.games.hub.ui.components.XpProgressBar import com.vayunmathur.games.hub.data.entities.encode-import com.vayunmathur.games.hub.ui.components.YuuBadge import com.vayunmathur.games.hub.ui.yuu.DASHBOARD_SURFACE_ID import com.vayunmathur.library.avatar.components.YuuAvatar3D import com.vayunmathur.games.hub.util.DashboardActions
games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/ProfileScreen.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/ProfileScreen.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/ProfileScreen.ktindex 6609788eea..9011b9de33 100644--- a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/ProfileScreen.kt+++ b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/ProfileScreen.kt@@ -30,7 +30,6 @@ import com.vayunmathur.games.hub.ui.components.AvatarBadge import com.vayunmathur.games.hub.ui.components.AvatarIcon import com.vayunmathur.games.hub.ui.components.StatCard import com.vayunmathur.games.hub.ui.components.XpProgressBar-import com.vayunmathur.games.hub.ui.components.YuuBadge import com.vayunmathur.games.hub.ui.components.YuuPoseGallery import com.vayunmathur.games.hub.ui.yuu.PROFILE_SURFACE_ID import com.vayunmathur.library.avatar.components.YuuAvatar3D
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 faed004cd7..6b560bb46b 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@@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.aspectRatio 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.size import androidx.compose.foundation.lazy.LazyRow@@ -41,12 +42,11 @@ import com.vayunmathur.games.hub.data.entities.YUU_MOUTH_COLORS import com.vayunmathur.games.hub.data.entities.YUU_SKIN_TONES import com.vayunmathur.games.hub.data.entities.YuuFaceConfig import com.vayunmathur.games.hub.data.entities.encode-import com.vayunmathur.games.hub.ui.components.YuuFace+import com.vayunmathur.games.hub.ui.components.YuuPlaceholder import com.vayunmathur.games.hub.ui.components.YuuPoseGallery import com.vayunmathur.games.hub.ui.yuu.EDITOR_SURFACE_ID import com.vayunmathur.games.hub.ui.yuu.YuuSurfaceIds import com.vayunmathur.library.avatar.components.YuuAvatar3D-import com.vayunmathur.games.hub.ui.yuu.EDITOR_SURFACE_ID import com.vayunmathur.games.hub.ui.yuu.YuuCategory import com.vayunmathur.games.hub.ui.yuu.YuuEditorActions import com.vayunmathur.games.hub.ui.yuu.YuuEditorUiState@@ -103,39 +103,46 @@ fun YuuEditorScreen(         scrollBehavior = appBarScrollBehavior(),     ) { padding ->         Column(-            modifier = modifier.fillMaxSize().padding(padding).padding(16.dp),-            verticalArrangement = Arrangement.spacedBy(10.dp),+            modifier = modifier.fillMaxSize().padding(padding).padding(12.dp),+            verticalArrangement = Arrangement.spacedBy(6.dp),         ) {-            // Zone 1: 3D preview (2D fallback when native is unavailable) with-            // overlay steppers for the active category, plus the pose gallery.+            // Zone 1: 3D preview with overlay steppers for the active category,+            // plus the pose gallery. Compact: wider aspect + height cap so the+            // option zone below gets room.             Card(modifier = Modifier.fillMaxWidth()) {                 Column(-                    modifier = Modifier.fillMaxWidth().padding(8.dp),-                    verticalArrangement = Arrangement.spacedBy(8.dp),+                    modifier = Modifier.fillMaxWidth().padding(6.dp),+                    verticalArrangement = Arrangement.spacedBy(6.dp),                 ) {                     Box(-                        modifier = Modifier.fillMaxWidth(),+                        modifier = Modifier.fillMaxWidth()+                            .heightIn(max = 240.dp),                         contentAlignment = Alignment.Center,                     ) {                         YuuAvatar3D(                             configJson = draft.toConfig().encode(),                             poseId = draft.poseId,                             surfaceId = EDITOR_SURFACE_ID,-                            modifier = Modifier.fillMaxWidth(0.72f).aspectRatio(0.9f).padding(8.dp),+                            modifier = Modifier.fillMaxWidth(0.6f).aspectRatio(PREVIEW_ASPECT).padding(6.dp),                             fallback = {-                                YuuFace(-                                    config = draft.toConfig(),-                                    withBody = true,+                                YuuPlaceholder(+                                    name = name.ifBlank { "…" },                                     modifier = Modifier.fillMaxSize(),                                 )                             },+                            // Drag-to-rotate lives inside YuuAvatar3D+                            // (enableDragRotate): the gesture overlay floats over+                            // the surface, under this stepper overlay, so the+                            // avatar stays where left and IconButtons keep working.+                            enableDragRotate = true,                         )-                        // Steppers overlay only the 2D fallback path's layout box;-                        // on the 3D path they float over the surface either way.+                        // Stepper overlay shares PREVIEW_ASPECT with the avatar so+                        // the rows bottom-anchor over the surface on both the 3D+                        // and placeholder paths.                         PreviewSteppers(                             category = category,                             draft = draft,-                            modifier = Modifier.fillMaxWidth().aspectRatio(0.9f),+                            modifier = Modifier.fillMaxWidth().aspectRatio(PREVIEW_ASPECT),                         )                     }                     SectionLabel(stringResource(R.string.yuu_pose))@@ -149,7 +156,7 @@ fun YuuEditorScreen(             // Zone 2: name + save on one compact row.             Row(                 modifier = Modifier.fillMaxWidth(),-                horizontalArrangement = Arrangement.spacedBy(8.dp),+                horizontalArrangement = Arrangement.spacedBy(6.dp),                 verticalAlignment = Alignment.CenterVertically,             ) {                 OutlinedTextField(@@ -174,7 +181,7 @@ fun YuuEditorScreen(                 ) { Text(stringResource(UiR.string.save)) }             }             // Zone 3: category rail (never scrolls the screen).-            LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {+            LazyRow(horizontalArrangement = Arrangement.spacedBy(6.dp)) {                 items(YuuCategory.entries) { cat ->                     FilterChip(                         selected = category == cat,@@ -186,7 +193,7 @@ fun YuuEditorScreen(             // Zone 4: the ONLY scrollable area — the option picker.             Column(                 modifier = Modifier.fillMaxWidth().weight(1f).verticalScroll(rememberScrollState()),-                verticalArrangement = Arrangement.spacedBy(8.dp),+                verticalArrangement = Arrangement.spacedBy(6.dp),             ) {                 when (category) {                     YuuCategory.Face -> FacePanel(draft)@@ -203,6 +210,9 @@ fun YuuEditorScreen(     } } +/** Preview aspect (w/h): avatar and stepper overlay share it — keep in sync. */+private const val PREVIEW_ASPECT = 1.5f+ private fun YuuCategory.labelRes(): Int = when (this) {     YuuCategory.Face -> R.string.yuu_cat_face     YuuCategory.Body -> R.string.yuu_cat_body@@ -432,8 +442,8 @@ private fun VariantCell(  /**  * Live-3D variant cell: renders the full draft config with one field- * overridden, keyed by a stable cell id. Over the live-surface cap it falls- * back to the 2D thumbnail (see [YuuSurfaceIds]).+ * overridden, keyed by a stable cell id. Over the live-surface cap it shows+ * the placeholder (see [YuuSurfaceIds]).  */ @Composable private fun VariantCell3D(@@ -457,11 +467,17 @@ private fun VariantCell3D(                     surfaceId = cellId,                     modifier = Modifier.fillMaxSize(),                     fallback = {-                        YuuFace(config = config, modifier = Modifier.fillMaxSize())+                        YuuPlaceholder(+                            name = "…",+                            modifier = Modifier.fillMaxSize(),+                        )                     },                 )             } else {-                YuuFace(config = config, modifier = Modifier.fillMaxSize())+                YuuPlaceholder(+                    name = "…",+                    modifier = Modifier.fillMaxSize(),+                )             }         }     }
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 64fd481554..d43ac7a71b 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@@ -26,7 +26,7 @@ import androidx.compose.ui.unit.dp import com.vayunmathur.games.hub.R import com.vayunmathur.games.hub.data.YuuUiModel import com.vayunmathur.games.hub.data.entities.encode-import com.vayunmathur.games.hub.ui.components.YuuFace+import com.vayunmathur.games.hub.ui.components.YuuPlaceholder import com.vayunmathur.games.hub.ui.yuu.YuuListActions import com.vayunmathur.games.hub.ui.yuu.YuuListUiState import com.vayunmathur.games.hub.ui.yuu.YuuSurfaceIds@@ -121,7 +121,7 @@ private fun YuuCard(             Box(contentAlignment = Alignment.TopEnd) {                 // Live 3D cell with a stable id (keyed by Yuu id, not position)                 // so config/pose never bleeds across recycled cells. Over the-                // live-surface cap the cell falls back to the 2D thumbnail.+                // live-surface cap the cell shows the placeholder.                 val surfaceId = YuuSurfaceIds.forYuu(yuu.id)                 if (YuuSurfaceIds.isLive(surfaceId)) {                     YuuAvatar3D(@@ -130,15 +130,15 @@ private fun YuuCard(                         surfaceId = surfaceId,                         modifier = Modifier.fillMaxWidth().aspectRatio(1f),                         fallback = {-                            YuuFace(-                                config = yuu.config,+                            YuuPlaceholder(+                                name = yuu.name,                                 modifier = Modifier.fillMaxSize(),                             )                         },                     )                 } else {-                    YuuFace(-                        config = yuu.config,+                    YuuPlaceholder(+                        name = yuu.name,                         modifier = Modifier.fillMaxWidth().aspectRatio(1f),                     )                 }
games/hub/src/main/java/com/vayunmathur/games/hub/ui/yuu/YuuSurfaceIds.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/yuu/YuuSurfaceIds.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/yuu/YuuSurfaceIds.ktindex 2915f58372..5935f0fe55 100644--- a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/yuu/YuuSurfaceIds.kt+++ b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/yuu/YuuSurfaceIds.kt@@ -13,7 +13,7 @@ const val PROFILE_SURFACE_ID = 3 /**  * Live-surface budget for the 3D grid expansion. Each live surface holds a  * swapchain + render thread + up to ~4MB of GPU buffers; beyond- * [MAX_LIVE_SURFACES] cells fall back to 2D thumbnails. Heroes (ids 1–3)+ * [MAX_LIVE_SURFACES] cells show the placeholder. Heroes (ids 1–3)  * always win eviction priority and are never counted here.  */ object YuuSurfaceIds {@@ -34,8 +34,8 @@ object YuuSurfaceIds {      /**      * Whether a cell id currently holds a live surface. Budget gate: the-     * lowest ids win so the first cells render 3D and the rest stay 2D.-     * Called during composition — pure arithmetic, no allocation.+     * lowest ids win so the first cells render 3D and the rest show the+     * placeholder. Called during composition — pure arithmetic, no allocation.      */     fun isLive(surfaceId: Int): Boolean = when {         surfaceId >= VARIANT_BASE -> surfaceId - VARIANT_BASE < MAX_LIVE_SURFACES
library/avatar/src/main/java/com/vayunmathur/library/avatar/YuuAvatarNative.kt
diff --git a/library/avatar/src/main/java/com/vayunmathur/library/avatar/YuuAvatarNative.kt b/library/avatar/src/main/java/com/vayunmathur/library/avatar/YuuAvatarNative.ktindex 39edefebee..70fbb59b33 100644--- a/library/avatar/src/main/java/com/vayunmathur/library/avatar/YuuAvatarNative.kt+++ b/library/avatar/src/main/java/com/vayunmathur/library/avatar/YuuAvatarNative.kt@@ -7,7 +7,7 @@ import com.vayunmathur.library.log.Log  * `MapNative`.  *  * Native calls are no-ops behind [isAvailable] = false (no `libyuu_avatar`- * on this device), and hero surfaces fall back to a 2D preview instead. The+ * on this device), and hero surfaces fall back to the placeholder instead. The  * signatures below are the contract the Rust engine implements.  *  * Surface lifecycle mirrors kart/voxels: each view owns a stable [surfaceId]@@ -23,7 +23,7 @@ internal object YuuAvatarNative {         Log.status("YuuAvatarNative", "libyuu_avatar loaded")         true     } catch (t: Throwable) {-        Log.status("YuuAvatarNative", "libyuu_avatar absent - using 2D Yuu preview")+        Log.status("YuuAvatarNative", "libyuu_avatar absent - using placeholder")         false     } @@ -72,6 +72,21 @@ internal object YuuAvatarNative {         nativeSetPaused(surfaceId, paused)     } +    /**+     * User drag-rotate delta for a surface, in radians. No-op without the+     * library. Pitch clamps native-side; yaw is unlimited.+     */+    fun onRotateInput(surfaceId: Int, yawDelta: Float, pitchDelta: Float) {+        if (!isAvailable) return+        nativeOnRotateInput(surfaceId, yawDelta, pitchDelta)+    }++    /** Set whether a surface auto-orbits (editor disables on creation). */+    fun setAutoRotate(surfaceId: Int, autoRotate: Boolean) {+        if (!isAvailable) return+        nativeSetAutoRotate(surfaceId, autoRotate)+    }+     fun onDestroy() {         if (!isAvailable) return         nativeOnDestroy()@@ -85,5 +100,7 @@ internal object YuuAvatarNative {     private external fun nativeSurfaceChanged(surfaceId: Int, width: Int, height: Int)     private external fun nativeSurfaceDestroyed(surfaceId: Int)     private external fun nativeSetPaused(surfaceId: Int, paused: Boolean)+    private external fun nativeOnRotateInput(surfaceId: Int, yawDelta: Float, pitchDelta: Float)+    private external fun nativeSetAutoRotate(surfaceId: Int, autoRotate: Boolean)     private external fun nativeOnDestroy() }
library/avatar/src/main/java/com/vayunmathur/library/avatar/components/YuuAvatar3D.kt
diff --git a/library/avatar/src/main/java/com/vayunmathur/library/avatar/components/YuuAvatar3D.kt b/library/avatar/src/main/java/com/vayunmathur/library/avatar/components/YuuAvatar3D.ktindex 9b15164bbf..a2e188e146 100644--- a/library/avatar/src/main/java/com/vayunmathur/library/avatar/components/YuuAvatar3D.kt+++ b/library/avatar/src/main/java/com/vayunmathur/library/avatar/components/YuuAvatar3D.kt@@ -1,11 +1,15 @@ package com.vayunmathur.library.avatar.components +import androidx.compose.foundation.gestures.detectDragGestures+import androidx.compose.foundation.gestures.detectDragGestures import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.Modifier+import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.viewinterop.AndroidView import androidx.lifecycle.Lifecycle@@ -19,12 +23,17 @@ import kotlinx.coroutines.delay  * debounce so editor typing doesn't spam JNI.  *  * The caller supplies [configJson] (the `YuuFaceConfig` JSON) and an optional- * [fallback] 2D preview shown when native is unavailable (no- * `libyuu_avatar`) and layered underneath the surface (so a failed renderer- * never shows a black hole).+ * [fallback] shown when native is unavailable (no `libyuu_avatar`) and layered+ * underneath the surface (so a failed renderer never shows a black hole).  *  * Each instance carries a stable [surfaceId] for the multi-renderer engine;  * dispose destroys that surface only.+ *+ * When [enableDragRotate] is true (editor preview), drags over the surface+ * orbit the camera: horizontal drag yaws (unlimited), vertical drag pitches+ * (clamped native-side). The avatar stays where left — no snap-back, no+ * auto-spin (auto-rotate is disabled for the surface). Overlays declared by+ * the caller (e.g. stepper buttons) sit above this layer and keep working.  */ @Composable fun YuuAvatar3D(@@ -33,6 +42,7 @@ fun YuuAvatar3D(     surfaceId: Int,     modifier: Modifier = Modifier,     fallback: (@Composable () -> Unit)? = null,+    enableDragRotate: Boolean = false, ) {     if (!YuuAvatarNative.isAvailable) {         fallback?.invoke()@@ -62,9 +72,14 @@ fun YuuAvatar3D(         YuuAvatarNative.setConfig(surfaceId, configJson, pose)     } +    // Editor drag mode owns the camera from first composition.+    LaunchedEffect(surfaceId, enableDragRotate) {+        if (enableDragRotate) YuuAvatarNative.setAutoRotate(surfaceId, false)+    }+     Box(modifier = modifier) {-        // 2D underneath: if the surface never draws (both backends failed),-        // the hero still shows the Yuu instead of a black hole.+        // Placeholder underneath: if the surface never draws (both backends+        // failed), the hero still shows something instead of a black hole.         fallback?.let { fb ->             Box(Modifier.fillMaxSize()) { fb() }         }@@ -72,5 +87,28 @@ fun YuuAvatar3D(             factory = { ctx -> YuuAvatarSurfaceView(ctx, surfaceId = surfaceId) },             modifier = Modifier.fillMaxSize(),         )+        // Drag layer ABOVE the SurfaceView: touches over a SurfaceView go to+        // the native view and bypass ancestor Compose pointer input, so the+        // gesture must live on a transparent overlay. Declared before any+        // caller overlays (e.g. stepper buttons) so those keep working.+        // Grab metaphor: drag-right turns the object right (yaw decreases),+        // drag-down pulls the front down (pitch increases, eye rises).+        if (enableDragRotate) {+            Box(+                Modifier.fillMaxSize().pointerInput(surfaceId) {+                    detectDragGestures { change, dragAmount ->+                        change.consume()+                        YuuAvatarNative.onRotateInput(+                            surfaceId,+                            -dragAmount.x * DRAG_RAD_PER_PX,+                            dragAmount.y * DRAG_RAD_PER_PX,+                        )+                    }+                }+            )+        }     } }++/** Radians of orbit per pixel of drag. */+private const val DRAG_RAD_PER_PX = 0.008f
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 cc92ecf87f..e6f9ced59b 100644--- a/library/avatar/src/main/rust/src/engine.rs+++ b/library/avatar/src/main/rust/src/engine.rs@@ -36,8 +36,18 @@ pub struct SurfaceState {     /// Render-thread generation: bumped on recreate so a stale thread     /// (rotation) exits instead of racing the new one.     pub generation: u64,+    /// User-driven orbit yaw radians (unlimited). Used when `autoRotate` is+    /// false (editor); heroes keep the time-based turntable.+    pub yaw: f32,+    /// User-driven orbit pitch radians, clamped to ±MAX_PITCH.+    pub pitch: f32,+    /// Whether the camera auto-orbits. The editor sets false on creation.+    pub auto_rotate: bool, } +/// Max orbit pitch: enough to inspect top/bottom, never straight down/up.+pub const MAX_PITCH: f32 = 0.6;+ impl SurfaceState {     /// Fresh surface with the idle pose.     fn new(width: u32, height: u32) -> Self {@@ -55,14 +65,35 @@ impl SurfaceState {             height: height.max(1),             paused: false,             generation: 0,+            yaw: 0.0,+            pitch: 0.0,+            auto_rotate: true,         }     } } +/// User orbit preference: survives surface removal (rotation) so the editor+/// keeps its drag position and auto-rotate opt-out.+#[derive(Clone, Copy, Debug)]+struct OrbitPrefs {+    yaw: f32,+    pitch: f32,+    auto_rotate: bool,+}++impl Default for OrbitPrefs {+    fn default() -> Self {+        Self { yaw: 0.0, pitch: 0.0, auto_rotate: true }+    }+}+ /// Engine state behind the global lock: the surface map plus shared assets. pub struct Engine {     /// Live surfaces by Kotlin-owned surface id.     pub surfaces: HashMap<i32, SurfaceState>,+    /// Orbit prefs by surface id: written on input, restored on (re)create,+    /// never cleared by surface removal.+    pub orbit: HashMap<i32, OrbitPrefs>,     /// Shared CPU mesh bytes (procedural fallback or parsed glb), uploaded     /// per-surface to GPU. Single allocation across all surfaces.     pub mesh: Arc<Vec<YuuVertex>>,@@ -75,6 +106,7 @@ impl Engine {     pub fn new() -> Self {         Self {             surfaces: HashMap::new(),+            orbit: HashMap::new(),             mesh: Arc::new(build_avatar_mesh()),             bundled_mesh: None,         }@@ -156,6 +188,35 @@ pub fn set_paused(surface_id: i32, paused: bool) {     } } +/// Accumulate a user drag-rotate delta on a surface. Yaw is unlimited;+/// pitch clamps to ±MAX_PITCH so the camera never goes straight down/up.+/// The avatar stays where left (no snap-back). Prefs persist across surface+/// removal so rotation keeps the orbit.+pub fn on_rotate_input(surface_id: i32, yaw_delta: f32, pitch_delta: f32) {+    if let Ok(mut eng) = engine().lock() {+        let prefs = eng.orbit.entry(surface_id).or_default();+        prefs.yaw += yaw_delta;+        prefs.pitch = (prefs.pitch + pitch_delta).clamp(-MAX_PITCH, MAX_PITCH);+        let (yaw, pitch) = (prefs.yaw, prefs.pitch);+        if let Some(state) = eng.surfaces.get_mut(&surface_id) {+            state.yaw = yaw;+            state.pitch = pitch;+        }+    }+}++/// Set whether a surface auto-orbits. The editor disables it on creation so+/// drag fully owns the camera; heroes leave it on. Never creates a phantom+/// surface entry — prefs persist and apply on (re)create.+pub fn set_auto_rotate(surface_id: i32, auto_rotate: bool) {+    if let Ok(mut eng) = engine().lock() {+        eng.orbit.entry(surface_id).or_default().auto_rotate = auto_rotate;+        if let Some(state) = eng.surfaces.get_mut(&surface_id) {+            state.auto_rotate = auto_rotate;+        }+    }+}+ /// Whether a surface's renderer is currently live. pub fn has_renderer(surface_id: i32) -> bool {     engine()@@ -198,17 +259,30 @@ unsafe fn ndk_log(_msg: &str, tag: &std::ffi::CString, text: &std::ffi::CString) #[cfg(not(target_os = "android"))] fn android_log(_msg: &str) {} -/// Preview camera: fixed-radius turntable looking at the upper body.+/// Preview camera: fixed-radius orbit looking at the upper body. ///-/// Mirrors kart `view_proj_for` (look_at_rh + perspective_rh via glam) with a-/// slow orbit so heroes show depth; the idle sway lives in the bone pass.-pub fn view_proj_for(width: u32, height: u32, time_s: f32) -> ([[f32; 4]; 4], [f32; 3]) {+/// Mirrors kart `view_proj_for` (look_at_rh + perspective_rh via glam). Heroes+/// use a slow time-based orbit so they show depth; the editor drives `yaw` /+/// `pitch` by drag and the avatar stays where left. Pitch raises/lowers the+/// eye (clamped native-side on input).+pub fn view_proj_for(+    width: u32,+    height: u32,+    time_s: f32,+    yaw: f32,+    pitch: f32,+    auto_rotate: bool,+) -> ([[f32; 4]; 4], [f32; 3]) {     let aspect = width.max(1) as f32 / height.max(1) as f32;-    let angle = time_s * 0.25;+    let angle = if auto_rotate { time_s * 0.25 } else { yaw };     // 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 eye = glam::Vec3::new(+        angle.sin() * radius,+        1.25 + pitch * radius * 0.5,+        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);@@ -244,10 +318,16 @@ pub unsafe fn create_renderer(     let w = width.max(1) as u32;     let h = height.max(1) as u32;     if let Ok(mut eng) = engine().lock() {+        let prefs = eng.orbit.get(&surface_id).copied().unwrap_or_default();         let state = eng.surface_mut(surface_id, w, h);         state.width = w;         state.height = h;         state.paused = false;+        // Restore the orbit across recreation (rotation keeps drag position+        // and the editor's auto-rotate opt-out).+        state.yaw = prefs.yaw;+        state.pitch = prefs.pitch;+        state.auto_rotate = prefs.auto_rotate;     }     let renderer = match unsafe { Renderer::select(window, width, height, w, h) } {         Ok(r) => r,@@ -311,7 +391,14 @@ pub fn tick_surface(surface_id: i32) {             return;         }         let t = state.started.elapsed().as_secs_f32();-        let (vp, cp) = view_proj_for(state.width, state.height, t);+        let (vp, cp) = view_proj_for(+            state.width,+            state.height,+            t,+            state.yaw,+            state.pitch,+            state.auto_rotate,+        );         let bones = compute_bone_matrices(&state.traits, &state.pose, t);         let skin = state.traits.skin_rgb();         (vp, cp, bones, skin, state.mesh_count, state.paused)
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 4873e5f2c1..73c699a76b 100644--- a/library/avatar/src/main/rust/src/lib.rs+++ b/library/avatar/src/main/rust/src/lib.rs@@ -14,7 +14,7 @@ pub mod renderer; pub mod vulkan;  use jni::objects::{JClass, JObject, JString};-use jni::sys::{jboolean, jint, jlong, jstring};+use jni::sys::{jboolean, jfloat, jint, jlong, jstring}; use jni::{Env, EnvUnowned};  #[cfg(target_os = "android")]@@ -223,6 +223,30 @@ pub extern "system" fn Java_com_vayunmathur_library_avatar_YuuAvatarNative_nativ     .resolve::<jni::errors::LogErrorAndDefault>() } +/// User drag-rotate delta for a surface (radians). Accumulates into the+/// surface's yaw/pitch; pitch clamps native-side.+#[no_mangle]+pub extern "system" fn Java_com_vayunmathur_library_avatar_YuuAvatarNative_nativeOnRotateInput<'l>(+    _env: EnvUnowned<'l>,+    _class: JClass<'l>,+    surface_id: jint,+    yaw_delta: jfloat,+    pitch_delta: jfloat,+) {+    engine::on_rotate_input(surface_id, yaw_delta, pitch_delta);+}++/// Set whether a surface auto-orbits (editor disables on creation).+#[no_mangle]+pub extern "system" fn Java_com_vayunmathur_library_avatar_YuuAvatarNative_nativeSetAutoRotate<'l>(+    _env: EnvUnowned<'l>,+    _class: JClass<'l>,+    surface_id: jint,+    auto_rotate: jboolean,+) {+    engine::set_auto_rotate(surface_id, auto_rotate != jni::sys::JNI_FALSE);+}+ /// Activity gone: destroy everything. #[no_mangle] pub extern "system" fn Java_com_vayunmathur_library_avatar_YuuAvatarNative_nativeOnDestroy<'l>(
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 1b510039bc..cef5afe4b5 100644--- a/library/avatar/src/main/rust/src/mesh.rs+++ b/library/avatar/src/main/rust/src/mesh.rs@@ -44,11 +44,24 @@ struct Part {     skin: bool, } -/// Push an axis-aligned box as skinned triangles into `out`.+/// Subdivisions per face edge for the rounded-box mesh (S=4 → visibly+/// round, ~7.5k verts total, fits both GPU budgets with no constant change).+const ROUND_SUBDIV: usize = 4;++/// Push a rounded axis-aligned box as skinned triangles into `out`.+///+/// Same `Part` contract as the old sharp box (centers/sizes, joint/blend,+/// skin/shirt UV split) but each face is subdivided `ROUND_SUBDIV ×+/// ROUND_SUBDIV` and pulled toward a rounded box: `p_clamped = clamp(p,+/// -half+r, half-r)`, `normal = normalize(p - p_clamped)`, `p' = p_clamped ++/// normal * r`, with `r = min(size) / 4`. Corners/edges round over, face+/// centers stay flat, and part centers never move (wave/idle test queries+/// still hit). fn box_skinned(out: &mut Vec<YuuVertex>, part: &Part) {     let (cx, cy, cz) = (part.center[0], part.center[1], part.center[2]);     let (sx, sy, sz) = (part.size[0] / 2.0, part.size[1] / 2.0, part.size[2] / 2.0);-    // 8 corners.+    let r = (part.size[0].min(part.size[1]).min(part.size[2]) / 4.0).max(0.005);+    // 8 corners of the sharp box.     let c = [         [cx - sx, cy - sy, cz - sz],         [cx + sx, cy - sy, cz - sz],@@ -59,33 +72,111 @@ fn box_skinned(out: &mut Vec<YuuVertex>, part: &Part) {         [cx + sx, cy + sy, cz + sz],         [cx - sx, cy + sy, cz + sz],     ];-    // 6 faces: (corners, normal).-    let faces: [([usize; 4], [f32; 3]); 6] = [-        ([0, 1, 2, 3], [0.0, 0.0, -1.0]),-        ([5, 4, 7, 6], [0.0, 0.0, 1.0]),-        ([4, 0, 3, 7], [-1.0, 0.0, 0.0]),-        ([1, 5, 6, 2], [1.0, 0.0, 0.0]),-        ([4, 5, 1, 0], [0.0, -1.0, 0.0]),-        ([3, 2, 6, 7], [0.0, 1.0, 0.0]),+    // 6 faces: corners + base UVs. Grid (iu, iv) walks each face so the+    // rounded push has vertices to move near edges/corners.+    let faces: [([usize; 4], [[f32; 2]; 4]); 6] = [+        ([0, 1, 2, 3], [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]),+        ([5, 4, 7, 6], [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]),+        ([4, 0, 3, 7], [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]),+        ([1, 5, 6, 2], [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]),+        ([4, 5, 1, 0], [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]),+        ([3, 2, 6, 7], [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]),     ];     let w0 = 1.0 - part.blend;-    for (corners, normal) in faces {-        // Simple planar UV per face.-        let uvs = [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]];-        let idx = [corners[0], corners[1], corners[2], corners[0], corners[2], corners[3]];-        let uv_idx = [0, 1, 2, 0, 2, 3];-        for k in 0..6 {-            out.push(YuuVertex {-                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, 0.0],-                weights: [w0, part.blend, 0.0, 0.0],-            });+    let s = ROUND_SUBDIV;+    for (corners, face_uv) in faces {+        // Bilinear grid over the quad, storing (rounded pos, smooth normal, uv).+        let mut grid: Vec<Vec<([f32; 3], [f32; 3], [f32; 2])>> = Vec::with_capacity(s + 1);+        for iy in 0..=s {+            let v = iy as f32 / s as f32;+            let mut row = Vec::with_capacity(s + 1);+            for ix in 0..=s {+                let u = ix as f32 / s as f32;+                // Bilinear interpolate corners and UVs.+                let mut p = [0.0f32; 3];+                let mut uv = [0.0f32; 2];+                let ws = [(1.0 - u) * (1.0 - v), u * (1.0 - v), u * v, (1.0 - u) * v];+                for k in 0..4 {+                    for a in 0..3 {+                        p[a] += ws[k] * c[corners[k]][a];+                    }+                    uv[0] += ws[k] * face_uv[k][0];+                    uv[1] += ws[k] * face_uv[k][1];+                }+                // Rounded-box push in part-local space.+                let local = [p[0] - cx, p[1] - cy, p[2] - cz];+                let half = [sx, sy, sz];+                let mut clamped = [0.0f32; 3];+                for a in 0..3 {+                    clamped[a] = local[a].clamp(-(half[a] - r), half[a] - r);+                }+                let n = rounded_normal_from_offset(local, clamped);+                let rounded = [+                    cx + clamped[0] + n[0] * r,+                    cy + clamped[1] + n[1] * r,+                    cz + clamped[2] + n[2] * r,+                ];+                let tinted = if part.skin {+                    [uv[0] * 0.25, uv[1] * 0.25]+                } else {+                    [0.5 + uv[0] * 0.5, uv[1] * 0.5]+                };+                row.push((rounded, n, tinted));+            }+            grid.push(row);+        }+        // Emit two triangles per grid cell with the smooth normals baked.+        for iy in 0..s {+            for ix in 0..s {+                let quad = [+                    grid[iy][ix],+                    grid[iy][ix + 1],+                    grid[iy + 1][ix + 1],+                    grid[iy + 1][ix],+                ];+                for k in [0, 1, 2, 0, 2, 3] {+                    let (pos, normal, uv) = quad[k];+                    out.push(YuuVertex {+                        pos,+                        normal,+                        uv,+                        joints: [part.joint, part.blend_joint, 0.0, 0.0],+                        weights: [w0, part.blend, 0.0, 0.0],+                    });+                }+            }         }     } } +/// Analytic rounded-box normal from a local offset and its clamped form.+/// Face interiors (zero offset) fall back to the dominant-axis flat normal.+fn rounded_normal_from_offset(local: [f32; 3], clamped: [f32; 3]) -> [f32; 3] {+    let mut n = [+        local[0] - clamped[0],+        local[1] - clamped[1],+        local[2] - clamped[2],+    ];+    let len = (n[0] * n[0] + n[1] * n[1] + n[2] * n[2]).sqrt();+    if len < 1e-6 {+        let mut ax = 0;+        let mut best = local[0].abs();+        for a in 1..3 {+            if local[a].abs() > best {+                best = local[a].abs();+                ax = a;+            }+        }+        let mut nn = [0.0f32; 3];+        nn[ax] = if local[ax] >= 0.0 { 1.0 } else { -1.0 };+        return nn;+    }+    n[0] /= len;+    n[1] /= len;+    n[2] /= len;+    n+}+ /// Joint index helper by name (0 when unknown — weighted to root). fn j(name: &str) -> f32 {     joint_by_name(name).map(|jj| jj as u32 as f32).unwrap_or(0.0)@@ -241,6 +332,12 @@ mod tests {     fn fallback_mesh_is_nonempty_and_weighted() {         let mesh = build_avatar_mesh();         assert!(!mesh.is_empty());+        // Rounded-box S=4 budget: 13 parts × 6 faces × 16 cells × 6 verts.+        assert!(+            mesh.len() <= 8_192,+            "mesh {} verts exceeds dynamic budget",+            mesh.len()+        );         for v in mesh.iter().take(64) {             let w: f32 = v.weights.iter().sum();             assert!((w - 1.0).abs() < 1e-4, "weights must sum to 1, got {w}");
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 e8b2c8330b..b22cba179d 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 17f5b621df..04de5fb30d 100644Binary files a/metadata_data/photos/games-hub/7.png and b/metadata_data/photos/games-hub/7.png differ