Exemplo n.º 1
0
def test_non_uniform_scale():
    _new()

    with cmdx.DagModifier() as mod:
        a = mod.create_node("transform", name="a")
        b = mod.create_node("transform", name="b", parent=a)
        c = mod.create_node("transform", name="c", parent=b)

        mod.set_attr(a["scale"], 2.0)
        mod.set_attr(a["ty"], 3.0)
        mod.set_attr(b["tx"], 1.0)
        mod.set_attr(b["scaleX"], 2.0)
        mod.set_attr(c["tx"], 1.0)

    cmds.select(str(a), str(b), str(c))
    ri.assign_group()

    solver = cmdx.ls(type="rdSolver")[0]
    solver["gravity"] = 0

    ri.record_markers()

    assert_almost_equals(a["ty"].read(), 3.0, 4)
    assert_almost_equals(b["tx"].read(), 1.0, 4)
    assert_almost_equals(b["ty"].read(), 0.0, 4)
    assert_almost_equals(c["tx"].read(), 1.0, 4)
    assert_almost_equals(c["ty"].read(), 0.0, 4)

    # Because C is a child of B that has been scaled,
    # it would be further along X than its local sum
    c_tm = c["worldMatrix"][0].as_matrix()
    c_tm = cmdx.Tm(c_tm)
    c_pos = c_tm.translation()
    assert_almost_equals(c_pos.x, 6.0, 4)
Exemplo n.º 2
0
def test_rotate_pivot():
    _new()

    with cmdx.DagModifier() as mod:
        a = mod.create_node("transform", name="a")
        b = mod.create_node("transform", name="b", parent=a)
        c = mod.create_node("transform", name="c", parent=b)

        mod.set_attr(a["ty"], 3.0)
        mod.set_attr(b["tx"], 1.0)
        mod.set_attr(c["tx"], 1.0)

    cmds.select(str(a), str(b), str(c))
    ri.assign_group()

    # Give them some droop
    group = cmdx.ls(type="rdGroup")[0]
    group["driveStiffness"] = 0.01

    cmdx.max_time(100)
    ri.record_markers()

    # We've got a dick-like shape
    #
    # a
    # .----. b
    #       \
    #        . c
    #        |
    #        |
    #
    assert_almost_equals(b["rz"].read(time=cmdx.max_time()),
                         cmdx.radians(-50.0), 1)
Exemplo n.º 3
0
def test_rotate_axis():
    _new()

    with cmdx.DagModifier() as mod:
        a = mod.create_node("transform", name="a")
        b = mod.create_node("transform", name="b", parent=a)
        c = mod.create_node("transform", name="c", parent=b)

        mod.set_attr(a["rotateAxisZ"], cmdx.radians(45))
        mod.set_attr(b["rotateAxisZ"], cmdx.radians(-45))
        mod.set_attr(c["rotateAxisZ"], cmdx.radians(-45))
        mod.set_attr(a["ty"], 3.0)
        mod.set_attr(b["tx"], 1.0)
        mod.set_attr(c["tx"], 1.0)

    cmds.select(str(a), str(b), str(c))
    ri.assign_group()

    # Give them some droop
    group = cmdx.ls(type="rdGroup")[0]
    group["driveStiffness"] = 0.01

    # We've got a bridge-like shape
    #
    #   b      c
    #   .-----.
    #  /       \
    # . a       \
    #
    cmdx.min_time(1)
    cmdx.max_time(50)
    ri.record_markers()

    assert_almost_equals(b["rz"].read(time=50), cmdx.radians(-48.0), 1)
Exemplo n.º 4
0
def test_locked_rotate_channels():
    _new()

    with cmdx.DagModifier() as mod:
        a = mod.create_node("transform", name="a")
        b = mod.create_node("transform", name="b", parent=a)
        c = mod.create_node("transform", name="c", parent=b)

        mod.set_attr(a["ty"], 3.0)
        mod.set_attr(b["tx"], 1.0)
        mod.set_attr(c["tx"], 1.0)
        mod.lock_attr(b["rx"], True)
        mod.lock_attr(b["ry"], True)
        mod.lock_attr(c["rx"], True)
        mod.lock_attr(c["ry"], True)

    cmds.select(str(a), str(b), str(c))
    ri.assign_group()

    # Give them some droop
    group = cmdx.ls(type="rdGroup")[0]
    group["driveStiffness"] = 0.01

    cmdx.min_time(1)
    cmdx.max_time(50)

    ri.record_markers()

    cmdx.current_time(50)

    # The default limit around the remaining unlocked axis is 45 degrees
    assert_almost_equals(b["rz", cmdx.Degrees].read(), -45.0, 0)
Exemplo n.º 5
0
def test_negative_non_uniform_scale():
    _new()

    with cmdx.DagModifier() as mod:
        a = mod.create_node("transform", name="a")
        b = mod.create_node("transform", name="b", parent=a)
        c = mod.create_node("transform", name="c", parent=b)

        mod.set_attr(a["scaleX"], -1.0)
        mod.set_attr(a["ty"], 3.0)
        mod.set_attr(b["tx"], 1.0)
        mod.set_attr(c["tx"], 1.0)

    cmds.select(str(a), str(b), str(c))
    ri.assign_group()

    # Give them some droop
    group = cmdx.ls(type="rdGroup")[0]
    group["driveStiffness"] = 0.01

    cmdx.min_time(1)
    cmdx.max_time(30)

    ri.record_markers()

    cmdx.current_time(30)
    assert_almost_equals(b["rz", cmdx.Degrees].read(), -50.25, 1)
Exemplo n.º 6
0
def test_uniform_scale():
    _new()

    with cmdx.DagModifier() as mod:
        a = mod.create_node("transform", name="a")
        b = mod.create_node("transform", name="b", parent=a)
        c = mod.create_node("transform", name="c", parent=b)

        mod.set_attr(a["scale"], 2.0)
        mod.set_attr(a["ty"], 3.0)
        mod.set_attr(b["tx"], 1.0)
        mod.set_attr(c["tx"], 1.0)

    cmds.select(str(a), str(b), str(c))
    ri.assign_group()

    solver = cmdx.ls(type="rdSolver")[0]
    solver["gravity"] = 0

    ri.record_markers()

    # Any motion is bad
    assert_almost_equals(a["ty"].read(), 3.0, 4)
    assert_almost_equals(b["tx"].read(), 1.0, 4)
    assert_almost_equals(b["ty"].read(), 0.0, 4)
    assert_almost_equals(c["tx"].read(), 1.0, 4)
    assert_almost_equals(c["ty"].read(), 0.0, 4)
Exemplo n.º 7
0
def test_delete_group_deletes_markers():
    # Deleting the group automatically deletes any associated markers
    _new()

    a = cmdx.create_node("transform", name="a")
    b = cmdx.create_node("transform", name="b", parent=a)
    c = cmdx.create_node("transform", name="c", parent=b)

    solver = commands.create_solver()
    group = commands.create_group(solver)
    commands.assign_markers([a, b, c], solver, group)

    cmdx.delete(group)

    assert_equals(len(cmdx.ls(type="rdMarker")), 0)
Exemplo n.º 8
0
def test_ungroup_delete_empty():
    # Ungrouping all markers from a group automatically deletes that group
    _new()

    a = cmdx.create_node("transform", name="a")
    b = cmdx.create_node("transform", name="b", parent=a)
    c = cmdx.create_node("transform", name="c", parent=b)

    solver = commands.create_solver()
    group = commands.create_group(solver)
    markers = commands.assign_markers([a, b, c], solver, group)

    commands.ungroup_markers(markers)

    assert_equals(len(cmdx.ls(type="rdGroup")), 0)
Exemplo n.º 9
0
def test_negative_non_uniform_scale2():
    # A more special case, based on Roy's rig
    _new()

    with cmdx.DagModifier() as mod:
        a = mod.create_node("transform", name="a")
        b = mod.create_node("transform", name="b", parent=a)
        c = mod.create_node("transform", name="c", parent=b)

        mod.set_attr(a["tx"], 0.028)
        mod.set_attr(a["ty"], 5.762)
        mod.set_attr(a["tz"], 1.024)

        mod.set_attr(b["scaleZ"], -1.0)
        mod.set_attr(b["tx"], -0.19)
        mod.set_attr(b["ty"], 0.942)
        mod.set_attr(b["tz"], -0.334)
        mod.set_attr(b["rx"], cmdx.radians(86.831))
        mod.set_attr(b["ry"], cmdx.radians(15.163))
        mod.set_attr(b["rz"], cmdx.radians(100.711))

        mod.set_attr(c["scaleZ"], -1.0)
        mod.set_attr(c["tx"], -1.306)
        mod.set_attr(c["ty"], -0.327)
        mod.set_attr(c["tz"], 3.804)
        mod.set_attr(c["rx"], cmdx.radians(-79.561))
        mod.set_attr(c["ry"], cmdx.radians(61.743))
        mod.set_attr(c["rz"], cmdx.radians(9.128))

    cmds.select(str(a), str(b), str(c))
    ri.assign_group()

    # Give them some droop
    group = cmdx.ls(type="rdGroup")[0]
    group["driveStiffness"] = 0.01

    cmdx.min_time(1)
    cmdx.max_time(40)

    ri.record_markers()

    cmdx.current_time(40)
    assert_almost_equals(c["rx", cmdx.Degrees].read(), -76.638, 1)
    assert_almost_equals(c["ry", cmdx.Degrees].read(), 63.653, 1)
    assert_almost_equals(c["rz", cmdx.Degrees].read(), -8.884, 1)
Exemplo n.º 10
0
def test_record_from_not_start_frame():
    _new()

    with cmdx.DagModifier() as mod:
        a = mod.create_node("transform", name="a")
        b = mod.create_node("transform", name="b", parent=a)
        c = mod.create_node("transform", name="c", parent=b)

        mod.set_attr(a["rz"], cmdx.radians(45))
        mod.set_attr(b["rz"], cmdx.radians(-45))
        mod.set_attr(c["rz"], cmdx.radians(-45))
        mod.set_attr(a["ty"], 3.0)
        mod.set_attr(b["tx"], 1.0)
        mod.set_attr(c["tx"], 1.0)

    cmds.select(str(a), str(b), str(c))
    ri.assign_group()

    # Give them some droop
    group = cmdx.ls(type="rdGroup")[0]
    group["driveStiffness"] = 0.01

    # We've got a bridge-like shape
    #
    #   b      c
    #   .-----.
    #  /       \
    # . a       \
    #
    cmdx.min_time(1)
    cmdx.max_time(50)

    _step(c, 25)

    ri.record_markers()

    # We didn't break the start frame
    cmdx.current_time(1)
    assert_almost_equals(b["rz"].read(), cmdx.radians(-45.0), 1)

    # And the final frame looks ok
    cmdx.current_time(50)
    assert_almost_equals(b["rz"].read(), cmdx.radians(-93.0), 1)
Exemplo n.º 11
0
def test_joint_orient():
    _new()

    with cmdx.DagModifier() as mod:
        a = mod.create_node("joint", name="a")
        b = mod.create_node("joint", name="b", parent=a)
        c = mod.create_node("joint", name="c", parent=b)
        tip = mod.create_node("joint", name="tip", parent=c)

        mod.set_attr(a["jointOrientZ"], cmdx.radians(45))
        mod.set_attr(b["jointOrientZ"], cmdx.radians(-45))
        mod.set_attr(c["jointOrientZ"], cmdx.radians(-45))
        mod.set_attr(a["ty"], 3.0)
        mod.set_attr(b["tx"], 5.0)
        mod.set_attr(c["tx"], 5.0)
        mod.set_attr(tip["tx"], 5.0)

    cmds.select(str(a), str(b), str(c))
    ri.assign_group()

    # Give them some droop
    group = cmdx.ls(type="rdGroup")[0]
    group["driveStiffness"] = 0.01

    # We've got a bridge-like shape
    #
    #   b      c
    #   .-----.
    #  /       \
    # . a       \
    #
    cmdx.min_time(1)
    cmdx.max_time(25)
    ri.record_markers(**{"markersIgnoreJoints": False})

    assert_almost_equals(b["rz"].read(time=25), cmdx.radians(-13.0), 1)