Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Blackbourn <chrisbblend@gmail.com>2022-08-11 05:18:31 +0300
committerChris Blackbourn <chrisbblend@gmail.com>2022-08-11 05:20:44 +0300
commitf35d671f466da324ebe70eef3edf12bd3b2b63c9 (patch)
treecc2187cd0844b1f6f911c9c9e2cc05cdec4b43d0 /source/blender/editors
parentd52d71b834433c7da3ac671ba965305568d64529 (diff)
Cleanup: refactoring uvislands to prepare for python api
Add element_map->island_total_uvs. Add element_map->island_total_unique_uvs. Simplify callers based on new members. Add comments. Resolves: D15598
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/mesh/editmesh_utils.c30
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_uv.c9
-rw-r--r--source/blender/editors/transform/transform_convert_mesh_uv.c6
-rw-r--r--source/blender/editors/uvedit/uvedit_ops.c13
-rw-r--r--source/blender/editors/uvedit/uvedit_select.c2
-rw-r--r--source/blender/editors/uvedit/uvedit_smart_stitch.c43
6 files changed, 44 insertions, 59 deletions
diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c
index a0e20e4db8a..e931dd02a9e 100644
--- a/source/blender/editors/mesh/editmesh_utils.c
+++ b/source/blender/editors/mesh/editmesh_utils.c
@@ -820,28 +820,32 @@ static void bm_uv_build_islands(UvElementMap *element_map,
}
}
- element_map->islandIndices = MEM_callocN(sizeof(*element_map->islandIndices) * nislands,
- "UvElementMap_island_indices");
+ element_map->island_indices = MEM_callocN(sizeof(*element_map->island_indices) * nislands,
+ __func__);
+ element_map->island_total_uvs = MEM_callocN(sizeof(*element_map->island_total_uvs) * nislands,
+ __func__);
+ element_map->island_total_unique_uvs = MEM_callocN(
+ sizeof(*element_map->island_total_unique_uvs) * nislands, __func__);
int j = 0;
for (int i = 0; i < totuv; i++) {
- UvElement *element = element_map->storage[i].next;
- if (element == NULL) {
- islandbuf[map[i]].next = NULL;
- }
- else {
- islandbuf[map[i]].next = &islandbuf[map[element - element_map->storage]];
- }
+ UvElement *next = element_map->storage[i].next;
+ islandbuf[map[i]].next = next ? &islandbuf[map[next - element_map->storage]] : NULL;
if (islandbuf[i].island != j) {
j++;
- element_map->islandIndices[j] = i;
+ element_map->island_indices[j] = i;
+ }
+ BLI_assert(islandbuf[i].island == j);
+ element_map->island_total_uvs[j]++;
+ if (islandbuf[i].separate) {
+ element_map->island_total_unique_uvs[j]++;
}
}
MEM_SAFE_FREE(element_map->storage);
element_map->storage = islandbuf;
islandbuf = NULL;
- element_map->totalIslands = nislands;
+ element_map->total_islands = nislands;
MEM_SAFE_FREE(stack);
MEM_SAFE_FREE(map);
}
@@ -1059,7 +1063,9 @@ void BM_uv_element_map_free(UvElementMap *element_map)
MEM_SAFE_FREE(element_map->storage);
MEM_SAFE_FREE(element_map->vertex);
MEM_SAFE_FREE(element_map->head_table);
- MEM_SAFE_FREE(element_map->islandIndices);
+ MEM_SAFE_FREE(element_map->island_indices);
+ MEM_SAFE_FREE(element_map->island_total_uvs);
+ MEM_SAFE_FREE(element_map->island_total_unique_uvs);
MEM_SAFE_FREE(element_map);
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c
index 2e2abd30ea2..14b06f888fe 100644
--- a/source/blender/editors/sculpt_paint/sculpt_uv.c
+++ b/source/blender/editors/sculpt_paint/sculpt_uv.c
@@ -518,13 +518,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm
/* Count 'unique' UV's */
int unique_uvs = data->elementMap->total_unique_uvs;
if (do_island_optimization) {
- unique_uvs = 0;
- for (int i = 0; i < data->elementMap->total_uvs; i++) {
- if (data->elementMap->storage[i].separate &&
- (data->elementMap->storage[i].island == island_index)) {
- unique_uvs++;
- }
- }
+ unique_uvs = data->elementMap->island_total_unique_uvs[island_index];
}
/* Allocate the unique uv buffers */
@@ -572,6 +566,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm
uniqueUv[element - data->elementMap->storage] = counter;
}
}
+ BLI_assert(counter + 1 == unique_uvs);
/* Now, on to generate our uv connectivity data */
counter = 0;
diff --git a/source/blender/editors/transform/transform_convert_mesh_uv.c b/source/blender/editors/transform/transform_convert_mesh_uv.c
index d95bc7b976f..f3bef2c283b 100644
--- a/source/blender/editors/transform/transform_convert_mesh_uv.c
+++ b/source/blender/editors/transform/transform_convert_mesh_uv.c
@@ -270,7 +270,7 @@ static void createTransUVs(bContext *C, TransInfo *t)
continue;
}
- island_center = MEM_callocN(sizeof(*island_center) * elementmap->totalIslands, __func__);
+ island_center = MEM_callocN(sizeof(*island_center) * elementmap->total_islands, __func__);
}
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
@@ -315,9 +315,7 @@ static void createTransUVs(bContext *C, TransInfo *t)
}
if (is_island_center) {
- int i;
-
- for (i = 0; i < elementmap->totalIslands; i++) {
+ for (int i = 0; i < elementmap->total_islands; i++) {
mul_v2_fl(island_center[i].co, 1.0f / island_center[i].co_num);
mul_v2_v2(island_center[i].co, t->aspect);
}
diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c
index 092f0c49d8a..6755630d3ef 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -541,14 +541,11 @@ static bool uvedit_uv_straighten(Scene *scene, BMesh *bm, eUVWeldAlign tool)
}
bool changed = false;
-
- /* Loop backwards to simplify logic. */
- int j1 = element_map->total_uvs;
- for (int i = element_map->totalIslands - 1; i >= 0; --i) {
- int j0 = element_map->islandIndices[i];
- changed |= uvedit_uv_straighten_elements(
- element_map->storage + j0, j1 - j0, cd_loop_uv_offset, tool);
- j1 = j0;
+ for (int i = 0; i < element_map->total_islands; i++) {
+ changed |= uvedit_uv_straighten_elements(element_map->storage + element_map->island_indices[i],
+ element_map->island_total_uvs[i],
+ cd_loop_uv_offset,
+ tool);
}
BM_uv_element_map_free(element_map);
diff --git a/source/blender/editors/uvedit/uvedit_select.c b/source/blender/editors/uvedit/uvedit_select.c
index 749c59ea6a4..d88da21ef98 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -5395,7 +5395,7 @@ static void uv_isolate_selected_islands(const Scene *scene,
return;
}
- int num_islands = elementmap->totalIslands;
+ int num_islands = elementmap->total_islands;
/* Boolean array that tells if island with index i is completely selected or not. */
bool *is_island_not_selected = MEM_callocN(sizeof(bool) * (num_islands), __func__);
diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c
index 26ed98ba236..4a2ea5c3aa6 100644
--- a/source/blender/editors/uvedit/uvedit_smart_stitch.c
+++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c
@@ -287,14 +287,6 @@ static void stitch_update_header(StitchStateContainer *ssc, bContext *C)
}
}
-static int getNumOfIslandUvs(UvElementMap *elementMap, int island)
-{
- if (island == elementMap->totalIslands - 1) {
- return elementMap->total_uvs - elementMap->islandIndices[island];
- }
- return elementMap->islandIndices[island + 1] - elementMap->islandIndices[island];
-}
-
static void stitch_uv_rotate(const float mat[2][2],
const float medianPoint[2],
float uv[2],
@@ -419,10 +411,9 @@ static void stitch_calculate_island_snapping(StitchState *state,
int final)
{
BMesh *bm = state->em->bm;
- int i;
UvElement *element;
- for (i = 0; i < state->element_map->totalIslands; i++) {
+ for (int i = 0; i < state->element_map->total_islands; i++) {
if (island_stitch_data[i].addedForPreview) {
int numOfIslandUVs = 0, j;
int totelem = island_stitch_data[i].num_rot_elements_neg +
@@ -464,8 +455,8 @@ static void stitch_calculate_island_snapping(StitchState *state,
}
angle_to_mat2(rotation_mat, rotation);
- numOfIslandUVs = getNumOfIslandUvs(state->element_map, i);
- element = &state->element_map->storage[state->element_map->islandIndices[i]];
+ numOfIslandUVs = state->element_map->island_total_uvs[i];
+ element = &state->element_map->storage[state->element_map->island_indices[i]];
for (j = 0; j < numOfIslandUVs; j++, element++) {
/* stitchable uvs have already been processed, don't process */
if (!(element->flag & STITCH_PROCESSED)) {
@@ -984,7 +975,7 @@ static int stitch_process_data(StitchStateContainer *ssc,
preview_position[i].data_position = STITCH_NO_PREVIEW;
}
- island_stitch_data = MEM_callocN(sizeof(*island_stitch_data) * state->element_map->totalIslands,
+ island_stitch_data = MEM_callocN(sizeof(*island_stitch_data) * state->element_map->total_islands,
"stitch_island_data");
if (!island_stitch_data) {
return 0;
@@ -1009,7 +1000,7 @@ static int stitch_process_data(StitchStateContainer *ssc,
}
/* Remember stitchable candidates as places the 'I' button will stop at. */
- for (int island_idx = 0; island_idx < state->element_map->totalIslands; island_idx++) {
+ for (int island_idx = 0; island_idx < state->element_map->total_islands; island_idx++) {
state->island_is_stitchable[island_idx] = island_stitch_data[island_idx].stitchableCandidate ?
true :
false;
@@ -1017,10 +1008,10 @@ static int stitch_process_data(StitchStateContainer *ssc,
if (is_active_state) {
/* set static island to one that is added for preview */
- ssc->static_island %= state->element_map->totalIslands;
+ ssc->static_island %= state->element_map->total_islands;
while (!(island_stitch_data[ssc->static_island].stitchableCandidate)) {
ssc->static_island++;
- ssc->static_island %= state->element_map->totalIslands;
+ ssc->static_island %= state->element_map->total_islands;
/* this is entirely possible if for example limit stitching
* with no stitchable verts or no selection */
if (ssc->static_island == previous_island) {
@@ -1141,13 +1132,11 @@ static int stitch_process_data(StitchStateContainer *ssc,
* Setup preview for stitchable islands *
****************************************/
if (ssc->snap_islands) {
- for (i = 0; i < state->element_map->totalIslands; i++) {
+ for (i = 0; i < state->element_map->total_islands; i++) {
if (island_stitch_data[i].addedForPreview) {
- int numOfIslandUVs = 0, j;
- UvElement *element;
- numOfIslandUVs = getNumOfIslandUvs(state->element_map, i);
- element = &state->element_map->storage[state->element_map->islandIndices[i]];
- for (j = 0; j < numOfIslandUVs; j++, element++) {
+ int numOfIslandUVs = state->element_map->island_total_uvs[i];
+ UvElement *element = &state->element_map->storage[state->element_map->island_indices[i]];
+ for (int j = 0; j < numOfIslandUVs; j++, element++) {
stitch_set_face_preview_buffer_position(element->l->f, preview, preview_position);
}
}
@@ -2120,8 +2109,8 @@ static StitchState *stitch_init(bContext *C,
/***** initialize static island preview data *****/
state->tris_per_island = MEM_mallocN(
- sizeof(*state->tris_per_island) * state->element_map->totalIslands, "stitch island tris");
- for (i = 0; i < state->element_map->totalIslands; i++) {
+ sizeof(*state->tris_per_island) * state->element_map->total_islands, "stitch island tris");
+ for (i = 0; i < state->element_map->total_islands; i++) {
state->tris_per_island[i] = 0;
}
@@ -2133,7 +2122,7 @@ static StitchState *stitch_init(bContext *C,
}
}
- state->island_is_stitchable = MEM_callocN(sizeof(bool) * state->element_map->totalIslands,
+ state->island_is_stitchable = MEM_callocN(sizeof(bool) * state->element_map->total_islands,
"stitch I stops");
if (!state->island_is_stitchable) {
state_delete(state);
@@ -2157,7 +2146,7 @@ static bool goto_next_island(StitchStateContainer *ssc)
do {
ssc->static_island++;
- if (ssc->static_island >= active_state->element_map->totalIslands) {
+ if (ssc->static_island >= active_state->element_map->total_islands) {
/* go to next object */
ssc->active_object_index++;
ssc->active_object_index %= ssc->objects_len;
@@ -2307,7 +2296,7 @@ static int stitch_init_all(bContext *C, wmOperator *op)
ssc->static_island = RNA_int_get(op->ptr, "static_island");
StitchState *state = ssc->states[ssc->active_object_index];
- ssc->static_island %= state->element_map->totalIslands;
+ ssc->static_island %= state->element_map->total_islands;
/* If the initial active object doesn't have any stitchable islands
* then no active island will be seen in the UI.