HDK
|
SOPs networks are responsible for creating and modifying Houdini geometry. In SOPs, geometry is represented as a Detail, as implemented by the GU_Detail class.
SOPs without inputs usually generate their own geometry when they cook, such as SOP_Circle. All other SOPs, when asked to cook, first ask their relevant input SOPs for their cooked geometry, only cooking own detail afterward, thus recursively traversing up the hierarchy tree along all node input connections.
This has the effect of cooking the most remote nodes first, passing the detail data to its children, and gradually approaching the display or render SOP node which initiated the cook request.
The actual modification or creation of the geometry itself is done in SOP_Node::cookMySop() in each node. The context parameter which this function receives passes in the time at which to cook and can be accessed through context.getTime().
HDK provides several useful function to access input geometry in a SOP while cooking:
A number of SOPs have an option to perform its operation only on a certain group or set of groups in the input geometry. If this is the case, you will want to determine the actual geometry group that is defined within the group string field. The three methods below allow this. If there is more than one group specified the resulting group will be the union of the input groups. If you do not pass in a gdp then it is assumed that the SOP's gdp is used to search for groups.
If the SOP is interested in receiving both primitive and point group information then parseGroups should be used. It will return both a point and primitive group based on the incoming pattern.
If you are just interested in one type then parsePrimitiveGroups or parsePointGroups may be used. They return a pointer to a GA_PrimitiveGroup or a GA_PointGroup respectively. If nothing was found (nil) is returned.
Another useful method, SOP_Node::forEachGroupMatchingMask(const char *pattern, GroupOperation operation, void *data, GA_GroupType type, GU_Detail *which_gdp), is related to the three methods defined above. However, instead of returning a single group to act upon, this method will perform an operation on each existing group that matches the specified pattern mask.
GroupOperation is a typedef to a member function that takes the group and void * data pointer as arguments.
Depending on what part of Houdini is requesting geometry, a SOP network cooks starting from the node whose display flag is set (if, for example, the geometry is being requested by an OpenGL viewport) or from the node whose render flag is set (if the geometry is being rendered). These can be queried by the OP_Network::getDisplayNodePtr() and OP_Network::getRenderNodePtr() methods.
In addition, setting the bypass flag on a SOP node (using OP_Node::setBypass()) will avoid cooking that node, and will pass its input geometry to the node connected to its output unmodified.
Finally, locking the node (OP_Node::setLock()) will preserve its geometry, and leave it unmodified regardless of whether input geometry changes or not.
For a detailed explanation on how to build custom SOPs and manipulate their geometry, see Creating Geometry and The Many Ways To Create a SOP.
SOP nodes operate on geometry, so to get access to data within a SOP, one only needs to get access to its stored GU_Detail. This can be accomplished using the following code:
SOP nodes only operate on geometry, their scene transformations derived from their creator OBJ nodes. To determine the world transform from a SOP node, you need to first obtain it's creator as demonstrated below.