visual_instance.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**************************************************************************/
  2. /* visual_instance.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. #ifndef VISUAL_INSTANCE_H
  31. #define VISUAL_INSTANCE_H
  32. #include "core/math/face3.h"
  33. #include "core/rid.h"
  34. #include "scene/3d/cull_instance.h"
  35. #include "scene/resources/material.h"
  36. class VisualInstance : public CullInstance {
  37. GDCLASS(VisualInstance, CullInstance);
  38. OBJ_CATEGORY("3D Visual Nodes");
  39. RID base;
  40. RID instance;
  41. uint32_t layers;
  42. float sorting_offset;
  43. bool sorting_use_aabb_center;
  44. RID _get_visual_instance_rid() const;
  45. protected:
  46. void _update_visibility();
  47. virtual void _refresh_portal_mode();
  48. virtual void _physics_interpolated_changed();
  49. void set_instance_use_identity_transform(bool p_enable);
  50. void _notification(int p_what);
  51. static void _bind_methods();
  52. public:
  53. enum GetFacesFlags {
  54. FACES_SOLID = 1, // solid geometry
  55. FACES_ENCLOSING = 2,
  56. FACES_DYNAMIC = 4 // dynamic object geometry
  57. };
  58. RID get_instance() const;
  59. virtual AABB get_aabb() const = 0;
  60. virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const = 0;
  61. virtual AABB get_transformed_aabb() const; // helper
  62. void set_base(const RID &p_base);
  63. RID get_base() const;
  64. void set_layer_mask(uint32_t p_mask);
  65. uint32_t get_layer_mask() const;
  66. void set_layer_mask_bit(int p_layer, bool p_enable);
  67. bool get_layer_mask_bit(int p_layer) const;
  68. void set_sorting_offset(float p_offset);
  69. float get_sorting_offset();
  70. void set_sorting_use_aabb_center(bool p_enabled);
  71. bool is_sorting_use_aabb_center();
  72. VisualInstance();
  73. ~VisualInstance();
  74. };
  75. class GeometryInstance : public VisualInstance {
  76. GDCLASS(GeometryInstance, VisualInstance);
  77. public:
  78. enum Flags {
  79. FLAG_USE_BAKED_LIGHT = VS::INSTANCE_FLAG_USE_BAKED_LIGHT,
  80. FLAG_DRAW_NEXT_FRAME_IF_VISIBLE = VS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE,
  81. FLAG_MAX = VS::INSTANCE_FLAG_MAX,
  82. };
  83. enum LightmapScale {
  84. LIGHTMAP_SCALE_1X,
  85. LIGHTMAP_SCALE_2X,
  86. LIGHTMAP_SCALE_4X,
  87. LIGHTMAP_SCALE_8X,
  88. LIGHTMAP_SCALE_MAX,
  89. };
  90. enum ShadowCastingSetting {
  91. SHADOW_CASTING_SETTING_OFF = VS::SHADOW_CASTING_SETTING_OFF,
  92. SHADOW_CASTING_SETTING_ON = VS::SHADOW_CASTING_SETTING_ON,
  93. SHADOW_CASTING_SETTING_DOUBLE_SIDED = VS::SHADOW_CASTING_SETTING_DOUBLE_SIDED,
  94. SHADOW_CASTING_SETTING_SHADOWS_ONLY = VS::SHADOW_CASTING_SETTING_SHADOWS_ONLY
  95. };
  96. private:
  97. bool flags[FLAG_MAX];
  98. bool generate_lightmap;
  99. LightmapScale lightmap_scale;
  100. ShadowCastingSetting shadow_casting_setting;
  101. Ref<Material> material_override;
  102. Ref<Material> material_overlay;
  103. float lod_min_distance;
  104. float lod_max_distance;
  105. float lod_min_hysteresis;
  106. float lod_max_hysteresis;
  107. float extra_cull_margin;
  108. protected:
  109. void _notification(int p_what);
  110. static void _bind_methods();
  111. public:
  112. void set_flag(Flags p_flag, bool p_value);
  113. bool get_flag(Flags p_flag) const;
  114. void set_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting);
  115. ShadowCastingSetting get_cast_shadows_setting() const;
  116. void set_generate_lightmap(bool p_enabled);
  117. bool get_generate_lightmap();
  118. void set_lightmap_scale(LightmapScale p_scale);
  119. LightmapScale get_lightmap_scale() const;
  120. void set_lod_min_distance(float p_dist);
  121. float get_lod_min_distance() const;
  122. void set_lod_max_distance(float p_dist);
  123. float get_lod_max_distance() const;
  124. void set_lod_min_hysteresis(float p_dist);
  125. float get_lod_min_hysteresis() const;
  126. void set_lod_max_hysteresis(float p_dist);
  127. float get_lod_max_hysteresis() const;
  128. virtual void set_material_override(const Ref<Material> &p_material);
  129. Ref<Material> get_material_override() const;
  130. virtual void set_material_overlay(const Ref<Material> &p_material);
  131. Ref<Material> get_material_overlay() const;
  132. void set_extra_cull_margin(float p_margin);
  133. float get_extra_cull_margin() const;
  134. void set_custom_aabb(AABB aabb);
  135. GeometryInstance();
  136. };
  137. VARIANT_ENUM_CAST(GeometryInstance::Flags);
  138. VARIANT_ENUM_CAST(GeometryInstance::LightmapScale);
  139. VARIANT_ENUM_CAST(GeometryInstance::ShadowCastingSetting);
  140. #endif // VISUAL_INSTANCE_H