0.2.0-dev Download ZIP
178 lines ·9.1 KB Raw
| 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 | |
| 31 | #include "importer_mesh_instance_3d.h" |
| 32 | |
| 33 | #include "core/object/class_db.h" |
| 34 | #include "scene/resources/3d/importer_mesh.h" |
| 35 | |
| 36 | void ImporterMeshInstance3D::set_mesh(const Ref<ImporterMesh> &p_mesh) { |
| 37 | mesh = p_mesh; |
| 38 | } |
| 39 | Ref<ImporterMesh> ImporterMeshInstance3D::get_mesh() const { |
| 40 | return mesh; |
| 41 | } |
| 42 | |
| 43 | void ImporterMeshInstance3D::set_skin(const Ref<Skin> &p_skin) { |
| 44 | skin = p_skin; |
| 45 | } |
| 46 | Ref<Skin> ImporterMeshInstance3D::get_skin() const { |
| 47 | return skin; |
| 48 | } |
| 49 | |
| 50 | void ImporterMeshInstance3D::set_surface_material(int p_idx, const Ref<Material> &p_material) { |
| 51 | ERR_FAIL_COND(p_idx < 0); |
| 52 | if (p_idx >= surface_materials.size()) { |
| 53 | surface_materials.resize(p_idx + 1); |
| 54 | } |
| 55 | |
| 56 | surface_materials.write[p_idx] = p_material; |
| 57 | } |
| 58 | Ref<Material> ImporterMeshInstance3D::get_surface_material(int p_idx) const { |
| 59 | ERR_FAIL_COND_V(p_idx < 0, Ref<Material>()); |
| 60 | if (p_idx >= surface_materials.size()) { |
| 61 | return Ref<Material>(); |
| 62 | } |
| 63 | return surface_materials[p_idx]; |
| 64 | } |
| 65 | |
| 66 | void ImporterMeshInstance3D::set_skeleton_path(const NodePath &p_path) { |
| 67 | skeleton_path = p_path; |
| 68 | } |
| 69 | NodePath ImporterMeshInstance3D::get_skeleton_path() const { |
| 70 | return skeleton_path; |
| 71 | } |
| 72 | |
| 73 | uint32_t ImporterMeshInstance3D::get_layer_mask() const { |
| 74 | return layer_mask; |
| 75 | } |
| 76 | |
| 77 | void ImporterMeshInstance3D::set_layer_mask(const uint32_t p_layer_mask) { |
| 78 | layer_mask = p_layer_mask; |
| 79 | } |
| 80 | |
| 81 | void ImporterMeshInstance3D::set_cast_shadows_setting(GeometryInstance3D::ShadowCastingSetting p_shadow_casting_setting) { |
| 82 | shadow_casting_setting = p_shadow_casting_setting; |
| 83 | } |
| 84 | |
| 85 | GeometryInstance3D::ShadowCastingSetting ImporterMeshInstance3D::get_cast_shadows_setting() const { |
| 86 | return shadow_casting_setting; |
| 87 | } |
| 88 | |
| 89 | void ImporterMeshInstance3D::set_visibility_range_begin(float p_dist) { |
| 90 | visibility_range_begin = p_dist; |
| 91 | update_configuration_warnings(); |
| 92 | } |
| 93 | |
| 94 | float ImporterMeshInstance3D::get_visibility_range_begin() const { |
| 95 | return visibility_range_begin; |
| 96 | } |
| 97 | |
| 98 | void ImporterMeshInstance3D::set_visibility_range_end(float p_dist) { |
| 99 | visibility_range_end = p_dist; |
| 100 | update_configuration_warnings(); |
| 101 | } |
| 102 | |
| 103 | float ImporterMeshInstance3D::get_visibility_range_end() const { |
| 104 | return visibility_range_end; |
| 105 | } |
| 106 | |
| 107 | void ImporterMeshInstance3D::set_visibility_range_begin_margin(float p_dist) { |
| 108 | visibility_range_begin_margin = p_dist; |
| 109 | update_configuration_warnings(); |
| 110 | } |
| 111 | |
| 112 | float ImporterMeshInstance3D::get_visibility_range_begin_margin() const { |
| 113 | return visibility_range_begin_margin; |
| 114 | } |
| 115 | |
| 116 | void ImporterMeshInstance3D::set_visibility_range_end_margin(float p_dist) { |
| 117 | visibility_range_end_margin = p_dist; |
| 118 | update_configuration_warnings(); |
| 119 | } |
| 120 | |
| 121 | float ImporterMeshInstance3D::get_visibility_range_end_margin() const { |
| 122 | return visibility_range_end_margin; |
| 123 | } |
| 124 | |
| 125 | void ImporterMeshInstance3D::set_visibility_range_fade_mode(GeometryInstance3D::VisibilityRangeFadeMode p_mode) { |
| 126 | visibility_range_fade_mode = p_mode; |
| 127 | update_configuration_warnings(); |
| 128 | } |
| 129 | |
| 130 | GeometryInstance3D::VisibilityRangeFadeMode ImporterMeshInstance3D::get_visibility_range_fade_mode() const { |
| 131 | return visibility_range_fade_mode; |
| 132 | } |
| 133 | |
| 134 | void ImporterMeshInstance3D::_bind_methods() { |
| 135 | ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &ImporterMeshInstance3D::set_mesh); |
| 136 | ClassDB::bind_method(D_METHOD("get_mesh"), &ImporterMeshInstance3D::get_mesh); |
| 137 | |
| 138 | ClassDB::bind_method(D_METHOD("set_skin", "skin"), &ImporterMeshInstance3D::set_skin); |
| 139 | ClassDB::bind_method(D_METHOD("get_skin"), &ImporterMeshInstance3D::get_skin); |
| 140 | |
| 141 | ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path"), &ImporterMeshInstance3D::set_skeleton_path); |
| 142 | ClassDB::bind_method(D_METHOD("get_skeleton_path"), &ImporterMeshInstance3D::get_skeleton_path); |
| 143 | |
| 144 | ClassDB::bind_method(D_METHOD("set_layer_mask", "layer_mask"), &ImporterMeshInstance3D::set_layer_mask); |
| 145 | ClassDB::bind_method(D_METHOD("get_layer_mask"), &ImporterMeshInstance3D::get_layer_mask); |
| 146 | |
| 147 | ClassDB::bind_method(D_METHOD("set_cast_shadows_setting", "shadow_casting_setting"), &ImporterMeshInstance3D::set_cast_shadows_setting); |
| 148 | ClassDB::bind_method(D_METHOD("get_cast_shadows_setting"), &ImporterMeshInstance3D::get_cast_shadows_setting); |
| 149 | |
| 150 | ClassDB::bind_method(D_METHOD("set_visibility_range_end_margin", "distance"), &ImporterMeshInstance3D::set_visibility_range_end_margin); |
| 151 | ClassDB::bind_method(D_METHOD("get_visibility_range_end_margin"), &ImporterMeshInstance3D::get_visibility_range_end_margin); |
| 152 | |
| 153 | ClassDB::bind_method(D_METHOD("set_visibility_range_end", "distance"), &ImporterMeshInstance3D::set_visibility_range_end); |
| 154 | ClassDB::bind_method(D_METHOD("get_visibility_range_end"), &ImporterMeshInstance3D::get_visibility_range_end); |
| 155 | |
| 156 | ClassDB::bind_method(D_METHOD("set_visibility_range_begin_margin", "distance"), &ImporterMeshInstance3D::set_visibility_range_begin_margin); |
| 157 | ClassDB::bind_method(D_METHOD("get_visibility_range_begin_margin"), &ImporterMeshInstance3D::get_visibility_range_begin_margin); |
| 158 | |
| 159 | ClassDB::bind_method(D_METHOD("set_visibility_range_begin", "distance"), &ImporterMeshInstance3D::set_visibility_range_begin); |
| 160 | ClassDB::bind_method(D_METHOD("get_visibility_range_begin"), &ImporterMeshInstance3D::get_visibility_range_begin); |
| 161 | |
| 162 | ClassDB::bind_method(D_METHOD("set_visibility_range_fade_mode", "mode"), &ImporterMeshInstance3D::set_visibility_range_fade_mode); |
| 163 | ClassDB::bind_method(D_METHOD("get_visibility_range_fade_mode"), &ImporterMeshInstance3D::get_visibility_range_fade_mode); |
| 164 | |
| 165 | ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, ImporterMesh::get_class_static()), "set_mesh", "get_mesh"); |
| 166 | ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skin", PROPERTY_HINT_RESOURCE_TYPE, Skin::get_class_static()), "set_skin", "get_skin"); |
| 167 | ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton"), "set_skeleton_path", "get_skeleton_path"); |
| 168 | ADD_PROPERTY(PropertyInfo(Variant::INT, "layer_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_layer_mask", "get_layer_mask"); |
| 169 | |
| 170 | ADD_PROPERTY(PropertyInfo(Variant::INT, "cast_shadow", PROPERTY_HINT_ENUM, "Off,On,Double-Sided,Shadows Only"), "set_cast_shadows_setting", "get_cast_shadows_setting"); |
| 171 | |
| 172 | ADD_GROUP("Visibility Range", "visibility_range_"); |
| 173 | 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"); |
| 174 | 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"); |
| 175 | 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"); |
| 176 | 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"); |
| 177 | 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"); |
| 178 | } |