|
|
Line 814: |
Line 814: |
| Scenario: You load two characters into Mod Tool and rotate (+/-180°) the throw target character because you need them to stand face to face as you work on an animation. When you are done animating, the target animation would need to be reversed again. This means multiplying the velocities by -1; the rotation also needs correcting. So it looks like you need *(-1) for the x rotation and -/+180° (depending on your initial change) for the Y rotation. | | Scenario: You load two characters into Mod Tool and rotate (+/-180°) the throw target character because you need them to stand face to face as you work on an animation. When you are done animating, the target animation would need to be reversed again. This means multiplying the velocities by -1; the rotation also needs correcting. So it looks like you need *(-1) for the x rotation and -/+180° (depending on your initial change) for the Y rotation. |
|
| |
|
| ====Blender script==== | | ====BlenderOni Throw Adjust==== |
| This is a Blender script for rotating -/+180° and adding PositionOffset to a forward throw Target animation. This was made by a hero from the Blender Discord named Danta. The add_object_offset_about_cursor_Z() function was written by Delano762.
| | There is a Blender script implemented within the BlenderOni addon for rotating and adding PositionOffset to a forward throw Target animation. It is capable of adjusting both forward and back throws. The script's old version can be accessed [[Obsolete_Blender_Scripts#Script_for_adjusting_forward_throw_targets|HERE.]] |
| | |
| For each frame in the range you specify, this script rotates the selected object by 180 degrees (or however many you want), and translates it by the offset found in the <TargetAdjustment> <Position> tag of the attacker's throw animation XML. It also has a frame-checking functionality that's buggy; ultimately there is no real reason at the moment to use it, but it may come in handy in the future, so it should be left in this snippet.
| |
| | |
| Step-by-step guide on using this script:
| |
| :1. Import a throw animation and its target animation into Blender.
| |
| :2. Open Scripting tab.
| |
| :3. Create a new text, and name it however you want with .py extension, e.g. TRAMAdjuster.py
| |
| :4. Paste the script.
| |
| :5. On the following lines…
| |
| | |
| <pre>scene.frame_set(start)
| |
| for i in range(start, end):</pre>
| |
| | |
| …set ''start'' and ''end'' to the start frame of the animation (always 0 for vanilla anims, but if you're animating and starting from 1, you'll want it set to 1) and the ''end'' to the (end + 1) frame of your animation; e.g. if you have a 99 frame animation, set ''end'' to 100.
| |
| | |
| :6. On the following line…
| |
| | |
| <pre>add_object_offset_about_cursor_Z(obj,x,-z,-y) #translate object</pre>
| |
| | |
| …paste the values from the <Position> tag according to the order of the function arguments. The minus sign means the value should be inverted in the function. As an example, assuming you have the following <Position> tag…
| |
| | |
| <pre><Position>1 2 -3</Position></pre>
| |
| | |
| …the function call should be as follows…
| |
| | |
| <pre>add_object_offset_about_cursor_Z(obj,1,3,-2) #translate object</pre>
| |
| | |
| :7. Select the pelvis of the target animation.
| |
| :8. Press Shift+C to ensure your 3D cursor is in the center of the animation.
| |
| :9. Set the Transform Pivot Point to "3D Cursor".
| |
| :10. On the Scripting tab, run the script.
| |
| :11. The target should be now adjusted as expected.
| |
| :12. If you want to revert the target back to an exportable position and rotation, simply invert the Z argument in the add_object_offset_about_cursor_Z function and run the script again.
| |
| | |
| <pre>import bpy
| |
| from math import pi, radians
| |
| from mathutils import Matrix, Quaternion, Vector
| |
| | |
| obj = bpy.context.active_object
| |
| scene = bpy.context.scene
| |
| | |
| | |
| def add_object_offset_about_cursor_Z(object,x,y,z): #Translation function
| |
| cursor_loc = bpy.context.scene.cursor.location #3D Cursor location
| |
|
| |
| mat = (Matrix.Translation(cursor_loc) @
| |
| Matrix.Translation((x,y,z))) #PositionOffset translation applied
| |
| object.matrix_world = mat @ object.matrix_world #Change applied to object
| |
| | |
| def rotate_object_about_cursor_Z(object, degrees): #Rotation function
| |
| cursor_loc = bpy.context.scene.cursor.location #3D Cursor location
| |
|
| |
| mat = (Matrix.Translation(cursor_loc) @
| |
| Matrix.Rotation(radians(degrees), 4, 'Z') @
| |
| Matrix.Translation(-cursor_loc)) #Rotation applied
| |
|
| |
| object.matrix_world = mat @ object.matrix_world #Change applied to object
| |
| | |
| #BUGGED KEYFRAME-CHECKING FUNCTION, NOT USED BUT MIGHT BE USEFUL IN THE FEATURE
| |
| """def is_keyframe(ob, frame, data_path, array_index=-1):
| |
| if ob is not None and ob.animation_data is not None and ob.animation_data.action is not None:
| |
| for fcu in ob.animation_data.action.fcurves:
| |
| if fcu.data_path == data_path:
| |
| if array_index == -1 or fcu.array_index == array_index:
| |
| return frame in (p.co.x for p in fcu.keyframe_points)
| |
| return False
| |
| | |
| bpy.types.Object.is_keyframe = is_keyframe """
| |
| | |
| #not really sure why those three lines are here, I think they can be left out
| |
| #obj.keyframe_insert(data_path="location", frame = 0) | |
| #obj.matrix_world.translation += Vector((-100, 0, 0))
| |
| #obj.keyframe_insert(data_path="location", frame = 100)
| |
| | |
| scene.frame_set(start) #set start frame
| |
| for i in range(start, end): #loop for every frame
| |
| #if obj.is_keyframe(i, obj.path_from_id("location")): Bugged keyframe-check
| |
| scene.frame_set(i)
| |
| rotate_object_about_cursor_Z(obj, 180) #rotate object
| |
| add_object_offset_about_cursor_Z(obj,x,-z,y) #translate object
| |
| obj.keyframe_insert(data_path="rotation_euler", frame=i) #keyframe rotation
| |
| obj.keyframe_insert(data_path="location", frame=i) #keyframe location
| |
| </pre>
| |
|
| |
|
| ===Excel macro=== | | ===Excel macro=== |