Ejemplo n.º 1
0
def appendShaders(menuDefinition, prefix="/Arnold"):

    with IECoreArnold.UniverseBlock():

        it = arnold.AiUniverseGetNodeEntryIterator(arnold.AI_NODE_SHADER
                                                   | arnold.AI_NODE_LIGHT)

        while not arnold.AiNodeEntryIteratorFinished(it):

            nodeEntry = arnold.AiNodeEntryIteratorGetNext(it)
            shaderName = arnold.AiNodeEntryGetName(nodeEntry)
            displayName = " ".join(
                [IECore.CamelCase.toSpaced(x) for x in shaderName.split("_")])

            if arnold.AiNodeEntryGetType(nodeEntry) == arnold.AI_NODE_SHADER:
                menuPath = prefix + "/Shader/" + displayName
                nodeType = GafferArnold.ArnoldShader
            else:
                menuPath = prefix + "/Light/" + displayName
                nodeType = GafferArnold.ArnoldLight

            menuDefinition.append(
                menuPath, {
                    "command":
                    GafferUI.NodeMenu.nodeCreatorWrapper(
                        IECore.curry(__shaderCreator, shaderName, nodeType)),
                })

        arnold.AiNodeEntryIteratorDestroy(it)

        arnold.AiEnd()
Ejemplo n.º 2
0
        typeParams[entryTypeName] = paramsList
    else:
        # We want the final list to be the union between the existing list and paramsList
        # So first we copy the existing list for this type
        prevParamList = typeParams[entryTypeName]
        # We create a new list that we'll set afterwards
        newList = []
        for prevParam in prevParamList:
            # for each of the existing parameters, we check if it also exists in this node entry
            if prevParam in paramsList:
                # it also exists, let's add it back to our list
                newList.append(prevParam)
        # Setting the updated list of parameters back to our dictionary
        typeParams[entryTypeName] = newList

ai.AiNodeEntryIteratorDestroy(nodeEntryIter)  # iterators need to be deleted

# list of the node entries that need an API schema, along with the list of parameters to ignore
ignoreShapeAttributes = ['matrix']
ignoreLightAttributes = [
    'intensity', 'color', 'exposure', 'diffuse', 'specular', 'normalize',
    'matrix'
]
ignoreCameraAttributes = [
    'matrix', 'shutter_start', 'shutter_end', 'near_clip', 'far_clip'
]

nativeUsdList = {
    'shape':
    ignoreShapeAttributes,
    'polymesh':
Ejemplo n.º 3
0
def appendShaders(menuDefinition, prefix="/Arnold"):

    MenuItem = collections.namedtuple("MenuItem", ["menuPath", "nodeCreator"])

    # Build a list of menu items we want to create.

    categorisedMenuItems = []
    uncategorisedMenuItems = []
    with IECoreArnold.UniverseBlock(writable=False):

        it = arnold.AiUniverseGetNodeEntryIterator(arnold.AI_NODE_SHADER
                                                   | arnold.AI_NODE_LIGHT)

        while not arnold.AiNodeEntryIteratorFinished(it):

            nodeEntry = arnold.AiNodeEntryIteratorGetNext(it)
            shaderName = arnold.AiNodeEntryGetName(nodeEntry)
            displayName = " ".join(
                [IECore.CamelCase.toSpaced(x) for x in shaderName.split("_")])

            category = __aiMetadataGetStr(nodeEntry, "",
                                          "gaffer.nodeMenu.category")
            if category == "":
                continue

            if arnold.AiNodeEntryGetType(nodeEntry) == arnold.AI_NODE_SHADER:
                menuPath = "Shader"
                if shaderName == "light_blocker":
                    nodeCreator = functools.partial(
                        __shaderCreator, shaderName,
                        GafferArnold.ArnoldLightFilter)
                else:
                    nodeCreator = functools.partial(__shaderCreator,
                                                    shaderName,
                                                    GafferArnold.ArnoldShader)
            else:
                menuPath = "Light"
                if shaderName != "mesh_light":
                    nodeCreator = functools.partial(__shaderCreator,
                                                    shaderName,
                                                    GafferArnold.ArnoldLight)
                else:
                    nodeCreator = GafferArnold.ArnoldMeshLight

            if category:
                menuPath += "/" + category.strip("/")
            menuPath += "/" + displayName

            if category:
                categorisedMenuItems.append(MenuItem(menuPath, nodeCreator))
            else:
                uncategorisedMenuItems.append(MenuItem(menuPath, nodeCreator))

        arnold.AiNodeEntryIteratorDestroy(it)

    # Tidy up uncategorised shaders into a submenu if necessary.

    rootsWithCategories = set(
        [m.menuPath.partition("/")[0] for m in categorisedMenuItems])

    for i, menuItem in enumerate(uncategorisedMenuItems):
        s = menuItem.menuPath.split("/")
        if s[0] in rootsWithCategories:
            uncategorisedMenuItems[i] = MenuItem(
                "/".join([s[0], "Other", s[1]]), menuItem.nodeCreator)

    # Create the actual menu items.

    for menuItem in categorisedMenuItems + uncategorisedMenuItems:
        menuDefinition.append(
            prefix + "/" + menuItem.menuPath, {
                "command":
                GafferUI.NodeMenu.nodeCreatorWrapper(menuItem.nodeCreator),
                "searchText":
                "ai" + menuItem.menuPath.rpartition("/")[2].replace(" ", ""),
            })