30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
|
|
"""Trim a skin_to_obj dump to the HAND only, so a bbox-framing renderer actually frames
|
||
|
|
the hand. The dumps span the whole arm (76cm in x); the hand is the outer ~13cm.
|
||
|
|
usage: trim_hand.py <in.obj> <out.obj> <l|r>"""
|
||
|
|
import sys
|
||
|
|
|
||
|
|
src, dst, side = sys.argv[1], sys.argv[2], sys.argv[3]
|
||
|
|
verts, faces = [], []
|
||
|
|
for line in open(src):
|
||
|
|
if line.startswith("v "):
|
||
|
|
verts.append([float(x) for x in line.split()[1:4]])
|
||
|
|
elif line.startswith("f "):
|
||
|
|
faces.append([int(t.split("/")[0]) - 1 for t in line.split()[1:]])
|
||
|
|
|
||
|
|
xs = [v[0] for v in verts]
|
||
|
|
# hand sits at the far end in |x|; keep the outer 15cm of the limb
|
||
|
|
cut = (max(xs) - 0.15) if side == "l" else (min(xs) + 0.15)
|
||
|
|
keep = [(v[0] >= cut) if side == "l" else (v[0] <= cut) for v in verts]
|
||
|
|
remap, out_v = {}, []
|
||
|
|
for i, v in enumerate(verts):
|
||
|
|
if keep[i]:
|
||
|
|
remap[i] = len(out_v)
|
||
|
|
out_v.append(v)
|
||
|
|
out_f = [f for f in faces if all(i in remap for i in f)]
|
||
|
|
with open(dst, "w") as f:
|
||
|
|
for v in out_v:
|
||
|
|
f.write(f"v {v[0]:.6f} {v[1]:.6f} {v[2]:.6f}\n")
|
||
|
|
for fc in out_f:
|
||
|
|
f.write("f " + " ".join(str(remap[i] + 1) for i in fc) + "\n")
|
||
|
|
print(f"[trim] {dst}: {len(out_v)}/{len(verts)} verts, {len(out_f)} faces (cut x={cut:.3f})")
|