-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow intercepting GLTFDocument on scene import
- Create EditorSceneImporterGLTFBase, which is how all scene importers that use glTF as backing format can share behavior. - Allow user to intercept creation of GLTFDocument with virtual method _initialize_gltf, for example to conditionally add GLTFDocumentExtensions - De-duplicate file extension check by moving it into the ResourceImporterScene class.
- Loading branch information
Showing
15 changed files
with
188 additions
and
85 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
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
23 changes: 23 additions & 0 deletions
23
modules/gltf/doc_classes/EditorSceneFormatImporterGLTFBase.xml
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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<class name="EditorSceneFormatImporterGLTFBase" inherits="EditorSceneFormatImporter" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd"> | ||
<brief_description> | ||
Base class for all scene format importers that use glTF as intermediate representation. | ||
</brief_description> | ||
<description> | ||
</description> | ||
<tutorials> | ||
</tutorials> | ||
<methods> | ||
<method name="_initialize_gltf" qualifiers="virtual"> | ||
<return type="void" /> | ||
<param index="0" name="original_path" type="String" /> | ||
<param index="1" name="gltf_path" type="String" /> | ||
<param index="2" name="document" type="GLTFDocument" /> | ||
<param index="3" name="state" type="GLTFState" /> | ||
<description> | ||
This method can be overridden to modify the glTF document or state before any parsing has taken place. | ||
For example, this can be used to handle the glTF metadata provided in [code]extras[/code] or [code]extensions[/code] by modifying the [member GLTFDocument.extensions] passed into this method. | ||
</description> | ||
</method> | ||
</methods> | ||
</class> |
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
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
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,78 @@ | ||
/*************************************************************************/ | ||
/* editor_scene_importer_gltf_base.cpp */ | ||
/*************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/*************************************************************************/ | ||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ | ||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ | ||
/* */ | ||
/* 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. */ | ||
/*************************************************************************/ | ||
|
||
#ifdef TOOLS_ENABLED | ||
|
||
#include "editor_scene_importer_gltf_base.h" | ||
|
||
Variant EditorSceneFormatImporterGLTFBase::get_option_visibility(const String &p_path, bool p_for_animation, | ||
const String &p_option, const HashMap<StringName, Variant> &p_options) { | ||
return true; | ||
} | ||
|
||
void EditorSceneFormatImporterGLTFBase::get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options) { | ||
} | ||
|
||
Node *EditorSceneFormatImporterGLTFBase::generate_gltf(const String &p_path, const String &p_gltf_path, uint32_t p_flags, | ||
const HashMap<StringName, Variant> &p_options, int p_bake_fps, | ||
const String &p_base_dir, Error *r_err) { | ||
// Use GLTFDocument instead of glTF importer to keep image references. | ||
Ref<GLTFDocument> gltf; | ||
gltf.instantiate(); | ||
Ref<GLTFState> state; | ||
state.instantiate(); | ||
|
||
// Allow augmentation (e.g. adding document extensions). | ||
initialize_gltf(p_path, p_gltf_path, gltf, state); | ||
|
||
print_verbose(vformat("glTF path: %s", p_gltf_path)); | ||
Error err = gltf->append_from_file(p_gltf_path, state, p_flags, p_bake_fps, p_base_dir); | ||
if (err != OK) { | ||
if (r_err) { | ||
*r_err = FAILED; | ||
} | ||
return nullptr; | ||
} | ||
if (p_options.has("animation/import")) { | ||
state->set_create_animations(bool(p_options["animation/import"])); | ||
} | ||
return gltf->generate_scene(state, p_bake_fps); | ||
} | ||
|
||
void EditorSceneFormatImporterGLTFBase::initialize_gltf(const String &p_src_path, const String &p_gltf_path, | ||
Ref<GLTFDocument> p_document, Ref<GLTFState> p_state) { | ||
GDVIRTUAL_CALL(_initialize_gltf, p_src_path, p_gltf_path, p_document, p_state); | ||
} | ||
|
||
void EditorSceneFormatImporterGLTFBase::_bind_methods() { | ||
GDVIRTUAL_BIND(_initialize_gltf, "original_path", "gltf_path", "document", "state"); | ||
} | ||
|
||
#endif // TOOLS_ENABLED |
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,64 @@ | ||
/*************************************************************************/ | ||
/* editor_scene_importer_gltf_base.h */ | ||
/*************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/*************************************************************************/ | ||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ | ||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ | ||
/* */ | ||
/* 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 EDITOR_SCENE_IMPORTER_GLTF_BASE_H | ||
#define EDITOR_SCENE_IMPORTER_GLTF_BASE_H | ||
|
||
#ifdef TOOLS_ENABLED | ||
|
||
#include "../gltf_document.h" | ||
#include "../gltf_state.h" | ||
|
||
#include "editor/import/resource_importer_scene.h" | ||
|
||
class EditorSceneFormatImporterGLTFBase : public EditorSceneFormatImporter { | ||
GDCLASS(EditorSceneFormatImporterGLTFBase, EditorSceneFormatImporter); | ||
|
||
protected: | ||
static void _bind_methods(); | ||
|
||
Node *generate_gltf(const String &p_path, const String &p_gltf_path, uint32_t p_flags, | ||
const HashMap<StringName, Variant> &p_options, int p_bake_fps, | ||
const String &p_base_dir, Error *r_err); | ||
|
||
GDVIRTUAL4(_initialize_gltf, String, String, Ref<GLTFDocument>, Ref<GLTFState>) | ||
|
||
public: | ||
virtual void get_import_options(const String &p_path, | ||
List<ResourceImporter::ImportOption> *r_options) override; | ||
virtual Variant get_option_visibility(const String &p_path, bool p_for_animation, const String &p_option, | ||
const HashMap<StringName, Variant> &p_options) override; | ||
virtual void initialize_gltf(const String &p_src_path, const String &p_gltf_path, | ||
Ref<GLTFDocument> p_document, Ref<GLTFState> p_state); | ||
}; | ||
|
||
#endif // TOOLS_ENABLED | ||
|
||
#endif // EDITOR_SCENE_IMPORTER_GLTF_BASE_H |
Oops, something went wrong.