2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* resource_importer_scene.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
2021-01-01 20:13:46 +01:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-03-05 15:47:28 +01: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-05 00:50:27 +01:00
|
|
|
|
2017-02-04 13:48:04 +01:00
|
|
|
#ifndef RESOURCEIMPORTERSCENE_H
|
|
|
|
#define RESOURCEIMPORTERSCENE_H
|
|
|
|
|
2019-02-12 13:30:56 +01:00
|
|
|
#include "core/io/resource_importer.h"
|
2020-12-12 13:06:59 +01:00
|
|
|
#include "scene/3d/node_3d.h"
|
2017-02-04 13:48:04 +01:00
|
|
|
#include "scene/resources/animation.h"
|
2017-06-07 23:18:55 +02:00
|
|
|
#include "scene/resources/mesh.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/resources/shape_3d.h"
|
2020-12-12 13:06:59 +01:00
|
|
|
#include "scene/resources/skin.h"
|
2017-02-04 13:48:04 +01:00
|
|
|
|
2017-02-05 00:31:15 +01:00
|
|
|
class Material;
|
2021-03-19 13:57:52 +01:00
|
|
|
class AnimationPlayer;
|
2017-02-05 00:31:15 +01:00
|
|
|
|
2021-03-19 13:57:52 +01:00
|
|
|
class EditorSceneImporterMesh;
|
2021-06-04 18:03:15 +02:00
|
|
|
class EditorSceneImporter : public RefCounted {
|
|
|
|
GDCLASS(EditorSceneImporter, RefCounted);
|
2017-12-07 19:44:20 +01:00
|
|
|
|
2017-12-09 18:11:26 +01:00
|
|
|
protected:
|
2017-12-07 19:44:20 +01:00
|
|
|
static void _bind_methods();
|
2017-02-04 13:48:04 +01:00
|
|
|
|
2017-12-09 18:11:26 +01:00
|
|
|
Node *import_scene_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps);
|
2017-12-07 19:44:20 +01:00
|
|
|
Ref<Animation> import_animation_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps);
|
2017-12-09 18:11:26 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2017-02-04 13:48:04 +01:00
|
|
|
enum ImportFlags {
|
2017-03-05 16:44:50 +01:00
|
|
|
IMPORT_SCENE = 1,
|
|
|
|
IMPORT_ANIMATION = 2,
|
2021-03-19 13:57:52 +01:00
|
|
|
IMPORT_FAIL_ON_MISSING_DEPENDENCIES = 4,
|
|
|
|
IMPORT_GENERATE_TANGENT_ARRAYS = 8,
|
|
|
|
IMPORT_USE_NAMED_SKIN_BINDS = 16,
|
2017-02-04 13:48:04 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-12-07 19:44:20 +01:00
|
|
|
virtual uint32_t get_import_flags() const;
|
|
|
|
virtual void get_extensions(List<String> *r_extensions) const;
|
2020-04-02 01:20:12 +02: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 18:11:26 +01:00
|
|
|
virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps);
|
2017-02-04 13:48:04 +01:00
|
|
|
|
|
|
|
EditorSceneImporter() {}
|
|
|
|
};
|
|
|
|
|
2021-06-04 18:03:15 +02:00
|
|
|
class EditorScenePostImport : public RefCounted {
|
|
|
|
GDCLASS(EditorScenePostImport, RefCounted);
|
2017-02-04 13:48:04 +01:00
|
|
|
|
2018-01-20 00:48:44 +01:00
|
|
|
String source_file;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
protected:
|
2017-02-04 13:48:04 +01:00
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2018-01-20 00:48:44 +01:00
|
|
|
String get_source_file() const;
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual Node *post_import(Node *p_scene);
|
2021-03-19 13:57:52 +01:00
|
|
|
virtual void init(const String &p_source_file);
|
2017-02-04 13:48:04 +01:00
|
|
|
EditorScenePostImport();
|
|
|
|
};
|
|
|
|
|
|
|
|
class ResourceImporterScene : public ResourceImporter {
|
2019-03-19 19:35:57 +01:00
|
|
|
GDCLASS(ResourceImporterScene, ResourceImporter);
|
2017-02-04 13:48:04 +01:00
|
|
|
|
2020-03-17 07:33:00 +01:00
|
|
|
Set<Ref<EditorSceneImporter>> importers;
|
2017-02-04 13:48:04 +01:00
|
|
|
|
|
|
|
static ResourceImporterScene *singleton;
|
|
|
|
|
2021-03-19 13:57:52 +01:00
|
|
|
enum LightBakeMode {
|
|
|
|
LIGHT_BAKE_DISABLED,
|
|
|
|
LIGHT_BAKE_DYNAMIC,
|
|
|
|
LIGHT_BAKE_STATIC,
|
|
|
|
LIGHT_BAKE_STATIC_LIGHTMAPS
|
|
|
|
};
|
2017-09-08 13:06:09 +02:00
|
|
|
|
2021-03-19 13:57:52 +01: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 13:06:09 +02:00
|
|
|
|
2021-03-19 13:57:52 +01:00
|
|
|
enum NavMeshMode {
|
|
|
|
NAVMESH_DISABLED,
|
|
|
|
NAVMESH_MESH_AND_NAVMESH,
|
|
|
|
NAVMESH_NAVMESH_ONLY,
|
2017-07-23 23:48:05 +02:00
|
|
|
};
|
|
|
|
|
2021-03-19 13:57:52 +01:00
|
|
|
enum MeshOverride {
|
|
|
|
MESH_OVERRIDE_DEFAULT,
|
|
|
|
MESH_OVERRIDE_ENABLE,
|
|
|
|
MESH_OVERRIDE_DISABLE,
|
2017-11-25 05:29:15 +01:00
|
|
|
};
|
|
|
|
|
2017-07-23 23:48:05 +02:00
|
|
|
void _replace_owner(Node *p_node, Node *p_scene, Node *p_new_owner);
|
2021-04-25 23:36:39 +02: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 08:08:06 +01:00
|
|
|
void _add_shapes(Node *p_node, const List<Ref<Shape3D>> &p_shapes);
|
2017-07-23 23:48:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2017-02-04 13:48:04 +01:00
|
|
|
static ResourceImporterScene *get_singleton() { return singleton; }
|
|
|
|
|
2020-03-17 07:33:00 +01:00
|
|
|
const Set<Ref<EditorSceneImporter>> &get_importers() const { return importers; }
|
2017-02-04 13:48:04 +01:00
|
|
|
|
|
|
|
void add_importer(Ref<EditorSceneImporter> p_importer) { importers.insert(p_importer); }
|
2017-12-07 19:44:20 +01:00
|
|
|
void remove_importer(Ref<EditorSceneImporter> p_importer) { importers.erase(p_importer); }
|
2017-02-04 13:48:04 +01:00
|
|
|
|
2020-07-10 12:34:39 +02: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 02:40:47 +01:00
|
|
|
virtual int get_format_version() const override;
|
2017-02-04 13:48:04 +01:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual int get_preset_count() const override;
|
|
|
|
virtual String get_preset_name(int p_idx) const override;
|
2017-02-04 13:48:04 +01:00
|
|
|
|
2021-03-19 13:57:52 +01: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 12:34:39 +02: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 12:10:32 +02:00
|
|
|
// Import scenes *after* everything else (such as textures).
|
|
|
|
virtual int get_import_order() const override { return ResourceImporter::IMPORT_ORDER_SCENE; }
|
2017-02-04 13:48:04 +01:00
|
|
|
|
2021-03-19 13:57:52 +01: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 18:11:26 +01:00
|
|
|
|
2021-03-19 13:57:52 +01: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 13:48:04 +01:00
|
|
|
|
2021-03-19 13:57:52 +01:00
|
|
|
Node *pre_import(const String &p_source_file);
|
2020-07-10 12:34:39 +02: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 13:48:04 +01:00
|
|
|
|
2017-12-09 18:11:26 +01: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 19:44:20 +01:00
|
|
|
|
2021-03-19 13:57:52 +01:00
|
|
|
virtual bool has_advanced_options() const override;
|
|
|
|
virtual void show_advanced_options(const String &p_path) override;
|
|
|
|
|
2021-03-25 00:44:13 +01:00
|
|
|
virtual bool can_import_threaded() const override { return false; }
|
|
|
|
|
2017-02-04 13:48:04 +01:00
|
|
|
ResourceImporterScene();
|
|
|
|
};
|
|
|
|
|
2018-01-30 15:03:46 +01:00
|
|
|
class EditorSceneImporterESCN : public EditorSceneImporter {
|
|
|
|
GDCLASS(EditorSceneImporterESCN, EditorSceneImporter);
|
|
|
|
|
|
|
|
public:
|
2020-07-10 12:34:39 +02: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 15:03:46 +01:00
|
|
|
};
|
|
|
|
|
2017-02-04 13:48:04 +01:00
|
|
|
#endif // RESOURCEIMPORTERSCENE_H
|