Cleanup: Rearrange transform_convert_mesh into doxy sections

This commit is contained in:
Germano Cavalcante 2020-06-20 12:14:25 -03:00
parent 3752c44b44
commit 2d866d77ae
1 changed files with 186 additions and 166 deletions

View File

@ -53,7 +53,11 @@
/* Used for both mirror epsilon and TD_MIRROR_EDGE_ */
#define TRANSFORM_MAXDIST_MIRROR 0.00002f
/* when transforming islands */
/* -------------------------------------------------------------------- */
/** \name Island Creation
*
* \{ */
struct TransIslandData {
float (*center)[3];
float (*axismtx)[3][3];
@ -61,8 +65,176 @@ struct TransIslandData {
int *island_vert_map;
};
static void editmesh_islands_info_calc(BMEditMesh *em,
const bool calc_single_islands,
const bool calc_island_axismtx,
struct TransIslandData *r_island_data)
{
BMesh *bm = em->bm;
char htype;
char itype;
int i;
/* group vars */
float(*center)[3];
float(*axismtx)[3][3] = NULL;
int *groups_array;
int(*group_index)[2];
int group_tot;
void **ele_array;
int *vert_map;
if (em->selectmode & (SCE_SELECT_VERTEX | SCE_SELECT_EDGE)) {
groups_array = MEM_mallocN(sizeof(*groups_array) * bm->totedgesel, __func__);
group_tot = BM_mesh_calc_edge_groups(
bm, groups_array, &group_index, NULL, NULL, BM_ELEM_SELECT);
htype = BM_EDGE;
itype = BM_VERTS_OF_EDGE;
}
else { /* (bm->selectmode & SCE_SELECT_FACE) */
groups_array = MEM_mallocN(sizeof(*groups_array) * bm->totfacesel, __func__);
group_tot = BM_mesh_calc_face_groups(
bm, groups_array, &group_index, NULL, NULL, BM_ELEM_SELECT, BM_VERT);
htype = BM_FACE;
itype = BM_VERTS_OF_FACE;
}
center = MEM_mallocN(sizeof(*center) * group_tot, __func__);
if (calc_island_axismtx) {
axismtx = MEM_mallocN(sizeof(*axismtx) * group_tot, __func__);
}
vert_map = MEM_mallocN(sizeof(*vert_map) * bm->totvert, __func__);
/* we shouldn't need this, but with incorrect selection flushing
* its possible we have a selected vertex that's not in a face,
* for now best not crash in that case. */
copy_vn_i(vert_map, bm->totvert, -1);
BM_mesh_elem_table_ensure(bm, htype);
ele_array = (htype == BM_FACE) ? (void **)bm->ftable : (void **)bm->etable;
BM_mesh_elem_index_ensure(bm, BM_VERT);
/* may be an edge OR a face array */
for (i = 0; i < group_tot; i++) {
BMEditSelection ese = {NULL};
const int fg_sta = group_index[i][0];
const int fg_len = group_index[i][1];
float co[3], no[3], tangent[3];
int j;
zero_v3(co);
zero_v3(no);
zero_v3(tangent);
ese.htype = htype;
/* loop on each face or edge in this group:
* - assign r_vert_map
* - calculate (co, no)
*/
for (j = 0; j < fg_len; j++) {
float tmp_co[3], tmp_no[3], tmp_tangent[3];
ese.ele = ele_array[groups_array[fg_sta + j]];
BM_editselection_center(&ese, tmp_co);
add_v3_v3(co, tmp_co);
if (axismtx) {
BM_editselection_normal(&ese, tmp_no);
BM_editselection_plane(&ese, tmp_tangent);
add_v3_v3(no, tmp_no);
add_v3_v3(tangent, tmp_tangent);
}
{
/* setup vertex map */
BMIter iter;
BMVert *v;
/* connected edge-verts */
BM_ITER_ELEM (v, &iter, ese.ele, itype) {
vert_map[BM_elem_index_get(v)] = i;
}
}
}
mul_v3_v3fl(center[i], co, 1.0f / (float)fg_len);
if (axismtx) {
if (createSpaceNormalTangent(axismtx[i], no, tangent)) {
/* pass */
}
else {
if (normalize_v3(no) != 0.0f) {
axis_dominant_v3_to_m3(axismtx[i], no);
invert_m3(axismtx[i]);
}
else {
unit_m3(axismtx[i]);
}
}
}
}
MEM_freeN(groups_array);
MEM_freeN(group_index);
/* for PET we need islands of 1 so connected vertices can use it with V3D_AROUND_LOCAL_ORIGINS */
if (calc_single_islands) {
BMIter viter;
BMVert *v;
int group_tot_single = 0;
BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, i) {
if (BM_elem_flag_test(v, BM_ELEM_SELECT) && (vert_map[i] == -1)) {
group_tot_single += 1;
}
}
if (group_tot_single != 0) {
center = MEM_reallocN(center, sizeof(*center) * (group_tot + group_tot_single));
if (axismtx) {
axismtx = MEM_reallocN(axismtx, sizeof(*axismtx) * (group_tot + group_tot_single));
}
BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, i) {
if (BM_elem_flag_test(v, BM_ELEM_SELECT) && (vert_map[i] == -1)) {
vert_map[i] = group_tot;
copy_v3_v3(center[group_tot], v->co);
if (axismtx) {
if (is_zero_v3(v->no) != 0.0f) {
axis_dominant_v3_to_m3(axismtx[group_tot], v->no);
invert_m3(axismtx[group_tot]);
}
else {
unit_m3(axismtx[group_tot]);
}
}
group_tot += 1;
}
}
}
}
r_island_data->axismtx = axismtx;
r_island_data->center = center;
r_island_data->island_tot = group_tot;
r_island_data->island_vert_map = vert_map;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Edit Mesh Verts Transform Creation
/** \name Connectivity Distance for Proportional Editing
*
* \{ */
@ -243,171 +415,12 @@ static void editmesh_set_connectivity_distance(BMesh *bm,
}
}
static void editmesh_islands_info_calc(BMEditMesh *em,
const bool calc_single_islands,
const bool calc_island_axismtx,
struct TransIslandData *r_island_data)
{
BMesh *bm = em->bm;
char htype;
char itype;
int i;
/** \} */
/* group vars */
float(*center)[3];
float(*axismtx)[3][3] = NULL;
int *groups_array;
int(*group_index)[2];
int group_tot;
void **ele_array;
int *vert_map;
if (em->selectmode & (SCE_SELECT_VERTEX | SCE_SELECT_EDGE)) {
groups_array = MEM_mallocN(sizeof(*groups_array) * bm->totedgesel, __func__);
group_tot = BM_mesh_calc_edge_groups(
bm, groups_array, &group_index, NULL, NULL, BM_ELEM_SELECT);
htype = BM_EDGE;
itype = BM_VERTS_OF_EDGE;
}
else { /* (bm->selectmode & SCE_SELECT_FACE) */
groups_array = MEM_mallocN(sizeof(*groups_array) * bm->totfacesel, __func__);
group_tot = BM_mesh_calc_face_groups(
bm, groups_array, &group_index, NULL, NULL, BM_ELEM_SELECT, BM_VERT);
htype = BM_FACE;
itype = BM_VERTS_OF_FACE;
}
center = MEM_mallocN(sizeof(*center) * group_tot, __func__);
if (calc_island_axismtx) {
axismtx = MEM_mallocN(sizeof(*axismtx) * group_tot, __func__);
}
vert_map = MEM_mallocN(sizeof(*vert_map) * bm->totvert, __func__);
/* we shouldn't need this, but with incorrect selection flushing
* its possible we have a selected vertex that's not in a face,
* for now best not crash in that case. */
copy_vn_i(vert_map, bm->totvert, -1);
BM_mesh_elem_table_ensure(bm, htype);
ele_array = (htype == BM_FACE) ? (void **)bm->ftable : (void **)bm->etable;
BM_mesh_elem_index_ensure(bm, BM_VERT);
/* may be an edge OR a face array */
for (i = 0; i < group_tot; i++) {
BMEditSelection ese = {NULL};
const int fg_sta = group_index[i][0];
const int fg_len = group_index[i][1];
float co[3], no[3], tangent[3];
int j;
zero_v3(co);
zero_v3(no);
zero_v3(tangent);
ese.htype = htype;
/* loop on each face or edge in this group:
* - assign r_vert_map
* - calculate (co, no)
*/
for (j = 0; j < fg_len; j++) {
float tmp_co[3], tmp_no[3], tmp_tangent[3];
ese.ele = ele_array[groups_array[fg_sta + j]];
BM_editselection_center(&ese, tmp_co);
add_v3_v3(co, tmp_co);
if (axismtx) {
BM_editselection_normal(&ese, tmp_no);
BM_editselection_plane(&ese, tmp_tangent);
add_v3_v3(no, tmp_no);
add_v3_v3(tangent, tmp_tangent);
}
{
/* setup vertex map */
BMIter iter;
BMVert *v;
/* connected edge-verts */
BM_ITER_ELEM (v, &iter, ese.ele, itype) {
vert_map[BM_elem_index_get(v)] = i;
}
}
}
mul_v3_v3fl(center[i], co, 1.0f / (float)fg_len);
if (axismtx) {
if (createSpaceNormalTangent(axismtx[i], no, tangent)) {
/* pass */
}
else {
if (normalize_v3(no) != 0.0f) {
axis_dominant_v3_to_m3(axismtx[i], no);
invert_m3(axismtx[i]);
}
else {
unit_m3(axismtx[i]);
}
}
}
}
MEM_freeN(groups_array);
MEM_freeN(group_index);
/* for PET we need islands of 1 so connected vertices can use it with V3D_AROUND_LOCAL_ORIGINS */
if (calc_single_islands) {
BMIter viter;
BMVert *v;
int group_tot_single = 0;
BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, i) {
if (BM_elem_flag_test(v, BM_ELEM_SELECT) && (vert_map[i] == -1)) {
group_tot_single += 1;
}
}
if (group_tot_single != 0) {
center = MEM_reallocN(center, sizeof(*center) * (group_tot + group_tot_single));
if (axismtx) {
axismtx = MEM_reallocN(axismtx, sizeof(*axismtx) * (group_tot + group_tot_single));
}
BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, i) {
if (BM_elem_flag_test(v, BM_ELEM_SELECT) && (vert_map[i] == -1)) {
vert_map[i] = group_tot;
copy_v3_v3(center[group_tot], v->co);
if (axismtx) {
if (is_zero_v3(v->no) != 0.0f) {
axis_dominant_v3_to_m3(axismtx[group_tot], v->no);
invert_m3(axismtx[group_tot]);
}
else {
unit_m3(axismtx[group_tot]);
}
}
group_tot += 1;
}
}
}
}
r_island_data->axismtx = axismtx;
r_island_data->center = center;
r_island_data->island_tot = group_tot;
r_island_data->island_vert_map = vert_map;
}
/* -------------------------------------------------------------------- */
/** \name TransDataMirror Creation
*
* \{ */
static bool is_in_quadrant_v3(const float co[3], const int quadrant[3], const float epsilon)
{
@ -582,6 +595,13 @@ static TransDataMirror *editmesh_mirror_data_calc(BMEditMesh *em,
return td_mirror;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Edit Mesh Verts Transform Creation
*
* \{ */
static void transdata_center_get(const struct TransIslandData *island_data,
const int island_index,
const bool no_island_center,