Skip to content

Commit de903b7

Browse files
committed
If animation is not in, we shouldn't be calling IGLAnimation
1 parent 5d91a88 commit de903b7

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

scripts/blender_igl_export.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,21 @@ def export(self, file_name_without_ext):
182182
skeleton_writer.write(f"\n{parent[0] + 1} {parent[1] + 1} 1")
183183

184184
skeleton_writer.write("\n#")
185+
186+
logger.info(f"SKELETON exported in {file_name_without_ext}.tgf")
187+
188+
igl_bind_pose = self.bind_pose[:, :3, :] # J X 3 X 4 ... last row of affine matrix not needed
189+
igl_bind_pose = igl_bind_pose.transpose((0, 2, 1)) # J X 4 X 3 ... igl standard
190+
191+
# Save bind pose as npy
192+
np.save(f"{file_name_without_ext}_bind_pose.npy", igl_bind_pose)
193+
logger.info(f"BIND POSE {igl_bind_pose.shape} exported in {file_name_without_ext}_bind_pose.npy")
194+
195+
# Save bind pose as dmat
196+
# J*4 X 3 ... stack the transforms
197+
bind_pose_flat = igl_bind_pose.reshape((-1, igl_bind_pose.shape[2]))
198+
_export_matrix_as_dmat(f"{file_name_without_ext}_bind_pose.dmat", bind_pose_flat)
199+
logger.info(f"BIND POSE {bind_pose_flat.shape} exported in {file_name_without_ext}_bind_pose.dmat")
185200

186201

187202
class IGLDeformableMesh:
@@ -289,26 +304,20 @@ def __init__(self, igl_skeleton, parent_armature, start_frame, end_frame):
289304

290305
logger.info(f"Ready to Export Animation frames [{self.start_frame}, {self.end_frame}]")
291306

292-
def _export_npy(self, filepath, bind_pose, animation):
293-
np.save(f"{filepath}_bind_pose.npy", bind_pose)
307+
def _export_npy(self, filepath, animation):
294308
np.save(f"{filepath}_animation.npy", animation)
295309
logger.info(
296-
f"Bind Pose ({bind_pose.shape}) and Animation ({animation.shape}) exported as npy")
310+
f"ANIMATION ({animation.shape}) exported as npy")
297311

298-
def _export_dmat(self, filepath, bind_pose, animation):
299-
# J*4 X 3 ... stack the transforms
300-
bind_pose_flat = bind_pose.reshape((-1, bind_pose.shape[2]))
301-
312+
def _export_dmat(self, filepath, animation):
302313
# Frames X J*4*3
303314
animation_flat = animation.reshape((animation.shape[0], -1))
304315
animation_flat = animation_flat.transpose() # J*4*3 X Frames
305316

306-
_export_matrix_as_dmat(f"{filepath}_bind_pose", bind_pose_flat)
307317
_export_matrix_as_dmat(f"{filepath}_animation", animation_flat)
308318

309319
logger.info(
310-
(f"Bind Pose [{bind_pose_flat.shape}] "
311-
f"and Animation [{animation_flat.shape} column ordered from {animation.shape}] "
320+
(f"ANIMATION [{animation_flat.shape} column ordered from {animation.shape}] "
312321
"exported as dmat"))
313322

314323
def _get_bind_pose_relative_animation(self, bind_pose, animation):
@@ -348,16 +357,14 @@ def export(self, filepath):
348357

349358
# Make IGL ready bind pose
350359
bind_pose = self.skeleton.bind_pose
351-
igl_bind_pose = bind_pose[:, :3, :] # J X 3 X 4 ... last row of affine matrix not needed
352-
igl_bind_pose = igl_bind_pose.transpose((0, 2, 1)) # J X 4 X 3 ... igl standard
353360

354361
# Make IGL ready animation
355362
igl_animation = np.array(self._get_bind_pose_relative_animation(bind_pose, animation))
356363
igl_animation = igl_animation[:, :, :3, :] # Frames X J X 3 X 4 ... last row of affine matrix not needed
357364
igl_animation = igl_animation.transpose((0, 1, 3, 2)) # Frames X J X 4 X 3 ... igl standard
358365

359-
self._export_npy(filepath, igl_bind_pose, igl_animation)
360-
self._export_dmat(filepath, igl_bind_pose, igl_animation)
366+
self._export_npy(filepath, igl_animation)
367+
self._export_dmat(filepath, igl_animation)
361368

362369

363370
# FILE BROWSER SETUP
@@ -449,16 +456,19 @@ def _begin_export(self, context, file_path):
449456
bones_to_process.append(child)
450457

451458
deformable_mesh = IGLDeformableMesh(geometry, igl_skeleton)
452-
animation = IGLAnimation(igl_skeleton, parent, self.anim_start, self.anim_end)
453-
459+
454460
if self.export_skeleton:
455461
igl_skeleton.export(file_path)
456462

457463
if self.export_mesh or self.export_skinning:
458464
deformable_mesh.export(file_path, self.export_mesh, self.export_skinning)
459465

460466
if self.export_animation:
461-
animation.export(file_path)
467+
if parent.animation_data is None:
468+
logger.error("Requested to export animation but no animation data found")
469+
else:
470+
animation = IGLAnimation(igl_skeleton, parent, self.anim_start, self.anim_end)
471+
animation.export(file_path)
462472

463473
self.report({'INFO'}, f"Finished Export to {file_path}")
464474
self.report({'INFO'}, f"Log dumped to {log_file}")

0 commit comments

Comments
 (0)