武器约束


from motionbuilder_pipe.tools.attachment_rigger.ui import attachment_rigger_ui
from motionbuilder_pipe.tools.attachment_rigger import attachment_rigger
reload(attachment_rigger_ui)
reload(attachment_rigger)
attachment_rigger.main()


ik_gun_bone = get_object_by_name('ik_hand_gun')[0]
hand = get_object_by_name('hand_r')[0]
m4 = get_object_by_name('root', namespace='Prop')[0]
m9 = get_object_by_name('root', namespace='Prop 1')[0]
hand_control = get_object_by_name('RightWristEffector', namespace='Character_Ctrl')[0]


ctrls = [hand, m4, m9]
create_ik_constraint()
x = create_constraint(ik_gun_bone, ctrls, hand_control)


 
# 选择IK
def GetGroupedObjects(groupName=str):
    for comp in FBSystem().Scene.Components:
        comp.Selected = False
    for group in FBSystem().Scene.Groups:
        if groupName == group.Name:
            for n in range(group.GetSrcCount()):
                group.GetSrc(n).Selected = True

GetGroupedObjects("SK_Export")
from pyfbsdk import FBConstraintRelation, FBModelMarker, FBConnect

# Define a utility function to look up a named animation node
# under a given parent. Will not recurse in the hierarchy.
def FindAnimationNode( pParent, pName ):
    lResult = None
    for lNode in pParent.Nodes:
        if lNode.Name == pName:
            lResult = lNode
            break
    return lResult

# Create a constraint relation. No need to use the FBConstraintManager.
lConstraintRelation = FBConstraintRelation( 'AConstraintRelation' )

# Create an object which will be constrained in the relation.
lModel = FBModelMarker( 'AModelMarker' )
lModel.Translation.SetAnimated(True)
lModel.Visible = True

# Create a source and place it in 2D space.
lSineRampBox = lConstraintRelation.CreateFunctionBox( 'Sources', 'Sine Ramp' )
lConstraintRelation.SetBoxPosition( lSineRampBox, 30, 30 )

# Create a converter.
lNumberToVectorBox = lConstraintRelation.CreateFunctionBox( 'Converters', 'Number to Vector' )
lConstraintRelation.SetBoxPosition( lNumberToVectorBox, 400, 30 )

# Now insert the marker in the constraint. Set its position.
lPlaceHolderBox = lConstraintRelation.ConstrainObject( lModel )
lConstraintRelation.SetBoxPosition(lPlaceHolderBox, 700, 30)

# In order to set up the constraint, we need to connect the boxe's
# animation node together.

# We will connect the sine ramp to the converter.
lSineRampOut       = FindAnimationNode( lSineRampBox.AnimationNodeOutGet(), 'Result' )
lNumberToVectorIn  = FindAnimationNode( lNumberToVectorBox.AnimationNodeInGet(), 'Y' )
if lSineRampOut and lNumberToVectorIn:
    FBConnect( lSineRampOut, lNumberToVectorIn )

# And connect the converter to the translation of the marker.
lNumberToVectorOut = FindAnimationNode( lNumberToVectorBox.AnimationNodeOutGet(), 'Result' )
lModelIn           = FindAnimationNode( lPlaceHolderBox.AnimationNodeInGet(), 'Translation' )
if lNumberToVectorOut and lModelIn:
    FBConnect( lNumberToVectorOut, lModelIn )

# Finally activate the constraint.
lConstraintRelation.Active = True 

# 创建自定义属性
ik_gun = get_object_by_name('ik_hand_gun')[0]
hand = get_object_by_name('hand_r')[0]
m4 = get_object_by_name('root', namespace='Prop')[0]
m9 = get_object_by_name('root', namespace='Prop 1')[0]
hand_control = get_object_by_name('RightWristEffector', namespace='Character_Ctrl')[0]
gun_constraint = create_parent_constraint('IK_Hd_2_gun', [hand, m4, m9], ik_gun)
gun_constraint.Lock = True

all_control_name = ['hand']
for i in [m4, m9]:
    parent_name = [p.Name for p in i.Parents if type(p) is FBModelNull][0]
    all_control_name.append(parent_name)
    
all_user_property = ['weight', 'IK_Match']
for control_name in all_control_name:
    all_user_property.append(control_name + '_index')
for user_property in all_user_property:
    _property = hand_control.PropertyList.Find(user_property)
    if _property:
        hand_control.PropertyRemove(_property)
    

prop = hand_control.PropertyCreate('IK_Match', FBPropertyType.kFBPT_enum, 'Enum', True, True, None) 
enum_list = prop.GetEnumStringList(True)
for i in all_control_name:
    enum_list.Add(i)
prop.NotifyEnumStringListChanged()

for i, control_name in enumerate(all_control_name):
    property_name = control_name + '_index'
    prop = hand_control.PropertyCreate(property_name, FBPropertyType.kFBPT_int, 'Integer', True, True, None) 
    prop.Data = i
    
prop = hand_control.PropertyCreate('weight', FBPropertyType.kFBPT_int, 'Integer', True, True, None) 
prop.Data = 100

评论
  目录