correct finger rotation

This commit is contained in:
Bart Moyaers
2020-06-02 17:17:02 +02:00
parent 5e95571127
commit a614e90055

View File

@@ -1,5 +1,6 @@
import bpy
from random import random
from mathutils import Matrix, Quaternion
ob = bpy.data.objects['Sphere']
frame_number = 0
@@ -14,7 +15,7 @@ thumb_rot_bone = "thumb_3"
def grab_movement(open):
# Todo:
# select the 4 base finger bones
# Then: bpy.ops.transform.rotate(value=0.1, orient_axis='X', orient_type='LOCAL')
# Then:
# To rotate around local axis (will cause to grab)
# Then do the same with thumb, but only around local Z axis!
bpy.ops.object.mode_set(mode='OBJECT')
@@ -29,20 +30,22 @@ def grab_movement(open):
else:
angle = 0.8
# Select all fingers
# Deselect all fingers
for bone in arm.pose.bones: # Deselect all selected bones
bone.bone.select = False
# Rotate fingers
for name in finger_grab_bones:
bone = arm.pose.bones.get(name).bone
#if bone: bone.select = True
bone = arm.pose.bones.get(name)
# Bones need to be selected when adding keyframes, otherwise blender will throw an error:
# https://blender.stackexchange.com/questions/1828/what-constitutes-a-context-in-pose-mode
bone.bone.select = True
# rotate
# TODO: change to posebone X axis instead of world X.l
axis = bone.x_axis
bone.rotation_euler = (obj.rotation_euler.to_matrix() * Matrix.Rotation(angle, 3, 'X')).to_euler()
#bpy.ops.transform.rotate(value=angle, orient_axis=axis, orient_type='LOCAL')
bone.rotation_quaternion = bone.rotation_quaternion @ Quaternion(axis, angle)
# bone.matrix = bone.matrix @ Matrix.Rotation(-angle, 4, axis)
# Add keyframe
bpy.ops.anim.keying_set_active_set(type='Rotation')
bpy.ops.anim.keyframe_insert(type='Rotation')
@@ -57,6 +60,11 @@ def grab_movement(open):
# Script start
open = False
#if len(bpy.data.scenes['Scene'].keying_sets) == 0:
# # Add new keying set
# bpy.ops.anim.keying_set_add()
# # Activate keying set
# bpy.ops.anim.keying_set_active_set()
for i in range(50):
x = random()*max_dist