visual_instance.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*************************************************************************/
  2. /* visual_instance.h */
  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. #ifndef VISUAL_INSTANCE_H
  30. #define VISUAL_INSTANCE_H
  31. #include "scene/3d/spatial.h"
  32. #include "face3.h"
  33. #include "rid.h"
  34. #include "scene/resources/material.h"
  35. /**
  36. @author Juan Linietsky <reduzio@gmail.com>
  37. */
  38. class VisualInstance : public Spatial {
  39. OBJ_TYPE( VisualInstance, Spatial );
  40. OBJ_CATEGORY("3D Visual Nodes");
  41. RID instance;
  42. uint32_t layers;
  43. RID _get_visual_instance_rid() const;
  44. protected:
  45. void _notification(int p_what);
  46. static void _bind_methods();
  47. public:
  48. enum GetFacesFlags {
  49. FACES_SOLID=1, // solid geometry
  50. FACES_ENCLOSING=2,
  51. FACES_DYNAMIC=4 // dynamic object geometry
  52. };
  53. RID get_instance() const;
  54. virtual AABB get_aabb() const=0;
  55. virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const=0;
  56. virtual AABB get_transformed_aabb() const; // helper
  57. void set_base(const RID& p_base);
  58. void set_layer_mask(uint32_t p_mask);
  59. uint32_t get_layer_mask() const;
  60. VisualInstance();
  61. ~VisualInstance();
  62. };
  63. class BakedLightInstance;
  64. class GeometryInstance : public VisualInstance {
  65. OBJ_TYPE( GeometryInstance, VisualInstance );
  66. public:
  67. enum Flags {
  68. FLAG_VISIBLE=VS::INSTANCE_FLAG_VISIBLE,
  69. FLAG_CAST_SHADOW=VS::INSTANCE_FLAG_CAST_SHADOW,
  70. FLAG_RECEIVE_SHADOWS=VS::INSTANCE_FLAG_RECEIVE_SHADOWS,
  71. FLAG_BILLBOARD=VS::INSTANCE_FLAG_BILLBOARD,
  72. FLAG_BILLBOARD_FIX_Y=VS::INSTANCE_FLAG_BILLBOARD_FIX_Y,
  73. FLAG_DEPH_SCALE=VS::INSTANCE_FLAG_DEPH_SCALE,
  74. FLAG_VISIBLE_IN_ALL_ROOMS=VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS,
  75. FLAG_USE_BAKED_LIGHT=VS::INSTANCE_FLAG_USE_BAKED_LIGHT,
  76. FLAG_MAX=VS::INSTANCE_FLAG_MAX,
  77. };
  78. private:
  79. bool flags[FLAG_MAX];
  80. Ref<Material> material_override;
  81. float draw_begin;
  82. float draw_end;
  83. void _find_baked_light();
  84. BakedLightInstance *baked_light_instance;
  85. int baked_light_texture_id;
  86. float extra_cull_margin;
  87. void _baked_light_changed();
  88. void _update_visibility();
  89. protected:
  90. void _notification(int p_what);
  91. static void _bind_methods();
  92. public:
  93. void set_flag(Flags p_flag,bool p_value);
  94. bool get_flag(Flags p_flag) const;
  95. void set_draw_range_begin(float p_dist);
  96. float get_draw_range_begin() const;
  97. void set_draw_range_end(float p_dist);
  98. float get_draw_range_end() const;
  99. void set_material_override(const Ref<Material>& p_material);
  100. Ref<Material> get_material_override() const;
  101. void set_baked_light_texture_id(int p_id);
  102. int get_baked_light_texture_id() const;
  103. void set_extra_cull_margin(float p_margin);
  104. float get_extra_cull_margin() const;
  105. GeometryInstance();
  106. };
  107. VARIANT_ENUM_CAST( GeometryInstance::Flags );
  108. #endif