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

Curves are often an important source of input in terms of user control. In this case we want curves that can be fed into the underlying Houdini asset to influence its computation, but which also appear in the host environment so they can be displayed and manipulated by the user.

Houdini Engine currently provides two alternative mechanisms for inputting curves from the host application: Curve Nodes and Curve Marshalling.

The Curve Node

A Curve Node is an easy way to create a curve OBJ node representing a single curve that can be manipulated and fed as an input for other nodes. See Asset Inputs for more on inputs.

You instantiate a curve node with a call to HAPI_CreateNode(), using "SOP/curve" for the operator_name and -1 for parent_node_id. You get back a HAPI_NodeId that can be used like for any other node. See Nodes.

The way this node is intended to be used is via its exposed parameters. The curve points (CVs) themselves are stored as a space-separated list string parameter named "coords". Other parameters exist to change properties on the curve such as primitive type, method, order and whether or not it is closed.

Curve Output

It is often necessary to access curve data, as curve data, that has been produced as a result of computation. Curves come as parts. You can tell if a part is a curve if HAPI_PartInfo::type is equal to HAPI_PARTTYPE_CURVE. A curves part can contain one or more curves as a curve mesh. Here are the general steps to get curve information:

  1. Having a curve part, fill a HAPI_CurveInfo struct using HAPI_GetCurveInfo(). Once you know the number of curves, the number of control vertices per curve can be retrieved using HAPI_GetCurveCounts().
  2. The control vertices (CVs) themselves can be extracted via per-point attributes "P" and "Pw".
  3. Likewise, the order information for each curve can be retrieved with HAPI_GetCurveOrders().
  4. Finally, the knots themselves can be retrieved with HAPI_GetCurveKnots(). The number of knots applicable to each curve is the order of that curve plus the number of control vertices.

Note that you will get 1 part per type of curve. For example, the asset below contains a merge of 5 separate curves:

HAPI_Curves_CurveOutput2.png

Two of them, nurbs_curve and nurbs_curve2, are represented as a single part because they are both open nurbs curves, while poly_curve and bezier_curve have their own part because they are curves of a different types. Finally, closed_nurbs_curve has its own part, even though it is a Nurbs curve, because it is closed, and thus different from nurbs_curve and nurbs_curve2:

HAPI_Curves_CurveOutput1.png

Curve Marshalling

Curve Marshalling follows the same principles as Marshalling Geometry Into Houdini. Curves are just another primitive type that can be stored in a part of an Input Node. Multiple curves can be stored per part in which case they represent a Curve Mesh. One possible use case for Curve Meshes is a hair system.

First, you need to have an Input Node created with HAPI_CreateInputNode(). Remember, an input node can have only one part, so just use 0 for your HAPI_PartId.

Once you have an Input Node, you have to set the parameters of the curve mesh part with a HAPI_SetPartInfo() call. For curves, HAPI_PartInfo::type has to be set to HAPI_PARTTYPE_CURVE. Just like with poly meshes, you have to set HAPI_PartInfo::vertexCount, HAPI_PartInfo::pointCount and HAPI_PartInfo::faceCount to the number of elements in attributes of the respective HAPI_AttributeOwner. The meaning of HAPI_PartInfo::faceCount for curves is per primitive, i.e. per curve.

You also have to set properties of the curve mesh with a call to HAPI_SetCurveInfo(), then HAPI_SetCurveCounts() to specify the number of CVs per curve and optionally HAPI_SetCurveOrders() and HAPI_SetCurveKnots(), depending on the type of the curve.

Next, you have to create and populate attributes of the curve mesh as described in Adding Attributes and Setting Attribute Values. Just like with poly meshes, you have to at least set the "P" (HAPI_ATTRIB_POSITION) per-point attribute, which represents the curves' control vertices.

Finally, you have to commit the curve mesh by calling HAPI_CommitGeo().