Path: blob/master/editor/import/3d/resource_importer_scene.h
9906 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(Vector<String>, _get_extensions)60GDVIRTUAL3R(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;119InternalImportCategory current_category = INTERNAL_IMPORT_CATEGORY_MAX;120121protected:122GDVIRTUAL1(_get_internal_import_options, int)123GDVIRTUAL3RC(Variant, _get_internal_option_visibility, int, bool, String)124GDVIRTUAL2RC(Variant, _get_internal_option_update_view_required, int, String)125GDVIRTUAL4(_internal_process, int, Node *, Node *, Ref<Resource>)126GDVIRTUAL1(_get_import_options, String)127GDVIRTUAL3RC(Variant, _get_option_visibility, String, bool, String)128GDVIRTUAL1(_pre_process, Node *)129GDVIRTUAL1(_post_process, Node *)130131static void _bind_methods();132133public:134Variant get_option_value(const StringName &p_name) const;135void add_import_option(const String &p_name, const Variant &p_default_value);136void 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);137138virtual void get_internal_import_options(InternalImportCategory p_category, List<ResourceImporter::ImportOption> *r_options);139virtual 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;140virtual Variant get_internal_option_update_view_required(InternalImportCategory p_category, const String &p_option, const HashMap<StringName, Variant> &p_options) const;141142virtual void internal_process(InternalImportCategory p_category, Node *p_base_scene, Node *p_node, Ref<Resource> p_resource, const Dictionary &p_options);143144virtual void get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options);145virtual 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;146147virtual void pre_process(Node *p_scene, const HashMap<StringName, Variant> &p_options);148virtual void post_process(Node *p_scene, const HashMap<StringName, Variant> &p_options);149};150151VARIANT_ENUM_CAST(EditorScenePostImportPlugin::InternalImportCategory)152153class ResourceImporterScene : public ResourceImporter {154GDCLASS(ResourceImporterScene, ResourceImporter);155156static Vector<Ref<EditorSceneFormatImporter>> scene_importers;157static Vector<Ref<EditorScenePostImportPlugin>> post_importer_plugins;158159static ResourceImporterScene *scene_singleton;160static ResourceImporterScene *animation_singleton;161162enum LightBakeMode {163LIGHT_BAKE_DISABLED,164LIGHT_BAKE_STATIC,165LIGHT_BAKE_STATIC_LIGHTMAPS,166LIGHT_BAKE_DYNAMIC,167};168169enum MeshPhysicsMode {170MESH_PHYSICS_DISABLED,171MESH_PHYSICS_MESH_AND_STATIC_COLLIDER,172MESH_PHYSICS_RIGID_BODY_AND_MESH,173MESH_PHYSICS_STATIC_COLLIDER_ONLY,174MESH_PHYSICS_AREA_ONLY,175};176177enum NavMeshMode {178NAVMESH_DISABLED,179NAVMESH_MESH_AND_NAVMESH,180NAVMESH_NAVMESH_ONLY,181};182183enum OccluderMode {184OCCLUDER_DISABLED,185OCCLUDER_MESH_AND_OCCLUDER,186OCCLUDER_OCCLUDER_ONLY,187};188189enum MeshOverride {190MESH_OVERRIDE_DEFAULT,191MESH_OVERRIDE_ENABLE,192MESH_OVERRIDE_DISABLE,193};194195enum BodyType {196BODY_TYPE_STATIC,197BODY_TYPE_DYNAMIC,198BODY_TYPE_AREA199};200201enum ShapeType {202SHAPE_TYPE_DECOMPOSE_CONVEX,203SHAPE_TYPE_SIMPLE_CONVEX,204SHAPE_TYPE_TRIMESH,205SHAPE_TYPE_BOX,206SHAPE_TYPE_SPHERE,207SHAPE_TYPE_CYLINDER,208SHAPE_TYPE_CAPSULE,209SHAPE_TYPE_AUTOMATIC,210};211212static Error _check_resource_save_paths(ResourceUID::ID p_source_id, const String &p_hash_suffix, const Dictionary &p_data);213Array _get_skinned_pose_transforms(ImporterMeshInstance3D *p_src_mesh_node);214void _replace_owner(Node *p_node, Node *p_scene, Node *p_new_owner);215Node *_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);216void _add_shapes(Node *p_node, const Vector<Ref<Shape3D>> &p_shapes);217void _copy_meta(Object *p_src_object, Object *p_dst_object);218Node *_replace_node_with_type_and_script(Node *p_node, String p_node_type, Ref<Script> p_script);219220enum AnimationImportTracks {221ANIMATION_IMPORT_TRACKS_IF_PRESENT,222ANIMATION_IMPORT_TRACKS_IF_PRESENT_FOR_ALL,223ANIMATION_IMPORT_TRACKS_NEVER,224};225enum TrackChannel {226TRACK_CHANNEL_POSITION,227TRACK_CHANNEL_ROTATION,228TRACK_CHANNEL_SCALE,229TRACK_CHANNEL_BLEND_SHAPE,230TRACK_CHANNEL_MAX231};232233void _optimize_track_usage(AnimationPlayer *p_player, AnimationImportTracks *p_track_actions);234235String _scene_import_type = "PackedScene";236237public:238static const String material_extension[3];239static ResourceImporterScene *get_scene_singleton() { return scene_singleton; }240static ResourceImporterScene *get_animation_singleton() { return animation_singleton; }241242static void add_post_importer_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin, bool p_first_priority = false);243static void remove_post_importer_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin);244245const Vector<Ref<EditorSceneFormatImporter>> &get_scene_importers() const { return scene_importers; }246static void add_scene_importer(Ref<EditorSceneFormatImporter> p_importer, bool p_first_priority = false);247static void remove_scene_importer(Ref<EditorSceneFormatImporter> p_importer);248static void get_scene_importer_extensions(List<String> *p_extensions);249250static void clean_up_importer_plugins();251252String get_scene_import_type() const { return _scene_import_type; }253void set_scene_import_type(const String &p_type) { _scene_import_type = p_type; }254255virtual String get_importer_name() const override;256virtual String get_visible_name() const override;257virtual void get_recognized_extensions(List<String> *p_extensions) const override;258virtual String get_save_extension() const override;259virtual String get_resource_type() const override;260virtual int get_format_version() const override;261262virtual int get_preset_count() const override;263virtual String get_preset_name(int p_idx) const override;264265enum InternalImportCategory {266INTERNAL_IMPORT_CATEGORY_NODE = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_NODE,267INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE,268INTERNAL_IMPORT_CATEGORY_MESH = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_MESH,269INTERNAL_IMPORT_CATEGORY_MATERIAL = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_MATERIAL,270INTERNAL_IMPORT_CATEGORY_ANIMATION = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_ANIMATION,271INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE,272INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE,273INTERNAL_IMPORT_CATEGORY_MAX = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_MAX274};275276void get_internal_import_options(InternalImportCategory p_category, List<ImportOption> *r_options) const;277bool get_internal_option_visibility(InternalImportCategory p_category, const String &p_option, const HashMap<StringName, Variant> &p_options) const;278bool get_internal_option_update_view_required(InternalImportCategory p_category, const String &p_option, const HashMap<StringName, Variant> &p_options) const;279280virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;281virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;282virtual void handle_compatibility_options(HashMap<StringName, Variant> &p_import_params) const override;283// Import scenes *after* everything else (such as textures).284virtual int get_import_order() const override { return ResourceImporter::IMPORT_ORDER_SCENE; }285286void _pre_fix_global(Node *p_scene, const HashMap<StringName, Variant> &p_options) const;287Node *_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);288Node *_pre_fix_animations(Node *p_node, Node *p_root, const Dictionary &p_node_data, const Dictionary &p_animation_data, float p_animation_fps);289Node *_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);290Node *_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);291292Ref<Animation> _save_animation_to_file(Ref<Animation> anim, bool p_save_to_file, const String &p_save_to_path, bool p_keep_custom_tracks);293void _create_slices(AnimationPlayer *ap, Ref<Animation> anim, const Array &p_clips, bool p_bake_all);294void _optimize_animations(AnimationPlayer *anim, float p_max_vel_error, float p_max_ang_error, int p_prc_error);295void _compress_animations(AnimationPlayer *anim, int p_page_size_kb);296297Node *pre_import(const String &p_source_file, const HashMap<StringName, Variant> &p_options);298virtual 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;299300virtual bool has_advanced_options() const override;301virtual void show_advanced_options(const String &p_path) override;302303ResourceImporterScene(const String &p_scene_import_type = "PackedScene", bool p_singleton = false);304~ResourceImporterScene();305306template <typename M>307static Vector<Ref<Shape3D>> get_collision_shapes(const Ref<ImporterMesh> &p_mesh, const M &p_options, float p_applied_root_scale);308309template <typename M>310static Transform3D get_collision_shapes_transform(const M &p_options);311};312313class EditorSceneFormatImporterESCN : public EditorSceneFormatImporter {314GDCLASS(EditorSceneFormatImporterESCN, EditorSceneFormatImporter);315316public:317virtual void get_extensions(List<String> *r_extensions) const override;318virtual 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;319};320321template <typename M>322Vector<Ref<Shape3D>> ResourceImporterScene::get_collision_shapes(const Ref<ImporterMesh> &p_mesh, const M &p_options, float p_applied_root_scale) {323ERR_FAIL_COND_V(p_mesh.is_null(), Vector<Ref<Shape3D>>());324325ShapeType generate_shape_type = SHAPE_TYPE_AUTOMATIC;326if (p_options.has(SNAME("physics/shape_type"))) {327generate_shape_type = (ShapeType)p_options[SNAME("physics/shape_type")].operator int();328}329330if (generate_shape_type == SHAPE_TYPE_AUTOMATIC) {331BodyType body_type = BODY_TYPE_STATIC;332if (p_options.has(SNAME("physics/body_type"))) {333body_type = (BodyType)p_options[SNAME("physics/body_type")].operator int();334}335336generate_shape_type = body_type == BODY_TYPE_DYNAMIC ? SHAPE_TYPE_DECOMPOSE_CONVEX : SHAPE_TYPE_TRIMESH;337}338339if (generate_shape_type == SHAPE_TYPE_DECOMPOSE_CONVEX) {340Ref<MeshConvexDecompositionSettings> decomposition_settings = Ref<MeshConvexDecompositionSettings>();341decomposition_settings.instantiate();342bool advanced = false;343if (p_options.has(SNAME("decomposition/advanced"))) {344advanced = p_options[SNAME("decomposition/advanced")];345}346347if (advanced) {348if (p_options.has(SNAME("decomposition/max_concavity"))) {349decomposition_settings->set_max_concavity(p_options[SNAME("decomposition/max_concavity")]);350}351352if (p_options.has(SNAME("decomposition/symmetry_planes_clipping_bias"))) {353decomposition_settings->set_symmetry_planes_clipping_bias(p_options[SNAME("decomposition/symmetry_planes_clipping_bias")]);354}355356if (p_options.has(SNAME("decomposition/revolution_axes_clipping_bias"))) {357decomposition_settings->set_revolution_axes_clipping_bias(p_options[SNAME("decomposition/revolution_axes_clipping_bias")]);358}359360if (p_options.has(SNAME("decomposition/min_volume_per_convex_hull"))) {361decomposition_settings->set_min_volume_per_convex_hull(p_options[SNAME("decomposition/min_volume_per_convex_hull")]);362}363364if (p_options.has(SNAME("decomposition/resolution"))) {365decomposition_settings->set_resolution(p_options[SNAME("decomposition/resolution")]);366}367368if (p_options.has(SNAME("decomposition/max_num_vertices_per_convex_hull"))) {369decomposition_settings->set_max_num_vertices_per_convex_hull(p_options[SNAME("decomposition/max_num_vertices_per_convex_hull")]);370}371372if (p_options.has(SNAME("decomposition/plane_downsampling"))) {373decomposition_settings->set_plane_downsampling(p_options[SNAME("decomposition/plane_downsampling")]);374}375376if (p_options.has(SNAME("decomposition/convexhull_downsampling"))) {377decomposition_settings->set_convex_hull_downsampling(p_options[SNAME("decomposition/convexhull_downsampling")]);378}379380if (p_options.has(SNAME("decomposition/normalize_mesh"))) {381decomposition_settings->set_normalize_mesh(p_options[SNAME("decomposition/normalize_mesh")]);382}383384if (p_options.has(SNAME("decomposition/mode"))) {385decomposition_settings->set_mode((MeshConvexDecompositionSettings::Mode)p_options[SNAME("decomposition/mode")].operator int());386}387388if (p_options.has(SNAME("decomposition/convexhull_approximation"))) {389decomposition_settings->set_convex_hull_approximation(p_options[SNAME("decomposition/convexhull_approximation")]);390}391392if (p_options.has(SNAME("decomposition/max_convex_hulls"))) {393decomposition_settings->set_max_convex_hulls(MAX(1, (int)p_options[SNAME("decomposition/max_convex_hulls")]));394}395396if (p_options.has(SNAME("decomposition/project_hull_vertices"))) {397decomposition_settings->set_project_hull_vertices(p_options[SNAME("decomposition/project_hull_vertices")]);398}399} else {400int precision_level = 5;401if (p_options.has(SNAME("decomposition/precision"))) {402precision_level = p_options[SNAME("decomposition/precision")];403}404405const real_t precision = real_t(precision_level - 1) / 9.0;406407decomposition_settings->set_max_concavity(Math::lerp(real_t(1.0), real_t(0.001), precision));408decomposition_settings->set_min_volume_per_convex_hull(Math::lerp(real_t(0.01), real_t(0.0001), precision));409decomposition_settings->set_resolution(Math::lerp(10'000, 100'000, precision));410decomposition_settings->set_max_num_vertices_per_convex_hull(Math::lerp(32, 64, precision));411decomposition_settings->set_plane_downsampling(Math::lerp(3, 16, precision));412decomposition_settings->set_convex_hull_downsampling(Math::lerp(3, 16, precision));413decomposition_settings->set_max_convex_hulls(Math::lerp(1, 32, precision));414}415416return p_mesh->convex_decompose(decomposition_settings);417} else if (generate_shape_type == SHAPE_TYPE_SIMPLE_CONVEX) {418Vector<Ref<Shape3D>> shapes;419shapes.push_back(p_mesh->create_convex_shape(true, /*Passing false, otherwise VHACD will be used to simplify (Decompose) the Mesh.*/ false));420return shapes;421} else if (generate_shape_type == SHAPE_TYPE_TRIMESH) {422Vector<Ref<Shape3D>> shapes;423shapes.push_back(p_mesh->create_trimesh_shape());424return shapes;425} else if (generate_shape_type == SHAPE_TYPE_BOX) {426Ref<BoxShape3D> box;427box.instantiate();428if (p_options.has(SNAME("primitive/size"))) {429box->set_size(p_options[SNAME("primitive/size")].operator Vector3() * p_applied_root_scale);430} else {431box->set_size(Vector3(2, 2, 2) * p_applied_root_scale);432}433434Vector<Ref<Shape3D>> shapes;435shapes.push_back(box);436return shapes;437438} else if (generate_shape_type == SHAPE_TYPE_SPHERE) {439Ref<SphereShape3D> sphere;440sphere.instantiate();441if (p_options.has(SNAME("primitive/radius"))) {442sphere->set_radius(p_options[SNAME("primitive/radius")].operator float() * p_applied_root_scale);443} else {444sphere->set_radius(1.0f * p_applied_root_scale);445}446447Vector<Ref<Shape3D>> shapes;448shapes.push_back(sphere);449return shapes;450} else if (generate_shape_type == SHAPE_TYPE_CYLINDER) {451Ref<CylinderShape3D> cylinder;452cylinder.instantiate();453if (p_options.has(SNAME("primitive/height"))) {454cylinder->set_height(p_options[SNAME("primitive/height")].operator float() * p_applied_root_scale);455} else {456cylinder->set_height(1.0f * p_applied_root_scale);457}458if (p_options.has(SNAME("primitive/radius"))) {459cylinder->set_radius(p_options[SNAME("primitive/radius")].operator float() * p_applied_root_scale);460} else {461cylinder->set_radius(1.0f * p_applied_root_scale);462}463464Vector<Ref<Shape3D>> shapes;465shapes.push_back(cylinder);466return shapes;467} else if (generate_shape_type == SHAPE_TYPE_CAPSULE) {468Ref<CapsuleShape3D> capsule;469capsule.instantiate();470if (p_options.has(SNAME("primitive/height"))) {471capsule->set_height(p_options[SNAME("primitive/height")].operator float() * p_applied_root_scale);472} else {473capsule->set_height(1.0f * p_applied_root_scale);474}475if (p_options.has(SNAME("primitive/radius"))) {476capsule->set_radius(p_options[SNAME("primitive/radius")].operator float() * p_applied_root_scale);477} else {478capsule->set_radius(1.0f * p_applied_root_scale);479}480481Vector<Ref<Shape3D>> shapes;482shapes.push_back(capsule);483return shapes;484}485return Vector<Ref<Shape3D>>();486}487488template <typename M>489Transform3D ResourceImporterScene::get_collision_shapes_transform(const M &p_options) {490Transform3D transform;491492ShapeType generate_shape_type = SHAPE_TYPE_AUTOMATIC;493if (p_options.has(SNAME("physics/shape_type"))) {494generate_shape_type = (ShapeType)p_options[SNAME("physics/shape_type")].operator int();495}496497if (generate_shape_type == SHAPE_TYPE_AUTOMATIC) {498BodyType body_type = BODY_TYPE_STATIC;499if (p_options.has(SNAME("physics/body_type"))) {500body_type = (BodyType)p_options[SNAME("physics/body_type")].operator int();501}502503generate_shape_type = body_type == BODY_TYPE_DYNAMIC ? SHAPE_TYPE_DECOMPOSE_CONVEX : SHAPE_TYPE_TRIMESH;504}505506if (generate_shape_type == SHAPE_TYPE_BOX ||507generate_shape_type == SHAPE_TYPE_SPHERE ||508generate_shape_type == SHAPE_TYPE_CYLINDER ||509generate_shape_type == SHAPE_TYPE_CAPSULE) {510if (p_options.has(SNAME("primitive/position"))) {511transform.origin = p_options[SNAME("primitive/position")];512}513514if (p_options.has(SNAME("primitive/rotation"))) {515transform.basis = Basis::from_euler(p_options[SNAME("primitive/rotation")].operator Vector3() * (Math::PI / 180.0));516}517}518return transform;519}520521522