Commit: afa59d100a043e17e22fab5abb4376bc5efda7e2
Author: Phil Gosch
Date:   Wed May 4 23:15:34 2016 +0200
Branches: soc-2016-uv_tools
https://developer.blender.org/rBafa59d100a043e17e22fab5abb4376bc5efda7e2

Added "Pack islands" option to Unwrap operator, to give artists the possibility 
to not automatically pack after unwrapping

===================================================================

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
M       source/blender/makesdna/DNA_scene_types.h

===================================================================

diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c 
b/source/blender/editors/uvedit/uvedit_parametrizer.c
index 59f9cd1..45c0649 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -4657,6 +4657,52 @@ void param_scale(ParamHandle *handle, float x, float y)
        }
 }
 
+void param_scale_bounds(ParamHandle *handle)
+{
+       PHandle *phandle = (PHandle *)handle;
+       PChart *chart;
+       int i;
+       
+       for (i = 0; i < phandle->ncharts; i++) {
+               chart = phandle->charts[i];
+               
+               float tot_width, tot_height, scale;
+               float minv[2], maxv[2], trans[2];
+               
+               /* Compute bounds of chart */
+               p_chart_uv_bbox(chart, minv, maxv);
+               
+               /* Move center to 0,0 */
+               trans[0] = (minv[0] + maxv[0]) / -2.0f;
+               trans[1] = (minv[1] + maxv[1]) / -2.0f;
+               p_chart_uv_translate(chart, trans);
+               
+               /* Compute width/height of bounds */
+               if (signf(minv[0]) != signf(maxv[0]))
+                       tot_width = fabsf(minv[0]) + fabsf(maxv[0]);
+               else
+                       tot_width = maxv[0] - minv[0];
+               
+               if (signf(minv[1]) != signf(maxv[1]))
+                       tot_height = fabsf(minv[1]) + fabsf(maxv[1]);
+               else
+                       tot_height = maxv[1] - minv[1];
+               
+               if (tot_height > tot_width)
+                       scale = 1.0f / tot_height;
+               else
+                       scale = 1.0f / tot_width;
+               
+               /* Scale to fit UV area */
+               p_chart_uv_scale(chart, scale);
+               
+               /* Move chart to center of UV Space*/
+               trans[0] = 0.5f;
+               trans[1] = 0.5f;
+               p_chart_uv_translate(chart, trans);
+       }
+}
+
 void param_flush(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 eaea781..efbaae7 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.h
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.h
@@ -109,6 +109,10 @@ void param_average(ParamHandle *handle);
 
 void param_scale(ParamHandle *handle, float x, float y);
 
+/* Scale to bounds */
+
+void param_scale_bounds(ParamHandle *handle);
+
 /* Flushing */
 
 void param_flush(ParamHandle *handle);
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c 
b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 8e4ba4c..1d16146 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -1146,6 +1146,7 @@ void ED_unwrap_lscm(Scene *scene, Object *obedit, const 
short sel)
 
        const bool fill_holes = (scene->toolsettings->uvcalc_flag & 
UVCALC_FILLHOLES) != 0;
        const bool correct_aspect = (scene->toolsettings->uvcalc_flag & 
UVCALC_NO_ASPECT_CORRECT) == 0;
+       const bool pack_islands = (scene->toolsettings->uvcalc_flag & 
UVCALC_PACKISLANDS) != 0;
        bool use_subsurf;
 
        modifier_unwrap_state(obedit, scene, &use_subsurf);
@@ -1160,7 +1161,10 @@ void ED_unwrap_lscm(Scene *scene, Object *obedit, const 
short sel)
        param_lscm_end(handle);
 
        param_average(handle);
-       param_pack(handle, scene->toolsettings->uvcalc_margin, false);
+       if (pack_islands)
+               param_pack(handle, scene->toolsettings->uvcalc_margin, false);
+       else
+               param_scale_bounds(handle);
 
        param_flush(handle);
 
@@ -1175,6 +1179,7 @@ static int unwrap_exec(bContext *C, wmOperator *op)
        int method = RNA_enum_get(op->ptr, "method");
        const bool fill_holes = RNA_boolean_get(op->ptr, "fill_holes");
        const bool correct_aspect = RNA_boolean_get(op->ptr, "correct_aspect");
+       const bool pack_islands = RNA_boolean_get(op->ptr, "pack_islands");
        const bool use_subsurf = RNA_boolean_get(op->ptr, "use_subsurf_data");
        bool use_subsurf_final;
        float obsize[3];
@@ -1215,6 +1220,9 @@ static int unwrap_exec(bContext *C, wmOperator *op)
        if (correct_aspect) scene->toolsettings->uvcalc_flag &= 
~UVCALC_NO_ASPECT_CORRECT;
        else scene->toolsettings->uvcalc_flag |=  UVCALC_NO_ASPECT_CORRECT;
 
+       if (pack_islands) scene->toolsettings->uvcalc_flag |= 
UVCALC_PACKISLANDS;
+       else scene->toolsettings->uvcalc_flag &= ~UVCALC_PACKISLANDS;
+
        if (use_subsurf) scene->toolsettings->uvcalc_flag |= UVCALC_USESUBSURF;
        else scene->toolsettings->uvcalc_flag &= ~UVCALC_USESUBSURF;
 
@@ -1258,6 +1266,8 @@ void UV_OT_unwrap(wmOperatorType *ot)
                        "Virtual fill holes in mesh before unwrapping, to 
better avoid overlaps and preserve symmetry");
        RNA_def_boolean(ot->srna, "correct_aspect", 1, "Correct Aspect",
                        "Map UVs taking image aspect ratio into account");
+       RNA_def_boolean(ot->srna, "pack_islands", 1, "Pack Islands",
+                                       "Pack UV islands after unwrapping");
        RNA_def_boolean(ot->srna, "use_subsurf_data", 0, "Use Subsurf Modifier",
                        "Map UVs taking vertex position after subsurf into 
account");
        RNA_def_float_factor(ot->srna, "margin", 0.001f, 0.0f, 1.0f, "Margin", 
"Space between islands", 0.0f, 1.0f);
diff --git a/source/blender/makesdna/DNA_scene_types.h 
b/source/blender/makesdna/DNA_scene_types.h
index 1bf044f..1f9b52c 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -2040,6 +2040,7 @@ typedef enum ImagePaintMode {
 #define UVCALC_NO_ASPECT_CORRECT       2       /* would call this 
UVCALC_ASPECT_CORRECT, except it should be default with old file */
 #define UVCALC_TRANSFORM_CORRECT       4       /* adjust UV's while 
transforming to avoid distortion */
 #define UVCALC_USESUBSURF                      8       /* Use mesh data after 
subsurf to compute UVs*/
+#define UVCALC_PACKISLANDS                     16      /* Pack Islands after 
unwrapping*/
 
 /* toolsettings->uv_flag */
 #define UV_SYNC_SELECTION      1

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to