visual_instance.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*************************************************************************/
  2. /* visual_instance.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 "core/math/face3.h"
  33. #include "core/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. GDCLASS(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 _update_visibility();
  47. void _notification(int p_what);
  48. static void _bind_methods();
  49. public:
  50. enum GetFacesFlags {
  51. FACES_SOLID = 1, // solid geometry
  52. FACES_ENCLOSING = 2,
  53. FACES_DYNAMIC = 4 // dynamic object geometry
  54. };
  55. RID get_instance() const;
  56. virtual AABB get_aabb() const = 0;
  57. virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const = 0;
  58. virtual AABB get_transformed_aabb() const; // helper
  59. void set_base(const RID &p_base);
  60. void set_layer_mask(uint32_t p_mask);
  61. uint32_t get_layer_mask() const;
  62. void set_layer_mask_bit(int p_layer, bool p_enable);
  63. bool get_layer_mask_bit(int p_layer) const;
  64. VisualInstance();
  65. ~VisualInstance();
  66. };
  67. class GeometryInstance : public VisualInstance {
  68. GDCLASS(GeometryInstance, VisualInstance);
  69. public:
  70. enum Flags {
  71. FLAG_USE_BAKED_LIGHT = VS::INSTANCE_FLAG_USE_BAKED_LIGHT,
  72. FLAG_MAX = VS::INSTANCE_FLAG_MAX,
  73. };
  74. enum ShadowCastingSetting {
  75. SHADOW_CASTING_SETTING_OFF = VS::SHADOW_CASTING_SETTING_OFF,
  76. SHADOW_CASTING_SETTING_ON = VS::SHADOW_CASTING_SETTING_ON,
  77. SHADOW_CASTING_SETTING_DOUBLE_SIDED = VS::SHADOW_CASTING_SETTING_DOUBLE_SIDED,
  78. SHADOW_CASTING_SETTING_SHADOWS_ONLY = VS::SHADOW_CASTING_SETTING_SHADOWS_ONLY
  79. };
  80. private:
  81. bool flags[FLAG_MAX];
  82. ShadowCastingSetting shadow_casting_setting;
  83. Ref<Material> material_override;
  84. float lod_min_distance;
  85. float lod_max_distance;
  86. float lod_min_hysteresis;
  87. float lod_max_hysteresis;
  88. float extra_cull_margin;
  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_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting);
  96. ShadowCastingSetting get_cast_shadows_setting() const;
  97. void set_lod_min_distance(float p_dist);
  98. float get_lod_min_distance() const;
  99. void set_lod_max_distance(float p_dist);
  100. float get_lod_max_distance() const;
  101. void set_lod_min_hysteresis(float p_dist);
  102. float get_lod_min_hysteresis() const;
  103. void set_lod_max_hysteresis(float p_dist);
  104. float get_lod_max_hysteresis() const;
  105. void set_material_override(const Ref<Material> &p_material);
  106. Ref<Material> get_material_override() const;
  107. void set_extra_cull_margin(float p_margin);
  108. float get_extra_cull_margin() const;
  109. GeometryInstance();
  110. };
  111. VARIANT_ENUM_CAST(GeometryInstance::Flags);
  112. VARIANT_ENUM_CAST(GeometryInstance::ShadowCastingSetting);
  113. #endif