[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37930] branches/soc-2011-onion/source/ blender: smart stitch - more stuff for edge stitching, a refactor will be needed in UvVertMaps to make it possible so making a slight variant named UvVertMap2 which will grow to accomodate some extra state I need + it finally stores editfaces as pointers , not indices, allowing me to skip initializing these horrible arrays every time.
Antony Riakiotakis
kalast at gmail.com
Wed Jun 29 02:40:15 CEST 2011
Revision: 37930
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37930
Author: psy-fi
Date: 2011-06-29 00:40:14 +0000 (Wed, 29 Jun 2011)
Log Message:
-----------
smart stitch - more stuff for edge stitching, a refactor will be needed in UvVertMaps to make it possible so making a slight variant named UvVertMap2 which will grow to accomodate some extra state I need + it finally stores editfaces as pointers, not indices, allowing me to skip initializing these horrible arrays every time. Maybe this is dangerous if pointers change internally between redraws but I don't do any geometry addition, so it is supposed to be valid. Looks like it's working too. Please notify if this is not a good idea.
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-28 22:14:40 UTC (rev 37929)
+++ branches/soc-2011-onion/source/blender/blenkernel/BKE_mesh.h 2011-06-29 00:40:14 UTC (rev 37930)
@@ -114,7 +114,6 @@
typedef struct UvVertMap {
struct UvMapVert **vert;
struct UvMapVert *buf;
- int numOfUVs;
} UvVertMap;
typedef struct UvMapVert {
@@ -123,6 +122,18 @@
unsigned char tfindex, separate, flag;
} UvMapVert;
+typedef struct UvVertMap2 {
+ struct UvElement **vert;
+ struct UvElement *buf;
+ int numOfUVs;
+} UvVertMap2;
+
+typedef struct UvElement {
+ struct UvElement *next;
+ struct EditFace *face;
+ unsigned char tfindex, separate, flag;
+} UvElement;
+
UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned int totface, unsigned int totvert, int selected, float *limit);
UvMapVert *get_uv_map_vert(UvVertMap *vmap, unsigned int v);
void free_uv_vert_map(UvVertMap *vmap);
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-28 22:14:40 UTC (rev 37929)
+++ branches/soc-2011-onion/source/blender/editors/include/ED_mesh.h 2011-06-29 00:40:14 UTC (rev 37930)
@@ -156,6 +156,10 @@
struct UvMapVert *EM_get_uv_map_vert(struct UvVertMap *vmap, unsigned int v);
void EM_free_uv_vert_map(struct UvVertMap *vmap);
+struct UvVertMap2 *EM_make_uv_vert_map2(struct EditMesh *em, int selected, float *limit);
+struct UvElement *EM_get_uv_element_for_edge(struct UvVertMap2 *vmap, struct EditMesh *em, struct EditEdge *edge, int initVertexArray);
+void EM_free_uv_vert_map2(struct UvVertMap2 *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-28 22:14:40 UTC (rev 37929)
+++ branches/soc-2011-onion/source/blender/editors/mesh/editmesh_lib.c 2011-06-29 00:40:14 UTC (rev 37930)
@@ -2294,8 +2294,6 @@
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,12 +2311,118 @@
}
}
+ /* 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;
+
+ 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;
+ 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];
+
+ 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;
+ }
+ newvlist->separate = 1;
+ }
+ vmap->vert[a]= newvlist;
+ }
+
+
+ if (do_face_idx_array)
+ EM_free_index_arrays();
+
+ return vmap;
+}
+
+UvVertMap2 *EM_make_uv_vert_map2(EditMesh *em, int selected, float *limit)
+{
+ EditVert *ev;
+ EditFace *efa;
+ int totverts;
+
+ /* vars from original func */
+ UvVertMap2 *vmap;
+ UvElement *buf;
+ MTFace *tf;
+ unsigned int a;
+ int i, totuv, nverts;
+
+ /* we need the vert */
+ for (ev= em->verts.first, totverts=0; ev; ev= ev->next, totverts++) {
+ ev->tmp.l = totverts;
+ }
+
+ totuv = 0;
+
+ /* generate UvMapVert array */
+ for (efa= em->faces.first; efa; efa= efa->next)
+ if(!selected || ((!efa->h) && (efa->f & SELECT)))
+ totuv += (efa->v4)? 4: 3;
+
+ if(totuv==0) {
+ return NULL;
+ }
+ vmap= (UvVertMap2 *)MEM_callocN(sizeof(*vmap), "UvVertMap2");
+ if (!vmap) {
+ return NULL;
+ }
+
+ vmap->vert= (UvElement**)MEM_callocN(sizeof(*vmap->vert)*totverts, "UvElement*");
+ buf= vmap->buf= (UvElement*)MEM_callocN(sizeof(*vmap->buf)*totuv, "UvElement");
+
+ if (!vmap->vert || !vmap->buf) {
+ EM_free_uv_vert_map2(vmap);
+ return NULL;
+ }
+
+ vmap->numOfUVs = totuv;
+
+ for (efa= em->faces.first; efa; a++, efa= efa->next) {
+ if(!selected || ((!efa->h) && (efa->f & SELECT))) {
+ nverts= (efa->v4)? 4: 3;
+
+ for(i=0; i<nverts; i++) {
+ buf->tfindex= i;
+ buf->face = efa;
+ buf->separate = 0;
+
+ buf->next= vmap->vert[(*(&efa->v1 + i))->tmp.l];
+ vmap->vert[(*(&efa->v1 + i))->tmp.l]= buf;
+
+ buf++;
+ }
+ }
+ }
+
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;
+ UvElement *newvlist= NULL, *vlist=vmap->vert[a];
+ UvElement *iterv, *v, *lastv, *next;
float *uv, *uv2;
while(vlist) {
@@ -2327,19 +2431,19 @@
v->next= newvlist;
newvlist= v;
- efa = EM_get_face_for_index(v->f);
+ efa = v->face;
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
uv = tf->uv[v->tfindex];
-
+
lastv= NULL;
iterv= vlist;
while(iterv) {
next= iterv->next;
- efa = EM_get_face_for_index(iterv->f);
+ efa = iterv->face;
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
uv2 = tf->uv[iterv->tfindex];
-
+
if(fabsf(uv[0]-uv2[0]) < limit[0] && fabsf(uv[1]-uv2[1]) < limit[1]) {
if(lastv) lastv->next= next;
else vlist= next;
@@ -2359,12 +2463,31 @@
}
}
- if (do_face_idx_array)
- EM_free_index_arrays();
-
return vmap;
}
+UvElement *EM_get_uv_map_vert_for_edge(UvVertMap2 *vmap, EditMesh *em, EditEdge *edge, int initVertexArray)
+{
+ int i;
+ EditVert *vert;
+ UvElement *element;
+ EditFace *efa;
+ MTFace *mt;
+ if(initVertexArray)
+ {
+ for(vert = em->verts.first, i = 0; vert; vert = vert->next, i++){
+ vert->tmp.t = i;
+ }
+ }
+
+ for(element = vmap->vert[edge->v1->tmp.t]; element; element = element->next){
+ efa = element->face;
+
+ }
+
+ return NULL;
+}
+
UvMapVert *EM_get_uv_map_vert(UvVertMap *vmap, unsigned int v)
{
return vmap->vert[v];
@@ -2379,6 +2502,15 @@
}
}
+void EM_free_uv_vert_map2(UvVertMap2 *vmap)
+{
+ if (vmap) {
+ if (vmap->vert) MEM_freeN(vmap->vert);
+ if (vmap->buf) MEM_freeN(vmap->buf);
+ MEM_freeN(vmap);
+ }
+}
+
/* poll call for mesh operators requiring a view3d context */
int EM_view3d_poll(bContext *C)
{
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-28 22:14:40 UTC (rev 37929)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c 2011-06-29 00:40:14 UTC (rev 37930)
@@ -1137,7 +1137,7 @@
/* editmesh, cached for use in modal handler */
EditMesh *em;
/* vertmap, contains vertices sharing uv's in linked lists. */
- UvVertMap *vmap;
+ UvVertMap2 *vmap;
/* gHash with operand edges */
GHash *edges;
} StitchState;
@@ -1250,13 +1250,14 @@
}
}
+
/* This function prepares the data of the previewer for display */
-static int stitch_process_data(StitchState *state, int final, Scene *scene)
+static int stitch_process_data(StitchState *state, int final, Scene *scene, int doIndexInit)
{
StitchPreviewer *preview = uv_get_stitch_previewer();
UVVertAverage *uv_average;
- UvVertMap *vmap = state->vmap;
- UvMapVert *mapVert = vmap->buf;
+ UvVertMap2 *vmap = state->vmap;
+ UvElement *element = vmap->buf;
int i;
int numOfEdges = 0;
int bufferIterator = 0;
@@ -1278,29 +1279,27 @@
* nevertheless :p */
uv_average = (UVVertAverage *)MEM_callocN(state->vmap->numOfUVs*sizeof(UVVertAverage), "stitch_averages");
- /* This serves exactly as the EM_init_arrays with the added advantage that we can initialize the preview buffer position. */
- 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;
+ if(doIndexInit){
+ for(editVert = state->em->verts.first, i = 0; editVert; editVert = editVert->next, i++){
+ editVert->tmp.t = i;
+ }
}
/* Make face array and initialize position in preview buffer */
for(editFace = state->em->faces.first, i = 0; editFace; editFace = editFace->next, i++){
- faceArray[i] = editFace;
editFace->tmp.l = -1;
}
- /* Vert stitching case */
+ /* Vertex stitching case */
if(state->mode == VERT_STITCH){
/* This holds uv's that must be updated if the initial uv is stitchable. */
- UvMapVert **commonVertMaps;
+ UvElement **commonVertMaps;
/* 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");
+ commonVertMaps = MEM_mallocN(state->em->totface*sizeof(UvElement *), "commonVertMaps");
/* Count number of points/faces so that we allocate appropriate buffer */
@@ -1316,7 +1315,7 @@
int averageIndex;
int iter = 0;
int iter2;
- UvMapVert *mv_iter;
+ UvElement *mv_iter;
EditVert *vt = *(&(editFace->v1)+i);
/* ...we'll iterate through all shared UV's of the corresponding vertex */
mv_iter = vmap->vert[vt->tmp.t];
@@ -1327,11 +1326,11 @@
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)
+ if(mv_iter->face == editFace)
{
/* Assign first UV coincident */
- mapVert = mv_iter;
- averageIndex = mapVert - vmap->buf;
+ element = mv_iter;
+ averageIndex = element - vmap->buf;
}
}
@@ -1342,11 +1341,11 @@
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list