Houdini Engine 1.9
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages

Instancing is very important to games. Without it, game levels would be hopelessly heavy with geometry. Houdini and Houdini Engine have built-in support to help deal with instancing effectively. Inside Houdini, instancing is handled by the use of Instance objects. An Instance object is an object level node with some special properties. Inside Houdini, an Instance node looks like the following:


The first thing is make sure the Point Instancing parameter is set to Full point instancing as shown in the screenshot.

If the Instance Object parameter is filled out, Houdini will try to create instances of the specified object. If the instance object is something that resides within the same asset, then it will be brought in along with the rest of the asset into the host environment, and the HAPI_ObjectInfo::objectToInstanceId will be set to the object id of that object. The host can then look up the object by its id and instance it.

Underneath the instance object (or inside it, rather) is another network of nodes, where geometry is being computed (a SOP network, in Houdini speak). Only in this case, the geometry isn't in the form of triangles and normals that you'd display directly, but rather it is a point cloud. Each point of the this point cloud has a position and several other attributes on it that indicate the proper orientation of the object to be instanced ("N", "up", "scale"). Here is a picture of what that point cloud might look like:


Once objects have been instanced onto the points, here is what this looks like in the host environment:


To find the transform to use at each point, use HAPI_GetInstanceTransforms(). This function takes into account the reserved attributes (such as "N" and "up") and returns a transform for every single point in the point cloud. You could then apply this transform in the host environment to the object you wish to instance.

The instance object field is simple, but it has a shortcoming: it assumes only one object is to be instanced. In many cases, such as the pictures above, each point might have a different geometry instanced to it. In this case, we can make use of a special attribute with the name instance:


As you can see from the figure above, the per point attribute instance is determining the model to be used at each point. This information can be extracted in the host environment through the attribute query functions covered earlier.