More editing progress. Now there are threading issues. Joy!

This commit is contained in:
Andrzej Kapolka 2013-05-10 21:02:08 -07:00
parent f0573e6ee5
commit 750843e867
4 changed files with 50 additions and 55 deletions

View file

@ -989,19 +989,10 @@ 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); _tree->deleteVoxelAt(x, y, z, s, true);
VoxelNode* node = _tree->getVoxelAt(x, y, z, s); // redraw!
if (node) { setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in?
// 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?
}
}; };
VoxelNode* VoxelSystem::getVoxelAt(float x, float y, float z, float s) const { VoxelNode* VoxelSystem::getVoxelAt(float x, float y, float z, float s) const {

View file

@ -726,7 +726,12 @@ void displaySide(Camera& whichCamera) {
// indicate what we'll be adding/removing in mouse mode, if anything // indicate what we'll be adding/removing in mouse mode, if anything
if (::mouseVoxel.s != 0) { if (::mouseVoxel.s != 0) {
glPushMatrix(); 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); glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE);
glTranslatef(::mouseVoxel.x + ::mouseVoxel.s*0.5f, glTranslatef(::mouseVoxel.x + ::mouseVoxel.s*0.5f,
::mouseVoxel.y + ::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)) { if (voxels.findRayIntersection(origin, direction, ::mouseVoxel, distance, face)) {
// find the nearest voxel with the desired scale // find the nearest voxel with the desired scale
if (::mouseVoxelScale > ::mouseVoxel.s) { if (::mouseVoxelScale > ::mouseVoxel.s) {
// choose the larger voxel that encompasses the one selected
::mouseVoxel.x = ::mouseVoxelScale * floorf(::mouseVoxel.x / ::mouseVoxelScale); ::mouseVoxel.x = ::mouseVoxelScale * floorf(::mouseVoxel.x / ::mouseVoxelScale);
::mouseVoxel.y = ::mouseVoxelScale * floorf(::mouseVoxel.y / ::mouseVoxelScale); ::mouseVoxel.y = ::mouseVoxelScale * floorf(::mouseVoxel.y / ::mouseVoxelScale);
::mouseVoxel.z = ::mouseVoxelScale * floorf(::mouseVoxel.z / ::mouseVoxelScale); ::mouseVoxel.z = ::mouseVoxelScale * floorf(::mouseVoxel.z / ::mouseVoxelScale);
::mouseVoxel.s = ::mouseVoxelScale; ::mouseVoxel.s = ::mouseVoxelScale;
} else if (::mouseVoxelScale < ::mouseVoxel.s) { } else {
glm::vec3 pt = (origin + direction * distance) / (float)TREE_SCALE - glm::vec3 faceVector = getFaceVector(face);
getFaceVector(face) * (::mouseVoxelScale * 0.5f); if (::mouseVoxelScale < ::mouseVoxel.s) {
::mouseVoxel.x = ::mouseVoxelScale * floorf(pt.x / ::mouseVoxelScale); // find the closest contained voxel
::mouseVoxel.y = ::mouseVoxelScale * floorf(pt.y / ::mouseVoxelScale); glm::vec3 pt = (origin + direction * distance) / (float)TREE_SCALE -
::mouseVoxel.z = ::mouseVoxelScale * floorf(pt.z / ::mouseVoxelScale); faceVector * (::mouseVoxelScale * 0.5f);
::mouseVoxel.s = ::mouseVoxelScale; ::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) { if (::mouseMode == COLOR_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) {
::mouseVoxel.red = 0; ::mouseVoxel.red = 0;
::mouseVoxel.green = 255; ::mouseVoxel.green = 255;
::mouseVoxel.blue = 0; ::mouseVoxel.blue = 0;
} else { // ::mouseMode == DELETE_VOXEL_MODE } else if (::mouseMode == DELETE_VOXEL_MODE) {
// red indicates deletion // red indicates deletion
::mouseVoxel.red = 255; ::mouseVoxel.red = 255;
::mouseVoxel.green = ::mouseVoxel.blue = 0; ::mouseVoxel.green = ::mouseVoxel.blue = 0;

View file

@ -229,16 +229,16 @@ void VoxelTree::readBitstreamToTree(unsigned char * bitstream, unsigned long int
this->voxelsBytesReadStats.updateAverage(bufferSizeBytes); 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); unsigned char* octalCode = pointToVoxel(x,y,z,s,0,0,0);
deleteVoxelCodeFromTree(octalCode); deleteVoxelCodeFromTree(octalCode, stage);
delete octalCode; // cleanup memory delete octalCode; // cleanup memory
} }
// 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) { void VoxelTree::deleteVoxelCodeFromTree(unsigned char *codeBuffer, bool stage) {
VoxelNode* parentNode = NULL; VoxelNode* parentNode = NULL;
VoxelNode* nodeToDelete = nodeForOctalCode(rootNode, codeBuffer, &parentNode); VoxelNode* nodeToDelete = nodeForOctalCode(rootNode, codeBuffer, &parentNode);
@ -249,38 +249,33 @@ void VoxelTree::deleteVoxelCodeFromTree(unsigned char *codeBuffer) {
if (parentNode) { if (parentNode) {
int childIndex = branchIndexWithDescendant(parentNode->getOctalCode(), codeBuffer); 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 reaverageVoxelColors(rootNode); // Fix our colors!! Need to call it on rootNode
_isDirty = true; _isDirty = true;
} }
} else { } else if (nodeToDelete->isLeaf()) {
// 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
if (!nodeToDelete->isColored()) { VoxelNode* ancestorNode = nodeToDelete;
return;
}
nodeColor color;
nodeColor noColor;
memcpy(color, nodeToDelete->getColor(), sizeof(nodeColor));
memcpy(noColor, nodeToDelete->getColor(), sizeof(nodeColor));
noColor[3] = 0;
while (true) { while (true) {
nodeToDelete->setColor(noColor); int index = branchIndexWithDescendant(ancestorNode->getOctalCode(), codeBuffer);
int index = branchIndexWithDescendant(nodeToDelete->getOctalCode(), codeBuffer);
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
if (i != index) { if (i != index) {
nodeToDelete->addChildAtIndex(i); ancestorNode->addChildAtIndex(i);
nodeToDelete->getChildAtIndex(i)->setColor(color); ancestorNode->getChildAtIndex(i)->setColor(nodeToDelete->getColor());
} }
} }
if (*nodeToDelete->getOctalCode() == *codeBuffer - 1) { if (*ancestorNode->getOctalCode() == *codeBuffer - 1) {
break; break;
} }
nodeToDelete->addChildAtIndex(index); ancestorNode->addChildAtIndex(index);
nodeToDelete = nodeToDelete->getChildAtIndex(index); ancestorNode = ancestorNode->getChildAtIndex(index);
ancestorNode->setColor(nodeToDelete->getColor());
} }
reaverageVoxelColors(rootNode);
_isDirty = true; _isDirty = true;
} }
} }

View file

@ -42,11 +42,11 @@ public:
void processRemoveVoxelBitstream(unsigned char * bitstream, int bufferSizeBytes); void processRemoveVoxelBitstream(unsigned char * bitstream, int bufferSizeBytes);
void readBitstreamToTree(unsigned char * bitstream, unsigned long int bufferSizeBytes); void readBitstreamToTree(unsigned char * bitstream, unsigned long int bufferSizeBytes);
void readCodeColorBufferToTree(unsigned char *codeColorBuffer); void readCodeColorBufferToTree(unsigned char *codeColorBuffer);
void deleteVoxelCodeFromTree(unsigned char *codeBuffer); void deleteVoxelCodeFromTree(unsigned char *codeBuffer, bool stage = false);
void printTreeForDebugging(VoxelNode *startNode); void printTreeForDebugging(VoxelNode *startNode);
void reaverageVoxelColors(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; 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 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); void createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, rgbColor color);