Skip to content

Commit 6533b24

Browse files
committed
reset the pose and timeline after the export
1 parent 8137303 commit 6533b24

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

__init__.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def execute(self, context):
410410

411411

412412

413-
self.clear_objects_transform(context, objects_to_export)
413+
self.change_objects_transform(context, objects_to_export)
414414

415415
try:
416416
# Get export configurations, based on the user choices.
@@ -475,8 +475,7 @@ def execute(self, context):
475475
self.report({'INFO'}, "EXPORT ERROR")
476476

477477

478-
# Return transform to how it was.
479-
self.undo_objects_transform(context)
478+
self.change_back_objects_transform(context)
480479

481480
# Return selection to how it was.
482481
bpy.ops.object.select_all(action='DESELECT')
@@ -488,6 +487,9 @@ def execute(self, context):
488487
if active_object:
489488
bpy.ops.object.mode_set(mode=tab_mode)
490489

490+
self.reset_animation_and_pose(context, objects_to_export)
491+
492+
491493
return {'FINISHED'}
492494

493495

@@ -524,7 +526,7 @@ def select_children_recursive(self, obj, context):
524526
self.select_children_recursive(c, context)
525527

526528

527-
def clear_objects_transform(self, context, objects_to_export):
529+
def change_objects_transform(self, context, objects_to_export):
528530
settings = context.scene.batch_export
529531

530532
self.old_locations = []
@@ -538,21 +540,22 @@ def clear_objects_transform(self, context, objects_to_export):
538540
if obj.parent:
539541
continue
540542

541-
self.objects_to_undo.append(obj)
542-
543543
if settings.clear_location:
544544
self.old_locations.append(obj.location.copy())
545545
obj.location = (0.0, 0.0, 0.0)
546+
546547
if settings.clear_rotation:
547548
self.old_rotations.append(obj.rotation_euler.copy())
548549
obj.rotation_euler = (0.0, 0.0, 0.0)
550+
549551
if settings.clear_scale:
550552
self.old_scales.append(obj.scale.copy())
551553
obj.scale = (0.0, 0.0, 0.0)
552-
553554

555+
self.objects_to_undo.append(obj)
554556

555-
def undo_objects_transform(self, context):
557+
558+
def change_back_objects_transform(self, context):
556559
settings = context.scene.batch_export
557560

558561
for i, obj in enumerate(self.objects_to_undo):
@@ -564,6 +567,23 @@ def undo_objects_transform(self, context):
564567
obj.scale = self.old_scales[i]
565568

566569

570+
def reset_animation_and_pose(self, context, objects_to_export):
571+
# Set the current frame to frame 0
572+
context.scene.frame_set(0)
573+
574+
# Check if the object is an armature
575+
for obj in objects_to_export:
576+
if obj.type == 'ARMATURE':
577+
# Go through all pose bones
578+
for pb in obj.pose.bones:
579+
# Reset bone's rotation to identity quaternion
580+
pb.rotation_quaternion.identity()
581+
# Reset bone's location to (0, 0, 0)
582+
pb.location = (0, 0, 0)
583+
# Reset bone's scale to (1, 1, 1)
584+
pb.scale = (1, 1, 1)
585+
586+
567587
def get_config_export(self, context, tex_dir):
568588
settings = context.scene.batch_export
569589

@@ -764,18 +784,22 @@ class BatchExportSettings(PropertyGroup):
764784

765785
# Transforms
766786
clear_location: BoolProperty(
767-
name="Clear Location", default=True
787+
name="Clear Location",
788+
default=False
768789
) # type: ignore
769790
clear_rotation: BoolProperty(
770-
name="Clear Rotation (XYZ Euler)", default=True
791+
name="Clear Rotation (XYZ Euler)",
792+
default=False
771793
) # type: ignore
772794
clear_scale: BoolProperty(
773-
name="Clear Scale", default=False
795+
name="Clear Scale",
796+
default=False
774797
) # type: ignore
775798

776799
# Types Affected
777800
limitar_por_tipo: BoolProperty(
778-
name="Enabled", default=False
801+
name="Enabled",
802+
default=False
779803
) # type: ignore
780804
object_types: EnumProperty(
781805
name="Object Types",
630 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)