visual_instance.h 5.2 KB

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