Is there any infomation about convert joints rotation in json file to blender rotation

The A2F plugin in blender works well when import blendshape animation from json file.But it can’t import joints animation.So I wrote my own script to import the joints animation.The script now can successfully read the joints animation, but the joint rotations got wrong orientation.

Here is my code:

import bpy
import json
import mathutils

bpy.ops.wm.console_toggle()

def ReadJsonFile(file_path):
    try:
        with open(file_path, 'r') as json_file:
            data = json.load(json_file)
            return data
    except FileNotFoundError:
        print(f"File '{file_path}' not found.")
        return None
    
jsonData = ReadJsonFile(r'G:\Omniverse\Audio2FaceTest\Export\ToBlender\a2f_export_face_bsweight.json')
print(jsonData["trackPath"])

joints = jsonData["joints"]
rotations = jsonData["rotations"]
numFrames = jsonData["numFrames"]

rootBone = bpy.data.objects["Root"]
for i in range(len(joints)):
    curBone = rootBone.pose.bones.get(joints[i].split("/")[-1])
    curBone.rotation_mode = 'QUATERNION'
    print(curBone)
    for fr in range(numFrames):
        quaternion = mathutils.Quaternion((rotations[fr][i][0], rotations[fr][i][1], rotations[fr][i][2], rotations[fr][i][3]))
        curBone.rotation_quaternion = quaternion
        curBone.keyframe_insert("rotation_quaternion", frame = fr)

I got the problem.When I import fbx into blender my eye and jaw bone got wrong orientation.I fixed the orientation and the script worked.
If there are any one who have problem importing json file into blender, can refer to the script I wrote, it worked for me.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.