[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43312] branches/soc-2011-onion-uv-tools/ source/blender/editors/uvedit/uvedit_smart_stitch.c: Code to make rotation during stitch work even when one uv is selected.
Antony Riakiotakis
kalast at gmail.com
Thu Jan 12 03:41:30 CET 2012
Revision: 43312
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43312
Author: psy-fi
Date: 2012-01-12 02:41:20 +0000 (Thu, 12 Jan 2012)
Log Message:
-----------
Code to make rotation during stitch work even when one uv is selected. This is still problematic in a few corner cases, island setups and midpoint/snap combinations but should work for simple scenarios now.
Modified Paths:
--------------
branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_smart_stitch.c
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-11 20:53:22 UTC (rev 43311)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_smart_stitch.c 2012-01-12 02:41:20 UTC (rev 43312)
@@ -43,6 +43,7 @@
#include "BLI_editVert.h"
#include "BLI_ghash.h"
#include "BLI_math.h"
+#include "BLI_math_vector.h"
#include "BLI_string.h"
#include "BKE_context.h"
@@ -78,7 +79,7 @@
/* Used for rotation, the island will rotate around this point */
float medianPoint[2];
int numOfElements;
- int numOfEdges;
+ int num_rot_elements;
/* Flag to remember if island has been added for preview */
char addedForPreview;
/* Flag an island to be considered for determining static island */
@@ -274,8 +275,8 @@
int numOfIslandUVs = 0, j;
/* check to avoid divide by 0 */
- if(island_stitch_data[i].numOfEdges>0){
- island_stitch_data[i].rotation /= island_stitch_data[i].numOfEdges;
+ if(island_stitch_data[i].num_rot_elements>0){
+ island_stitch_data[i].rotation /= island_stitch_data[i].num_rot_elements;
island_stitch_data[i].medianPoint[0] /= island_stitch_data[i].numOfElements;
island_stitch_data[i].medianPoint[1] /= island_stitch_data[i].numOfElements;
}
@@ -352,46 +353,47 @@
edgecos = uv1[0]*uv2[0] + uv1[1]*uv2[1];
edgesin = uv1[0]*uv2[1] - uv2[0]*uv1[1];
- island_stitch_data[element->island].numOfEdges++;
+ island_stitch_data[element->island].num_rot_elements++;
island_stitch_data[element->island].rotation += (edgesin > 0)? acos(MAX2(-1.0, MIN2(1.0, edgecos))): -acos(MAX2(-1.0, MIN2(1.0, edgecos)));
}
-static void stitch_island_calculate_vert_rotation(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data)
+static void stitch_island_calculate_vert_rotation(UvElement *element, StitchState *state, IslandStitchData *island_stitch_data, char do_static)
{
- EditFace *efa;
- MTFace *mt;
- float edgecos, edgesin;
+ float edgecos = 1, edgesin = 0;
int index;
UvElement *element_iter;
- if((element->island == state->static_island) && !state->midpoints)
+ if((element->island == state->static_island) && !do_static)
return;
- efa = element->face;
- mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
-
index = (*(&element->face->v1 + element->tfindex))->tmp.l;
element_iter = state->element_map->vert[index];
- for(; element_iter; element_iter = element_iter->next){
- if(element_iter->separate && (element_iter != element) &&
- (element_iter->flag & STITCH_STITCHABLE)){
- int index_tmp;
- /* easily possible*/
- if(element_iter->island == element->island){
- continue;
+ if(!do_static){
+ for(; element_iter; element_iter = element_iter->next){
+ if((element_iter->separate) && (element_iter->flag & STITCH_STITCHABLE) &&
+ (element_iter != element) && (element_iter->island == state->static_island)
+ ){
+ int index_tmp1, index_tmp2;
+ float normal[2];
+ /* easily possible*/
+
+ index_tmp1 = element_iter - state->element_map->buf;
+ index_tmp1 = state->map[index_tmp1];
+ index_tmp2 = element - state->element_map->buf;
+ index_tmp2 = state->map[index_tmp2];
+
+ negate_v2_v2(normal, state->normals + index_tmp2*2);
+ edgecos = dot_v2v2(normal, state->normals + index_tmp1*2);
+ edgesin = cross_v2v2(normal, state->normals + index_tmp1*2);
+ break;
}
- index_tmp = element_iter - state->element_map->buf;
- index_tmp = state->map[index_tmp];
}
}
- edgecos = 0;
- edgesin = 0;
+ island_stitch_data[element->island].num_rot_elements++;
island_stitch_data[element->island].rotation += (edgesin > 0)? acos(edgecos): -acos(edgecos);
- island_stitch_data[element->island].medianPoint[0] += mt->uv[element->tfindex][0];
- island_stitch_data[element->island].medianPoint[1] += mt->uv[element->tfindex][1];;
}
@@ -763,11 +765,11 @@
use_vert_normals = 0;
}
}
- if(0){
+ if(use_vert_normals){
for(i = 0; i < state->selection_size; i++){
UvElement *element = state->selection_stack[i];
if(element->flag & STITCH_STITCHABLE){
- stitch_island_calculate_vert_rotation(element, state, island_stitch_data);
+ stitch_island_calculate_vert_rotation(element, state, island_stitch_data, 0);
}
}
}
@@ -890,16 +892,11 @@
UvElement *element = edge->element;
EditFace *efa = element->face;
MTFace *mt = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
- int index;
+ int nverts = efa->v4?4 : 3;
+ int index = index = (element->tfindex + 2)%nverts;
float tangent[2], internal[2];
- if(efa->v4){
- index = (element->tfindex + 2)%4;
- }else{
- index = (element->tfindex + 2)%3;
- }
-
- sub_v2_v2v2(tangent, mt->uv[element->tfindex + 1], mt->uv[element->tfindex]);
+ sub_v2_v2v2(tangent, mt->uv[(element->tfindex + 1)%nverts], mt->uv[element->tfindex]);
sub_v2_v2v2(internal, mt->uv[index], mt->uv[element->tfindex]);
/* choose one of the normals */
@@ -1028,13 +1025,12 @@
all_edges[counter].uv1 = offset2;
all_edges[counter].uv2 = offset1;
}
- /* Hack! Set the value of the key to its flag. Now we can set the flag when an edge exists twice :) */
+
if(BLI_ghash_haskey(edgeHash, &all_edges[counter])){
char *flag = BLI_ghash_lookup(edgeHash, &all_edges[counter]);
*flag = 0;
}
else{
- /* Hack mentioned */
BLI_ghash_insert(edgeHash, &all_edges[counter], &(all_edges[counter].flag));
all_edges[counter].flag = STITCH_BOUNDARY;
}
More information about the Bf-blender-cvs
mailing list