Created
October 23, 2012 09:20
-
-
Save flufy3d/3937823 to your computer and use it in GitHub Desktop.
How to convert global to local coordinates in blender
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mathutils import Matrix | |
from mathutils import Vector | |
from mathutils import Quaternion | |
import bpy | |
print('start') | |
rVector = Vector((0.0, 0.0, 0.0)) | |
rquat = Quaternion((0.707,0.707,0,0)).to_matrix().to_4x4() | |
mw = bpy.data.armatures['Armature'].bones['Bone'].matrix.copy() | |
hymat = Quaternion((0.707,-0.707,0,0)).inverted().to_matrix().to_4x4() | |
mat = Matrix.Translation(rVector) * rquat * mw.to_4x4() | |
bpy.context.object.pose.bones['Bone'].matrix = mat | |
squat = Quaternion((1.0,0,0,0)).to_matrix().to_4x4() | |
globalVector = Vector((0.0, 0.0, 1.0)) | |
mw = bpy.data.armatures['Armature'].bones['Bone.001'].matrix.copy() | |
hymat = Quaternion((0.707,-0.707,0,0)).inverted().to_matrix().to_4x4() | |
mat = Matrix.Translation(globalVector) * squat * hymat * mw.to_4x4() | |
bpy.context.object.pose.bones['Bone.001'].matrix = mat | |
mw = bpy.data.armatures['Armature'].bones['Bone.002'].matrix.copy() | |
hymat = Quaternion((0.707,-0.707,0,0)).inverted().to_matrix().to_4x4() | |
mat = Matrix.Translation(globalVector) * squat * hymat * mw.to_4x4() | |
bpy.context.object.pose.bones['Bone.002'].matrix = mat | |
print('end') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/7132018/how-to-convert-global-to-local-coordinates-in-blender-2-5