[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37800] branches/soc-2011-onion/source/ blender: smart stitch - preview for limit stitch working, almost restored all the old functionality :)
Antony Riakiotakis
kalast at gmail.com
Sat Jun 25 01:27:42 CEST 2011
Revision: 37800
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37800
Author: psy-fi
Date: 2011-06-24 23:27:41 +0000 (Fri, 24 Jun 2011)
Log Message:
-----------
smart stitch - preview for limit stitch working, almost restored all the old functionality :)
Modified Paths:
--------------
branches/soc-2011-onion/source/blender/blenkernel/BKE_mesh.h
branches/soc-2011-onion/source/blender/editors/include/ED_mesh.h
branches/soc-2011-onion/source/blender/editors/mesh/editmesh_lib.c
branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c
Modified: branches/soc-2011-onion/source/blender/blenkernel/BKE_mesh.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/BKE_mesh.h 2011-06-24 23:14:26 UTC (rev 37799)
+++ branches/soc-2011-onion/source/blender/blenkernel/BKE_mesh.h 2011-06-24 23:27:41 UTC (rev 37800)
@@ -114,6 +114,7 @@
typedef struct UvVertMap {
struct UvMapVert **vert;
struct UvMapVert *buf;
+ int numOfUVs;
} UvVertMap;
typedef struct UvMapVert {
Modified: branches/soc-2011-onion/source/blender/editors/include/ED_mesh.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/include/ED_mesh.h 2011-06-24 23:14:26 UTC (rev 37799)
+++ branches/soc-2011-onion/source/blender/editors/include/ED_mesh.h 2011-06-24 23:27:41 UTC (rev 37800)
@@ -154,7 +154,8 @@
struct UvVertMap *EM_make_uv_vert_map(struct EditMesh *em, int selected, int do_face_idx_array, float *limit);
struct UvMapVert *EM_get_uv_map_vert(struct UvVertMap *vmap, unsigned int v);
-void EM_free_uv_vert_map(struct UvVertMap *vmap);
+void EM_uv_vert_map_sort(struct UvVertMap *vmap, struct EditMesh *em, float *limit);
+void EM_free_uv_vert_map(struct UvVertMap *vmap);
void EM_add_data_layer(struct EditMesh *em, struct CustomData *data, int type, const char *name);
void EM_free_data_layer(struct EditMesh *em, struct CustomData *data, int type);
Modified: branches/soc-2011-onion/source/blender/editors/mesh/editmesh_lib.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/mesh/editmesh_lib.c 2011-06-24 23:14:26 UTC (rev 37799)
+++ branches/soc-2011-onion/source/blender/editors/mesh/editmesh_lib.c 2011-06-24 23:27:41 UTC (rev 37800)
@@ -2294,6 +2294,8 @@
return NULL;
}
+ vmap->numOfUVs = totuv;
+
for (a=0, efa= em->faces.first; efa; a++, efa= efa->next) {
if(!selected || ((!efa->h) && (efa->f & SELECT))) {
nverts= (efa->v4)? 4: 3;
@@ -2313,56 +2315,67 @@
if(limit)
{
- /* sort individual uvs for each vert */
- for(a=0, ev=em->verts.first; ev; a++, ev= ev->next) {
- UvMapVert *newvlist= NULL, *vlist=vmap->vert[a];
- UvMapVert *iterv, *v, *lastv, *next;
- float *uv, *uv2, uvdiff[2];
+ EM_uv_vert_map_sort(vmap, em, limit);
+ }
- while(vlist) {
- v= vlist;
- vlist= vlist->next;
- v->next= newvlist;
- newvlist= v;
+ if (do_face_idx_array)
+ EM_free_index_arrays();
- efa = EM_get_face_for_index(v->f);
- tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
- uv = tf->uv[v->tfindex];
+ return vmap;
+}
+
+/* Sort UVs of vertmap according to limit */
+void EM_uv_vert_map_sort(UvVertMap *vmap, EditMesh *em, float *limit)
+{
+ EditFace *efa;
+ MTFace *tf;
+ unsigned int a;
+ EditVert *ev;
+
+ /* sort individual uvs for each vert */
+ for(a=0, ev=em->verts.first; ev; a++, ev= ev->next) {
+ UvMapVert *newvlist= NULL, *vlist=vmap->vert[a];
+ UvMapVert *iterv, *v, *lastv, *next;
+ float *uv, *uv2, uvdiff[2];
+
+ while(vlist) {
+ v= vlist;
+ vlist= vlist->next;
+ v->next= newvlist;
+ newvlist= v;
+
+ efa = EM_get_face_for_index(v->f);
+ tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+ uv = tf->uv[v->tfindex];
- lastv= NULL;
- iterv= vlist;
+ lastv= NULL;
+ iterv= vlist;
- while(iterv) {
- next= iterv->next;
- efa = EM_get_face_for_index(iterv->f);
- tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
- uv2 = tf->uv[iterv->tfindex];
+ while(iterv) {
+ next= iterv->next;
+ efa = EM_get_face_for_index(iterv->f);
+ tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+ uv2 = tf->uv[iterv->tfindex];
- sub_v2_v2v2(uvdiff, uv2, uv);
+ sub_v2_v2v2(uvdiff, uv2, uv);
- if(fabsf(uv[0]-uv2[0]) < limit[0] && fabsf(uv[1]-uv2[1]) < limit[1]) {
- if(lastv) lastv->next= next;
- else vlist= next;
- iterv->next= newvlist;
- newvlist= iterv;
- }
- else
- lastv=iterv;
-
- iterv= next;
+ if(fabsf(uv[0]-uv2[0]) < limit[0] && fabsf(uv[1]-uv2[1]) < limit[1]) {
+ if(lastv) lastv->next= next;
+ else vlist= next;
+ iterv->next= newvlist;
+ newvlist= iterv;
}
+ else
+ lastv=iterv;
- newvlist->separate = 1;
+ iterv= next;
}
- vmap->vert[a]= newvlist;
+ newvlist->separate = 1;
}
+
+ vmap->vert[a]= newvlist;
}
-
- if (do_face_idx_array)
- EM_free_index_arrays();
-
- return vmap;
}
UvMapVert *EM_get_uv_map_vert(UvVertMap *vmap, unsigned int v)
Modified: branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c 2011-06-24 23:14:26 UTC (rev 37799)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c 2011-06-24 23:27:41 UTC (rev 37800)
@@ -1203,13 +1203,13 @@
return _stitch_preview;
}
-
+/* This function updates the header of the UV editor when the stitch tool updates its settings */
static void stitch_update_header(StitchState *stitch_state, bContext *C)
{
- static char str[] = "%c V(ertices) %c E(dges) %c P(review) %c L(imit) %c S(nap) Wheel(limit adjust): %f";
+ static char str[] = "Select(V {+Ctrl deselect}) Mode(M): %c Vertex %c Edge %c Preview(P) %c Limit(L) %c Snap(S) Wheel(limit adjust): %f";
char msg[256];
ScrArea *sa= CTX_wm_area(C);
- char mode = stitch_state->mode == VERT_STITCH;
+ char mode = (stitch_state->mode == VERT_STITCH);
if(sa) {
sprintf(msg, str, (mode)? '*':' ',
@@ -1222,11 +1222,13 @@
}
}
+/* This function prepares the data of the previewer for display */
static void stitch_prepare_preview_data(StitchState *state)
{
StitchPreviewer *preview = uv_get_stitch_previewer();
UVVertAverage *uv_average;
UvVertMap *vmap = state->vmap;
+ UvMapVert *mapVert = vmap->buf;
int i;
int bufferIterator = 0;
EditFace *editFace, *efa, **faceArray;
@@ -1234,6 +1236,8 @@
MTFace *mt;
short preview_enabled = preview->enabled;
const char FACE_UVS_SELECTED = TF_SEL1 | TF_SEL2 | TF_SEL3 | TF_SEL4;
+ /* This holds uv's that are coincident with the initial uv checked. */
+ UvMapVert **commonVertMaps;
/* cleanup previous preview */
stitch_preview_delete();
@@ -1241,13 +1245,14 @@
/*todo better store this in state */
preview->enabled = preview_enabled;
- uv_average = (UVVertAverage *)MEM_callocN(state->em->totvert*sizeof(UVVertAverage), "stitch_averages");
+ /* UV average is stored for every UV since potentially every UV can be stitched with another. Highly unlikely, I know but possible
+ * nevertheless :p */
+ uv_average = (UVVertAverage *)MEM_callocN(state->vmap->numOfUVs*sizeof(UVVertAverage), "stitch_averages");
faceArray = (EditFace **)MEM_mallocN(state->em->totface*sizeof(EditFace *), "stitch preview faceArray");
/* Store Indices to editVerts */
for(editVert = state->em->verts.first, i = 0; editVert; editVert = editVert->next, i++){
editVert->tmp.t = i;
- editVert->f1 = 0;
}
/* Make face array and initialize position in preview buffer */
@@ -1256,6 +1261,10 @@
editFace->tmp.l = -1;
}
+ /* The maximum number of faces that a UV can be part of is totfaces. We allocate this here to avoid allocating
+ * this too many times on the fly */
+ commonVertMaps = MEM_mallocN(state->em->totface*sizeof(UvMapVert *), "commonVertMaps");
+
/* Count number of points/faces so that we allocate appropriate buffer */
for(editFace = state->em->faces.first ; editFace; editFace=editFace->next){
mt = CustomData_em_get(&state->em->fdata, editFace->data, CD_MTFACE);
@@ -1266,62 +1275,133 @@
for(i = 0; i < vertsPerFace; i++){
if(mt->flag & TF_SEL_MASK(i))
{
+ int averageIndex;
+ int iter = 0;
+ int iter2;
+ UvMapVert *mv_iter;
EditVert *vt = *(&(editFace->v1)+i);
/* ...we'll iterate through all shared UV's of the corresponding vertex */
- UvMapVert *mapVert = vmap->vert[vt->tmp.t];
- int numOfPreviewPoints = 0;
+ mv_iter = vmap->vert[vt->tmp.t];
+ /* Original vertex will be previewed, of course */
+ preview->numOfPoints++;
- /* Have we traversed this vertex before? */
- if(vt->f1 == 0){
- vt->f1 = STITCH_UNSTITCHABLE;
+ /* First we need the UVMapVert that corresponds to our uv */
+ for(;mv_iter; mv_iter = mv_iter->next)
+ {
+ /* Here we assume face does not use the same vertex twice. */
+ if(faceArray[mv_iter->f] == editFace)
+ {
+ mapVert = mv_iter;
+ /* If the selected UV has not been flagged as stichable or anything at all, tag it as unstitchable */
+ if(!mapVert->flag)
+ {
+ mapVert->flag = STITCH_UNSTITCHABLE;
+ }
+ averageIndex = mapVert - vmap->buf;
+ }
+ }
+ /* if uv is stitchable, it has already been processed */
+ if(mapVert->flag != STITCH_STITCHABLE)
+ {
+ uv_average[averageIndex].count++;
+ uv_average[averageIndex].uv[0] = mt->uv[i][0];
+ uv_average[averageIndex].uv[1] = mt->uv[i][1];
- while(mapVert){
+ for(mv_iter = vmap->vert[vt->tmp.t], iter = 0; mv_iter; mv_iter = mv_iter->next){
MTFace *tmptface;
- efa = faceArray[mapVert->f];
+ if(mv_iter == mapVert)
+ continue;
+
+ efa = faceArray[mv_iter->f];
tmptface = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
- numOfPreviewPoints++;
- /* should probably change these limits to something better. Still it will do for now. */
- if(fabs((mt->uv[i][0] - tmptface->uv[mapVert->tfindex][0]) > 0.001) ||
- (fabs(mt->uv[i][1] - tmptface->uv[mapVert->tfindex][1]) > 0.001) ){
- vt->f1 = STITCH_STITCHABLE;
- }
+ if(fabs((mt->uv[i][0] - tmptface->uv[mv_iter->tfindex][0]) < STD_UV_CONNECT_LIMIT) &&
+ (fabs(mt->uv[i][1] - tmptface->uv[mv_iter->tfindex][1]) < STD_UV_CONNECT_LIMIT)){
+ /* if the uv being iterated is coincident with the original, add it to be updated later if
+ * original uv is stitchable */
+ commonVertMaps[iter++] = mv_iter;
+ } else {
+ if((!state->use_limit) || ( (fabs(mt->uv[i][0] - tmptface->uv[mv_iter->tfindex][0]) < state->limitDist
+ && fabs(mt->uv[i][1] - tmptface->uv[mv_iter->tfindex][1]) < state->limitDist) ))
+ {
+ commonVertMaps[iter++] = mv_iter;
+ /* pointer arithmetic to the rescue */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list