text stringlengths 0 1.47k |
|---|
missing = [n for n in want if n not in names] |
if missing: |
raise ValueError(f"{len(missing)} of the cond's {len(want)} joints missing: {missing[:3]}") |
rest = skel['rest_anim_shared'] # export convention (Y-up), as the NPZs |
tpos_data = { |
'names': np.array(names), 'parents': np.asarray(skel['parents_array']), |
'rest_local_pos': np.asarray(rest.positions[0]), |
'rest_local_rot': np.asarray(rest.rotations.qs[0]), 'fps': np.array(30), |
} |
(canon_anim, _offsets, _scale, _ground, canon_parents, canon_names, |
*_rest) = process_tpose( |
tpos_data, corps_idxs=[names.index(n) for n in want], |
corps_names=want, face_joints=cond_face_joints(cond), |
target_diameter=cond_diameter(cond)) |
# Same joints and hierarchy, matched by NAME: BFS breaks sibling ties by |
# the source's bone order, which differs between files (a character GLB |
# lists Right* before Left*, the clips' FBX the other way round), and the |
# canonicalization itself does not depend on joint order. |
got = [str(n) for n in canon_names] |
parent_of = {n: (got[p] if p >= 0 else None) for n, p in zip(got, canon_parents)} |
want_parent = {n: (want[int(p)] if int(p) >= 0 else None) |
for n, p in zip(want, cond['parents'])} |
if sorted(got) != sorted(want) or parent_of != want_parent: |
raise ValueError("joints differ from the shared cond's (names or hierarchy)") |
positions = np.asarray(positions_global(canon_anim)[0]) |
out = copy.copy(cond) |
out['tpos_first_frame'] = positions[[got.index(n) for n in want]] |
return out |
def glb_digest(path): |
"""The ``canonical_cond_digest`` stored in a baked GLB (glTF extras), or None.""" |
return glb_node_extra(path, DIGEST_KEY) |
class CollinearSkeleton(UndeterminedRoll): |
"""A skeleton the bake refuses (see :func:`_check_not_collinear`).""" |
def _check_not_collinear(entry, rel_tol=1e-3): |
"""The bake fits the asset onto the canonical joints with one similarity; |
joints on a straight line leave the roll about that line undetermined, and |
the mesh would come out at an arbitrary roll, so such skeletons are refused.""" |
if line_ratio(entry['tpos_first_frame']) <= rel_tol: |
raise CollinearSkeleton("collinear skeleton: its roll about the joint line is " |
"undetermined, so the mesh cannot be fitted to the canonical frame") |
def _texture_note(assets_dir, name, source, baked): |
"""Images the baked GLB lost relative to its source GLB. The glTF exporter |
may rename an image it re-embeds (``dressrun.2`` -> ``dressrun``), so an |
image counts as kept when its bytes are embedded under any name.""" |
kept = {digest for _, digest in glb_image_digests(baked)} |
lost = sorted({n for n, digest in glb_image_digests(source) if digest is None or digest not in kept}) |
write_note(assets_dir, TEXTURE_ISSUES_DIR, name, |
[f"images of {os.path.basename(source)} not in the canonical GLB: {lost}"] if lost else []) |
if lost: |
logger.warning(f"'{name}': canonical GLB lost image(s) {lost}") |
def _shard(name, num_workers): |
"""The worker (of *num_workers*) that handles asset *name*.""" |
return int(hashlib.sha1(name.encode()).hexdigest(), 16) % num_workers |
def _remove_asset_files(out_dir, name, partial=None): |
"""Remove ``<name>.<fmt>`` for every format a bake can write (a run asks |
for fewer than an earlier one may have written), the ``<partial>.<fmt>`` |
files of a broken bake and the asset's texture note.""" |
for fmt in CANONICAL_FORMATS: |
for path in [os.path.join(out_dir, f'{name}.{fmt}')] + \ |
([f'{partial}.{fmt}'] if partial else []): |
if os.path.isfile(path): |
os.remove(path) |
write_note(out_dir, TEXTURE_ISSUES_DIR, name, []) |
def bake_canonical_assets(export_dir, features_dir, assets_dir=None, dataset_type=None, |
object_types=None, worker_id=0, num_workers=1, overwrite=False, |
formats=('glb',)): |
"""Write ``<assets_dir>/<object_type>.glb`` (module docstring; *assets_dir* |
defaults to :func:`default_assets_dir`), plus ``<object_type>.fbx`` when |
*formats* holds ``'fbx'`` (the GLB is always written: it carries the digest). |
Returns ``{'baked': n, 'up_to_date': n, 'no_source': n, 'stale_removed': n, |
'refused': n, 'failed': n}`` (refused: collinear skeletons, an expected |
outcome; stale_removed: the no_source assets whose GLB was baked from |
another cond frame and was removed with its other formats). |
""" |
if not 0 <= worker_id < num_workers: |
raise ValueError(f"worker_id {worker_id} not in [0, {num_workers})") |
cond = np.load(os.path.join(features_dir, 'cond.npy'), allow_pickle=True).item() |
out_dir = assets_dir or default_assets_dir(features_dir) |
src_dir = os.path.join(export_dir, PROCESSED_GLB_DIR) |
mixamo = dataset_type == 'mixamo' or list(cond) == ['mixamo'] |
if mixamo: |
# (asset name, source GLB, object type) per character. |
if 'mixamo' not in cond: |
raise ValueError(f"{features_dir}/cond.npy has no 'mixamo' entry") |
# Characters with a canonical GLB but no source are checked too. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.