Merge pull request #47287 from Shatur95/fix-duplicated-code
Move duplicated code into a function
This commit is contained in:
commit
300f86351e
@ -376,15 +376,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
|
||||
memdelete(p_node);
|
||||
p_node = col;
|
||||
|
||||
int idx = 0;
|
||||
for (List<Ref<Shape3D>>::Element *E = shapes.front(); E; E = E->next()) {
|
||||
CollisionShape3D *cshape = memnew(CollisionShape3D);
|
||||
cshape->set_shape(E->get());
|
||||
col->add_child(cshape);
|
||||
|
||||
cshape->set_owner(col->get_owner());
|
||||
idx++;
|
||||
}
|
||||
_add_shapes(col, shapes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -443,15 +435,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
|
||||
rigid_body->add_child(mi);
|
||||
mi->set_owner(rigid_body->get_owner());
|
||||
|
||||
int idx = 0;
|
||||
for (List<Ref<Shape3D>>::Element *E = shapes.front(); E; E = E->next()) {
|
||||
CollisionShape3D *cshape = memnew(CollisionShape3D);
|
||||
cshape->set_shape(E->get());
|
||||
rigid_body->add_child(cshape);
|
||||
|
||||
cshape->set_owner(p_node->get_owner());
|
||||
idx++;
|
||||
}
|
||||
_add_shapes(rigid_body, shapes);
|
||||
}
|
||||
|
||||
} else if ((_teststr(name, "col") || (_teststr(name, "convcol"))) && Object::cast_to<EditorSceneImporterMeshNode3D>(p_node)) {
|
||||
@ -489,16 +473,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
|
||||
mi->add_child(col);
|
||||
col->set_owner(mi->get_owner());
|
||||
|
||||
int idx = 0;
|
||||
for (List<Ref<Shape3D>>::Element *E = shapes.front(); E; E = E->next()) {
|
||||
CollisionShape3D *cshape = memnew(CollisionShape3D);
|
||||
cshape->set_shape(E->get());
|
||||
col->add_child(cshape);
|
||||
|
||||
cshape->set_owner(p_node->get_owner());
|
||||
|
||||
idx++;
|
||||
}
|
||||
_add_shapes(col, shapes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -546,15 +521,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
|
||||
p_node->add_child(col);
|
||||
col->set_owner(p_node->get_owner());
|
||||
|
||||
int idx = 0;
|
||||
for (List<Ref<Shape3D>>::Element *E = shapes.front(); E; E = E->next()) {
|
||||
CollisionShape3D *cshape = memnew(CollisionShape3D);
|
||||
cshape->set_shape(E->get());
|
||||
col->add_child(cshape);
|
||||
|
||||
cshape->set_owner(p_node->get_owner());
|
||||
idx++;
|
||||
}
|
||||
_add_shapes(col, shapes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1300,6 +1267,16 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceImporterScene::_add_shapes(Node *p_node, const List<Ref<Shape3D>> &p_shapes) {
|
||||
for (const List<Ref<Shape3D>>::Element *E = p_shapes.front(); E; E = E->next()) {
|
||||
CollisionShape3D *cshape = memnew(CollisionShape3D);
|
||||
cshape->set_shape(E->get());
|
||||
p_node->add_child(cshape);
|
||||
|
||||
cshape->set_owner(p_node->get_owner());
|
||||
}
|
||||
}
|
||||
|
||||
Node *ResourceImporterScene::pre_import(const String &p_source_file) {
|
||||
Ref<EditorSceneImporter> importer;
|
||||
String ext = p_source_file.get_extension().to_lower();
|
||||
|
@ -120,6 +120,7 @@ class ResourceImporterScene : public ResourceImporter {
|
||||
|
||||
void _replace_owner(Node *p_node, Node *p_scene, Node *p_new_owner);
|
||||
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<uint8_t> &r_dst_lightmap_cache);
|
||||
void _add_shapes(Node *p_node, const List<Ref<Shape3D>> &p_shapes);
|
||||
|
||||
public:
|
||||
static ResourceImporterScene *get_singleton() { return singleton; }
|
||||
|
Loading…
Reference in New Issue
Block a user