mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 19:52:26 +02:00
add SURFACE_EDGED_MARCHING_CUBES polyvox surface extraction style
This commit is contained in:
parent
27e5322cb4
commit
79a7755cdb
3 changed files with 15 additions and 10 deletions
|
@ -1072,6 +1072,7 @@
|
||||||
<option value='0'>marching cubes</option>
|
<option value='0'>marching cubes</option>
|
||||||
<option value='1'>cubic</option>
|
<option value='1'>cubic</option>
|
||||||
<option value='2'>edged cubic</option>
|
<option value='2'>edged cubic</option>
|
||||||
|
<option value='3'>edged marching cubes</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ bool inUserBounds(const PolyVox::SimpleVolume<uint8_t>* vol, PolyVoxEntityItem::
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case PolyVoxEntityItem::SURFACE_EDGED_CUBIC:
|
case PolyVoxEntityItem::SURFACE_EDGED_CUBIC:
|
||||||
|
case PolyVoxEntityItem::SURFACE_EDGED_MARCHING_CUBES:
|
||||||
if (x < 0 || y < 0 || z < 0 ||
|
if (x < 0 || y < 0 || z < 0 ||
|
||||||
x >= vol->getWidth() - 2 || y >= vol->getHeight() - 2 || z >= vol->getDepth() - 2) {
|
x >= vol->getWidth() - 2 || y >= vol->getHeight() - 2 || z >= vol->getDepth() - 2) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -112,7 +113,7 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize)
|
||||||
|
|
||||||
_onCount = 0;
|
_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
|
// 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
|
// 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
|
// 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) {
|
void RenderablePolyVoxEntityItem::updateVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) {
|
||||||
// if we are switching to or from "edged" we need to force a resize of _volData.
|
// if we are switching to or from "edged" we need to force a resize of _volData.
|
||||||
if (voxelSurfaceStyle == SURFACE_EDGED_CUBIC ||
|
if (voxelSurfaceStyle == SURFACE_EDGED_CUBIC || _voxelSurfaceStyle == SURFACE_EDGED_MARCHING_CUBES) {
|
||||||
_voxelSurfaceStyle == SURFACE_EDGED_CUBIC) {
|
|
||||||
if (_volData) {
|
if (_volData) {
|
||||||
delete _volData;
|
delete _volData;
|
||||||
}
|
}
|
||||||
|
@ -182,11 +182,11 @@ glm::vec3 RenderablePolyVoxEntityItem::getSurfacePositionAdjustment() const {
|
||||||
glm::vec3 scale = getDimensions() / _voxelVolumeSize; // meters / voxel-units
|
glm::vec3 scale = getDimensions() / _voxelVolumeSize; // meters / voxel-units
|
||||||
switch (_voxelSurfaceStyle) {
|
switch (_voxelSurfaceStyle) {
|
||||||
case PolyVoxEntityItem::SURFACE_MARCHING_CUBES:
|
case PolyVoxEntityItem::SURFACE_MARCHING_CUBES:
|
||||||
return scale / 2.0f;
|
|
||||||
case PolyVoxEntityItem::SURFACE_EDGED_CUBIC:
|
|
||||||
return scale / -2.0f;
|
|
||||||
case PolyVoxEntityItem::SURFACE_CUBIC:
|
case PolyVoxEntityItem::SURFACE_CUBIC:
|
||||||
return scale / 2.0f;
|
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);
|
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
|
// voxels all around the requested voxel space. Having the empty voxels around
|
||||||
// the edges changes how the surface extractor behaves.
|
// 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 + 1, y + 1, z + 1);
|
||||||
}
|
}
|
||||||
return _volData->getVoxelAt(x, y, z);
|
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);
|
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);
|
_volData->setVoxelAt(x + 1, y + 1, z + 1, toValue);
|
||||||
} else {
|
} else {
|
||||||
_volData->setVoxelAt(x, y, z, toValue);
|
_volData->setVoxelAt(x, y, z, toValue);
|
||||||
|
@ -399,6 +399,7 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o
|
||||||
glm::vec4 result = callback._result;
|
glm::vec4 result = callback._result;
|
||||||
switch (_voxelSurfaceStyle) {
|
switch (_voxelSurfaceStyle) {
|
||||||
case PolyVoxEntityItem::SURFACE_EDGED_CUBIC:
|
case PolyVoxEntityItem::SURFACE_EDGED_CUBIC:
|
||||||
|
case PolyVoxEntityItem::SURFACE_EDGED_MARCHING_CUBES:
|
||||||
result -= glm::vec4(1, 1, 1, 0); // compensate for the extra voxel border
|
result -= glm::vec4(1, 1, 1, 0); // compensate for the extra voxel border
|
||||||
break;
|
break;
|
||||||
case PolyVoxEntityItem::SURFACE_MARCHING_CUBES:
|
case PolyVoxEntityItem::SURFACE_MARCHING_CUBES:
|
||||||
|
@ -556,7 +557,8 @@ void RenderablePolyVoxEntityItem::computeShapeInfo(ShapeInfo& info) {
|
||||||
AABox box;
|
AABox box;
|
||||||
glm::mat4 vtoM = voxelToLocalMatrix();
|
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;
|
unsigned int i = 0;
|
||||||
/* pull top-facing triangles into polyhedrons so they can be walked on */
|
/* pull top-facing triangles into polyhedrons so they can be walked on */
|
||||||
const model::MeshPointer& mesh = _modelGeometry.getMesh();
|
const model::MeshPointer& mesh = _modelGeometry.getMesh();
|
||||||
|
@ -683,6 +685,7 @@ void RenderablePolyVoxEntityItem::getModel() {
|
||||||
PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> polyVoxMesh;
|
PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> polyVoxMesh;
|
||||||
|
|
||||||
switch (_voxelSurfaceStyle) {
|
switch (_voxelSurfaceStyle) {
|
||||||
|
case PolyVoxEntityItem::SURFACE_EDGED_MARCHING_CUBES:
|
||||||
case PolyVoxEntityItem::SURFACE_MARCHING_CUBES: {
|
case PolyVoxEntityItem::SURFACE_MARCHING_CUBES: {
|
||||||
PolyVox::MarchingCubesSurfaceExtractor<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor
|
PolyVox::MarchingCubesSurfaceExtractor<PolyVox::SimpleVolume<uint8_t>> surfaceExtractor
|
||||||
(_volData, _volData->getEnclosingRegion(), &polyVoxMesh);
|
(_volData, _volData->getEnclosingRegion(), &polyVoxMesh);
|
||||||
|
|
|
@ -58,7 +58,8 @@ class PolyVoxEntityItem : public EntityItem {
|
||||||
enum PolyVoxSurfaceStyle {
|
enum PolyVoxSurfaceStyle {
|
||||||
SURFACE_MARCHING_CUBES,
|
SURFACE_MARCHING_CUBES,
|
||||||
SURFACE_CUBIC,
|
SURFACE_CUBIC,
|
||||||
SURFACE_EDGED_CUBIC
|
SURFACE_EDGED_CUBIC,
|
||||||
|
SURFACE_EDGED_MARCHING_CUBES
|
||||||
};
|
};
|
||||||
|
|
||||||
void setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle);
|
void setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle);
|
||||||
|
|
Loading…
Reference in a new issue