Pages

Tuesday, 28 March 2023

How to create a pointcloud from any joint of crowd of agents in Houdini

 

Here is a method I have learned to create a pointcloud from any joint of crowd of agents in Houdini.

For example, an army of soldiers, carrying guns. The FX department require the location and orientation of the end of each gun barrel. We can deliver a pointcloud which has that data.

Here are the steps

First, take your crowd....

// 1. get joint name
string JOINT_NAME = "r_handJA_JNT";
 
// 2. get joint index
int JOINT_IDX = agentrigfind(0, @ptnum, JOINT_NAME);
 
// 3. get position of agent
matrix AGENT_XFORM = primintrinsic(0, "packedfulltransform", @ptnum);
 
// 4. get position of joint within agent
matrix JOINT_XFORM = agentworldtransform(0, @ptnum, JOINT_IDX);
 
// 5. set offset to end of the gun barrel (enter manually)
vector POS = chv("offset");
 
// 6. transform by JOINT_XFORM
POS *= JOINT_XFORM;

// 7. trnasform by AGENT_XFORM
POS *= AGENT_XFORM;

// 8. set initial direction along the gun (+x direction)
vector DIR = set(1, 0, 0);

// 9. transform by rotation component of JOINT_XFORM
DIR *= matrix3(JOINT_XFORM);

// 10. trnasform by the rotation component of AGENT_XFORM
DIR *= matrix3(AGENT_XFORM);

// 11. make a new point
int newPoint = addpoint(0, POS);

// 12. set DIR on new point
setpointattrib(0, "DIR", newPoint, DIR);

// 13. delete the agent
removepoint(0, @ptnum, 1);


then export this pointcloud.