Sun Salutation drawn like the studio's 3D woman: a seat under a draped top
A three.js body lab (design/tai-chi/sun-salutation.html, tools/sun-salutation.mjs) plays the app's exact Sun Salutation motion, exported by render-sun-salutation-live.py --motion, on the studio's skinned 3D woman in the app's look. There the long top drapes over the hips and a seat ellipsoid sits inside it, which looks natural in every pose. The app now draws her the same way: the slimmer top at the Jade woman's length over one seat ellipsoid on the pelvis, in place of separate buttock shapes.
This commit is contained in:
1 parent
8675cbdee3
commit
4276dbbf75
11 files changed
+419
-30
No files matched your search
@@ -86,3 +86,6 @@ design/sun-salutation/girl-parts/head-layers-check.png
|
||||
/design/promo-film/
|
||||
/design/videos/
|
||||
/design/lumi-promo/
|
||||
|
||||
# Sun Salutation motion exported for the three.js lab (render-sun-salutation-live.py --motion).
|
||||
/design/tai-chi/lab/
|
||||
@@ -38,16 +38,17 @@ SunSalutationWomanLook :: () -> TaiChiFlatLook {
|
||||
look.blush_alpha = 0.3
|
||||
// The band round her bun is a darker auburn, not a bright tie.
|
||||
look.accent = 0x5a2818
|
||||
// A fitted tunic without a flared hem, slim sleeves and trousers over
|
||||
// rounded hips, and finer hands and feet.
|
||||
TaiChiFlatJacket(*look, 0.106, 0.102, 0.09, 0.097, 0.1, 0.064, 0.062, 0.071, 0.006)
|
||||
// The top ends at the hips and lies over the seat, set back with it.
|
||||
TaiChiFlatJacketRow(*look, 0, 0.53, 0.106, 0.06, -0.012)
|
||||
TaiChiFlatJacketRow(*look, 1, 0.54, 0.105, 0.06, -0.009)
|
||||
TaiChiFlatJacketRow(*look, 2, 0.55, 0.102, 0.06, -0.006)
|
||||
// A slimmer top of the Jade woman's length over a seat inside it, as the
|
||||
// studio's 3D figure wears them (design/tai-chi, the sunWoman look), and
|
||||
// finer hands and feet than the cartoon figure's.
|
||||
TaiChiFlatJacket(*look, 0.112, 0.106, 0.09, 0.097, 0.1, 0.075, 0.062, 0.071, 0.006)
|
||||
look.jacket_from = look.jacket[0][0]
|
||||
look.limbs = 0.92
|
||||
look.glutes = true
|
||||
look.seat[0] = 0.088
|
||||
look.seat[1] = 0.058
|
||||
look.seat[2] = 0.06
|
||||
look.seat[3] = -0.03
|
||||
look.seat[4] = -0.008
|
||||
look.hand_size = 0.92
|
||||
look.foot_length = 0.85
|
||||
look.foot_depth = 0.8
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
// Sun Salutation on the studio's skinned 3D woman, to design her body in
|
||||
// real 3D before the app's flat painter draws it.
|
||||
//
|
||||
// The motion is the app's own: every frame of the solved skeleton exported
|
||||
// by `scripts/render-sun-salutation-live.py --motion` from the Ziran pose
|
||||
// solver. This page turns those joints into the studio's segment frames and
|
||||
// plays them on a skinned studio character (the app's woman by default), in
|
||||
// the app's camera or an orbit.
|
||||
//
|
||||
// Query: ?t=SECONDS to start there, ?camera=app|side|back|front|orbit,
|
||||
// ?figure=sunWoman|sageBun|sageMale,
|
||||
// ?render=JOB&stills=T1,T2 to post stills to tools/sun-salutation.mjs.
|
||||
|
||||
import { Quaternion, Vector3 } from 'three'
|
||||
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
|
||||
import { makeRig } from './rig.js'
|
||||
import { frameQuat } from './solve.js'
|
||||
import { createStage } from './view/stage.js'
|
||||
import { createFigure } from './view/figure.js'
|
||||
import './view/characters.js'
|
||||
|
||||
const params = new URLSearchParams(location.search)
|
||||
const SIDES = ['L', 'R']
|
||||
const TILT = 7 * Math.PI / 180
|
||||
|
||||
const vector = (a) => new Vector3(a[0], a[1], a[2])
|
||||
const quaternion = (a) => new Quaternion(a[0], a[1], a[2], a[3])
|
||||
const axis = (quat, x, y, z) => new Vector3(x, y, z).applyQuaternion(quat)
|
||||
|
||||
// The studio's segment frames from one exported frame of the app's solver.
|
||||
function segmentsOf(frame, rig) {
|
||||
const H = rig.height
|
||||
const segments = {}
|
||||
const pelvisQuat = quaternion(frame.pelvis_quat)
|
||||
const chestQuat = quaternion(frame.chest_quat)
|
||||
const headQuat = quaternion(frame.head_quat)
|
||||
const pelvis = vector(frame.pelvis)
|
||||
const spine1 = vector(frame.spine1)
|
||||
const chest = vector(frame.chest)
|
||||
const neckBase = vector(frame.neck_base)
|
||||
const pelvisZ = axis(pelvisQuat, 0, 0, 1)
|
||||
const chestZ = axis(chestQuat, 0, 0, 1)
|
||||
segments.pelvis = { pos: pelvis, quat: pelvisQuat }
|
||||
segments.spine0 = { pos: pelvis.clone(), quat: frameQuat(spine1.clone().sub(pelvis), pelvisZ.clone().lerp(chestZ, 0.4)) }
|
||||
segments.spine1 = { pos: spine1, quat: frameQuat(chest.clone().sub(spine1), pelvisZ.clone().lerp(chestZ, 0.8)) }
|
||||
segments.chest = { pos: chest, quat: chestQuat }
|
||||
segments.neck = { pos: neckBase, quat: chestQuat.clone().slerp(headQuat, 0.5) }
|
||||
const headPivot = vector(frame.head_center).sub(new Vector3(0, 0.065 * H, 0.012 * H).applyQuaternion(headQuat))
|
||||
segments.head = { pos: headPivot, quat: headQuat }
|
||||
const hands = {}
|
||||
SIDES.forEach((side, index) => {
|
||||
const sign = index === 0 ? 1 : -1
|
||||
const shoulder = vector(frame.shoulders[index])
|
||||
const elbow = vector(frame.elbows[index])
|
||||
const wrist = vector(frame.wrists[index])
|
||||
const handQuat = quaternion(frame.hand_quats[index])
|
||||
const clavicleRoot = neckBase.clone().add(new Vector3(sign * 0.012 * H, -0.008 * H, 0.012 * H).applyQuaternion(chestQuat))
|
||||
const upperDir = elbow.clone().sub(shoulder)
|
||||
const foreDir = wrist.clone().sub(elbow)
|
||||
const palmNormal = axis(handQuat, 0, 0, 1)
|
||||
segments[`clavicle${side}`] = { pos: clavicleRoot, quat: frameQuat(clavicleRoot.clone().sub(shoulder), chestZ) }
|
||||
segments[`upperArm${side}`] = { pos: shoulder, quat: frameQuat(upperDir.clone().negate(), foreDir, chestZ) }
|
||||
segments[`foreArm${side}`] = { pos: elbow, quat: frameQuat(foreDir.clone().negate(), palmNormal, foreDir.clone().negate().cross(upperDir)) }
|
||||
segments[`hand${side}`] = { pos: wrist, quat: handQuat }
|
||||
hands[side] = { shape: frame.hand_shapes[index] }
|
||||
const hip = vector(frame.hips[index])
|
||||
const knee = vector(frame.knees[index])
|
||||
const ankle = vector(frame.ankles[index])
|
||||
const footQuat = quaternion(frame.foot_quats[index])
|
||||
// The knee bends toward where it sits off the hip-ankle line; a
|
||||
// straight leg keeps the foot's forward.
|
||||
const line = ankle.clone().sub(hip)
|
||||
const share = knee.clone().sub(hip).dot(line) / Math.max(line.lengthSq(), 1e-9)
|
||||
let pole = knee.clone().sub(hip.clone().addScaledVector(line, share))
|
||||
if (pole.length() < 0.004 * H) {
|
||||
pole = axis(footQuat, 0, 0, 1)
|
||||
}
|
||||
segments[`thigh${side}`] = { pos: hip, quat: frameQuat(knee.clone().sub(hip).negate(), pole) }
|
||||
segments[`shin${side}`] = { pos: knee, quat: frameQuat(ankle.clone().sub(knee).negate(), pole) }
|
||||
segments[`foot${side}`] = { pos: ankle, quat: footQuat }
|
||||
segments[`toes${side}`] = { pos: vector(frame.balls[index]), quat: quaternion(frame.toes_quats[index]) }
|
||||
})
|
||||
return { segments, hands }
|
||||
}
|
||||
|
||||
const motion = await (await fetch('lab/sun-salutation-motion.json')).json()
|
||||
const rig = makeRig('jadeWoman')
|
||||
const canvas = document.getElementById('view')
|
||||
const stage = createStage(canvas, { preserveDrawingBuffer: params.has('render') })
|
||||
const figure = createFigure(rig, params.get('figure') ?? 'sunWoman')
|
||||
stage.scene.add(figure.root)
|
||||
const controls = new OrbitControls(stage.camera, canvas)
|
||||
controls.enabled = false
|
||||
|
||||
const duration = motion.frames.length / motion.fps
|
||||
let time = Number(params.get('t') ?? 0)
|
||||
let playing = !params.has('render') && !params.has('t')
|
||||
let cameraMode = params.get('camera') ?? 'app'
|
||||
|
||||
// The app's camera: its turn and tilt, centred on the figure; or a fixed side,
|
||||
// back or front view; or a free orbit.
|
||||
function placeCamera(frame) {
|
||||
const pelvis = vector(frame.pelvis)
|
||||
const center = new Vector3(pelvis.x, 0, pelvis.z)
|
||||
stage.follow(center)
|
||||
if (cameraMode === 'orbit') {
|
||||
controls.enabled = true
|
||||
controls.target.set(pelvis.x, Math.max(0.4, pelvis.y), pelvis.z)
|
||||
controls.update()
|
||||
return
|
||||
}
|
||||
controls.enabled = false
|
||||
const turns = { side: -90, back: -150, front: 0 }
|
||||
const yaw = (turns[cameraMode] ?? frame.yaw) * Math.PI / 180
|
||||
const distance = 4.4
|
||||
const direction = new Vector3(Math.sin(yaw), 0, Math.cos(yaw))
|
||||
const target = new Vector3(center.x, 0.62, center.z)
|
||||
stage.camera.position.copy(target).addScaledVector(direction, distance * Math.cos(TILT))
|
||||
stage.camera.position.y += distance * Math.sin(TILT)
|
||||
stage.camera.lookAt(target)
|
||||
}
|
||||
|
||||
function show(second) {
|
||||
const index = Math.max(0, Math.min(motion.frames.length - 1, Math.round(second * motion.fps)))
|
||||
const frame = motion.frames[index]
|
||||
figure.update(segmentsOf(frame, rig))
|
||||
placeCamera(frame)
|
||||
stage.render()
|
||||
const label = document.getElementById('time')
|
||||
if (label) {
|
||||
label.textContent = `${second.toFixed(2)} s`
|
||||
}
|
||||
const slider = document.getElementById('scrub')
|
||||
if (slider) {
|
||||
slider.value = String(second)
|
||||
}
|
||||
}
|
||||
|
||||
function resize() {
|
||||
const width = Number(params.get('width') ?? canvas.clientWidth)
|
||||
const height = Number(params.get('height') ?? canvas.clientHeight)
|
||||
stage.resize(width, height)
|
||||
}
|
||||
|
||||
async function renderStills() {
|
||||
const job = params.get('render')
|
||||
const stills = (params.get('stills') ?? '0').split(',').map(Number)
|
||||
resize()
|
||||
for (let index = 0; index < stills.length; index += 1) {
|
||||
show(stills[index])
|
||||
const blob = await new Promise((done) => canvas.toBlob(done, 'image/png'))
|
||||
await fetch(`/render/${job}/frame/${index}`, { method: 'POST', body: blob })
|
||||
}
|
||||
await fetch(`/render/${job}/done`, { method: 'POST', body: JSON.stringify({ frames: stills.length }) })
|
||||
}
|
||||
|
||||
if (params.has('render')) {
|
||||
renderStills().catch((error) => fetch(`/render/${params.get('render')}/error`, { method: 'POST', body: String(error?.stack ?? error) }))
|
||||
} else {
|
||||
const slider = document.getElementById('scrub')
|
||||
slider.max = String(duration)
|
||||
slider.addEventListener('input', () => {
|
||||
playing = false
|
||||
time = Number(slider.value)
|
||||
show(time)
|
||||
})
|
||||
document.getElementById('play').addEventListener('click', () => {
|
||||
playing = !playing
|
||||
})
|
||||
for (const button of document.querySelectorAll('[data-camera]')) {
|
||||
button.addEventListener('click', () => {
|
||||
cameraMode = button.dataset.camera
|
||||
show(time)
|
||||
})
|
||||
}
|
||||
addEventListener('resize', () => {
|
||||
resize()
|
||||
show(time)
|
||||
})
|
||||
resize()
|
||||
let last = performance.now()
|
||||
const tick = (now) => {
|
||||
if (playing) {
|
||||
time = (time + (now - last) / 1000) % duration
|
||||
}
|
||||
last = now
|
||||
show(time)
|
||||
requestAnimationFrame(tick)
|
||||
}
|
||||
requestAnimationFrame(tick)
|
||||
}
|
||||
@@ -41,6 +41,32 @@ const LOOKS = {
|
||||
neckRadius: 0.025,
|
||||
handSize: 0.95,
|
||||
},
|
||||
// The app's Sun Salutation woman: the Jade woman in the chosen auburn
|
||||
// colours, in a slimmer jacket and trousers (apps/practice/sun_salutation_artwork.zi).
|
||||
sunWoman: {
|
||||
skin: 0xf7c4a3,
|
||||
skinShade: 0xe8ad8c,
|
||||
lips: 0xd9937c,
|
||||
eyes: 0x3a2119,
|
||||
brows: 0x5a2818,
|
||||
hair: 0x7c3a24,
|
||||
hairTie: 0x5a2818,
|
||||
jacket: 0x3f8f7a,
|
||||
buttons: 0x3f8f7a,
|
||||
trousers: 0x2e3d63,
|
||||
trousersInside: 0x222d4a,
|
||||
slipper: 0xf7c4a3,
|
||||
sole: 0xe8ad8c,
|
||||
style: 'bun',
|
||||
jacketShape: {
|
||||
hem: 0.112, hip: 0.106, waist: 0.09, chest: 0.097, shoulder: 0.1,
|
||||
hemDepth: 0.075, waistDepth: 0.062, chestDepth: 0.071, bust: 0.006,
|
||||
},
|
||||
// The seat sits inside the slimmer jacket.
|
||||
seat: [0.088, 0.058, 0.06, -0.03, -0.008],
|
||||
neckRadius: 0.025,
|
||||
handSize: 0.92,
|
||||
},
|
||||
sageMale: {
|
||||
skin: 0xe9b691,
|
||||
skinShade: 0xd59c78,
|
||||
@@ -393,8 +419,10 @@ function buildCharacter(figure, rig, options, lookName) {
|
||||
addMesh(g.spine1, ellipsoid(0.008 * H, 0.0035 * H, 0.004 * H), buttons, [0, local, (depth + forward) * H - 0.001 * H])
|
||||
}
|
||||
|
||||
// Seat of the trousers under the hem.
|
||||
addMesh(g.pelvis, ellipsoid(0.098 * H, 0.06 * H, 0.074 * H), trousers, [0, -0.028 * H, -0.004 * H])
|
||||
// Seat of the trousers under the hem: half width, height and depth, and
|
||||
// its drop and forward offset from the pelvis, as shares of the height.
|
||||
const seat = look.seat ?? [0.098, 0.06, 0.074, -0.028, -0.004]
|
||||
addMesh(g.pelvis, ellipsoid(seat[0] * H, seat[1] * H, seat[2] * H), trousers, [0, seat[3] * H, seat[4] * H])
|
||||
|
||||
// Sleeves and trousers.
|
||||
for (const side of SIDES) {
|
||||
@@ -535,3 +563,4 @@ 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('sunWoman', (figure, rig, options) => buildCharacter(figure, rig, options, 'sunWoman'))
|
||||
@@ -0,0 +1,44 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Sun Salutation Body Lab</title>
|
||||
<link rel="icon" href="data:,">
|
||||
<script type="importmap">
|
||||
{
|
||||
"imports": {
|
||||
"three": "./node_modules/three/build/three.module.js",
|
||||
"three/addons/": "./node_modules/three/examples/jsm/"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
:root { --bg: #f1ece0; --ink: #2e3a33; --line: #ddd5c4; --panel: #faf7f0; }
|
||||
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 14px system-ui, sans-serif; }
|
||||
#view { display: block; width: 100%; height: calc(100% - 52px); }
|
||||
body.render #view { height: 100%; }
|
||||
body.render #bar { display: none; }
|
||||
#bar { display: flex; gap: 8px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel); }
|
||||
#scrub { flex: 1; }
|
||||
button { font: inherit; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="view"></canvas>
|
||||
<div id="bar">
|
||||
<button id="play">Play</button>
|
||||
<input id="scrub" type="range" min="0" max="150" step="0.033" value="0">
|
||||
<span id="time">0.00 s</span>
|
||||
<button data-camera="app">App camera</button>
|
||||
<button data-camera="side">Side</button>
|
||||
<button data-camera="back">Back</button>
|
||||
<button data-camera="front">Front</button>
|
||||
<button data-camera="orbit">Orbit</button>
|
||||
</div>
|
||||
<script>
|
||||
if (new URLSearchParams(location.search).has('render')) document.body.classList.add('render')
|
||||
</script>
|
||||
<script type="module" src="./src/sun-salutation-lab.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -50,7 +50,7 @@ function privateEnvironment() {
|
||||
return environment
|
||||
}
|
||||
|
||||
function launchBrowser(url, width, height) {
|
||||
export function launchBrowser(url, width, height) {
|
||||
const profile = mkdtempSync(join(tmpdir(), 'tai-chi-render-'))
|
||||
const browser = spawn(chromiumBinary(), [
|
||||
'--headless=new',
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// Renders stills of the Sun Salutation body lab (sun-salutation.html) with
|
||||
// headless Chromium, the way tools/render.mjs renders the course.
|
||||
//
|
||||
// python3 scripts/render-sun-salutation-live.py --motion design/tai-chi/lab/sun-salutation-motion.json
|
||||
// node tools/sun-salutation.mjs --stills 11.5,28.5,52.4 [--camera app|side|back|front] [--name lab]
|
||||
//
|
||||
// Stills go to build/tai-chi/sun-salutation/ as NAME-tSECONDS.png.
|
||||
|
||||
import { mkdirSync, writeFileSync } from 'node:fs'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { STUDIO_ROOT, startServer } from './serve.mjs'
|
||||
import { launchBrowser } from './render.mjs'
|
||||
|
||||
const options = { camera: 'app', name: 'lab', width: '1280', height: '900' }
|
||||
const argv = process.argv.slice(2)
|
||||
for (let index = 0; index < argv.length; index += 2) {
|
||||
options[argv[index].replace(/^--/, '')] = argv[index + 1]
|
||||
}
|
||||
if (!options.stills) {
|
||||
console.error('Give --stills T1,T2,...')
|
||||
process.exit(1)
|
||||
}
|
||||
const out = resolve(STUDIO_ROOT, '..', '..', 'build', 'tai-chi', 'sun-salutation')
|
||||
mkdirSync(out, { recursive: true })
|
||||
const server = await startServer()
|
||||
const job = `lab${process.pid}`
|
||||
const times = options.stills.split(',')
|
||||
const written = []
|
||||
const finished = new Promise((done, fail) => {
|
||||
server.jobs.set(job, {
|
||||
async frame(index, png) {
|
||||
const path = join(out, `${options.name}-t${Number(times[index]).toFixed(2).replace('.', '_')}.png`)
|
||||
writeFileSync(path, png)
|
||||
written.push(path)
|
||||
},
|
||||
done,
|
||||
error: (text) => fail(new Error(text)),
|
||||
})
|
||||
})
|
||||
const query = new URLSearchParams({ render: job, stills: options.stills, camera: options.camera, figure: options.figure ?? 'sunWoman',
|
||||
width: options.width, height: options.height })
|
||||
const browser = launchBrowser(`${server.url}sun-salutation.html?${query}`, Number(options.width), Number(options.height))
|
||||
try {
|
||||
await Promise.race([
|
||||
finished,
|
||||
new Promise((_, fail) => setTimeout(() => fail(new Error(`Timed out\n${browser.log()}`)), 300000)),
|
||||
])
|
||||
console.log(written.join('\n'))
|
||||
} finally {
|
||||
browser.close()
|
||||
server.server.close()
|
||||
}
|
||||
@@ -8,6 +8,7 @@ paint operations, pose solver, timing and framing as the app.
|
||||
|
||||
import argparse
|
||||
import ctypes
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
from pathlib import Path
|
||||
@@ -33,6 +34,37 @@ class Operation(ctypes.Structure):
|
||||
]
|
||||
|
||||
|
||||
V3 = ctypes.c_double * 3
|
||||
QUAT = ctypes.c_double * 4
|
||||
|
||||
|
||||
class Solved(ctypes.Structure):
|
||||
"""TaiChiSolved in src/practices/tai_chi/tai_chi_solve.zi, field by field."""
|
||||
_fields_ = [
|
||||
("pelvis", V3), ("pelvis_quat", QUAT), ("spine1", V3), ("chest", V3), ("chest_quat", QUAT),
|
||||
("head_quat", QUAT), ("neck_base", V3), ("shoulder_center", V3), ("head_center", V3),
|
||||
("head_top", V3), ("com", V3), ("balance_target", V3), ("load", ctypes.c_double),
|
||||
("shoulders", V3 * 2), ("elbows", V3 * 2), ("wrists", V3 * 2), ("palms", V3 * 2),
|
||||
("hand_quats", QUAT * 2), ("hand_shapes", (ctypes.c_double * 3) * 2),
|
||||
("hips", V3 * 2), ("knees", V3 * 2), ("ankles", V3 * 2), ("heels", V3 * 2),
|
||||
("balls", V3 * 2), ("toes", V3 * 2), ("foot_quats", QUAT * 2), ("toes_quats", QUAT * 2),
|
||||
]
|
||||
|
||||
|
||||
def solved_json(solved):
|
||||
"""Every joint as plain lists, sides as [left, right]."""
|
||||
record = {}
|
||||
for name, kind in Solved._fields_:
|
||||
value = getattr(solved, name)
|
||||
if kind is ctypes.c_double:
|
||||
record[name] = value
|
||||
elif kind in (V3, QUAT):
|
||||
record[name] = [round(v, 6) for v in value]
|
||||
else:
|
||||
record[name] = [[round(v, 6) for v in item] for item in value]
|
||||
return record
|
||||
|
||||
|
||||
class Frame(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("ops", Operation * 512), ("op_count", ctypes.c_int32),
|
||||
@@ -68,6 +100,10 @@ class Renderer:
|
||||
self.native = ctypes.CDLL(str(compile_renderer()))
|
||||
self.native.PreviewFrame.argtypes = [ctypes.c_double, ctypes.c_int32, ctypes.c_int32]
|
||||
self.native.PreviewFrame.restype = ctypes.POINTER(Frame)
|
||||
self.native.PreviewSolved.argtypes = [ctypes.c_double]
|
||||
self.native.PreviewSolved.restype = ctypes.POINTER(Solved)
|
||||
self.native.PreviewYaw.argtypes = []
|
||||
self.native.PreviewYaw.restype = ctypes.c_double
|
||||
for name in ("PreviewDuration", "PreviewHeight", "PreviewCenter"):
|
||||
function = getattr(self.native, name)
|
||||
function.argtypes = []
|
||||
@@ -122,12 +158,25 @@ def main():
|
||||
parser.add_argument("--fps", type=int, default=30)
|
||||
parser.add_argument("--still", type=float, action="append")
|
||||
parser.add_argument("--review", action="store_true", help="save review poses before the complete video")
|
||||
parser.add_argument("--motion", type=Path,
|
||||
help="write every frame's solved skeleton and camera turn as JSON, for the three.js lab")
|
||||
options = parser.parse_args()
|
||||
if options.width <= 0 or options.height <= 0 or options.fps <= 0:
|
||||
parser.error("Width, height and frame rate must be positive")
|
||||
if not options.still and (options.width % 2 or options.height % 2):
|
||||
parser.error("H.264 dimensions must be even")
|
||||
renderer = Renderer(options.width, options.height)
|
||||
if options.motion:
|
||||
frames = []
|
||||
for index in range(round(renderer.duration * options.fps)):
|
||||
second = index / options.fps
|
||||
record = solved_json(renderer.native.PreviewSolved(second).contents)
|
||||
record["yaw"] = renderer.native.PreviewYaw()
|
||||
frames.append(record)
|
||||
options.motion.parent.mkdir(parents=True, exist_ok=True)
|
||||
options.motion.write_text(json.dumps({"fps": options.fps, "height": 1.65, "frames": frames}))
|
||||
print(f"Saved {options.motion} ({len(frames)} frames)")
|
||||
return
|
||||
options.output.parent.mkdir(parents=True, exist_ok=True)
|
||||
if options.still or options.review:
|
||||
for second in options.still or [0, 11, 41]:
|
||||
|
||||
@@ -5,9 +5,12 @@
|
||||
#import, file "../src/practices/sun_salutation/sun_salutation_rules.zi";
|
||||
#import, file "../src/practices/tai_chi/tai_chi_flat.zi";
|
||||
#import, file "../src/practices/tai_chi/tai_chi_rules.zi";
|
||||
#import, file "../src/practices/tai_chi/tai_chi_solve.zi";
|
||||
|
||||
preview_frame: TaiChiFlatFrame;
|
||||
preview_framing: TaiChiFraming;
|
||||
preview_solved: TaiChiSolved;
|
||||
preview_yaw: float64;
|
||||
|
||||
PreviewState :: () -> SunSalutationPracticeState {
|
||||
state: SunSalutationPracticeState
|
||||
@@ -41,3 +44,20 @@ PreviewHeight :: () -> float64 {
|
||||
PreviewCenter :: () -> float64 {
|
||||
return preview_framing.view_center
|
||||
}
|
||||
|
||||
// The solved skeleton at `second` and the camera's turn in degrees, for the
|
||||
// three.js lab (design/tai-chi/sun-salutation.html).
|
||||
#program_export
|
||||
PreviewSolved :: (second: float64) -> *TaiChiSolved {
|
||||
state := SalutationAdvance(PreviewState(), second).state
|
||||
rig := WorkoutRig()
|
||||
pose := SunSalutationPoseAt(state, *rig)
|
||||
preview_solved = WorkoutSolve(*pose, *rig)
|
||||
preview_yaw = SunSalutationViewAt(state).yaw
|
||||
return *preview_solved
|
||||
}
|
||||
|
||||
#program_export
|
||||
PreviewYaw :: () -> float64 {
|
||||
return preview_yaw
|
||||
}
|
||||
@@ -103,8 +103,11 @@ TaiChiFlatLook :: struct {
|
||||
sash_to: [TAI_CHI_FLAT_SASH_CAPACITY]float64
|
||||
sash_color: [TAI_CHI_FLAT_SASH_CAPACITY]u32
|
||||
limbs: float64
|
||||
// Buttocks as rounded domes behind the hips, rather than one ball.
|
||||
glutes: bool
|
||||
// The trousers' seat as one ellipsoid on the pelvis, as the 3D studio
|
||||
// figures have it: half width, height and depth, then its drop and
|
||||
// forward offset from the pelvis, as height shares. Zero width keeps the
|
||||
// round seat of spheres.
|
||||
seat: [5]float64
|
||||
// Hand size, foot length and foot thickness as shares of the usual.
|
||||
hand_size: float64
|
||||
foot_length: float64
|
||||
@@ -862,21 +865,19 @@ TaiChiFlatTorsoLines :: (painter: *TaiChiFlatPainter, spine: *TaiChiFlatSpine) {
|
||||
}
|
||||
}
|
||||
|
||||
// Each buttock is a dome on the pelvis, behind and a little below its hip
|
||||
// joint, so from any side it shows one smooth curve into the thigh.
|
||||
TaiChiFlatGlutes :: (painter: *TaiChiFlatPainter, solved: *TaiChiSolved, spine: *TaiChiFlatSpine, color: u32) {
|
||||
// The seat of the trousers: one ellipsoid on the pelvis under the top's hem,
|
||||
// as in the 3D studio (design/tai-chi/src/view/characters.js).
|
||||
TaiChiFlatSeat :: (painter: *TaiChiFlatPainter, solved: *TaiChiSolved, color: u32) {
|
||||
height := painter.height
|
||||
k := height * painter.look.limbs
|
||||
seat := painter.look.seat
|
||||
pelvis: TaiChiFlatHead
|
||||
pelvis.quat = solved.pelvis_quat
|
||||
pelvis.inverse = TaiChiFlatConjugate(solved.pelvis_quat)
|
||||
pelvis.pivot = spine.hip_center
|
||||
for side: cast(s32)0..1 {
|
||||
part: TaiChiFlatPart
|
||||
part.center = TaiChiV3(TaiChiSideSign(side) * 0.042 * height, -0.03 * height, -0.03 * height)
|
||||
part.radii = TaiChiV3(0.058 * k, 0.07 * k, 0.056 * k)
|
||||
TaiChiFlatFill(painter, TaiChiFlatOutline(painter, *pelvis, part), color, 1.0)
|
||||
}
|
||||
pelvis.pivot = solved.pelvis
|
||||
part: TaiChiFlatPart
|
||||
part.center = TaiChiV3(0.0, seat[3] * height, seat[4] * height)
|
||||
part.radii = TaiChiV3(seat[0] * height, seat[1] * height, seat[2] * height)
|
||||
TaiChiFlatFill(painter, TaiChiFlatOutline(painter, *pelvis, part), color, 1.0)
|
||||
}
|
||||
|
||||
// --- Limbs -----------------------------------------------------------------------
|
||||
@@ -1524,13 +1525,12 @@ TaiChiFlatPaintLook :: (frame: *TaiChiFlatFrame, solved: *TaiChiSolved, rig: *Ta
|
||||
TaiChiFlatArmPaint(*painter, *arms[side], no_clips)
|
||||
}
|
||||
}
|
||||
// The farther leg first. Buttocks lie over the farther leg, so its
|
||||
// darker tone never shows across them.
|
||||
// The farther leg first. An ellipsoid seat lies over the farther leg, so
|
||||
// its darker tone never shows across it.
|
||||
far_first := ifx legs[0].depth <= legs[1].depth then 0 else 1
|
||||
if painter.look.glutes {
|
||||
if painter.look.seat[0] > 0.0 {
|
||||
TaiChiFlatLegPaint(*painter, *legs[far_first])
|
||||
TaiChiFlatFill(*painter, seat, palette.pants, 1.0)
|
||||
TaiChiFlatGlutes(*painter, solved, *spine, palette.pants)
|
||||
TaiChiFlatSeat(*painter, solved, palette.pants)
|
||||
} else {
|
||||
TaiChiFlatFill(*painter, seat, palette.pants, 1.0)
|
||||
TaiChiFlatLegPaint(*painter, *legs[far_first])
|
||||
|
||||
@@ -19,7 +19,7 @@ Answer :: () -> s32 {
|
||||
chosen.hair_style != original.hair_style || chosen.head_scale != original.head_scale {
|
||||
return 501
|
||||
}
|
||||
if !(chosen.limbs < original.limbs && chosen.jacket[7][2] < original.jacket[7][2] && chosen.glutes) {
|
||||
if !(chosen.limbs < original.limbs && chosen.jacket[7][2] < original.jacket[7][2] && chosen.seat[0] > 0.0) {
|
||||
return 502
|
||||
}
|
||||
rig := WorkoutRig()
|
||||
|
||||
Reference in new issue
Block a user