diff options
Diffstat (limited to 'editor/import/resource_importer_scene.cpp')
-rw-r--r-- | editor/import/resource_importer_scene.cpp | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 94a6fee6b7..16b5c00969 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -32,19 +32,19 @@ #include "core/io/resource_saver.h" #include "editor/editor_node.h" -#include "scene/3d/collision_shape.h" -#include "scene/3d/mesh_instance.h" -#include "scene/3d/navigation.h" -#include "scene/3d/physics_body.h" +#include "scene/3d/collision_shape_3d.h" +#include "scene/3d/mesh_instance_3d.h" +#include "scene/3d/navigation_3d.h" +#include "scene/3d/physics_body_3d.h" #include "scene/3d/vehicle_body.h" #include "scene/animation/animation_player.h" #include "scene/resources/animation.h" -#include "scene/resources/box_shape.h" +#include "scene/resources/box_shape_3d.h" #include "scene/resources/packed_scene.h" #include "scene/resources/ray_shape.h" #include "scene/resources/resource_format_text.h" -#include "scene/resources/sphere_shape.h" -#include "scene/resources/world_margin_shape.h" +#include "scene/resources/sphere_shape_3d.h" +#include "scene/resources/world_margin_shape_3d.h" uint32_t EditorSceneImporter::get_import_flags() const { @@ -276,15 +276,15 @@ static String _fixstr(const String &p_what, const String &p_str) { return what; } -static void _gen_shape_list(const Ref<Mesh> &mesh, List<Ref<Shape>> &r_shape_list, bool p_convex) { +static void _gen_shape_list(const Ref<Mesh> &mesh, List<Ref<Shape3D>> &r_shape_list, bool p_convex) { if (!p_convex) { - Ref<Shape> shape = mesh->create_trimesh_shape(); + Ref<Shape3D> shape = mesh->create_trimesh_shape(); r_shape_list.push_back(shape); } else { - Vector<Ref<Shape>> cd = mesh->convex_decompose(); + Vector<Ref<Shape3D>> cd = mesh->convex_decompose(); if (cd.size()) { for (int i = 0; i < cd.size(); i++) { r_shape_list.push_back(cd[i]); @@ -293,7 +293,7 @@ static void _gen_shape_list(const Ref<Mesh> &mesh, List<Ref<Shape>> &r_shape_lis } } -Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>, List<Ref<Shape>>> &collision_map, LightBakeMode p_light_bake_mode) { +Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>, List<Ref<Shape3D>>> &collision_map, LightBakeMode p_light_bake_mode) { // children first for (int i = 0; i < p_node->get_child_count(); i++) { @@ -314,9 +314,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> return NULL; } - if (Object::cast_to<MeshInstance>(p_node)) { + if (Object::cast_to<MeshInstance3D>(p_node)) { - MeshInstance *mi = Object::cast_to<MeshInstance>(p_node); + MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); Ref<ArrayMesh> m = mi->get_mesh(); @@ -344,7 +344,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> if (p_light_bake_mode != LIGHT_BAKE_DISABLED) { - mi->set_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT, true); + mi->set_flag(GeometryInstance3D::FLAG_USE_BAKED_LIGHT, true); } } @@ -377,12 +377,12 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> if (isroot) return p_node; - MeshInstance *mi = Object::cast_to<MeshInstance>(p_node); + MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); if (mi) { Ref<Mesh> mesh = mi->get_mesh(); if (mesh.is_valid()) { - List<Ref<Shape>> shapes; + List<Ref<Shape3D>> shapes; String fixed_name; if (collision_map.has(mesh)) { shapes = collision_map[mesh]; @@ -404,7 +404,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> if (shapes.size()) { - StaticBody *col = memnew(StaticBody); + StaticBody3D *col = memnew(StaticBody3D); col->set_transform(mi->get_transform()); col->set_name(fixed_name); p_node->replace_by(col); @@ -412,9 +412,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> p_node = col; int idx = 0; - for (List<Ref<Shape>>::Element *E = shapes.front(); E; E = E->next()) { + for (List<Ref<Shape3D>>::Element *E = shapes.front(); E; E = E->next()) { - CollisionShape *cshape = memnew(CollisionShape); + CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(E->get()); col->add_child(cshape); @@ -427,55 +427,55 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } else if (p_node->has_meta("empty_draw_type")) { String empty_draw_type = String(p_node->get_meta("empty_draw_type")); - StaticBody *sb = memnew(StaticBody); + StaticBody3D *sb = memnew(StaticBody3D); sb->set_name(_fixstr(name, "colonly")); - Object::cast_to<Spatial>(sb)->set_transform(Object::cast_to<Spatial>(p_node)->get_transform()); + Object::cast_to<Node3D>(sb)->set_transform(Object::cast_to<Node3D>(p_node)->get_transform()); p_node->replace_by(sb); memdelete(p_node); p_node = NULL; - CollisionShape *colshape = memnew(CollisionShape); + CollisionShape3D *colshape = memnew(CollisionShape3D); if (empty_draw_type == "CUBE") { - BoxShape *boxShape = memnew(BoxShape); + BoxShape3D *boxShape = memnew(BoxShape3D); boxShape->set_extents(Vector3(1, 1, 1)); colshape->set_shape(boxShape); - colshape->set_name("BoxShape"); + colshape->set_name("BoxShape3D"); } else if (empty_draw_type == "SINGLE_ARROW") { - RayShape *rayShape = memnew(RayShape); + RayShape3D *rayShape = memnew(RayShape3D); rayShape->set_length(1); colshape->set_shape(rayShape); - colshape->set_name("RayShape"); - Object::cast_to<Spatial>(sb)->rotate_x(Math_PI / 2); + colshape->set_name("RayShape3D"); + Object::cast_to<Node3D>(sb)->rotate_x(Math_PI / 2); } else if (empty_draw_type == "IMAGE") { - WorldMarginShape *world_margin_shape = memnew(WorldMarginShape); + WorldMarginShape3D *world_margin_shape = memnew(WorldMarginShape3D); colshape->set_shape(world_margin_shape); colshape->set_name("WorldMarginShape"); } else { - SphereShape *sphereShape = memnew(SphereShape); + SphereShape3D *sphereShape = memnew(SphereShape3D); sphereShape->set_radius(1); colshape->set_shape(sphereShape); - colshape->set_name("SphereShape"); + colshape->set_name("SphereShape3D"); } sb->add_child(colshape); colshape->set_owner(sb->get_owner()); } - } else if (_teststr(name, "rigid") && Object::cast_to<MeshInstance>(p_node)) { + } else if (_teststr(name, "rigid") && Object::cast_to<MeshInstance3D>(p_node)) { if (isroot) return p_node; - MeshInstance *mi = Object::cast_to<MeshInstance>(p_node); + MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); Ref<Mesh> mesh = mi->get_mesh(); if (mesh.is_valid()) { - List<Ref<Shape>> shapes; + List<Ref<Shape3D>> shapes; if (collision_map.has(mesh)) { shapes = collision_map[mesh]; } else { _gen_shape_list(mesh, shapes, true); } - RigidBody *rigid_body = memnew(RigidBody); + RigidBody3D *rigid_body = memnew(RigidBody3D); rigid_body->set_name(_fixstr(name, "rigid")); p_node->replace_by(rigid_body); rigid_body->set_transform(mi->get_transform()); @@ -486,9 +486,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> mi->set_owner(rigid_body->get_owner()); int idx = 0; - for (List<Ref<Shape>>::Element *E = shapes.front(); E; E = E->next()) { + for (List<Ref<Shape3D>>::Element *E = shapes.front(); E; E = E->next()) { - CollisionShape *cshape = memnew(CollisionShape); + CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(E->get()); rigid_body->add_child(cshape); @@ -498,14 +498,14 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } } - } else if ((_teststr(name, "col") || (_teststr(name, "convcol"))) && Object::cast_to<MeshInstance>(p_node)) { + } else if ((_teststr(name, "col") || (_teststr(name, "convcol"))) && Object::cast_to<MeshInstance3D>(p_node)) { - MeshInstance *mi = Object::cast_to<MeshInstance>(p_node); + MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); Ref<Mesh> mesh = mi->get_mesh(); if (mesh.is_valid()) { - List<Ref<Shape>> shapes; + List<Ref<Shape3D>> shapes; String fixed_name; if (collision_map.has(mesh)) { shapes = collision_map[mesh]; @@ -530,15 +530,15 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } if (shapes.size()) { - StaticBody *col = memnew(StaticBody); + StaticBody3D *col = memnew(StaticBody3D); col->set_name("static_collision"); mi->add_child(col); col->set_owner(mi->get_owner()); int idx = 0; - for (List<Ref<Shape>>::Element *E = shapes.front(); E; E = E->next()) { + for (List<Ref<Shape3D>>::Element *E = shapes.front(); E; E = E->next()) { - CollisionShape *cshape = memnew(CollisionShape); + CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(E->get()); col->add_child(cshape); @@ -550,22 +550,22 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } } - } else if (_teststr(name, "navmesh") && Object::cast_to<MeshInstance>(p_node)) { + } else if (_teststr(name, "navmesh") && Object::cast_to<MeshInstance3D>(p_node)) { if (isroot) return p_node; - MeshInstance *mi = Object::cast_to<MeshInstance>(p_node); + MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); Ref<ArrayMesh> mesh = mi->get_mesh(); ERR_FAIL_COND_V(mesh.is_null(), NULL); - NavigationRegion *nmi = memnew(NavigationRegion); + NavigationRegion3D *nmi = memnew(NavigationRegion3D); nmi->set_name(_fixstr(name, "navmesh")); Ref<NavigationMesh> nmesh = memnew(NavigationMesh); nmesh->create_from_mesh(mesh); nmi->set_navigation_mesh(nmesh); - Object::cast_to<Spatial>(nmi)->set_transform(mi->get_transform()); + Object::cast_to<Node3D>(nmi)->set_transform(mi->get_transform()); p_node->replace_by(nmi); memdelete(p_node); p_node = nmi; @@ -575,7 +575,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> return p_node; Node *owner = p_node->get_owner(); - Spatial *s = Object::cast_to<Spatial>(p_node); + Node3D *s = Object::cast_to<Node3D>(p_node); VehicleBody *bv = memnew(VehicleBody); String n = _fixstr(p_node->get_name(), "vehicle"); bv->set_name(n); @@ -595,7 +595,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> return p_node; Node *owner = p_node->get_owner(); - Spatial *s = Object::cast_to<Spatial>(p_node); + Node3D *s = Object::cast_to<Node3D>(p_node); VehicleWheel *bv = memnew(VehicleWheel); String n = _fixstr(p_node->get_name(), "wheel"); bv->set_name(n); @@ -609,16 +609,16 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> p_node = bv; - } else if (Object::cast_to<MeshInstance>(p_node)) { + } else if (Object::cast_to<MeshInstance3D>(p_node)) { //last attempt, maybe collision inside the mesh data - MeshInstance *mi = Object::cast_to<MeshInstance>(p_node); + MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); Ref<ArrayMesh> mesh = mi->get_mesh(); if (!mesh.is_null()) { - List<Ref<Shape>> shapes; + List<Ref<Shape3D>> shapes; if (collision_map.has(mesh)) { shapes = collision_map[mesh]; } else if (_teststr(mesh->get_name(), "col")) { @@ -632,15 +632,15 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } if (shapes.size()) { - StaticBody *col = memnew(StaticBody); + StaticBody3D *col = memnew(StaticBody3D); col->set_name("static_collision"); p_node->add_child(col); col->set_owner(p_node->get_owner()); int idx = 0; - for (List<Ref<Shape>>::Element *E = shapes.front(); E; E = E->next()) { + for (List<Ref<Shape3D>>::Element *E = shapes.front(); E; E = E->next()) { - CollisionShape *cshape = memnew(CollisionShape); + CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(E->get()); col->add_child(cshape); @@ -934,14 +934,14 @@ void ResourceImporterScene::_find_meshes(Node *p_node, Map<Ref<ArrayMesh>, Trans List<PropertyInfo> pi; p_node->get_property_list(&pi); - MeshInstance *mi = Object::cast_to<MeshInstance>(p_node); + MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); if (mi) { Ref<ArrayMesh> mesh = mi->get_mesh(); if (mesh.is_valid() && !meshes.has(mesh)) { - Spatial *s = mi; + Node3D *s = mi; Transform transform; while (s) { transform = transform * s->get_transform(); @@ -1141,7 +1141,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, int p_preset) const { - r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "nodes/root_type", PROPERTY_HINT_TYPE_STRING, "Node"), "Spatial")); + r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "nodes/root_type", PROPERTY_HINT_TYPE_STRING, "Node"), "Node3D")); r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "nodes/root_name"), "Scene Root")); List<String> script_extentions; @@ -1333,7 +1333,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p root_type = ScriptServer::get_global_class_base(root_type); } - if (root_type != "Spatial") { + if (root_type != "Node3D") { Node *base_node = Object::cast_to<Node>(ClassDB::instance(root_type)); if (base_node) { @@ -1348,9 +1348,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p scene->set_script(Variant(root_script)); } - if (Object::cast_to<Spatial>(scene)) { + if (Object::cast_to<Node3D>(scene)) { float root_scale = p_options["nodes/root_scale"]; - Object::cast_to<Spatial>(scene)->scale(Vector3(root_scale, root_scale, root_scale)); + Object::cast_to<Node3D>(scene)->scale(Vector3(root_scale, root_scale, root_scale)); } if (p_options["nodes/root_name"] != "Scene Root") @@ -1368,7 +1368,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p float anim_optimizer_maxang = p_options["animation/optimizer/max_angle"]; int light_bake_mode = p_options["meshes/light_baking"]; - Map<Ref<Mesh>, List<Ref<Shape>>> collision_map; + Map<Ref<Mesh>, List<Ref<Shape3D>>> collision_map; scene = _fix_node(scene, scene, collision_map, LightBakeMode(light_bake_mode)); |