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()
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#
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.',
    })
Ejemplo n.º 4
0
def registerBgeoIn():
    """
    Registers a new BgeoIn node type using the NodeTypeBuilder utility
    class.
    """

    from Katana import Nodes3DAPI
    from Katana import AssetAPI
    from Katana import FnAttribute
    from Katana import FnGeolibServices

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

        @type node: C{Nodes3DAPI.NodeTypeBuilder.BgeoIn}
        @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')
        fileNameParam = node.getParameter('fileName')
        makeFacesetsParam = node.getParameter('makeFacesets')
        reportEmptyParam = node.getParameter('reportEmpty')
        computeBoundParam = node.getParameter('computePointCloudBound')
        createSubdParam = node.getParameter('createSubd')
        checkVersionParam = node.getParameter('checkVersion')

        # resolve file path so that it can include frame number replacement
        # i.e. %04d
        filePath = fileNameParam.getValue(frameTime)
        fileSequencePlugin = AssetAPI.GetDefaultFileSequencePlugin()
        if fileSequencePlugin and fileSequencePlugin.isFileSequence(filePath):
            fileSequence = fileSequencePlugin.getFileSequence(filePath)
            resolvedPath = fileSequence.getResolvedPath(int(frameTime))
        else:
            resolvedPath = filePath

        argsGb.set('fileName', FnAttribute.StringAttribute(resolvedPath))
        argsGb.set(
            'makeFacesets',
            FnAttribute.IntAttribute(makeFacesetsParam.getValue(frameTime)))
        argsGb.set(
            'reportEmpty',
            FnAttribute.IntAttribute(reportEmptyParam.getValue(frameTime)))
        argsGb.set(
            'computePointCloudBound',
            FnAttribute.IntAttribute(computeBoundParam.getValue(frameTime)))
        argsGb.set(
            'createSubd',
            FnAttribute.IntAttribute(createSubdParam.getValue(frameTime)))
        argsGb.set(
            'checkVersion',
            FnAttribute.IntAttribute(checkVersionParam.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, 'BgeoIn', argsGb.build())

        interface.appendOp('StaticSceneCreate', sscb.build())

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

    nodeTypeBuilder.setHintsForNode({'help': buildHelp("BgeoInHelp.txt")})

    # Build the node's parameters
    gb = FnAttribute.GroupBuilder()
    gb.set('location', FnAttribute.StringAttribute('/root/world/geo/BgeoIn'))
    gb.set('fileName', FnAttribute.StringAttribute(''))
    gb.set('makeFacesets', FnAttribute.IntAttribute(0))
    gb.set('reportEmpty', FnAttribute.IntAttribute(1))
    gb.set('computePointCloudBound', FnAttribute.IntAttribute(0))
    gb.set('createSubd', FnAttribute.IntAttribute(1))
    gb.set('checkVersion', FnAttribute.IntAttribute(1))

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

    # Set parameter hints
    nodeTypeBuilder.setHintsForParameter('location', {
        'label': 'Location',
        'widget': 'scenegraphLocation'
    })
    nodeTypeBuilder.setHintsForParameter('fileName', {
        'label': 'File Name',
        'widget': 'fileInput'
    })
    nodeTypeBuilder.setHintsForParameter(
        'makeFacesets', {
            'label': 'Make Facesets',
            'widget': 'checkBox',
            'help': 'Create facesets from primitive groups.'
        })
    nodeTypeBuilder.setHintsForParameter(
        'reportEmpty', {
            'label': 'Report Empty Geometry',
            'widget': 'checkBox',
            'help': 'Report empty BGEO files (i.e. no geometry) as an error.'
        })
    nodeTypeBuilder.setHintsForParameter(
        'computePointCloudBound', {
            'label':
            'Compute Point Cloud Bound',
            'widget':
            'checkBox',
            'help':
            'Compute the bound based on point P and width attributes, ' +
            'instead of using the embedded header bound. This will prevent ' +
            'points at the edges of the bound from be clipped. Enabling this '
            + 'option prevents deferred loading of the BGEO file.'
        })
    nodeTypeBuilder.setHintsForParameter(
        'createSubd', {
            'label': 'Create Subdivision Surfaces',
            'widget': 'checkBox',
            'help': 'Create subdivision surfaces for polymesh primitives.'
        })
    nodeTypeBuilder.setHintsForParameter(
        'checkVersion', {
            'label':
            'Check Version',
            'widget':
            'checkBox',
            'help':
            'Verify the version in the bgeo file is compatible. ' +
            'Turn this off if you know the file is compatible regardless of ' +
            'the version it was written out from, i.e. from use of ' +
            'HOUDINIX_Y_GEO_COMPATIBILITY environment variables.'
        })

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

    # Build the new node type
    nodeTypeBuilder.build()
Ejemplo n.º 5
0
def registerViewerTagSet():
    """
    Registers a new node type using the NodeTypeBuilder utility class.
    """

    from Katana import Nodes3DAPI
    from Katana import FnAttribute

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

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

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

    # Build the node's parameters
    gb = FnAttribute.GroupBuilder()
    gb.set('CEL', FnAttribute.StringAttribute(''))
    colorb = FnAttribute.GroupBuilder()
    colorb.set('red', FnAttribute.FloatAttribute(0.0))
    colorb.set('green', FnAttribute.FloatAttribute(0.0))
    colorb.set('blue', FnAttribute.FloatAttribute(0.0))
    colorg = colorb.build()
    gb.set("color", colorg)
    gb.set('pickable', FnAttribute.IntAttribute(1))
    # Set the parameters template
    nodeTypeBuilder.setParametersTemplateAttr(gb.build())
    # Set parameter hints
    nodeTypeBuilder.setHintsForParameter('CEL', {'widget': 'cel'})
    nodeTypeBuilder.setHintsForParameter(
        'color.red', {'help': "set viewer.default.annotation.color.red value"})
    nodeTypeBuilder.setHintsForParameter(
        'color.green',
        {'help': "set viewer.default.annotation.color.green value"})
    nodeTypeBuilder.setHintsForParameter(
        'color.blue',
        {'help': "set viewer.default.annotation.color.blue value"})
    nodeTypeBuilder.setHintsForParameter(
        'pickable', {
            'widget': 'checkBox',
            'help': 'Whether you can select object in viewer'
        })

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

    # Build the new node type
    nodeTypeBuilder.build()
Ejemplo n.º 6
0
def registerSubdividedSpaceOp():
    """
    Registers the SubdividedSpace Op using the NodeTypeBuilder.
    This is a helper class that takes care of registering a suitable
    node graph node type, and configuring it to call the supplied method
    in order to build the Op chain that is used to represent the
    node in the Op Graph.
    """

    from Katana import Nodes3DAPI
    from Katana import FnAttribute, FnGeolibServices

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

    # Here we need to define the parameters for the node, and register the op
    # chain creation callback function

    nodeBuilder = Nodes3DAPI.NodeTypeBuilder("SubdividedSpace")

    # If we wanted to merge with incoming scene, we could simply allow the
    # node to have an input. Unless you delete locations in your Op, any
    # existing locations will pass-through. It is encouraged though to avoid
    # long chains of Ops, as it makes multi-threading and caching less
    # efficient, so for 'Generator' Ops, no input is preferable.
    # nodeBuilder.setInputPortNames( ("in",) )

    # Parameters can be described by a group attribute
    paramGb = FnAttribute.GroupBuilder()
    paramGb.set("location",
                FnAttribute.StringAttribute("/root/world/geo/dividedSpace"))
    paramGb.set("maxDepth", FnAttribute.IntAttribute(4))
    paramGb.set("subdivisions", FnAttribute.IntAttribute(1))

    nodeBuilder.setParametersTemplateAttr(paramGb.build())

    nodeBuilder.setHintsForParameter("location",
                                     {'widget': 'newScenegraphLocation'})

    # Register our Op build function
    nodeBuilder.setBuildOpChainFnc(buildOpChain)

    # Create the new Node3D type
    nodeBuilder.build()
Ejemplo n.º 7
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()
Ejemplo n.º 8
0
def registerMaterialDescribe():
    def buildMaterialDescribeOpChain(node, interface):
        interface.setMinRequiredInputs(0)

        baseLocationParam = node.getParameter('baseLocation')
        baseLocationString = baseLocationParam.getValue(0)

        materialNameParam = node.getParameter('materialName')
        materialNameString = materialNameParam.getValue(0)

        descriptionParam = node.getParameter('description')
        descriptionString = descriptionParam.getValue(0)

        specRoughnessValuesConversionTypeParam = node.getParameter(
            'specRoughnessValuesConversionType')
        specRoughnessValuesConversionTypeValue = specRoughnessValuesConversionTypeParam.getValue(
            0)

        enableCausticsInArnoldParam = node.getParameter(
            'enableCausticsInArnold')
        enableCausticsInArnoldValue = bool(
            enableCausticsInArnoldParam.getValue(0))

        materialDefinition = parseMaterialDescription(descriptionString)

        rendererListGroupParam = node.getParameter('rendererList')
        renderersToMakeMatsFor = []
        numRendererItems = rendererListGroupParam.getNumChildren()
        for i in range(0, numRendererItems):
            subItemParam = rendererListGroupParam.getChildByIndex(i)
            intValue = subItemParam.getValue(0)
            if intValue == 0:
                continue

            rendererName = MaterialPlugin.pluginsNameList[i]
            renderersToMakeMatsFor.append(rendererName)

            materialLocationPath = os.path.join(baseLocationString,
                                                rendererName,
                                                materialNameString)

            materialStaticSCB = FnGeolibServices.OpArgsBuilders.StaticSceneCreate(
            )
            materialStaticSCB.createEmptyLocation(materialLocationPath)
            materialStaticSCB.setAttrAtLocation(
                materialLocationPath, 'type',
                FnAttribute.StringAttribute('material'))

            # invoke the renderer material plugin to create its attributes on the location...
            pluginResult = MaterialPlugin.pluginsDict[rendererName]
            pluginInstance = pluginResult[2]
            # todo: use keyword / dict for all these options...
            pluginInstance.generateMaterialAttributes(
                materialDefinition, materialStaticSCB, materialLocationPath,
                specRoughnessValuesConversionTypeValue,
                enableCausticsInArnoldValue)

            interface.appendOp("StaticSceneCreate", materialStaticSCB.build())

    nodeTypeBuilder = Nodes3DAPI.NodeTypeBuilder('MaterialDescribe')

    # build params
    gb = FnAttribute.GroupBuilder()
    gb.set('baseLocation', FnAttribute.StringAttribute('/root/materials/'))
    gb.set('materialName', FnAttribute.StringAttribute('material1'))

    gb.set('description',
           FnAttribute.StringAttribute('diffColour = RGB(0.18);'))

    gb.set('specRoughnessValuesConversionType', FnAttribute.IntAttribute(1))

    # it's pretty annoying that this isn't an Arnold option, but...
    gb.set('enableCausticsInArnold', FnAttribute.IntAttribute(1))

    rendererListGb = FnAttribute.GroupBuilder()
    for pluginName in MaterialPlugin.pluginsNameList:
        rendererListGb.set(pluginName, FnAttribute.IntAttribute(1))
    gb.set('rendererList', rendererListGb.build())

    nodeTypeBuilder.setParametersTemplateAttr(gb.build())
    nodeTypeBuilder.setHintsForParameter('description',
                                         {'widget': 'scriptEditor'})

    nodeTypeBuilder.setHintsForParameter(
        'specRoughnessValuesConversionType', {
            'widget':
            'mapper',
            'options':
            'none - as raw value per renderer:0|convert to microfacet alpha:1|convert to sqr(roughness):2'
        })

    nodeTypeBuilder.setHintsForParameter('enableCausticsInArnold',
                                         {'widget': 'checkBox'})

    for pluginName in MaterialPlugin.pluginsNameList:
        nodeTypeBuilder.setHintsForParameter('rendererList.' + pluginName,
                                             {'widget': 'checkBox'})

    nodeTypeBuilder.setInputPortNames(('in', ))

    nodeTypeBuilder.setBuildOpChainFnc(buildMaterialDescribeOpChain)

    nodeTypeBuilder.build()
Ejemplo n.º 9
0
# language governing permissions and limitations under the Apache License.
#
from Katana import (
    Nodes3DAPI,
    NodegraphAPI,
    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.',
        'widget': 'assetIdInput',
        'fileTypes': 'usd|usda|usdc',
    })

gb.set('location', '/root/world/geo')
nb.setHintsForParameter(
    'location', {
def registerSpeedTreeIn():
    """
    Registers a new SpeedTreeIn node type using the NodeTypeBuilder utility
    class.
    """

    from Katana import Nodes3DAPI
    from Katana import FnAttribute, FnGeolibServices

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

        @type node: C{Nodes3DAPI.NodeTypeBuilder.SpeedTreeIn}
        @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')
        argsGb.set(
            "location",
            FnAttribute.StringAttribute(locationParam.getValue(frameTime)))

        srtFileParam = node.getParameter("srtFile")
        argsGb.set(
            "srtFile",
            FnAttribute.StringAttribute(srtFileParam.getValue(frameTime)))

        globalMotionParam = node.getParameter('useGlobalMotion')
        argsGb.set(
            "useGlobalMotion",
            FnAttribute.IntAttribute(globalMotionParam.getValue(frameTime)))

        currentFrameParam = node.getParameter('currentFrame')
        argsGb.set(
            "currentFrame",
            FnAttribute.FloatAttribute(currentFrameParam.getValue(frameTime)))

        globalMotionParam = node.getParameter('enableMotionBlur')
        argsGb.set(
            "enableMotionBlur",
            FnAttribute.IntAttribute(globalMotionParam.getValue(frameTime)))

        motionSamplesParam = node.getParameter('motionSamples')
        motionSamples = []
        for ci in range(0, motionSamplesParam.getNumChildren()):
            motionSamples = motionSamples + [
                motionSamplesParam.getChildByIndex(ci).getValue(frameTime)
            ]
        if motionSamples is not None and len(motionSamples) > 0:
            opMotionSamplesParam = FnAttribute.FloatAttribute(motionSamples)
            argsGb.set("motionSamples", opMotionSamplesParam)

        fpsParam = node.getParameter('fps')
        argsGb.set("fps",
                   FnAttribute.FloatAttribute(fpsParam.getValue(frameTime)))

        globalFrequencyParam = node.getParameter('globalFrequency')
        argsGb.set(
            "globalFrequency",
            FnAttribute.FloatAttribute(
                globalFrequencyParam.getValue(frameTime)))

        gustFrequencyParam = node.getParameter('gustFrequency')
        argsGb.set(
            "gustFrequency",
            FnAttribute.FloatAttribute(gustFrequencyParam.getValue(frameTime)))

        windSpeedParam = node.getParameter('windSpeed')
        argsGb.set(
            "windSpeed",
            FnAttribute.FloatAttribute(windSpeedParam.getValue(frameTime)))

        windDirectionGb = FnAttribute.GroupBuilder()
        windDirectionGb.set(
            'x',
            FnAttribute.FloatAttribute(
                node.getParameter('windDirection.x').getValue(frameTime)))
        windDirectionGb.set(
            'y',
            FnAttribute.FloatAttribute(
                node.getParameter('windDirection.y').getValue(frameTime)))
        windDirectionGb.set(
            'z',
            FnAttribute.FloatAttribute(
                node.getParameter('windDirection.z').getValue(frameTime)))
        argsGb.set("windDirection", windDirectionGb.build())

        windTypeParam = node.getParameter('windType')
        argsGb.set("windType",
                   FnAttribute.IntAttribute(windTypeParam.getValue(frameTime)))

        LODTypeParam = node.getParameter('LODType')
        argsGb.set("LODType",
                   FnAttribute.IntAttribute(LODTypeParam.getValue(frameTime)))

        LODSmoothTypeParam = node.getParameter('LODSmoothType')
        argsGb.set(
            "LODSmoothType",
            FnAttribute.IntAttribute(LODSmoothTypeParam.getValue(frameTime)))

        speedKeyFrameParam = node.getParameter('speedKeyFrame')
        speedKeyFrames = []
        for ci in range(0, speedKeyFrameParam.getNumChildren()):
            speedKeyFrames = speedKeyFrames + [
                speedKeyFrameParam.getChildByIndex(ci).getValue(frameTime)
            ]
        if speedKeyFrames is not None and len(speedKeyFrames) > 0:
            opSpeedKeyFrameParam = FnAttribute.FloatAttribute(speedKeyFrames)
            argsGb.set("speedKeyFrame", opSpeedKeyFrameParam)

        speedResponseTimeParam = node.getParameter('speedResponseTime')
        speedResponseTime = []
        for ci in range(0, speedResponseTimeParam.getNumChildren()):
            speedResponseTime = speedResponseTime + [
                speedResponseTimeParam.getChildByIndex(ci).getValue(frameTime)
            ]
        if speedResponseTime is not None and len(speedResponseTime) > 0:
            opSpeedResponseTimeParam = FnAttribute.FloatAttribute(
                speedResponseTime)
            argsGb.set("speedResponseTime", opSpeedResponseTimeParam)

        speedKeyValueParam = node.getParameter('speedKeyValue')
        speedKeyValue = []
        for ci in range(0, speedKeyValueParam.getNumChildren()):
            speedKeyValue = speedKeyValue + [
                speedKeyValueParam.getChildByIndex(ci).getValue(frameTime)
            ]
        if speedKeyValue is not None and len(speedKeyValue) > 0:
            opSpeedKeyValueParam = FnAttribute.FloatAttribute(speedKeyValue)
            argsGb.set("speedKeyValue", opSpeedKeyValueParam)

        direResponseTimeParam = node.getParameter('direResponseTime')
        direResponseTime = []
        for ci in range(0, direResponseTimeParam.getNumChildren()):
            direResponseTime = direResponseTime + [
                direResponseTimeParam.getChildByIndex(ci).getValue(frameTime)
            ]
        if direResponseTime is not None and len(direResponseTime) > 0:
            opDireResponseTimeParam = FnAttribute.FloatAttribute(
                direResponseTime)
            argsGb.set("direResponseTime", opDireResponseTimeParam)

        direKeyFrameParam = node.getParameter('direKeyFrame')
        direKeyFrame = []
        for ci in range(0, direKeyFrameParam.getNumChildren()):
            direKeyFrame = direKeyFrame + [
                direKeyFrameParam.getChildByIndex(ci).getValue(frameTime)
            ]
        if direKeyFrame is not None and len(direKeyFrame) > 0:
            opDireKeyFrameParam = FnAttribute.FloatAttribute(direKeyFrame)
            argsGb.set("direKeyFrame", opDireKeyFrameParam)

        direKeyValueParam = node.getParameter("direKeyValue")
        direKeyValue = []
        for ci in range(0, direKeyValueParam.getNumChildren()):
            direKeyValue = direKeyValue + [
                direKeyValueParam.getChildByIndex(ci).getValue(frameTime)
            ]
        if direKeyValue is not None and len(direKeyValue) > 0:
            opDireKeyValueParam = FnAttribute.FloatAttribute(direKeyValue, 3)
            argsGb.set("direKeyValue", opDireKeyValueParam)

        # Add the SpeedTree_In Op to the Ops chain
        rootLocation = locationParam.getValue(frameTime)

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

        interface.appendOp("StaticSceneCreate", sscb.build())

        # set expression on the currentFrame parameter
        node.getParameter('currentFrame').setExpression("frame")

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

    # Build the node's parameters
    gb = FnAttribute.GroupBuilder()
    gb.set('location',
           FnAttribute.StringAttribute('/root/world/geo/SpeedTreeProc'))
    gb.set('srtFile', FnAttribute.StringAttribute(""))

    gb.set('useGlobalMotion', FnAttribute.IntAttribute(0))
    gb.set('currentFrame', FnAttribute.FloatAttribute(1001.0))
    gb.set('enableMotionBlur', FnAttribute.IntAttribute(1))
    gb.set("motionSamples", FnAttribute.FloatAttribute([-0.25, 0.25], 1))

    gb.set('fps', FnAttribute.FloatAttribute(24.0))
    gb.set('globalFrequency', FnAttribute.FloatAttribute(0.0))
    gb.set('gustFrequency', FnAttribute.FloatAttribute(0.0))

    gb.set('windSpeed', FnAttribute.FloatAttribute(0.0))
    gb.set('windDirection.x', FnAttribute.FloatAttribute(1.0))
    gb.set('windDirection.y', FnAttribute.FloatAttribute(0.0))
    gb.set('windDirection.z', FnAttribute.FloatAttribute(0.0))

    gb.set('windType', FnAttribute.IntAttribute(6))
    gb.set('LODType', FnAttribute.IntAttribute(0))
    gb.set('LODSmoothType', FnAttribute.IntAttribute(0))

    gb.set("speedKeyFrame", FnAttribute.FloatAttribute([1.0], 1))
    gb.set("speedResponseTime", FnAttribute.FloatAttribute([1.0], 1))
    gb.set("speedKeyValue", FnAttribute.FloatAttribute([0.3], 1))
    gb.set("direKeyFrame", FnAttribute.FloatAttribute([1.0], 1))
    gb.set("direResponseTime", FnAttribute.FloatAttribute([1.0], 1))
    gb.set("direKeyValue", FnAttribute.FloatAttribute([1.0, 0.0, 0.0], 3))

    nodeTypeBuilder.setParametersTemplateAttr(gb.build())

    # Set parameter hints

    nodeTypeBuilder.setHintsForNode({
        'help':
        '<p>Create Arnold procedurals suitable for SpeedTree.</p>' +
        '<p>Read and prase srt file data into arnold origin geometry'
    })
    nodeTypeBuilder.setHintsForParameter(
        'location', {
            'widget': 'scenegraphLocation',
            'help': 'The location of rendererProcedural node.'
        })
    nodeTypeBuilder.setHintsForParameter(
        'srtFile', {
            'widget': 'assetIdInput',
            'sequenceListing': False,
            'fileTypes': 'srt',
            'help': 'SpeedTree srt file path'
        })

    nodeTypeBuilder.setHintsForParameter(
        'useGlobalMotion', {
            'widget': 'checkBox',
            'help': 'SpeedTree Procedutal useGlobalMotion'
        })
    nodeTypeBuilder.setHintsForParameter(
        'currentFrame', {'help': 'SpeedTree Procedutal currentFrame'})
    nodeTypeBuilder.setHintsForParameter(
        'enableMotionBlur', {
            'widget': 'checkBox',
            'help': 'SpeedTree Procedutal enableMotionBlur'
        })
    nodeTypeBuilder.setHintsForParameter(
        "motionSamples", {
            'widget': 'sortableArray',
            'help': 'SpeedTree Procedutal motionSamples'
        })

    nodeTypeBuilder.setHintsForParameter('fps',
                                         {'help': 'SpeedTree Procedutal fps'})
    nodeTypeBuilder.setHintsForParameter(
        'globalFrequency', {'help': 'SpeedTree Procedutal globalFrequency'})
    nodeTypeBuilder.setHintsForParameter(
        'gustFrequency', {'help': 'SpeedTree Procedutal gustFrequency'})
    nodeTypeBuilder.setHintsForParameter(
        'windSpeed', {'help': 'SpeedTree Procedutal windSpeed'})

    nodeTypeBuilder.setHintsForParameter('windDirection', {
        'widget': 'multi',
        'help': 'SpeedTree Procedutal'
    })

    nodeTypeBuilder.setHintsForParameter(
        'windType', {'help': 'SpeedTree Procedutal windType'})
    nodeTypeBuilder.setHintsForParameter(
        'LODType', {'help': 'SpeedTree Procedutal LODType'})
    nodeTypeBuilder.setHintsForParameter(
        'LODSmoothType', {'help': 'SpeedTree Procedutal LODSmoothType'})

    nodeTypeBuilder.setHintsForParameter(
        "speedKeyFrame", {
            'widget': 'sortableArray',
            'help': 'SpeedTree Procedutal speedKeyFrame'
        })
    nodeTypeBuilder.setHintsForParameter(
        "speedResponseTime", {
            'widget': 'sortableArray',
            'help': 'SpeedTree Procedutal speedResponseTime'
        })
    nodeTypeBuilder.setHintsForParameter(
        "speedKeyValue", {
            'widget': 'sortableArray',
            'help': 'SpeedTree Procedutal speedKeyValue'
        })
    nodeTypeBuilder.setHintsForParameter(
        "direKeyFrame", {
            'widget': 'sortableArray',
            'help': 'SpeedTree Procedutal direKeyFrame'
        })
    nodeTypeBuilder.setHintsForParameter(
        "direResponseTime", {
            'widget': 'sortableArray',
            'help': 'SpeedTree Procedutal direKeyFrame'
        })
    nodeTypeBuilder.setHintsForParameter(
        "direKeyValue", {
            'widget': 'dynamicArray',
            'help': 'SpeedTree Procedutal direKeyValue'
        })

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

    # Build the new node type
    nodeTypeBuilder.build()
Ejemplo n.º 11
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())
Ejemplo n.º 12
0
def registerArnoldXGenOp():
    """
    Registers the ArnoldXGen Op using the NodeTypeBuilder.
    This is a helper class that takes care of registering a suitable
    node graph node type, and configuring it to call the supplied method
    in order to build the Op chain that is used to represent the
    node in the Op Graph.
    """

    from Katana import Nodes3DAPI
    from Katana import FnAttribute, FnGeolibServices

    MODE_RIBBON = 0
    MODE_THICK = 1
    MODE_ORIENTED = 2
    modeDict = {
        'ribbon': MODE_RIBBON,
        'thick': MODE_THICK,
        'oriented': MODE_ORIENTED
    }

    XGEN_FILE = 0
    XGEN_ROOT = 1
    xgenSpecStyle = {'xgen_file': XGEN_FILE, 'xgen_root': XGEN_ROOT}

    FROM_ENVIRONMENT = 0
    CUSTOM_PATHS = 1
    customPathsSetting = {
        'from environment': FROM_ENVIRONMENT,
        'customize paths': CUSTOM_PATHS
    }

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

        # TODO: figure this out so it's automatic
        #fps = interface.getGraphState().getFramesPerSecond()

        # Get the parameters from our node
        locationParam = node.getParameter("location")
        xgenRootParam = node.getParameter("xgen_root")
        xgenFileParam = node.getParameter("xgen_file")
        pathsParam = node.getParameter("paths")
        mayaPathParam = node.getParameter("maya_path")
        mtoaPathParam = node.getParameter("mtoa_path")
        xgenLocParam = node.getParameter("xgen_location")
        sceneParam = node.getParameter("scene")
        paletteParam = node.getParameter("collection")
        descParam = node.getParameter("description")
        schemeParam = node.getParameter("name_scheme")
        cameraParam = node.getParameter("camera")
        samplesParam = node.getParameter("samples")
        fpsParam = node.getParameter("fps")
        mpwParam = node.getParameter("min_pixel_width")
        modeParam = node.getParameter("mode")
        patchesParam = node.getParameter("patches")
        verboseParam = node.getParameter("verbose")
        specParam = node.getParameter("specification")

        if not locationParam or not (xgenRootParam or xgenFileParam):
            raise RuntimeError(
                "Missing node parameters, requires 'location' and one of 'xgen_root' or 'xgen_scene' to be set"
            )

        # copy array param values out to appropriate attributes
        samples = []
        for ci in range(0, samplesParam.getNumChildren()):
            samples = samples + [
                samplesParam.getChildByIndex(ci).getValue(frameTime)
            ]
        if not samples:
            samples = [0.0]
        opSamplesParam = FnAttribute.FloatAttribute(samples)

        patches = []
        for ci in range(0, patchesParam.getNumChildren()):
            patches = patches + [
                patchesParam.getChildByIndex(ci).getValue(frameTime)
            ]
        if not patches:
            opPatchesParam = FnAttribute.StringAttribute([], 1)
        else:
            opPatchesParam = FnAttribute.StringAttribute(patches)

        # Build the Op args from our node
        argsGb = FnAttribute.GroupBuilder()
        argsGb.set("patch", opPatchesParam)
        argsGb.set("samples", opSamplesParam)
        argsGb.set("specification",
                   FnAttribute.IntAttribute(specParam.getValue(frameTime)))
        argsGb.set(
            "xgen_root",
            FnAttribute.StringAttribute(xgenRootParam.getValue(frameTime)))
        argsGb.set(
            "xgen_file",
            FnAttribute.StringAttribute(xgenFileParam.getValue(frameTime)))
        if pathsParam.getValue(frameTime) == CUSTOM_PATHS:
            argsGb.set(
                "maya_path",
                FnAttribute.StringAttribute(mayaPathParam.getValue(frameTime)))
            argsGb.set(
                "mtoa_path",
                FnAttribute.StringAttribute(mtoaPathParam.getValue(frameTime)))
            argsGb.set(
                "xgen_location",
                FnAttribute.StringAttribute(xgenLocParam.getValue(frameTime)))
        else:
            argsGb.set("maya_path", FnAttribute.StringAttribute(''))
            argsGb.set("mtoa_path", FnAttribute.StringAttribute(''))
            argsGb.set("xgen_location", FnAttribute.StringAttribute(''))
        argsGb.set("scene",
                   FnAttribute.StringAttribute(sceneParam.getValue(frameTime)))
        argsGb.set(
            "palette",
            FnAttribute.StringAttribute(paletteParam.getValue(frameTime)))
        argsGb.set("description",
                   FnAttribute.StringAttribute(descParam.getValue(frameTime)))
        argsGb.set(
            "name_scheme",
            FnAttribute.StringAttribute(schemeParam.getValue(frameTime)))
        argsGb.set(
            "camera",
            FnAttribute.StringAttribute(cameraParam.getValue(frameTime)))
        argsGb.set("min_pixel_width",
                   FnAttribute.FloatAttribute(mpwParam.getValue(frameTime)))
        argsGb.set("fps",
                   FnAttribute.FloatAttribute(fpsParam.getValue(frameTime)))
        argsGb.set("verbose",
                   FnAttribute.IntAttribute(verboseParam.getValue(frameTime)))
        argsGb.set("frame", FnAttribute.IntAttribute(int(frameTime)))
        argsGb.set("mode",
                   FnAttribute.IntAttribute(modeParam.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, "ArnoldXGen", argsGb.build())

        interface.appendOp("StaticSceneCreate", sscb.build())

    # Here we need to define the parameters for the node, and register the op
    # chain creation callback function

    nodeBuilder = Nodes3DAPI.NodeTypeBuilder("ArnoldXGen")

    # Merge with incoming scene, simply allow the node to have an input. Unless
    # you delete locations in your Op, any existing locations will pass-through.
    # We need the input to allow the camera to be used
    nodeBuilder.setInputPortNames(("in", ))

    # Parameters can be described by a group attribute
    paramGb = FnAttribute.GroupBuilder()
    paramGb.set("location",
                FnAttribute.StringAttribute("/root/world/geo/xgen"))
    # Can specify these paths, but if empty they will fall back on MAYA_PATH and MTOA_PATH environment vars
    paramGb.set("paths", FnAttribute.IntAttribute(FROM_ENVIRONMENT))
    paramGb.set("maya_path", FnAttribute.StringAttribute(""))
    paramGb.set("mtoa_path", FnAttribute.StringAttribute(""))
    paramGb.set("xgen_location", FnAttribute.StringAttribute(""))
    paramGb.set("specification", FnAttribute.IntAttribute(XGEN_FILE))
    paramGb.set("xgen_root",
                FnAttribute.StringAttribute(""))  # hidden for XGEN_FILE
    paramGb.set("xgen_file",
                FnAttribute.StringAttribute(""))  # hidden for XGEN_ROOT
    paramGb.set("scene",
                FnAttribute.StringAttribute(""))  # hidden for XGEN_FILE
    paramGb.set("collection",
                FnAttribute.StringAttribute(""))  # hidden for XGEN_FILE
    paramGb.set("description", FnAttribute.StringAttribute(""))
    paramGb.set("patches", FnAttribute.StringAttribute([], 1))
    paramGb.set(
        "name_scheme",
        FnAttribute.StringAttribute(
            "<scene>_<collection>_<description>_<patch>"))
    paramGb.set("camera",
                FnAttribute.StringAttribute("/root/world/cam/camera"))
    paramGb.set("fps", FnAttribute.FloatAttribute(24.0))
    paramGb.set("samples", FnAttribute.FloatAttribute([], 1))
    paramGb.set("min_pixel_width", FnAttribute.FloatAttribute(0.0))
    paramGb.set("mode", FnAttribute.IntAttribute(MODE_RIBBON))
    paramGb.set("verbose", FnAttribute.IntAttribute(1))

    nodeBuilder.setParametersTemplateAttr(paramGb.build(),
                                          forceArrayNames=('samples',
                                                           'patches'))

    nodeBuilder.setHintsForNode({
        'help':
        '<p>Create Arnold procedurals suitable for invoking Autodesk XGen (bundled with Maya).</p>'
        +
        '<p>It is recommended that you turn on "compatible_motion_blur" in an ArnoldGlobalSettings node if you use ArnoldXGen. '
        +
        'Also, if you wish to use camera-guided data (such as LOD), feed the scene with a camera to the input.</p>'
        +
        '<p><b>NOTE:</b> this node is influenced by the following environment variables:</p><ul><li><b>MAYA_PATH</b> root of Maya installation</li><li><b>MTOA_PATH</b> root of MtoA installation</li><li><b>XGEN_LOCATION</b> xgen location within Maya, usually ${MAYA_PATH}/plug-ins/xgen</li></ul>'
    })

    nodeBuilder.setHintsForParameter("location",
                                     {'widget': 'newScenegraphLocation'})
    nodeBuilder.setHintsForParameter(
        "camera", {
            'widget':
            'scenegraphLocation',
            'help':
            'The camera used for LOD and other effects; can be blank to disable camera-related effects'
        })
    nodeBuilder.setHintsForParameter(
        "specification", {
            'widget':
            'mapper',
            'options':
            xgenSpecStyle,
            'help':
            'How to find the xgen data; either directly specify a .xgen file, or else specify a maya project directory and the .xgen files will be searched for.'
        })
    nodeBuilder.setHintsForParameter(
        "xgen_root", {
            'widget': 'fileInput',
            'dirsOnly': 'True',
            'help': 'Requred; path to maya project directory',
            'conditionalVisOp': 'equalTo',
            'conditionalVisPath': '../specification',
            'conditionalVisValue': XGEN_ROOT
        })
    nodeBuilder.setHintsForParameter(
        "xgen_file", {
            'widget': 'fileInput',
            'help': 'Requred; path to .xgen file',
            'conditionalVisOp': 'equalTo',
            'conditionalVisPath': '../specification',
            'conditionalVisValue': XGEN_FILE
        })

    nodeBuilder.setHintsForParameter(
        "paths", {
            'widget':
            'mapper',
            'options':
            customPathsSetting,
            'help':
            'Whether to customize paths to Maya/MtoA/XGen, or just use MAYA_PATH, MTOA_PATH, and XGEN_LOCATION environment variables.'
        })
    nodeBuilder.setHintsForParameter(
        "maya_path", {
            'widget': 'fileInput',
            'help':
            'Optional; path to Maya installation (to find xgen libraries).  If empty, KtoA will use the MAYA_PATH environment variable to locate Maya.',
            'conditionalVisOp': 'equalTo',
            'conditionalVisPath': '../paths',
            'conditionalVisValue': CUSTOM_PATHS
        })
    nodeBuilder.setHintsForParameter(
        "mtoa_path", {
            'widget': 'fileInput',
            'help':
            'Optional; path to MtoA installation (to find xgen_procedural for Arnold).  If empty, KtoA will use the MTOA_PATH environment variable to locate MtoA.',
            'conditionalVisOp': 'equalTo',
            'conditionalVisPath': '../paths',
            'conditionalVisValue': CUSTOM_PATHS
        })
    nodeBuilder.setHintsForParameter(
        "xgen_location", {
            'widget': 'fileInput',
            'help':
            'Optional; path to XGen installation (to find presets, scripts, etc). Usually this is "${MAYA_PATH}/plug-ins/xgen/"  If empty, KtoA will use the XGEN_LOCATION environment variable or infer it from the Maya path.',
            'conditionalVisOp': 'equalTo',
            'conditionalVisPath': '../paths',
            'conditionalVisValue': CUSTOM_PATHS
        })
    nodeBuilder.setHintsForParameter(
        "patches", {
            'widget':
            'sortableArray',
            'help':
            'Optional; Maya shapes serving as base surfaces from which xgen curves/shapes are populated.  Please include namespaces.  If left empty, patches will be found from the xgen data.'
        })
    nodeBuilder.setHintsForParameter(
        "name_scheme", {
            'help':
            'Naming scheme for child locations of unique xgen procedurals.  It honors the following tags (enclosed in angle braces): scene, collection, description, patch'
        })
    nodeBuilder.setHintsForParameter(
        "scene", {
            'help':
            'Optional; Maya scene file name (without file path or extension) in which the xgen data lives.  If left empty, all scenes with xgen data will be found.',
            'conditionalVisOp': 'equalTo',
            'conditionalVisPath': '../specification',
            'conditionalVisValue': XGEN_ROOT
        })
    nodeBuilder.setHintsForParameter(
        "collection", {
            'help':
            'XGen collection to render.  Please include namespace.  If left empty, collections will be found from the xgen data.',
            'conditionalVisOp': 'equalTo',
            'conditionalVisPath': '../specification',
            'conditionalVisValue': XGEN_ROOT
        })
    nodeBuilder.setHintsForParameter(
        "description", {
            'help':
            'XGen description to render.  If left empty, descriptions will be found from the xgen data.'
        })
    nodeBuilder.setHintsForParameter(
        "fps", {
            'help':
            'Frames per second animation is proceeding at; 24, 30, 48 and 60 are typical'
        })
    nodeBuilder.setHintsForParameter(
        "min_pixel_width", {
            'help':
            'Arnold min-pixel-width; typically between 0 and 1, can help reduce aliasing'
        })
    nodeBuilder.setHintsForParameter(
        "mode", {
            'widget':
            'mapper',
            'options':
            modeDict,
            'help':
            'Rendering mode of the curves; camera-facing ribbons, thick cylinders, or ribbons oriented by normal vectors.'
        })
    nodeBuilder.setHintsForParameter(
        "samples", {
            'widget':
            'sortableArray',
            'help':
            'Required; frame-relative motion sample times (e.g -0.25, 0.25).  It is recommended that you turn on "compatible_motion_blur" in an ArnoldGlobalSettings node if you use ArnoldXGen.'
        })
    nodeBuilder.setHintsForParameter("verbose", {'help': 'Log level for XGen'})

    # Register our Op build function
    nodeBuilder.setBuildOpChainFnc(buildOpChain)

    # Create the new Node3D type
    nodeBuilder.build()
    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())


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

# Build the node's parameters and default values. The parameter types are
# inferred from the types of the default values, so location becomes a
# "string" parameter, and numberOfSpheres becomes a "number" parameter.
paramsBuilder = FnAttribute.GroupBuilder()
paramsBuilder.set('location', '/root/world/geo/SphereMaker')
paramsBuilder.set('numberOfSpheres', 20)

# Convenience method to add the 'timing.mode' parameter and give it the
# appropriate UI hints.
nodeTypeBuilder.addTimingParameters(paramsBuilder)

# Set the parameters template
nodeTypeBuilder.setParametersTemplateAttr(paramsBuilder.build())
Ejemplo n.º 14
0
def registerWalterAssign():
    """
    Registers a new WalterAssign node type.
    """

    from Katana import Nodes3DAPI
    from Katana import FnAttribute

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

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

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

    # Build the node's parameters
    gb = FnAttribute.GroupBuilder()
    gb.set('CEL', FnAttribute.StringAttribute('/root/world/geo/asset//*'))
    gb.set('root', FnAttribute.StringAttribute('/root/world/geo/asset'))
    gb.set('abcAsset', FnAttribute.StringAttribute(''))

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

    # Set parameter hints
    nodeTypeBuilder.setHintsForParameter('CEL', {'widget': 'cel'})
    nodeTypeBuilder.setHintsForParameter('abcAsset',
                                         {'widget': 'walterLayers'})
    # Set the callback responsible to build the Ops chain
    nodeTypeBuilder.setBuildOpChainFnc(buildWalterAssignOpChain)

    # Build the new node type
    nodeTypeBuilder.build()
Ejemplo n.º 15
0
from Katana import FnAttribute, Nodes3DAPI

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

nb.setParametersTemplateAttr(FnAttribute.GroupBuilder().set(
    'argParent', FnAttribute.StringAttribute("father")).set(
        'argChild', FnAttribute.StringAttribute("son")).build())

nb.setHintsForNode({'help': 'Node hints here!!!'})
nb.setHintsForParameter('attrName', {'help': 'Arg hints here!!!'})


def myBuildOps(node, interface):
    op = interface.buildOp('testParentOp')

    if op.areParametersDirty():
        frameTime = interface.getFrameTime()

        op.setOpType('TestParentOp')
        op.setOpArg('argParent',
                    node.getParameter('argParent').getValue(frameTime))
        op.setOpArg('argChild',
                    node.getParameter('argChild').getValue(frameTime))

    if op.areInputsDirty():
        op.setOpInputs(interface.getAllInputOps())

    return op

Ejemplo n.º 16
0
def registerGeoScaler():
    """
    Registers a new GeoScaler node type using the NodeTypeBuilder utility
    class.
    """

    from Katana import Nodes3DAPI
    from Katana import FnAttribute

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

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

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

    # Build the node's parameters
    gb = FnAttribute.GroupBuilder()
    gb.set('CEL', FnAttribute.StringAttribute(''))
    gb.set('scale', FnAttribute.FloatAttribute(1.0))

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

    # Set parameter hints
    nodeTypeBuilder.setHintsForParameter('CEL', {'widget': 'scenegraphLocation'})

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

    # Build the new node type
    nodeTypeBuilder.build()
Ejemplo n.º 17
0
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#
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.',
    })
Ejemplo n.º 18
0
def registerLocationDescribe():
    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())

    nodeTypeBuilder = Nodes3DAPI.NodeTypeBuilder('LocationDescribe')

    # build params
    gb = FnAttribute.GroupBuilder()
    gb.set('location',
           FnAttribute.StringAttribute('/root/world/geo/location1'))
    gb.set('mode', FnAttribute.StringAttribute('create'))
    gb.set('type', FnAttribute.StringAttribute('sphere'))
    gb.set('description',
           FnAttribute.StringAttribute('double geometry.radius = 1.0;'))

    nodeTypeBuilder.setParametersTemplateAttr(gb.build())
    nodeTypeBuilder.setHintsForParameter('mode', {
        'widget': 'popup',
        'options': 'create|edit'
    })
    nodeTypeBuilder.setHintsForParameter('description',
                                         {'widget': 'scriptEditor'})

    nodeTypeBuilder.setInputPortNames(('in', ))

    nodeTypeBuilder.setBuildOpChainFnc(buildLocationDescribeOpChain)

    nodeTypeBuilder.build()
			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())

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))
Ejemplo n.º 20
0
def registerMesser():
    """
    Registers a new Messer node type using the nb utility class.
    """
    import sys
    print sys.path
    from Katana import Nodes3DAPI, NodegraphAPI
    from Katana import FnAttribute
    import NodegraphAPI.Constants.ApplyWhenOptions as ApplyWhenOptions
    import NodegraphAPI.Constants.ApplyWhereOptions as ApplyWhereOptions
    import NodegraphAPI.Constants.ExecutionModeOptions as ExecutionModeOptions
    from Katana import FnGeolibServices

    def _DoInputRequests(interface, inputBehavior, inputPorts, graphState):
        interface.setExplicitInputRequestsEnabled(True)
        if inputBehavior == 'only valid':
            state = interface.SKIP
        else:
            state = interface.NO_OP
        for inputPort in inputPorts:
            interface.addInputRequest(inputPort.getName(),
                                      graphState,
                                      invalidInputBehavior=state)

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

        @type node: C{Nodes3DAPI.nb.Messer}
        @type interface: C{Nodes3DAPI.nb.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
        # Set the minimum number of input ports
        interface.setMinRequiredInputs(1)

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

        argsGb = FnAttribute.GroupBuilder()
        argsGb.set('system', graphState.getOpSystemArgs())

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

        userParam = node.getParameter('user')
        if userParam:
            userAttr = NodegraphAPI.BuildAttrFromGroupParameter(
                userParam, graphState)
            if userAttr is not None:
                argsGb.set('user', userAttr)

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

        # xform
        transformParam = node.getParameter('transform')
        if transformParam:
            transformAttr = NodegraphAPI.BuildAttrFromGroupParameter(
                transformParam, graphState)
            if transformAttr is not None:
                argsGb.set('transform', transformAttr)

        opArgs = argsGb.build()
        if opArgs is not None:
            argsGb.deepUpdate(opArgs)

        opType = 'CartesianScript'
        #executionMode = node.getParameter('executionMode').getValue(frameTime)
        #if executionMode == ExecutionModeOptions.Immediate:
        #gb = FnAttribute.GroupBuilder()
        #gb.set('system', graphState.getOpSystemArgs())
        #if opArgs is not None:
        #    gb.deepUpdate(opArgs)
        #opArgs = gb.build()
        #asb = FnGeolibServices.OpArgsBuilders.AttributeSet()
        #asb.setCEL(FnAttribute.StringAttribute(node.getParameter('CEL').getValue(frameTime)))
        #asb.addSubOp(opType, opArgs)
        #interface.appendOp('AttributeSet', asb.build())
        #_DoInputRequests(interface, node.getParameter('inputBehavior').getValue(frameTime), node.getInputPorts(), graphState)
        # Add the explicit input request for our input port with the modified graph state
        # Add a variable to the local graph state
        #interface.setExplicitInputRequestsEnabled(True)
        #interface.addInputRequest('i0', graphState)
        #interface.addInputRequest('i1', graphState)

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

    # Create a nb to register the new type
    nb = Nodes3DAPI.NodeTypeBuilder('CartesianScript')

    print dir(nb)
    # Add an input port
    nb.setInputPortNames((
        'i0',
        'i1',
    ))
    nb.setOutputPortNames(('out', ))

    # Build the node's parameters
    gb = FnAttribute.GroupBuilder()
    gb.set('CEL', FnAttribute.StringAttribute(''))
    gb.set('script', FnAttribute.StringAttribute('print(Time)'))
    gb.set('executionMode', FnAttribute.StringAttribute('immediate'))
    gb.set('inputBehavior', FnAttribute.StringAttribute('by index'))
    nb.addTransformParameters(gb)
    nb.addMakeInteractiveParameter(gb)
    nb.addTimingParameters(gb)
    #gb.set('transform.rotate', FnAttribute.DoubleAttribute([0,0,0]))
    #gb.set('transform.scale', FnAttribute.DoubleAttribute([0,0,0]))
    # Set the parameters template
    nb.setParametersTemplateAttr(gb.build())
    # Set parameter hints
    nb.setHintsForParameter('CartesianScript', {'widget': 'opScriptNode'})
    nb.setHintsForParameter('CEL', {'widget': 'cel'})
    nb.setHintsForParameter(
        'script', {
            'widget': 'scriptEditor',
            'highlighter': 'Lua',
            'supportsNonmodalExternalEditing': 'True',
            'resistLabelResize': 'True',
            'externalEditorSuffix': '.lua',
            'mono': 'True'
        })
    nb.setHintsForParameter(
        'executionMode', {
            'widget':
            'popup',
            'options':
            [ExecutionModeOptions.Immediate, ExecutionModeOptions.Deferred]
        })
    nb.setHintsForParameter('inputBehavior', {
        'widget': 'popup',
        'options': ['by index', 'only valid']
    })
    # Set the callback responsible to build the Ops chain
    nb.setBuildOpChainFnc(buildMesserOpChain)
    # Build the new node type
    nb.build()
Ejemplo n.º 21
0
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#
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.',
    })
Ejemplo n.º 22
0
def registerArnoldYetiInOp():
    """
    Registers the ArnoldYeti Op using the NodeTypeBuilder.
    This is a helper class that takes care of registering a suitable
    node graph node type, and configuring it to call the supplied method
    in order to build the Op chain that is used to represent the
    node in the Op Graph.
    """

    from Katana import Nodes3DAPI
    from Katana import FnAttribute, FnGeolibServices

    MODE_RIBBON = 0
    MODE_THICK = 1
    MODE_ORIENTED = 2
    modeDict = {
        'ribbon': MODE_RIBBON,
        'thick': MODE_THICK,
        'oriented': MODE_ORIENTED
    }

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

        # Pass these along through the ops so that the have shutter open/close and number of samples
        systemArgs = interface.getGraphState().getOpSystemArgs()

        # Get the parameters from our node
        locationParam = node.getParameter("location")
        filenameParam = node.getParameter("filename")
        proxyParam = node.getParameter("proxy")
        samplesParam = node.getParameter("samples")
        imageSearchPathParam = node.getParameter("imageSearchPath")
        disableBoundingboxParam = node.getParameter("disableBoundingbox")
        lengthParam = node.getParameter("length")
        densityParam = node.getParameter("density")
        minPixelWidthParam = node.getParameter("min_pixel_width")
        modeParam = node.getParameter("mode")
        widthParam = node.getParameter("width")
        verboseParam = node.getParameter("verbose")
        threadsParam = node.getParameter("threads")
        makeInteractiveParam = node.getParameter("makeInteractive")

        if not locationParam or not filenameParam:
            raise RuntimeError(
                "Missing node parameters, requires 'location' and 'filename'")

        # Copy array param values out to appropriate attributes
        samples = []
        for ci in range(0, samplesParam.getNumChildren()):
            samples = samples + [
                samplesParam.getChildByIndex(ci).getValue(frameTime)
            ]
        if samples is not None and len(samples) > 0:
            opSamplesParam = FnAttribute.FloatAttribute(samples)
        imageSearchPath = ""
        if imageSearchPathParam.getNumChildren() >= 1:
            imageSearchPath = imageSearchPathParam.getChildByIndex(
                ci).getValue(frameTime)
        for ci in range(1, imageSearchPathParam.getNumChildren()):
            imageSearchPath = imageSearchPath + ":" + imageSearchPathParam.getChildByIndex(
                ci).getValue(frameTime)
        opImageSearchPathParam = FnAttribute.StringAttribute(imageSearchPath)

        # Build the Op args from our node
        argsGb = FnAttribute.GroupBuilder()
        argsGb.set(
            "filename",
            FnAttribute.StringAttribute(filenameParam.getValue(frameTime)))
        argsGb.set("proxy",
                   FnAttribute.StringAttribute(proxyParam.getValue(frameTime)))
        if samples is not None and len(samples) > 0:
            argsGb.set("samples", opSamplesParam)
        argsGb.set("length",
                   FnAttribute.FloatAttribute(lengthParam.getValue(frameTime)))
        argsGb.set(
            "density",
            FnAttribute.FloatAttribute(densityParam.getValue(frameTime)))
        argsGb.set(
            "min_pixel_width",
            FnAttribute.FloatAttribute(minPixelWidthParam.getValue(frameTime)))
        argsGb.set("width",
                   FnAttribute.FloatAttribute(widthParam.getValue(frameTime)))
        argsGb.set("imageSearchPath", opImageSearchPathParam)
        argsGb.set("verbose",
                   FnAttribute.IntAttribute(verboseParam.getValue(frameTime)))
        argsGb.set("threads",
                   FnAttribute.IntAttribute(threadsParam.getValue(frameTime)))
        argsGb.set("frame", FnAttribute.IntAttribute(int(round(frameTime))))
        argsGb.set("mode",
                   FnAttribute.IntAttribute(modeParam.getValue(frameTime)))
        argsGb.set("system", systemArgs)
        argsGb.set(
            "disableBoundingbox",
            FnAttribute.IntAttribute(
                disableBoundingboxParam.getValue(frameTime)))
        argsGb.set(
            "makeInteractive",
            FnAttribute.StringAttribute(
                makeInteractiveParam.getValue(frameTime)))

        argsGb.set("xform", interface.getTransformAsAttribute())
        exclusiveAttrName, exclusiveAttr = interface.getExclusiveToNameAndAttribute(
        )
        if exclusiveAttr is not None:
            argsGb.set("exclusiveTo", exclusiveAttr)

        # 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, "ArnoldYeti_In", argsGb.build())

        interface.appendOp("StaticSceneCreate", sscb.build())

    def getScenegraphLocation(node, frameTime):
        locationParam = node.getParameter("location")
        return locationParam.getValue(0.0)

    # Here we need to define the parameters for the node, and register the op
    # chain creation callback function

    nodeBuilder = Nodes3DAPI.NodeTypeBuilder("ArnoldYeti_In")

    # If we wanted to merge with incoming scene, we could simply allow the
    # node to have an input. Unless you delete locations in your Op, any
    # existing locations will pass-through. It is encouraged though to avoid
    # long chains of Ops, as it makes multi-threading and caching less
    # efficient, so for 'Generator' Ops, no input is preferable.
    # nodeBuilder.setInputPortNames( ("in",) )

    # Parameters can be described by a group attribute
    paramGb = FnAttribute.GroupBuilder()
    paramGb.set("location",
                FnAttribute.StringAttribute("/root/world/geo/yetiProc"))
    paramGb.set("filename", FnAttribute.StringAttribute(""))
    paramGb.set("proxy", FnAttribute.StringAttribute(""))
    paramGb.set("density", FnAttribute.FloatAttribute(1.0))
    paramGb.set("length", FnAttribute.FloatAttribute(1.0))
    paramGb.set("imageSearchPath", FnAttribute.StringAttribute([], 1))
    paramGb.set("min_pixel_width", FnAttribute.FloatAttribute(0.0))
    paramGb.set("width", FnAttribute.FloatAttribute(1.0))
    paramGb.set("mode", FnAttribute.IntAttribute(MODE_RIBBON))
    paramGb.set("samples", FnAttribute.FloatAttribute([], 1))
    paramGb.set("threads", FnAttribute.IntAttribute(0))
    paramGb.set("verbose", FnAttribute.IntAttribute(2))
    paramGb.set("disableBoundingbox", FnAttribute.IntAttribute(1))

    nodeBuilder.addTransformParameters(paramGb)
    nodeBuilder.addMakeInteractiveParameter(paramGb)
    nodeBuilder.addInteractiveTransformCallbacks(paramGb)

    nodeBuilder.setParametersTemplateAttr(paramGb.build(),
                                          forceArrayNames=('samples',
                                                           'imageSearchPath'))

    nodeBuilder.setHintsForNode({
        'help':
        'Create an Arnold procedural node suitable for invoking Peregrine Labs\' Yeti.'
    })

    nodeBuilder.setHintsForParameter("location",
                                     {'widget': 'newScenegraphLocation'})
    nodeBuilder.setHintsForParameter(
        "filename", {
            'widget': 'assetIdInput',
            'sequenceListing': False,
            'fileTypes': 'fur',
            'help': 'Requred; path to Yeti fur cache file'
        })
    nodeBuilder.setHintsForParameter(
        "proxy", {
            'widget': 'assetIdInput',
            'sequenceListing': False,
            'fileTypes': 'abc',
            'help': 'Not Requred; path to Yeti fur alembic proxy file'
        })
    nodeBuilder.setHintsForParameter(
        "density", {'help': 'Density scale for curve population'})
    nodeBuilder.setHintsForParameter("length",
                                     {'help': 'Length scale for curves'})
    nodeBuilder.setHintsForParameter(
        "imageSearchPath", {
            'widget':
            'sortableArray',
            'help':
            'Optional; colon-separated paths to images for curve operations'
        })
    nodeBuilder.setHintsForParameter(
        "min_pixel_width", {
            'help':
            'Arnold min-pixel-width; typically between 0 and 1, can help reduce aliasing'
        })
    nodeBuilder.setHintsForParameter(
        "mode", {
            'widget':
            'mapper',
            'options':
            modeDict,
            'help':
            'Rendering mode of the curves; camera-facing ribbons, thick cylinders, or ribbons oriented by normal vectors.'
        })
    nodeBuilder.setHintsForParameter(
        "width", {'help': 'Width/radius scale factor for curves'})
    nodeBuilder.setHintsForParameter(
        "samples", {
            'widget':
            'sortableArray',
            'help':
            'Optional; frame-relative motion sample times (e.g -0.25, 0.25).'
        })
    nodeBuilder.setHintsForParameter(
        "threads", {'help': 'Number of threads for curve generation'})
    nodeBuilder.setHintsForParameter("verbose", {'help': 'Log level for Yeti'})
    nodeBuilder.setHintsForParameter(
        'disableBoundingbox', {
            'widget': 'checkBox',
            'help': 'disable caculating Yeti fur Boundingbox'
        })

    # Register our Op build function
    nodeBuilder.setBuildOpChainFnc(buildOpChain)

    # Make this available for widgets and parameter expressions
    nodeBuilder.setGetScenegraphLocationFnc(getScenegraphLocation)

    # Create the new Node3D type
    nodeBuilder.build()