Beispiel #1
0
def buildOpChain(self, interface):
    interface.setMinRequiredInputs(0)
    
    frameTime = interface.getGraphState().getTime()
    
    
    # simpler case for the archive
    if self.getParameter('asArchive').getValue(frameTime):
        sscb = FnGeolibServices.OpArgsBuilders.StaticSceneCreate(True)
        location = self.getScenegraphLocation(frameTime)
        sscb.createEmptyLocation(location, 'usd archive')
        
        
        gb = FnAttribute.GroupBuilder()
        
        
        for name in ('fileName', 'isolatePath'):
            gb.set(name, interface.buildAttrFromParam(
                    self.getParameter(name)))
        
        gb.set('currentTime', FnAttribute.DoubleAttribute(frameTime))
        
        attrs = gb.build()
        
        sscb.setAttrAtLocation(location, 'geometry', attrs)
        
        if self.getParameter('includeProxyForArchive').getValue(frameTime):
            sscb.addSubOpAtLocation(location,
                    'UsdIn.AddViewerProxy', attrs)
        
        
        interface.appendOp('StaticSceneCreate', sscb.build())
        return
    
    
    graphState = interface.getGraphState()
    pxrUsdInArgs = self.buildPxrUsdInOpArgsAtGraphState(graphState)
    
    # When buildOpChain is reached as result of a call to
    # buildPxrUsdInOpArgsFromDownstreamNode, an additional entry will be
    # present in the graphState (otherwise not meaningful to the cooked scene).
    # If found, we'll record opArgs at the specified key in a member variable
    # dict.
    argsCookTmpKey = graphState.getDynamicEntry(kArgsCookTmpKeyToken)
    if isinstance(argsCookTmpKey, FnAttribute.StringAttribute):
        self._argsCookTmp[argsCookTmpKey.getValue('', False)] = pxrUsdInArgs
    
    
    # our primary op in the chain that will create the root location
    sscb = FnGeolibServices.OpArgsBuilders.StaticSceneCreate(True)

    sscb.addSubOpAtLocation(self.getScenegraphLocation(
        interface.getFrameTime()), 'UsdIn', pxrUsdInArgs)

    sscb.setAttrAtLocation('/root', 'info.usdLoader', FnAttribute.StringAttribute('UsdIn'))

    interface.appendOp('StaticSceneCreate', sscb.build())
    def buildCubeMakerOpChain(node, interface):
        """
        Defines the callback function used to create the Ops chain for the
        node type being registered.

        @type node: C{Nodes3DAPI.NodeTypeBuilder.CubeMaker}
        @type interface: C{Nodes3DAPI.NodeTypeBuilder.BuildChainInterface}
        @param node: The node for which to define the Ops chain
        @param interface: The interface providing the functions needed to set
            up the Ops chain for the given node.
        """
        # Get the current frame time
        frameTime = interface.getGraphState().getTime()

        # Set the minimum number of input ports
        interface.setMinRequiredInputs(0)

        argsGb = FnAttribute.GroupBuilder()

        # Parse node parameters
        locationParam = node.getParameter('location')
        numberOfCubesParam = node.getParameter('numberOfCubes')
        rotateCubesParam = node.getParameter('rotateCubes')
        maxRotationParam = node.getParameter('maxRotation')
        if locationParam:
            location = locationParam.getValue(frameTime)

            # The base location is encoded using nested group attributes
            # defining a hierarchy where the elements in the location paths
            # are interleaved with group attributes named 'c' (for child).
            # The last element will contain a group attribute, named 'a',
            # which in turn will hold an attribute defining the number of
            # cubes to be generated.
            # See the Ops source code for more details
            locationPaths = location[1:].split('/')[1:]
            attrsHierarchy = \
                '.'.join([x for t in zip(['c',] * len(locationPaths),
                                         locationPaths) for x in t])
            argsGb.set(
                attrsHierarchy + '.a.numberOfCubes',
                FnAttribute.IntAttribute(
                    numberOfCubesParam.getValue(frameTime)))
            if rotateCubesParam.getValue(frameTime) == 1:
                argsGb.set(
                    attrsHierarchy + '.a.maxRotation',
                    FnAttribute.DoubleAttribute(
                        maxRotationParam.getValue(frameTime)))

        # Add the CubeMaker Op to the Ops chain
        interface.appendOp('CubeMaker', argsGb.build())
Beispiel #3
0
def myBuildOps(node, interface):
    op = interface.buildOp('pointCloudOp')
    
    if op.areParametersDirty():
        frameTime = interface.getFrameTime()

        op.setOpType('PointCloudOp')
        op.setOpArg('source', node.getParameter('source').getValue(frameTime))
        op.setOpArg('dest', node.getParameter('dest').getValue(frameTime))
        op.setOpArg('instance', node.getParameter('instance').getValue(frameTime))
        op.setOpArg('instanceScale', FnAttribute.DoubleAttribute(node.getParameter('instanceScale').getValue(frameTime)))
    if op.areInputsDirty():
        op.setOpInputs(interface.getAllInputOps())

    return op
    def buildLocationDescribeOpChain(node, interface):
        interface.setMinRequiredInputs(0)

        locationParam = node.getParameter('location')
        if not locationParam:
            # set an error
            staticSCB = FnGeolibServices.OpArgsBuilders.StaticSceneCreate()
            staticSCB.createEmptyLocation('/root/world/geo/')
            staticSCB.setAttrAtLocation(
                '/root/world/', 'errorMessage',
                FnAttribute.StringAttribute(
                    'Invalid location used for LocationDescribe'))
            interface.appendOp('StaticSceneCreate', staticSCB.build())
        else:
            # do the actual work creating location and attributes
            locationPath = locationParam.getValue(0)

            modeParam = node.getParameter('mode')
            modeParamValue = modeParam.getValue(0)
            descriptionParam = node.getParameter('description')
            typeParam = node.getParameter('type')
            typeParamValue = typeParam.getValue(0)

            interface.setMinRequiredInputs(0 if modeParamValue ==
                                           "create" else 1)

            internalBuilder = InternalBuilderSSC(
                locationPath, typeParamValue
            ) if modeParamValue == "create" else InternalBuilderAS(
                locationPath, typeParamValue)

            descriptionString = descriptionParam.getValue(0)
            attributeItems = parseDescription(descriptionString)

            for attribItem in attributeItems:
                if attribItem[0] == 1:
                    # single item
                    if attribItem[1] == "int":
                        internalBuilder.addAttribute(
                            attribItem[2],
                            FnAttribute.IntAttribute(int(attribItem[3])))
                    elif attribItem[1] == "string":
                        internalBuilder.addAttribute(
                            attribItem[2],
                            FnAttribute.StringAttribute(attribItem[3]))
                    elif attribItem[1] == "float":
                        internalBuilder.addAttribute(
                            attribItem[2],
                            FnAttribute.FloatAttribute(
                                float(attribItem[3].translate(None, 'f'))))
                    elif attribItem[1] == "double":
                        internalBuilder.addAttribute(
                            attribItem[2],
                            FnAttribute.DoubleAttribute(
                                float(attribItem[3].translate(None, 'f'))))
                elif attribItem[0] == 2:
                    # array item
                    itemDataType = attribItem[1]

                    if itemDataType == "int":
                        intArray = [
                            int(stringItem) for stringItem in attribItem[3]
                        ]
                        internalBuilder.addAttribute(
                            attribItem[2],
                            FnAttribute.IntAttribute(intArray, attribItem[4]))
                    elif itemDataType == "float" or itemDataType == "double":
                        floatArray = [
                            float(stringItem.translate(None, 'f'))
                            for stringItem in attribItem[3]
                        ]
                        # print floatArray
                        if itemDataType == "float":
                            internalBuilder.addAttribute(
                                attribItem[2],
                                FnAttribute.FloatAttribute(
                                    floatArray, attribItem[4]))
                        elif itemDataType == "double":
                            internalBuilder.addAttribute(
                                attribItem[2],
                                FnAttribute.DoubleAttribute(
                                    floatArray, attribItem[4]))

            interface.appendOp(internalBuilder.getOpName(),
                               internalBuilder.build())
Beispiel #5
0
from Katana import FnAttribute, Nodes3DAPI 

nb = Nodes3DAPI.NodeTypeBuilder('PointCloudOp')
nb.setInputPortNames(('in',))

nb.setParametersTemplateAttr(FnAttribute.GroupBuilder()
    .set('source', FnAttribute.StringAttribute(""))
    .set('dest', FnAttribute.StringAttribute(""))
    .set('instance', FnAttribute.StringAttribute(""))
    .set('instanceScale', FnAttribute.DoubleAttribute(0.01))
    .build())

nb.setHintsForNode({'help': 'Instantiates a point cloud with a piece of geometry'})
nb.setHintsForParameter('source', {'widget':'scenegraphLocation'})
nb.setHintsForParameter('dest', {'widget':'scenegraphLocation'})
nb.setHintsForParameter('instance', {'widget':'scenegraphLocation'})


def myBuildOps(node, interface):
    op = interface.buildOp('pointCloudOp')
    
    if op.areParametersDirty():
        frameTime = interface.getFrameTime()

        op.setOpType('PointCloudOp')
        op.setOpArg('source', node.getParameter('source').getValue(frameTime))
        op.setOpArg('dest', node.getParameter('dest').getValue(frameTime))
        op.setOpArg('instance', node.getParameter('instance').getValue(frameTime))
        op.setOpArg('instanceScale', FnAttribute.DoubleAttribute(node.getParameter('instanceScale').getValue(frameTime)))
    if op.areInputsDirty():
        op.setOpInputs(interface.getAllInputOps())
def registerCubeMaker():
    """
    Registers a new CubMaker node type using the NodeTypeBuilder utility class.
    """

    from Katana import Nodes3DAPI
    from Katana import FnAttribute

    def buildCubeMakerOpChain(node, interface):
        """
        Defines the callback function used to create the Ops chain for the
        node type being registered.

        @type node: C{Nodes3DAPI.NodeTypeBuilder.CubeMaker}
        @type interface: C{Nodes3DAPI.NodeTypeBuilder.BuildChainInterface}
        @param node: The node for which to define the Ops chain
        @param interface: The interface providing the functions needed to set
            up the Ops chain for the given node.
        """
        # Get the current frame time
        frameTime = interface.getGraphState().getTime()

        # Set the minimum number of input ports
        interface.setMinRequiredInputs(0)

        argsGb = FnAttribute.GroupBuilder()

        # Parse node parameters
        locationParam = node.getParameter('location')
        numberOfCubesParam = node.getParameter('numberOfCubes')
        rotateCubesParam = node.getParameter('rotateCubes')
        maxRotationParam = node.getParameter('maxRotation')
        if locationParam:
            location = locationParam.getValue(frameTime)

            # The base location is encoded using nested group attributes
            # defining a hierarchy where the elements in the location paths
            # are interleaved with group attributes named 'c' (for child).
            # The last element will contain a group attribute, named 'a',
            # which in turn will hold an attribute defining the number of
            # cubes to be generated.
            # See the Ops source code for more details
            locationPaths = location[1:].split('/')[1:]
            attrsHierarchy = \
                '.'.join([x for t in zip(['c',] * len(locationPaths),
                                         locationPaths) for x in t])
            argsGb.set(
                attrsHierarchy + '.a.numberOfCubes',
                FnAttribute.IntAttribute(
                    numberOfCubesParam.getValue(frameTime)))
            if rotateCubesParam.getValue(frameTime) == 1:
                argsGb.set(
                    attrsHierarchy + '.a.maxRotation',
                    FnAttribute.DoubleAttribute(
                        maxRotationParam.getValue(frameTime)))

        # Add the CubeMaker Op to the Ops chain
        interface.appendOp('CubeMaker', argsGb.build())

    # Create a NodeTypeBuilder to register the new type
    nodeTypeBuilder = Nodes3DAPI.NodeTypeBuilder('CubeMaker')

    # Build the node's parameters
    gb = FnAttribute.GroupBuilder()
    gb.set('location',
           FnAttribute.StringAttribute('/root/world/geo/cubeMaker'))
    gb.set('numberOfCubes', FnAttribute.IntAttribute(20))
    gb.set('rotateCubes', FnAttribute.IntAttribute(0))
    gb.set('maxRotation', FnAttribute.DoubleAttribute(0))

    # Set the parameters template
    nodeTypeBuilder.setParametersTemplateAttr(gb.build())

    # Set parameter hints
    nodeTypeBuilder.setHintsForParameter('location',
                                         {'widget': 'scenegraphLocation'})
    nodeTypeBuilder.setHintsForParameter('numberOfCubes', {'int': True})
    nodeTypeBuilder.setHintsForParameter('rotateCubes', {'widget': 'boolean'})
    nodeTypeBuilder.setHintsForParameter(
        'maxRotation',
        {
            'conditionalVisOp': 'equalTo',
            'conditionalVisPath': '../rotateCubes',
            'conditionalVisValue': 1
        },
    )

    # Set the callback responsible to build the Ops chain
    nodeTypeBuilder.setBuildOpChainFnc(buildCubeMakerOpChain)

    # Build the new node type
    nodeTypeBuilder.build()