I'm making a script for import models from a game. This game has inital position and rotation for each bone. If I load the model without rotating bones, it looks like this:
and if I load rotations it should be like this
Unfortunately, when I load the rotations, they change the model completely
The model should be in something like 'A' pose, like this:
This is the script:
bpy.ops.object.mode_set(mode='EDIT')
for h in range(boneCount):
name = f[h * 3 + 1][:-1]
parent = int(f[h * 3 + 2])
coords = f[h * 3 + 3][:-1].split(" ")
bone = skl.data.edit_bones.new(name)
bone.head = mathutils.Vector([float(coords[0]), float(coords[1]), float(coords[2])])
bone.tail = mathutils.Vector([float(coords[0]), float(coords[1])+0.01, float(coords[2])])
bpy.ops.object.mode_set(mode='POSE')
for h in range(boneCount):
name = f[h * 3 + 1][:-1]
parent = int(f[h * 3 + 2])
coords = f[h * 3 + 3][:-1].split(" ")
rot = mathutils.Quaternion([float(coords[6]), float(coords[3]), float(coords[4]), float(coords[5])])
bone = skl.data.edit_bones.get(name)
bpy.context.object.pose.bones[h].rotation_quaternion = rot
bpy.ops.object.mode_set(mode='EDIT')
for h in range(boneCount):
name = f[h * 3 + 1][:-1]
parent = int(f[h * 3 + 2])
coords = f[h * 3 + 3][:-1].split(" ")
bone = skl.data.edit_bones.get(name)
if parent != -1:
bone.parent = skl.data.edit_bones[parent]
Rotations are quaternions. Any ideas on how I can implement it? Thanks