[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40241] branches/soc-2011-onion-uv-tools/ source/blender/editors/uvedit/uvedit_ops.c: Preview for stitchable/ unstitchable uvs working.
Antony Riakiotakis
kalast at gmail.com
Thu Sep 15 19:55:56 CEST 2011
Revision: 40241
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40241
Author: psy-fi
Date: 2011-09-15 17:55:55 +0000 (Thu, 15 Sep 2011)
Log Message:
-----------
Preview for stitchable/unstitchable uvs working.
Modified Paths:
--------------
branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c
Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c 2011-09-15 17:28:18 UTC (rev 40240)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c 2011-09-15 17:55:55 UTC (rev 40241)
@@ -1305,6 +1305,7 @@
UvEdge *uvedges;
/* container of first of a group of coincident uvs, these will be operated upon */
UvElement **uvs;
+ int numOfSeparateUvs;
/* maps uvelements to their first coincident uv */
int *map;
/* hold selection related information */
@@ -2206,7 +2207,42 @@
return 0;
}
+/* registers uvs so that they can be */
+static void stitch_setup_preview_for_uv_group(UvElement *element, StitchState *state){
+ StitchPreviewer *preview = uv_get_stitch_previewer();
+ UvElement *element_iter = state->elementMap->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
+ for(; element_iter; element_iter = element_iter->next){
+ if(state->use_limit){
+ MTFace *mtface_orig = CustomData_em_get(&state->em->fdata, element->face->data, CD_MTFACE);
+ MTFace *mtface_iter = CustomData_em_get(&state->em->fdata, element_iter->face->data, CD_MTFACE);
+
+ if(fabs(mtface_orig->uv[element->tfindex][0] - mtface_iter->uv[element_iter->tfindex][0]) < state->limitDist
+ && fabs(mtface_orig->uv[element->tfindex][1] - mtface_iter->uv[element_iter->tfindex][1]) < state->limitDist){
+ int uniqueIndex;
+ stitch_set_face_preview_buffer_position(element_iter->face, preview);
+
+ uniqueIndex = state->map[element_iter - state->elementMap->buf];
+ state->uvs[uniqueIndex]->flag |= STITCH_STITCHABLE;
+
+ if(element_iter->separate){
+ preview->numOfOrig++;
+ }
+ }
+ }else{
+ int uniqueIndex;
+ /* if no limit exists, then the mere existence of a separate uv means that the uv is stitchable */
+ stitch_set_face_preview_buffer_position(element_iter->face, preview);
+ uniqueIndex = state->map[element_iter - state->elementMap->buf];
+ state->uvs[uniqueIndex]->flag |= STITCH_STITCHABLE;
+
+ if(element_iter->separate){
+ preview->numOfOrig++;
+ }
+ }
+ }
+}
+
/* Main processing function. It calculates preview and final positions. */
static int stitch_process_data(StitchState *state, int final, Scene *scene, int doIndexInit)
{
@@ -2240,24 +2276,19 @@
/* First determine stitchability of uvs */
if(state->mode == VERT_STITCH){
for(i = 0; i < state->selection_size; i++){
- if(determine_uv_stitchability(state->selection_stack[i], state)){
- ((UvElement *)(state->selection_stack[i]))->flag |= STITCH_STITCHABLE;
- }
- }
- /* Now we need to register our stitchable and any remote uvs for preview */
- for(i = 0; i < state->selection_size; i++){
UvElement *element = (UvElement *)state->selection_stack[i];
- if(element->flag & STITCH_STITCHABLE){
- UvElement *element_iter = state->elementMap->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
- for(; element_iter; element_iter = element_iter->next){
- stitch_set_face_preview_buffer_position(element_iter->face, preview);
- }
+ if(determine_uv_stitchability(element, state)){
+ stitch_setup_preview_for_uv_group(element, state);
+ }else{
+ /* Add to preview */
+ preview->numOfOrig++;
}
}
}
if(!final){
+ int origBufferIndex = 0;
/* Initialize the preview buffers */
preview->previewQuads = (float *)MEM_mallocN(preview->numOfQuads*sizeof(float)*8, "quad_uv_stitch_prev");
preview->previewTris = (float *)MEM_mallocN(preview->numOfTris*sizeof(float)*6, "tri_uv_stitch_prev");
@@ -2270,15 +2301,28 @@
}
/* Fill the preview buffers with stitchable only faces */
- for(i = 0; i < state->selection_size; i++){
- UvElement *element = (UvElement *)state->selection_stack[i];
+ for(i = 0; i < state->numOfSeparateUvs; i++){
+ UvElement *element = (UvElement *)state->uvs[i];
if(element->flag & STITCH_STITCHABLE){
- UvElement *element_iter = state->elementMap->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
+ MTFace *mt;
+ UvElement *element_iter;
+
+ efa = element->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+ preview->previewOrig[origBufferIndex*2] = mt->uv[element->tfindex][0];
+ preview->previewOrig[origBufferIndex*2 + 1] = mt->uv[element->tfindex][1];
+ UI_GetThemeColor4ubv(TH_STITCH_PREVIEW_STITCHABLE, (unsigned char *)&preview->previewOrigColors[origBufferIndex++]);
+
+ element_iter = state->elementMap->vert[(*(&element->face->v1 + element->tfindex))->tmp.l];
+
for(element_iter = element; element_iter; element_iter = element_iter->next){
+ /* necessary to avoid cleaning up preview of vertices for common stitchable uvs */
+ if(element_iter->separate && element_iter != element)
+ break;
efa = element_iter->face;
if(efa->tmp.l != -1)
{
- MTFace *mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
if(efa->v4) {
memcpy(preview->previewQuads+efa->tmp.l, &mt->uv[0][0], 8*sizeof(float));
@@ -2288,9 +2332,17 @@
}
}
}
- else{
+ else if(element->flag & STITCH_SELECTED){
+ MTFace *mt;
+ efa = element->face;
+ mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+ preview->previewOrig[origBufferIndex*2] = mt->uv[element->tfindex][0];
+ preview->previewOrig[origBufferIndex*2 + 1] = mt->uv[element->tfindex][1];
+ UI_GetThemeColor4ubv(TH_STITCH_PREVIEW_UNSTITCHABLE, (unsigned char *)&preview->previewOrigColors[origBufferIndex++]);
}
+ /* keep only the selection flag */
+ element->flag &= STITCH_SELECTED;
}
}
@@ -2341,6 +2393,7 @@
}
stitch_state->uvs = MEM_mallocN(sizeof(*stitch_state->uvs)*counter, "uv_stitch_unique_uvs");
+ stitch_state->numOfSeparateUvs = counter;
/* we can at most have totalUVs edges or uvs selected. Actually they are less, considering we store only
* unique uvs for processing but I am accounting for all bizarre cases, especially for edges, this way */
stitch_state->selection_stack = MEM_mallocN(sizeof(*stitch_state->selection_stack)*stitch_state->elementMap->totalUVs, "uv_stitch_selection_stack");
@@ -2571,6 +2624,7 @@
/* remove element from selection stack */
if(unique_element->flag & STITCH_SELECTED){
int i;
+ unique_element->flag &= ~STITCH_SELECTED;
for(i = 0; i < stitch_state->selection_size; i++){
if(((UvElement *)stitch_state->selection_stack[i]) == unique_element){
--stitch_state->selection_size;
@@ -2580,8 +2634,10 @@
}
}
}else{
- unique_element->flag |= STITCH_SELECTED;
- stitch_state->selection_stack[stitch_state->selection_size++] = unique_element;
+ if(!(unique_element->flag & STITCH_SELECTED)){
+ unique_element->flag |= STITCH_SELECTED;
+ stitch_state->selection_stack[stitch_state->selection_size++] = unique_element;
+ }
}
#else
More information about the Bf-blender-cvs
mailing list