room.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*************************************************************************/
  2. /* room.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "room.h"
  30. #include "servers/visual_server.h"
  31. RID RoomBounds::get_rid() {
  32. return area;
  33. }
  34. void RoomBounds::set_bounds( const BSP_Tree& p_bounds ) {
  35. VisualServer::get_singleton()->room_set_bounds(area,p_bounds);
  36. emit_signal("changed");
  37. }
  38. BSP_Tree RoomBounds::get_bounds() const {
  39. return VisualServer::get_singleton()->room_get_bounds(area);
  40. }
  41. void RoomBounds::set_geometry_hint(const DVector<Face3>& p_geometry_hint) {
  42. geometry_hint=p_geometry_hint;
  43. }
  44. const DVector<Face3>& RoomBounds::get_geometry_hint() const {
  45. return geometry_hint;
  46. }
  47. void RoomBounds::_regenerate_bsp_cubic() {
  48. if (geometry_hint.size()) {
  49. float err=0;
  50. geometry_hint= Geometry::wrap_geometry( geometry_hint, &err ); ///< create a "wrap" that encloses the given geometry
  51. BSP_Tree new_bounds(geometry_hint,err);
  52. set_bounds(new_bounds);
  53. }
  54. }
  55. void RoomBounds::_regenerate_bsp() {
  56. if (geometry_hint.size()) {
  57. BSP_Tree new_bounds(geometry_hint,0);
  58. set_bounds(new_bounds);
  59. }
  60. }
  61. void RoomBounds::_bind_methods() {
  62. ObjectTypeDB::bind_method(_MD("set_bounds","bsp_tree"),&RoomBounds::set_bounds);
  63. ObjectTypeDB::bind_method(_MD("get_bounds"),&RoomBounds::get_bounds);
  64. ObjectTypeDB::bind_method(_MD("set_geometry_hint","triangles"),&RoomBounds::set_geometry_hint);
  65. ObjectTypeDB::bind_method(_MD("get_geometry_hint"),&RoomBounds::get_geometry_hint);
  66. ObjectTypeDB::bind_method(_MD("regenerate_bsp"),&RoomBounds::_regenerate_bsp);
  67. ObjectTypeDB::set_method_flags(get_type_static(),_SCS("regenerate_bsp"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
  68. ObjectTypeDB::bind_method(_MD("regenerate_bsp_cubic"),&RoomBounds::_regenerate_bsp_cubic);
  69. ObjectTypeDB::set_method_flags(get_type_static(),_SCS("regenerate_bsp_cubic"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
  70. ADD_PROPERTY( PropertyInfo( Variant::DICTIONARY, "bounds"), _SCS("set_bounds"),_SCS("get_bounds") );
  71. ADD_PROPERTY( PropertyInfo( Variant::VECTOR3_ARRAY, "geometry_hint"),_SCS("set_geometry_hint"),_SCS("get_geometry_hint") );
  72. }
  73. RoomBounds::RoomBounds() {
  74. area=VisualServer::get_singleton()->room_create();
  75. }
  76. RoomBounds::~RoomBounds() {
  77. VisualServer::get_singleton()->free(area);
  78. }