diff --git a/figure/README.md b/figure/README.md index fe77cbf9..3e6df8c4 100644 --- a/figure/README.md +++ b/figure/README.md @@ -50,6 +50,9 @@ The modules: The prepared models compact each primitive to the vertices its indices use, including matching facial-expression deltas. Triangle order, skin weights, normals and UVs stay the same; unreferenced vertices are never posed or uploaded. +Consecutive cutout hair strands share one draw when their material, skin and +attribute formats match. Triangle order and every drawn corner stay unchanged; +the woman's three authored ponytail locks remain separate for styling. The practices' backdrops are in `shared/figure/backdrops/`. The owner's references for the render quality are in `design/reference/`. diff --git a/figure/tools/prepare_attire.py b/figure/tools/prepare_attire.py index a8aca20e..7efa8927 100644 --- a/figure/tools/prepare_attire.py +++ b/figure/tools/prepare_attire.py @@ -130,6 +130,44 @@ class Asset: primitive['indices'] = self.append(remapped.reshape(-1, 1), component, 'SCALAR') return {'geometry_vertices_before': before, 'geometry_vertices': after} + def batch_hair(self, person): + """Draw consecutive cutout strands with one shared material and skin.""" + mesh = next(mesh for mesh in self.doc['meshes'] if mesh['name'] == 'Hair001.baked') + # Keep the three authored ponytail locks separate for further styling. + source = mesh['primitives'][:-3] if person == 'woman' else mesh['primitives'] + tail = mesh['primitives'][-3:] if person == 'woman' else [] + first = source[0] + metadata = {key: value for key, value in first.items() if key not in ('attributes', 'indices')} + assert not first.get('targets') and first.get('mode', 4) == 4 + attributes = first['attributes'] + values = {name: [] for name in attributes} + indices, offset = [], 0 + for primitive in source: + assert {key: value for key, value in primitive.items() + if key not in ('attributes', 'indices')} == metadata + assert primitive['attributes'].keys() == attributes.keys() + count = self.doc['accessors'][primitive['attributes']['POSITION']]['count'] + for name, accessor in primitive['attributes'].items(): + original = self.doc['accessors'][attributes[name]] + current = self.doc['accessors'][accessor] + for key in ('componentType', 'type'): + assert current.get(key) == original.get(key) + assert current.get('normalized', False) == original.get('normalized', False) + assert current['count'] == count + values[name].append(self.read(accessor)) + indices.append(self.read(primitive['indices']).astype(np.uint32) + offset) + offset += count + merged = copy.deepcopy(first) + for name, arrays in values.items(): + original = self.doc['accessors'][attributes[name]] + accessor = self.append(np.concatenate(arrays), original['componentType'], original['type']) + if 'normalized' in original: + self.doc['accessors'][accessor]['normalized'] = original['normalized'] + merged['attributes'][name] = accessor + merged['indices'] = self.append(np.concatenate(indices), 5123 if offset <= 65536 else 5125, 'SCALAR') + mesh['primitives'] = [merged, *tail] + return {'hair_draws_before': len(source) + len(tail), 'hair_draws': 1 + len(tail)} + def save(self, path): self.binary.extend(b'\0' * (-len(self.binary) % 4)) self.doc['buffers'][0]['byteLength'] = len(self.binary) @@ -962,6 +1000,7 @@ def dress(source, target, person): training_tshirt(asset, body_node, skin_parts, skin, trouser_attrs, trouser_faces) # Removed hood springs have no visible geometry; keep skeleton compatibility. compacted = asset.compact() + batched = asset.batch_hair(person) asset.save(target) return {'source_sha256': ORIGINAL[person], 'output_sha256': sha(target), 'bare_feet': measurements, @@ -971,6 +1010,7 @@ def dress(source, target, person): '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', **compacted, + **batched, **({'training_top': 'Short-sleeved crew-neck T-shirt', 'training_bottom': 'Tapered, ankle-length athletic trousers'} if person == 'man' else {'hair': 'High layered ponytail on the original hair rig and texture', diff --git a/shared/figure/attire.json b/shared/figure/attire.json index 1f7dce3f..4fa53a3a 100644 --- a/shared/figure/attire.json +++ b/shared/figure/attire.json @@ -1,7 +1,7 @@ { "woman": { "source_sha256": "adfd242317aaabc773f31f7fff7b013979fbb5baa47e97427a78913d9cb4e979", - "output_sha256": "32c0722aec016788aa8a3c79bc870da75a6dad0a927d5896ca032044a8a4ef6e", + "output_sha256": "769a7d17869008830278c4b9339d94e00a7cde847eb12a76933e98ae4fe28496", "bare_feet": [ { "side": "L", @@ -29,12 +29,14 @@ "style": "Matte linen cross-collar wrap, plain sash and flared skirt", "geometry_vertices_before": 660085, "geometry_vertices": 24802, + "hair_draws_before": 89, + "hair_draws": 4, "hair": "High layered ponytail on the original hair rig and texture", "tai_chi_bottom": "Slim, tapered ankle-length trousers under the wrap top" }, "man": { "source_sha256": "7aeca142dabbc26ba0f5b9c998c8f3cb6df341287d67788427ac837223785a3f", - "output_sha256": "b685750550e537cb39c4d4f586a13131f93cfff6fff5153a3dc8145d9311444e", + "output_sha256": "bca20c02c97132fac67afe6e94015e12b85602576ac77a05bf59d746745c3086", "bare_feet": [ { "side": "L", @@ -66,6 +68,8 @@ "style": "Matte linen cross-collar tunic and relaxed trousers; hood/cord meshes removed", "geometry_vertices_before": 942114, "geometry_vertices": 22377, + "hair_draws_before": 114, + "hair_draws": 1, "training_top": "Short-sleeved crew-neck T-shirt", "training_bottom": "Tapered, ankle-length athletic trousers" } diff --git a/shared/figure/man.vrm b/shared/figure/man.vrm index 1feecc64..c8613cfe 100644 Binary files a/shared/figure/man.vrm and b/shared/figure/man.vrm differ diff --git a/shared/figure/woman.vrm b/shared/figure/woman.vrm index eb28e2b1..b6f5ce33 100644 Binary files a/shared/figure/woman.vrm and b/shared/figure/woman.vrm differ diff --git a/tests/attire_test.py b/tests/attire_test.py index 76b7754f..17e244b1 100644 --- a/tests/attire_test.py +++ b/tests/attire_test.py @@ -28,6 +28,26 @@ def same_primitive(old, new, before, after): assert np.array_equal(old.read(source[name])[a], new.read(output[name])[b]), name +def split_batch(asset, primitive, counts): + """Recover source strand boundaries without changing any drawn corner.""" + indices = asset.read(primitive['indices']).ravel() + assert sum(counts) == len(indices) + result, offset = [], 0 + for count in counts: + used, remapped = np.unique(indices[offset:offset + count], return_inverse=True) + attributes = {} + for name, index in primitive['attributes'].items(): + source = asset.doc['accessors'][index] + output = asset.append(asset.read(index)[used], source['componentType'], source['type']) + if 'normalized' in source: + asset.doc['accessors'][output]['normalized'] = source['normalized'] + attributes[name] = output + result.append({**primitive, 'attributes': attributes, + 'indices': asset.append(remapped.reshape(-1, 1), 5125, 'SCALAR')}) + offset += count + return result + + def verify_feet(old, new, receipts, person): original = next(p for mesh in old.doc['meshes'] for p in mesh['primitives'] if is_foot_skin(old, p)) source = {name: old.read(accessor) for name, accessor in original['attributes'].items()} @@ -245,7 +265,13 @@ def verify_training_trousers(asset): def verify_woman_hair(old, new, authored, styled): - original, updated = authored['primitives'], styled['primitives'] + original = authored['primitives'] + assert len(styled['primitives']) == 4 + kept = [primitive for index, primitive in enumerate(original) + if index >= 6 and not 50 <= index < 66] + updated = [*split_batch(new, styled['primitives'][0], + [len(old.read(primitive['indices'])) for primitive in kept]), + *styled['primitives'][1:]] assert len(updated) == len(original) - 22 + 3 assert new.doc['extensions']['VRM']['secondaryAnimation'] == old.doc['extensions']['VRM']['secondaryAnimation'] for before, after in [*zip(original[6:14], updated[:8]), @@ -317,6 +343,9 @@ def main(): expected = [p for p in mesh['primitives'] if 'CLOTH' not in o['materials'][p['material']]['name'] and not is_foot_skin(old, p)] actual = [p for p in d['meshes'][i]['primitives'] if not d['materials'][p['material']]['name'].startswith('Practice_')] + if mesh['name'] == 'Hair001.baked': + assert len(actual) == 1 + actual = split_batch(new, actual[0], [len(old.read(p['indices'])) for p in expected]) assert len(actual) == len(expected), (person, mesh.get('name')) for before, after in zip(expected, actual): same_primitive(old, new, before, after)