Skip Draco-compressed glTF 3d format files.

(cherry picked from commit b468104842)
This commit is contained in:
K. S. Ernest (iFire) Lee 2022-01-07 19:01:09 -08:00 committed by Rémi Verschelde
parent 7c61e6f72f
commit 44d436add6
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 38 additions and 17 deletions

View file

@ -6586,103 +6586,110 @@ Error GLTFDocument::parse(Ref<GLTFState> state, String p_path, bool p_read_binar
state->major_version = version.get_slice(".", 0).to_int(); state->major_version = version.get_slice(".", 0).to_int();
state->minor_version = version.get_slice(".", 1).to_int(); state->minor_version = version.get_slice(".", 1).to_int();
/* STEP 0 PARSE SCENE */ /* PARSE EXTENSIONS */
err = _parse_gltf_extensions(state);
if (err != OK) {
return Error::FAILED;
}
/* PARSE SCENE */
err = _parse_scenes(state); err = _parse_scenes(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 1 PARSE NODES */ /* PARSE NODES */
err = _parse_nodes(state); err = _parse_nodes(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 2 PARSE BUFFERS */ /* PARSE BUFFERS */
err = _parse_buffers(state, p_path.get_base_dir()); err = _parse_buffers(state, p_path.get_base_dir());
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 3 PARSE BUFFER VIEWS */ /* PARSE BUFFER VIEWS */
err = _parse_buffer_views(state); err = _parse_buffer_views(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 4 PARSE ACCESSORS */ /* PARSE ACCESSORS */
err = _parse_accessors(state); err = _parse_accessors(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 5 PARSE IMAGES */ /* PARSE IMAGES */
err = _parse_images(state, p_path.get_base_dir()); err = _parse_images(state, p_path.get_base_dir());
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 6 PARSE TEXTURES */ /* PARSE TEXTURES */
err = _parse_textures(state); err = _parse_textures(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 7 PARSE TEXTURES */ /* PARSE TEXTURES */
err = _parse_materials(state); err = _parse_materials(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 9 PARSE SKINS */ /* PARSE SKINS */
err = _parse_skins(state); err = _parse_skins(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 10 DETERMINE SKELETONS */ /* DETERMINE SKELETONS */
err = _determine_skeletons(state); err = _determine_skeletons(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 11 CREATE SKELETONS */ /* CREATE SKELETONS */
err = _create_skeletons(state); err = _create_skeletons(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 12 CREATE SKINS */ /* CREATE SKINS */
err = _create_skins(state); err = _create_skins(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 13 PARSE MESHES (we have enough info now) */ /* PARSE MESHES (we have enough info now) */
err = _parse_meshes(state); err = _parse_meshes(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 14 PARSE LIGHTS */ /* PARSE LIGHTS */
err = _parse_lights(state); err = _parse_lights(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 15 PARSE CAMERAS */ /* PARSE CAMERAS */
err = _parse_cameras(state); err = _parse_cameras(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 16 PARSE ANIMATIONS */ /* PARSE ANIMATIONS */
err = _parse_animations(state); err = _parse_animations(state);
if (err != OK) { if (err != OK) {
return Error::FAILED; return Error::FAILED;
} }
/* STEP 17 ASSIGN SCENE NAMES */ /* ASSIGN SCENE NAMES */
_assign_scene_names(state); _assign_scene_names(state);
return OK; return OK;
@ -6802,3 +6809,15 @@ Error GLTFDocument::_serialize_file(Ref<GLTFState> state, const String p_path) {
} }
return err; return err;
} }
Error GLTFDocument::_parse_gltf_extensions(Ref<GLTFState> state) {
ERR_FAIL_COND_V(!state.is_valid(), ERR_PARSE_ERROR);
if (state->json.has("extensionsRequired") && state->json["extensionsRequired"].get_type() == Variant::ARRAY) {
Array extensions_required = state->json["extensionsRequired"];
if (extensions_required.find("KHR_draco_mesh_compression") != -1) {
ERR_PRINT("glTF2 extension KHR_draco_mesh_compression is not supported.");
return ERR_UNAVAILABLE;
}
}
return OK;
}

View file

@ -373,6 +373,8 @@ public:
String _sanitize_scene_name(Ref<GLTFState> state, const String &p_name); String _sanitize_scene_name(Ref<GLTFState> state, const String &p_name);
String _legacy_validate_node_name(const String &p_name); String _legacy_validate_node_name(const String &p_name);
Error _parse_gltf_extensions(Ref<GLTFState> state);
void _process_mesh_instances(Ref<GLTFState> state, Node *scene_root); void _process_mesh_instances(Ref<GLTFState> state, Node *scene_root);
void _generate_scene_node(Ref<GLTFState> state, Node *scene_parent, void _generate_scene_node(Ref<GLTFState> state, Node *scene_parent,
Spatial *scene_root, Spatial *scene_root,