2017-03-05 14:47:28 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* resource_importer_scene.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 14:47:28 +00:00
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-03-05 14:47:28 +00:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2017-02-04 12:48:04 +00:00
|
|
|
#ifndef RESOURCEIMPORTERSCENE_H
|
|
|
|
#define RESOURCEIMPORTERSCENE_H
|
|
|
|
|
2019-02-12 12:30:56 +00:00
|
|
|
#include "core/io/resource_importer.h"
|
2020-12-12 12:06:59 +00:00
|
|
|
#include "scene/3d/node_3d.h"
|
2017-02-04 12:48:04 +00:00
|
|
|
#include "scene/resources/animation.h"
|
2017-06-07 21:18:55 +00:00
|
|
|
#include "scene/resources/mesh.h"
|
2020-03-26 21:49:16 +00:00
|
|
|
#include "scene/resources/shape_3d.h"
|
2020-12-12 12:06:59 +00:00
|
|
|
#include "scene/resources/skin.h"
|
2017-02-04 12:48:04 +00:00
|
|
|
|
2017-02-04 23:31:15 +00:00
|
|
|
class Material;
|
2021-03-19 12:57:52 +00:00
|
|
|
class AnimationPlayer;
|
2017-02-04 23:31:15 +00:00
|
|
|
|
2021-03-19 12:57:52 +00:00
|
|
|
class EditorSceneImporterMesh;
|
2021-06-04 16:03:15 +00:00
|
|
|
class EditorSceneImporter : public RefCounted {
|
|
|
|
GDCLASS(EditorSceneImporter, RefCounted);
|
2017-12-07 18:44:20 +00:00
|
|
|
|
2017-12-09 17:11:26 +00:00
|
|
|
protected:
|
2017-12-07 18:44:20 +00:00
|
|
|
static void _bind_methods();
|
2017-02-04 12:48:04 +00:00
|
|
|
|
2017-12-09 17:11:26 +00:00
|
|
|
Node *import_scene_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps);
|
2017-12-07 18:44:20 +00:00
|
|
|
Ref<Animation> import_animation_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps);
|
2017-12-09 17:11:26 +00:00
|
|
|
|
2021-08-22 01:52:44 +00:00
|
|
|
GDVIRTUAL0RC(int, _get_import_flags)
|
|
|
|
GDVIRTUAL0RC(Vector<String>, _get_extensions)
|
|
|
|
GDVIRTUAL3R(Object *, _import_scene, String, uint32_t, uint32_t)
|
|
|
|
GDVIRTUAL3R(Ref<Animation>, _import_animation, String, uint32_t, uint32_t)
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2017-02-04 12:48:04 +00:00
|
|
|
enum ImportFlags {
|
2017-03-05 15:44:50 +00:00
|
|
|
IMPORT_SCENE = 1,
|
|
|
|
IMPORT_ANIMATION = 2,
|
2021-03-19 12:57:52 +00:00
|
|
|
IMPORT_FAIL_ON_MISSING_DEPENDENCIES = 4,
|
|
|
|
IMPORT_GENERATE_TANGENT_ARRAYS = 8,
|
|
|
|
IMPORT_USE_NAMED_SKIN_BINDS = 16,
|
2017-02-04 12:48:04 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-12-07 18:44:20 +00:00
|
|
|
virtual uint32_t get_import_flags() const;
|
|
|
|
virtual void get_extensions(List<String> *r_extensions) const;
|
2020-04-01 23:20:12 +00:00
|
|
|
virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = nullptr);
|
2017-12-09 17:11:26 +00:00
|
|
|
virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps);
|
2017-02-04 12:48:04 +00:00
|
|
|
|
|
|
|
EditorSceneImporter() {}
|
|
|
|
};
|
|
|
|
|
2021-06-04 16:03:15 +00:00
|
|
|
class EditorScenePostImport : public RefCounted {
|
|
|
|
GDCLASS(EditorScenePostImport, RefCounted);
|
2017-02-04 12:48:04 +00:00
|
|
|
|
2018-01-19 23:48:44 +00:00
|
|
|
String source_file;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
protected:
|
2017-02-04 12:48:04 +00:00
|
|
|
static void _bind_methods();
|
|
|
|
|
2021-08-22 01:52:44 +00:00
|
|
|
GDVIRTUAL1R(Object *, _post_import, Node *)
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2018-01-19 23:48:44 +00:00
|
|
|
String get_source_file() const;
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual Node *post_import(Node *p_scene);
|
2021-03-19 12:57:52 +00:00
|
|
|
virtual void init(const String &p_source_file);
|
2017-02-04 12:48:04 +00:00
|
|
|
EditorScenePostImport();
|
|
|
|
};
|
|
|
|
|
|
|
|
class ResourceImporterScene : public ResourceImporter {
|
2019-03-19 18:35:57 +00:00
|
|
|
GDCLASS(ResourceImporterScene, ResourceImporter);
|
2017-02-04 12:48:04 +00:00
|
|
|
|
2020-03-17 06:33:00 +00:00
|
|
|
Set<Ref<EditorSceneImporter>> importers;
|
2017-02-04 12:48:04 +00:00
|
|
|
|
|
|
|
static ResourceImporterScene *singleton;
|
|
|
|
|
2021-03-19 12:57:52 +00:00
|
|
|
enum LightBakeMode {
|
|
|
|
LIGHT_BAKE_DISABLED,
|
|
|
|
LIGHT_BAKE_DYNAMIC,
|
|
|
|
LIGHT_BAKE_STATIC,
|
|
|
|
LIGHT_BAKE_STATIC_LIGHTMAPS
|
|
|
|
};
|
2017-09-08 11:06:09 +00:00
|
|
|
|
2021-03-19 12:57:52 +00:00
|
|
|
enum MeshPhysicsMode {
|
|
|
|
MESH_PHYSICS_DISABLED,
|
|
|
|
MESH_PHYSICS_MESH_AND_STATIC_COLLIDER,
|
|
|
|
MESH_PHYSICS_RIGID_BODY_AND_MESH,
|
|
|
|
MESH_PHYSICS_STATIC_COLLIDER_ONLY,
|
|
|
|
MESH_PHYSICS_AREA_ONLY,
|
|
|
|
};
|
2017-09-08 11:06:09 +00:00
|
|
|
|
2021-03-19 12:57:52 +00:00
|
|
|
enum NavMeshMode {
|
|
|
|
NAVMESH_DISABLED,
|
|
|
|
NAVMESH_MESH_AND_NAVMESH,
|
|
|
|
NAVMESH_NAVMESH_ONLY,
|
2017-07-23 21:48:05 +00:00
|
|
|
};
|
|
|
|
|
2021-03-19 12:57:52 +00:00
|
|
|
enum MeshOverride {
|
|
|
|
MESH_OVERRIDE_DEFAULT,
|
|
|
|
MESH_OVERRIDE_ENABLE,
|
|
|
|
MESH_OVERRIDE_DISABLE,
|
2017-11-25 04:29:15 +00:00
|
|
|
};
|
|
|
|
|
2017-07-23 21:48:05 +00:00
|
|
|
void _replace_owner(Node *p_node, Node *p_scene, Node *p_new_owner);
|
2021-04-25 21:36:39 +00:00
|
|
|
void _generate_meshes(Node *p_node, const Dictionary &p_mesh_data, bool p_generate_lods, bool p_create_shadow_meshes, LightBakeMode p_light_bake_mode, float p_lightmap_texel_size, const Vector<uint8_t> &p_src_lightmap_cache, Vector<Vector<uint8_t>> &r_lightmap_caches);
|
2021-03-23 07:08:06 +00:00
|
|
|
void _add_shapes(Node *p_node, const List<Ref<Shape3D>> &p_shapes);
|
2017-07-23 21:48:05 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2017-02-04 12:48:04 +00:00
|
|
|
static ResourceImporterScene *get_singleton() { return singleton; }
|
|
|
|
|
2020-03-17 06:33:00 +00:00
|
|
|
const Set<Ref<EditorSceneImporter>> &get_importers() const { return importers; }
|
2017-02-04 12:48:04 +00:00
|
|
|
|
|
|
|
void add_importer(Ref<EditorSceneImporter> p_importer) { importers.insert(p_importer); }
|
2017-12-07 18:44:20 +00:00
|
|
|
void remove_importer(Ref<EditorSceneImporter> p_importer) { importers.erase(p_importer); }
|
2017-02-04 12:48:04 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual String get_importer_name() const override;
|
|
|
|
virtual String get_visible_name() const override;
|
|
|
|
virtual void get_recognized_extensions(List<String> *p_extensions) const override;
|
|
|
|
virtual String get_save_extension() const override;
|
|
|
|
virtual String get_resource_type() const override;
|
2020-12-02 01:40:47 +00:00
|
|
|
virtual int get_format_version() const override;
|
2017-02-04 12:48:04 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual int get_preset_count() const override;
|
|
|
|
virtual String get_preset_name(int p_idx) const override;
|
2017-02-04 12:48:04 +00:00
|
|
|
|
2021-03-19 12:57:52 +00:00
|
|
|
enum InternalImportCategory {
|
|
|
|
INTERNAL_IMPORT_CATEGORY_NODE,
|
|
|
|
INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE,
|
|
|
|
INTERNAL_IMPORT_CATEGORY_MESH,
|
|
|
|
INTERNAL_IMPORT_CATEGORY_MATERIAL,
|
|
|
|
INTERNAL_IMPORT_CATEGORY_ANIMATION,
|
|
|
|
INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE,
|
|
|
|
INTERNAL_IMPORT_CATEGORY_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
void get_internal_import_options(InternalImportCategory p_category, List<ImportOption> *r_options) const;
|
|
|
|
bool get_internal_option_visibility(InternalImportCategory p_category, const String &p_option, const Map<StringName, Variant> &p_options) const;
|
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const override;
|
|
|
|
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override;
|
2021-07-23 10:10:32 +00:00
|
|
|
// Import scenes *after* everything else (such as textures).
|
|
|
|
virtual int get_import_order() const override { return ResourceImporter::IMPORT_ORDER_SCENE; }
|
2017-02-04 12:48:04 +00:00
|
|
|
|
2021-03-19 12:57:52 +00:00
|
|
|
Node *_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<EditorSceneImporterMesh>, List<Ref<Shape3D>>> &collision_map);
|
|
|
|
Node *_post_fix_node(Node *p_node, Node *p_root, Map<Ref<EditorSceneImporterMesh>, List<Ref<Shape3D>>> &collision_map, Set<Ref<EditorSceneImporterMesh>> &r_scanned_meshes, const Dictionary &p_node_data, const Dictionary &p_material_data, const Dictionary &p_animation_data, float p_animation_fps);
|
2017-12-09 17:11:26 +00:00
|
|
|
|
2021-03-19 12:57:52 +00:00
|
|
|
Ref<Animation> _save_animation_to_file(Ref<Animation> anim, bool p_save_to_file, String p_save_to_path, bool p_keep_custom_tracks);
|
|
|
|
void _create_clips(AnimationPlayer *anim, const Array &p_clips, bool p_bake_all);
|
|
|
|
void _optimize_animations(AnimationPlayer *anim, float p_max_lin_error, float p_max_ang_error, float p_max_angle);
|
2017-02-04 12:48:04 +00:00
|
|
|
|
2021-03-19 12:57:52 +00:00
|
|
|
Node *pre_import(const String &p_source_file);
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
|
2017-02-04 12:48:04 +00:00
|
|
|
|
2017-12-09 17:11:26 +00:00
|
|
|
Node *import_scene_from_other_importer(EditorSceneImporter *p_exception, const String &p_path, uint32_t p_flags, int p_bake_fps);
|
|
|
|
Ref<Animation> import_animation_from_other_importer(EditorSceneImporter *p_exception, const String &p_path, uint32_t p_flags, int p_bake_fps);
|
2017-12-07 18:44:20 +00:00
|
|
|
|
2021-03-19 12:57:52 +00:00
|
|
|
virtual bool has_advanced_options() const override;
|
|
|
|
virtual void show_advanced_options(const String &p_path) override;
|
|
|
|
|
2021-03-24 23:44:13 +00:00
|
|
|
virtual bool can_import_threaded() const override { return false; }
|
|
|
|
|
2017-02-04 12:48:04 +00:00
|
|
|
ResourceImporterScene();
|
|
|
|
};
|
|
|
|
|
2018-01-30 14:03:46 +00:00
|
|
|
class EditorSceneImporterESCN : public EditorSceneImporter {
|
|
|
|
GDCLASS(EditorSceneImporterESCN, EditorSceneImporter);
|
|
|
|
|
|
|
|
public:
|
2020-07-10 10:34:39 +00:00
|
|
|
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, int p_bake_fps, 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) override;
|
2018-01-30 14:03:46 +00:00
|
|
|
};
|
|
|
|
|
2017-02-04 12:48:04 +00:00
|
|
|
#endif // RESOURCEIMPORTERSCENE_H
|