Octree.pkg 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. $#include "Graphics/Octree.h"
  2. class Octree : public Component
  3. {
  4. void SetSize(const BoundingBox& box, unsigned numLevels);
  5. void Update(const FrameInfo& frame);
  6. void AddManualDrawable(Drawable* drawable);
  7. void RemoveManualDrawable(Drawable* drawable);
  8. // void GetDrawables(OctreeQuery& query) const;
  9. tolua_outside const PODVector<OctreeQueryResult>& OctreeGetDrawablesPoint @ GetDrawables(const Vector3& point, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
  10. tolua_outside const PODVector<OctreeQueryResult>& OctreeGetDrawablesBoundingBox @ GetDrawables(const BoundingBox& box, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
  11. tolua_outside const PODVector<OctreeQueryResult>& OctreeGetDrawablesFrustum @ GetDrawables(const Frustum& frustum, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
  12. tolua_outside const PODVector<OctreeQueryResult>& OctreeGetDrawablesSphere @ GetDrawables(const Sphere& sphere, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
  13. tolua_outside const PODVector<OctreeQueryResult>& OctreeGetAllDrawables @ GetAllDrawables(unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
  14. // void Raycast(RayOctreeQuery& query) const;
  15. tolua_outside const PODVector<RayQueryResult>& OctreeRaycast @ Raycast(const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags, unsigned viewMask = DEFAULT_VIEWMASK) const;
  16. // void RaycastSingle(RayOctreeQuery& query) const;
  17. tolua_outside RayQueryResult OctreeRaycastSingle @ RaycastSingle(const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags, unsigned viewMask = DEFAULT_VIEWMASK) const;
  18. unsigned GetNumLevels() const;
  19. void QueueUpdate(Drawable* drawable);
  20. void DrawDebugGeometry(bool depthTest);
  21. tolua_readonly tolua_property__get_set unsigned numLevels;
  22. };
  23. ${
  24. static const PODVector<OctreeQueryResult>& OctreeGetDrawablesPoint(const Octree* octree, const Vector3& point, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
  25. {
  26. PODVector<Drawable*> drawableResult;
  27. PointOctreeQuery query(drawableResult, point, drawableFlags, viewMask);
  28. octree->GetDrawables(query);
  29. static PODVector<OctreeQueryResult> result;
  30. result.Resize(drawableResult.Size());
  31. for (unsigned i = 0; i < drawableResult.Size(); ++i)
  32. {
  33. result[i].drawable_ = drawableResult[i];
  34. result[i].node_ = drawableResult[i]->GetNode();
  35. }
  36. return result;
  37. }
  38. static const PODVector<OctreeQueryResult>& OctreeGetDrawablesBoundingBox(const Octree* octree, const BoundingBox& box, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
  39. {
  40. PODVector<Drawable*> drawableResult;
  41. BoxOctreeQuery query(drawableResult, box, drawableFlags, viewMask);
  42. octree->GetDrawables(query);
  43. static PODVector<OctreeQueryResult> result;
  44. result.Resize(drawableResult.Size());
  45. for (unsigned i = 0; i < drawableResult.Size(); ++i)
  46. {
  47. result[i].drawable_ = drawableResult[i];
  48. result[i].node_ = drawableResult[i]->GetNode();
  49. }
  50. return result;
  51. }
  52. static const PODVector<OctreeQueryResult>& OctreeGetDrawablesFrustum(const Octree* octree, const Frustum& frustum, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
  53. {
  54. PODVector<Drawable*> drawableResult;
  55. FrustumOctreeQuery query(drawableResult, frustum, drawableFlags, viewMask);
  56. octree->GetDrawables(query);
  57. static PODVector<OctreeQueryResult> result;
  58. result.Resize(drawableResult.Size());
  59. for (unsigned i = 0; i < drawableResult.Size(); ++i)
  60. {
  61. result[i].drawable_ = drawableResult[i];
  62. result[i].node_ = drawableResult[i]->GetNode();
  63. }
  64. return result;
  65. }
  66. static const PODVector<OctreeQueryResult>& OctreeGetDrawablesSphere(const Octree* octree, const Sphere& sphere, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
  67. {
  68. PODVector<Drawable*> drawableResult;
  69. SphereOctreeQuery query(drawableResult, sphere, drawableFlags, viewMask);
  70. octree->GetDrawables(query);
  71. static PODVector<OctreeQueryResult> result;
  72. result.Resize(drawableResult.Size());
  73. for (unsigned i = 0; i < drawableResult.Size(); ++i)
  74. {
  75. result[i].drawable_ = drawableResult[i];
  76. result[i].node_ = drawableResult[i]->GetNode();
  77. }
  78. return result;
  79. }
  80. static const PODVector<OctreeQueryResult>& OctreeGetAllDrawables(const Octree* octree, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
  81. {
  82. PODVector<Drawable*> drawableResult;
  83. AllContentOctreeQuery query(drawableResult, drawableFlags, viewMask);
  84. octree->GetDrawables(query);
  85. static PODVector<OctreeQueryResult> result;
  86. result.Resize(drawableResult.Size());
  87. for (unsigned i = 0; i < drawableResult.Size(); ++i)
  88. {
  89. result[i].drawable_ = drawableResult[i];
  90. result[i].node_ = drawableResult[i]->GetNode();
  91. }
  92. return result;
  93. }
  94. static RayQueryResult OctreeRaycastSingle(const Octree* octree, const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags, unsigned viewMask = DEFAULT_VIEWMASK)
  95. {
  96. PODVector<RayQueryResult> result;
  97. RayOctreeQuery query(result, ray, level, maxDistance, drawableFlags, viewMask);
  98. octree->RaycastSingle(query);
  99. if (!query.result_.Empty())
  100. return query.result_[0];
  101. else
  102. {
  103. RayQueryResult empty;
  104. empty.position_ = Vector3::ZERO;
  105. empty.normal_ = Vector3::ZERO;
  106. empty.distance_ = M_INFINITY;
  107. empty.subObject_ = 0;
  108. return empty;
  109. }
  110. }
  111. static const PODVector<RayQueryResult>& OctreeRaycast(const Octree* octree, const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags, unsigned viewMask = DEFAULT_VIEWMASK)
  112. {
  113. static PODVector<RayQueryResult> result;
  114. result.Clear();
  115. RayOctreeQuery query(result, ray, level, maxDistance, drawableFlags, viewMask);
  116. octree->Raycast(query);
  117. return result;
  118. }
  119. $}