[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36152] branches/bmesh/blender/source/ blender: =bmesh=
Joseph Eagar
joeedh at gmail.com
Wed Apr 13 23:48:17 CEST 2011
Revision: 36152
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36152
Author: joeedh
Date: 2011-04-13 21:48:16 +0000 (Wed, 13 Apr 2011)
Log Message:
-----------
=bmesh=
Edge slide now handles facedata (e.g. sliding within uv
space), including multires.
Modified Paths:
--------------
branches/bmesh/blender/source/blender/blenkernel/intern/customdata.c
branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h
branches/bmesh/blender/source/blender/bmesh/bmesh.h
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c
branches/bmesh/blender/source/blender/bmesh/operators/bevel.c
branches/bmesh/blender/source/blender/editors/mesh/knifetool.c
branches/bmesh/blender/source/blender/editors/space_view3d/drawmesh.c
branches/bmesh/blender/source/blender/editors/transform/transform.c
branches/bmesh/blender/source/blender/editors/transform/transform.h
Modified: branches/bmesh/blender/source/blender/blenkernel/intern/customdata.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/customdata.c 2011-04-13 15:30:26 UTC (rev 36151)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/customdata.c 2011-04-13 21:48:16 UTC (rev 36152)
@@ -589,6 +589,7 @@
static void layerValidate_mdisps(void *data, int sub_elements)
{
+#if 0
MDisps *disps = data;
if(disps->disps) {
int corners = multires_mdisp_corners(disps);
@@ -599,6 +600,7 @@
disps->disps = BLI_cellalloc_calloc(3*disps->totdisp*sizeof(float), "layerValidate_mdisps");
}
}
+#endif
}
static void layerFree_mdisps(void *data, int count, int UNUSED(size))
Modified: branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h 2011-04-13 15:30:26 UTC (rev 36151)
+++ branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h 2011-04-13 21:48:16 UTC (rev 36152)
@@ -36,11 +36,13 @@
#include "MEM_guardedalloc.h"
#include "BLO_sys_types.h"
#include "BLI_utildefines.h"
+#include <string.h>
extern unsigned int hashsizes[];
#define NONHASH -25436536
-typedef struct entry {intptr_t key; void *val;} entry;
+typedef struct entry {uintptr_t key; void *val;} entry;
+/*how much stack space to use before dynamically allocating memory*/
#define SMSTACKSIZE 521
typedef struct SmallHash {
entry *table, _stacktable[SMSTACKSIZE], _copytable[SMSTACKSIZE];
@@ -50,6 +52,11 @@
int size;
} SmallHash;
+typedef struct SmallHashIter {
+ SmallHash *hash;
+ int i;
+} SmallHashIter;
+
/*CELL_UNUSED means this cell is inside a key series, while CELL_FREE
means this cell terminates a key series.
@@ -89,7 +96,7 @@
MEM_freeN(hash->table);
}
-BM_INLINE void BLI_smallhash_insert(SmallHash *hash, intptr_t key, void *item)
+BM_INLINE void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item)
{
int h, hoff=1;
@@ -145,7 +152,7 @@
hash->used++;
}
-BM_INLINE void BLI_smallhash_remove(SmallHash *hash, intptr_t key)
+BM_INLINE void BLI_smallhash_remove(SmallHash *hash, uintptr_t key)
{
int h, hoff=1;
@@ -165,7 +172,7 @@
hash->table[h].val = CELL_UNUSED;
}
-BM_INLINE void *BLI_smallhash_lookup(SmallHash *hash, intptr_t key)
+BM_INLINE void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key)
{
int h, hoff=1;
@@ -187,7 +194,7 @@
}
-BM_INLINE int BLI_smallhash_haskey(SmallHash *hash, intptr_t key)
+BM_INLINE int BLI_smallhash_haskey(SmallHash *hash, uintptr_t key)
{
int h = ABS(key), hoff=1;
key = ABS(key);
@@ -211,4 +218,29 @@
return hash->used;
}
+BM_INLINE void *BLI_smallhash_iternext(SmallHashIter *iter, uintptr_t *key)
+{
+ while (iter->i < iter->hash->size) {
+ if (iter->hash->table[iter->i].val != CELL_UNUSED && iter->hash->table[iter->i].val != CELL_FREE) {
+ if (key)
+ *key = iter->hash->table[iter->i].key;
+
+ iter->i++;
+ return iter->hash->table[iter->i-1].val;
+ }
+
+ iter->i++;
+ }
+
+ return NULL;
+}
+
+BM_INLINE void *BLI_smallhash_iternew(SmallHash *hash, SmallHashIter *iter, uintptr_t *key)
+{
+ iter->hash = hash;
+ iter->i = 0;
+
+ return BLI_smallhash_iternext(iter, key);
+}
+
#endif // BLI_SMALLHASH_H
Modified: branches/bmesh/blender/source/blender/bmesh/bmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh.h 2011-04-13 15:30:26 UTC (rev 36151)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh.h 2011-04-13 21:48:16 UTC (rev 36152)
@@ -219,6 +219,11 @@
(e.g. if the vert is part of a wire edge, etc).*/
int BM_Dissolve_Vert ( BMesh *bm, BMVert *v );
+/*Projects co onto face f, and returns true if it is inside
+ the face bounds. Note that this uses a best-axis projection
+ test, instead of projecting co directly into f's orientation
+ space, so there might be accuracy issues.*/
+int BM_Point_In_Face(BMesh *bm, BMFace *f, float co[3]);
/*Interpolation*/
@@ -228,7 +233,8 @@
/*projects a single loop, target, onto source for customdata interpolation. multires is handled.
if do_vertex is true, target's vert data will also get interpolated.*/
-void BM_loop_interp_from_face(BMesh *bm, BMLoop *target, BMFace *source, int do_vertex);
+void BM_loop_interp_from_face(BMesh *bm, BMLoop *target, BMFace *source,
+ int do_vertex, int do_multires);
/*smoothes boundaries between multires grids, including some borders in adjacent faces*/
void BM_multires_smooth_bounds(BMesh *bm, BMFace *f);
Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c 2011-04-13 15:30:26 UTC (rev 36151)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c 2011-04-13 21:48:16 UTC (rev 36152)
@@ -657,17 +657,18 @@
bmesh_loop_interp_mdisps(bm, target, source);
}
-void BM_loop_interp_from_face(BMesh *bm, BMLoop *target, BMFace *source, int do_vertex)
+void BM_loop_interp_from_face(BMesh *bm, BMLoop *target, BMFace *source,
+ int do_vertex, int do_multires)
{
BMLoop *l;
void **blocks=NULL;
void **vblocks=NULL;
- float (*cos)[3]=NULL, *w=NULL, cent[3] = {0.0f, 0.0f, 0.0f};
+ float (*cos)[3]=NULL, co[3], *w=NULL, cent[3] = {0.0f, 0.0f, 0.0f};
BLI_array_staticdeclare(cos, 64);
BLI_array_staticdeclare(w, 64);
BLI_array_staticdeclare(blocks, 64);
BLI_array_staticdeclare(vblocks, 64);
- int i;
+ int i, xn, yn, zn, ax, ay;
BM_Copy_Attributes(bm, bm, source, target->f);
@@ -686,18 +687,37 @@
l = l->next;
} while (l != bm_firstfaceloop(source));
+ /* find best projection of face XY, XZ or YZ: barycentric weights of
+ the 2d projected coords are the same and faster to compute */
+ xn= (float)fabs(source->no[0]);
+ yn= (float)fabs(source->no[1]);
+ zn= (float)fabs(source->no[2]);
+ if(zn>=xn && zn>=yn) {ax= 0; ay= 1;}
+ else if(yn>=xn && yn>=zn) {ax= 0; ay= 2;}
+ else {ax= 1; ay= 2;}
+
/*scale source face coordinates a bit, so points sitting directonly on an
edge will work.*/
mul_v3_fl(cent, 1.0f/(float)source->len);
for (i=0; i<source->len; i++) {
- float vec[3];
+ float vec[3], tmp[3];
sub_v3_v3v3(vec, cent, cos[i]);
- mul_v3_fl(vec, 0.0001);
+ mul_v3_fl(vec, 0.001);
add_v3_v3(cos[i], vec);
+
+ copy_v3_v3(tmp, cos[i]);
+ cos[i][0] = tmp[ax];
+ cos[i][1] = tmp[ay];
+ cos[i][2] = 0.0;
}
+
/*interpolate*/
- interp_weights_poly_v3(w, cos, source->len, target->v->co);
+ co[0] = target->v->co[ax];
+ co[1] = target->v->co[ay];
+ co[2] = 0.0f;
+
+ interp_weights_poly_v3(w, cos, source->len, co);
CustomData_bmesh_interp(&bm->ldata, blocks, w, NULL, source->len, target->head.data);
if (do_vertex)
CustomData_bmesh_interp(&bm->vdata, vblocks, w, NULL, source->len, target->v->head.data);
@@ -706,8 +726,10 @@
BLI_array_free(w);
BLI_array_free(blocks);
- if (CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
- bmesh_loop_interp_mdisps(bm, target, source);
+ if (do_multires) {
+ if (CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
+ bmesh_loop_interp_mdisps(bm, target, source);
+ }
}
}
Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c 2011-04-13 15:30:26 UTC (rev 36151)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c 2011-04-13 21:48:16 UTC (rev 36152)
@@ -310,13 +310,13 @@
l = bm_firstfaceloop(f);
do {
- BM_loop_interp_from_face(bm, l, of, 0);
+ BM_loop_interp_from_face(bm, l, of, 0, 1);
l = l->next;
} while (l != bm_firstfaceloop(f));
l = bm_firstfaceloop(nf);
do {
- BM_loop_interp_from_face(bm, l, of, 0);
+ BM_loop_interp_from_face(bm, l, of, 0, 1);
l = l->next;
} while (l != bm_firstfaceloop(nf));
Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c 2011-04-13 15:30:26 UTC (rev 36151)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c 2011-04-13 21:48:16 UTC (rev 36152)
@@ -547,69 +547,106 @@
int linecrossesf(float *v1, float *v2, float *v3, float *v4)
{
int w1, w2, w3, w4, w5 /*, ret*/;
+ float mv1[2], mv2[2], mv3[2], mv4[2];
-/* int test1_a, test1_a, test2_a, test2_a;
-
- test1_a = check_tri_clock_dir(l1p1, l1p2, l2p1);
- test1_b = check_tri_clock_dir(l1p1, l1p2, l2p2);
- if (test1_a != test1_b)
- {
- test2_a = check_tri_clock_dir(l2p1, l2p2, l1p1);
- test2_b = check_tri_clock_dir(l2p1, l2p2, l1p2);
- if (test2_a != test2_b)
- {
- return 1;
- }
- }*/
- /*w1 = testedgesidef(v1, v2, v3);
- w2 = testedgesidef(v1, v2, v4);
- if(w1 != w2) {
- w3 = testedgesidef(v3, v4, v1);
- w4 = testedgesidef(v3, v4, v2);
- if (w3 != w4) return 1;
- }
-
- return 0;*/
-
- /*w1 = testedgesidef(v1, v3, v4);
- w2 = testedgesidef(v2, v3, v4);
- w3 = testedgesidef(v3, v1, v2);
- w4 = testedgesidef(v4, v1, v2);
+ /*now test winding*/
+ w1 = testedgesidef(v1, v3, v2);
+ w2 = testedgesidef(v2, v4, v1);
+ w3 = !testedgesidef(v1, v2, v3);
+ w4 = testedgesidef(v3, v2, v4);
+ w5 = !testedgesidef(v3, v1, v4);
- return (w1 == w2) && (w2 == w3) && (w3 == w4);*/
-
+ if (w1 == w2 && w2 == w3 && w3 == w4 && w4==w5)
+ return 1;
+
+#define GETMIN2_AXIS(a, b, ma, mb, axis) ma[axis] = MIN2(a[axis], b[axis]), mb[axis] = MAX2(a[axis], b[axis])
+#define GETMIN2(a, b, ma, mb) GETMIN2_AXIS(a, b, ma, mb, 0); GETMIN2_AXIS(a, b, ma, mb, 1);
+
+ GETMIN2(v1, v2, mv1, mv2);
+ GETMIN2(v3, v4, mv3, mv4);
+
/*do an interval test on the x and y axes*/
/*first do x axis*/
- #define T 0.01
+ #define T FLT_EPSILON*15
if (ABS(v1[1]-v2[1]) < T && ABS(v3[1]-v4[1]) < T &&
- ABS(v1[1]-v3[1]) < T) {
- if (v3[0] >= v1[0] && v3[0] <= v2[0])
- return 1;
- if (v4[0] >= v1[0] && v4[0] <= v2[0])
- return 1;
- if (v3[0] <= v1[0] && v4[0] >= v2[0])
- return 1;
+ ABS(v1[1]-v3[1]) < T)
+ {
+ return (mv4[0] >= mv1[0] && mv3[0] <= mv2[0]);
}
/*now do y axis*/
if (ABS(v1[0]-v2[0]) < T && ABS(v3[0]-v4[0]) < T &&
- ABS(v1[0]-v3[0]) < T) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list