I’m working with SimpleOpenNI to capture Kinect data. They have a method getJointPositionSkeleton() which returns what appears to be a rotation matrix (I’m working under this assumption) example:
I’ve been trying to figure out how to apply these rotations to my bones in Blender, currently, I’m constructing the Matrix within python and setting the matrix of the pose bone to the product of rotation matrix and the local matrix of the bone:
Honestly I’m out of my league math wise here and I’m looking for any push in the right direction, or someone to tell me if I’ve just completely goofed this up. In addition I’m able to grab the coordinates of the joints themselves but I am unaware of a way that this could be utilized to set the rotation of the bones, however I figured I’d add that piece of information just in case that could provide another path forward.
Yup, that looks pretty much like a rotation matrix.
Here’s some code I wrote a while back that applies a rotation to a pose bone; note how it uses the bone origin as the rotation origin:
parent_bone = context.selected_pose_bones[0]
# parent_origin = parent_bone.matrix * parent_bone.bone.head
# seems like “head” property is actually tail of parent bone,
# real head of a bone is always at (0, 0, 0) in its own coord system
parent_origin = parent_bone.matrix * Vector((0, 0, 0))
parent_axis = (parent_bone.tail - parent_bone.head).normalized()
parent_matrix = parent_bone.matrix.copy()
parent_bone.matrix = \
(
Matrix.Translation(parent_origin)
*
Matrix.Rotation(- self.rotation_angle, 4, parent_axis)
*
Matrix.Translation(parent_origin).inverted()
*
parent_matrix
)
I’m going to go ahead and provide the full code of my plugin and an example capture file, because I seem to keep arriving at the same place no matter what I do (even trying to adapt the code that ldo so graciously provided. Attached find my current code (for Blender 2.8), the test blend, and a gif of the results I’m seeing with the current code and a text file containing output from the SimpleOpenNI capture system I implemented. kinect2blend.py (6.7 KB) test.blend (769.1 KB) test_capture.txt (88 KB)