Finish practice figure attire and restore English narration headroom
This commit is contained in:
1 parent
d8b54df173
commit
2bc1edf718
171 files changed
+1667
-53
No files matched your search
+34
-7
@@ -25,10 +25,13 @@ The modules:
|
||||
as she moves and turns, and her eyes blink every few seconds
|
||||
(`FigureBlink`); a still pose has the hair hanging at rest. Its
|
||||
humanoid bones are found by name (VRoid's `J_Bip_*`, Mixamo's
|
||||
`mixamorig` and common Blender names). Each pose turns them so the limbs
|
||||
point where the solver's joints are, keeping the model's own
|
||||
proportions, scales the model so its legs match the solver's and stands
|
||||
its ankles on the solver's ankles. `FigureModelToon` gives it a
|
||||
`mixamorig` and common Blender names). Each pose solves the limbs with
|
||||
the model's own segment lengths to reach the solver's wrists and ankles,
|
||||
keeping its proportions. It scales the model to the solver's leg length and stands
|
||||
its measured slipper support on the solver's heel/ball contacts. The wrist uses the solver's palm
|
||||
frame, converted from the model's bind pose; the fingers curl gently
|
||||
unless the technique calls for a fist or hook. Eyes follow cued head
|
||||
turns gently. `FigureModelToon` gives it a
|
||||
cel-shaded look on its own textures.
|
||||
|
||||
The practices' backdrops are in `shared/figure/backdrops/`. The owner's
|
||||
@@ -36,13 +39,37 @@ references for the render quality are in `design/reference/`.
|
||||
|
||||
## Tests
|
||||
|
||||
Run from the repository root through the build queue:
|
||||
Run from the repository root in a managed Harmony command.
|
||||
|
||||
```sh
|
||||
build-queue -- ziran build --project --target=c --exe --entry figure_parts_test:main -o build/figure-parts-test tests/figure_parts_test.zi
|
||||
build-queue -- ./build/figure-parts-test/figure_parts_test
|
||||
for suite in figure_parts_test figure_model_pose_test figure_model_sole_test figure_cloth_test; do
|
||||
ziran build --project --target=c --exe --entry "$suite:main" -o "build/$suite" "tests/$suite.zi" &&
|
||||
"build/$suite/$suite" || exit
|
||||
done
|
||||
python3 tests/slippers_test.py
|
||||
python3 tests/attire_test.py --source-dir backup/figure-source
|
||||
```
|
||||
|
||||
`figure_parts_test` checks that a skinned vertex follows its bone's motion,
|
||||
the contact shadow, a picture laid over a covering backdrop, and that a
|
||||
missing model file is refused cleanly.
|
||||
|
||||
`figure_model_pose_test` loads both selected VRM skeletons and checks the
|
||||
rendered hand direction, wrist alignment and planted ankle alignment as the pelvis moves
|
||||
over fixed foot targets. It does not need a window or display.
|
||||
|
||||
`figure_model_sole_test` measures actual skinned underside vertices for both
|
||||
models during flat stances and heel/ball pivots, with a 1 mm floor,
|
||||
flatness and pivot limit. `slippers_test.py` validates the shipped CC0
|
||||
models, rigid foot weights, matte cloth materials and flat soles; with
|
||||
`--source-dir` it also proves every original bitmap/accessor byte and every
|
||||
non-shoe primitive is retained. See `shared/figure/MODELS.md` for the
|
||||
reproducible footwear pipeline.
|
||||
|
||||
`figure_cloth` drapes the skirt hem, resolves leg-capsule contacts and
|
||||
shares displacement across nearby fabric edges. `figure_model` applies
|
||||
those constraints to the named skirt after skinning. `figure_cloth_test`
|
||||
covers the fold through ninety degrees, waist anchoring and capsule
|
||||
contacts. The preview's `--clothing-audit` checks actual named garment
|
||||
surfaces throughout every timeline. Its private capture commands render
|
||||
complete items and slow transitions for visual review.
|
||||
@@ -0,0 +1,37 @@
|
||||
// Small deterministic cloth constraints for the meditation skirt. The upper
|
||||
// edge follows the fitted garment skin; the hem hangs under gravity instead
|
||||
// of rotating over the head with a forward-folded pelvis. Leg capsules and
|
||||
// the real floor keep the cloth outside the body. There is no free-running
|
||||
// simulation or seek-dependent state.
|
||||
#import "figure_math"
|
||||
#import "kryon/scene"
|
||||
|
||||
FigureClothOutside :: (point: Vector3, from: Vector3, to: Vector3, radius: float64, fallback: Vector3) -> Vector3 {
|
||||
segment := FigureSub(to, from)
|
||||
length := FigureDot(segment, segment)
|
||||
along := ifx length > 0.000000001 then FigureClamp(FigureDot(FigureSub(point, from), segment) / length, 0.0, 1.0) else 0.0
|
||||
center := FigureAddScaled(from, segment, along)
|
||||
delta := FigureSub(point, center)
|
||||
distance := FigureLength(delta)
|
||||
if distance >= radius {
|
||||
return point
|
||||
}
|
||||
if distance < 0.000001 {
|
||||
delta = FigureNormalize(fallback)
|
||||
} else {
|
||||
delta = FigureScale(delta, 1.0 / distance)
|
||||
}
|
||||
return FigureAddScaled(center, delta, radius)
|
||||
}
|
||||
|
||||
FigureClothHang :: (skinned: Vector3, rest: Vector3, rest_hips: Vector3, hips: Vector3,
|
||||
facing: FigureQuat, yaw: float64, scale: float64) -> Vector3 {
|
||||
local := FigureSub(rest, rest_hips)
|
||||
depth := FigureMax(0.0, -local.y)
|
||||
// Preserve the waist seam and let the lower skirt settle continuously.
|
||||
loose := FigureSmooth(depth, 0.015, 0.19)
|
||||
lateral := FigureRotate(facing, .{local.x, 0.0, local.z})
|
||||
lateral = FigureRotate(FigureAxisAngle(.{0.0, 1.0, 0.0}, yaw), lateral)
|
||||
hanging := FigureAdd(hips, FigureScale(.{lateral.x, -depth, lateral.z}, scale))
|
||||
return FigureLerp(skinned, hanging, loose)
|
||||
}
|
||||
@@ -27,6 +27,9 @@ FigureJoints :: struct {
|
||||
knees: [2]Vector3
|
||||
ankles: [2]Vector3
|
||||
toes: [2]Vector3
|
||||
// Actual solver heel/ball contacts, including lift and pivots.
|
||||
heels: [2]Vector3
|
||||
balls: [2]Vector3
|
||||
feet: [2]FigureQuat
|
||||
}
|
||||
|
||||
|
||||
+441
-39
@@ -3,13 +3,14 @@
|
||||
//
|
||||
// The model's humanoid bones are found by name: VRoid's J_Bip_*, Mixamo's
|
||||
// mixamorig names and the common Blender names. Each pose turns those bones
|
||||
// so the limbs point where the solver's joints are, keeping the model's own
|
||||
// proportions; the trunk, head and feet take the solver's turns. The whole
|
||||
// so the limbs reach the solver's wrists and ankles with the model's own
|
||||
// segment lengths; the trunk, head and feet take the solver's turns. The whole
|
||||
// model is scaled so its legs match the solver's and placed so its ankles
|
||||
// stand on the solver's ankles. A VRM model's hair and clothes swing on its
|
||||
// spring bones and its eyes blink while the pose is played over time.
|
||||
#import "figure_math"
|
||||
#import "figure_joints"
|
||||
#import "figure_cloth"
|
||||
#import "kryon/scene"
|
||||
#import "kryon/scene_gltf"
|
||||
#import "kryon/scene_skin"
|
||||
@@ -56,6 +57,14 @@ FigureModel :: struct {
|
||||
// Turns the model to face +Z with its left at +X.
|
||||
facing: FigureQuat
|
||||
yaw: float64
|
||||
// The model's relaxed palm frames in the solver's coordinate system.
|
||||
hand_rest: [2]FigureQuat
|
||||
// Measured sole vertices in foot-relative, facing-corrected bind space.
|
||||
sole_points: [128]Vector3
|
||||
sole_count: [2]s32
|
||||
sole_heel: [2]Vector3
|
||||
sole_ball: [2]Vector3
|
||||
foot_stretch: [2]float64
|
||||
// The toon look: a shader, and per scene mesh its uniforms. Each mesh
|
||||
// keeps the importer's own base colour texture, which the renderer
|
||||
// uploads once and samples into the shader's vertex data.
|
||||
@@ -105,6 +114,29 @@ FigureModelLoad :: (figure: *FigureModel, scene: *Scene, path: string) -> bool {
|
||||
return false
|
||||
}
|
||||
GltfSetDualQuaternion(*figure.instance, true)
|
||||
// Feet use their exact affine transform: the calibrated sole length
|
||||
// needs nonuniform Z scale, which a rigid dual quaternion cannot encode.
|
||||
// The tunic and trousers also use affine blending across joints. In a
|
||||
// deep lunge the thighs can rotate far enough apart to make adjacent
|
||||
// vertices choose opposite dual-quaternion rotation paths at the seat.
|
||||
skirt := false
|
||||
for index: 0..figure.model.meshes.count - 1 {
|
||||
mesh := *figure.model.meshes[index]
|
||||
skirt = skirt || TextView(mesh.name[:]) == "PracticeSkirt"
|
||||
}
|
||||
for index: 0..figure.instance.meshes.count - 1 {
|
||||
inst := *figure.instance.meshes[index]
|
||||
mesh := *figure.model.meshes[inst.mesh_index]
|
||||
name := TextView(mesh.name[:])
|
||||
primitive := *mesh.primitives[inst.primitive_index]
|
||||
high: float64 = -1000.0
|
||||
for vertex: primitive.indices[:] {
|
||||
high = FigureMax(high, primitive.positions[vertex].y)
|
||||
}
|
||||
if high < 0.30 || (!skirt && (name == "PracticeClothing" || name == "PracticeWrapFacings")) {
|
||||
inst.skin.dual_quaternion = false
|
||||
}
|
||||
}
|
||||
count := figure.model.nodes.count
|
||||
if !VecResize(figure.rest_turn, count) || !VecResize(figure.rest_at, count) ||
|
||||
!VecResize(figure.turn, count) || !VecResize(figure.role_of, count) {
|
||||
@@ -165,6 +197,10 @@ FigureModelLoad :: (figure: *FigureModel, scene: *Scene, path: string) -> bool {
|
||||
// keeps its own naming; only the heading is turned.
|
||||
figure.yaw = -Atan2(forward.x, forward.z)
|
||||
figure.facing = FigureAxisAngle(FigureV3(0.0, 1.0, 0.0), figure.yaw)
|
||||
for side: cast(s32)0..1 {
|
||||
figure.hand_rest[side] = FigureModelHandRest(figure, side)
|
||||
}
|
||||
FigureModelReadSoles(figure)
|
||||
// A VRM model's springs start from its rest pose.
|
||||
if VrmReadFile(*figure.avatar, path) {
|
||||
unused VrmSpringsReset(*figure.avatar, *figure.model, *figure.instance)
|
||||
@@ -202,56 +238,35 @@ FigureModelPose :: (figure: *FigureModel, scene: *Scene, joints: *FigureJoints,
|
||||
lower := FigureModelAim(figure, upper, FigureSideRole(side, FIGURE_LOWER_ARM), FigureSideRole(side, FIGURE_HAND),
|
||||
FigureSub(joints.wrists[side], joints.elbows[side]))
|
||||
turns[FigureSideRole(side, FIGURE_LOWER_ARM)] = lower
|
||||
turns[FigureSideRole(side, FIGURE_HAND)] = lower
|
||||
turns[FigureSideRole(side, FIGURE_HAND)] = FigureMultiply(
|
||||
FigureQuatNormalize(joints.hands[side]), FigureConjugate(figure.hand_rest[side]))
|
||||
thigh := FigureModelAim(figure, pelvis, FigureSideRole(side, FIGURE_UPPER_LEG),
|
||||
FigureSideRole(side, FIGURE_LOWER_LEG), FigureSub(joints.knees[side], joints.hips[side]))
|
||||
turns[FigureSideRole(side, FIGURE_UPPER_LEG)] = thigh
|
||||
shin := FigureModelAim(figure, thigh, FigureSideRole(side, FIGURE_LOWER_LEG), FigureSideRole(side, FIGURE_FOOT),
|
||||
FigureSub(joints.ankles[side], joints.knees[side]))
|
||||
turns[FigureSideRole(side, FIGURE_LOWER_LEG)] = shin
|
||||
foot := FigureModelAim(figure, FigureQuatNormalize(joints.feet[side]), FigureSideRole(side, FIGURE_FOOT),
|
||||
FigureSideRole(side, FIGURE_TOES), FigureSub(joints.toes[side], joints.ankles[side]))
|
||||
// The prepared slipper sole is level at rest. Toe-bone direction
|
||||
// is anatomical, not the sole plane; aiming it tilted planted shoes.
|
||||
foot := FigureQuatNormalize(joints.feet[side])
|
||||
turns[FigureSideRole(side, FIGURE_FOOT)] = foot
|
||||
turns[FigureSideRole(side, FIGURE_TOES)] = foot
|
||||
// The fingers relax into a soft curl, closing further with a fist.
|
||||
hand := turns[FigureSideRole(side, FIGURE_HAND)]
|
||||
curl := 0.18 + FigureClamp(joints.fist[side], 0.0, 1.0) * 1.0
|
||||
for finger: cast(s32)0..4 {
|
||||
parent := hand
|
||||
for segment: cast(s32)0..2 {
|
||||
role := FigureFingerRole(side, finger, segment)
|
||||
next := ifx segment < 2 then FigureFingerRole(side, finger, segment + 1) else -1
|
||||
bend := FigureModelFingerAxis(figure, role, next, side)
|
||||
amount := ifx finger == 0 then curl * 0.4 else curl
|
||||
amount := FigureFingerCurl(joints.fist[side], joints.hook[side], finger, segment)
|
||||
turned := FigureMultiply(FigureAxisAngle(FigureRotate(parent, bend), amount), parent)
|
||||
turns[role] = turned
|
||||
parent = turned
|
||||
}
|
||||
}
|
||||
}
|
||||
// Each node turns with the nearest posed bone above it.
|
||||
for at: 0..figure.order.count - 1 {
|
||||
node := figure.order[at]
|
||||
parent := figure.model.nodes[node].parent
|
||||
role := figure.role_of[node]
|
||||
figure.turn[node] = ifx role >= 0 then turns[role] else ifx parent >= 0 then figure.turn[parent] else FigureIdentity()
|
||||
if role < 0 {
|
||||
continue
|
||||
}
|
||||
// World rotation now: the figure-space turn carried into the
|
||||
// model's space; the local rotation is that against the parent's.
|
||||
inverse_facing := FigureConjugate(figure.facing)
|
||||
mine := FigureMultiply(FigureMultiply(FigureMultiply(inverse_facing, figure.turn[node]), figure.facing),
|
||||
figure.rest_turn[node])
|
||||
above := FigureIdentity()
|
||||
if parent >= 0 {
|
||||
above = FigureMultiply(FigureMultiply(FigureMultiply(inverse_facing, figure.turn[parent]), figure.facing),
|
||||
figure.rest_turn[parent])
|
||||
}
|
||||
local := FigureQuatNormalize(FigureMultiply(FigureConjugate(above), mine))
|
||||
figure.instance.rotations[node] = .{local.x, local.y, local.z, local.w}
|
||||
figure.instance.trs_dirty[node] = true
|
||||
}
|
||||
FigureModelSetTurns(figure, turns[:])
|
||||
// The legs match the solver's; the ankles stand on the solver's ankles.
|
||||
model_leg: float64
|
||||
solver_leg: float64
|
||||
@@ -263,18 +278,292 @@ FigureModelPose :: (figure: *FigureModel, scene: *Scene, joints: *FigureJoints,
|
||||
solver_leg += FigureDistance(joints.hips[side], joints.knees[side]) + FigureDistance(joints.knees[side], joints.ankles[side])
|
||||
}
|
||||
scale := ifx model_leg > 0.000001 then solver_leg / model_leg else 1.0
|
||||
feet_targets: [2]Vector3
|
||||
for side: cast(s32)0..1 {
|
||||
figure.foot_stretch[side] = 1.0
|
||||
span := FigureDistance(joints.heels[side], joints.balls[side])
|
||||
model_span := FigureDistance(figure.sole_heel[side], figure.sole_ball[side]) * scale
|
||||
if figure.sole_count[side] > 0 && span > 0.01 && model_span > 0.01 {
|
||||
figure.foot_stretch[side] = span / model_span
|
||||
}
|
||||
foot_node := figure.bones[FigureSideRole(side, FIGURE_FOOT)]
|
||||
if foot_node >= 0 {
|
||||
figure.instance.scales[foot_node].z = figure.model.nodes[foot_node].scale.z * figure.foot_stretch[side]
|
||||
figure.instance.trs_dirty[foot_node] = true
|
||||
}
|
||||
feet_targets[side] = FigureModelSoleTarget(figure, joints, side, scale)
|
||||
}
|
||||
offset: Vector3
|
||||
for side: cast(s32)0..1 {
|
||||
ankle := FigureScale(FigureRotate(figure.facing, FigureModelPosed(figure, figure.bones[FigureSideRole(side, FIGURE_FOOT)])),
|
||||
scale)
|
||||
offset = FigureAdd(offset, FigureScale(FigureSub(joints.ankles[side], ankle), 0.5))
|
||||
offset = FigureAdd(offset, FigureScale(FigureSub(feet_targets[side], ankle), 0.5))
|
||||
}
|
||||
// A measured sole changes the ankle target. Keep the pelvis inside
|
||||
// both legs' reach before solving them, including nearly straight
|
||||
// stances where the two avatars' thigh/shin ratios differ.
|
||||
hips: [2]Vector3
|
||||
reaches: [2]float64
|
||||
for side: cast(s32)0..1 {
|
||||
upper := FigureSideRole(side, FIGURE_UPPER_LEG)
|
||||
lower := FigureSideRole(side, FIGURE_LOWER_LEG)
|
||||
foot := FigureSideRole(side, FIGURE_FOOT)
|
||||
hips[side] = FigureScale(FigureRotate(figure.facing,
|
||||
FigureModelPosed(figure, figure.bones[upper])), scale)
|
||||
reaches[side] = (FigureDistance(FigureModelRest(figure, upper, -1), FigureModelRest(figure, lower, -1)) +
|
||||
FigureDistance(FigureModelRest(figure, lower, -1), FigureModelRest(figure, foot, -1))) * scale - 0.000002
|
||||
}
|
||||
for pass: 0..31 {
|
||||
adjusted := false
|
||||
for side: cast(s32)0..1 {
|
||||
delta := FigureSub(FigureAdd(offset, hips[side]), feet_targets[side])
|
||||
distance := FigureLength(delta)
|
||||
if distance > reaches[side] + 0.0000000001 && reaches[side] > 0.0 {
|
||||
offset = FigureAddScaled(offset, delta, reaches[side] / distance - 1.0)
|
||||
adjusted = true
|
||||
}
|
||||
}
|
||||
if !adjusted {
|
||||
break
|
||||
}
|
||||
}
|
||||
// Bone directions alone cannot keep contacts fixed when the model's
|
||||
// thigh/shin or upper/lower arm ratios differ from the solver's. Solve
|
||||
// each limb again with the model's lengths, reaching the same targets.
|
||||
for side: cast(s32)0..1 {
|
||||
FigureModelReach(figure, turns[:], pelvis, FigureSideRole(side, FIGURE_UPPER_LEG),
|
||||
FigureSideRole(side, FIGURE_LOWER_LEG), FigureSideRole(side, FIGURE_FOOT),
|
||||
feet_targets[side], joints.knees[side], offset, scale)
|
||||
FigureModelReach(figure, turns[:], chest, FigureSideRole(side, FIGURE_UPPER_ARM),
|
||||
FigureSideRole(side, FIGURE_LOWER_ARM), FigureSideRole(side, FIGURE_HAND),
|
||||
joints.wrists[side], joints.elbows[side], offset, scale)
|
||||
}
|
||||
FigureModelSetTurns(figure, turns[:])
|
||||
root := figure.instance.root_node
|
||||
SetPosition(scene, root, offset.x, offset.y, offset.z)
|
||||
SetRotation(scene, root, 0.0, figure.yaw, 0.0)
|
||||
SetScale(scene, root, scale, scale, scale)
|
||||
gaze := FigureGaze(joints)
|
||||
VrmLookAtSet(*figure.avatar, *figure.model, *figure.instance, gaze.x, gaze.y)
|
||||
FigureModelLive(figure, offset, scale, seconds)
|
||||
return GltfUpdateScene(*figure.model, *figure.instance, scene)
|
||||
if !GltfUpdateScene(*figure.model, *figure.instance, scene) {
|
||||
return false
|
||||
}
|
||||
FigureModelCloth(figure, scene, joints)
|
||||
return true
|
||||
}
|
||||
|
||||
// Drape only the named skirt emitted by prepare_attire.py. Other garment,
|
||||
// body, hair and slipper skins retain their existing deformation.
|
||||
FigureModelCloth :: (figure: *FigureModel, scene: *Scene, joints: *FigureJoints) {
|
||||
root := scene.nodes[figure.instance.root_node]
|
||||
scale := root.scale.x
|
||||
rest_hips := figure.rest_at[figure.bones[FIGURE_HIPS]]
|
||||
hip_world := FigureModelWorld(figure, scene, FIGURE_HIPS)
|
||||
forward := FigureRotate(FigureQuatNormalize(joints.pelvis_turn), .{0.0, 0.0, 1.0})
|
||||
lateral := FigureRotate(FigureQuatNormalize(joints.pelvis_turn), .{1.0, 0.0, 0.0})
|
||||
yaw := ifx lateral.x * lateral.x + lateral.z * lateral.z > 0.000001 then Atan2(-lateral.z, lateral.x) else Atan2(forward.x, forward.z)
|
||||
legs: [6]Vector3
|
||||
for side: cast(s32)0..1 {
|
||||
legs[side * 3] = FigureModelWorld(figure, scene, FigureSideRole(side, FIGURE_UPPER_LEG))
|
||||
legs[side * 3 + 1] = FigureModelWorld(figure, scene, FigureSideRole(side, FIGURE_LOWER_LEG))
|
||||
legs[side * 3 + 2] = FigureModelWorld(figure, scene, FigureSideRole(side, FIGURE_FOOT))
|
||||
}
|
||||
for index: 0..figure.instance.meshes.count - 1 {
|
||||
inst := *figure.instance.meshes[index]
|
||||
source := *figure.model.meshes[inst.mesh_index]
|
||||
name := TextView(source.name[:])
|
||||
skirt := name == "PracticeSkirt"
|
||||
tailored := !inst.skin.dual_quaternion && (name == "PracticeClothing" || name == "PracticeWrapFacings")
|
||||
if !skirt && !tailored {
|
||||
continue
|
||||
}
|
||||
mesh := scene.meshes[scene.nodes[inst.scene_node].mesh]
|
||||
if skirt {
|
||||
for vertex: 0..inst.skin.positions.count - 1 {
|
||||
rest := inst.skin.positions[vertex]
|
||||
skinned := FigureAdd(root.position, FigureScale(FigureRotate(figure.facing,
|
||||
scene.positions[mesh.first_vertex + vertex]), scale))
|
||||
point := FigureClothHang(skinned, rest, rest_hips, hip_world, figure.facing, yaw, scale)
|
||||
loose := FigureSmooth(rest_hips.y - rest.y, 0.015, 0.10)
|
||||
if loose > 0.0 {
|
||||
fallback := FigureRotate(figure.facing, .{rest.x - rest_hips.x, 0.0, rest.z - rest_hips.z})
|
||||
// Alternate projections resolve both legs when the skirt lies
|
||||
// between them, without changing the body or the foot contacts.
|
||||
for pass: 0..3 {
|
||||
for side: 0..1 {
|
||||
outside := FigureClothOutside(point, legs[side * 3], legs[side * 3 + 1], 0.078 * scale, fallback)
|
||||
point = FigureLerp(point, outside, loose)
|
||||
outside = FigureClothOutside(point, legs[side * 3 + 1], legs[side * 3 + 2], 0.054 * scale, fallback)
|
||||
point = FigureLerp(point, outside, loose)
|
||||
}
|
||||
}
|
||||
}
|
||||
point.y = FigureMax(point.y, 0.006)
|
||||
scene.positions[mesh.first_vertex + vertex] = FigureScale(FigureRotate(FigureConjugate(figure.facing),
|
||||
FigureSub(point, root.position)), 1.0 / scale)
|
||||
}
|
||||
}
|
||||
// Spread a point's displacement over neighbouring fabric edges.
|
||||
// The skirt keeps its skinned waist seam as the drape settles.
|
||||
stretch := ifx skirt then 1.6 else 2.2
|
||||
refresh_normals := skirt
|
||||
for pass: 0..11 {
|
||||
changed := false
|
||||
for edge: 0..mesh.index_count - 1 {
|
||||
next := edge - edge % 3 + (edge + 1) % 3
|
||||
a := scene.indices[mesh.first_index + edge]
|
||||
b := scene.indices[mesh.first_index + next]
|
||||
rest_a := inst.skin.positions[a]
|
||||
rest_b := inst.skin.positions[b]
|
||||
length := FigureDistance(rest_a, rest_b)
|
||||
if length < 0.001 {
|
||||
continue
|
||||
}
|
||||
point_a := *scene.positions[mesh.first_vertex + a]
|
||||
point_b := *scene.positions[mesh.first_vertex + b]
|
||||
delta := FigureSub(<<point_b, <<point_a)
|
||||
distance := FigureLength(delta)
|
||||
limit := length * stretch
|
||||
if distance <= limit {
|
||||
continue
|
||||
}
|
||||
weight_a := ifx skirt then FigureSmooth(rest_hips.y - rest_a.y, 0.015, 0.10) else 1.0
|
||||
weight_b := ifx skirt then FigureSmooth(rest_hips.y - rest_b.y, 0.015, 0.10) else 1.0
|
||||
if weight_a + weight_b <= 0.0 {
|
||||
continue
|
||||
}
|
||||
correction := FigureScale(delta, (1.0 - limit / distance) / (weight_a + weight_b))
|
||||
<<point_a = FigureAddScaled(<<point_a, correction, weight_a)
|
||||
<<point_b = FigureAddScaled(<<point_b, correction, -weight_b)
|
||||
changed = true
|
||||
}
|
||||
if !changed {
|
||||
break
|
||||
}
|
||||
refresh_normals = true
|
||||
}
|
||||
if refresh_normals {
|
||||
ComputeNormals(scene, inst.scene_node)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FigureModelWorld :: (figure: *FigureModel, scene: *Scene, role: s32) -> Vector3 {
|
||||
world := figure.instance.node_world[figure.bones[role]]
|
||||
root := scene.nodes[figure.instance.root_node]
|
||||
return FigureAdd(root.position, FigureScale(FigureRotate(figure.facing,
|
||||
.{world.m[3], world.m[7], world.m[11]}), root.scale.x))
|
||||
}
|
||||
|
||||
// Relaxed fingers have a small graduated curl; fists close every joint,
|
||||
// while a hook curls the tips further without clenching the knuckles.
|
||||
FigureFingerCurl :: (fist: float64, hook: float64, finger: s32, segment: s32) -> float64 {
|
||||
relaxed := 0.14 + cast(float64)finger * 0.025
|
||||
closed := relaxed + FigureClamp(fist, 0.0, 1.0) * 1.0
|
||||
if segment > 0 {
|
||||
closed += FigureClamp(hook, 0.0, 1.0) * 0.65
|
||||
}
|
||||
return FigureMin(1.35, closed) * ifx finger == 0 then 0.4 else 1.0
|
||||
}
|
||||
|
||||
// Eyes lead a gentle head turn rather than staring straight out of the
|
||||
// skull. The practice's head frame already follows its cued hand or gaze.
|
||||
// Return degrees left and up, bounded well within the VRM's lookAt curves.
|
||||
FigureGaze :: (joints: *FigureJoints) -> Vector3 {
|
||||
forward := FigureRotate(FigureQuatNormalize(joints.head_turn), FigureV3(0.0, 0.0, 1.0))
|
||||
relative := FigureRotate(FigureConjugate(FigureQuatNormalize(joints.chest_turn)), forward)
|
||||
yaw := Atan2(relative.x, relative.z) * 180.0 / FIGURE_PI
|
||||
pitch := Atan2(relative.y, Sqrt(relative.x * relative.x + relative.z * relative.z)) * 180.0 / FIGURE_PI
|
||||
return .{FigureClamp(yaw * 0.2, -8.0, 8.0), FigureClamp(pitch * 0.2, -5.0, 5.0), 0.0}
|
||||
}
|
||||
|
||||
// Place the measured shoe support on the solver's actual contact, rather
|
||||
// than assuming two avatars have the solver's ankle-to-sole dimensions.
|
||||
FigureModelSoleTarget :: (figure: *FigureModel, joints: *FigureJoints, side: s32, scale: float64) -> Vector3 {
|
||||
if figure.sole_count[side] == 0 || FigureDistance(joints.heels[side], joints.balls[side]) < 0.01 {
|
||||
return joints.ankles[side]
|
||||
}
|
||||
heel := joints.heels[side].y <= joints.balls[side].y
|
||||
contact := ifx heel then joints.heels[side] else joints.balls[side]
|
||||
relative := ifx heel then figure.sole_heel[side] else figure.sole_ball[side]
|
||||
relative.z *= figure.foot_stretch[side]
|
||||
turned := FigureRotate(FigureQuatNormalize(joints.feet[side]), FigureScale(relative, scale))
|
||||
target := FigureSub(contact, turned)
|
||||
lowest: float64 = 1000.0
|
||||
for index: cast(s32)0..figure.sole_count[side] - 1 {
|
||||
relative_point := figure.sole_points[side * 64 + index]
|
||||
relative_point.z *= figure.foot_stretch[side]
|
||||
point := FigureRotate(FigureQuatNormalize(joints.feet[side]), FigureScale(relative_point, scale))
|
||||
lowest = FigureMin(lowest, point.y)
|
||||
}
|
||||
target.y = contact.y - lowest
|
||||
return target
|
||||
}
|
||||
|
||||
// Measurements from the actual skinned slipper vertices in the scene.
|
||||
// Only contacts on the floor with the sole facing upward are planted.
|
||||
FigureContactMeasure :: struct {
|
||||
vertices: s64
|
||||
floor_error: float64
|
||||
flatness: float64
|
||||
pivot_error: float64
|
||||
}
|
||||
|
||||
FigureModelContacts :: (figure: *FigureModel, scene: *Scene, joints: *FigureJoints, surface_height: float64 = 0.0) -> FigureContactMeasure {
|
||||
result: FigureContactMeasure
|
||||
root := scene.nodes[figure.instance.root_node]
|
||||
for index: 0..figure.instance.meshes.count - 1 {
|
||||
inst := *figure.instance.meshes[index]
|
||||
source := *figure.model.meshes[inst.mesh_index]
|
||||
if TextView(source.name[:]) != "PracticeClothSlippers" {
|
||||
continue
|
||||
}
|
||||
side := inst.primitive_index
|
||||
heel_down := joints.heels[side].y <= joints.balls[side].y
|
||||
target := ifx heel_down then joints.heels[side] else joints.balls[side]
|
||||
up := FigureRotate(FigureQuatNormalize(joints.feet[side]), FigureV3(0.0, 1.0, 0.0))
|
||||
if FigureAbs(target.y - surface_height) > 0.000001 || up.y < 0.1 {
|
||||
continue
|
||||
}
|
||||
mesh := scene.meshes[scene.nodes[inst.scene_node].mesh]
|
||||
matrix := figure.instance.node_world[inst.gltf_node]
|
||||
low: float64 = 1000.0
|
||||
high: float64 = -1000.0
|
||||
back: float64 = 1000.0
|
||||
front: float64 = -1000.0
|
||||
heel: Vector3
|
||||
ball: Vector3
|
||||
for vertex: 0..inst.skin.positions.count - 1 {
|
||||
rest := inst.skin.positions[vertex]
|
||||
if FigureAbs(rest.y) > 0.000001 {
|
||||
continue
|
||||
}
|
||||
point := scene.positions[mesh.first_vertex + vertex]
|
||||
in_model := FigureV3(matrix.m[0] * point.x + matrix.m[1] * point.y + matrix.m[2] * point.z + matrix.m[3],
|
||||
matrix.m[4] * point.x + matrix.m[5] * point.y + matrix.m[6] * point.z + matrix.m[7],
|
||||
matrix.m[8] * point.x + matrix.m[9] * point.y + matrix.m[10] * point.z + matrix.m[11])
|
||||
actual := FigureAdd(root.position, FigureScale(FigureRotate(figure.facing, in_model), root.scale.x))
|
||||
low = FigureMin(low, actual.y)
|
||||
high = FigureMax(high, actual.y)
|
||||
along := FigureRotate(figure.facing, rest).z
|
||||
if along < back {
|
||||
back = along
|
||||
heel = actual
|
||||
}
|
||||
if along > front {
|
||||
front = along
|
||||
ball = actual
|
||||
}
|
||||
result.vertices += 1
|
||||
}
|
||||
result.floor_error = FigureMax(result.floor_error, FigureAbs(low - surface_height))
|
||||
if up.y > 0.999999 {
|
||||
result.flatness = FigureMax(result.flatness, high - low)
|
||||
}
|
||||
result.pivot_error = FigureMax(result.pivot_error, FigureDistance(ifx heel_down then heel else ball, target))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// How closed the eyes are at SECONDS: a blink every two to five seconds,
|
||||
@@ -294,9 +583,9 @@ FigureBlink :: (seconds: float64) -> float64 {
|
||||
cast(float64)twice * 0.32
|
||||
t := seconds - start
|
||||
if t >= 0.0 && t < 0.07 {
|
||||
closed = FigureMax(closed, FigureSmooth(t / 0.07))
|
||||
closed = FigureMax(closed, FigureSmooth(t, 0.0, 0.07))
|
||||
} else if t >= 0.07 && t < 0.2 {
|
||||
closed = FigureMax(closed, 1.0 - FigureSmooth((t - 0.07) / 0.13))
|
||||
closed = FigureMax(closed, 1.0 - FigureSmooth(t - 0.07, 0.0, 0.13))
|
||||
}
|
||||
}
|
||||
return closed
|
||||
@@ -349,11 +638,6 @@ FigureHash :: (value: float64) -> float64 {
|
||||
return wave - cast(float64)cast(s64)wave + ifx wave < 0.0 then 1.0 else 0.0
|
||||
}
|
||||
|
||||
FigureSmooth :: (u: float64) -> float64 {
|
||||
t := FigureClamp(u, 0.0, 1.0)
|
||||
return t * t * (3.0 - 2.0 * t)
|
||||
}
|
||||
|
||||
// The live parts of a VRM model at SECONDS: springs placed in the world as
|
||||
// the root is, swinging since the last pose (settled and hung at rest on a
|
||||
// still pose, a seek or the first one), and the eyes' blink.
|
||||
@@ -425,6 +709,110 @@ FigureModelRest :: (figure: *FigureModel, role: s32, fallback: s32) -> Vector3 {
|
||||
return ifx node >= 0 then figure.rest_at[node] else Vector3.{}
|
||||
}
|
||||
|
||||
// The generated slippers are separate primitives with one rigid foot
|
||||
// weight. Measure the actual underside vertices; no guessed ankle height.
|
||||
FigureModelReadSoles :: (figure: *FigureModel) {
|
||||
figure.sole_count[0] = 0
|
||||
figure.sole_count[1] = 0
|
||||
for mesh_index: 0..figure.model.meshes.count - 1 {
|
||||
mesh := *figure.model.meshes[mesh_index]
|
||||
if TextView(mesh.name[:]) != "PracticeClothSlippers" || mesh.primitives.count != 2 {
|
||||
continue
|
||||
}
|
||||
for side: cast(s32)0..1 {
|
||||
primitive := *mesh.primitives[side]
|
||||
low: float64 = 1000.0
|
||||
for point: primitive.positions[:] {
|
||||
low = FigureMin(low, point.y)
|
||||
}
|
||||
ankle := FigureModelRest(figure, FigureSideRole(side, FIGURE_FOOT), -1)
|
||||
back: float64 = 1000.0
|
||||
front: float64 = -1000.0
|
||||
for point: primitive.positions[:] {
|
||||
if point.y > low + 0.000001 || figure.sole_count[side] >= 64 {
|
||||
continue
|
||||
}
|
||||
relative := FigureRotate(figure.facing, FigureSub(point, ankle))
|
||||
figure.sole_points[side * 64 + figure.sole_count[side]] = relative
|
||||
figure.sole_count[side] += 1
|
||||
if relative.z < back {
|
||||
back = relative.z
|
||||
figure.sole_heel[side] = relative
|
||||
}
|
||||
if relative.z > front {
|
||||
front = relative.z
|
||||
figure.sole_ball[side] = relative
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply world-space bone turns as local glTF rotations. Unmapped nodes
|
||||
// retain their bind rotation and inherit the nearest posed ancestor.
|
||||
FigureModelSetTurns :: (figure: *FigureModel, turns: []FigureQuat) {
|
||||
// Each node turns with the nearest posed bone above it.
|
||||
for at: 0..figure.order.count - 1 {
|
||||
node := figure.order[at]
|
||||
parent := figure.model.nodes[node].parent
|
||||
role := figure.role_of[node]
|
||||
figure.turn[node] = ifx role >= 0 then turns[role] else ifx parent >= 0 then figure.turn[parent] else FigureIdentity()
|
||||
if role < 0 {
|
||||
continue
|
||||
}
|
||||
// World rotation now: the figure-space turn carried into the
|
||||
// model's space; the local rotation is that against the parent's.
|
||||
inverse_facing := FigureConjugate(figure.facing)
|
||||
mine := FigureMultiply(FigureMultiply(FigureMultiply(inverse_facing, figure.turn[node]), figure.facing),
|
||||
figure.rest_turn[node])
|
||||
above := FigureIdentity()
|
||||
if parent >= 0 {
|
||||
above = FigureMultiply(FigureMultiply(FigureMultiply(inverse_facing, figure.turn[parent]), figure.facing),
|
||||
figure.rest_turn[parent])
|
||||
}
|
||||
local := FigureQuatNormalize(FigureMultiply(FigureConjugate(above), mine))
|
||||
figure.instance.rotations[node] = .{local.x, local.y, local.z, local.w}
|
||||
figure.instance.trs_dirty[node] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Retarget a limb with its own segment lengths. The knee/elbow keeps the
|
||||
// solver's bend plane; unreachable targets stop just short of full reach.
|
||||
FigureModelReach :: (figure: *FigureModel, turns: []FigureQuat, base: FigureQuat,
|
||||
upper: s32, lower: s32, end: s32, target: Vector3, bend: Vector3, offset: Vector3, scale: float64) {
|
||||
if figure.bones[upper] < 0 || figure.bones[lower] < 0 || figure.bones[end] < 0 {
|
||||
return
|
||||
}
|
||||
origin := FigureAdd(offset, FigureScale(FigureRotate(figure.facing,
|
||||
FigureModelPosed(figure, figure.bones[upper])), scale))
|
||||
first := FigureDistance(FigureModelRest(figure, upper, -1), FigureModelRest(figure, lower, -1)) * scale
|
||||
second := FigureDistance(FigureModelRest(figure, lower, -1), FigureModelRest(figure, end, -1)) * scale
|
||||
if first < 0.000001 || second < 0.000001 {
|
||||
return
|
||||
}
|
||||
delta := FigureSub(target, origin)
|
||||
distance := FigureLength(delta)
|
||||
if distance < 0.000001 {
|
||||
return
|
||||
}
|
||||
direction := FigureScale(delta, 1.0 / distance)
|
||||
distance = FigureClamp(distance, FigureAbs(first - second) + 0.000001, first + second - 0.000001)
|
||||
pole := FigureSub(bend, origin)
|
||||
pole = FigureAddScaled(pole, direction, -FigureDot(pole, direction))
|
||||
if FigureLength(pole) < 0.000001 {
|
||||
pole = FigureAddScaled(FigureV3(0.0, 0.0, 1.0), direction, -direction.z)
|
||||
}
|
||||
if FigureLength(pole) < 0.000001 {
|
||||
pole = FigureCross(direction, FigureV3(1.0, 0.0, 0.0))
|
||||
}
|
||||
along := (first * first - second * second + distance * distance) / (2.0 * distance)
|
||||
across := Sqrt(FigureMax(first * first - along * along, 0.0))
|
||||
middle := FigureAddScaled(FigureAddScaled(origin, direction, along), FigureNormalize(pole), across)
|
||||
endpoint := FigureAddScaled(origin, direction, distance)
|
||||
turns[upper] = FigureModelAim(figure, base, upper, lower, FigureSub(middle, origin))
|
||||
turns[lower] = FigureModelAim(figure, turns[upper], lower, end, FigureSub(endpoint, middle))
|
||||
}
|
||||
|
||||
// BASE carried on, then swung so the bone from ROLE to NEXT points along
|
||||
// TARGET (in the figure's space).
|
||||
FigureModelAim :: (figure: *FigureModel, base: FigureQuat, role: s32, next: s32, target: Vector3) -> FigureQuat {
|
||||
@@ -438,6 +826,20 @@ FigureModelAim :: (figure: *FigureModel, base: FigureQuat, role: s32, next: s32,
|
||||
return FigureQuatNormalize(FigureMultiply(FigureSwing(FigureRotate(base, rest), target), base))
|
||||
}
|
||||
|
||||
// Palm frames use -Y along the fingers and +Z out of the palm. Convert
|
||||
// that frame to the model's bind pose once, rather than letting the wrist
|
||||
// inherit the forearm and discard the technique's cued palm turns.
|
||||
FigureModelHandRest :: (figure: *FigureModel, side: s32) -> FigureQuat {
|
||||
wrist := FigureModelRest(figure, FigureSideRole(side, FIGURE_HAND), -1)
|
||||
middle := FigureModelRest(figure, FigureFingerRole(side, 2, 0), FigureSideRole(side, FIGURE_HAND))
|
||||
along := FigureNormalize(FigureRotate(figure.facing, FigureSub(middle, wrist)))
|
||||
if FigureLength(along) < 0.000001 {
|
||||
along = FigureNormalize(FigureRotate(figure.facing, FigureSub(wrist,
|
||||
FigureModelRest(figure, FigureSideRole(side, FIGURE_LOWER_ARM), -1))))
|
||||
}
|
||||
return FigureFrame(FigureScale(along, -1.0), FigureV3(0.0, -1.0, 0.0), FigureV3(0.0, 0.0, 1.0))
|
||||
}
|
||||
|
||||
// The axis a finger segment curls about at rest, in the figure's space:
|
||||
// across the finger, towards the palm (which faces down in a T pose and
|
||||
// in towards the body in an A pose).
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build calm cross-collar meditation clothes on the owner's CC0 VRoid figures.
|
||||
|
||||
Starts with prepare_slippers' checksummed originals. Keeps identity, original
|
||||
texture bytes, skeleton, hair, body and slippers. Reuses the fitted garment
|
||||
surface and bind weights, removes the man's hood/cords, relaxes his trousers,
|
||||
and adds real crossed lapel/sash geometry. The woman's flared skirt remains
|
||||
separate so the runtime can drape it under gravity during folds.
|
||||
"""
|
||||
import argparse
|
||||
import copy
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
|
||||
import numpy as np
|
||||
from prepare_slippers import prepare, ORIGINAL, COMPONENT, WIDTH
|
||||
|
||||
|
||||
def sha(path):
|
||||
with path.open('rb') as stream:
|
||||
return hashlib.file_digest(stream, 'sha256').hexdigest()
|
||||
|
||||
|
||||
class Asset:
|
||||
def __init__(self, path):
|
||||
with path.open('rb') as stream:
|
||||
assert struct.unpack('<III', stream.read(12))[:2] == (0x46546C67, 2)
|
||||
size, kind = struct.unpack('<II', stream.read(8))
|
||||
assert kind == 0x4E4F534A
|
||||
self.doc = json.loads(stream.read(size))
|
||||
size, kind = struct.unpack('<II', stream.read(8))
|
||||
assert kind == 0x004E4942
|
||||
self.binary = bytearray(stream.read(size))
|
||||
|
||||
def read(self, index):
|
||||
a = self.doc['accessors'][index]
|
||||
v = self.doc['bufferViews'][a['bufferView']]
|
||||
dtype = np.dtype(COMPONENT[a['componentType']])
|
||||
width = WIDTH[a['type']]
|
||||
return np.ndarray((a['count'], width), dtype=dtype, buffer=self.binary,
|
||||
offset=v.get('byteOffset', 0) + a.get('byteOffset', 0),
|
||||
strides=(v.get('byteStride', dtype.itemsize * width), dtype.itemsize)).copy()
|
||||
|
||||
def append(self, values, component, kind):
|
||||
values = np.asarray(values, dtype=COMPONENT[component])
|
||||
self.binary.extend(b'\0' * (-len(self.binary) % 4))
|
||||
view = len(self.doc['bufferViews'])
|
||||
self.doc['bufferViews'].append({'buffer': 0, 'byteOffset': len(self.binary), 'byteLength': values.nbytes})
|
||||
self.binary.extend(values.tobytes())
|
||||
a = {'bufferView': view, 'componentType': component, 'count': len(values), 'type': kind}
|
||||
if kind == 'VEC3':
|
||||
a.update(min=values.min(0).tolist(), max=values.max(0).tolist())
|
||||
self.doc['accessors'].append(a)
|
||||
return len(self.doc['accessors']) - 1
|
||||
|
||||
def material(self, name, color):
|
||||
d = self.doc
|
||||
i = len(d['materials'])
|
||||
d['materials'].append({'name': name, 'doubleSided': True,
|
||||
'pbrMetallicRoughness': {'baseColorFactor': color,
|
||||
'roughnessFactor': 1, 'metallicFactor': 0}})
|
||||
d['extensions']['VRM']['materialProperties'].append({
|
||||
'name': name, 'shader': 'VRM/MToon', 'renderQueue': -1,
|
||||
'floatProperties': {'_Cutoff': .5, '_CullMode': 0, '_BlendMode': 0},
|
||||
'vectorProperties': {'_Color': color, '_ShadeColor': color},
|
||||
'textureProperties': {}, 'keywordMap': {}, 'tagMap': {}})
|
||||
return i
|
||||
|
||||
def primitive(self, attrs, triangles, material):
|
||||
# Compact the garment so its skin has only actual cloth vertices.
|
||||
used, indices = np.unique(np.asarray(triangles).reshape(-1), return_inverse=True)
|
||||
kinds = {'POSITION': (5126, 'VEC3'), 'NORMAL': (5126, 'VEC3'),
|
||||
'TEXCOORD_0': (5126, 'VEC2'), 'JOINTS_0': (5123, 'VEC4'), 'WEIGHTS_0': (5126, 'VEC4')}
|
||||
return {'attributes': {key: self.append(values[used], *kinds[key]) for key, values in attrs.items()},
|
||||
'indices': self.append(indices.reshape(-1, 1), 5123, 'SCALAR'), 'material': material, 'mode': 4}
|
||||
|
||||
def mesh(self, parent_node, name, primitives):
|
||||
d = self.doc
|
||||
node = d['nodes'][parent_node]
|
||||
mesh = len(d['meshes'])
|
||||
d['meshes'].append({'name': name, 'primitives': primitives})
|
||||
new = len(d['nodes'])
|
||||
d['nodes'].append({**node, 'name': name, 'mesh': mesh})
|
||||
parent = next((n for n in d['nodes'][:new] if parent_node in n.get('children', [])), None)
|
||||
if parent is not None:
|
||||
parent['children'].append(new)
|
||||
else:
|
||||
for scene in d['scenes']:
|
||||
if parent_node in scene['nodes']:
|
||||
scene['nodes'].append(new)
|
||||
|
||||
def save(self, path):
|
||||
self.binary.extend(b'\0' * (-len(self.binary) % 4))
|
||||
self.doc['buffers'][0]['byteLength'] = len(self.binary)
|
||||
data = json.dumps(self.doc, separators=(',', ':'), ensure_ascii=False).encode()
|
||||
data += b' ' * (-len(data) % 4)
|
||||
with path.open('wb') as stream:
|
||||
stream.write(struct.pack('<III', 0x46546C67, 2, 28 + len(data) + len(self.binary)))
|
||||
stream.write(struct.pack('<II', len(data), 0x4E4F534A))
|
||||
stream.write(data)
|
||||
stream.write(struct.pack('<II', len(self.binary), 0x004E4942))
|
||||
stream.write(self.binary)
|
||||
|
||||
|
||||
def ribbon(asset, attrs, points, width, material, candidates):
|
||||
"""A narrow real cloth facing fitted to the source top, with its weights."""
|
||||
source = attrs['POSITION']
|
||||
front = candidates[(np.abs(source[candidates, 0]) < .24) & (source[candidates, 2] < -.02)]
|
||||
values = {key: [] for key in attrs}
|
||||
for i, (x, y) in enumerate(points):
|
||||
# Fit depth to the local front surface instead of a floating flat stripe.
|
||||
distance = (source[front, 0] - x) ** 2 + (source[front, 1] - y) ** 2
|
||||
nearest = front[np.argsort(distance)[:6]]
|
||||
z = float(np.min(source[nearest, 2])) - .006
|
||||
nearest = int(nearest[0])
|
||||
tangent = np.array(points[min(i + 1, len(points) - 1)]) - np.array(points[max(0, i - 1)])
|
||||
across = np.array([-tangent[1], tangent[0]])
|
||||
across /= max(float(np.linalg.norm(across)), 1e-8)
|
||||
for sign in (-1, 1):
|
||||
for key in attrs:
|
||||
value = attrs[key][nearest].copy()
|
||||
if key == 'POSITION':
|
||||
value = [x + sign * width * across[0] / 2, y + sign * width * across[1] / 2, z]
|
||||
elif key == 'NORMAL':
|
||||
value = [0, 0, -1]
|
||||
values[key].append(value)
|
||||
triangles = []
|
||||
for i in range(len(points) - 1):
|
||||
a = i * 2
|
||||
triangles.extend([[a, a + 2, a + 1], [a + 1, a + 2, a + 3]])
|
||||
return asset.primitive({key: np.array(value) for key, value in values.items()}, triangles, material)
|
||||
|
||||
|
||||
def blend_sleeves(asset, attrs, skin):
|
||||
"""Grade the sleeve weights so they follow the bent shoulder and elbow."""
|
||||
joint_indices = {asset.doc['nodes'][node].get('name'): index for index, node in enumerate(skin['joints'])}
|
||||
bind = asset.read(skin['inverseBindMatrices'])
|
||||
positions, joints, weights = (attrs[key] for key in ('POSITION', 'JOINTS_0', 'WEIGHTS_0'))
|
||||
for side in ('L', 'R'):
|
||||
upper, lower = (joint_indices[f'J_Bip_{side}_{part}Arm'] for part in ('Upper', 'Lower'))
|
||||
shoulder = np.linalg.inv(bind[upper].reshape((4, 4), order='F'))[:3, 3]
|
||||
elbow = np.linalg.inv(bind[lower].reshape((4, 4), order='F'))[:3, 3]
|
||||
along = elbow - shoulder
|
||||
distance = (positions - elbow) @ (along / np.linalg.norm(along))
|
||||
sleeve = np.sum(np.where((joints == upper) | (joints == lower), weights, 0), axis=1) >= .999
|
||||
forearm = np.clip((distance[sleeve] + .11) / .22, 0, 1)
|
||||
forearm *= forearm * (3 - 2 * forearm)
|
||||
joints[sleeve] = [upper, lower, 0, 0]
|
||||
weights[sleeve] = np.column_stack((1 - forearm, forearm, np.zeros((len(forearm), 2))))
|
||||
|
||||
|
||||
def blend_trouser_seat(asset, attrs, skin):
|
||||
"""Keep the waistband on the hips and let each trouser leg follow its thigh."""
|
||||
names = [asset.doc['nodes'][node].get('name') for node in skin['joints']]
|
||||
hips, left, right = (names.index(name) for name in ('J_Bip_C_Hips', 'J_Bip_L_UpperLeg', 'J_Bip_R_UpperLeg'))
|
||||
bind = asset.read(skin['inverseBindMatrices'])[hips].reshape((4, 4), order='F')
|
||||
waist = np.linalg.inv(bind)[:3, 3]
|
||||
positions, joints, weights = (attrs[key] for key in ('POSITION', 'JOINTS_0', 'WEIGHTS_0'))
|
||||
left_shin, right_shin = (names.index(f'J_Bip_{side}_LowerLeg') for side in ('L', 'R'))
|
||||
seat = np.sum(np.where(np.isin(joints, [hips, left, right]), weights, 0), axis=1) >= .90
|
||||
seat &= waist[1] - positions[:, 1] < .43
|
||||
x = waist[0] - positions[seat, 0]
|
||||
depth = waist[1] - positions[seat, 1]
|
||||
leg = np.clip((depth - .02) / .23, 0, 1)
|
||||
leg *= leg * (3 - 2 * leg)
|
||||
width = .095 * np.clip((.43 - depth) / .15, 0, 1)
|
||||
side = np.clip((x + width) / (2 * width), 0, 1)
|
||||
side *= side * (3 - 2 * side)
|
||||
shin = np.where(x >= 0, left_shin, right_shin)
|
||||
shin_weight = np.sum(np.where(joints[seat] == shin[:, None], weights[seat], 0), axis=1)
|
||||
joints[seat] = np.column_stack((np.full(len(leg), hips), np.full(len(leg), left), np.full(len(leg), right), shin))
|
||||
weights[seat] = np.column_stack((1 - leg, leg * side, leg * (1 - side), np.zeros(len(leg)))) * (1 - shin_weight[:, None])
|
||||
weights[seat, 3] = shin_weight
|
||||
|
||||
|
||||
def diffuse_garment_weights(attrs, triangles, joint_count):
|
||||
"""Smooth neighboring skin weights, including across UV seams."""
|
||||
used, indices = np.unique(triangles.reshape(-1), return_inverse=True)
|
||||
positions = attrs['POSITION'][used]
|
||||
_, welded = np.unique(np.round(positions, 5), axis=0, return_inverse=True)
|
||||
triangles = welded[indices].reshape(-1, 3)
|
||||
edges = np.concatenate([triangles[:, [0, 1]], triangles[:, [1, 2]], triangles[:, [2, 0]]])
|
||||
edges = np.unique(np.concatenate([edges, edges[:, ::-1]]), axis=0)
|
||||
source, neighbor = edges[edges[:, 0] != edges[:, 1]].T
|
||||
neighbors = np.bincount(source, minlength=int(welded.max()) + 1)[:, None]
|
||||
weights = np.zeros((len(neighbors), joint_count), dtype=np.float64)
|
||||
np.add.at(weights, (welded[:, None], attrs['JOINTS_0'][used]), attrs['WEIGHTS_0'][used])
|
||||
weights /= np.sum(weights, axis=1, keepdims=True)
|
||||
for _ in range(5):
|
||||
average = np.zeros_like(weights)
|
||||
np.add.at(average, source, weights[neighbor])
|
||||
weights = np.where(neighbors, .4 * weights + .6 * average / np.maximum(neighbors, 1), weights)
|
||||
strongest = np.argsort(-weights, axis=1, kind='stable')[:, :4][welded]
|
||||
values = np.take_along_axis(weights[welded], strongest, axis=1)
|
||||
attrs['JOINTS_0'][used] = strongest
|
||||
attrs['WEIGHTS_0'][used] = values / np.sum(values, axis=1, keepdims=True)
|
||||
|
||||
|
||||
def dress(source, target, person):
|
||||
slippers = prepare(source, target, person)
|
||||
asset = Asset(target)
|
||||
d = asset.doc
|
||||
body_node = next(i for i, n in enumerate(d['nodes']) if n.get('name') == 'Body')
|
||||
body = d['meshes'][d['nodes'][body_node]['mesh']]
|
||||
skin = d['skins'][d['nodes'][body_node]['skin']]
|
||||
top = asset.material('Practice_Linen_Wrap', [.76, .79, .69, 1] if person == 'woman' else [.36, .46, .39, 1])
|
||||
bottom = asset.material('Practice_Linen_Skirt' if person == 'woman' else 'Practice_Relaxed_Trousers',
|
||||
[.22, .36, .33, 1] if person == 'woman' else [.25, .29, .27, 1])
|
||||
trim = asset.material('Practice_Crossed_Cloth_Facing', [.16, .27, .24, 1])
|
||||
kept, changed, skirt, trims, cloth = [], [], [], [], []
|
||||
for primitive_index, primitive in enumerate(body['primitives']):
|
||||
name = d['materials'][primitive['material']]['name']
|
||||
if 'CLOTH' not in name:
|
||||
kept.append(primitive)
|
||||
continue
|
||||
attrs = {key: asset.read(index) for key, index in primitive['attributes'].items()}
|
||||
triangles = asset.read(primitive['indices']).reshape(-1, 3)
|
||||
if 'Tops' in name:
|
||||
blend_sleeves(asset, attrs, skin)
|
||||
if person == 'man':
|
||||
# The hood and drawstrings have their own spring-bone weights.
|
||||
hood = [i for i, node in enumerate(skin['joints']) if 'Hood' in d['nodes'][node].get('name', '')]
|
||||
hood_weight = np.sum(np.where(np.isin(attrs['JOINTS_0'], hood), attrs['WEIGHTS_0'], 0), axis=1)
|
||||
triangles = triangles[np.max(hood_weight[triangles], axis=1) < .01]
|
||||
if person == 'woman':
|
||||
lower = np.mean(attrs['POSITION'][triangles, 1], axis=1) < .975
|
||||
skirt.append(asset.primitive(attrs, triangles[lower], bottom))
|
||||
triangles = triangles[~lower]
|
||||
if person == 'man':
|
||||
diffuse_garment_weights(attrs, triangles, len(skin['joints']))
|
||||
top_attrs = copy.deepcopy(attrs)
|
||||
cloth.append(asset.primitive(attrs, triangles, top))
|
||||
# Two overlapping facings describe a left-over-right wrap closure.
|
||||
neck_y, waist_y = (1.375, 1.005) if person == 'woman' else (1.46, 1.06)
|
||||
points = [(float(-.043 + u * .15), float(neck_y + u * (waist_y - neck_y))) for u in np.linspace(0, 1, 18)]
|
||||
trims.append(ribbon(asset, top_attrs, points, .022, trim, np.unique(triangles)))
|
||||
points = [(float(.043 - u * .087), float(neck_y - u * .18)) for u in np.linspace(0, 1, 10)]
|
||||
trims.append(ribbon(asset, top_attrs, points, .018, trim, np.unique(triangles)))
|
||||
# Fitted sash follows the waist surface, not a rigid accessory.
|
||||
sash = np.abs(top_attrs['POSITION'][:, 1] - waist_y) < .035
|
||||
sash_triangles = asset.read(primitive['indices']).reshape(-1, 3)
|
||||
sash_triangles = sash_triangles[np.all(sash[sash_triangles], axis=1)]
|
||||
if len(sash_triangles):
|
||||
top_attrs['POSITION'][:, 0] *= 1.008
|
||||
top_attrs['POSITION'][:, 2] *= 1.012
|
||||
trims.append(asset.primitive(top_attrs, sash_triangles, trim))
|
||||
else:
|
||||
# Relax the trousers around each leg while leaving the ankle cuff.
|
||||
blend_trouser_seat(asset, attrs, skin)
|
||||
diffuse_garment_weights(attrs, triangles, len(skin['joints']))
|
||||
xyz = attrs['POSITION']
|
||||
used = np.unique(triangles)
|
||||
u = np.clip((xyz[used, 1] - .10) / .88, 0, 1)
|
||||
expansion = .022 * np.sin(np.pi * u)
|
||||
# Expand around each leg's centre, rather than translating both
|
||||
# walls outward and exposing skin at the inside of the trousers.
|
||||
center_x = np.sign(xyz[used, 0]) * (.061 + .018 * np.clip((xyz[used, 1] - .45) / .45, 0, 1))
|
||||
radial_x = xyz[used, 0] - center_x
|
||||
radial_z = xyz[used, 2] - .01
|
||||
length = np.maximum(np.sqrt(radial_x ** 2 + radial_z ** 2), 1e-6)
|
||||
xyz[used, 0] += radial_x / length * expansion
|
||||
xyz[used, 2] += radial_z / length * expansion
|
||||
normals = np.zeros_like(attrs['NORMAL'])
|
||||
cross = np.cross(xyz[triangles[:, 1]] - xyz[triangles[:, 0]], xyz[triangles[:, 2]] - xyz[triangles[:, 0]])
|
||||
for corner in range(3):
|
||||
np.add.at(normals, triangles[:, corner], cross)
|
||||
length = np.linalg.norm(normals, axis=1)
|
||||
normals[length > 1e-8] /= length[length > 1e-8, None]
|
||||
attrs['NORMAL'][used] = normals[used]
|
||||
cloth.append(asset.primitive(attrs, triangles, bottom))
|
||||
changed.append({'original_primitive': primitive_index, 'original_material': name})
|
||||
body['primitives'] = kept
|
||||
asset.mesh(body_node, 'PracticeClothing', cloth)
|
||||
if skirt:
|
||||
asset.mesh(body_node, 'PracticeSkirt', skirt)
|
||||
asset.mesh(body_node, 'PracticeWrapFacings', trims)
|
||||
# Removed hood springs have no visible geometry; keep skeleton compatibility.
|
||||
asset.save(target)
|
||||
slippers['output_sha256'] = sha(target)
|
||||
return slippers, {'source_sha256': ORIGINAL[person], 'output_sha256': sha(target),
|
||||
'changed_body_primitives': changed, 'skirt_preserved': person == 'woman',
|
||||
'identity': 'Original face, hair, body, skeleton and flat slippers retained',
|
||||
'style': 'Matte linen cross-collar wrap, plain sash and flared skirt' if person == 'woman'
|
||||
else 'Matte linen cross-collar tunic and relaxed trousers; hood/cord meshes removed'}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--source-dir', required=True, type=Path)
|
||||
parser.add_argument('--output-dir', default=Path('shared/figure'), type=Path)
|
||||
args = parser.parse_args()
|
||||
slippers, attire = {}, {}
|
||||
for person in ORIGINAL:
|
||||
slippers[person], attire[person] = dress(args.source_dir / f'{person}.vrm', args.output_dir / f'{person}.vrm', person)
|
||||
(args.output_dir / 'slippers.json').write_text(json.dumps(slippers, indent=2) + '\n')
|
||||
(args.output_dir / 'attire.json').write_text(json.dumps(attire, indent=2) + '\n')
|
||||
print('Prepared both traditional-inspired meditation outfits; original CC0 identities and flat slippers retained')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,174 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Replace only the CC0 samples' shoe primitives with simple cloth slippers.
|
||||
|
||||
Inputs must be the unmodified, checksummed VRoid samples (see MODELS.md).
|
||||
Textures, body/clothing/hair geometry, skeleton, expressions and springs
|
||||
are retained byte for byte. New slippers have one flat sole plane, no heel,
|
||||
and rigid foot weights so heel/ball pivots preserve that measured plane.
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
import struct
|
||||
|
||||
import numpy as np
|
||||
|
||||
ORIGINAL = {
|
||||
'woman': 'adfd242317aaabc773f31f7fff7b013979fbb5baa47e97427a78913d9cb4e979',
|
||||
'man': '7aeca142dabbc26ba0f5b9c998c8f3cb6df341287d67788427ac837223785a3f',
|
||||
}
|
||||
COMPONENT = {5121: '<u1', 5123: '<u2', 5125: '<u4', 5126: '<f4'}
|
||||
WIDTH = {'SCALAR': 1, 'VEC2': 2, 'VEC3': 3, 'VEC4': 4, 'MAT4': 16}
|
||||
|
||||
|
||||
def prepare(source, target, person):
|
||||
if hashlib.file_digest(source.open('rb'), 'sha256').hexdigest() != ORIGINAL[person]:
|
||||
raise ValueError(f'{source}: expected the original CC0 sample')
|
||||
with source.open('rb') as stream:
|
||||
magic, version, _ = struct.unpack('<III', stream.read(12))
|
||||
size, kind = struct.unpack('<II', stream.read(8))
|
||||
assert magic == 0x46546C67 and version == 2 and kind == 0x4E4F534A
|
||||
doc = json.loads(stream.read(size))
|
||||
size, kind = struct.unpack('<II', stream.read(8))
|
||||
assert kind == 0x004E4942
|
||||
binary = bytearray(stream.read(size))
|
||||
|
||||
def read(index):
|
||||
accessor = doc['accessors'][index]
|
||||
view = doc['bufferViews'][accessor['bufferView']]
|
||||
dtype = np.dtype(COMPONENT[accessor['componentType']])
|
||||
count, width = accessor['count'], WIDTH[accessor['type']]
|
||||
return np.ndarray((count, width), dtype=dtype, buffer=binary,
|
||||
offset=view.get('byteOffset', 0) + accessor.get('byteOffset', 0),
|
||||
strides=(view.get('byteStride', dtype.itemsize * width), dtype.itemsize)).copy()
|
||||
|
||||
def append(values, component, kind):
|
||||
values = np.asarray(values, dtype=COMPONENT[component])
|
||||
binary.extend(b'\0' * (-len(binary) % 4))
|
||||
view = len(doc['bufferViews'])
|
||||
doc['bufferViews'].append({'buffer': 0, 'byteOffset': len(binary), 'byteLength': values.nbytes})
|
||||
binary.extend(values.tobytes())
|
||||
accessor = len(doc['accessors'])
|
||||
spec = {'bufferView': view, 'componentType': component, 'count': len(values), 'type': kind}
|
||||
if kind == 'VEC3':
|
||||
spec.update(min=values.min(axis=0).tolist(), max=values.max(axis=0).tolist())
|
||||
doc['accessors'].append(spec)
|
||||
return accessor
|
||||
|
||||
shoe_material = next(i for i, material in enumerate(doc['materials']) if 'Shoes' in material['name'])
|
||||
body_node = next(i for i, node in enumerate(doc['nodes']) if 'mesh' in node and
|
||||
any(p.get('material') == shoe_material for p in doc['meshes'][node['mesh']]['primitives']))
|
||||
node = doc['nodes'][body_node]
|
||||
old = doc['meshes'][node['mesh']]
|
||||
original_points = []
|
||||
for primitive in old['primitives']:
|
||||
if primitive.get('material') == shoe_material:
|
||||
original_points.extend(read(primitive['attributes']['POSITION'])[np.unique(read(primitive['indices']))])
|
||||
original_points = np.array(original_points)
|
||||
old['primitives'] = [p for p in old['primitives'] if p.get('material') != shoe_material]
|
||||
material = len(doc['materials'])
|
||||
color = [.44, .43, .39, 1] if person == 'woman' else [.25, .27, .26, 1]
|
||||
doc['materials'].append({'name': 'Practice_Matte_Cloth', 'doubleSided': False,
|
||||
'pbrMetallicRoughness': {'baseColorFactor': color, 'metallicFactor': 0,
|
||||
'roughnessFactor': 1}})
|
||||
doc['extensions']['VRM']['materialProperties'].append({
|
||||
'name': 'Practice_Matte_Cloth', 'shader': 'VRM/MToon', 'renderQueue': -1,
|
||||
'floatProperties': {'_Cutoff': .5, '_CullMode': 2, '_BlendMode': 0},
|
||||
'vectorProperties': {'_Color': color, '_ShadeColor': color},
|
||||
'textureProperties': {}, 'keywordMap': {}, 'tagMap': {}})
|
||||
slippers = {'name': 'PracticeClothSlippers', 'primitives': []}
|
||||
measurements = []
|
||||
segments = 32
|
||||
for side in ['L', 'R']:
|
||||
foot_node = next(i for i, n in enumerate(doc['nodes']) if n.get('name') == f'J_Bip_{side}_Foot')
|
||||
joint = doc['skins'][node['skin']]['joints'].index(foot_node)
|
||||
inverse_bind = read(doc['skins'][node['skin']]['inverseBindMatrices'])[joint].reshape(4, 4).T
|
||||
foot_bind = np.linalg.inv(inverse_bind)
|
||||
sign = 1 if foot_bind[0, 3] > 0 else -1
|
||||
points = original_points[original_points[:, 0] * sign > 0]
|
||||
lower, upper = points.min(axis=0), points.max(axis=0)
|
||||
center_x = float((lower[0] + upper[0]) / 2)
|
||||
center_z = float((lower[2] + upper[2]) / 2)
|
||||
half_width = float((upper[0] - lower[0]) / 2) * .94
|
||||
half_length = float((upper[2] - lower[2]) / 2) * .96
|
||||
positions, indices = [], []
|
||||
# Thin flat underside, rounded cloth upper. No platform or heel block.
|
||||
for ring in range(7):
|
||||
angle = (ring - 1) / 5 * math.pi / 2 if ring > 0 else 0
|
||||
radius = math.cos(angle) if ring > 0 else 1
|
||||
height = .003 + .054 * math.sin(angle) if ring > 0 else 0
|
||||
for segment in range(segments):
|
||||
theta = 2 * math.pi * segment / segments
|
||||
# Toe is slightly broader than the heel, without a pointed tip.
|
||||
width = half_width * (1 - .12 * math.cos(theta))
|
||||
positions.append([center_x + math.sin(theta) * width * radius,
|
||||
height, center_z + math.cos(theta) * half_length * radius])
|
||||
positions.append([center_x, 0, center_z])
|
||||
center = len(positions) - 1
|
||||
for segment in range(segments):
|
||||
after = (segment + 1) % segments
|
||||
indices.extend([center, after, segment])
|
||||
for ring in range(6):
|
||||
a, b = ring * segments + segment, ring * segments + after
|
||||
c, d = a + segments, b + segments
|
||||
indices.extend([a, b, c, b, d, c])
|
||||
positions = np.array(positions)
|
||||
# Derive smooth normals from the generated triangles.
|
||||
normals = np.zeros_like(positions)
|
||||
for a, b, c in np.array(indices).reshape(-1, 3):
|
||||
normal = np.cross(positions[b] - positions[a], positions[c] - positions[a])
|
||||
normals[[a, b, c]] += normal
|
||||
lengths = np.linalg.norm(normals, axis=1)
|
||||
normals[lengths > 0] /= lengths[lengths > 0, None]
|
||||
joints = [[joint, 0, 0, 0]] * len(positions)
|
||||
weights = [[1, 0, 0, 0]] * len(positions)
|
||||
slippers['primitives'].append({'attributes': {
|
||||
'POSITION': append(positions, 5126, 'VEC3'), 'NORMAL': append(normals, 5126, 'VEC3'),
|
||||
'JOINTS_0': append(joints, 5123, 'VEC4'), 'WEIGHTS_0': append(weights, 5126, 'VEC4')},
|
||||
'indices': append(np.array(indices).reshape(-1, 1), 5123, 'SCALAR'), 'material': material, 'mode': 4})
|
||||
measurements.append({'side': side, 'vertices': len(positions), 'sole_height': 0,
|
||||
'sole_flatness': 0, 'heel': [center_x, 0, center_z + half_length],
|
||||
'ball': [center_x, 0, center_z - half_length],
|
||||
'original_shoe_height': float(upper[1] - lower[1]), 'upper_height': .057})
|
||||
mesh_index = len(doc['meshes'])
|
||||
doc['meshes'].append(slippers)
|
||||
new_node = len(doc['nodes'])
|
||||
# Preserve the source mesh-node transform and skin binding exactly.
|
||||
doc['nodes'].append({**node, 'name': 'PracticeClothSlippers', 'mesh': mesh_index})
|
||||
parent = next((n for n in doc['nodes'][:new_node] if body_node in n.get('children', [])), None)
|
||||
if parent is not None:
|
||||
parent['children'].append(new_node)
|
||||
else:
|
||||
for scene in doc['scenes']:
|
||||
if body_node in scene['nodes']:
|
||||
scene['nodes'].append(new_node)
|
||||
binary.extend(b'\0' * (-len(binary) % 4))
|
||||
doc['buffers'][0]['byteLength'] = len(binary)
|
||||
encoded = json.dumps(doc, separators=(',', ':'), ensure_ascii=False).encode()
|
||||
encoded += b' ' * (-len(encoded) % 4)
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
with target.open('wb') as stream:
|
||||
stream.write(struct.pack('<III', 0x46546C67, 2, 28 + len(encoded) + len(binary)))
|
||||
stream.write(struct.pack('<II', len(encoded), 0x4E4F534A))
|
||||
stream.write(encoded)
|
||||
stream.write(struct.pack('<II', len(binary), 0x004E4942))
|
||||
stream.write(binary)
|
||||
return {'source_sha256': ORIGINAL[person], 'output_sha256': hashlib.file_digest(target.open('rb'), 'sha256').hexdigest(),
|
||||
'slippers': measurements}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--source-dir', required=True, type=Path)
|
||||
parser.add_argument('--output-dir', default=Path('shared/figure'), type=Path)
|
||||
args = parser.parse_args()
|
||||
report = {person: prepare(args.source_dir / f'{person}.vrm', args.output_dir / f'{person}.vrm', person)
|
||||
for person in ORIGINAL}
|
||||
(args.output_dir / 'slippers.json').write_text(json.dumps(report, indent=2) + '\n')
|
||||
print('Prepared both cloth-slipper models; measurements: shared/figure/slippers.json')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
+56
-4
@@ -14,13 +14,65 @@
|
||||
- Source: pixiv's VRoid Studio sample models, as mirrored unchanged at
|
||||
<https://github.com/madjin/vrm-samples> (`vroid/beta/HairSample_Female.vrm`
|
||||
and `vroid/beta/HairSample_Male.vrm`).
|
||||
- SHA-256:
|
||||
- Original SHA-256:
|
||||
- `woman.vrm` adfd242317aaabc773f31f7fff7b013979fbb5baa47e97427a78913d9cb4e979
|
||||
- `man.vrm` 7aeca142dabbc26ba0f5b9c998c8f3cb6df341287d67788427ac837223785a3f
|
||||
- Format: VRM 0.x (glTF 2.0 binary with the `VRM` extension), PNG textures,
|
||||
a VRM humanoid skeleton with hair spring bones. 27,068 and 24,858
|
||||
triangles.
|
||||
|
||||
They are loaded unchanged through Kryon's glTF importer (`figure_model`)
|
||||
and drawn with the toon look the owner approved. Do not change their
|
||||
appearance without asking the owner.
|
||||
On 2026-11-18 the owner requested simple, flat cloth Tai Chi slippers for
|
||||
both figures. `figure/tools/prepare_slippers.py` removes only the original
|
||||
shoe primitives and adds closed, rounded cloth slippers: matte stone grey
|
||||
for the woman and charcoal for the man, a 3 mm edge and 57 mm upper, with
|
||||
one level underside and no heel or platform. The rest of the mesh,
|
||||
textures, skeleton and VRM metadata is retained. Output checksums and sole
|
||||
measurements are in `slippers.json`; the CC0 dedication still applies.
|
||||
|
||||
Reproduce from the original files (checksums above), kept in the ignored
|
||||
`backup/figure-source/` directory during development:
|
||||
|
||||
```sh
|
||||
python3 figure/tools/prepare_slippers.py --source-dir backup/figure-source
|
||||
python3 tests/slippers_test.py --source-dir backup/figure-source
|
||||
```
|
||||
|
||||
The originals can also be recovered from this repository's pre-slipper
|
||||
revision or the source URLs above. The pipeline refuses modified input,
|
||||
so re-running it never compounds a previous edit. No texture regeneration
|
||||
or changes to the other clothing, hair or face are part of this edit.
|
||||
|
||||
Kryon's importer loads these models through `figure_model`, using the
|
||||
approved toon look. The retargeter measures actual sole vertices and fits
|
||||
the foot length to the solver's heel/ball span, keeping both pivots fixed.
|
||||
Only foot-only primitives use affine skinning for that length adjustment;
|
||||
the rest retain volume-preserving dual-quaternion skinning.
|
||||
|
||||
## Traditional meditation attire
|
||||
|
||||
The owner's later request includes the clothes and explicitly keeps the
|
||||
woman's skirt. `figure/tools/prepare_attire.py --source-dir
|
||||
backup/figure-source` starts from the same checksummed originals, builds the
|
||||
existing neutral flat slippers, and then replaces only clothing draw
|
||||
primitives. The new matte linen colors, crossed cloth facings and fitted
|
||||
sash form a calm traditional-inspired wrap. The woman retains the fitted
|
||||
long-sleeve top and flared skirt silhouette; the man loses the hoodie/cord
|
||||
geometry and gains a cross-collar tunic with relaxed trousers. Faces,
|
||||
hair, bodies, skeleton, expressions, source texture bytes, CC0 metadata and
|
||||
slipper geometry remain intact. Blended skin weights at the sleeves and
|
||||
the trouser seat spread deformation through those joints. `attire.json`
|
||||
records exact output identity and the source primitives replaced.
|
||||
|
||||
The skirt is its own `PracticeSkirt` mesh. `figure_cloth` and
|
||||
`FigureModelCloth` constrain its lower portion under gravity, outside leg
|
||||
capsules and above the floor, while preserving the skinned waist seam.
|
||||
Short edge-length constraints distribute the drape below the waist during
|
||||
forward folds and lunges. The constraints use the pose at the requested
|
||||
time, so seeking to a frame gives the same drape as playing it. The
|
||||
pre-attire slippers and original models remain in ignored recovery storage.
|
||||
|
||||
```sh
|
||||
python3 figure/tools/prepare_attire.py --source-dir backup/figure-source
|
||||
python3 tests/slippers_test.py --source-dir backup/figure-source
|
||||
python3 tests/attire_test.py --source-dir backup/figure-source
|
||||
```
|
||||
@@ -9,3 +9,10 @@
|
||||
veranda for astral projection. Their originals, prompts and checks are
|
||||
in `source/` (`provenance.json`); the stored backdrops have their colour
|
||||
made about 1.3 times as strong and are sized for phones.
|
||||
|
||||
Each backdrop has a same-name JSON ground registration: source-image
|
||||
horizon, a safe open-floor rectangle, cover crop, camera pitch and minimum
|
||||
view height. Coordinates exclude the Tai Chi wall/stairs, Workout deck
|
||||
edges/railings, Sun Salutation foliage and astral veranda railing. The
|
||||
preview transforms these marks through the actual image crop and fits the
|
||||
entire motion and contact shadow into the remaining floor.
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"woman": {
|
||||
"source_sha256": "adfd242317aaabc773f31f7fff7b013979fbb5baa47e97427a78913d9cb4e979",
|
||||
"output_sha256": "f677800f355982139bdc59c471846c262eda6bbc2b13bd89a00a5591bac3a75c",
|
||||
"changed_body_primitives": [
|
||||
{
|
||||
"original_primitive": 4,
|
||||
"original_material": "F00_002_01_Tops_01_CLOTH"
|
||||
}
|
||||
],
|
||||
"skirt_preserved": true,
|
||||
"identity": "Original face, hair, body, skeleton and flat slippers retained",
|
||||
"style": "Matte linen cross-collar wrap, plain sash and flared skirt"
|
||||
},
|
||||
"man": {
|
||||
"source_sha256": "7aeca142dabbc26ba0f5b9c998c8f3cb6df341287d67788427ac837223785a3f",
|
||||
"output_sha256": "727443b67b3c30856976446cc3e644dc4074107bb67b970b5d342010a138c1ea",
|
||||
"changed_body_primitives": [
|
||||
{
|
||||
"original_primitive": 4,
|
||||
"original_material": "M00_006_01_Tops_01_CLOTH"
|
||||
},
|
||||
{
|
||||
"original_primitive": 5,
|
||||
"original_material": "M00_001_01_Bottoms_01_CLOTH"
|
||||
}
|
||||
],
|
||||
"skirt_preserved": false,
|
||||
"identity": "Original face, hair, body, skeleton and flat slippers retained",
|
||||
"style": "Matte linen cross-collar tunic and relaxed trousers; hood/cord meshes removed"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"schema": 1,
|
||||
"image_width": 1280,
|
||||
"image_height": 853,
|
||||
"horizon": 0.71,
|
||||
"floor_left": 0.18,
|
||||
"floor_top": 0.78,
|
||||
"floor_right": 0.82,
|
||||
"floor_bottom": 0.96,
|
||||
"zoom": 1.5,
|
||||
"focus": 1.0,
|
||||
"pitch": 0.22,
|
||||
"minimum_view_height": 2.4,
|
||||
"description": "Normalized source-image coordinates. Usable ground excludes walls, rails, plants, stairs and foreground edges. Camera fits the entire motion and shadow inside this area, with additional screen margins."
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"schema": 1,
|
||||
"image_width": 1280,
|
||||
"image_height": 853,
|
||||
"horizon": 0.79,
|
||||
"floor_left": 0.4,
|
||||
"floor_top": 0.87,
|
||||
"floor_right": 0.6,
|
||||
"floor_bottom": 0.97,
|
||||
"zoom": 2.0,
|
||||
"focus": 1.0,
|
||||
"pitch": 0.22,
|
||||
"minimum_view_height": 2.4,
|
||||
"description": "Normalized source-image coordinates. Usable ground excludes walls, rails, plants, stairs and foreground edges. Camera fits the entire motion and shadow inside this area, with additional screen margins."
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"schema": 1,
|
||||
"image_width": 1280,
|
||||
"image_height": 853,
|
||||
"horizon": 0.76,
|
||||
"floor_left": 0.2,
|
||||
"floor_top": 0.81,
|
||||
"floor_right": 0.8,
|
||||
"floor_bottom": 0.97,
|
||||
"zoom": 1.6,
|
||||
"focus": 1.0,
|
||||
"pitch": 0.16,
|
||||
"minimum_view_height": 2.4,
|
||||
"description": "Normalized source-image coordinates. Usable ground excludes walls, rails, plants, stairs and foreground edges. Camera fits the entire motion and shadow inside this area, with additional screen margins."
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"schema": 1,
|
||||
"image_width": 1280,
|
||||
"image_height": 853,
|
||||
"horizon": 0.73,
|
||||
"floor_left": 0.2,
|
||||
"floor_top": 0.79,
|
||||
"floor_right": 0.8,
|
||||
"floor_bottom": 0.96,
|
||||
"zoom": 1.6,
|
||||
"focus": 1.0,
|
||||
"pitch": 0.22,
|
||||
"minimum_view_height": 2.4,
|
||||
"description": "Normalized source-image coordinates. Usable ground excludes walls, rails, plants, stairs and foreground edges. Camera fits the entire motion and shadow inside this area, with additional screen margins."
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,86 @@
|
||||
{
|
||||
"woman": {
|
||||
"source_sha256": "adfd242317aaabc773f31f7fff7b013979fbb5baa47e97427a78913d9cb4e979",
|
||||
"output_sha256": "f677800f355982139bdc59c471846c262eda6bbc2b13bd89a00a5591bac3a75c",
|
||||
"slippers": [
|
||||
{
|
||||
"side": "L",
|
||||
"vertices": 225,
|
||||
"sole_height": 0,
|
||||
"sole_flatness": 0,
|
||||
"heel": [
|
||||
-0.04924570769071579,
|
||||
0,
|
||||
0.07680007204413414
|
||||
],
|
||||
"ball": [
|
||||
-0.04924570769071579,
|
||||
0,
|
||||
-0.11925879254937172
|
||||
],
|
||||
"original_shoe_height": 0.17255966365337372,
|
||||
"upper_height": 0.057
|
||||
},
|
||||
{
|
||||
"side": "R",
|
||||
"vertices": 225,
|
||||
"sole_height": 0,
|
||||
"sole_flatness": 0,
|
||||
"heel": [
|
||||
0.049919672310352325,
|
||||
0,
|
||||
0.07680031567811965
|
||||
],
|
||||
"ball": [
|
||||
0.049919672310352325,
|
||||
0,
|
||||
-0.11925847738981246
|
||||
],
|
||||
"original_shoe_height": 0.17256003618240356,
|
||||
"upper_height": 0.057
|
||||
}
|
||||
]
|
||||
},
|
||||
"man": {
|
||||
"source_sha256": "7aeca142dabbc26ba0f5b9c998c8f3cb6df341287d67788427ac837223785a3f",
|
||||
"output_sha256": "727443b67b3c30856976446cc3e644dc4074107bb67b970b5d342010a138c1ea",
|
||||
"slippers": [
|
||||
{
|
||||
"side": "L",
|
||||
"vertices": 225,
|
||||
"sole_height": 0,
|
||||
"sole_flatness": 0,
|
||||
"heel": [
|
||||
-0.05338574945926666,
|
||||
0,
|
||||
0.0861485032737255
|
||||
],
|
||||
"ball": [
|
||||
-0.05338574945926666,
|
||||
0,
|
||||
-0.17508904173970222
|
||||
],
|
||||
"original_shoe_height": 0.10461036115884781,
|
||||
"upper_height": 0.057
|
||||
},
|
||||
{
|
||||
"side": "R",
|
||||
"vertices": 225,
|
||||
"sole_height": 0,
|
||||
"sole_flatness": 0,
|
||||
"heel": [
|
||||
0.05440085381269455,
|
||||
0,
|
||||
0.08614855796098708
|
||||
],
|
||||
"ball": [
|
||||
0.05440085381269455,
|
||||
0,
|
||||
-0.17508904427289962
|
||||
],
|
||||
"original_shoe_height": 0.10461036115884781,
|
||||
"upper_height": 0.057
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loaded 100 of 171 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user