Skip to content
Snippets Groups Projects
Commit 8da041a3 authored by Nathan Vegdahl's avatar Nathan Vegdahl
Browse files

Rigify: fixed broken ik/fk snapping (api changes).

parent 940b6cd3
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ from rigify.utils import MetarigError, new_bone, get_rig_type
from rigify.utils import ORG_PREFIX, MCH_PREFIX, DEF_PREFIX, WGT_PREFIX, ROOT_NAME, make_original_name
from rigify.utils import RIG_DIR
from rigify.utils import create_root_widget
from rigify.utils import random_string
from rigify.utils import random_id
from rigify.rig_ui_template import UI_SLIDERS, layers_ui, UI_REGISTER
from rigify import rigs
......@@ -55,7 +55,7 @@ def generate_rig(context, metarig):
# Random string with time appended so that
# different rigs don't collide id's
rig_id = random_string(8) + str(hex(int(time.time())))[2:][-8:].rjust(8, '0')
rig_id = random_id(16)
# Initial configuration
mode_orig = context.mode
......
......@@ -49,42 +49,12 @@ def get_pose_matrix_in_other_space(mat, pose_bone):
# Get matrix in bone's current transform space
smat = rest_inv * (par_rest * (par_inv * mat))
# Compensate for non-inherited rotation/scale
if not pose_bone.bone.use_inherit_rotation:
loc = mat.to_translation()
loc -= (par_mat*(par_rest.inverted() * rest)).to_translation()
loc *= rest.inverted().to_quaternion()
if pose_bone.bone.use_inherit_scale:
t = par_mat.to_scale()
par_scale = Matrix.Scale(t[0], 4, Vector((1,0,0)))
par_scale *= Matrix.Scale(t[1], 4, Vector((0,1,0)))
par_scale *= Matrix.Scale(t[2], 4, Vector((0,0,1)))
else:
par_scale = Matrix()
smat = rest_inv * mat * par_scale.inverted()
smat[3][0] = loc[0]
smat[3][1] = loc[1]
smat[3][2] = loc[2]
elif not pose_bone.bone.use_inherit_scale:
loc = smat.to_translation()
rot = smat.to_quaternion()
scl = mat.to_scale()
smat = Matrix.Scale(scl[0], 4, Vector((1,0,0)))
smat *= Matrix.Scale(scl[1], 4, Vector((0,1,0)))
smat *= Matrix.Scale(scl[2], 4, Vector((0,0,1)))
smat *= Matrix.Rotation(rot.angle, 4, rot.axis)
smat[3][0] = loc[0]
smat[3][1] = loc[1]
smat[3][2] = loc[2]
# Compensate for non-local location
if not pose_bone.bone.use_local_location:
loc = smat.to_translation() * (par_rest.inverted() * rest).to_quaternion()
smat[3][0] = loc[0]
smat[3][1] = loc[1]
smat[3][2] = loc[2]
#if not pose_bone.bone.use_local_location:
# loc = smat.to_translation() * (par_rest.inverted() * rest).to_quaternion()
# smat[3][0] = loc[0]
# smat[3][1] = loc[1]
# smat[3][2] = loc[2]
return smat
......
......@@ -18,7 +18,8 @@
import bpy
import imp
from random import randint
import random
import time
from mathutils import Vector
from math import ceil, floor
from rna_prop_ui import rna_idprop_ui_prop_get
......@@ -497,10 +498,16 @@ def write_metarig(obj, layers=False, func_name="create_sample"):
return "\n".join(code)
def random_string(length):
def random_id(length = 8):
""" Generates a random alphanumeric id string.
"""
tlength = int(length / 2)
rlength = int(length / 2) + int(length % 2)
chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
text = ""
for i in range(0, length):
text += chars[randint(0, 35)]
for i in range(0, rlength):
text += random.choice(chars)
text += str(hex(int(time.time())))[2:][-tlength:].rjust(tlength, '0')[::-1]
return text
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment