Hi,
I want to be able to write data into individual voxels inside of a VDB that is input to my HDK node.
So far I have done the following:
// Get the first VDB primitive in the geometry
GEO_PrimVDB* vdbPrim = NULL;
for (GA_Iterator it(gdp->getPrimitiveRange()); !it.atEnd(); it.advance())
{
GEO_Primitive* prim = gdp->getGEOPrimitive(it.getOffset());
if(dynamic_cast<const GEO_PrimVDB *>(prim))
{
vdbPrim = dynamic_cast<GEO_PrimVDB *>(prim);
break;
}
}
// Make sure we got a valid prim
if(!vdbPrim)
{
addError(SOP_MESSAGE, “Input geometry must contain a VDB”);
return error();
}
// Docs say to do this in case the grid is shared
vdbPrim->makeGridUnique();
Next I try to get the Grid from vdbPrim, but I can't get it to work. I've tried a handful of functions like getGrid(), getGridPtr(), etc. Can anyone recommend what I need to do next?
EDIT - SOLVED Posting for any others who might find themselves in a similar struggle
Some more digging through the VDB docs lead me to this. Works!
// Docs say to do this in case the grid is shared
vdbPrim->makeGridUnique();
// Try to get the vdb's grid
openvdb::GridBase:tr baseGrid;
if(vdbPrim->hasGrid())
baseGrid = vdbPrim->getGridPtr();
openvdb::FloatGrid:tr grid = openvdb::gridPtrCast<openvdb::FloatGrid>(baseGrid);
openvdb::FloatGrid::Accessor accessor = grid->getAccessor();
openvdb::Coord xyz(0,0,0);
accessor.setValue(xyz, 1.0);