Octree.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (C) 2009-2023, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <Tests/Framework/Framework.h>
  6. #include <AnKi/Scene/Octree.h>
  7. ANKI_TEST(Scene, Octree)
  8. {
  9. HeapAllocator<U8> alloc(allocAligned, nullptr);
  10. // Fuzzy
  11. #if 0
  12. {
  13. Octree octree(alloc);
  14. octree.init(Vec3(-100.0f), Vec3(100.0f), 4);
  15. OrthographicFrustum frustum(-200.0f, 200.0f, -200.0f, 200.0f, 200.0f, -200.0f);
  16. frustum.resetTransform(Transform::getIdentity());
  17. const U ITERATION_COUNT = 1000;
  18. Array<OctreePlaceable, ITERATION_COUNT> placeables;
  19. std::vector<U32> placed;
  20. for(U i = 0; i < ITERATION_COUNT; ++i)
  21. {
  22. F32 min = randRange(-100.0f, 100.0f - 1.0f);
  23. F32 max = randRange(min + 1.0f, 100.0f);
  24. Aabb volume(Vec4(Vec3(min), 0.0f), Vec4(Vec3(max), 0.0f));
  25. I mode = rand() % 3;
  26. if(mode == 0)
  27. {
  28. // Place
  29. placeables[i].m_userData = &placeables[i];
  30. octree.place(volume, &placeables[i], true);
  31. placed.push_back(i);
  32. }
  33. else if(mode == 1 && placed.size() > 0)
  34. {
  35. // Remove
  36. octree.remove(placeables[placed.back()]);
  37. placed.pop_back();
  38. }
  39. else if(placed.size() > 0)
  40. {
  41. // Gather
  42. // Reset the placed
  43. for(U32 idx : placed)
  44. {
  45. placeables[idx].reset();
  46. }
  47. DynamicArrayRaii<void*> arr(alloc);
  48. octree.gatherVisible(frustum, 0, nullptr, nullptr, arr);
  49. ANKI_TEST_EXPECT_EQ(arr.getSize(), placed.size());
  50. for(U32 idx : placed)
  51. {
  52. Bool found = false;
  53. for(void* placeable : arr)
  54. {
  55. if(&placeables[idx] == static_cast<OctreePlaceable*>(placeable))
  56. {
  57. found = true;
  58. break;
  59. }
  60. }
  61. ANKI_TEST_EXPECT_EQ(found, true);
  62. }
  63. }
  64. }
  65. // Remove all
  66. while(!placed.empty())
  67. {
  68. octree.remove(placeables[placed.back()]);
  69. placed.pop_back();
  70. }
  71. }
  72. #endif
  73. }