def CreateConstraint(_type, name=None):
    """
    Create a constraint with the given type and optionally with a name
    @param _type: name of constraint type found in kConstraintTypes
    @param name: name to give constraint. Default is used if None 
    """
    try:
        constraint = FBConstraintManager().TypeCreateConstraint(kConstraintTypes[_type])
    except KeyError:
        raise Exception("Invalid constraint type '%s'" % _type)

    FBSystem().Scene.Constraints.append(constraint)

    if name:
        constraint.Name = name

    return ConvertToPMBConstraint(constraint)
Esempio n. 2
0
def GenericConstraint(constraintType,
                      parent,
                      child,
                      active=True,
                      snap=False,
                      zero=True):
    constraint = FBConstraintManager().TypeCreateConstraint(constraintType)
    if not isinstance(parent, list) and not isinstance(
            parent, FBPropertyListComponent):
        parent = [parent]
    constraint.Name = constraintType + "_" + child.Name + "_to_" + parent[
        0].Name
    if constraintType == "Parent/Child":
        SetConstraintReference(constraint, child, "Constrained object (Child)")
    else:
        SetConstraintReference(constraint, child, "Constrained Object")
    for obj in parent:
        if constraintType == "Parent/Child":
            SetConstraintReference(constraint, obj, "Source (Parent)")
        else:
            SetConstraintReference(constraint, obj, "Source")
    if snap:
        constraint.snap()
    if zero:
        if constraintType == "Position" or constraintType == "Parent/Child":
            SetGlobalRotation(child, GetGlobalRotation(parent[0]))
        if constraintType == "Rotation" or constraintType == "Parent/Child":
            SetGlobalRotation(child, GetGlobalRotation(parent[0]))
    constraint.Active = active
    constraint.Lock = True
    return constraint
Esempio n. 3
0
def CreateConstraint(_type, name=None):
    '''
    Create a constraint with the given type and optionally with a name
    @param _type: name of constraint type found in kConstraintTypes
    @param name: name to give constraint. Default is used if None 
    '''
    try:
        constraint = FBConstraintManager().TypeCreateConstraint(
            kConstraintTypes[_type])
    except KeyError:
        raise Exception("Invalid constraint type '%s'" % _type)

    FBSystem().Scene.Constraints.append(constraint)

    if name:
        constraint.Name = name

    return ConvertToPMBConstraint(constraint)
Esempio n. 4
0
def AimConstrain(constrainedObject,
                 aimAtObject,
                 worldUpObject=None,
                 active=True,
                 snap=False):
    constraint = FBConstraintManager().TypeCreateConstraint("Aim")
    constraint.Name = "Aim_" + constrainedObject.Name + "_to_" + aimAtObject.Name
    SetConstraintReference(constraint, constrainedObject, "Constrained Object")
    SetConstraintReference(constraint, aimAtObject, "Aim At Object")
    if worldUpObject:
        SetConstraintReference(constraint, worldUpObject, "World Up Object")
    if snap:
        constraint.snap()
    else:
        constraint.Active = active
    constraint.Lock = True
    return constraint
Esempio n. 5
0
Individual constraint classes and related functions

You can instantiate a PyMoBu constraint passing a MotionBuilder
constraint into one of the specific constraint classes.

You can also create a specific constraint through either the class's
'Create' method or through the CreateConstraint function.
'''
from pyfbsdk import FBConstraintManager  #@UnresolvedImport
from pyfbsdk import FBSystem  #@UnresolvedImport
from pyfbsdk import FBConstraint  #@UnresolvedImport

from pymobu.components import PMBBox

# create a dictionary of constraint name / indices
kConstraintTypes = dict((FBConstraintManager().TypeGetName(i), i)
                        for i in xrange(FBConstraintManager().TypeGetCount()))


# -----------------------------------------------------
# Constraint Utility Functions
# -----------------------------------------------------
def GetConstraintByName(name, includeNamespace=True):
    '''Returns a constraint that matches it's long name'''
    for const in FBSystem().Scene.Constraints:
        if includeNamespace:
            constraintName = const.LongName
        else:
            constraintName = const.Name
        if name == constraintName:
            return ConvertToPMBConstraint(const)
lSelected = getSelectedOrder()
# for i in range(len(lSelected)): print "%d: %s" % ( i, lSelected[i].Name )

result = []
for i in lSelected:
    # test_print
    # print i.Name

    # ヌルの生成
    pSrcObj = FBModelNull("SourceNull")
    pSrcObj.Show = True

    result.append(pSrcObj)

    # コンストレイント
    CM = FBConstraintManager()
    c = CM.TypeCreateConstraint(3)
    # コンストイント内名前検索
    PropertyName = "Source (Parent)"

    # models = FBModelList()
    # FBGetSelectedModels(models)
    # つまり i

    # コンストレイント処理
    c.PropertyList.Find(PropertyName).append(i)
    c.ReferenceAdd(0, pSrcObj)

    c.Active = True
    c.Lock = True
Esempio n. 7
0
def RelationConstrain(name=None):
    constraint = FBConstraintManager().TypeCreateConstraint("Relation")
    if name:
        constraint.Name = name
    return constraint