如何在搅拌机2.5中将全局坐标转换为本地坐标?
问题描述:
我想在搅拌机2.5移动骨下面的脚本如何在搅拌机2.5中将全局坐标转换为本地坐标?
bpy.context.object.pose.bones['hand_ik.L'].location=(X1,Y1,Z1)
,但我有全局(X2,Y2,Z2)。我如何转换X2,Y2,Z2(含矩阵运算),以相应的X1,Y1,Z1
我想达到同样的动作为
bpy.ops.transform.translate(value=(X2,Y2,Z2),const raint_orientation='GLOBAL')
我发现下面的代码我可以移动父母的骨头
ob = bpy.context.object
globalVector = Vector((1.0, 0.0, 0.0))
mw = bpy.data.armatures['Armature'].bones['hand_IK.R'].matrix.copy()
bpy.context.object.pose.bones['hand_IK.R'].location = mw.inverted()*globalVector
但是当骨骼有父母并且没有连接时该怎么办?
感谢名单
答
几周前,写访问PoseBose.matrix(骨的电枢空间矩阵)被授予了Python API。如果您使用2.59或最新的躯干,你可以使用类似这样的代码:
from mathutils import Matrix
ob = bpy.context.object
globalVector = Vector((1.0, 0.0, 0.0))
mw = bpy.data.armatures['Armature'].bones['hand_IK.R'].matrix.copy()
obGlobal = ob.matrix_world
bpy.context.object.pose.bones['hand_IK.R'].matrix = ob.matrix_world.inverted()*(Matrix.Translation(globalVector)+mw.to_3x3().to_4x4())
转换到3维,然后返回到4清除原来的翻译,然后你在你的globalVector添加并且将整个事物转化为考虑对象的全局矩阵。
有关操作骨骼的很好的代码示例,请查看我的用于Motion Capture的Blender Addon,Here,位于retargetEndUser中的函数bakeTransform中。