Exemplo n.º 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)
Exemplo n.º 2
0
def registerMesser():
    """
    Registers a new Messer node type using the NodeTypeBuilder utility class.
    """

    from Katana import Nodes3DAPI
    from Katana import FnAttribute

    def buildMesserOpChain(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 displacement parameter
        dispParam = node.getParameter('displacement')
        if dispParam:
            argsGb.set('displacement', dispParam.getValue(frameTime))

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

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

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

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

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

    # Build the new node type
    nodeTypeBuilder.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())
Exemplo n.º 4
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()
Exemplo n.º 5
0
    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())
    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())
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()
Exemplo n.º 8
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()
Exemplo n.º 9
0
    def generateMaterialAttributes(self, materialDefinition, materialStaticSCB,
                                   materialLocationPath,
                                   convertSpecRoughnessValues,
                                   enableCausticsInArnold):
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, "material.style",
            FnAttribute.StringAttribute("network"))

        nodeName = "PRManShadingNode"
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, "material.terminals.prmanBxdf",
            FnAttribute.StringAttribute(nodeName))
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, "material.terminals.prmanBxdfPort",
            FnAttribute.StringAttribute("out"))

        matAttrPath = "material.nodes." + nodeName + "."
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, matAttrPath + "name",
            FnAttribute.StringAttribute(nodeName))
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, matAttrPath + "type",
            FnAttribute.StringAttribute("PxrSurface"))
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, matAttrPath + "target",
            FnAttribute.StringAttribute("prman"))
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, matAttrPath + "srcName",
            FnAttribute.StringAttribute(nodeName))

        imageNodeCount = 1

        matParamsPath = matAttrPath + "parameters."

        for matDefName, matDefItem in materialDefinition.iteritems():
            if matDefName == "diffColour":
                if matDefItem[0] == "col3":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath, matParamsPath + "diffuseColor",
                        FnAttribute.FloatAttribute(matDefItem[1], 3))
                elif matDefItem[0] == "image":
                    imageNodeName = "PSNTexture%i" % (imageNodeCount)
                    imageNodeCount += 1
                    self.addImageShadingNode(materialStaticSCB,
                                             materialLocationPath,
                                             matDefItem[1], imageNodeName)
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        matAttrPath + "connections.diffuseColor",
                        FnAttribute.StringAttribute("resultRGB@" +
                                                    imageNodeName))
            elif matDefName == "diffRoughness":
                if matDefItem[0] == "float":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        matParamsPath + "diffuseRoughness",
                        FnAttribute.FloatAttribute(matDefItem[1]))
                elif matDefItem[0] == "image":
                    imageNodeName = "PSNTexture%i" % (imageNodeCount)
                    imageNodeCount += 1
                    self.addImageShadingNode(materialStaticSCB,
                                             materialLocationPath,
                                             matDefItem[1], imageNodeName)
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        matAttrPath + "connections.diffuseRoughness",
                        FnAttribute.StringAttribute("resultA@" +
                                                    imageNodeName))
            elif matDefName == "refraIndex" and matDefItem[0] == "float":
                tempArrayValue = matDefItem[1] * 3
                materialStaticSCB.setAttrAtLocation(
                    materialLocationPath, matParamsPath + "specularIOR",
                    FnAttribute.FloatAttribute(tempArrayValue, 3))
            elif matDefName == "specColour":
                materialStaticSCB.setAttrAtLocation(
                    materialLocationPath,
                    matParamsPath + "specularFresnelMode",
                    FnAttribute.IntAttribute(1))
                # Set GGX microfacet type
                materialStaticSCB.setAttrAtLocation(
                    materialLocationPath, matParamsPath + "specularModelType",
                    FnAttribute.IntAttribute(1))
                if matDefItem[0] == "col3":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        matParamsPath + "specularEdgeColor",
                        FnAttribute.FloatAttribute(matDefItem[1], 3))
                elif matDefItem[0] == "image":
                    imageNodeName = "PSNTexture%i" % (imageNodeCount)
                    imageNodeCount += 1
                    self.addImageShadingNode(materialStaticSCB,
                                             materialLocationPath,
                                             matDefItem[1], imageNodeName)
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        matAttrPath + "connections.specularEdgeColor",
                        FnAttribute.StringAttribute("resultRGB@" +
                                                    imageNodeName))
            elif matDefName == "specRoughness":
                if matDefItem[0] == "float":
                    actualRoughnessValue = self.adjustSpecRoughnessToAlpha(
                        matDefItem[1]
                    ) if convertSpecRoughnessValues == 1 else matDefItem[1]
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        matParamsPath + "specularRoughness",
                        FnAttribute.FloatAttribute(actualRoughnessValue))
                elif matDefItem[0] == "image":
                    imageNodeName = "PSNTexture%i" % (imageNodeCount)
                    imageNodeCount += 1
                    self.addImageShadingNode(materialStaticSCB,
                                             materialLocationPath,
                                             matDefItem[1], imageNodeName)
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        matAttrPath + "connections.specularRoughness",
                        FnAttribute.StringAttribute("resultA@" +
                                                    imageNodeName))
Exemplo n.º 10
0
    def generateMaterialAttributes(self, materialDefinition, materialStaticSCB,
                                   materialLocationPath,
                                   convertSpecRoughnessValues,
                                   enableCausticsInArnold):
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, "material.style",
            FnAttribute.StringAttribute("network"))

        nodeName = "ArnoldShadingNode"
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, "material.terminals.arnoldSurface",
            FnAttribute.StringAttribute(nodeName))
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, "material.terminals.arnoldSurfacePort",
            FnAttribute.StringAttribute("out"))

        matAttrPath = "material.nodes." + nodeName + "."
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, matAttrPath + "name",
            FnAttribute.StringAttribute(nodeName))
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, matAttrPath + "type",
            FnAttribute.StringAttribute("standard_surface"))
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, matAttrPath + "target",
            FnAttribute.StringAttribute("arnold"))
        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, matAttrPath + "srcName",
            FnAttribute.StringAttribute(nodeName))

        imageNodeCount = 1

        matParamsPath = matAttrPath + "parameters."
        if enableCausticsInArnold:
            materialStaticSCB.setAttrAtLocation(materialLocationPath,
                                                matParamsPath + "caustics",
                                                FnAttribute.IntAttribute(1))

        for matDefName, matDefItem in materialDefinition.iteritems():
            if matDefName == "diffColour":
                materialStaticSCB.setAttrAtLocation(
                    materialLocationPath, matParamsPath + "base",
                    FnAttribute.FloatAttribute(1.0))
                if matDefItem[0] == "col3":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath, matParamsPath + "base_color",
                        FnAttribute.FloatAttribute(matDefItem[1], 3))
                elif matDefItem[0] == "image":
                    imageNodeName = "ASNImage%i" % (imageNodeCount)
                    imageNodeCount += 1
                    self.addImageShadingNode(materialStaticSCB,
                                             materialLocationPath,
                                             matDefItem[1], imageNodeName)
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        matAttrPath + "connections.base_color",
                        FnAttribute.StringAttribute("out@" + imageNodeName))
            elif matDefName == "diffRoughness":
                if matDefItem[0] == "float":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        matParamsPath + "diffuse_roughness",
                        FnAttribute.FloatAttribute(matDefItem[1]))
                elif matDefItem[0] == "image":
                    imageNodeName = "ASNImage%i" % (imageNodeCount)
                    imageNodeCount += 1
                    self.addImageShadingNode(materialStaticSCB,
                                             materialLocationPath,
                                             matDefItem[1], imageNodeName)
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        matAttrPath + "connections.diffuse_roughness",
                        FnAttribute.StringAttribute("out@" + imageNodeName))
            elif matDefName == "refraIndex" and matDefItem[0] == "float":
                materialStaticSCB.setAttrAtLocation(
                    materialLocationPath, matParamsPath + "specular_IOR",
                    FnAttribute.FloatAttribute(matDefItem[1]))
            if matDefName == "specColour":
                if matDefItem[0] == "col3":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath, matParamsPath + "specular_color",
                        FnAttribute.FloatAttribute(matDefItem[1], 3))
                elif matDefItem[0] == "image":
                    imageNodeName = "ASNImage%i" % (imageNodeCount)
                    imageNodeCount += 1
                    self.addImageShadingNode(materialStaticSCB,
                                             materialLocationPath,
                                             matDefItem[1], imageNodeName)
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        matAttrPath + "connections.specular_color",
                        FnAttribute.StringAttribute("out@" + imageNodeName))
            elif matDefName == "specRoughness":
                if matDefItem[0] == "float":
                    actualRoughnessValue = self.adjustSpecRoughnessToAlpha(
                        matDefItem[1]
                    ) if convertSpecRoughnessValues == 1 else matDefItem[1]
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        matParamsPath + "specular_roughness",
                        FnAttribute.FloatAttribute(actualRoughnessValue))
                elif matDefItem[0] == "image":
                    imageNodeName = "ASNImage%i" % (imageNodeCount)
                    imageNodeCount += 1
                    self.addImageShadingNode(materialStaticSCB,
                                             materialLocationPath,
                                             matDefItem[1], imageNodeName)
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        matAttrPath + "connections.specular_roughness",
                        FnAttribute.StringAttribute("out@" + imageNodeName))
Exemplo n.º 11
0
    def generateMaterialAttributes(self, materialDefinition, materialStaticSCB,
                                   materialLocationPath,
                                   convertSpecRoughnessValues,
                                   enableCausticsInArnold):
        shaderNameItem = "otherSurfaceShader"
        shaderParamsItem = "otherSurfaceParams"

        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, "material." + shaderNameItem,
            FnAttribute.StringAttribute("surfaces/basic"))

        attrLevelItemPath = "material." + shaderParamsItem + "."

        for matDefName, matDefItem in materialDefinition.iteritems():
            if matDefName == "diffColour":
                if matDefItem[0] == "col3":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "diffuseColor",
                        FnAttribute.FloatAttribute(matDefItem[1], 3))
                elif matDefItem[0] == "image":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "diffuseTextureMap",
                        FnAttribute.StringAttribute(matDefItem[1]))
            elif matDefName == "diffRoughness":
                if matDefItem[0] == "float":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "diffuseRoughness",
                        FnAttribute.FloatAttribute(matDefItem[1]))
                elif matDefItem[0] == "image":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "diffuseRoughnessTextureMap",
                        FnAttribute.StringAttribute(matDefItem[1]))
            elif matDefName == "refraIndex" and matDefItem[0] == "float":
                materialStaticSCB.setAttrAtLocation(
                    materialLocationPath, attrLevelItemPath + "ior",
                    FnAttribute.FloatAttribute(matDefItem[1]))
            elif matDefName == "specColour":
                # Arnold is always GGX, so we'll match that
                materialStaticSCB.setAttrAtLocation(
                    materialLocationPath,
                    attrLevelItemPath + "microfacetModel",
                    FnAttribute.FloatAttribute(1.0))
                if matDefItem[0] == "col3":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "specularColor",
                        FnAttribute.FloatAttribute(matDefItem[1], 3))
                elif matDefItem[0] == "image":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "specularTextureMap",
                        FnAttribute.StringAttribute(matDefItem[1]))
            elif matDefName == "specRoughness":
                if convertSpecRoughnessValues == 2:
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "specularRoughnessValueMapping",
                        FnAttribute.FloatAttribute(1.0))
                if matDefItem[0] == "float":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "specularRoughness",
                        FnAttribute.FloatAttribute(matDefItem[1]))
                elif matDefItem[0] == "image":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "specularRoughnessTextureMap",
                        FnAttribute.StringAttribute(matDefItem[1]))
    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")
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()
Exemplo n.º 14
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()
Exemplo n.º 15
0
    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())
		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))

nodeTypeBuilder.setParametersTemplateAttr(gb.build())

nodeTypeBuilder.setHintsForParameter('location', {'widget' : 'scenegraphLocation'})
nodeTypeBuilder.setHintsForParameter('generateType', {'widget' : 'mapper',
				 'options' : 'regular cube of points:0|read from file:1'})
nodeTypeBuilder.setHintsForParameter('fileType', {'widget' : 'mapper',
				 'options' : 'ASCII positions (space separated):0|ASCII positions and radii (space separated):1',
				 'conditionalVisOp' : 'equalTo', 'conditionalVisPath' : '../generateType', 'conditionalVisValue' : '1'})
Exemplo n.º 17
0
    def generateMaterialAttributes(self, materialDefinition, materialStaticSCB,
                                   materialLocationPath,
                                   convertSpecRoughnessValues,
                                   enableCausticsInArnold):
        shaderNameItem = "imagineSurfaceShader"
        shaderParamsItem = "imagineSurfaceParams"

        materialStaticSCB.setAttrAtLocation(
            materialLocationPath, "material." + shaderNameItem,
            FnAttribute.StringAttribute("StandardImage"))

        attrLevelItemPath = "material." + shaderParamsItem + "."

        for matDefName, matDefItem in materialDefinition.iteritems():
            if matDefName == "diffColour":
                if matDefItem[0] == "col3":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath, attrLevelItemPath + "diff_col",
                        FnAttribute.FloatAttribute(matDefItem[1], 3))
                elif matDefItem[0] == "image":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "diff_col_texture",
                        FnAttribute.StringAttribute(matDefItem[1]))
            elif matDefName == "diffRoughness":
                if matDefItem[0] == "float":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "diff_roughness",
                        FnAttribute.FloatAttribute(matDefItem[1]))
                elif matDefItem[0] == "image":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "diff_roughness_texture",
                        FnAttribute.StringAttribute(matDefItem[1]))
            elif matDefName == "refraIndex" and matDefItem[0] == "float":
                materialStaticSCB.setAttrAtLocation(
                    materialLocationPath,
                    attrLevelItemPath + "refraction_index",
                    FnAttribute.FloatAttribute(matDefItem[1]))
            elif matDefName == "specColour":
                # Arnold is always GGX, so we'll match that
                materialStaticSCB.setAttrAtLocation(
                    materialLocationPath,
                    attrLevelItemPath + "microfacet_type",
                    FnAttribute.StringAttribute("ggx"))
                if matDefItem[0] == "col3":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath, attrLevelItemPath + "spec_col",
                        FnAttribute.FloatAttribute(matDefItem[1], 3))
                elif matDefItem[0] == "image":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "spec_col_texture",
                        FnAttribute.StringAttribute(matDefItem[1]))
            elif matDefName == "specRoughness":
                if matDefItem[0] == "float":
                    actualRoughnessValue = matDefItem[1]
                    if convertSpecRoughnessValues == 2:
                        actualRoughnessValue = self.adjustSpecRoughnessFromAlpha(
                            actualRoughnessValue)
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "spec_roughness",
                        FnAttribute.FloatAttribute(actualRoughnessValue))
                elif matDefItem[0] == "image":
                    materialStaticSCB.setAttrAtLocation(
                        materialLocationPath,
                        attrLevelItemPath + "spec_roughness_texture",
                        FnAttribute.StringAttribute(matDefItem[1]))
Exemplo n.º 18
0
    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())