Showing the changes to interface/src/VoxelSystem.cpp (1 of 5 files). Show all
Unified · Split
| @@ -1050,15 +1050,13 @@ int VoxelSystem::updateNodeInArrays(VoxelTreeElement* node, bool reuseIndex, boo · 1049 unmodified lines | |||
| 1050 | if (primitiveIndex) { | 1050 | if (primitiveIndex) { |
| 1051 | _renderer->remove(primitiveIndex); | 1051 | _renderer->remove(primitiveIndex); |
| 1052 | node->setPrimitiveIndex(0); | 1052 | node->setPrimitiveIndex(0); |
| 1053 | } | 1053 | } else { |
| 1054 | else { | ||
| 1055 | node->setVoxelSystem(this); | 1054 | node->setVoxelSystem(this); |
| 1056 | } | 1055 | } |
| 1057 | inspectForInteriorOcclusionsOperation(node, 0); | 1056 | inspectForInteriorOcclusionsOperation(node, 0); |
| 1058 | 1057 | ||
| 1059 | if (node->getInteriorOcclusions() != OctreeElement::HalfSpace::All) | 1058 | if (node->getInteriorOcclusions() != OctreeElement::HalfSpace::All) { |
| 1060 | { | 1059 | Cube* cube = new Cube( |
| 1061 | Cube *cube = new Cube( | ||
| 1062 | startVertex.x, startVertex.y, startVertex.z, voxelScale, | 1060 | startVertex.x, startVertex.y, startVertex.z, voxelScale, |
| 1063 | color[RED_INDEX], color[GREEN_INDEX], color[BLUE_INDEX], | 1061 | color[RED_INDEX], color[GREEN_INDEX], color[BLUE_INDEX], |
| 1064 | node->getInteriorOcclusions()); | 1062 | node->getInteriorOcclusions()); |
| @@ -1067,8 +1065,7 @@ int VoxelSystem::updateNodeInArrays(VoxelTreeElement* node, bool reuseIndex, boo · 2 unmodified lines | |||
| 1067 | node->setPrimitiveIndex(primitiveIndex); | 1065 | node->setPrimitiveIndex(primitiveIndex); |
| 1068 | } | 1066 | } |
| 1069 | } | 1067 | } |
| 1070 | } | 1068 | } else { |
| 1071 | else { | ||
| 1072 | glBufferIndex nodeIndex = GLBUFFER_INDEX_UNKNOWN; | 1069 | glBufferIndex nodeIndex = GLBUFFER_INDEX_UNKNOWN; |
| 1073 | if (reuseIndex && node->isKnownBufferIndex()) { | 1070 | if (reuseIndex && node->isKnownBufferIndex()) { |
| 1074 | nodeIndex = node->getBufferIndex(); | 1071 | nodeIndex = node->getBufferIndex(); |
| @@ -1531,12 +1528,12 @@ bool VoxelSystem::inspectForInteriorOcclusionsOperation(OctreeElement* element, · 456 unmodified lines | |||
| 1531 | } | 1528 | } |
| 1532 | 1529 | ||
| 1533 | // Bit mask of occluded shared faces indexed by child | 1530 | // Bit mask of occluded shared faces indexed by child |
| 1534 | unsigned char occludedSharedFace[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; | 1531 | unsigned char occludedSharedFace[NUMBER_OF_CHILDREN] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 1535 | 1532 | ||
| 1536 | // Traverse all pair combinations of children | 1533 | // Traverse all pair combinations of children |
| 1537 | for (int i = NUMBER_OF_CHILDREN; --i >= 0; ) { | 1534 | for (int i = NUMBER_OF_CHILDREN; --i >= 0; ) { |
| 1538 | 1535 | ||
| 1539 | VoxelTreeElement *childA = voxel->getChildAtIndex(i); | 1536 | VoxelTreeElement* childA = voxel->getChildAtIndex(i); |
| 1540 | if (childA) { | 1537 | if (childA) { |
| 1541 | 1538 | ||
| 1542 | // Get the child A's occluding faces, for a leaf that will be | 1539 | // Get the child A's occluding faces, for a leaf that will be |
| @@ -1551,7 +1548,7 @@ bool VoxelSystem::inspectForInteriorOcclusionsOperation(OctreeElement* element, · 8 unmodified lines | |||
| 1551 | 1548 | ||
| 1552 | for (int j = i; --j >= 0; ) { | 1549 | for (int j = i; --j >= 0; ) { |
| 1553 | 1550 | ||
| 1554 | VoxelTreeElement *childB = voxel->getChildAtIndex(j); | 1551 | VoxelTreeElement* childB = voxel->getChildAtIndex(j); |
| 1555 | if (childB) { | 1552 | if (childB) { |
| 1556 | 1553 | ||
| 1557 | // Get child B's occluding faces | 1554 | // Get child B's occluding faces |
| @@ -1564,22 +1561,22 @@ bool VoxelSystem::inspectForInteriorOcclusionsOperation(OctreeElement* element, · 6 unmodified lines | |||
| 1564 | 1561 | ||
| 1565 | // Determine the shared halfspace partition between siblings A and B, | 1562 | // Determine the shared halfspace partition between siblings A and B, |
| 1566 | // i.e., near/far, left/right, or top/bottom | 1563 | // i.e., near/far, left/right, or top/bottom |
| 1567 | unsigned char partition = octantIndexToSharedBitMask[i][j] & | 1564 | unsigned char partition = _sOctantIndexToSharedBitMask[i][j] & |
| 1568 | exteriorOcclusionsA & exteriorOcclusionsB; | 1565 | exteriorOcclusionsA & exteriorOcclusionsB; |
| 1569 | 1566 | ||
| 1570 | // Determine which face of each sibling is occluded. | 1567 | // Determine which face of each sibling is occluded. |
| 1571 | // Note the intentionally crossed indicies. It is necessary because | 1568 | // Note the intentionally crossed indicies. It is necessary because |
| 1572 | // the octantIndexToBitMask is a partition occupancy mask. For | 1569 | // the _sOctantIndexToBitMask is a partition occupancy mask. For |
| 1573 | // example, if the near-left-top (NLT) and near-left-bottom (NLB) child voxels | 1570 | // example, if the near-left-top (NLT) and near-left-bottom (NLB) child voxels |
| 1574 | // exist, the shared partition is top-bottom (TB), and thus the occluded | 1571 | // exist, the shared partition is top-bottom (TB), and thus the occluded |
| 1575 | // shared face of the NLT voxel is its bottom face. | 1572 | // shared face of the NLT voxel is its bottom face. |
| 1576 | occludedSharedFace[i] |= (partition & octantIndexToBitMask[j]); | 1573 | occludedSharedFace[i] |= (partition & _sOctantIndexToBitMask[j]); |
| 1577 | occludedSharedFace[j] |= (partition & octantIndexToBitMask[i]); | 1574 | occludedSharedFace[j] |= (partition & _sOctantIndexToBitMask[i]); |
| 1578 | } | 1575 | } |
| 1579 | } | 1576 | } |
| 1580 | // Combine this voxel's interior excluded shared face only to those children which are coincident | 1577 | // Combine this voxel's interior excluded shared face only to those children which are coincident |
| 1581 | // with the excluded face. | 1578 | // with the excluded face. |
| 1582 | occludedSharedFace[i] |= (voxel->getInteriorOcclusions() & octantIndexToBitMask[i]); | 1579 | occludedSharedFace[i] |= (voxel->getInteriorOcclusions() & _sOctantIndexToBitMask[i]); |
| 1583 | 1580 | ||
| 1584 | // Inform the child | 1581 | // Inform the child |
| 1585 | childA->setInteriorOcclusions(occludedSharedFace[i]); | 1582 | childA->setInteriorOcclusions(occludedSharedFace[i]); |
| @@ -1610,13 +1607,13 @@ bool VoxelSystem::inspectForExteriorOcclusionsOperation(OctreeElement* element, · 24 unmodified lines | |||
| 1610 | // Traverse all children | 1607 | // Traverse all children |
| 1611 | for (int i = NUMBER_OF_CHILDREN; --i >= 0; ) { | 1608 | for (int i = NUMBER_OF_CHILDREN; --i >= 0; ) { |
| 1612 | 1609 | ||
| 1613 | VoxelTreeElement *child = voxel->getChildAtIndex(i); | 1610 | VoxelTreeElement* child = voxel->getChildAtIndex(i); |
| 1614 | if (child) { | 1611 | if (child) { |
| 1615 | // Get the child's occluding faces, for a leaf, that will be | 1612 | // Get the child's occluding faces, for a leaf, that will be |
| 1616 | // all six voxel faces, and for a non leaf, that will be | 1613 | // all six voxel faces, and for a non leaf, that will be |
| 1617 | // all faces which are completely covered by four child octants. | 1614 | // all faces which are completely covered by four child octants. |
| 1618 | unsigned char exteriorOcclusionsOfChild = child->getExteriorOcclusions(); | 1615 | unsigned char exteriorOcclusionsOfChild = child->getExteriorOcclusions(); |
| 1619 | exteriorOcclusionsOfChild &= octantIndexToBitMask[i]; | 1616 | exteriorOcclusionsOfChild &= _sOctantIndexToBitMask[i]; |
| 1620 | 1617 | ||
| 1621 | for (int j = 6; --j >= 0; ) { | 1618 | for (int j = 6; --j >= 0; ) { |
| 1622 | 1619 | ||
| @@ -1656,9 +1653,7 @@ bool VoxelSystem::inspectForExteriorOcclusionsOperation(OctreeElement* element, · 33 unmodified lines | |||
| 1656 | // occupied. Hence, the subtree from this node could be | 1653 | // occupied. Hence, the subtree from this node could be |
| 1657 | // pruned and replaced by a leaf voxel, if the visible | 1654 | // pruned and replaced by a leaf voxel, if the visible |
| 1658 | // properties of the children are the same | 1655 | // properties of the children are the same |
| 1659 | } | 1656 | } else if (exteriorOcclusions) { |
| 1660 | else | ||
| 1661 | if (exteriorOcclusions) { | ||
| 1662 | //const glm::vec3& v = voxel->getCorner(); | 1657 | //const glm::vec3& v = voxel->getCorner(); |
| 1663 | //float s = voxel->getScale(); | 1658 | //float s = voxel->getScale(); |
| 1664 | 1659 | ||
| @@ -1682,8 +1677,7 @@ bool VoxelSystem::clearOcclusionsOperation(OctreeElement* element, void* extraDa · 17 unmodified lines | |||
| 1682 | // And the sibling occluders | 1677 | // And the sibling occluders |
| 1683 | voxel->setInteriorOcclusions(0); | 1678 | voxel->setInteriorOcclusions(0); |
| 1684 | rc = false; | 1679 | rc = false; |
| 1685 | } | 1680 | } else { |
| 1686 | else { | ||
| 1687 | voxel->setExteriorOcclusions(0); | 1681 | voxel->setExteriorOcclusions(0); |
| 1688 | voxel->setInteriorOcclusions(0); | 1682 | voxel->setInteriorOcclusions(0); |
| 1689 | rc = true; | 1683 | rc = true; |
| @@ -1711,8 +1705,7 @@ void VoxelSystem::cullSharedFaces() { · 21 unmodified lines | |||
| 1711 | _tree->recurseTreeWithOperation(inspectForInteriorOcclusionsOperation); | 1705 | _tree->recurseTreeWithOperation(inspectForInteriorOcclusionsOperation); |
| 1712 | unlockTree(); | 1706 | unlockTree(); |
| 1713 | qDebug("culling shared faces in %d nodes", _nodeCount); | 1707 | qDebug("culling shared faces in %d nodes", _nodeCount); |
| 1714 | } | 1708 | } else { |
| 1715 | else { | ||
| 1716 | cleanupVoxelMemory(); | 1709 | cleanupVoxelMemory(); |
| 1717 | _usePrimitiveRenderer = false; | 1710 | _usePrimitiveRenderer = false; |
| 1718 | initVoxelMemory(); | 1711 | initVoxelMemory(); |
| @@ -3112,7 +3105,7 @@ void VoxelSystem::beginLoadingLocalVoxelCache() { · 1393 unmodified lines | |||
| 3112 | // Octant bitmask array indexed by octant. The mask value indicates the octant's halfspace partitioning. The index | 3105 | // Octant bitmask array indexed by octant. The mask value indicates the octant's halfspace partitioning. The index |
| 3113 | // value corresponds to the voxel's octal code derived in "pointToVoxel" in SharedUtil.cpp, which, BTW, does *not* | 3106 | // value corresponds to the voxel's octal code derived in "pointToVoxel" in SharedUtil.cpp, which, BTW, does *not* |
| 3114 | // correspond to the "ChildIndex" enum value in OctreeElement.h | 3107 | // correspond to the "ChildIndex" enum value in OctreeElement.h |
| 3115 | unsigned char VoxelSystem::octantIndexToBitMask[8] = { | 3108 | unsigned char VoxelSystem::_sOctantIndexToBitMask[8] = { |
| 3116 | OctreeElement::HalfSpace::Bottom | OctreeElement::HalfSpace::Left | OctreeElement::HalfSpace::Near, | 3109 | OctreeElement::HalfSpace::Bottom | OctreeElement::HalfSpace::Left | OctreeElement::HalfSpace::Near, |
| 3117 | OctreeElement::HalfSpace::Bottom | OctreeElement::HalfSpace::Left | OctreeElement::HalfSpace::Far, | 3110 | OctreeElement::HalfSpace::Bottom | OctreeElement::HalfSpace::Left | OctreeElement::HalfSpace::Far, |
| 3118 | OctreeElement::HalfSpace::Top | OctreeElement::HalfSpace::Left | OctreeElement::HalfSpace::Near, | 3111 | OctreeElement::HalfSpace::Top | OctreeElement::HalfSpace::Left | OctreeElement::HalfSpace::Near, |
| @@ -3125,7 +3118,7 @@ unsigned char VoxelSystem::octantIndexToBitMask[8] = { · 6 unmodified lines | |||
| 3125 | 3118 | ||
| 3126 | // Two dimensional array map indexed by octant row and column. The mask value | 3119 | // Two dimensional array map indexed by octant row and column. The mask value |
| 3127 | // indicates the two faces shared by the octants | 3120 | // indicates the two faces shared by the octants |
| 3128 | unsigned char VoxelSystem::octantIndexToSharedBitMask[8][8] = { | 3121 | unsigned char VoxelSystem::_sOctantIndexToSharedBitMask[8][8] = { |
| 3129 | { // Index 0: Bottom-Left-Near | 3122 | { // Index 0: Bottom-Left-Near |
| 3130 | 0, // Bottom-Left-Near | 3123 | 0, // Bottom-Left-Near |
| 3131 | OctreeElement::HalfSpace::Near | OctreeElement::HalfSpace::Far, // Bottom-Left-Far | 3124 | OctreeElement::HalfSpace::Near | OctreeElement::HalfSpace::Far, // Bottom-Left-Far |