mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:44:01 +02:00
Adding density to nodes
This commit is contained in:
parent
f42f248db2
commit
769383582b
3 changed files with 35 additions and 14 deletions
|
@ -35,7 +35,7 @@ void VoxelNode::init(unsigned char * octalCode) {
|
|||
_currentColor[0] = _currentColor[1] = _currentColor[2] = _currentColor[3] = 0;
|
||||
#endif
|
||||
_trueColor[0] = _trueColor[1] = _trueColor[2] = _trueColor[3] = 0;
|
||||
|
||||
_density = 0.0f;
|
||||
|
||||
// default pointers to child nodes to NULL
|
||||
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
||||
|
@ -165,6 +165,7 @@ void VoxelNode::safeDeepDeleteChildAtIndex(int childIndex, bool& stagedForDeleti
|
|||
// will average the child colors...
|
||||
void VoxelNode::setColorFromAverageOfChildren() {
|
||||
int colorArray[4] = {0,0,0,0};
|
||||
float density = 0.0f;
|
||||
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
||||
if (_children[i] && !_children[i]->isStagedForDeletion() && _children[i]->isColored()) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
|
@ -172,11 +173,27 @@ void VoxelNode::setColorFromAverageOfChildren() {
|
|||
}
|
||||
colorArray[3]++;
|
||||
}
|
||||
if (_children[i]) {
|
||||
density += _children[i]->getDensity();
|
||||
}
|
||||
}
|
||||
if (_childCount > 0) {
|
||||
// If there are children, density is sum of child densities
|
||||
density /= (float) NUMBER_OF_CHILDREN;
|
||||
} else {
|
||||
// If there are no children
|
||||
density = 1.f;
|
||||
}
|
||||
|
||||
if (colorArray[3] > 0) {
|
||||
printf("children: %d, density = %4.2f\n", colorArray[3], density);
|
||||
}
|
||||
|
||||
const float VISIBLE_ABOVE_DENSITY = 0.0f;
|
||||
nodeColor newColor = { 0, 0, 0, 0};
|
||||
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
|
||||
// if (density > VISIBLE_ABOVE_DENSITY) {
|
||||
if (colorArray[3] > 0) {
|
||||
// The density of material in the space of the voxel sets whether it is actually colored
|
||||
for (int c = 0; c < 3; c++) {
|
||||
// set the average color value
|
||||
newColor[c] = colorArray[c] / colorArray[3];
|
||||
|
@ -188,6 +205,7 @@ void VoxelNode::setColorFromAverageOfChildren() {
|
|||
// this will be the default value all zeros, and therefore be marked as
|
||||
// transparent with a 4th element of 0
|
||||
setColor(newColor);
|
||||
setDensity(density);
|
||||
}
|
||||
|
||||
// Note: !NO_FALSE_COLOR implementations of setFalseColor(), setFalseColored(), and setColor() here.
|
||||
|
|
|
@ -36,6 +36,7 @@ private:
|
|||
unsigned char* _octalCode;
|
||||
VoxelNode* _children[8];
|
||||
int _childCount;
|
||||
float _density; // If leaf: density = 1, if internal node: 0-1 density of voxels inside
|
||||
|
||||
void calculateAABox();
|
||||
|
||||
|
@ -102,11 +103,14 @@ public:
|
|||
void setColor(const nodeColor& color);
|
||||
const nodeColor& getTrueColor() const { return _trueColor; };
|
||||
const nodeColor& getColor() const { return _currentColor; };
|
||||
void setDensity(const float density) { _density = density; };
|
||||
const float getDensity() const { return _density; };
|
||||
#else
|
||||
void setFalseColor(colorPart red, colorPart green, colorPart blue) { /* no op */ };
|
||||
void setFalseColored(bool isFalseColored) { /* no op */ };
|
||||
bool getFalseColored() { return false; };
|
||||
void setColor(const nodeColor& color) { memcpy(_trueColor,color,sizeof(nodeColor)); };
|
||||
void setDensity(const float density) { _density = density; };
|
||||
const nodeColor& getTrueColor() const { return _trueColor; };
|
||||
const nodeColor& getColor() const { return _trueColor; };
|
||||
#endif
|
||||
|
|
|
@ -387,16 +387,6 @@ void persistVoxelsWhenDirty() {
|
|||
|
||||
// check the dirty bit and persist here...
|
||||
if (::wantVoxelPersist && ::serverTree.isDirty() && sinceLastTime > VOXEL_PERSIST_INTERVAL) {
|
||||
|
||||
{
|
||||
PerformanceWarning warn(::shouldShowAnimationDebug,
|
||||
"persistVoxelsWhenDirty() - reaverageVoxelColors()", ::shouldShowAnimationDebug);
|
||||
|
||||
// after done inserting all these voxels, then reaverage colors
|
||||
serverTree.reaverageVoxelColors(serverTree.rootNode);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
PerformanceWarning warn(::shouldShowAnimationDebug,
|
||||
"persistVoxelsWhenDirty() - writeToSVOFile()", ::shouldShowAnimationDebug);
|
||||
|
@ -506,6 +496,15 @@ int main(int argc, const char * argv[]) {
|
|||
if (::wantVoxelPersist) {
|
||||
printf("loading voxels from file...\n");
|
||||
persistantFileRead = ::serverTree.readFromSVOFile(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE);
|
||||
if (persistantFileRead) {
|
||||
PerformanceWarning warn(::shouldShowAnimationDebug,
|
||||
"persistVoxelsWhenDirty() - reaverageVoxelColors()", ::shouldShowAnimationDebug);
|
||||
|
||||
// after done inserting all these voxels, then reaverage colors
|
||||
serverTree.reaverageVoxelColors(serverTree.rootNode);
|
||||
printf("Voxels reAveraged\n");
|
||||
}
|
||||
|
||||
::serverTree.clearDirtyBit(); // the tree is clean since we just loaded it
|
||||
printf("DONE loading voxels from file... fileRead=%s\n", debug::valueOf(persistantFileRead));
|
||||
unsigned long nodeCount = ::serverTree.getVoxelCount();
|
||||
|
|
Loading…
Reference in a new issue