Backported and added EditorSceneFormatImporterFBX and EditorSceneFormatImporterGLTF to the build.

This commit is contained in:
Relintai 2022-08-08 18:52:58 +02:00
parent f086cf4128
commit 9ae0437034
8 changed files with 60 additions and 45 deletions

View File

@ -18,5 +18,7 @@ env_gltf.add_source_files(env.modules_sources, "gltf_document.cpp")
env_gltf.add_source_files(env.modules_sources, "extensions/*.cpp")
env_gltf.add_source_files(env.modules_sources, "structures/*.cpp")
#if env["tools"]:
# env_gltf.add_source_files(env.modules_sources, "editor/*.cpp")
if env["tools"]:
env_gltf.add_source_files(env.modules_sources, "editor/editor_scene_importer_gltf.cpp")
env_gltf.add_source_files(env.modules_sources, "editor/editor_scene_importer_fbx.cpp")
#env_gltf.add_source_files(env.modules_sources, "editor/*.cpp")

View File

@ -35,7 +35,8 @@
#include "../gltf_document.h"
#include "../gltf_state.h"
#include "core/config/project_settings.h"
#include "core/os/os.h"
#include "core/project_settings.h"
#include "editor/editor_settings.h"
#include "scene/main/node.h"
#include "scene/resources/animation.h"
@ -48,16 +49,14 @@ void EditorSceneFormatImporterFBX::get_extensions(List<String> *r_extensions) co
r_extensions->push_back("fbx");
}
Node *EditorSceneFormatImporterFBX::import_scene(const String &p_path, uint32_t p_flags,
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
List<String> *r_missing_deps, Error *r_err) {
Node *EditorSceneFormatImporterFBX::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, uint32_t p_compress_flags, List<String> *r_missing_deps, Error *r_err) {
// Get global paths for source and sink.
// Don't use `c_escape()` as it can generate broken paths. These paths will be
// enclosed in double quotes by OS::execute(), so we only need to escape those.
// `c_escape_multiline()` seems to do this (escapes `\` and `"` only).
const String source_global = ProjectSettings::get_singleton()->globalize_path(p_path).c_escape_multiline();
const String sink = ProjectSettings::get_singleton()->get_imported_files_path().plus_file(
const String sink = ProjectSettings::get_singleton()->get_project_data_path().plus_file(
vformat("%s-%s.glb", p_path.get_file().get_basename(), p_path.md5_text()));
const String sink_global = ProjectSettings::get_singleton()->globalize_path(sink).c_escape_multiline();
@ -75,7 +74,8 @@ Node *EditorSceneFormatImporterFBX::import_scene(const String &p_path, uint32_t
String standard_out;
int ret;
OS::get_singleton()->execute(fbx2gltf_path, args, &standard_out, &ret, true);
OS::get_singleton()->execute(fbx2gltf_path, args, true, nullptr, &standard_out, &ret, true);
print_verbose(fbx2gltf_path);
print_verbose(standard_out);
@ -91,27 +91,33 @@ Node *EditorSceneFormatImporterFBX::import_scene(const String &p_path, uint32_t
// Use GLTFDocument instead of glTF importer to keep image references.
Ref<GLTFDocument> gltf;
gltf.instantiate();
gltf.instance();
Ref<GLTFState> state;
state.instantiate();
state.instance();
print_verbose(vformat("glTF path: %s", sink));
Error err = gltf->append_from_file(sink, state, p_flags, p_bake_fps);
if (err != OK) {
if (r_err) {
*r_err = FAILED;
}
return nullptr;
}
return gltf->generate_scene(state, p_bake_fps);
}
Variant EditorSceneFormatImporterFBX::get_option_visibility(const String &p_path, bool p_for_animation,
const String &p_option, const HashMap<StringName, Variant> &p_options) {
bool EditorSceneFormatImporterFBX::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
return true;
}
void EditorSceneFormatImporterFBX::get_import_options(const String &p_path,
List<ResourceImporter::ImportOption> *r_options) {
void EditorSceneFormatImporterFBX::get_import_options(List<ResourceImporterScene::ImportOption> *r_options, int p_preset) const {
}
EditorSceneFormatImporterFBX::EditorSceneFormatImporterFBX() {
}
EditorSceneFormatImporterFBX::~EditorSceneFormatImporterFBX() {
}
#endif // TOOLS_ENABLED

View File

@ -38,19 +38,19 @@
class Animation;
class Node;
class EditorSceneFormatImporterFBX : public EditorSceneFormatImporter {
GDCLASS(EditorSceneFormatImporterFBX, EditorSceneFormatImporter);
class EditorSceneFormatImporterFBX : public EditorSceneImporter {
GDCLASS(EditorSceneFormatImporterFBX, EditorSceneImporter);
public:
virtual uint32_t get_import_flags() const override;
virtual void get_extensions(List<String> *r_extensions) const override;
virtual Node *import_scene(const String &p_path, uint32_t p_flags,
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
List<String> *r_missing_deps, Error *r_err = nullptr) override;
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 uint32_t get_import_flags() const;
virtual void get_extensions(List<String> *r_extensions) const;
virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, uint32_t p_compress_flags, List<String> *r_missing_deps = nullptr, Error *r_err = nullptr);
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
virtual void get_import_options(List<ResourceImporterScene::ImportOption> *r_options, int p_preset = 0) const;
EditorSceneFormatImporterFBX();
~EditorSceneFormatImporterFBX();
};
#endif // TOOLS_ENABLED

View File

@ -47,20 +47,27 @@ void EditorSceneFormatImporterGLTF::get_extensions(List<String> *r_extensions) c
}
Node *EditorSceneFormatImporterGLTF::import_scene(const String &p_path, uint32_t p_flags,
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
List<String> *r_missing_deps, Error *r_err) {
int p_bake_fps, uint32_t p_compress_flags, List<String> *r_missing_deps, Error *r_err) {
Ref<GLTFDocument> doc;
doc.instantiate();
doc.instance();
Ref<GLTFState> state;
state.instantiate();
state.instance();
Error err = doc->append_from_file(p_path, state, p_flags, p_bake_fps);
if (err != OK) {
if (r_err) {
*r_err = err;
}
return nullptr;
}
return doc->generate_scene(state, p_bake_fps);
}
Ref<Animation> EditorSceneFormatImporterGLTF::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) {
return Ref<Animation>();
}
#endif // TOOLS_ENABLED

View File

@ -41,15 +41,15 @@
class Animation;
class Node;
class EditorSceneFormatImporterGLTF : public EditorSceneFormatImporter {
GDCLASS(EditorSceneFormatImporterGLTF, EditorSceneFormatImporter);
class EditorSceneFormatImporterGLTF : public EditorSceneImporter {
GDCLASS(EditorSceneFormatImporterGLTF, EditorSceneImporter);
public:
virtual uint32_t get_import_flags() const override;
virtual void get_extensions(List<String> *r_extensions) const override;
virtual Node *import_scene(const String &p_path, uint32_t p_flags,
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
List<String> *r_missing_deps, Error *r_err = nullptr) override;
virtual uint32_t get_import_flags() const;
virtual void get_extensions(List<String> *r_extensions) const;
virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, uint32_t p_compress_flags, List<String> *r_missing_deps = nullptr, Error *r_err = nullptr);
virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps);
};
#endif // TOOLS_ENABLED

View File

@ -7201,6 +7201,9 @@ GLTFDocument::GLTFDocument() {
document_extensions.push_back(extension_editor);
}
GLTFDocument::~GLTFDocument() {
}
PoolByteArray GLTFDocument::_serialize_glb_buffer(Ref<GLTFState> state, Error *r_err) {
Error err = _encode_buffer_glb(state, "");
if (r_err) {
@ -7290,11 +7293,11 @@ Node *GLTFDocument::generate_scene(Ref<GLTFState> state, int32_t p_bake_fps) {
}
}
const GLTFNodeIndex* scene_nodes_ptr = NULL;
const GLTFNodeIndex *scene_nodes_ptr = NULL;
while ((scene_nodes_ptr = state->scene_nodes.next(scene_nodes_ptr))) {
//for (KeyValue<GLTFNodeIndex, Node *> E : state->scene_nodes) {
GLTFNodeIndex E_key = *scene_nodes_ptr;
Node ** E_value = state->scene_nodes.getptr(E_key);
//for (KeyValue<GLTFNodeIndex, Node *> E : state->scene_nodes) {
GLTFNodeIndex E_key = *scene_nodes_ptr;
Node **E_value = state->scene_nodes.getptr(E_key);
ERR_CONTINUE(!E_value);

View File

@ -42,6 +42,7 @@
#include "scene/resources/material.h"
class Camera;
class GLTFDocumentExtension;
class GLTFDocument : public Resource {
GDCLASS(GLTFDocument, Resource);
@ -356,6 +357,7 @@ public:
Error _parse(Ref<GLTFState> state, String p_path, FileAccess *f, int p_bake_fps);
GLTFDocument();
~GLTFDocument();
protected:
static void _bind_methods();

View File

@ -75,11 +75,6 @@ void unregister_gltf_types() {
/*
#ifdef TOOLS_ENABLED
#include "core/project_settings.h"
#include "editor/editor_node.h"