/**************************************************************************/ /* resource_importer_scene.h */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* 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. */ /**************************************************************************/ #pragma once #include "core/error/error_macros.h" #include "core/io/resource_importer.h" #include "core/variant/dictionary.h" #include "scene/3d/importer_mesh_instance_3d.h" #include "scene/resources/3d/box_shape_3d.h" #include "scene/resources/3d/capsule_shape_3d.h" #include "scene/resources/3d/cylinder_shape_3d.h" #include "scene/resources/3d/importer_mesh.h" #include "scene/resources/3d/sphere_shape_3d.h" #include "scene/resources/animation.h" #include "scene/resources/mesh.h" class AnimationPlayer; class ImporterMesh; class Material; class EditorSceneFormatImporter : public RefCounted { GDCLASS(EditorSceneFormatImporter, RefCounted); List *current_option_list = nullptr; protected: static void _bind_methods(); Node *import_scene_wrapper(const String &p_path, uint32_t p_flags, const Dictionary &p_options); Ref import_animation_wrapper(const String &p_path, uint32_t p_flags, const Dictionary &p_options); GDVIRTUAL0RC(Vector, _get_extensions) GDVIRTUAL3R(Object *, _import_scene, String, uint32_t, Dictionary) GDVIRTUAL1(_get_import_options, String) GDVIRTUAL3RC(Variant, _get_option_visibility, String, bool, String) public: enum ImportFlags { IMPORT_SCENE = 1, IMPORT_ANIMATION = 2, IMPORT_FAIL_ON_MISSING_DEPENDENCIES = 4, IMPORT_GENERATE_TANGENT_ARRAYS = 8, IMPORT_USE_NAMED_SKIN_BINDS = 16, IMPORT_DISCARD_MESHES_AND_MATERIALS = 32, //used for optimizing animation import IMPORT_FORCE_DISABLE_MESH_COMPRESSION = 64, }; void add_import_option(const String &p_name, const Variant &p_default_value); void add_import_option_advanced(Variant::Type p_type, const String &p_name, const Variant &p_default_value, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = String(), int p_usage_flags = PROPERTY_USAGE_DEFAULT); virtual void get_extensions(List *r_extensions) const; virtual Node *import_scene(const String &p_path, uint32_t p_flags, const HashMap &p_options, List *r_missing_deps, Error *r_err = nullptr); virtual void get_import_options(const String &p_path, List *r_options); virtual Variant get_option_visibility(const String &p_path, const String &p_scene_import_type, const String &p_option, const HashMap &p_options); virtual void handle_compatibility_options(HashMap &p_import_params) const {} }; class EditorScenePostImport : public RefCounted { GDCLASS(EditorScenePostImport, RefCounted); String source_file; protected: static void _bind_methods(); GDVIRTUAL1R(Object *, _post_import, Node *) public: String get_source_file() const; virtual Node *post_import(Node *p_scene); virtual void init(const String &p_source_file); }; class EditorScenePostImportPlugin : public RefCounted { GDCLASS(EditorScenePostImportPlugin, RefCounted); public: 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_SKELETON_3D_NODE, INTERNAL_IMPORT_CATEGORY_MAX }; private: mutable const HashMap *current_options = nullptr; mutable const Dictionary *current_options_dict = nullptr; List *current_option_list = nullptr; InternalImportCategory current_category = INTERNAL_IMPORT_CATEGORY_MAX; protected: GDVIRTUAL1(_get_internal_import_options, int) GDVIRTUAL3RC(Variant, _get_internal_option_visibility, int, bool, String) GDVIRTUAL2RC(Variant, _get_internal_option_update_view_required, int, String) GDVIRTUAL4(_internal_process, int, Node *, Node *, Ref) GDVIRTUAL1(_get_import_options, String) GDVIRTUAL3RC(Variant, _get_option_visibility, String, bool, String) GDVIRTUAL1(_pre_process, Node *) GDVIRTUAL1(_post_process, Node *) static void _bind_methods(); public: Variant get_option_value(const StringName &p_name) const; void add_import_option(const String &p_name, const Variant &p_default_value); void add_import_option_advanced(Variant::Type p_type, const String &p_name, const Variant &p_default_value, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = String(), int p_usage_flags = PROPERTY_USAGE_DEFAULT); virtual void get_internal_import_options(InternalImportCategory p_category, List *r_options); virtual Variant get_internal_option_visibility(InternalImportCategory p_category, const String &p_scene_import_type, const String &p_option, const HashMap &p_options) const; virtual Variant get_internal_option_update_view_required(InternalImportCategory p_category, const String &p_option, const HashMap &p_options) const; virtual void internal_process(InternalImportCategory p_category, Node *p_base_scene, Node *p_node, Ref p_resource, const Dictionary &p_options); virtual void get_import_options(const String &p_path, List *r_options); virtual Variant get_option_visibility(const String &p_path, const String &p_scene_import_type, const String &p_option, const HashMap &p_options) const; virtual void pre_process(Node *p_scene, const HashMap &p_options); virtual void post_process(Node *p_scene, const HashMap &p_options); }; VARIANT_ENUM_CAST(EditorScenePostImportPlugin::InternalImportCategory) class ResourceImporterScene : public ResourceImporter { GDCLASS(ResourceImporterScene, ResourceImporter); static Vector> scene_importers; static Vector> post_importer_plugins; static ResourceImporterScene *scene_singleton; static ResourceImporterScene *animation_singleton; enum LightBakeMode { LIGHT_BAKE_DISABLED, LIGHT_BAKE_STATIC, LIGHT_BAKE_STATIC_LIGHTMAPS, LIGHT_BAKE_DYNAMIC, }; 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, }; enum NavMeshMode { NAVMESH_DISABLED, NAVMESH_MESH_AND_NAVMESH, NAVMESH_NAVMESH_ONLY, }; enum OccluderMode { OCCLUDER_DISABLED, OCCLUDER_MESH_AND_OCCLUDER, OCCLUDER_OCCLUDER_ONLY, }; enum MeshOverride { MESH_OVERRIDE_DEFAULT, MESH_OVERRIDE_ENABLE, MESH_OVERRIDE_DISABLE, }; enum BodyType { BODY_TYPE_STATIC, BODY_TYPE_DYNAMIC, BODY_TYPE_AREA }; enum ShapeType { SHAPE_TYPE_DECOMPOSE_CONVEX, SHAPE_TYPE_SIMPLE_CONVEX, SHAPE_TYPE_TRIMESH, SHAPE_TYPE_BOX, SHAPE_TYPE_SPHERE, SHAPE_TYPE_CYLINDER, SHAPE_TYPE_CAPSULE, SHAPE_TYPE_AUTOMATIC, }; static Error _check_resource_save_paths(ResourceUID::ID p_source_id, const String &p_hash_suffix, const Dictionary &p_data); Array _get_skinned_pose_transforms(ImporterMeshInstance3D *p_src_mesh_node); void _replace_owner(Node *p_node, Node *p_scene, Node *p_new_owner); Node *_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 &p_src_lightmap_cache, Vector> &r_lightmap_caches); void _add_shapes(Node *p_node, const Vector> &p_shapes); void _copy_meta(Object *p_src_object, Object *p_dst_object); Node *_replace_node_with_type_and_script(Node *p_node, String p_node_type, Ref