Esempio n. 1
0
def test_link_solver():
    _new()
    cube1, _ = cmds.polyCube(height=1)
    cmds.move(0, 5, 0)
    cube2, _ = cmds.polyCube(height=1)
    cmds.move(0, 10, 0)

    solver1 = api.createSolver()
    solver2 = api.createSolver()
    api.createGround(solver1)
    api.createGround(solver2)

    api.assignMarker(cube1, solver1)
    api.assignMarker(cube2, solver2)

    api.linkSolver(solver1, solver2)

    api.recordPhysics(solver2, opts={"startTime": 1, "endTime": 20})

    # box2 is now stacked on top of box1
    cube2 = cmdx.encode(cube2)

    # The center of the cube on top of the other cube
    # both of which are 1 unit high.
    #   ____
    #  /   /|
    # /___/ | <--- 1.5 units
    # |   | /
    # |___|/|
    # |   | /
    # |___|/
    #
    assert_almost_equals(cmds.getAttr("pCube2.ty", time=20), 1.5, 1)
Esempio n. 2
0
def test_retarget():
    _new()
    solver = api.createSolver()
    joint1 = cmds.joint()
    cmds.move(0, 5, 0)
    joint2 = cmds.joint()
    cmds.move(5, 5, 0)
    cmds.joint()  # tip
    cmds.move(10, 5, 0)
    markers = api.assignMarkers([joint1, joint2], solver)

    # Retarget to this box
    box, _ = cmds.polyCube()
    api.retargetMarker(markers[1], box)

    # The box should now get recorded, not the joint
    cmdx.min_time(1)
    cmdx.max_time(50)
    api.recordPhysics(solver)

    joint2 = cmdx.encode(joint2)
    box = cmdx.encode(box)

    assert not joint2["tx"].input(), "%s was connected" % joint2["tx"].path()
    assert box["tx"].input(), "%s was not connected" % box["tx"].path()
Esempio n. 3
0
def test_animated_controls():
    # Existing animation should be kept and ignored,
    # new animation ending up on a layer

    _new()
    joint1 = cmds.joint()
    cmds.move(0, 5, 0)
    joint2 = cmds.joint()
    cmds.move(5, 5, 0)
    joint3 = cmds.joint()  # tip
    cmds.move(10, 5, 0)

    joint = cmdx.encode(joint2)
    joint["rz"] = {1: 0.0, 10: 1.0, 20: 0.0}  # Some animation

    solver = api.createSolver()
    api.assignMarkers([joint1, joint2, joint3], solver)

    cmdx.min_time(1)
    cmdx.max_time(15)
    api.recordPhysics(solver)

    # It must have changed by now
    value = joint["rz"].read(time=cmdx.time(10))
    assert_not_equals("%.1f" % value, "1.0")

    # Deleting the animation layer restores the original animation
    cmds.delete(cmds.ls(type="container"))

    value = joint["rz"].read(time=cmdx.time(10))
    assert_equals("%.1f" % value, "1.0")
Esempio n. 4
0
def test_record_constrained_controls():
    # Existing constraints should be preserved

    _new()
    joint1 = cmds.joint()
    cmds.move(0, 5, 0)
    joint2 = cmds.joint()
    cmds.move(5, 5, 0)
    joint3 = cmds.joint()  # tip
    cmds.move(10, 5, 0)

    ctrl = cmds.createNode("transform", name="control")
    con = cmds.parentConstraint(ctrl, joint1)[0]

    # o---o---o
    # 1   2   3

    solver = api.createSolver()
    api.assignMarkers([joint1, joint2, joint3], solver)

    cmdx.min_time(1)
    cmdx.max_time(5)  # Won't need many frames
    api.recordPhysics(solver)

    # The joint was kinematic, and is still connected
    joint1 = cmdx.encode(joint1)
    con = cmdx.encode(con)
    assert_equals(joint1["tx"].input(type="parentConstraint"), con)
Esempio n. 5
0
def test_record_ik():
    # Recording IK involves retargeting and untargeting

    _new()
    joint1 = cmds.joint()
    cmds.move(0, 5, 0)
    joint2 = cmds.joint()
    cmds.move(5, 5, 0)
    joint3 = cmds.joint()  # tip
    cmds.move(10, 5, 0)

    handle, eff = cmds.ikHandle(joint1, joint2)
    pole = cmds.spaceLocator()[0]
    cmds.poleVectorConstraint(pole, handle)[0]

    # o---o---o
    # 1   2   3

    solver = api.createSolver()
    markers = api.assignMarkers([joint1, joint2, joint3], solver)
    api.untarget_marker(markers[0])
    api.retarget_marker(markers[1], pole)
    api.retarget_marker(markers[2], handle)

    cmdx.min_time(1)
    cmdx.max_time(5)  # Won't need many frames
    api.recordPhysics(solver)

    joint1 = cmdx.encode(joint1)
    joint2 = cmdx.encode(joint2)
    handle = cmdx.encode(handle)

    assert not joint1["tx"].connected, "%s was connected" % joint1["tx"].path()
    assert not joint2["tx"].connected, "%s was connected" % joint2["tx"].path()
    assert handle["tx"].connected, "%s was not connected" % handle["tx"].path()
Esempio n. 6
0
def test_record_100():
    # Non-commercial users can only record up to 100 frames
    _new()
    solver = api.createSolver()
    cube1, _ = cmds.polyCube()
    api.assignMarker(cube1, solver)

    # The cube will fall and fall, long past 100 frames
    cmdx.min_time(0)
    cmdx.max_time(120)
    api.recordPhysics(solver)

    value_at_100 = cmds.getAttr(cube1 + ".ty", time=100)
    value_at_110 = cmds.getAttr(cube1 + ".ty", time=110)

    # It'll have fallen far beyond minus 10
    assert_less(value_at_100, -10)

    if is_commercial:
        # Since we're able to record past 100 frames, the box will
        # have kept falling further than frame 100
        commercial = 0
        assert_less(value_at_110, value_at_100 + commercial)
    else:
        # Since recording stops at 100, any frame after that will be the same
        non_commercial = 0
        assert_equals(value_at_110, value_at_100 + non_commercial)
Esempio n. 7
0
def test_record_nokinematic():
    _new()
    solver = api.createSolver()
    cube1, _ = cmds.polyCube()
    marker = api.assignMarker(cube1, solver)
    cmds.setAttr(marker + ".inputType", api.InputKinematic)
    api.recordPhysics(solver, opts={"includeKinematic": False})

    cube1 = cmdx.encode(cube1)
    assert not cube1["tx"].connected, (
        "%s was kinematic, it should not have been recorded" %
        cube1["tx"].path())
Esempio n. 8
0
def test_unlink_solver():
    test_link_solver()

    solver1 = "rSolverShape"
    solver2 = "rSolverShape1"

    api.unlinkSolver(solver1)

    # Delete old record
    cmds.delete(cmds.ls(type="container"))

    # The box should now intersect the other, landing at ty=0.5
    api.recordPhysics(solver2, opts={"startTime": 1, "endTime": 20})

    # box2 is no longer stacked on top of box1
    assert_almost_equals(cmds.getAttr("pCube2.ty", time=20), 0.5, 1)
Esempio n. 9
0
def test_assign_group():
    _new()
    solver = api.createSolver()
    joint1 = cmds.joint()
    cmds.move(0, 5, 0)
    joint2 = cmds.joint()
    cmds.move(5, 5, 0)
    cmds.joint()  # tip
    cmds.move(10, 5, 0)
    markers = api.assignMarkers([joint1, joint2], solver)

    # Check the results
    marker = cmdx.encode(markers[0])
    group = marker["startState"].output(type="rdGroup")
    group["driveStiffness"] = 0.001
    cmdx.min_time(1)
    cmdx.max_time(50)
    api.recordPhysics(solver)

    joint2 = cmdx.encode(joint2)
    assert_almost_equals(joint2["rz", cmdx.Degrees].read(time=cmdx.time(50)),
                         -32, 0)