Skip to content

Latest commit

 

History

History
207 lines (192 loc) · 18.5 KB

STYLE.md

File metadata and controls

207 lines (192 loc) · 18.5 KB

STYLE.md — PSX Character Creator

Goal: a character creator in the style of the reference screenshots in /refs (cute chibi PSX low-poly, paper-like hair planes, pixel faces), with extra Y2K / NewJeans-inspired fashion packs.

1. Rendering (PSX)

  • Render the 3D scene to a low-res WebGLRenderTarget (default 480x360, configurable), upscale to screen with NearestFilter. Keep aspect ratio.
  • Vertex snapping: in the vertex shader, after projection, snap xy to a grid: floor(clip.xy/clip.w * RES) / RES * clip.w (RES ~ 160-240; uniform).
  • Affine-like texture warp: optional uniform affine (default 0.5) mixing perspective-correct and affine UV.
  • Textures: NearestFilter, no mipmaps, no anisotropy. Sizes: face 128x128, patterns 32x32.
  • Lighting: Gouraud/Lambert, one directional + ambient. No shadows, no PBR, no bloom.
  • Optional post: colour quantization + dither (uniform, default OFF).
  • Background of the page UI is NOT rendered in 3D (CSS checkerboard). Canvas has transparent background.

2. Character body

  • Chibi proportion: head ~ 1/3 of total height. Head is a rounded low-poly box (about 8-12 faces per side group), not a smooth sphere.
  • Parts (separate meshes): head, torso, armL, armR, handL, handR, legL, legR, footL, footR. Feet are carried by the shoe's sole slab: the foot skin spans y 0.02..0.15 (lifted inside every sole plate) so no pose can show skin through a sole; bare state reads the same from the fixed top-down camera.
  • Body triangle budget: <= 800 total (excluding hair/clothes/accessories).
  • Colouring: vertex-colour vertical gradient (lighter top -> darker bottom, ~15-25% darker) on skin, clothes, hair. Gradient strength is a uniform.
  • Default pose: slight A-pose, arms out ~25 degrees. No animation required except auto-rotation (turntable).
  • Skin colour is user-selectable (colour picker + 8 presets).

3. Face system

  • One 128x128 canvas texture on the face quad of the head, composed of 3 layers: skin base -> eyes layer -> mouth layer. Optional blush layer.
  • Eyes: 12 styles (round, half-lidded, angry-brow, sleepy-brow, droopy, blush-closed arcs, "u u", ">_<", pill, dot, spiral, flat-closed). Mouth: >= 6 styles (smile, cat-mouth, flat, open, small-o, tongue-out).
  • Drawn procedurally on canvas with a limited palette (<= 16 colours), 1-2 px black pixel outline, no anti-aliasing (ctx.imageSmoothingEnabled = false, draw at 32x32 then upscale 4x).
  • Eyes are large (about half of the face width in total).
  • Changing a choice only redraws the canvas and sets needsUpdate = true.

4. Hair (11 styles + none)

  • Built from several flat double-sided planes/strips ("paper" look) with jagged edges. Not volumetric.
  • <= 150 triangles each. Single colour with vertex gradient; colour user-selectable.
  • IDs: hair_01 ... hair_11 (see catalog.json for descriptions). Option 0 = none.

5. Clothes, shoes, accessories

  • All items defined in catalog.json with: id, slot, label, tags (style packs), colorSlots, anchor/coverage, maxTris, pattern.
  • Slots: top, outer (layered over top), bottom, socks, shoes, hair, headwear, eyewear, neck, waist, wrist, bag.
  • Every colour slot is user-selectable. Patterns (plaid, stripes, star, denim wash, pleats) are generated on a 32x32 canvas with Nearest sampling; the pattern uses colorSlot[0] as main and colorSlot[1] as secondary.
  • Cropped tops: expose a strip of skin at the waist. Low-rise bottoms: lower waistline to hip so skin shows between top and bottom.
  • Pleated skirts: 6-8 vertical planes (not a smooth cone). Wide pants: tapered boxes, wider at ankle.
  • Logos/crests/stars are 32x32 canvas decals, ORIGINAL designs only.
  • Layering rules: outer hides nothing but must be slightly larger (scale 1.04-1.08) than top. Bottom hides legs under it. Socks drawn under shoes.

6. Style packs (tags) and presets

  • preppy: plaid pleated skirt, tennis skirt, cropped knit vest, polo, blazer with crest, white long socks, white sneakers, choker.
  • street: wide cargo pants, off-shoulder crop top, beanie, platform sneakers, big sunglasses.
  • denim: low-rise jeans, denim shirt, denim jacket, baguette bag.
  • sport: crop jersey, knee socks, sneakers.
  • colorblock: monochrome set; "auto colour-block" button picks one hue and derives shades for top/bottom/shoes.
  • Presets list is in catalog.json -> "presets". UI shows a "Style" tab to apply a preset in one click.

7. UI (match screenshots)

  • Page background: yellow/orange checkerboard (CSS), orange frame border (~10px).
  • Title text: pixel font, red with dark drop shadow (use a free pixel font or CSS text-shadow with image-rendering: pixelated; no copying of site assets).
  • Left: a pink vertical column of round thumbnails = currently selected items of the active category. Next to it a coloured panel (colour changes by category) with a title and a 2-column grid of round thumbnail buttons.
  • Bottom: 5 round category buttons: Face (eye icon, orange), Head (hair/headwear, green), Top (blue), Bottom (purple), Shoes (pink). Extra tabs allowed for Accessories and Style presets, same visual language.
  • Top right: three buttons: AUTO ROTATION (pink), RANDOM (purple), RESET (orange).
  • Colour picker for every selected item (swatch row + custom input).
  • Rotation: mouse drag, arrow keys, A/D, touch drag. Auto-rotation toggle.
  • Layout must work in portrait mobile (panel collapses to bottom sheet).
    • Portrait phones: the 3D preview and the bottom sheet split the free height below the top bar 50:50 (a small floor keeps the sheet usable on very short screens). The sheet lays the thumbnail grid and the colour/pose column side by side (Pose gets a wider right column) with CONFIRM / EXPORT / IMPORT / GLB on a full-width bottom row.
    • The category bar spans the full width and wraps to two rows.
    • The AUTO ROTATION button stays visible/reachable in portrait.
    • Touch hit-pockets (pointer: coarse) must be anchored to their own button. Every button is position: relative so a pocket can never expand to a parent and swallow its neighbours' taps.
    • Covered by npm run mobile (tests/mobileLayout.mjs): hit targets, 50:50 ratio, no panel overlap, and tap routing on 390/360/320 phones.
  • Thumbnails: render each item once to an offscreen canvas at 64x64 (or draw procedural icons) and cache.
  • UI layout follows ui-psx-mockup.png

8. Config / save format

{
  "skin": "#f5d5bf", "eyes": 3, "mouth": 1,
  "hair": {"id": "hair_07", "color": "#ffffff"},
  "headwear": null, "eyewear": null,
  "top": {"id": "top_jacket", "colors": ["#9b4d6f"]},
  "outer": null,
  "bottom": {"id": "bot_long_skirt", "colors": ["#3a5ca8"]},
  "socks": null,
  "shoes": {"id": "shoe_sneaker", "colors": ["#e8913a"]},
  "neck": null, "waist": null, "wrist": null, "bag": null
  "pose": {"preset": "pose\_default", "custom": null}
}

Saved to localStorage key psxcc.v1. Export/import as JSON file.

9. Acceptance checklist (use after every milestone)

  • Rendering looks low-res and pixelated; vertex wobble visible when rotating.
  • Head is ~1/3 of height; body parts are simple tapered boxes.
  • Colours show vertical gradients, no smooth PBR highlights.
  • Faces are crisp pixels with black outlines.
  • Hair looks like flat paper strips.
  • Every item has a colour option; changes apply instantly.
  • UI matches layout in /refs (checkerboard, orange frame, pink left column, 5 bottom buttons, 3 top-right buttons).
  • Works on mobile portrait; keyboard/mouse/touch rotation OK.
  • Triangle budgets respected (log counts in console in dev mode).
  • No copied assets, no real brand logos.
  • (M6.5) Rendering low-res/pixelated ✓; head ~1/3 ✓; gradients ✓; face crisp ✓; paper hair ✓; colour options ✓; UI layout ✓; mobile portrait ✓; triangle budgets unchanged (rig split +12 tris/leg, sleeves unchanged) ✓; no copied assets ✓.
  • (M7) State: STYLE.md §8 save format (colour arrays indexed by colorSlots) in localStorage psxcc.v1; validated import (unknown id -> none / default hair, invalid hex -> default, eyes/mouth range-checked, pose sanitized); RANDOM fills every colour slot + skin palette + random pose preset; RESET restores defaults; selection (colours) preserved on item switch; JSON file export/import; dev-only state inspector (?debug=state). Verified by tests/m7State.mjs (34 checks) + desktop/mobile shots.
  • (M8) Photo Studio + GLB export: PSX/Clean captures through a dedicated offscreen render pipeline (never the DOM); nearest upscale proven by pixel-identity test (4x ds == 1x); real alpha (corner 0); PSX/Clean/aspect/scale matrix exact; 4096 cap + clamp; turnaround with one shared scale; GLB = baked unlit vertex colours + embedded decal textures + posed joint hierarchy, loads back via GLTFLoader (36 meshes); capture prefs in psxcc.capture.v1; P/Esc; clipboard blocked -> toast + fallback download; 20 repeated captures heap-stable; mobile full-screen sheet. Verified by tests/m8Capture.mjs (34 checks) + shots.
  • (M9) OBJ exports: display "OBJ + textures (.zip)" (per-slot objects, relative MTL refs, face mapped ON the head via face.png, decal planes dropped, Kd white + "v x y z r g b" screen-colour extension, zip members = obj/mtl/PNGs) and print "OBJ for 3D printing" (single merged mm mesh, Y-up, feet y=0, ±0.5mm height window, ceiling/geometry-only/single colours 0..1, mesh-check report shells/open/nm/flipped/winding/wall/bbox with no printability claim; closed thin shells thicken PER SHELL — shell-local bbox + shell-only triangles). Export modal behind the GLB button (FORMAT / HEIGHT / THICKNESS / COLOUR / ROUND BASE / CONNECT FEET), mobile sheet, pixel toasts, all local. Verified by tests/m9Export.mjs (23), m9Print.mjs (33), m9Characters.mjs (8 characters incl. cat ears, plaid pleats, cargo+cap, bag flap + glasses, blazer + white sneakers, raised-arm and tilt+twist poses), m9Face.mjs (11: the exported face image carries the skin base + eye/mouth features on both the GLB and the zip) + export-panel shots.

11. M8 Photo Studio / captures / GLB (final state)

  • Camera button (#btnCamera) sits in the top bar beside RANDOM/RESET; the Photo Studio modal shares the wood/bevel/pill UI language; mobile = full-screen sheet with the options list scrollable. P opens, Esc closes, focus returns.
  • CAPTURES ARE NEVER TAKEN FROM THE VISIBLE UI: a dedicated offscreen WebGLRenderer renders the same scene; DOM overlays can not leak in. PSX look = base 480-wide low-res buffer + nearest (proven by the 4x-ds == 1x pixel identity test); Clean look = same scene straight at full output res (vertex-snap uniform raised during the pass and restored). Alpha is real: clear colour (0,0,0,0), no AA, opaque/discarded decals, so PNG corners read alpha 0 exactly.
  • Auto-framing uses Box3 of the visible set (character + optional platform + optional shadow blob) with ~7% margin (+16% bottom band when the name text is on); front yaws the root to 0, side +-90, back 180 (saved + restored synchronously, the live loop never sees the mutation).
  • Sizes: base width 480 x per-aspect height, x1/2/4 (nearest); client-requested scales outside 1/2/4 clamp to the nearest step; the longest side hard-caps at 4096 with a pixel toast when reduced. Turnaround renders all three views at ONE shared distance (max of per-view fits) so the sheet keeps a consistent scale.
  • GLB export (v2) bakes a one-off clone that keeps the FULL POSED JOINT HIERARCHY: vertices stay in LOCAL space (matrixWorld is only sampled for the per-vertex colour), local transforms are copied verbatim, and the colour contract follows the glTF spec — COLOR_0 = srgbToLinear(screen colour), screen colour = uniform x world-Y gradient x Lambert (map surfaces carry the gradient x lighting scalar; embedded PNGs stay byte-perfect). Materials: unlit MeshBasicMaterial, side/transparency carried from the source, missing normals computed for paper strips. Stage platform only when toggled. The runtime pixel shader / post pipeline is NOT stored in the GLB (UI note). Fidelity gate: tests/m8GlbViewer.mjs (npm run m8glb) reloads the GLB with DEFAULT colour management (standard-viewer behaviour) and pixel-compares against the on-page capture: mean dRGB < 2.5/255, <1.5% pixels over 32.
  • Capture preferences live in localStorage psxcc.capture.v1 (background/solid/ look/scale/aspect), sanitized with defaults; they never enter psxcc.v1.
  • Exports stay local: no upload, no clipboard network; blocked clipboard falls back to a download with a pixel error toast + RETRY.

10. Pose system (M6.5)

  • Joint hierarchy of THREE.Groups (root → hips → waist → chest → neck → head; chest → shoulder → elbow; hips → thigh → knee → foot). No skinning, no skeletal libraries.
  • Pivots at true joints; fixed rotation order (root YXZ, joints ZXY); all angles clamped to LIMITS.
  • 9 presets in catalog.json ("poses"): default, wave, hands on hips, peace, walk, run, salute, arms up, sit. Interpolated over ~0.25 s at 12-15 fps steps on switch; sliders apply immediately.
  • Pose tab: preset grid with cached 64x64 chibi stick-figure thumbs; manual sliders grouped (Body / L arm / R arm / L leg / R leg) with numeric readout + reset dot; MIRROR / SYMMETRY / RESET pose buttons.
  • Slider edits switch config to preset "custom" seeded from the last preset; MIRROR copies one arm/leg to the other (twist sign flipped).
  • Collision guard (analytic, no physics): palm tip + forearm mid tested against head box and torso volume; foot toe/heel vs the thigh tube (deep knee folds unfold); negative spread that crosses the feet closes back. The ankle has NO articulation: foot.rotation.x = 0 — the foot plate and every shoe piece riding the foot joint are a rigid continuation of the shin, so a folding shin can never slice through the foot plate or the sole (the old ground-parallel counter-rotation tilted the shoe away from the shin and made the shin's end ring sweep through the sole; a ground-parallel foot is no longer a goal).
  • Knee cloth pieces (pant tubes / socks / boot shafts): the shin piece nests RIG.kneeOver (0.12) inside the thigh piece's expanding extension so a ~90° fold never opens a wedge that shows the knee (boot shafts use the same overlap).
  • Clothing follows the rig: tagged pieces re-parented to joints at rest with world-preserving attach() (sleeves → shoulder, torso shells (top/outer) → waist so they twist with the trunk, pant tubes + socks + boot shafts split at the knee, shoe foot-fitting pieces (body/sole/toe/strap) → ANKLE joint where they share the shin's frame, cuffs/shafts → shin). The hips block mirrors the trunk's own torsoW curve (+0.03 margin) so the pant pelvis covers the trunk's hips rows whenever the tubes swing away. Skirt cones and pant tubes flare (scale x/xz up to ~1.25) with leg spread AND forward lean; long hair shifts back when arms are raised.
  • Trunk rows span 0.58..1.18 exactly like every clothing shell (torsoGeo rows profile-locked); waistTwist rotates trunk and shirt together, so no row can slide out of its shell silhouette. Regression tools: tests/poseProbe.mjs (per-vertex OBB exposure scan, all presets × outfits) and tests/poseAudit.mjs (canvas-only pose screenshots).
  • Sit preset folds legs within slider clamps + internal drop 0.12 (keeps feet on the ground; long skirt hides the fold).
  • Preset "custom" saved in config; old saves (no pose key) load as pose_default. RANDOM picks a random preset (not random sliders); RESET returns to pose_default.

12. M9 exports — OBJ + 3D print (final state)

  • The GLB button (#btnGlb) is retitled "Export GLB / OBJ" and opens ONE Export modal (PSX modal language, Esc/backdrop/X close, focus restored). Views: FORMAT (GLB / OBJ+TEX / OBJ PRINT), HEIGHT 50/80/100/150 mm (default 80), THICKNESS 0.8/1.2/2 (default 1.2), COLOUR FULL/SINGLE, ROUND BASE and CONNECT FEET toggles (print rows hidden for GLB/OBJ+TEX), the slicer note, and a print-only MESH CHECK report view (measured numbers + DOWNLOAD/BACK + in-modal pixel toasts). Nothing uploads; downloads go through the shared blob saver. Report honesty: measured shells/open/nm/flipped/wall/bbox only, no printability claim; overlapping shells allowed and counted.
  • Face handling (all three formats): the UI keeps its two decal planes for the live renderer, but every EXPORT drops them and maps the combined face canvas (skin + blush + eyes + mouth, 128px opaque) ONTO the head surface via an export-only head rebuild (exportFace.js: front-face triangles get decal-rect UVs, triangles re-grouped [face|skin]). FACE_RECT is the shared constant, so geometry and pixels can never drift apart. The skin base fill accepts CSS "#rrggbb" and THREE's bare "rrggbb" (canvas silently ignores an invalid fillStyle and would keep its default BLACK — the M9 export black-face bug).
  • Display OBJ zip: one object per slot tag (head/hair/top/... in SLOT_ORDER order, body items merged per slot), baked world transforms (turntable yaw included), vt+vn present, "v x y z r g b" carries the raw screen colour (base x gradient x Lambert), Kd stays pure WHITE so viewers tint nothing twice, map_Kd + -clamp on with RELATIVE paths only, textures kept at their ORIGINAL canvas resolution (nearest look preserved). Filenames psx-character-<name>-display-<YYYYMMDD-HHMM>.zip.
  • Print OBJ: bakeClone(raw + neutral yaw) -> mm scale to the requested height -> per-shell manufacture: open sheets rim-solidified (outer surface exact, thickness inward), closed thin boxes thinnest-axis scaled PER SHELL (the scale reads the shell's own bbox and emits only that shell's triangles), closed solids kept — the head too, but its FACE region samples the canvas, so a uniform k-lattice runs on ALL head tris (T-junction-free) within a 20k triangle budget. Optional 3mm base disc (top = y0) + foot bridge, feet plane y=0, origin at base centre. Colour = canvas/pattern sample x baked ramp; SINGLE prints plain "v x y z" (no colour). Filenames psx-character-<name>-print-<height>mm-<YYYYMMDD-HHMM>.obj.
  • Mesh-check contract: analyseMeshes welds with the same 1e-4 mm buckets the printed file carries (the report measures the delivered topology, not a pre-rounding fiction), reports tris/verts/shells/open/nm/flipped/winding/ bbox/min-wall and pose-aware support warnings (BODY TILT / RAISED ARM / BENT KNEE / SIT POSE). One known list entry: two hair strand slabs share an exact edge (PSX slab style) — reads as 1 non-manifold edge, harmless to slicers' repair steps.
  • Regression gates: tests/m9Export.mjs (zip contract + OBJLoader re-import bbox vs the live scene), tests/m9Print.mjs (mm/height/topology/colour/ warnings/determinism), tests/m9Characters.mjs (8 characters through both formats, incl. the thin-shell kit that used to break the print export). Probe scripts from development are removed.