When defining custom Auto DOP nodes several steps must be performed.
An example of how to construct a simple custom Auto DOP can be seen at SIM/SIM_ElectricalProperties.C.
An example of how to construct an Auto DOP with custom guide geometry can be seen at SIM/SIM_ForceOrbit.C.
An example of how to construct a simple custom force Auto DOP can be seen at SIM/SIM_ForceOrbit.C.
There are two macros to make it easy to both fetch and cast the desired data from an object, SIM_DATA_GET and SIM_DATA_GETCONST. Whenever you want read only access, one should always use SIM_DATA_GETCONST. The SIM_DATA_GET will create a non-const reference that will unique the data across time, a possible waste of memory if the data isn't changing.
Most of the standard DOP data is generated with Auto DOP Nodes. Things such as RBD_State, SIM_Position, etc, can be accessed in the following fashion.
const RBD_State *state; const SIM_Object *obj; UT_Vector3 pivot; state = SIM_DATA_GETCONST(*obj, /* Object to fetch */ "Position", /* Path to data to fetch. */ RBD_State /* Type to cast to */ ); if (!state) { // Either obj doesn't have subdata called "Position" OR // that data can't be cast into type RBD_State pivot = 0.0; } else { // We can now access all of the read-only methods of RBD_State. // This also includes stuff created by the GETSET_DATA_FUNC_S // style macros pivot = state->getPivot(); }
The next example shows how to write to the data. It will also create the data if it can't be found. If data exists of the wrong type, it will be deleted and replaced by the RBD_State data.
RBD_State *state; SIM_Object *obj; state = SIM_DATA_GET(*obj, "Position", RBD_State); if (!state) { state = SIM_DATA_CREATE(*obj, "Position", RBD_State, 0 /* Flags */); } state->setPivot(UT_Vector3(0,0,0));
Finally, this example will again create a missing RBD_State. However, it sets the flags to SIM_DATA_RETURN_EXISTING so if it already exists, the current version is used. This is orred with SIM_DATA_ADOPT_EXISTING_ON_DELETE which will try to up-convert any base types into RBD_State. In this way, if SIM_Position is already on the object and is named "Position", it will be converted into an RBD_State and returned.
RBD_State *state; SIM_Object *obj; state = SIM_DATA_CREATE(*obj, "Position", RBD_State SIM_DATA_RETURN_EXISTING | SIM_DATA_ADOPT_EXISTING_ON_DELETE); state->setPivot(UT_Vector3(0,0,0));
Note that when you add your own dophints.cmd to your HOUDINI_SCRIPT_PATH, only the first dophints.cmd is called. Thus you need to chain into the official dohints.cmd by assing as the final line:
source $HFS/houdini/scripts/dophints.cmd
Instead of adding to the dophints.cmd, you can also directly add hints in C++ in your initializeSIM hook.
SIM_DataHint::addHint(parenttype, childtype, childname, -1);
1.5.9