diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 16:41:43 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 21:57:34 +0200 |
commit | 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (patch) | |
tree | 198d4ff7665d89307f6ca2469fa38620a9eb1672 /editor/import | |
parent | 07bc4e2f96f8f47991339654ff4ab16acc19d44f (diff) |
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
Diffstat (limited to 'editor/import')
-rw-r--r-- | editor/import/collada.cpp | 330 | ||||
-rw-r--r-- | editor/import/collada.h | 36 | ||||
-rw-r--r-- | editor/import/editor_import_collada.cpp | 142 | ||||
-rw-r--r-- | editor/import/editor_scene_importer_gltf.cpp | 147 | ||||
-rw-r--r-- | editor/import/resource_importer_bitmask.cpp | 3 | ||||
-rw-r--r-- | editor/import/resource_importer_layered_texture.cpp | 3 | ||||
-rw-r--r-- | editor/import/resource_importer_obj.cpp | 14 | ||||
-rw-r--r-- | editor/import/resource_importer_scene.cpp | 158 | ||||
-rw-r--r-- | editor/import/resource_importer_texture.cpp | 18 | ||||
-rw-r--r-- | editor/import/resource_importer_texture_atlas.cpp | 5 | ||||
-rw-r--r-- | editor/import/resource_importer_wav.cpp | 6 | ||||
-rw-r--r-- | editor/import/resource_importer_wav.h | 17 |
12 files changed, 576 insertions, 303 deletions
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<float> Collada::AnimationTrack::get_value_at_time(float p_time) const { @@ -178,14 +182,17 @@ Vector<float> 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 <asset> + } } } @@ -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 <asset> + } } } @@ -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 <asset> + } } } @@ -343,8 +360,9 @@ void Collada::_parse_material(XMLParser &parser) { //! reads floats from inside of xml element until end of xml element Vector<float> Collada::_read_float_array(XMLParser &parser) { - if (parser.is_empty()) + if (parser.is_empty()) { return Vector<float>(); + } Vector<String> splitters; splitters.push_back(" "); @@ -362,16 +380,18 @@ Vector<float> 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<String> Collada::_read_string_array(XMLParser &parser) { - if (parser.is_empty()) + if (parser.is_empty()) { return Vector<String>(); + } Vector<String> array; while (parser.read() == OK) { @@ -382,16 +402,18 @@ Vector<String> 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<String> 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 <asset> + } } 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 <asset> + } } 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<String> 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<String, Vector<String>> 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<String, String>(); } 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 <asset> + } } 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<int>(); + } 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<int>(); + } 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 <asset> + } } 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 <asset> + } } } @@ -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 <asset> + } } } @@ -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<NodeGeometry *>(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<Node *> 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<Collada::NodeJoint *>(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<StandardMaterial3D> 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<ArrayMesh> &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<ArrayMesh> &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<ArrayMesh> &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<ArrayMesh> &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<ArrayMesh> &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<ArrayMesh> &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> 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<String, NodeMap>::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<String, bool>::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<String> *r_extensions) cons Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *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;i<state.missing_textures.size();i++) { - EditorNode::add_io_error("Texture Not Found: "+state.missing_textures[i]); - } - */ + for(int i=0;i<state.missing_textures.size();i++) { + EditorNode::add_io_error("Texture Not Found: "+state.missing_textures[i]); + } + */ if (r_missing_deps) { for (int i = 0; i < state.missing_textures.size(); i++) { @@ -1645,10 +1682,11 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_ AnimationPlayer *ap = memnew(AnimationPlayer); for (int i = 0; i < state.animations.size(); i++) { String name; - if (state.animations[i]->get_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<Animation> 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<Animation>(); + } Ref<Animation> 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<uint8_t> _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<double> EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, const ERR_FAIL_INDEX_V(a.buffer_view, state.buffer_views.size(), Vector<double>()); 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<double>(); + } } else { //fill with zeros, as bufferview is not defined. @@ -731,14 +740,16 @@ Vector<double> 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<double>(); + } Vector<double> 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<double>(); + } for (int i = 0; i < indices.size(); i++) { const int write_offset = int(indices[i]) * component_count; @@ -756,8 +767,9 @@ Vector<int> EditorSceneImporterGLTF::_decode_accessor_as_ints(GLTFState &state, const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<int> 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<float> EditorSceneImporterGLTF::_decode_accessor_as_floats(GLTFState &sta const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<float> 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<Vector2> EditorSceneImporterGLTF::_decode_accessor_as_vec2(GLTFState &sta const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Vector2> 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<Vector3> EditorSceneImporterGLTF::_decode_accessor_as_vec3(GLTFState &sta const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Vector3> 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<Color> EditorSceneImporterGLTF::_decode_accessor_as_color(GLTFState &stat const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Color> 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<Quat> EditorSceneImporterGLTF::_decode_accessor_as_quat(GLTFState &state, const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Quat> 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<Transform2D> EditorSceneImporterGLTF::_decode_accessor_as_xform2d(GLTFSta const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Transform2D> 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<Basis> EditorSceneImporterGLTF::_decode_accessor_as_basis(GLTFState &stat const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Basis> 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<Transform> EditorSceneImporterGLTF::_decode_accessor_as_xform(GLTFState & const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); Vector<Transform> 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<Transform> 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<Texture2D> 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<float> &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; 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; 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<Ref<Mesh>> &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<Ref<Mesh>> &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<StringName, Variant> &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<Ref<Mesh> if (m.is_valid()) { for (int i = 0; i < m->get_surface_count(); i++) { Ref<StandardMaterial3D> 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<Ref<Mesh> } if (_teststr(name, "colonly") || _teststr(name, "convcolonly")) { - if (isroot) + if (isroot) { return p_node; + } MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); if (mi) { Ref<Mesh> mesh = mi->get_mesh(); @@ -436,8 +449,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } } else if (_teststr(name, "rigid") && Object::cast_to<MeshInstance3D>(p_node)) { - if (isroot) + if (isroot) { return p_node; + } MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); Ref<Mesh> mesh = mi->get_mesh(); @@ -523,8 +537,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } } else if (_teststr(name, "navmesh") && Object::cast_to<MeshInstance3D>(p_node)) { - if (isroot) + if (isroot) { return p_node; + } MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); @@ -541,8 +556,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> 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<Node3D>(p_node); @@ -560,8 +576,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> 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<Node3D>(p_node); @@ -622,16 +639,18 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } 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<AnimationPlayer>(n); ERR_FAIL_COND(!anim); - if (!anim->has_animation("default")) + if (!anim->has_animation("default")) { return; + } Ref<Animation> 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<Animation> new_anim = memnew(Animation); @@ -746,8 +766,9 @@ void ResourceImporterScene::_filter_anim_tracks(Ref<Animation> anim, Set<String> } 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<AnimationPlayer>(n); @@ -779,55 +800,63 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { Vector<String> 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<Animation> 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<AnimationPlayer>(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<ImportOption> *r_options, in String script_ext_hint; for (List<String>::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<Ref<EditorSceneImporter>>::Element *E = importers.front(); E; E = E->next()) { - if (E->get().ptr() == p_exception) + if (E->get().ptr() == p_exception) { continue; + } List<String> 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<Animation> ResourceImporterScene::import_animation_from_other_importer(Edito String ext = p_path.get_extension().to_lower(); for (Set<Ref<EditorSceneImporter>>::Element *E = importers.front(); E; E = E->next()) { - if (E->get().ptr() == p_exception) + if (E->get().ptr() == p_exception) { continue; + } List<String> extensions; E->get()->get_extensions(&extensions); @@ -1170,8 +1206,9 @@ Ref<Animation> 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<String> 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<Node3D>(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<Image> &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; 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; |