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
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)
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
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)
def RelationConstrain(name=None): constraint = FBConstraintManager().TypeCreateConstraint("Relation") if name: constraint.Name = name return constraint