[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43148] branches/soc-2011-onion-uv-tools/ source/blender: smart stitch
Antony Riakiotakis
kalast at gmail.com
Thu Jan 5 01:47:42 CET 2012
Revision: 43148
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43148
Author: psy-fi
Date: 2012-01-05 00:47:29 +0000 (Thu, 05 Jan 2012)
Log Message:
-----------
smart stitch
==============
-Add code to highlight static island in preview
-some more renames to keep line length manageable (though still too long in some cases)
-Midpoint snap off by default(Makes static island easier to understand)
Modified Paths:
--------------
branches/soc-2011-onion-uv-tools/source/blender/editors/include/UI_resources.h
branches/soc-2011-onion-uv-tools/source/blender/editors/interface/resources.c
branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_draw.c
branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_smart_stitch.c
branches/soc-2011-onion-uv-tools/source/blender/makesdna/DNA_userdef_types.h
Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/include/UI_resources.h
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/include/UI_resources.h 2012-01-04 22:59:12 UTC (rev 43147)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/include/UI_resources.h 2012-01-05 00:47:29 UTC (rev 43148)
@@ -262,6 +262,7 @@
TH_STITCH_PREVIEW_VERT,
TH_STITCH_PREVIEW_STITCHABLE,
TH_STITCH_PREVIEW_UNSTITCHABLE,
+ TH_STITCH_PREVIEW_ACTIVE
};
/* XXX WARNING: previous is saved in file, so do not change order! */
Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/interface/resources.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/interface/resources.c 2012-01-04 22:59:12 UTC (rev 43147)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/interface/resources.c 2012-01-05 00:47:29 UTC (rev 43148)
@@ -429,6 +429,9 @@
case TH_STITCH_PREVIEW_UNSTITCHABLE:
cp = ts->preview_stitch_unstitchable;
break;
+ case TH_STITCH_PREVIEW_ACTIVE:
+ cp = ts->preview_stitch_active;
+ break;
case TH_MARKER_OUTLINE:
cp= ts->marker_outline; break;
case TH_MARKER:
@@ -1711,6 +1714,7 @@
SETCOLF(btheme->tima.preview_stitch_vert, 0.0, 0.0, 1.0, 0.2);
SETCOLF(btheme->tima.preview_stitch_stitchable, 0.0, 1.0, 0.0, 1.0);
SETCOLF(btheme->tima.preview_stitch_unstitchable, 1.0, 0.0, 0.0, 1.0);
+ SETCOLF(btheme->tima.preview_stitch_active, 0.9, 0.9, 1.0, 0.2);
}
U.high_bit_depth_tex = 0;
}
Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_draw.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_draw.c 2012-01-04 22:59:12 UTC (rev 43147)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_draw.c 2012-01-05 00:47:29 UTC (rev 43148)
@@ -869,6 +869,14 @@
glEnable(GL_BLEND);
+ UI_ThemeColor4(TH_STITCH_PREVIEW_ACTIVE);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->static_tris);
+ glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_static_tris*3);
+
+ glVertexPointer(2, GL_FLOAT, 0, stitch_preview->static_quads);
+ glDrawArrays(GL_QUADS, 0, stitch_preview->num_static_quads*4);
+
glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_tris);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
UI_ThemeColor4(TH_STITCH_PREVIEW_FACE);
Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_smart_stitch.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_smart_stitch.c 2012-01-04 22:59:12 UTC (rev 43147)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_smart_stitch.c 2012-01-05 00:47:29 UTC (rev 43148)
@@ -134,8 +134,9 @@
/* ...and actual edge storage */
UvEdge *edges;
int total_edges;
- /* */
- unsigned int faces_per_island;
+ /* store number of primitives per face so that we can allocate the active island buffer later */
+ unsigned int *quads_per_island;
+ unsigned int *tris_per_island;
} StitchState;
@@ -167,6 +168,12 @@
_stitch_preview->num_stitchable = 0;
_stitch_preview->num_unstitchable = 0;
+ _stitch_preview->static_quads = NULL;
+ _stitch_preview->static_tris = NULL;
+
+ _stitch_preview->num_static_tris = 0;
+ _stitch_preview->num_static_quads = 0;
+
return _stitch_preview;
}
@@ -175,26 +182,30 @@
{
if(_stitch_preview)
{
- if(_stitch_preview->preview_quads)
- {
+ if(_stitch_preview->preview_quads){
MEM_freeN(_stitch_preview->preview_quads);
_stitch_preview->preview_quads = NULL;
}
- if(_stitch_preview->preview_tris)
- {
+ if(_stitch_preview->preview_tris){
MEM_freeN(_stitch_preview->preview_tris);
_stitch_preview->preview_tris = NULL;
}
- if(_stitch_preview->preview_stitchable)
- {
+ if(_stitch_preview->preview_stitchable){
MEM_freeN(_stitch_preview->preview_stitchable);
_stitch_preview->preview_stitchable = NULL;
}
- if(_stitch_preview->preview_unstitchable)
- {
+ if(_stitch_preview->preview_unstitchable){
MEM_freeN(_stitch_preview->preview_unstitchable);
_stitch_preview->preview_unstitchable = NULL;
}
+ if(_stitch_preview->static_quads){
+ MEM_freeN(_stitch_preview->static_quads);
+ _stitch_preview->static_quads = NULL;
+ }
+ if(_stitch_preview->static_tris){
+ MEM_freeN(_stitch_preview->static_tris);
+ _stitch_preview->static_tris = NULL;
+ }
MEM_freeN(_stitch_preview);
_stitch_preview = NULL;
}
@@ -367,6 +378,12 @@
if(stitch_state->edges){
MEM_freeN(stitch_state->edges);
}
+ if(stitch_state->quads_per_island){
+ MEM_freeN(stitch_state->quads_per_island);
+ }
+ if(stitch_state->tris_per_island){
+ MEM_freeN(stitch_state->tris_per_island);
+ }
MEM_freeN(stitch_state);
}
}
@@ -502,6 +519,7 @@
int previousIsland = state->static_island;
EditFace *efa;
EditVert *ev;
+ UVVertAverage *averageUvPosition;
char stitchAtMidpoints = state->midpoints;
/* cleanup previous preview */
@@ -575,6 +593,7 @@
* Setup the preview buffers and fill them with the appropriate data *
*********************************************************************/
if(!final){
+ unsigned int tricount = 0, quadcount = 0;
int stitchBufferIndex = 0, unstitchBufferIndex = 0;
/* initialize the preview buffers */
preview->preview_quads = (float *)MEM_mallocN(preview->num_quads*sizeof(float)*8, "quad_uv_stitch_prev");
@@ -583,7 +602,11 @@
preview->preview_stitchable = (float *)MEM_mallocN(preview->num_stitchable*sizeof(float)*2, "stitch_preview_stichable_data");
preview->preview_unstitchable = (float *)MEM_mallocN(preview->num_unstitchable*sizeof(float)*2, "stitch_preview_unstichable_data");
+ preview->static_quads = (float *)MEM_mallocN(state->quads_per_island[state->static_island]*sizeof(float)*8, "static_island_preview_quads");
+ preview->static_tris = (float *)MEM_mallocN(state->tris_per_island[state->static_island]*sizeof(float)*6, "static_island_preview_tris");
+ preview->num_static_quads = state->quads_per_island[state->static_island];
+ preview->num_static_tris = state->tris_per_island[state->static_island];
/* will cause cancel and freeing of all data structures so OK */
if(!preview->preview_quads || !preview->preview_tris || !preview->preview_stitchable || !preview->preview_unstitchable){
return 0;
@@ -591,12 +614,10 @@
/* copy data from MTFaces to the preview display buffers */
for(efa = state->em->faces.first; efa; efa = efa->next){
+ MTFace *mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
UvElement *element = ED_get_uv_element(state->element_map, efa, 0);
- if(efa->tmp.l != STITCH_NO_PREVIEW)
- {
- MTFace *mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
-
+ if(efa->tmp.l != STITCH_NO_PREVIEW){
if(efa->v4) {
memcpy(preview->preview_quads+efa->tmp.l, &mt->uv[0][0], 8*sizeof(float));
} else {
@@ -605,9 +626,16 @@
}
if(element->island == state->static_island){
-
+ if(efa->v4) {
+ memcpy(preview->static_quads + quadcount*8, &mt->uv[0][0], 8*sizeof(float));
+ quadcount++;
+ } else {
+ memcpy(preview->static_tris + tricount*6, &mt->uv[0][0], 6*sizeof(float));
+ tricount++;
+ }
}
}
+
/* fill the appropriate preview buffers */
for(i = 0; i < state->total_separate_uvs; i++){
UvElement *element = (UvElement *)state->uvs[i];
@@ -636,250 +664,108 @@
* Here we calculate the final coordinates of the uvs *
******************************************************/
- if(1){
- UVVertAverage *averageUvPosition = MEM_callocN(state->selection_size*sizeof(*averageUvPosition), "stitch_uv_average");
+ averageUvPosition = MEM_callocN(state->selection_size*sizeof(*averageUvPosition), "stitch_uv_average");
- /* first pass, calculate final position for stitchable uvs */
- for(i = 0; i < state->selection_size; i++){
- UvElement *element = (UvElement *)state->selection_stack[i];
- if(element->flag & STITCH_STITCHABLE){
- UvElement *element_iter = state->element_map->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
- for(;element_iter; element_iter = element_iter->next){
- if(element_iter->flag & STITCH_STITCHABLE){
- MTFace *mt;
- efa = element_iter->face;
- mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
- if(stitchAtMidpoints){
- averageUvPosition[i].uv[0] += mt->uv[element_iter->tfindex][0];
- averageUvPosition[i].uv[1] += mt->uv[element_iter->tfindex][1];
- averageUvPosition[i].count++;
- }else if(element_iter->island == state->static_island){
- averageUvPosition[i].uv[0] = mt->uv[element_iter->tfindex][0];
- averageUvPosition[i].uv[1] = mt->uv[element_iter->tfindex][1];
- }
- }
- }
- }
- if(stitchAtMidpoints){
- averageUvPosition[i].uv[0] /= averageUvPosition[i].count;
- averageUvPosition[i].uv[1] /= averageUvPosition[i].count;
- }
- }
-
- /* second pass, propagate changes to stitchable uvs */
- if(state->snap_islands){
- for(i = 0; i < state->selection_size; i++){
- UvElement *element = (UvElement *)state->selection_stack[i];
- if(element->flag & STITCH_STITCHABLE){
+ /* first pass, calculate final position for stitchable uvs */
+ for(i = 0; i < state->selection_size; i++){
+ UvElement *element = (UvElement *)state->selection_stack[i];
+ if(element->flag & STITCH_STITCHABLE){
+ UvElement *element_iter = state->element_map->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
+ for(;element_iter; element_iter = element_iter->next){
+ if(element_iter->flag & STITCH_STITCHABLE){
MTFace *mt;
- efa = element->face;
+ efa = element_iter->face;
mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
-
- /* accumulate each islands' translation from stitchable elements. it is important to do here
- * because in final pass MTFaces get modified and result is zero. */
- island_stitch_data[element->island].translation[0] += averageUvPosition[i].uv[0] - mt->uv[element->tfindex][0];
- island_stitch_data[element->island].translation[1] += averageUvPosition[i].uv[1] - mt->uv[element->tfindex][1];
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list