1. Forums
  2. Discord
  3. About Mapcore
  4. Patreon Supporters
  • Login
  • Register
  • Search
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • More Options
  1. Mapcore
  2. Discussions
  3. Level Design

Vertex normal script for Maya

  • Pomperi
  • June 24, 2013 at 9:07 PM
  • Pomperi
    • June 24, 2013 at 9:07 PM
    • #1

    Hi everyone!

    I just wanted to share a script I've done for Maya to quickly be able to set the vertex normals based on the face normals. I know there are a few ways to do this within native maya, as well as a few scripts, but I haven't been able to find one which averages the normals for verts shared by multiple selected faces. This can be quite annoying when setting up curved or round surfaces.

    [Blocked Image: http://i.imgur.com/oBTdSYt.jpg]

    For 3ds max there's a great script called GetVertNormalFromFace which does this. What mine does is essentially the same but in Maya. Just make a face selection of the faces you want to set the vert normals for and run the script.

    [Blocked Image: http://i.imgur.com/98uBPfL.jpg]

    To run the script, just paste into the script editor as python and drag it to a shelf, or set it up as a hotkey

    Here's the script:

    Code
    # ---------------------------------------------------------------------------------------
    
    
    # - pompVertNormFaceAvg
    
    
    #
    
    
    # - Sets the vertex normals of a face selection,
    
    
    #   averaging normals shared by multiple selected faces.
    
    
    #
    
    
    #
    
    
    # - by Pontus Karlsson 2013 (www.pomperi.com)
    
    
    # ---------------------------------------------------------------------------------------
    
    
    
    
    import maya.cmds as cmds
    
    
    
    
    faces = cmds.filterExpand(sm=34, ex=True)
    
    
    verts = cmds.ls((cmds.polyListComponentConversion(faces, ff=True, tv=True)), flatten=True)
    
    
    normals = [[], [], []]
    
    
    
    
    for v in verts:
    
    
        conFaces = cmds.ls(cmds.polyListComponentConversion(v, fv=True, tf=True), flatten=True)
    
    
        shaFaces = list(set(conFaces).intersection(set(faces)))
    
    
        faceNorm = cmds.polyInfo(shaFaces, fn=True)
    
    
    
    
        for normal in faceNorm:
    
    
    	    label, vertex, x, y, z = normal.split()
    
    
    	    normals[0].append(float(x))
    
    
    	    normals[1].append(float(y))
    
    
    	    normals[2].append(float(z))
    
    
    
    
        x_avg = (sum(normals[0]) / len(shaFaces))
    
    
        y_avg = (sum(normals[1]) / len(shaFaces))
    
    
        z_avg = (sum(normals[2]) / len(shaFaces))
    
    
    
    
        cmds.select(v)
    
    
        cmds.polyNormalPerVertex(xyz = (x_avg, y_avg, z_avg))
    
    
    
    
        normals[:] = [[], [], []]
    
    
    
    
    cmds.select(cl=True)
    Display More

    I hope someone finds it useful

  • kikette
    • June 26, 2013 at 7:42 AM
    • #2

    Oh oh ! Smells good ! Going to test right now dude. Thanks =)

    EDIT :

    Works great. Amazing job dude !

  • Kreigore
    • July 3, 2013 at 1:42 PM
    • #3

    Awesome as usual Pomp!

  • PogoP
    • July 3, 2013 at 1:50 PM
    • #4

    Good boy Pontus. Look at you with all your fancy technical know-how.

    I use this script all the time in 3ds max. If ever I make the dirty leap to Maya, I'll be sure to give this an install!

  • Pomperi
    • July 6, 2013 at 10:15 AM
    • #5

    Hehe, thanks guys


    kikette: Glad you like it!


    I'm currently trying to re-write the script in OpenMaya to make it a bit faster. Also trying to come up with a good way to maintain hard edges, as it's quite cumbersome whenever you want to keep hard edges intact when setting up the vertex normals for a mesh. I think the best way workflow-wise is to set up hard and soft edges before manipulating the vert normals (meaning you would simply soften the whole mesh if you don't want any hard edges) then run the script and wherever there's a split, the vert normal will be set for each face individually.


    If anyone have any suggestions, that would be awesome!

  • knj
    • July 6, 2013 at 4:19 PM
    • #6

    i was looking for this lol !

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!

Register Yourself Login
Discord

The Mapcore Discord is our lively IRC channel of the 2000s reborn. Chat about level design, gaming, and more.

Latest Posts

  1. Tangerine

    Harry Poster
    July 18, 2026 at 11:10 AM
  2. Any of the old guard still around? D:

    Warby
    July 12, 2026 at 8:23 PM
  3. About our archived forums

    Thrik
    June 30, 2026 at 2:12 PM
  4. Mapcore Discord

    mason_fan123
    June 24, 2026 at 8:52 PM
  5. [CS2] Valley

    Serialmapper
    June 22, 2026 at 11:56 AM
  6. Free Music / SFX Resource - Over 2500 Tracks

    Eric Matyas
    June 18, 2026 at 12:32 PM
  7. Pango [WIP]

    Elowen
    June 11, 2026 at 10:13 AM
  8. [CS2] Dvina

    Jeremy Rivera
    June 11, 2026 at 10:03 AM
  9. Bridges 2.0 by NEXSIDE, MAP SHOWCASE. ( Steam Workshop )

    MrTrane18
    June 1, 2026 at 7:46 PM
  10. Classic Maps Reborn For CS2

    SillySpaceCat
    May 31, 2026 at 10:33 PM
  1. Privacy Policy
  2. Contact
Powered by WoltLab Suite™