Remove the 3D toon Tai Chi characters

The owner wants Tai Chi drawn flat in 2D like Sun Salutation, not as 3D
figures; this reverts 3ef6a493.
This commit is contained in:
waozi committed 2026-10-15 20:39:14 -03:00
1 parent 525982013f
commit 6376ea6386
6 files changed
+23 -195

No files matched your search

-18
View File
@@ -76,24 +76,6 @@ still there.
drawings from the hand's shape and which way the palm faces. Back arms,
legs, head, torso and front arms are drawn in that order.
## Flat characters
Jade Woman (`?figure=jadeWoman`: dark hair in a bun with a light orange
tie, jade jacket, indigo trousers) and Lake Man (`?figure=lakeMan`: short
dark hair, lake-blue jacket, earth-brown trousers) are the 3D characters
drawn like a flat illustration, matching the flat Sun Salutation style
(`docs/sun-salutation-flat.md` in Inbe). They are looks in
`src/view/characters.js` with `flat: true`: two-tone toon materials
(`flatMaterial` in `src/view/figure.js`; cloth takes a clear shade, skin a
light one), calm closed eyes, and dark bands at the sleeve and trouser cuffs.
The stage's flat lighting turns the sky light off, makes ambient and sun add
up to π so the lit tone is the colour itself, and keeps the sun beside the
camera so the side you see is lit.
```sh
node tools/render.mjs --item lesson-1/all --figure jadeWoman --label --video --out ../../build/tai-chi-flat --name lesson-1-jade-woman
```
## How it works
- `src/rig.js`: proportions as fractions of height, per figure.
-2
View File
@@ -32,8 +32,6 @@ export const FIGURES = {
mannequin: { height: 1.70 },
sageBun: { height: 1.66, shoulderHalfWidth: 0.102, hipHalfWidth: 0.054 },
sageMale: { height: 1.78, shoulderHalfWidth: 0.114, hipHalfWidth: 0.050 },
jadeWoman: { height: 1.65, shoulderHalfWidth: 0.102, hipHalfWidth: 0.054 },
lakeMan: { height: 1.77, shoulderHalfWidth: 0.114, hipHalfWidth: 0.050 },
monk: { height: 1.72, shoulderHalfWidth: 0.1, hipHalfWidth: 0.052 },
tibetanWoman: { height: 1.62, shoulderHalfWidth: 0.098, hipHalfWidth: 0.056 },
}
+1 -5
View File
@@ -20,10 +20,7 @@ if (renderMode) {
document.body.classList.add('render')
}
const FIGURE_LABELS = {
mannequin: 'Mannequin', sageBun: 'Sage Bun', sageMale: 'Sage Male', jadeWoman: 'Jade Woman', lakeMan: 'Lake Man',
monk: 'Monk', tibetanWoman: 'Tibetan Woman',
}
const FIGURE_LABELS = { mannequin: 'Mannequin', sageBun: 'Sage Bun', sageMale: 'Sage Male', monk: 'Monk', tibetanWoman: 'Tibetan Woman' }
// Painted 2D characters: cut-out paintings over the same solved body.
const PAINTED = {
monk: 'characters/monk/character.json',
@@ -97,7 +94,6 @@ async function setFigure(name) {
painted.setBackground(THEMES[state.theme]?.background ?? THEMES.light.background)
} else {
figure = createFigure(rig, name, { theme: state.theme })
stage.setFlat(figure.flat)
stage.scene.add(figure.root)
ghost = createFigure(rig, name, { theme: state.theme })
ghost.setGhost(0.22)
+18 -110
View File
@@ -1,6 +1,4 @@
// The course characters: Sage Bun and Sage Male in loose Tai Chi clothes,
// and the flat Jade Woman and Lake Man, drawn in two tones like a flat
// illustration (calm closed eyes, dark sleeve cuffs; see flatMaterial).
// The course characters: Sage Bun and Sage Male in loose Tai Chi clothes.
//
// Cloth is skinned so it bends smoothly: the jacket follows the pelvis and
// the three spine pieces (its hem gives a little to the thighs), sleeves
@@ -14,7 +12,7 @@ import {
} from 'three'
import { standingPose } from '../pose.js'
import { solvePose } from '../solve.js'
import { FLAT_SHADE, addMesh, buildHand, curlHand, flatMaterial, material, registerStyle } from './figure.js'
import { addMesh, buildHand, curlHand, material, registerStyle } from './figure.js'
import { ellipsoid, taperedCapsule } from './parts.js'
const SIDES = ['L', 'R']
@@ -65,60 +63,6 @@ const LOOKS = {
neckRadius: 0.029,
handSize: 1.0,
},
jadeWoman: {
flat: true,
face: 'calm',
skin: 0xf1c7a6,
skinShade: 0xe0ad8c,
blush: 0xec9f8f,
lips: 0xc9806f,
eyes: 0x2a2238,
brows: 0x2a2238,
hair: 0x2a2238,
hairTie: 0xf2a65e,
jacket: 0x3f8f7a,
buttons: 0x2f705f,
cuff: 0x2e3d63,
trousers: 0x2e3d63,
trousersInside: 0x232f4d,
legCuff: 0x232f4d,
slipper: 0x2a2238,
sole: 0xeee8dc,
style: 'bun',
jacketShape: {
hem: 0.134, hip: 0.12, waist: 0.104, chest: 0.105, shoulder: 0.103,
hemDepth: 0.095, waistDepth: 0.073, chestDepth: 0.079, bust: 0.004,
},
neckRadius: 0.025,
handSize: 0.95,
},
lakeMan: {
flat: true,
face: 'calm',
skin: 0xd9a07c,
skinShade: 0xc68c69,
blush: null,
lips: 0xa8705c,
eyes: 0x2a2238,
brows: 0x2a2238,
hair: 0x2a2238,
hairTie: 0x2a2238,
jacket: 0x3f6f8f,
buttons: 0x2f5470,
cuff: 0x6e4c36,
trousers: 0x6e4c36,
trousersInside: 0x553a29,
legCuff: 0x553a29,
slipper: 0x2a2238,
sole: 0xeee8dc,
style: 'short',
jacketShape: {
hem: 0.126, hip: 0.116, waist: 0.105, chest: 0.111, shoulder: 0.114,
hemDepth: 0.09, waistDepth: 0.073, chestDepth: 0.08, bust: 0,
},
neckRadius: 0.029,
handSize: 1.0,
},
}
function clamp01(value) {
@@ -305,7 +249,6 @@ function buildCharacter(figure, rig, options, lookName) {
const look = LOOKS[lookName]
const H = rig.height
const g = figure.groups
figure.flat = Boolean(look.flat)
// A little self-light keeps faces warm on the dark stage instead of
// shading the chin like a beard.
const glow = (color, share) => {
@@ -314,33 +257,25 @@ function buildCharacter(figure, rig, options, lookName) {
const b = (color & 255) * share
return (Math.round(r) << 16) | (Math.round(g2) << 8) | Math.round(b)
}
// Flat looks keep only which faces they show; lit looks have their
// roughness and glow.
const surface = (color, extra = {}, shade = FLAT_SHADE.cloth) => (look.flat
? flatMaterial(figure, color, extra.side ? { side: extra.side } : {}, shade)
: material(figure, color, extra))
const skin = surface(look.skin, { roughness: 0.62, emissive: glow(look.skin, 0.16) }, FLAT_SHADE.skin)
const skinShade = surface(look.skinShade, { roughness: 0.65, emissive: glow(look.skinShade, 0.12) }, FLAT_SHADE.skin)
const skin = material(figure, look.skin, { roughness: 0.62, emissive: glow(look.skin, 0.16) })
const skinShade = material(figure, look.skinShade, { roughness: 0.65, emissive: glow(look.skinShade, 0.12) })
// On the dark stage, cloth and hair carry a little light of their own so
// the figure stays clear of the background.
const lift = options.theme === 'dark' ? 0.12 : 0
const cloth = (color, extra = {}) => surface(color, { roughness: 0.88, emissive: glow(color, lift), ...extra })
const cloth = (color, extra = {}) => material(figure, color, { roughness: 0.88, emissive: glow(color, lift), ...extra })
const jacket = cloth(look.jacket, { side: DoubleSide })
const sleeve = cloth(look.jacket)
const trousers = cloth(look.trousers, { roughness: 0.9 })
const trousersInside = cloth(look.trousersInside, { roughness: 0.92 })
const hair = cloth(look.hair, { roughness: 0.7 })
const hairTie = surface(look.hairTie, { roughness: 0.7 })
const dark = surface(look.eyes, { roughness: 0.4 })
const brows = surface(look.brows, { roughness: 0.8 })
const lips = surface(look.lips, { roughness: 0.6 })
const white = surface(0xffffff, { roughness: 0.3 })
const buttons = surface(look.buttons, { roughness: 0.6 })
const slipper = surface(look.slipper, { roughness: 0.85 })
const sole = surface(look.sole, { roughness: 0.9 })
const blush = look.blush ? surface(look.blush, {}, FLAT_SHADE.skin) : null
const cuff = look.cuff !== undefined ? surface(look.cuff, { side: DoubleSide }) : null
const legCuff = look.legCuff !== undefined ? surface(look.legCuff, { side: DoubleSide }) : null
const hairTie = material(figure, look.hairTie, { roughness: 0.7 })
const dark = material(figure, look.eyes, { roughness: 0.4 })
const brows = material(figure, look.brows, { roughness: 0.8 })
const lips = material(figure, look.lips, { roughness: 0.6 })
const white = material(figure, 0xffffff, { roughness: 0.3 })
const buttons = material(figure, look.buttons, { roughness: 0.6 })
const slipper = material(figure, look.slipper, { roughness: 0.85 })
const sole = material(figure, look.sole, { roughness: 0.9 })
// Bind pose: the standing pose, solved for this figure.
const rest = solvePose(standingPose(), rig)
@@ -486,12 +421,6 @@ function buildCharacter(figure, rig, options, lookName) {
// Shoulder cap and elbow filler, rigid.
addMesh(g[`upperArm${side}`], new SphereGeometry(0.03 * H, 20, 14), sleeve, [0, -0.022 * H, 0])
addMesh(g[`foreArm${side}`], new SphereGeometry(0.031 * H, 16, 12), sleeve)
// A dark band at the end of the sleeve, like a lined wide cuff.
if (cuff) {
const band = 0.026 * H
addMesh(g[`foreArm${side}`], new CylinderGeometry(0.0318 * H, 0.0322 * H, band, 28, 1, true), cuff,
[0, -(rig.foreArm - 0.012 * H - band / 2), 0])
}
// Inside of the cuff and the wrist.
addMesh(g[`hand${side}`], taperedCapsule(0.0165 * H, 0.0175 * H, 0.03 * H, 14), skin, [0, 0.028 * H, 0])
buildHand(figure, side, g[`hand${side}`], rig, skin, look.handSize)
@@ -514,11 +443,6 @@ function buildCharacter(figure, rig, options, lookName) {
addMesh(g[`shin${side}`], new SphereGeometry(0.041 * H, 18, 12), trousers, [0, 0.002 * H, 0.002 * H])
// Ankle under the cuff.
addMesh(g[`shin${side}`], taperedCapsule(0.022 * H, 0.021 * H, 0.03 * H, 12), trousersInside, [0, -rig.shin + 0.03 * H, 0])
if (legCuff) {
const band = 0.03 * H
addMesh(g[`shin${side}`], new CylinderGeometry(0.0335 * H, 0.0335 * H, band, 28, 1, true), legCuff,
[0, -rig.shin + 0.006 * H + band / 2, 0])
}
// Slipper: cloth upper and pale sole; the toe box bends at the ball.
const foot = g[`foot${side}`]
@@ -535,7 +459,7 @@ function buildCharacter(figure, rig, options, lookName) {
// Neck and head.
addMesh(g.neck, taperedCapsule(look.neckRadius * H, look.neckRadius * H * 1.05, 0.05 * H, 16), skin, [0, 0.045 * H, 0.002 * H])
buildHead(figure, rig, look, { skin, skinShade, hair, hairTie, dark, brows, lips, white, blush })
buildHead(figure, rig, look, { skin, skinShade, hair, hairTie, dark, brows, lips, white })
figure.updateHand = (side, shapeWeights) => curlHand(figure, side, shapeWeights)
figure.afterUpdate = (solved) => {
@@ -564,27 +488,13 @@ function buildHead(figure, rig, look, mats) {
const share = 1 - Math.pow((x - skull.x) / skull.rx, 2) - Math.pow((y - skull.y) / skull.ry, 2)
return skull.z + skull.rz * Math.sqrt(Math.max(share, 0))
}
const calm = look.face === 'calm'
for (const sign of [1, -1]) {
const x = sign * 0.021 * H
const y = 0.066 * H
if (calm) {
// Closed, peaceful eyes: a thin arc curving down, and a blush.
const eye = addMesh(head, new TorusGeometry(0.0078 * H, 0.0013 * H, 6, 18, Math.PI * 0.7), mats.dark,
[x, y + 0.004 * H, faceZ(x, y) + 0.0002 * H])
eye.rotation.set(0, sign * 0.32, Math.PI * 1.15)
if (mats.blush) {
const cheek = addMesh(head, ellipsoid(0.0085 * H, 0.0062 * H, 0.003 * H, 14, 10), mats.blush,
[sign * 0.031 * H, 0.049 * H, faceZ(sign * 0.031 * H, 0.049 * H) - 0.0012 * H])
cheek.rotation.y = sign * 0.55
}
} else {
const eye = addMesh(head, ellipsoid(0.0072 * H, 0.0098 * H, 0.004 * H, 16, 12), mats.dark, [x, y, faceZ(x, y) - 0.0016 * H])
eye.rotation.y = sign * 0.32
addMesh(head, new SphereGeometry(0.0022 * H, 8, 6), mats.white, [x + 0.0025 * H, y + 0.0035 * H, faceZ(x, y) + 0.0018 * H])
}
const browRadius = calm ? 0.0012 * H : 0.0019 * H
const brow = addMesh(head, taperedCapsule(browRadius, browRadius * 0.85, 0.016 * H, 8), mats.brows,
const eye = addMesh(head, ellipsoid(0.0072 * H, 0.0098 * H, 0.004 * H, 16, 12), mats.dark, [x, y, faceZ(x, y) - 0.0016 * H])
eye.rotation.y = sign * 0.32
addMesh(head, new SphereGeometry(0.0022 * H, 8, 6), mats.white, [x + 0.0025 * H, y + 0.0035 * H, faceZ(x, y) + 0.0018 * H])
const brow = addMesh(head, taperedCapsule(0.0019 * H, 0.0016 * H, 0.016 * H, 8), mats.brows,
[x - sign * 0.008 * H, y + 0.0185 * H, faceZ(x, y + 0.018 * H) - 0.0006 * H])
brow.rotation.set(0, sign * 0.3, sign * (Math.PI / 2 + 0.12))
// Ears.
@@ -625,5 +535,3 @@ function buildHead(figure, rig, look, mats) {
registerStyle('sageBun', (figure, rig, options) => buildCharacter(figure, rig, options, 'sageBun'))
registerStyle('sageMale', (figure, rig, options) => buildCharacter(figure, rig, options, 'sageMale'))
registerStyle('jadeWoman', (figure, rig, options) => buildCharacter(figure, rig, options, 'jadeWoman'))
registerStyle('lakeMan', (figure, rig, options) => buildCharacter(figure, rig, options, 'lakeMan'))
+1 -30
View File
@@ -4,8 +4,7 @@
// local frame (see solve.js); `update` copies the solved world transforms.
import {
BoxGeometry, DataTexture, Group, Mesh, MeshStandardMaterial, MeshToonMaterial, NearestFilter,
RedFormat, SphereGeometry,
BoxGeometry, Group, Mesh, MeshStandardMaterial, SphereGeometry,
} from 'three'
import { ellipsoid, taperedCapsule } from './parts.js'
@@ -104,34 +103,6 @@ export function material(figure, color, extra = {}) {
return made
}
// Flat characters are drawn in two tones, like a flat illustration: their
// colour where the surface faces the light, and one shade where it turns
// away, with a hard edge between. The stage's flat lighting (see stage.js)
// makes the lit tone the colour itself.
// `shade` is how much of the sun the shaded side keeps: cloth turns a clear
// step darker, skin only a little, so faces never look smudged.
export const FLAT_SHADE = { cloth: 0.58, skin: 0.8 }
const flatSteps = new Map()
function flatGradient(shade) {
if (!flatSteps.has(shade)) {
const value = Math.round(shade * 255)
const steps = new DataTexture(new Uint8Array([value, value, value, value, 255, 255, 255, 255]), 8, 1, RedFormat)
steps.minFilter = NearestFilter
steps.magFilter = NearestFilter
steps.generateMipmaps = false
steps.needsUpdate = true
flatSteps.set(shade, steps)
}
return flatSteps.get(shade)
}
export function flatMaterial(figure, color, extra = {}, shade = FLAT_SHADE.cloth) {
const made = new MeshToonMaterial({ color, gradientMap: flatGradient(shade), ...extra })
figure.materials.push(made)
return made
}
export function addMesh(group, geometry, mat, position = [0, 0, 0], rotation = null) {
const mesh = new Mesh(geometry, mat)
mesh.position.set(position[0], position[1], position[2])
+3 -30
View File
@@ -6,10 +6,6 @@ import {
RepeatWrapping, Scene, SRGBColorSpace, Vector3, WebGLRenderer,
} from 'three'
// Share of the flat characters' light that comes from everywhere; the
// rest comes from the sun beside the camera.
const FLAT_AMBIENT = 0.45
export const THEMES = {
light: {
background: '#f1ece0',
@@ -100,14 +96,12 @@ export function createStage(canvas, { preserveDrawingBuffer = false } = {}) {
const overlay = new Group()
scene.add(overlay)
const center = new Vector3()
const stage = {
renderer,
scene,
camera,
overlay,
theme: 'light',
flat: false,
setTheme(name) {
const theme = THEMES[name] ?? THEMES.light
stage.theme = name
@@ -123,27 +117,11 @@ export function createStage(canvas, { preserveDrawingBuffer = false } = {}) {
hemi.intensity = theme.hemiIntensity
sun.color.set(theme.sun)
sun.intensity = theme.sunIntensity
stage.setFlat(stage.flat)
},
// Flat characters (see figure.js) take their colours unchanged
// where they face the light: the sky light is off, and the ambient
// and sun add up to π, which cancels Lambert's 1/π. The sun then
// shines from beside the camera, so the side you see is lit and
// only the edges turning away take the shade.
setFlat(flat) {
stage.flat = flat
const theme = THEMES[stage.theme] ?? THEMES.light
hemi.intensity = flat ? 0 : theme.hemiIntensity
ambient.intensity = flat ? Math.PI * FLAT_AMBIENT : 0.15
sun.intensity = flat ? Math.PI * (1 - FLAT_AMBIENT) : theme.sunIntensity
sun.shadow.radius = flat ? 8 : 4
sun.shadow.intensity = flat ? 0.45 : 1
},
// Keeps the light and its shadow box over the figure.
follow(point) {
center.copy(point)
sun.target.position.copy(point).setY(0)
sun.position.copy(point).add(new Vector3(2.5, 6, 3.5))
follow(center) {
sun.target.position.copy(center).setY(0)
sun.position.copy(center).add(new Vector3(2.5, 6, 3.5))
},
resize(width, height) {
renderer.setSize(width, height, false)
@@ -151,11 +129,6 @@ export function createStage(canvas, { preserveDrawingBuffer = false } = {}) {
camera.updateProjectionMatrix()
},
render() {
if (stage.flat) {
const toCamera = camera.position.clone().sub(center).setY(0).normalize()
const right = new Vector3(toCamera.z, 0, -toCamera.x)
sun.position.copy(center).addScaledVector(toCamera, 4.5).addScaledVector(right, 2).setY(center.y + 2.6)
}
renderer.render(scene, camera)
},
}