room.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*************************************************************************/
  2. /* room.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  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. #include "room.h"
  31. #include "servers/visual_server.h"
  32. RID RoomBounds::get_rid() const {
  33. return area;
  34. }
  35. void RoomBounds::set_bounds(const BSP_Tree &p_bounds) {
  36. VisualServer::get_singleton()->room_set_bounds(area, p_bounds);
  37. emit_signal("changed");
  38. }
  39. BSP_Tree RoomBounds::get_bounds() const {
  40. return VisualServer::get_singleton()->room_get_bounds(area);
  41. }
  42. void RoomBounds::set_geometry_hint(const DVector<Face3> &p_geometry_hint) {
  43. geometry_hint = p_geometry_hint;
  44. }
  45. DVector<Face3> RoomBounds::get_geometry_hint() const {
  46. return geometry_hint;
  47. }
  48. void RoomBounds::_regenerate_bsp_cubic() {
  49. if (geometry_hint.size()) {
  50. float err = 0;
  51. geometry_hint = Geometry::wrap_geometry(geometry_hint, &err); ///< create a "wrap" that encloses the given geometry
  52. BSP_Tree new_bounds(geometry_hint, err);
  53. set_bounds(new_bounds);
  54. }
  55. }
  56. void RoomBounds::_regenerate_bsp() {
  57. if (geometry_hint.size()) {
  58. BSP_Tree new_bounds(geometry_hint, 0);
  59. set_bounds(new_bounds);
  60. }
  61. }
  62. void RoomBounds::_bind_methods() {
  63. ObjectTypeDB::bind_method(_MD("set_bounds", "bsp_tree"), &RoomBounds::set_bounds);
  64. ObjectTypeDB::bind_method(_MD("get_bounds"), &RoomBounds::get_bounds);
  65. ObjectTypeDB::bind_method(_MD("set_geometry_hint", "triangles"), &RoomBounds::set_geometry_hint);
  66. ObjectTypeDB::bind_method(_MD("get_geometry_hint"), &RoomBounds::get_geometry_hint);
  67. ObjectTypeDB::bind_method(_MD("regenerate_bsp"), &RoomBounds::_regenerate_bsp);
  68. ObjectTypeDB::set_method_flags(get_type_static(), _SCS("regenerate_bsp"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
  69. ObjectTypeDB::bind_method(_MD("regenerate_bsp_cubic"), &RoomBounds::_regenerate_bsp_cubic);
  70. ObjectTypeDB::set_method_flags(get_type_static(), _SCS("regenerate_bsp_cubic"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
  71. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "bounds"), _SCS("set_bounds"), _SCS("get_bounds"));
  72. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3_ARRAY, "geometry_hint"), _SCS("set_geometry_hint"), _SCS("get_geometry_hint"));
  73. }
  74. RoomBounds::RoomBounds() {
  75. area = VisualServer::get_singleton()->room_create();
  76. }
  77. RoomBounds::~RoomBounds() {
  78. VisualServer::get_singleton()->free(area);
  79. }