Exemple #1
0
    def test_standard_trace(self):
        """ Test regular tracing """

        expected_trace = [
            "cmds.setAttr('A.translateY', 1.1)", "val1 = cmds.getAttr('A.ty')",
            "var1 = cmds.createNode('multiplyDivide', name='nc_MUL_translateX_1f_multiplyDivide')",
            "cmds.setAttr(var1 + '.operation', 1)",
            "cmds.connectAttr('A.translateX', var1 + '.input1X', force=True)",
            "cmds.setAttr(var1 + '.input2X', (val1 + 2) / 2)",
            "var2 = cmds.createNode('plusMinusAverage', name='nc_SUB_list_plusMinusAverage')",
            "cmds.setAttr(var2 + '.operation', 2)",
            "cmds.connectAttr('B.scale', var2 + '.input3D[0]', force=True)",
            "cmds.connectAttr(var1 + '.outputX', var2 + '.input3D[1].input3Dx', force=True)",
            "cmds.connectAttr(var1 + '.outputX', var2 + '.input3D[1].input3Dy', force=True)",
            "cmds.connectAttr(var1 + '.outputX', var2 + '.input3D[1].input3Dz', force=True)",
            "cmds.connectAttr(var2 + '.output3D', 'C.translate', force=True)"
        ]

        with noca.Tracer() as trace:
            a = noca.Node("A")
            b = noca.Node("B")
            c = noca.Node("C")
            a.ty = 1.1
            num = a.ty.get()
            c.t = b.s - a.tx * ((num + 2) / 2)

        self.assertEqual(trace, expected_trace)
    def test_basic_methods(self):
        for i, noca_instance in enumerate(self.test_items):
            desired_attrs = self.desired_attrs[i]
            desired_value_a = self.desired_values_a[i]
            desired_value_b = self.desired_values_b[i]

            # Test node property
            self.assertEqual(noca_instance.node, TEST_TRANSFORM)
            self.assertEqual(noca_instance.nodes, [TEST_TRANSFORM])

            # Test attrs property
            self.assertIsInstance(noca_instance.attrs, noca.NcAttrs)
            # If current noca_instance is NcAttrs, its .attrs should be itself!
            if isinstance(noca_instance, noca.NcAttrs):
                self.assertIs(noca_instance.attrs, noca_instance)

            # Test attrs_list property
            self.assertListEqual(noca_instance.attrs_list, desired_attrs)

            # Move TEST_NODE back to same place every time loop comes around!
            cmds.setAttr(
                "{}.translate".format(TEST_TRANSFORM),
                *TEST_POSITION_A,
                type="double3"
            )

            # Test len method
            self.assertEqual(len(noca_instance), len(desired_attrs))

            # Test iter method
            for item, desired_attr in zip(noca_instance, desired_attrs):
                plug = "{}.{}".format(TEST_TRANSFORM, desired_attr)
                self.assertEqual(item.plugs[0], plug)

            # Test get method (use Tracer to get NcValues back!)
            with noca.Tracer():
                queried_value = noca_instance.get()
                self.assertEqual(queried_value, desired_value_a)
                if not isinstance(desired_value_a, list):
                    self.assertIsInstance(queried_value, noca.nc_value.NcValue)

            # Test set method
            noca_instance.set(desired_value_b)
            self.assertEqual(noca_instance.get(), desired_value_b)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Tab1
# TRACER

import node_calculator.core as noca

a = noca.Node("A_geo")
b = noca.Node("B_geo")
c = noca.Node("C_geo")

# This is our lovely formula, but it needs to be faster!
c.ty = a.tx + b.ty / 2

# Tab2
# TRACER
with noca.Tracer() as trace:
    c.ty = a.tx + b.ty / 2
print trace

with noca.Tracer(pprint_trace=True):
    current_val = a.tx.get()
    offset_val = (current_val - 1) / 3
    c.ty = a.tx + b.ty / offset_val

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# CUSTOMIZE IT

from node_calculator.core import noca_op
from node_calculator.core import _create_operation_node
b = noca.Node("geo")
b_mat = noca.Node("mat")
multiplier = b.add_float("multiplier", value=0.25, max=0.5)
r_value = b.ty * b.tz * multiplier
b_mat.colorR = noca.Op.condition(b.ty > 0, noca.Op.condition(b.tz > 0, r_value, 0), 0)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# Doesn't display correctly in viewport!
b = noca.Node("geo")
b_mat = noca.Node("mat")

multiplier = b.add_float("multiplier", value=0.25, max=0.5)
threshold = 1

tx_zeroed = b.tx - threshold
ty_zeroed = b.ty - threshold
tz_zeroed = b.tz - threshold

r_value = ty_zeroed * tz_zeroed * multiplier
g_value = tx_zeroed * tz_zeroed * multiplier
b_value = tx_zeroed * ty_zeroed * multiplier

black = 0
with noca.Tracer(pprint_trace=True):
    b_mat.color = [
        noca.Op.condition(b.ty > threshold, noca.Op.condition(b.tz > threshold, r_value, black), black),
        noca.Op.condition(b.tz > threshold, noca.Op.condition(b.tx > threshold, g_value, black), black),
        noca.Op.condition(b.tx > threshold, noca.Op.condition(b.ty > threshold, b_value, black), black),
    ]
Exemple #5
0
# Tab3
# UNDER THE HOOD

# NcValues
# This does NOT work:
normal_int = 1
normal_int.marco = "polo"

# This works:
noca_int = noca.Node(1)
noca_int.marco = "polo"
noca_int.metadata
noca_int.created_by_user

# Keeping track of origin of values:
from maya import cmds
scale = cmds.getAttr("A_geo.scaleX")
translate = cmds.getAttr("A_geo.translateX")
print(scale.metadata)
print(translate.metadata)
# vs
a_geo = noca.Node("A_geo")
with noca.Tracer():
    scale = a_geo.scaleX.get()
    translate = a_geo.translateX.get()

    a_geo.tx = scale + translate

print(scale.metadata)
print(translate.metadata)