[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37873] branches/soc-2011-avocado/blender/ source/blender: incremental commit to "splines to bmesh" tool.

Dan Walters dan683 at gmail.com
Mon Jun 27 20:31:35 CEST 2011


Revision: 37873
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37873
Author:   dan_w
Date:     2011-06-27 18:31:34 +0000 (Mon, 27 Jun 2011)
Log Message:
-----------
incremental commit to "splines to bmesh" tool. This commit adds primitive style creation of a bmesh based on gpencil strokes. At this stage, the tool generates edges and vertices only, no faces. UI calls a function in primitiveops.c which in turn creates a bmesh and initializes it with the gpencil stroke data.

Modified Paths:
--------------
    branches/soc-2011-avocado/blender/source/blender/bmesh/bmesh.h
    branches/soc-2011-avocado/blender/source/blender/bmesh/intern/bmesh_opdefines.c
    branches/soc-2011-avocado/blender/source/blender/bmesh/intern/bmesh_operators_private.h
    branches/soc-2011-avocado/blender/source/blender/bmesh/operators/primitiveops.c
    branches/soc-2011-avocado/blender/source/blender/editors/gpencil/gpencil_paint.c
    branches/soc-2011-avocado/blender/source/blender/editors/mesh/editbmesh_add.c
    branches/soc-2011-avocado/blender/source/blender/editors/mesh/editbmesh_bvh.h

Modified: branches/soc-2011-avocado/blender/source/blender/bmesh/bmesh.h
===================================================================
--- branches/soc-2011-avocado/blender/source/blender/bmesh/bmesh.h	2011-06-27 17:21:08 UTC (rev 37872)
+++ branches/soc-2011-avocado/blender/source/blender/bmesh/bmesh.h	2011-06-27 18:31:34 UTC (rev 37873)
@@ -302,7 +302,6 @@
 void bmesh_begin_edit(struct BMesh *bm, int flag);
 void bmesh_end_edit(struct BMesh *bm, int flag);
 
-
 #define bm_firstfaceloop(p) ((BMLoopList*)(p->loops.first))->first
 
 /*include the rest of the API*/

Modified: branches/soc-2011-avocado/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/soc-2011-avocado/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2011-06-27 17:21:08 UTC (rev 37872)
+++ branches/soc-2011-avocado/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2011-06-27 18:31:34 UTC (rev 37873)
@@ -940,6 +940,20 @@
 };
 
 /*
+  Create Mesh from Splines
+
+  Creates a mesh from splines by intersecting splines, cleaning, and filling with faces
+*/
+static BMOpDefine def_create_mesh_from_splines = {
+	"create_mesh_from_splines",
+	{{BMOP_OPSLOT_ELEMENT_BUF, "vertout"}, //output verts
+	{BMOP_OPSLOT_PNT, "frame"}, //spline frame
+	 {0, /*null-terminating sentinel*/}},
+	bmesh_create_mesh_from_splines,
+	0,
+};
+
+/*
   Bevel
 
   Bevels edges and vertices
@@ -1049,6 +1063,7 @@
 	&def_bevel,
 	&def_beautify_fill,
 	&def_triangle_fill,
+	&def_create_mesh_from_splines,
 };
 
 int bmesh_total_ops = (sizeof(opdefines) / sizeof(void*));

Modified: branches/soc-2011-avocado/blender/source/blender/bmesh/intern/bmesh_operators_private.h
===================================================================
--- branches/soc-2011-avocado/blender/source/blender/bmesh/intern/bmesh_operators_private.h	2011-06-27 17:21:08 UTC (rev 37872)
+++ branches/soc-2011-avocado/blender/source/blender/bmesh/intern/bmesh_operators_private.h	2011-06-27 18:31:34 UTC (rev 37873)
@@ -67,6 +67,7 @@
 void bmesh_create_uvsphere_exec(BMesh *bm, BMOperator *op);
 void bmesh_create_grid_exec(BMesh *bm, BMOperator *op);
 void bmesh_create_cube_exec(BMesh *bm, BMOperator *op);
+void bmesh_create_mesh_from_splines(BMesh *bm, BMOperator *op);
 void bmesh_jointriangles_exec(BMesh *bm, BMOperator *op);
 void bmesh_bevel_exec(BMesh *bm, BMOperator *op);
 void bmesh_beautify_fill_exec(BMesh *bm, BMOperator *op);

Modified: branches/soc-2011-avocado/blender/source/blender/bmesh/operators/primitiveops.c
===================================================================
--- branches/soc-2011-avocado/blender/source/blender/bmesh/operators/primitiveops.c	2011-06-27 17:21:08 UTC (rev 37872)
+++ branches/soc-2011-avocado/blender/source/blender/bmesh/operators/primitiveops.c	2011-06-27 18:31:34 UTC (rev 37873)
@@ -4,6 +4,7 @@
 #include "DNA_mesh_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_gpencil_types.h"
 
 #include "BLI_utildefines.h"
 
@@ -15,6 +16,7 @@
 #include "ED_mesh.h"
 
 #include "bmesh.h"
+#include "bmesh_class.h"
 #include "mesh_intern.h"
 #include "bmesh_private.h"
 
@@ -683,3 +685,53 @@
 
 	BMO_Flag_To_Slot(bm, op, "vertout", VERT_MARK, BM_VERT);
 }
+
+void bmesh_create_mesh_from_splines(BMesh *bm, BMOperator *op)
+{
+	bGPDstroke *gps, *gpsn;
+
+	float vec[3];
+
+	BMVert *bm_vertex;
+	BMVert *bm_previous;
+
+	int i;
+
+	BMVert *v1, *v2, *v3, *v4, *v5, *v6, *v7, *v8;// bin
+	float mat[4][4], off = 1.0f / 2.0f;// bin
+
+	bGPDframe* p_frame = BMO_Get_Pnt(op, "frame");
+
+	/* error checking */
+	if (p_frame == NULL) return;
+
+	/* iterate strokes */
+	for (gps = p_frame->strokes.first; gps; gps = gpsn)
+	{
+		gpsn = gps->next;
+
+		for(i = 0; i < gps->totpoints; i++)
+		{
+			vec[0] = gps->points[i].x;
+			vec[1] = gps->points[i].y;
+			vec[2] = gps->points[i].z;
+			bm_vertex = BM_Make_Vert(bm, vec, NULL);
+
+			if(i != 0)
+			{
+				// intersect line
+
+				// create edge
+				BM_Make_Edge(bm, bm_vertex, bm_previous, NULL, 0);
+			}
+			bm_previous = bm_vertex;
+		}
+	}
+	// intersect each spline segment with each other spline segment
+	// generate bmesh edge list, using start of spline, end of spline, intersections as vertices
+	// weld / merge vertices
+	// fill in faces
+	// clean up
+
+	BMO_Flag_To_Slot(bm, op, "vertout", VERT_MARK, BM_VERT);
+}

Modified: branches/soc-2011-avocado/blender/source/blender/editors/gpencil/gpencil_paint.c
===================================================================
--- branches/soc-2011-avocado/blender/source/blender/editors/gpencil/gpencil_paint.c	2011-06-27 17:21:08 UTC (rev 37872)
+++ branches/soc-2011-avocado/blender/source/blender/editors/gpencil/gpencil_paint.c	2011-06-27 18:31:34 UTC (rev 37873)
@@ -65,6 +65,8 @@
 
 #include "gpencil_intern.h"
 
+#include "../mesh/editbmesh_bvh.h"
+
 /* ******************************************* */
 /* 'Globals' and Defines */
 
@@ -1615,7 +1617,8 @@
 			bGPDframe* p_actframe = p_gp_layer->actframe;
 			if(p_actframe)
 			{
-				//
+				// create target bmesh object
+				make_mesh_from_splines(C, op, p_actframe);
 			}
 		}
 	}

Modified: branches/soc-2011-avocado/blender/source/blender/editors/mesh/editbmesh_add.c
===================================================================
--- branches/soc-2011-avocado/blender/source/blender/editors/mesh/editbmesh_add.c	2011-06-27 17:21:08 UTC (rev 37872)
+++ branches/soc-2011-avocado/blender/source/blender/editors/mesh/editbmesh_add.c	2011-06-27 18:31:34 UTC (rev 37873)
@@ -155,6 +155,32 @@
 	WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
 
 }
+
+extern void make_mesh_from_splines(bContext *C, wmOperator *op, void* p_frame)
+{
+	Object *obedit;
+	Mesh *me;
+	BMEditMesh *em;
+	float loc[3], rot[3], mat[4][4], dia;
+	int enter_editmode;
+	int state;
+	unsigned int layer;
+
+	ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL);
+	loc[0] = loc[1] = loc[2] = 0;
+	rot[0] = rot[1] = rot[2] = 0;
+	make_prim_init(C, &dia, mat, &state, loc, rot, layer);
+
+	obedit= CTX_data_edit_object(C);
+	me = obedit->data;
+	em = me->edit_btmesh;
+
+	EDBM_CallAndSelectOpf(em, op, "vertout", "create_mesh_from_splines frame=%p", p_frame);
+
+	/* BMESH_TODO make plane side this: sqrt(2.0f) - plane (diameter of 1.41 makes it unit size) */
+	make_prim_finish(C, &state, enter_editmode);
+}
+
 static int add_primitive_plane_exec(bContext *C, wmOperator *op)
 {
 	Object *obedit;

Modified: branches/soc-2011-avocado/blender/source/blender/editors/mesh/editbmesh_bvh.h
===================================================================
--- branches/soc-2011-avocado/blender/source/blender/editors/mesh/editbmesh_bvh.h	2011-06-27 17:21:08 UTC (rev 37872)
+++ branches/soc-2011-avocado/blender/source/blender/editors/mesh/editbmesh_bvh.h	2011-06-27 18:31:34 UTC (rev 37873)
@@ -28,4 +28,8 @@
 struct BMVert *BMBVH_FindClosestVert(struct BMBVHTree *tree, float *co, float maxdist);
 struct BMVert *BMBVH_FindClosestVertTopo(struct BMBVHTree *tree, float *co,
                                          float maxdist, struct BMVert *sourcev);
+
+// creates bmesh primitive
+extern void make_mesh_from_splines(struct bContext *C, struct wmOperator *op, void* p_frame);
+
 #endif /* _EDITBMESH_H */




More information about the Bf-blender-cvs mailing list