Maya LightLink Tool

Light Linking in Maya may appear at times to be black magic, this tool aims to
demystify it and make fixing problems effortless for any user.
Unfortunately, some lightlinking tools/scripts actually create more problems.
This tool is designed to safely clean scenes anytime, and additionally provide
tools for efficiently light linking. For more info, read the full help docs.

Released under: http://www.gnu.org/licenses/gpl-3.0.html
Download MayaLightLinkTool here (contains 1 directory with readme, license, and 2 python scripts)

 

Example of before and after cleaning:

Actually, here’s the full description from the help():

requires: pymel 1.0+, getNodesPM
developed with Maya2011
tested with Maya2009

Designed to clean light linking back to "no light links" clean. Scenes, even
    without any lights, can sometimes be plagued by excessive light links.
    Maya's Light Link Editor is useless if there are no lights, and is impossible
    for cleanup. This problem often arises from improper light linking, poor
    cleaning tools, or what seems to be no reason at all. Described below are
    known causes for Light Link expansion.
In any case, this tools is designed to be comprehensive for cleaning, and also
    includes relevant shortcuts for linking properly and diagnostics.
    
This tool is not designed to reproduce features of Maya's Light Link Editor or 
    Rendering > Lighting/Shading Menu. It does offer improved workflow shortcuts
    for some equivalent functions however. If you want visual feedback, open up
    the Light Link Editor or Hypershade/Hypergraph to see what's going on. If
    you need separate control over light/shadow links, use the Maya menu
    instead, just be aware you will no longer be limited to linking sets only.

Note on Light Linking practices:
    Maya can create "light links" between lights and Geometry, or Sets of
    either. Autodesk documentation explains that Sets are preferred:
    http://download.autodesk.com/us/maya/2011help/Commands/lightlink.html
    
    Light Links between individual objects or lights quickly create a mess, use
    objectSets instead. It's cleaner, and more obvious, even if you are just
    linking one light to one object! As far as this tool is concerned, any
    individual light or object linked to something is bad and will be cleaned,
    because there's no way to tell its intention; this type of light link can
    also contradict other links. For this reason, the tool is designed around
    deliberately linking with Sets only, all other links get cleaned back to
    normal required links only. Don't worry, you can destroy the deliberate
    links too if you choose.
    
    shadingGroups as objectSets: Unreliable method because rebuilding default
    links has no way to determine if connection to defaultLightSet was
    deliberately broken. Use a new objectSet instead and its Light Linking
    should override the shadingGroup's connection to defaultLightSet; that way,
    all members of the shadingGroup don't necessarily have to be lit by default.
    
    Another note: Lights with 'Illuminate by default' off are not a members of
    the defaultLightSet, and so will be off.
    In order to link those lights to specific things, you should create:
        - an objectSet for the exclusive LIGHTS (not in default light set) 
        - an objectSet for the exclusive MESHES (also receives default lights)
    Then, make or break links as necessary. The objectSet with geometry can
    contain all geometry in the scene if you wish. If you want that geometry to
    be affected by ONLY those lights, "Make Links" between them, then
    "Break Links" between the geometry objectSet and the defaultLightSet.
    
    #===========================================================================
    # IMPORTANT: For deliberate light linking, always use sets of objects and
    # lights, NEVER individual lights or objects.
    #===========================================================================
    
Known Cause of Light Link Expansion 1: Links come in pairs, cleanup should too!
    At minimum (i.e. ignoring shadow linking), each shadingGroup should have one
    connection to lightLinker1, such as:
        (initialShadingGroup.message --> lightLinker1.link[*].object)
    For each connection from any set to lightLinker1, there should be a matching
    connection from the defaultLightSet to the lightLinker node, such as:
        (defaultLightSet.message --> lightLinker1.link[*].light)
    Proof of Concept --- Create a new (empty) scene and run this:

[sourcecode language=’python’]import LightLinkTool
ll = LightLinkTool.LightLinkTool()
ll.buildUI()
ll.bad_repair(iterations=100)
del ll[/sourcecode]

Known Cause of Light Link Expansion 2: Maya's Light Link Editor, avoid using it.
    The Rendering > Lighting/Shading Menu items to make/break links are fine.
    
Features:
    1 - Cleanup.
            LightLink counter updates automatically after any clean or
            rebuild action. Recount button allows manual recount any time.
    1a - Auto Cleanup.
            No options or feedback besides the counter update.
            Safe for use by anyone any time, not just lighters/TDs.
    1b - Manual Cleanup.
            Requires clicking two buttons successively instead of
            one. Allows the inquisitive lighter/TD to see exactly what is
            performed, if chosen.
        "Preserve Manual Links" preserves deliberate light linking as described
            above. Recommended ON.
        "Preserve Reference Links" will skip operation on referenced nodes.
            Ignoring this can create unnecessary, redundant, or futile links.
            Instead, you should clean links in the references themselves, or
            dare to save reference edits.  Recommended ON.
        "Verbose" will print what is performed.
        "Dry Run" (or Test mode) forces Verbose on, but performs no action.
    2 - Tools.
            Workflow shortcuts. *Improvements upon regular commands.
            I don't recommend Light Linking generally, but if you want to, these
            buttons should be relevant and useful.
        "Create Sets" buttons create an objectSet based on selection with either
            lights or geometry only. Just a shortcut that filters set contents.
        "Light Linking" executes lightlink 'make' or 'break' command for regular
            and shadow links, and ensures the use of objectSets.
        "Affecting/Effected" selects lights affecting (lighting or shadowing)
            the currently selected objects (or objectSets), or the geometry
            effected (lit or shadowed) by the currently selected lights
            (or objectSets). Unlike Maya's equivalent command, this works for
            multiple objects/lights at once (although you CAN select multiple,
            Maya's Rendering > Lighting/Shading Menu command is hard coded to
            only use the first object/light).
        "Light not in defaultLightSet" just in case you want to know.
        "LightLinker node" each scene should only have one, unless you break its
            outgoing connections, at which point a new one will be created, 
            (don't do that; this tool wont let you, only incoming connections
            should ever be broken). Useful for graphing in the hypershade/graph.
        
Usage Examples:

[sourcecode language=’python’]# GUI mode
import LightLinkTool
LightLinkTool.loadUI()

# command-line cleanup:
import LightLinkTool
ll = LightLinkTool.LightLinkTool()
ll.destroy();ll.rebuild()[/sourcecode]


One Reply to “Maya LightLink Tool”

  1. At some point I’ll Add/Revise these features to the Tools section:
    select defaultLightSet members
    select defaultLightSet non-members
    add selected lights to defaultLightSet
    remove selected lights from defaultLightSet

Leave a Reply

Your email address will not be published.