WalkingOnSaturn commited on
Commit
72e41d3
·
verified ·
1 Parent(s): 3ada6a7

chunk 6: emit SOMA-30 globalRotMats in motion envelopes

Browse files
Files changed (1) hide show
  1. server.py +28 -1
server.py CHANGED
@@ -9,7 +9,11 @@ and returns a JSON envelope:
9
  "numFrames": int,
10
  "fps": 30,
11
  "rootTranslation": [[x,y,z], ...], # [N, 3]
12
- "jointRotMats": [[[[...]]]], # [N, 30, 3, 3]
 
 
 
 
13
  "footContacts": [[lh, lt, lte, rh, rt, rte]], # [N, 6] (optional;
14
  # SOMA-77 layout — toe-end copies
15
  # toe-base contact, see
@@ -169,6 +173,17 @@ def kimodo_motion(
169
  local_rot_mats_30 = local_rot_mats_30[0]
170
  local_rot_mats = local_rot_mats_30.detach().cpu().numpy().astype(np.float32)
171
 
 
 
 
 
 
 
 
 
 
 
 
172
  # Step 3: root translation = Hips (joint 0) in posed_joints.
173
  root_translation = (
174
  joints_pos_t[:, 0, :].detach().cpu().numpy().astype(np.float32)
@@ -208,6 +223,7 @@ def kimodo_motion(
208
  "fps": int(getattr(model, "fps", 30)),
209
  "rootTranslation": root_translation.tolist(),
210
  "jointRotMats": local_rot_mats.tolist(),
 
211
  "footContacts": foot_contacts_out,
212
  "summary": prompt.strip(),
213
  }
@@ -360,6 +376,16 @@ def kimodo_motion_seq(
360
  if local_rot_mats_30.ndim == 5 and local_rot_mats_30.shape[0] == 1:
361
  local_rot_mats_30 = local_rot_mats_30[0]
362
  local_rot_mats = local_rot_mats_30.detach().cpu().numpy().astype(np.float32)
 
 
 
 
 
 
 
 
 
 
363
  root_translation = joints_pos_t[:, 0, :].detach().cpu().numpy().astype(np.float32)
364
 
365
  T, J = local_rot_mats.shape[0], local_rot_mats.shape[1]
@@ -387,6 +413,7 @@ def kimodo_motion_seq(
387
  "fps": int(getattr(model, "fps", 30)),
388
  "rootTranslation": root_translation.tolist(),
389
  "jointRotMats": local_rot_mats.tolist(),
 
390
  "footContacts": foot_contacts_out,
391
  "summary": " → ".join(p.strip() for p in prompts),
392
  "segments": [{"prompt": p.strip(), "frames": int(n)} for p, n in zip(prompts, frames)],
 
9
  "numFrames": int,
10
  "fps": 30,
11
  "rootTranslation": [[x,y,z], ...], # [N, 3]
12
+ "jointRotMats": [[[[...]]]], # [N, 30, 3, 3] local rotations
13
+ "globalRotMats": [[[[...]]]], # [N, 30, 3, 3] world-space rotations
14
+ # (kimodo's SOMA-77 FK output sliced
15
+ # to SOMA-30; finger-tip joints carry
16
+ # relaxed_hands_rest compounding)
17
  "footContacts": [[lh, lt, lte, rh, rt, rte]], # [N, 6] (optional;
18
  # SOMA-77 layout — toe-end copies
19
  # toe-base contact, see
 
173
  local_rot_mats_30 = local_rot_mats_30[0]
174
  local_rot_mats = local_rot_mats_30.detach().cpu().numpy().astype(np.float32)
175
 
176
+ # Step 2b: same slice on the global rotation tensor. from_SOMASkeleton77
177
+ # is just per-joint indexing (definitions.py:from_SOMASkeleton77), so it
178
+ # works on globals too. Webapp uses this for FK-parity validation.
179
+ joints_rot_t = torch.from_numpy(global_rot_mats[0]).to(device)
180
+ global_rot_mats_30_t = skeleton.from_SOMASkeleton77(joints_rot_t)
181
+ if global_rot_mats_30_t.ndim == 5 and global_rot_mats_30_t.shape[0] == 1:
182
+ global_rot_mats_30_t = global_rot_mats_30_t[0]
183
+ global_rot_mats_30 = (
184
+ global_rot_mats_30_t.detach().cpu().numpy().astype(np.float32)
185
+ )
186
+
187
  # Step 3: root translation = Hips (joint 0) in posed_joints.
188
  root_translation = (
189
  joints_pos_t[:, 0, :].detach().cpu().numpy().astype(np.float32)
 
223
  "fps": int(getattr(model, "fps", 30)),
224
  "rootTranslation": root_translation.tolist(),
225
  "jointRotMats": local_rot_mats.tolist(),
226
+ "globalRotMats": global_rot_mats_30.tolist(),
227
  "footContacts": foot_contacts_out,
228
  "summary": prompt.strip(),
229
  }
 
376
  if local_rot_mats_30.ndim == 5 and local_rot_mats_30.shape[0] == 1:
377
  local_rot_mats_30 = local_rot_mats_30[0]
378
  local_rot_mats = local_rot_mats_30.detach().cpu().numpy().astype(np.float32)
379
+
380
+ # Same slice on global_rot_mats; webapp uses this for FK-parity validation.
381
+ joints_rot_t = torch.from_numpy(global_rot_mats[0]).to(device)
382
+ global_rot_mats_30_t = skeleton.from_SOMASkeleton77(joints_rot_t)
383
+ if global_rot_mats_30_t.ndim == 5 and global_rot_mats_30_t.shape[0] == 1:
384
+ global_rot_mats_30_t = global_rot_mats_30_t[0]
385
+ global_rot_mats_30 = (
386
+ global_rot_mats_30_t.detach().cpu().numpy().astype(np.float32)
387
+ )
388
+
389
  root_translation = joints_pos_t[:, 0, :].detach().cpu().numpy().astype(np.float32)
390
 
391
  T, J = local_rot_mats.shape[0], local_rot_mats.shape[1]
 
413
  "fps": int(getattr(model, "fps", 30)),
414
  "rootTranslation": root_translation.tolist(),
415
  "jointRotMats": local_rot_mats.tolist(),
416
+ "globalRotMats": global_rot_mats_30.tolist(),
417
  "footContacts": foot_contacts_out,
418
  "summary": " → ".join(p.strip() for p in prompts),
419
  "segments": [{"prompt": p.strip(), "frames": int(n)} for p, n in zip(prompts, frames)],