Пример #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)
Пример #2
0
def test_record_options():
    _new()
    solver = api.createSolver()
    cube1, _ = cmds.polyCube()
    cmds.move(0, 100)

    cmds.setAttr(solver + ".startTime", api.StartTimeCustom)
    cmds.setAttr(solver + ".startTimeCustom", 10)
    api.assignMarker(cube1, solver)

    start = cmdx.time(10)
    end = cmdx.time(15)
    api.record_physics(solver,
                       opts={
                           "startTime": start,
                           "endTime": end,
                           "toLayer": False,
                       })

    # Should still be at a Y-value of 100 here
    cube1 = cmdx.encode(cube1)
    assert cube1["ty"].read(time=start) > 99, ("%s was not 100" %
                                               cube1["ty"].read(time=start))

    assert cube1["ty"].read(time=end) < 99, (
        "Should have fallen more than %s" % cube1["ty"].read(time=end))

    # Not baking to a layer
    curve_type = "animCurveTL"
    assert cube1["ty"].input().isA(curve_type), (
        "%s.%s should have been an '%s'" %
        (cube1["ty"].input(), cube1["ty"].input().type_name, curve_type))
Пример #3
0
def test_delete_physics():
    _new()
    solver = api.createSolver()
    cube1, _ = cmds.polyCube()
    api.assignMarker(cube1, solver)
    api.deletePhysics([cube1])
    assert not cmds.ls(type="rdMarker"), cmds.ls(type="rdMarker")
Пример #4
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)
Пример #5
0
def test_basics():
    _new()
    solver = api.createSolver()
    cube1, _ = cmds.polyCube()
    cube2, _ = cmds.polyCube()
    marker1 = api.assignMarker(cube1, solver)
    marker2 = api.assignMarker(cube2, solver)
    api.createDistanceConstraint(marker1, marker2)
Пример #6
0
def test_delete_all_physics():
    _new()
    solver1 = api.createSolver()
    solver2 = api.createSolver()
    cube1, _ = cmds.polyCube()
    cube2, _ = cmds.polyCube()
    api.assignMarker(cube1, solver1)
    api.assignMarker(cube2, solver2)
    api.deleteAllPhysics()
    assert not cmds.ls(type="rdSolver"), cmds.ls(type="rdSolver")
Пример #7
0
def test_record():
    _new()
    solver = api.createSolver()
    cube1, _ = cmds.polyCube()
    api.assignMarker(cube1, solver)
    api.record_physics(solver)

    cube1 = cmdx.encode(cube1)
    assert cube1["tx"].connected, ("%s should have been recorded" %
                                   cube1["tx"].path())

    # Baking to layer per default, which means the curve type is
    curve_type = "animBlendNodeAdditiveDL"
    assert cube1["tx"].input().isA(curve_type), (
        "%s.%s should have been an '%s'" %
        (cube1["tx"].input(), cube1["tx"].input().type_name, curve_type))
Пример #8
0
def test_attribute_set():
    # Attributes are set like any other Maya node with cmds

    _new()
    solver = api.createSolver()
    cube1, _ = cmds.polyCube()
    marker1 = api.assignMarker(cube1, solver)

    cmds.setAttr(solver + ".gravityY", -982)
    cmds.setAttr(marker1 + ".shapeType", api.SphereShape)
Пример #9
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())
Пример #10
0
def test_export_10():
    # The user can only ever export 10 markers from a Personal licence
    _new()
    solver = api.createSolver()

    for cube in range(15):
        cube1, _ = cmds.polyCube()
        api.assignMarker(cube1, solver)

    # Only 1 markers will be exported
    data = api.exportPhysics()
    registry = dump.Registry(data)

    print("Entities:")
    for entity in registry.view("MarkerUIComponent"):
        print("  - %s" % registry.get(entity, "NameComponent")["value"])

    if is_unlimited:
        assert_equals(registry.count("MarkerUIComponent"), 15)
    else:
        assert_equals(registry.count("MarkerUIComponent"), 10)
Пример #11
0
def test_marker_options():
    _new()
    solver = api.createSolver()
    cube1, _ = cmds.polyCube()
    marker1 = api.assignMarker(cube1,
                               solver,
                               opts={
                                   "density": api.DensityWood,
                               })

    marker1 = cmdx.encode(marker1)
    assert marker1["densityType"] == api.DensityWood, (
        "Density '%d' should have been '%d'" %
        (marker1["densityType"], api.DensityWood))