mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:44:01 +02:00
More editing progress. Now there are threading issues. Joy!
This commit is contained in:
parent
f0573e6ee5
commit
750843e867
4 changed files with 50 additions and 55 deletions
|
@ -989,19 +989,10 @@ void VoxelSystem::collectStatsForTreesAndVBOs() {
|
|||
|
||||
|
||||
void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) {
|
||||
printLog("VoxelSystem::deleteVoxelAt(%f,%f,%f,%f)\n",x,y,z,s);
|
||||
|
||||
VoxelNode* node = _tree->getVoxelAt(x, y, z, s);
|
||||
if (node) {
|
||||
// tell the node we want it deleted
|
||||
node->stageForDeletion();
|
||||
|
||||
// tree is now dirty
|
||||
_tree->setDirtyBit();
|
||||
|
||||
// redraw!
|
||||
setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in?
|
||||
}
|
||||
_tree->deleteVoxelAt(x, y, z, s, true);
|
||||
|
||||
// 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 {
|
||||
|
|
|
@ -726,7 +726,12 @@ void displaySide(Camera& whichCamera) {
|
|||
// indicate what we'll be adding/removing in mouse mode, if anything
|
||||
if (::mouseVoxel.s != 0) {
|
||||
glPushMatrix();
|
||||
glColor3ub(::mouseVoxel.red, ::mouseVoxel.green, ::mouseVoxel.blue);
|
||||
if (::mouseMode == ADD_VOXEL_MODE) {
|
||||
// use a contrasting color so that we can see what we're doing
|
||||
glColor3ub(~::mouseVoxel.red, ~::mouseVoxel.green, ~::mouseVoxel.blue);
|
||||
} else {
|
||||
glColor3ub(::mouseVoxel.red, ::mouseVoxel.green, ::mouseVoxel.blue);
|
||||
}
|
||||
glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE);
|
||||
glTranslatef(::mouseVoxel.x + ::mouseVoxel.s*0.5f,
|
||||
::mouseVoxel.y + ::mouseVoxel.s*0.5f,
|
||||
|
@ -1752,33 +1757,37 @@ void idle(void) {
|
|||
if (voxels.findRayIntersection(origin, direction, ::mouseVoxel, distance, face)) {
|
||||
// find the nearest voxel with the desired scale
|
||||
if (::mouseVoxelScale > ::mouseVoxel.s) {
|
||||
// choose the larger voxel that encompasses the one selected
|
||||
::mouseVoxel.x = ::mouseVoxelScale * floorf(::mouseVoxel.x / ::mouseVoxelScale);
|
||||
::mouseVoxel.y = ::mouseVoxelScale * floorf(::mouseVoxel.y / ::mouseVoxelScale);
|
||||
::mouseVoxel.z = ::mouseVoxelScale * floorf(::mouseVoxel.z / ::mouseVoxelScale);
|
||||
::mouseVoxel.s = ::mouseVoxelScale;
|
||||
|
||||
} else if (::mouseVoxelScale < ::mouseVoxel.s) {
|
||||
glm::vec3 pt = (origin + direction * distance) / (float)TREE_SCALE -
|
||||
getFaceVector(face) * (::mouseVoxelScale * 0.5f);
|
||||
::mouseVoxel.x = ::mouseVoxelScale * floorf(pt.x / ::mouseVoxelScale);
|
||||
::mouseVoxel.y = ::mouseVoxelScale * floorf(pt.y / ::mouseVoxelScale);
|
||||
::mouseVoxel.z = ::mouseVoxelScale * floorf(pt.z / ::mouseVoxelScale);
|
||||
::mouseVoxel.s = ::mouseVoxelScale;
|
||||
} else {
|
||||
glm::vec3 faceVector = getFaceVector(face);
|
||||
if (::mouseVoxelScale < ::mouseVoxel.s) {
|
||||
// find the closest contained voxel
|
||||
glm::vec3 pt = (origin + direction * distance) / (float)TREE_SCALE -
|
||||
faceVector * (::mouseVoxelScale * 0.5f);
|
||||
::mouseVoxel.x = ::mouseVoxelScale * floorf(pt.x / ::mouseVoxelScale);
|
||||
::mouseVoxel.y = ::mouseVoxelScale * floorf(pt.y / ::mouseVoxelScale);
|
||||
::mouseVoxel.z = ::mouseVoxelScale * floorf(pt.z / ::mouseVoxelScale);
|
||||
::mouseVoxel.s = ::mouseVoxelScale;
|
||||
}
|
||||
if (::mouseMode == ADD_VOXEL_MODE) {
|
||||
// use the face to determine the side on which to create a neighbor
|
||||
::mouseVoxel.x += faceVector.x * ::mouseVoxel.s;
|
||||
::mouseVoxel.y += faceVector.y * ::mouseVoxel.s;
|
||||
::mouseVoxel.z += faceVector.z * ::mouseVoxel.s;
|
||||
}
|
||||
}
|
||||
|
||||
if (::mouseMode == ADD_VOXEL_MODE) {
|
||||
// use the face to determine the side on which to create a neighbor
|
||||
glm::vec3 offset = getFaceVector(face);
|
||||
::mouseVoxel.x += offset.x * ::mouseVoxel.s;
|
||||
::mouseVoxel.y += offset.y * ::mouseVoxel.s;
|
||||
::mouseVoxel.z += offset.z * ::mouseVoxel.s;
|
||||
|
||||
} else if (::mouseMode == COLOR_VOXEL_MODE) {
|
||||
if (::mouseMode == COLOR_VOXEL_MODE) {
|
||||
::mouseVoxel.red = 0;
|
||||
::mouseVoxel.green = 255;
|
||||
::mouseVoxel.blue = 0;
|
||||
|
||||
} else { // ::mouseMode == DELETE_VOXEL_MODE
|
||||
} else if (::mouseMode == DELETE_VOXEL_MODE) {
|
||||
// red indicates deletion
|
||||
::mouseVoxel.red = 255;
|
||||
::mouseVoxel.green = ::mouseVoxel.blue = 0;
|
||||
|
|
|
@ -229,16 +229,16 @@ void VoxelTree::readBitstreamToTree(unsigned char * bitstream, unsigned long int
|
|||
this->voxelsBytesReadStats.updateAverage(bufferSizeBytes);
|
||||
}
|
||||
|
||||
void VoxelTree::deleteVoxelAt(float x, float y, float z, float s) {
|
||||
void VoxelTree::deleteVoxelAt(float x, float y, float z, float s, bool stage) {
|
||||
unsigned char* octalCode = pointToVoxel(x,y,z,s,0,0,0);
|
||||
deleteVoxelCodeFromTree(octalCode);
|
||||
deleteVoxelCodeFromTree(octalCode, stage);
|
||||
delete octalCode; // cleanup memory
|
||||
}
|
||||
|
||||
|
||||
// Note: uses the codeColorBuffer format, but the color's are ignored, because
|
||||
// this only finds and deletes the node from the tree.
|
||||
void VoxelTree::deleteVoxelCodeFromTree(unsigned char *codeBuffer) {
|
||||
void VoxelTree::deleteVoxelCodeFromTree(unsigned char *codeBuffer, bool stage) {
|
||||
VoxelNode* parentNode = NULL;
|
||||
VoxelNode* nodeToDelete = nodeForOctalCode(rootNode, codeBuffer, &parentNode);
|
||||
|
||||
|
@ -249,38 +249,33 @@ void VoxelTree::deleteVoxelCodeFromTree(unsigned char *codeBuffer) {
|
|||
if (parentNode) {
|
||||
int childIndex = branchIndexWithDescendant(parentNode->getOctalCode(), codeBuffer);
|
||||
|
||||
parentNode->deleteChildAtIndex(childIndex);
|
||||
|
||||
if (stage) {
|
||||
nodeToDelete->stageForDeletion();
|
||||
} else {
|
||||
parentNode->deleteChildAtIndex(childIndex);
|
||||
}
|
||||
|
||||
reaverageVoxelColors(rootNode); // Fix our colors!! Need to call it on rootNode
|
||||
_isDirty = true;
|
||||
}
|
||||
} else {
|
||||
} else if (nodeToDelete->isLeaf()) {
|
||||
// we need to break up ancestors until we get to the right level
|
||||
if (!nodeToDelete->isColored()) {
|
||||
return;
|
||||
}
|
||||
nodeColor color;
|
||||
nodeColor noColor;
|
||||
memcpy(color, nodeToDelete->getColor(), sizeof(nodeColor));
|
||||
memcpy(noColor, nodeToDelete->getColor(), sizeof(nodeColor));
|
||||
noColor[3] = 0;
|
||||
|
||||
VoxelNode* ancestorNode = nodeToDelete;
|
||||
while (true) {
|
||||
nodeToDelete->setColor(noColor);
|
||||
int index = branchIndexWithDescendant(nodeToDelete->getOctalCode(), codeBuffer);
|
||||
int index = branchIndexWithDescendant(ancestorNode->getOctalCode(), codeBuffer);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (i != index) {
|
||||
nodeToDelete->addChildAtIndex(i);
|
||||
nodeToDelete->getChildAtIndex(i)->setColor(color);
|
||||
ancestorNode->addChildAtIndex(i);
|
||||
ancestorNode->getChildAtIndex(i)->setColor(nodeToDelete->getColor());
|
||||
}
|
||||
}
|
||||
if (*nodeToDelete->getOctalCode() == *codeBuffer - 1) {
|
||||
if (*ancestorNode->getOctalCode() == *codeBuffer - 1) {
|
||||
break;
|
||||
}
|
||||
nodeToDelete->addChildAtIndex(index);
|
||||
nodeToDelete = nodeToDelete->getChildAtIndex(index);
|
||||
ancestorNode->addChildAtIndex(index);
|
||||
ancestorNode = ancestorNode->getChildAtIndex(index);
|
||||
ancestorNode->setColor(nodeToDelete->getColor());
|
||||
}
|
||||
reaverageVoxelColors(rootNode);
|
||||
_isDirty = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,11 +42,11 @@ public:
|
|||
void processRemoveVoxelBitstream(unsigned char * bitstream, int bufferSizeBytes);
|
||||
void readBitstreamToTree(unsigned char * bitstream, unsigned long int bufferSizeBytes);
|
||||
void readCodeColorBufferToTree(unsigned char *codeColorBuffer);
|
||||
void deleteVoxelCodeFromTree(unsigned char *codeBuffer);
|
||||
void deleteVoxelCodeFromTree(unsigned char *codeBuffer, bool stage = false);
|
||||
void printTreeForDebugging(VoxelNode *startNode);
|
||||
void reaverageVoxelColors(VoxelNode *startNode);
|
||||
|
||||
void deleteVoxelAt(float x, float y, float z, float s);
|
||||
void deleteVoxelAt(float x, float y, float z, float s, bool stage = false);
|
||||
VoxelNode* getVoxelAt(float x, float y, float z, float s) const;
|
||||
void createVoxel(float x, float y, float z, float s, unsigned char red, unsigned char green, unsigned char blue);
|
||||
void createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, rgbColor color);
|
||||
|
|
Loading…
Reference in a new issue