diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-22 02:19:45 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-22 12:48:16 +0300 |
commit | 620b960d3d8cfd90b9f0df6ba3671c33eccb8309 (patch) | |
tree | 64f69db4bf9d44f0a32d1c92b0714bf2dc98ff2d /source/blender/editors/uvedit/uvedit_unwrap_ops.c | |
parent | bba60bb564cf5a16cfcac744d4ba82cf8eba3da9 (diff) |
Cleanup: style, use braces for editors
Diffstat (limited to 'source/blender/editors/uvedit/uvedit_unwrap_ops.c')
-rw-r--r-- | source/blender/editors/uvedit/uvedit_unwrap_ops.c | 213 |
1 files changed, 142 insertions, 71 deletions
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index 92f7873d5c1..85393925802 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -84,10 +84,12 @@ static void modifier_unwrap_state(Object *obedit, Scene *scene, bool *r_use_subs /* subsurf will take the modifier settings only if modifier is first or right after mirror */ if (subsurf) { - if (md && md->type == eModifierType_Subsurf) + if (md && md->type == eModifierType_Subsurf) { subsurf = true; - else + } + else { subsurf = false; + } } *r_use_subsurf = subsurf; @@ -105,14 +107,17 @@ static bool ED_uvedit_ensure_uvs(bContext *C, Scene *UNUSED(scene), Object *obed SpaceImage *sima; int cd_loop_uv_offset; - if (ED_uvedit_test(obedit)) + if (ED_uvedit_test(obedit)) { return 1; + } - if (em && em->bm->totface && !CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV)) + if (em && em->bm->totface && !CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV)) { ED_mesh_uv_texture_add(obedit->data, NULL, true, true); + } - if (!ED_uvedit_test(obedit)) + if (!ED_uvedit_test(obedit)) { return 0; + } cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); @@ -129,10 +134,12 @@ static bool ED_uvedit_ensure_uvs(bContext *C, Scene *UNUSED(scene), Object *obed ima = sima->image; if (ima) { - if (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE) + if (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE) { ima = NULL; - else + } + else { break; + } } } } @@ -176,19 +183,23 @@ static bool uvedit_have_selection(Scene *scene, BMEditMesh *em, const UnwrapOpti * so we can cancel the operator early */ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { if (scene->toolsettings->uv_flag & UV_SYNC_SELECTION) { - if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) + if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { continue; + } } - else if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + else if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { break; + } } - if (options->topology_from_uvs && !l) + if (options->topology_from_uvs && !l) { continue; + } return true; } @@ -286,8 +297,9 @@ static ParamHandle *construct_param_handle(Scene *scene, ED_uvedit_get_aspect(scene, ob, bm, &aspx, &aspy); - if (aspx != aspy) + if (aspx != aspy) { param_aspect_ratio(handle, aspx, aspy); + } } /* we need the vert indices */ @@ -432,8 +444,9 @@ static void texface_from_original_index(BMFace *efa, *pin = 0; *select = 1; - if (index == ORIGINDEX_NONE) + if (index == ORIGINDEX_NONE) { return; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { if (BM_elem_index_get(l->v) == index) { @@ -495,8 +508,9 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, ED_uvedit_get_aspect(scene, ob, em->bm, &aspx, &aspy); - if (aspx != aspy) + if (aspx != aspy) { param_aspect_ratio(handle, aspx, aspy); + } } /* number of subdivisions to perform */ @@ -531,8 +545,9 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BM_mesh_elem_table_ensure(em->bm, BM_EDGE | BM_FACE); /* map subsurfed faces to original editFaces */ - for (i = 0; i < numOfFaces; i++) + for (i = 0; i < numOfFaces; i++) { faceMap[i] = BM_face_at_index(em->bm, origPolyIndices[i]); + } edgeMap = MEM_mallocN(numOfEdges * sizeof(BMEdge *), "unwrap_edit_edge_map"); @@ -553,8 +568,9 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMFace *origFace = faceMap[i]; if (scene->toolsettings->uv_flag & UV_SYNC_SELECTION) { - if (BM_elem_flag_test(origFace, BM_ELEM_HIDDEN)) + if (BM_elem_flag_test(origFace, BM_ELEM_HIDDEN)) { continue; + } } else { if (BM_elem_flag_test(origFace, BM_ELEM_HIDDEN) || @@ -678,8 +694,9 @@ static bool minimize_stretch_init(bContext *C, wmOperator *op) ms->lasttime = PIL_check_seconds_timer(); param_stretch_begin(ms->handle); - if (ms->blend != 0.0f) + if (ms->blend != 0.0f) { param_stretch_blend(ms->handle, ms->blend); + } op->customdata = ms; @@ -738,13 +755,16 @@ static void minimize_stretch_exit(bContext *C, wmOperator *op, bool cancel) ED_area_status_text(sa, NULL); ED_workspace_status_text(C, NULL); - if (ms->timer) + if (ms->timer) { WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), ms->timer); + } - if (cancel) + if (cancel) { param_flush_restore(ms->handle); - else + } + else { param_flush(ms->handle); + } param_stretch_end(ms->handle); param_delete(ms->handle); @@ -770,12 +790,14 @@ static int minimize_stretch_exec(bContext *C, wmOperator *op) { int i, iterations; - if (!minimize_stretch_init(C, op)) + if (!minimize_stretch_init(C, op)) { return OPERATOR_CANCELLED; + } iterations = RNA_int_get(op->ptr, "iterations"); - for (i = 0; i < iterations; i++) + for (i = 0; i < iterations; i++) { minimize_stretch_iteration(C, op, false); + } minimize_stretch_exit(C, op, false); return OPERATOR_FINISHED; @@ -785,8 +807,9 @@ static int minimize_stretch_invoke(bContext *C, wmOperator *op, const wmEvent *U { MinStretch *ms; - if (!minimize_stretch_init(C, op)) + if (!minimize_stretch_init(C, op)) { return OPERATOR_CANCELLED; + } minimize_stretch_iteration(C, op, true); @@ -964,10 +987,12 @@ static int pack_islands_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - if (RNA_struct_property_is_set(op->ptr, "margin")) + if (RNA_struct_property_is_set(op->ptr, "margin")) { scene->toolsettings->uvcalc_margin = RNA_float_get(op->ptr, "margin"); - else + } + else { RNA_float_set(op->ptr, "margin", scene->toolsettings->uvcalc_margin); + } uvedit_pack_islands_multi(scene, objects, objects_len, &options, rotate, ignore_pinned); @@ -1081,10 +1106,12 @@ void ED_uvedit_live_unwrap_begin(Scene *scene, Object *obedit) .correct_aspect = (scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT) == 0, }; - if (use_subsurf) + if (use_subsurf) { handle = construct_param_handle_subsurfed(scene, obedit, em, &options); - else + } + else { handle = construct_param_handle(scene, obedit, em->bm, &options); + } param_lscm_begin(handle, PARAM_TRUE, abf); @@ -1119,8 +1146,9 @@ void ED_uvedit_live_unwrap_end(short cancel) if (g_live_unwrap.handles) { for (int i = 0; i < g_live_unwrap.len; i++) { param_lscm_end(g_live_unwrap.handles[i]); - if (cancel) + if (cancel) { param_flush_restore(g_live_unwrap.handles[i]); + } param_delete(g_live_unwrap.handles[i]); } MEM_freeN(g_live_unwrap.handles); @@ -1232,10 +1260,12 @@ static void uv_map_rotation_matrix_ex(float result[4][4], float sideangle = 0.0f, upangle = 0.0f; /* get rotation of the current view matrix */ - if (rv3d) + if (rv3d) { copy_m4_m4(viewmatrix, rv3d->viewmat); - else + } + else { unit_m4(viewmatrix); + } /* but shifting */ copy_v4_fl(viewmatrix[3], 0.0f); @@ -1300,17 +1330,21 @@ static void uv_map_transform(bContext *C, wmOperator *op, float rotmat[4][4]) } else { upangledeg = 0.0f; - if (align == POLAR_ZY) + if (align == POLAR_ZY) { sideangledeg = 0.0f; - else + } + else { sideangledeg = 90.0f; + } } /* be compatible to the "old" sphere/cylinder mode */ - if (direction == ALIGN_TO_OBJECT) + if (direction == ALIGN_TO_OBJECT) { unit_m4(rotmat); - else + } + else { uv_map_rotation_matrix(rotmat, rv3d, obedit, upangledeg, sideangledeg, radius); + } } static void uv_transform_properties(wmOperatorType *ot, int radius) @@ -1343,7 +1377,7 @@ static void uv_transform_properties(wmOperatorType *ot, int radius) VIEW_ON_EQUATOR, "Align", "How to determine rotation around the pole"); - if (radius) + if (radius) { RNA_def_float(ot->srna, "radius", 1.0f, @@ -1353,6 +1387,7 @@ static void uv_transform_properties(wmOperatorType *ot, int radius) "Radius of the sphere or cylinder", 0.0001f, 100.0f); + } } static void correct_uv_aspect(Scene *scene, Object *ob, BMEditMesh *em) @@ -1367,15 +1402,17 @@ static void correct_uv_aspect(Scene *scene, Object *ob, BMEditMesh *em) ED_uvedit_get_aspect(scene, ob, em->bm, &aspx, &aspy); - if (aspx == aspy) + if (aspx == aspy) { return; + } if (aspx > aspy) { scale = aspy / aspx; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1387,8 +1424,9 @@ static void correct_uv_aspect(Scene *scene, Object *ob, BMEditMesh *em) scale = aspx / aspy; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1442,14 +1480,16 @@ static void uv_map_clip_correct_multi(Scene *scene, const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); /* correct for image aspect ratio */ - if (correct_aspect) + if (correct_aspect) { correct_uv_aspect(scene, ob, em); + } if (scale_to_bounds) { /* find uv limits */ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1460,8 +1500,9 @@ static void uv_map_clip_correct_multi(Scene *scene, else if (clip_to_bounds) { /* clipping and wrapping */ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1477,10 +1518,12 @@ static void uv_map_clip_correct_multi(Scene *scene, dx = (max[0] - min[0]); dy = (max[1] - min[1]); - if (dx > 0.0f) + if (dx > 0.0f) { dx = 1.0f / dx; - if (dy > 0.0f) + } + if (dy > 0.0f) { dy = 1.0f / dy; + } for (uint ob_index = 0; ob_index < objects_len; ob_index++) { Object *ob = objects[ob_index]; @@ -1489,8 +1532,9 @@ static void uv_map_clip_correct_multi(Scene *scene, const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1522,10 +1566,12 @@ static void uvedit_unwrap(Scene *scene, Object *obedit, const UnwrapOptions *opt modifier_unwrap_state(obedit, scene, &use_subsurf); ParamHandle *handle; - if (use_subsurf) + if (use_subsurf) { handle = construct_param_handle_subsurfed(scene, obedit, em, options); - else + } + else { handle = construct_param_handle(scene, obedit, em->bm, options); + } param_lscm_begin(handle, PARAM_FALSE, scene->toolsettings->unwrapper == 0); param_lscm_solve(handle); @@ -1655,31 +1701,41 @@ static int unwrap_exec(bContext *C, wmOperator *op) } /* remember last method for live unwrap */ - if (RNA_struct_property_is_set(op->ptr, "method")) + if (RNA_struct_property_is_set(op->ptr, "method")) { scene->toolsettings->unwrapper = method; - else + } + else { RNA_enum_set(op->ptr, "method", scene->toolsettings->unwrapper); + } /* remember packing margin */ - if (RNA_struct_property_is_set(op->ptr, "margin")) + if (RNA_struct_property_is_set(op->ptr, "margin")) { scene->toolsettings->uvcalc_margin = RNA_float_get(op->ptr, "margin"); - else + } + else { RNA_float_set(op->ptr, "margin", scene->toolsettings->uvcalc_margin); + } - if (options.fill_holes) + if (options.fill_holes) { scene->toolsettings->uvcalc_flag |= UVCALC_FILLHOLES; - else + } + else { scene->toolsettings->uvcalc_flag &= ~UVCALC_FILLHOLES; + } - if (options.correct_aspect) + if (options.correct_aspect) { scene->toolsettings->uvcalc_flag &= ~UVCALC_NO_ASPECT_CORRECT; - else + } + else { scene->toolsettings->uvcalc_flag |= UVCALC_NO_ASPECT_CORRECT; + } - if (use_subsurf) + if (use_subsurf) { scene->toolsettings->uvcalc_flag |= UVCALC_USESUBSURF; - else + } + else { scene->toolsettings->uvcalc_flag &= ~UVCALC_USESUBSURF; + } /* execute unwrap */ uvedit_unwrap_multi(scene, objects, objects_len, &options); @@ -1748,11 +1804,13 @@ static int uv_from_view_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE PropertyRNA *prop; prop = RNA_struct_find_property(op->ptr, "camera_bounds"); - if (!RNA_property_is_set(op->ptr, prop)) + if (!RNA_property_is_set(op->ptr, prop)) { RNA_property_boolean_set(op->ptr, prop, (camera != NULL)); + } prop = RNA_struct_find_property(op->ptr, "correct_aspect"); - if (!RNA_property_is_set(op->ptr, prop)) + if (!RNA_property_is_set(op->ptr, prop)) { RNA_property_boolean_set(op->ptr, prop, (camera == NULL)); + } return uv_from_view_exec(C, op); } @@ -1808,8 +1866,9 @@ static int uv_from_view_exec(bContext *C, wmOperator *op) uv_map_rotation_matrix_ex(rotmat, rv3d, obedit, 90.0f, 0.0f, 1.0f, objects_pos_offset); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1828,8 +1887,9 @@ static int uv_from_view_exec(bContext *C, wmOperator *op) if (uci) { BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1845,8 +1905,9 @@ static int uv_from_view_exec(bContext *C, wmOperator *op) copy_m4_m4(rotmat, obedit->obmat); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -1886,8 +1947,9 @@ static bool uv_from_view_poll(bContext *C) { RegionView3D *rv3d = CTX_wm_region_view3d(C); - if (!ED_operator_uvmap(C)) + if (!ED_operator_uvmap(C)) { return 0; + } return (rv3d != NULL); } @@ -1980,8 +2042,9 @@ static void uv_sphere_project(float target[2], map_to_sphere(&target[0], &target[1], pv[0], pv[1], pv[2]); /* split line is always zero */ - if (target[0] >= 1.0f) + if (target[0] >= 1.0f) { target[0] -= 1.0f; + } } static void uv_map_mirror(BMEditMesh *em, BMFace *efa) @@ -2001,15 +2064,18 @@ static void uv_map_mirror(BMEditMesh *em, BMFace *efa) } mi = 0; - for (i = 1; i < efa->len; i++) - if (uvs[i][0] > uvs[mi][0]) + for (i = 1; i < efa->len; i++) { + if (uvs[i][0] > uvs[mi][0]) { mi = i; + } + } for (i = 0; i < efa->len; i++) { if (i != mi) { dx = uvs[mi][0] - uvs[i][0]; - if (dx > 0.5f) + if (dx > 0.5f) { uvs[i][0] += 1.0f; + } } } } @@ -2047,8 +2113,9 @@ static int sphere_project_exec(bContext *C, wmOperator *op) uv_map_transform_center(scene, v3d, obedit, em, center, NULL); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -2102,8 +2169,9 @@ static void uv_cylinder_project(float target[2], map_to_tube(&target[0], &target[1], pv[0], pv[1], pv[2]); /* split line is always zero */ - if (target[0] >= 1.0f) + if (target[0] >= 1.0f) { target[0] -= 1.0f; + } } static int cylinder_project_exec(bContext *C, wmOperator *op) @@ -2139,8 +2207,9 @@ static int cylinder_project_exec(bContext *C, wmOperator *op) uv_map_transform_center(scene, v3d, obedit, em, center, NULL); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); @@ -2209,8 +2278,9 @@ static void uvedit_unwrap_cube_project(BMesh *bm, BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { /* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */ - if (use_select && !BM_elem_flag_test(efa, BM_ELEM_SELECT)) + if (use_select && !BM_elem_flag_test(efa, BM_ELEM_SELECT)) { continue; + } axis_dominant_v3(&cox, &coy, efa->no); @@ -2340,6 +2410,7 @@ void ED_uvedit_add_simple_uvs(Main *bmain, Scene *scene, Object *ob) BM_mesh_bm_to_me(bmain, bm, me, (&(struct BMeshToMeshParams){0})); BM_mesh_free(bm); - if (sync_selection) + if (sync_selection) { scene->toolsettings->uv_flag |= UV_SYNC_SELECTION; + } } |