bvh_debug.inc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. public:
  2. #ifdef BVH_VERBOSE
  3. void _debug_recursive_print_tree(int p_tree_id) const {
  4. if (_root_node_id[p_tree_id] != BVHCommon::INVALID)
  5. _debug_recursive_print_tree_node(_root_node_id[p_tree_id]);
  6. }
  7. String _debug_aabb_to_string(const BVH_ABB &aabb) const {
  8. String sz = "(";
  9. sz += itos(aabb.min.x);
  10. sz += " ~ ";
  11. sz += itos(-aabb.neg_max.x);
  12. sz += ") (";
  13. sz += itos(aabb.min.y);
  14. sz += " ~ ";
  15. sz += itos(-aabb.neg_max.y);
  16. sz += ") (";
  17. sz += itos(aabb.min.z);
  18. sz += " ~ ";
  19. sz += itos(-aabb.neg_max.z);
  20. sz += ") ";
  21. Vector3 size = aabb.calculate_size();
  22. float vol = size.x * size.y * size.z;
  23. sz += "vol " + itos(vol);
  24. return sz;
  25. }
  26. void _debug_recursive_print_tree_node(uint32_t p_node_id, int depth = 0) const {
  27. const TNode &tnode = _nodes[p_node_id];
  28. String sz = "";
  29. for (int n = 0; n < depth; n++) {
  30. sz += "\t";
  31. }
  32. sz += itos(p_node_id);
  33. if (tnode.is_leaf()) {
  34. sz += " L";
  35. sz += itos(tnode.height) + " ";
  36. const TLeaf &leaf = _node_get_leaf(tnode);
  37. sz += "[";
  38. for (int n = 0; n < leaf.num_items; n++) {
  39. if (n)
  40. sz += ", ";
  41. sz += "r";
  42. sz += itos(leaf.get_item_ref_id(n));
  43. }
  44. sz += "] ";
  45. } else {
  46. sz += " N";
  47. sz += itos(tnode.height) + " ";
  48. }
  49. sz += _debug_aabb_to_string(tnode.aabb);
  50. print_line(sz);
  51. if (!tnode.is_leaf()) {
  52. for (int n = 0; n < tnode.num_children; n++) {
  53. _debug_recursive_print_tree_node(tnode.children[n], depth + 1);
  54. }
  55. }
  56. }
  57. #endif