make a copy of volData before computing the visual mesh

This commit is contained in:
Seth Alves 2017-02-25 15:32:08 -08:00
parent e3dbc53643
commit 1e81edbaea

View file

@ -40,6 +40,7 @@
#include <PolyVoxCore/SurfaceMesh.h>
#include <PolyVoxCore/SimpleVolume.h>
#include <PolyVoxCore/Material.h>
#include <PolyVoxCore/VolumeResampler.h>
#ifdef _WIN32
#pragma warning(pop)
#endif
@ -1128,8 +1129,20 @@ void RenderablePolyVoxEntityItem::getMesh() {
// A mesh object to hold the result of surface extraction
PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> polyVoxMesh;
PolyVox::SimpleVolume<uint8_t>* volData = nullptr;
entity->withReadLock([&] {
PolyVox::SimpleVolume<uint8_t>* volData = entity->getVolData();
PolyVox::SimpleVolume<uint8_t>* entityVolData = entity->getVolData();
PolyVox::Region region = entityVolData->getEnclosingRegion();
volData = new PolyVox::SimpleVolume<uint8_t>(region);
volData->setBorderValue(255);
PolyVox::VolumeResampler<PolyVox::SimpleVolume<uint8_t>,
PolyVox::SimpleVolume<uint8_t>> copier =
PolyVox::VolumeResampler<PolyVox::SimpleVolume<uint8_t>,
PolyVox::SimpleVolume<uint8_t>>(entityVolData, region, volData, region);
copier.execute();
});
switch (voxelSurfaceStyle) {
case PolyVoxEntityItem::SURFACE_EDGED_MARCHING_CUBES: {
PolyVox::MarchingCubesSurfaceExtractor<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor
@ -1156,7 +1169,7 @@ void RenderablePolyVoxEntityItem::getMesh() {
break;
}
}
});
delete volData;
// convert PolyVox mesh to a Sam mesh
const std::vector<uint32_t>& vecIndices = polyVoxMesh.getIndices();