Voronoi in Maya with Qhull

voronoi

Voronoi diagrams are cool, and it sucks that they aren’t in Maya. I wrote this wrapper around Qhull to create 3d voronoi diagrams. Just select a bunch of locators and run the script.

first you need to download Qhull at www.qhull.org

download my script here

run the script below in a python tab. Replace the directories with the bin’s directory from your Qhull download, and provide another temporary directory to dump the text files that Qhull creates

import dw_qvoronoi
dw_qvoronoi.main(
	qhull_dir = r"C:\Users\Danny\Documents\qhull\bin", 
	tmp_dir = r"C:\Users\Danny\Documents\qhull\tmp"
	)

the script will not clean up the temporary directory for safety reasons. I don’t want someone to delete an important directory. So just remember to clean it out each time you use it or add that functionality yourself.

I plan on exploring the Qhull c++ interface at some point to make it much faster. And I’d like to make a slick interface.

Comments

  1. K says:

    Hi, I try to run the scrip and Maya spits back:

    # Error: IOError: file My Documents/maya/scripts\dw_qvoronoi.py line 45: 2 #

    • Danny Wynne says:

      you need to pass the main() command a temporary directory, and make sure that temporary directory already exists. the script doesnt create it for you.

  2. Aaron says:

    I greatly appreciate your work on this. I am new to Qhull and am trying to create a mesh where I only render the edges (The Mesh without Faces), almost as though they are tubes or just the connections. Any advice on how I might look into altering your code to accomplish this?

    Thanks

  3. lavi1 says:

    Hi Danny,
    I have error in the script editor, any hint ?

    import dw_qvoronoi
    dw_qvoronoi.main(
    qhull_dir = r”C:\Program Files\qhull-2012.1\bin”,
    tmp_dir = r”C:\qhull\tmp”
    )
    # Error: ValueError: file C:/Users/WORKSTATION/Documents/maya/2013-x64/scripts\dw_qvoronoi.py line 172: No object matches name: pSphere1.vtx[0:381].t #

  4. Vladi says:

    Yes i am on windows7 64 bit. I turned on “show stack trace” & “Echo all comands”.
    So far i didnt receive any error massage.

    what i did is:

    qhull_dir = r”C:\Users\V\Documents\qhull-2012.1\bin”
    tmp_dir =r”C:\Users\V\Documents\qhull-2012.1\temp”

    # then select all the locators

    sel = cmds.ls(sl=1)
    points = []
    for s in sel:
    points.append(om.MPoint(*cmds.getAttr(s+”.t”)[0]))

    vor = Maya_QVoronoi(qhull_dir, tmp_dir)
    vor.voronoi_from_points(points)

    Maybe there is a problem because i have the latest version of Qhull 2012.1?

    • danny says:

      ok, so it might be that you aren’t selecting enough points, or your working in a large world space. The script trims off polys that shoot very far into space. So if you are selecting a small amount of points, almost all the voronoi cells are going to shoot off into the distance. you can increase the trimming bounding box by changing the vor.voronoi_from_points(points) function. just add limits = [100,-100,100,-100,100,-100] (change those values to be much larger). so the function should look like this:
      vor.voronoi_from_points(points, limits = [100000,-100000,100000,-100000,100000,-100000])

      hope that works, let me know!

  5. Vladi says:

    Hi Danny!

    I tried to test out your script. I downloaded the latest version of Qhull and the paths are correct.
    So when I run voronoi_from_points(points) on the instance nothing happens,
    except that in the temp folder of Qhull i receive the input_points.txt
    It would be great if you can help me out.

    Thx !

    • danny says:

      Sure I can help. Are you on windows? Is there an error in the script editor? Make sure “show stack trace” is on in script editor and send me the error. I’ll take a look at the script again tonight and see if anything stands out,
      Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *