importer_mesh_instance_3d.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**************************************************************************/
  2. /* importer_mesh_instance_3d.cpp */
  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. #include "importer_mesh_instance_3d.h"
  31. #include "scene/resources/importer_mesh.h"
  32. void ImporterMeshInstance3D::set_mesh(const Ref<ImporterMesh> &p_mesh) {
  33. mesh = p_mesh;
  34. }
  35. Ref<ImporterMesh> ImporterMeshInstance3D::get_mesh() const {
  36. return mesh;
  37. }
  38. void ImporterMeshInstance3D::set_skin(const Ref<Skin> &p_skin) {
  39. skin = p_skin;
  40. }
  41. Ref<Skin> ImporterMeshInstance3D::get_skin() const {
  42. return skin;
  43. }
  44. void ImporterMeshInstance3D::set_surface_material(int p_idx, const Ref<Material> &p_material) {
  45. ERR_FAIL_COND(p_idx < 0);
  46. if (p_idx >= surface_materials.size()) {
  47. surface_materials.resize(p_idx + 1);
  48. }
  49. surface_materials.write[p_idx] = p_material;
  50. }
  51. Ref<Material> ImporterMeshInstance3D::get_surface_material(int p_idx) const {
  52. ERR_FAIL_COND_V(p_idx < 0, Ref<Material>());
  53. if (p_idx >= surface_materials.size()) {
  54. return Ref<Material>();
  55. }
  56. return surface_materials[p_idx];
  57. }
  58. void ImporterMeshInstance3D::set_skeleton_path(const NodePath &p_path) {
  59. skeleton_path = p_path;
  60. }
  61. NodePath ImporterMeshInstance3D::get_skeleton_path() const {
  62. return skeleton_path;
  63. }
  64. uint32_t ImporterMeshInstance3D::get_layer_mask() const {
  65. return layer_mask;
  66. }
  67. void ImporterMeshInstance3D::set_layer_mask(const uint32_t p_layer_mask) {
  68. layer_mask = p_layer_mask;
  69. }
  70. void ImporterMeshInstance3D::set_cast_shadows_setting(GeometryInstance3D::ShadowCastingSetting p_shadow_casting_setting) {
  71. shadow_casting_setting = p_shadow_casting_setting;
  72. }
  73. GeometryInstance3D::ShadowCastingSetting ImporterMeshInstance3D::get_cast_shadows_setting() const {
  74. return shadow_casting_setting;
  75. }
  76. void ImporterMeshInstance3D::set_visibility_range_begin(float p_dist) {
  77. visibility_range_begin = p_dist;
  78. update_configuration_warnings();
  79. }
  80. float ImporterMeshInstance3D::get_visibility_range_begin() const {
  81. return visibility_range_begin;
  82. }
  83. void ImporterMeshInstance3D::set_visibility_range_end(float p_dist) {
  84. visibility_range_end = p_dist;
  85. update_configuration_warnings();
  86. }
  87. float ImporterMeshInstance3D::get_visibility_range_end() const {
  88. return visibility_range_end;
  89. }
  90. void ImporterMeshInstance3D::set_visibility_range_begin_margin(float p_dist) {
  91. visibility_range_begin_margin = p_dist;
  92. update_configuration_warnings();
  93. }
  94. float ImporterMeshInstance3D::get_visibility_range_begin_margin() const {
  95. return visibility_range_begin_margin;
  96. }
  97. void ImporterMeshInstance3D::set_visibility_range_end_margin(float p_dist) {
  98. visibility_range_end_margin = p_dist;
  99. update_configuration_warnings();
  100. }
  101. float ImporterMeshInstance3D::get_visibility_range_end_margin() const {
  102. return visibility_range_end_margin;
  103. }
  104. void ImporterMeshInstance3D::set_visibility_range_fade_mode(GeometryInstance3D::VisibilityRangeFadeMode p_mode) {
  105. visibility_range_fade_mode = p_mode;
  106. update_configuration_warnings();
  107. }
  108. GeometryInstance3D::VisibilityRangeFadeMode ImporterMeshInstance3D::get_visibility_range_fade_mode() const {
  109. return visibility_range_fade_mode;
  110. }
  111. void ImporterMeshInstance3D::_bind_methods() {
  112. ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &ImporterMeshInstance3D::set_mesh);
  113. ClassDB::bind_method(D_METHOD("get_mesh"), &ImporterMeshInstance3D::get_mesh);
  114. ClassDB::bind_method(D_METHOD("set_skin", "skin"), &ImporterMeshInstance3D::set_skin);
  115. ClassDB::bind_method(D_METHOD("get_skin"), &ImporterMeshInstance3D::get_skin);
  116. ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path"), &ImporterMeshInstance3D::set_skeleton_path);
  117. ClassDB::bind_method(D_METHOD("get_skeleton_path"), &ImporterMeshInstance3D::get_skeleton_path);
  118. ClassDB::bind_method(D_METHOD("set_layer_mask", "layer_mask"), &ImporterMeshInstance3D::set_layer_mask);
  119. ClassDB::bind_method(D_METHOD("get_layer_mask"), &ImporterMeshInstance3D::get_layer_mask);
  120. ClassDB::bind_method(D_METHOD("set_cast_shadows_setting", "shadow_casting_setting"), &ImporterMeshInstance3D::set_cast_shadows_setting);
  121. ClassDB::bind_method(D_METHOD("get_cast_shadows_setting"), &ImporterMeshInstance3D::get_cast_shadows_setting);
  122. ClassDB::bind_method(D_METHOD("set_visibility_range_end_margin", "distance"), &ImporterMeshInstance3D::set_visibility_range_end_margin);
  123. ClassDB::bind_method(D_METHOD("get_visibility_range_end_margin"), &ImporterMeshInstance3D::get_visibility_range_end_margin);
  124. ClassDB::bind_method(D_METHOD("set_visibility_range_end", "distance"), &ImporterMeshInstance3D::set_visibility_range_end);
  125. ClassDB::bind_method(D_METHOD("get_visibility_range_end"), &ImporterMeshInstance3D::get_visibility_range_end);
  126. ClassDB::bind_method(D_METHOD("set_visibility_range_begin_margin", "distance"), &ImporterMeshInstance3D::set_visibility_range_begin_margin);
  127. ClassDB::bind_method(D_METHOD("get_visibility_range_begin_margin"), &ImporterMeshInstance3D::get_visibility_range_begin_margin);
  128. ClassDB::bind_method(D_METHOD("set_visibility_range_begin", "distance"), &ImporterMeshInstance3D::set_visibility_range_begin);
  129. ClassDB::bind_method(D_METHOD("get_visibility_range_begin"), &ImporterMeshInstance3D::get_visibility_range_begin);
  130. ClassDB::bind_method(D_METHOD("set_visibility_range_fade_mode", "mode"), &ImporterMeshInstance3D::set_visibility_range_fade_mode);
  131. ClassDB::bind_method(D_METHOD("get_visibility_range_fade_mode"), &ImporterMeshInstance3D::get_visibility_range_fade_mode);
  132. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "ImporterMesh"), "set_mesh", "get_mesh");
  133. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skin", PROPERTY_HINT_RESOURCE_TYPE, "Skin"), "set_skin", "get_skin");
  134. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton"), "set_skeleton_path", "get_skeleton_path");
  135. ADD_PROPERTY(PropertyInfo(Variant::INT, "layer_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_layer_mask", "get_layer_mask");
  136. ADD_PROPERTY(PropertyInfo(Variant::INT, "cast_shadow", PROPERTY_HINT_ENUM, "Off,On,Double-Sided,Shadows Only"), "set_cast_shadows_setting", "get_cast_shadows_setting");
  137. ADD_GROUP("Visibility Range", "visibility_range_");
  138. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "visibility_range_begin", PROPERTY_HINT_RANGE, "0.0,4096.0,0.01,or_greater,suffix:m"), "set_visibility_range_begin", "get_visibility_range_begin");
  139. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "visibility_range_begin_margin", PROPERTY_HINT_RANGE, "0.0,4096.0,0.01,or_greater,suffix:m"), "set_visibility_range_begin_margin", "get_visibility_range_begin_margin");
  140. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "visibility_range_end", PROPERTY_HINT_RANGE, "0.0,4096.0,0.01,or_greater,suffix:m"), "set_visibility_range_end", "get_visibility_range_end");
  141. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "visibility_range_end_margin", PROPERTY_HINT_RANGE, "0.0,4096.0,0.01,or_greater,suffix:m"), "set_visibility_range_end_margin", "get_visibility_range_end_margin");
  142. ADD_PROPERTY(PropertyInfo(Variant::INT, "visibility_range_fade_mode", PROPERTY_HINT_ENUM, "Disabled,Self,Dependencies"), "set_visibility_range_fade_mode", "get_visibility_range_fade_mode");
  143. }