Friday, June 24, 2011

Houdini Notebook #4: OBJ Files Across Maya and Houdini

Importing and exporting OBJ files is pretty easy. In this notebook, I just want to go into more detail about using them across the two softwares.

Maya to Houdini

Lets take this Maya scene of five objects. I could export each object into separate OBJ files. But say this is a character and I would like it to be just one file.

If I select all of the objects and go to the export dialogue, I can check on 'Groups'. This will let the OBJ data to recognize that there are 5 "groups" in this geometry.

When we bring in the file in Houdini, sometimes the normals will turn out strange. To fix that, just use a Facet SOP, and 'Pre-Compute Normals' checked. Now if we take a look at the information...

...we see that we have 5 primitive groups with the same names as the objects in Maya. We also have the UV information coming in as a Vertex attribute, so that's useful. Geometry coming from Maya usually comes with Normal and UV data embedded. Groups created in Maya will also appear in the list.

Houdini to Maya

Here is a ground chunk model I created in Houdini. Before exporting this geometry as OBJ, we should first prepare the data we want embedded in the file.

I need to create primitive groups for each of the chunks. Depending on the model's topology, the methods may vary. For this one, I can just use a Connectivity SOP to Partition SOP.

Next, it is a good idea to clean out unnecessary attributes. This will help keep the OBJ's file size to a minimum. Besides, Maya cannot use data such as point color and point velocity. The Clean SOP is a convenient way to do this. Just remove everything but the Normal and UV attributes. Make sure that the UV attribute is a Vertex type attribute and not a Point type.

Also clean out unused groups. Make sure that, one, they are Primitive type groups and not Point type. And, two, that no primitives are a member to more than one group. Maya doesn't like that too much.

Now in Maya's Import Options menu, check 'Multiple Objects' so that each group you created in Houdini will come in as a separate object. The other stuff in the menu is optional.

There you go. Sometimes the edges come in hard. You can just use Maya's Soften Edge function to fix that.

Our UVs came in OK too.

What if you have animation? What if your UVs change over time? Well that's another story. For now I just wanted to focus on OBJ files in general.

Friday, June 10, 2011

Houdini Notebook #3: Camera Clipping Points/Particles

Here is a neat trick that will clip points or particles that are not seen through the camera. Note that this will not work well with geometry.

After your particles, use a UV Texture SOP and set it to 'Perspective From Camera'. Enter the camera you are using. This will create a uv[3] point attribute onto the particles. In the field of view of the camera, u is the horizontal, v is the vertical, and w is the depth. u and v range from 0 to 1, while w is the distance from the camera.

So after that, just use the Delete SOP and use $MAPU, $MAPV, and $MAPW to delete the range of uv values.

If you use 'Near Clipping' and 'Far Clipping' on the camera, the u, v, and w values of points that lay outside of the clip will be 0.

So before you copy objects on the particles, or add a particle fluid surface, you can use this trick to clip out the points you don't see in frame. This could avoid tons of unneeded calculations. But be careful if you have shadows or reflections, this might result in some popping.

You could also pad the deletion to be safe, say:
$MAPU <= -0.5 || $MAPU >= 1.5

Or maybe instead of just deleting the points, you could reduce detail or something.

Here is a Digital Asset that does all of this:
Download [ sop_cameraclip.otl ]

Thursday, June 9, 2011

Houdini Notebook #2: SOP Attributes to DOPs

You can easily use attributes that you created in SOPs in DOPs by using the point( ) or prim( ) expressions. In DOPs, the syntax is, for example:

point( $OBJID, 0, "Cd", 0)

Here I am grouping the pieces of the fractured object by primitive color:

Here I am using a Velocity Impulse Force DOP to give a sudden push in velocity at frame 30. In SOPs, I created a vector attribute called impulse.

If your attribute values change over time, you can check 'Use Deforming Geometry' in the DOP object nodes or use a SOP Solver to update the attributes every frame.

Wednesday, June 8, 2011

Houdini Notebook #1: Vectors Along a Curve

Ever need a vector attribute that runs along a curve? Maybe you want to use it as a force for particle movement or FLIP fluids. Here are a few easy ways to do it.

One of the most underused and badly named SOPs in Houdini, the Polyframe SOP. If used on a curve, this will create a tangent attribute along the u coordinate. By default, this attribute is named tangentu, but you can just enter something more commonly used for effects, like N or v.


You can also use a Point SOP, go to the Force tab, and check on Add Edge Force. The vector point attribute created is called edge_dir. You can later remap this to N or v.

If you need to reverse the direction of the vectors, just use a Reverse SOP before doing these procedures.