Curves to Geometry Script

Ever wonder how to render out your nurbs curves? Maybe you wanted to do a nice rendered animation of a rig for a reel? Well, then this is the script for you 😉

 

import maya.cmds as cmds
import maya.mel as mel

# Converts every curve in the scene into a paint fx stroke and then a renderable polygon object. 
def curveGeo():
    # get all the curves in the scene.
    curves = cmds.ls(type="nurbsCurve")
    # this array will hold all of the stroke objects for our brush. We will use it to convert our strokes to polys.
    strokes = []
    # one brush for all these strokes ensures we get just one output shader for our strokes, making editing of the shader easier
    brush = cmds.createNode("brush",n="brush#")
    # this is just one of the necessary actions for the brush to work
    cmds.connectAttr("time1.outTime",brush + ".time")
    meshes = []

    for crv in curves:
        # make a stroke node and append it to our stroke array
        stroke = cmds.createNode("stroke",n="stroke#")
        strokes.append(stroke)
        # connect the attributes necessary to draw the stroke around the curve. 
        # This was found out by just doing it manually and looking at what was made in the node editor
        cmds.connectAttr(brush + ".outBrush",stroke + ".brush")
        cmds.connectAttr(crv + ".worldSpace[0]",stroke + ".pathCurve[0].curve")
        # up the samples for sharp cornered objects like arrows
        cmds.setAttr(stroke + ".pathCurve[0].samples",255)
        cmds.setAttr(stroke + ".displayPercent",100)
        cmds.setAttr(brush + ".depth",1)
        cmds.setAttr(brush + ".globalScale",.25)

    for shape in strokes:
        cmds.select(shape)
        # This command is only accessible in Mel so we have to do a Mel eval for it. 
        # Unfortunately that means we can't access the resulting groups/geo from this action, as it just returns True
        mel.eval("doPaintEffectsToPoly(1,0,1,1,100000);")
        
    cmds.select(cl=1)

# To turn off cast and recieve shadows, select all the brush groups, pickwalk down, 
# and go to Window - General Editors - Attribute Spread Sheet. 
# Under the Render tab, turn off Cast and Receive Shadows.
Advertisements
Image

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s