mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-22 17:17:17 +01:00
Backported and added EditorSceneFormatImporterFBX and EditorSceneFormatImporterGLTF to the build.
This commit is contained in:
parent
f086cf4128
commit
9ae0437034
@ -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, "extensions/*.cpp")
|
||||||
env_gltf.add_source_files(env.modules_sources, "structures/*.cpp")
|
env_gltf.add_source_files(env.modules_sources, "structures/*.cpp")
|
||||||
|
|
||||||
#if env["tools"]:
|
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")
|
#env_gltf.add_source_files(env.modules_sources, "editor/*.cpp")
|
||||||
|
@ -35,7 +35,8 @@
|
|||||||
#include "../gltf_document.h"
|
#include "../gltf_document.h"
|
||||||
#include "../gltf_state.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 "editor/editor_settings.h"
|
||||||
#include "scene/main/node.h"
|
#include "scene/main/node.h"
|
||||||
#include "scene/resources/animation.h"
|
#include "scene/resources/animation.h"
|
||||||
@ -48,16 +49,14 @@ void EditorSceneFormatImporterFBX::get_extensions(List<String> *r_extensions) co
|
|||||||
r_extensions->push_back("fbx");
|
r_extensions->push_back("fbx");
|
||||||
}
|
}
|
||||||
|
|
||||||
Node *EditorSceneFormatImporterFBX::import_scene(const String &p_path, uint32_t p_flags,
|
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) {
|
||||||
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
|
|
||||||
List<String> *r_missing_deps, Error *r_err) {
|
|
||||||
// Get global paths for source and sink.
|
// Get global paths for source and sink.
|
||||||
|
|
||||||
// Don't use `c_escape()` as it can generate broken paths. These paths will be
|
// 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.
|
// enclosed in double quotes by OS::execute(), so we only need to escape those.
|
||||||
// `c_escape_multiline()` seems to do this (escapes `\` and `"` only).
|
// `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 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()));
|
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();
|
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;
|
String standard_out;
|
||||||
int ret;
|
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(fbx2gltf_path);
|
||||||
print_verbose(standard_out);
|
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.
|
// Use GLTFDocument instead of glTF importer to keep image references.
|
||||||
Ref<GLTFDocument> gltf;
|
Ref<GLTFDocument> gltf;
|
||||||
gltf.instantiate();
|
gltf.instance();
|
||||||
Ref<GLTFState> state;
|
Ref<GLTFState> state;
|
||||||
state.instantiate();
|
state.instance();
|
||||||
|
|
||||||
print_verbose(vformat("glTF path: %s", sink));
|
print_verbose(vformat("glTF path: %s", sink));
|
||||||
Error err = gltf->append_from_file(sink, state, p_flags, p_bake_fps);
|
Error err = gltf->append_from_file(sink, state, p_flags, p_bake_fps);
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
if (r_err) {
|
if (r_err) {
|
||||||
*r_err = FAILED;
|
*r_err = FAILED;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return gltf->generate_scene(state, p_bake_fps);
|
return gltf->generate_scene(state, p_bake_fps);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant EditorSceneFormatImporterFBX::get_option_visibility(const String &p_path, bool p_for_animation,
|
bool EditorSceneFormatImporterFBX::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
|
||||||
const String &p_option, const HashMap<StringName, Variant> &p_options) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorSceneFormatImporterFBX::get_import_options(const String &p_path,
|
void EditorSceneFormatImporterFBX::get_import_options(List<ResourceImporterScene::ImportOption> *r_options, int p_preset) const {
|
||||||
List<ResourceImporter::ImportOption> *r_options) {
|
}
|
||||||
|
|
||||||
|
EditorSceneFormatImporterFBX::EditorSceneFormatImporterFBX() {
|
||||||
|
}
|
||||||
|
EditorSceneFormatImporterFBX::~EditorSceneFormatImporterFBX() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TOOLS_ENABLED
|
#endif // TOOLS_ENABLED
|
||||||
|
@ -38,19 +38,19 @@
|
|||||||
class Animation;
|
class Animation;
|
||||||
class Node;
|
class Node;
|
||||||
|
|
||||||
class EditorSceneFormatImporterFBX : public EditorSceneFormatImporter {
|
class EditorSceneFormatImporterFBX : public EditorSceneImporter {
|
||||||
GDCLASS(EditorSceneFormatImporterFBX, EditorSceneFormatImporter);
|
GDCLASS(EditorSceneFormatImporterFBX, EditorSceneImporter);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual uint32_t get_import_flags() const override;
|
virtual uint32_t get_import_flags() const;
|
||||||
virtual void get_extensions(List<String> *r_extensions) const override;
|
virtual void get_extensions(List<String> *r_extensions) const;
|
||||||
virtual Node *import_scene(const String &p_path, uint32_t p_flags,
|
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);
|
||||||
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
|
|
||||||
List<String> *r_missing_deps, Error *r_err = nullptr) override;
|
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
|
||||||
virtual void get_import_options(const String &p_path,
|
virtual void get_import_options(List<ResourceImporterScene::ImportOption> *r_options, int p_preset = 0) const;
|
||||||
List<ResourceImporter::ImportOption> *r_options) override;
|
|
||||||
virtual Variant get_option_visibility(const String &p_path, bool p_for_animation, const String &p_option,
|
EditorSceneFormatImporterFBX();
|
||||||
const HashMap<StringName, Variant> &p_options) override;
|
~EditorSceneFormatImporterFBX();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TOOLS_ENABLED
|
#endif // TOOLS_ENABLED
|
||||||
|
@ -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,
|
Node *EditorSceneFormatImporterGLTF::import_scene(const String &p_path, uint32_t p_flags,
|
||||||
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
|
int p_bake_fps, uint32_t p_compress_flags, List<String> *r_missing_deps, Error *r_err) {
|
||||||
List<String> *r_missing_deps, Error *r_err) {
|
|
||||||
Ref<GLTFDocument> doc;
|
Ref<GLTFDocument> doc;
|
||||||
doc.instantiate();
|
doc.instance();
|
||||||
Ref<GLTFState> state;
|
Ref<GLTFState> state;
|
||||||
state.instantiate();
|
state.instance();
|
||||||
|
|
||||||
Error err = doc->append_from_file(p_path, state, p_flags, p_bake_fps);
|
Error err = doc->append_from_file(p_path, state, p_flags, p_bake_fps);
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
if (r_err) {
|
if (r_err) {
|
||||||
*r_err = err;
|
*r_err = err;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return doc->generate_scene(state, p_bake_fps);
|
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
|
#endif // TOOLS_ENABLED
|
||||||
|
@ -41,15 +41,15 @@
|
|||||||
class Animation;
|
class Animation;
|
||||||
class Node;
|
class Node;
|
||||||
|
|
||||||
class EditorSceneFormatImporterGLTF : public EditorSceneFormatImporter {
|
class EditorSceneFormatImporterGLTF : public EditorSceneImporter {
|
||||||
GDCLASS(EditorSceneFormatImporterGLTF, EditorSceneFormatImporter);
|
GDCLASS(EditorSceneFormatImporterGLTF, EditorSceneImporter);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual uint32_t get_import_flags() const override;
|
virtual uint32_t get_import_flags() const;
|
||||||
virtual void get_extensions(List<String> *r_extensions) const override;
|
virtual void get_extensions(List<String> *r_extensions) const;
|
||||||
virtual Node *import_scene(const String &p_path, uint32_t p_flags,
|
|
||||||
const HashMap<StringName, Variant> &p_options, int p_bake_fps,
|
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);
|
||||||
List<String> *r_missing_deps, Error *r_err = nullptr) override;
|
virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TOOLS_ENABLED
|
#endif // TOOLS_ENABLED
|
||||||
|
@ -7201,6 +7201,9 @@ GLTFDocument::GLTFDocument() {
|
|||||||
document_extensions.push_back(extension_editor);
|
document_extensions.push_back(extension_editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLTFDocument::~GLTFDocument() {
|
||||||
|
}
|
||||||
|
|
||||||
PoolByteArray GLTFDocument::_serialize_glb_buffer(Ref<GLTFState> state, Error *r_err) {
|
PoolByteArray GLTFDocument::_serialize_glb_buffer(Ref<GLTFState> state, Error *r_err) {
|
||||||
Error err = _encode_buffer_glb(state, "");
|
Error err = _encode_buffer_glb(state, "");
|
||||||
if (r_err) {
|
if (r_err) {
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include "scene/resources/material.h"
|
#include "scene/resources/material.h"
|
||||||
|
|
||||||
class Camera;
|
class Camera;
|
||||||
|
class GLTFDocumentExtension;
|
||||||
|
|
||||||
class GLTFDocument : public Resource {
|
class GLTFDocument : public Resource {
|
||||||
GDCLASS(GLTFDocument, Resource);
|
GDCLASS(GLTFDocument, Resource);
|
||||||
@ -356,6 +357,7 @@ public:
|
|||||||
Error _parse(Ref<GLTFState> state, String p_path, FileAccess *f, int p_bake_fps);
|
Error _parse(Ref<GLTFState> state, String p_path, FileAccess *f, int p_bake_fps);
|
||||||
|
|
||||||
GLTFDocument();
|
GLTFDocument();
|
||||||
|
~GLTFDocument();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
@ -75,11 +75,6 @@ void unregister_gltf_types() {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
#include "core/project_settings.h"
|
#include "core/project_settings.h"
|
||||||
#include "editor/editor_node.h"
|
#include "editor/editor_node.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user