[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37929] branches/soc-2011-onion/source/ blender/editors/uvedit: smart stitch - more edge evaluation stuff, not quite there yet but closer
Antony Riakiotakis
kalast at gmail.com
Wed Jun 29 00:14:42 CEST 2011
Revision: 37929
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37929
Author: psy-fi
Date: 2011-06-28 22:14:40 +0000 (Tue, 28 Jun 2011)
Log Message:
-----------
smart stitch - more edge evaluation stuff, not quite there yet but closer
Modified Paths:
--------------
branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_intern.h
branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c
Modified: branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_intern.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_intern.h 2011-06-28 21:24:20 UTC (rev 37928)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_intern.h 2011-06-28 22:14:40 UTC (rev 37929)
@@ -69,7 +69,7 @@
#define TF_PIN_MASK(id) (TF_PIN1 << id)
#define TF_SEL_MASK(id) (TF_SEL1 << id)
-/* margin for scale to differ from 1.0 for printing debug info */
+/* margin for scale to differ from 1.0 for printing unwrapping warning */
#define UNWRAP_SCALE_EPSILON 0.00001
/* geometric utilities */
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 21:24:20 UTC (rev 37928)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c 2011-06-28 22:14:40 UTC (rev 37929)
@@ -73,10 +73,6 @@
#include "uvedit_intern.h"
-#define STITCH_PROCESSED 1
-#define STITCH_STITCHABLE 2
-#define STITCH_SELECTED 4
-
/************************* state testing ************************/
int ED_uvedit_test(Object *obedit)
@@ -1142,14 +1138,38 @@
EditMesh *em;
/* vertmap, contains vertices sharing uv's in linked lists. */
UvVertMap *vmap;
+ /* gHash with operand edges */
+ GHash *edges;
} StitchState;
+/*
+ * defines for operator
+ */
#define VERT_STITCH 1
#define EDGE_STITCH 2
+/*
+ * defines for UvMapVert flags
+ */
+#define STITCH_PROCESSED 1
+#define STITCH_STITCHABLE 2
+#define STITCH_SELECTED 4
+#define STITCH_EDGE_PLUS 8
+#define STITCH_UV_SELECTED 16
+
/* Previewer stuff (see uvedit_intern.h for more info) */
static StitchPreviewer *_stitch_preview;
+typedef struct EdgeStitchData {
+ /* each edge corresponds to a UVVertMap, This is a hack I know, but essentially the same data
+ * will be used anyway */
+ int vmapPosition;
+ /* indices to uvVertmap for fast access */
+ int uvVertMap1Index, uvVertMap2Index;
+ /* */
+
+}EdgeStitchData;
+
/* constructor */
static StitchPreviewer * stitch_preview_init(void)
{
@@ -1246,8 +1266,6 @@
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();
@@ -1262,6 +1280,7 @@
/* 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;
@@ -1273,17 +1292,17 @@
editFace->tmp.l = -1;
}
- /* If mode is edge mode initialize the edge position on preview buffer to -1 (invalid) */
- if(state->mode == EDGE_STITCH){
- for(editEdge = state->em->edges.first; editEdge; editEdge = editEdge->next){
- editEdge->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");
+ /* Vert stitching case */
if(state->mode == VERT_STITCH){
+ /* This holds uv's that must be updated if the initial uv is stitchable. */
+ UvMapVert **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");
+
+
/* 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);
@@ -1316,9 +1335,9 @@
}
}
- uv_average[averageIndex].count = 1;
- uv_average[averageIndex].uv[0] = mt->uv[i][0];
- uv_average[averageIndex].uv[1] = mt->uv[i][1];
+ uv_average[averageIndex].count ++;
+ uv_average[averageIndex].uv[0] += mt->uv[i][0];
+ uv_average[averageIndex].uv[1] += mt->uv[i][1];
for(mv_iter = vmap->vert[vt->tmp.t], iter = 0; mv_iter; mv_iter = mv_iter->next){
MTFace *tmptface;
@@ -1400,12 +1419,85 @@
}
}
}
+
+ MEM_freeN(commonVertMaps);
+
+ /* Edge stitching case */
} else {
+ /* Here we store the indices corresponding to UvMapVerts that contain the first vertex of the edge.*/
+ int *faceStack = MEM_mallocN(state->em->totface*sizeof(float)*8, "quad_uv_stitch_prev");
+ GHashIterator* edgeIterator = BLI_ghashIterator_new(state->edges);
+
+ for(; !BLI_ghashIterator_isDone(edgeIterator); BLI_ghashIterator_step(edgeIterator)){
+ /* simple check to see which of the two face vertices corresponds to the original */
+ char vertCheck = 0;
+ EditVert *v1, *v2;
+ UvMapVert *mapVert;
+ int stackSize = 0;
+ /* initialize position in preview buffer */
+ editEdge->tmp.l = -1;
+ editEdge = BLI_ghashIterator_getKey(edgeIterator);
+
+ v1 = editEdge->v1;
+ v2 = editEdge->v2;
+
+ /* search for faces with the corresponding UV's*/
+ for(mapVert = vmap->vert[v1->tmp.t]; mapVert; mapVert = mapVert->next){
+ int nverts;
+ efa = faceArray[mapVert->f];
+ nverts = efa->v4 ? 4 : 3;
+ if((vertCheck = (*(&efa->v1 + (mapVert->tfindex + 1)%nverts) == v2)) || (*(&efa->v1 + (mapVert->tfindex + nverts - 1)%nverts) == v2)){
+ mapVert->flag |= (vertCheck) ? STITCH_EDGE_PLUS : 0;
+ faceStack[stackSize++] = mapVert - vmap->buf;
+ }
+ }
+
+ /* Check if faces found comply with stitchability restrictions */
+ for(i = 0; i < stackSize; i++)
+ {
+ int faceIter;
+ float uv1[2][2];
+ int nverts;
+ mapVert = vmap->buf + faceStack[i];
+ editFace = faceArray[mapVert->f];
+ nverts = (editFace->v4)? 4 : 3;
+ mt = CustomData_em_get(&state->em->fdata, editFace->data, CD_MTFACE);
+
+ /* Take uv's of first face */
+ uv1[0][0] = mt->uv[mapVert->tfindex][0];
+ uv1[0][1] = mt->uv[mapVert->tfindex][1];
+ uv1[1][0] = (mapVert->flag & STITCH_EDGE_PLUS)? mt->uv[(mapVert->tfindex + 1)%nverts][0] : mt->uv[(mapVert->tfindex + nverts - 1)%nverts][0];
+ uv1[1][1] = (mapVert->flag & STITCH_EDGE_PLUS)? mt->uv[(mapVert->tfindex + 1)%nverts][1] : mt->uv[(mapVert->tfindex + nverts - 1)%nverts][1];
+
+ /* iterate through all of the rest faces and check if they are */
+ for(faceIter = i+1; faceIter < stackSize; faceIter++){
+ float uv2[2][2];
+ MTFace *tmptface;
+ UvMapVert *mapVertIter = vmap->buf + faceStack[faceIter];
+ efa = faceArray[mapVertIter->f];
+ nverts = (efa->v4)? 4 : 3;
+
+ tmptface = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
+
+ /* Take uv's of first face */
+ uv2[0][0] = tmptface->uv[mapVertIter->tfindex][0];
+ uv2[0][1] = tmptface->uv[mapVertIter->tfindex][1];
+ uv2[1][0] = (mapVertIter->flag & STITCH_EDGE_PLUS)? tmptface->uv[(mapVertIter->tfindex + 1)%nverts][0] : tmptface->uv[(mapVertIter->tfindex + nverts - 1)%nverts][0];
+ uv2[1][1] = (mapVertIter->flag & STITCH_EDGE_PLUS)? tmptface->uv[(mapVertIter->tfindex + 1)%nverts][1] : tmptface->uv[(mapVertIter->tfindex + nverts - 1)%nverts][1];
+
+ /* Actual check */
+ if(1)
+ {
+
+ }
+ }
+ }
+ }
+
+ BLI_ghashIterator_free(edgeIterator);
}
- MEM_freeN(commonVertMaps);
-
if(!final)
{
/* Initialize the preview buffers */
@@ -1512,6 +1604,7 @@
stitch_state->limitDist = RNA_float_get(op->ptr, "limit");
stitch_state->em = em = BKE_mesh_get_editmesh((Mesh*)obedit->data);
stitch_state->mode = VERT_STITCH;
+ stitch_state->edges = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "stitch edge selection hash");
EM_init_index_arrays(stitch_state->em, 0, 0, 1);
stitch_state->vmap = EM_make_uv_vert_map(stitch_state->em, 1, 0, limit);
@@ -1558,6 +1651,7 @@
/* remember to set vertices used for redo operator in an RNA array or something */
EM_free_uv_vert_map(stitch_state->vmap);
+ BLI_ghash_free(stitch_state->edges, NULL, NULL);
BKE_mesh_end_editmesh(obedit->data, stitch_state->em);
@@ -1659,8 +1753,12 @@
Scene *scene= CTX_data_scene(C);
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
- if(stitch_state->mode == VERT_STITCH)
+ if(stitch_state->mode == VERT_STITCH){
find_nearest_uv_vert(scene, ima, stitch_state->em, co, NULL, &hit);
+ }
+ else{
+ find_nearest_uv_edge(scene, ima, stitch_state->em, co, &hit);
+ }
if(hit.efa)
{
@@ -1675,9 +1773,12 @@
else
tface->flag |= TF_SEL_MASK(hit.uv);
}
- if(stitch_state->mode == EDGE_STITCH)
+ else
{
-
+ EditEdge *edge = *(&hit.efa->e1 + hit.edge);
+ if(!BLI_ghash_haskey(stitch_state->edges,edge)){
+ BLI_ghash_insert(stitch_state->edges, edge, NULL);
+ }
}
}
stitch_process_data(stitch_state, 0, scene);
More information about the Bf-blender-cvs
mailing list