From 44d436add624ab07d14e8fb193f309ff6c330cd2 Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Fri, 7 Jan 2022 19:01:09 -0800 Subject: [PATCH] Skip Draco-compressed glTF 3d format files. (cherry picked from commit b46810484214ff1a5ab109e0131cb2582cb57f83) --- modules/gltf/gltf_document.cpp | 53 +++++++++++++++++++++++----------- modules/gltf/gltf_document.h | 2 ++ 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 7716faae795..fda0379982f 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -6586,103 +6586,110 @@ Error GLTFDocument::parse(Ref state, String p_path, bool p_read_binar state->major_version = version.get_slice(".", 0).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); if (err != OK) { return Error::FAILED; } - /* STEP 1 PARSE NODES */ + /* PARSE NODES */ err = _parse_nodes(state); if (err != OK) { return Error::FAILED; } - /* STEP 2 PARSE BUFFERS */ + /* PARSE BUFFERS */ err = _parse_buffers(state, p_path.get_base_dir()); if (err != OK) { return Error::FAILED; } - /* STEP 3 PARSE BUFFER VIEWS */ + /* PARSE BUFFER VIEWS */ err = _parse_buffer_views(state); if (err != OK) { return Error::FAILED; } - /* STEP 4 PARSE ACCESSORS */ + /* PARSE ACCESSORS */ err = _parse_accessors(state); if (err != OK) { return Error::FAILED; } - /* STEP 5 PARSE IMAGES */ + /* PARSE IMAGES */ err = _parse_images(state, p_path.get_base_dir()); if (err != OK) { return Error::FAILED; } - /* STEP 6 PARSE TEXTURES */ + /* PARSE TEXTURES */ err = _parse_textures(state); if (err != OK) { return Error::FAILED; } - /* STEP 7 PARSE TEXTURES */ + /* PARSE TEXTURES */ err = _parse_materials(state); if (err != OK) { return Error::FAILED; } - /* STEP 9 PARSE SKINS */ + /* PARSE SKINS */ err = _parse_skins(state); if (err != OK) { return Error::FAILED; } - /* STEP 10 DETERMINE SKELETONS */ + /* DETERMINE SKELETONS */ err = _determine_skeletons(state); if (err != OK) { return Error::FAILED; } - /* STEP 11 CREATE SKELETONS */ + /* CREATE SKELETONS */ err = _create_skeletons(state); if (err != OK) { return Error::FAILED; } - /* STEP 12 CREATE SKINS */ + /* CREATE SKINS */ err = _create_skins(state); if (err != OK) { return Error::FAILED; } - /* STEP 13 PARSE MESHES (we have enough info now) */ + /* PARSE MESHES (we have enough info now) */ err = _parse_meshes(state); if (err != OK) { return Error::FAILED; } - /* STEP 14 PARSE LIGHTS */ + /* PARSE LIGHTS */ err = _parse_lights(state); if (err != OK) { return Error::FAILED; } - /* STEP 15 PARSE CAMERAS */ + /* PARSE CAMERAS */ err = _parse_cameras(state); if (err != OK) { return Error::FAILED; } - /* STEP 16 PARSE ANIMATIONS */ + /* PARSE ANIMATIONS */ err = _parse_animations(state); if (err != OK) { return Error::FAILED; } - /* STEP 17 ASSIGN SCENE NAMES */ + /* ASSIGN SCENE NAMES */ _assign_scene_names(state); return OK; @@ -6802,3 +6809,15 @@ Error GLTFDocument::_serialize_file(Ref state, const String p_path) { } return err; } + +Error GLTFDocument::_parse_gltf_extensions(Ref 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; +} diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h index 4a1666838ee..dfc4eeb14f5 100644 --- a/modules/gltf/gltf_document.h +++ b/modules/gltf/gltf_document.h @@ -373,6 +373,8 @@ public: String _sanitize_scene_name(Ref state, const String &p_name); String _legacy_validate_node_name(const String &p_name); + Error _parse_gltf_extensions(Ref state); + void _process_mesh_instances(Ref state, Node *scene_root); void _generate_scene_node(Ref state, Node *scene_parent, Spatial *scene_root,