23 lines
1.3 KiB
Python
23 lines
1.3 KiB
Python
"""Per race/gender displacement field learned from Octo(1.12-shaped) -> native HD helm pairs."""
|
|
import struct, os, json, numpy as np
|
|
PINS = '/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/helm-hd-d6d9-20261123/pins'
|
|
PAIRS = '/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/helm-hd-reinstate-20261123/helm-model-pairs.json'
|
|
def verts(b):
|
|
assert b[:4] == b'MD21'; m = b[8:]; n, o = struct.unpack_from('<II', m, 60)
|
|
return np.frombuffer(m, dtype=np.dtype([('p', '<3f'), ('r', 'V36')]), count=n, offset=o)['p'].astype(float)
|
|
def race(path): return path.rsplit('_', 1)[1][:3]
|
|
def samples():
|
|
P = {str(p['imported_fdid']): p['path'] for p in json.load(open(PAIRS))['pairs']}
|
|
out = {}
|
|
for d in os.listdir(PINS):
|
|
if d not in P: continue
|
|
a = verts(open(f'{PINS}/{d}/before.m2', 'rb').read()); b = verts(open(f'{PINS}/{d}/after.m2', 'rb').read())
|
|
if len(a) != len(b) or not len(a): continue
|
|
out.setdefault(race(P[d]), []).append((P[d], a, b - a))
|
|
return out
|
|
def predict(src, disp, q, k=8):
|
|
d = np.linalg.norm(q[:, None, :] - src[None, :, :], axis=2)
|
|
idx = np.argsort(d, axis=1)[:, :k]; dd = np.take_along_axis(d, idx, 1)
|
|
w = 1 / (dd + 1e-3) ** 2; w /= w.sum(1, keepdims=True)
|
|
return (disp[idx] * w[..., None]).sum(1), dd[:, 0]
|