fixes for automatic tests and some errors in last commit

This commit is contained in:
Campbell Barton 2009-12-05 20:45:51 +00:00
parent bca53f0906
commit 651336d5df
7 changed files with 57 additions and 28 deletions

@ -31,17 +31,28 @@ from bpy import ops as _ops_module
# fake operator module
ops = _ops_module.ops_fake_module
import sys
DEBUG = ("-d" in sys.argv)
def load_scripts(reload_scripts=False):
import os
import sys
import traceback
import time
t_main = time.time()
def test_import(module_name):
try:
return __import__(module_name)
t = time.time()
ret= __import__(module_name)
if DEBUG:
print("time %s %.4f" % (module_name, time.time() - t))
return ret
except:
traceback.print_exc()
return None
for base_path in utils.script_paths():
for path_subdir in ("ui", "op", "io"):
@ -62,6 +73,9 @@ def load_scripts(reload_scripts=False):
print("Reloading:", mod)
reload(mod)
if DEBUG:
print("Time %.4f" % (time.time() - t_main))
def _main():
# a bit nasty but this prevents help() and input() from locking blender
@ -70,7 +84,8 @@ def _main():
import sys
sys.stdin = None
if "-d" in sys.argv and False: # Enable this to measure startup speed
# if "-d" in sys.argv: # Enable this to measure startup speed
if 0:
import cProfile
cProfile.run('import bpy; bpy.load_scripts()', 'blender.prof')

@ -47,7 +47,8 @@ def compat_str(text, line_length=0):
text = text.replace('"', '\\"')
return "* " + text
def graph_armature(obj, path, FAKE_PARENT=True, CONSTRAINTS=True, DRIVERS=True):
def graph_armature(obj, path, FAKE_PARENT=True, CONSTRAINTS=True, DRIVERS=True, XTRA_INFO=False):
CONSTRAINTS = DRIVERS = True
file = open(path, "w")
fw = file.write
@ -76,7 +77,7 @@ def graph_armature(obj, path, FAKE_PARENT=True, CONSTRAINTS=True, DRIVERS=True):
label.append("%s = %s" % (key, value))
opts = ["shape=box", "regular=1", "style=filled", 'width="2.33"', 'height="0.35"', "fixedsize=false", 'label="%s"' % compat_str('\n'.join(label))]
opts = ["shape=box", "regular=1", "style=filled", "fixedsize=false", 'label="%s"' % compat_str('\n'.join(label))]
if bone.name.startswith('ORG'):
opts.append("fillcolor=yellow")
@ -123,8 +124,9 @@ def graph_armature(obj, path, FAKE_PARENT=True, CONSTRAINTS=True, DRIVERS=True):
if subtarget:
# TODO, not internal links
opts = ['dir=forward', "weight=1", "arrowhead=normal", "arrowtail=none", "constraint=false", 'color="red"', 'labelfontsize=4']
label = "%s\n%s" % (constraint.type, constraint.name)
opts.append('label="%s"' % compat_str(label))
if XTRA_INFO:
label = "%s\n%s" % (constraint.type, constraint.name)
opts.append('label="%s"' % compat_str(label))
fw('"%s" -> "%s" [%s] ;\n' % (subtarget, pbone.name, ','.join(opts)))
# Drivers
@ -157,8 +159,9 @@ def graph_armature(obj, path, FAKE_PARENT=True, CONSTRAINTS=True, DRIVERS=True):
opts = ['dir=forward', "weight=1", "arrowhead=normal", "arrowtail=none", "constraint=false", 'color="blue"', "labelfontsize=4"] # ,
display_source = rna_path.replace("pose.bones", "")
display_target = rna_path_target.replace("pose.bones", "")
label = "%s\\n%s" % (display_source, display_target)
opts.append('label="%s"' % compat_str(label))
if XTRA_INFO:
label = "%s\\n%s" % (display_source, display_target)
opts.append('label="%s"' % compat_str(label))
fw('"%s" -> "%s" [%s] ;\n' % (pbone_target.name, pbone.name, ','.join(opts)))
fw(footer)

@ -164,7 +164,7 @@ def get_bone_data(obj, bone_name):
def copy_bone_simple(arm, from_bone, name, parent=False):
ebone = arm.edit_bones[from_bone]
ebone_new = arm.edit_bones.new(name)
if parent:
ebone_new.connected = ebone.connected
ebone_new.parent = ebone.parent
@ -429,6 +429,7 @@ def generate_rig(context, obj_orig, prefix="ORG-"):
bone_typeinfo = bone_typeinfos.setdefault(bone_name, [])
type_func = getattr(submod, func_name)
bone_typeinfo.append((submod_name, type_func))

@ -338,10 +338,7 @@ def main(obj, definitions, base_names):
bpy.ops.object.mode_set(mode='EDIT')
# remove the shoulder and re-parent
chain_init()
chain_ik()
chain_switch()
chain_shoulder()

@ -98,7 +98,7 @@ def main(obj, bone_definition, base_names):
# first make a new bone at the location of the finger
#control_ebone = arm.edit_bones.new(base_name)
control_ebone = copy_bone_simple(arm, base_name, base_name)
control_ebone = copy_bone_simple(arm, bone_definition[0], base_name)
control_bone_name = control_ebone.name # we dont know if we get the name requested
control_ebone.connected = orig_ebone.connected

@ -17,7 +17,7 @@
# ##### END GPL LICENSE BLOCK #####
import bpy
from rigify import bone_class_instance, copy_bone_simple, copy_bone_simple_list, add_pole_target_bone, add_stretch_to
from rigify import bone_class_instance, copy_bone_simple, copy_bone_simple_list, add_pole_target_bone, add_stretch_to, blend_bone_list
from rna_prop_ui import rna_idprop_ui_get, rna_idprop_ui_prop_get
METARIG_NAMES = "hips", "thigh", "shin", "foot", "toe", "heel"
@ -249,7 +249,9 @@ def ik(obj, bone_definition, base_names):
else:
con.minimum_x = -180.0 # XXX -deg
con.maximum_x = 0.0
bpy.ops.object.mode_set(mode='EDIT')
return None, ik_chain.thigh, ik_chain.shin, ik_chain.foot, ik_chain.toe, None
@ -323,5 +325,14 @@ def fk(obj, bone_definition, base_names):
mod.coefficients[0] = 1.0
mod.coefficients[1] = -1.0
bpy.ops.object.mode_set(mode='EDIT')
# dont blend the hips or heel
return None, fk_chain.thigh, fk_chain.shin, fk_chain.foot, fk_chain.toe, None
def main(obj, bone_definition, base_names):
bones_ik = ik(obj, bone_definition, base_names)
bones_fk = fk(obj, bone_definition, base_names)
bpy.ops.object.mode_set(mode='OBJECT')
blend_bone_list(obj, bone_definition, bones_ik, bones_fk)

@ -123,10 +123,12 @@ def main(obj, bone_definition, base_names):
mt.ribcage = bone_definition[1]
mt.update()
spine_chain_orig = bone_definition[2:]
spine_chain_orig = tuple(bone_definition[2:])
spine_chain = [arm.edit_bones[child_name] for child_name in spine_chain_orig]
spine_chain_basename = base_names[spine_chain[0].name].rsplit(".", 1) # probably 'ORG-spine.01' -> 'spine'
spine_chain_basename = base_names[spine_chain[0].name].rsplit(".", 1)[0] # probably 'ORG-spine.01' -> 'spine'
spine_chain_len = len(spine_chain_orig)
print(spine_chain_orig)
print(spine_chain_len)
'''
children = mt.ribcage_e.children
@ -180,10 +182,6 @@ def main(obj, bone_definition, base_names):
ex.ribcage_e.translate(Vector(0.0, -ex.ribcage_e.length / 2.0, 0.0))
ex.ribcage_e.parent = mt.ribcage_e
# rename!
for child in spine_chain:
child.name = "ORG-" + child.name
spine_chain = [child.name for child in spine_chain]
# We have 3 spine chains
@ -198,11 +196,11 @@ def main(obj, bone_definition, base_names):
del spine_chain_attrs
for i, child_name in enumerate(spine_chain):
child_name_orig = spine_chain_orig[i]
child_name_orig = base_names[spine_chain_orig[i]]
attr = mt_chain.attr_names[i] # eg. spine_04
setattr(mt_chain, attr, spine_chain[i]) # use the new name
setattr(mt_chain, attr, spine_chain_orig[i]) # the original bone
ebone = copy_bone_simple(arm, child_name, child_name_orig) # use the original name
setattr(ex_chain, attr, ebone.name)
@ -210,7 +208,7 @@ def main(obj, bone_definition, base_names):
ebone = copy_bone_simple(arm, child_name, "MCH-rev_%s" % child_name_orig)
setattr(rv_chain, attr, ebone.name)
ebone.connected = False
mt_chain.update()
ex_chain.update()
rv_chain.update()
@ -284,7 +282,7 @@ def main(obj, bone_definition, base_names):
con.target = obj
con.subtarget = ex.pelvis
con.owner_space = 'LOCAL'
con.target_space = 'LOCAL'
con.target_space = 'LOCAL'
# df.ribcage_p / DEF-wgt_rib_cage
con = df.ribcage_p.constraints.new('COPY_ROTATION')
@ -332,10 +330,14 @@ def main(obj, bone_definition, base_names):
con = ex.pelvis_p.constraints.new('COPY_LOCATION')
con.target = obj
con.subtarget = mt_chain.spine_01
con.owner_space = 'WORLD'
con.target_space = 'WORLD'
con = ex.pelvis_p.constraints.new('COPY_ROTATION')
con.target = obj
con.subtarget = mt_chain.spine_01
con.owner_space = 'WORLD'
con.target_space = 'WORLD'
# ex.ribcage_p / MCH-wgt_rib_cage
con = ex.ribcage_p.constraints.new('COPY_LOCATION')
@ -424,7 +426,7 @@ def main(obj, bone_definition, base_names):
# original bone drivers
# note: the first bone has a lot more constraints, but also this simple one is first.
for i in attr, enumerate(mt_chain.attr_names):
for i, attr in enumerate(mt_chain.attr_names):
spine_p = getattr(mt_chain, attr + "_p")
con = spine_p.constraints.new('COPY_ROTATION')