[Bf-blender-cvs] [9015e4f] soc-2016-uv_tools: Added (initial) random rotation for uv islands

Phil Gosch noreply at git.blender.org
Wed Jul 20 17:57:32 CEST 2016


Commit: 9015e4f1f8e005f8468c69d594a57f989bc03f0b
Author: Phil Gosch
Date:   Wed Jul 20 17:57:05 2016 +0200
Branches: soc-2016-uv_tools
https://developer.blender.org/rB9015e4f1f8e005f8468c69d594a57f989bc03f0b

Added (initial) random rotation for uv islands

This also introduces a new user-controllable operator parameter "rotation steps"

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

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 fa7f86d..2e95848 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -3806,9 +3806,8 @@ static float p_chart_minimum_area_angle(PChart *chart)
 	return minangle;
 }
 
-static void p_chart_rotate_minimum_area(PChart *chart)
+static void p_chart_rotate(PChart *chart, float angle)
 {
-	float angle = p_chart_minimum_area_angle(chart);
 	float sine = sinf(angle);
 	float cosine = cosf(angle);
 	PVert *v;
@@ -3820,6 +3819,12 @@ static void p_chart_rotate_minimum_area(PChart *chart)
 	}
 }
 
+static void p_chart_rotate_minimum_area(PChart *chart)
+{
+	float angle = p_chart_minimum_area_angle(chart);
+	p_chart_rotate(chart, angle);
+}
+
 /* Area Smoothing */
 
 /* 2d bsp tree for inverse mapping - that's a bit silly */
@@ -5413,7 +5418,7 @@ bool p_compute_packing_solution(PHandle *phandle /* ToDo SaphireS: Simulated Ann
 	return true;
 }
 
-void param_irregular_pack_begin(ParamHandle *handle, float *w_area)
+void param_irregular_pack_begin(ParamHandle *handle, float *w_area, int rot_step)
 {
 	PHandle *phandle = (PHandle *)handle;
 	PChart *chart;
@@ -5421,7 +5426,7 @@ void param_irregular_pack_begin(ParamHandle *handle, float *w_area)
 	PFace *f;
 	int npoint, right, i, j;
 	unsigned int seed = 31415926;
-	float used_area, init_scale, init_value = 0.6f;
+	float used_area, init_scale, init_value = 0.6f, randf1, rot;
 
 	param_assert(phandle->state == PHANDLE_STATE_CONSTRUCTED);
 	phandle->state = PHANDLE_STATE_PACK;
@@ -5444,6 +5449,12 @@ void param_irregular_pack_begin(ParamHandle *handle, float *w_area)
 		/* ToDo: Do this in p_compute_packing_solution */
 		/*p_chart_uv_scale_origin(chart, init_scale); */
 
+		/* Initial random rotation */
+		randf1 = BLI_rng_get_float(phandle->rng);
+		rot = (int)(randf1 * (float)rot_step) * (2 * M_PI / (float)rot_step);
+		printf("init rot for chart[%i]: %f\n", i, rot);
+		p_chart_rotate(chart, rot);
+
 		/* Compute convex hull for each chart -> CW */
 		chart->u.ipack.convex_hull = p_convex_hull_new(chart);
 		chart->u.ipack.best_pos = MEM_callocN(sizeof(PPointUV), "PPointUV");
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.h b/source/blender/editors/uvedit/uvedit_parametrizer.h
index 0935a8d..bbee4e2 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.h
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.h
@@ -105,7 +105,7 @@ void param_pack(ParamHandle *handle, float margin, bool do_rotate);
 
 /* Packing 2.0 */
 
-void param_irregular_pack_begin(ParamHandle *handle);
+void param_irregular_pack_begin(ParamHandle *handle, float *w_area, int rot_step);
 void param_irregular_pack_iter(ParamHandle *handle, float *w_area, unsigned int seed);
 void param_irregular_pack_end(ParamHandle *handle);
 void param_store_packing_solution(ParamHandle *handle);
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 3fe85742..f4109e2 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -836,6 +836,7 @@ typedef struct SimulatedAnnealing {
 	float f;
 	float r;
 	float temperature;
+	int rot_steps;
 } SimulatedAnnealing;
 
 typedef struct PackIslands {
@@ -846,7 +847,7 @@ typedef struct PackIslands {
 	double lasttime;
 	int iter_global, iter_local, iter_max;
 	wmTimer *timer;
-	float wasted_area_last;
+	float wasted_area_last, margin;
 	SimulatedAnnealing *sa;
 } PackIslands;
 
@@ -858,7 +859,7 @@ static bool irregular_pack_islands_init(bContext *C, wmOperator *op)
 	PackIslands *pi;
 	SimulatedAnnealing *simann;
 	unsigned int seed = 31415926;
-	float wasted_area;
+	float wasted_area, rot_steps;
 
 	/* Keep for now, needed when making packing work with current selection */
 	/*if (!uvedit_have_selection(scene, em, implicit)) {
@@ -874,6 +875,7 @@ static bool irregular_pack_islands_init(bContext *C, wmOperator *op)
 	pi->iter_max = RNA_int_get(op->ptr, "iterations");
 	pi->iter_global = 0;
 	pi->iter_local = 0;
+	pi->margin = RNA_float_get(op->ptr, "margin");
 	pi->handle = construct_param_handle(scene, obedit, em->bm, hparams);
 	pi->lasttime = PIL_check_seconds_timer();
 
@@ -884,9 +886,10 @@ static bool irregular_pack_islands_init(bContext *C, wmOperator *op)
 	simann->f = 0.0f;
 	simann->r = 0.0f;
 	simann->temperature = 1.0f;
+	simann->rot_steps = RNA_int_get(op->ptr, "rotation_steps");
 	pi->sa = simann;
 
-	param_irregular_pack_begin(pi->handle, &wasted_area /* SA */);
+	param_irregular_pack_begin(pi->handle, &wasted_area, pi->sa->rot_steps /* SA */);
 	pi->wasted_area_last = wasted_area;
 
 	op->customdata = pi;
@@ -1079,6 +1082,8 @@ void UV_OT_irregular_pack_islands(wmOperatorType *ot)
 	ot->poll = ED_operator_uvedit;
 
 	/* properties */
+	RNA_def_float(ot->srna, "margin", 0.0f, 0.0f, 1.0f, "Margin", "Border Margin/Padding to apply per UV island", 0.0f, 1.0f);
+	RNA_def_int(ot->srna, "rotation_steps", 4, 0, 360, "Rotation Steps", "Allowed rotations to try during packing. (2=180�, 4=90�, etc.)", 0, 360);
 	RNA_def_int(ot->srna, "iterations", 0, 0, INT_MAX, "Iterations", "Number of iterations to run, 0 is unlimited when run interactively", 0, 10000);
 }




More information about the Bf-blender-cvs mailing list