Hi, I'm pretty new to PolyVox and curious if anyone has experience doing 3d picking - basically I am trying to figure out which voxel is hit, and then modifying the density to be 0 for that voxel - which I assume should have the effect of "eroding" my voxel terrain.
I do a raycastWithDirection from my eye point, in the direction of the projected 2D touch point (I'm doing this on iOS):
Code:
VoxelPickerRaycastCallback voxelPickerRaycastCallback;
RaycastResult intersection=raycastWithDirection(volData, start, direction, voxelPickerRaycastCallback);
Inside my VoxelPickerRaycastCallback, I keep track of the intersection points (I am suspicious of whether this is correct):
Code:
bool operator()(const SimpleVolume<MaterialDensityPair88>::Sampler& sampler) {
MaterialDensityPair88 voxel=sampler.getVoxel();
Vector3DInt32 position=sampler.getPosition();
intersectPoints.push_back(position);
return true;
}
And then finally I go through the intersect points and modify the density:
Code:
if (intersection==RaycastResult::Completed) {
NSLog(@"Found Intersection");
vector<Vector3DInt32>::iterator i=voxelPickerRaycastCallback.intersectPoints.begin();
while (i!=voxelPickerRaycastCallback.intersectPoints.end()) {
//NSLog(@"Hit At:%d, %d, %d", (*i).getX(), (*i).getY(), (*i).getZ());
//update the voxel data and rebuild the
MaterialDensityPair88 voxel=volData->getVoxelAt((int)(i->getX()), (int)(i->getY()), (int)(i->getZ()));
if (voxel.getDensity()>0) {
voxel.setDensity(0);
volData->setVoxelAt((int)(i->getX()), (int)(i->getY()), (int)(i->getZ()), voxel);
}
++i;
}
[self regenerateBuffers];
}
I get back a bunch of points in the intersect points, and it turns out that none of them ever trigger the voxel.getDensity()>0 condition.
Am I on the completely wrong path? I have done 3D picking before, but never felt completely confident in my abilities on it however.