def buildPxrUsdInOpArgsFromDownstreamNode(self, downstreamNode, graphState, portIndex=0): if not hasattr(self, '_argsCookTmp'): self._argsCookTmp = {} key = (FnAttribute.GroupBuilder().set('graphState', graphState.getOpSystemArgs()).set( 'node', hash(downstreamNode)).set( 'portIndex', portIndex).build().getHash()) # Set a dynamic entry that's not prefixed with "var:" so it won't show up # in op system args (or other graph state comparisons other than hash # uniqueness) useGraphState = graphState.edit().setDynamicEntry( kArgsCookTmpKeyToken, FnAttribute.StringAttribute(key)).build() # trigger a cook with this unique graph state Nodes3DAPI.CreateClient(downstreamNode, graphState=useGraphState, portIndex=portIndex) if key in self._argsCookTmp: result = self._argsCookTmp[key] return result else: # TODO, exception? pass
def registerShapeID(): """ Registers a new ShapeID node type using the NodeTypeBuilder utility class. """ from Katana import Nodes3DAPI from Katana import FnAttribute def buildShapeIDOpChain(node, interface): """ Defines the callback function used to define the Ops chain for the node type being registered. @type node: C{Nodes3DAPI.NodeTypeBuilder.ShapeID} @type interface: C{Nodes3DAPI.NodeTypeBuilder.BuildChainInterface} @param node: The node for which to define the Ops chain @param interface: The interface providing the functions needed to set up the Ops chain for the given node. """ # Get the current frame time frameTime = interface.getGraphState().getTime() # Set the minimum number of input ports interface.setMinRequiredInputs(1) argsGb = FnAttribute.GroupBuilder() # Parse the CEL parameter celParam = node.getParameter('CEL') if celParam: argsGb.set('CEL', celParam.getValue(frameTime)) # Parse the displacement parameter pathParam = node.getParameter('regedit') if pathParam: argsGb.set('regedit', pathParam.getValue(frameTime)) # Add the ShapeID Op to the Ops chain interface.appendOp('ShapeID', argsGb.build()) # Create a NodeTypeBuilder to register the new type nodeTypeBuilder = Nodes3DAPI.NodeTypeBuilder('ShapeID') # Add an input port nodeTypeBuilder.setInputPortNames(('in', )) # Build the node's parameters gb = FnAttribute.GroupBuilder() gb.set('CEL', FnAttribute.StringAttribute('')) gb.set('regedit', FnAttribute.StringAttribute('*.json')) # Set the parameters template nodeTypeBuilder.setParametersTemplateAttr(gb.build()) # Set parameter hints nodeTypeBuilder.setHintsForParameter('CEL', {'widget': 'cel'}) # Set the callback responsible to build the Ops chain nodeTypeBuilder.setBuildOpChainFnc(buildShapeIDOpChain) # Build the new node type nodeTypeBuilder.build()
def buildOpChain(self, interface): interface.setExplicitInputRequestsEnabled(True) graphState = interface.getGraphState() frameTime = interface.getFrameTime() locations = self.getParameter("locations") if locations: gb = FnAttribute.GroupBuilder() for loc in locations.getChildren(): gb.set( "defaultMotionPaths." + FnAttribute.DelimiterEncode(loc.getValue(frameTime)), FnAttribute.IntAttribute(1)) existingValue = ( interface.getGraphState().getDynamicEntry("var:pxrUsdInSession")) if isinstance(existingValue, FnAttribute.GroupAttribute): gb.deepUpdate(existingValue) graphState = (graphState.edit().setDynamicEntry( "var:pxrUsdInSession", gb.build()).build()) interface.addInputRequest("in", graphState)
def buildOpChain(self, interface): interface.setMinRequiredInputs(0) gb = FnAttribute.GroupBuilder() gb.set('fileName', interface.buildAttrFromParam( self.getParameter('fileName'))) gb.set('location', interface.buildAttrFromParam( self.getParameter('location'))) gb.set('isolatePath', interface.buildAttrFromParam( self.getParameter('isolatePath'))) gb.set('variants', interface.buildAttrFromParam( self.getParameter('variants'))) gb.set('ignoreLayerRegex', interface.buildAttrFromParam( self.getParameter('ignoreLayerRegex'))) gb.set('motionSampleTimes', interface.buildAttrFromParam( self.getParameter('motionSampleTimes'))) gb.set('verbose', interface.buildAttrFromParam( self.getParameter('verbose'), numberType=FnAttribute.IntAttribute)) gb.set('instanceMode', interface.buildAttrFromParam( self.getParameter('instanceMode'))) sessionValues = ( interface.getGraphState().getDynamicEntry("var:pxrUsdInSession")) if isinstance(sessionValues, FnAttribute.GroupAttribute): gb.set('session', sessionValues) gb.set('system', interface.getGraphState().getOpSystemArgs()) # our primary op in the chain that will create the root location sscb = FnGeolibServices.OpArgsBuilders.StaticSceneCreate(True) # check for any extra attributes or namespaces set downstream # via graph state extra = interface.getGraphState().getDynamicEntry('var:usdExtraAttributesOrNamespaces') if extra: gb.set('extraAttributesOrNamespaces', extra) argsOverride = interface.getGraphState().getDynamicEntry('var:pxrUsdInArgs') if isinstance(argsOverride, FnAttribute.GroupAttribute): gb.update(argsOverride) # add the PxrUsdIn op as a sub op pxrUsdInArgs = gb.build() sscb.addSubOpAtLocation(self.getScenegraphLocation( interface.getFrameTime()), 'PxrUsdIn', pxrUsdInArgs) sscb.setAttrAtLocation('/root', 'info.usdLoader', FnAttribute.StringAttribute('PxrUsdIn')) interface.appendOp('StaticSceneCreate', sscb.build())
def buildOpChain(self, interface): interface.setMinRequiredInputs(0) frameTime = interface.getGraphState().getTime() # simpler case for the archive if self.getParameter('asArchive').getValue(frameTime): sscb = FnGeolibServices.OpArgsBuilders.StaticSceneCreate(True) location = self.getScenegraphLocation(frameTime) sscb.createEmptyLocation(location, 'usd archive') gb = FnAttribute.GroupBuilder() for name in ('fileName', 'isolatePath'): gb.set(name, interface.buildAttrFromParam( self.getParameter(name))) gb.set('currentTime', FnAttribute.DoubleAttribute(frameTime)) attrs = gb.build() sscb.setAttrAtLocation(location, 'geometry', attrs) if self.getParameter('includeProxyForArchive').getValue(frameTime): sscb.addSubOpAtLocation(location, 'UsdIn.AddViewerProxy', attrs) interface.appendOp('StaticSceneCreate', sscb.build()) return graphState = interface.getGraphState() pxrUsdInArgs = self.buildPxrUsdInOpArgsAtGraphState(graphState) # When buildOpChain is reached as result of a call to # buildPxrUsdInOpArgsFromDownstreamNode, an additional entry will be # present in the graphState (otherwise not meaningful to the cooked scene). # If found, we'll record opArgs at the specified key in a member variable # dict. argsCookTmpKey = graphState.getDynamicEntry(kArgsCookTmpKeyToken) if isinstance(argsCookTmpKey, FnAttribute.StringAttribute): self._argsCookTmp[argsCookTmpKey.getValue('', False)] = pxrUsdInArgs # our primary op in the chain that will create the root location sscb = FnGeolibServices.OpArgsBuilders.StaticSceneCreate(True) sscb.addSubOpAtLocation(self.getScenegraphLocation( interface.getFrameTime()), 'UsdIn', pxrUsdInArgs) sscb.setAttrAtLocation('/root', 'info.usdLoader', FnAttribute.StringAttribute('UsdIn')) interface.appendOp('StaticSceneCreate', sscb.build())
def buildPxrUsdInOpArgsAtGraphState(self, graphState): gb = FnAttribute.GroupBuilder() frameTime = graphState.getTime() gb.set('fileName', self.getParameter('fileName').getValue(frameTime)) gb.set('location', self.getParameter('location').getValue(frameTime)) gb.set('isolatePath', self.getParameter('isolatePath').getValue(frameTime)) gb.set('variants', self.getParameter('variants').getValue(frameTime)) gb.set('ignoreLayerRegex', self.getParameter('ignoreLayerRegex').getValue(frameTime)) gb.set('motionSampleTimes', self.getParameter('motionSampleTimes').getValue(frameTime)) gb.set('verbose', int(self.getParameter('verbose').getValue(frameTime))) gb.set('instanceMode', self.getParameter('instanceMode').getValue(frameTime)) gb.set('prePopulate', int(self.getParameter('prePopulate').getValue(frameTime))) sessionValues = ( graphState.getDynamicEntry("var:pxrUsdInSession")) if isinstance(sessionValues, FnAttribute.GroupAttribute): gb.set('session', sessionValues) gb.set('system', graphState.getOpSystemArgs()) gb.set('processStageWideQueries', FnAttribute.IntAttribute(1)) gb.set('setOpArgsToInfo', FnAttribute.IntAttribute(1)) # check for any extra attributes or namespaces set downstream # via graph state extra = graphState.getDynamicEntry('var:usdExtraAttributesOrNamespaces') if extra: gb.set('extraAttributesOrNamespaces', extra) argsOverride = graphState.getDynamicEntry('var:pxrUsdInArgs') if isinstance(argsOverride, FnAttribute.GroupAttribute): gb.update(argsOverride) pxrUsdInArgs = gb.build() return pxrUsdInArgs
def build_pass_resolve_op_chain(node, interface): """ """ module_logger.debug("PassResolve - build_pass_resolve_op_chain()") interface.setMinRequiredInputs(0) frame_time = interface.getGraphState().getTime() active_pass_location_param = node.getParameter("activePassLocation") # Setup the currently active pass in the SceneGraph. attribute_set_args_builder = FnGeolibServices.OpArgsBuilders.AttributeSet() attribute_set_args_builder.setCEL(["/root"]) if active_pass_location_param.getValue(frame_time): attribute_set_args_builder.setAttr( "passResolve.activePassLocation", FnAttribute.StringAttribute( active_pass_location_param.getValue(frame_time))) interface.appendOp("AttributeSet", attribute_set_args_builder.build()) # Expose all locations under "/root/world" to the PassVisibility Op that will # set the appropriate locations as visible or not, as per the setup of the currently # active pass. group_builder = FnAttribute.GroupBuilder() attribute_set_args_builder = FnGeolibServices.OpArgsBuilders.AttributeSet() attribute_set_args_builder.setCEL(["/root/world//*"]) attribute_set_args_builder.addSubOp("PassVisibility", group_builder.build()) interface.appendOp("AttributeSet", attribute_set_args_builder.build()) # Expose all locations under "/root/world" to the PassRays Op that will # set the rays related attributes on the appropriate locations, which are renderer dependent, # as per the setup of the currently active pass. group_builder = FnAttribute.GroupBuilder() attribute_set_args_builder = FnGeolibServices.OpArgsBuilders.AttributeSet() attribute_set_args_builder.setCEL(["/root/world//*"]) attribute_set_args_builder.addSubOp("PassRays", group_builder.build()) interface.appendOp("AttributeSet", attribute_set_args_builder.build()) # Expose the "/root" location to the PassCollections Op that will # create collections attributes on the root location, according the to active pass configuration. group_builder = FnAttribute.GroupBuilder() attribute_set_args_builder = FnGeolibServices.OpArgsBuilders.AttributeSet() attribute_set_args_builder.setCEL(["/root"]) attribute_set_args_builder.addSubOp("PassCollections", group_builder.build()) interface.appendOp("AttributeSet", attribute_set_args_builder.build())
def buildCubeMakerOpChain(node, interface): """ Defines the callback function used to create the Ops chain for the node type being registered. @type node: C{Nodes3DAPI.NodeTypeBuilder.CubeMaker} @type interface: C{Nodes3DAPI.NodeTypeBuilder.BuildChainInterface} @param node: The node for which to define the Ops chain @param interface: The interface providing the functions needed to set up the Ops chain for the given node. """ # Get the current frame time frameTime = interface.getGraphState().getTime() # Set the minimum number of input ports interface.setMinRequiredInputs(0) argsGb = FnAttribute.GroupBuilder() # Parse node parameters locationParam = node.getParameter('location') numberOfCubesParam = node.getParameter('numberOfCubes') rotateCubesParam = node.getParameter('rotateCubes') maxRotationParam = node.getParameter('maxRotation') if locationParam: location = locationParam.getValue(frameTime) # The base location is encoded using nested group attributes # defining a hierarchy where the elements in the location paths # are interleaved with group attributes named 'c' (for child). # The last element will contain a group attribute, named 'a', # which in turn will hold an attribute defining the number of # cubes to be generated. # See the Ops source code for more details locationPaths = location[1:].split('/')[1:] attrsHierarchy = \ '.'.join([x for t in zip(['c',] * len(locationPaths), locationPaths) for x in t]) argsGb.set( attrsHierarchy + '.a.numberOfCubes', FnAttribute.IntAttribute( numberOfCubesParam.getValue(frameTime))) if rotateCubesParam.getValue(frameTime) == 1: argsGb.set( attrsHierarchy + '.a.maxRotation', FnAttribute.DoubleAttribute( maxRotationParam.getValue(frameTime))) # Add the CubeMaker Op to the Ops chain interface.appendOp('CubeMaker', argsGb.build())
def buildOpChain(node, interface): """ Configures the Ops to represent the current state of the node. The calling mechanism in Node3D takes are of ensuring that the underlying Op network is only updated if Op Args and types have changed. @type node: C{Nodes3DAPI.NodeTypeBuilder.SubdividedSpace} @type interface: C[Nodes3DAPI.NodeTypeBuilder.BuildChainInterface} @param node: The node to build the Op and OpArgs from (ie: an instance of our node). @param interface: The interface that will configure the Ops in the underlying Op network. """ # Ensure the runtime doesn't error for us if there are no inputs on the # Node - as we want to allow it to exist in isolation. The default is 1 interface.setMinRequiredInputs(0) # We first need the current time for parameter value queries frameTime = interface.getGraphState().getTime() # Get the parameters from our node maxDepthParam = node.getParameter("maxDepth") subdivParam = node.getParameter("subdivisions") locationParam = node.getParameter("location") if not locationParam or not maxDepthParam or not subdivParam: raise RuntimeError("Missing node parameters, require " + "'location', 'maxdepth' and 'subdivisions'") # Build the Op args from our node argsGb = FnAttribute.GroupBuilder() argsGb.set("maxDepth", FnAttribute.IntAttribute(maxDepthParam.getValue(frameTime))) argsGb.set("subdivisions", FnAttribute.IntAttribute(subdivParam.getValue(frameTime))) # We want to use the StaticSceneCreate Op to build the parent # hierarchy, so that our op only has to worry about generating its # children. Its args are somewhat complex, but fortunately, there # is a helper class that makes it all much easier. rootLocation = locationParam.getValue(frameTime) sscb = FnGeolibServices.OpArgsBuilders.StaticSceneCreate() sscb.addSubOpAtLocation(rootLocation, "SubdividedSpace", argsGb.build()) interface.appendOp("StaticSceneCreate", sscb.build())
def buildOpChain(self, interface): interface.setExplicitInputRequestsEnabled(True) graphState = interface.getGraphState() frameTime = interface.getFrameTime() location = self.getParameter("location").getValue(frameTime) variantSetName = '' if self.getParameter("args.variantSetName.enable").getValue(frameTime): variantSetName = self.getParameter("args.variantSetName.value").getValue( frameTime) variantSelection = None if self.getParameter("args.variantSelection.enable").getValue(frameTime): variantSelection = self.getParameter( "args.variantSelection.value").getValue(frameTime) if location and variantSetName and variantSelection is not None: entryName = FnAttribute.DelimiterEncode(location) entryPath = "variants." + entryName + "." + variantSetName valueAttr = FnAttribute.StringAttribute(variantSelection) gb = FnAttribute.GroupBuilder() gb.set(entryPath, valueAttr) for addLocParam in self.getParameter( 'additionalLocations').getChildren(): location = addLocParam.getValue(frameTime) if location: entryName = FnAttribute.DelimiterEncode(location) entryPath = "variants." + entryName + "." + variantSetName gb.set(entryPath, valueAttr) existingValue = ( interface.getGraphState().getDynamicEntry("var:pxrUsdInSession")) if isinstance(existingValue, FnAttribute.GroupAttribute): gb.deepUpdate(existingValue) graphState = (graphState.edit() .setDynamicEntry("var:pxrUsdInSession", gb.build()) .build()) interface.addInputRequest("in", graphState)
def buildOpChain(self, interface): interface.setExplicitInputRequestsEnabled(True) graphState = interface.getGraphState() frameTime = interface.getFrameTime() locationsParam = self.getParameter("locations") attrName = self.getParameter('attrName').getValue(frameTime).replace( '.', ':') locations = [ y for y in (x.getValue(frameTime) for x in locationsParam.getChildren()) if y ] if attrName and locations: typeValue = self.getParameter('type').getValue(frameTime) if typeValue == 'string': valueAttr = interface.buildAttrFromParam( self.getParameter('stringValue')) else: valueAttr = interface.buildAttrFromParam( self.getParameter('numberValue'), numberType=__numberAttrTypes.get(typeValue, FnAttribute.FloatAttribute)) entryGroup = (FnAttribute.GroupBuilder().set('value', valueAttr).build()) gb = FnAttribute.GroupBuilder() for loc in locations: gb.set( "attrs.%s.%s" % ( FnAttribute.DelimiterEncode(loc), attrName, ), entryGroup) existingValue = ( interface.getGraphState().getDynamicEntry("var:pxrUsdInSession")) if isinstance(existingValue, FnAttribute.GroupAttribute): gb.deepUpdate(existingValue) graphState = (graphState.edit().setDynamicEntry( "var:pxrUsdInSession", gb.build()).build()) interface.addInputRequest("in", graphState)
def buildShapeIDOpChain(node, interface): """ Defines the callback function used to define the Ops chain for the node type being registered. @type node: C{Nodes3DAPI.NodeTypeBuilder.ShapeID} @type interface: C{Nodes3DAPI.NodeTypeBuilder.BuildChainInterface} @param node: The node for which to define the Ops chain @param interface: The interface providing the functions needed to set up the Ops chain for the given node. """ # Get the current frame time frameTime = interface.getGraphState().getTime() # Set the minimum number of input ports interface.setMinRequiredInputs(1) argsGb = FnAttribute.GroupBuilder() # Parse the CEL parameter celParam = node.getParameter('CEL') if celParam: argsGb.set('CEL', celParam.getValue(frameTime)) # Parse the displacement parameter pathParam = node.getParameter('regedit') if pathParam: argsGb.set('regedit', pathParam.getValue(frameTime)) # Add the ShapeID Op to the Ops chain interface.appendOp('ShapeID', argsGb.build())
def buildOpChain(self, interface): interface.setMinRequiredInputs(0) graphState = interface.getGraphState() pxrUsdInArgs = self.buildPxrUsdInOpArgsAtGraphState(graphState) # When buildOpChain is reached as result of a call to # buildPxrUsdInOpArgsFromDownstreamNode, an additional entry will be # present in the graphState (otherwise not meaningful to the cooked scene). # If found, we'll record opArgs at the specified key in a member variable # dict. argsCookTmpKey = graphState.getDynamicEntry(kArgsCookTmpKeyToken) if isinstance(argsCookTmpKey, FnAttribute.StringAttribute): self._argsCookTmp[argsCookTmpKey.getValue('', False)] = pxrUsdInArgs # our primary op in the chain that will create the root location sscb = FnGeolibServices.OpArgsBuilders.StaticSceneCreate(True) sscb.addSubOpAtLocation(self.getScenegraphLocation( interface.getFrameTime()), 'PxrUsdIn', pxrUsdInArgs) sscb.setAttrAtLocation('/root', 'info.usdLoader', FnAttribute.StringAttribute('PxrUsdIn')) interface.appendOp('StaticSceneCreate', sscb.build())
def buildGeoScalerOpChain(node, interface): """ Defines the callback function used to create the Ops chain for the node type being registered. @type node: C{Nodes3DAPI.NodeTypeBuilder.GeoScaler} @type interface: C{Nodes3DAPI.NodeTypeBuilder.BuildChainInterface} @param node: The node for which to define the Ops chain @param interface: The interface providing the functions needed to set up the Ops chain for the given node. """ # Get the current frame time frameTime = interface.getGraphState().getTime() # Set the minimum number of input ports interface.setMinRequiredInputs(1) argsGb = FnAttribute.GroupBuilder() # Parse node parameters CELParam = node.getParameter("CEL") if CELParam: CEL = CELParam.getValue(frameTime) argsGb.set("CEL", CEL) scaleParam = node.getParameter('scale') if scaleParam: scale = scaleParam.getValue(frameTime) argsGb.set("scale", scale) # Add the GeoScaler Op to the Ops chain interface.appendOp('GeoScaler', argsGb.build())
def __init__(self, locationPath, locationType): self.locationPath = locationPath self.locationType = locationType self.staticSCB = FnGeolibServices.OpArgsBuilders.StaticSceneCreate() self.staticSCB.createEmptyLocation(self.locationPath) self.staticSCB.setAttrAtLocation( self.locationPath, 'type', FnAttribute.StringAttribute(self.locationType))
def appendToParametersOpChain(self, interface): frameTime = interface.getFrameTime() location = self.getScenegraphLocation(frameTime) variantSetName = '' if self.getParameter('args.variantSetName.enable').getValue(frameTime): variantSetName = self.getParameter( 'args.variantSetName.value').getValue(frameTime) # This makes use of the attrs recognized by PxrUsdInUtilExtraHintsDap # to provide the hinting from incoming attr values. uiscript = ''' local variantSetName = Interface.GetOpArg('user.variantSetName'):getValue() local variantsGroup = (Interface.GetAttr('info.usd.variants') or GroupAttribute()) local variantSetNames = {} for i = 0, variantsGroup:getNumberOfChildren() - 1 do variantSetNames[#variantSetNames + 1] = variantsGroup:getChildName(i) end Interface.SetAttr("__pxrUsdInExtraHints." .. Attribute.DelimiterEncode("__variantUI.variantSetName"), GroupBuilder() :set('widget', StringAttribute('popup')) :set('options', StringAttribute(variantSetNames)) :set('editable', IntAttribute(1)) :build()) local variantOptions = {} if variantSetName ~= '' then local variantOptionsAttr = variantsGroup:getChildByName(variantSetName) if Attribute.IsString(variantOptionsAttr) then variantOptions = variantOptionsAttr:getNearestSample(0.0) end end Interface.SetAttr("__pxrUsdInExtraHints." .. Attribute.DelimiterEncode("__variantUI.variantSelection"), GroupBuilder() :set('widget', StringAttribute('popup')) :set('options', StringAttribute(variantOptions)) :set('editable', IntAttribute(1)) :build()) ''' sscb = FnGeolibServices.OpArgsBuilders.StaticSceneCreate(True) sscb.addSubOpAtLocation( location, 'OpScript.Lua', FnAttribute.GroupBuilder().set('script', uiscript).set('user.variantSetName', variantSetName).build()) interface.appendOp('StaticSceneCreate', sscb.build())
def buildViewerTagSetOpChain(node, interface): """ Defines the callback function used to define the Ops chain for the node type being registered. @type node: C{Nodes3DAPI.NodeTypeBuilder.Messer} @type interface: C{Nodes3DAPI.NodeTypeBuilder.BuildChainInterface} @param node: The node for which to define the Ops chain @param interface: The interface providing the functions needed to set up the Ops chain for the given node. """ # Get the current frame time frameTime = interface.getGraphState().getTime() # Set the minimum number of input ports interface.setMinRequiredInputs(1) argsGb = FnAttribute.GroupBuilder() # Parse the CEL parameter celParam = node.getParameter('CEL') if celParam: argsGb.set('CEL', celParam.getValue(frameTime)) # Parse the color parameter colorRParam = node.getParameter('color.red') if colorRParam: argsGb.set('color.red', colorRParam.getValue(frameTime)) colorGParam = node.getParameter('color.green') if colorGParam: argsGb.set('color.green', colorGParam.getValue(frameTime)) colorBParam = node.getParameter('color.blue') if colorBParam: argsGb.set('color.blue', colorBParam.getValue(frameTime)) colorParam = node.getParameter('color') # Parse the pickable parameter pickableParam = node.getParameter('pickable') if pickableParam: argsGb.set( 'pickable', FnAttribute.IntAttribute(pickableParam.getValue(frameTime))) # Add the Messer Op to the Ops chain interface.appendOp('ViewerTagSet', argsGb.build())
def buildMaterialDescribeOpChain(node, interface): interface.setMinRequiredInputs(0) baseLocationParam = node.getParameter('baseLocation') baseLocationString = baseLocationParam.getValue(0) materialNameParam = node.getParameter('materialName') materialNameString = materialNameParam.getValue(0) descriptionParam = node.getParameter('description') descriptionString = descriptionParam.getValue(0) specRoughnessValuesConversionTypeParam = node.getParameter( 'specRoughnessValuesConversionType') specRoughnessValuesConversionTypeValue = specRoughnessValuesConversionTypeParam.getValue( 0) enableCausticsInArnoldParam = node.getParameter( 'enableCausticsInArnold') enableCausticsInArnoldValue = bool( enableCausticsInArnoldParam.getValue(0)) materialDefinition = parseMaterialDescription(descriptionString) rendererListGroupParam = node.getParameter('rendererList') renderersToMakeMatsFor = [] numRendererItems = rendererListGroupParam.getNumChildren() for i in range(0, numRendererItems): subItemParam = rendererListGroupParam.getChildByIndex(i) intValue = subItemParam.getValue(0) if intValue == 0: continue rendererName = MaterialPlugin.pluginsNameList[i] renderersToMakeMatsFor.append(rendererName) materialLocationPath = os.path.join(baseLocationString, rendererName, materialNameString) materialStaticSCB = FnGeolibServices.OpArgsBuilders.StaticSceneCreate( ) materialStaticSCB.createEmptyLocation(materialLocationPath) materialStaticSCB.setAttrAtLocation( materialLocationPath, 'type', FnAttribute.StringAttribute('material')) # invoke the renderer material plugin to create its attributes on the location... pluginResult = MaterialPlugin.pluginsDict[rendererName] pluginInstance = pluginResult[2] # todo: use keyword / dict for all these options... pluginInstance.generateMaterialAttributes( materialDefinition, materialStaticSCB, materialLocationPath, specRoughnessValuesConversionTypeValue, enableCausticsInArnoldValue) interface.appendOp("StaticSceneCreate", materialStaticSCB.build())
def buildOpChain(self, interface): interface.appendOp("PxrUsdInResolveMaterialBindings", FnAttribute.GroupBuilder() .set("purpose", interface.buildAttrFromParam( self.getParameter('purpose'))) .set("omitIfParentValueMatches", interface.buildAttrFromParam( self.getParameter('omitIfParentValueMatches'), numberType=FnAttribute.IntAttribute)) .build())
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)
def addImageShadingNode(self, materialStaticSCB, materialLocationPath, imagePath, nodeName): matAttrPath = "material.nodes." + nodeName + "." materialStaticSCB.setAttrAtLocation( materialLocationPath, matAttrPath + "name", FnAttribute.StringAttribute(nodeName)) materialStaticSCB.setAttrAtLocation( materialLocationPath, matAttrPath + "type", FnAttribute.StringAttribute("image")) materialStaticSCB.setAttrAtLocation( materialLocationPath, matAttrPath + "target", FnAttribute.StringAttribute("arnold")) materialStaticSCB.setAttrAtLocation( materialLocationPath, matAttrPath + "srcName", FnAttribute.StringAttribute(nodeName)) materialStaticSCB.setAttrAtLocation( materialLocationPath, matAttrPath + "parameters.filename", FnAttribute.StringAttribute(imagePath))
def addImageShadingNode(self, materialStaticSCB, materialLocationPath, imagePath, nodeName): matAttrPath = "material.nodes." + nodeName + "." materialStaticSCB.setAttrAtLocation( materialLocationPath, matAttrPath + "name", FnAttribute.StringAttribute(nodeName)) materialStaticSCB.setAttrAtLocation( materialLocationPath, matAttrPath + "type", FnAttribute.StringAttribute("PxrTexture")) materialStaticSCB.setAttrAtLocation( materialLocationPath, matAttrPath + "target", FnAttribute.StringAttribute("prman")) materialStaticSCB.setAttrAtLocation( materialLocationPath, matAttrPath + "srcName", FnAttribute.StringAttribute(nodeName)) convertedFilename = self.replacementTexture(imagePath) materialStaticSCB.setAttrAtLocation( materialLocationPath, matAttrPath + "parameters.filename", FnAttribute.StringAttribute(convertedFilename))
def buildOpChain(self, interface): interface.setExplicitInputRequestsEnabled(True) graphState = interface.getGraphState() frameTime = interface.getFrameTime() locationsParam = self.getParameter("locations") locations = [ y for y in (x.getValue(frameTime) for x in locationsParam.getChildren()) if y ] if locations: existingValue = (graphState.getDynamicEntry("var:pxrUsdInSession") or FnAttribute.GroupAttribute()) # later nodes set to 'replace' win out maskIsFinal = existingValue.getChildByName('maskIsFinal') if not maskIsFinal: gb = FnAttribute.GroupBuilder() gb.update(existingValue) mode = self.getParameter('mode').getValue(frameTime) if mode == 'replace': gb.set('mask', FnAttribute.StringAttribute(locations)) gb.set('maskIsFinal', 1) else: existingLocationsAttr = existingValue.getChildByName('mask') if isinstance(existingLocationsAttr, FnAttribute.StringAttribute): locations.extend(existingLocationsAttr.getNearestSample(0)) gb.set('mask', FnAttribute.StringAttribute(locations)) graphState = (graphState.edit().setDynamicEntry( "var:pxrUsdInSession", gb.build()).build()) interface.addInputRequest("in", graphState)
def stripBlacklistAttrs(attrs, blacklist): """ Strip blacklisted attributes from the given attributes. Examples of blacklisted attributes are internal-only attributes or ones that may change depending on the context in which this test is executed. """ gb = FnAttribute.GroupBuilder() gb.update(attrs) for attrName in blacklist: gb.delete(attrName) return gb.build()
def registerAutoLookfileAssign(): """ Registers a new AutoLookfileAssign node type using the NodeTypeBuilder utility class. """ from Katana import Nodes3DAPI from Katana import FnAttribute def buildAutoLookfileAssignOpChain(node, interface): """ Defines the callback function used to create the Ops chain for the node type being registered. @type node: C{Nodes3DAPI.NodeTypeBuilder.AutoLookfileAssign} @type interface: C{Nodes3DAPI.NodeTypeBuilder.BuildChainInterface} @param node: The node for which to define the Ops chain @param interface: The interface providing the functions needed to set up the Ops chain for the given node. """ # Get the current frame time frameTime = interface.getGraphState().getTime() # Set the minimum number of input ports interface.setMinRequiredInputs(1) argsGb = FnAttribute.GroupBuilder() # Add the AutoLookfileAssign Op to the Ops chain interface.appendOp('AutoLookfileAssign', argsGb.build()) # Create a NodeTypeBuilder to register the new type nodeTypeBuilder = Nodes3DAPI.NodeTypeBuilder('alaAutoLookfile') # Add input port nodeTypeBuilder.setInputPortNames(("in",)) # Build the node's parameters gb = FnAttribute.GroupBuilder() # Set the parameters template nodeTypeBuilder.setParametersTemplateAttr(gb.build()) # Set the callback responsible to build the Ops chain nodeTypeBuilder.setBuildOpChainFnc(buildAutoLookfileAssignOpChain) # Build the new node type nodeTypeBuilder.build()
def myBuildOps(node, interface): op = interface.buildOp('pointCloudOp') if op.areParametersDirty(): frameTime = interface.getFrameTime() op.setOpType('PointCloudOp') op.setOpArg('source', node.getParameter('source').getValue(frameTime)) op.setOpArg('dest', node.getParameter('dest').getValue(frameTime)) op.setOpArg('instance', node.getParameter('instance').getValue(frameTime)) op.setOpArg('instanceScale', FnAttribute.DoubleAttribute(node.getParameter('instanceScale').getValue(frameTime))) if op.areInputsDirty(): op.setOpInputs(interface.getAllInputOps()) return op
def build_node_parameters(self): """ """ module_logger.debug("PassResolve - build_node_parameters()") group_builder = FnAttribute.GroupBuilder() # group_builder.set("node_version", 1) group_builder.set("activePassLocation", "") group_builder.set("setupRenderNodeScript", "") parameters_hints = self.get_parameters_hints() for parameter in parameters_hints: self.setHintsForParameter(parameter, parameters_hints[parameter]) self.setParametersTemplateAttr(group_builder.build())
def build_node_parameters(self): """ """ module_logger.debug("RendererOutputExport - build_node_parameters()") group_builder = FnAttribute.GroupBuilder() # group_builder.set("node_version", 1) group_builder.set("filename", "") group_builder.set("Export.expandProcedurals", True) group_builder.set("Debug.logLevel", 20) group_builder.set("exportRendererOutput", "") parameters_hints = self.get_parameters_hints() for parameter in parameters_hints: self.setHintsForParameter(parameter, parameters_hints[parameter]) self.setParametersTemplateAttr(group_builder.build())
def buildAutoLookfileAssignOpChain(node, interface): """ Defines the callback function used to create the Ops chain for the node type being registered. @type node: C{Nodes3DAPI.NodeTypeBuilder.AutoLookfileAssign} @type interface: C{Nodes3DAPI.NodeTypeBuilder.BuildChainInterface} @param node: The node for which to define the Ops chain @param interface: The interface providing the functions needed to set up the Ops chain for the given node. """ # Get the current frame time frameTime = interface.getGraphState().getTime() # Set the minimum number of input ports interface.setMinRequiredInputs(1) argsGb = FnAttribute.GroupBuilder() # Add the AutoLookfileAssign Op to the Ops chain interface.appendOp('AutoLookfileAssign', argsGb.build())
def buildSphereMakerOpChain(node, interface): """ Defines the callback function used to create the Ops chain for the node type being registered. @type node: C{Nodes3DAPI.Node3D} @type interface: C{Nodes3DAPI.NodeTypeBuilder.OpChainInterface} @param node: The node requesting the op chain. @param interface: The interface providing the functions needed to set up the Ops chain for the given node. """ # Set the minimum number of input ports interface.setMinRequiredInputs(0) # Get the current graph state and frame time graphState = interface.getGraphState() frameTime = graphState.getTime() # Compute the actual frame time we want to use modifiedFrameTime = GetModifiedFrameTime(node, frameTime) modGraphState = graphState.edit().setTime(modifiedFrameTime).build() systemAttr = modGraphState.getOpSystemArgs() locationPath = node.getParameter('location').getValue(frameTime) numberOfSpheres = node.getParameter('numberOfSpheres').getValue(frameTime) procArgsGb = FnAttribute.GroupBuilder() procArgsGb.set('args.system', systemAttr) procArgsGb.set('generatorType', 'SphereMaker') procArgsGb.set('args.numberOfSpheres', numberOfSpheres) sscb = FnGeolibServices.OpArgsBuilders.StaticSceneCreate() sscb.addSubOpAtLocation(locationPath, 'ScenegraphGeneratorHost', procArgsGb.build()) interface.appendOp('StaticSceneCreate', sscb.build())