Example #1
0
def buildOpChain(self, interface):
    interface.setExplicitInputRequestsEnabled(True)

    graphState = interface.getGraphState()
    frameTime = interface.getFrameTime()

    locations = self.getParameter('locations')
    overrides = self.getParameter('overrides')

    if locations.getNumChildren() > 0:

        # Build overrides as a child group
        gb1 = FnAttribute.GroupBuilder()

        motionSampleTimes = overrides.getChild('motionSampleTimes').getValue(
            frameTime)
        currentTime = overrides.getChild('currentTime').getValue(frameTime)
        shutterOpen = overrides.getChild('shutterOpen').getValue(frameTime)
        shutterClose = overrides.getChild('shutterClose').getValue(frameTime)

        if motionSampleTimes:
            floatTimes = [float(t) for t in motionSampleTimes.split(' ')]
            gb1.set('motionSampleTimes',
                    FnAttribute.FloatAttribute(floatTimes))

        if currentTime:
            gb1.set('currentTime',
                    FnAttribute.FloatAttribute(float(currentTime)))

        if shutterOpen:
            gb1.set('shutterOpen',
                    FnAttribute.FloatAttribute(float(shutterOpen)))

        if shutterClose:
            gb1.set('shutterClose',
                    FnAttribute.FloatAttribute(float(shutterClose)))

        overridesAttr = gb1.build()

        if overridesAttr.getNumberOfChildren() > 0:

            # Encode per-location overrides in the graph state
            gb2 = FnAttribute.GroupBuilder()

            for loc in locations.getChildren():
                encodedLoc = FnAttribute.DelimiterEncode(
                    loc.getValue(frameTime))
                if encodedLoc:
                    gb2.set('overrides.' + encodedLoc, overridesAttr)

            existingValue = (interface.getGraphState().getDynamicEntry(
                'var:pxrUsdInSession'))
            if isinstance(existingValue, FnAttribute.GroupAttribute):
                gb2.deepUpdate(existingValue)

            graphState = (graphState.edit().setDynamicEntry(
                'var:pxrUsdInSession', gb2.build()).build())

    interface.addInputRequest('in', graphState)
Example #2
0
def build_pass_resolve_op_chain(node, interface):
    """
    """
    module_logger.debug("PassResolve - build_pass_resolve_op_chain()")

    interface.setMinRequiredInputs(0)

    frame_time = interface.getGraphState().getTime()
    active_pass_location_param = node.getParameter("activePassLocation")

    # Setup the currently active pass in the SceneGraph.
    attribute_set_args_builder = FnGeolibServices.OpArgsBuilders.AttributeSet()

    attribute_set_args_builder.setCEL(["/root"])
    if active_pass_location_param.getValue(frame_time):
        attribute_set_args_builder.setAttr(
            "passResolve.activePassLocation",
            FnAttribute.StringAttribute(
                active_pass_location_param.getValue(frame_time)))

    interface.appendOp("AttributeSet", attribute_set_args_builder.build())

    # Expose all locations under "/root/world" to the PassVisibility Op that will
    # set the appropriate locations as visible or not, as per the setup of the currently
    # active pass.
    group_builder = FnAttribute.GroupBuilder()
    attribute_set_args_builder = FnGeolibServices.OpArgsBuilders.AttributeSet()

    attribute_set_args_builder.setCEL(["/root/world//*"])
    attribute_set_args_builder.addSubOp("PassVisibility",
                                        group_builder.build())

    interface.appendOp("AttributeSet", attribute_set_args_builder.build())

    # Expose all locations under "/root/world" to the PassRays Op that will
    # set the rays related attributes on the appropriate locations, which are renderer dependent,
    # as per the setup of the currently active pass.
    group_builder = FnAttribute.GroupBuilder()
    attribute_set_args_builder = FnGeolibServices.OpArgsBuilders.AttributeSet()

    attribute_set_args_builder.setCEL(["/root/world//*"])
    attribute_set_args_builder.addSubOp("PassRays", group_builder.build())

    interface.appendOp("AttributeSet", attribute_set_args_builder.build())

    # Expose the "/root" location to the PassCollections Op that will
    # create collections attributes on the root location, according the to active pass configuration.
    group_builder = FnAttribute.GroupBuilder()
    attribute_set_args_builder = FnGeolibServices.OpArgsBuilders.AttributeSet()

    attribute_set_args_builder.setCEL(["/root"])
    attribute_set_args_builder.addSubOp("PassCollections",
                                        group_builder.build())

    interface.appendOp("AttributeSet", attribute_set_args_builder.build())
Example #3
0
def buildOpChain(self, interface):
    interface.setExplicitInputRequestsEnabled(True)

    graphState = interface.getGraphState()
    frameTime = interface.getFrameTime()
    locationsParam = self.getParameter("locations")

    attrName = self.getParameter('attrName').getValue(frameTime).replace(
        '.', ':')

    locations = [
        y for y in (x.getValue(frameTime)
                    for x in locationsParam.getChildren()) if y
    ]

    if attrName and locations:
        typeValue = self.getParameter('type').getValue(frameTime)
        if typeValue == 'string':
            valueAttr = interface.buildAttrFromParam(
                self.getParameter('stringValue'))
        else:
            valueAttr = interface.buildAttrFromParam(
                self.getParameter('numberValue'),
                numberType=__numberAttrTypes.get(typeValue,
                                                 FnAttribute.FloatAttribute))

        entryGroup = (FnAttribute.GroupBuilder().set('value',
                                                     valueAttr).build())

        gb = FnAttribute.GroupBuilder()

        for loc in locations:
            gb.set(
                "attrs.%s.%s" % (
                    FnAttribute.DelimiterEncode(loc),
                    attrName,
                ), entryGroup)

        existingValue = (
            interface.getGraphState().getDynamicEntry("var:pxrUsdInSession"))

        if isinstance(existingValue, FnAttribute.GroupAttribute):
            gb.deepUpdate(existingValue)

        graphState = (graphState.edit().setDynamicEntry(
            "var:pxrUsdInSession", gb.build()).build())

    interface.addInputRequest("in", graphState)
Example #4
0
def buildOpChain(self, interface):
    interface.setExplicitInputRequestsEnabled(True)

    graphState = interface.getGraphState()
    frameTime = interface.getFrameTime()
    locations = self.getParameter("locations")

    if locations:
        gb = FnAttribute.GroupBuilder()

        for loc in locations.getChildren():
            gb.set(
                "defaultMotionPaths." +
                FnAttribute.DelimiterEncode(loc.getValue(frameTime)),
                FnAttribute.IntAttribute(1))

        existingValue = (
            interface.getGraphState().getDynamicEntry("var:pxrUsdInSession"))

        if isinstance(existingValue, FnAttribute.GroupAttribute):
            gb.deepUpdate(existingValue)

        graphState = (graphState.edit().setDynamicEntry(
            "var:pxrUsdInSession", gb.build()).build())

    interface.addInputRequest("in", graphState)
    def buildShapeIDOpChain(node, interface):
        """
        Defines the callback function used to define the Ops chain for the
        node type being registered.

        @type node: C{Nodes3DAPI.NodeTypeBuilder.ShapeID}
        @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(1)

        argsGb = FnAttribute.GroupBuilder()

        # Parse the CEL parameter
        celParam = node.getParameter('CEL')
        if celParam:
            argsGb.set('CEL', celParam.getValue(frameTime))

        # Parse the displacement parameter
        pathParam = node.getParameter('regedit')
        if pathParam:
            argsGb.set('regedit', pathParam.getValue(frameTime))

        # Add the ShapeID Op to the Ops chain
        interface.appendOp('ShapeID', argsGb.build())
    def buildGeoScalerOpChain(node, interface):
        """
        Defines the callback function used to create the Ops chain for the
        node type being registered.

        @type node: C{Nodes3DAPI.NodeTypeBuilder.GeoScaler}
        @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(1)

        argsGb = FnAttribute.GroupBuilder()

        # Parse node parameters
        CELParam = node.getParameter("CEL")
        if CELParam:
            CEL = CELParam.getValue(frameTime)
            argsGb.set("CEL", CEL)

        scaleParam = node.getParameter('scale')
        if scaleParam:
            scale = scaleParam.getValue(frameTime)
            argsGb.set("scale", scale)

        # Add the GeoScaler Op to the Ops chain
        interface.appendOp('GeoScaler', argsGb.build())
def registerShapeID():
    """
    Registers a new ShapeID node type using the NodeTypeBuilder utility class.
    """

    from Katana import Nodes3DAPI
    from Katana import FnAttribute

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

        @type node: C{Nodes3DAPI.NodeTypeBuilder.ShapeID}
        @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(1)

        argsGb = FnAttribute.GroupBuilder()

        # Parse the CEL parameter
        celParam = node.getParameter('CEL')
        if celParam:
            argsGb.set('CEL', celParam.getValue(frameTime))

        # Parse the displacement parameter
        pathParam = node.getParameter('regedit')
        if pathParam:
            argsGb.set('regedit', pathParam.getValue(frameTime))

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

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

    # Add an input port
    nodeTypeBuilder.setInputPortNames(('in', ))

    # Build the node's parameters
    gb = FnAttribute.GroupBuilder()
    gb.set('CEL', FnAttribute.StringAttribute(''))
    gb.set('regedit', FnAttribute.StringAttribute('*.json'))

    # Set the parameters template
    nodeTypeBuilder.setParametersTemplateAttr(gb.build())
    # Set parameter hints
    nodeTypeBuilder.setHintsForParameter('CEL', {'widget': 'cel'})
    # Set the callback responsible to build the Ops chain
    nodeTypeBuilder.setBuildOpChainFnc(buildShapeIDOpChain)

    # Build the new node type
    nodeTypeBuilder.build()
Example #8
0
def buildPxrUsdInOpArgsFromDownstreamNode(self,
                                          downstreamNode,
                                          graphState,
                                          portIndex=0):
    if not hasattr(self, '_argsCookTmp'):
        self._argsCookTmp = {}

    key = (FnAttribute.GroupBuilder().set('graphState',
                                          graphState.getOpSystemArgs()).set(
                                              'node',
                                              hash(downstreamNode)).set(
                                                  'portIndex',
                                                  portIndex).build().getHash())

    # Set a dynamic entry that's not prefixed with "var:" so it won't show up
    # in op system args (or other graph state comparisons other than hash
    # uniqueness)
    useGraphState = graphState.edit().setDynamicEntry(
        kArgsCookTmpKeyToken, FnAttribute.StringAttribute(key)).build()

    # trigger a cook with this unique graph state
    Nodes3DAPI.CreateClient(downstreamNode,
                            graphState=useGraphState,
                            portIndex=portIndex)

    if key in self._argsCookTmp:
        result = self._argsCookTmp[key]
        return result
    else:
        # TODO, exception?
        pass
Example #9
0
File: PxrUsdIn.py Project: MWDD/USD
def buildOpChain(self, interface):
    interface.setMinRequiredInputs(0)

    gb = FnAttribute.GroupBuilder()

    gb.set('fileName', interface.buildAttrFromParam(
        self.getParameter('fileName')))

    gb.set('location', interface.buildAttrFromParam(
        self.getParameter('location')))

    gb.set('isolatePath', interface.buildAttrFromParam(
        self.getParameter('isolatePath')))

    gb.set('variants', interface.buildAttrFromParam(
        self.getParameter('variants')))

    gb.set('ignoreLayerRegex', interface.buildAttrFromParam(
        self.getParameter('ignoreLayerRegex')))

    gb.set('motionSampleTimes', interface.buildAttrFromParam(
        self.getParameter('motionSampleTimes')))

    gb.set('verbose', interface.buildAttrFromParam(
        self.getParameter('verbose'), 
            numberType=FnAttribute.IntAttribute))
    
    gb.set('instanceMode', interface.buildAttrFromParam(
        self.getParameter('instanceMode')))

    sessionValues = (
            interface.getGraphState().getDynamicEntry("var:pxrUsdInSession"))
    if isinstance(sessionValues, FnAttribute.GroupAttribute):
        gb.set('session', sessionValues)

    
    gb.set('system', interface.getGraphState().getOpSystemArgs())

    # our primary op in the chain that will create the root location
    sscb = FnGeolibServices.OpArgsBuilders.StaticSceneCreate(True)

    # check for any extra attributes or namespaces set downstream
    # via graph state
    extra = interface.getGraphState().getDynamicEntry('var:usdExtraAttributesOrNamespaces')
    if extra:
        gb.set('extraAttributesOrNamespaces', extra)

    argsOverride = interface.getGraphState().getDynamicEntry('var:pxrUsdInArgs')
    if isinstance(argsOverride, FnAttribute.GroupAttribute):
        gb.update(argsOverride)

    # add the PxrUsdIn op as a sub op
    pxrUsdInArgs = gb.build()
    sscb.addSubOpAtLocation(self.getScenegraphLocation(
        interface.getFrameTime()), 'PxrUsdIn', pxrUsdInArgs)

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

    interface.appendOp('StaticSceneCreate', sscb.build())
Example #10
0
def appendToParametersOpChain(self, interface):
    frameTime = interface.getFrameTime()

    location = self.getScenegraphLocation(frameTime)
    variantSetName = ''
    if self.getParameter('args.variantSetName.enable').getValue(frameTime):
        variantSetName = self.getParameter(
            'args.variantSetName.value').getValue(frameTime)

    # This makes use of the attrs recognized by PxrUsdInUtilExtraHintsDap
    # to provide the hinting from incoming attr values.
    uiscript = '''
        local variantSetName = Interface.GetOpArg('user.variantSetName'):getValue()
        
        local variantsGroup = (Interface.GetAttr('info.usd.variants') or
                GroupAttribute())
        
        local variantSetNames = {}
        for i = 0, variantsGroup:getNumberOfChildren() - 1 do
            variantSetNames[#variantSetNames + 1] = variantsGroup:getChildName(i)
        end
        
        Interface.SetAttr("__pxrUsdInExtraHints." ..
                Attribute.DelimiterEncode("__variantUI.variantSetName"),
                        GroupBuilder()
                            :set('widget', StringAttribute('popup'))
                            :set('options', StringAttribute(variantSetNames))
                            :set('editable', IntAttribute(1))
                            :build())
        
        local variantOptions = {}
            
        if variantSetName ~= '' then
            local variantOptionsAttr =
                    variantsGroup:getChildByName(variantSetName)
            if Attribute.IsString(variantOptionsAttr) then
                variantOptions = variantOptionsAttr:getNearestSample(0.0)
            end
        end
        
        Interface.SetAttr("__pxrUsdInExtraHints." ..
                Attribute.DelimiterEncode("__variantUI.variantSelection"),
                        GroupBuilder()
                            :set('widget', StringAttribute('popup'))
                            :set('options', StringAttribute(variantOptions))
                            :set('editable', IntAttribute(1))
                            :build())
    '''

    sscb = FnGeolibServices.OpArgsBuilders.StaticSceneCreate(True)

    sscb.addSubOpAtLocation(
        location, 'OpScript.Lua',
        FnAttribute.GroupBuilder().set('script',
                                       uiscript).set('user.variantSetName',
                                                     variantSetName).build())

    interface.appendOp('StaticSceneCreate', sscb.build())
Example #11
0
def buildOpChain(self, interface):
    interface.appendOp("PxrUsdInResolveMaterialBindings",
            FnAttribute.GroupBuilder()
            .set("purpose", interface.buildAttrFromParam(
                    self.getParameter('purpose')))
            .set("omitIfParentValueMatches", interface.buildAttrFromParam(
                    self.getParameter('omitIfParentValueMatches'),
                            numberType=FnAttribute.IntAttribute))
            .build())
Example #12
0
def buildPxrUsdInOpArgsAtGraphState(self, graphState):
    gb = FnAttribute.GroupBuilder()
    
    frameTime = graphState.getTime()
    
    gb.set('fileName',
            self.getParameter('fileName').getValue(frameTime))
    gb.set('location',
            self.getParameter('location').getValue(frameTime))

    gb.set('isolatePath',
            self.getParameter('isolatePath').getValue(frameTime))

    gb.set('variants',
            self.getParameter('variants').getValue(frameTime))

    gb.set('ignoreLayerRegex',
            self.getParameter('ignoreLayerRegex').getValue(frameTime))

    gb.set('motionSampleTimes',
            self.getParameter('motionSampleTimes').getValue(frameTime))

    gb.set('verbose',
            int(self.getParameter('verbose').getValue(frameTime)))
    
    gb.set('instanceMode',
            self.getParameter('instanceMode').getValue(frameTime))
    
    gb.set('prePopulate',
            int(self.getParameter('prePopulate').getValue(frameTime)))
    

    sessionValues = (
            graphState.getDynamicEntry("var:pxrUsdInSession"))
    if isinstance(sessionValues, FnAttribute.GroupAttribute):
        gb.set('session', sessionValues)

    
    gb.set('system', graphState.getOpSystemArgs())
    gb.set('processStageWideQueries', FnAttribute.IntAttribute(1))
    
    gb.set('setOpArgsToInfo', FnAttribute.IntAttribute(1))
    

    # check for any extra attributes or namespaces set downstream
    # via graph state
    extra = graphState.getDynamicEntry('var:usdExtraAttributesOrNamespaces')
    if extra:
        gb.set('extraAttributesOrNamespaces', extra)

    argsOverride = graphState.getDynamicEntry('var:pxrUsdInArgs')
    if isinstance(argsOverride, FnAttribute.GroupAttribute):
        gb.update(argsOverride)

    pxrUsdInArgs = gb.build()
    
    return pxrUsdInArgs
Example #13
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 stripBlacklistAttrs(attrs, blacklist):
    """
    Strip blacklisted attributes from the given attributes. Examples
    of blacklisted attributes are internal-only attributes or ones that
    may change depending on the context in which this test is executed.
    """
    gb = FnAttribute.GroupBuilder()
    gb.update(attrs)

    for attrName in blacklist:
        gb.delete(attrName)

    return gb.build()
    def buildOpChain(node, interface):
        """
        Configures the Ops to represent the current state of the node.
        The calling mechanism in Node3D takes are of ensuring that
        the underlying Op network is only updated if Op Args and types
        have changed.

        @type node: C{Nodes3DAPI.NodeTypeBuilder.SubdividedSpace}
        @type interface: C[Nodes3DAPI.NodeTypeBuilder.BuildChainInterface}
        @param node: The node to build the Op and OpArgs from (ie: an instance
        of our node).
        @param interface: The interface that will configure the Ops in the
        underlying Op network.
        """

        # Ensure the runtime doesn't error for us if there are no inputs on the
        # Node - as we want to allow it to exist in isolation. The default is 1
        interface.setMinRequiredInputs(0)

        # We first need the current time for parameter value queries
        frameTime = interface.getGraphState().getTime()

        # Get the parameters from our node
        maxDepthParam = node.getParameter("maxDepth")
        subdivParam = node.getParameter("subdivisions")
        locationParam = node.getParameter("location")

        if not locationParam or not maxDepthParam or not subdivParam:
            raise RuntimeError("Missing node parameters, require " +
                               "'location', 'maxdepth' and 'subdivisions'")

        # Build the Op args from our node
        argsGb = FnAttribute.GroupBuilder()
        argsGb.set("maxDepth",
                   FnAttribute.IntAttribute(maxDepthParam.getValue(frameTime)))
        argsGb.set("subdivisions",
                   FnAttribute.IntAttribute(subdivParam.getValue(frameTime)))

        # We want to use the StaticSceneCreate Op to build the parent
        # hierarchy, so that our op only has to worry about generating its
        # children. Its args are somewhat complex, but fortunately, there
        # is a helper class that makes it all much easier.

        rootLocation = locationParam.getValue(frameTime)

        sscb = FnGeolibServices.OpArgsBuilders.StaticSceneCreate()
        sscb.addSubOpAtLocation(rootLocation, "SubdividedSpace",
                                argsGb.build())

        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())
Example #17
0
def registerAutoLookfileAssign():
    """
    Registers a new AutoLookfileAssign node type using the NodeTypeBuilder utility
    class.
    """

    from Katana import Nodes3DAPI
    from Katana import FnAttribute

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

        @type node: C{Nodes3DAPI.NodeTypeBuilder.AutoLookfileAssign}
        @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(1)

        argsGb = FnAttribute.GroupBuilder()

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


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

    # Add input port
    nodeTypeBuilder.setInputPortNames(("in",))

    # Build the node's parameters
    gb = FnAttribute.GroupBuilder()

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

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

    # Build the new node type
    nodeTypeBuilder.build()
Example #18
0
def buildOpChain(self, interface):
    interface.setExplicitInputRequestsEnabled(True)
    
    graphState = interface.getGraphState()
    
    frameTime = interface.getFrameTime()
    
    location = self.getParameter("location").getValue(frameTime)
    
    variantSetName = ''
    if self.getParameter("args.variantSetName.enable").getValue(frameTime):
        variantSetName = self.getParameter("args.variantSetName.value").getValue(
                frameTime)
    
    
    variantSelection = None
    if self.getParameter("args.variantSelection.enable").getValue(frameTime):
         variantSelection = self.getParameter(
                "args.variantSelection.value").getValue(frameTime)
    
    if location and variantSetName and variantSelection is not None:
        entryName = FnAttribute.DelimiterEncode(location)
        entryPath = "variants." + entryName + "." + variantSetName
        
        valueAttr = FnAttribute.StringAttribute(variantSelection)
        gb = FnAttribute.GroupBuilder()
        gb.set(entryPath, valueAttr)
        
        for addLocParam in self.getParameter(
                'additionalLocations').getChildren():
            location = addLocParam.getValue(frameTime)
            if location:
                entryName = FnAttribute.DelimiterEncode(location)
                entryPath = "variants." + entryName + "." + variantSetName
                gb.set(entryPath, valueAttr)
        
        
        existingValue = (
                interface.getGraphState().getDynamicEntry("var:pxrUsdInSession"))
        
        if isinstance(existingValue, FnAttribute.GroupAttribute):
            gb.deepUpdate(existingValue)
        
        graphState = (graphState.edit()
                .setDynamicEntry("var:pxrUsdInSession", gb.build())
                .build())
        
    
    interface.addInputRequest("in", graphState)
Example #19
0
    def build_node_parameters(self):
        """
        """
        module_logger.debug("PassResolve - build_node_parameters()")

        group_builder = FnAttribute.GroupBuilder()
        # group_builder.set("node_version", 1)
        group_builder.set("activePassLocation", "")
        group_builder.set("setupRenderNodeScript", "")

        parameters_hints = self.get_parameters_hints()

        for parameter in parameters_hints:
            self.setHintsForParameter(parameter, parameters_hints[parameter])

        self.setParametersTemplateAttr(group_builder.build())
Example #20
0
    def buildViewerTagSetOpChain(node, interface):
        """
        Defines the callback function used to define the Ops chain for the
        node type being registered.

        @type node: C{Nodes3DAPI.NodeTypeBuilder.Messer}
        @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(1)

        argsGb = FnAttribute.GroupBuilder()

        # Parse the CEL parameter
        celParam = node.getParameter('CEL')
        if celParam:
            argsGb.set('CEL', celParam.getValue(frameTime))

        # Parse the color parameter
        colorRParam = node.getParameter('color.red')
        if colorRParam:
            argsGb.set('color.red', colorRParam.getValue(frameTime))
        colorGParam = node.getParameter('color.green')
        if colorGParam:
            argsGb.set('color.green', colorGParam.getValue(frameTime))
        colorBParam = node.getParameter('color.blue')
        if colorBParam:
            argsGb.set('color.blue', colorBParam.getValue(frameTime))
        colorParam = node.getParameter('color')

        # Parse the pickable parameter
        pickableParam = node.getParameter('pickable')
        if pickableParam:
            argsGb.set(
                'pickable',
                FnAttribute.IntAttribute(pickableParam.getValue(frameTime)))

        # Add the Messer Op to the Ops chain
        interface.appendOp('ViewerTagSet', argsGb.build())
    def build_node_parameters(self):
        """
        """
        module_logger.debug("RendererOutputExport - build_node_parameters()")

        group_builder = FnAttribute.GroupBuilder()
        # group_builder.set("node_version", 1)
        group_builder.set("filename", "")
        group_builder.set("Export.expandProcedurals", True)
        group_builder.set("Debug.logLevel", 20)
        group_builder.set("exportRendererOutput", "")

        parameters_hints = self.get_parameters_hints()

        for parameter in parameters_hints:
            self.setHintsForParameter(parameter, parameters_hints[parameter])

        self.setParametersTemplateAttr(group_builder.build())
def buildPointCloudCreateOpChain(node, interface):
	interface.setMinRequiredInputs(0)
	argsGb = FnAttribute.GroupBuilder()

	targetLocationParam = node.getParameter('location')
	generateTypeParam = node.getParameter('generateType')
	fileTypeParam = node.getParameter('fileType')
	filePathParam = node.getParameter('filePath')
	numPointsParam = node.getParameter('numPoints')
	splitPointcloudLocationsParam = node.getParameter('splitPointcloudLocations')
	pointWidthTypeParam = node.getParameter('pointWidthType')
	constantPointWidthParam = node.getParameter('constantPointWidth')
	randomPointWidthMinParam = node.getParameter('randomPointWidthMin')
	randomPointWidthMaxParam = node.getParameter('randomPointWidthMax')
	areaSpreadParamX = node.getParameter('areaSpread.i0')
	areaSpreadParamY = node.getParameter('areaSpread.i1')
	areaSpreadParamZ = node.getParameter('areaSpread.i2')
	extraFloatPrimvarTypeParam = node.getParameter('extraFloatPrimvarType')
	extraVectorPrimvarTypeParam = node.getParameter('extraVectorPrimvarType')
	extraColorPrimvarTypeParam = node.getParameter('extraColorPrimvarType')
	if targetLocationParam:
		location = targetLocationParam.getValue(0)

		locationPaths = location[1:].split('/')[1:]
		attrsHierarchy = 'c.' + '.c.'.join(locationPaths)

		argsGb.set(attrsHierarchy + '.a.generateType', FnAttribute.IntAttribute(generateTypeParam.getValue(0)))
		if generateTypeParam.getValue(0) == 1:
			argsGb.set(attrsHierarchy + '.a.fileType', FnAttribute.IntAttribute(fileTypeParam.getValue(0)))
			argsGb.set(attrsHierarchy + '.a.filePath', FnAttribute.StringAttribute(filePathParam.getValue(0)))
		else:
			argsGb.set(attrsHierarchy + '.a.numPoints', FnAttribute.IntAttribute(numPointsParam.getValue(0)))
			argsGb.set(attrsHierarchy + '.a.splitPointcloudLocations', FnAttribute.IntAttribute(splitPointcloudLocationsParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.pointWidthType', FnAttribute.IntAttribute(pointWidthTypeParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.constantPointWidth', FnAttribute.FloatAttribute(constantPointWidthParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.randomPointWidthMin', FnAttribute.FloatAttribute(randomPointWidthMinParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.randomPointWidthMax', FnAttribute.FloatAttribute(randomPointWidthMaxParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.areaSpread', FnAttribute.FloatAttribute([areaSpreadParamX.getValue(0), areaSpreadParamY.getValue(0), areaSpreadParamZ.getValue(0)], 3))
		argsGb.set(attrsHierarchy + '.a.extraFloatPrimvarType', FnAttribute.IntAttribute(extraFloatPrimvarTypeParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.extraVectorPrimvarType', FnAttribute.IntAttribute(extraVectorPrimvarTypeParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.extraColorPrimvarType', FnAttribute.IntAttribute(extraColorPrimvarTypeParam.getValue(0)))

	interface.appendOp('PointCloudCreate', argsGb.build())
Example #23
0
def buildOpChain(self, interface):
    interface.setExplicitInputRequestsEnabled(True)

    graphState = interface.getGraphState()
    frameTime = interface.getFrameTime()
    locationsParam = self.getParameter("locations")

    locations = [
        y for y in (x.getValue(frameTime)
                    for x in locationsParam.getChildren()) if y
    ]

    if locations:
        existingValue = (graphState.getDynamicEntry("var:pxrUsdInSession")
                         or FnAttribute.GroupAttribute())

        # later nodes set to 'replace' win out
        maskIsFinal = existingValue.getChildByName('maskIsFinal')
        if not maskIsFinal:

            gb = FnAttribute.GroupBuilder()

            gb.update(existingValue)

            mode = self.getParameter('mode').getValue(frameTime)

            if mode == 'replace':
                gb.set('mask', FnAttribute.StringAttribute(locations))
                gb.set('maskIsFinal', 1)
            else:
                existingLocationsAttr = existingValue.getChildByName('mask')
                if isinstance(existingLocationsAttr,
                              FnAttribute.StringAttribute):
                    locations.extend(existingLocationsAttr.getNearestSample(0))

                gb.set('mask', FnAttribute.StringAttribute(locations))

            graphState = (graphState.edit().setDynamicEntry(
                "var:pxrUsdInSession", gb.build()).build())

    interface.addInputRequest("in", graphState)
Example #24
0
    def buildAutoLookfileAssignOpChain(node, interface):
        """
        Defines the callback function used to create the Ops chain for the
        node type being registered.

        @type node: C{Nodes3DAPI.NodeTypeBuilder.AutoLookfileAssign}
        @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(1)

        argsGb = FnAttribute.GroupBuilder()

        # Add the AutoLookfileAssign Op to the Ops chain
        interface.appendOp('AutoLookfileAssign', argsGb.build())
Example #25
0
    def buildWalterAssignOpChain(node, interface):
        """
        Defines the callback function used to define the Ops chain for the
        node type being registered.

        @type node: C{Nodes3DAPI.NodeTypeBuilder.WalterAssign}
        @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(1)

        argsGb = FnAttribute.GroupBuilder()

        # Parse the CEL parameter
        parm = node.getParameter('CEL')
        if parm:
            argsGb.set('CEL', parm.getValue(frameTime))

        # Parse the root parameter
        parm = node.getParameter('root')
        if parm:
            argsGb.set('root', parm.getValue(frameTime))

        # Parse the abcAsset parameter
        parm = node.getParameter('abcAsset')
        if parm:
            argsGb.set('fileName', parm.getValue(frameTime))

        # Add the WalterAssign Op to the Ops chain
        interface.appendOp('WalterAssign', argsGb.build())
def buildSphereMakerOpChain(node, interface):
    """
    Defines the callback function used to create the Ops chain for the
    node type being registered.

    @type node: C{Nodes3DAPI.Node3D}
    @type interface: C{Nodes3DAPI.NodeTypeBuilder.OpChainInterface}
    @param node: The node requesting the op chain.
    @param interface: The interface providing the functions needed to set
        up the Ops chain for the given node.
    """
    # Set the minimum number of input ports
    interface.setMinRequiredInputs(0)

    # Get the current graph state and frame time
    graphState = interface.getGraphState()
    frameTime = graphState.getTime()

    # Compute the actual frame time we want to use
    modifiedFrameTime = GetModifiedFrameTime(node, frameTime)
    modGraphState = graphState.edit().setTime(modifiedFrameTime).build()
    systemAttr = modGraphState.getOpSystemArgs()

    locationPath = node.getParameter('location').getValue(frameTime)
    numberOfSpheres = node.getParameter('numberOfSpheres').getValue(frameTime)

    procArgsGb = FnAttribute.GroupBuilder()
    procArgsGb.set('args.system', systemAttr)
    procArgsGb.set('generatorType', 'SphereMaker')
    procArgsGb.set('args.numberOfSpheres', numberOfSpheres)

    sscb = FnGeolibServices.OpArgsBuilders.StaticSceneCreate()
    sscb.addSubOpAtLocation(locationPath, 'ScenegraphGeneratorHost',
                            procArgsGb.build())

    interface.appendOp('StaticSceneCreate', sscb.build())
Example #27
0
inserting your own implicit resolver Op that will determine if a location
should be resolved.

Side effects of unresolved locations include:
    - Materials not displaying on geometry
    - Light manipulators not being available
    - Incorrect light representation by the light viewer modifier

"""
from Katana import (
    Nodes3DAPI,
    FnAttribute,
    RenderingAPI,
)

requiredAttrs = FnAttribute.GroupBuilder()

#-------------------------------------------------------------------------------
# Match by name - Specify which attribute names to search for.
#-------------------------------------------------------------------------------

requiredAttrs.set("material.resolveInViewer", FnAttribute.IntAttribute(1))
requiredAttrs.set("material.lightShader", FnAttribute.NullAttribute())
requiredAttrs.set("material.viewerSurfaceShader", FnAttribute.NullAttribute())
requiredAttrs.set("material.parameters", FnAttribute.NullAttribute())
requiredAttrs.set("material.reference", FnAttribute.NullAttribute())

# Get the names of all known renderer plug-ins for light shaders
rendererPluginNames = RenderingAPI.RenderPlugins.GetRendererPluginNames()
for rendererPluginName in rendererPluginNames:
    requiredAttrs.set("material.%sLightShader" % rendererPluginName,
Example #28
0
from Katana import (
    Nodes3DAPI,
    FnAttribute,
    FnGeolibServices,
)


def getScenegraphLocation(self, frameTime):
    return self.getParameter('location').getValue(frameTime)


# node type builder for a our new node type
nb = Nodes3DAPI.NodeTypeBuilder('PxrUsdIn')

# group builder for the node parameters
gb = FnAttribute.GroupBuilder()

gb.set('fileName', '')
nb.setHintsForParameter('fileName', {
    'help': 'The USD file to read.',
})

gb.set('location', '/root/world/geo')
nb.setHintsForParameter(
    'location', {
        'widget': 'scenegraphLocation',
        'help': 'The Katana scenegraph location to load the USD contents.',
    })

gb.set('isolatePath', '')
nb.setHintsForParameter('isolatePath', {
Example #29
0
def registerSphereMaker():
    """
    Registers a new SphereMaker node type using the NodeTypeBuilder utility
    class.
    """

    from Katana import Nodes3DAPI
    from Katana import FnAttribute

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

        @type node: C{Nodes3DAPI.NodeTypeBuilder.SphereMaker}
        @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')
        numberOfSpheresParam = node.getParameter('numberOfSpheres')
        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
            # spheres to be generated.
            # See the Op source code for more details
            locationPaths = location[1:].split('/')[1:]
            attrsHierarchy = 'c.' + '.c.'.join(locationPaths)
            argsGb.set(
                attrsHierarchy + '.a.numberOfSpheres',
                FnAttribute.IntAttribute(
                    numberOfSpheresParam.getValue(frameTime)))

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

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

    # Build the node's parameters
    gb = FnAttribute.GroupBuilder()
    gb.set('location',
           FnAttribute.StringAttribute('/root/world/geo/SphereMaker'))
    gb.set('numberOfSpheres', FnAttribute.IntAttribute(20))

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

    # Set parameter hints
    nodeTypeBuilder.setHintsForParameter('location',
                                         {'widget': 'scenegraphLocation'})
    nodeTypeBuilder.setHintsForParameter('numberOfSpheres', {'int': True})

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

    # Build the new node type
    nodeTypeBuilder.build()
			argsGb.set(attrsHierarchy + '.a.numPoints', FnAttribute.IntAttribute(numPointsParam.getValue(0)))
			argsGb.set(attrsHierarchy + '.a.splitPointcloudLocations', FnAttribute.IntAttribute(splitPointcloudLocationsParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.pointWidthType', FnAttribute.IntAttribute(pointWidthTypeParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.constantPointWidth', FnAttribute.FloatAttribute(constantPointWidthParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.randomPointWidthMin', FnAttribute.FloatAttribute(randomPointWidthMinParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.randomPointWidthMax', FnAttribute.FloatAttribute(randomPointWidthMaxParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.areaSpread', FnAttribute.FloatAttribute([areaSpreadParamX.getValue(0), areaSpreadParamY.getValue(0), areaSpreadParamZ.getValue(0)], 3))
		argsGb.set(attrsHierarchy + '.a.extraFloatPrimvarType', FnAttribute.IntAttribute(extraFloatPrimvarTypeParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.extraVectorPrimvarType', FnAttribute.IntAttribute(extraVectorPrimvarTypeParam.getValue(0)))
		argsGb.set(attrsHierarchy + '.a.extraColorPrimvarType', FnAttribute.IntAttribute(extraColorPrimvarTypeParam.getValue(0)))

	interface.appendOp('PointCloudCreate', argsGb.build())

nodeTypeBuilder = Nodes3DAPI.NodeTypeBuilder('PointCloudCreate')

gb = FnAttribute.GroupBuilder()
gb.set('location', FnAttribute.StringAttribute('/root/world/geo/pointcloud1'))
gb.set('generateType', FnAttribute.IntAttribute(0))
gb.set('fileType', FnAttribute.IntAttribute(0))
gb.set('filePath', FnAttribute.StringAttribute(""))
gb.set('numPoints', FnAttribute.IntAttribute(10000))
gb.set('splitPointcloudLocations', FnAttribute.IntAttribute(0))
gb.set('pointWidthType', FnAttribute.IntAttribute(0))
gb.set('constantPointWidth', FnAttribute.FloatAttribute(0.1))
gb.set('randomPointWidthMin', FnAttribute.FloatAttribute(0.1))
gb.set('randomPointWidthMax', FnAttribute.FloatAttribute(0.2))
gb.set('areaSpread', FnAttribute.FloatAttribute([20.0, 20.0, 20.0], 3))
gb.set('extraFloatPrimvarType', FnAttribute.IntAttribute(0))
gb.set('extraVectorPrimvarType', FnAttribute.IntAttribute(0))
gb.set('extraColorPrimvarType', FnAttribute.IntAttribute(0))