VOXEDIT: implemented deletion of voxels

master
Martin Gerhardy 2018-05-01 21:46:50 +02:00
parent 9c20c8b921
commit 6cd4aa7b0f
8 changed files with 85 additions and 13 deletions

View File

@ -50,7 +50,7 @@ Validate that each `$out` of the vertex shader has a `$in` in the fragment shade
# VoxEdit
Extract meshes in max 32x32x32 boundaries - `RawVolumeRenderer` maybe? This allows us to only re-extract the chunk that was modified, not always the whole volume.
Extract meshes in max 32x32x32 boundaries - `RawVolumeRenderer` maybe? This allows us to only re-extract the chunk that was modified, not always the whole volume. See `Model::modified`.
Voxelizer via assimp
@ -66,6 +66,9 @@ Improve selections and implement invert-selection
Fix assert when cropping
Improve deletion of selected voxels - x should trigger popup like in blender which shows amount of voxels and enter to perform
the delete step (or esc to close the dialog without deleting anything).
# EventMgr
## Proper event-end-while-application-is-not-running handling

View File

@ -33,5 +33,6 @@ ctrl+down "+movecursordown"
space +place
shift+space pick
del +remove
x remove
return setreferencepositiontocursor
shift+c "setreferenceposition 0 0 0"

View File

@ -53,6 +53,7 @@ set(SRCS
polyvox/VolumeRescaler.h
polyvox/VolumeRotator.h polyvox/VolumeRotator.cpp
polyvox/VolumeCropper.h
polyvox/VolumeVisitor.h
SurfaceExtractionTask.h SurfaceExtractionTask.cpp
OctreeNode.h OctreeNode.cpp
OctreeVolume.h OctreeVolume.cpp

View File

@ -0,0 +1,42 @@
/**
* @file
*/
#pragma once
#include "RawVolume.h"
#include "core/Common.h"
#include "core/Trace.h"
namespace voxel {
/**
* @brief Will skip air voxels on volume
*/
struct SkipEmpty {
inline bool operator() (const voxel::Voxel& voxel) const {
return !isAir(voxel.getMaterial());
}
};
template<class Volume, class Visitor, typename Condition = SkipEmpty>
int visitVolume(const Volume& volume, Visitor&& visitor, Condition condition = Condition()) {
core_trace_scoped(VisitVolume);
const voxel::Region& region = volume.region();
int cnt = 0;
for (int32_t z = region.getLowerZ(); z <= region.getUpperZ(); ++z) {
for (int32_t y = region.getLowerY(); y <= region.getUpperY(); ++y) {
for (int32_t x = region.getLowerX(); x <= region.getUpperX(); ++x) {
const Voxel& voxel = volume.voxel(x, y, z);
if (!condition(voxel)) {
continue;
}
visitor(x, y, z, voxel);
++cnt;
}
}
}
return cnt;
}
}

View File

@ -37,7 +37,6 @@ struct CustomIsQuadNeeded {
RawVolumeRenderer::RawVolumeRenderer() :
_worldShader(shader::WorldShader::getInstance()) {
_sunDirection = glm::vec3(glm::left.x, glm::down.y, 0.0f);
}
bool RawVolumeRenderer::init() {
@ -136,6 +135,9 @@ void RawVolumeRenderer::extractAll() {
}
bool RawVolumeRenderer::extract(int idx) {
if (idx < 0 || idx >= MAX_VOLUMES) {
return false;
}
voxel::RawVolume* volume = _rawVolume[idx];
if (volume == nullptr) {
return false;
@ -150,7 +152,10 @@ bool RawVolumeRenderer::extract(int idx) {
return true;
}
void RawVolumeRenderer::update(int idx, voxel::Mesh* mesh) {
bool RawVolumeRenderer::update(int idx, voxel::Mesh* mesh) {
if (idx < 0 || idx >= MAX_VOLUMES) {
return false;
}
if (_mesh[idx] != mesh) {
delete _mesh[idx];
_mesh[idx] = mesh;
@ -159,9 +164,9 @@ void RawVolumeRenderer::update(int idx, voxel::Mesh* mesh) {
if (meshNumberIndices == 0u) {
_vertexBuffer[idx].update(_vertexBufferIndex[idx], nullptr, 0);
_vertexBuffer[idx].update(_indexBufferIndex[idx], nullptr, 0);
return;
return true;
}
update(idx, mesh->getVertexVector(), mesh->getIndexVector());
return update(idx, mesh->getVertexVector(), mesh->getIndexVector());
}
void RawVolumeRenderer::extract(voxel::RawVolume* volume, voxel::Mesh* mesh) const {

View File

@ -44,7 +44,6 @@ protected:
glm::vec3 _diffuseColor = glm::vec3(1.0, 1.0, 1.0);
glm::vec3 _ambientColor = glm::vec3(0.2, 0.2, 0.2);
glm::vec3 _sunDirection;
public:
RawVolumeRenderer();
@ -55,7 +54,7 @@ public:
* @sa extract()
*/
bool update(int idx, const std::vector<voxel::VoxelVertex>& vertices, const std::vector<voxel::IndexType>& indices);
void update(int idx, voxel::Mesh* mesh);
bool update(int idx, voxel::Mesh* mesh);
/**
* @brief Reextract the whole volume region and updates the vertex buffers.
@ -82,7 +81,6 @@ public:
const voxel::RawVolume* volume(int idx = 0) const;
void setAmbientColor(const glm::vec3& color);
void setSunDirection(const glm::vec3& sunDirection);
/**
* @sa shutdown()
@ -98,10 +96,6 @@ public:
std::vector<voxel::RawVolume*> shutdown();
};
inline void RawVolumeRenderer::setSunDirection(const glm::vec3& sunDirection) {
_sunDirection = sunDirection;
}
inline void RawVolumeRenderer::setAmbientColor(const glm::vec3& color) {
_ambientColor = color;
}

View File

@ -8,6 +8,7 @@
#include "voxel/polyvox/VolumeRotator.h"
#include "voxel/polyvox/VolumeMover.h"
#include "voxel/polyvox/VolumeRescaler.h"
#include "voxel/polyvox/VolumeVisitor.h"
#include "voxel/polyvox//RawVolumeWrapper.h"
#include "voxel/polyvox//RawVolumeMoveWrapper.h"
#include "voxel/generator/WorldGenerator.h"
@ -195,8 +196,28 @@ bool Model::place() {
return extract;
}
// TODO: delete selected volume from model volume
bool Model::remove() {
if (_selectionHandler.selectedVoxels() > 0) {
const voxel::RawVolume* selection = _rawVolumeSelectionRenderer.volume(SelectionVolumeIndex);
glm::ivec3 mins(0);
glm::ivec3 maxs(0);
const bool extract = voxel::visitVolume(*selection, [this, &mins, &maxs] (int x, int y, int z, const voxel::Voxel& voxel) {
modelVolume()->setVoxel(x, y, z, voxel::Voxel());
mins.x = glm::min(mins.x, x);
mins.y = glm::min(mins.y, y);
mins.z = glm::min(mins.z, z);
maxs.x = glm::max(maxs.x, x);
maxs.y = glm::max(maxs.y, y);
maxs.z = glm::max(maxs.z, z);
}) > 0;
if (extract) {
const voxel::Region modifiedRegion(mins, maxs);
modified(modifiedRegion);
return true;
}
return false;
}
const bool extract = setVoxel(_cursorPos, voxel::Voxel());
if (extract) {
const voxel::Region modifiedRegion(_cursorPos, _cursorPos);

View File

@ -23,6 +23,7 @@ public:
bool select(const voxel::RawVolume* volume, voxel::RawVolume* selectionVolume, const glm::ivec3& pos);
void unselectAll();
int selectedVoxels() const;
};
inline void SelectionHandler::setSelectionType(SelectType type) {
@ -33,4 +34,8 @@ inline SelectType SelectionHandler::selectionType() const {
return _selectionType;
}
inline int SelectionHandler::selectedVoxels() const {
return _selectedVoxels;
}
}