Last active
December 18, 2015 20:48
-
-
Save adhihargo/5842868 to your computer and use it in GitHub Desktop.
Bone snapping tool. Works for parented bone, only if there's no Child Of constraint involved, and all parent's scale are uniform across all axis.
This file contains 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
import bpy | |
class VIEW3D_OT_BoneSnapToObject(bpy.types.Operator): | |
"""Snap active bone to selected object.""" | |
bl_idname = 'object.snap_to_object' | |
bl_label = 'Snap Bone to Object' | |
bl_options = {'REGISTER', 'UNDO'} | |
@classmethod | |
def poll(self, context): | |
return len(context.selected_objects) == 2\ | |
and context.mode == 'POSE' | |
def execute(self, context): | |
target = [o for o in context.selected_objects | |
if o != context.active_object][0] | |
active = context.active_object | |
mat = active.matrix_world.inverted() * target.matrix_world | |
pbone = context.active_pose_bone | |
for p in pbone.parent_recursive: | |
mat = p.matrix_basis * mat | |
mat[3][0] = mat[3][1] = mat[3][2] = 0 | |
pbone.matrix = mat | |
return {'FINISHED'} | |
def register(): | |
bpy.utils.register_class(VIEW3D_OT_BoneSnapToObject) | |
def unregister(): | |
bpy.utils.unregister_class(VIEW3D_OT_BoneSnapToObject) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment