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)
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)
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()
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)
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")
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)
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()
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)
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)
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)
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)
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)