[Bf-blender-cvs] [2ba2860] master: Transforms to Delta Transforms

Joshua Leung noreply at git.blender.org
Thu Jul 7 15:53:47 CEST 2016


Commit: 2ba2860e11c122824bb4e083b3f1148610693be3
Author: Joshua Leung
Date:   Mon Jul 4 12:52:51 2016 +1200
Branches: master
https://developer.blender.org/rB2ba2860e11c122824bb4e083b3f1148610693be3

Transforms to Delta Transforms

* Added new operators to take the current transform value (loc/rot/scale or all 3)
  and convert/apply that transform to a corresponding delta transform value. By default,
  the transform value will be zeroed out again afterwards, so you don't end up with a
  double transform.

* These operators can be found in the "Apply" menu (Ctrl-A)

* The "Animated Transforms to Deltas" (which does a similar job, except it adjusts all
  existing animation data instead of the current transform) has also been moved to the
  Apply menu (it was in the Transform menu instead)

===================================================================

M	release/scripts/startup/bl_operators/object.py
M	release/scripts/startup/bl_ui/space_view3d.py

===================================================================

diff --git a/release/scripts/startup/bl_operators/object.py b/release/scripts/startup/bl_operators/object.py
index b89890a..caea8e5 100644
--- a/release/scripts/startup/bl_operators/object.py
+++ b/release/scripts/startup/bl_operators/object.py
@@ -685,6 +685,88 @@ class ClearAllRestrictRender(Operator):
         return {'FINISHED'}
 
 
+class TransformsToDeltas(Operator):
+    """Convert normal object transforms to delta transforms, """ \
+    """any existing delta transforms will be included as well"""
+    bl_idname = "object.transforms_to_deltas"
+    bl_label = "Transforms to Deltas"
+    bl_options = {'REGISTER', 'UNDO'}
+    
+    mode = EnumProperty(
+            items=(('ALL',
+                    "All Transforms",
+                    "Transfer location, rotation, and scale transforms",
+                    ),
+                   ('LOC',
+                    "Location",
+                    "Transfer location transforms only",
+                    ),
+                   ('ROT',
+                    "Rotation",
+                    "Transfer rotation transforms only",
+                    ),
+                   ('SCALE',
+                    "Scale",
+                    "Transfer scale transforms only",
+                    ),
+                   ),
+            name="Mode",
+            description="Which transforms to transfer",
+            default='ALL',
+            )
+    reset_values = BoolProperty(
+            name="Reset Values",
+            description=("Clear transform values after transferring to deltas"),
+            default=True,
+            )
+    
+    @classmethod
+    def poll(cls, context):
+        obs = context.selected_editable_objects
+        return (obs is not None)
+    
+    def execute(self, context):
+        for obj in context.selected_editable_objects:
+            if self.mode in ('ALL', 'LOC'):
+                self.transfer_location(obj)
+                    
+            if self.mode in ('ALL', 'ROT'):
+                self.transfer_rotation(obj)
+            
+            if self.mode in ('ALL', 'SCALE'):
+                self.transfer_scale(obj)
+        
+        return {'FINISHED'}
+    
+    def transfer_location(self, obj):
+        obj.delta_location += obj.location
+        
+        if self.reset_values:
+            obj.location.zero()
+        
+    def transfer_rotation(self, obj):
+        # TODO: add transforms together...
+        if obj.rotation_mode == 'QUATERNION':
+            obj.delta_rotation_quaternion += obj.rotation_quaternion
+            
+            if self.reset_values:
+                obj.rotation_quaternion.identity() 
+        elif obj.rotation_mode == 'AXIS_ANGLE':
+            pass  # Unsupported
+        else:
+            delta = obj.delta_rotation_euler.copy()
+            obj.delta_rotation_euler = obj.rotation_euler.copy()
+            obj.delta_rotation_euler.rotate(delta)
+            
+            if self.reset_values:
+                obj.rotation_euler.zero()
+    
+    def transfer_scale(self, obj):
+        obj.delta_scale += obj.scale
+        if self.reset_values:
+            obj.scale[:] = (1, 1, 1)
+
+
 class TransformsToDeltasAnim(Operator):
     """Convert object animation for normal transforms to delta transforms"""
     bl_idname = "object.anim_transforms_to_deltas"
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 1aaf5c0..923d682 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -296,10 +296,6 @@ class VIEW3D_MT_transform_object(VIEW3D_MT_transform_base):
         layout.operator("object.randomize_transform")
         layout.operator("object.align")
 
-        layout.separator()
-
-        layout.operator("object.anim_transforms_to_deltas")
-
 
 # Armature EditMode extensions to Transform menu
 class VIEW3D_MT_transform_armature(VIEW3D_MT_transform_base):
@@ -1508,6 +1504,15 @@ class VIEW3D_MT_object_apply(Menu):
         props.location, props.rotation, props.scale = False, True, True
 
         layout.separator()
+        
+        layout.operator("object.transforms_to_deltas", text="Location to Deltas", text_ctxt=i18n_contexts.default).mode = 'LOC'
+        layout.operator("object.transforms_to_deltas", text="Rotation to Deltas", text_ctxt=i18n_contexts.default).mode = 'ROT'
+        layout.operator("object.transforms_to_deltas", text="Scale to Deltas", text_ctxt=i18n_contexts.default).mode = 'SCALE'
+        
+        layout.operator("object.transforms_to_deltas", text="All Transforms to Deltas", text_ctxt=i18n_contexts.default).mode = 'ALL'
+        layout.operator("object.anim_transforms_to_deltas")
+        
+        layout.separator()
 
         layout.operator("object.visual_transform_apply", text="Visual Transform", text_ctxt=i18n_contexts.default)
         layout.operator("object.duplicates_make_real")




More information about the Bf-blender-cvs mailing list