Path: blob/master/editor/import/3d/resource_importer_scene.h
21798 views
/**************************************************************************/1/* resource_importer_scene.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/error/error_macros.h"33#include "core/io/resource_importer.h"34#include "core/variant/dictionary.h"35#include "scene/3d/importer_mesh_instance_3d.h"36#include "scene/resources/3d/box_shape_3d.h"37#include "scene/resources/3d/capsule_shape_3d.h"38#include "scene/resources/3d/cylinder_shape_3d.h"39#include "scene/resources/3d/importer_mesh.h"40#include "scene/resources/3d/sphere_shape_3d.h"41#include "scene/resources/animation.h"42#include "scene/resources/mesh.h"4344class AnimationPlayer;45class ImporterMesh;46class Material;4748class EditorSceneFormatImporter : public RefCounted {49GDCLASS(EditorSceneFormatImporter, RefCounted);5051List<ResourceImporter::ImportOption> *current_option_list = nullptr;5253protected:54static void _bind_methods();5556Node *import_scene_wrapper(const String &p_path, uint32_t p_flags, const Dictionary &p_options);57Ref<Animation> import_animation_wrapper(const String &p_path, uint32_t p_flags, const Dictionary &p_options);5859GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_extensions)60GDVIRTUAL3R_REQUIRED(Object *, _import_scene, String, uint32_t, Dictionary)61GDVIRTUAL1(_get_import_options, String)62GDVIRTUAL3RC(Variant, _get_option_visibility, String, bool, String)6364public:65enum ImportFlags {66IMPORT_SCENE = 1,67IMPORT_ANIMATION = 2,68IMPORT_FAIL_ON_MISSING_DEPENDENCIES = 4,69IMPORT_GENERATE_TANGENT_ARRAYS = 8,70IMPORT_USE_NAMED_SKIN_BINDS = 16,71IMPORT_DISCARD_MESHES_AND_MATERIALS = 32, //used for optimizing animation import72IMPORT_FORCE_DISABLE_MESH_COMPRESSION = 64,73};7475void add_import_option(const String &p_name, const Variant &p_default_value);76void 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);77virtual void get_extensions(List<String> *r_extensions) const;78virtual Node *import_scene(const String &p_path, uint32_t p_flags, const HashMap<StringName, Variant> &p_options, List<String> *r_missing_deps, Error *r_err = nullptr);79virtual void get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options);80virtual Variant get_option_visibility(const String &p_path, const String &p_scene_import_type, const String &p_option, const HashMap<StringName, Variant> &p_options);81virtual void handle_compatibility_options(HashMap<StringName, Variant> &p_import_params) const {}82};8384class EditorScenePostImport : public RefCounted {85GDCLASS(EditorScenePostImport, RefCounted);8687String source_file;8889protected:90static void _bind_methods();9192GDVIRTUAL1R(Object *, _post_import, Node *)9394public:95String get_source_file() const;96virtual Node *post_import(Node *p_scene);97virtual void init(const String &p_source_file);98};99100class EditorScenePostImportPlugin : public RefCounted {101GDCLASS(EditorScenePostImportPlugin, RefCounted);102103public:104enum InternalImportCategory {105INTERNAL_IMPORT_CATEGORY_NODE,106INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE,107INTERNAL_IMPORT_CATEGORY_MESH,108INTERNAL_IMPORT_CATEGORY_MATERIAL,109INTERNAL_IMPORT_CATEGORY_ANIMATION,110INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE,111INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE,112INTERNAL_IMPORT_CATEGORY_MAX113};114115private:116mutable const HashMap<StringName, Variant> *current_options = nullptr;117mutable const Dictionary *current_options_dict = nullptr;118List<ResourceImporter::ImportOption> *current_option_list = nullptr;119120protected:121GDVIRTUAL1(_get_internal_import_options, int)122GDVIRTUAL3RC(Variant, _get_internal_option_visibility, int, bool, String)123GDVIRTUAL2RC(Variant, _get_internal_option_update_view_required, int, String)124GDVIRTUAL4(_internal_process, int, Node *, Node *, Ref<Resource>)125GDVIRTUAL1(_get_import_options, String)126GDVIRTUAL3RC(Variant, _get_option_visibility, String, bool, String)127GDVIRTUAL1(_pre_process, Node *)128GDVIRTUAL1(_post_process, Node *)129130static void _bind_methods();131132public:133Variant get_option_value(const StringName &p_name) const;134void add_import_option(const String &p_name, const Variant &p_default_value);135void 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);136137virtual void get_internal_import_options(InternalImportCategory p_category, List<ResourceImporter::ImportOption> *r_options);138virtual Variant get_internal_option_visibility(InternalImportCategory p_category, const String &p_scene_import_type, const String &p_option, const HashMap<StringName, Variant> &p_options) const;139virtual Variant get_internal_option_update_view_required(InternalImportCategory p_category, const String &p_option, const HashMap<StringName, Variant> &p_options) const;140141virtual void internal_process(InternalImportCategory p_category, Node *p_base_scene, Node *p_node, Ref<Resource> p_resource, const Dictionary &p_options);142143virtual void get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options);144virtual Variant get_option_visibility(const String &p_path, const String &p_scene_import_type, const String &p_option, const HashMap<StringName, Variant> &p_options) const;145146virtual void pre_process(Node *p_scene, const HashMap<StringName, Variant> &p_options);147virtual void post_process(Node *p_scene, const HashMap<StringName, Variant> &p_options);148};149150VARIANT_ENUM_CAST(EditorScenePostImportPlugin::InternalImportCategory)151152class ResourceImporterScene : public ResourceImporter {153GDCLASS(ResourceImporterScene, ResourceImporter);154155static Vector<Ref<EditorSceneFormatImporter>> scene_importers;156static Vector<Ref<EditorScenePostImportPlugin>> post_importer_plugins;157158enum LightBakeMode {159LIGHT_BAKE_DISABLED,160LIGHT_BAKE_STATIC,161LIGHT_BAKE_STATIC_LIGHTMAPS,162LIGHT_BAKE_DYNAMIC,163};164165enum MeshPhysicsMode {166MESH_PHYSICS_DISABLED,167MESH_PHYSICS_MESH_AND_STATIC_COLLIDER,168MESH_PHYSICS_RIGID_BODY_AND_MESH,169MESH_PHYSICS_STATIC_COLLIDER_ONLY,170MESH_PHYSICS_AREA_ONLY,171};172173enum NavMeshMode {174NAVMESH_DISABLED,175NAVMESH_MESH_AND_NAVMESH,176NAVMESH_NAVMESH_ONLY,177};178179enum OccluderMode {180OCCLUDER_DISABLED,181OCCLUDER_MESH_AND_OCCLUDER,182OCCLUDER_OCCLUDER_ONLY,183};184185enum MeshOverride {186MESH_OVERRIDE_DEFAULT,187MESH_OVERRIDE_ENABLE,188MESH_OVERRIDE_DISABLE,189};190191enum BodyType {192BODY_TYPE_STATIC,193BODY_TYPE_DYNAMIC,194BODY_TYPE_AREA195};196197enum ShapeType {198SHAPE_TYPE_DECOMPOSE_CONVEX,199SHAPE_TYPE_SIMPLE_CONVEX,200SHAPE_TYPE_TRIMESH,201SHAPE_TYPE_BOX,202SHAPE_TYPE_SPHERE,203SHAPE_TYPE_CYLINDER,204SHAPE_TYPE_CAPSULE,205SHAPE_TYPE_AUTOMATIC,206};207208static Error _check_resource_save_paths(ResourceUID::ID p_source_id, const String &p_hash_suffix, const Dictionary &p_data);209Array _get_skinned_pose_transforms(ImporterMeshInstance3D *p_src_mesh_node);210void _replace_owner(Node *p_node, Node *p_scene, Node *p_new_owner);211Node *_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);212void _add_shapes(Node *p_node, const Vector<Ref<Shape3D>> &p_shapes);213void _copy_meta(Object *p_src_object, Object *p_dst_object);214Node *_replace_node_with_type_and_script(Node *p_node, String p_node_type, Ref<Script> p_script);215216enum AnimationImportTracks {217ANIMATION_IMPORT_TRACKS_IF_PRESENT,218ANIMATION_IMPORT_TRACKS_IF_PRESENT_FOR_ALL,219ANIMATION_IMPORT_TRACKS_NEVER,220};221enum TrackChannel {222TRACK_CHANNEL_POSITION,223TRACK_CHANNEL_ROTATION,224TRACK_CHANNEL_SCALE,225TRACK_CHANNEL_BLEND_SHAPE,226TRACK_CHANNEL_MAX227};228229void _optimize_track_usage(AnimationPlayer *p_player, AnimationImportTracks *p_track_actions);230231String _scene_import_type = "PackedScene";232233public:234static const String material_extension[3];235236static void add_post_importer_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin, bool p_first_priority = false);237static void remove_post_importer_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin);238239const Vector<Ref<EditorSceneFormatImporter>> &get_scene_importers() const { return scene_importers; }240static void add_scene_importer(Ref<EditorSceneFormatImporter> p_importer, bool p_first_priority = false);241static void remove_scene_importer(Ref<EditorSceneFormatImporter> p_importer);242static void get_scene_importer_extensions(List<String> *p_extensions);243244static void clean_up_importer_plugins();245246String get_scene_import_type() const { return _scene_import_type; }247void set_scene_import_type(const String &p_type) { _scene_import_type = p_type; }248249virtual String get_importer_name() const override;250virtual String get_visible_name() const override;251virtual void get_recognized_extensions(List<String> *p_extensions) const override;252virtual String get_save_extension() const override;253virtual String get_resource_type() const override;254virtual int get_format_version() const override;255256virtual int get_preset_count() const override;257virtual String get_preset_name(int p_idx) const override;258259enum InternalImportCategory {260INTERNAL_IMPORT_CATEGORY_NODE = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_NODE,261INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE,262INTERNAL_IMPORT_CATEGORY_MESH = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_MESH,263INTERNAL_IMPORT_CATEGORY_MATERIAL = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_MATERIAL,264INTERNAL_IMPORT_CATEGORY_ANIMATION = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_ANIMATION,265INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE,266INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE,267INTERNAL_IMPORT_CATEGORY_MAX = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_MAX268};269270void get_internal_import_options(InternalImportCategory p_category, List<ImportOption> *r_options) const;271bool get_internal_option_visibility(InternalImportCategory p_category, const String &p_option, const HashMap<StringName, Variant> &p_options) const;272bool get_internal_option_update_view_required(InternalImportCategory p_category, const String &p_option, const HashMap<StringName, Variant> &p_options) const;273274virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;275virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;276virtual void handle_compatibility_options(HashMap<StringName, Variant> &p_import_params) const override;277// Import scenes *after* everything else (such as textures).278virtual int get_import_order() const override { return ResourceImporter::IMPORT_ORDER_SCENE; }279280void _pre_fix_global(Node *p_scene, const HashMap<StringName, Variant> &p_options) const;281Node *_pre_fix_node(Node *p_node, Node *p_root, HashMap<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &r_collision_map, Pair<PackedVector3Array, PackedInt32Array> *r_occluder_arrays, List<Pair<NodePath, Node *>> &r_node_renames, const HashMap<StringName, Variant> &p_options);282Node *_pre_fix_animations(Node *p_node, Node *p_root, const Dictionary &p_node_data, const Dictionary &p_animation_data, float p_animation_fps);283Node *_post_fix_node(Node *p_node, Node *p_root, HashMap<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &collision_map, Pair<PackedVector3Array, PackedInt32Array> &r_occluder_arrays, HashSet<Ref<ImporterMesh>> &r_scanned_meshes, const Dictionary &p_node_data, const Dictionary &p_material_data, const Dictionary &p_animation_data, float p_animation_fps, float p_applied_root_scale, const String &p_source_file, const HashMap<StringName, Variant> &p_options);284Node *_post_fix_animations(Node *p_node, Node *p_root, const Dictionary &p_node_data, const Dictionary &p_animation_data, float p_animation_fps, bool p_remove_immutable_tracks);285286Ref<Animation> _save_animation_to_file(Ref<Animation> anim, bool p_save_to_file, const String &p_save_to_path, bool p_keep_custom_tracks);287void _create_slices(AnimationPlayer *ap, Ref<Animation> anim, const Array &p_clips, bool p_bake_all);288void _optimize_animations(AnimationPlayer *anim, float p_max_vel_error, float p_max_ang_error, int p_prc_error);289void _compress_animations(AnimationPlayer *anim, int p_page_size_kb);290291Node *pre_import(const String &p_source_file, const HashMap<StringName, Variant> &p_options);292virtual Error import(ResourceUID::ID p_source_id, const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;293294virtual bool has_advanced_options() const override;295virtual void show_advanced_options(const String &p_path) override;296297ResourceImporterScene(const String &p_scene_import_type = "PackedScene");298299template <typename M>300static Vector<Ref<Shape3D>> get_collision_shapes(const Ref<ImporterMesh> &p_mesh, const M &p_options, float p_applied_root_scale);301302template <typename M>303static Transform3D get_collision_shapes_transform(const M &p_options);304};305306class EditorSceneFormatImporterESCN : public EditorSceneFormatImporter {307GDCLASS(EditorSceneFormatImporterESCN, EditorSceneFormatImporter);308309public:310virtual void get_extensions(List<String> *r_extensions) const override;311virtual Node *import_scene(const String &p_path, uint32_t p_flags, const HashMap<StringName, Variant> &p_options, List<String> *r_missing_deps, Error *r_err = nullptr) override;312};313314template <typename M>315Vector<Ref<Shape3D>> ResourceImporterScene::get_collision_shapes(const Ref<ImporterMesh> &p_mesh, const M &p_options, float p_applied_root_scale) {316ERR_FAIL_COND_V(p_mesh.is_null(), Vector<Ref<Shape3D>>());317318ShapeType generate_shape_type = SHAPE_TYPE_AUTOMATIC;319if (p_options.has(SNAME("physics/shape_type"))) {320generate_shape_type = (ShapeType)p_options[SNAME("physics/shape_type")].operator int();321}322323if (generate_shape_type == SHAPE_TYPE_AUTOMATIC) {324BodyType body_type = BODY_TYPE_STATIC;325if (p_options.has(SNAME("physics/body_type"))) {326body_type = (BodyType)p_options[SNAME("physics/body_type")].operator int();327}328329generate_shape_type = body_type == BODY_TYPE_DYNAMIC ? SHAPE_TYPE_DECOMPOSE_CONVEX : SHAPE_TYPE_TRIMESH;330}331332if (generate_shape_type == SHAPE_TYPE_DECOMPOSE_CONVEX) {333Ref<MeshConvexDecompositionSettings> decomposition_settings = Ref<MeshConvexDecompositionSettings>();334decomposition_settings.instantiate();335bool advanced = false;336if (p_options.has(SNAME("decomposition/advanced"))) {337advanced = p_options[SNAME("decomposition/advanced")];338}339340if (advanced) {341if (p_options.has(SNAME("decomposition/max_concavity"))) {342decomposition_settings->set_max_concavity(p_options[SNAME("decomposition/max_concavity")]);343}344345if (p_options.has(SNAME("decomposition/symmetry_planes_clipping_bias"))) {346decomposition_settings->set_symmetry_planes_clipping_bias(p_options[SNAME("decomposition/symmetry_planes_clipping_bias")]);347}348349if (p_options.has(SNAME("decomposition/revolution_axes_clipping_bias"))) {350decomposition_settings->set_revolution_axes_clipping_bias(p_options[SNAME("decomposition/revolution_axes_clipping_bias")]);351}352353if (p_options.has(SNAME("decomposition/min_volume_per_convex_hull"))) {354decomposition_settings->set_min_volume_per_convex_hull(p_options[SNAME("decomposition/min_volume_per_convex_hull")]);355}356357if (p_options.has(SNAME("decomposition/resolution"))) {358decomposition_settings->set_resolution(p_options[SNAME("decomposition/resolution")]);359}360361if (p_options.has(SNAME("decomposition/max_num_vertices_per_convex_hull"))) {362decomposition_settings->set_max_num_vertices_per_convex_hull(p_options[SNAME("decomposition/max_num_vertices_per_convex_hull")]);363}364365if (p_options.has(SNAME("decomposition/plane_downsampling"))) {366decomposition_settings->set_plane_downsampling(p_options[SNAME("decomposition/plane_downsampling")]);367}368369if (p_options.has(SNAME("decomposition/convexhull_downsampling"))) {370decomposition_settings->set_convex_hull_downsampling(p_options[SNAME("decomposition/convexhull_downsampling")]);371}372373if (p_options.has(SNAME("decomposition/normalize_mesh"))) {374decomposition_settings->set_normalize_mesh(p_options[SNAME("decomposition/normalize_mesh")]);375}376377if (p_options.has(SNAME("decomposition/mode"))) {378decomposition_settings->set_mode((MeshConvexDecompositionSettings::Mode)p_options[SNAME("decomposition/mode")].operator int());379}380381if (p_options.has(SNAME("decomposition/convexhull_approximation"))) {382decomposition_settings->set_convex_hull_approximation(p_options[SNAME("decomposition/convexhull_approximation")]);383}384385if (p_options.has(SNAME("decomposition/max_convex_hulls"))) {386decomposition_settings->set_max_convex_hulls(MAX(1, (int)p_options[SNAME("decomposition/max_convex_hulls")]));387}388389if (p_options.has(SNAME("decomposition/project_hull_vertices"))) {390decomposition_settings->set_project_hull_vertices(p_options[SNAME("decomposition/project_hull_vertices")]);391}392} else {393int precision_level = 5;394if (p_options.has(SNAME("decomposition/precision"))) {395precision_level = p_options[SNAME("decomposition/precision")];396}397398const real_t precision = real_t(precision_level - 1) / 9.0;399400decomposition_settings->set_max_concavity(Math::lerp(real_t(1.0), real_t(0.001), precision));401decomposition_settings->set_min_volume_per_convex_hull(Math::lerp(real_t(0.01), real_t(0.0001), precision));402decomposition_settings->set_resolution(Math::lerp(10'000, 100'000, precision));403decomposition_settings->set_max_num_vertices_per_convex_hull(Math::lerp(32, 64, precision));404decomposition_settings->set_plane_downsampling(Math::lerp(3, 16, precision));405decomposition_settings->set_convex_hull_downsampling(Math::lerp(3, 16, precision));406decomposition_settings->set_max_convex_hulls(Math::lerp(1, 32, precision));407}408409return p_mesh->convex_decompose(decomposition_settings);410} else if (generate_shape_type == SHAPE_TYPE_SIMPLE_CONVEX) {411Vector<Ref<Shape3D>> shapes;412shapes.push_back(p_mesh->create_convex_shape(true, /*Passing false, otherwise VHACD will be used to simplify (Decompose) the Mesh.*/ false));413return shapes;414} else if (generate_shape_type == SHAPE_TYPE_TRIMESH) {415Vector<Ref<Shape3D>> shapes;416shapes.push_back(p_mesh->create_trimesh_shape());417return shapes;418} else if (generate_shape_type == SHAPE_TYPE_BOX) {419Ref<BoxShape3D> box;420box.instantiate();421if (p_options.has(SNAME("primitive/size"))) {422box->set_size(p_options[SNAME("primitive/size")].operator Vector3() * p_applied_root_scale);423} else {424box->set_size(Vector3(2, 2, 2) * p_applied_root_scale);425}426427Vector<Ref<Shape3D>> shapes;428shapes.push_back(box);429return shapes;430431} else if (generate_shape_type == SHAPE_TYPE_SPHERE) {432Ref<SphereShape3D> sphere;433sphere.instantiate();434if (p_options.has(SNAME("primitive/radius"))) {435sphere->set_radius(p_options[SNAME("primitive/radius")].operator float() * p_applied_root_scale);436} else {437sphere->set_radius(1.0f * p_applied_root_scale);438}439440Vector<Ref<Shape3D>> shapes;441shapes.push_back(sphere);442return shapes;443} else if (generate_shape_type == SHAPE_TYPE_CYLINDER) {444Ref<CylinderShape3D> cylinder;445cylinder.instantiate();446if (p_options.has(SNAME("primitive/height"))) {447cylinder->set_height(p_options[SNAME("primitive/height")].operator float() * p_applied_root_scale);448} else {449cylinder->set_height(1.0f * p_applied_root_scale);450}451if (p_options.has(SNAME("primitive/radius"))) {452cylinder->set_radius(p_options[SNAME("primitive/radius")].operator float() * p_applied_root_scale);453} else {454cylinder->set_radius(1.0f * p_applied_root_scale);455}456457Vector<Ref<Shape3D>> shapes;458shapes.push_back(cylinder);459return shapes;460} else if (generate_shape_type == SHAPE_TYPE_CAPSULE) {461Ref<CapsuleShape3D> capsule;462capsule.instantiate();463if (p_options.has(SNAME("primitive/height"))) {464capsule->set_height(p_options[SNAME("primitive/height")].operator float() * p_applied_root_scale);465} else {466capsule->set_height(1.0f * p_applied_root_scale);467}468if (p_options.has(SNAME("primitive/radius"))) {469capsule->set_radius(p_options[SNAME("primitive/radius")].operator float() * p_applied_root_scale);470} else {471capsule->set_radius(1.0f * p_applied_root_scale);472}473474Vector<Ref<Shape3D>> shapes;475shapes.push_back(capsule);476return shapes;477}478return Vector<Ref<Shape3D>>();479}480481template <typename M>482Transform3D ResourceImporterScene::get_collision_shapes_transform(const M &p_options) {483Transform3D transform;484485ShapeType generate_shape_type = SHAPE_TYPE_AUTOMATIC;486if (p_options.has(SNAME("physics/shape_type"))) {487generate_shape_type = (ShapeType)p_options[SNAME("physics/shape_type")].operator int();488}489490if (generate_shape_type == SHAPE_TYPE_AUTOMATIC) {491BodyType body_type = BODY_TYPE_STATIC;492if (p_options.has(SNAME("physics/body_type"))) {493body_type = (BodyType)p_options[SNAME("physics/body_type")].operator int();494}495496generate_shape_type = body_type == BODY_TYPE_DYNAMIC ? SHAPE_TYPE_DECOMPOSE_CONVEX : SHAPE_TYPE_TRIMESH;497}498499if (generate_shape_type == SHAPE_TYPE_BOX ||500generate_shape_type == SHAPE_TYPE_SPHERE ||501generate_shape_type == SHAPE_TYPE_CYLINDER ||502generate_shape_type == SHAPE_TYPE_CAPSULE) {503if (p_options.has(SNAME("primitive/position"))) {504transform.origin = p_options[SNAME("primitive/position")];505}506507if (p_options.has(SNAME("primitive/rotation"))) {508transform.basis = Basis::from_euler(p_options[SNAME("primitive/rotation")].operator Vector3() * (Math::PI / 180.0));509}510}511return transform;512}513514515