[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35598] branches/bmesh/blender/source/ blender: =bmesh=
Joseph Eagar
joeedh at gmail.com
Thu Mar 17 23:59:54 CET 2011
Revision: 35598
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35598
Author: joeedh
Date: 2011-03-17 22:59:54 +0000 (Thu, 17 Mar 2011)
Log Message:
-----------
=bmesh=
Bevel! Implemented bevel (from scratch). Man is
this tool way cooler then I thought it was. Note that
uv/vcol interpolation is working (loop level data) but
vert/edge data (like vgroups) likely still needs
work.
Modified Paths:
--------------
branches/bmesh/blender/source/blender/blenkernel/intern/BME_tools.c
branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h
branches/bmesh/blender/source/blender/blenlib/intern/math_geom.c
branches/bmesh/blender/source/blender/bmesh/CMakeLists.txt
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_opdefines.c
branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h
branches/bmesh/blender/source/blender/editors/mesh/bmesh_tools.c
branches/bmesh/blender/source/blender/editors/mesh/loopcut.c
branches/bmesh/blender/source/blender/editors/mesh/mesh_intern.h
branches/bmesh/blender/source/blender/editors/mesh/mesh_ops.c
branches/bmesh/blender/source/blender/editors/space_view3d/view3d_edit.c
branches/bmesh/blender/source/blender/editors/uvedit/uvedit_ops.c
branches/bmesh/blender/source/blender/modifiers/intern/MOD_util.c
Added Paths:
-----------
branches/bmesh/blender/source/blender/bmesh/operators/bevel.c
Modified: branches/bmesh/blender/source/blender/blenkernel/intern/BME_tools.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/BME_tools.c 2011-03-17 22:49:46 UTC (rev 35597)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/BME_tools.c 2011-03-17 22:59:54 UTC (rev 35598)
@@ -41,11 +41,8 @@
#include "DNA_object_types.h"
#include "BLI_math.h"
-<<<<<<< .working
#include "BLI_cellalloc.h"
-=======
#include "BLI_utildefines.h"
->>>>>>> .merge-right.r35190
#include "BKE_bmesh.h"
Modified: branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h 2011-03-17 22:49:46 UTC (rev 35597)
+++ branches/bmesh/blender/source/blender/blenlib/BLI_smallhash.h 2011-03-17 22:59:54 UTC (rev 35598)
@@ -59,7 +59,7 @@
#define CELL_FREE ((void*)0x7FFFFFFD)
#define NONZERO(n) ((n) + !(n))
-#define HASHNEXT(h, hoff) ((h) + ((hoff=NONZERO(hoff*2)+1), hoff))
+#define HASHNEXT(h, hoff) ABS(((h) + ((hoff=NONZERO(hoff*2)+1), hoff)))
BM_INLINE void BLI_smallhash_init(SmallHash *hash)
{
@@ -92,7 +92,9 @@
BM_INLINE void BLI_smallhash_insert(SmallHash *hash, intptr_t key, void *item)
{
int h, hoff=1;
-
+
+ key = ABS(key);
+
if (hash->size < hash->used*3) {
int newsize = hashsizes[++hash->curhash];
entry *tmp;
@@ -145,7 +147,10 @@
BM_INLINE void BLI_smallhash_remove(SmallHash *hash, intptr_t key)
{
- int h = key, hoff=1;
+ int h, hoff=1;
+
+ key = ABS(key);
+ h = key;
while (hash->table[h % hash->size].key != key
|| hash->table[h % hash->size].val == CELL_UNUSED)
@@ -162,7 +167,10 @@
BM_INLINE void *BLI_smallhash_lookup(SmallHash *hash, intptr_t key)
{
- int h = key, hoff=1;
+ int h, hoff=1;
+
+ key = ABS(key);
+ h = key;
if (!hash->table)
return NULL;
@@ -181,7 +189,8 @@
BM_INLINE int BLI_smallhash_haskey(SmallHash *hash, intptr_t key)
{
- int h = key, hoff=1;
+ int h = ABS(key), hoff=1;
+ key = ABS(key);
if (!hash->table)
return 0;
Modified: branches/bmesh/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- branches/bmesh/blender/source/blender/blenlib/intern/math_geom.c 2011-03-17 22:49:46 UTC (rev 35597)
+++ branches/bmesh/blender/source/blender/blenlib/intern/math_geom.c 2011-03-17 22:59:54 UTC (rev 35598)
@@ -905,7 +905,7 @@
normalize_v3_v3(dir1, a);
normalize_v3_v3(dir2, b);
d = dot_v3v3(dir1, dir2);
- if (d == 1.0f || d == -1.0f) {
+ if (d >= 1.0-FLT_EPSILON*10 || d <= -1.0 + FLT_EPSILON*10) {
/* colinear */
return 0;
}
Modified: branches/bmesh/blender/source/blender/bmesh/CMakeLists.txt
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/CMakeLists.txt 2011-03-17 22:49:46 UTC (rev 35597)
+++ branches/bmesh/blender/source/blender/bmesh/CMakeLists.txt 2011-03-17 22:59:54 UTC (rev 35598)
@@ -58,6 +58,7 @@
)
set(SRC
+ operators/bevel.c
operators/bmesh_dupeops.c
operators/utils.c
operators/subdivideop.c
Modified: branches/bmesh/blender/source/blender/bmesh/bmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh.h 2011-03-17 22:49:46 UTC (rev 35597)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh.h 2011-03-17 22:59:54 UTC (rev 35598)
@@ -216,16 +216,23 @@
/*Interpolation*/
+
+/*projects target onto source for customdata interpolation. note: only
+ does loop customdata.*/
+void BM_face_interp_from_face(BMesh *bm, BMFace *target, BMFace *source);
+
+/*same as BM_face_interp_from_face, but only interpolates one loop, instead
+ of all loops in a face*/
+void BM_loop_interp_from_face(BMesh *bm, BMLoop *target, BMFace *source);
+
void BM_Data_Interp_From_Verts ( struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMVert *v, float fac );
void BM_Data_Facevert_Edgeinterp ( struct BMesh *bm, struct BMVert *v1, struct BMVert *v2, struct BMVert *v, struct BMEdge *e1, float fac );
-//void bmesh_data_interp_from_face(struct BMesh *bm, struct BMFace *source, struct BMFace *target);
void BM_add_data_layer ( BMesh *em, CustomData *data, int type );
void BM_add_data_layer_named ( BMesh *bm, CustomData *data, int type, char *name );
void BM_free_data_layer ( BMesh *em, CustomData *data, int type );
float BM_GetCDf(struct CustomData *cd, void *element, int type);
void BM_SetCDf(struct CustomData *cd, void *element, int type, float val);
-
/*computes the centroid of a face, using the center of the bounding box*/
int BM_Compute_Face_Center ( BMesh *bm, BMFace *f, float center[3] );
Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c 2011-03-17 22:49:46 UTC (rev 35597)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_interp.c 2011-03-17 22:59:54 UTC (rev 35598)
@@ -39,6 +39,7 @@
#include "BKE_utildefines.h"
#include "BLI_array.h"
+#include "BLI_math.h"
#include "bmesh.h"
#include "bmesh_private.h"
@@ -78,7 +79,6 @@
to the average of the face regions surrounding it.
*/
-//CustomData_bmesh_interp(&bm->ldata, src,w, NULL, 2, vloop->head.data);
void BM_Data_Vert_Average(BMesh *bm, BMFace *f)
{
@@ -175,13 +175,91 @@
}
}
-//static void bmesh_data_interp_from_face(BME_Mesh *bm, BMFace *source, BMFace *target)
-//{
-//
-//}
-/*insert BM_data_interp_from_face here for mean value coordinates...*/
+/**
+ * BM_data_interp_from_face
+ *
+ * projects target onto source, and pulls interpolated customdata from
+ * source.
+ *
+ * Returns -
+ * Nothing
+*/
+void BM_face_interp_from_face(BMesh *bm, BMFace *target, BMFace *source)
+{
+ BMLoop *l1, *l2;
+ void **blocks=NULL;
+ float (*cos)[3]=NULL, *w=NULL;
+ BLI_array_staticdeclare(cos, 64);
+ BLI_array_staticdeclare(w, 64);
+ BLI_array_staticdeclare(blocks, 64);
+
+ BM_Copy_Attributes(bm, bm, source, target);
+
+ l2 = bm_firstfaceloop(source);
+ do {
+ BLI_array_growone(cos);
+ copy_v3_v3(cos[BLI_array_count(cos)-1], l2->v->co);
+ BLI_array_growone(w);
+ BLI_array_append(blocks, l2->head.data);
+ l2 = l2->next;
+ } while (l2 != bm_firstfaceloop(source));
+
+ l1 = bm_firstfaceloop(target);
+ do {
+ interp_weights_poly_v3(w, cos, source->len, l1->v->co);
+ CustomData_bmesh_interp(&bm->ldata, blocks, w, NULL, BLI_array_count(blocks), l1->head.data);
+ l1 = l1->next;
+ } while (l1 != bm_firstfaceloop(target));
+
+ BLI_array_free(cos);
+ BLI_array_free(w);
+ BLI_array_free(blocks);
+}
+
+void BM_loop_interp_from_face(BMesh *bm, BMLoop *target, BMFace *source)
+{
+ BMLoop *l;
+ void **blocks=NULL;
+ float (*cos)[3]=NULL, *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);
+ int i;
+
+ BM_Copy_Attributes(bm, bm, source, target->f);
+
+ l = bm_firstfaceloop(source);
+ do {
+ BLI_array_growone(cos);
+ copy_v3_v3(cos[BLI_array_count(cos)-1], l->v->co);
+ add_v3_v3(cent, cos[BLI_array_count(cos)-1]);
+
+ BLI_array_append(w, 0.0f);
+ BLI_array_append(blocks, l->head.data);
+ l = l->next;
+ } while (l != bm_firstfaceloop(source));
+
+ /*scale source face coordinates a bit, so points sitting directonly on an
+ edge will work.*/
+ mul_v3_fl(cent, 1.0/source->len);
+ for (i=0; i<source->len; i++) {
+ float vec[3];
+ sub_v3_v3v3(vec, cent, cos[i]);
+ mul_v3_fl(vec, 0.01);
+ add_v3_v3(cos[i], vec);
+ }
+
+ /*interpolate*/
+ interp_weights_poly_v3(w, cos, source->len, target->v->co);
+ CustomData_bmesh_interp(&bm->ldata, blocks, w, NULL, source->len, target->head.data);
+
+ BLI_array_free(cos);
+ BLI_array_free(w);
+ BLI_array_free(blocks);
+}
+
static void update_data_blocks(BMesh *bm, CustomData *olddata, CustomData *data)
{
BMIter iter;
Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c 2011-03-17 22:49:46 UTC (rev 35597)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c 2011-03-17 22:59:54 UTC (rev 35598)
@@ -938,6 +938,22 @@
0,
};
+/*
+ Bevel
+
+ Bevels edges and vertices
+ */
+BMOpDefine def_bevel = {
+ "bevel",
+ {{BMOP_OPSLOT_ELEMENT_BUF, "geom"}, /* input edges and vertices */
+ {BMOP_OPSLOT_ELEMENT_BUF, "face_spans"}, /* new geometry */
+ {BMOP_OPSLOT_ELEMENT_BUF, "face_holes"}, /* new geometry */
+ {BMOP_OPSLOT_FLT, "percent"}, /* percentage to expand bevelled edges*/
+ {0} /*null-terminating sentinel*/},
+ bmesh_bevel_exec,
+ 0
+};
+
BMOpDefine *opdefines[] = {
&def_splitop,
&def_dupeop,
@@ -997,6 +1013,7 @@
&def_create_cone,
&def_create_cube,
&def_join_triangles,
+ &def_bevel,
};
int bmesh_total_ops = (sizeof(opdefines) / sizeof(void*));
Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h 2011-03-17 22:49:46 UTC (rev 35597)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators_private.h 2011-03-17 22:59:54 UTC (rev 35598)
@@ -68,5 +68,6 @@
void bmesh_create_grid_exec(BMesh *bm, BMOperator *op);
void bmesh_create_cube_exec(BMesh *bm, BMOperator *op);
void bmesh_jointriangles_exec(BMesh *bm, BMOperator *op);
+void bmesh_bevel_exec(BMesh *bm, BMOperator *op);
#endif
Added: branches/bmesh/blender/source/blender/bmesh/operators/bevel.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/bevel.c (rev 0)
+++ branches/bmesh/blender/source/blender/bmesh/operators/bevel.c 2011-03-17 22:59:54 UTC (rev 35598)
@@ -0,0 +1,704 @@
+#include "MEM_guardedalloc.h"
+
+#include "BKE_utildefines.h"
+
+#include "BLI_ghash.h"
+#include "BLI_memarena.h"
+#include "BLI_blenlib.h"
+#include "BLI_array.h"
+#include "BLI_math.h"
+#include "BLI_array.h"
+#include "BLI_utildefines.h"
+#include "BLI_smallhash.h"
+
+#include "bmesh.h"
+#include "bmesh_operators_private.h"
+
+#define BEVEL_FLAG 1
+#define BEVEL_DEL 2
+#define FACE_NEW 4
+#define EDGE_OLD 8
+#define FACE_OLD 16
+#define FACE_DONE 32
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list