[Bf-blender-cvs] [901f02b8ec0] uv_unwrapping_slim_algorithm: UV Unwrapping SLIM: removing remainder of old minimize stretch
Aurel Gruber
noreply at git.blender.org
Tue Mar 14 09:43:29 CET 2017
Commit: 901f02b8ec0bf991fa02b3f0a76e78b81063c032
Author: Aurel Gruber
Date: Fri Mar 10 08:55:29 2017 +0100
Branches: uv_unwrapping_slim_algorithm
https://developer.blender.org/rB901f02b8ec0bf991fa02b3f0a76e78b81063c032
UV Unwrapping SLIM: removing remainder of old minimize stretch
===================================================================
M source/blender/editors/uvedit/uvedit_parametrizer.c
M source/blender/editors/uvedit/uvedit_parametrizer.h
M source/blender/editors/uvedit/uvedit_unwrap_ops.c
===================================================================
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c
index 87a87797f21..17799ae6e07 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -3245,152 +3245,6 @@ static void p_chart_lscm_end(PChart *chart)
chart->u.lscm.pin2 = NULL;
}
-/* Stretch */
-
-#define P_STRETCH_ITER 20
-
-static void p_stretch_pin_boundary(PChart *chart)
-{
- PVert *v;
-
- for (v = chart->verts; v; v = v->nextlink)
- if (v->edge->pair == NULL)
- v->flag |= PVERT_PIN;
- else
- v->flag &= ~PVERT_PIN;
-}
-
-static float p_face_stretch(PFace *f)
-{
- float T, w, tmp[3];
- float Ps[3], Pt[3];
- float a, c, area;
- PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next;
- PVert *v1 = e1->vert, *v2 = e2->vert, *v3 = e3->vert;
-
- area = p_face_uv_area_signed(f);
-
- if (area <= 0.0f) /* flipped face -> infinite stretch */
- return 1e10f;
-
- w = 1.0f / (2.0f * area);
-
- /* compute derivatives */
- copy_v3_v3(Ps, v1->co);
- mul_v3_fl(Ps, (v2->uv[1] - v3->uv[1]));
-
- copy_v3_v3(tmp, v2->co);
- mul_v3_fl(tmp, (v3->uv[1] - v1->uv[1]));
- add_v3_v3(Ps, tmp);
-
- copy_v3_v3(tmp, v3->co);
- mul_v3_fl(tmp, (v1->uv[1] - v2->uv[1]));
- add_v3_v3(Ps, tmp);
-
- mul_v3_fl(Ps, w);
-
- copy_v3_v3(Pt, v1->co);
- mul_v3_fl(Pt, (v3->uv[0] - v2->uv[0]));
-
- copy_v3_v3(tmp, v2->co);
- mul_v3_fl(tmp, (v1->uv[0] - v3->uv[0]));
- add_v3_v3(Pt, tmp);
-
- copy_v3_v3(tmp, v3->co);
- mul_v3_fl(tmp, (v2->uv[0] - v1->uv[0]));
- add_v3_v3(Pt, tmp);
-
- mul_v3_fl(Pt, w);
-
- /* Sander Tensor */
- a = dot_v3v3(Ps, Ps);
- c = dot_v3v3(Pt, Pt);
-
- T = sqrtf(0.5f * (a + c));
- if (f->flag & PFACE_FILLED)
- T *= 0.2f;
-
- return T;
-}
-
-static float p_stretch_compute_vertex(PVert *v)
-{
- PEdge *e = v->edge;
- float sum = 0.0f;
-
- do {
- sum += p_face_stretch(e->face);
- e = p_wheel_edge_next(e);
- } while (e && e != (v->edge));
-
- return sum;
-}
-
-static void p_chart_stretch_minimize(PChart *chart, RNG *rng)
-{
- PVert *v;
- PEdge *e;
- int j, nedges;
- float orig_stretch, low, stretch_low, high, stretch_high, mid, stretch;
- float orig_uv[2], dir[2], random_angle, trusted_radius;
-
- for (v = chart->verts; v; v = v->nextlink) {
- if ((v->flag & PVERT_PIN) || !(v->flag & PVERT_SELECT))
- continue;
-
- orig_stretch = p_stretch_compute_vertex(v);
- orig_uv[0] = v->uv[0];
- orig_uv[1] = v->uv[1];
-
- /* move vertex in a random direction */
- trusted_radius = 0.0f;
- nedges = 0;
- e = v->edge;
-
- do {
- trusted_radius += p_edge_uv_length(e);
- nedges++;
-
- e = p_wheel_edge_next(e);
- } while (e && e != (v->edge));
-
- trusted_radius /= 2 * nedges;
-
- random_angle = BLI_rng_get_float(rng) * 2.0f * (float)M_PI;
- dir[0] = trusted_radius * cosf(random_angle);
- dir[1] = trusted_radius * sinf(random_angle);
-
- /* calculate old and new stretch */
- low = 0;
- stretch_low = orig_stretch;
-
- add_v2_v2v2(v->uv, orig_uv, dir);
- high = 1;
- stretch = stretch_high = p_stretch_compute_vertex(v);
-
- /* binary search for lowest stretch position */
- for (j = 0; j < P_STRETCH_ITER; j++) {
- mid = 0.5f * (low + high);
- v->uv[0] = orig_uv[0] + mid * dir[0];
- v->uv[1] = orig_uv[1] + mid * dir[1];
- stretch = p_stretch_compute_vertex(v);
-
- if (stretch_low < stretch_high) {
- high = mid;
- stretch_high = stretch;
- }
- else {
- low = mid;
- stretch_low = stretch;
- }
- }
-
- /* no luck, stretch has increased, reset to old values */
- if (stretch >= orig_stretch)
- copy_v2_v2(v->uv, orig_uv);
- }
-}
-
/* Minimum area enclosing rectangle for packing */
static int p_compare_geometric_uv(const void *a, const void *b)
@@ -4346,19 +4200,6 @@ void param_construct_end(ParamHandle *handle, ParamBool fill, ParamBool impl)
phandle->state = PHANDLE_STATE_CONSTRUCTED;
}
-void add_index_to_vertices(BMEditMesh *em)
-{
-
- // iterate over bm edit mesh and set indices for weight retrieval,
- // This allows for later matching of vertices to weights.
- BMVert *vert;
- BMIter iter;
- int i;
- BM_ITER_MESH_INDEX(vert, &iter, em->bm, BM_VERTS_OF_MESH, i) {
- vert->id = i;
- }
-}
-
int retrieve_weightmap_index(Object *obedit, char *vertex_group)
{
return defgroup_name_index(obedit, vertex_group);
@@ -4497,57 +4338,6 @@ void param_lscm_end(ParamHandle *handle)
phandle->state = PHANDLE_STATE_CONSTRUCTED;
}
-void param_stretch_begin(ParamHandle *handle)
-{
- PHandle *phandle = (PHandle *)handle;
- PChart *chart;
- PVert *v;
- PFace *f;
- int i;
-
- param_assert(phandle->state == PHANDLE_STATE_CONSTRUCTED);
- phandle->state = PHANDLE_STATE_STRETCH;
-
- phandle->rng = BLI_rng_new(31415926);
- phandle->blend = 0.0f;
-
- for (i = 0; i < phandle->ncharts; i++) {
- chart = phandle->charts[i];
-
- for (v = chart->verts; v; v = v->nextlink)
- v->flag &= ~PVERT_PIN; /* don't use user-defined pins */
-
- p_stretch_pin_boundary(chart);
-
- for (f = chart->faces; f; f = f->nextlink) {
- p_face_backup_uvs(f);
- f->u.area3d = p_face_area(f);
- }
- }
-}
-
-void param_stretch_blend(ParamHandle *handle, float blend)
-{
- PHandle *phandle = (PHandle *)handle;
-
- param_assert(phandle->state == PHANDLE_STATE_STRETCH);
- phandle->blend = blend;
-}
-
-void param_stretch_iter(ParamHandle *handle)
-{
- PHandle *phandle = (PHandle *)handle;
- PChart *chart;
- int i;
-
- param_assert(phandle->state == PHANDLE_STATE_STRETCH);
-
- for (i = 0; i < phandle->ncharts; i++) {
- chart = phandle->charts[i];
- p_chart_stretch_minimize(chart, phandle->rng);
- }
-}
-
void param_stretch_end(ParamHandle *handle)
{
PHandle *phandle = (PHandle *)handle;
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.h b/source/blender/editors/uvedit/uvedit_parametrizer.h
index 9cb7d57ee54..f3781b79ec3 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.h
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.h
@@ -137,13 +137,6 @@ void param_lscm_begin(ParamHandle *handle, ParamBool live, ParamBool abf);
void param_lscm_solve(ParamHandle *handle);
void param_lscm_end(ParamHandle *handle);
-/* Stretch */
-
-void param_stretch_begin(ParamHandle *handle);
-void param_stretch_blend(ParamHandle *handle, float blend);
-void param_stretch_iter(ParamHandle *handle);
-void param_stretch_end(ParamHandle *handle);
-
/* Area Smooth */
void param_smooth_area(ParamHandle *handle);
@@ -171,7 +164,6 @@ void convert_blender_slim(ParamHandle *handle, bool selection_only, int weight_m
void set_uv_param_slim(ParamHandle *handle, SLIMMatrixTransfer *mt);
bool transformIslands(ParamHandle *handle);
bool mark_pins(ParamHandle *param_handle);
-void add_index_to_vertices(BMEditMesh *em);
void free_slim_matrix_transfer(SLIMMatrixTransfer *mt);
#ifdef __cplusplus
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index e94853a834e..f80d23117cd 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -568,7 +568,9 @@ static bool minimize_stretch_init(bContext *C, wmOperator *op)
Object *obedit = CTX_data_edit_object(C);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
- add_index_to_vertices(em);
+ if (!uvedit_have_selection(scene, em, true)) {
+ return false;
+ }
ParamHandle *handle = construct_param_handle(scene, obedit, em->bm, false, true, 1, 1);
@@ -1224,10 +1226,6 @@ void ED_unwrap_lscm(Scene *scene, Object *obedit, const short sel)
bool use_slim_method = (scene->toolsettings->unwrapper == 2);
- if(use_slim_method) {
- add_index_to_vertices(em);
- }
-
modifier_unwrap_state(obedit, scene, &use_subsurf);
if (use_subsurf)
More information about the Bf-blender-cvs
mailing list