[Bf-blender-cvs] [d7ead92] temp-curve-draw: Re-arrange functions into sections

Campbell Barton noreply at git.blender.org
Thu Apr 14 22:46:07 CEST 2016


Commit: d7ead9273ddf76d5066a611ec3ae2aac47443de6
Author: Campbell Barton
Date:   Fri Apr 15 06:45:33 2016 +1000
Branches: temp-curve-draw
https://developer.blender.org/rBd7ead9273ddf76d5066a611ec3ae2aac47443de6

Re-arrange functions into sections

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

M	source/blender/editors/curve/editcurve_paint.c

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

diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c
index 1ab53cd..acd6d3e 100644
--- a/source/blender/editors/curve/editcurve_paint.c
+++ b/source/blender/editors/curve/editcurve_paint.c
@@ -64,9 +64,105 @@
 #define STROKE_SAMPLE_DIST_MIN_PX 3
 #define STROKE_SAMPLE_DIST_MAX_PX 6
 
+
+/* -------------------------------------------------------------------- */
+
+/** \name Depth Utilities
+ * \{ */
+
+
+static float depth_read_zbuf(const ViewContext *vc, int x, int y)
+{
+	ViewDepths *vd = vc->rv3d->depths;
+
+	if (vd && vd->depths && x > 0 && y > 0 && x < vd->w && y < vd->h)
+		return vd->depths[y * vd->w + x];
+	else
+		return -1.0f;
+}
+
+static bool depth_unproject(
+        const ARegion *ar, const bglMats *mats,
+        const int mval[2], const float depth,
+        float r_location_world[3])
+{
+	double p[3];
+	if (gluUnProject(
+	        (double)ar->winrct.xmin + mval[0] + 0.5,
+	        (double)ar->winrct.ymin + mval[1] + 0.5,
+	        depth, mats->modelview, mats->projection, (const GLint *)mats->viewport,
+	        &p[0], &p[1], &p[2]))
+	{
+		copy_v3fl_v3db(r_location_world, p);
+		return true;
+	}
+	return false;
+}
+
+static bool depth_read_normal(
+        const ViewContext *vc, const bglMats *mats, const int mval[2],
+        float r_normal[3])
+{
+	/* pixels surrounding */
+	bool  depths_valid[9] = {false};
+	float coords[9][3] = {{0}};
+
+	ARegion *ar = vc->ar;
+	const ViewDepths *depths = vc->rv3d->depths;
+
+	for (int x = 0, i = 0; x < 2; x++) {
+		for (int y = 0; y < 2; y++) {
+			const int mval_ofs[2] = {mval[0] + (x - 1), mval[1] + (y - 1)};
+
+			float depth = depth_read_zbuf(vc, mval_ofs[0], mval_ofs[1]);
+			if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
+				if (depth_unproject(ar, mats, mval_ofs, depth, coords[i])) {
+					depths_valid[i] = true;
+				}
+			}
+			i++;
+		}
+	}
+
+	const int edges[2][6][2] = {
+	    /* x edges */
+	    {{0, 1}, {1, 2},
+	     {3, 4}, {4, 5},
+	     {6, 7}, {7, 8}},
+	    /* y edges */
+	    {{0, 3}, {3, 6},
+	     {1, 4}, {4, 7},
+	     {2, 5}, {5, 8}},
+	};
+
+	float cross[2][3] = {{0.0f}};
+
+	for (int i = 0; i < 6; i++) {
+		for (int axis = 0; axis < 2; axis++) {
+			if (depths_valid[edges[axis][i][0]] && depths_valid[edges[axis][i][1]]) {
+				float delta[3];
+				sub_v3_v3v3(delta, coords[edges[axis][i][0]], coords[edges[axis][i][1]]);
+				add_v3_v3(cross[axis], delta);
+			}
+		}
+	}
+
+	cross_v3_v3v3(r_normal, cross[0], cross[1]);
+
+	if (normalize_v3(r_normal) != 0.0f) {
+		return true;
+	}
+	else {
+		return false;
+	}
+}
+
+/** \} */
+
+
 /* -------------------------------------------------------------------- */
 
-/** \name StrokeElem / RNA_OperatorStrokeElement Conversion Functions
+/** \name StrokeElem / #RNA_OperatorStrokeElement Conversion Functions
  * \{ */
 
 struct StrokeElem {
@@ -136,6 +232,103 @@ static void stroke_elem_interp(
 	selem_out->pressure = interpf(selem_a->pressure, selem_b->pressure, t);
 }
 
+
+/**
+ * Sets the depth from #StrokeElem.mval
+ */
+static bool stroke_elem_project(
+        const struct CurveDrawData *cdd,
+        const int mval_i[2], const float mval_fl[2],
+        const float radius_offset, const float radius,
+        float r_location_world[3])
+{
+	View3D *v3d = cdd->vc.v3d;
+	ARegion *ar = cdd->vc.ar;
+	RegionView3D *rv3d = cdd->vc.rv3d;
+
+	bool is_location_world_set = false;
+
+	/* project to 'location_world' */
+	if (cdd->project.use_plane) {
+		/* get the view vector to 'location' */
+		float ray_origin[3], ray_direction[3];
+		ED_view3d_win_to_ray(cdd->vc.ar, v3d, mval_fl, ray_origin, ray_direction, false);
+
+		float lambda;
+		if (isect_ray_plane_v3(ray_origin, ray_direction, cdd->project.plane, &lambda, true)) {
+			madd_v3_v3v3fl(r_location_world, ray_origin, ray_direction, lambda);
+			is_location_world_set = true;
+		}
+	}
+	else {
+		const ViewDepths *depths = rv3d->depths;
+		if (depths &&
+		    ((unsigned int)mval_i[0] < depths->w) &&
+		    ((unsigned int)mval_i[1] < depths->h))
+		{
+			float depth = depth_read_zbuf(&cdd->vc, mval_i[0], mval_i[1]);
+			if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
+				if (depth_unproject(ar, &cdd->mats, mval_i, depth, r_location_world)) {
+					is_location_world_set = true;
+
+					if (radius_offset != 0.0f) {
+						float normal[3];
+						if (depth_read_normal(&cdd->vc, &cdd->mats, mval_i, normal)) {
+							madd_v3_v3fl(r_location_world, normal, radius_offset * radius);
+						}
+					}
+				}
+			}
+		}
+	}
+
+	return is_location_world_set;
+}
+
+static bool stroke_elem_project_fallback(
+        const struct CurveDrawData *cdd,
+        const int mval_i[2], const float mval_fl[2],
+        const float radius_offset, const float radius,
+        const float location_fallback_depth[3],
+        float r_location_world[3], float r_location_local[3])
+{
+	bool is_depth_found = stroke_elem_project(
+	        cdd, mval_i, mval_fl,
+	        radius_offset, radius,
+	        r_location_world);
+	if (is_depth_found == false) {
+		ED_view3d_win_to_3d(cdd->vc.ar, location_fallback_depth, mval_fl, r_location_world);
+	}
+	mul_v3_m4v3(r_location_local, cdd->vc.obedit->imat, r_location_world);
+
+	return is_depth_found;
+}
+
+/**
+ * \note #StrokeElem.mval & #StrokeElem.pressure must be set first.
+ */
+static bool stroke_elem_project_fallback_elem(
+        const struct CurveDrawData *cdd,
+        const float location_fallback_depth[3],
+        struct StrokeElem *selem)
+{
+	const int mval_i[2] = {UNPACK2(selem->mval)};
+	const float radius = stroke_elem_radius(cdd, selem);
+	return stroke_elem_project_fallback(
+	        cdd, mval_i, selem->mval,
+	        cdd->radius.offset, radius,
+	        location_fallback_depth,
+	        selem->location_world, selem->location_local);
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Operator/Stroke Conversion
+ * \{ */
+
 static void curve_draw_stroke_to_operator_elem(
         wmOperator *op, const struct StrokeElem *selem)
 {
@@ -185,10 +378,10 @@ static void curve_draw_stroke_from_operator(wmOperator *op)
 /** \} */
 
 
-enum {
-	CURVE_PAINT_TYPE_BEZIER = 0,
-	CURVE_PAINT_TYPE_POLY,
-};
+/* -------------------------------------------------------------------- */
+
+/** \name Operator Callbacks & Helpers
+ * \{ */
 
 static void curve_draw_stroke_3d(const struct bContext *UNUSED(C), ARegion *UNUSED(ar), void *arg)
 {
@@ -284,181 +477,6 @@ static void curve_draw_stroke_3d(const struct bContext *UNUSED(C), ARegion *UNUS
 	}
 }
 
-static float depth_read_zbuf(const ViewContext *vc, int x, int y)
-{
-	ViewDepths *vd = vc->rv3d->depths;
-
-	if (vd && vd->depths && x > 0 && y > 0 && x < vd->w && y < vd->h)
-		return vd->depths[y * vd->w + x];
-	else
-		return -1.0f;
-}
-
-static bool depth_unproject(
-        const ARegion *ar, const bglMats *mats,
-        const int mval[2], const float depth,
-        float r_location_world[3])
-{
-	double p[3];
-	if (gluUnProject(
-	        (double)ar->winrct.xmin + mval[0] + 0.5,
-	        (double)ar->winrct.ymin + mval[1] + 0.5,
-	        depth, mats->modelview, mats->projection, (const GLint *)mats->viewport,
-	        &p[0], &p[1], &p[2]))
-	{
-		copy_v3fl_v3db(r_location_world, p);
-		return true;
-	}
-	return false;
-}
-
-static bool depth_read_normal(
-        const ViewContext *vc, const bglMats *mats, const int mval[2],
-        float r_normal[3])
-{
-	/* pixels surrounding */
-	bool  depths_valid[9] = {false};
-	float coords[9][3] = {{0}};
-
-	ARegion *ar = vc->ar;
-	const ViewDepths *depths = vc->rv3d->depths;
-
-	for (int x = 0, i = 0; x < 2; x++) {
-		for (int y = 0; y < 2; y++) {
-			const int mval_ofs[2] = {mval[0] + (x - 1), mval[1] + (y - 1)};
-
-			float depth = depth_read_zbuf(vc, mval_ofs[0], mval_ofs[1]);
-			if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
-				if (depth_unproject(ar, mats, mval_ofs, depth, coords[i])) {
-					depths_valid[i] = true;
-				}
-			}
-			i++;
-		}
-	}
-
-	const int edges[2][6][2] = {
-	    /* x edges */
-	    {{0, 1}, {1, 2},
-	     {3, 4}, {4, 5},
-	     {6, 7}, {7, 8}},
-	    /* y edges */
-	    {{0, 3}, {3, 6},
-	     {1, 4}, {4, 7},
-	     {2, 5}, {5, 8}},
-	};
-
-	float cross[2][3] = {{0.0f}};
-
-	for (int i = 0; i < 6; i++) {
-		for (int axis = 0; axis < 2; axis++) {
-			if (depths_valid[edges[axis][i][0]] && depths_valid[edges[axis][i][1]]) {
-				float delta[3];
-				sub_v3_v3v3(delta, coords[edges[axis][i][0]], coords[edges[axis][i][1]]);
-				add_v3_v3(cross[axis], delta);
-			}
-		}
-	}
-
-	cross_v3_v3v3(r_normal, cross[0], cross[1]);
-
-	if (normalize_v3(r_normal) != 0.0f) {
-		return true;
-	}
-	else {
-		return false;
-	}
-}
-
-/**
- * Sets the depth from #StrokeElem.mval
- */
-static bool stroke_elem_project(
-        const struct CurveDrawData *cdd,
-        const int mval_i[2], const float mval_fl[2],
-        const float radius_offset, const float radius,
-        float r_location_world[3])
-{
-	View3D *v3d = cdd->vc.v3d;
-	ARegion *ar = cdd->vc.ar;
-	RegionView3D *rv3d = cdd->vc.rv3d;
-
-	bool is_location_world_set = false;
-
-	/* project to 'location_world' */
-	if (cdd->project.use_plane) {
-		/* get the view vector to 'location' */
-		float ray_origin[3], ray_direction[3];
-		ED_view3d_win_to_ray(cdd->vc.ar, v3d, mval_fl, ray_origin, ray_direction, false);
-
-		float lambda;
-		if (isect_ray_plane_v3(ray_origin, ray_direction, cdd->project.plane, &lambda, true)) {
-			madd_v3_v3v3fl(r_location_world, ray_origin, ray_direction, lambda);
-			is_location_world_set = true;
-		}
-	}
-	else {
-		const ViewDepths *depths = rv3d->depths;
-		if (depths &&
-		    ((unsigned int)mval_i[0] < depths->w) &&
-		    ((unsigned int)mval_i[1] < depths->h))
-		{
-			float depth = depth_read_zbuf(&cdd->vc, mval_i[0], mval_i[1]);
-			if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
-				if (depth_unproject(ar, &cdd->mats, mval_i, depth, r_location_world)) {
-					is_location_world_set = true;
-
-					if (radius_offset != 0.0f) {
-						float normal[3];
-						if (depth_read_normal(&cdd->vc, &cdd->mats, mval_i, normal)) {
-							madd_v

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list