From 79a7755cdbc762163394195d5de829ba2ba0405f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 15 Aug 2015 12:18:36 -0700 Subject: [PATCH] add SURFACE_EDGED_MARCHING_CUBES polyvox surface extraction style --- examples/html/entityProperties.html | 1 + .../src/RenderablePolyVoxEntityItem.cpp | 21 +++++++++++-------- libraries/entities/src/PolyVoxEntityItem.h | 3 ++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index a2358b40d5..ad489afddf 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -1072,6 +1072,7 @@ + diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index be2d9b8fe6..07026f073c 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -78,6 +78,7 @@ bool inUserBounds(const PolyVox::SimpleVolume* vol, PolyVoxEntityItem:: return true; case PolyVoxEntityItem::SURFACE_EDGED_CUBIC: + case PolyVoxEntityItem::SURFACE_EDGED_MARCHING_CUBES: if (x < 0 || y < 0 || z < 0 || x >= vol->getWidth() - 2 || y >= vol->getHeight() - 2 || z >= vol->getDepth() - 2) { return false; @@ -112,7 +113,7 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) _onCount = 0; - if (_voxelSurfaceStyle == SURFACE_EDGED_CUBIC) { + if (_voxelSurfaceStyle == SURFACE_EDGED_CUBIC || _voxelSurfaceStyle == SURFACE_EDGED_MARCHING_CUBES) { // with _EDGED_ we maintain an extra box of voxels around those that the user asked for. This // changes how the surface extractor acts -- mainly it becomes impossible to have holes in the // generated mesh. The non _EDGED_ modes will leave holes in the mesh at the edges of the @@ -156,8 +157,7 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) void RenderablePolyVoxEntityItem::updateVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { // if we are switching to or from "edged" we need to force a resize of _volData. - if (voxelSurfaceStyle == SURFACE_EDGED_CUBIC || - _voxelSurfaceStyle == SURFACE_EDGED_CUBIC) { + if (voxelSurfaceStyle == SURFACE_EDGED_CUBIC || _voxelSurfaceStyle == SURFACE_EDGED_MARCHING_CUBES) { if (_volData) { delete _volData; } @@ -182,11 +182,11 @@ glm::vec3 RenderablePolyVoxEntityItem::getSurfacePositionAdjustment() const { glm::vec3 scale = getDimensions() / _voxelVolumeSize; // meters / voxel-units switch (_voxelSurfaceStyle) { case PolyVoxEntityItem::SURFACE_MARCHING_CUBES: - return scale / 2.0f; - case PolyVoxEntityItem::SURFACE_EDGED_CUBIC: - return scale / -2.0f; case PolyVoxEntityItem::SURFACE_CUBIC: return scale / 2.0f; + case PolyVoxEntityItem::SURFACE_EDGED_CUBIC: + case PolyVoxEntityItem::SURFACE_EDGED_MARCHING_CUBES: + return scale / -2.0f; } return glm::vec3(0.0f, 0.0f, 0.0f); } @@ -223,7 +223,7 @@ uint8_t RenderablePolyVoxEntityItem::getVoxel(int x, int y, int z) { // voxels all around the requested voxel space. Having the empty voxels around // the edges changes how the surface extractor behaves. - if (_voxelSurfaceStyle == SURFACE_EDGED_CUBIC) { + if (_voxelSurfaceStyle == SURFACE_EDGED_CUBIC || _voxelSurfaceStyle == SURFACE_EDGED_MARCHING_CUBES) { return _volData->getVoxelAt(x + 1, y + 1, z + 1); } return _volData->getVoxelAt(x, y, z); @@ -238,7 +238,7 @@ void RenderablePolyVoxEntityItem::setVoxelInternal(int x, int y, int z, uint8_t updateOnCount(x, y, z, toValue); - if (_voxelSurfaceStyle == SURFACE_EDGED_CUBIC) { + if (_voxelSurfaceStyle == SURFACE_EDGED_CUBIC || _voxelSurfaceStyle == SURFACE_EDGED_MARCHING_CUBES) { _volData->setVoxelAt(x + 1, y + 1, z + 1, toValue); } else { _volData->setVoxelAt(x, y, z, toValue); @@ -399,6 +399,7 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o glm::vec4 result = callback._result; switch (_voxelSurfaceStyle) { case PolyVoxEntityItem::SURFACE_EDGED_CUBIC: + case PolyVoxEntityItem::SURFACE_EDGED_MARCHING_CUBES: result -= glm::vec4(1, 1, 1, 0); // compensate for the extra voxel border break; case PolyVoxEntityItem::SURFACE_MARCHING_CUBES: @@ -556,7 +557,8 @@ void RenderablePolyVoxEntityItem::computeShapeInfo(ShapeInfo& info) { AABox box; glm::mat4 vtoM = voxelToLocalMatrix(); - if (_voxelSurfaceStyle == PolyVoxEntityItem::SURFACE_MARCHING_CUBES) { + if (_voxelSurfaceStyle == PolyVoxEntityItem::SURFACE_MARCHING_CUBES || + _voxelSurfaceStyle == PolyVoxEntityItem::SURFACE_EDGED_MARCHING_CUBES) { unsigned int i = 0; /* pull top-facing triangles into polyhedrons so they can be walked on */ const model::MeshPointer& mesh = _modelGeometry.getMesh(); @@ -683,6 +685,7 @@ void RenderablePolyVoxEntityItem::getModel() { PolyVox::SurfaceMesh polyVoxMesh; switch (_voxelSurfaceStyle) { + case PolyVoxEntityItem::SURFACE_EDGED_MARCHING_CUBES: case PolyVoxEntityItem::SURFACE_MARCHING_CUBES: { PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 0d0ab060f9..29d0b2e595 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -58,7 +58,8 @@ class PolyVoxEntityItem : public EntityItem { enum PolyVoxSurfaceStyle { SURFACE_MARCHING_CUBES, SURFACE_CUBIC, - SURFACE_EDGED_CUBIC + SURFACE_EDGED_CUBIC, + SURFACE_EDGED_MARCHING_CUBES }; void setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle);