2
\$\begingroup\$

Below code snippet shows the way to export coordinate of bones:

def export_bone_matrix(armature, bone, label, file_handler):
  SystemMatrix = Matrix.Scale(-1, 4, Vector((0, 0, 1))) * Matrix.Rotation(radians(90), 4, 'X')

if (bone.parent):
    Export_babylon.write_matrix4(file_handler, label, (SystemMatrix * armature.matrix_world * bone.parent.matrix).inverted() * (SystemMatrix * armature.matrix_world * bone.matrix))
else:
    Export_babylon.write_matrix4(file_handler, label, SystemMatrix * armature.matrix_world * bone.matrix)

I have create a 3D character in Blender, and add keyframes in it by transforming
in some frames. From the graph editor, you can easily tell the all displacement
of transformation - translate, rotate, scale are all measured with respect to the
original value in frame 0.

Is it possible to write OpenGL in Android to animate the same 3D animation in Blender?
I'd like to transform the 3D character - translate, rotate in each frame according to
the displacement value exported from Blender.

Below lists the python function to export translate, rotate displacement in each frame:

def get_bone_action_location(action, bonename, frame=1):
loc = Vector()
if action == None:
    return(loc)
data_path = 'pose.bones["%s"].location'%(bonename)
for fc in action.fcurves:
    if fc.data_path == data_path:
        loc[fc.array_index] = fc.evaluate(frame)
return(loc)

def get_bone_action_rotation(action, bonename, frame=1):
rot = Quaternion( (1, 0, 0, 0) )  #the default quat is not 0
if action == None:
    return(rot)
data_path = 'pose.bones["%s"].rotation_quaternion'%(bonename)
for fc in action.fcurves:
    if fc.data_path == data_path: # and frame > 0 and frame-1 <= len(fc.keyframe_points):
        rot[fc.array_index] = fc.evaluate(frame)
return(rot)

Or I need to transform the meshes with vertex group controlled by root bone by the
transform matrix - SystemMatrix * armature.matrix_world * bone.matrix? And for those
controlled by child bones by the matrix in terms of (SystemMatrix * armature.matrix_world * bone.parent.matrix).inverted() * (SystemMatrix * armature.matrix_world * bone.matrix)?

\$\endgroup\$

0

You must log in to answer this question.

Browse other questions tagged .