Exemplo n.º 1
0
def nodeHelper(nodeType,
               chainAttr,
               inputs=(),
               outputs=(),
               minimalOutput=True,
               setAttr=(),
               **kwargs):
    from nodex.core import Nodex

    # ensure nodex
    inputs = tuple(
        (attrName,
         attrValue) if isinstance(attrValue, Nodex) else (attrName,
                                                          Nodex(attrValue))
        for attrName, attrValue in inputs if attrValue is not None)

    outputs = tuple(
        (attrName,
         attrValue) if isinstance(attrValue, Nodex) else (attrName,
                                                          Nodex(attrValue))
        for attrName, attrValue in outputs if attrValue is not None)

    # highest dimensions among inputs
    dim = max(y.dimensions() for x, y in inputs)

    # create node
    createKwargs = {}
    name = kwargs.pop('name', None)
    if name:
        createKwargs['name'] = name

    n = pm.createNode(nodeType, **createKwargs)

    for attrName, attrValue in setAttr:
        n.attr(attrName).set(
            attrValue)  # without nodex (optimization for static values)

    # check input dimensions
    for attrName, attrValue in inputs:
        attrNodex = Nodex(n.attr(attrName))
        if dim < attrNodex.dimensions():
            if dim == 1:
                attrNodex = attrNodex[0]
            else:
                attrNodex = attrNodex[:dim]
        attrValue.connect(attrNodex)

    # result chain
    result = Nodex(n.attr(chainAttr))

    # if dimensions mismatch give resulting dimensions lowest dimensions (if minimalOutput)
    if minimalOutput and dim != 0:
        if result.dimensions() > dim:
            if dim == 1:
                result = result[0]
            else:
                result = result[:dim]

    return result
Exemplo n.º 2
0
def nodeHelper(nodeType, chainAttr, inputs=(), outputs=(), minimalOutput=True, setAttr=(), **kwargs):
    from nodex.core import Nodex

    # ensure nodex
    inputs = tuple((attrName, attrValue) if isinstance(attrValue, Nodex) else (attrName, Nodex(attrValue))
               for attrName, attrValue in inputs if attrValue is not None)

    outputs = tuple((attrName, attrValue) if isinstance(attrValue, Nodex) else (attrName, Nodex(attrValue))
               for attrName, attrValue in outputs if attrValue is not None)

    # highest dimensions among inputs
    dim = max(y.dimensions() for x, y in inputs)

    # create node
    createKwargs = {}
    name = kwargs.pop('name', None)
    if name:
        createKwargs['name'] = name

    n = pm.createNode(nodeType, **createKwargs)

    for attrName, attrValue in setAttr:
        n.attr(attrName).set(attrValue)     # without nodex (optimization for static values)

    # check input dimensions
    for attrName, attrValue in inputs:
        attrNodex = Nodex(n.attr(attrName))
        if dim < attrNodex.dimensions():
            if dim == 1:
                attrNodex = attrNodex[0]
            else:
                attrNodex = attrNodex[:dim]
        attrValue.connect(attrNodex)

    # result chain
    result = Nodex(n.attr(chainAttr))

    # if dimensions mismatch give resulting dimensions lowest dimensions (if minimalOutput)
    if minimalOutput and dim != 0:
        if result.dimensions() > dim:
            if dim == 1:
                result = result[0]
            else:
                result = result[:dim]

    return result
Exemplo n.º 3
0
 def test_len(self):
     # __len__ and dimensions
     n = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 123, 3213, 125, 245]
     n = Nodex(n)
     self.assertEqual(n.dimensions(), len(n))
Exemplo n.º 4
0
 def test_len(self):
     # __len__ and dimensions
     n = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 123, 3213, 125, 245]
     n = Nodex(n)
     self.assertEqual(n.dimensions(), len(n))