test_navigation_region_3d.h 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**************************************************************************/
  2. /* test_navigation_region_3d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef TEST_NAVIGATION_REGION_3D_H
  31. #define TEST_NAVIGATION_REGION_3D_H
  32. #include "scene/3d/mesh_instance_3d.h"
  33. #include "scene/3d/navigation_region_3d.h"
  34. #include "scene/main/window.h"
  35. #include "scene/resources/3d/primitive_meshes.h"
  36. #include "tests/test_macros.h"
  37. namespace TestNavigationRegion3D {
  38. TEST_SUITE("[Navigation]") {
  39. TEST_CASE("[SceneTree][NavigationRegion3D] New region should have valid RID") {
  40. NavigationRegion3D *region_node = memnew(NavigationRegion3D);
  41. CHECK(region_node->get_rid().is_valid());
  42. memdelete(region_node);
  43. }
  44. TEST_CASE("[SceneTree][NavigationRegion3D] Region should bake successfully from valid geometry") {
  45. Node3D *node_3d = memnew(Node3D);
  46. SceneTree::get_singleton()->get_root()->add_child(node_3d);
  47. Ref<NavigationMesh> navigation_mesh = memnew(NavigationMesh);
  48. NavigationRegion3D *navigation_region = memnew(NavigationRegion3D);
  49. navigation_region->set_navigation_mesh(navigation_mesh);
  50. node_3d->add_child(navigation_region);
  51. Ref<PlaneMesh> plane_mesh = memnew(PlaneMesh);
  52. plane_mesh->set_size(Size2(10.0, 10.0));
  53. MeshInstance3D *mesh_instance = memnew(MeshInstance3D);
  54. mesh_instance->set_mesh(plane_mesh);
  55. navigation_region->add_child(mesh_instance);
  56. CHECK_FALSE(navigation_region->is_baking());
  57. CHECK_EQ(navigation_mesh->get_polygon_count(), 0);
  58. CHECK_EQ(navigation_mesh->get_vertices().size(), 0);
  59. SUBCASE("Synchronous bake should have immediate effects") {
  60. ERR_PRINT_OFF; // Suppress warning about baking from visual meshes as source geometry.
  61. navigation_region->bake_navigation_mesh(false);
  62. ERR_PRINT_ON;
  63. CHECK_FALSE(navigation_region->is_baking());
  64. CHECK_NE(navigation_mesh->get_polygon_count(), 0);
  65. CHECK_NE(navigation_mesh->get_vertices().size(), 0);
  66. }
  67. memdelete(mesh_instance);
  68. memdelete(navigation_region);
  69. memdelete(node_3d);
  70. }
  71. }
  72. } //namespace TestNavigationRegion3D
  73. #endif // TEST_NAVIGATION_REGION_3D_H