コード例 #1
0
ファイル: MobuCoreLibrary.py プロジェクト: rmxonline/MobuCore
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
コード例 #2
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)
コード例 #3
0
ファイル: MobuCoreLibrary.py プロジェクト: rmxonline/MobuCore
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
コード例 #4
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)
コード例 #5
0
ファイル: MobuCoreLibrary.py プロジェクト: rmxonline/MobuCore
def RelationConstrain(name=None):
    constraint = FBConstraintManager().TypeCreateConstraint("Relation")
    if name:
        constraint.Name = name
    return constraint