Jump to content

Python Shelf Tool To Create Nurbs Hulls


Atom

Recommended Posts

I was watching a video on how to model cleanly with skinning nurbs curves and I thought that entire process could be turned into a shelf tool script.

Here is a script that makes a series of nurbs curves and skins them. Then all you have to do it tweak points on each curve to shape the result into the surface you need.

nurbs_tweak.gif.7b51ccf822b9c4c5d56dd9298ad9cdc9.gif

Place this code into a new shelf tool button and give it a try.

import hou

# Make a list out of points.
lst_points = []
i = 3
if i == 0:
    # Each curve is a circle made up of 8 points.
    obj_name = 'geo_circle_nurbs_8_points'
    coords ="0.199896,-0.00135633,0 0.141061,0.135946,0 0.000196548,0.201143,0 -0.148343,0.129586,0 -0.199228,0.000404187,0 -0.140393,-0.140737,0 0.00112954,-0.199571,0 0.147421,-0.139146,0 "
if i == 1:
    # Each curve is a circle made up of 12 points.
    obj_name = 'geo_circle_nurbs_12_points'
    coords ="0.200049,-2.80302e-05,0 0.178722,0.0897887,0 0.105347,0.173801,0 3.18798e-06,0.200027,0 -0.102717,0.173868,0 -0.176395,0.0946115,0 -0.199966,-2.77692e-05,0 -0.177798,-0.0917639,0 -0.108816,-0.162907,0 -8.24313e-05,-0.199995,0 0.11598,-0.165246,0 0.181712,-0.0912162,0 "
if i == 2:
    # Each curve is a circle made up of 16 points.
    obj_name = 'geo_circle_nurbs_16_points'
    coords ="0.199989,-1.26676e-05,0 0.190041,0.0731502,0 0.156104,0.130593,0 0.0953511,0.176511,0 -2.58479e-05,0.199939,0 -0.0919984,0.179028,0 -0.150667,0.13433,0 -0.185264,0.0771601,0 -0.199996,6.17147e-05,0 -0.188199,-0.0731249,0 -0.151323,-0.13508,0 -0.0916997,-0.179085,0 -5.45059e-05,-0.200103,0 0.0895729,-0.179231,0 0.151534,-0.129568,0 0.188371,-0.0707092,0 "
if i == 3:
    # Each curve is a square made up of 16 points.
    obj_name = 'geo_square_nurbs_16_points'
    coords ="0.2,0.0,0 0.2,0.1,0 0.2,0.2,0 0.1,0.2,0 0,0.2,0 -0.1,0.2,0 -0.2,0.2,0 -0.2,0.1,0 -0.2,0,0 -0.2,-0.1,0 -0.2,-0.2,0 -0.1,-0.2,0 0,-0.2,0 0.1,-0.2,0 0.2,-0.2,0 0.2,-0.1,0 "

ary_points = coords.split(" ")
for s in ary_points:
    vector = s.split(",")
    if len(vector) == 3:
        lst_points.append((float(vector[0]),float(vector[1]),float(vector[2])))

# Create new object to contain internal nurbs curves.
obj = hou.node('/obj').createNode('geo', obj_name)
obj.node('file1').destroy()
merge = obj.createNode('merge')

offset = 0.25
curve_count = 9
for n in range(curve_count):
    curve_name = "nurbs%s" % (n+1)
    curve = obj.createNode('curve', curve_name)
    geo = curve.geometry()
    hou_parm = curve.parm("type")
    hou_parm.set("nurbs")
    hou_parm = curve.parm("method")
    hou_parm.set("breakpoints")
    hou_parm = curve.parm("coords")
    
    s = ""
    for v in lst_points:
        s += "%s,%s,%s " % (v[0],v[1],v[2]+ (n*offset))
        
    hou_parm.set(s)
    hou_parm = curve.parm("close")
    hou_parm.set(1)
    curve.moveToGoodPosition()
    trans = obj.createNode('xform')
    trans.setInput(0,curve)
    trans.moveToGoodPosition()
    merge.setInput(n,trans)
    merge.moveToGoodPosition()
    
skin = obj.createNode('skin')
skin.setInput(0,merge)
skin.moveToGoodPosition()
convert = obj.createNode('convert')
hou_parm = convert.parm("lodu")
hou_parm.set(0.25)
hou_parm = convert.parm("lodv")
hou_parm.set(0.25)
convert.setInput(0,skin)
convert.moveToGoodPosition()
convert.setDisplayFlag(1)
convert.setRenderFlag(1)

 

Untitled-1.jpg

Edited by Atom
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...