From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- editor/import/collada.cpp | 281 --------------------- editor/import/collada.h | 39 --- editor/import/editor_import_collada.cpp | 162 ------------ editor/import/editor_import_collada.h | 1 - editor/import/editor_import_plugin.cpp | 3 - editor/import/editor_scene_importer_gltf.cpp | 95 ------- editor/import/editor_scene_importer_gltf.h | 7 - editor/import/resource_importer_bitmask.cpp | 9 - editor/import/resource_importer_csv.cpp | 6 - .../import/resource_importer_csv_translation.cpp | 11 - editor/import/resource_importer_image.cpp | 7 - .../import/resource_importer_layered_texture.cpp | 18 -- editor/import/resource_importer_obj.cpp | 19 -- editor/import/resource_importer_obj.h | 1 - editor/import/resource_importer_scene.cpp | 113 --------- editor/import/resource_importer_scene.h | 2 - editor/import/resource_importer_shader_file.cpp | 6 - editor/import/resource_importer_texture.cpp | 30 --- editor/import/resource_importer_texture.h | 1 - editor/import/resource_importer_texture_atlas.cpp | 18 -- editor/import/resource_importer_wav.cpp | 28 -- editor/import/resource_importer_wav.h | 3 - 22 files changed, 860 deletions(-) (limited to 'editor/import') diff --git a/editor/import/collada.cpp b/editor/import/collada.cpp index 9e49fa9066..e82e1bb098 100644 --- a/editor/import/collada.cpp +++ b/editor/import/collada.cpp @@ -45,14 +45,12 @@ /* HELPERS */ String Collada::Effect::get_texture_path(const String &p_source, Collada &state) const { - const String &image = p_source; ERR_FAIL_COND_V(!state.state.image_map.has(image), ""); return state.state.image_map[image].path; } Transform Collada::get_root_transform() const { - Transform unit_scale_transform; #ifndef COLLADA_IMPORT_SCALE_SCENE unit_scale_transform.scale(Vector3(state.unit_scale, state.unit_scale, state.unit_scale)); @@ -67,7 +65,6 @@ void Collada::Vertex::fix_unit_scale(Collada &state) { } static String _uri_to_id(const String &p_uri) { - if (p_uri.begins_with("#")) return p_uri.substr(1, p_uri.size() - 1); else @@ -77,13 +74,11 @@ static String _uri_to_id(const String &p_uri) { /** HELPER FUNCTIONS **/ Transform Collada::fix_transform(const Transform &p_transform) { - Transform tr = p_transform; #ifndef NO_UP_AXIS_SWAP if (state.up_axis != Vector3::AXIS_Y) { - for (int i = 0; i < 3; i++) SWAP(tr.basis[1][i], tr.basis[state.up_axis][i]); for (int i = 0; i < 3; i++) @@ -105,7 +100,6 @@ Transform Collada::fix_transform(const Transform &p_transform) { } static Transform _read_transform_from_array(const Vector &array, int ofs = 0) { - Transform tr; // i wonder why collada matrices are transposed, given that's opposed to opengl.. tr.basis.elements[0][0] = array[0 + ofs]; @@ -126,39 +120,30 @@ static Transform _read_transform_from_array(const Vector &array, int ofs /* STRUCTURES */ Transform Collada::Node::compute_transform(Collada &state) const { - Transform xform; for (int i = 0; i < xform_list.size(); i++) { - Transform xform_step; const XForm &xf = xform_list[i]; switch (xf.op) { - case XForm::OP_ROTATE: { if (xf.data.size() >= 4) { - xform_step.rotate(Vector3(xf.data[0], xf.data[1], xf.data[2]), Math::deg2rad(xf.data[3])); } } break; case XForm::OP_SCALE: { - if (xf.data.size() >= 3) { - xform_step.scale(Vector3(xf.data[0], xf.data[1], xf.data[2])); } } break; case XForm::OP_TRANSLATE: { - if (xf.data.size() >= 3) { - xform_step.origin = Vector3(xf.data[0], xf.data[1], xf.data[2]); } } break; case XForm::OP_MATRIX: { - if (xf.data.size() >= 16) { xform_step = _read_transform_from_array(xf.data, 0); } @@ -178,12 +163,10 @@ Transform Collada::Node::compute_transform(Collada &state) const { } Transform Collada::Node::get_transform() const { - return default_transform; } Transform Collada::Node::get_global_transform() const { - if (parent) return parent->get_global_transform() * default_transform; else @@ -191,12 +174,10 @@ Transform Collada::Node::get_global_transform() const { } Vector Collada::AnimationTrack::get_value_at_time(float p_time) const { - ERR_FAIL_COND_V(keys.size() == 0, Vector()); int i = 0; for (i = 0; i < keys.size(); i++) { - if (keys[i].time > p_time) break; } @@ -207,10 +188,8 @@ Vector Collada::AnimationTrack::get_value_at_time(float p_time) const { return keys[keys.size() - 1].data; switch (keys[i].interp_type) { - case INTERP_BEZIER: //wait for bezier case INTERP_LINEAR: { - float c = (p_time - keys[i - 1].time) / (keys[i].time - keys[i - 1].time); if (keys[i].data.size() == 16) { @@ -243,11 +222,9 @@ Vector Collada::AnimationTrack::get_value_at_time(float p_time) const { return ret; } else { - Vector dest; dest.resize(keys[i].data.size()); for (int j = 0; j < dest.size(); j++) { - dest.write[j] = keys[i].data[j] * c + keys[i - 1].data[j] * (1.0 - c); } return dest; @@ -260,15 +237,11 @@ Vector Collada::AnimationTrack::get_value_at_time(float p_time) const { } void Collada::_parse_asset(XMLParser &parser) { - while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String name = parser.get_node_name(); if (name == "up_axis") { - parser.read(); if (parser.get_node_data() == "X_UP") state.up_axis = Vector3::AXIS_X; @@ -279,7 +252,6 @@ void Collada::_parse_asset(XMLParser &parser) { COLLADA_PRINT("up axis: " + parser.get_node_data()); } else if (name == "unit") { - state.unit_scale = parser.get_attribute_value("meter").to_double(); COLLADA_PRINT("unit scale: " + rtos(state.unit_scale)); } @@ -290,7 +262,6 @@ void Collada::_parse_asset(XMLParser &parser) { } void Collada::_parse_image(XMLParser &parser) { - String id = parser.get_attribute_value("id"); if (!(state.import_flags & IMPORT_FLAG_SCENE)) { @@ -309,15 +280,11 @@ void Collada::_parse_image(XMLParser &parser) { image.path = ProjectSettings::get_singleton()->localize_path(state.local_path.get_base_dir().plus_file(path.percent_decode())); } } else { - while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String name = parser.get_node_name(); if (name == "init_from") { - parser.read(); String path = parser.get_node_data().strip_edges().percent_decode(); @@ -333,7 +300,6 @@ void Collada::_parse_image(XMLParser &parser) { image.path = path; } else if (name == "data") { - ERR_PRINT("COLLADA Embedded image data not supported!"); } else if (name == "extra" && !parser.is_empty()) @@ -348,7 +314,6 @@ void Collada::_parse_image(XMLParser &parser) { } void Collada::_parse_material(XMLParser &parser) { - if (!(state.import_flags & IMPORT_FLAG_SCENE)) { if (!parser.is_empty()) parser.skip_section(); @@ -365,11 +330,8 @@ void Collada::_parse_material(XMLParser &parser) { /* <1.4 */ ERR_PRINT("Collada Materials < 1.4 are not supported (yet)"); } else { - while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT && parser.get_node_name() == "instance_effect") { - material.instance_effect = _uri_to_id(parser.get_attribute_value("url")); } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "material") break; //end of @@ -381,7 +343,6 @@ void Collada::_parse_material(XMLParser &parser) { //! reads floats from inside of xml element until end of xml element Vector Collada::_read_float_array(XMLParser &parser) { - if (parser.is_empty()) return Vector(); @@ -409,7 +370,6 @@ Vector Collada::_read_float_array(XMLParser &parser) { } Vector Collada::_read_string_array(XMLParser &parser) { - if (parser.is_empty()) return Vector(); @@ -430,7 +390,6 @@ Vector Collada::_read_string_array(XMLParser &parser) { } Transform Collada::_read_transform(XMLParser &parser) { - if (parser.is_empty()) return Transform(); @@ -458,7 +417,6 @@ Transform Collada::_read_transform(XMLParser &parser) { } String Collada::_read_empty_draw_type(XMLParser &parser) { - String empty_draw_type = ""; if (parser.is_empty()) @@ -474,7 +432,6 @@ String Collada::_read_empty_draw_type(XMLParser &parser) { } Variant Collada::_parse_param(XMLParser &parser) { - if (parser.is_empty()) return Variant(); @@ -483,50 +440,36 @@ Variant Collada::_parse_param(XMLParser &parser) { while (parser.read() == OK) { if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "float") { - parser.read(); if (parser.get_node_type() == XMLParser::NODE_TEXT) { - data = parser.get_node_data().to_double(); } } else if (parser.get_node_name() == "float2") { - Vector v2 = _read_float_array(parser); if (v2.size() >= 2) { - data = Vector2(v2[0], v2[1]); } } else if (parser.get_node_name() == "float3") { - Vector v3 = _read_float_array(parser); if (v3.size() >= 3) { - data = Vector3(v3[0], v3[1], v3[2]); } } else if (parser.get_node_name() == "float4") { - Vector v4 = _read_float_array(parser); if (v4.size() >= 4) { - data = Color(v4[0], v4[1], v4[2], v4[3]); } } else if (parser.get_node_name() == "sampler2D") { - while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "source") { - parser.read(); if (parser.get_node_type() == XMLParser::NODE_TEXT) { - data = parser.get_node_data(); } } @@ -534,17 +477,12 @@ Variant Collada::_parse_param(XMLParser &parser) { break; } } else if (parser.get_node_name() == "surface") { - while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "init_from") { - parser.read(); if (parser.get_node_type() == XMLParser::NODE_TEXT) { - data = parser.get_node_data(); } } @@ -562,7 +500,6 @@ Variant Collada::_parse_param(XMLParser &parser) { } void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String &id) { - if (!(state.import_flags & IMPORT_FLAG_SCENE)) { if (!parser.is_empty()) parser.skip_section(); @@ -570,15 +507,12 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String & } while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - // first come the tags we descend, but ignore the top-levels COLLADA_PRINT("node name: " + parser.get_node_name()); if (!parser.is_empty() && (parser.get_node_name() == "profile_COMMON" || parser.get_node_name() == "technique" || parser.get_node_name() == "extra")) { - _parse_effect_material(parser, effect, id); // try again } else if (parser.get_node_name() == "newparam") { @@ -591,31 +525,23 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String & parser.get_node_name() == "lambert" || parser.get_node_name() == "phong" || parser.get_node_name() == "blinn") { - COLLADA_PRINT("shade model: " + parser.get_node_name()); while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String what = parser.get_node_name(); if (what == "emission" || what == "diffuse" || what == "specular" || what == "reflective") { - // color or texture types while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "color") { - Vector colorarr = _read_float_array(parser); COLLADA_PRINT("colorarr size: " + rtos(colorarr.size())); if (colorarr.size() >= 3) { - // alpha strangely not alright? maybe it needs to be multiplied by value as a channel intensity Color color(colorarr[0], colorarr[1], colorarr[2], 1.0); if (what == "diffuse") @@ -629,7 +555,6 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String & } } else if (parser.get_node_name() == "texture") { - String sampler = parser.get_attribute_value("texture"); if (!effect.params.has(sampler)) { ERR_PRINT(String("Couldn't find sampler: " + sampler + " in material:" + id).utf8().get_data()); @@ -685,14 +610,10 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String & parser.read(); effect.unshaded = parser.get_node_data().to_int(); } else if (parser.get_node_name() == "bump") { - // color or texture types while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "texture") { - String sampler = parser.get_attribute_value("texture"); if (!effect.params.has(sampler)) { ERR_PRINT(String("Couldn't find sampler: " + sampler + " in material:" + id).utf8().get_data()); @@ -731,7 +652,6 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String & } void Collada::_parse_effect(XMLParser &parser) { - if (!(state.import_flags & IMPORT_FLAG_SCENE)) { if (!parser.is_empty()) parser.skip_section(); @@ -751,7 +671,6 @@ void Collada::_parse_effect(XMLParser &parser) { } void Collada::_parse_camera(XMLParser &parser) { - if (!(state.import_flags & IMPORT_FLAG_SCENE)) { if (!parser.is_empty()) parser.skip_section(); @@ -764,47 +683,36 @@ void Collada::_parse_camera(XMLParser &parser) { CameraData &camera = state.camera_data_map[id]; while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String name = parser.get_node_name(); if (name == "perspective") { - camera.mode = CameraData::MODE_PERSPECTIVE; } else if (name == "orthographic") { - camera.mode = CameraData::MODE_ORTHOGONAL; } else if (name == "xfov") { - parser.read(); camera.perspective.x_fov = parser.get_node_data().to_double(); } else if (name == "yfov") { - parser.read(); camera.perspective.y_fov = parser.get_node_data().to_double(); } else if (name == "xmag") { - parser.read(); camera.orthogonal.x_mag = parser.get_node_data().to_double(); } else if (name == "ymag") { - parser.read(); camera.orthogonal.y_mag = parser.get_node_data().to_double(); } else if (name == "aspect_ratio") { - parser.read(); camera.aspect = parser.get_node_data().to_double(); } else if (name == "znear") { - parser.read(); camera.z_near = parser.get_node_data().to_double(); } else if (name == "zfar") { - parser.read(); camera.z_far = parser.get_node_data().to_double(); } @@ -817,7 +725,6 @@ void Collada::_parse_camera(XMLParser &parser) { } void Collada::_parse_light(XMLParser &parser) { - if (!(state.import_flags & IMPORT_FLAG_SCENE)) { if (!parser.is_empty()) parser.skip_section(); @@ -830,25 +737,18 @@ void Collada::_parse_light(XMLParser &parser) { LightData &light = state.light_data_map[id]; while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String name = parser.get_node_name(); if (name == "ambient") { - light.mode = LightData::MODE_AMBIENT; } else if (name == "directional") { - light.mode = LightData::MODE_DIRECTIONAL; } else if (name == "point") { - light.mode = LightData::MODE_OMNI; } else if (name == "spot") { - light.mode = LightData::MODE_SPOT; } else if (name == "color") { - parser.read(); Vector colorarr = _read_float_array(parser); COLLADA_PRINT("colorarr size: " + rtos(colorarr.size())); @@ -860,24 +760,19 @@ void Collada::_parse_light(XMLParser &parser) { } } else if (name == "constant_attenuation") { - parser.read(); light.constant_att = parser.get_node_data().to_double(); } else if (name == "linear_attenuation") { - parser.read(); light.linear_att = parser.get_node_data().to_double(); } else if (name == "quadratic_attenuation") { - parser.read(); light.quad_att = parser.get_node_data().to_double(); } else if (name == "falloff_angle") { - parser.read(); light.spot_angle = parser.get_node_data().to_double(); } else if (name == "falloff_exponent") { - parser.read(); light.spot_exp = parser.get_node_data().to_double(); } @@ -890,7 +785,6 @@ void Collada::_parse_light(XMLParser &parser) { } void Collada::_parse_curve_geometry(XMLParser &parser, String p_id, String p_name) { - if (!(state.import_flags & IMPORT_FLAG_SCENE)) { if (!parser.is_empty()) parser.skip_section(); @@ -914,13 +808,10 @@ void Collada::_parse_curve_geometry(XMLParser &parser, String p_id, String p_nam } while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String section = parser.get_node_name(); if (section == "source") { - String id = parser.get_attribute_value("id"); curvedata.sources[id] = CurveData::Source(); current_source = id; @@ -929,14 +820,12 @@ void Collada::_parse_curve_geometry(XMLParser &parser, String p_id, String p_nam } else if (section == "float_array" || section == "array") { // create a new array and read it. if (curvedata.sources.has(current_source)) { - curvedata.sources[current_source].array = _read_float_array(parser); COLLADA_PRINT("section: " + current_source + " read " + itos(curvedata.sources[current_source].array.size()) + " values."); } } else if (section == "Name_array") { // create a new array and read it. if (curvedata.sources.has(current_source)) { - curvedata.sources[current_source].sarray = _read_string_array(parser); COLLADA_PRINT("section: " + current_source + " read " + itos(curvedata.sources[current_source].array.size()) + " values."); } @@ -950,13 +839,9 @@ void Collada::_parse_curve_geometry(XMLParser &parser, String p_id, String p_nam COLLADA_PRINT("section: " + current_source + " stride " + itos(curvedata.sources[current_source].stride)); } } else if (section == "control_vertices") { - while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "input") { - String semantic = parser.get_attribute_value("semantic"); String source = _uri_to_id(parser.get_attribute_value("source")); @@ -969,7 +854,6 @@ void Collada::_parse_curve_geometry(XMLParser &parser, String p_id, String p_nam } } else if (!parser.is_empty()) { - parser.skip_section(); } } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "spline") @@ -978,7 +862,6 @@ void Collada::_parse_curve_geometry(XMLParser &parser, String p_id, String p_nam } void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name) { - if (!(state.import_flags & IMPORT_FLAG_SCENE)) { if (!parser.is_empty()) parser.skip_section(); @@ -1002,13 +885,10 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name } while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String section = parser.get_node_name(); if (section == "source") { - String id = parser.get_attribute_value("id"); meshdata.sources[id] = MeshData::Source(); current_source = id; @@ -1017,7 +897,6 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name } else if (section == "float_array" || section == "array") { // create a new array and read it. if (meshdata.sources.has(current_source)) { - meshdata.sources[current_source].array = _read_float_array(parser); COLLADA_PRINT("section: " + current_source + " read " + itos(meshdata.sources[current_source].array.size()) + " values."); } @@ -1030,16 +909,12 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name COLLADA_PRINT("section: " + current_source + " stride " + itos(meshdata.sources[current_source].stride)); } } else if (section == "vertices") { - MeshData::Vertices vert; String id = parser.get_attribute_value("id"); while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "input") { - String semantic = parser.get_attribute_value("semantic"); String source = _uri_to_id(parser.get_attribute_value("source")); @@ -1054,7 +929,6 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name meshdata.vertices[id] = vert; } else if (section == "triangles" || section == "polylist" || section == "polygons") { - bool polygons = (section == "polygons"); if (polygons) { WARN_PRINT("Primitive type \"polygons\" is not well supported (concave shapes may fail). To ensure that the geometry is properly imported, please re-export using \"triangles\" or \"polylist\"."); @@ -1068,11 +942,8 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name int last_ref = 0; while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "input") { - String semantic = parser.get_attribute_value("semantic"); String source = _uri_to_id(parser.get_attribute_value("source")); @@ -1098,7 +969,6 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name Vector values = _read_float_array(parser); if (polygons) { - ERR_CONTINUE(prim.vertex_size == 0); prim.polygons.push_back(values.size() / prim.vertex_size); int from = prim.indices.size(); @@ -1125,7 +995,6 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name meshdata.primitives.push_back(prim); } else if (parser.get_node_name() == "double_sided") { - parser.read(); meshdata.found_double_sided = true; meshdata.double_sided = parser.get_node_data().to_int(); @@ -1133,7 +1002,6 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name } else if (parser.get_node_name() == "polygons") { ERR_PRINT("Primitive type \"polygons\" not supported, re-export using \"polylist\" or \"triangles\"."); } else if (!parser.is_empty()) { - parser.skip_section(); } } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "mesh") @@ -1142,7 +1010,6 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name } void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { - state.skin_controller_data_map[p_id] = SkinControllerData(); SkinControllerData &skindata = state.skin_controller_data_map[p_id]; @@ -1151,13 +1018,10 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { String current_source; while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String section = parser.get_node_name(); if (section == "bind_shape_matrix") { - skindata.bind_shape = _read_transform(parser); #ifdef COLLADA_IMPORT_SCALE_SCENE skindata.bind_shape.origin *= state.unit_scale; @@ -1166,7 +1030,6 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { COLLADA_PRINT("skeleton bind shape transform: " + skindata.bind_shape); } else if (section == "source") { - String id = parser.get_attribute_value("id"); skindata.sources[id] = SkinControllerData::Source(); current_source = id; @@ -1175,7 +1038,6 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { } else if (section == "float_array" || section == "array") { // create a new array and read it. if (skindata.sources.has(current_source)) { - skindata.sources[current_source].array = _read_float_array(parser); COLLADA_PRINT("section: " + current_source + " read " + itos(skindata.sources[current_source].array.size()) + " values."); } @@ -1185,7 +1047,6 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { if (section == "IDREF_array") skindata.use_idrefs = true; if (skindata.sources.has(current_source)) { - skindata.sources[current_source].sarray = _read_string_array(parser); if (section == "IDREF_array") { Vector sa = skindata.sources[current_source].sarray; @@ -1199,7 +1060,6 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { } else if (section == "accessor") { // child of source (below a technique tag) if (skindata.sources.has(current_source)) { - int stride = 1; if (parser.has_attribute("stride")) stride = parser.get_attribute_value("stride").to_int(); @@ -1209,15 +1069,11 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { } } else if (section == "joints") { - SkinControllerData::Joints joint; while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "input") { - String semantic = parser.get_attribute_value("semantic"); String source = _uri_to_id(parser.get_attribute_value("source")); @@ -1232,17 +1088,13 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { skindata.joints = joint; } else if (section == "vertex_weights") { - SkinControllerData::Weights weights; weights.count = parser.get_attribute_value("count").to_int(); while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "input") { - String semantic = parser.get_attribute_value("semantic"); String source = _uri_to_id(parser.get_attribute_value("source")); @@ -1300,7 +1152,6 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { ERR_FAIL_COND(joint_source.sarray.size() != ibm_source.array.size() / 16); for (int i = 0; i < joint_source.sarray.size(); i++) { - String name = joint_source.sarray[i]; Transform xform = _read_transform_from_array(ibm_source.array, i * 16); //<- this is a mistake, it must be applied to vertices xform.affine_invert(); // inverse for rest, because it's an inverse @@ -1312,7 +1163,6 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { } void Collada::_parse_morph_controller(XMLParser &parser, String p_id) { - state.morph_controller_data_map[p_id] = MorphControllerData(); MorphControllerData &morphdata = state.morph_controller_data_map[p_id]; @@ -1321,13 +1171,10 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) { String current_source; while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String section = parser.get_node_name(); if (section == "source") { - String id = parser.get_attribute_value("id"); morphdata.sources[id] = MorphControllerData::Source(); current_source = id; @@ -1336,7 +1183,6 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) { } else if (section == "float_array" || section == "array") { // create a new array and read it. if (morphdata.sources.has(current_source)) { - morphdata.sources[current_source].array = _read_float_array(parser); COLLADA_PRINT("section: " + current_source + " read " + itos(morphdata.sources[current_source].array.size()) + " values."); } @@ -1348,7 +1194,6 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) { morphdata.use_idrefs=true; */ if (morphdata.sources.has(current_source)) { - morphdata.sources[current_source].sarray = _read_string_array(parser); /* if (section=="IDREF_array") { @@ -1363,7 +1208,6 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) { } else if (section == "accessor") { // child of source (below a technique tag) if (morphdata.sources.has(current_source)) { - int stride = 1; if (parser.has_attribute("stride")) stride = parser.get_attribute_value("stride").to_int(); @@ -1373,13 +1217,9 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) { } } else if (section == "targets") { - while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "input") { - String semantic = parser.get_attribute_value("semantic"); String source = _uri_to_id(parser.get_attribute_value("source")); @@ -1401,13 +1241,11 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) { } if (morphdata.targets.has("MORPH_WEIGHT")) { - state.morph_name_map[morphdata.targets["MORPH_WEIGHT"]] = p_id; } } void Collada::_parse_controller(XMLParser &parser) { - String id = parser.get_attribute_value("id"); if (parser.is_empty()) { @@ -1415,9 +1253,7 @@ void Collada::_parse_controller(XMLParser &parser) { } while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String section = parser.get_node_name(); if (section == "skin") { @@ -1431,7 +1267,6 @@ void Collada::_parse_controller(XMLParser &parser) { } Collada::Node *Collada::_parse_visual_instance_geometry(XMLParser &parser) { - String type = parser.get_node_name(); NodeGeometry *geom = memnew(NodeGeometry); geom->controller = type == "instance_controller"; @@ -1441,11 +1276,8 @@ Collada::Node *Collada::_parse_visual_instance_geometry(XMLParser &parser) { return geom; // try to find also many materials and skeletons! while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "instance_material") { - String symbol = parser.get_attribute_value("symbol"); String target = _uri_to_id(parser.get_attribute_value("target")); @@ -1454,7 +1286,6 @@ Collada::Node *Collada::_parse_visual_instance_geometry(XMLParser &parser) { geom->material_map[symbol] = mat; COLLADA_PRINT("uses material: '" + target + "' on primitive'" + symbol + "'"); } else if (parser.get_node_name() == "skeleton") { - parser.read(); String uri = _uri_to_id(parser.get_node_data()); if (uri != "") { @@ -1467,7 +1298,6 @@ Collada::Node *Collada::_parse_visual_instance_geometry(XMLParser &parser) { } if (geom->controller) { - if (geom->skeletons.empty()) { //XSI style @@ -1487,7 +1317,6 @@ Collada::Node *Collada::_parse_visual_instance_geometry(XMLParser &parser) { } Collada::Node *Collada::_parse_visual_instance_camera(XMLParser &parser) { - NodeCamera *cam = memnew(NodeCamera); cam->camera = _uri_to_id(parser.get_attribute_value_safe("url")); @@ -1498,7 +1327,6 @@ Collada::Node *Collada::_parse_visual_instance_camera(XMLParser &parser) { return cam; while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_camera") break; } @@ -1507,7 +1335,6 @@ Collada::Node *Collada::_parse_visual_instance_camera(XMLParser &parser) { } Collada::Node *Collada::_parse_visual_instance_light(XMLParser &parser) { - NodeLight *cam = memnew(NodeLight); cam->light = _uri_to_id(parser.get_attribute_value_safe("url")); @@ -1518,7 +1345,6 @@ Collada::Node *Collada::_parse_visual_instance_light(XMLParser &parser) { return cam; while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_light") break; } @@ -1527,13 +1353,11 @@ Collada::Node *Collada::_parse_visual_instance_light(XMLParser &parser) { } Collada::Node *Collada::_parse_visual_node_instance_data(XMLParser &parser) { - String instance_type = parser.get_node_name(); if (instance_type == "instance_geometry" || instance_type == "instance_controller") { return _parse_visual_instance_geometry(parser); } else if (instance_type == "instance_camera") { - return _parse_visual_instance_camera(parser); } else if (instance_type == "instance_light") { return _parse_visual_instance_light(parser); @@ -1543,7 +1367,6 @@ Collada::Node *Collada::_parse_visual_node_instance_data(XMLParser &parser) { return nullptr; while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == instance_type) break; } @@ -1552,7 +1375,6 @@ Collada::Node *Collada::_parse_visual_node_instance_data(XMLParser &parser) { } Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { - String name; String id = parser.get_attribute_value_safe("id"); @@ -1560,7 +1382,6 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { bool found_name = false; if (id == "") { - id = "%NODEID%" + itos(Math::rand()); } else { @@ -1576,7 +1397,6 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { name = parser.has_attribute("name") ? parser.get_attribute_value_safe("name") : parser.get_attribute_value_safe("id"); if (name == "") { - name = id; } else { found_name = true; @@ -1604,9 +1424,7 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { } while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String section = parser.get_node_name(); if (section == "translate") { @@ -1678,13 +1496,10 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { } else if (section == "empty_draw_type") { empty_draw_type = _read_empty_draw_type(parser); } else if (section == "technique" || section == "extra") { - } else if (section != "node") { //usually what defines the type of node if (section.begins_with("instance_")) { - if (!node) { - node = _parse_visual_node_instance_data(parser); } else { @@ -1693,7 +1508,6 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { } } else { - /* Found a child node!! what to do..*/ Node *child = _parse_visual_scene_node(parser); @@ -1705,7 +1519,6 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { } if (!node) { - node = memnew(Node); //generic node, nothing of relevance found } @@ -1734,7 +1547,6 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { } void Collada::_parse_visual_scene(XMLParser &parser) { - String id = parser.get_attribute_value("id"); if (parser.is_empty()) { @@ -1748,9 +1560,7 @@ void Collada::_parse_visual_scene(XMLParser &parser) { vscene.name = parser.get_attribute_value("name"); while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String section = parser.get_node_name(); if (section == "node") { @@ -1765,7 +1575,6 @@ void Collada::_parse_visual_scene(XMLParser &parser) { } void Collada::_parse_animation(XMLParser &parser) { - if (!(state.import_flags & IMPORT_FLAG_ANIMATION)) { if (!parser.is_empty()) parser.skip_section(); @@ -1790,38 +1599,30 @@ void Collada::_parse_animation(XMLParser &parser) { Vector channel_targets; while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String name = parser.get_node_name(); if (name == "source") { - current_source = parser.get_attribute_value("id"); source_param_names[current_source] = Vector(); source_param_types[current_source] = Vector(); } else if (name == "float_array") { - if (current_source != "") { float_sources[current_source] = _read_float_array(parser); } } else if (name == "Name_array") { - if (current_source != "") { string_sources[current_source] = _read_string_array(parser); } } else if (name == "accessor") { - if (current_source != "" && parser.has_attribute("stride")) { source_strides[current_source] = parser.get_attribute_value("stride").to_int(); } } else if (name == "sampler") { - current_sampler = parser.get_attribute_value("id"); samplers[current_sampler] = Map(); } else if (name == "param") { - if (parser.has_attribute("name")) source_param_names[current_source].push_back(parser.get_attribute_value("name")); else @@ -1833,14 +1634,11 @@ void Collada::_parse_animation(XMLParser &parser) { source_param_types[current_source].push_back(""); } else if (name == "input") { - if (current_sampler != "") { - samplers[current_sampler][parser.get_attribute_value("semantic")] = parser.get_attribute_value("source"); } } else if (name == "channel") { - channel_sources.push_back(parser.get_attribute_value("source")); channel_targets.push_back(parser.get_attribute_value("target")); } @@ -1850,7 +1648,6 @@ void Collada::_parse_animation(XMLParser &parser) { } for (int i = 0; i < channel_sources.size(); i++) { - String source = _uri_to_id(channel_sources[i]); String target = channel_targets[i]; ERR_CONTINUE(!samplers.has(source)); @@ -1870,7 +1667,6 @@ void Collada::_parse_animation(XMLParser &parser) { Vector &names = source_param_names[output_id]; for (int l = 0; l < names.size(); l++) { - String name = names[l]; Vector &time_keys = float_sources[input_id]; @@ -1908,7 +1704,6 @@ void Collada::_parse_animation(XMLParser &parser) { } if (sampler.has("INTERPOLATION")) { - String interp_id = _uri_to_id(sampler["INTERPOLATION"]); ERR_CONTINUE(!string_sources.has(interp_id)); Vector &interps = string_sources[interp_id]; @@ -1976,7 +1771,6 @@ void Collada::_parse_animation(XMLParser &parser) { } void Collada::_parse_animation_clip(XMLParser &parser) { - if (!(state.import_flags & IMPORT_FLAG_ANIMATION)) { if (!parser.is_empty()) parser.skip_section(); @@ -1996,12 +1790,9 @@ void Collada::_parse_animation_clip(XMLParser &parser) { clip.end = parser.get_attribute_value("end").to_double(); while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String name = parser.get_node_name(); if (name == "instance_animation") { - String url = _uri_to_id(parser.get_attribute_value("url")); clip.tracks.push_back(url); } @@ -2014,22 +1805,17 @@ void Collada::_parse_animation_clip(XMLParser &parser) { } void Collada::_parse_scene(XMLParser &parser) { - if (parser.is_empty()) { return; } while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String name = parser.get_node_name(); if (name == "instance_visual_scene") { - state.root_visual_scene = _uri_to_id(parser.get_attribute_value("url")); } else if (name == "instance_physics_scene") { - state.root_physics_scene = _uri_to_id(parser.get_attribute_value("url")); } @@ -2039,40 +1825,29 @@ void Collada::_parse_scene(XMLParser &parser) { } void Collada::_parse_library(XMLParser &parser) { - if (parser.is_empty()) { return; } while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - String name = parser.get_node_name(); COLLADA_PRINT("library name is: " + name); if (name == "image") { - _parse_image(parser); } else if (name == "material") { - _parse_material(parser); } else if (name == "effect") { - _parse_effect(parser); } else if (name == "camera") { - _parse_camera(parser); } else if (name == "light") { - _parse_light(parser); } else if (name == "geometry") { - String id = parser.get_attribute_value("id"); String name2 = parser.get_attribute_value_safe("name"); while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "mesh") { state.mesh_name_map[id] = (name2 != "") ? name2 : id; _parse_mesh_geometry(parser, id, name2); @@ -2086,16 +1861,12 @@ void Collada::_parse_library(XMLParser &parser) { } } else if (name == "controller") { - _parse_controller(parser); } else if (name == "animation") { - _parse_animation(parser); } else if (name == "animation_clip") { - _parse_animation_clip(parser); } else if (name == "visual_scene") { - COLLADA_PRINT("visual scene"); _parse_visual_scene(parser); } else if (!parser.is_empty()) @@ -2107,27 +1878,21 @@ void Collada::_parse_library(XMLParser &parser) { } void Collada::_joint_set_owner(Collada::Node *p_node, NodeSkeleton *p_owner) { - if (p_node->type == Node::TYPE_JOINT) { - NodeJoint *nj = static_cast(p_node); nj->owner = p_owner; for (int i = 0; i < nj->children.size(); i++) { - _joint_set_owner(nj->children.write[i], p_owner); } } } void Collada::_create_skeletons(Collada::Node **p_node, NodeSkeleton *p_skeleton) { - Node *node = *p_node; if (node->type == Node::TYPE_JOINT) { - if (!p_skeleton) { - // ohohohoohoo it's a joint node, time to work! NodeSkeleton *sk = memnew(NodeSkeleton); *p_node = sk; @@ -2149,9 +1914,7 @@ void Collada::_create_skeletons(Collada::Node **p_node, NodeSkeleton *p_skeleton } bool Collada::_remove_node(Node *p_parent, Node *p_node) { - for (int i = 0; i < p_parent->children.size(); i++) { - if (p_parent->children[i] == p_node) { p_parent->children.remove(i); return true; @@ -2164,10 +1927,8 @@ bool Collada::_remove_node(Node *p_parent, Node *p_node) { } void Collada::_remove_node(VisualScene *p_vscene, Node *p_node) { - for (int i = 0; i < p_vscene->root_nodes.size(); i++) { if (p_vscene->root_nodes[i] == p_node) { - p_vscene->root_nodes.remove(i); return; } @@ -2179,17 +1940,13 @@ void Collada::_remove_node(VisualScene *p_vscene, Node *p_node) { } void Collada::_merge_skeletons(VisualScene *p_vscene, Node *p_node) { - if (p_node->type == Node::TYPE_GEOMETRY) { - NodeGeometry *gnode = static_cast(p_node); if (gnode->controller) { - // recount skeletons used Set skeletons; for (int i = 0; i < gnode->skeletons.size(); i++) { - String nodeid = gnode->skeletons[i]; ERR_CONTINUE(!state.scene_map.has(nodeid)); //weird, it should have it... @@ -2206,17 +1963,14 @@ void Collada::_merge_skeletons(VisualScene *p_vscene, Node *p_node) { } if (skeletons.size() > 1) { - //do the merger!! Set::Element *E = skeletons.front(); NodeSkeleton *base = E->get(); for (E = E->next(); E; E = E->next()) { - NodeSkeleton *merged = E->get(); _remove_node(p_vscene, merged); for (int i = 0; i < merged->children.size(); i++) { - _joint_set_owner(merged->children[i], base); base->children.push_back(merged->children[i]); merged->children[i]->parent = base; @@ -2235,15 +1989,12 @@ void Collada::_merge_skeletons(VisualScene *p_vscene, Node *p_node) { } void Collada::_merge_skeletons2(VisualScene *p_vscene) { - for (Map::Element *E = state.skin_controller_data_map.front(); E; E = E->next()) { - SkinControllerData &cd = E->get(); NodeSkeleton *skeleton = nullptr; for (Map::Element *F = cd.bone_rest_map.front(); F; F = F->next()) { - String name; if (!state.sid_to_node_map.has(F->key())) { @@ -2260,7 +2011,6 @@ void Collada::_merge_skeletons2(VisualScene *p_vscene) { NodeSkeleton *sk = nullptr; while (node && !sk) { - if (node->type == Node::TYPE_SKELETON) { sk = static_cast(node); } @@ -2278,7 +2028,6 @@ void Collada::_merge_skeletons2(VisualScene *p_vscene) { //whoa.. wtf, merge. _remove_node(p_vscene, sk); for (int i = 0; i < sk->children.size(); i++) { - _joint_set_owner(sk->children[i], skeleton); skeleton->children.push_back(sk->children[i]); sk->children[i]->parent = skeleton; @@ -2292,7 +2041,6 @@ void Collada::_merge_skeletons2(VisualScene *p_vscene) { } bool Collada::_optimize_skeletons(VisualScene *p_vscene, Node *p_node) { - Node *node = p_node; if (node->type == Node::TYPE_SKELETON && node->parent && node->parent->type == Node::TYPE_NODE && node->parent->children.size() == 1) { @@ -2312,7 +2060,6 @@ bool Collada::_optimize_skeletons(VisualScene *p_vscene, Node *p_node) { Node *gp = parent->parent; bool found = false; for (int i = 0; i < gp->children.size(); i++) { - if (gp->children[i] == parent) { gp->children.write[i] = node; found = true; @@ -2323,13 +2070,10 @@ bool Collada::_optimize_skeletons(VisualScene *p_vscene, Node *p_node) { ERR_PRINT("BUG"); } } else { - bool found = false; for (int i = 0; i < p_vscene->root_nodes.size(); i++) { - if (p_vscene->root_nodes[i] == parent) { - p_vscene->root_nodes.write[i] = node; found = true; break; @@ -2346,7 +2090,6 @@ bool Collada::_optimize_skeletons(VisualScene *p_vscene, Node *p_node) { } for (int i = 0; i < node->children.size(); i++) { - if (_optimize_skeletons(p_vscene, node->children[i])) return false; //stop processing, go up } @@ -2355,18 +2098,15 @@ bool Collada::_optimize_skeletons(VisualScene *p_vscene, Node *p_node) { } bool Collada::_move_geometry_to_skeletons(VisualScene *p_vscene, Node *p_node, List *p_mgeom) { - // Bind Shape Matrix scales the bones and makes them gigantic, so the matrix then shrinks the model? // Solution: apply the Bind Shape Matrix to the VERTICES, and if the object comes scaled, it seems to be left alone! if (p_node->type == Node::TYPE_GEOMETRY) { - NodeGeometry *ng = static_cast(p_node); if (ng->ignore_anim) return false; //already made child of skeleton and processeg if (ng->controller && ng->skeletons.size()) { - String nodeid = ng->skeletons[0]; ERR_FAIL_COND_V(!state.scene_map.has(nodeid), false); //weird, it should have it... @@ -2401,7 +2141,6 @@ bool Collada::_move_geometry_to_skeletons(VisualScene *p_vscene, Node *p_node, L //make rests relative to the skeleton (they seem to be always relative to world) for (Map::Element *E = skin.bone_rest_map.front(); E; E = E->next()) { - E->get() = skel_inv * E->get(); //make the bone rest local to the skeleton state.bone_rest_map[E->key()] = E->get(); // make it remember where the bone is globally, now that it's relative } @@ -2419,7 +2158,6 @@ bool Collada::_move_geometry_to_skeletons(VisualScene *p_vscene, Node *p_node, L } for (int i = 0; i < p_node->children.size(); i++) { - if (_move_geometry_to_skeletons(p_vscene, p_node->children[i], p_mgeom)) { p_node->children.remove(i); i--; @@ -2430,23 +2168,17 @@ bool Collada::_move_geometry_to_skeletons(VisualScene *p_vscene, Node *p_node, L } void Collada::_find_morph_nodes(VisualScene *p_vscene, Node *p_node) { - if (p_node->type == Node::TYPE_GEOMETRY) { - NodeGeometry *nj = static_cast(p_node); if (nj->controller) { - String base = nj->source; while (base != "" && !state.mesh_data_map.has(base)) { - if (state.skin_controller_data_map.has(base)) { - SkinControllerData &sk = state.skin_controller_data_map[base]; base = sk.base; } else if (state.morph_controller_data_map.has(base)) { - state.morph_ownership_map[base] = nj->id; break; } else { @@ -2457,15 +2189,12 @@ void Collada::_find_morph_nodes(VisualScene *p_vscene, Node *p_node) { } for (int i = 0; i < p_node->children.size(); i++) { - _find_morph_nodes(p_vscene, p_node->children[i]); } } void Collada::_optimize() { - for (Map::Element *E = state.visual_scene_map.front(); E; E = E->next()) { - VisualScene &vs = E->get(); for (int i = 0; i < vs.root_nodes.size(); i++) { _create_skeletons(&vs.root_nodes.write[i]); @@ -2482,7 +2211,6 @@ void Collada::_optimize() { } for (int i = 0; i < vs.root_nodes.size(); i++) { - List mgeom; if (_move_geometry_to_skeletons(&vs, vs.root_nodes[i], &mgeom)) { vs.root_nodes.remove(i); @@ -2490,7 +2218,6 @@ void Collada::_optimize() { } while (!mgeom.empty()) { - Node *n = mgeom.front()->get(); n->parent->children.push_back(n); mgeom.pop_front(); @@ -2504,9 +2231,7 @@ void Collada::_optimize() { } int Collada::get_uv_channel(String p_name) { - if (!channel_map.has(p_name)) { - ERR_FAIL_COND_V(channel_map.size() == 2, 0); channel_map[p_name] = channel_map.size(); @@ -2516,7 +2241,6 @@ int Collada::get_uv_channel(String p_name) { } Error Collada::load(const String &p_path, int p_flags) { - Ref parserr = memnew(XMLParser); XMLParser &parser = *parserr.ptr(); Error err = parser.open(p_path); @@ -2526,9 +2250,7 @@ Error Collada::load(const String &p_path, int p_flags) { state.import_flags = p_flags; /* Skip headers */ while ((err = parser.read()) == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { - if (parser.get_node_name() == "COLLADA") { break; } else if (!parser.is_empty()) @@ -2550,7 +2272,6 @@ Error Collada::load(const String &p_path, int p_flags) { } while ((err = parser.read()) == OK) { - /* Read all the main sections.. */ if (parser.get_node_type() != XMLParser::NODE_ELEMENT) @@ -2564,10 +2285,8 @@ Error Collada::load(const String &p_path, int p_flags) { _parse_asset(parser); } else if (section.begins_with("library_")) { - _parse_library(parser); } else if (section == "scene") { - _parse_scene(parser); } else if (!parser.is_empty()) { parser.skip_section(); // unknown section, likely headers diff --git a/editor/import/collada.h b/editor/import/collada.h index 187a8092da..02c3277911 100644 --- a/editor/import/collada.h +++ b/editor/import/collada.h @@ -44,23 +44,19 @@ public: }; struct Image { - String path; }; struct Material { - String name; String instance_effect; }; struct Effect { - String name; Map params; struct Channel { - int uv_idx = 0; String texture; Color color; @@ -81,7 +77,6 @@ public: }; struct CameraData { - enum Mode { MODE_PERSPECTIVE, MODE_ORTHOGONAL @@ -108,7 +103,6 @@ public: }; struct LightData { - enum Mode { MODE_AMBIENT, MODE_DIRECTIONAL, @@ -131,10 +125,8 @@ public: }; struct MeshData { - String name; struct Source { - Vector array; int stride; }; @@ -142,16 +134,13 @@ public: Map sources; struct Vertices { - Map sources; }; Map vertices; struct Primitives { - struct SourceRef { - String source; int offset; }; @@ -173,12 +162,10 @@ public: }; struct CurveData { - String name; bool closed = false; struct Source { - Vector sarray; Vector array; int stride; @@ -192,14 +179,12 @@ public: }; struct SkinControllerData { - String base; bool use_idrefs = false; Transform bind_shape; struct Source { - Vector sarray; //maybe for names Vector array; int stride = 1; @@ -209,14 +194,11 @@ public: Map sources; struct Joints { - Map sources; } joints; struct Weights { - struct SourceRef { - String source; int offset; }; @@ -234,12 +216,10 @@ public: }; struct MorphControllerData { - String mesh; String mode; struct Source { - int stride = 1; Vector sarray; //maybe for names Vector array; @@ -253,7 +233,6 @@ public: }; struct Vertex { - int idx = 0; Vector3 vertex; Vector3 normal; @@ -271,7 +250,6 @@ public: Vector weights; void fix_weights() { - weights.sort(); if (weights.size() > 4) { //cap to 4 and make weights add up 1 @@ -288,17 +266,13 @@ public: void fix_unit_scale(Collada &state); bool operator<(const Vertex &p_vert) const { - if (uid == p_vert.uid) { if (vertex == p_vert.vertex) { if (normal == p_vert.normal) { if (uv == p_vert.uv) { if (uv2 == p_vert.uv2) { - if (!weights.empty() || !p_vert.weights.empty()) { - if (weights.size() == p_vert.weights.size()) { - for (int i = 0; i < weights.size(); i++) { if (weights[i].bone_idx != p_vert.weights[i].bone_idx) return weights[i].bone_idx < p_vert.weights[i].bone_idx; @@ -328,7 +302,6 @@ public: }; struct Node { - enum Type { TYPE_NODE, @@ -340,7 +313,6 @@ public: }; struct XForm { - enum Op { OP_ROTATE, OP_SCALE, @@ -381,12 +353,10 @@ public: }; struct NodeSkeleton : public Node { - NodeSkeleton() { type = TYPE_SKELETON; } }; struct NodeJoint : public Node { - NodeSkeleton *owner = nullptr; String sid; NodeJoint() { @@ -395,7 +365,6 @@ public: }; struct NodeGeometry : public Node { - bool controller; String source; @@ -410,21 +379,18 @@ public: }; struct NodeCamera : public Node { - String camera; NodeCamera() { type = TYPE_CAMERA; } }; struct NodeLight : public Node { - String light; NodeLight() { type = TYPE_LIGHT; } }; struct VisualScene { - String name; Vector root_nodes; @@ -435,7 +401,6 @@ public: }; struct AnimationClip { - String name; float begin = 0; float end = 1; @@ -445,7 +410,6 @@ public: }; struct AnimationTrack { - String id; String target; String param; @@ -458,7 +422,6 @@ public: }; struct Key { - enum Type { TYPE_FLOAT, TYPE_MATRIX @@ -485,7 +448,6 @@ public: /****************/ struct State { - int import_flags = 0; float unit_scale = 1.0; @@ -493,7 +455,6 @@ public: bool z_up; struct Version { - int major, minor, rev; bool operator<(const Version &p_ver) const { return (major == p_ver.major) ? ((minor == p_ver.minor) ? (rev < p_ver.rev) : minor < p_ver.minor) : major < p_ver.major; } diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 697ddfba96..0f3faf4189 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -45,7 +45,6 @@ #include "scene/resources/surface_tool.h" struct ColladaImport { - Collada collada; Node3D *scene; @@ -101,7 +100,6 @@ struct ColladaImport { void _pre_process_lights(Collada::Node *p_node); ColladaImport() { - found_ambient = false; found_directional = false; force_make_tangents = false; @@ -111,7 +109,6 @@ struct ColladaImport { }; Error ColladaImport::_populate_skeleton(Skeleton3D *p_skeleton, Collada::Node *p_node, int &r_bone, int p_parent) { - if (p_node->type != Collada::Node::TYPE_JOINT) return OK; @@ -130,7 +127,6 @@ Error ColladaImport::_populate_skeleton(Skeleton3D *p_skeleton, Collada::Node *p skeleton_bone_map[p_skeleton][joint->sid] = r_bone; if (collada.state.bone_rest_map.has(joint->sid)) { - p_skeleton->set_bone_rest(r_bone, collada.fix_transform(collada.state.bone_rest_map[joint->sid])); //should map this bone to something for animation? } else { @@ -139,7 +135,6 @@ Error ColladaImport::_populate_skeleton(Skeleton3D *p_skeleton, Collada::Node *p int id = r_bone++; for (int i = 0; i < p_node->children.size(); i++) { - Error err = _populate_skeleton(p_skeleton, p_node->children[i], r_bone, id); if (err) return err; @@ -149,12 +144,9 @@ Error ColladaImport::_populate_skeleton(Skeleton3D *p_skeleton, Collada::Node *p } void ColladaImport::_pre_process_lights(Collada::Node *p_node) { - if (p_node->type == Collada::Node::TYPE_LIGHT) { - Collada::NodeLight *light = static_cast(p_node); if (collada.state.light_data_map.has(light->light)) { - Collada::LightData &ld = collada.state.light_data_map[light->light]; if (ld.mode == Collada::LightData::MODE_AMBIENT) { found_ambient = true; @@ -171,13 +163,10 @@ void ColladaImport::_pre_process_lights(Collada::Node *p_node) { } Error ColladaImport::_create_scene_skeletons(Collada::Node *p_node) { - if (p_node->type == Collada::Node::TYPE_SKELETON) { - Skeleton3D *sk = memnew(Skeleton3D); int bone = 0; for (int i = 0; i < p_node->children.size(); i++) { - _populate_skeleton(sk, p_node->children[i], bone, -1); } sk->localize_rests(); //after creating skeleton, rests must be localized...! @@ -185,7 +174,6 @@ Error ColladaImport::_create_scene_skeletons(Collada::Node *p_node) { } for (int i = 0; i < p_node->children.size(); i++) { - Error err = _create_scene_skeletons(p_node->children[i]); if (err) return err; @@ -194,29 +182,22 @@ Error ColladaImport::_create_scene_skeletons(Collada::Node *p_node) { } Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { - Node3D *node = nullptr; switch (p_node->type) { - case Collada::Node::TYPE_NODE: { - node = memnew(Node3D); } break; case Collada::Node::TYPE_JOINT: { - return OK; // do nothing } break; case Collada::Node::TYPE_LIGHT: { - //node = memnew( Light) Collada::NodeLight *light = static_cast(p_node); if (collada.state.light_data_map.has(light->light)) { - Collada::LightData &ld = collada.state.light_data_map[light->light]; if (ld.mode == Collada::LightData::MODE_AMBIENT) { - if (found_directional) return OK; //do nothing not needed @@ -230,7 +211,6 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { node = l; } else if (ld.mode == Collada::LightData::MODE_DIRECTIONAL) { - //well, it's an ambient light.. Light3D *l = memnew(DirectionalLight3D); /* @@ -242,7 +222,6 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { */ node = l; } else { - Light3D *l; if (ld.mode == Collada::LightData::MODE_OMNI) @@ -261,43 +240,33 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { } } else { - node = memnew(Node3D); } } break; case Collada::Node::TYPE_CAMERA: { - Collada::NodeCamera *cam = static_cast(p_node); Camera3D *camera = memnew(Camera3D); if (collada.state.camera_data_map.has(cam->camera)) { - const Collada::CameraData &cd = collada.state.camera_data_map[cam->camera]; switch (cd.mode) { - case Collada::CameraData::MODE_ORTHOGONAL: { - if (cd.orthogonal.y_mag) { - camera->set_keep_aspect_mode(Camera3D::KEEP_HEIGHT); camera->set_orthogonal(cd.orthogonal.y_mag * 2.0, cd.z_near, cd.z_far); } else if (!cd.orthogonal.y_mag && cd.orthogonal.x_mag) { - camera->set_keep_aspect_mode(Camera3D::KEEP_WIDTH); camera->set_orthogonal(cd.orthogonal.x_mag * 2.0, cd.z_near, cd.z_far); } } break; case Collada::CameraData::MODE_PERSPECTIVE: { - if (cd.perspective.y_fov) { - camera->set_perspective(cd.perspective.y_fov, cd.z_near, cd.z_far); } else if (!cd.perspective.y_fov && cd.perspective.x_fov) { - camera->set_perspective(cd.perspective.x_fov / cd.aspect, cd.z_near, cd.z_far); } @@ -309,11 +278,9 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { } break; case Collada::Node::TYPE_GEOMETRY: { - Collada::NodeGeometry *ng = static_cast(p_node); if (collada.state.curve_data_map.has(ng->source)) { - node = memnew(Path3D); } else { //mesh since nothing else @@ -322,7 +289,6 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { } } break; case Collada::Node::TYPE_SKELETON: { - ERR_FAIL_COND_V(!skeleton_map.has(p_node), ERR_CANT_CREATE); Skeleton3D *sk = skeleton_map[p_node]; node = sk; @@ -347,7 +313,6 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { } for (int i = 0; i < p_node->children.size(); i++) { - Error err = _create_scene(p_node->children[i], node); if (err) return err; @@ -356,7 +321,6 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { } Error ColladaImport::_create_material(const String &p_target) { - ERR_FAIL_COND_V(material_cache.has(p_target), ERR_ALREADY_EXISTS); ERR_FAIL_COND_V(!collada.state.material_map.has(p_target), ERR_INVALID_PARAMETER); Collada::Material &src_mat = collada.state.material_map[p_target]; @@ -373,16 +337,13 @@ Error ColladaImport::_create_material(const String &p_target) { // DIFFUSE if (effect.diffuse.texture != "") { - String texfile = effect.get_texture_path(effect.diffuse.texture, collada); if (texfile != "") { - if (texfile.begins_with("/")) { texfile = texfile.replace_first("/", "res://"); } Ref texture = ResourceLoader::load(texfile, "Texture2D"); if (texture.is_valid()) { - material->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, texture); material->set_albedo(Color(1, 1, 1, 1)); //material->set_parameter(StandardMaterial3D::PARAM_DIFFUSE,Color(1,1,1,1)); @@ -397,10 +358,8 @@ Error ColladaImport::_create_material(const String &p_target) { // SPECULAR if (effect.specular.texture != "") { - String texfile = effect.get_texture_path(effect.specular.texture, collada); if (texfile != "") { - if (texfile.begins_with("/")) { texfile = texfile.replace_first("/", "res://"); } @@ -424,17 +383,14 @@ Error ColladaImport::_create_material(const String &p_target) { // EMISSION if (effect.emission.texture != "") { - String texfile = effect.get_texture_path(effect.emission.texture, collada); if (texfile != "") { - if (texfile.begins_with("/")) { texfile = texfile.replace_first("/", "res://"); } Ref texture = ResourceLoader::load(texfile, "Texture2D"); if (texture.is_valid()) { - material->set_feature(StandardMaterial3D::FEATURE_EMISSION, true); material->set_texture(StandardMaterial3D::TEXTURE_EMISSION, texture); material->set_emission(Color(1, 1, 1, 1)); @@ -454,10 +410,8 @@ Error ColladaImport::_create_material(const String &p_target) { // NORMAL if (effect.bump.texture != "") { - String texfile = effect.get_texture_path(effect.bump.texture, collada); if (texfile != "") { - if (texfile.begins_with("/")) { texfile = texfile.replace_first("/", "res://"); } @@ -490,18 +444,15 @@ Error ColladaImport::_create_material(const String &p_target) { } Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_mesh, const Map &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector &bone_remap, const Collada::SkinControllerData *p_skin_controller, const Collada::MorphControllerData *p_morph_data, Vector> p_morph_meshes, bool p_use_compression, bool p_use_mesh_material) { - bool local_xform_mirror = p_local_xform.basis.determinant() < 0; if (p_morph_data) { - //add morphie target ERR_FAIL_COND_V(!p_morph_data->targets.has("MORPH_TARGET"), ERR_INVALID_DATA); String mt = p_morph_data->targets["MORPH_TARGET"]; ERR_FAIL_COND_V(!p_morph_data->sources.has(mt), ERR_INVALID_DATA); int morph_targets = p_morph_data->sources[mt].sarray.size(); for (int i = 0; i < morph_targets; i++) { - String target = p_morph_data->sources[mt].sarray[i]; ERR_FAIL_COND_V(!collada.state.mesh_data_map.has(target), ERR_INVALID_DATA); String name = collada.state.mesh_data_map[target].name; @@ -516,7 +467,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me int surface = 0; for (int p_i = 0; p_i < meshdata.primitives.size(); p_i++) { - const Collada::MeshData::Primitives &p = meshdata.primitives[p_i]; /* VERTEX SOURCE */ @@ -540,7 +490,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me int normal_ofs = 0; if (p.sources.has("NORMAL")) { - String normal_source_id = p.sources["NORMAL"].source; normal_ofs = p.sources["NORMAL"].offset; ERR_FAIL_COND_V(!meshdata.sources.has(normal_source_id), ERR_INVALID_DATA); @@ -551,7 +500,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me int binormal_ofs = 0; if (p.sources.has("TEXBINORMAL")) { - String binormal_source_id = p.sources["TEXBINORMAL"].source; binormal_ofs = p.sources["TEXBINORMAL"].offset; ERR_FAIL_COND_V(!meshdata.sources.has(binormal_source_id), ERR_INVALID_DATA); @@ -562,7 +510,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me int tangent_ofs = 0; if (p.sources.has("TEXTANGENT")) { - String tangent_source_id = p.sources["TEXTANGENT"].source; tangent_ofs = p.sources["TEXTANGENT"].offset; ERR_FAIL_COND_V(!meshdata.sources.has(tangent_source_id), ERR_INVALID_DATA); @@ -573,7 +520,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me int uv_ofs = 0; if (p.sources.has("TEXCOORD0")) { - String uv_source_id = p.sources["TEXCOORD0"].source; uv_ofs = p.sources["TEXCOORD0"].offset; ERR_FAIL_COND_V(!meshdata.sources.has(uv_source_id), ERR_INVALID_DATA); @@ -584,7 +530,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me int uv2_ofs = 0; if (p.sources.has("TEXCOORD1")) { - String uv2_source_id = p.sources["TEXCOORD1"].source; uv2_ofs = p.sources["TEXCOORD1"].offset; ERR_FAIL_COND_V(!meshdata.sources.has(uv2_source_id), ERR_INVALID_DATA); @@ -595,7 +540,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me int color_ofs = 0; if (p.sources.has("COLOR")) { - String color_source_id = p.sources["COLOR"].source; color_ofs = p.sources["COLOR"].offset; ERR_FAIL_COND_V(!meshdata.sources.has(color_source_id), ERR_INVALID_DATA); @@ -613,16 +557,13 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me bool has_weights = false; if (p_skin_controller) { - const Collada::SkinControllerData::Source *weight_src = nullptr; int weight_ofs = 0; if (p_skin_controller->weights.sources.has("WEIGHT")) { - String weight_id = p_skin_controller->weights.sources["WEIGHT"].source; weight_ofs = p_skin_controller->weights.sources["WEIGHT"].offset; if (p_skin_controller->sources.has(weight_id)) { - weight_src = &p_skin_controller->sources[weight_id]; } } @@ -630,7 +571,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me int joint_ofs = 0; if (p_skin_controller->weights.sources.has("JOINT")) { - joint_ofs = p_skin_controller->weights.sources["JOINT"].offset; } @@ -639,13 +579,11 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me int index_ofs = 0; int wstride = p_skin_controller->weights.sources.size(); for (int w_i = 0; w_i < p_skin_controller->weights.sets.size(); w_i++) { - int amount = p_skin_controller->weights.sets[w_i]; Vector weights; for (int a_i = 0; a_i < amount; a_i++) { - Collada::Vertex::Weight w; int read_from = index_ofs + a_i * wstride; @@ -715,10 +653,8 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me int _prim_ofs = 0; int vertidx = 0; for (int p_j = 0; p_j < p.count; p_j++) { - int amount; if (p.polygons.size()) { - ERR_FAIL_INDEX_V(p_j, p.polygons.size(), ERR_INVALID_DATA); amount = p.polygons[p_j]; } else { @@ -730,7 +666,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me int prev2[2] = { 0, 0 }; for (int j = 0; j < amount; j++) { - int src = _prim_ofs; //_prim_ofs+=p.sources.size() @@ -750,13 +685,11 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me } if (normal_src) { - int normal_pos = (normal_src->stride ? normal_src->stride : 3) * p.indices[src + normal_ofs]; ERR_FAIL_INDEX_V(normal_pos, normal_src->array.size(), ERR_INVALID_DATA); vertex.normal = Vector3(normal_src->array[normal_pos + 0], normal_src->array[normal_pos + 1], normal_src->array[normal_pos + 2]); if (tangent_src && binormal_src) { - int binormal_pos = (binormal_src->stride ? binormal_src->stride : 3) * p.indices[src + binormal_ofs]; ERR_FAIL_INDEX_V(binormal_pos, binormal_src->array.size(), ERR_INVALID_DATA); Vector3 binormal = Vector3(binormal_src->array[binormal_pos + 0], binormal_src->array[binormal_pos + 1], binormal_src->array[binormal_pos + 2]); @@ -771,21 +704,18 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me } if (uv_src) { - int uv_pos = (uv_src->stride ? uv_src->stride : 2) * p.indices[src + uv_ofs]; ERR_FAIL_INDEX_V(uv_pos, uv_src->array.size(), ERR_INVALID_DATA); vertex.uv = Vector3(uv_src->array[uv_pos + 0], 1.0 - uv_src->array[uv_pos + 1], 0); } if (uv2_src) { - int uv2_pos = (uv2_src->stride ? uv2_src->stride : 2) * p.indices[src + uv2_ofs]; ERR_FAIL_INDEX_V(uv2_pos, uv2_src->array.size(), ERR_INVALID_DATA); vertex.uv2 = Vector3(uv2_src->array[uv2_pos + 0], 1.0 - uv2_src->array[uv2_pos + 1], 0); } if (color_src) { - int color_pos = (color_src->stride ? color_src->stride : 3) * p.indices[src + color_ofs]; // colors are RGB in collada.. ERR_FAIL_INDEX_V(color_pos, color_src->array.size(), ERR_INVALID_DATA); vertex.color = Color(color_src->array[color_pos + 0], color_src->array[color_pos + 1], color_src->array[color_pos + 2], (color_src->stride > 3) ? color_src->array[color_pos + 3] : 1.0); @@ -793,7 +723,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me #ifndef NO_UP_AXIS_SWAP if (collada.state.up_axis == Vector3::AXIS_Z) { - Vector3 bn = vertex.normal.cross(vertex.tangent.normal) * vertex.tangent.d; SWAP(vertex.vertex.z, vertex.vertex.y); @@ -815,10 +744,8 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me //COLLADA_PRINT("vertex: "+vertex.vertex); if (vertex_set.has(vertex)) { - index = vertex_set.find(vertex)->get().idx; } else { - index = vertex_set.size(); vertex.idx = index; vertex_set.insert(vertex); @@ -831,7 +758,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me if (j >= 2) { //insert indices in reverse order (collada uses CCW as frontface) if (local_xform_mirror) { - indices_list.push_back(prev2[0]); indices_list.push_back(prev2[1]); indices_list.push_back(index); @@ -852,16 +778,13 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me vertex_array.resize(vertex_set.size()); for (Set::Element *F = vertex_set.front(); F; F = F->next()) { - vertex_array.write[F->get().idx] = F->get(); } if (has_weights) { - //if skeleton, localize Transform local_xform = p_local_xform; for (int i = 0; i < vertex_array.size(); i++) { - vertex_array.write[i].vertex = local_xform.xform(vertex_array[i].vertex); vertex_array.write[i].normal = local_xform.basis.xform(vertex_array[i].normal).normalized(); vertex_array.write[i].tangent.normal = local_xform.basis.xform(vertex_array[i].tangent.normal).normalized(); @@ -878,11 +801,9 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me /*****************/ { - Ref material; { - if (p_material_map.has(p.material)) { String target = p_material_map[p.material].target; @@ -931,7 +852,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me bones.write[l] = vertex_array[k].weights[l].bone_idx; //sum += vertex_array[k].weights[l].weight; } else { - weights.write[l] = 0; bones.write[l] = 0; } @@ -954,7 +874,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me } if ((!binormal_src || !tangent_src) && normal_src && uv_src && force_make_tangents) { - surftool->generate_tangents(); } @@ -972,7 +891,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me //////////////////////////// for (int mi = 0; mi < p_morph_meshes.size(); mi++) { - Array a = p_morph_meshes[mi]->surface_get_arrays(surface); //add valid weight and bone arrays if they exist, TODO check if they are unique to shape (generally not) @@ -1007,21 +925,16 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me } Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compression) { - if (p_node->type == Collada::Node::TYPE_GEOMETRY && node_map.has(p_node->id)) { - Node3D *node = node_map[p_node->id].node; Collada::NodeGeometry *ng = static_cast(p_node); if (Object::cast_to(node)) { - Path3D *path = Object::cast_to(node); if (curve_cache.has(ng->source)) { - path->set_curve(curve_cache[ng->source]); } else { - Ref c = memnew(Curve3D); const Collada::CurveData &cd = collada.state.curve_data_map[ng->source]; @@ -1053,14 +966,12 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres int pc = vertices.array.size() / 3; for (int i = 0; i < pc; i++) { - Vector3 pos(vertices.array[i * 3 + 0], vertices.array[i * 3 + 1], vertices.array[i * 3 + 2]); Vector3 in(in_tangents.array[i * 3 + 0], in_tangents.array[i * 3 + 1], in_tangents.array[i * 3 + 2]); Vector3 out(out_tangents.array[i * 3 + 0], out_tangents.array[i * 3 + 1], out_tangents.array[i * 3 + 2]); #ifndef NO_UP_AXIS_SWAP if (collada.state.up_axis == Vector3::AXIS_Z) { - SWAP(pos.y, pos.z); pos.z = -pos.z; SWAP(in.y, in.z); @@ -1084,7 +995,6 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres } if (Object::cast_to(node)) { - Collada::NodeGeometry *ng2 = static_cast(p_node); MeshInstance3D *mi = Object::cast_to(node); @@ -1099,11 +1009,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres Vector> morphs; if (ng2->controller) { - String ngsource = ng2->source; if (collada.state.skin_controller_data_map.has(ngsource)) { - ERR_FAIL_COND_V(!collada.state.skin_controller_data_map.has(ngsource), ERR_INVALID_DATA); skin = &collada.state.skin_controller_data_map[ngsource]; @@ -1147,7 +1055,6 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres bone_remap.resize(joint_src->sarray.size()); for (int i = 0; i < bone_remap.size(); i++) { - String str = joint_src->sarray[i]; ERR_FAIL_COND_V(!bone_remap_map.has(str), ERR_INVALID_DATA); bone_remap.write[i] = bone_remap_map[str]; @@ -1155,7 +1062,6 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres } if (collada.state.morph_controller_data_map.has(ngsource)) { - //it's a morph!! morph = &collada.state.morph_controller_data_map[ngsource]; meshid = morph->mesh; @@ -1167,7 +1073,6 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres valid = true; Vector names = morph->sources[target].sarray; for (int i = 0; i < names.size(); i++) { - String meshid2 = names[i]; if (collada.state.mesh_data_map.has(meshid2)) { Ref mesh = Ref(memnew(ArrayMesh)); @@ -1211,19 +1116,16 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres mesh_cache[meshid] = mesh; } else { - WARN_PRINT("Collada: Will not import geometry: " + meshid); } } if (!mesh.is_null()) { - mi->set_mesh(mesh); if (!use_mesh_builtin_materials) { const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid]; for (int i = 0; i < meshdata.primitives.size(); i++) { - String matname = meshdata.primitives[i].material; if (ng2->material_map.has(matname)) { @@ -1248,7 +1150,6 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres } for (int i = 0; i < p_node->children.size(); i++) { - Error err = _create_resources(p_node->children[i], p_use_compression); if (err) return err; @@ -1257,7 +1158,6 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres } Error ColladaImport::load(const String &p_path, int p_flags, bool p_force_make_tangents, bool p_use_compression) { - Error err = collada.load(p_path, p_flags); ERR_FAIL_COND_V_MSG(err, err, "Cannot load file '" + p_path + "'."); @@ -1269,13 +1169,11 @@ Error ColladaImport::load(const String &p_path, int p_flags, bool p_force_make_t //determine what's going on with the lights for (int i = 0; i < vs.root_nodes.size(); i++) { - _pre_process_lights(vs.root_nodes[i]); } //import scene for (int i = 0; i < vs.root_nodes.size(); i++) { - Error err2 = _create_scene_skeletons(vs.root_nodes[i]); if (err2 != OK) { memdelete(scene); @@ -1284,7 +1182,6 @@ Error ColladaImport::load(const String &p_path, int p_flags, bool p_force_make_t } for (int i = 0; i < vs.root_nodes.size(); i++) { - Error err2 = _create_scene(vs.root_nodes[i], scene); if (err2 != OK) { memdelete(scene); @@ -1305,48 +1202,36 @@ Error ColladaImport::load(const String &p_path, int p_flags, bool p_force_make_t } void ColladaImport::_fix_param_animation_tracks() { - for (Map::Element *E = collada.state.scene_map.front(); E; E = E->next()) { - Collada::Node *n = E->get(); switch (n->type) { - case Collada::Node::TYPE_NODE: { // ? do nothing } break; case Collada::Node::TYPE_JOINT: { - } break; case Collada::Node::TYPE_SKELETON: { - } break; case Collada::Node::TYPE_LIGHT: { - } break; case Collada::Node::TYPE_CAMERA: { - } break; case Collada::Node::TYPE_GEOMETRY: { - Collada::NodeGeometry *ng = static_cast(n); // test source(s) String source = ng->source; while (source != "") { - if (collada.state.skin_controller_data_map.has(source)) { - const Collada::SkinControllerData &skin = collada.state.skin_controller_data_map[source]; //nothing to animate here i think source = skin.base; } else if (collada.state.morph_controller_data_map.has(source)) { - const Collada::MorphControllerData &morph = collada.state.morph_controller_data_map[source]; if (morph.targets.has("MORPH_WEIGHT") && morph.targets.has("MORPH_TARGET")) { - String weights = morph.targets["MORPH_WEIGHT"]; String targets = morph.targets["MORPH_TARGET"]; //fails here @@ -1358,11 +1243,9 @@ void ColladaImport::_fix_param_animation_tracks() { ERR_FAIL_COND(weight_src.array.size() != target_src.sarray.size()); for (int i = 0; i < weight_src.array.size(); i++) { - String track_name = weights + "(" + itos(i) + ")"; String mesh_name = target_src.sarray[i]; if (collada.state.mesh_name_map.has(mesh_name) && collada.state.referenced_tracks.has(track_name)) { - const Vector &rt = collada.state.referenced_tracks[track_name]; for (int rti = 0; rti < rt.size(); rti++) { @@ -1379,7 +1262,6 @@ void ColladaImport::_fix_param_animation_tracks() { } source = morph.mesh; } else { - source = ""; // for now nothing else supported } } @@ -1390,24 +1272,19 @@ void ColladaImport::_fix_param_animation_tracks() { } void ColladaImport::create_animations(bool p_make_tracks_in_all_bones, bool p_import_value_tracks) { - _fix_param_animation_tracks(); for (int i = 0; i < collada.state.animation_clips.size(); i++) { - for (int j = 0; j < collada.state.animation_clips[i].tracks.size(); j++) tracks_in_clips.insert(collada.state.animation_clips[i].tracks[j]); } for (int i = 0; i < collada.state.animation_tracks.size(); i++) { - const Collada::AnimationTrack &at = collada.state.animation_tracks[i]; String node; if (!node_map.has(at.target)) { - if (node_name_map.has(at.target)) { - node = node_name_map[at.target]; } else { WARN_PRINT("Collada: Couldn't find node: " + at.target); @@ -1418,11 +1295,9 @@ void ColladaImport::create_animations(bool p_make_tracks_in_all_bones, bool p_im } if (at.property) { - valid_animated_properties.push_back(i); } else { - node_map[node].anim_tracks.push_back(i); valid_animated_nodes.insert(node); } @@ -1434,7 +1309,6 @@ void ColladaImport::create_animations(bool p_make_tracks_in_all_bones, bool p_im } void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones, bool p_import_value_tracks) { - Ref animation = Ref(memnew(Animation)); if (p_clip == -1) { @@ -1444,7 +1318,6 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones } for (Map::Element *E = node_map.front(); E; E = E->next()) { - if (E->get().bone < 0) continue; bones_with_animation[E->key()] = false; @@ -1458,15 +1331,11 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones Set track_filter; if (p_clip == -1) { - for (int i = 0; i < collada.state.animation_clips.size(); i++) { - int tc = collada.state.animation_clips[i].tracks.size(); for (int j = 0; j < tc; j++) { - String n = collada.state.animation_clips[i].tracks[j]; if (collada.state.by_id_tracks.has(n)) { - const Vector &ti = collada.state.by_id_tracks[n]; for (int k = 0; k < ti.size(); k++) { track_filter.insert(ti[k]); @@ -1475,13 +1344,10 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones } } } else { - int tc = collada.state.animation_clips[p_clip].tracks.size(); for (int j = 0; j < tc; j++) { - String n = collada.state.animation_clips[p_clip].tracks[j]; if (collada.state.by_id_tracks.has(n)) { - const Vector &ti = collada.state.by_id_tracks[n]; for (int k = 0; k < ti.size(); k++) { track_filter.insert(ti[k]); @@ -1503,7 +1369,6 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones anim_length = collada.state.animation_clips[p_clip].end; while (f < anim_length) { - base_snapshots.push_back(f); f += snapshot_interval; @@ -1518,11 +1383,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones bool tracks_found = false; for (Set::Element *E = valid_animated_nodes.front(); E; E = E->next()) { - // take snapshots if (!collada.state.scene_map.has(E->get())) { - continue; } @@ -1539,7 +1402,6 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones Collada::Node *cn = collada.state.scene_map[E->get()]; if (cn->ignore_anim) { - continue; } @@ -1559,18 +1421,14 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones } for (int i = 0; i < snapshots.size(); i++) { - for (List::Element *ET = nm.anim_tracks.front(); ET; ET = ET->next()) { //apply tracks if (p_clip == -1) { - if (track_filter.has(ET->get())) { - continue; } } else { - if (!track_filter.has(ET->get())) continue; } @@ -1581,9 +1439,7 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones int xform_idx = -1; for (int j = 0; j < cn->xform_list.size(); j++) { - if (cn->xform_list[j].id == at.param) { - xform_idx = j; break; } @@ -1623,10 +1479,8 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones //make bone transform relative to rest (in case of skeleton) Skeleton3D *sk = Object::cast_to(nm.node); if (sk) { - xform = sk->get_bone_rest(nm.bone).affine_inverse() * xform; } else { - ERR_PRINT("Collada: Invalid skeleton"); } } @@ -1652,10 +1506,8 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones } if (p_make_tracks_in_all_bones) { - //some bones may lack animation, but since we don't store pose as a property, we must add keyframes! for (Map::Element *E = bones_with_animation.front(); E; E = E->next()) { - if (E->get()) continue; @@ -1695,15 +1547,12 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones if (p_import_value_tracks) { for (int i = 0; i < valid_animated_properties.size(); i++) { - int ti = valid_animated_properties[i]; if (p_clip == -1) { - if (track_filter.has(ti)) continue; } else { - if (!track_filter.has(ti)) continue; } @@ -1725,7 +1574,6 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones animation->track_set_imported(track, true); //helps merging later for (int j = 0; j < at.keys.size(); j++) { - float time = at.keys[j].time; Variant value; Vector data = at.keys[j].data; @@ -1748,7 +1596,6 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones } if (tracks_found) { - animations.push_back(animation); } } @@ -1758,15 +1605,12 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones /*********************************************************************************/ uint32_t EditorSceneImporterCollada::get_import_flags() const { - return IMPORT_SCENE | IMPORT_ANIMATION; } void EditorSceneImporterCollada::get_extensions(List *r_extensions) const { - r_extensions->push_back("dae"); } Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List *r_missing_deps, Error *r_err) { - ColladaImport state; uint32_t flags = Collada::IMPORT_FLAG_SCENE; if (p_flags & IMPORT_ANIMATION) @@ -1780,7 +1624,6 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_ ERR_FAIL_COND_V_MSG(err != OK, nullptr, "Cannot load scene from file '" + p_path + "'."); if (state.missing_textures.size()) { - /* for(int i=0;ipush_back(state.missing_textures[i]); @@ -1797,7 +1639,6 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_ } if (p_flags & IMPORT_ANIMATION) { - state.create_animations(p_flags & IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS, p_flags & EditorSceneImporter::IMPORT_ANIMATION_KEEP_VALUE_TRACKS); AnimationPlayer *ap = memnew(AnimationPlayer); for (int i = 0; i < state.animations.size(); i++) { @@ -1808,7 +1649,6 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_ name = state.animations[i]->get_name(); if (p_flags & IMPORT_ANIMATION_DETECT_LOOP) { - if (name.begins_with("loop") || name.ends_with("loop") || name.begins_with("cycle") || name.ends_with("cycle")) { state.animations.write[i]->set_loop(true); } @@ -1824,7 +1664,6 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_ } Ref EditorSceneImporterCollada::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) { - ColladaImport state; state.use_mesh_builtin_materials = false; @@ -1841,7 +1680,6 @@ Ref EditorSceneImporterCollada::import_animation(const String &p_path Ref anim = state.animations[0]; String base = p_path.get_basename().to_lower(); if (p_flags & IMPORT_ANIMATION_DETECT_LOOP) { - if (base.begins_with("loop") || base.ends_with("loop") || base.begins_with("cycle") || base.ends_with("cycle")) { anim->set_loop(true); } diff --git a/editor/import/editor_import_collada.h b/editor/import/editor_import_collada.h index 932a064e76..57c694b698 100644 --- a/editor/import/editor_import_collada.h +++ b/editor/import/editor_import_collada.h @@ -34,7 +34,6 @@ #include "editor/import/resource_importer_scene.h" class EditorSceneImporterCollada : public EditorSceneImporter { - GDCLASS(EditorSceneImporterCollada, EditorSceneImporter); public: diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp index aad378c94f..6d46d4d2e9 100644 --- a/editor/import/editor_import_plugin.cpp +++ b/editor/import/editor_import_plugin.cpp @@ -87,7 +87,6 @@ int EditorImportPlugin::get_import_order() const { } void EditorImportPlugin::get_import_options(List *r_options, int p_preset) const { - ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("get_import_options"))); Array needed; needed.push_back("name"); @@ -131,7 +130,6 @@ bool EditorImportPlugin::get_option_visibility(const String &p_option, const Map } Error EditorImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("import")), ERR_UNAVAILABLE); Dictionary options; Array platform_variants, gen_files; @@ -153,7 +151,6 @@ Error EditorImportPlugin::import(const String &p_source_file, const String &p_sa } void EditorImportPlugin::_bind_methods() { - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_importer_name")); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_visible_name")); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "get_preset_count")); diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 1a1e7171b9..c4bf9189f1 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -44,17 +44,14 @@ #include "scene/resources/surface_tool.h" uint32_t EditorSceneImporterGLTF::get_import_flags() const { - return IMPORT_SCENE | IMPORT_ANIMATION; } void EditorSceneImporterGLTF::get_extensions(List *r_extensions) const { - r_extensions->push_back("gltf"); r_extensions->push_back("glb"); } Error EditorSceneImporterGLTF::_parse_json(const String &p_path, GLTFState &state) { - Error err; FileAccessRef f = FileAccess::open(p_path, FileAccess::READ, &err); if (!f) { @@ -81,7 +78,6 @@ Error EditorSceneImporterGLTF::_parse_json(const String &p_path, GLTFState &stat } Error EditorSceneImporterGLTF::_parse_glb(const String &p_path, GLTFState &state) { - Error err; FileAccessRef f = FileAccess::open(p_path, FileAccess::READ, &err); if (!f) { @@ -163,7 +159,6 @@ String EditorSceneImporterGLTF::_sanitize_scene_name(const String &name) { } String EditorSceneImporterGLTF::_gen_unique_name(GLTFState &state, const String &p_name) { - const String s_name = _sanitize_scene_name(p_name); String name; @@ -204,7 +199,6 @@ String EditorSceneImporterGLTF::_sanitize_bone_name(const String &name) { } String EditorSceneImporterGLTF::_gen_unique_bone_name(GLTFState &state, const GLTFSkeletonIndex skel_i, const String &p_name) { - const String s_name = _sanitize_bone_name(p_name); String name; @@ -227,7 +221,6 @@ String EditorSceneImporterGLTF::_gen_unique_bone_name(GLTFState &state, const GL } Error EditorSceneImporterGLTF::_parse_scenes(GLTFState &state) { - ERR_FAIL_COND_V(!state.json.has("scenes"), ERR_FILE_CORRUPT); const Array &scenes = state.json["scenes"]; int loaded_scene = 0; @@ -257,11 +250,9 @@ Error EditorSceneImporterGLTF::_parse_scenes(GLTFState &state) { } Error EditorSceneImporterGLTF::_parse_nodes(GLTFState &state) { - ERR_FAIL_COND_V(!state.json.has("nodes"), ERR_FILE_CORRUPT); const Array &nodes = state.json["nodes"]; for (int i = 0; i < nodes.size(); i++) { - GLTFNode *node = memnew(GLTFNode); const Dictionary &n = nodes[i]; @@ -281,7 +272,6 @@ Error EditorSceneImporterGLTF::_parse_nodes(GLTFState &state) { node->xform = _arr_to_xform(n["matrix"]); } else { - if (n.has("translation")) { node->translation = _arr_to_vec3(n["translation"]); } @@ -308,7 +298,6 @@ Error EditorSceneImporterGLTF::_parse_nodes(GLTFState &state) { // build the hierarchy for (GLTFNodeIndex node_i = 0; node_i < state.nodes.size(); node_i++) { - for (int j = 0; j < state.nodes[node_i]->children.size(); j++) { GLTFNodeIndex child_i = state.nodes[node_i]->children[j]; @@ -325,7 +314,6 @@ Error EditorSceneImporterGLTF::_parse_nodes(GLTFState &state) { } void EditorSceneImporterGLTF::_compute_node_heights(GLTFState &state) { - state.root_nodes.clear(); for (GLTFNodeIndex node_i = 0; node_i < state.nodes.size(); ++node_i) { GLTFNode *node = state.nodes[node_i]; @@ -347,7 +335,6 @@ void EditorSceneImporterGLTF::_compute_node_heights(GLTFState &state) { } static Vector _parse_base64_uri(const String &uri) { - int start = uri.find(","); ERR_FAIL_COND_V(start == -1, Vector()); @@ -367,20 +354,17 @@ static Vector _parse_base64_uri(const String &uri) { } Error EditorSceneImporterGLTF::_parse_buffers(GLTFState &state, const String &p_base_path) { - if (!state.json.has("buffers")) return OK; const Array &buffers = state.json["buffers"]; for (GLTFBufferIndex i = 0; i < buffers.size(); i++) { - if (i == 0 && state.glb_data.size()) { state.buffers.push_back(state.glb_data); } else { const Dictionary &buffer = buffers[i]; if (buffer.has("uri")) { - Vector buffer_data; String uri = buffer["uri"]; @@ -388,7 +372,6 @@ Error EditorSceneImporterGLTF::_parse_buffers(GLTFState &state, const String &p_ //embedded data buffer_data = _parse_base64_uri(uri); } else { - uri = p_base_path.plus_file(uri).replace("\\", "/"); //fix for windows buffer_data = FileAccess::get_file_as_array(uri); ERR_FAIL_COND_V(buffer.size() == 0, ERR_PARSE_ERROR); @@ -408,11 +391,9 @@ Error EditorSceneImporterGLTF::_parse_buffers(GLTFState &state, const String &p_ } Error EditorSceneImporterGLTF::_parse_buffer_views(GLTFState &state) { - ERR_FAIL_COND_V(!state.json.has("bufferViews"), ERR_FILE_CORRUPT); const Array &buffers = state.json["bufferViews"]; for (GLTFBufferViewIndex i = 0; i < buffers.size(); i++) { - const Dictionary &d = buffers[i]; GLTFBufferView buffer_view; @@ -444,7 +425,6 @@ Error EditorSceneImporterGLTF::_parse_buffer_views(GLTFState &state) { } EditorSceneImporterGLTF::GLTFType EditorSceneImporterGLTF::_get_type_from_str(const String &p_string) { - if (p_string == "SCALAR") return TYPE_SCALAR; @@ -466,11 +446,9 @@ EditorSceneImporterGLTF::GLTFType EditorSceneImporterGLTF::_get_type_from_str(co } Error EditorSceneImporterGLTF::_parse_accessors(GLTFState &state) { - ERR_FAIL_COND_V(!state.json.has("accessors"), ERR_FILE_CORRUPT); const Array &accessors = state.json["accessors"]; for (GLTFAccessorIndex i = 0; i < accessors.size(); i++) { - const Dictionary &d = accessors[i]; GLTFAccessor accessor; @@ -536,7 +514,6 @@ Error EditorSceneImporterGLTF::_parse_accessors(GLTFState &state) { } String EditorSceneImporterGLTF::_get_component_type_name(const uint32_t p_component) { - switch (p_component) { case COMPONENT_TYPE_BYTE: return "Byte"; @@ -556,7 +533,6 @@ String EditorSceneImporterGLTF::_get_component_type_name(const uint32_t p_compon } String EditorSceneImporterGLTF::_get_type_name(const GLTFType p_component) { - static const char *names[] = { "float", "vec2", @@ -571,7 +547,6 @@ String EditorSceneImporterGLTF::_get_type_name(const GLTFType p_component) { } Error EditorSceneImporterGLTF::_decode_buffer_view(GLTFState &state, double *dst, const GLTFBufferViewIndex p_buffer_view, const int skip_every, const int skip_bytes, const int element_size, const int count, const GLTFType type, const int component_count, const int component_type, const int component_size, const bool normalized, const int byte_offset, const bool for_vertex) { - const GLTFBufferView &bv = state.buffer_views[p_buffer_view]; int stride = bv.byte_stride ? bv.byte_stride : element_size; @@ -597,11 +572,9 @@ Error EditorSceneImporterGLTF::_decode_buffer_view(GLTFState &state, double *dst //fill everything as doubles for (int i = 0; i < count; i++) { - const uint8_t *src = &bufptr[offset + i * stride]; for (int j = 0; j < component_count; j++) { - if (skip_every && j > 0 && (j % skip_every) == 0) { src += skip_bytes; } @@ -659,7 +632,6 @@ Error EditorSceneImporterGLTF::_decode_buffer_view(GLTFState &state, double *dst } int EditorSceneImporterGLTF::_get_component_type_size(const int component_type) { - switch (component_type) { case COMPONENT_TYPE_BYTE: return 1; @@ -687,7 +659,6 @@ int EditorSceneImporterGLTF::_get_component_type_size(const int component_type) } Vector EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - //spec, for reference: //https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#data-alignment @@ -710,7 +681,6 @@ Vector EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, const switch (a.component_type) { case COMPONENT_TYPE_BYTE: case COMPONENT_TYPE_UNSIGNED_BYTE: { - if (a.type == TYPE_MAT2) { skip_every = 2; skip_bytes = 2; @@ -740,7 +710,6 @@ Vector EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, const double *dst = dst_buffer.ptrw(); if (a.buffer_view >= 0) { - ERR_FAIL_INDEX_V(a.buffer_view, state.buffer_views.size(), Vector()); const Error err = _decode_buffer_view(state, dst, a.buffer_view, skip_every, skip_bytes, element_size, a.count, a.type, component_count, a.component_type, component_size, a.normalized, a.byte_offset, p_for_vertex); @@ -783,7 +752,6 @@ Vector EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, const } Vector EditorSceneImporterGLTF::_decode_accessor_as_ints(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; @@ -803,7 +771,6 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_ints(GLTFState &state, } Vector EditorSceneImporterGLTF::_decode_accessor_as_floats(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; @@ -823,7 +790,6 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_floats(GLTFState &sta } Vector EditorSceneImporterGLTF::_decode_accessor_as_vec2(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; @@ -844,7 +810,6 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_vec2(GLTFState &sta } Vector EditorSceneImporterGLTF::_decode_accessor_as_vec3(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; @@ -865,7 +830,6 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_vec3(GLTFState &sta } Vector EditorSceneImporterGLTF::_decode_accessor_as_color(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; @@ -893,7 +857,6 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_color(GLTFState &stat } Vector EditorSceneImporterGLTF::_decode_accessor_as_quat(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; @@ -912,7 +875,6 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_quat(GLTFState &state, return ret; } Vector EditorSceneImporterGLTF::_decode_accessor_as_xform2d(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; @@ -929,7 +891,6 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_xform2d(GLTFSta } Vector EditorSceneImporterGLTF::_decode_accessor_as_basis(GLTFState &state, const GLTFAccessorIndex p_accessor, bool p_for_vertex) { - const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; @@ -947,7 +908,6 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_basis(GLTFState &stat } Vector EditorSceneImporterGLTF::_decode_accessor_as_xform(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; @@ -966,13 +926,11 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_xform(GLTFState & } Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { - if (!state.json.has("meshes")) return OK; Array meshes = state.json["meshes"]; for (GLTFMeshIndex i = 0; i < meshes.size(); i++) { - print_verbose("glTF: Parsing mesh: " + itos(i)); Dictionary d = meshes[i]; @@ -985,7 +943,6 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { const Dictionary &extras = d.has("extras") ? (Dictionary)d["extras"] : Dictionary(); for (int j = 0; j < primitives.size(); j++) { - Dictionary p = primitives[j]; Array array; @@ -1123,7 +1080,6 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { } for (int k = 0; k < targets.size(); k++) { - const Dictionary &t = targets[k]; Array array_copy; @@ -1141,7 +1097,6 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { const int size = src_varr.size(); ERR_FAIL_COND_V(size == 0, ERR_PARSE_ERROR); { - const int max_idx = varr.size(); varr.resize(size); @@ -1188,7 +1143,6 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { Vector tangents_v4; { - int max_idx = tangents_v3.size(); int size4 = src_tangents.size(); @@ -1199,7 +1153,6 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { const float *r4 = src_tangents.ptr(); for (int l = 0; l < size4 / 4; l++) { - if (l < max_idx) { w4[l * 4 + 0] = r3[l].x + r4[l * 4 + 0]; w4[l * 4 + 1] = r3[l].y + r4[l * 4 + 1]; @@ -1259,13 +1212,11 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { } Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_base_path) { - if (!state.json.has("images")) return OK; const Array &images = state.json["images"]; for (int i = 0; i < images.size(); i++) { - const Dictionary &d = images[i]; String mimetype; @@ -1287,7 +1238,6 @@ Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_b data_ptr = data.ptr(); data_size = data.size(); } else { - uri = p_base_path.plus_file(uri).replace("\\", "/"); //fix for windows Ref texture = ResourceLoader::load(uri); state.images.push_back(texture); @@ -1355,13 +1305,11 @@ Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_b } Error EditorSceneImporterGLTF::_parse_textures(GLTFState &state) { - if (!state.json.has("textures")) return OK; const Array &textures = state.json["textures"]; for (GLTFTextureIndex i = 0; i < textures.size(); i++) { - const Dictionary &d = textures[i]; ERR_FAIL_COND_V(!d.has("source"), ERR_PARSE_ERROR); @@ -1384,13 +1332,11 @@ Ref EditorSceneImporterGLTF::_get_texture(GLTFState &state, const GLT } Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) { - if (!state.json.has("materials")) return OK; const Array &materials = state.json["materials"]; for (GLTFMaterialIndex i = 0; i < materials.size(); i++) { - const Dictionary &d = materials[i]; Ref material; @@ -1400,7 +1346,6 @@ Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) { } if (d.has("pbrMetallicRoughness")) { - const Dictionary &mr = d["pbrMetallicRoughness"]; if (mr.has("baseColorFactor")) { const Array &arr = mr["baseColorFactor"]; @@ -1534,7 +1479,6 @@ EditorSceneImporterGLTF::GLTFNodeIndex EditorSceneImporterGLTF::_find_highest_no } bool EditorSceneImporterGLTF::_capture_nodes_in_skin(GLTFState &state, GLTFSkin &skin, const GLTFNodeIndex node_index) { - bool found_joint = false; for (int i = 0; i < state.nodes[node_index]->children.size(); ++i) { @@ -1558,7 +1502,6 @@ bool EditorSceneImporterGLTF::_capture_nodes_in_skin(GLTFState &state, GLTFSkin } void EditorSceneImporterGLTF::_capture_nodes_for_multirooted_skin(GLTFState &state, GLTFSkin &skin) { - DisjointSet disjoint_set; for (int i = 0; i < skin.joints.size(); ++i) { @@ -1592,7 +1535,6 @@ void EditorSceneImporterGLTF::_capture_nodes_for_multirooted_skin(GLTFState &sta // Go up the tree till all of the multiple roots of the skin are at the same hierarchy level. // This sucks, but 99% of all game engines (not just Godot) would have this same issue. for (int i = 0; i < roots.size(); ++i) { - GLTFNodeIndex current_node = roots[i]; while (state.nodes[current_node]->height > maxHeight) { GLTFNodeIndex parent = state.nodes[current_node]->parent; @@ -1640,7 +1582,6 @@ void EditorSceneImporterGLTF::_capture_nodes_for_multirooted_skin(GLTFState &sta } Error EditorSceneImporterGLTF::_expand_skin(GLTFState &state, GLTFSkin &skin) { - _capture_nodes_for_multirooted_skin(state, skin); // Grab all nodes that lay in between skin joints/nodes @@ -1686,7 +1627,6 @@ Error EditorSceneImporterGLTF::_expand_skin(GLTFState &state, GLTFSkin &skin) { } Error EditorSceneImporterGLTF::_verify_skin(GLTFState &state, GLTFSkin &skin) { - // This may seem duplicated from expand_skins, but this is really a sanity check! (so it kinda is) // In case additional interpolating logic is added to the skins, this will help ensure that you // do not cause it to self implode into a fiery blaze @@ -1752,7 +1692,6 @@ Error EditorSceneImporterGLTF::_verify_skin(GLTFState &state, GLTFSkin &skin) { } Error EditorSceneImporterGLTF::_parse_skins(GLTFState &state) { - if (!state.json.has("skins")) return OK; @@ -1760,7 +1699,6 @@ Error EditorSceneImporterGLTF::_parse_skins(GLTFState &state) { // Create the base skins, and mark nodes that are joints for (int i = 0; i < skins.size(); i++) { - const Dictionary &d = skins[i]; GLTFSkin skin; @@ -1810,7 +1748,6 @@ Error EditorSceneImporterGLTF::_parse_skins(GLTFState &state) { } Error EditorSceneImporterGLTF::_determine_skeletons(GLTFState &state) { - // Using a disjoint set, we are going to potentially combine all skins that are actually branches // of a main skeleton, or treat skins defining the same set of nodes as ONE skeleton. // This is another unclear issue caused by the current glTF specification. @@ -1888,7 +1825,6 @@ Error EditorSceneImporterGLTF::_determine_skeletons(GLTFState &state) { // Mark all the skins actual skeletons, after we have merged them for (GLTFSkeletonIndex skel_i = 0; skel_i < skeleton_owners.size(); ++skel_i) { - const GLTFNodeIndex skeleton_owner = skeleton_owners[skel_i]; GLTFSkeleton skeleton; @@ -1943,7 +1879,6 @@ Error EditorSceneImporterGLTF::_determine_skeletons(GLTFState &state) { } Error EditorSceneImporterGLTF::_reparent_non_joint_skeleton_subtrees(GLTFState &state, GLTFSkeleton &skeleton, const Vector &non_joints) { - DisjointSet subtree_set; // Populate the disjoint set with ONLY non joints that are in the skeleton hierarchy (non_joints vector) @@ -2058,7 +1993,6 @@ Error EditorSceneImporterGLTF::_reparent_to_fake_joint(GLTFState &state, GLTFSke } Error EditorSceneImporterGLTF::_determine_skeleton_roots(GLTFState &state, const GLTFSkeletonIndex skel_i) { - DisjointSet disjoint_set; for (GLTFNodeIndex i = 0; i < state.nodes.size(); ++i) { @@ -2113,7 +2047,6 @@ Error EditorSceneImporterGLTF::_determine_skeleton_roots(GLTFState &state, const Error EditorSceneImporterGLTF::_create_skeletons(GLTFState &state) { for (GLTFSkeletonIndex skel_i = 0; skel_i < state.skeletons.size(); ++skel_i) { - GLTFSkeleton &gltf_skeleton = state.skeletons.write[skel_i]; Skeleton3D *skeleton = memnew(Skeleton3D); @@ -2214,7 +2147,6 @@ Error EditorSceneImporterGLTF::_create_skins(GLTFState &state) { const bool has_ibms = !gltf_skin.inverse_binds.empty(); for (int joint_i = 0; joint_i < gltf_skin.joints_original.size(); ++joint_i) { - Transform xform; if (has_ibms) { xform = gltf_skin.inverse_binds[joint_i]; @@ -2253,7 +2185,6 @@ bool EditorSceneImporterGLTF::_skins_are_same(const Ref &skin_a, const Ref } for (int i = 0; i < skin_a->get_bind_count(); ++i) { - if (skin_a->get_bind_bone(i) != skin_b->get_bind_bone(i)) { return false; } @@ -2284,21 +2215,18 @@ void EditorSceneImporterGLTF::_remove_duplicate_skins(GLTFState &state) { } Error EditorSceneImporterGLTF::_parse_cameras(GLTFState &state) { - if (!state.json.has("cameras")) return OK; const Array &cameras = state.json["cameras"]; for (GLTFCameraIndex i = 0; i < cameras.size(); i++) { - const Dictionary &d = cameras[i]; GLTFCamera camera; ERR_FAIL_COND_V(!d.has("type"), ERR_PARSE_ERROR); const String &type = d["type"]; if (type == "orthographic") { - camera.perspective = false; if (d.has("orthographic")) { const Dictionary &og = d["orthographic"]; @@ -2310,7 +2238,6 @@ Error EditorSceneImporterGLTF::_parse_cameras(GLTFState &state) { } } else if (type == "perspective") { - camera.perspective = true; if (d.has("perspective")) { const Dictionary &ppt = d["perspective"]; @@ -2334,14 +2261,12 @@ Error EditorSceneImporterGLTF::_parse_cameras(GLTFState &state) { } Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) { - if (!state.json.has("animations")) return OK; const Array &animations = state.json["animations"]; for (GLTFAnimationIndex i = 0; i < animations.size(); i++) { - const Dictionary &d = animations[i]; GLTFAnimation animation; @@ -2361,7 +2286,6 @@ Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) { } for (int j = 0; j < channels.size(); j++) { - const Dictionary &c = channels[j]; if (!c.has("target")) continue; @@ -2471,7 +2395,6 @@ Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) { } void EditorSceneImporterGLTF::_assign_scene_names(GLTFState &state) { - for (int i = 0; i < state.nodes.size(); i++) { GLTFNode *n = state.nodes[i]; @@ -2494,7 +2417,6 @@ void EditorSceneImporterGLTF::_assign_scene_names(GLTFState &state) { } BoneAttachment3D *EditorSceneImporterGLTF::_generate_bone_attachment(GLTFState &state, Skeleton3D *skeleton, const GLTFNodeIndex node_index) { - const GLTFNode *gltf_node = state.nodes[node_index]; const GLTFNode *bone_node = state.nodes[gltf_node->parent]; @@ -2558,7 +2480,6 @@ Node3D *EditorSceneImporterGLTF::_generate_spatial(GLTFState &state, Node *scene } void EditorSceneImporterGLTF::_generate_scene_node(GLTFState &state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index) { - const GLTFNode *gltf_node = state.nodes[node_index]; Node3D *current_node = nullptr; @@ -2623,14 +2544,11 @@ void EditorSceneImporterGLTF::_generate_scene_node(GLTFState &state, Node *scene template struct EditorSceneImporterGLTFInterpolate { - T lerp(const T &a, const T &b, float c) const { - return a + (b - a) * c; } T catmull_rom(const T &p0, const T &p1, const T &p2, const T &p3, float t) { - const float t2 = t * t; const float t3 = t2 * t; @@ -2652,7 +2570,6 @@ struct EditorSceneImporterGLTFInterpolate { // thank you for existing, partial specialization template <> struct EditorSceneImporterGLTFInterpolate { - Quat lerp(const Quat &a, const Quat &b, const float c) const { ERR_FAIL_COND_V_MSG(!a.is_normalized(), Quat(), "The quaternion \"a\" must be normalized."); ERR_FAIL_COND_V_MSG(!b.is_normalized(), Quat(), "The quaternion \"b\" must be normalized."); @@ -2677,7 +2594,6 @@ struct EditorSceneImporterGLTFInterpolate { template T EditorSceneImporterGLTF::_interpolate_track(const Vector &p_times, const Vector &p_values, const float p_time, const GLTFAnimation::Interpolation p_interp) { - //could use binary search, worth it? int idx = -1; for (int i = 0; i < p_times.size(); i++) { @@ -2690,7 +2606,6 @@ T EditorSceneImporterGLTF::_interpolate_track(const Vector &p_times, cons switch (p_interp) { case GLTFAnimation::INTERP_LINEAR: { - if (idx == -1) { return p_values[0]; } else if (idx >= p_times.size() - 1) { @@ -2703,7 +2618,6 @@ T EditorSceneImporterGLTF::_interpolate_track(const Vector &p_times, cons } break; case GLTFAnimation::INTERP_STEP: { - if (idx == -1) { return p_values[0]; } else if (idx >= p_times.size() - 1) { @@ -2714,7 +2628,6 @@ T EditorSceneImporterGLTF::_interpolate_track(const Vector &p_times, cons } break; case GLTFAnimation::INTERP_CATMULLROMSPLINE: { - if (idx == -1) { return p_values[1]; } else if (idx >= p_times.size() - 1) { @@ -2727,7 +2640,6 @@ T EditorSceneImporterGLTF::_interpolate_track(const Vector &p_times, cons } break; case GLTFAnimation::INTERP_CUBIC_SPLINE: { - if (idx == -1) { return p_values[1]; } else if (idx >= p_times.size() - 1) { @@ -2750,7 +2662,6 @@ T EditorSceneImporterGLTF::_interpolate_track(const Vector &p_times, cons } void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlayer *ap, const GLTFAnimationIndex index, const int bake_fps) { - const GLTFAnimation &anim = state.animations[index]; String name = anim.name; @@ -2770,7 +2681,6 @@ void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlaye float length = 0; for (Map::Element *E = anim.tracks.front(); E; E = E->next()) { - const GLTFAnimation::Track &track = E->get(); //need to find the path NodePath node_path; @@ -2838,7 +2748,6 @@ void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlaye bool last = false; while (true) { - Vector3 pos = base_pos; Quat rot = base_rot; Vector3 scale = base_scale; @@ -2856,7 +2765,6 @@ void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlaye } if (node->skeleton >= 0) { - Transform xform; xform.basis.set_quat_scale(rot, scale); xform.origin = pos; @@ -2958,7 +2866,6 @@ void EditorSceneImporterGLTF::_process_mesh_instances(GLTFState &state, Node3D * } Node3D *EditorSceneImporterGLTF::_generate_scene(GLTFState &state, const int p_bake_fps) { - Node3D *root = memnew(Node3D); // scene_name is already unique @@ -2985,7 +2892,6 @@ Node3D *EditorSceneImporterGLTF::_generate_scene(GLTFState &state, const int p_b } Node *EditorSceneImporterGLTF::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List *r_missing_deps, Error *r_err) { - GLTFState state; if (p_path.to_lower().ends_with("glb")) { @@ -3098,7 +3004,6 @@ Node *EditorSceneImporterGLTF::import_scene(const String &p_path, uint32_t p_fla } Ref EditorSceneImporterGLTF::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) { - return Ref(); } diff --git a/editor/import/editor_scene_importer_gltf.h b/editor/import/editor_scene_importer_gltf.h index 86d7e627a3..eee978ce16 100644 --- a/editor/import/editor_scene_importer_gltf.h +++ b/editor/import/editor_scene_importer_gltf.h @@ -40,7 +40,6 @@ class BoneAttachment3D; class MeshInstance3D; class EditorSceneImporterGLTF : public EditorSceneImporter { - GDCLASS(EditorSceneImporterGLTF, EditorSceneImporter); typedef int GLTFAccessorIndex; @@ -92,7 +91,6 @@ class EditorSceneImporterGLTF : public EditorSceneImporter { String _get_type_name(const GLTFType p_component); struct GLTFNode { - //matrices need to be transformed to this GLTFNodeIndex parent = -1; int height = -1; @@ -119,7 +117,6 @@ class EditorSceneImporterGLTF : public EditorSceneImporter { }; struct GLTFBufferView { - GLTFBufferIndex buffer = -1; int byte_offset = 0; int byte_length = 0; @@ -131,7 +128,6 @@ class EditorSceneImporterGLTF : public EditorSceneImporter { }; struct GLTFAccessor { - GLTFBufferViewIndex buffer_view = 0; int byte_offset = 0; int component_type = 0; @@ -214,7 +210,6 @@ class EditorSceneImporterGLTF : public EditorSceneImporter { }; struct GLTFCamera { - bool perspective = true; float fov_size = 64; float zfar = 500; @@ -241,7 +236,6 @@ class EditorSceneImporterGLTF : public EditorSceneImporter { }; struct Track { - Channel translation_track; Channel rotation_track; Channel scale_track; @@ -254,7 +248,6 @@ class EditorSceneImporterGLTF : public EditorSceneImporter { }; struct GLTFState { - Dictionary json; int major_version; int minor_version; diff --git a/editor/import/resource_importer_bitmask.cpp b/editor/import/resource_importer_bitmask.cpp index 252af9050b..05a3bfc386 100644 --- a/editor/import/resource_importer_bitmask.cpp +++ b/editor/import/resource_importer_bitmask.cpp @@ -38,16 +38,13 @@ #include "scene/resources/texture.h" String ResourceImporterBitMap::get_importer_name() const { - return "bitmap"; } String ResourceImporterBitMap::get_visible_name() const { - return "BitMap"; } void ResourceImporterBitMap::get_recognized_extensions(List *p_extensions) const { - ImageLoader::get_recognized_extensions(p_extensions); } String ResourceImporterBitMap::get_save_extension() const { @@ -55,12 +52,10 @@ String ResourceImporterBitMap::get_save_extension() const { } String ResourceImporterBitMap::get_resource_type() const { - return "BitMap"; } bool ResourceImporterBitMap::get_option_visibility(const String &p_option, const Map &p_options) const { - return true; } @@ -68,18 +63,15 @@ int ResourceImporterBitMap::get_preset_count() const { return 0; } String ResourceImporterBitMap::get_preset_name(int p_idx) const { - return String(); } void ResourceImporterBitMap::get_import_options(List *r_options, int p_preset) const { - r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "create_from", PROPERTY_HINT_ENUM, "Black & White,Alpha"), 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "threshold", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.5)); } Error ResourceImporterBitMap::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { - int create_from = p_options["create_from"]; float threshold = p_options["threshold"]; Ref image; @@ -97,7 +89,6 @@ Error ResourceImporterBitMap::import(const String &p_source_file, const String & for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { - bool bit; Color c = image->get_pixel(j, i); if (create_from == 0) { //b&W diff --git a/editor/import/resource_importer_csv.cpp b/editor/import/resource_importer_csv.cpp index 424f90bd54..e56cb1d3a1 100644 --- a/editor/import/resource_importer_csv.cpp +++ b/editor/import/resource_importer_csv.cpp @@ -34,16 +34,13 @@ #include "core/os/file_access.h" String ResourceImporterCSV::get_importer_name() const { - return "csv"; } String ResourceImporterCSV::get_visible_name() const { - return "CSV"; } void ResourceImporterCSV::get_recognized_extensions(List *p_extensions) const { - p_extensions->push_back("csv"); } @@ -52,12 +49,10 @@ String ResourceImporterCSV::get_save_extension() const { } String ResourceImporterCSV::get_resource_type() const { - return "TextFile"; } bool ResourceImporterCSV::get_option_visibility(const String &p_option, const Map &p_options) const { - return true; } @@ -65,7 +60,6 @@ int ResourceImporterCSV::get_preset_count() const { return 0; } String ResourceImporterCSV::get_preset_name(int p_idx) const { - return ""; } diff --git a/editor/import/resource_importer_csv_translation.cpp b/editor/import/resource_importer_csv_translation.cpp index 9d72396449..09f2d691f0 100644 --- a/editor/import/resource_importer_csv_translation.cpp +++ b/editor/import/resource_importer_csv_translation.cpp @@ -36,16 +36,13 @@ #include "core/translation.h" String ResourceImporterCSVTranslation::get_importer_name() const { - return "csv_translation"; } String ResourceImporterCSVTranslation::get_visible_name() const { - return "CSV Translation"; } void ResourceImporterCSVTranslation::get_recognized_extensions(List *p_extensions) const { - p_extensions->push_back("csv"); } @@ -54,12 +51,10 @@ String ResourceImporterCSVTranslation::get_save_extension() const { } String ResourceImporterCSVTranslation::get_resource_type() const { - return "Translation"; } bool ResourceImporterCSVTranslation::get_option_visibility(const String &p_option, const Map &p_options) const { - return true; } @@ -67,18 +62,15 @@ int ResourceImporterCSVTranslation::get_preset_count() const { return 0; } String ResourceImporterCSVTranslation::get_preset_name(int p_idx) const { - return ""; } void ResourceImporterCSVTranslation::get_import_options(List *r_options, int p_preset) const { - r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress"), true)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "delimiter", PROPERTY_HINT_ENUM, "Comma,Semicolon,Tab"), 0)); } Error ResourceImporterCSVTranslation::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { - bool compress = p_options["compress"]; String delimiter; @@ -105,7 +97,6 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const Vector> translations; for (int i = 1; i < line.size(); i++) { - String locale = line[i]; ERR_FAIL_COND_V_MSG(!TranslationServer::is_locale_valid(locale), ERR_PARSE_ERROR, "Error importing CSV translation: '" + locale + "' is not a valid locale."); @@ -119,10 +110,8 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const line = f->get_csv_line(delimiter); while (line.size() == locales.size() + 1) { - String key = line[0]; if (key != "") { - for (int i = 1; i < line.size(); i++) { translations.write[i - 1]->add_message(key, line[i].c_unescape()); } diff --git a/editor/import/resource_importer_image.cpp b/editor/import/resource_importer_image.cpp index a1f5a79b00..927d911e94 100644 --- a/editor/import/resource_importer_image.cpp +++ b/editor/import/resource_importer_image.cpp @@ -36,16 +36,13 @@ #include "scene/resources/texture.h" String ResourceImporterImage::get_importer_name() const { - return "image"; } String ResourceImporterImage::get_visible_name() const { - return "Image"; } void ResourceImporterImage::get_recognized_extensions(List *p_extensions) const { - ImageLoader::get_recognized_extensions(p_extensions); } @@ -54,12 +51,10 @@ String ResourceImporterImage::get_save_extension() const { } String ResourceImporterImage::get_resource_type() const { - return "Image"; } bool ResourceImporterImage::get_option_visibility(const String &p_option, const Map &p_options) const { - return true; } @@ -67,7 +62,6 @@ int ResourceImporterImage::get_preset_count() const { return 0; } String ResourceImporterImage::get_preset_name(int p_idx) const { - return String(); } @@ -75,7 +69,6 @@ void ResourceImporterImage::get_import_options(List *r_options, in } Error ResourceImporterImage::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { - FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ); ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open file from path '" + p_source_file + "'."); diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp index c46cf4c1a8..18c6dc149b 100644 --- a/editor/import/resource_importer_layered_texture.cpp +++ b/editor/import/resource_importer_layered_texture.cpp @@ -40,7 +40,6 @@ #include "scene/resources/texture.h" String ResourceImporterLayeredTexture::get_importer_name() const { - switch (mode) { case MODE_CUBEMAP: { return "cubemap_texture"; @@ -60,7 +59,6 @@ String ResourceImporterLayeredTexture::get_importer_name() const { } String ResourceImporterLayeredTexture::get_visible_name() const { - switch (mode) { case MODE_CUBEMAP: { return "Cubemap"; @@ -79,7 +77,6 @@ String ResourceImporterLayeredTexture::get_visible_name() const { ERR_FAIL_V(""); } void ResourceImporterLayeredTexture::get_recognized_extensions(List *p_extensions) const { - ImageLoader::get_recognized_extensions(p_extensions); } String ResourceImporterLayeredTexture::get_save_extension() const { @@ -102,7 +99,6 @@ String ResourceImporterLayeredTexture::get_save_extension() const { } String ResourceImporterLayeredTexture::get_resource_type() const { - switch (mode) { case MODE_CUBEMAP: { return "StreamCubemap"; @@ -121,7 +117,6 @@ String ResourceImporterLayeredTexture::get_resource_type() const { } bool ResourceImporterLayeredTexture::get_option_visibility(const String &p_option, const Map &p_options) const { - if (p_option == "compress/lossy_quality" && p_options.has("compress/mode")) { return int(p_options["compress/mode"]) == COMPRESS_LOSSY; } @@ -132,12 +127,10 @@ int ResourceImporterLayeredTexture::get_preset_count() const { return 0; } String ResourceImporterLayeredTexture::get_preset_name(int p_idx) const { - return ""; } void ResourceImporterLayeredTexture::get_import_options(List *r_options, int p_preset) const { - r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/mode", PROPERTY_HINT_ENUM, "Lossless,Lossy,Video RAM,Uncompressed,Basis Universal", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 1)); r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "compress/lossy_quality", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.7)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/hdr_compression", PROPERTY_HINT_ENUM, "Disabled,Opaque Only,Always"), 1)); @@ -160,9 +153,7 @@ void ResourceImporterLayeredTexture::get_import_options(List *r_op } void ResourceImporterLayeredTexture::_save_tex(Vector> p_images, const String &p_to_path, int p_compress_mode, float p_lossy, Image::CompressMode p_vram_compression, Image::CompressSource p_csource, Image::UsedChannels used_channels, bool p_mipmaps, bool p_force_po2) { - for (int i = 0; i < p_images.size(); i++) { - if (p_force_po2) { p_images.write[i]->resize_to_po2(); } @@ -199,7 +190,6 @@ void ResourceImporterLayeredTexture::_save_tex(Vector> p_images, cons } Error ResourceImporterLayeredTexture::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { - int compress_mode = p_options["compress/mode"]; float lossy = p_options["compress/lossy_quality"]; int hdr_compression = p_options["compress/hdr_compression"]; @@ -315,7 +305,6 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const bool can_compress_hdr = hdr_compression > 0; if (is_hdr && can_compress_hdr) { - if (used_channels == Image::USED_CHANNELS_LA || used_channels == Image::USED_CHANNELS_RGBA) { //can compress hdr, but hdr with alpha is not compressible @@ -337,9 +326,7 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const } if (can_compress_hdr) { - if (!can_bptc) { - //default to rgbe if (image->get_format() != Image::FORMAT_RGBE9995) { for (int i = 0; i < slices.size(); i++) { @@ -366,14 +353,12 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2")) { - _save_tex(slices, p_save_path + ".etc2." + extension, compress_mode, lossy, Image::COMPRESS_ETC2, csource, used_channels, mipmaps, true); r_platform_variants->push_back("etc2"); formats_imported.push_back("etc2"); } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc")) { - _save_tex(slices, p_save_path + ".etc2." + extension, compress_mode, lossy, Image::COMPRESS_ETC2, csource, used_channels, mipmaps, true); r_platform_variants->push_back("pvrtc"); formats_imported.push_back("pvrtc"); @@ -408,7 +393,6 @@ const char *ResourceImporterLayeredTexture::compression_formats[] = { nullptr }; String ResourceImporterLayeredTexture::get_import_settings_string() const { - String s; int index = 0; @@ -425,7 +409,6 @@ String ResourceImporterLayeredTexture::get_import_settings_string() const { } bool ResourceImporterLayeredTexture::are_import_settings_valid(const String &p_path) const { - //will become invalid if formats are missing to import Dictionary metadata = ResourceFormatImporter::get_singleton()->get_resource_metadata(p_path); @@ -463,7 +446,6 @@ bool ResourceImporterLayeredTexture::are_import_settings_valid(const String &p_p ResourceImporterLayeredTexture *ResourceImporterLayeredTexture::singleton = nullptr; ResourceImporterLayeredTexture::ResourceImporterLayeredTexture() { - singleton = this; mode = MODE_CUBEMAP; } diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 6a6eadfa5c..73150c8516 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -38,12 +38,10 @@ #include "scene/resources/surface_tool.h" uint32_t EditorOBJImporter::get_import_flags() const { - return IMPORT_SCENE; } static Error _parse_material_library(const String &p_path, Map> &material_map, List *r_missing_deps) { - FileAccessRef f = FileAccess::open(p_path, FileAccess::READ); ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, vformat("Couldn't open MTL file '%s', it may not exist or not be readable.", p_path)); @@ -51,7 +49,6 @@ static Error _parse_material_library(const String &p_path, Mapget_line().strip_edges(); if (l.begins_with("newmtl ")) { @@ -204,7 +201,6 @@ static Error _parse_material_library(const String &p_path, Map> &r_meshes, bool p_single_mesh, bool p_generate_tangents, bool p_optimize, Vector3 p_scale_mesh, Vector3 p_offset_mesh, List *r_missing_deps) { - FileAccessRef f = FileAccess::open(p_path, FileAccess::READ); ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, vformat("Couldn't open OBJ file '%s', it may not exist or not be readable.", p_path)); @@ -231,7 +227,6 @@ static Error _parse_obj(const String &p_path, List> &r_meshes, bool p_ String current_group; while (true) { - String l = f->get_line().strip_edges(); while (l.length() && l[l.length() - 1] == '\\') { String add = f->get_line().strip_edges(); @@ -283,12 +278,10 @@ static Error _parse_obj(const String &p_path, List> &r_meshes, bool p_ ERR_FAIL_COND_V(face[0].size() != face[1].size(), ERR_FILE_CORRUPT); for (int i = 2; i < v.size() - 1; i++) { - face[2] = v[i + 1].split("/"); ERR_FAIL_COND_V(face[0].size() != face[2].size(), ERR_FILE_CORRUPT); for (int j = 0; j < 3; j++) { - int idx = j; if (idx < 2) { @@ -365,7 +358,6 @@ static Error _parse_obj(const String &p_path, List> &r_meshes, bool p_ } if (l.begins_with("o ") || f->eof_reached()) { - if (!p_single_mesh) { mesh->set_name(name); r_meshes.push_back(mesh); @@ -384,12 +376,10 @@ static Error _parse_obj(const String &p_path, List> &r_meshes, bool p_ } if (l.begins_with("usemtl ")) { - current_material = l.replace("usemtl", "").strip_edges(); } if (l.begins_with("g ")) { - current_group = l.substr(2, l.length()).strip_edges(); } @@ -411,7 +401,6 @@ static Error _parse_obj(const String &p_path, List> &r_meshes, bool p_ } if (p_single_mesh) { - r_meshes.push_back(mesh); } @@ -419,7 +408,6 @@ static Error _parse_obj(const String &p_path, List> &r_meshes, bool p_ } Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List *r_missing_deps, Error *r_err) { - List> meshes; Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, p_flags & IMPORT_USE_COMPRESSION, Vector3(1, 1, 1), Vector3(0, 0, 0), r_missing_deps); @@ -434,7 +422,6 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in Node3D *scene = memnew(Node3D); for (List>::Element *E = meshes.front(); E; E = E->next()) { - MeshInstance3D *mi = memnew(MeshInstance3D); mi->set_mesh(E->get()); mi->set_name(E->get()->get_name()); @@ -449,12 +436,10 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in return scene; } Ref EditorOBJImporter::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) { - return Ref(); } void EditorOBJImporter::get_extensions(List *r_extensions) const { - r_extensions->push_back("obj"); } @@ -469,7 +454,6 @@ String ResourceImporterOBJ::get_visible_name() const { return "OBJ As Mesh"; } void ResourceImporterOBJ::get_recognized_extensions(List *p_extensions) const { - p_extensions->push_back("obj"); } String ResourceImporterOBJ::get_save_extension() const { @@ -487,19 +471,16 @@ String ResourceImporterOBJ::get_preset_name(int p_idx) const { } void ResourceImporterOBJ::get_import_options(List *r_options, int p_preset) const { - r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "generate_tangents"), true)); r_options->push_back(ImportOption(PropertyInfo(Variant::VECTOR3, "scale_mesh"), Vector3(1, 1, 1))); r_options->push_back(ImportOption(PropertyInfo(Variant::VECTOR3, "offset_mesh"), Vector3(0, 0, 0))); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "optimize_mesh"), true)); } bool ResourceImporterOBJ::get_option_visibility(const String &p_option, const Map &p_options) const { - return true; } Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { - List> meshes; Error err = _parse_obj(p_source_file, meshes, true, p_options["generate_tangents"], p_options["optimize_mesh"], p_options["scale_mesh"], p_options["offset_mesh"], nullptr); diff --git a/editor/import/resource_importer_obj.h b/editor/import/resource_importer_obj.h index 7485e60f7b..aec5de3dcc 100644 --- a/editor/import/resource_importer_obj.h +++ b/editor/import/resource_importer_obj.h @@ -34,7 +34,6 @@ #include "resource_importer_scene.h" class EditorOBJImporter : public EditorSceneImporter { - GDCLASS(EditorOBJImporter, EditorSceneImporter); public: diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 37941109a1..012e3e95a7 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -47,7 +47,6 @@ #include "scene/resources/world_margin_shape_3d.h" uint32_t EditorSceneImporter::get_import_flags() const { - if (get_script_instance()) { return get_script_instance()->call("_get_import_flags"); } @@ -55,7 +54,6 @@ uint32_t EditorSceneImporter::get_import_flags() const { ERR_FAIL_V(0); } void EditorSceneImporter::get_extensions(List *r_extensions) const { - if (get_script_instance()) { Array arr = get_script_instance()->call("_get_extensions"); for (int i = 0; i < arr.size(); i++) { @@ -67,7 +65,6 @@ void EditorSceneImporter::get_extensions(List *r_extensions) const { ERR_FAIL(); } Node *EditorSceneImporter::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List *r_missing_deps, Error *r_err) { - if (get_script_instance()) { return get_script_instance()->call("_import_scene", p_path, p_flags, p_bake_fps); } @@ -76,7 +73,6 @@ Node *EditorSceneImporter::import_scene(const String &p_path, uint32_t p_flags, } Ref EditorSceneImporter::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) { - if (get_script_instance()) { return get_script_instance()->call("_import_animation", p_path, p_flags); } @@ -88,17 +84,14 @@ Ref EditorSceneImporter::import_animation(const String &p_path, uint3 //and you want to load the resulting file Node *EditorSceneImporter::import_scene_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps) { - return ResourceImporterScene::get_singleton()->import_scene_from_other_importer(this, p_path, p_flags, p_bake_fps); } Ref EditorSceneImporter::import_animation_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps) { - return ResourceImporterScene::get_singleton()->import_animation_from_other_importer(this, p_path, p_flags, p_bake_fps); } void EditorSceneImporter::_bind_methods() { - ClassDB::bind_method(D_METHOD("import_scene_from_other_importer", "path", "flags", "bake_fps"), &EditorSceneImporter::import_scene_from_other_importer); ClassDB::bind_method(D_METHOD("import_animation_from_other_importer", "path", "flags", "bake_fps"), &EditorSceneImporter::import_animation_from_other_importer); @@ -126,14 +119,12 @@ void EditorSceneImporter::_bind_methods() { ///////////////////////////////// void EditorScenePostImport::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::OBJECT, "post_import", PropertyInfo(Variant::OBJECT, "scene"))); ClassDB::bind_method(D_METHOD("get_source_folder"), &EditorScenePostImport::get_source_folder); ClassDB::bind_method(D_METHOD("get_source_file"), &EditorScenePostImport::get_source_file); } Node *EditorScenePostImport::post_import(Node *p_scene) { - if (get_script_instance()) return get_script_instance()->call("post_import", p_scene); @@ -141,12 +132,10 @@ Node *EditorScenePostImport::post_import(Node *p_scene) { } String EditorScenePostImport::get_source_folder() const { - return source_folder; } String EditorScenePostImport::get_source_file() const { - return source_file; } @@ -159,17 +148,14 @@ EditorScenePostImport::EditorScenePostImport() { } String ResourceImporterScene::get_importer_name() const { - return "scene"; } String ResourceImporterScene::get_visible_name() const { - return "Scene"; } void ResourceImporterScene::get_recognized_extensions(List *p_extensions) const { - for (Set>::Element *E = importers.front(); E; E = E->next()) { E->get()->get_extensions(p_extensions); } @@ -180,12 +166,10 @@ String ResourceImporterScene::get_save_extension() const { } String ResourceImporterScene::get_resource_type() const { - return "PackedScene"; } bool ResourceImporterScene::get_option_visibility(const String &p_option, const Map &p_options) const { - if (p_option.begins_with("animation/")) { if (p_option != "animation/import" && !bool(p_options["animation/import"])) return false; @@ -219,7 +203,6 @@ int ResourceImporterScene::get_preset_count() const { return PRESET_MAX; } String ResourceImporterScene::get_preset_name(int p_idx) const { - switch (p_idx) { case PRESET_SINGLE_SCENE: return TTR("Import as Single Scene"); @@ -247,12 +230,10 @@ String ResourceImporterScene::get_preset_name(int p_idx) const { } static bool _teststr(const String &p_what, const String &p_str) { - String what = p_what; //remove trailing spaces and numbers, some apps like blender add ".number" to duplicates so also compensate for this while (what.length() && ((what[what.length() - 1] >= '0' && what[what.length() - 1] <= '9') || what[what.length() - 1] <= 32 || what[what.length() - 1] == '.')) { - what = what.substr(0, what.length() - 1); } @@ -266,12 +247,10 @@ static bool _teststr(const String &p_what, const String &p_str) { } static String _fixstr(const String &p_what, const String &p_str) { - String what = p_what; //remove trailing spaces and numbers, some apps like blender add ".number" to duplicates so also compensate for this while (what.length() && ((what[what.length() - 1] >= '0' && what[what.length() - 1] <= '9') || what[what.length() - 1] <= 32 || what[what.length() - 1] == '.')) { - what = what.substr(0, what.length() - 1); } @@ -287,13 +266,10 @@ static String _fixstr(const String &p_what, const String &p_str) { } static void _gen_shape_list(const Ref &mesh, List> &r_shape_list, bool p_convex) { - if (!p_convex) { - Ref shape = mesh->create_trimesh_shape(); r_shape_list.push_back(shape); } else { - Vector> cd = mesh->convex_decompose(); if (cd.size()) { for (int i = 0; i < cd.size(); i++) { @@ -304,10 +280,8 @@ static void _gen_shape_list(const Ref &mesh, List> &r_shape_l } Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map, List>> &collision_map, LightBakeMode p_light_bake_mode) { - // children first for (int i = 0; i < p_node->get_child_count(); i++) { - Node *r = _fix_node(p_node->get_child(i), p_root, collision_map, p_light_bake_mode); if (!r) { i--; //was erased @@ -319,32 +293,26 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map bool isroot = p_node == p_root; if (!isroot && _teststr(name, "noimp")) { - memdelete(p_node); return nullptr; } if (Object::cast_to(p_node)) { - MeshInstance3D *mi = Object::cast_to(p_node); Ref m = mi->get_mesh(); if (m.is_valid()) { - for (int i = 0; i < m->get_surface_count(); i++) { - Ref mat = m->surface_get_material(i); if (!mat.is_valid()) continue; if (_teststr(mat->get_name(), "alpha")) { - mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); mat->set_name(_fixstr(mat->get_name(), "alpha")); } if (_teststr(mat->get_name(), "vcol")) { - mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); mat->set_name(_fixstr(mat->get_name(), "vcol")); @@ -353,7 +321,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map } if (p_light_bake_mode != LIGHT_BAKE_DISABLED) { - mi->set_gi_mode(GeometryInstance3D::GI_MODE_BAKED); } } @@ -365,7 +332,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map List anims; ap->get_animation_list(&anims); for (List::Element *E = anims.front(); E; E = E->next()) { - Ref anim = ap->get_animation(E->get()); ERR_CONTINUE(anim.is_null()); for (int i = 0; i < anim->get_track_count(); i++) { @@ -384,7 +350,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map } if (_teststr(name, "colonly") || _teststr(name, "convcolonly")) { - if (isroot) return p_node; MeshInstance3D *mi = Object::cast_to(p_node); @@ -413,7 +378,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map ERR_FAIL_COND_V(fixed_name == String(), nullptr); if (shapes.size()) { - StaticBody3D *col = memnew(StaticBody3D); col->set_transform(mi->get_transform()); col->set_name(fixed_name); @@ -423,7 +387,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map int idx = 0; for (List>::Element *E = shapes.front(); E; E = E->next()) { - CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(E->get()); col->add_child(cshape); @@ -470,7 +433,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map } } else if (_teststr(name, "rigid") && Object::cast_to(p_node)) { - if (isroot) return p_node; @@ -497,7 +459,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map int idx = 0; for (List>::Element *E = shapes.front(); E; E = E->next()) { - CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(E->get()); rigid_body->add_child(cshape); @@ -509,7 +470,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map } } else if ((_teststr(name, "col") || (_teststr(name, "convcol"))) && Object::cast_to(p_node)) { - MeshInstance3D *mi = Object::cast_to(p_node); Ref mesh = mi->get_mesh(); @@ -547,7 +507,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map int idx = 0; for (List>::Element *E = shapes.front(); E; E = E->next()) { - CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(E->get()); col->add_child(cshape); @@ -561,7 +520,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map } } else if (_teststr(name, "navmesh") && Object::cast_to(p_node)) { - if (isroot) return p_node; @@ -580,7 +538,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map memdelete(p_node); p_node = nmi; } else if (_teststr(name, "vehicle")) { - if (isroot) return p_node; @@ -600,7 +557,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map p_node = bv; } else if (_teststr(name, "wheel")) { - if (isroot) return p_node; @@ -620,14 +576,12 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map p_node = bv; } else if (Object::cast_to(p_node)) { - //last attempt, maybe collision inside the mesh data MeshInstance3D *mi = Object::cast_to(p_node); Ref mesh = mi->get_mesh(); if (!mesh.is_null()) { - List> shapes; if (collision_map.has(mesh)) { shapes = collision_map[mesh]; @@ -649,7 +603,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map int idx = 0; for (List>::Element *E = shapes.front(); E; E = E->next()) { - CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(E->get()); col->add_child(cshape); @@ -666,7 +619,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map } void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, bool p_bake_all) { - if (!scene->has_node(String("AnimationPlayer"))) return; @@ -681,7 +633,6 @@ void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, boo Ref default_anim = anim->get_animation("default"); for (int i = 0; i < p_clips.size(); i += 4) { - String name = p_clips[i]; float from = p_clips[i + 1]; float to = p_clips[i + 2]; @@ -692,15 +643,12 @@ void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, boo Ref new_anim = memnew(Animation); for (int j = 0; j < default_anim->get_track_count(); j++) { - List keys; int kc = default_anim->track_get_key_count(j); int dtrack = -1; for (int k = 0; k < kc; k++) { - float kt = default_anim->track_get_key_time(j, k); if (kt >= from && kt < to) { - //found a key within range, so create track if (dtrack == -1) { new_anim->add_track(default_anim->track_get_type(j)); @@ -708,7 +656,6 @@ void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, boo new_anim->track_set_path(dtrack, default_anim->track_get_path(j)); if (kt > (from + 0.01) && k > 0) { - if (default_anim->track_get_type(j) == Animation::TYPE_TRANSFORM) { Quat q; Vector3 p; @@ -737,7 +684,6 @@ void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, boo } if (dtrack != -1 && kt >= to) { - if (default_anim->track_get_type(j) == Animation::TYPE_TRANSFORM) { Quat q; Vector3 p; @@ -757,7 +703,6 @@ void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, boo dtrack = new_anim->get_track_count() - 1; new_anim->track_set_path(dtrack, default_anim->track_get_path(j)); if (default_anim->track_get_type(j) == Animation::TYPE_TRANSFORM) { - Quat q; Vector3 p; Vector3 s; @@ -784,12 +729,10 @@ void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, boo } void ResourceImporterScene::_filter_anim_tracks(Ref anim, Set &keep) { - Ref a = anim; ERR_FAIL_COND(!a.is_valid()); for (int j = 0; j < a->get_track_count(); j++) { - String path = a->track_get_path(j); if (!keep.has(path)) { @@ -800,7 +743,6 @@ void ResourceImporterScene::_filter_anim_tracks(Ref anim, Set } void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { - if (!scene->has_node(String("AnimationPlayer"))) return; Node *n = scene->get_node(String("AnimationPlayer")); @@ -810,14 +752,12 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { Vector strings = p_text.split("\n"); for (int i = 0; i < strings.size(); i++) { - strings.write[i] = strings[i].strip_edges(); } List anim_names; anim->get_animation_list(&anim_names); for (List::Element *E = anim_names.front(); E; E = E->next()) { - String name = E->get(); bool valid_for_this = false; bool valid = false; @@ -826,9 +766,7 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { Set keep_local; for (int i = 0; i < strings.size(); i++) { - if (strings[i].begins_with("@")) { - valid_for_this = false; for (Set::Element *F = keep_local.front(); F; F = F->next()) { keep.insert(F->get()); @@ -837,7 +775,6 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { Vector filters = strings[i].substr(1, strings[i].length()).split(","); for (int j = 0; j < filters.size(); j++) { - String fname = filters[j].strip_edges(); if (fname == "") continue; @@ -861,13 +798,11 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { valid = true; } else if (valid_for_this) { - Ref a = anim->get_animation(name); if (!a.is_valid()) continue; for (int j = 0; j < a->get_track_count(); j++) { - String path = a->track_get_path(j); String tname = strings[i]; @@ -906,7 +841,6 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { } void ResourceImporterScene::_optimize_animations(Node *scene, float p_max_lin_error, float p_max_ang_error, float p_max_angle) { - if (!scene->has_node(String("AnimationPlayer"))) return; Node *n = scene->get_node(String("AnimationPlayer")); @@ -917,14 +851,12 @@ void ResourceImporterScene::_optimize_animations(Node *scene, float p_max_lin_er List anim_names; anim->get_animation_list(&anim_names); for (List::Element *E = anim_names.front(); E; E = E->next()) { - Ref a = anim->get_animation(E->get()); a->optimize(p_max_lin_error, p_max_ang_error, Math::deg2rad(p_max_angle)); } } static String _make_extname(const String &p_str) { - String ext_name = p_str.replace(".", "_"); ext_name = ext_name.replace(":", "_"); ext_name = ext_name.replace("\"", "_"); @@ -940,14 +872,12 @@ static String _make_extname(const String &p_str) { } void ResourceImporterScene::_find_meshes(Node *p_node, Map, Transform> &meshes) { - List pi; p_node->get_property_list(&pi); MeshInstance3D *mi = Object::cast_to(p_node); if (mi) { - Ref mesh = mi->get_mesh(); if (mesh.is_valid() && !meshes.has(mesh)) { @@ -962,13 +892,11 @@ void ResourceImporterScene::_find_meshes(Node *p_node, Map, Trans } } for (int i = 0; i < p_node->get_child_count(); i++) { - _find_meshes(p_node->get_child(i), meshes); } } void ResourceImporterScene::_make_external_resources(Node *p_node, const String &p_base_path, bool p_make_animations, bool p_animations_as_text, bool p_keep_animations, bool p_make_materials, bool p_materials_as_text, bool p_keep_materials, bool p_make_meshes, bool p_meshes_as_text, Map, Ref> &p_animations, Map, Ref> &p_materials, Map, Ref> &p_meshes) { - List pi; if (p_make_animations) { @@ -978,12 +906,10 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String List anims; ap->get_animation_list(&anims); for (List::Element *E = anims.front(); E; E = E->next()) { - Ref anim = ap->get_animation(E->get()); ERR_CONTINUE(anim.is_null()); if (!p_animations.has(anim)) { - //mark what comes from the file first, this helps eventually keep user data for (int i = 0; i < anim->get_track_count(); i++) { anim->track_set_imported(i, true); @@ -1022,15 +948,11 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String p_node->get_property_list(&pi); for (List::Element *E = pi.front(); E; E = E->next()) { - if (E->get().type == Variant::OBJECT) { - Ref mat = p_node->get(E->get().name); if (p_make_materials && mat.is_valid() && mat->get_name() != "") { - if (!p_materials.has(mat)) { - String ext_name; if (p_materials_as_text) { @@ -1043,28 +965,22 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String //if exists, use it p_materials[mat] = ResourceLoader::load(ext_name); } else { - ResourceSaver::save(ext_name, mat, ResourceSaver::FLAG_CHANGE_PATH); p_materials[mat] = ResourceLoader::load(ext_name, "", true); // disable loading from the cache. } } if (p_materials[mat] != mat) { - p_node->set(E->get().name, p_materials[mat]); } } else { - Ref mesh = p_node->get(E->get().name); if (mesh.is_valid()) { - bool mesh_just_added = false; if (p_make_meshes) { - if (!p_meshes.has(mesh)) { - //meshes are always overwritten, keeping them is not practical String ext_name; @@ -1082,9 +998,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String } if (p_make_materials) { - if (mesh_just_added || !p_meshes.has(mesh)) { - for (int i = 0; i < mesh->get_surface_count(); i++) { mat = mesh->surface_get_material(i); @@ -1106,19 +1020,16 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String //if exists, use it p_materials[mat] = ResourceLoader::load(ext_name); } else { - ResourceSaver::save(ext_name, mat, ResourceSaver::FLAG_CHANGE_PATH); p_materials[mat] = ResourceLoader::load(ext_name, "", true); // disable loading from the cache. } } if (p_materials[mat] != mat) { - mesh->surface_set_material(i, p_materials[mat]); //re-save the mesh since a material is now assigned if (p_make_meshes) { - String ext_name; if (p_meshes_as_text) { @@ -1144,13 +1055,11 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String } for (int i = 0; i < p_node->get_child_count(); i++) { - _make_external_resources(p_node->get_child(i), p_base_path, p_make_animations, p_animations_as_text, p_keep_animations, p_make_materials, p_materials_as_text, p_keep_materials, p_make_meshes, p_meshes_as_text, p_animations, p_materials, p_meshes); } } void ResourceImporterScene::get_import_options(List *r_options, int p_preset) const { - r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "nodes/root_type", PROPERTY_HINT_TYPE_STRING, "Node"), "Node3D")); r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "nodes/root_name"), "Scene Root")); @@ -1203,7 +1112,6 @@ void ResourceImporterScene::get_import_options(List *r_options, in } void ResourceImporterScene::_replace_owner(Node *p_node, Node *p_scene, Node *p_new_owner) { - if (p_node != p_new_owner && p_node->get_owner() == p_scene) { p_node->set_owner(p_new_owner); } @@ -1215,21 +1123,17 @@ void ResourceImporterScene::_replace_owner(Node *p_node, Node *p_scene, Node *p_ } Node *ResourceImporterScene::import_scene_from_other_importer(EditorSceneImporter *p_exception, const String &p_path, uint32_t p_flags, int p_bake_fps) { - Ref importer; String ext = p_path.get_extension().to_lower(); for (Set>::Element *E = importers.front(); E; E = E->next()) { - if (E->get().ptr() == p_exception) continue; List extensions; E->get()->get_extensions(&extensions); for (List::Element *F = extensions.front(); F; F = F->next()) { - if (F->get().to_lower() == ext) { - importer = E->get(); break; } @@ -1247,21 +1151,17 @@ Node *ResourceImporterScene::import_scene_from_other_importer(EditorSceneImporte } Ref ResourceImporterScene::import_animation_from_other_importer(EditorSceneImporter *p_exception, const String &p_path, uint32_t p_flags, int p_bake_fps) { - Ref importer; String ext = p_path.get_extension().to_lower(); for (Set>::Element *E = importers.front(); E; E = E->next()) { - if (E->get().ptr() == p_exception) continue; List extensions; E->get()->get_extensions(&extensions); for (List::Element *F = extensions.front(); F; F = F->next()) { - if (F->get().to_lower() == ext) { - importer = E->get(); break; } @@ -1277,7 +1177,6 @@ Ref ResourceImporterScene::import_animation_from_other_importer(Edito } Error ResourceImporterScene::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { - const String &src_path = p_source_file; Ref importer; @@ -1287,14 +1186,11 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p progress.step(TTR("Importing Scene..."), 0); for (Set>::Element *E = importers.front(); E; E = E->next()) { - List extensions; E->get()->get_extensions(&extensions); for (List::Element *F = extensions.front(); F; F = F->next()) { - if (F->get().to_lower() == ext) { - importer = E->get(); break; } @@ -1347,7 +1243,6 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p Node *base_node = Object::cast_to(ClassDB::instance(root_type)); if (base_node) { - scene->replace_by(base_node); memdelete(scene); scene = base_node; @@ -1389,7 +1284,6 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p Array animation_clips; { - int clip_count = p_options["animation/clips/amount"]; for (int i = 0; i < clip_count; i++) { @@ -1424,7 +1318,6 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p String base_path = p_source_file.get_base_dir(); if (external_animations || external_materials || external_meshes || external_scenes) { - if (bool(p_options["external_files/store_in_subdir"])) { String subdir_name = p_source_file.get_file().get_basename(); DirAccess *da = DirAccess::open(base_path); @@ -1436,7 +1329,6 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p } if (light_bake_mode == 2 /* || generate LOD */) { - Map, Transform> meshes; _find_meshes(scene, meshes); @@ -1467,7 +1359,6 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p EditorProgress progress2("gen_lightmaps", TTR("Generating Lightmaps"), meshes.size()); int step = 0; for (Map, Transform>::Element *E = meshes.front(); E; E = E->next()) { - Ref mesh = E->key(); String name = mesh->get_name(); if (name == "") { //should not happen but.. @@ -1484,7 +1375,6 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p if (err2 != OK) { EditorNode::add_io_error("Mesh '" + name + "' failed lightmap generation. Please fix geometry."); } else { - String hash = String::md5((unsigned char *)ret_cache_data); used_unwraps.insert(hash, ret_cache_size); @@ -1515,7 +1405,6 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p if (file) memdelete(file); } else { - // Store number of entries file->store_32(used_unwraps.size()); @@ -1567,7 +1456,6 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p if (!scr.is_valid()) { EditorNode::add_io_error(TTR("Couldn't load post-import script:") + " " + post_import_script_path); } else { - post_import_script = Ref(memnew(EditorScenePostImport)); post_import_script->set_script(scr); if (!post_import_script->get_script_instance()) { @@ -1641,7 +1529,6 @@ void EditorSceneImporterESCN::get_extensions(List *r_extensions) const { r_extensions->push_back("escn"); } Node *EditorSceneImporterESCN::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List *r_missing_deps, Error *r_err) { - Error error; Ref ps = ResourceFormatLoaderText::singleton->load(p_path, p_path, &error); ERR_FAIL_COND_V_MSG(!ps.is_valid(), nullptr, "Cannot load scene as text resource from path '" + p_path + "'."); diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h index f48f181951..34d96bbc44 100644 --- a/editor/import/resource_importer_scene.h +++ b/editor/import/resource_importer_scene.h @@ -39,7 +39,6 @@ class Material; class EditorSceneImporter : public Reference { - GDCLASS(EditorSceneImporter, Reference); protected: @@ -73,7 +72,6 @@ public: }; class EditorScenePostImport : public Reference { - GDCLASS(EditorScenePostImport, Reference); String source_folder; diff --git a/editor/import/resource_importer_shader_file.cpp b/editor/import/resource_importer_shader_file.cpp index f085341969..0813bca6f1 100644 --- a/editor/import/resource_importer_shader_file.cpp +++ b/editor/import/resource_importer_shader_file.cpp @@ -38,16 +38,13 @@ #include "servers/rendering/rendering_device_binds.h" String ResourceImporterShaderFile::get_importer_name() const { - return "glsl"; } String ResourceImporterShaderFile::get_visible_name() const { - return "GLSL Shader File"; } void ResourceImporterShaderFile::get_recognized_extensions(List *p_extensions) const { - p_extensions->push_back("glsl"); } String ResourceImporterShaderFile::get_save_extension() const { @@ -55,7 +52,6 @@ String ResourceImporterShaderFile::get_save_extension() const { } String ResourceImporterShaderFile::get_resource_type() const { - return "RDShaderFile"; } @@ -63,7 +59,6 @@ int ResourceImporterShaderFile::get_preset_count() const { return 0; } String ResourceImporterShaderFile::get_preset_name(int p_idx) const { - return String(); } @@ -91,7 +86,6 @@ static String _include_function(const String &p_path, void *userpointer) { } Error ResourceImporterShaderFile::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { - /* STEP 1, Read shader code */ Error err; diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index 111eab78b4..aeeae36f5b 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -37,7 +37,6 @@ #include "editor/editor_node.h" void ResourceImporterTexture::_texture_reimport_roughness(const Ref &p_tex, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_channel) { - MutexLock lock(singleton->mutex); StringName path = p_tex->get_path(); @@ -52,7 +51,6 @@ void ResourceImporterTexture::_texture_reimport_roughness(const Ref &p_tex) { - MutexLock lock(singleton->mutex); StringName path = p_tex->get_path(); @@ -65,7 +63,6 @@ void ResourceImporterTexture::_texture_reimport_3d(const Ref &p } void ResourceImporterTexture::_texture_reimport_normal(const Ref &p_tex) { - MutexLock lock(singleton->mutex); StringName path = p_tex->get_path(); @@ -78,7 +75,6 @@ void ResourceImporterTexture::_texture_reimport_normal(const Refis_scanning() || EditorFileSystem::get_singleton()->is_importing()) { return; // do nothing for now } @@ -91,7 +87,6 @@ void ResourceImporterTexture::update_imports() { } for (Map::Element *E = make_flags.front(); E; E = E->next()) { - Ref cf; cf.instance(); String src_path = String(E->key()) + ".import"; @@ -139,16 +134,13 @@ void ResourceImporterTexture::update_imports() { } String ResourceImporterTexture::get_importer_name() const { - return "texture"; } String ResourceImporterTexture::get_visible_name() const { - return "Texture2D"; } void ResourceImporterTexture::get_recognized_extensions(List *p_extensions) const { - ImageLoader::get_recognized_extensions(p_extensions); } String ResourceImporterTexture::get_save_extension() const { @@ -156,12 +148,10 @@ String ResourceImporterTexture::get_save_extension() const { } String ResourceImporterTexture::get_resource_type() const { - return "StreamTexture2D"; } bool ResourceImporterTexture::get_option_visibility(const String &p_option, const Map &p_options) const { - if (p_option == "compress/lossy_quality") { int compress_mode = int(p_options["compress/mode"]); if (compress_mode != COMPRESS_LOSSY && compress_mode != COMPRESS_VRAM_COMPRESSED) { @@ -192,7 +182,6 @@ int ResourceImporterTexture::get_preset_count() const { return 4; } String ResourceImporterTexture::get_preset_name(int p_idx) const { - static const char *preset_names[] = { "2D, Detect 3D", "2D", @@ -204,7 +193,6 @@ String ResourceImporterTexture::get_preset_name(int p_idx) const { } void ResourceImporterTexture::get_import_options(List *r_options, int p_preset) const { - r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/mode", PROPERTY_HINT_ENUM, "Lossless,Lossy,VRAM Compressed,VRAM Uncompressed,Basis Universal", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), p_preset == PRESET_3D ? 2 : 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "compress/lossy_quality", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.7)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/hdr_compression", PROPERTY_HINT_ENUM, "Disabled,Opaque Only,Always"), 1)); @@ -226,10 +214,8 @@ void ResourceImporterTexture::get_import_options(List *r_options, } void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref &p_image, CompressMode p_compress_mode, Image::UsedChannels p_channels, Image::CompressMode p_compress_format, float p_lossy_quality) { - switch (p_compress_mode) { case COMPRESS_LOSSLESS: { - f->store_32(StreamTexture2D::DATA_FORMAT_LOSSLESS); f->store_16(p_image->get_width()); f->store_16(p_image->get_height()); @@ -237,7 +223,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Refstore_32(p_image->get_format()); for (int i = 0; i < p_image->get_mipmap_count() + 1; i++) { - Vector data = Image::lossless_packer(p_image->get_image_from_mipmap(i)); int data_len = data.size(); f->store_32(data_len); @@ -248,7 +233,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Refstore_32(StreamTexture2D::DATA_FORMAT_LOSSY); f->store_16(p_image->get_width()); f->store_16(p_image->get_height()); @@ -256,7 +240,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Refstore_32(p_image->get_format()); for (int i = 0; i < p_image->get_mipmap_count() + 1; i++) { - Vector data = Image::lossy_packer(p_image->get_image_from_mipmap(i), p_lossy_quality); int data_len = data.size(); f->store_32(data_len); @@ -266,7 +249,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref image = p_image->duplicate(); image->compress_from_channels(p_compress_format, p_channels, p_lossy_quality); @@ -283,7 +265,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Refstore_buffer(r, dl); } break; case COMPRESS_VRAM_UNCOMPRESSED: { - f->store_32(StreamTexture2D::DATA_FORMAT_IMAGE); f->store_16(p_image->get_width()); f->store_16(p_image->get_height()); @@ -298,7 +279,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Refstore_32(StreamTexture2D::DATA_FORMAT_BASIS_UNIVERSAL); f->store_16(p_image->get_width()); f->store_16(p_image->get_height()); @@ -306,7 +286,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Refstore_32(p_image->get_format()); for (int i = 0; i < p_image->get_mipmap_count() + 1; i++) { - Vector data = Image::basis_universal_packer(p_image->get_image_from_mipmap(i), p_channels); int data_len = data.size(); f->store_32(data_len); @@ -319,7 +298,6 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref &p_image, const String &p_to_path, CompressMode p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, bool p_streamable, bool p_detect_3d, bool p_detect_roughness, bool p_detect_normal, bool p_force_normal, bool p_srgb_friendly, bool p_force_po2_for_compressed, uint32_t p_limit_mipmap, const Ref &p_normal, Image::RoughnessChannel p_roughness_channel) { - FileAccess *f = FileAccess::open(p_to_path, FileAccess::WRITE); f->store_8('G'); f->store_8('S'); @@ -396,7 +374,6 @@ void ResourceImporterTexture::_save_stex(const Ref &p_image, const String } Error ResourceImporterTexture::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { - CompressMode compress_mode = CompressMode(int(p_options["compress/mode"])); float lossy = p_options["compress/lossy_quality"]; int pack_channels = p_options["compress/channel_pack"]; @@ -440,7 +417,6 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String image->resize(new_width, new_height, Image::INTERPOLATE_CUBIC); } else { - int new_height = size_limit; int new_width = image->get_width() * new_height / image->get_height(); @@ -501,7 +477,6 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String bool has_alpha = image->detect_alpha() != Image::ALPHA_NONE; if (is_hdr && can_compress_hdr) { - if (has_alpha) { //can compress hdr, but hdr with alpha is not compressible if (hdr_compression == 2) { @@ -542,7 +517,6 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2")) { - _save_stex(image, p_save_path + ".etc2.stex", compress_mode, lossy, Image::COMPRESS_ETC2, mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, true, mipmap_limit, normal_image, roughness_channel); r_platform_variants->push_back("etc2"); formats_imported.push_back("etc2"); @@ -555,7 +529,6 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc")) { - _save_stex(image, p_save_path + ".pvrtc.stex", compress_mode, lossy, Image::COMPRESS_PVRTC4, mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, true, mipmap_limit, normal_image, roughness_channel); r_platform_variants->push_back("pvrtc"); formats_imported.push_back("pvrtc"); @@ -589,7 +562,6 @@ const char *ResourceImporterTexture::compression_formats[] = { nullptr }; String ResourceImporterTexture::get_import_settings_string() const { - String s; int index = 0; @@ -606,7 +578,6 @@ String ResourceImporterTexture::get_import_settings_string() const { } bool ResourceImporterTexture::are_import_settings_valid(const String &p_path) const { - //will become invalid if formats are missing to import Dictionary metadata = ResourceFormatImporter::get_singleton()->get_resource_metadata(p_path); @@ -644,7 +615,6 @@ bool ResourceImporterTexture::are_import_settings_valid(const String &p_path) co ResourceImporterTexture *ResourceImporterTexture::singleton = nullptr; ResourceImporterTexture::ResourceImporterTexture() { - singleton = this; StreamTexture2D::request_3d_callback = _texture_reimport_3d; StreamTexture2D::request_roughness_callback = _texture_reimport_roughness; diff --git a/editor/import/resource_importer_texture.h b/editor/import/resource_importer_texture.h index da8ce3c0a8..b770d240eb 100644 --- a/editor/import/resource_importer_texture.h +++ b/editor/import/resource_importer_texture.h @@ -60,7 +60,6 @@ protected: Mutex mutex; struct MakeInfo { - int flags; String normal_path_for_roughness; RS::TextureDetectRoughnessChannel channel_for_roughness; diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp index 2765bb7fae..314c27b8e4 100644 --- a/editor/import/resource_importer_texture_atlas.cpp +++ b/editor/import/resource_importer_texture_atlas.cpp @@ -39,16 +39,13 @@ #include "scene/resources/texture.h" String ResourceImporterTextureAtlas::get_importer_name() const { - return "texture_atlas"; } String ResourceImporterTextureAtlas::get_visible_name() const { - return "TextureAtlas"; } void ResourceImporterTextureAtlas::get_recognized_extensions(List *p_extensions) const { - ImageLoader::get_recognized_extensions(p_extensions); } @@ -57,12 +54,10 @@ String ResourceImporterTextureAtlas::get_save_extension() const { } String ResourceImporterTextureAtlas::get_resource_type() const { - return "Texture2D"; } bool ResourceImporterTextureAtlas::get_option_visibility(const String &p_option, const Map &p_options) const { - return true; } @@ -70,12 +65,10 @@ int ResourceImporterTextureAtlas::get_preset_count() const { return 0; } String ResourceImporterTextureAtlas::get_preset_name(int p_idx) const { - return String(); } void ResourceImporterTextureAtlas::get_import_options(List *r_options, int p_preset) const { - r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "atlas_file", PROPERTY_HINT_SAVE_FILE, "*.png"), "")); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "import_mode", PROPERTY_HINT_ENUM, "Region,Mesh2D"), 0)); } @@ -85,7 +78,6 @@ String ResourceImporterTextureAtlas::get_option_group_file() const { } Error ResourceImporterTextureAtlas::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { - /* If this happens, it's because the atlas_file field was not filled, so just import a broken texture */ //use an xpm because it's size independent, the editor images are vector and size dependent @@ -103,7 +95,6 @@ Error ResourceImporterTextureAtlas::import(const String &p_source_file, const St } static void _plot_triangle(Vector2 *vertices, const Vector2 &p_offset, bool p_transposed, Ref p_image, const Ref &p_src_image) { - int width = p_image->get_width(); int height = p_image->get_height(); int src_width = p_src_image->get_width(); @@ -113,7 +104,6 @@ static void _plot_triangle(Vector2 *vertices, const Vector2 &p_offset, bool p_tr int y[3]; for (int j = 0; j < 3; j++) { - x[j] = vertices[j].x; y[j] = vertices[j].y; } @@ -140,7 +130,6 @@ static void _plot_triangle(Vector2 *vertices, const Vector2 &p_offset, bool p_tr for (int yi = y[0]; yi <= (y[2] > height - 1 ? height - 1 : y[2]); yi++) { if (yi >= 0) { for (int xi = (xf > 0 ? int(xf) : 0); xi <= (xt < width ? xt : width - 1); xi++) { - int px = xi, py = yi; int sx = px, sy = py; sx = CLAMP(sx, 0, src_width - 1); @@ -193,7 +182,6 @@ static void _plot_triangle(Vector2 *vertices, const Vector2 &p_offset, bool p_tr } Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file, const Map> &p_source_file_options, const Map &p_base_paths) { - ERR_FAIL_COND_V(p_source_file_options.size() == 0, ERR_BUG); //should never happen Vector charts; @@ -203,7 +191,6 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file int idx = 0; for (const Map>::Element *E = p_source_file_options.front(); E; E = E->next(), idx++) { - PackData &pack_data = pack_data_files.write[idx]; const String &source = E->key(); const Map &options = E->get(); @@ -218,7 +205,6 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file int mode = options["import_mode"]; if (mode == IMPORT_MODE_REGION) { - pack_data.is_mesh = false; EditorAtlasPacker::Chart chart; @@ -254,14 +240,12 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file Vector> polygons = bit_map->clip_opaque_to_polygons(Rect2(0, 0, image->get_width(), image->get_height())); for (int j = 0; j < polygons.size(); j++) { - EditorAtlasPacker::Chart chart; chart.vertices = polygons[j]; chart.can_transpose = true; Vector poly = Geometry::triangulate_polygon(polygons[j]); for (int i = 0; i < poly.size(); i += 3) { - EditorAtlasPacker::Chart::Face f; f.vertex[0] = poly[i + 0]; f.vertex[1] = poly[i + 1]; @@ -287,7 +271,6 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file new_atlas->create(atlas_width, atlas_height, false, Image::FORMAT_RGBA8); for (int i = 0; i < pack_data_files.size(); i++) { - PackData &pack_data = pack_data_files.write[i]; for (int j = 0; j < pack_data.chart_pieces.size(); j++) { @@ -324,7 +307,6 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file //save the images idx = 0; for (const Map>::Element *E = p_source_file_options.front(); E; E = E->next(), idx++) { - PackData &pack_data = pack_data_files.write[idx]; Ref texture; diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index 71f81051bc..3ffc7b34af 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -39,16 +39,13 @@ const float TRIM_DB_LIMIT = -50; const int TRIM_FADE_OUT_FRAMES = 500; String ResourceImporterWAV::get_importer_name() const { - return "wav"; } String ResourceImporterWAV::get_visible_name() const { - return "Microsoft WAV"; } void ResourceImporterWAV::get_recognized_extensions(List *p_extensions) const { - p_extensions->push_back("wav"); } String ResourceImporterWAV::get_save_extension() const { @@ -56,12 +53,10 @@ String ResourceImporterWAV::get_save_extension() const { } String ResourceImporterWAV::get_resource_type() const { - return "AudioStreamSample"; } bool ResourceImporterWAV::get_option_visibility(const String &p_option, const Map &p_options) const { - if (p_option == "force/max_rate_hz" && !bool(p_options["force/max_rate"])) { return false; } @@ -73,12 +68,10 @@ int ResourceImporterWAV::get_preset_count() const { return 0; } String ResourceImporterWAV::get_preset_name(int p_idx) const { - return String(); } void ResourceImporterWAV::get_import_options(List *r_options, int p_preset) const { - r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "force/8_bit"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "force/mono"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "force/max_rate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false)); @@ -90,7 +83,6 @@ void ResourceImporterWAV::get_import_options(List *r_options, int } Error ResourceImporterWAV::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { - /* STEP 1, READ WAVE FILE */ Error err; @@ -104,7 +96,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s file->get_buffer((uint8_t *)&riff, 4); //RIFF if (riff[0] != 'R' || riff[1] != 'I' || riff[2] != 'F' || riff[3] != 'F') { - file->close(); memdelete(file); ERR_FAIL_V(ERR_FILE_UNRECOGNIZED); @@ -120,7 +111,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s file->get_buffer((uint8_t *)&wave, 4); //RIFF if (wave[0] != 'W' || wave[1] != 'A' || wave[2] != 'V' || wave[3] != 'E') { - file->close(); memdelete(file); ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Not a WAV file (no WAVE RIFF header)."); @@ -141,7 +131,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s Vector data; while (!file->eof_reached()) { - /* chunk */ char chunkID[4]; file->get_buffer((uint8_t *)&chunkID, 4); //RIFF @@ -151,7 +140,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s uint32_t file_pos = file->get_position(); //save file pos, so we can skip to next chunk safely if (file->eof_reached()) { - //ERR_PRINT("EOF REACH"); break; } @@ -242,7 +230,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s uint32_t s = 0; for (int b = 0; b < (format_bits >> 3); b++) { - s |= ((uint32_t)file->get_8()) << (b * 8); } s <<= (32 - format_bits); @@ -322,12 +309,10 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s Vector new_data; new_data.resize(new_data_frames * format_channels); for (int c = 0; c < format_channels; c++) { - float frac = .0f; int ipos = 0; for (int i = 0; i < new_data_frames; i++) { - //simple cubic interpolation should be enough. float mu = frac; @@ -370,20 +355,16 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s bool normalize = p_options["edit/normalize"]; if (normalize) { - float max = 0; for (int i = 0; i < data.size(); i++) { - float amp = Math::abs(data[i]); if (amp > max) max = amp; } if (max > 0) { - float mult = 1.0 / max; for (int i = 0; i < data.size(); i++) { - data.write[i] *= mult; } } @@ -392,7 +373,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s bool trim = p_options["edit/trim"]; if (trim && !loop && format_channels > 0) { - int first = 0; int last = (frames / format_channels) - 1; bool found = false; @@ -420,7 +400,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s Vector new_data; new_data.resize((last - first) * format_channels); for (int i = first; i < last; i++) { - float fadeOutMult = 1; if (last - i < TRIM_FADE_OUT_FRAMES) { @@ -440,7 +419,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s bool make_loop = p_options["edit/loop"]; if (make_loop && !loop) { - loop = AudioStreamSample::LOOP_FORWARD; loop_begin = 0; loop_end = frames; @@ -450,7 +428,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s bool force_mono = p_options["force/mono"]; if (force_mono && format_channels == 2) { - Vector new_data; new_data.resize(data.size() / 2); for (int i = 0; i < frames; i++) { @@ -463,7 +440,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s bool force_8_bit = p_options["force/8_bit"]; if (force_8_bit) { - is16 = false; } @@ -471,12 +447,10 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s AudioStreamSample::Format dst_format; if (compression == 1) { - dst_format = AudioStreamSample::FORMAT_IMA_ADPCM; if (format_channels == 1) { _compress_ima_adpcm(data, dst_data); } else { - //byte interleave Vector left; Vector right; @@ -510,7 +484,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s } } else { - dst_format = is16 ? AudioStreamSample::FORMAT_16_BITS : AudioStreamSample::FORMAT_8_BITS; dst_data.resize(data.size() * (is16 ? 2 : 1)); { @@ -518,7 +491,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s int ds = data.size(); for (int i = 0; i < ds; i++) { - if (is16) { int16_t v = CLAMP(data[i] * 32768, -32768, 32767); encode_uint16(v, &w[i * 2]); diff --git a/editor/import/resource_importer_wav.h b/editor/import/resource_importer_wav.h index bc2f023e6b..b48c5f4c32 100644 --- a/editor/import/resource_importer_wav.h +++ b/editor/import/resource_importer_wav.h @@ -99,7 +99,6 @@ public: if (i >= datamax) xm_sample = 0; else { - xm_sample = CLAMP(in[i] * 32767.0, -32768, 32767); /* if (xm_sample==32767 || xm_sample==-32768) @@ -121,9 +120,7 @@ public: } mask = 4; while (mask) { - if (diff >= step) { - nibble |= mask; diff -= step; vpdiff += step; -- cgit v1.2.3 From 07bc4e2f96f8f47991339654ff4ab16acc19d44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 14:29:06 +0200 Subject: Style: Enforce separation line between function definitions I couldn't find a tool that enforces it, so I went the manual route: ``` find -name "thirdparty" -prune \ -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \ -o -name "*.glsl" > files perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files) misc/scripts/fix_style.sh -c ``` This adds a newline after all `}` on the first column, unless they are followed by `#` (typically `#endif`). This leads to having lots of places with two lines between function/class definitions, but clang-format then fixes it as we enforce max one line of separation. This doesn't fix potential occurrences of function definitions which are indented (e.g. for a helper class defined in a .cpp), but it's better than nothing. Also can't be made to run easily on CI/hooks so we'll have to be careful with new code. Part of #33027. --- editor/import/editor_import_collada.cpp | 2 ++ editor/import/editor_scene_importer_gltf.cpp | 2 ++ editor/import/resource_importer_bitmask.cpp | 3 +++ editor/import/resource_importer_csv.cpp | 2 ++ editor/import/resource_importer_csv_translation.cpp | 2 ++ editor/import/resource_importer_image.cpp | 2 ++ editor/import/resource_importer_layered_texture.cpp | 3 +++ editor/import/resource_importer_obj.cpp | 8 ++++++++ editor/import/resource_importer_scene.cpp | 7 +++++++ editor/import/resource_importer_shader_file.cpp | 4 ++++ editor/import/resource_importer_texture.cpp | 3 +++ editor/import/resource_importer_texture_atlas.cpp | 2 ++ editor/import/resource_importer_wav.cpp | 3 +++ 13 files changed, 43 insertions(+) (limited to 'editor/import') diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 0f3faf4189..54b4dc2972 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -1607,9 +1607,11 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones uint32_t EditorSceneImporterCollada::get_import_flags() const { return IMPORT_SCENE | IMPORT_ANIMATION; } + void EditorSceneImporterCollada::get_extensions(List *r_extensions) const { r_extensions->push_back("dae"); } + Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List *r_missing_deps, Error *r_err) { ColladaImport state; uint32_t flags = Collada::IMPORT_FLAG_SCENE; diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index c4bf9189f1..3c9f04322e 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -46,6 +46,7 @@ uint32_t EditorSceneImporterGLTF::get_import_flags() const { return IMPORT_SCENE | IMPORT_ANIMATION; } + void EditorSceneImporterGLTF::get_extensions(List *r_extensions) const { r_extensions->push_back("gltf"); r_extensions->push_back("glb"); @@ -874,6 +875,7 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_quat(GLTFState &state, } return ret; } + Vector EditorSceneImporterGLTF::_decode_accessor_as_xform2d(GLTFState &state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; diff --git a/editor/import/resource_importer_bitmask.cpp b/editor/import/resource_importer_bitmask.cpp index 05a3bfc386..5e52a95e4e 100644 --- a/editor/import/resource_importer_bitmask.cpp +++ b/editor/import/resource_importer_bitmask.cpp @@ -44,9 +44,11 @@ String ResourceImporterBitMap::get_importer_name() const { String ResourceImporterBitMap::get_visible_name() const { return "BitMap"; } + void ResourceImporterBitMap::get_recognized_extensions(List *p_extensions) const { ImageLoader::get_recognized_extensions(p_extensions); } + String ResourceImporterBitMap::get_save_extension() const { return "res"; } @@ -62,6 +64,7 @@ bool ResourceImporterBitMap::get_option_visibility(const String &p_option, const int ResourceImporterBitMap::get_preset_count() const { return 0; } + String ResourceImporterBitMap::get_preset_name(int p_idx) const { return String(); } diff --git a/editor/import/resource_importer_csv.cpp b/editor/import/resource_importer_csv.cpp index e56cb1d3a1..d29ba28a96 100644 --- a/editor/import/resource_importer_csv.cpp +++ b/editor/import/resource_importer_csv.cpp @@ -40,6 +40,7 @@ String ResourceImporterCSV::get_importer_name() const { String ResourceImporterCSV::get_visible_name() const { return "CSV"; } + void ResourceImporterCSV::get_recognized_extensions(List *p_extensions) const { p_extensions->push_back("csv"); } @@ -59,6 +60,7 @@ bool ResourceImporterCSV::get_option_visibility(const String &p_option, const Ma int ResourceImporterCSV::get_preset_count() const { return 0; } + String ResourceImporterCSV::get_preset_name(int p_idx) const { return ""; } diff --git a/editor/import/resource_importer_csv_translation.cpp b/editor/import/resource_importer_csv_translation.cpp index 09f2d691f0..04e20dee86 100644 --- a/editor/import/resource_importer_csv_translation.cpp +++ b/editor/import/resource_importer_csv_translation.cpp @@ -42,6 +42,7 @@ String ResourceImporterCSVTranslation::get_importer_name() const { String ResourceImporterCSVTranslation::get_visible_name() const { return "CSV Translation"; } + void ResourceImporterCSVTranslation::get_recognized_extensions(List *p_extensions) const { p_extensions->push_back("csv"); } @@ -61,6 +62,7 @@ bool ResourceImporterCSVTranslation::get_option_visibility(const String &p_optio int ResourceImporterCSVTranslation::get_preset_count() const { return 0; } + String ResourceImporterCSVTranslation::get_preset_name(int p_idx) const { return ""; } diff --git a/editor/import/resource_importer_image.cpp b/editor/import/resource_importer_image.cpp index 927d911e94..885b00865b 100644 --- a/editor/import/resource_importer_image.cpp +++ b/editor/import/resource_importer_image.cpp @@ -42,6 +42,7 @@ String ResourceImporterImage::get_importer_name() const { String ResourceImporterImage::get_visible_name() const { return "Image"; } + void ResourceImporterImage::get_recognized_extensions(List *p_extensions) const { ImageLoader::get_recognized_extensions(p_extensions); } @@ -61,6 +62,7 @@ bool ResourceImporterImage::get_option_visibility(const String &p_option, const int ResourceImporterImage::get_preset_count() const { return 0; } + String ResourceImporterImage::get_preset_name(int p_idx) const { return String(); } diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp index 18c6dc149b..2c9e7dcd3b 100644 --- a/editor/import/resource_importer_layered_texture.cpp +++ b/editor/import/resource_importer_layered_texture.cpp @@ -76,9 +76,11 @@ String ResourceImporterLayeredTexture::get_visible_name() const { ERR_FAIL_V(""); } + void ResourceImporterLayeredTexture::get_recognized_extensions(List *p_extensions) const { ImageLoader::get_recognized_extensions(p_extensions); } + String ResourceImporterLayeredTexture::get_save_extension() const { switch (mode) { case MODE_CUBEMAP: { @@ -126,6 +128,7 @@ bool ResourceImporterLayeredTexture::get_option_visibility(const String &p_optio int ResourceImporterLayeredTexture::get_preset_count() const { return 0; } + String ResourceImporterLayeredTexture::get_preset_name(int p_idx) const { return ""; } diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 73150c8516..4316a9b512 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -435,6 +435,7 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in return scene; } + Ref EditorOBJImporter::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) { return Ref(); } @@ -445,20 +446,25 @@ void EditorOBJImporter::get_extensions(List *r_extensions) const { EditorOBJImporter::EditorOBJImporter() { } + //////////////////////////////////////////////////// String ResourceImporterOBJ::get_importer_name() const { return "wavefront_obj"; } + String ResourceImporterOBJ::get_visible_name() const { return "OBJ As Mesh"; } + void ResourceImporterOBJ::get_recognized_extensions(List *p_extensions) const { p_extensions->push_back("obj"); } + String ResourceImporterOBJ::get_save_extension() const { return "mesh"; } + String ResourceImporterOBJ::get_resource_type() const { return "Mesh"; } @@ -466,6 +472,7 @@ String ResourceImporterOBJ::get_resource_type() const { int ResourceImporterOBJ::get_preset_count() const { return 0; } + String ResourceImporterOBJ::get_preset_name(int p_idx) const { return ""; } @@ -476,6 +483,7 @@ void ResourceImporterOBJ::get_import_options(List *r_options, int r_options->push_back(ImportOption(PropertyInfo(Variant::VECTOR3, "offset_mesh"), Vector3(0, 0, 0))); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "optimize_mesh"), true)); } + bool ResourceImporterOBJ::get_option_visibility(const String &p_option, const Map &p_options) const { return true; } diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 012e3e95a7..f4fb0f9f0c 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -53,6 +53,7 @@ uint32_t EditorSceneImporter::get_import_flags() const { ERR_FAIL_V(0); } + void EditorSceneImporter::get_extensions(List *r_extensions) const { if (get_script_instance()) { Array arr = get_script_instance()->call("_get_extensions"); @@ -64,6 +65,7 @@ void EditorSceneImporter::get_extensions(List *r_extensions) const { ERR_FAIL(); } + Node *EditorSceneImporter::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List *r_missing_deps, Error *r_err) { if (get_script_instance()) { return get_script_instance()->call("_import_scene", p_path, p_flags, p_bake_fps); @@ -202,6 +204,7 @@ bool ResourceImporterScene::get_option_visibility(const String &p_option, const int ResourceImporterScene::get_preset_count() const { return PRESET_MAX; } + String ResourceImporterScene::get_preset_name(int p_idx) const { switch (p_idx) { case PRESET_SINGLE_SCENE: @@ -1520,14 +1523,17 @@ ResourceImporterScene *ResourceImporterScene::singleton = nullptr; ResourceImporterScene::ResourceImporterScene() { singleton = this; } + /////////////////////////////////////// uint32_t EditorSceneImporterESCN::get_import_flags() const { return IMPORT_SCENE; } + void EditorSceneImporterESCN::get_extensions(List *r_extensions) const { r_extensions->push_back("escn"); } + Node *EditorSceneImporterESCN::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List *r_missing_deps, Error *r_err) { Error error; Ref ps = ResourceFormatLoaderText::singleton->load(p_path, p_path, &error); @@ -1538,6 +1544,7 @@ Node *EditorSceneImporterESCN::import_scene(const String &p_path, uint32_t p_fla return scene; } + Ref EditorSceneImporterESCN::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) { ERR_FAIL_V(Ref()); } diff --git a/editor/import/resource_importer_shader_file.cpp b/editor/import/resource_importer_shader_file.cpp index 0813bca6f1..a2e80dfa18 100644 --- a/editor/import/resource_importer_shader_file.cpp +++ b/editor/import/resource_importer_shader_file.cpp @@ -44,9 +44,11 @@ String ResourceImporterShaderFile::get_importer_name() const { String ResourceImporterShaderFile::get_visible_name() const { return "GLSL Shader File"; } + void ResourceImporterShaderFile::get_recognized_extensions(List *p_extensions) const { p_extensions->push_back("glsl"); } + String ResourceImporterShaderFile::get_save_extension() const { return "res"; } @@ -58,6 +60,7 @@ String ResourceImporterShaderFile::get_resource_type() const { int ResourceImporterShaderFile::get_preset_count() const { return 0; } + String ResourceImporterShaderFile::get_preset_name(int p_idx) const { return String(); } @@ -68,6 +71,7 @@ void ResourceImporterShaderFile::get_import_options(List *r_option bool ResourceImporterShaderFile::get_option_visibility(const String &p_option, const Map &p_options) const { return true; } + static String _include_function(const String &p_path, void *userpointer) { Error err; diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index aeeae36f5b..ab23ab6db6 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -140,9 +140,11 @@ String ResourceImporterTexture::get_importer_name() const { String ResourceImporterTexture::get_visible_name() const { return "Texture2D"; } + void ResourceImporterTexture::get_recognized_extensions(List *p_extensions) const { ImageLoader::get_recognized_extensions(p_extensions); } + String ResourceImporterTexture::get_save_extension() const { return "stex"; } @@ -181,6 +183,7 @@ bool ResourceImporterTexture::get_option_visibility(const String &p_option, cons int ResourceImporterTexture::get_preset_count() const { return 4; } + String ResourceImporterTexture::get_preset_name(int p_idx) const { static const char *preset_names[] = { "2D, Detect 3D", diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp index 314c27b8e4..0ef5d84eca 100644 --- a/editor/import/resource_importer_texture_atlas.cpp +++ b/editor/import/resource_importer_texture_atlas.cpp @@ -45,6 +45,7 @@ String ResourceImporterTextureAtlas::get_importer_name() const { String ResourceImporterTextureAtlas::get_visible_name() const { return "TextureAtlas"; } + void ResourceImporterTextureAtlas::get_recognized_extensions(List *p_extensions) const { ImageLoader::get_recognized_extensions(p_extensions); } @@ -64,6 +65,7 @@ bool ResourceImporterTextureAtlas::get_option_visibility(const String &p_option, int ResourceImporterTextureAtlas::get_preset_count() const { return 0; } + String ResourceImporterTextureAtlas::get_preset_name(int p_idx) const { return String(); } diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index 3ffc7b34af..eace84400a 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -45,9 +45,11 @@ String ResourceImporterWAV::get_importer_name() const { String ResourceImporterWAV::get_visible_name() const { return "Microsoft WAV"; } + void ResourceImporterWAV::get_recognized_extensions(List *p_extensions) const { p_extensions->push_back("wav"); } + String ResourceImporterWAV::get_save_extension() const { return "sample"; } @@ -67,6 +69,7 @@ bool ResourceImporterWAV::get_option_visibility(const String &p_option, const Ma int ResourceImporterWAV::get_preset_count() const { return 0; } + String ResourceImporterWAV::get_preset_name(int p_idx) const { return String(); } -- cgit v1.2.3 From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 16:41:43 +0200 Subject: Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- editor/import/collada.cpp | 330 ++++++++++++++------- editor/import/collada.h | 36 ++- editor/import/editor_import_collada.cpp | 142 +++++---- editor/import/editor_scene_importer_gltf.cpp | 147 ++++++--- editor/import/resource_importer_bitmask.cpp | 3 +- .../import/resource_importer_layered_texture.cpp | 3 +- editor/import/resource_importer_obj.cpp | 14 +- editor/import/resource_importer_scene.cpp | 158 ++++++---- editor/import/resource_importer_texture.cpp | 18 +- editor/import/resource_importer_texture_atlas.cpp | 5 +- editor/import/resource_importer_wav.cpp | 6 +- editor/import/resource_importer_wav.h | 17 +- 12 files changed, 576 insertions(+), 303 deletions(-) (limited to 'editor/import') diff --git a/editor/import/collada.cpp b/editor/import/collada.cpp index e82e1bb098..41e71248a9 100644 --- a/editor/import/collada.cpp +++ b/editor/import/collada.cpp @@ -65,10 +65,11 @@ void Collada::Vertex::fix_unit_scale(Collada &state) { } static String _uri_to_id(const String &p_uri) { - if (p_uri.begins_with("#")) + if (p_uri.begins_with("#")) { return p_uri.substr(1, p_uri.size() - 1); - else + } else { return p_uri; + } } /** HELPER FUNCTIONS **/ @@ -79,10 +80,12 @@ Transform Collada::fix_transform(const Transform &p_transform) { #ifndef NO_UP_AXIS_SWAP if (state.up_axis != Vector3::AXIS_Y) { - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { SWAP(tr.basis[1][i], tr.basis[state.up_axis][i]); - for (int i = 0; i < 3; i++) + } + for (int i = 0; i < 3; i++) { SWAP(tr.basis[i][1], tr.basis[i][state.up_axis]); + } SWAP(tr.origin[1], tr.origin[state.up_axis]); @@ -167,10 +170,11 @@ Transform Collada::Node::get_transform() const { } Transform Collada::Node::get_global_transform() const { - if (parent) + if (parent) { return parent->get_global_transform() * default_transform; - else + } else { return default_transform; + } } Vector Collada::AnimationTrack::get_value_at_time(float p_time) const { @@ -178,14 +182,17 @@ Vector Collada::AnimationTrack::get_value_at_time(float p_time) const { int i = 0; for (i = 0; i < keys.size(); i++) { - if (keys[i].time > p_time) + if (keys[i].time > p_time) { break; + } } - if (i == 0) + if (i == 0) { return keys[0].data; - if (i == keys.size()) + } + if (i == keys.size()) { return keys[keys.size() - 1].data; + } switch (keys[i].interp_type) { case INTERP_BEZIER: //wait for bezier @@ -243,12 +250,15 @@ void Collada::_parse_asset(XMLParser &parser) { if (name == "up_axis") { parser.read(); - if (parser.get_node_data() == "X_UP") + if (parser.get_node_data() == "X_UP") { state.up_axis = Vector3::AXIS_X; - if (parser.get_node_data() == "Y_UP") + } + if (parser.get_node_data() == "Y_UP") { state.up_axis = Vector3::AXIS_Y; - if (parser.get_node_data() == "Z_UP") + } + if (parser.get_node_data() == "Z_UP") { state.up_axis = Vector3::AXIS_Z; + } COLLADA_PRINT("up axis: " + parser.get_node_data()); } else if (name == "unit") { @@ -256,8 +266,9 @@ void Collada::_parse_asset(XMLParser &parser) { COLLADA_PRINT("unit scale: " + rtos(state.unit_scale)); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "asset") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "asset") { break; //end of + } } } @@ -265,8 +276,9 @@ void Collada::_parse_image(XMLParser &parser) { String id = parser.get_attribute_value("id"); if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -302,11 +314,13 @@ void Collada::_parse_image(XMLParser &parser) { } else if (name == "data") { ERR_PRINT("COLLADA Embedded image data not supported!"); - } else if (name == "extra" && !parser.is_empty()) + } else if (name == "extra" && !parser.is_empty()) { parser.skip_section(); + } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "image") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "image") { break; //end of + } } } @@ -315,16 +329,18 @@ void Collada::_parse_image(XMLParser &parser) { void Collada::_parse_material(XMLParser &parser) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } Material material; String id = parser.get_attribute_value("id"); - if (parser.has_attribute("name")) + if (parser.has_attribute("name")) { material.name = parser.get_attribute_value("name"); + } if (state.version < State::Version(1, 4, 0)) { /* <1.4 */ @@ -333,8 +349,9 @@ void Collada::_parse_material(XMLParser &parser) { while (parser.read() == OK) { if (parser.get_node_type() == XMLParser::NODE_ELEMENT && parser.get_node_name() == "instance_effect") { material.instance_effect = _uri_to_id(parser.get_attribute_value("url")); - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "material") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "material") { break; //end of + } } } @@ -343,8 +360,9 @@ void Collada::_parse_material(XMLParser &parser) { //! reads floats from inside of xml element until end of xml element Vector Collada::_read_float_array(XMLParser &parser) { - if (parser.is_empty()) + if (parser.is_empty()) { return Vector(); + } Vector splitters; splitters.push_back(" "); @@ -362,16 +380,18 @@ Vector Collada::_read_float_array(XMLParser &parser) { String str = parser.get_node_data(); array = str.split_floats_mk(splitters, false); //array=str.split_floats(" ",false); - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) { break; // end parsing text + } } return array; } Vector Collada::_read_string_array(XMLParser &parser) { - if (parser.is_empty()) + if (parser.is_empty()) { return Vector(); + } Vector array; while (parser.read() == OK) { @@ -382,16 +402,18 @@ Vector Collada::_read_string_array(XMLParser &parser) { // parse String data String str = parser.get_node_data(); array = str.split_spaces(); - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) { break; // end parsing text + } } return array; } Transform Collada::_read_transform(XMLParser &parser) { - if (parser.is_empty()) + if (parser.is_empty()) { return Transform(); + } Vector array; while (parser.read() == OK) { @@ -402,8 +424,9 @@ Transform Collada::_read_transform(XMLParser &parser) { // parse float data String str = parser.get_node_data(); array = str.split_spaces(); - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) { break; // end parsing text + } } ERR_FAIL_COND_V(array.size() != 16, Transform()); @@ -419,21 +442,24 @@ Transform Collada::_read_transform(XMLParser &parser) { String Collada::_read_empty_draw_type(XMLParser &parser) { String empty_draw_type = ""; - if (parser.is_empty()) + if (parser.is_empty()) { return empty_draw_type; + } while (parser.read() == OK) { if (parser.get_node_type() == XMLParser::NODE_TEXT) { empty_draw_type = parser.get_node_data(); - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) { break; // end parsing text + } } return empty_draw_type; } Variant Collada::_parse_param(XMLParser &parser) { - if (parser.is_empty()) + if (parser.is_empty()) { return Variant(); + } String from = parser.get_node_name(); Variant data; @@ -473,8 +499,9 @@ Variant Collada::_parse_param(XMLParser &parser) { data = parser.get_node_data(); } } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "sampler2D") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "sampler2D") { break; + } } } else if (parser.get_node_name() == "surface") { while (parser.read() == OK) { @@ -486,13 +513,15 @@ Variant Collada::_parse_param(XMLParser &parser) { data = parser.get_node_data(); } } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "surface") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "surface") { break; + } } } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == from) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == from) { break; + } } COLLADA_PRINT("newparam ending " + parser.get_node_name()); @@ -501,8 +530,9 @@ Variant Collada::_parse_param(XMLParser &parser) { void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String &id) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -544,12 +574,15 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String & if (colorarr.size() >= 3) { // alpha strangely not alright? maybe it needs to be multiplied by value as a channel intensity Color color(colorarr[0], colorarr[1], colorarr[2], 1.0); - if (what == "diffuse") + if (what == "diffuse") { effect.diffuse.color = color; - if (what == "specular") + } + if (what == "specular") { effect.specular.color = color; - if (what == "emission") + } + if (what == "emission") { effect.emission.color = color; + } COLLADA_PRINT(what + " color: " + color); } @@ -583,11 +616,13 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String & COLLADA_PRINT(what + " texture: " + uri); } } - } else if (!parser.is_empty()) + } else if (!parser.is_empty()) { parser.skip_section(); + } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == what) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == what) { break; + } } } else if (what == "shininess") { @@ -596,8 +631,9 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String & } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && (parser.get_node_name() == "constant" || parser.get_node_name() == "lambert" || parser.get_node_name() == "phong" || - parser.get_node_name() == "blinn")) + parser.get_node_name() == "blinn")) { break; + } } } else if (parser.get_node_name() == "double_sided" || parser.get_node_name() == "show_double_sided") { // colladamax / google earth @@ -633,36 +669,42 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String & COLLADA_PRINT(" bump: " + uri); } } - } else if (!parser.is_empty()) + } else if (!parser.is_empty()) { parser.skip_section(); + } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "bump") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "bump") { break; + } } - } else if (!parser.is_empty()) + } else if (!parser.is_empty()) { parser.skip_section(); + } } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && (parser.get_node_name() == "effect" || parser.get_node_name() == "profile_COMMON" || parser.get_node_name() == "technique" || - parser.get_node_name() == "extra")) + parser.get_node_name() == "extra")) { break; + } } } void Collada::_parse_effect(XMLParser &parser) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } String id = parser.get_attribute_value("id"); Effect effect; - if (parser.has_attribute("name")) + if (parser.has_attribute("name")) { effect.name = parser.get_attribute_value("name"); + } _parse_effect_material(parser, effect, id); state.effect_map[id] = effect; @@ -672,8 +714,9 @@ void Collada::_parse_effect(XMLParser &parser) { void Collada::_parse_camera(XMLParser &parser) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -717,8 +760,9 @@ void Collada::_parse_camera(XMLParser &parser) { camera.z_far = parser.get_node_data().to_double(); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "camera") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "camera") { break; //end of + } } COLLADA_PRINT("Camera ID:" + id); @@ -726,8 +770,9 @@ void Collada::_parse_camera(XMLParser &parser) { void Collada::_parse_light(XMLParser &parser) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -777,8 +822,9 @@ void Collada::_parse_light(XMLParser &parser) { light.spot_exp = parser.get_node_data().to_double(); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "light") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "light") { break; //end of + } } COLLADA_PRINT("Light ID:" + id); @@ -786,8 +832,9 @@ void Collada::_parse_light(XMLParser &parser) { void Collada::_parse_curve_geometry(XMLParser &parser, String p_id, String p_name) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -849,22 +896,25 @@ void Collada::_parse_curve_geometry(XMLParser &parser, String p_id, String p_nam COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) { break; + } } } else if (!parser.is_empty()) { parser.skip_section(); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "spline") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "spline") { break; + } } } void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name) { if (!(state.import_flags & IMPORT_FLAG_SCENE)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -922,8 +972,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) { break; + } } meshdata.vertices[id] = vert; @@ -935,8 +986,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name } MeshData::Primitives prim; - if (parser.has_attribute("material")) + if (parser.has_attribute("material")) { prim.material = parser.get_attribute_value("material"); + } prim.count = parser.get_attribute_value("count").to_int(); prim.vertex_size = 0; int last_ref = 0; @@ -973,8 +1025,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name prim.polygons.push_back(values.size() / prim.vertex_size); int from = prim.indices.size(); prim.indices.resize(from + values.size()); - for (int i = 0; i < values.size(); i++) + for (int i = 0; i < values.size(); i++) { prim.indices.write[from + i] = values[i]; + } } else if (prim.vertex_size > 0) { prim.indices = values; @@ -988,8 +1041,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name prim.polygons = values; COLLADA_PRINT("read " + itos(values.size()) + " polygon values"); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) { break; + } } meshdata.primitives.push_back(prim); @@ -1004,8 +1058,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name } else if (!parser.is_empty()) { parser.skip_section(); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "mesh") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "mesh") { break; + } } } @@ -1044,14 +1099,16 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { } else if (section == "Name_array" || section == "IDREF_array") { // create a new array and read it. - if (section == "IDREF_array") + if (section == "IDREF_array") { skindata.use_idrefs = true; + } if (skindata.sources.has(current_source)) { skindata.sources[current_source].sarray = _read_string_array(parser); if (section == "IDREF_array") { Vector sa = skindata.sources[current_source].sarray; - for (int i = 0; i < sa.size(); i++) + for (int i = 0; i < sa.size(); i++) { state.idref_joints.insert(sa[i]); + } } COLLADA_PRINT("section: " + current_source + " read " + itos(skindata.sources[current_source].array.size()) + " values."); } @@ -1061,8 +1118,9 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { if (skindata.sources.has(current_source)) { int stride = 1; - if (parser.has_attribute("stride")) + if (parser.has_attribute("stride")) { stride = parser.get_attribute_value("stride").to_int(); + } skindata.sources[current_source].stride = stride; COLLADA_PRINT("section: " + current_source + " stride " + itos(skindata.sources[current_source].stride)); @@ -1081,8 +1139,9 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) { break; + } } skindata.joints = joint; @@ -1119,8 +1178,9 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { weights.sets = values; COLLADA_PRINT("read " + itos(values.size()) + " polygon values"); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) { break; + } } skindata.weights = weights; @@ -1130,8 +1190,9 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) { parser.skip_section(); */ - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "skin") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "skin") { break; + } } /* STORE REST MATRICES */ @@ -1209,8 +1270,9 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) { if (morphdata.sources.has(current_source)) { int stride = 1; - if (parser.has_attribute("stride")) + if (parser.has_attribute("stride")) { stride = parser.get_attribute_value("stride").to_int(); + } morphdata.sources[current_source].stride = stride; COLLADA_PRINT("section: " + current_source + " stride " + itos(morphdata.sources[current_source].stride)); @@ -1227,8 +1289,9 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) { COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) { break; + } } } /* @@ -1236,8 +1299,9 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) { parser.skip_section(); */ - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "morph") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "morph") { break; + } } if (morphdata.targets.has("MORPH_WEIGHT")) { @@ -1261,8 +1325,9 @@ void Collada::_parse_controller(XMLParser &parser) { } else if (section == "morph") { _parse_morph_controller(parser, id); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "controller") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "controller") { break; + } } } @@ -1272,8 +1337,9 @@ Collada::Node *Collada::_parse_visual_instance_geometry(XMLParser &parser) { geom->controller = type == "instance_controller"; geom->source = _uri_to_id(parser.get_attribute_value_safe("url")); - if (parser.is_empty()) //nothing else to parse... + if (parser.is_empty()) { //nothing else to parse... return geom; + } // try to find also many materials and skeletons! while (parser.read() == OK) { if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { @@ -1293,8 +1359,9 @@ Collada::Node *Collada::_parse_visual_instance_geometry(XMLParser &parser) { } } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == type) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == type) { break; + } } if (geom->controller) { @@ -1320,15 +1387,18 @@ Collada::Node *Collada::_parse_visual_instance_camera(XMLParser &parser) { NodeCamera *cam = memnew(NodeCamera); cam->camera = _uri_to_id(parser.get_attribute_value_safe("url")); - if (state.up_axis == Vector3::AXIS_Z) //collada weirdness + if (state.up_axis == Vector3::AXIS_Z) { //collada weirdness cam->post_transform.basis.rotate(Vector3(1, 0, 0), -Math_PI * 0.5); + } - if (parser.is_empty()) //nothing else to parse... + if (parser.is_empty()) { //nothing else to parse... return cam; + } while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_camera") + if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_camera") { break; + } } return cam; @@ -1338,15 +1408,18 @@ Collada::Node *Collada::_parse_visual_instance_light(XMLParser &parser) { NodeLight *cam = memnew(NodeLight); cam->light = _uri_to_id(parser.get_attribute_value_safe("url")); - if (state.up_axis == Vector3::AXIS_Z) //collada weirdness + if (state.up_axis == Vector3::AXIS_Z) { //collada weirdness cam->post_transform.basis.rotate(Vector3(1, 0, 0), -Math_PI * 0.5); + } - if (parser.is_empty()) //nothing else to parse... + if (parser.is_empty()) { //nothing else to parse... return cam; + } while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_light") + if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_light") { break; + } } return cam; @@ -1363,12 +1436,14 @@ Collada::Node *Collada::_parse_visual_node_instance_data(XMLParser &parser) { return _parse_visual_instance_light(parser); } - if (parser.is_empty()) //nothing else to parse... + if (parser.is_empty()) { //nothing else to parse... return nullptr; + } while (parser.read() == OK) { - if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == instance_type) + if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == instance_type) { break; + } } return nullptr; @@ -1475,8 +1550,9 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { xf.data = matrix; String mtx; - for (int i = 0; i < matrix.size(); i++) + for (int i = 0; i < matrix.size(); i++) { mtx += " " + rtos(matrix[i]); + } xform_list.push_back(xf); @@ -1514,8 +1590,9 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { children.push_back(child); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "node") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "node") { break; + } } if (!node) { @@ -1556,8 +1633,9 @@ void Collada::_parse_visual_scene(XMLParser &parser) { state.visual_scene_map[id] = VisualScene(); VisualScene &vscene = state.visual_scene_map[id]; - if (parser.has_attribute("name")) + if (parser.has_attribute("name")) { vscene.name = parser.get_attribute_value("name"); + } while (parser.read() == OK) { if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { @@ -1567,8 +1645,9 @@ void Collada::_parse_visual_scene(XMLParser &parser) { vscene.root_nodes.push_back(_parse_visual_scene_node(parser)); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "visual_scene") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "visual_scene") { break; + } } COLLADA_PRINT("Scene ID:" + id); @@ -1576,8 +1655,9 @@ void Collada::_parse_visual_scene(XMLParser &parser) { void Collada::_parse_animation(XMLParser &parser) { if (!(state.import_flags & IMPORT_FLAG_ANIMATION)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } @@ -1590,8 +1670,9 @@ void Collada::_parse_animation(XMLParser &parser) { Map> source_param_types; String id = ""; - if (parser.has_attribute("id")) + if (parser.has_attribute("id")) { id = parser.get_attribute_value("id"); + } String current_source; String current_sampler; @@ -1623,15 +1704,17 @@ void Collada::_parse_animation(XMLParser &parser) { current_sampler = parser.get_attribute_value("id"); samplers[current_sampler] = Map(); } else if (name == "param") { - if (parser.has_attribute("name")) + if (parser.has_attribute("name")) { source_param_names[current_source].push_back(parser.get_attribute_value("name")); - else + } else { source_param_names[current_source].push_back(""); + } - if (parser.has_attribute("type")) + if (parser.has_attribute("type")) { source_param_types[current_source].push_back(parser.get_attribute_value("type")); - else + } else { source_param_types[current_source].push_back(""); + } } else if (name == "input") { if (current_sampler != "") { @@ -1643,8 +1726,9 @@ void Collada::_parse_animation(XMLParser &parser) { channel_targets.push_back(parser.get_attribute_value("target")); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "animation") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "animation") { break; //end of + } } for (int i = 0; i < channel_sources.size(); i++) { @@ -1686,8 +1770,9 @@ void Collada::_parse_animation(XMLParser &parser) { int stride = 1; - if (source_strides.has(output_id)) + if (source_strides.has(output_id)) { stride = source_strides[output_id]; + } int output_len = stride / names.size(); ERR_CONTINUE(output_len == 0); @@ -1699,8 +1784,9 @@ void Collada::_parse_animation(XMLParser &parser) { for (int j = 0; j < key_count; j++) { track.keys.write[j].data.resize(output_len); - for (int k = 0; k < output_len; k++) + for (int k = 0; k < output_len; k++) { track.keys.write[j].data.write[k] = output[l + j * stride + k]; //super weird but should work: + } } if (sampler.has("INTERPOLATION")) { @@ -1710,10 +1796,11 @@ void Collada::_parse_animation(XMLParser &parser) { ERR_CONTINUE(interps.size() != key_count); for (int j = 0; j < key_count; j++) { - if (interps[j] == "BEZIER") + if (interps[j] == "BEZIER") { track.keys.write[j].interp_type = AnimationTrack::INTERP_BEZIER; - else + } else { track.keys.write[j].interp_type = AnimationTrack::INTERP_LINEAR; + } } } @@ -1739,8 +1826,9 @@ void Collada::_parse_animation(XMLParser &parser) { if (target.find("/") != -1) { //transform component track.target = target.get_slicec('/', 0); track.param = target.get_slicec('/', 1); - if (track.param.find(".") != -1) + if (track.param.find(".") != -1) { track.component = track.param.get_slice(".", 1).to_upper(); + } track.param = track.param.get_slice(".", 0); if (names.size() > 1 && track.component == "") { //this is a guess because the collada spec is ambiguous here... @@ -1753,14 +1841,16 @@ void Collada::_parse_animation(XMLParser &parser) { state.animation_tracks.push_back(track); - if (!state.referenced_tracks.has(target)) + if (!state.referenced_tracks.has(target)) { state.referenced_tracks[target] = Vector(); + } state.referenced_tracks[target].push_back(state.animation_tracks.size() - 1); if (id != "") { - if (!state.by_id_tracks.has(id)) + if (!state.by_id_tracks.has(id)) { state.by_id_tracks[id] = Vector(); + } state.by_id_tracks[id].push_back(state.animation_tracks.size() - 1); } @@ -1772,22 +1862,26 @@ void Collada::_parse_animation(XMLParser &parser) { void Collada::_parse_animation_clip(XMLParser &parser) { if (!(state.import_flags & IMPORT_FLAG_ANIMATION)) { - if (!parser.is_empty()) + if (!parser.is_empty()) { parser.skip_section(); + } return; } AnimationClip clip; - if (parser.has_attribute("name")) + if (parser.has_attribute("name")) { clip.name = parser.get_attribute_value("name"); - else if (parser.has_attribute("id")) + } else if (parser.has_attribute("id")) { clip.name = parser.get_attribute_value("id"); - if (parser.has_attribute("start")) + } + if (parser.has_attribute("start")) { clip.begin = parser.get_attribute_value("start").to_double(); - if (parser.has_attribute("end")) + } + if (parser.has_attribute("end")) { clip.end = parser.get_attribute_value("end").to_double(); + } while (parser.read() == OK) { if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { @@ -1797,8 +1891,9 @@ void Collada::_parse_animation_clip(XMLParser &parser) { clip.tracks.push_back(url); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "animation_clip") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "animation_clip") { break; //end of + } } state.animation_clips.push_back(clip); @@ -1819,8 +1914,9 @@ void Collada::_parse_scene(XMLParser &parser) { state.root_physics_scene = _uri_to_id(parser.get_attribute_value("url")); } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "scene") + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "scene") { break; //end of + } } } @@ -1854,10 +1950,12 @@ void Collada::_parse_library(XMLParser &parser) { } else if (parser.get_node_name() == "spline") { state.mesh_name_map[id] = (name2 != "") ? name2 : id; _parse_curve_geometry(parser, id, name2); - } else if (!parser.is_empty()) + } else if (!parser.is_empty()) { parser.skip_section(); - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "geometry") + } + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "geometry") { break; + } } } else if (name == "controller") { @@ -1869,11 +1967,13 @@ void Collada::_parse_library(XMLParser &parser) { } else if (name == "visual_scene") { COLLADA_PRINT("visual scene"); _parse_visual_scene(parser); - } else if (!parser.is_empty()) + } else if (!parser.is_empty()) { parser.skip_section(); + } - } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name().begins_with("library_")) + } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name().begins_with("library_")) { break; //end of + } } } @@ -1919,8 +2019,9 @@ bool Collada::_remove_node(Node *p_parent, Node *p_node) { p_parent->children.remove(i); return true; } - if (_remove_node(p_parent->children[i], p_node)) + if (_remove_node(p_parent->children[i], p_node)) { return true; + } } return false; @@ -1932,8 +2033,9 @@ void Collada::_remove_node(VisualScene *p_vscene, Node *p_node) { p_vscene->root_nodes.remove(i); return; } - if (_remove_node(p_vscene->root_nodes[i], p_node)) + if (_remove_node(p_vscene->root_nodes[i], p_node)) { return; + } } ERR_PRINT("ERROR: Not found node to remove?"); @@ -2090,8 +2192,9 @@ bool Collada::_optimize_skeletons(VisualScene *p_vscene, Node *p_node) { } for (int i = 0; i < node->children.size(); i++) { - if (_optimize_skeletons(p_vscene, node->children[i])) + if (_optimize_skeletons(p_vscene, node->children[i])) { return false; //stop processing, go up + } } return false; @@ -2103,8 +2206,9 @@ bool Collada::_move_geometry_to_skeletons(VisualScene *p_vscene, Node *p_node, L if (p_node->type == Node::TYPE_GEOMETRY) { NodeGeometry *ng = static_cast(p_node); - if (ng->ignore_anim) + if (ng->ignore_anim) { return false; //already made child of skeleton and processeg + } if (ng->controller && ng->skeletons.size()) { String nodeid = ng->skeletons[0]; @@ -2253,8 +2357,9 @@ Error Collada::load(const String &p_path, int p_flags) { if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { if (parser.get_node_name() == "COLLADA") { break; - } else if (!parser.is_empty()) + } else if (!parser.is_empty()) { parser.skip_section(); // unknown section, likely headers + } } } @@ -2274,8 +2379,9 @@ Error Collada::load(const String &p_path, int p_flags) { while ((err = parser.read()) == OK) { /* Read all the main sections.. */ - if (parser.get_node_type() != XMLParser::NODE_ELEMENT) + if (parser.get_node_type() != XMLParser::NODE_ELEMENT) { continue; //no idea what this may be, but skipping anyway + } String section = parser.get_node_name(); diff --git a/editor/import/collada.h b/editor/import/collada.h index 02c3277911..90c6c47e0b 100644 --- a/editor/import/collada.h +++ b/editor/import/collada.h @@ -255,11 +255,14 @@ public: //cap to 4 and make weights add up 1 weights.resize(4); float total = 0; - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { total += weights[i].weight; - if (total) - for (int i = 0; i < 4; i++) + } + if (total) { + for (int i = 0; i < 4; i++) { weights.write[i].weight /= total; + } + } } } @@ -274,11 +277,13 @@ public: if (!weights.empty() || !p_vert.weights.empty()) { if (weights.size() == p_vert.weights.size()) { for (int i = 0; i < weights.size(); i++) { - if (weights[i].bone_idx != p_vert.weights[i].bone_idx) + if (weights[i].bone_idx != p_vert.weights[i].bone_idx) { return weights[i].bone_idx < p_vert.weights[i].bone_idx; + } - if (weights[i].weight != p_vert.weights[i].weight) + if (weights[i].weight != p_vert.weights[i].weight) { return weights[i].weight < p_vert.weights[i].weight; + } } } else { return weights.size() < p_vert.weights.size(); @@ -286,16 +291,21 @@ public: } return (color < p_vert.color); - } else + } else { return (uv2 < p_vert.uv2); - } else + } + } else { return (uv < p_vert.uv); - } else + } + } else { return (normal < p_vert.normal); - } else + } + } else { return vertex < p_vert.vertex; - } else + } + } else { return uid < p_vert.uid; + } } Vertex() {} @@ -347,8 +357,9 @@ public: Node() {} virtual ~Node() { - for (int i = 0; i < children.size(); i++) + for (int i = 0; i < children.size(); i++) { memdelete(children[i]); + } }; }; @@ -395,8 +406,9 @@ public: Vector root_nodes; ~VisualScene() { - for (int i = 0; i < root_nodes.size(); i++) + for (int i = 0; i < root_nodes.size(); i++) { memdelete(root_nodes[i]); + } } }; diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 54b4dc2972..12cbaaa885 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -109,14 +109,16 @@ struct ColladaImport { }; Error ColladaImport::_populate_skeleton(Skeleton3D *p_skeleton, Collada::Node *p_node, int &r_bone, int p_parent) { - if (p_node->type != Collada::Node::TYPE_JOINT) + if (p_node->type != Collada::Node::TYPE_JOINT) { return OK; + } Collada::NodeJoint *joint = static_cast(p_node); p_skeleton->add_bone(p_node->name); - if (p_parent >= 0) + if (p_parent >= 0) { p_skeleton->set_bone_parent(r_bone, p_parent); + } NodeMap nm; nm.node = p_skeleton; @@ -136,8 +138,9 @@ Error ColladaImport::_populate_skeleton(Skeleton3D *p_skeleton, Collada::Node *p int id = r_bone++; for (int i = 0; i < p_node->children.size(); i++) { Error err = _populate_skeleton(p_skeleton, p_node->children[i], r_bone, id); - if (err) + if (err) { return err; + } } return OK; @@ -158,8 +161,9 @@ void ColladaImport::_pre_process_lights(Collada::Node *p_node) { } } - for (int i = 0; i < p_node->children.size(); i++) + for (int i = 0; i < p_node->children.size(); i++) { _pre_process_lights(p_node->children[i]); + } } Error ColladaImport::_create_scene_skeletons(Collada::Node *p_node) { @@ -175,8 +179,9 @@ Error ColladaImport::_create_scene_skeletons(Collada::Node *p_node) { for (int i = 0; i < p_node->children.size(); i++) { Error err = _create_scene_skeletons(p_node->children[i]); - if (err) + if (err) { return err; + } } return OK; } @@ -198,11 +203,13 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { Collada::LightData &ld = collada.state.light_data_map[light->light]; if (ld.mode == Collada::LightData::MODE_AMBIENT) { - if (found_directional) + if (found_directional) { return OK; //do nothing not needed + } - if (!bool(GLOBAL_DEF("collada/use_ambient", false))) + if (!bool(GLOBAL_DEF("collada/use_ambient", false))) { return OK; + } //well, it's an ambient light.. Light3D *l = memnew(DirectionalLight3D); //l->set_color(Light::COLOR_AMBIENT,ld.color); @@ -224,9 +231,9 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { } else { Light3D *l; - if (ld.mode == Collada::LightData::MODE_OMNI) + if (ld.mode == Collada::LightData::MODE_OMNI) { l = memnew(OmniLight3D); - else { + } else { l = memnew(SpotLight3D); //l->set_parameter(Light::PARAM_SPOT_ANGLE,ld.spot_angle); //l->set_parameter(Light::PARAM_SPOT_ATTENUATION,ld.spot_exp); @@ -295,8 +302,9 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { } break; } - if (p_node->name != "") + if (p_node->name != "") { node->set_name(p_node->name); + } NodeMap nm; nm.node = node; node_map[p_node->id] = nm; @@ -314,8 +322,9 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) { for (int i = 0; i < p_node->children.size(); i++) { Error err = _create_scene(p_node->children[i], node); - if (err) + if (err) { return err; + } } return OK; } @@ -329,10 +338,11 @@ Error ColladaImport::_create_material(const String &p_target) { Ref material = memnew(StandardMaterial3D); - if (src_mat.name != "") + if (src_mat.name != "") { material->set_name(src_mat.name); - else if (effect.name != "") + } else if (effect.name != "") { material->set_name(effect.name); + } // DIFFUSE @@ -459,10 +469,11 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me p_mesh->add_blend_shape(name); } - if (p_morph_data->mode == "RELATIVE") + if (p_morph_data->mode == "RELATIVE") { p_mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_RELATIVE); - else if (p_morph_data->mode == "NORMALIZED") + } else if (p_morph_data->mode == "NORMALIZED") { p_mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_NORMALIZED); + } } int surface = 0; @@ -594,8 +605,9 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me w.weight = weight_src->array[weight_index]; int bone_index = p_skin_controller->weights.indices[read_from + joint_ofs]; - if (bone_index == -1) + if (bone_index == -1) { continue; //ignore this weight (refers to bind shape) + } ERR_FAIL_INDEX_V(bone_index, bone_remap.size(), ERR_INVALID_DATA); w.bone_idx = bone_remap[bone_index]; @@ -614,11 +626,14 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me //make sure weights always add up to 1 float total = 0; - for (int i = 0; i < weights.size(); i++) + for (int i = 0; i < weights.size(); i++) { total += weights[i].weight; - if (total) - for (int i = 0; i < weights.size(); i++) + } + if (total) { + for (int i = 0; i < weights.size(); i++) { weights.write[i].weight /= total; + } + } if (weights.size() == 0 || total == 0) { //if nothing, add a weight to bone 0 //no weights assigned @@ -672,8 +687,9 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me ERR_FAIL_INDEX_V(src, p.indices.size(), ERR_INVALID_DATA); Collada::Vertex vertex; - if (!p_optimize) + if (!p_optimize) { vertex.uid = vertidx++; + } int vertex_index = p.indices[src + vertex_ofs]; //used for index field (later used by controllers) int vertex_pos = (vertex_src->stride ? vertex_src->stride : 3) * vertex_index; @@ -752,8 +768,9 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me } //build triangles if needed - if (j == 0) + if (j == 0) { prev2[0] = index; + } if (j >= 2) { //insert indices in reverse order (collada uses CCW as frontface) @@ -809,10 +826,12 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me if (!material_cache.has(target)) { Error err = _create_material(target); - if (!err) + if (!err) { material = material_cache[target]; - } else + } + } else { material = material_cache[target]; + } } else if (p.material != "") { WARN_PRINT("Collada: Unreferenced material in geometry instance: " + p.material); @@ -961,8 +980,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres ERR_FAIL_COND_V(interps.stride != 1, ERR_INVALID_DATA); const Collada::CurveData::Source *tilts = nullptr; - if (cd.control_vertices.has("TILT") && cd.sources.has(cd.control_vertices["TILT"])) + if (cd.control_vertices.has("TILT") && cd.sources.has(cd.control_vertices["TILT"])) { tilts = &cd.sources[cd.control_vertices["TILT"]]; + } int pc = vertices.array.size() / 3; for (int i = 0; i < pc; i++) { @@ -985,8 +1005,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres out *= collada.state.unit_scale; c->add_point(pos, in - pos, out - pos); - if (tilts) + if (tilts) { c->set_point_tilt(i, tilts->array[i]); + } } curve_cache[ng->source] = c; @@ -1088,8 +1109,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres } } - if (!valid) + if (!valid) { morphs.clear(); + } ngsource = ""; } } @@ -1134,10 +1156,12 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres Ref material; if (!material_cache.has(target)) { Error err = _create_material(target); - if (!err) + if (!err) { material = material_cache[target]; - } else + } + } else { material = material_cache[target]; + } mi->set_surface_material(i, material); } else if (matname != "") { @@ -1151,8 +1175,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres for (int i = 0; i < p_node->children.size(); i++) { Error err = _create_resources(p_node->children[i], p_use_compression); - if (err) + if (err) { return err; + } } return OK; } @@ -1274,8 +1299,9 @@ void ColladaImport::_fix_param_animation_tracks() { void ColladaImport::create_animations(bool p_make_tracks_in_all_bones, bool p_import_value_tracks) { _fix_param_animation_tracks(); for (int i = 0; i < collada.state.animation_clips.size(); i++) { - for (int j = 0; j < collada.state.animation_clips[i].tracks.size(); j++) + for (int j = 0; j < collada.state.animation_clips[i].tracks.size(); j++) { tracks_in_clips.insert(collada.state.animation_clips[i].tracks[j]); + } } for (int i = 0; i < collada.state.animation_tracks.size(); i++) { @@ -1304,8 +1330,9 @@ void ColladaImport::create_animations(bool p_make_tracks_in_all_bones, bool p_im } create_animation(-1, p_make_tracks_in_all_bones, p_import_value_tracks); - for (int i = 0; i < collada.state.animation_clips.size(); i++) + for (int i = 0; i < collada.state.animation_clips.size(); i++) { create_animation(i, p_make_tracks_in_all_bones, p_import_value_tracks); + } } void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones, bool p_import_value_tracks) { @@ -1318,8 +1345,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones } for (Map::Element *E = node_map.front(); E; E = E->next()) { - if (E->get().bone < 0) + if (E->get().bone < 0) { continue; + } bones_with_animation[E->key()] = false; } //store and validate tracks @@ -1365,8 +1393,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones float snapshot_interval = 1.0 / bake_fps; //should be customizable somewhere... float anim_length = collada.state.animation_length; - if (p_clip >= 0 && collada.state.animation_clips[p_clip].end) + if (p_clip >= 0 && collada.state.animation_clips[p_clip].end) { anim_length = collada.state.animation_clips[p_clip].end; + } while (f < anim_length) { base_snapshots.push_back(f); @@ -1416,8 +1445,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones //use snapshot keys from anim track instead, because this was most likely exported baked const Collada::AnimationTrack &at = collada.state.animation_tracks[nm.anim_tracks.front()->get()]; snapshots.clear(); - for (int i = 0; i < at.keys.size(); i++) + for (int i = 0; i < at.keys.size(); i++) { snapshots.push_back(at.keys[i].time); + } } for (int i = 0; i < snapshots.size(); i++) { @@ -1429,8 +1459,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones continue; } } else { - if (!track_filter.has(ET->get())) + if (!track_filter.has(ET->get())) { continue; + } } found_anim = true; @@ -1494,13 +1525,14 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones } if (nm.bone >= 0) { - if (found_anim) + if (found_anim) { bones_with_animation[E->get()] = true; + } } - if (found_anim) + if (found_anim) { tracks_found = true; - else { + } else { animation->remove_track(track); } } @@ -1508,8 +1540,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones if (p_make_tracks_in_all_bones) { //some bones may lack animation, but since we don't store pose as a property, we must add keyframes! for (Map::Element *E = bones_with_animation.front(); E; E = E->next()) { - if (E->get()) + if (E->get()) { continue; + } NodeMap &nm = node_map[E->key()]; String path = scene->get_path_to(nm.node); @@ -1550,18 +1583,21 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones int ti = valid_animated_properties[i]; if (p_clip == -1) { - if (track_filter.has(ti)) + if (track_filter.has(ti)) { continue; + } } else { - if (!track_filter.has(ti)) + if (!track_filter.has(ti)) { continue; + } } const Collada::AnimationTrack &at = collada.state.animation_tracks[ti]; // take snapshots - if (!collada.state.scene_map.has(at.target)) + if (!collada.state.scene_map.has(at.target)) { continue; + } NodeMap &nm = node_map[at.target]; String path = scene->get_path_to(nm.node); @@ -1615,8 +1651,9 @@ void EditorSceneImporterCollada::get_extensions(List *r_extensions) cons Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List *r_missing_deps, Error *r_err) { ColladaImport state; uint32_t flags = Collada::IMPORT_FLAG_SCENE; - if (p_flags & IMPORT_ANIMATION) + if (p_flags & IMPORT_ANIMATION) { flags |= Collada::IMPORT_FLAG_ANIMATION; + } state.use_mesh_builtin_materials = !(p_flags & IMPORT_MATERIALS_IN_INSTANCES); state.bake_fps = p_bake_fps; @@ -1627,10 +1664,10 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_ if (state.missing_textures.size()) { /* - for(int i=0;iget_name() == "") + if (state.animations[i]->get_name() == "") { name = "default"; - else + } else { name = state.animations[i]->get_name(); + } if (p_flags & IMPORT_ANIMATION_DETECT_LOOP) { if (name.begins_with("loop") || name.ends_with("loop") || name.begins_with("cycle") || name.ends_with("cycle")) { @@ -1674,11 +1712,13 @@ Ref EditorSceneImporterCollada::import_animation(const String &p_path ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot load animation from file '" + p_path + "'."); state.create_animations(p_flags & EditorSceneImporter::IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS, p_flags & EditorSceneImporter::IMPORT_ANIMATION_KEEP_VALUE_TRACKS); - if (state.scene) + if (state.scene) { memdelete(state.scene); + } - if (state.animations.size() == 0) + if (state.animations.size() == 0) { return Ref(); + } Ref anim = state.animations[0]; String base = p_path.get_basename().to_lower(); if (p_flags & IMPORT_ANIMATION_DETECT_LOOP) { diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 3c9f04322e..6ffff09ce5 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -355,8 +355,9 @@ static Vector _parse_base64_uri(const String &uri) { } Error EditorSceneImporterGLTF::_parse_buffers(GLTFState &state, const String &p_base_path) { - if (!state.json.has("buffers")) + if (!state.json.has("buffers")) { return OK; + } const Array &buffers = state.json["buffers"]; for (GLTFBufferIndex i = 0; i < buffers.size(); i++) { @@ -426,22 +427,29 @@ Error EditorSceneImporterGLTF::_parse_buffer_views(GLTFState &state) { } EditorSceneImporterGLTF::GLTFType EditorSceneImporterGLTF::_get_type_from_str(const String &p_string) { - if (p_string == "SCALAR") + if (p_string == "SCALAR") { return TYPE_SCALAR; + } - if (p_string == "VEC2") + if (p_string == "VEC2") { return TYPE_VEC2; - if (p_string == "VEC3") + } + if (p_string == "VEC3") { return TYPE_VEC3; - if (p_string == "VEC4") + } + if (p_string == "VEC4") { return TYPE_VEC4; + } - if (p_string == "MAT2") + if (p_string == "MAT2") { return TYPE_MAT2; - if (p_string == "MAT3") + } + if (p_string == "MAT3") { return TYPE_MAT3; - if (p_string == "MAT4") + } + if (p_string == "MAT4") { return TYPE_MAT4; + } ERR_FAIL_V(TYPE_SCALAR); } @@ -714,8 +722,9 @@ Vector EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, const ERR_FAIL_INDEX_V(a.buffer_view, state.buffer_views.size(), Vector()); const Error err = _decode_buffer_view(state, dst, a.buffer_view, skip_every, skip_bytes, element_size, a.count, a.type, component_count, a.component_type, component_size, a.normalized, a.byte_offset, p_for_vertex); - if (err != OK) + if (err != OK) { return Vector(); + } } else { //fill with zeros, as bufferview is not defined. @@ -731,14 +740,16 @@ Vector EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, const const int indices_component_size = _get_component_type_size(a.sparse_indices_component_type); Error err = _decode_buffer_view(state, indices.ptrw(), a.sparse_indices_buffer_view, 0, 0, indices_component_size, a.sparse_count, TYPE_SCALAR, 1, a.sparse_indices_component_type, indices_component_size, false, a.sparse_indices_byte_offset, false); - if (err != OK) + if (err != OK) { return Vector(); + } Vector data; data.resize(component_count * a.sparse_count); err = _decode_buffer_view(state, data.ptrw(), a.sparse_values_buffer_view, skip_every, skip_bytes, element_size, a.sparse_count, a.type, component_count, a.component_type, component_size, a.normalized, a.sparse_values_byte_offset, p_for_vertex); - if (err != OK) + if (err != OK) { return Vector(); + } for (int i = 0; i < indices.size(); i++) { const int write_offset = int(indices[i]) * component_count; @@ -756,8 +767,9 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_ints(GLTFState &state, const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } const double *attribs_ptr = attribs.ptr(); const int ret_size = attribs.size(); @@ -775,8 +787,9 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_floats(GLTFState &sta const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } const double *attribs_ptr = attribs.ptr(); const int ret_size = attribs.size(); @@ -794,8 +807,9 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_vec2(GLTFState &sta const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } ERR_FAIL_COND_V(attribs.size() % 2 != 0, ret); const double *attribs_ptr = attribs.ptr(); @@ -814,8 +828,9 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_vec3(GLTFState &sta const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } ERR_FAIL_COND_V(attribs.size() % 3 != 0, ret); const double *attribs_ptr = attribs.ptr(); @@ -834,8 +849,9 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_color(GLTFState &stat const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } const int type = state.accessors[p_accessor].type; ERR_FAIL_COND_V(!(type == TYPE_VEC3 || type == TYPE_VEC4), ret); @@ -861,8 +877,9 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_quat(GLTFState &state, const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } ERR_FAIL_COND_V(attribs.size() % 4 != 0, ret); const double *attribs_ptr = attribs.ptr(); @@ -880,8 +897,9 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_xform2d(GLTFSta const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } ERR_FAIL_COND_V(attribs.size() % 4 != 0, ret); ret.resize(attribs.size() / 4); @@ -896,8 +914,9 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_basis(GLTFState &stat const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } ERR_FAIL_COND_V(attribs.size() % 9 != 0, ret); ret.resize(attribs.size() / 9); @@ -913,8 +932,9 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_xform(GLTFState & const Vector attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector ret; - if (attribs.size() == 0) + if (attribs.size() == 0) { return ret; + } ERR_FAIL_COND_V(attribs.size() % 16 != 0, ret); ret.resize(attribs.size() / 16); @@ -928,8 +948,9 @@ Vector EditorSceneImporterGLTF::_decode_accessor_as_xform(GLTFState & } Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { - if (!state.json.has("meshes")) + if (!state.json.has("meshes")) { return OK; + } Array meshes = state.json["meshes"]; for (GLTFMeshIndex i = 0; i < meshes.size(); i++) { @@ -1214,8 +1235,9 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { } Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_base_path) { - if (!state.json.has("images")) + if (!state.json.has("images")) { return OK; + } const Array &images = state.json["images"]; for (int i = 0; i < images.size(); i++) { @@ -1307,8 +1329,9 @@ Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_b } Error EditorSceneImporterGLTF::_parse_textures(GLTFState &state) { - if (!state.json.has("textures")) + if (!state.json.has("textures")) { return OK; + } const Array &textures = state.json["textures"]; for (GLTFTextureIndex i = 0; i < textures.size(); i++) { @@ -1334,8 +1357,9 @@ Ref EditorSceneImporterGLTF::_get_texture(GLTFState &state, const GLT } Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) { - if (!state.json.has("materials")) + if (!state.json.has("materials")) { return OK; + } const Array &materials = state.json["materials"]; for (GLTFMaterialIndex i = 0; i < materials.size(); i++) { @@ -1694,8 +1718,9 @@ Error EditorSceneImporterGLTF::_verify_skin(GLTFState &state, GLTFSkin &skin) { } Error EditorSceneImporterGLTF::_parse_skins(GLTFState &state) { - if (!state.json.has("skins")) + if (!state.json.has("skins")) { return OK; + } const Array &skins = state.json["skins"]; @@ -1940,8 +1965,9 @@ Error EditorSceneImporterGLTF::_reparent_to_fake_joint(GLTFState &state, GLTFSke state.nodes.push_back(fake_joint); // We better not be a joint, or we messed up in our logic - if (node->joint) + if (node->joint) { return FAILED; + } fake_joint->translation = node->translation; fake_joint->rotation = node->rotation; @@ -2217,8 +2243,9 @@ void EditorSceneImporterGLTF::_remove_duplicate_skins(GLTFState &state) { } Error EditorSceneImporterGLTF::_parse_cameras(GLTFState &state) { - if (!state.json.has("cameras")) + if (!state.json.has("cameras")) { return OK; + } const Array &cameras = state.json["cameras"]; @@ -2263,8 +2290,9 @@ Error EditorSceneImporterGLTF::_parse_cameras(GLTFState &state) { } Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) { - if (!state.json.has("animations")) + if (!state.json.has("animations")) { return OK; + } const Array &animations = state.json["animations"]; @@ -2273,8 +2301,9 @@ Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) { GLTFAnimation animation; - if (!d.has("channels") || !d.has("samplers")) + if (!d.has("channels") || !d.has("samplers")) { continue; + } Array channels = d["channels"]; Array samplers = d["samplers"]; @@ -2289,8 +2318,9 @@ Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) { for (int j = 0; j < channels.size(); j++) { const Dictionary &c = channels[j]; - if (!c.has("target")) + if (!c.has("target")) { continue; + } const Dictionary &t = c["target"]; if (!t.has("node") || !t.has("path")) { @@ -2401,8 +2431,9 @@ void EditorSceneImporterGLTF::_assign_scene_names(GLTFState &state) { GLTFNode *n = state.nodes[i]; // Any joints get unique names generated when the skeleton is made, unique to the skeleton - if (n->skeleton >= 0) + if (n->skeleton >= 0) { continue; + } if (n->name.empty()) { if (n->mesh >= 0) { @@ -2599,8 +2630,9 @@ T EditorSceneImporterGLTF::_interpolate_track(const Vector &p_times, cons //could use binary search, worth it? int idx = -1; for (int i = 0; i < p_times.size(); i++) { - if (p_times[i] > p_time) + if (p_times[i] > p_time) { break; + } idx++; } @@ -2900,13 +2932,15 @@ Node *EditorSceneImporterGLTF::import_scene(const String &p_path, uint32_t p_fla //binary file //text file Error err = _parse_glb(p_path, state); - if (err) + if (err) { return nullptr; + } } else { //text file Error err = _parse_json(p_path, state); - if (err) + if (err) { return nullptr; + } } ERR_FAIL_COND_V(!state.json.has("asset"), nullptr); @@ -2923,78 +2957,93 @@ Node *EditorSceneImporterGLTF::import_scene(const String &p_path, uint32_t p_fla /* STEP 0 PARSE SCENE */ Error err = _parse_scenes(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 1 PARSE NODES */ err = _parse_nodes(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 2 PARSE BUFFERS */ err = _parse_buffers(state, p_path.get_base_dir()); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 3 PARSE BUFFER VIEWS */ err = _parse_buffer_views(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 4 PARSE ACCESSORS */ err = _parse_accessors(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 5 PARSE IMAGES */ err = _parse_images(state, p_path.get_base_dir()); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 6 PARSE TEXTURES */ err = _parse_textures(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 7 PARSE TEXTURES */ err = _parse_materials(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 9 PARSE SKINS */ err = _parse_skins(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 10 DETERMINE SKELETONS */ err = _determine_skeletons(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 11 CREATE SKELETONS */ err = _create_skeletons(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 12 CREATE SKINS */ err = _create_skins(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 13 PARSE MESHES (we have enough info now) */ err = _parse_meshes(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 14 PARSE CAMERAS */ err = _parse_cameras(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 15 PARSE ANIMATIONS */ err = _parse_animations(state); - if (err != OK) + if (err != OK) { return nullptr; + } /* STEP 16 ASSIGN SCENE NAMES */ _assign_scene_names(state); diff --git a/editor/import/resource_importer_bitmask.cpp b/editor/import/resource_importer_bitmask.cpp index 5e52a95e4e..da2d1c9bdf 100644 --- a/editor/import/resource_importer_bitmask.cpp +++ b/editor/import/resource_importer_bitmask.cpp @@ -80,8 +80,9 @@ Error ResourceImporterBitMap::import(const String &p_source_file, const String & Ref image; image.instance(); Error err = ImageLoader::load_image(p_source_file, image); - if (err != OK) + if (err != OK) { return err; + } int w = image->get_width(); int h = image->get_height(); diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp index 2c9e7dcd3b..1f39a12c25 100644 --- a/editor/import/resource_importer_layered_texture.cpp +++ b/editor/import/resource_importer_layered_texture.cpp @@ -239,8 +239,9 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const Ref image; image.instance(); Error err = ImageLoader::load_image(p_source_file, image, nullptr, false, 1.0); - if (err != OK) + if (err != OK) { return err; + } if (compress_mode == COMPRESS_BASIS_UNIVERSAL && image->get_format() >= Image::FORMAT_RF) { //basis universal does not support float formats, fall back diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 4316a9b512..49b47bf4be 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -290,23 +290,26 @@ static Error _parse_obj(const String &p_path, List> &r_meshes, bool p_ if (face[idx].size() == 3) { int norm = face[idx][2].to_int() - 1; - if (norm < 0) + if (norm < 0) { norm += normals.size() + 1; + } ERR_FAIL_INDEX_V(norm, normals.size(), ERR_FILE_CORRUPT); surf_tool->add_normal(normals[norm]); } if (face[idx].size() >= 2 && face[idx][1] != String()) { int uv = face[idx][1].to_int() - 1; - if (uv < 0) + if (uv < 0) { uv += uvs.size() + 1; + } ERR_FAIL_INDEX_V(uv, uvs.size(), ERR_FILE_CORRUPT); surf_tool->add_uv(uvs[uv]); } int vtx = face[idx][0].to_int() - 1; - if (vtx < 0) + if (vtx < 0) { vtx += vertices.size() + 1; + } ERR_FAIL_INDEX_V(vtx, vertices.size(), ERR_FILE_CORRUPT); Vector3 vertex = vertices[vtx]; @@ -319,10 +322,11 @@ static Error _parse_obj(const String &p_path, List> &r_meshes, bool p_ } } else if (l.begins_with("s ")) { //smoothing String what = l.substr(2, l.length()).strip_edges(); - if (what == "off") + if (what == "off") { surf_tool->add_smooth_group(false); - else + } else { surf_tool->add_smooth_group(true); + } } else if (/*l.begins_with("g ") ||*/ l.begins_with("usemtl ") || (l.begins_with("o ") || f->eof_reached())) { //commit group to mesh //groups are too annoying if (surf_tool->get_vertex_array().size()) { diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index f4fb0f9f0c..ec82f78e75 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -127,8 +127,9 @@ void EditorScenePostImport::_bind_methods() { } Node *EditorScenePostImport::post_import(Node *p_scene) { - if (get_script_instance()) + if (get_script_instance()) { return get_script_instance()->call("post_import", p_scene); + } return p_scene; } @@ -173,20 +174,24 @@ String ResourceImporterScene::get_resource_type() const { bool ResourceImporterScene::get_option_visibility(const String &p_option, const Map &p_options) const { if (p_option.begins_with("animation/")) { - if (p_option != "animation/import" && !bool(p_options["animation/import"])) + if (p_option != "animation/import" && !bool(p_options["animation/import"])) { return false; + } - if (p_option == "animation/keep_custom_tracks" && int(p_options["animation/storage"]) == 0) + if (p_option == "animation/keep_custom_tracks" && int(p_options["animation/storage"]) == 0) { return false; + } - if (p_option.begins_with("animation/optimizer/") && p_option != "animation/optimizer/enabled" && !bool(p_options["animation/optimizer/enabled"])) + if (p_option.begins_with("animation/optimizer/") && p_option != "animation/optimizer/enabled" && !bool(p_options["animation/optimizer/enabled"])) { return false; + } if (p_option.begins_with("animation/clip_")) { int max_clip = p_options["animation/clips/amount"]; int clip = p_option.get_slice("/", 1).get_slice("_", 1).to_int() - 1; - if (clip >= max_clip) + if (clip >= max_clip) { return false; + } } } @@ -240,12 +245,15 @@ static bool _teststr(const String &p_what, const String &p_str) { what = what.substr(0, what.length() - 1); } - if (what.findn("$" + p_str) != -1) //blender and other stuff + if (what.findn("$" + p_str) != -1) { //blender and other stuff return true; - if (what.to_lower().ends_with("-" + p_str)) //collada only supports "_" and "-" besides letters + } + if (what.to_lower().ends_with("-" + p_str)) { //collada only supports "_" and "-" besides letters return true; - if (what.to_lower().ends_with("_" + p_str)) //collada only supports "_" and "-" besides letters + } + if (what.to_lower().ends_with("_" + p_str)) { //collada only supports "_" and "-" besides letters return true; + } return false; } @@ -259,12 +267,15 @@ static String _fixstr(const String &p_what, const String &p_str) { String end = p_what.substr(what.length(), p_what.length() - what.length()); - if (what.findn("$" + p_str) != -1) //blender and other stuff + if (what.findn("$" + p_str) != -1) { //blender and other stuff return what.replace("$" + p_str, "") + end; - if (what.to_lower().ends_with("-" + p_str)) //collada only supports "_" and "-" besides letters + } + if (what.to_lower().ends_with("-" + p_str)) { //collada only supports "_" and "-" besides letters return what.substr(0, what.length() - (p_str.length() + 1)) + end; - if (what.to_lower().ends_with("_" + p_str)) //collada only supports "_" and "-" besides letters + } + if (what.to_lower().ends_with("_" + p_str)) { //collada only supports "_" and "-" besides letters return what.substr(0, what.length() - (p_str.length() + 1)) + end; + } return what; } @@ -308,8 +319,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map if (m.is_valid()) { for (int i = 0; i < m->get_surface_count(); i++) { Ref mat = m->surface_get_material(i); - if (!mat.is_valid()) + if (!mat.is_valid()) { continue; + } if (_teststr(mat->get_name(), "alpha")) { mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); @@ -353,8 +365,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map } if (_teststr(name, "colonly") || _teststr(name, "convcolonly")) { - if (isroot) + if (isroot) { return p_node; + } MeshInstance3D *mi = Object::cast_to(p_node); if (mi) { Ref mesh = mi->get_mesh(); @@ -436,8 +449,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map } } else if (_teststr(name, "rigid") && Object::cast_to(p_node)) { - if (isroot) + if (isroot) { return p_node; + } MeshInstance3D *mi = Object::cast_to(p_node); Ref mesh = mi->get_mesh(); @@ -523,8 +537,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map } } else if (_teststr(name, "navmesh") && Object::cast_to(p_node)) { - if (isroot) + if (isroot) { return p_node; + } MeshInstance3D *mi = Object::cast_to(p_node); @@ -541,8 +556,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map memdelete(p_node); p_node = nmi; } else if (_teststr(name, "vehicle")) { - if (isroot) + if (isroot) { return p_node; + } Node *owner = p_node->get_owner(); Node3D *s = Object::cast_to(p_node); @@ -560,8 +576,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map p_node = bv; } else if (_teststr(name, "wheel")) { - if (isroot) + if (isroot) { return p_node; + } Node *owner = p_node->get_owner(); Node3D *s = Object::cast_to(p_node); @@ -622,16 +639,18 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map } void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, bool p_bake_all) { - if (!scene->has_node(String("AnimationPlayer"))) + if (!scene->has_node(String("AnimationPlayer"))) { return; + } Node *n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); AnimationPlayer *anim = Object::cast_to(n); ERR_FAIL_COND(!anim); - if (!anim->has_animation("default")) + if (!anim->has_animation("default")) { return; + } Ref default_anim = anim->get_animation("default"); @@ -640,8 +659,9 @@ void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, boo float from = p_clips[i + 1]; float to = p_clips[i + 2]; bool loop = p_clips[i + 3]; - if (from >= to) + if (from >= to) { continue; + } Ref new_anim = memnew(Animation); @@ -746,8 +766,9 @@ void ResourceImporterScene::_filter_anim_tracks(Ref anim, Set } void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { - if (!scene->has_node(String("AnimationPlayer"))) + if (!scene->has_node(String("AnimationPlayer"))) { return; + } Node *n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); AnimationPlayer *anim = Object::cast_to(n); @@ -779,55 +800,63 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { Vector filters = strings[i].substr(1, strings[i].length()).split(","); for (int j = 0; j < filters.size(); j++) { String fname = filters[j].strip_edges(); - if (fname == "") + if (fname == "") { continue; + } int fc = fname[0]; bool plus; - if (fc == '+') + if (fc == '+') { plus = true; - else if (fc == '-') + } else if (fc == '-') { plus = false; - else + } else { continue; + } String filter = fname.substr(1, fname.length()).strip_edges(); - if (!name.matchn(filter)) + if (!name.matchn(filter)) { continue; + } valid_for_this = plus; } - if (valid_for_this) + if (valid_for_this) { valid = true; + } } else if (valid_for_this) { Ref a = anim->get_animation(name); - if (!a.is_valid()) + if (!a.is_valid()) { continue; + } for (int j = 0; j < a->get_track_count(); j++) { String path = a->track_get_path(j); String tname = strings[i]; - if (tname == "") + if (tname == "") { continue; + } int fc = tname[0]; bool plus; - if (fc == '+') + if (fc == '+') { plus = true; - else if (fc == '-') + } else if (fc == '-') { plus = false; - else + } else { continue; + } String filter = tname.substr(1, tname.length()).strip_edges(); - if (!path.matchn(filter)) + if (!path.matchn(filter)) { continue; + } - if (plus) + if (plus) { keep_local.insert(path); - else if (!keep.has(path)) { + } else if (!keep.has(path)) { keep_local.erase(path); } } @@ -844,8 +873,9 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { } void ResourceImporterScene::_optimize_animations(Node *scene, float p_max_lin_error, float p_max_ang_error, float p_max_angle) { - if (!scene->has_node(String("AnimationPlayer"))) + if (!scene->has_node(String("AnimationPlayer"))) { return; + } Node *n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); AnimationPlayer *anim = Object::cast_to(n); @@ -1005,10 +1035,12 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String for (int i = 0; i < mesh->get_surface_count(); i++) { mat = mesh->surface_get_material(i); - if (!mat.is_valid()) + if (!mat.is_valid()) { continue; - if (mat->get_name() == "") + } + if (mat->get_name() == "") { continue; + } if (!p_materials.has(mat)) { String ext_name; @@ -1072,8 +1104,9 @@ void ResourceImporterScene::get_import_options(List *r_options, in String script_ext_hint; for (List::Element *E = script_extentions.front(); E; E = E->next()) { - if (script_ext_hint != "") + if (script_ext_hint != "") { script_ext_hint += ","; + } script_ext_hint += "*." + E->get(); } @@ -1130,8 +1163,9 @@ Node *ResourceImporterScene::import_scene_from_other_importer(EditorSceneImporte String ext = p_path.get_extension().to_lower(); for (Set>::Element *E = importers.front(); E; E = E->next()) { - if (E->get().ptr() == p_exception) + if (E->get().ptr() == p_exception) { continue; + } List extensions; E->get()->get_extensions(&extensions); @@ -1142,8 +1176,9 @@ Node *ResourceImporterScene::import_scene_from_other_importer(EditorSceneImporte } } - if (importer.is_valid()) + if (importer.is_valid()) { break; + } } ERR_FAIL_COND_V(!importer.is_valid(), nullptr); @@ -1158,8 +1193,9 @@ Ref ResourceImporterScene::import_animation_from_other_importer(Edito String ext = p_path.get_extension().to_lower(); for (Set>::Element *E = importers.front(); E; E = E->next()) { - if (E->get().ptr() == p_exception) + if (E->get().ptr() == p_exception) { continue; + } List extensions; E->get()->get_extensions(&extensions); @@ -1170,8 +1206,9 @@ Ref ResourceImporterScene::import_animation_from_other_importer(Edito } } - if (importer.is_valid()) + if (importer.is_valid()) { break; + } } ERR_FAIL_COND_V(!importer.is_valid(), nullptr); @@ -1199,8 +1236,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p } } - if (importer.is_valid()) + if (importer.is_valid()) { break; + } } ERR_FAIL_COND_V(!importer.is_valid(), ERR_FILE_UNRECOGNIZED); @@ -1208,23 +1246,29 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p float fps = p_options["animation/fps"]; int import_flags = EditorSceneImporter::IMPORT_ANIMATION_DETECT_LOOP; - if (!bool(p_options["animation/optimizer/remove_unused_tracks"])) + if (!bool(p_options["animation/optimizer/remove_unused_tracks"])) { import_flags |= EditorSceneImporter::IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS; + } - if (bool(p_options["animation/import"])) + if (bool(p_options["animation/import"])) { import_flags |= EditorSceneImporter::IMPORT_ANIMATION; + } - if (int(p_options["meshes/compress"])) + if (int(p_options["meshes/compress"])) { import_flags |= EditorSceneImporter::IMPORT_USE_COMPRESSION; + } - if (bool(p_options["meshes/ensure_tangents"])) + if (bool(p_options["meshes/ensure_tangents"])) { import_flags |= EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS; + } - if (int(p_options["materials/location"]) == 0) + if (int(p_options["materials/location"]) == 0) { import_flags |= EditorSceneImporter::IMPORT_MATERIALS_IN_INSTANCES; + } - if (bool(p_options["skins/use_named_skins"])) + if (bool(p_options["skins/use_named_skins"])) { import_flags |= EditorSceneImporter::IMPORT_USE_NAMED_SKIN_BINDS; + } Error err = OK; List missing_deps; // for now, not much will be done with this @@ -1262,10 +1306,11 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p Object::cast_to(scene)->scale(Vector3(root_scale, root_scale, root_scale)); } - if (p_options["nodes/root_name"] != "Scene Root") + if (p_options["nodes/root_name"] != "Scene Root") { scene->set_name(p_options["nodes/root_name"]); - else + } else { scene->set_name(p_save_path.get_file().get_basename()); + } err = OK; @@ -1345,8 +1390,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p FileAccess *file = FileAccess::open(cache_file_path, FileAccess::READ, &err2); if (err2) { - if (file) + if (file) { memdelete(file); + } } else { int cache_size = file->get_len(); cache_data.resize(cache_size); @@ -1405,8 +1451,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p FileAccess *file = FileAccess::open(cache_file_path, FileAccess::WRITE, &err2); if (err2) { - if (file) + if (file) { memdelete(file); + } } else { // Store number of entries file->store_32(used_unwraps.size()); @@ -1486,8 +1533,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p //save sub-scenes as instances! for (int i = 0; i < scene->get_child_count(); i++) { Node *child = scene->get_child(i); - if (child->get_owner() != scene) + if (child->get_owner() != scene) { continue; //not a real child probably created by scene type (ig, a scrollbar) + } _replace_owner(child, scene, child); String cn = String(child->get_name()).strip_edges().replace(".", "_").replace(":", "_"); diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index ab23ab6db6..a13324f0fc 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -314,16 +314,21 @@ void ResourceImporterTexture::_save_stex(const Ref &p_image, const String f->store_32(p_image->get_height()); uint32_t flags = 0; - if (p_streamable) + if (p_streamable) { flags |= StreamTexture2D::FORMAT_BIT_STREAM; - if (p_mipmaps) + } + if (p_mipmaps) { flags |= StreamTexture2D::FORMAT_BIT_HAS_MIPMAPS; //mipmaps bit - if (p_detect_3d) + } + if (p_detect_3d) { flags |= StreamTexture2D::FORMAT_BIT_DETECT_3D; - if (p_detect_roughness) + } + if (p_detect_roughness) { flags |= StreamTexture2D::FORMAT_BIT_DETECT_ROUGNESS; - if (p_detect_normal) + } + if (p_detect_normal) { flags |= StreamTexture2D::FORMAT_BIT_DETECT_NORMAL; + } f->store_32(flags); f->store_32(p_limit_mipmap); @@ -407,8 +412,9 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String Ref image; image.instance(); Error err = ImageLoader::load_image(p_source_file, image, nullptr, hdr_as_srgb, scale); - if (err != OK) + if (err != OK) { return err; + } Array formats_imported; diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp index 0ef5d84eca..0818655c4c 100644 --- a/editor/import/resource_importer_texture_atlas.cpp +++ b/editor/import/resource_importer_texture_atlas.cpp @@ -176,10 +176,11 @@ static void _plot_triangle(Vector2 *vertices, const Vector2 &p_offset, bool p_tr } } xf += dx_far; - if (yi < y[1]) + if (yi < y[1]) { xt += dx_upper; - else + } else { xt += dx_low; + } } } diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index eace84400a..cb669b4c89 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -260,8 +260,9 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s * 22:38 06.07.2017 GMT **/ - for (int i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) { file->get_32(); // i wish to know why should i do this... no doc! + } // only read 0x00 (loop forward), 0x01 (loop ping-pong) and 0x02 (loop backward) // Skip anything else because it's not supported, reserved for future uses or sampler specific @@ -361,8 +362,9 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s float max = 0; for (int i = 0; i < data.size(); i++) { float amp = Math::abs(data[i]); - if (amp > max) + if (amp > max) { max = amp; + } } if (max > 0) { diff --git a/editor/import/resource_importer_wav.h b/editor/import/resource_importer_wav.h index b48c5f4c32..3ff3aea9f4 100644 --- a/editor/import/resource_importer_wav.h +++ b/editor/import/resource_importer_wav.h @@ -72,8 +72,9 @@ public: int datalen = p_data.size(); int datamax = datalen; - if (datalen & 1) + if (datalen & 1) { datalen++; + } dst_data.resize(datalen / 2 + 4); uint8_t *w = dst_data.ptrw(); @@ -96,9 +97,9 @@ public: uint8_t nibble; int16_t xm_sample; - if (i >= datamax) + if (i >= datamax) { xm_sample = 0; - else { + } else { xm_sample = CLAMP(in[i] * 32767.0, -32768, 32767); /* if (xm_sample==32767 || xm_sample==-32768) @@ -130,10 +131,11 @@ public: mask >>= 1; }; - if (nibble & 8) + if (nibble & 8) { prev -= vpdiff; - else + } else { prev += vpdiff; + } if (prev > 32767) { //printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip up %i\n",i,xm_sample,prev,diff,vpdiff,prev); @@ -144,10 +146,11 @@ public: } step_idx += _ima_adpcm_index_table[nibble]; - if (step_idx < 0) + if (step_idx < 0) { step_idx = 0; - else if (step_idx > 88) + } else if (step_idx > 88) { step_idx = 88; + } if (i & 1) { *out |= nibble << 4; -- cgit v1.2.3