Keep wrap seams stable and remove painted socks
This commit is contained in:
1 parent
d82bcc2565
commit
01e649eb13
6 files changed
+77
-13
No files matched your search
@@ -139,14 +139,8 @@ FigureModelUse :: (figure: *FigureModel, scene: *Scene, loaded: *GltfModel) -> b
|
||||
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"
|
||||
}
|
||||
// Tailored garments use affine blending so adjacent vertices keep
|
||||
// following the same rotation path in deep reaches and lunges.
|
||||
for index: 0..figure.instance.meshes.count - 1 {
|
||||
inst := *figure.instance.meshes[index]
|
||||
mesh := *figure.model.meshes[inst.mesh_index]
|
||||
@@ -156,7 +150,7 @@ FigureModelUse :: (figure: *FigureModel, scene: *Scene, loaded: *GltfModel) -> b
|
||||
for vertex: primitive.indices[:] {
|
||||
high = FigureMax(high, primitive.positions[vertex].y)
|
||||
}
|
||||
if high < 0.30 || (!skirt && (name == "PracticeClothing" || name == "PracticeWrapFacings")) {
|
||||
if high < 0.30 || name == "PracticeClothing" || name == "PracticeWrapFacings" {
|
||||
inst.skin.dual_quaternion = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
from io import BytesIO
|
||||
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFilter
|
||||
ORIGINAL = {
|
||||
'woman': 'adfd242317aaabc773f31f7fff7b013979fbb5baa47e97427a78913d9cb4e979',
|
||||
'man': '7aeca142dabbc26ba0f5b9c998c8f3cb6df341287d67788427ac837223785a3f',
|
||||
@@ -245,6 +247,55 @@ def is_foot_skin(asset, primitive):
|
||||
return heights.min() < .05 and heights.max() < .20
|
||||
|
||||
|
||||
def remove_sock_dye(asset, body, material_id):
|
||||
"""Recover the skin colour below the sock line on the original atlas."""
|
||||
doc = asset.doc
|
||||
material = doc['materials'][material_id]['pbrMetallicRoughness']['baseColorTexture']
|
||||
texture_id = material['index']
|
||||
texture = doc['textures'][texture_id]
|
||||
image = doc['images'][texture['source']]
|
||||
data = doc['bufferViews'][image['bufferView']]
|
||||
start = data.get('byteOffset', 0)
|
||||
original = Image.open(BytesIO(asset.binary[start:start + data['byteLength']])).convert('RGBA')
|
||||
region = Image.new('L', original.size)
|
||||
draw = ImageDraw.Draw(region)
|
||||
dimensions = np.array(original.size) - 1
|
||||
for primitive in body['primitives']:
|
||||
if primitive['material'] != material_id:
|
||||
continue
|
||||
attrs = primitive['attributes']
|
||||
vertices = asset.read(attrs['POSITION'])
|
||||
triangles = asset.read(primitive['indices']).reshape(-1, 3)
|
||||
below_sock_line = np.any(vertices[triangles, 1] < .29, axis=1)
|
||||
pixels = asset.read(attrs['TEXCOORD_0']) * dimensions
|
||||
for triangle in pixels[triangles[below_sock_line]]:
|
||||
draw.polygon([tuple(point) for point in triangle], fill=255)
|
||||
# Include neighbouring texels so normal texture filtering cannot pull
|
||||
# the sock colour back in at a UV seam. Preserve the skin above the sock.
|
||||
mask = np.asarray(region.filter(ImageFilter.MaxFilter(5))) != 0
|
||||
rgba = np.array(original)
|
||||
rgb = rgba[mask, :3].astype(np.float32)
|
||||
weight = np.clip((180 - rgb[:, 0]) / 123, 0, 1)
|
||||
rgb += weight[:, None] * [187, 161, 134]
|
||||
rgba[mask, :3] = np.clip(np.rint(rgb), 0, 255).astype(np.uint8)
|
||||
stream = BytesIO()
|
||||
Image.fromarray(rgba).save(stream, 'PNG')
|
||||
encoded = stream.getbuffer()
|
||||
asset.binary.extend(b'\0' * (-len(asset.binary) % 4))
|
||||
view = len(doc['bufferViews'])
|
||||
doc['bufferViews'].append({'buffer': 0, 'byteOffset': len(asset.binary), 'byteLength': len(encoded)})
|
||||
asset.binary.extend(encoded)
|
||||
source = len(doc['images'])
|
||||
doc['images'].append({'name': 'PracticeBareSkin', 'mimeType': 'image/png', 'bufferView': view})
|
||||
corrected = len(doc['textures'])
|
||||
doc['textures'].append({**texture, 'source': source})
|
||||
material['index'] = corrected
|
||||
properties = doc['extensions']['VRM']['materialProperties'][material_id]['textureProperties']
|
||||
for key in ('_MainTex', '_ShadeTexture'):
|
||||
if properties.get(key) == texture_id:
|
||||
properties[key] = corrected
|
||||
|
||||
|
||||
def barefoot(asset, body_node, primitive, person):
|
||||
"""Level the original plantar skin while preserving toes, UVs and seams."""
|
||||
doc = asset.doc
|
||||
@@ -304,6 +355,8 @@ def dress(source, target, person):
|
||||
body = d['meshes'][d['nodes'][body_node]['mesh']]
|
||||
skin = d['skins'][d['nodes'][body_node]['skin']]
|
||||
foot_skin = next(p for p in body['primitives'] if is_foot_skin(asset, p))
|
||||
if person == 'man':
|
||||
remove_sock_dye(asset, body, foot_skin['material'])
|
||||
measurements = barefoot(asset, body_node, foot_skin, person)
|
||||
skin_parts = [p for p in body['primitives'] if p is not foot_skin and
|
||||
'SKIN' in d['materials'][p['material']]['name']]
|
||||
|
||||
@@ -39,14 +39,17 @@ The matte linen colors, crossed facings and fitted sash form a traditional
|
||||
wrap. The woman keeps the long-sleeve top and flared skirt. The man wears a
|
||||
cross-collar tunic with relaxed trousers. Blended weights at the sleeves and
|
||||
trouser seat spread deformation through each joint. The generator preserves
|
||||
faces, hair, skeletons, expressions, original textures and CC0 metadata.
|
||||
faces, hair, skeletons, expressions and CC0 metadata. The man’s skin uses a
|
||||
copy of the original atlas with the painted sock colour removed at the ankles
|
||||
and feet. The generator retains the original atlas in the model.
|
||||
|
||||
The separate `PracticeSkirt` mesh keeps its skinned waist seam. Its lower
|
||||
portion drapes around the legs and sleeves, stays above the floor, and
|
||||
spreads the displacement across neighboring fabric edges. The current pose
|
||||
sets these constraints so seeking and playback produce the same drape.
|
||||
|
||||
Reproduce from the checksummed originals in `backup/figure-source/`.
|
||||
Reproduce from the checksummed originals in `backup/figure-source/` with NumPy
|
||||
and Pillow installed.
|
||||
|
||||
```sh
|
||||
python3 figure/tools/prepare_attire.py --source-dir backup/figure-source
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
},
|
||||
"man": {
|
||||
"source_sha256": "7aeca142dabbc26ba0f5b9c998c8f3cb6df341287d67788427ac837223785a3f",
|
||||
"output_sha256": "12f08ad217679f3c6f17d4e2dc0f04593b84092b08bfd35e5c0c0a8cc98d8685",
|
||||
"output_sha256": "4b9051fc34963a31810829cad8a54b025d81019804423bafe54cb50cbf7c3fca",
|
||||
"bare_feet": [
|
||||
{
|
||||
"side": "L",
|
||||
|
||||
Binary file not shown.
+15
-1
@@ -1,10 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify real garment edits preserve both selected identities and plain soles."""
|
||||
import argparse
|
||||
from io import BytesIO
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'figure/tools'))
|
||||
from prepare_attire import Asset, ORIGINAL, is_foot_skin, sha
|
||||
@@ -35,6 +37,15 @@ def verify_feet(old, new, receipts):
|
||||
assert len(contact) == receipt['support_vertices'] >= 8
|
||||
assert .12 < np.ptp(position[contact, 2]) == receipt['heel_to_ball']
|
||||
assert np.all(attrs['WEIGHTS_0'][contact] == [1, 0, 0, 0])
|
||||
material = new.doc['materials'][primitive['material']]['pbrMetallicRoughness']
|
||||
texture = new.doc['textures'][material['baseColorTexture']['index']]
|
||||
image = new.doc['images'][texture['source']]
|
||||
view = new.doc['bufferViews'][image['bufferView']]
|
||||
offset = view.get('byteOffset', 0)
|
||||
atlas = np.asarray(Image.open(BytesIO(new.binary[offset:offset + view['byteLength']])).convert('RGB'))
|
||||
x, y = np.rint(attrs['TEXCOORD_0'][used] * [atlas.shape[1] - 1, atlas.shape[0] - 1]).astype(int).T
|
||||
toes = position[used, 1] < .04
|
||||
assert np.quantile(atlas[y[toes], x[toes], 0], .05) > 215, 'The atlas still paints dark socks on the foot'
|
||||
|
||||
|
||||
def main():
|
||||
@@ -53,8 +64,11 @@ def main():
|
||||
assert new.binary[:len(old.binary)] == old.binary
|
||||
assert d['extensions']['VRM']['meta'] == o['extensions']['VRM']['meta']
|
||||
assert d['extensions']['VRM']['meta']['licenseName'] == 'CC0'
|
||||
for key in ('images', 'textures', 'samplers', 'skins'):
|
||||
for key in ('samplers', 'skins'):
|
||||
assert d[key] == o[key], (person, key)
|
||||
for key in ('images', 'textures'):
|
||||
extra = int(person == 'man')
|
||||
assert len(d[key]) == len(o[key]) + extra and d[key][:len(o[key])] == o[key], (person, key)
|
||||
for i, node in enumerate(o['nodes']):
|
||||
# Appended garment nodes may be new children; original nodes stay.
|
||||
assert {k: v for k, v in node.items() if k != 'children'} == {k: v for k, v in d['nodes'][i].items() if k != 'children'}
|
||||
|
||||
Reference in new issue
Block a user