From adbe74951362591f39828e346db10225bee36298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Mon, 19 Mar 2018 00:05:29 +0100 Subject: Fix glTF not accepting VEC3 colors Aside from the colors themselves, the rejection was adding somes issues later in the mesh import process. --- editor/import/editor_scene_importer_gltf.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 2636839764..9db1032e35 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -762,14 +762,22 @@ PoolVector EditorSceneImporterGLTF::_decode_accessor_as_color(GLTFState & PoolVector ret; if (attribs.size() == 0) return ret; - ERR_FAIL_COND_V(attribs.size() % 4 != 0, ret); + int type = state.accessors[p_accessor].type; + ERR_FAIL_COND_V(!(type == TYPE_VEC3 || type == TYPE_VEC4), ret); + int components; + if (type == TYPE_VEC3) { + components = 3; + } else { // TYPE_VEC4 + components = 4; + } + ERR_FAIL_COND_V(attribs.size() % components != 0, ret); const double *attribs_ptr = attribs.ptr(); - int ret_size = attribs.size() / 4; + int ret_size = attribs.size() / components; ret.resize(ret_size); { PoolVector::Write w = ret.write(); for (int i = 0; i < ret_size; i++) { - w[i] = Color(attribs_ptr[i * 4 + 0], attribs_ptr[i * 4 + 1], attribs_ptr[i * 4 + 2], attribs_ptr[i * 4 + 3]); + w[i] = Color(attribs_ptr[i * 4 + 0], attribs_ptr[i * 4 + 1], attribs_ptr[i * 4 + 2], components == 4 ? attribs_ptr[i * 4 + 3] : 1.0); } } return ret; -- cgit v1.2.3 From 1f26da0ad11e3b68f4ceecb2e39dc6b3302082ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Mon, 19 Mar 2018 00:24:00 +0100 Subject: Fix animation length from glTF not correctly set --- editor/import/editor_scene_importer_gltf.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 9db1032e35..321d29f2f6 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -1883,6 +1883,8 @@ void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlaye animation.instance(); animation->set_name(name); + float length = 0; + for (Map::Element *E = anim.tracks.front(); E; E = E->next()) { const GLTFAnimation::Track &track = E->get(); @@ -1901,8 +1903,6 @@ void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlaye node_path = ap->get_parent()->get_path_to(node->godot_nodes[i]); } - float length = 0; - for (int i = 0; i < track.rotation_track.times.size(); i++) { length = MAX(length, track.rotation_track.times[i]); } @@ -1919,8 +1919,6 @@ void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlaye } } - animation->set_length(length); - if (track.rotation_track.values.size() || track.translation_track.values.size() || track.scale_track.values.size()) { //make transform track int track_idx = animation->get_track_count(); @@ -2038,6 +2036,7 @@ void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlaye } } } + animation->set_length(length); ap->add_animation(name, animation); } -- cgit v1.2.3