Cleanup: Use attribute API for "Reset UVs" function
Also make the implementation local, and take an attribute name argument rather than the index of the UV map. Pull Request: https://projects.blender.org/blender/blender/pulls/146342
This commit is contained in:
@@ -526,10 +526,6 @@ int ED_mesh_uv_add(
|
||||
Mesh *mesh, const char *name, bool active_set, bool do_init, ReportList *reports);
|
||||
|
||||
void ED_mesh_uv_loop_reset(bContext *C, Mesh *mesh);
|
||||
/**
|
||||
* Without a #bContext, called when UV-editing.
|
||||
*/
|
||||
void ED_mesh_uv_loop_reset_ex(Mesh *mesh, int layernum);
|
||||
bool ED_mesh_color_ensure(Mesh *mesh, const char *name);
|
||||
int ED_mesh_color_add(
|
||||
Mesh *mesh, const char *name, bool active_set, bool do_init, ReportList *reports);
|
||||
|
||||
@@ -149,7 +149,7 @@ static void mesh_uv_reset_array(float **fuv, const int len)
|
||||
}
|
||||
}
|
||||
|
||||
static void mesh_uv_reset_bmface(BMFace *f, const int cd_loop_uv_offset)
|
||||
static void reset_uvs_bmesh(BMFace *f, const int cd_loop_uv_offset)
|
||||
{
|
||||
Array<float *, BM_DEFAULT_NGON_STACK_SIZE> fuv(f->len);
|
||||
BMIter liter;
|
||||
@@ -163,47 +163,43 @@ static void mesh_uv_reset_bmface(BMFace *f, const int cd_loop_uv_offset)
|
||||
mesh_uv_reset_array(fuv.data(), f->len);
|
||||
}
|
||||
|
||||
static void mesh_uv_reset_mface(const blender::IndexRange face, float2 *uv_map)
|
||||
static void reset_uvs_mesh(const blender::IndexRange face, MutableSpan<float2> uv_map)
|
||||
{
|
||||
Array<float *, BM_DEFAULT_NGON_STACK_SIZE> fuv(face.size());
|
||||
|
||||
for (int i = 0; i < face.size(); i++) {
|
||||
fuv[i] = uv_map[face[i]];
|
||||
fuv[i] = &uv_map[face[i]].x;
|
||||
}
|
||||
|
||||
mesh_uv_reset_array(fuv.data(), face.size());
|
||||
}
|
||||
|
||||
void ED_mesh_uv_loop_reset_ex(Mesh *mesh, const int layernum)
|
||||
static void reset_uv_map(Mesh *mesh, const StringRef name)
|
||||
{
|
||||
using namespace blender;
|
||||
if (BMEditMesh *em = mesh->runtime->edit_mesh.get()) {
|
||||
/* Collect BMesh UVs */
|
||||
const int cd_loop_uv_offset = CustomData_get_n_offset(
|
||||
&em->bm->ldata, CD_PROP_FLOAT2, layernum);
|
||||
const int cd_loop_uv_offset = CustomData_get_offset_named(
|
||||
&em->bm->ldata, CD_PROP_FLOAT2, name);
|
||||
BLI_assert(cd_loop_uv_offset >= 0);
|
||||
|
||||
BMFace *efa;
|
||||
BMIter iter;
|
||||
|
||||
BLI_assert(cd_loop_uv_offset >= 0);
|
||||
|
||||
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
|
||||
if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mesh_uv_reset_bmface(efa, cd_loop_uv_offset);
|
||||
reset_uvs_bmesh(efa, cd_loop_uv_offset);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Collect Mesh UVs */
|
||||
BLI_assert(CustomData_has_layer(&mesh->corner_data, CD_PROP_FLOAT2));
|
||||
float2 *uv_map = static_cast<float2 *>(CustomData_get_layer_n_for_write(
|
||||
&mesh->corner_data, CD_PROP_FLOAT2, layernum, mesh->corners_num));
|
||||
|
||||
const blender::OffsetIndices polys = mesh->faces();
|
||||
for (const int i : polys.index_range()) {
|
||||
mesh_uv_reset_mface(polys[i], uv_map);
|
||||
const OffsetIndices faces = mesh->faces();
|
||||
bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
|
||||
bke::SpanAttributeWriter uv_map = attributes.lookup_for_write_span<float2>(name);
|
||||
BLI_assert(uv_map.domain == bke::AttrDomain::Corner);
|
||||
for (const int i : faces.index_range()) {
|
||||
reset_uvs_mesh(faces[i], uv_map.span);
|
||||
}
|
||||
uv_map.finish();
|
||||
}
|
||||
|
||||
DEG_id_tag_update(&mesh->id, 0);
|
||||
@@ -213,8 +209,8 @@ void ED_mesh_uv_loop_reset(bContext *C, Mesh *mesh)
|
||||
{
|
||||
/* could be ldata or pdata */
|
||||
CustomData *ldata = mesh_customdata_get_type(mesh, BM_LOOP, nullptr);
|
||||
const int layernum = CustomData_get_active_layer(ldata, CD_PROP_FLOAT2);
|
||||
ED_mesh_uv_loop_reset_ex(mesh, layernum);
|
||||
const char *name = CustomData_get_active_layer_name(ldata, CD_PROP_FLOAT2);
|
||||
reset_uv_map(mesh, name);
|
||||
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, mesh);
|
||||
}
|
||||
@@ -284,7 +280,7 @@ int ED_mesh_uv_add(
|
||||
|
||||
/* don't overwrite our copied coords */
|
||||
if (!is_init && do_init) {
|
||||
ED_mesh_uv_loop_reset_ex(mesh, layernum_dst);
|
||||
reset_uv_map(mesh, unique_name);
|
||||
}
|
||||
|
||||
DEG_id_tag_update(&mesh->id, 0);
|
||||
|
||||
Reference in New Issue
Block a user