HDK
|
It is possible to use the HDK to write your own solver. This solver will have access to the all the objects and data in your simulation. Your solver can interact with other, existing solvers in Houdini.
The easiest way to get started writing your own solver is to derive from SIM_SingleSolver:
The main thing to do is to write your own implementation of solveSingleObjectSubclass. A typical implementation of a custom solver that derives from SIM_SingleSolver looks like this:
If you want to integrate your simulation objects simultaneously, then you need to derive your custom solver directly from SIM_Solver. In that case you would have to implement your own version of the member solveObjectsSubclass, which takes an SIM_ObjectArray of objects, instead of a single object.
It is possible for your own solver work with any of the constraints that are specified in a DOP network. The responsibility for enforcing constraints lies with the solver; if you don't explicitly implement support for the constraints, then they will not affect your custom solver's objects.
Pin constraints can be used to ensure that certain specified points of simulation objects don't move, or follow an animated trajectory. The code to read, update, and apply pin constraints in your solver would look like this:
It is possible to make your own solver react to the forces that are applied to its objects in a DOP network. Examples of these forces are gravity, wind, drag, and fan. Each of these forces is represented by a SIM_Force object. For each object in the objects array you will need to process all SIM_Force objects that affect it. You will want to evaluate these SIM_Force objects for each of the points in your simulation object's geometry. In general, the force direction and magnitude will vary from point to point. These point forces depend on the point positions as well as the point velocities. The drag force is an example of a force that is velocity-dependent. In general, the mass of each point is also needed. The gravity force is an example of this.
The code for extracting the per-point forces forces for a simulation object looks like this:
This code uses the getForce method on SIM_Force, which assumes that all the mass in your physical model is concentrated in the query points. Note that, in addition, the SIM_Force takes an angular velocity, and returns a torque. These parameters are legacy; they may be removed from the SIM_Force::getForce interface in future versions of the HDK. Dummy variables are passed in for both the angular velocity and torque.
Examples of custom solvers can be found in SIM/SIM_SolverSNOW::h and SIM/SIM_SolverHair.h. Both these examples derive from SIM_SingleSolver (as opposed to deriving from SIM_Solver directly).