mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 16:36:54 +02:00
fixed bug in recursive delete that caused animation ghosts
This commit is contained in:
parent
4f1131fc97
commit
57aff0af64
1 changed files with 15 additions and 5 deletions
|
@ -264,6 +264,7 @@ void VoxelTree::deleteVoxelAt(float x, float y, float z, float s, bool stage) {
|
||||||
reaverageVoxelColors(rootNode);
|
reaverageVoxelColors(rootNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class DeleteVoxelCodeFromTreeArgs {
|
class DeleteVoxelCodeFromTreeArgs {
|
||||||
public:
|
public:
|
||||||
bool stage;
|
bool stage;
|
||||||
|
@ -277,7 +278,6 @@ public:
|
||||||
// Note: uses the codeColorBuffer format, but the color's are ignored, because
|
// Note: uses the codeColorBuffer format, but the color's are ignored, because
|
||||||
// this only finds and deletes the node from the tree.
|
// this only finds and deletes the node from the tree.
|
||||||
void VoxelTree::deleteVoxelCodeFromTree(unsigned char* codeBuffer, bool stage, bool collapseEmptyTrees) {
|
void VoxelTree::deleteVoxelCodeFromTree(unsigned char* codeBuffer, bool stage, bool collapseEmptyTrees) {
|
||||||
|
|
||||||
// recurse the tree while decoding the codeBuffer, once you find the node in question, recurse
|
// recurse the tree while decoding the codeBuffer, once you find the node in question, recurse
|
||||||
// back and implement color reaveraging, and marking of lastChanged
|
// back and implement color reaveraging, and marking of lastChanged
|
||||||
DeleteVoxelCodeFromTreeArgs args;
|
DeleteVoxelCodeFromTreeArgs args;
|
||||||
|
@ -312,9 +312,10 @@ void VoxelTree::deleteVoxelCodeFromTreeRecursion(VoxelNode* node, void* extraDat
|
||||||
int childIndex = branchIndexWithDescendant(node->getOctalCode(), args->codeBuffer);
|
int childIndex = branchIndexWithDescendant(node->getOctalCode(), args->codeBuffer);
|
||||||
VoxelNode* childNode = node->getChildAtIndex(childIndex);
|
VoxelNode* childNode = node->getChildAtIndex(childIndex);
|
||||||
|
|
||||||
// If there is no child at the target location, then it likely means we were asked to delete a child out
|
// If there is no child at the target location, and the current parent node is a colored leaf,
|
||||||
// of a larger leaf voxel. We support this by breaking up the parent voxel into smaller pieces.
|
// then it means we were asked to delete a child out of a larger leaf voxel.
|
||||||
if (!childNode) {
|
// We support this by breaking up the parent voxel into smaller pieces.
|
||||||
|
if (!childNode && node->isLeaf() && node->isColored()) {
|
||||||
// we need to break up ancestors until we get to the right level
|
// we need to break up ancestors until we get to the right level
|
||||||
VoxelNode* ancestorNode = node;
|
VoxelNode* ancestorNode = node;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -345,8 +346,17 @@ void VoxelTree::deleteVoxelCodeFromTreeRecursion(VoxelNode* node, void* extraDat
|
||||||
// ends recursion, unwinds up stack
|
// ends recursion, unwinds up stack
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we don't have a child and we reach this point, then we actually know that the parent
|
||||||
|
// isn't a colored leaf, and the child branch doesn't exist, so there's nothing to do below and
|
||||||
|
// we can safely return, ending the recursion and unwinding
|
||||||
|
if (!childNode) {
|
||||||
|
//printLog("new___deleteVoxelCodeFromTree() child branch doesn't exist, but parent is not a leaf, just unwind\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// recurse...
|
// If we got this far then we have a child for the branch we're looking for, but we're not there yet
|
||||||
|
// recurse till we get there
|
||||||
deleteVoxelCodeFromTreeRecursion(childNode, args);
|
deleteVoxelCodeFromTreeRecursion(childNode, args);
|
||||||
|
|
||||||
// If the lower level determined it needs to be deleted, then we should delete now.
|
// If the lower level determined it needs to be deleted, then we should delete now.
|
||||||
|
|
Loading…
Reference in a new issue