Guest User

Untitled

a guest
May 20th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. struct FlatOctant
  2. {
  3. static const unsigned NUM_OCTANTS = 8;
  4. IntVector3 index_;
  5. BoundingBox boundingBox_;
  6. SceneProcessorDrawableSoA data_;
  7. Vector<FlatOctant> children_;
  8. unsigned numActiveChildren_ = 0;
  9. bool HasChildren() const { return data_.size_ == 0; }
  10. bool IsSubdivided() const { return !children_.Empty(); }
  11. void Subdivide()
  12. {
  13. const Vector3 center = boundingBox_.Center();
  14. children_.Resize(NUM_OCTANTS);
  15. for (unsigned i = 0; i < NUM_OCTANTS; ++i)
  16. {
  17. FlatOctant& child = children_[i];
  18. child.index_ = IntVector3(i & 1u, i & 2u, i & 4u);
  19. child.boundingBox_.min_ = boundingBox_.min_;
  20. child.boundingBox_.max_ = boundingBox_.max_;
  21.  
  22. if (child.index_.x_)
  23. child.boundingBox_.min_.x_ = center.x_;
  24. else
  25. child.boundingBox_.max_.x_ = center.x_;
  26.  
  27. if (child.index_.y_)
  28. child.boundingBox_.min_.y_ = center.y_;
  29. else
  30. child.boundingBox_.max_.y_ = center.y_;
  31.  
  32. if (child.index_.z_)
  33. child.boundingBox_.min_.z_ = center.z_;
  34. else
  35. child.boundingBox_.max_.z_ = center.z_;
  36. }
  37. }
  38. void Rebalance(unsigned threshold, Vector<bool>& tempObjectsMask)
  39. {
  40. const unsigned effectiveThreshold = (threshold * (NUM_OCTANTS - numActiveChildren_) - 1) / NUM_OCTANTS + 1;
  41. Rebalance(effectiveThreshold, threshold / NUM_OCTANTS, threshold / NUM_OCTANTS / 2, tempObjectsMask);
  42. }
  43. void Rebalance(unsigned subdivisionThreshold, unsigned childCreationThreshold, unsigned childCollapseThreshold,
  44. Vector<bool>& tempObjectsMask)
  45. {
  46. if (data_.size_ < subdivisionThreshold || numActiveChildren_ == NUM_OCTANTS)
  47. return;
  48.  
  49. // Subdivide if needed
  50. if (!IsSubdivided())
  51. Subdivide();
  52.  
  53. // For each chunk, check whether to collapse
  54. tempObjectsMask.Resize(data_.size_);
  55. for (unsigned i = 0; i < NUM_OCTANTS; ++i)
  56. {
  57. // Skip already initialized children
  58. FlatOctant& child = children_[i];
  59. if (child.HasChildren())
  60. continue;
  61.  
  62. for ()
  63. {
  64. }
  65. }
  66. }
  67. bool IsInside(const BoundingBox& boundingBox) const
  68. {
  69. return boundingBox_.IsInsideFast(boundingBox) == INSIDE;
  70. }
  71. };
  72.  
  73. class FlatOctree
  74. {
  75. public:
  76. void Reset(float rootOctantSize, const BoundingBox& volume)
  77. {
  78. rootOctantSize_ = rootOctantSize;
  79. const IntVector3 beginOctant = VectorCeilToInt(volume.min_ / rootOctantSize_);
  80. const IntVector3 endOctant = VectorCeilToInt(volume.max_ / rootOctantSize_);
  81. const IntVector3 numOctants3 = endOctant - beginOctant + IntVector3::ONE;
  82. const unsigned numOctants = static_cast<unsigned>(numOctants3.x_ * numOctants3.y_ * numOctants3.z_);
  83.  
  84. // Initialize octants
  85. rootOctants_.Resize(numOctants);
  86. unsigned index = 0;
  87. for (int x = beginOctant.x_; x <= endOctant.x_; ++x)
  88. {
  89. for (int y = beginOctant.y_; y <= endOctant.y_; ++y)
  90. {
  91. for (int z = beginOctant.z_; z <= endOctant.z_; ++z)
  92. {
  93. FlatOctant& octant = rootOctants_[index];
  94. octant.index_ = IntVector3(x, y, z);
  95. octant.boundingBox_.min_ = Vector3(x, y, z) * rootOctantSize_;
  96. octant.boundingBox_.max_ = octant.boundingBox_.min_ + Vector3::ONE * rootOctantSize_;
  97. ++index;
  98. }
  99. }
  100. }
  101. }
  102. /// Update or add drawable.
  103. void UpdateDrawable(Drawable* drawable)
  104. {
  105. const BoundingBox& boundingBox = drawable->GetWorldBoundingBox();
  106. }
  107. private:
  108. float rootOctantSize_;
  109. FlatOctant defaultOctant_;
  110. Vector<FlatOctant> rootOctants_;
  111. };
Add Comment
Please, Sign In to add comment