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
40 changed files with 89 additions and 84 deletions
Showing only changes of commit 10d175e223 - Show all commits

View File

@ -158,15 +158,15 @@ void BKE_mesh_ensure_skin_customdata(struct Mesh *me);
/** Add poly offsets to describe faces to a new mesh. */ /** Add poly offsets to describe faces to a new mesh. */
void BKE_mesh_poly_offsets_ensure_alloc(struct Mesh *mesh); void BKE_mesh_poly_offsets_ensure_alloc(struct Mesh *mesh);
struct Mesh *BKE_mesh_new_nomain(int verts_len, int edges_len, int loops_len, int polys_len); struct Mesh *BKE_mesh_new_nomain(int verts_num, int edges_num, int polys_num, int loops_num);
struct Mesh *BKE_mesh_new_nomain_from_template( struct Mesh *BKE_mesh_new_nomain_from_template(
const struct Mesh *me_src, int verts_len, int edges_len, int loops_len, int polys_len); const struct Mesh *me_src, int verts_num, int edges_num, int polys_num, int loops_num);
struct Mesh *BKE_mesh_new_nomain_from_template_ex(const struct Mesh *me_src, struct Mesh *BKE_mesh_new_nomain_from_template_ex(const struct Mesh *me_src,
int verts_len, int verts_num,
int edges_len, int edges_num,
int tessface_len, int tessface_num,
int loops_len, int polys_num,
int polys_len, int loops_num,
struct CustomData_MeshMasks mask); struct CustomData_MeshMasks mask);
void BKE_mesh_eval_delete(struct Mesh *mesh_eval); void BKE_mesh_eval_delete(struct Mesh *mesh_eval);

View File

@ -691,7 +691,7 @@ Mesh *curve_to_mesh_sweep(const CurvesGeometry &main,
} }
Mesh *mesh = BKE_mesh_new_nomain( Mesh *mesh = BKE_mesh_new_nomain(
offsets.vert.last(), offsets.edge.last(), offsets.loop.last(), offsets.poly.last()); offsets.vert.last(), offsets.edge.last(), offsets.poly.last(), offsets.loop.last());
mesh->flag |= ME_AUTOSMOOTH; mesh->flag |= ME_AUTOSMOOTH;
mesh->smoothresh = DEG2RADF(180.0f); mesh->smoothresh = DEG2RADF(180.0f);
MutableSpan<float3> positions = mesh->vert_positions_for_write(); MutableSpan<float3> positions = mesh->vert_positions_for_write();

View File

@ -3229,7 +3229,7 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
return nullptr; return nullptr;
} }
me = BKE_mesh_new_nomain(num_verts, 0, num_faces * 3, num_faces); me = BKE_mesh_new_nomain(num_verts, 0, num_faces, num_faces * 3);
if (!me) { if (!me) {
return nullptr; return nullptr;
} }
@ -3367,7 +3367,7 @@ static Mesh *create_smoke_geometry(FluidDomainSettings *fds, Mesh *orgmesh, Obje
return BKE_mesh_copy_for_eval(orgmesh, false); return BKE_mesh_copy_for_eval(orgmesh, false);
} }
result = BKE_mesh_new_nomain(num_verts, 0, num_faces * 4, num_faces); result = BKE_mesh_new_nomain(num_verts, 0, num_faces, num_faces * 4);
float(*positions)[3] = BKE_mesh_vert_positions_for_write(result); float(*positions)[3] = BKE_mesh_vert_positions_for_write(result);
blender::MutableSpan<int> poly_offsets = result->poly_offsets_for_write(); blender::MutableSpan<int> poly_offsets = result->poly_offsets_for_write();
blender::MutableSpan<int> corner_verts = result->corner_verts_for_write(); blender::MutableSpan<int> corner_verts = result->corner_verts_for_write();

View File

@ -1032,7 +1032,10 @@ static void mesh_ensure_cdlayers_primary(Mesh &mesh)
} }
} }
Mesh *BKE_mesh_new_nomain(int verts_len, int edges_len, int loops_len, int polys_len) Mesh *BKE_mesh_new_nomain(const int verts_num,
const int edges_num,
const int polys_num,
const int loops_num)
{ {
Mesh *mesh = (Mesh *)BKE_libblock_alloc( Mesh *mesh = (Mesh *)BKE_libblock_alloc(
nullptr, ID_ME, BKE_idtype_idcode_to_name(ID_ME), LIB_ID_CREATE_LOCALIZE); nullptr, ID_ME, BKE_idtype_idcode_to_name(ID_ME), LIB_ID_CREATE_LOCALIZE);
@ -1042,13 +1045,13 @@ Mesh *BKE_mesh_new_nomain(int verts_len, int edges_len, int loops_len, int polys
copy_vn_i(mesh->vdata.typemap, CD_NUMTYPES, -1); copy_vn_i(mesh->vdata.typemap, CD_NUMTYPES, -1);
copy_vn_i(mesh->edata.typemap, CD_NUMTYPES, -1); copy_vn_i(mesh->edata.typemap, CD_NUMTYPES, -1);
copy_vn_i(mesh->fdata.typemap, CD_NUMTYPES, -1); copy_vn_i(mesh->fdata.typemap, CD_NUMTYPES, -1);
copy_vn_i(mesh->ldata.typemap, CD_NUMTYPES, -1);
copy_vn_i(mesh->pdata.typemap, CD_NUMTYPES, -1); copy_vn_i(mesh->pdata.typemap, CD_NUMTYPES, -1);
copy_vn_i(mesh->ldata.typemap, CD_NUMTYPES, -1);
mesh->totvert = verts_len; mesh->totvert = verts_num;
mesh->totedge = edges_len; mesh->totedge = edges_num;
mesh->totloop = loops_len; mesh->totpoly = polys_num;
mesh->totpoly = polys_len; mesh->totloop = loops_num;
mesh_ensure_cdlayers_primary(*mesh); mesh_ensure_cdlayers_primary(*mesh);
BKE_mesh_poly_offsets_ensure_alloc(mesh); BKE_mesh_poly_offsets_ensure_alloc(mesh);
@ -1112,35 +1115,35 @@ void BKE_mesh_copy_parameters_for_eval(Mesh *me_dst, const Mesh *me_src)
} }
Mesh *BKE_mesh_new_nomain_from_template_ex(const Mesh *me_src, Mesh *BKE_mesh_new_nomain_from_template_ex(const Mesh *me_src,
int verts_len, const int verts_num,
int edges_len, const int edges_num,
int tessface_len, const int tessface_num,
int loops_len, const int polys_num,
int polys_len, const int loops_num,
CustomData_MeshMasks mask) const CustomData_MeshMasks mask)
{ {
/* Only do tessface if we are creating tessfaces or copying from mesh with only tessfaces. */ /* Only do tessface if we are creating tessfaces or copying from mesh with only tessfaces. */
const bool do_tessface = (tessface_len || ((me_src->totface != 0) && (me_src->totpoly == 0))); const bool do_tessface = (tessface_num || ((me_src->totface != 0) && (me_src->totpoly == 0)));
Mesh *me_dst = (Mesh *)BKE_id_new_nomain(ID_ME, nullptr); Mesh *me_dst = (Mesh *)BKE_id_new_nomain(ID_ME, nullptr);
me_dst->mselect = (MSelect *)MEM_dupallocN(me_src->mselect); me_dst->mselect = (MSelect *)MEM_dupallocN(me_src->mselect);
me_dst->totvert = verts_len; me_dst->totvert = verts_num;
me_dst->totedge = edges_len; me_dst->totedge = edges_num;
me_dst->totface = tessface_len; me_dst->totpoly = polys_num;
me_dst->totloop = loops_len; me_dst->totloop = loops_num;
me_dst->totpoly = polys_len; me_dst->totface = tessface_num;
BKE_mesh_copy_parameters_for_eval(me_dst, me_src); BKE_mesh_copy_parameters_for_eval(me_dst, me_src);
CustomData_copy_layout(&me_src->vdata, &me_dst->vdata, mask.vmask, CD_SET_DEFAULT, verts_len); CustomData_copy_layout(&me_src->vdata, &me_dst->vdata, mask.vmask, CD_SET_DEFAULT, verts_num);
CustomData_copy_layout(&me_src->edata, &me_dst->edata, mask.emask, CD_SET_DEFAULT, edges_len); CustomData_copy_layout(&me_src->edata, &me_dst->edata, mask.emask, CD_SET_DEFAULT, edges_num);
CustomData_copy_layout(&me_src->ldata, &me_dst->ldata, mask.lmask, CD_SET_DEFAULT, loops_len); CustomData_copy_layout(&me_src->pdata, &me_dst->pdata, mask.pmask, CD_SET_DEFAULT, polys_num);
CustomData_copy_layout(&me_src->pdata, &me_dst->pdata, mask.pmask, CD_SET_DEFAULT, polys_len); CustomData_copy_layout(&me_src->ldata, &me_dst->ldata, mask.lmask, CD_SET_DEFAULT, loops_num);
if (do_tessface) { if (do_tessface) {
CustomData_copy_layout( CustomData_copy_layout(
&me_src->fdata, &me_dst->fdata, mask.fmask, CD_SET_DEFAULT, tessface_len); &me_src->fdata, &me_dst->fdata, mask.fmask, CD_SET_DEFAULT, tessface_num);
} }
else { else {
mesh_tessface_clear_intern(me_dst, false); mesh_tessface_clear_intern(me_dst, false);
@ -1160,11 +1163,14 @@ Mesh *BKE_mesh_new_nomain_from_template_ex(const Mesh *me_src,
return me_dst; return me_dst;
} }
Mesh *BKE_mesh_new_nomain_from_template( Mesh *BKE_mesh_new_nomain_from_template(const Mesh *me_src,
const Mesh *me_src, int verts_len, int edges_len, int loops_len, int polys_len) const int verts_num,
const int edges_num,
const int polys_num,
const int loops_num)
{ {
return BKE_mesh_new_nomain_from_template_ex( return BKE_mesh_new_nomain_from_template_ex(
me_src, verts_len, edges_len, 0, loops_len, polys_len, CD_MASK_EVERYTHING); me_src, verts_num, edges_num, 0, polys_num, loops_num, CD_MASK_EVERYTHING);
} }
void BKE_mesh_eval_delete(struct Mesh *mesh_eval) void BKE_mesh_eval_delete(struct Mesh *mesh_eval)

View File

@ -700,7 +700,7 @@ static Mesh *imesh_to_mesh(IMesh *im, MeshesToIMeshInfo &mim)
} }
/* Will calculate edges later. */ /* Will calculate edges later. */
Mesh *result = BKE_mesh_new_nomain_from_template( Mesh *result = BKE_mesh_new_nomain_from_template(
mim.meshes[0], out_totvert, 0, out_totloop, out_totpoly); mim.meshes[0], out_totvert, 0, out_totpoly, out_totloop);
merge_vertex_loop_poly_customdata_layers(result, mim); merge_vertex_loop_poly_customdata_layers(result, mim);
/* Set the vertex coordinate values and other data. */ /* Set the vertex coordinate values and other data. */

View File

@ -113,7 +113,7 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
return BKE_mesh_new_nomain(0, 0, 0, 0); return BKE_mesh_new_nomain(0, 0, 0, 0);
} }
Mesh *mesh = BKE_mesh_new_nomain(totvert, totedge, totloop, totpoly); Mesh *mesh = BKE_mesh_new_nomain(totvert, totedge, totpoly, totloop);
MutableSpan<float3> positions = mesh->vert_positions_for_write(); MutableSpan<float3> positions = mesh->vert_positions_for_write();
MutableSpan<blender::int2> edges = mesh->edges_for_write(); MutableSpan<blender::int2> edges = mesh->edges_for_write();
MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write(); MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write();

View File

@ -191,7 +191,7 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
const int src_loops_num = mesh->totloop; const int src_loops_num = mesh->totloop;
Mesh *result = BKE_mesh_new_nomain_from_template( Mesh *result = BKE_mesh_new_nomain_from_template(
mesh, src_verts_num * 2, src_edges_num * 2, src_loops_num * 2, src_polys.size() * 2); mesh, src_verts_num * 2, src_edges_num * 2, src_polys.size() * 2, src_loops_num * 2);
/* Copy custom-data to original geometry. */ /* Copy custom-data to original geometry. */
CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, src_verts_num); CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, src_verts_num);

View File

@ -117,7 +117,7 @@ static Mesh *remesh_quadriflow(const Mesh *input_mesh,
} }
/* Construct the new output mesh */ /* Construct the new output mesh */
Mesh *mesh = BKE_mesh_new_nomain(qrd.out_totverts, 0, qrd.out_totfaces * 4, qrd.out_totfaces); Mesh *mesh = BKE_mesh_new_nomain(qrd.out_totverts, 0, qrd.out_totfaces, qrd.out_totfaces * 4);
BKE_mesh_copy_parameters(mesh, input_mesh); BKE_mesh_copy_parameters(mesh, input_mesh);
MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write(); MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write();
MutableSpan<int> corner_verts = mesh->corner_verts_for_write(); MutableSpan<int> corner_verts = mesh->corner_verts_for_write();
@ -222,7 +222,7 @@ static Mesh *remesh_voxel_volume_to_mesh(const openvdb::FloatGrid::Ptr level_set
*level_set_grid, vertices, tris, quads, isovalue, adaptivity, relax_disoriented_triangles); *level_set_grid, vertices, tris, quads, isovalue, adaptivity, relax_disoriented_triangles);
Mesh *mesh = BKE_mesh_new_nomain( Mesh *mesh = BKE_mesh_new_nomain(
vertices.size(), 0, quads.size() * 4 + tris.size() * 3, quads.size() + tris.size()); vertices.size(), 0, quads.size() + tris.size(), quads.size() * 4 + tris.size() * 3);
MutableSpan<float3> vert_positions = mesh->vert_positions_for_write(); MutableSpan<float3> vert_positions = mesh->vert_positions_for_write();
MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write(); MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write();
MutableSpan<int> mesh_corner_verts = mesh->corner_verts_for_write(); MutableSpan<int> mesh_corner_verts = mesh->corner_verts_for_write();
@ -317,8 +317,7 @@ void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, const Mesh *source)
const OffsetIndices target_polys = target->polys(); const OffsetIndices target_polys = target->polys();
const Span<int> target_corner_verts = target->corner_verts(); const Span<int> target_corner_verts = target->corner_verts();
const VArray src_face_sets = const VArray src_face_sets = *src_attributes.lookup<int>(".sculpt_face_set", ATTR_DOMAIN_FACE);
* src_attributes.lookup<int>(".sculpt_face_set", ATTR_DOMAIN_FACE);
if (!src_face_sets) { if (!src_face_sets) {
return; return;
} }

View File

@ -532,7 +532,7 @@ static bool subdiv_mesh_topology_info(const SubdivForeachContext *foreach_contex
SubdivMeshContext *subdiv_context = static_cast<SubdivMeshContext *>(foreach_context->user_data); SubdivMeshContext *subdiv_context = static_cast<SubdivMeshContext *>(foreach_context->user_data);
subdiv_context->subdiv_mesh = BKE_mesh_new_nomain_from_template_ex( subdiv_context->subdiv_mesh = BKE_mesh_new_nomain_from_template_ex(
subdiv_context->coarse_mesh, num_vertices, num_edges, 0, num_loops, num_polygons, mask); subdiv_context->coarse_mesh, num_vertices, num_edges, 0, num_polygons, num_loops, mask);
subdiv_mesh_ctx_cache_custom_data_layers(subdiv_context); subdiv_mesh_ctx_cache_custom_data_layers(subdiv_context);
subdiv_mesh_prepare_accumulator(subdiv_context, num_vertices); subdiv_mesh_prepare_accumulator(subdiv_context, num_vertices);
subdiv_context->subdiv_mesh->runtime->subsurf_face_dot_tags.clear(); subdiv_context->subdiv_mesh->runtime->subsurf_face_dot_tags.clear();

View File

@ -165,7 +165,7 @@ Mesh *volume_to_mesh(const openvdb::GridBase &grid,
const int tot_loops = 3 * mesh_data.tris.size() + 4 * mesh_data.quads.size(); const int tot_loops = 3 * mesh_data.tris.size() + 4 * mesh_data.quads.size();
const int tot_polys = mesh_data.tris.size() + mesh_data.quads.size(); const int tot_polys = mesh_data.tris.size() + mesh_data.quads.size();
Mesh *mesh = BKE_mesh_new_nomain(mesh_data.verts.size(), 0, tot_loops, tot_polys); Mesh *mesh = BKE_mesh_new_nomain(mesh_data.verts.size(), 0, tot_polys, tot_loops);
fill_mesh_from_openvdb_data(mesh_data.verts, fill_mesh_from_openvdb_data(mesh_data.verts,
mesh_data.tris, mesh_data.tris,

View File

@ -1135,7 +1135,7 @@ static void sculpt_gesture_trim_geometry_generate(SculptGestureContext *sgcontex
const int trim_totverts = tot_screen_points * 2; const int trim_totverts = tot_screen_points * 2;
const int trim_totpolys = (2 * (tot_screen_points - 2)) + (2 * tot_screen_points); const int trim_totpolys = (2 * (tot_screen_points - 2)) + (2 * tot_screen_points);
trim_operation->mesh = BKE_mesh_new_nomain(trim_totverts, 0, trim_totpolys * 3, trim_totpolys); trim_operation->mesh = BKE_mesh_new_nomain(trim_totverts, 0, trim_totpolys, trim_totpolys * 3);
trim_operation->true_mesh_co = static_cast<float(*)[3]>( trim_operation->true_mesh_co = static_cast<float(*)[3]>(
MEM_malloc_arrayN(trim_totverts, sizeof(float[3]), "mesh orco")); MEM_malloc_arrayN(trim_totverts, sizeof(float[3]), "mesh orco"));

View File

@ -1544,7 +1544,7 @@ static Mesh *create_merged_mesh(const Mesh &mesh,
const int result_npolys = src_polys.size() - weld_mesh.poly_kill_len + weld_mesh.wpoly_new_len; const int result_npolys = src_polys.size() - weld_mesh.poly_kill_len + weld_mesh.wpoly_new_len;
Mesh *result = BKE_mesh_new_nomain_from_template( Mesh *result = BKE_mesh_new_nomain_from_template(
&mesh, result_nverts, result_nedges, result_nloops, result_npolys); &mesh, result_nverts, result_nedges, result_npolys, result_nloops);
MutableSpan<int2> dst_edges = result->edges_for_write(); MutableSpan<int2> dst_edges = result->edges_for_write();
MutableSpan<int> dst_poly_offsets = result->poly_offsets_for_write(); MutableSpan<int> dst_poly_offsets = result->poly_offsets_for_write();
MutableSpan<int> dst_corner_verts = result->corner_verts_for_write(); MutableSpan<int> dst_corner_verts = result->corner_verts_for_write();

View File

@ -400,7 +400,7 @@ Mesh *create_cuboid_mesh(const float3 &size,
{ {
const CuboidConfig config(size, verts_x, verts_y, verts_z); const CuboidConfig config(size, verts_x, verts_y, verts_z);
Mesh *mesh = BKE_mesh_new_nomain(config.vertex_count, 0, config.loop_count, config.poly_count); Mesh *mesh = BKE_mesh_new_nomain(config.vertex_count, 0, config.poly_count, config.loop_count);
MutableSpan<float3> positions = mesh->vert_positions_for_write(); MutableSpan<float3> positions = mesh->vert_positions_for_write();
MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write(); MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write();
MutableSpan<int> corner_verts = mesh->corner_verts_for_write(); MutableSpan<int> corner_verts = mesh->corner_verts_for_write();

View File

@ -1081,7 +1081,7 @@ static void execute_realize_mesh_tasks(const RealizeInstancesOptions &options,
const int tot_loops = last_task.start_indices.loop + last_mesh.totloop; const int tot_loops = last_task.start_indices.loop + last_mesh.totloop;
const int tot_poly = last_task.start_indices.poly + last_mesh.totpoly; const int tot_poly = last_task.start_indices.poly + last_mesh.totpoly;
Mesh *dst_mesh = BKE_mesh_new_nomain(tot_vertices, tot_edges, tot_loops, tot_poly); Mesh *dst_mesh = BKE_mesh_new_nomain(tot_vertices, tot_edges, tot_poly, tot_loops);
MeshComponent &dst_component = r_realized_geometry.get_component_for_write<MeshComponent>(); MeshComponent &dst_component = r_realized_geometry.get_component_for_write<MeshComponent>();
dst_component.replace(dst_mesh); dst_component.replace(dst_mesh);
bke::MutableAttributeAccessor dst_attributes = dst_mesh->attributes_for_write(); bke::MutableAttributeAccessor dst_attributes = dst_mesh->attributes_for_write();

View File

@ -723,7 +723,7 @@ Mesh *AbcMeshReader::read_mesh(Mesh *existing_mesh,
if (topology_changed(existing_mesh, sample_sel)) { if (topology_changed(existing_mesh, sample_sel)) {
new_mesh = BKE_mesh_new_nomain_from_template( new_mesh = BKE_mesh_new_nomain_from_template(
existing_mesh, positions->size(), 0, face_indices->size(), face_counts->size()); existing_mesh, positions->size(), 0, face_counts->size(), face_indices->size());
settings.read_flag |= MOD_MESHSEQ_READ_ALL; settings.read_flag |= MOD_MESHSEQ_READ_ALL;
} }

View File

@ -21,7 +21,7 @@ namespace blender::io::ply {
Mesh *convert_ply_to_mesh(PlyData &data, const PLYImportParams &params) Mesh *convert_ply_to_mesh(PlyData &data, const PLYImportParams &params)
{ {
Mesh *mesh = BKE_mesh_new_nomain( Mesh *mesh = BKE_mesh_new_nomain(
data.vertices.size(), data.edges.size(), data.face_vertices.size(), data.face_sizes.size()); data.vertices.size(), data.edges.size(), data.face_sizes.size(), data.face_vertices.size());
mesh->vert_positions_for_write().copy_from(data.vertices); mesh->vert_positions_for_write().copy_from(data.vertices);

View File

@ -71,7 +71,7 @@ Mesh *STLMeshHelper::to_mesh()
<< std::endl; << std::endl;
} }
Mesh *mesh = BKE_mesh_new_nomain(verts_.size(), 0, tris_.size() * 3, tris_.size()); Mesh *mesh = BKE_mesh_new_nomain(verts_.size(), 0, tris_.size(), tris_.size() * 3);
mesh->vert_positions_for_write().copy_from(verts_); mesh->vert_positions_for_write().copy_from(verts_);

View File

@ -942,7 +942,7 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh,
if (topology_changed(existing_mesh, params.motion_sample_time)) { if (topology_changed(existing_mesh, params.motion_sample_time)) {
new_mesh = true; new_mesh = true;
active_mesh = BKE_mesh_new_nomain_from_template( active_mesh = BKE_mesh_new_nomain_from_template(
existing_mesh, positions_.size(), 0, face_indices_.size(), face_counts_.size()); existing_mesh, positions_.size(), 0, face_counts_.size(), face_indices_.size());
for (pxr::TfToken token : uv_tokens) { for (pxr::TfToken token : uv_tokens) {
add_customdata_cb(active_mesh, token.GetText(), CD_PROP_FLOAT2); add_customdata_cb(active_mesh, token.GetText(), CD_PROP_FLOAT2);

View File

@ -179,7 +179,7 @@ Mesh *USDShapeReader::mesh_from_prim(Mesh *existing_mesh,
Mesh *active_mesh = nullptr; Mesh *active_mesh = nullptr;
if (!position_counts_match || !poly_counts_match) { if (!position_counts_match || !poly_counts_match) {
active_mesh = BKE_mesh_new_nomain_from_template( active_mesh = BKE_mesh_new_nomain_from_template(
existing_mesh, positions.size(), 0, face_indices.size(), face_counts.size()); existing_mesh, positions.size(), 0, face_counts.size(), face_indices.size());
} }
else { else {
active_mesh = existing_mesh; active_mesh = existing_mesh;

View File

@ -48,7 +48,7 @@ Object *MeshFromGeometry::create_mesh(Main *bmain,
const int64_t tot_face_elems{mesh_geometry_.face_elements_.size()}; const int64_t tot_face_elems{mesh_geometry_.face_elements_.size()};
const int64_t tot_loops{mesh_geometry_.total_loops_}; const int64_t tot_loops{mesh_geometry_.total_loops_};
Mesh *mesh = BKE_mesh_new_nomain(tot_verts_object, tot_edges, tot_loops, tot_face_elems); Mesh *mesh = BKE_mesh_new_nomain(tot_verts_object, tot_edges, tot_face_elems, tot_loops);
Object *obj = BKE_object_add_only_object(bmain, OB_MESH, ob_name.c_str()); Object *obj = BKE_object_add_only_object(bmain, OB_MESH, ob_name.c_str());
obj->data = BKE_object_obdata_add_from_type(bmain, OB_MESH, ob_name.c_str()); obj->data = BKE_object_obdata_add_from_type(bmain, OB_MESH, ob_name.c_str());

View File

@ -551,7 +551,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
/* Initialize a result dm */ /* Initialize a result dm */
result = BKE_mesh_new_nomain_from_template( result = BKE_mesh_new_nomain_from_template(
mesh, result_nverts, result_nedges, result_nloops, result_npolys); mesh, result_nverts, result_nedges, result_npolys, result_nloops);
float(*result_positions)[3] = BKE_mesh_vert_positions_for_write(result); float(*result_positions)[3] = BKE_mesh_vert_positions_for_write(result);
blender::MutableSpan<int2> result_edges = result->edges_for_write(); blender::MutableSpan<int2> result_edges = result->edges_for_write();
blender::MutableSpan<int> result_poly_offsets = result->poly_offsets_for_write(); blender::MutableSpan<int> result_poly_offsets = result->poly_offsets_for_write();

View File

@ -189,7 +189,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
/* now we know the number of verts, edges and faces, we can create the mesh. */ /* now we know the number of verts, edges and faces, we can create the mesh. */
result = BKE_mesh_new_nomain_from_template( result = BKE_mesh_new_nomain_from_template(
mesh, BLI_ghash_len(vertHash), BLI_ghash_len(edgeHash), loops_dst_num, faces_dst_num); mesh, BLI_ghash_len(vertHash), BLI_ghash_len(edgeHash), faces_dst_num, loops_dst_num);
blender::MutableSpan<blender::int2> result_edges = result->edges_for_write(); blender::MutableSpan<blender::int2> result_edges = result->edges_for_write();
blender::MutableSpan<int> result_poly_offsets = result->poly_offsets_for_write(); blender::MutableSpan<int> result_poly_offsets = result->poly_offsets_for_write();
blender::MutableSpan<int> result_corner_verts = result->corner_verts_for_write(); blender::MutableSpan<int> result_corner_verts = result->corner_verts_for_write();

View File

@ -702,8 +702,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext * /*ctx*/, M
Mesh *result = BKE_mesh_new_nomain_from_template(mesh, Mesh *result = BKE_mesh_new_nomain_from_template(mesh,
verts_masked_num + verts_add_num, verts_masked_num + verts_add_num,
edges_masked_num + edges_add_num, edges_masked_num + edges_add_num,
loops_masked_num + loops_add_num, polys_masked_num + polys_add_num,
polys_masked_num + polys_add_num); loops_masked_num + loops_add_num);
copy_masked_verts_to_new_mesh(*mesh, *result, vertex_map); copy_masked_verts_to_new_mesh(*mesh, *result, vertex_map);
if (use_interpolation) { if (use_interpolation) {

View File

@ -255,7 +255,7 @@ static Mesh *generate_ocean_geometry(OceanModifierData *omd, Mesh *mesh_orig, co
gogd.sx /= gogd.rx; gogd.sx /= gogd.rx;
gogd.sy /= gogd.ry; gogd.sy /= gogd.ry;
result = BKE_mesh_new_nomain(verts_num, 0, polys_num * 4, polys_num); result = BKE_mesh_new_nomain(verts_num, 0, polys_num, polys_num * 4);
BKE_mesh_copy_parameters_for_eval(result, mesh_orig); BKE_mesh_copy_parameters_for_eval(result, mesh_orig);
gogd.vert_positions = BKE_mesh_vert_positions_for_write(result); gogd.vert_positions = BKE_mesh_vert_positions_for_write(result);

View File

@ -312,7 +312,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
max_co = max[track]; max_co = max[track];
} }
result = BKE_mesh_new_nomain_from_template(mesh, maxvert, maxedge, maxloop, maxpoly); result = BKE_mesh_new_nomain_from_template(mesh, maxvert, maxedge, maxpoly, maxloop);
const blender::OffsetIndices orig_polys = mesh->polys(); const blender::OffsetIndices orig_polys = mesh->polys();
const blender::Span<int> orig_corner_verts = mesh->corner_verts(); const blender::Span<int> orig_corner_verts = mesh->corner_verts();

View File

@ -93,7 +93,7 @@ static void *dualcon_alloc_output(int totvert, int totquad)
return nullptr; return nullptr;
} }
output->mesh = BKE_mesh_new_nomain(totvert, 0, 4 * totquad, totquad); output->mesh = BKE_mesh_new_nomain(totvert, 0, totquad, 4 * totquad);
output->vert_positions = BKE_mesh_vert_positions_for_write(output->mesh); output->vert_positions = BKE_mesh_vert_positions_for_write(output->mesh);
output->poly_offsets = output->mesh->poly_offsets_for_write().data(); output->poly_offsets = output->mesh->poly_offsets_for_write().data();
output->corner_verts = output->mesh->corner_verts_for_write().data(); output->corner_verts = output->mesh->corner_verts_for_write().data();

View File

@ -390,7 +390,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
const bool do_remove_doubles = (ltmd->flag & MOD_SCREW_MERGE) && (screw_ofs == 0.0f); const bool do_remove_doubles = (ltmd->flag & MOD_SCREW_MERGE) && (screw_ofs == 0.0f);
result = BKE_mesh_new_nomain_from_template( result = BKE_mesh_new_nomain_from_template(
mesh, int(maxVerts), int(maxEdges), int(maxPolys) * 4, int(maxPolys)); mesh, int(maxVerts), int(maxEdges), int(maxPolys), int(maxPolys) * 4);
/* The modifier doesn't support original index mapping on the edge or face domains. Remove /* The modifier doesn't support original index mapping on the edge or face domains. Remove
* original index layers, since otherwise edges aren't displayed at all in wireframe view. */ * original index layers, since otherwise edges aren't displayed at all in wireframe view. */
CustomData_free_layers(&result->edata, CD_ORIGINDEX, result->totedge); CustomData_free_layers(&result->edata, CD_ORIGINDEX, result->totedge);

View File

@ -321,8 +321,8 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
result = BKE_mesh_new_nomain_from_template(mesh, result = BKE_mesh_new_nomain_from_template(mesh,
int((verts_num * stride) + newVerts), int((verts_num * stride) + newVerts),
int((edges_num * stride) + newEdges + rimVerts), int((edges_num * stride) + newEdges + rimVerts),
int((loops_num * stride) + newLoops), int((polys_num * stride) + newPolys),
int((polys_num * stride) + newPolys)); int((loops_num * stride) + newLoops));
float(*vert_positions)[3] = BKE_mesh_vert_positions_for_write(result); float(*vert_positions)[3] = BKE_mesh_vert_positions_for_write(result);
blender::MutableSpan<blender::int2> edges = result->edges_for_write(); blender::MutableSpan<blender::int2> edges = result->edges_for_write();

View File

@ -1982,7 +1982,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
/* Create Mesh *result with proper capacity. */ /* Create Mesh *result with proper capacity. */
result = BKE_mesh_new_nomain_from_template( result = BKE_mesh_new_nomain_from_template(
mesh, int(new_verts_num), int(new_edges_num), int(new_loops_num), int(new_polys_num)); mesh, int(new_verts_num), int(new_edges_num), int(new_polys_num), int(new_loops_num));
float(*vert_positions)[3] = BKE_mesh_vert_positions_for_write(result); float(*vert_positions)[3] = BKE_mesh_vert_positions_for_write(result);
blender::MutableSpan<int2> edges = result->edges_for_write(); blender::MutableSpan<int2> edges = result->edges_for_write();

View File

@ -37,10 +37,10 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
/* Create Mesh *result with proper capacity. */ /* Create Mesh *result with proper capacity. */
Mesh *result; Mesh *result;
if (mesh) { if (mesh) {
result = BKE_mesh_new_nomain_from_template(mesh, verts_num, edges_num, loops_num, faces_num); result = BKE_mesh_new_nomain_from_template(mesh, verts_num, edges_num, faces_num, loops_num);
} }
else { else {
result = BKE_mesh_new_nomain(verts_num, edges_num, loops_num, faces_num); result = BKE_mesh_new_nomain(verts_num, edges_num, faces_num, loops_num);
BKE_id_material_eval_ensure_default_slot(&result->id); BKE_id_material_eval_ensure_default_slot(&result->id);
} }
BKE_mesh_smooth_flag_set(result, false); BKE_mesh_smooth_flag_set(result, false);

View File

@ -79,7 +79,7 @@ static Mesh *cdt_to_mesh(const meshintersect::CDT_result<double> &result)
loop_len += face.size(); loop_len += face.size();
} }
Mesh *mesh = BKE_mesh_new_nomain(vert_len, edge_len, loop_len, poly_len); Mesh *mesh = BKE_mesh_new_nomain(vert_len, edge_len, poly_len, loop_len);
MutableSpan<float3> positions = mesh->vert_positions_for_write(); MutableSpan<float3> positions = mesh->vert_positions_for_write();
mesh->edges_for_write().copy_from(result.edge.as_span().cast<int2>()); mesh->edges_for_write().copy_from(result.edge.as_span().cast<int2>());
MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write(); MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write();

View File

@ -913,8 +913,8 @@ static void do_mesh_separation(GeometrySet &geometry_set,
mesh_out = BKE_mesh_new_nomain_from_template(&mesh_in, mesh_out = BKE_mesh_new_nomain_from_template(&mesh_in,
selected_verts_num, selected_verts_num,
selected_edges_num, selected_edges_num,
selected_loops_num, selected_polys_num,
selected_polys_num); selected_loops_num);
/* Copy the selected parts of the mesh over to the new mesh. */ /* Copy the selected parts of the mesh over to the new mesh. */
copy_masked_edges_to_new_mesh(mesh_in, *mesh_out, vertex_map, edge_map); copy_masked_edges_to_new_mesh(mesh_in, *mesh_out, vertex_map, edge_map);
@ -986,7 +986,7 @@ static void do_mesh_separation(GeometrySet &geometry_set,
break; break;
} }
mesh_out = BKE_mesh_new_nomain_from_template( mesh_out = BKE_mesh_new_nomain_from_template(
&mesh_in, mesh_in.totvert, selected_edges_num, selected_loops_num, selected_polys_num); &mesh_in, mesh_in.totvert, selected_edges_num, selected_polys_num, selected_loops_num);
/* Copy the selected parts of the mesh over to the new mesh. */ /* Copy the selected parts of the mesh over to the new mesh. */
copy_masked_edges_to_new_mesh(mesh_in, *mesh_out, edge_map); copy_masked_edges_to_new_mesh(mesh_in, *mesh_out, edge_map);
@ -1049,7 +1049,7 @@ static void do_mesh_separation(GeometrySet &geometry_set,
break; break;
} }
mesh_out = BKE_mesh_new_nomain_from_template( mesh_out = BKE_mesh_new_nomain_from_template(
&mesh_in, mesh_in.totvert, mesh_in.totedge, selected_loops_num, selected_polys_num); &mesh_in, mesh_in.totvert, mesh_in.totedge, selected_polys_num, selected_loops_num);
/* Copy the selected parts of the mesh over to the new mesh. */ /* Copy the selected parts of the mesh over to the new mesh. */
mesh_out->edges_for_write().copy_from(mesh_in.edges()); mesh_out->edges_for_write().copy_from(mesh_in.edges());

View File

@ -869,7 +869,7 @@ static Mesh *calc_dual_mesh(const Mesh &src_mesh,
} }
} }
Mesh *mesh_out = BKE_mesh_new_nomain( Mesh *mesh_out = BKE_mesh_new_nomain(
vert_positions.size(), new_edges.size(), loops.size(), loop_lengths.size()); vert_positions.size(), new_edges.size(), loop_lengths.size(), loops.size());
BKE_mesh_smooth_flag_set(mesh_out, false); BKE_mesh_smooth_flag_set(mesh_out, false);
transfer_attributes(vertex_types, transfer_attributes(vertex_types,

View File

@ -512,7 +512,7 @@ static void duplicate_faces(GeometrySet &geometry_set,
const OffsetIndices<int> duplicates(offset_data); const OffsetIndices<int> duplicates(offset_data);
Mesh *new_mesh = BKE_mesh_new_nomain(total_loops, total_loops, total_loops, total_polys); Mesh *new_mesh = BKE_mesh_new_nomain(total_loops, total_loops, total_polys, total_loops);
MutableSpan<int2> new_edges = new_mesh->edges_for_write(); MutableSpan<int2> new_edges = new_mesh->edges_for_write();
MutableSpan<int> new_poly_offsets = new_mesh->poly_offsets_for_write(); MutableSpan<int> new_poly_offsets = new_mesh->poly_offsets_for_write();
MutableSpan<int> new_corner_verts = new_mesh->corner_verts_for_write(); MutableSpan<int> new_corner_verts = new_mesh->corner_verts_for_write();

View File

@ -110,8 +110,8 @@ static Mesh *create_circle_mesh(const float radius,
{ {
Mesh *mesh = BKE_mesh_new_nomain(circle_vert_total(fill_type, verts_num), Mesh *mesh = BKE_mesh_new_nomain(circle_vert_total(fill_type, verts_num),
circle_edge_total(fill_type, verts_num), circle_edge_total(fill_type, verts_num),
circle_corner_total(fill_type, verts_num), circle_face_total(fill_type, verts_num),
circle_face_total(fill_type, verts_num)); circle_corner_total(fill_type, verts_num));
BKE_id_material_eval_ensure_default_slot(&mesh->id); BKE_id_material_eval_ensure_default_slot(&mesh->id);
MutableSpan<float3> positions = mesh->vert_positions_for_write(); MutableSpan<float3> positions = mesh->vert_positions_for_write();
MutableSpan<int2> edges = mesh->edges_for_write(); MutableSpan<int2> edges = mesh->edges_for_write();

View File

@ -704,7 +704,7 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top,
} }
Mesh *mesh = BKE_mesh_new_nomain( Mesh *mesh = BKE_mesh_new_nomain(
config.tot_verts, config.tot_edges, config.tot_corners, config.tot_faces); config.tot_verts, config.tot_edges, config.tot_faces, config.tot_corners);
BKE_id_material_eval_ensure_default_slot(&mesh->id); BKE_id_material_eval_ensure_default_slot(&mesh->id);
MutableSpan<float3> positions = mesh->vert_positions_for_write(); MutableSpan<float3> positions = mesh->vert_positions_for_write();

View File

@ -51,8 +51,8 @@ Mesh *create_grid_mesh(const int verts_x,
const int edges_y = verts_y - 1; const int edges_y = verts_y - 1;
Mesh *mesh = BKE_mesh_new_nomain(verts_x * verts_y, Mesh *mesh = BKE_mesh_new_nomain(verts_x * verts_y,
edges_x * verts_y + edges_y * verts_x, edges_x * verts_y + edges_y * verts_x,
edges_x * edges_y * 4, edges_x * edges_y,
edges_x * edges_y); edges_x * edges_y * 4);
MutableSpan<float3> positions = mesh->vert_positions_for_write(); MutableSpan<float3> positions = mesh->vert_positions_for_write();
MutableSpan<int2> edges = mesh->edges_for_write(); MutableSpan<int2> edges = mesh->edges_for_write();
MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write(); MutableSpan<int> poly_offsets = mesh->poly_offsets_for_write();

View File

@ -306,8 +306,8 @@ static Mesh *create_uv_sphere_mesh(const float radius,
{ {
Mesh *mesh = BKE_mesh_new_nomain(sphere_vert_total(segments, rings), Mesh *mesh = BKE_mesh_new_nomain(sphere_vert_total(segments, rings),
sphere_edge_total(segments, rings), sphere_edge_total(segments, rings),
sphere_corner_total(segments, rings), sphere_face_total(segments, rings),
sphere_face_total(segments, rings)); sphere_corner_total(segments, rings));
BKE_id_material_eval_ensure_default_slot(&mesh->id); BKE_id_material_eval_ensure_default_slot(&mesh->id);
MutableSpan<float3> positions = mesh->vert_positions_for_write(); MutableSpan<float3> positions = mesh->vert_positions_for_write();
MutableSpan<int2> edges = mesh->edges_for_write(); MutableSpan<int2> edges = mesh->edges_for_write();

View File

@ -123,7 +123,7 @@ static Mesh *create_mesh_from_volume_grids(Span<openvdb::GridBase::ConstPtr> gri
loop_offset += (3 * data.tris.size() + 4 * data.quads.size()); loop_offset += (3 * data.tris.size() + 4 * data.quads.size());
} }
Mesh *mesh = BKE_mesh_new_nomain(vert_offset, 0, loop_offset, poly_offset); Mesh *mesh = BKE_mesh_new_nomain(vert_offset, 0, poly_offset, loop_offset);
BKE_id_material_eval_ensure_default_slot(&mesh->id); BKE_id_material_eval_ensure_default_slot(&mesh->id);
MutableSpan<float3> positions = mesh->vert_positions_for_write(); MutableSpan<float3> positions = mesh->vert_positions_for_write();
MutableSpan<int> dst_poly_offsets = mesh->poly_offsets_for_write(); MutableSpan<int> dst_poly_offsets = mesh->poly_offsets_for_write();

View File

@ -492,7 +492,7 @@ static void do_multires_bake(MultiresBakeRender *bkr,
void *bake_data = nullptr; void *bake_data = nullptr;
Mesh *temp_mesh = BKE_mesh_new_nomain( Mesh *temp_mesh = BKE_mesh_new_nomain(
dm->getNumVerts(dm), dm->getNumEdges(dm), dm->getNumLoops(dm), dm->getNumPolys(dm)); dm->getNumVerts(dm), dm->getNumEdges(dm), dm->getNumPolys(dm), dm->getNumLoops(dm));
temp_mesh->vert_positions_for_write().copy_from( temp_mesh->vert_positions_for_write().copy_from(
{reinterpret_cast<const blender::float3 *>(dm->getVertArray(dm)), temp_mesh->totvert}); {reinterpret_cast<const blender::float3 *>(dm->getVertArray(dm)), temp_mesh->totvert});
temp_mesh->edges_for_write().copy_from( temp_mesh->edges_for_write().copy_from(