Jump to content

[SOLVED] How to modify a VDB prim?


Recommended Posts

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::Ptr baseGrid;
	if(vdbPrim->hasGrid())
		baseGrid = vdbPrim->getGridPtr();

	openvdb::FloatGrid::Ptr grid = openvdb::gridPtrCast<openvdb::FloatGrid>(baseGrid);
	openvdb::FloatGrid::Accessor accessor = grid->getAccessor();

	openvdb::Coord xyz(0,0,0);
	accessor.setValue(xyz, 1.0);
Edited by kgmcnamara
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...