test_navigation_region_3d.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #pragma once
  31. #include "scene/3d/mesh_instance_3d.h"
  32. #include "scene/3d/navigation/navigation_region_3d.h"
  33. #include "scene/main/window.h"
  34. #include "scene/resources/3d/primitive_meshes.h"
  35. #include "tests/test_macros.h"
  36. namespace TestNavigationRegion3D {
  37. TEST_SUITE("[Navigation3D]") {
  38. TEST_CASE("[SceneTree][NavigationRegion3D] New region should have valid RID") {
  39. NavigationRegion3D *region_node = memnew(NavigationRegion3D);
  40. CHECK(region_node->get_rid().is_valid());
  41. memdelete(region_node);
  42. }
  43. TEST_CASE("[SceneTree][NavigationRegion3D] Region should bake successfully from valid geometry") {
  44. Node3D *node_3d = memnew(Node3D);
  45. SceneTree::get_singleton()->get_root()->add_child(node_3d);
  46. Ref<NavigationMesh> navigation_mesh = memnew(NavigationMesh);
  47. NavigationRegion3D *navigation_region = memnew(NavigationRegion3D);
  48. navigation_region->set_navigation_mesh(navigation_mesh);
  49. node_3d->add_child(navigation_region);
  50. Ref<PlaneMesh> plane_mesh = memnew(PlaneMesh);
  51. plane_mesh->set_size(Size2(10.0, 10.0));
  52. MeshInstance3D *mesh_instance = memnew(MeshInstance3D);
  53. mesh_instance->set_mesh(plane_mesh);
  54. navigation_region->add_child(mesh_instance);
  55. CHECK_FALSE(navigation_region->is_baking());
  56. CHECK_EQ(navigation_mesh->get_polygon_count(), 0);
  57. CHECK_EQ(navigation_mesh->get_vertices().size(), 0);
  58. SUBCASE("Synchronous bake should have immediate effects") {
  59. ERR_PRINT_OFF; // Suppress warning about baking from visual meshes as source geometry.
  60. navigation_region->bake_navigation_mesh(false);
  61. ERR_PRINT_ON;
  62. CHECK_FALSE(navigation_region->is_baking());
  63. CHECK_NE(navigation_mesh->get_polygon_count(), 0);
  64. CHECK_NE(navigation_mesh->get_vertices().size(), 0);
  65. }
  66. memdelete(mesh_instance);
  67. memdelete(navigation_region);
  68. memdelete(node_3d);
  69. }
  70. }
  71. } //namespace TestNavigationRegion3D