mirror of
https://github.com/lubosz/overte.git
synced 2025-04-09 08:22:30 +02:00
fixed reaverageVoxelColors() behavior. seems to work better now
This commit is contained in:
parent
16ad4fc220
commit
12e06135bb
4 changed files with 16 additions and 37 deletions
|
@ -37,25 +37,20 @@ void VoxelNode::addChildAtIndex(int childIndex) {
|
|||
}
|
||||
|
||||
// will average the child colors...
|
||||
void VoxelNode::setColorFromAverageOfChildren(int * colorArray) {
|
||||
if (colorArray == NULL) {
|
||||
colorArray = new int[4];
|
||||
memset(colorArray, 0, 4*sizeof(int));
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (children[i] != NULL && children[i]->color[3] == 1) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
colorArray[j] += children[i]->color[j];
|
||||
}
|
||||
colorArray[3]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
void VoxelNode::setColorFromAverageOfChildren() {
|
||||
int colorArray[4] = {0,0,0,0};
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (children[i] != NULL && children[i]->color[3] == 1) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
colorArray[j] += children[i]->color[j];
|
||||
}
|
||||
colorArray[3]++;
|
||||
}
|
||||
}
|
||||
|
||||
if (colorArray[3] > 4) {
|
||||
// we need at least 4 colored children to have an average color value
|
||||
// or if we have none we generate random values
|
||||
|
||||
for (int c = 0; c < 3; c++) {
|
||||
// set the average color value
|
||||
color[c] = colorArray[c] / colorArray[3];
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
~VoxelNode();
|
||||
|
||||
void addChildAtIndex(int childIndex);
|
||||
void setColorFromAverageOfChildren(int * colorArray = NULL);
|
||||
void setColorFromAverageOfChildren();
|
||||
void setRandomColor(int minimumBrightness);
|
||||
bool collapseIdenticalLeaves();
|
||||
|
||||
|
|
|
@ -100,8 +100,6 @@ int VoxelTree::readNodeData(VoxelNode *destinationNode,
|
|||
|
||||
// instantiate variable for bytes already read
|
||||
int bytesRead = 1;
|
||||
int colorArray[4] = {};
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// check the colors mask to see if we have a child to color in
|
||||
if (oneAtBit(*nodeData, i)) {
|
||||
|
@ -115,17 +113,12 @@ int VoxelTree::readNodeData(VoxelNode *destinationNode,
|
|||
memcpy(destinationNode->children[i]->color, nodeData + bytesRead, 3);
|
||||
destinationNode->children[i]->color[3] = 1;
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
colorArray[j] += destinationNode->children[i]->color[j];
|
||||
}
|
||||
|
||||
bytesRead += 3;
|
||||
colorArray[3]++;
|
||||
}
|
||||
}
|
||||
|
||||
// average node's color based on color of children
|
||||
destinationNode->setColorFromAverageOfChildren(colorArray);
|
||||
destinationNode->setColorFromAverageOfChildren();
|
||||
|
||||
// give this destination node the child mask from the packet
|
||||
unsigned char childMask = *(nodeData + bytesRead);
|
||||
|
|
|
@ -85,8 +85,6 @@ void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
|
|||
if (levelsToGo > 0) {
|
||||
|
||||
bool createdChildren = false;
|
||||
int colorArray[4] = {};
|
||||
|
||||
createdChildren = false;
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
|
@ -96,17 +94,8 @@ void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
|
|||
|
||||
// give this child it's octal code
|
||||
currentRootNode->children[i]->octalCode = childOctalCode(currentRootNode->octalCode, i);
|
||||
|
||||
randomlyFillVoxelTree(levelsToGo - 1, currentRootNode->children[i]);
|
||||
|
||||
if (currentRootNode->children[i]->color[3] == 1) {
|
||||
for (int c = 0; c < 3; c++) {
|
||||
colorArray[c] += currentRootNode->children[i]->color[c];
|
||||
}
|
||||
|
||||
colorArray[3]++;
|
||||
}
|
||||
|
||||
randomlyFillVoxelTree(levelsToGo - 1, currentRootNode->children[i]);
|
||||
createdChildren = true;
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +106,7 @@ void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
|
|||
currentRootNode->setRandomColor(MIN_BRIGHTNESS);
|
||||
} else {
|
||||
// set the color value for this node
|
||||
currentRootNode->setColorFromAverageOfChildren(colorArray);
|
||||
currentRootNode->setColorFromAverageOfChildren();
|
||||
}
|
||||
} else {
|
||||
// this is a leaf node, just give it a color
|
||||
|
@ -316,6 +305,8 @@ int main(int argc, const char * argv[])
|
|||
pVoxelData+=voxelDataSize;
|
||||
atByte+=voxelDataSize;
|
||||
}
|
||||
// after done inserting all these voxels, then reaverage colors
|
||||
randomTree.reaverageVoxelColors(randomTree.rootNode);
|
||||
}
|
||||
if (packetData[0] == 'R') {
|
||||
|
||||
|
|
Loading…
Reference in a new issue