Maya – Mesh Append

Today I managed to finish part of my assignment early, giving me enough time to work on the new level that we’re current building for The Very Organized Thief. But once again, Maya got in the way!

One thing that Maya does really badly is instance handling, primarily within the context of level creation. In other situations, it’s instance handling is quite flexible. But when it comes to level creation and optimization, or even just making changes to an instance which you want to propagate to all other instances, you’ll be losing your mind, cursing “WHY!?”, until you finally suck it up and just re-do the work needed. Anyone who has had to apply a new material to an instance should know what I’m talking about.

Today I encountered another problem with instances. And that is to do with combining meshes within or into an instance. The problem being when you use Maya’s Mesh > Combine, it doesn’t take into account instancing as you would expect it to. It’s a big issue when you have a lot of instances of something, and you really don’t want to replace them every single time you make a change.

Uncombine mesh cubes inside a Group.

Uncombine mesh cubes inside a Group.

So to make sure I didn’t have to do that for every single thing I’ll be doing with instances and waste a bunch of time. I did some experimenting. And here’s what I did and discovered in the process. If your not quiet Maya savvy, some of this might go over your head.

First, Mesh > Combine. Using Mesh > Combine will result in all your instances except the one you are working with getting the new combined mesh. So all other instances will appear to have lost the meshes you’ve combined. To fix this, you can re-parent it back into the transform that is left behind after you combine them. But doing this means that it will be in an addition level higher in the hierarchy and it’s History can’t be deleted. Un-parenting the mesh from this hierarchy also causes Maya to do some reconstructing of node history. Very bad, very messy and potentially more destructive when working with big levels, not recommended!

Combine mesh result using Maya's Mesh > Combine. New mesh is re-parented into hierarchy to allow mesh to appear in other instances.

Combine mesh result using Maya’s Mesh > Combine. New mesh is re-parented into hierarchy to allow mesh to appear in other instances.

To avoid all the badness, you can write a MEL script to “manually” connect the meshShapes you want to combine into a polyUnite node, then plug it’s output into polySurfaceShapes inMesh attribute. It’s the same as doing Mesh > Combine, but you can write code to manage all the relationships for instancing, handle where that mesh information should go and make the connections a little more cleanly. Maya’s version, not only doesn’t handle instancing, it adds additional nodes and connections.

I tried do it that way. But I only ended up confusing myself, and made a complete mess. It’s probably possible but it would probably require more time then I could be bothered with committing to it.

I ended up going with writing a Maya Plugin.

In 3D Studio Max the Edit Poly modifier has a tool called “Append Mesh”, which basically lets you click a mesh object in the scene to be added to one your working in. It also takes into account Instances… I think. It’s been about 5-6 years since I last used it so I could be wrong, but I do remember never having to complain about how it handled instancing… REGARDLESS! I wanted to mimic that behaviour.

What I ended up doing was writing a custom MEL command in C++ using the Maya API, that takes your current selection and appends any mesh data to the last selected mesh. Copying the polygons from one mesh into the target. It’s pretty simple and works pretty well. The result is in about an hours work, I have a tool which lets me append meshes into other meshes including instances!

Custom plugin to maintain neatness and instancing.

Custom plugin to maintain neatness and instancing.

It still needs work as you can probably tell in the above image. It currently doesn’t take into account Normals, UVs, or Vertex Coloring. It also doesn’t handle clean up of the meshes being appended, but that can be easily handled by writing MEL Script which uses the new command. But at the moment, it does what it needs to do, which is save me some time. I’ll probably add those things in the future.

The cool thing is that it can even append instances into an instance, from the same instance. I don’t know why you’d ever need to do that, but hey, bonus!

TAKE THAT MAYA!!! *shaking fist*

Leave a Reply

Protected by WP Anti Spam