-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not duplicate textures files when importing blender files
blender imports will always start with `.godot/imported` because we first convert the blend to gltf, store it in `.godot/imported` and run the import from there, so resources linked from blend files end up with duplicate textures. Introduce a new state where the resource exists on the disk but has not been imported yet.GLTF: Don't duplicate textures when importing blend files blender imports will always start with `.godot/imported` because we first convert the blend to gltf, store it in `.godot/imported` and run the import from there, so resources linked from blend files end up with duplicate textures after #96778 Introduce a new state where the resource exists on the disk but has not been imported yet.
- Loading branch information
Showing
5 changed files
with
270 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/**************************************************************************/ | ||
/* test_gltf_extras.h */ | ||
/**************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/**************************************************************************/ | ||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/**************************************************************************/ | ||
|
||
#ifndef TEST_GLTF_H | ||
#define TEST_GLTF_H | ||
|
||
#include "tests/test_macros.h" | ||
|
||
#ifdef TOOLS_ENABLED | ||
|
||
#include "core/os/os.h" | ||
#include "editor/import/3d/resource_importer_scene.h" | ||
#include "modules/gltf/editor/editor_scene_importer_gltf.h" | ||
#include "modules/gltf/gltf_document.h" | ||
#include "modules/gltf/gltf_state.h" | ||
#include "scene/3d/mesh_instance_3d.h" | ||
#include "scene/3d/skeleton_3d.h" | ||
#include "scene/main/window.h" | ||
#include "scene/resources/3d/primitive_meshes.h" | ||
#include "scene/resources/material.h" | ||
#include "scene/resources/packed_scene.h" | ||
|
||
namespace TestGltf { | ||
|
||
static Node *gltf_export_then_import(Node *p_root, String &p_tempfilebase) { | ||
Ref<GLTFDocument> doc; | ||
doc.instantiate(); | ||
Ref<GLTFState> state; | ||
state.instantiate(); | ||
Error err = doc->append_from_scene(p_root, state, EditorSceneFormatImporter::IMPORT_USE_NAMED_SKIN_BINDS); | ||
CHECK_MESSAGE(err == OK, "GLTF state generation failed."); | ||
err = doc->write_to_filesystem(state, p_tempfilebase + ".gltf"); | ||
CHECK_MESSAGE(err == OK, "Writing GLTF to cache dir failed."); | ||
|
||
// Setting up importers. | ||
Ref<ResourceImporterScene> import_scene = memnew(ResourceImporterScene("PackedScene", true)); | ||
ResourceFormatImporter::get_singleton()->add_importer(import_scene); | ||
Ref<EditorSceneFormatImporterGLTF> import_gltf; | ||
import_gltf.instantiate(); | ||
ResourceImporterScene::add_scene_importer(import_gltf); | ||
|
||
// GTLF importer behaves differently outside of editor, it's too late to modify Engine::get_editor_hint | ||
// as the registration of runtime extensions already happened, so remove them. See modules/gltf/register_types.cpp | ||
GLTFDocument::unregister_all_gltf_document_extensions(); | ||
|
||
HashMap<StringName, Variant> options(20); | ||
options["nodes/root_type"] = ""; | ||
options["nodes/root_name"] = ""; | ||
options["nodes/apply_root_scale"] = true; | ||
options["nodes/root_scale"] = 1.0; | ||
options["meshes/ensure_tangents"] = true; | ||
options["meshes/generate_lods"] = false; | ||
options["meshes/create_shadow_meshes"] = true; | ||
options["meshes/light_baking"] = 1; | ||
options["meshes/lightmap_texel_size"] = 0.2; | ||
options["meshes/force_disable_compression"] = false; | ||
options["skins/use_named_skins"] = true; | ||
options["animation/import"] = true; | ||
options["animation/fps"] = 30; | ||
options["animation/trimming"] = false; | ||
options["animation/remove_immutable_tracks"] = true; | ||
options["import_script/path"] = ""; | ||
options["_subresources"] = Dictionary(); | ||
options["gltf/naming_version"] = 1; | ||
|
||
// Process gltf file, note that this generates `.scn` resource from the 2nd argument. | ||
err = import_scene->import(p_tempfilebase + ".gltf", p_tempfilebase, options, nullptr, nullptr, nullptr); | ||
CHECK_MESSAGE(err == OK, "GLTF import failed."); | ||
ResourceImporterScene::remove_scene_importer(import_gltf); | ||
|
||
Ref<PackedScene> packed_scene = ResourceLoader::load(p_tempfilebase + ".scn", "", ResourceFormatLoader::CACHE_MODE_REPLACE, &err); | ||
CHECK_MESSAGE(err == OK, "Loading scene failed."); | ||
Node *p_scene = packed_scene->instantiate(); | ||
return p_scene; | ||
} | ||
} //namespace TestGltf | ||
|
||
#endif // TOOLS_ENABLED | ||
|
||
#endif // TEST_GLTF_EXTRAS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.