예제 #1
0
 def setDefaults(self):
     self.target = "ERROR"
     self.shape = "box"
     self.boxsize = vs.Vector(0, 0, 0)
     self.boxcenter = vs.Vector(0, 0, 0)
     self.margin = 0.04
     self.bounce = 0.25
     self.friction = 0.9
     self.mass = 1
     self.lindamp = 0.05
     self.rotdamp = 0.1
예제 #2
0
def SetTransformAtTime(dag, time, transform):
	pos = vs.Vector()
	quat = vs.Quaternion()
	vs.MatrixPosition(transform, pos)
	vs.MatrixQuaternion(transform, quat)
	SetValueAtTime(dag.FindTransformControl().GetPositionChannel(), time, pos)
	SetValueAtTime(dag.FindTransformControl().GetOrientationChannel(), time, quat)
예제 #3
0
def TransformToPosQuat(transform):
	pos = vs.Vector()
	quat = vs.Quaternion()
	vs.MatrixPosition(transform, pos)
	vs.MatrixQuaternion(transform, quat)

	return pos, quat
예제 #4
0
def ComputeVectorBetweenBones(boneA, boneB, scaleFactor):

    vPosA = vs.Vector(0, 0, 0)
    boneA.GetAbsPosition(vPosA)

    vPosB = vs.Vector(0, 0, 0)
    boneB.GetAbsPosition(vPosB)

    vDir = vs.Vector(0, 0, 0)
    vs.mathlib.VectorSubtract(vPosB, vPosA, vDir)
    vDir.NormalizeInPlace()

    vScaledDir = vs.Vector(0, 0, 0)
    vs.mathlib.VectorScale(vDir, scaleFactor, vScaledDir)

    return vScaledDir
예제 #5
0
def TransformToPosEuler(transform):
	pos = vs.Vector()
	quat = vs.Quaternion()
	vs.MatrixPosition(transform, pos)
	vs.MatrixQuaternion(transform, quat)

	euler = vs.RadianEuler()
	vs.QuaternionAngles(quat, euler)

	return pos, euler
예제 #6
0
def listToVector(tup):
    return vs.Vector(tup[0], tup[1], tup[2])
예제 #7
0
    def testFusionIMU(self):
        acc = vs.Vector(0, 0, 1)
        gyr = vs.Vector(0, 0, 0)
        fusionIMU = vs.FusionIMU()
        q = fusionIMU.init(acc, 0)
        qTarget = vs.Quat(1., 0, 0, 0)
        self.checkAlmostEqualQuaternions(q, qTarget)

        angle = math.pi / 3

        acc = vs.Vector(0, math.sin(angle), math.cos(angle))
        q = fusionIMU.init(acc, 0)
        qTarget = vs.Quat(math.cos(angle / 2.), math.sin(angle / 2.), 0, 0)
        self.checkAlmostEqualQuaternions(q, qTarget)

        acc = vs.Vector(0, -math.sin(angle), math.cos(angle))
        q = fusionIMU.init(acc, 0)
        qTarget = vs.Quat(math.cos(angle / 2.), -math.sin(angle / 2.), 0, 0)
        self.checkAlmostEqualQuaternions(q, qTarget)

        acc = vs.Vector(math.sin(angle), 0, math.cos(angle))
        q = fusionIMU.init(acc, 0)
        qTarget = vs.Quat(math.cos(angle / 2.), 0, -math.sin(angle / 2.), 0)
        self.checkAlmostEqualQuaternions(q, qTarget)

        acc = vs.Vector(-math.sin(angle), 0, math.cos(angle))
        q = fusionIMU.init(acc, 0)
        qTarget = vs.Quat(math.cos(angle / 2.), 0, math.sin(angle / 2.), 0)
        self.checkAlmostEqualQuaternions(q, qTarget)

        # use accelerometer only
        fusionIMU.setFusionFactor(1)  # discard gyroscope during fusion
        acc = vs.Vector(0, 0, 1)
        q = fusionIMU.init(acc, 1000000)
        qTarget = vs.Quat(1, 0, 0, 0)
        self.checkAlmostEqualQuaternions(q, qTarget)

        acc = vs.Vector(0, math.sin(angle), math.cos(angle))
        gyr = vs.Vector(1, 1, 1)
        q = fusionIMU.update(gyr, acc, 2000000)
        qTarget = vs.Quat(math.cos(angle / 2.), math.sin(angle / 2.), 0, 0)
        self.checkAlmostEqualQuaternions(q, qTarget)

        # use gyroscope only
        fusionIMU.setFusionFactor(0)  # discard accelerometer during fusion
        acc = vs.Vector(0, 0, 1)
        q = fusionIMU.init(acc, 1000000)
        qTarget = vs.Quat(1, 0, 0, 0)
        self.checkAlmostEqualQuaternions(q, qTarget)

        acc = vs.Vector(0, 0, 1)
        gyr = vs.Vector(angle, 0, 0)
        q = fusionIMU.update(gyr, acc,
                             1033333)  # integrate only during 1/30 of a second
        qTarget = vs.Quat(math.cos(angle / (2. * 30.)),
                          math.sin(angle / (2. * 30.)), 0, 0)
        self.checkAlmostEqualQuaternions(q, qTarget)
예제 #8
0
def CreateReverseFoot(controlName, sideName, gameModel, animSet, shot,
                      helperControlGroup, footControlGroup):

    # Cannot create foot controls without heel position, so check for that first
    heelAttachName = "pvt_heel_" + sideName
    if (gameModel.FindAttachment(heelAttachName) == 0):
        print "Could not create foot control " + controlName + ", model is missing heel attachment point: " + heelAttachName
        return None

    footRollDefault = 0.5
    rotationAxis = vs.Vector(0, 0, 1)

    # Construct the name of the dag nodes of the foot and toe for the specified side
    footName = "rig_foot_" + sideName
    toeName = "rig_toe_" + sideName

    # Get the world space position and orientation of the foot and toe
    footPos = sfm.GetPosition(footName)
    footRot = sfm.GetRotation(footName)
    toePos = sfm.GetPosition(toeName)

    # Setup the reverse foot hierarchy such that the foot is the parent of all the foot transforms, the
    # reverse heel is the parent of the heel, so it can be used for rotations around the ball of the
    # foot that will move the heel, the heel is the parent of the foot IK handle so that it can perform
    # rotations around the heel and move the foot IK handle, resulting in moving all the foot bones.
    # root
    #   + rig_foot_R
    #       + rig_knee_R
    #       + rig_reverseHeel_R
    #           + rig_heel_R
    #               + rig_footIK_R

    # Construct the reverse heel joint this will be used to rotate the heel around the toe, and as
    # such is positioned at the toe, but using the rotation of the foot which will be its parent,
    # so that it has no local rotation once parented to the foot.
    reverseHeelName = "rig_reverseHeel_" + sideName
    reverseHeelDag = sfm.CreateRigHandle(reverseHeelName,
                                         pos=toePos,
                                         rot=footRot,
                                         rotControl=False)
    sfmUtils.Parent(reverseHeelName, footName, vs.REPARENT_LOGS_OVERWRITE)

    # Construct the heel joint, this will be used to rotate the foot around the back of the heel so it
    # is created at the heel location (offset from the foot) and also given the rotation of its parent.
    heelName = "rig_heel_" + sideName
    vecHeelPos = gameModel.ComputeAttachmentPosition(heelAttachName)
    heelPos = [vecHeelPos.x, vecHeelPos.y, vecHeelPos.z]
    heelRot = sfm.GetRotation(reverseHeelName)
    heelDag = sfm.CreateRigHandle(heelName,
                                  pos=heelPos,
                                  rot=heelRot,
                                  posControl=True,
                                  rotControl=False)
    sfmUtils.Parent(heelName, reverseHeelName, vs.REPARENT_LOGS_OVERWRITE)

    # Create the ik handle which will be used as the target for the ik chain for the leg
    ikHandleName = "rig_footIK_" + sideName
    ikHandleDag = sfmUtils.CreateHandleAt(ikHandleName, footName)
    sfmUtils.Parent(ikHandleName, heelName, vs.REPARENT_LOGS_OVERWRITE)

    # Create an orient constraint which causes the toe's orientation to match the foot's orientation
    footRollControlName = controlName + "_" + sideName
    toeOrientTarget = sfm.OrientConstraint(footName,
                                           toeName,
                                           mo=True,
                                           controls=False)
    footRollControl, footRollValue = sfmUtils.CreateControlledValue(
        footRollControlName, "value", vs.AT_FLOAT, footRollDefault, animSet,
        shot)

    # Create the expressions to re-map the footroll slider value for use in the constraint and rotation operators
    toeOrientExprName = "expr_toeOrientEnable_" + sideName
    toeOrientExpr = sfmUtils.CreateExpression(
        toeOrientExprName, "inrange( footRoll, 0.5001, 1.0 )", animSet)
    toeOrientExpr.SetValue("footRoll", footRollDefault)

    toeRotateExprName = "expr_toeRotation_" + sideName
    toeRotateExpr = sfmUtils.CreateExpression(
        toeRotateExprName, "max( 0, (footRoll - 0.5) ) * 140", animSet)
    toeRotateExpr.SetValue("footRoll", footRollDefault)

    heelRotateExprName = "expr_heelRotation_" + sideName
    heelRotateExpr = sfmUtils.CreateExpression(
        heelRotateExprName, "max( 0, (0.5 - footRoll) ) * -100", animSet)
    heelRotateExpr.SetValue("footRoll", footRollDefault)

    # Create a connection from the footroll value to all of the expressions that require it
    footRollConnName = "conn_footRoll_" + sideName
    footRollConn = sfmUtils.CreateConnection(footRollConnName, footRollValue,
                                             "value", animSet)
    footRollConn.AddOutput(toeOrientExpr, "footRoll")
    footRollConn.AddOutput(toeRotateExpr, "footRoll")
    footRollConn.AddOutput(heelRotateExpr, "footRoll")

    # Create the connection from the toe orientation enable expression to the target weight of the
    # toe orientation constraint, this will turn the constraint on an off based on the footRoll value
    toeOrientConnName = "conn_toeOrientExpr_" + sideName
    toeOrientConn = sfmUtils.CreateConnection(toeOrientConnName, toeOrientExpr,
                                              "result", animSet)
    toeOrientConn.AddOutput(toeOrientTarget, "targetWeight")

    # Create a rotation constraint to drive the toe rotation and connect its input to the
    # toe rotation expression and connect its output to the reverse heel dag's orientation
    toeRotateConstraintName = "rotationConstraint_toe_" + sideName
    toeRotateConstraint = sfmUtils.CreateRotationConstraint(
        toeRotateConstraintName, rotationAxis, reverseHeelDag, animSet)

    toeRotateExprConnName = "conn_toeRotateExpr_" + sideName
    toeRotateExprConn = sfmUtils.CreateConnection(toeRotateExprConnName,
                                                  toeRotateExpr, "result",
                                                  animSet)
    toeRotateExprConn.AddOutput(toeRotateConstraint, "rotations", 0)

    # Create a rotation constraint to drive the heel rotation and connect its input to the
    # heel rotation expression and connect its output to the heel dag's orientation
    heelRotateConstraintName = "rotationConstraint_heel_" + sideName
    heelRotateConstraint = sfmUtils.CreateRotationConstraint(
        heelRotateConstraintName, rotationAxis, heelDag, animSet)

    heelRotateExprConnName = "conn_heelRotateExpr_" + sideName
    heelRotateExprConn = sfmUtils.CreateConnection(heelRotateExprConnName,
                                                   heelRotateExpr, "result",
                                                   animSet)
    heelRotateExprConn.AddOutput(heelRotateConstraint, "rotations", 0)

    if (helperControlGroup != None):
        sfmUtils.AddDagControlsToGroup(helperControlGroup, reverseHeelDag,
                                       ikHandleDag, heelDag)

    if (footControlGroup != None):
        footControlGroup.AddControl(footRollControl)

    return ikHandleDag
예제 #9
0
 def as_vsVector(self):
     return vs.Vector(*self)
예제 #10
0
def btToVsVector(vec):
    return vs.Vector(vec.x() * unitsPerMeter,
                     vec.y() * unitsPerMeter,
                     vec.z() * unitsPerMeter)
예제 #11
0
# Test getting the position and rotatation of a dag
cubePos = animUtils.GetDagPosition(DagList(cubeDag), vs.TS_WORLD_SPACE)
cubeRot = animUtils.GetDagRotation(DagList(cubeDag), vs.TS_WORLD_SPACE)
print cubePos
print cubeRot

# Create a test dag
testDag = animUtils.CreateDag("testDag", vs.vec3_origin, vs.quat_identity)
print testDag

# Test creating a dag list with multiple dag nodes
dagList = vs.DagList(cubeDag, sphereDag, testDag)

# Move the test dag
animUtils.TransformDagNodes(vs.Vector(5, 5, 5), vs.quat_identity,
                            DagList(testDag), False,
                            vs.dmeutils.TS_WORLD_SPACE)
testPos = animUtils.GetDagPosition(DagList(testDag), vs.TS_WORLD_SPACE)
print testPos

# Constrain the test dag, this should overwrite the position of the test dag
testConstraint = animUtils.CreatePointConstraint("testConstraint", testDag,
                                                 DagList(cubeDag), False, 1.0)
print testConstraint

testPos = animUtils.GetDagPosition(DagList(testDag), vs.TS_WORLD_SPACE)
print testPos

# Generate log samples for the test dag evaluating the constraint
animUtils.GenerateLogSamples(testDag, None, True, True)