Merge pull request #17622 from RandomShaper/gltf-fixes
A couple of fixes for glTF importing
This commit is contained in:
commit
ebce36c22f
1 changed files with 14 additions and 7 deletions
|
@ -762,14 +762,22 @@ PoolVector<Color> EditorSceneImporterGLTF::_decode_accessor_as_color(GLTFState &
|
||||||
PoolVector<Color> ret;
|
PoolVector<Color> ret;
|
||||||
if (attribs.size() == 0)
|
if (attribs.size() == 0)
|
||||||
return ret;
|
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();
|
const double *attribs_ptr = attribs.ptr();
|
||||||
int ret_size = attribs.size() / 4;
|
int ret_size = attribs.size() / components;
|
||||||
ret.resize(ret_size);
|
ret.resize(ret_size);
|
||||||
{
|
{
|
||||||
PoolVector<Color>::Write w = ret.write();
|
PoolVector<Color>::Write w = ret.write();
|
||||||
for (int i = 0; i < ret_size; i++) {
|
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;
|
return ret;
|
||||||
|
@ -1875,6 +1883,8 @@ void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlaye
|
||||||
animation.instance();
|
animation.instance();
|
||||||
animation->set_name(name);
|
animation->set_name(name);
|
||||||
|
|
||||||
|
float length = 0;
|
||||||
|
|
||||||
for (Map<int, GLTFAnimation::Track>::Element *E = anim.tracks.front(); E; E = E->next()) {
|
for (Map<int, GLTFAnimation::Track>::Element *E = anim.tracks.front(); E; E = E->next()) {
|
||||||
|
|
||||||
const GLTFAnimation::Track &track = E->get();
|
const GLTFAnimation::Track &track = E->get();
|
||||||
|
@ -1893,8 +1903,6 @@ void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlaye
|
||||||
node_path = ap->get_parent()->get_path_to(node->godot_nodes[i]);
|
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++) {
|
for (int i = 0; i < track.rotation_track.times.size(); i++) {
|
||||||
length = MAX(length, track.rotation_track.times[i]);
|
length = MAX(length, track.rotation_track.times[i]);
|
||||||
}
|
}
|
||||||
|
@ -1911,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()) {
|
if (track.rotation_track.values.size() || track.translation_track.values.size() || track.scale_track.values.size()) {
|
||||||
//make transform track
|
//make transform track
|
||||||
int track_idx = animation->get_track_count();
|
int track_idx = animation->get_track_count();
|
||||||
|
@ -2030,6 +2036,7 @@ void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlaye
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
animation->set_length(length);
|
||||||
|
|
||||||
ap->add_animation(name, animation);
|
ap->add_animation(name, animation);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue