[Bf-blender-cvs] [6fbf02f2a78] greasepencil-object: GP: Check if z-depth has valid values

Antonioya noreply at git.blender.org
Thu Dec 13 13:56:52 CET 2018


Commit: 6fbf02f2a787e6466eb07003ed681809633f0b2d
Author: Antonioya
Date:   Thu Dec 13 13:56:42 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB6fbf02f2a787e6466eb07003ed681809633f0b2d

GP: Check if z-depth has valid values

If the values are too high, disable because not surface to project.

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

M	source/blender/editors/gpencil/gpencil_primitive.c

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

diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index a545dfcba18..2a00fd30dbb 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -636,43 +636,57 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
 			}
 		}
 		else {
-			if ((ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE_ENDPOINTS) ||
-				(ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE_FIRST))
-			{
-				int first_valid = 0;
-				int last_valid = 0;
-
-				/* find first valid contact point */
-				for (i = 0; i < gps->totpoints; i++) {
-					if (depth_arr[i] != FLT_MAX)
-						break;
-				}
-				first_valid = i;
-
-				/* find last valid contact point */
-				if (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE_FIRST) {
-					last_valid = first_valid;
+			/* if all depth are too high disable */
+			bool valid_depth = false;
+			for (i = gps->totpoints - 1; i >= 0; i--) {
+				if (depth_arr[i] < 0.9999f) {
+					valid_depth = true;
+					break;
 				}
-				else {
-					for (i = gps->totpoints - 1; i >= 0; i--) {
+			}
+			if (!valid_depth) {
+				MEM_SAFE_FREE(depth_arr);
+				is_depth = false;
+			}
+			else {
+				if ((ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE_ENDPOINTS) ||
+					(ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE_FIRST))
+				{
+					int first_valid = 0;
+					int last_valid = 0;
+
+					/* find first valid contact point */
+					for (i = 0; i < gps->totpoints; i++) {
 						if (depth_arr[i] != FLT_MAX)
 							break;
 					}
-					last_valid = i;
-				}
+					first_valid = i;
 
-				/* invalidate any other point, to interpolate between
-				 * first and last contact in an imaginary line between them */
-				for (i = 0; i < gps->totpoints; i++) {
-					if ((i != first_valid) && (i != last_valid)) {
-						depth_arr[i] = FLT_MAX;
+					/* find last valid contact point */
+					if (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE_FIRST) {
+						last_valid = first_valid;
 					}
+					else {
+						for (i = gps->totpoints - 1; i >= 0; i--) {
+							if (depth_arr[i] != FLT_MAX)
+								break;
+						}
+						last_valid = i;
+					}
+
+					/* invalidate any other point, to interpolate between
+					 * first and last contact in an imaginary line between them */
+					for (i = 0; i < gps->totpoints; i++) {
+						if ((i != first_valid) && (i != last_valid)) {
+							depth_arr[i] = FLT_MAX;
+						}
+					}
+					interp_depth = true;
 				}
-				interp_depth = true;
-			}
 
-			if (interp_depth) {
-				interp_sparse_array(depth_arr, gps->totpoints, FLT_MAX);
+				if (interp_depth) {
+					interp_sparse_array(depth_arr, gps->totpoints, FLT_MAX);
+				}
 			}
 		}
 	}



More information about the Bf-blender-cvs mailing list