mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 11:37:58 +02:00
make VoxelSystem::deleteVoxelAt() work properly
This commit is contained in:
parent
57d0b40e81
commit
9dc09de75e
3 changed files with 31 additions and 4 deletions
|
@ -232,7 +232,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) {
|
||||||
bool inChildBoundary = (distanceToNode <= childBoundary);
|
bool inChildBoundary = (distanceToNode <= childBoundary);
|
||||||
shouldRender = (node->isLeaf() && inChildBoundary) || (inBoundary && !inChildBoundary);
|
shouldRender = (node->isLeaf() && inChildBoundary) || (inBoundary && !inChildBoundary);
|
||||||
}
|
}
|
||||||
node->setShouldRender(shouldRender);
|
node->setShouldRender(shouldRender && !node->deleteMe());
|
||||||
// let children figure out their renderness
|
// let children figure out their renderness
|
||||||
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
||||||
if (node->getChildAtIndex(i)) {
|
if (node->getChildAtIndex(i)) {
|
||||||
|
@ -244,6 +244,15 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) {
|
||||||
} else {
|
} else {
|
||||||
voxelsUpdated += updateNodeInArraysAsPartialVBO(node);
|
voxelsUpdated += updateNodeInArraysAsPartialVBO(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the node has been asked to be deleted, but we've gotten to here, after updateNodeInArraysXXX()
|
||||||
|
// then it means our VBOs are "clean" and our vertices have been removed or not added. So we can now
|
||||||
|
// safely remove the node from the tree and actually delete it.
|
||||||
|
// otherwise honor our calculated shouldRender
|
||||||
|
if (node->deleteMe()) {
|
||||||
|
_tree->deleteVoxelCodeFromTree(node->getOctalCode());
|
||||||
|
}
|
||||||
|
|
||||||
node->clearDirtyBit(); // always clear the dirty bit, even if it doesn't need to be rendered
|
node->clearDirtyBit(); // always clear the dirty bit, even if it doesn't need to be rendered
|
||||||
return voxelsUpdated;
|
return voxelsUpdated;
|
||||||
}
|
}
|
||||||
|
@ -901,9 +910,19 @@ void VoxelSystem::collectStatsForTreesAndVBOs() {
|
||||||
|
|
||||||
|
|
||||||
void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) {
|
void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) {
|
||||||
//printLog("VoxelSystem::deleteVoxelAt(%f,%f,%f,%f)\n",x,y,z,s);
|
printLog("VoxelSystem::deleteVoxelAt(%f,%f,%f,%f)\n",x,y,z,s);
|
||||||
_tree->deleteVoxelAt(x, y, z, s);
|
|
||||||
setupNewVoxelsForDrawing();
|
VoxelNode* node = _tree->getVoxelAt(x, y, z, s);
|
||||||
|
if (node) {
|
||||||
|
// tell the node we want it deleted
|
||||||
|
node->pleaseDeleteMe();
|
||||||
|
|
||||||
|
// tree is now dirty
|
||||||
|
_tree->setDirtyBit();
|
||||||
|
|
||||||
|
// redraw!
|
||||||
|
setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in?
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VoxelNode* VoxelSystem::getVoxelAt(float x, float y, float z, float s) const {
|
VoxelNode* VoxelSystem::getVoxelAt(float x, float y, float z, float s) const {
|
||||||
|
|
|
@ -44,6 +44,7 @@ void VoxelNode::init(unsigned char * octalCode) {
|
||||||
_glBufferIndex = GLBUFFER_INDEX_UNKNOWN;
|
_glBufferIndex = GLBUFFER_INDEX_UNKNOWN;
|
||||||
_isDirty = true;
|
_isDirty = true;
|
||||||
_shouldRender = false;
|
_shouldRender = false;
|
||||||
|
_deleteMe = false;
|
||||||
|
|
||||||
calculateAABox();
|
calculateAABox();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ private:
|
||||||
glBufferIndex _glBufferIndex;
|
glBufferIndex _glBufferIndex;
|
||||||
bool _isDirty;
|
bool _isDirty;
|
||||||
bool _shouldRender;
|
bool _shouldRender;
|
||||||
|
bool _deleteMe;
|
||||||
AABox _box;
|
AABox _box;
|
||||||
unsigned char* _octalCode;
|
unsigned char* _octalCode;
|
||||||
VoxelNode* _children[8];
|
VoxelNode* _children[8];
|
||||||
|
@ -66,9 +67,15 @@ public:
|
||||||
glBufferIndex getBufferIndex() const { return _glBufferIndex; };
|
glBufferIndex getBufferIndex() const { return _glBufferIndex; };
|
||||||
bool isKnownBufferIndex() const { return (_glBufferIndex != GLBUFFER_INDEX_UNKNOWN); };
|
bool isKnownBufferIndex() const { return (_glBufferIndex != GLBUFFER_INDEX_UNKNOWN); };
|
||||||
void setBufferIndex(glBufferIndex index) { _glBufferIndex = index; };
|
void setBufferIndex(glBufferIndex index) { _glBufferIndex = index; };
|
||||||
|
|
||||||
|
// Used by VoxelSystem for rendering in/out of view and LOD
|
||||||
void setShouldRender(bool shouldRender);
|
void setShouldRender(bool shouldRender);
|
||||||
bool getShouldRender() const { return _shouldRender; }
|
bool getShouldRender() const { return _shouldRender; }
|
||||||
|
|
||||||
|
// Used by VoxelSystem to mark a node as to be deleted on next render pass
|
||||||
|
void pleaseDeleteMe() { _deleteMe = true; };
|
||||||
|
bool deleteMe() const { return _deleteMe; }
|
||||||
|
|
||||||
#ifndef NO_FALSE_COLOR // !NO_FALSE_COLOR means, does have false color
|
#ifndef NO_FALSE_COLOR // !NO_FALSE_COLOR means, does have false color
|
||||||
void setFalseColor(colorPart red, colorPart green, colorPart blue);
|
void setFalseColor(colorPart red, colorPart green, colorPart blue);
|
||||||
void setFalseColored(bool isFalseColored);
|
void setFalseColored(bool isFalseColored);
|
||||||
|
|
Loading…
Reference in a new issue