C++ Resources

Updated on January 7 2017



Deborah R. Fowler | HDK Resources

Deborah R. Fowler



HDK (Houdini Developers Toolkit)

Updated on March 2  2014
Updated on March 1  2015

Here are some excellent links to getting started with HDK - Houdini Developers Kit.
Summary of steps to get hcustom working on your Windows machine at home
www.sidefx.com/docs/hdk13.0/

http://fourthwall.ndo.co.uk/
Also consult the odforce forum.


Getting Started:

Setting up compiling for HDK Code

On linux, you will use hcustom (linux is strongly *preferred* but if you only have windows at home ....)

On Windows you will be using MSVC (Microsoft visual compiler?) : Instructions found in the documentation here.
On my personal computer: ie. houdini-13.0.582-win64-vc9.exe
You need to
Set up the MSVCDir environment variable

Interesting note: I have not tried this personally, but you can use VS 2008 with HDK. Thanks Soum. See link here.

Open your Windows start menu and go to All Programs / Side Effects Software / Houdini 13.0.582 / Utilities / Command Line Tools
In the window type in the following:

    # Set MSVCDir to point to the Microsoft Visual C++ installed location.
    set MSVCDir=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC

    cd %HFS%\toolkit
    xcopy /S samples C:\samples
    cd C:\samples\SOP
    hcustom.exe SOP_Star.C

Note, that the version of Houdini13.0.582 uses vc9 (which is really Visual Studios 2008).
However, only my VS10 directory contained a VC folder. The full download for Visual Studios 2008 (which is vc9)
is still available on the Resources tab under software downloads. This is a slow download and mine did not work.
I did download a free trial version successfully from microsoft's site.
(Note - it is an iso file that you have to burn to DVD and then run the DVD to install - old style).

See note here about future versions.

You can also test it by downloading SOP_Star.C and SOP_Star.h directly (zip here).
NOTE for H13: currently the SOP_Star.C example file will compile cleanly on Windows, but will give warnings on linux about
deprecated data structures. It will still work, but you will see warning on linux.

This produces SOP_Star.o, and a plugin libraries, SOP_Star.lib, SOP_Star.exp, in the current working directory. The dll file is automatically installed into $HOME/houdini13.0/dso as well. This is why Houdini is able to locate and load your custom plugins. (ie. if you look in your Documents/houdini13.0/dso you will find SOP_Star.dll and SOP_Star.dll.manifest).

So what now? Open Houdini and create a Geometry object, then once inside, press TAB-> and type Star and your Star surface operator will appear. (I was going to say a star is born but that's a bad pun.)
Note that you can have your hip file set up and it will update, but you can't run hcustom unless you close the Houdini session (the files are not writable at that point - dso(dll in windows) is in use).

This is reviewed below with other examples.


Printing

for debugging purposes is quite easy cout << "Your message"; will work fine on Windows, on Linux you likely will have to add the line cout.flush(); to flush the buffer.


hcustom is really handy, but eventually you will use Makefiles since you are likely to have multiple source file projects.

Troubleshooting

If you see an error like this:
LINK : fatal error LNK1104: cannot open file 'C:/Users/..../houdini13.0/dso/pointCreate.dll
This means you have a session of Houdini open - simply close it and run hcustom again. This may seem obvious, but when you are developing a program outside of an IDE it can be easy to overlook this and fire up houdini without noticing since the screen is full of messages C:/PROGRA .... /...lib


Another common error is to forget to save the file(s) in the editor (notepad++ for example).

I personally find a good sanity check when developing code is to put a print statement in with a version number. This way you can be sure you have the most up to date file, and you haven't forgotten or overlooked the above common errors.


NOTE: Currently on Monty computers Windows will be set up to run hcustom this week. You can run it at home following the instructions given at the top of this page and you will see SOP_Star.C compiles cleanly. If you run hcustom on that example file on linux, you will get warnings about deprecated includes. IT DOES STILL WORK. H13 has changed some of the Classes and thus some warnings will be generated.

Word of advice - keep versions - either by zipping your files or numbering - whatever way works best for you.

Getting Started Section

Note: if you are on windows, use % around rather than $, for example $HFS becomes %HFS%
(Assuming you have copied the files in C:\samples - in above example - otherwise the permissions may not be correct)
    
On Linux
On Windows
cd $HFS/toolkit/samples/standalone  
cd C:\samples\standalone
hcustom -s geoisosurface.C 
hcustom -s geoisosurface.C 
./geoisosurface
geoisosurface 
gplay sphere.bgeo gplay sphere.bgeo
  
This is one of the example files provided that produces sphere geometry.


(Also please review your naming/formatting conventions discussed in class. The HDK examples are not always conforming to these.)

Nice Examples

Here are some excellent starting examples of custom sops built in HDK. These have been tested on H12 and modified by me where necessary (comments at the top of the code). The first two were originally developed by Dave Kin - however I have changed substantially to upgrade to H13 using the SOP_Star example as a guide. The next one by Nate Usiak, and the last two by me.
I have provided the zipped files below.
(To be consistent, the UI name (tab menu) includes the name of the node plus "HDK" to allow easy searching.) ie. EmptyNodeHDK brings up Empty Node.

sopEmptyNode.zip    contains sopEmptyNode.C and sopEmptyNode.h
sopNewPointCreate.zip contains sopNewPointCreate.C and sopNewPointCreate.h

The example files above compile cleanly on linux and windows in H13 (tested 3/2/2014 on windows7 and centOS and tested 3/1/2015 on windows7)

THE ONES BELOW ARE TO BE UPDATED TO H13 SOON 
In the H13 installed files is a power point guide that is for H12 that may be helpful (here). To be continued ...

sopCircleNode.zip     contains sopCircleNode.C and sopCircleNode.h
sopPointCreate.zip    contains sopPointCreate.C and sopPointCreate.h

In addition, I have created a simple sphere (polygon mesh) to introduce more gdp/geometry
sopSphereExample.zip contains sopSphereExample.C and sopSphereExample.h
sopShellSpiral.zip contains sopShellSpiral.C and sopShellSpiral.h as well as a hip file - this is a good example for adding attributes.

To use these, go to the directory you have unzipped them in, then (for example) type hcustom sopEmptyNode.C. Next, in houdini, inside a geometry contain, hit tab and type EmptyNode. This node does nothing, but this example provides you with the skeleton code for a custom sop.


NewPointCreate used to use the following lines to create a point (which is expanded to many point in the sphere example). Although this only take a few lines, the essential part is knowing what lines, and understanding the data structure hierarchy and types.

    with H12 data structures   

    now with H13 (see example in the documentation under Geometry Introduction/Adding a Primitive)

NewPointCreate has been updated to use the new H13 data structures

 As I develop more examples I will add them here.

Try to create your own custom SOP to better understand what is involved. Use these examples and the SOP_Star.C as starting points as well as the documentation.


Compiling review

1. On Windows:

    On Linux: cd to that directory

2. Compile: hcustom pointCreate.C

3. In Houdini: create a geometry container, inside hit tab - and type in pointCreate. Voila - a point is created. Right now it will also print "Hello There -    This is version 3, I'm in Point Create and curious is at 0".

When you run hcustom, it produces a .exp (Exports Library File), .lib (Object File Library) and .o file as well as puts the so/(Windows the dll) into the .../MyDocuments/houdini12.1/dso. For example, contained in the dso would be sopPointCreate.dll (dynamic-link library) and sopPointCreate.dll.manifest (I had to look up what a manifest files was see here and here).

READ the documentation over and try to create your own custom SOP to better understand what is involved. Use these examples and the SOP_Star.C as starting points.


SOP Simplified Overview

addOperator is called to create a new OP_Operator of your custom node, which sets up specific attributes. The constructors ensure everything is put into the proper network and can be referenced correctly. Local variables are defined using a CH_LocalVariable type list associated with your custom sop, similarly parameters are created using the PRM_Template list. Finally, the most important function your custom sop will contain is, cookMySOP (which is the function that is executed each time the node is "cooked" - for example, when you change parameters).

Parameters: PRM_Template

For example, suppose we wanted a new integer parameter called curious: The following lines would be added (see pointCreate.C):

Further, if you wanted to define the range for your parameters: static PRM_Range variableRange( PRM_RANGE_UI, 0, PRM_RANGE_UI, 500);
Then add &variableRange to your template list (ie. PRM_Template(PRM_INT, 1, &variableName, 0, 0, &variableRange)

NOTE: arguments for PRM_Template(type, number of values, name, defaults, menu, range)


Geometry and HDK

Keep in mind, much like OpenGL, we are at the lower level. We do not have an interface such as "glut" to more easily say, draw a sphere.
This world is about point, polygons and primitives. The key is gdp and the GU_Detail type. The sidefx documentation introduces geometry here.

The examples sopCircleNode and sopSphereExampe are a good starting point.

Geometry Structures

gdp is a pointer to the data that is passed in/out of a sop - it is altered in cookMySop function. You use the gdp to call functions from GU_Detail.

There are three essential pieces to GU_Detail: GEO_POINT, GEO_PRIMITIVE and GEO_VERTEX. (See sidefx documentation here).
GEO_Point - has a position, possibly other data.
GEO_Primitive - a primitive object, such as GEO_PrimPoly, GEO_PrimSphere. Each primitive is a list of one or more GEO_Vertex objects.
GEO_Vertex - stores a reference to a GEO_Point (because geometry can share points, a vertex is just a link to a point).
GEO_Vertex are not shared.

Geometry Attributes - maintained at a global level by GU_Detail (see adding attributes below)
name - ie. P or N
type - ie. GB_ATTRIB_FLOAT, GB_ATTRIB_INT, GB_ATTRIB_VECTOR (and mixed, string, index)
size - size of the data

useful
GEO_Detail::addVariableName(), removeVariableName() and getVariableNameMap() - mappings of attributes

Face Primitives
Sub-classes of GEO_Primitive are:
Face Primitives - vertices stored in a 1-D list. GEO_Face has three sub-classes, GEO_PrimPoly, GEO_Curve which is refined to GEO_PrimNURBCurve and GEO_PrimRBezCurve

Path Primitives
vertices stored in a 2-D matrix (u and v open or closed). GEO_Hull base class with GEO_PrimMish (linear mesh), GEO_PrimNURBSurf (NURBS surface) and GEO_PrimRBezSurf (ration Bezier surface)

Quadric Primitives - a single GEO_Vertex represents the center, also store in a 3x3 matrix transformation matrix
GEO_PrimCircle
GEO_PrimSphere
GEO_PrimTube

Volume Primitives - see documentation



Adding Attributes

The sidefx documentation for attributes is here.
The most basic steps are:
Declare the attribute:
                GA_RWAttributeRef N;  
                N = gdp->addFloatTuple( GA_ATTRIB_POINT, "N", 3 );

Write the value:
                UT_Vector3 normal;
                normal.assign(nx,ny,nz);
                spiralPoints[i]->setValue(N,normal);

These are used in the case where spiralPoints is a list of points ie. vector <GEO_Point * > spiralPoints;
spiralPoints.push_back( gdp->appendPoint() ); (See full example above).
 


Other ways to create SOPS

This documentation is focused on how to create SOPs using C++ but there are may ways to create a SOP, particularly using Python. See documentation here for details - note the time (speed) factor involved. I implemented each of these 6 ways and used the performance monitor running through 240 frames, "bouncing" a sphere to give the following results (check the documentation results as well - they differ.)
       
MyQuickComparison

The pure CPP code is the fastest, but they all have their strengths and weaknesses. If you are interested in seeing the source refer to sidefx documentation or my zipped files here. These include otl's for PythonPure, PythonNumby (a python optimization), PythonInlineC (using C++ embedded in python), and an otl generated from the pure vex (use vcc -l SOP_VexWave.otl SOP_VexWave.vfl) .
The code for hom_wave (Houdini Object Module calls in C++) and pure HDK C++ as it appears in the sidefx documentation in also contained in the zip files and these are compiled using hcustom just as we have done in the above HDK examples.

CVEX - in addition to Python, VEX can also be used with C++

Cvex - calling VEX from C++  - is introduced in the sidefx documentation here. I only mention this here so that the reader is aware, now back to HDK.


SOHO - Scripted output of Houdini Objects

Sidefx documentation link here.