Example #1
0
 def creator():
     col = collection.create(nodeName+"_col")
     col.setSelectorType(selectorType)
     sel = col.getSelector()
     sel.staticSelection.set([nodeName])
     sel.setFilterType(filterType)
     sel.setCustomFilterValue(customFilter)
     return col
Example #2
0
 def getDefaultCollection(self):
     """ Get the default collection where newly created nodes are placed """
     defaultCollectionName = "_untitled_"
     for col in nodeList.forwardListGenerator(self):
         if col.name().startswith(defaultCollectionName):
             return col
     col = collection.create(defaultCollectionName)
     self.attachCollection(self.getFirstCollectionIndex(), col)
     return col
Example #3
0
    def createCollection(self, collectionName):
        """ Create and append a new Collection

            @type collectionName: string
            @param collectionName: Name of collection to create
        """
        with profiler.ProfilerMgr('createCollection'):
            c = collection.create(collectionName)
            self.appendCollection(c)
            # Note: No need to update visibility here since it's an empty collection
            # which will not modify membership. 
            return c
Example #4
0
def createAovOverride():
    layer_name = 'charaA'  # any layer
    layer = renderSetup.instance().getRenderLayer(layer_name)  # any layer
    aov_collection = layer.aovCollectionInstance()
    aov_name = 'diffuse_albedo'  # any AOV
    sub_colle = collection.create(layer_name + '_' + aov_name,
                                  collection.AOVChildCollection.kTypeId,
                                  aovName=aov_name)
    aov_collection.appendChild(sub_colle)
    override = sub_colle.createAbsoluteOverride(
        'aiAOV_' + aov_name, 'enabled')  #(aov name, attr name)
    override.setAttrValue(0)  # override value
    override.setName(layer_name + '_' + aov_name)
Example #5
0
    def getCorrespondingCollection(self, nodeName, selectedCollectionName):
        """ 
            The behavior is to look for Render Settings attribute to add the override
            in the Render Settings collection if it exists, then to use the selected
            collection; otherwise, to create a new collection containing the override.
        """
        
        # Search if the node is part of the render settings node list
        if collection.RenderSettingsCollection.containsNodeName(nodeName):
            return self.renderSettingsCollectionInstance()

        # Search if the node is part of the AOV selector list
        if collection.AOVCollection.containsNodeName(nodeName):
            aovCol = self.aovCollectionInstance()
            # Look for a child collection whose selection contains the node            
            for childColl in aovCol.getCollections():
                if childColl and childColl.containsNodeName(nodeName):
                    return childColl
                    
            # If it doesn't exist, create a new child node
            with undo.CtxMgr(kCreateAOVChildCollection % self.name()):
                # Create a new AOV child collection and put it last in the list
                callbacks = rendererCallbacks.getCallbacks(rendererCallbacks.CALLBACKS_TYPE_AOVS)
                aovName = callbacks.getAOVName(nodeName)
                coll = collection.create(aovName, collection.AOVChildCollection.kTypeId, aovName=aovName)
                aovCol.appendChild(coll)
                return coll

        coll = self.getCollectionByName(selectedCollectionName, True) if selectedCollectionName else None
        if coll:
            return coll
        
        selectorType = selector.SimpleSelector.kTypeName
        filterType, customFilter = selector.Filters.getFiltersFor(cmds.objectType(nodeName))
        def predicate(col):
            sel = col.getSelector()
            return sel.kTypeName == selectorType and \
                sel.getPattern() == "" and \
                len(sel.staticSelection) == 1 and nodeName in sel.staticSelection and \
                sel.getFilterType() == filterType and \
                (filterType != selector.Filters.kCustom or sel.getCustomFilterValue() == customFilter)
        def creator():
            col = collection.create(nodeName+"_col")
            col.setSelectorType(selectorType)
            sel = col.getSelector()
            sel.staticSelection.set([nodeName])
            sel.setFilterType(filterType)
            sel.setCustomFilterValue(customFilter)
            return col
        return self.findCollection(predicate, creator)
Example #6
0
    def renderSettingsCollectionInstance(self):
        """ Get the render settings collection instance for this render layer,
            creating it if it doesn't exists. """

        # Check if we already have a render settings on the list
        # We can only have zero or one lights collections so pick the first
        # one we find. It is always among the first ones on the list so this 
        # search is quick.
        settings = self._getTypedCollection(collection.RenderSettingsCollection.kTypeId)
        if not settings:
            with undo.CtxMgr(kCreateRenderSettingsCollection % self.name()):
                # Create a new render settings collection and put it first in the list
                settings = collection.create("RenderSettingsCollection", collection.RenderSettingsCollection.kTypeId)
                self.attachCollection(0, settings)

        return settings
Example #7
0
    def aovCollectionInstance(self):
        """ Get the AOV collection instance for this render layer,
            creating it if it doesn't exists as long as renderer 
            callbacks are registered for the current renderer. """

        # Check if we already have an AOV collection in the list
        # We can only have zero or one AOV collections so pick the first
        # one we find. It is always among the first ones on the list so this 
        # search is quick.
        aovCollection = self._getTypedCollection(collection.AOVCollection.kTypeId)
        if not aovCollection and not rendererCallbacks.getCallbacks(rendererCallbacks.CALLBACKS_TYPE_AOVS) is None:
            with undo.CtxMgr(kCreateAOVCollection % self.name()):
                # Create a new AOV collection and put it first in the list
                aovCollection = collection.create("AOVCollection", collection.AOVCollection.kTypeId)
                settings = self._getTypedCollection(collection.RenderSettingsCollection.kTypeId)
                self.attachCollection(0 if settings is None else 1, aovCollection)

        return aovCollection
Example #8
0
    def lightsCollectionInstance(self):
        """ Get the lights collection instance for this render layer,
            creating it if it doesn't exists. """

        # Check if we already have a lights collection on the list
        # We can only have zero or one lights collections so pick the first
        # one we find. It is always among the first ones on the list so this 
        # search is quick.
        lights = self._getTypedCollection(collection.LightsCollection.kTypeId)
        if not lights:
            # Create a new light collection and put it first in the list
            with undo.CtxMgr(kCreateLightsCollection % self.name()):
                lights = collection.create("lightsCollection", collection.LightsCollection.kTypeId)
                settings = self._getTypedCollection(collection.RenderSettingsCollection.kTypeId)
                aovCollection = self._getTypedCollection(collection.AOVCollection.kTypeId)
                self.attachCollection(0 if settings is None and aovCollection is None else \
                                      2 if not settings is None and not aovCollection is None else 1, lights)

        return lights
def create_layers():
    if not pm.objExists('objs'):
        pm.confirmDialog(t='confirm',
                         m='No objs grp, please put all objects under it!',
                         b=['ok'])
        sys.exit('')

    # save origin
    current_file = pm.sceneName()
    if 'original' in current_file.basename():
        pm.saveFile()
    else:
        origin_file = current_file.dirname() + '/' + current_file.basename(
        ).stripext() + '_original' + current_file.ext
        pm.saveAs(origin_file)

    rs_ins = rs.instance()
    rs_ins.getDefaultRenderLayer().setRenderable(0)
    ar.createOptions()
    pm.setAttr("defaultArnoldDriver.ai_translator", "tif", type="string")
    # pm.setAttr('defaultArnoldDriver.mergeAOVs', 0)
    pm.setAttr('defaultRenderGlobals.imageFilePrefix',
               '<Scene>/<RenderLayer>_<RenderPass>')

    aovs.AOVInterface().addAOV('ao', aovType='rgba')
    ao = pm.createNode('aiAmbientOcclusion')
    ao.outColor >> pm.PyNode('aiAOV_ao').defaultValue

    asm = pm.createNode('aiShadowMatte')

    # rs layer
    for obj in pm.PyNode('objs').getChildren():
        # if has a rayswitch child
        flag = 1 if obj.getChildren(typ='transform') else 0

        # beauty with shadow
        print obj.name(), obj.type()

        obj.getShape().aiSubdivType.set(1)
        obj.getShape().aiSubdivIterations.set(2)

        obj.getShape().primaryVisibility.set(1)
        obj.getShape().castsShadows.set(1)
        obj.getShape().aiVisibleInDiffuseReflection.set(1)
        obj.getShape().aiVisibleInSpecularReflection.set(1)
        obj.getShape().aiVisibleInDiffuseTransmission.set(1)
        obj.getShape().aiVisibleInSpecularTransmission.set(1)
        obj.getShape().aiVisibleInVolume.set(1)
        obj.getShape().aiSelfShadows.set(1)

        rsl = rs_ins.createRenderLayer(obj.name() + '_color')

        co1 = rsl.createCollection('co1_' + obj.name())
        co1.getSelector().setPattern('*')

        skydomelight = pm.ls(typ='aiSkyDomeLight')[0]
        co1_skydome = co1.createCollection('co1_skydome_' + obj.name())
        co1_skydome.getSelector().setPattern(skydomelight)
        co1_skydome.getSelector().setFilterType(4)
        ov_skydome = co1_skydome.createOverride('ov_skydome_' + obj.name(),
                                                absOverride)
        ov_skydome.finalize('aiCastShadows')
        ov_skydome.setAttrValue(1)

        co2 = co1.createCollection('co2_' + obj.name())
        co2.getSelector().setPattern('objs')

        co3 = co2.createCollection('co3_' + obj.name())
        co3.getSelector().setFilterType(2)
        other_shapes = [i for i in pm.PyNode('objs').getChildren() if i != obj]
        other_shapes_name = ', '.join(
            [i.getShape().name() for i in other_shapes])
        co3.getSelector().setPattern(other_shapes_name)
        ov1 = co3.createOverride('ov1_' + obj.name(), absOverride)
        ov1.finalize('primaryVisibility')
        ov1.setAttrValue(0)
        ov2 = co3.createOverride('ov2_' + obj.name(), absOverride)
        ov2.finalize('castsShadows')
        ov2.setAttrValue(0)

        co4 = co2.createCollection('co4_' + obj.name())
        co4.getSelector().setFilterType(2)
        co4.getSelector().setPattern(obj.getShape().name())
        ov3 = co4.createOverride('ov3_' + obj.name(), absOverride)
        ov3.finalize('aiSelfShadows')
        ov3.setAttrValue(1)

        # shadow
        rsl = rs_ins.createRenderLayer(obj.name() + '_shadow')

        aov = rsl.aovCollectionInstance()
        sub_colle = coll.create(obj.name() + '_ao',
                                coll.AOVChildCollection.kTypeId,
                                aovName='ao')
        aov.appendChild(sub_colle)
        override = sub_colle.createAbsoluteOverride('aiAOV_ao', 'enabled')
        override.setAttrValue(0)
        override.setName(obj.name() + '_ov_ao')

        co5 = rsl.createCollection('co5_' + obj.name())
        co5.getSelector().setPattern('*')

        co5_skydome = co5.createCollection('co5_skydome_' + obj.name())
        co5_skydome.getSelector().setPattern(skydomelight)
        co5_skydome.getSelector().setFilterType(4)
        ov5_skydome = co5_skydome.createOverride('ov5_skydome_' + obj.name(),
                                                 absOverride)
        ov5_skydome.finalize('aiCastShadows')
        ov5_skydome.setAttrValue(0)

        co6 = co5.createCollection('co6_' + obj.name())
        co6.getSelector().setPattern('objs')
        co7 = co6.createCollection('co7_' + obj.name())
        co7.getSelector().setFilterType(2)
        co7.getSelector().setPattern(obj.getShape().name())
        ov4 = co7.createOverride('ov4_' + obj.name(), absOverride)
        ov4.finalize('primaryVisibility')
        ov4.setAttrValue(0)

        co8 = co6.createCollection('co8_' + obj.name())
        co8.getSelector().setFilterType(2)
        co8.getSelector().setPattern(other_shapes_name)
        # co9 = co8.createCollection('co9_'+obj.name())
        # co9.getSelector().setFilterType(5)
        # co9.getSelector().setPattern('*')
        ov6 = co8.createOverride('ov6_' + obj.name(), shaderOverride)
        ov6.setShader(asm.name())
        ov7 = co8.createOverride('ov7_' + obj.name(), absOverride)
        ov7.finalize('castsShadows')
        ov7.setAttrValue(0)
        ov8 = co8.createOverride('ov8_' + obj.name(), absOverride)
        ov8.finalize('aiSelfShadows')
        ov8.setAttrValue(0)

        if flag:
            for ii in obj.getChildren(typ='transform'):
                ii.getShape().aiSubdivType.set(1)
                ii.getShape().aiSubdivIterations.set(2)

                ii.getShape().primaryVisibility.set(0)
                ii.getShape().castsShadows.set(0)
                ii.getShape().aiVisibleInDiffuseReflection.set(0)
                ii.getShape().aiVisibleInSpecularReflection.set(0)
                ii.getShape().aiVisibleInDiffuseTransmission.set(0)
                ii.getShape().aiVisibleInSpecularTransmission.set(0)
                ii.getShape().aiVisibleInVolume.set(0)
                ii.getShape().aiSelfShadows.set(0)

                ii.getShape().aiMatte.set(1)

            coa = co2.createCollection('coa_' + obj.name())
            coa.getSelector().setFilterType(2)
            rayswitch_names = ', '.join([
                i.getShape().name() for i in obj.getChildren(typ='transform')
            ])
            coa.getSelector().setPattern(rayswitch_names)
            ova = coa.createOverride('ova_' + obj.name(), absOverride)
            ova.finalize('primaryVisibility')
            ova.setAttrValue(1)

            cob = co6.createCollection('cob_' + obj.name())
            cob.getSelector().setFilterType(2)
            cob.getSelector().setPattern(rayswitch_names)
            ovb = cob.createOverride('ovb_' + obj.name(), absOverride)
            ovb.finalize('primaryVisibility')
            ovb.setAttrValue(1)

    rsl = rs_ins.createRenderLayer('all_objs')
    co = rsl.createCollection('co_all')
    co.getSelector().setPattern('*')

    # save after script
    modify_file = current_file.dirname() + '/' + current_file.basename(
    ).stripext() + '_modify' + current_file.ext
    pm.saveAs(modify_file)