Dupliverts MEL script for Maya

I hate writing (and reading) long blog posts, but it appears I'm about to put up another one. If you're not into reading long posts, you're probably not into MEL scripting either so it works out. :)

After some encouragement from Pete Molinero (http://petemolinero.wordpress.com/), I decided to dig out an in-progress modeling tool I had been working on this past semester, dust it off and start work on bringing it to a useable state. I call it my "dupliverts" script, and it's modeled after an identically-named tool available in Blender 3D.

Basically, it works like this: you define a parent object and a child object and the script will duplicate copies of the child object onto the parent object's vertices. This is actually one point where it differs pretty significantly from the one in Blender; in that program, the tool would create instances of your child object instead of actually duplicating it (pretty misleading considering the name, huh?). Sort of like a particle instancer where you emit static particles from an object's vertices, actually; except in Blender you could set it up super easy with a click of a button, and you could freely move the instances (as a group) off the parent object wherever you wanted.

But yeah, in my script, it actually duplicates the child object.

There are advantages and disadvantages to both approaches, and I'm currently running into some maintenance issues with my way (having 100 individual objects named "tree1, tree2, tree3..." is a little cumbersome). Also, you can't do things like add a different shader to the base object and have it show up in all the rest...

That being said, however, it does give you a significantly greater level of control versus using a particle instancer, as you can individually move every single object afterward. (Just a note: I have seen a script that will replace particles instances with actual geometry, but I've never tried it...) Also, you can easily gain control over coverage percentage and can randomize placement with a few clicks, something that would eat up tons of time in the particle systems window. I'm sure there's a way of doing the geometry instancing for my script as well, I honestly just haven't checked into it.

All that being said...here's a screen capture of a small forest as an example of the script. I created three trees by hand, and the script did the rest.

Pretty nifty, huh? I'm pretty happy with the features written in so far, but I do have a growing list of changes and additions I want to make. The current feature set:

- Support for multiple child objects in a single operation
- Can choose x, y, or z axis of child object(s) to align to parent object's vertex normals (aim your objects!)
- Can randomize child object's size
- Can randomize child object's position
- Can specify percent of coverage for child object (based on parent object's number of vertices)

Now, here are the current features/updates I would like to write in (most will be pretty simple):

- Clean up resulting meshes from the script (grouping, etc.). Perhaps have a option to combine all duplicated objects into a single object?
- Ability to overdrive all random input values (they only allow for 1 Maya unit difference right now)
- Ability to specify certain axis to disregard when calculating random position movement
- Ability to work on faces as well as vertices!
- Ability to switch between geometry duplication and instancing? I'd especially like to find some way of linking all the new objects' shaders to the base one (maybe there's an option for something like this in Maya, but I haven't looked into it). If I were customizing the tool for a specific project, a randomized shader option could definitely be written in.

Now, to the slightly annoying part. I'm definitely going to release it online for anyone who wants to use it, but I'd rather wait until some of the changes are done, I can bug-test it, and I've gotten a chance to improve the code (definitely NOT as efficient as it could be right now). So, feel free to give comments or suggestions; this is more a learning experience for me than anything else, and I'm up for trying out different things.


(wow...that post is way too long...)