index-of-nearest-104619 #2

Merged
Iliya Katushenock merged 62 commits from HooglyBoogly/blender:index-of-nearest-104619 into index_of_nearest 2023-04-20 21:19:53 +02:00
Showing only changes of commit 3e41b98295 - Show all commits

View File

@ -1451,18 +1451,17 @@ Mesh *BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob)
freepolygonize(&process); freepolygonize(&process);
Mesh *mesh = (Mesh *)BKE_id_new_nomain(ID_ME, ((ID *)ob->data)->name + 2); int corners_num = 0;
for (uint i = 0; i < process.curindex; i++) {
const int *indices = process.indices[i];
const int count = indices[2] != indices[3] ? 4 : 3;
corners_num += count;
}
mesh->totvert = int(process.co.size()); Mesh *mesh = BKE_mesh_new_nomain(int(process.co.size()), 0, int(process.curindex), corners_num);
CustomData_add_layer_named(
&mesh->vdata, CD_PROP_FLOAT3, CD_CONSTRUCT, mesh->totvert, "position");
mesh->vert_positions_for_write().copy_from(process.co); mesh->vert_positions_for_write().copy_from(process.co);
mesh->totpoly = int(process.curindex);
BKE_mesh_poly_offsets_ensure_alloc(mesh);
blender::MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write(); blender::MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write();
int *corner_verts = static_cast<int *>(CustomData_add_layer_named( blender::MutableSpan<int> corner_verts = mesh->corner_verts_for_write();
&mesh->ldata, CD_PROP_INT32, CD_CONSTRUCT, mesh->totpoly * 4, ".corner_vert"));
int loop_offset = 0; int loop_offset = 0;
for (int i = 0; i < mesh->totpoly; i++) { for (int i = 0; i < mesh->totpoly; i++) {
@ -1490,9 +1489,6 @@ Mesh *BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob)
sizeof(float[3]) * size_t(mesh->totvert)); sizeof(float[3]) * size_t(mesh->totvert));
BKE_mesh_vert_normals_clear_dirty(mesh); BKE_mesh_vert_normals_clear_dirty(mesh);
mesh->totloop = loop_offset;
poly_offsets.last() = loop_offset;
BKE_mesh_calc_edges(mesh, false, false); BKE_mesh_calc_edges(mesh, false, false);
return mesh; return mesh;