Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-04-17 10:21:49 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-17 10:21:49 +0400
commitaed9f92734b043ac686ffc10c3374b4cd5ce3153 (patch)
treeaea9c50c21ec62eb5de548285f3de919ac49cdd1 /source
parent0cda4903b1a6f8a94e45fef9847c5b3a5fe56890 (diff)
packing from the UV window with margin had a problem with feedback, so running again and again would give different results.
Scale the margin by the combined area of all boxes to give predictable results.
Diffstat (limited to 'source')
-rw-r--r--source/blender/src/parametrizer.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/source/blender/src/parametrizer.c b/source/blender/src/parametrizer.c
index 654113f5f0c..feb774b604a 100644
--- a/source/blender/src/parametrizer.c
+++ b/source/blender/src/parametrizer.c
@@ -4134,6 +4134,7 @@ void param_pack(ParamHandle *handle, float margin)
PChart *chart;
int i, unpacked=0;
float trans[2];
+ double area= 0.0;
PHandle *phandle = (PHandle*)handle;
@@ -4146,6 +4147,7 @@ void param_pack(ParamHandle *handle, float margin)
/* we may not use all these boxes */
boxarray = MEM_mallocN( phandle->ncharts*sizeof(boxPack), "boxPack box");
+
for (i = 0; i < phandle->ncharts; i++) {
chart = phandle->charts[i];
@@ -4158,14 +4160,40 @@ void param_pack(ParamHandle *handle, float margin)
p_chart_uv_bbox(chart, trans, chart->u.pack.size);
- trans[0] = -(trans[0] - margin);
- trans[1] = -(trans[1] - margin);
+ trans[0] = -trans[0];
+ trans[1] = -trans[1];
p_chart_uv_translate(chart, trans);
- box->w = (chart->u.pack.size[0] + trans[0]) + margin*2;
- box->h = (chart->u.pack.size[1] + trans[1]) + margin*2;
+ box->w = chart->u.pack.size[0] + trans[0];
+ box->h = chart->u.pack.size[1] + trans[1];
box->index = i; /* warning this index skips PCHART_NOPACK boxes */
+
+ if(margin>0.0f)
+ area += sqrt(box->w*box->h);
+ }
+
+ if(margin>0.0f) {
+ /* multiply the margin by the area to give pradictable results not dependant on UV scale,
+ * ...Without using the area running pack multiple times also gives a bad feedback loop.
+ * multiply by 0.1 so the margin value from the UI can be from 0.0 to 1.0 but not give a massive margin */
+ margin = (margin*(float)area) * 0.1;
+ unpacked= 0;
+ for (i = 0; i < phandle->ncharts; i++) {
+ chart = phandle->charts[i];
+
+ if (chart->flag & PCHART_NOPACK) {
+ unpacked++;
+ continue;
+ }
+
+ box = boxarray+(i-unpacked);
+ trans[0] = margin * area;
+ trans[1] = margin * area;
+ p_chart_uv_translate(chart, trans);
+ box->w += (margin * area) *2;
+ box->h += (margin * area) *2;
+ }
}
boxPack2D(boxarray, phandle->ncharts-unpacked, &tot_width, &tot_height);