I changed my function to take a structure, but it's crashing during the same Raycast that worked fine before and I'm not really sure why. The crash happens in simpleVolumeSampler.inl in this block of code with an Access Violation.
Raycast is like so -
Code:
PolyVox::RaycastResult raycastResult;
PolyVox::Raycast<PolyVox::SimpleVolume, PolyVox::Density8> raycast(&pMesh.volume, start, direction, raycastResult);
raycast.execute();
crash stops here-
Code:
template <typename VoxelType>
VoxelType SimpleVolume<VoxelType>::Sampler::getVoxel(void) const
{
return *mCurrentVoxel;
}
my custom stucture to hold volume, node data -
Code:
struct Polymesh {
PolyVox::SimpleVolume<Density8> volume;
Ogre::SceneNode * node;
Ogre::ManualObject * meshOBJ;
Vector3 position;
Polymesh():volume(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(100,256,100))), node(NULL), meshOBJ(NULL){}
};
function that takes Polymesh structure and renders a mesh from it -
Code:
void WorldCraft::PolyvoxMeshtoManual(Polymesh pMesh)
{
// ************ start mesh build code
// Make a surfaceMesh from the voxelData
SurfaceMesh<PositionMaterialNormal> mesh;
SurfaceMesh<PositionMaterialNormal> mesh2;
// Reduced mesh - use for non-smooth mesh
/*
Region reducedRegion = volData.getEnclosingRegion();
reducedRegion.shiftLowerCorner(Vector3DInt32(2,2,2));
reducedRegion.shiftUpperCorner(Vector3DInt32(-2,-2,-2));
PolyVox::CubicSurfaceExtractorWithNormals<SimpleVolume, Density8> surf(&volData, reducedRegion, &mesh);
// Smooth using a lowpassfilter
Region fullRegion = volData.getEnclosingRegion();
//fullRegion.shiftLowerCorner(Vector3DInt32(2,2,2));
//fullRegion.shiftUpperCorner(Vector3DInt32(-2,-2,-2));
SimpleVolume<Density8> resultVolume(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(myTerrainHM.getWidth(),256,myTerrainHM.getHeight())));
Region fullRegion2 = resultVolume.getEnclosingRegion();
fullRegion2.shiftLowerCorner(Vector3DInt32(2,2,2));
fullRegion2.shiftUpperCorner(Vector3DInt32(-2,-2,-2));
LowPassFilter<SimpleVolume, SimpleVolume, Density8> pass1(&volData, fullRegion2, &resultVolume, fullRegion2, 5);
pass1.execute();
*/
// Extract the surface
//PolyVox::SurfaceExtractor<SimpleVolume, Density8> surf(&resultVolume, fullRegion2, &mesh); // Use if smoothing
PolyVox::SurfaceExtractor<SimpleVolume, Density8> surf(&pMesh.volume, pMesh.volume.getEnclosingRegion(), &mesh); // Use for semi-smooth surface
//PolyVox::CubicSurfaceExtractorWithNormals <SimpleVolume, Density8> surf(pMesh.volume, pMesh.volume->getEnclosingRegion(), &mesh); // Use if not smoothing
surf.execute();
//Optional in release mode - simplify (decimate) the mesh
//PolyVox::MeshDecimator<PolyVox::PositionMaterialNormal> decim(&mesh, &mesh2);
//decim.execute();
// Change mesh to mesh2 if using decimation
const std::vector<PolyVox::PositionMaterialNormal>& vecVertices = mesh.getVertices();
const std::vector<uint32_t>& vecIndices = mesh.getIndices();
// create something to draw the PolyVox stuff to
/*
if(ogreMesh != NULL) {
ogreNode->detachObject(ogreMesh);
mKeyDevices.mSceneMgr->destroyManualObject(ogreMesh);
ogreMesh = NULL;
}
*/
if(pMesh.meshOBJ == NULL) {
pMesh.meshOBJ = mKeyDevices.mSceneMgr->createManualObject();
// YES we do intend to change the mesh later -.-
pMesh.meshOBJ->setDynamic(true);
pMesh.meshOBJ->begin("Worldcraft/Greengrass", Ogre::RenderOperation::OT_TRIANGLE_LIST);
} else pMesh.meshOBJ->beginUpdate(0);
if(pMesh.meshOBJ != NULL) {
/*
if ( ogreNode != NULL) {
mKeyDevices.mSceneMgr->destroySceneNode(ogreNode);
ogreNode = NULL;
}
*/
if (pMesh.node == NULL) {
pMesh.node = mKeyDevices.mSceneMgr->getRootSceneNode()->createChildSceneNode(pMesh.position);
}
// Begin writing to manualObject
unsigned int uLodLevel = 0;
for(int index = 0; index < vecIndices.size(); index++) {
const PolyVox::PositionMaterialNormal& vertex = vecVertices[vecIndices[index]];
const PolyVox::Vector3DFloat& v3dVertexPos = vertex.getPosition();
const PolyVox::Vector3DFloat& v3dVertexNormal = vertex.getNormal();
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
const PolyVox::Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<PolyVox::Vector3DFloat>(mesh.m_Region.getLowerCorner());
pMesh.meshOBJ->position(v3dVertexPos.getX(), v3dVertexPos.getY(), v3dVertexPos.getZ());
pMesh.meshOBJ->normal(v3dVertexNormal.getX(), v3dVertexNormal.getY(), v3dVertexNormal.getZ());
uint8_t mat = vertex.getMaterial() + 0.5;
uint8_t red = mat & 0xF0;
uint8_t green = mat & 0x03;
uint8_t blue = mat & 0x0C;
pMesh.meshOBJ->colour(red*2, green*4, blue*4);// just some random colors, I'm too lazy for hsv
}
// end writing
pMesh.meshOBJ->end();
//atach object to node
pMesh.node->attachObject(pMesh.meshOBJ);
}
}