[Bf-blender-cvs] [d213d26e3cc] soc-2017-sculpting_improvements: Minor code cleanup and structuring. Bug fixes!

witt noreply at git.blender.org
Mon Jul 3 16:50:57 CEST 2017


Commit: d213d26e3cc1bca9b3747f0ee6da37563e5ee306
Author: witt
Date:   Mon Jul 3 16:48:27 2017 +0200
Branches: soc-2017-sculpting_improvements
https://developer.blender.org/rBd213d26e3cc1bca9b3747f0ee6da37563e5ee306

Minor code cleanup and structuring. Bug fixes!

===================================================================

M	source/blender/editors/sculpt_paint/sculpt.c

===================================================================

diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index b117d8c5725..c1f0f6d08cd 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -5017,156 +5017,16 @@ static void SCULPT_OT_set_persistent_base(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
-/* Topology tools Silhouette */
-/*init data:*/
-/*** Silhouette Data ***/
+/****************** Topology tools Silhouette ******************/
+
+/*	init data:
+ * 	Silhouette Data */
 typedef struct SilhouetteStroke {
 	float *points;
 	int totvert;
 	int max_verts;
 }SilhouetteStroke;
 
-/* Axis-aligned bounding box (Same as in pbvh_intern.h)*/
-typedef struct {
-	float bmin[3], bmax[3];
-} BB;
-
-#if 0
-//taken from RecastMeshDetail.cpp
-static int triangulateHull(const float* verts, const int nhull, const int* hull, int *tris)
-{
-	int start = 0, left = 1, right = nhull-1, tri_pos = 0;
-
-	// Start from an ear with shortest perimeter.
-	// This tends to favor well formed triangles as starting point.
-	float dmin = 0;
-	for (int i = 0; i < nhull; i++)
-	{
-		int pi = i-1 >= 0 ? i-1 : nhull-1;
-		int ni = i+1 < nhull ? i+1 : 0;
-		const float* pv = &verts[hull[pi]*2];
-		const float* cv = &verts[hull[i]*2];
-		const float* nv = &verts[hull[ni]*2];
-		const float d = len_v2v2(pv,cv) + len_v2v2(cv,nv) + len_v2v2(nv,pv);
-		if (d < dmin)
-		{
-			start = i;
-			left = ni;
-			right = pi;
-			dmin = d;
-		}
-	}
-
-	// Add first triangle
-	tris[tri_pos] = hull[start];
-	tri_pos++;
-	tris[tri_pos] = hull[left];
-	tri_pos++;
-	tris[tri_pos] = hull[right];
-	tri_pos++;
-
-	// Triangulate the polygon by moving left or right,
-	// depending on which triangle has shorter perimeter.
-	// This heuristic was chose emprically, since it seems
-	// handle tesselated straight edges well.
-	while ((left+1 < nhull ? left+1 : 0) != right)
-	{
-		// Check to see if se should advance left or right.
-		int nleft = (left+1 < nhull ? left+1 : 0);
-		int nright = right-1 >= 0 ? right-1 : nhull-1;
-
-		const float* cvleft = &verts[hull[left]*2];
-		const float* nvleft = &verts[hull[nleft]*2];
-		const float* cvright = &verts[hull[right]*2];
-		const float* nvright = &verts[hull[nright]*2];
-		const float dleft = len_v2v2(cvleft, nvleft) + len_v2v2(nvleft, cvright);
-		const float dright = len_v2v2(cvright, nvright) + len_v2v2(cvleft, nvright);
-
-		if (dleft < dright)
-		{
-			tris[tri_pos] = hull[left];
-			tri_pos++;
-			tris[tri_pos] = hull[nleft];
-			tri_pos++;
-			tris[tri_pos] = hull[right];
-			tri_pos++;
-			left = nleft;
-		}
-		else
-		{
-			tris[tri_pos] = hull[left];
-			tri_pos++;
-			tris[tri_pos] = hull[nright];
-			tri_pos++;
-			tris[tri_pos] = hull[right];
-			tri_pos++;
-			right = nright;
-		}
-	}
-	return tri_pos;
-}
-#endif
-
-#ifdef DEBUG_DRAW
-static void bl_debug_draw_BB_add(BB *bb,const unsigned int col)
-{
-	float v1[3],v2[3],v3[3],v4[3];
-	float xd[3], yd[3], zd[3];
-
-	bl_debug_color_set(col);
-
-	xd[0] = bb->bmax[0]-bb->bmin[0];
-	xd[1] = 0.0f;
-	xd[2] = 0.0f;
-
-	yd[0] = 0.0f;
-	yd[1] = bb->bmax[1]-bb->bmin[1];
-	yd[2] = 0.0f;
-
-	zd[0] = 0.0f;
-	zd[1] = 0.0f;
-	zd[2] = bb->bmax[2]-bb->bmin[2];
-
-	copy_v3_v3(v1,bb->bmin);
-	copy_v3_v3(v2,bb->bmin);
-	add_v3_v3(v2,xd);
-	add_v3_v3v3(v3,v1,yd);
-	add_v3_v3v3(v4,v2,yd);
-
-	bl_debug_draw_edge_add(v1,v2);
-	bl_debug_draw_edge_add(v1,v3);
-	bl_debug_draw_edge_add(v2,v4);
-
-	copy_v3_v3(v1,v3);
-	copy_v3_v3(v2,v4);
-	add_v3_v3v3(v3,v1,zd);
-	add_v3_v3v3(v4,v2,zd);
-
-	bl_debug_draw_edge_add(v1,v2);
-	bl_debug_draw_edge_add(v1,v3);
-	bl_debug_draw_edge_add(v2,v4);
-
-	copy_v3_v3(v1,v3);
-	copy_v3_v3(v2,v4);
-	sub_v3_v3v3(v3,v1,yd);
-	sub_v3_v3v3(v4,v2,yd);
-
-	bl_debug_draw_edge_add(v1,v2);
-	bl_debug_draw_edge_add(v1,v3);
-	bl_debug_draw_edge_add(v2,v4);
-
-	copy_v3_v3(v1,v3);
-	copy_v3_v3(v2,v4);
-	sub_v3_v3v3(v3,v1,zd);
-	sub_v3_v3v3(v4,v2,zd);
-
-	bl_debug_draw_edge_add(v1,v2);
-	bl_debug_draw_edge_add(v1,v3);
-	bl_debug_draw_edge_add(v2,v4);
-
-}
-#endif
-
 typedef enum {
 	SIL_INIT = 0,
 	SIL_DRAWING = 1,
@@ -5174,59 +5034,25 @@ typedef enum {
 } SilhouetteState;
 
 typedef struct SilhouetteData {
-	ARegion *ar;        /* region that Silhouette started drawn in */
-	void *draw_handle;  /* for drawing preview loop */
+	ARegion *ar;        	/* region that Silhouette started drawn in */
+	void *draw_handle;  	/* for drawing preview loop */
 	ViewContext vc;
 	SilhouetteStroke *current_stroke;
 	Object *ob;
-	BMEditMesh *em;
+	BMEditMesh *em;			/*Triangulated stroke for spine generation*/
 	Scene *scene;
 
-	float add_col[3];
+	float add_col[3];		/* preview color */
 	float last_mouse_pos[2];
 
-	SilhouetteState state;
+	SilhouetteState state;	/* Operator state */
 
-	float depth;
-	float smoothness;
-	float anchor[3];
-	float z_vec[3];
+	float depth;			/* Depth or thickness of the generated shape */
+	float smoothness;		/* Smoothness of the generated shape */
+	float anchor[3];		/* Origin point of the reference plane */
+	float z_vec[3];			/* Orientation of the reference plane */
 } SilhouetteData;
 
-typedef struct {
-	SculptSession *ss;
-	BB *bb_target;
-	bool original;
-} SculptSearchBBData;
-
-#if 0
-/* Search nodes to integrate another BB into (used for silhouette)*/
-static bool sculpt_search_BB_cb(PBVHNode *node, void *data_v)
-{
-	SculptSearchBBData *data = data_v;
-	BB *bb_target = data->bb_target;
-	float bb_min[3], bb_max[3];
-	int i;
-
-	/*TODO: */
-	/*if (data->original)
-		BKE_pbvh_node_get_original_BB(node, bb_min, bb_max);
-	else*/
-		BKE_pbvh_node_get_BB(node, bb_min, bb_max);
-
-	/* min is inclusive max is exclusive? BB*/
-	for (i = 0; i < 3; ++i) {
-		if (bb_target->bmin[i] >= bb_max[i] || bb_target->bmax[i] < bb_min[i]) {
-			return false;
-		}
-	}
-
-	//float tmp[3] = {bb_min[0]*0.5f+bb_max[0]*0.5f,bb_min[1]*0.5f+bb_max[1]*0.5f,bb_min[2]*0.5f+bb_max[2]*0.5f};
-	//printf("node found at: (%f,%f,%f)\n",bb_min[0]*0.5f+bb_max[0]*0.5f,bb_min[1]*0.5f+bb_max[1]*0.5f,bb_min[2]*0.5f+bb_max[2]*0.5f);
-	return true;
-}
-#endif
-
 static void silhouette_stroke_free(SilhouetteStroke *stroke)
 {
 	if (stroke) {
@@ -5235,18 +5061,15 @@ static void silhouette_stroke_free(SilhouetteStroke *stroke)
 		}
 		MEM_SAFE_FREE(stroke);
 	}
-	printf("Stroke freed.\n");
-	//MEM_SAFE_FREE(stroke);
 }
 
 static SilhouetteStroke *silhouette_stroke_new(int max_verts)
 {
 	SilhouetteStroke *stroke = MEM_callocN(sizeof(SilhouetteStroke), "SilhouetteStroke");
 	stroke->points = 0;
-	stroke->points = MEM_callocN(sizeof(float) * 3 * max_verts,"SilhouetteStrokePoints");//TODO: Dynamic length
+	stroke->points = MEM_callocN(sizeof(float) * 3 * max_verts,"SilhouetteStrokePoints");/* TODO: Dynamic length */
 	stroke->totvert = 0;
 	stroke->max_verts = max_verts;
-	printf("Init silhouette Data\n");
 	return stroke;
 }
 
@@ -5256,30 +5079,25 @@ static SilhouetteData *silhouette_data_new(bContext *C, wmOperator *op, bool rna
 	Object *obedit = CTX_data_edit_object(C);
 	Scene *scene = CTX_data_scene(C);
 	sil->ar = CTX_wm_region(C);
-	sil->current_stroke = 0;
-
 	sil->current_stroke = silhouette_stroke_new(1024);
-
 	view3d_set_viewcontext(C, &sil->vc);
 
 	sil->add_col[0] = 1.00; /* add mode color is light red */
 	sil->add_col[1] = 0.39;
 	sil->add_col[2] = 0.39;
 
+	/*Load RNA Data if present */
 	sil->smoothness = RNA_float_get(op->ptr, "smoothness");
 	sil->depth = RNA_float_get(op->ptr, "depth");
-	if(rna_full){
+	if (rna_full) {
 		RNA_float_get_array(op->ptr, "z_vec", sil->z_vec);
 		RNA_float_get_array(op->ptr, "anchor", sil->anchor);
 		RNA_float_get_array(op->ptr, "points", sil->current_stroke->points);
 		sil->current_stroke->totvert = RNA_int_get(op->ptr, "totvert");
 	}
 
-
-	/* assign the drawing handle for drawing preview line... */
 	sil->scene = scene;
 	sil->ob = obedit;
-
 	sil->state = SIL_INIT;
 	return sil;
 }
@@ -5294,18 +5112,17 @@ static void silhouette_data_free(struct wmOperator *op)
 	}
 }
 
-static void silhoute_stroke_point_to_3d(SilhouetteData *sil, int point, float r_v[3]){
-	copy_v3_v3(r_v,&sil->current_stroke->points[point]);
-	//ED_view3d_win_to_3d(sil->vc.v3d, sil->ar, sil->anchor, &sil->current_stroke->points[point], r_v);
+static void silhoute_stroke_point_to_3d(SilhouetteData *sil, int point, float r_v[3])
+{
+	copy_v3_v3(r_v, &sil->current_stroke->points[point]);
+	/*ED_view3d_win_to_3d(sil->vc.v3d, sil->ar, sil->anchor, &sil->current_stroke->points[point], r_v);*/
 }
 
+/* TODO: Add dynamic memory allocation */
 static void silhouette_stroke_add_3Dpoint(SilhouetteStroke *stroke, float point[3])
 {
 	if (stroke->totvert < stroke->max_verts) {
 		copy_v3_v3(&stroke->points[stroke->totvert * 3], point);
-		//ED_view3d_win_to_3d(sil->vc.v3d, sil->ar, sil->anchor, point, &sil->current_stroke->points[stroke->totvert * 3]);
-		/*stroke->points[stroke->totvert * 3] = point[0];
-		 stroke->points[stroke->totvert*2+1] = point[1];*/
 		stroke->totvert ++;
 	} else {
 		printf("Stroke reached maximum vert count.\n");
@@ -5316,14 +5133,13 @@ static void silhouette_stroke_add_point(SilhouetteData *sil, SilhouetteStroke *s
 {
 	if (stroke->totvert < stroke->max_verts) {
 		ED_view3d_win_to_3d(sil->vc.v3d, sil->ar, sil->anchor, point, &sil->current_stroke->points[stroke->totvert * 3]);
-		/*stroke->points[stroke->totvert * 3] = point[0];
-		stroke->points[stroke->totvert*2+1] = point[1];*/
 		stroke->totvert ++;
 	} else {
 		printf("Stroke reached maximum vert count.\n");
 	}
 }
 
+/* Set reference plane, 3D plane which is drawn on in 2D */
 static void silhouette_set_ref_plane(const bContext *C, SilhouetteData *sil)
 {
 	Scene *scene = CTX_data_scene(C);
@@ -5331,7 +5147,6 @@ static void silhouette_set_ref_plane(const bContext *C, SilhouetteData *sil)
 	const float *fp = ED_view3d_cursor3d_get(scene, v3d);
 
 	ED_view3d_global_to_vector(sil->ar->regiondata, (float[3]){0.0f,0.0f,0.0f}, sil->z_vec);
-	/* the reference point used depends on the owner... */
 	copy_v3_v3(sil->anchor, fp);
 }
 
@@ -5348,57 +5163,60 @@ static void sculpt_silhouette_stroke_update(bContext *C, float mouse[2], Silhoue
 }
 
 typedef enum {
-	SHAPE_RING = 1
-} ShapeTypes;
-
-typedef enum {
 	BRANCH_INIT = 0,
-	BRANCH_VERT_GEN = 1,
-	BRANCH_ED

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list