[Bf-blender-cvs] [b0ba132] strand_gpu: Ensure correct storage of curve normals and tangents with edit BMesh curves.

Lukas Tönne noreply at git.blender.org
Wed Jul 13 14:01:41 CEST 2016


Commit: b0ba1328b4cde9e14e6c8effeb338d15b0a785aa
Author: Lukas Tönne
Date:   Wed Jul 13 05:33:18 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rBb0ba1328b4cde9e14e6c8effeb338d15b0a785aa

Ensure correct storage of curve normals and tangents with edit BMesh curves.

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

M	source/blender/blenkernel/intern/strands.c
M	source/blender/gpu/intern/gpu_buffers.c

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

diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index 75ed2f7..543f0d9 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -251,15 +251,15 @@ static int curve_cache_subdivide(StrandCurveCache *cache, int orig_num_verts, in
 }
 
 static void curve_cache_transport_frame(StrandCurveCache *cache, int num_verts,
-                                        const float normal[3], const float tangent[3])
+                                        float rootmat[4][4])
 {
 	const float (*verts)[3] = cache->verts;
 	float (*dir)[3] = cache->normals;
 	float (*codir)[3] = cache->tangents;
 	float prev_dir[3], prev_codir[3];
 	
-	copy_v3_v3(prev_dir, normal);
-	copy_v3_v3(prev_codir, tangent);
+	copy_v3_v3(prev_dir, rootmat[2]);
+	copy_v3_v3(prev_codir, rootmat[0]);
 	
 	for (int i = 0; i < num_verts - 1; ++i) {
 		float rot[3][3];
@@ -295,7 +295,7 @@ int BKE_strand_curve_cache_calc(const StrandVertex *orig_verts, int orig_num_ver
 	}
 	
 	int num_verts = curve_cache_subdivide(cache, orig_num_verts, subdiv);
-	curve_cache_transport_frame(cache, num_verts, rootmat[2], rootmat[0]);
+	curve_cache_transport_frame(cache, num_verts, rootmat);
 	return num_verts;
 }
 
@@ -311,13 +311,14 @@ int BKE_strand_curve_cache_calc_bm(BMVert *root, int orig_num_verts, StrandCurve
 		BMIter iter;
 		BMVert *v;
 		BM_ITER_STRANDS_ELEM(v, &iter, root, BM_VERTS_OF_STRAND) {
-			mul_v3_m4v3(verts[index], rootmat, v->co);
+			/* BMesh already stores verts in object space, no need to apply the rootmat */
+			copy_v3_v3(verts[index], v->co);
 			index += step;
 		}
 	}
 	
 	int num_verts = curve_cache_subdivide(cache, orig_num_verts, subdiv);
-	curve_cache_transport_frame(cache, num_verts, rootmat[2], rootmat[0]);
+	curve_cache_transport_frame(cache, num_verts, rootmat);
 	return num_verts;
 }
 
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 3276b6e..6d9d0d2 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -2639,17 +2639,15 @@ static void strands_copy_control_attribute_data(GPUDrawStrandsParams *params, vo
 		
 		StrandCurveCache *cache = BKE_strand_curve_cache_create_bm(bm, params->subdiv);
 		
-		/* Note: edit bmesh has all vertices in object space already,
-		 * so we don't need to apply curve transforms!
-		 */
-		float rootmat[4][4];
-		unit_m4(rootmat);
-		
 		BMIter iter;
 		BMVert *root;
 		BM_ITER_STRANDS(root, &iter, bm, BM_STRANDS_OF_MESH) {
+			float rootmat[4][4];
+			BKE_editstrands_get_matrix(params->edit, root, rootmat);
+			
 			int orig_num_verts = BM_strand_verts_count(root);
 			int num_verts = BKE_strand_curve_cache_calc_bm(root, orig_num_verts, cache, rootmat, params->subdiv);
+			BLI_assert(orig_num_verts >= 2);
 			
 			strands_copy_control_cache_attribute_data(cache, num_verts, &varray, type);
 		}




More information about the Bf-blender-cvs mailing list