[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48879] branches/soc-2012-sushi/source/ blender: add UI for bridge
Alexander Mokhov
alexander.mokhov at gmail.com
Fri Jul 13 00:42:03 CEST 2012
Revision: 48879
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48879
Author: redtriangle
Date: 2012-07-12 22:42:02 +0000 (Thu, 12 Jul 2012)
Log Message:
-----------
add UI for bridge
fix error with calculate normals
Modified Paths:
--------------
branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c
branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_connect.c
branches/soc-2012-sushi/source/blender/editors/mesh/editmesh_tools.c
Modified: branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c 2012-07-12 20:10:41 UTC (rev 48878)
+++ branches/soc-2012-sushi/source/blender/bmesh/intern/bmesh_opdefines.c 2012-07-12 22:42:02 UTC (rev 48879)
@@ -440,6 +440,11 @@
//{{BMO_OP_SLOT_ELEMENT_BUF, "edges"}, /* input edge */
{{BMO_OP_SLOT_ELEMENT_BUF, "edgefacein"}, /* input faces and edge */
{BMO_OP_SLOT_ELEMENT_BUF, "faceout"}, /* new face */
+
+ {BMO_OP_SLOT_INT, "segmentation"}, /* input segmentation param */
+ {BMO_OP_SLOT_INT, "interpolation"}, /* input interpolation param */
+ {BMO_OP_SLOT_FLT, "strenght"}, /* input strenght param */
+
{0, /* null-terminating sentinel */}},
bmo_bridge_loops_exec,
0,
Modified: branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_connect.c
===================================================================
--- branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_connect.c 2012-07-12 20:10:41 UTC (rev 48878)
+++ branches/soc-2012-sushi/source/blender/bmesh/operators/bmo_connect.c 2012-07-12 22:42:02 UTC (rev 48879)
@@ -26,6 +26,7 @@
#include "MEM_guardedalloc.h"
+#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_array.h"
#include "BLI_utildefines.h"
@@ -34,15 +35,36 @@
#include "intern/bmesh_operators_private.h" /* own include */
+
#define VERT_INPUT 1
#define EDGE_OUT 1
#define FACE_NEW 2
#define EDGE_MARK 4
#define EDGE_DONE 8
-#define FACE_MARK 1
-#define EDGE_CONNECTED 7
+#define FACE_MARK 1
+#define EDGE_CONNECTED 7
+#define EDGE_NON_CONNECTED 9
+#define LINEAR_INTER 2
+#define CUBIC_INTER 4
+
+typedef struct VertexItem{
+ struct VertexItem *next, *prev;
+ BMVert *v;
+}VertexItem;
+
+
+typedef struct BridgeParams{
+ ListBase newVertices; // list of new vertex
+ int inter; // interpolation
+ int seg; // segmentation param
+ float strenght;
+ float centrod1[3]; // coordinate of centrod input loops
+ float centrod2[3];
+} BridgeParams;
+
+
void bmo_connect_verts_exec(BMesh *bm, BMOperator *op)
{
BMIter iter, liter;
@@ -213,7 +235,8 @@
*l2 = BM_iter_at_index(bm, BM_LOOPS_OF_VERT, v2, 0);
}
-//TODO: rename and comented
+//TODO: rename function
+// return count entry element into list
int bmo_bridge_array_entry_elem(BMEdge **list, int size, BMEdge *elem)
{
int i = 0, count = 0;
@@ -249,26 +272,90 @@
mul_v3_fl(center, 1.0f/vert_count);
}
+
+BMVert* bridge_check_existing_vertex(BridgeParams *bp, float co[3])
+{
+ float epsilon = 1e-6;
+ BMVert *vert = NULL;
+ VertexItem *item;
+ for (item = bp->newVertices.first; item; item = item->next)
+ {
+ if (compare_v3v3(item->v->co, co, epsilon))
+ vert = item->v;
+ }
+ return vert;
+}
/*
-* this function return vertex of linear interpolation
+* this function return vertex of linear interpolation between v1 and v2
*/
-BMVert* get_linear_seg(BMesh *bm, int seg, int n, BMVert *v1, BMVert *v2)
+BMVert* get_linear_seg(BMesh *bm, BridgeParams* bp, int n, BMVert *v1, BMVert *v2)
{
float co[3];
BMVert *v;
- co[0] = v1->co[0] + (v2->co[0]-v1->co[0])*n / seg;
- co[1] = v1->co[1] + (v2->co[1]-v1->co[1])*n / seg;
- co[2] = v1->co[2] + (v2->co[2]-v1->co[2])*n / seg;
- // TODO проверка на то что уже это вершина существует
+ VertexItem *item;
- v = BM_vert_create(bm, co, NULL);
- //BLI_array_append(list_exist_vert, v);
+ co[0] = v1->co[0] + (v2->co[0]-v1->co[0])*n / bp->seg;
+ co[1] = v1->co[1] + (v2->co[1]-v1->co[1])*n / bp->seg;
+ co[2] = v1->co[2] + (v2->co[2]-v1->co[2])*n / bp->seg;
+
+ v = bridge_check_existing_vertex(bp, co);
+ if (!v)
+ {
+ item = (VertexItem*)MEM_callocN(sizeof(VertexItem), "VertexItem");
+ item->v = BM_vert_create(bm, co, NULL);
+ BLI_addtail(&bp->newVertices, item);
+ v = item->v;
+ }
return v;
}
-BMVert* get_cubic_seg(BMesh *bm, int seg, int n, BMVert *v1, BMVert *v2){
- //float co[3];
+/*
+* this function return vertex of cubic interpolation between v1 and v2
+* Parametric cubic spline in Hermite form
+* 0 <= t <= 1
+*/
+BMVert* get_cubic_seg(BMesh *bm, BridgeParams *bp, int n, BMVert *v1, BMVert *v2){
BMVert *v = NULL;
+ VertexItem *item;
+ float t, co[3], r1[3], r2[3], mn[3];
+ t = (float) (n) / bp->seg;
+
+ //sub_v3_v3v3(r1, bp->centrod2 , v1->co);
+ //sub_v3_v3v3(r2, v2->co, bp->centrod1);
+
+ sub_v3_v3v3(r1, bp->centrod1 , v1->co);
+ sub_v3_v3v3(r2, v2->co, bp->centrod2);
+ //sub_v3_v3v3(mn, v1->co, v2->co);
+
+ //mul_v3_fl(r1, bp->strenght);
+ //mul_v3_fl(r2, bp->strenght);
+ //add_v3_v3(r1, mn);
+ //add_v3_v3(r2, mn);
+
+ mul_v3_fl(r1, 2*asin(bp->strenght));
+ mul_v3_fl(r2, 2*asin(bp->strenght));
+
+ co[0] = v1->co[0] * (2 * t * t * t - 3 * t * t + 1) +
+ v2->co[0] * (-2 * t * t * t + 3 * t * t ) +
+ r1[0] * (t * t * t - 2 * t * t + t) +
+ r2[0] * (t * t * t - t * t);
+ co[1] = v1->co[1] * (2 * t * t * t - 3 * t * t + 1) +
+ v2->co[1] * (-2 * t * t * t + 3 * t * t ) +
+ r1[1] * (t * t * t - 2 * t * t + t) +
+ r2[1] * (t * t * t - t * t);
+ co[2] = v1->co[2] * (2 * t * t * t - 3 * t * t + 1) +
+ v2->co[2] * (-2 * t * t * t + 3 * t * t ) +
+ r1[2] * (t * t * t - 2 * t * t + t) +
+ r2[2] * (t * t * t - t * t);
+
+ v = bridge_check_existing_vertex(bp, co);
+ if (!v)
+ {
+ item = (VertexItem*)MEM_callocN(sizeof(VertexItem), "VertexItem");
+ item->v = BM_vert_create(bm, co, NULL);
+ BLI_addtail(&bp->newVertices, item);
+ v = item->v;
+ }
return v;
}
@@ -279,14 +366,16 @@
return cos_ab;
}
/*
- create face betwin two edge
+ create polygons between two edge
*/
-void bmo_edge_face_connect(BMesh *bm, BMEdge *e1, BMEdge *e2, BMFace *f_example, BMVert** list_exist_vert, int count)
+void bmo_edge_face_connect(BMesh *bm, BridgeParams* bp, BMEdge *e1, BMEdge *e2, BMFace *f_example)
{
- int seg=5, i;
+ int i;
+ BMVert *vv[4];
BMVert *v1, *v2, *v3, *v4;
BMVert *vi1, *vi2, *vi3, *vi4; // input vertex
- float vect1[3], vect2[3], vect3[3], vect4[3];
+ BMFace *f;
+ float vect1[3], vect2[3], vect3[3], vect4[3], normalA[3], normalB[3], normalVector[3];
float vp1[3], vp2[3], vp3[3], vp4[3];
vi1 = e1->v1;
@@ -304,6 +393,14 @@
cross_v3_v3v3(vp2, vect2, vect3);
cross_v3_v3v3(vp3, vect3, vect4);
cross_v3_v3v3(vp4, vect4, vect1);
+// calculate normal vector
+ mid_v3_v3v3(normalA, bp->centrod1, bp->centrod2);
+ vv[0] = vi1;
+ vv[1] = vi2;
+ vv[2] = vi3;
+ vv[3] = vi4;
+ get_centroid(vv, 4, normalB);
+ sub_v3_v3v3(normalVector, normalB, normalA);
// check direction cros produc result
if (!(get_cos_v3v3(vp1, vp2)>0 &&
@@ -316,49 +413,104 @@
vi3 = BM_edge_other_vert(e2,vi2);
vi4 = BM_edge_other_vert(e1,vi1);
}
-
// vi1 - v1 - v2 ... vi2
// | | | |
// vi4 .. v4 - v3 ... vi3
- v1 = vi1; v2 = vi2; v3 = vi3; v4 = vi4;
- if (seg > 1){
- for (i = 1; i <= seg; i++){
- v2 = get_linear_seg (bm, seg, i, vi1, vi2);
- v3 = get_linear_seg(bm, seg, i, vi4, vi3);
-
- BM_face_create_quad_tri(bm, v1, v2, v3, v4, f_example, TRUE);
+ v1 = vi1;
+ v2 = vi2;
+ v3 = vi3;
+ v4 = vi4;
+ if (bp->seg > 1){
+ for (i = 1; i < bp->seg; i++){
+ if (bp->inter == LINEAR_INTER)
+ {
+ v2 = get_linear_seg (bm, bp, i, vi1, vi2);
+ v3 = get_linear_seg(bm, bp, i, vi4, vi3);
+ }
+ if (bp->inter == CUBIC_INTER)
+ {
+ v2 = get_cubic_seg (bm, bp, i, vi1, vi2);
+ v3 = get_cubic_seg(bm, bp, i, vi4, vi3);
+ }
+ f = BM_face_create_quad_tri(bm, v1, v2, v3, v4, f_example, TRUE);
+ BM_face_normal_update(f);
+ //check normal BM_face_normal_flip(bm, f);
+ if (get_cos_v3v3(f->no, normalVector)<0)
+ BM_face_normal_flip(bm, f);
v1 = v2;
v4 = v3;
}
+ f = BM_face_create_quad_tri(bm, v1, vi2, vi3, v4, f_example, TRUE);
+ BM_face_normal_update(f);
+ if (get_cos_v3v3(f->no, normalVector)<0)
+ BM_face_normal_flip(bm, f);
}
else {
- BM_face_create_quad_tri(bm, v1, v2, v3, v4, f_example, TRUE);
+ f = BM_face_create_quad_tri(bm, v1, v2, v3, v4, f_example, TRUE);
+ BM_face_normal_update(f);
+ if (get_cos_v3v3(f->no, normalVector)<0)
+ BM_face_normal_flip(bm, f);
}
}
-
-void bmo_edge_vert_connect(BMesh *bm, BMEdge *e, BMVert *v, BMFace *f_example)
+/*
+This function create polygons between edge and vert
+*/
+void bmo_edge_vert_connect(BMesh *bm, BridgeParams *bp, BMEdge *e, BMVert *v, BMFace *f_example)
{
- int seg = 5, i;
- BMVert *v1, *v2, *v3, *v4;
+ BMVert *v1, *v2, *v3, *v4, *vv[3];
+ BMFace *f;
+ float normalA[3], normalB[3], normalVector[3];
+ int i;
v1 = e->v1;
v2 = v;
- v3 = 0;
- v4 = BM_edge_other_vert(e, e->v1);;
- if (seg > 1){
- for (i = 1; i < seg; i++){
- v2 = get_linear_seg(bm, seg, i, e->v1, v);
- v3 = get_linear_seg(bm, seg, i, BM_edge_other_vert(e, e->v1), v);
- BM_face_create_quad_tri(bm, v1, v2, v3, v4, f_example, TRUE);
+ v3 = NULL;
+ v4 = BM_edge_other_vert(e, e->v1);
+
+ // calculate normal vector
+ mid_v3_v3v3(normalA, bp->centrod1, bp->centrod2);
+ vv[0] = v1;
+ vv[1] = v2;
+ vv[2] = v4;
+ get_centroid(vv, 3, normalB);
+ sub_v3_v3v3(normalVector, normalB, normalA);
+
+ if (bp->seg > 1){
+ for (i = 1; i < bp->seg; i++){
+ if (bp->inter == LINEAR_INTER)
+ {
+ v2 = get_linear_seg(bm, bp, i, v, e->v1);
+ v3 = get_linear_seg(bm, bp, i, v, BM_edge_other_vert(e, e->v1));
+ }
+ if (bp->inter == CUBIC_INTER)
+ {
+ v2 = get_cubic_seg (bm, bp, i, v, e->v1);
+ v3 = get_cubic_seg (bm, bp, i, v, BM_edge_other_vert(e, e->v1));
+ }
+ if (i == 1)
+ f = BM_face_create_quad_tri(bm, v2, v, v3, NULL, f_example, TRUE);
+ else
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list