[Bf-blender-cvs] [cda563c] hair_system: Fix for hair root transformation: was missing a world/object space transformation.

Lukas Tönne noreply at git.blender.org
Fri Aug 22 17:30:13 CEST 2014


Commit: cda563cfc676ab25d3dc0b7e62186136300d3246
Author: Lukas Tönne
Date:   Fri Aug 22 17:30:35 2014 +0200
Branches: hair_system
https://developer.blender.org/rBcda563cfc676ab25d3dc0b7e62186136300d3246

Fix for hair root transformation: was missing a world/object space
transformation.

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

M	source/blender/editors/physics/hair_ops.c
M	source/blender/hair/intern/HAIR_curve.h
M	source/blender/hair/intern/HAIR_scene.cpp
M	source/blender/hair/intern/HAIR_solver.cpp

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

diff --git a/source/blender/editors/physics/hair_ops.c b/source/blender/editors/physics/hair_ops.c
index 0a6076d..1f5154c 100644
--- a/source/blender/editors/physics/hair_ops.c
+++ b/source/blender/editors/physics/hair_ops.c
@@ -186,19 +186,11 @@ static bool hair_copy_particle_emitter_location(Object *UNUSED(ob), ParticleSyst
 static void hair_copy_root(Object *ob, HairSystem *UNUSED(hsys), ParticleSystem *psys, struct DerivedMesh *dm, HairCurve *hair, int index)
 {
 	ParticleData *root = &psys->particles[index];
-	float nor[3], tan[3];
+	float loc[3], nor[3], tan[3];
 	
 	hair_copy_particle_emitter_location(ob, psys, root, dm, &hair->root);
 	
-	if (root->totkey >= 2) {
-		sub_v3_v3v3(nor, root->hair[1].co, root->hair[0].co);
-		normalize_v3(nor);
-	}
-	else {
-		float loc[3];
-		
-		BKE_mesh_sample_eval(dm, &hair->root, loc, nor);
-	}
+	BKE_mesh_sample_eval(dm, &hair->root, loc, nor);
 	
 	copy_v3_v3(hair->rest_nor, nor);
 	
diff --git a/source/blender/hair/intern/HAIR_curve.h b/source/blender/hair/intern/HAIR_curve.h
index 4bf9ea2..2e9e6cb 100644
--- a/source/blender/hair/intern/HAIR_curve.h
+++ b/source/blender/hair/intern/HAIR_curve.h
@@ -28,6 +28,8 @@
 #define __HAIR_CURVE_H__
 
 extern "C" {
+#include "BLI_math.h"
+
 #include "RBI_api.h"
 }
 
@@ -95,12 +97,20 @@ struct Frame {
 	    normal(normal),
 	    tangent(tangent),
 	    cotangent(cotangent)
-	{}
+	{
+//		BLI_ASSERT_UNIT_V3(normal.data());
+//		BLI_ASSERT_UNIT_V3(tangent.data());
+//		BLI_ASSERT_UNIT_V3(cotangent.data());
+	}
 	Frame(const Transform &t) :
 	    normal(float3(t.x.x, t.y.x, t.z.x)),
 	    tangent(float3(t.x.y, t.y.y, t.z.y)),
 	    cotangent(float3(t.x.z, t.y.z, t.z.z))
-	{}
+	{
+//		BLI_ASSERT_UNIT_V3(normal.data());
+//		BLI_ASSERT_UNIT_V3(tangent.data());
+//		BLI_ASSERT_UNIT_V3(cotangent.data());
+	}
 	
 	float3 normal;
 	float3 tangent;
diff --git a/source/blender/hair/intern/HAIR_scene.cpp b/source/blender/hair/intern/HAIR_scene.cpp
index f91b2b8..1e28213 100644
--- a/source/blender/hair/intern/HAIR_scene.cpp
+++ b/source/blender/hair/intern/HAIR_scene.cpp
@@ -90,14 +90,7 @@ SolverData *SceneConverter::build_solver_data(Scene *scene, Object *ob, DerivedM
 		Curve *curve = solver_curves + i;
 		*curve = Curve(hair->totpoints, point);
 		
-		float3 nor;
-		mesh_sample_eval_transformed(dm, mat, &hair->root, curve->root1.co, nor);
-		if (hair->totpoints >= 2) {
-			float3 first_edge = transform_direction(mat, float3(hair->points[1].co) - float3(hair->points[0].co));
-			normalize_v3_v3(curve->root1.nor, first_edge);
-		}
-		else
-			curve->root1.nor = nor;
+		mesh_sample_eval_transformed(dm, mat, &hair->root, curve->root1.co, curve->root1.nor);
 		normalize_v3_v3(curve->root1.tan, float3(0,0,1) - dot_v3v3(float3(0,0,1), curve->root1.nor) * curve->root1.nor);
 		
 		curve->root0 = curve->root1;
@@ -105,8 +98,8 @@ SolverData *SceneConverter::build_solver_data(Scene *scene, Object *ob, DerivedM
 		curve->avg_rest_length = hair->avg_rest_length;
 		curve->rest_root_normal = float3(hair->rest_nor);
 		curve->rest_root_tangent = float3(hair->rest_tan);
-		transform_direction(mat, curve->rest_root_normal);
-		transform_direction(mat, curve->rest_root_tangent);
+		curve->rest_root_normal = transform_direction(mat, curve->rest_root_normal);
+		curve->rest_root_tangent = transform_direction(mat, curve->rest_root_tangent);
 		
 		for (int k = 0; k < hair->totpoints; ++k, ++point) {
 			HairPoint *hair_pt = hair->points + k;
@@ -333,14 +326,8 @@ void SceneConverter::update_solver_data_externals(SolverData *data, SolverForces
 		Curve *curve = solver_curves + i;
 		
 		curve->root0 = curve->root1;
-		float3 nor;
-		mesh_sample_eval_transformed(dm, mat, &hair->root, curve->root1.co, nor);
-		if (hair->totpoints >= 2) {
-//			float3 first_edge = transform_direction(mat, float3(hair->points[1].co) - float3(hair->points[0].co));
-//			normalize_v3_v3(curve->root1.nor, first_edge);
-		}
-		else
-			curve->root1.nor = nor;
+		
+		mesh_sample_eval_transformed(dm, mat, &hair->root, curve->root1.co, curve->root1.nor);
 		normalize_v3_v3(curve->root1.tan, float3(0,0,1) - dot_v3v3(float3(0,0,1), curve->root1.nor) * curve->root1.nor);
 	}
 	
diff --git a/source/blender/hair/intern/HAIR_solver.cpp b/source/blender/hair/intern/HAIR_solver.cpp
index dec4790..15b48e3 100644
--- a/source/blender/hair/intern/HAIR_solver.cpp
+++ b/source/blender/hair/intern/HAIR_solver.cpp
@@ -132,6 +132,12 @@ void SolverData::precompute_rest_bend(const HairParams &params)
 			FrameIterator<SolverDataRestLocWalker> iter(SolverDataRestLocWalker(curve), curve->avg_rest_length, params.bend_smoothing, rest_frame);
 			while (iter.index() < curve->totpoints - 1) {
 				pt->rest_bend = world_to_frame_space(iter.frame(), next_pt->rest_co - pt->rest_co);
+				if (iter.index() == 0) {
+					Debug::vector(pt->rest_co, pt->rest_bend, 0, 0.3, 0.9, hash_int_2d(iter.index(), 577));
+					Debug::vector(pt->rest_co, iter.frame().normal, 1, 0.6, 0.6, hash_int_2d(iter.index(), 578));
+					Debug::vector(pt->rest_co, iter.frame().tangent, 0.6, 1, 0.6, hash_int_2d(iter.index(), 570));
+					Debug::vector(pt->rest_co, iter.frame().cotangent, 0.6, 0.6, 1, hash_int_2d(iter.index(), 579));
+				}
 				
 				iter.next();
 				++pt;
@@ -237,7 +243,7 @@ static float3 calc_stretch_force(const HairParams &params, const Point *point0,
 static float3 calc_bend_force(const HairParams &params, int k, const Point *point0, const Point *point1, const Frame &frame, float time)
 {
 	float3 target = frame_to_world_space(frame, point0->rest_bend);
-	Debug::vector(point0->cur.co, target, 1.0f, 0.5f, 1.0f, hash_int_2d(hash_int_2d(k, 0), 837));
+//	Debug::vector(point0->cur.co, target, 1.0f, 0.5f, 1.0f, hash_int_2d(hash_int_2d(k, 0), 837));
 	
 	float3 dir;
 	float3 edge = point1->cur.co - point0->cur.co;
@@ -254,7 +260,7 @@ static void calc_damping(const HairParams &params, int k, const Point *point0, c
 	/* NB: for damping, use the updated next.vel velocities! */
 	float3 dvel = point1->next.vel - point0->next.vel;
 	
-	Debug::vector(point0->cur.co, dvel, 0.5f, 0.5f, 1.0f, hash_int_2d(hash_int_2d(k, 0), 867));
+//	Debug::vector(point0->cur.co, dvel, 0.5f, 0.5f, 1.0f, hash_int_2d(hash_int_2d(k, 0), 867));
 	
 	float3 dvel_edge = dot_v3v3(dvel, dir) * dir;
 	stretch = params.stretch_damping * dvel_edge;
@@ -391,16 +397,18 @@ static void calc_forces(const HairParams &params, const SolverForces &forces, fl
 		
 		{
 			float3 rest_bend = frame_to_world_space(frame_iter.frame(), point->rest_bend);
+//			float3 rest_bend = point->rest_bend;
 			float3 bend = frame_to_world_space(frame_iter.frame(), point_next ? point_next->cur.co - point->cur.co : float3(0,0,0));
 //			float3 bend = point_next ? point_next->cur.co - point->cur.co : float3(0,0,0);
 
 //			float3 bend = point_next ? calc_bend_force(params, point, point_next, frame_iter.frame(), time) : float3(0,0,0);
 //			float3 rest_bend = point->rest_bend;
 //			float3 bend = point_next ? point_next->cur.co - point->cur.co : float3(0,0,0);
-//			Debug::point(data.debug_data, k_tot, point->cur.co, rest_bend, bend, frame_iter.frame());
-//			Debug::vector(point->cur.co, frame_iter.frame().normal, 1.0f, 0.0f, 0.0f, hash_int_2d(hash_int_2d(i, k), 61));
-//			Debug::vector(point->cur.co, frame_iter.frame().tangent, 0.0f, 1.0f, 0.0f, hash_int_2d(hash_int_2d(i, k), 71));
-//			Debug::vector(point->cur.co, frame_iter.frame().cotangent, 0.0f, 0.0f, 1.0f, hash_int_2d(hash_int_2d(i, k), 81));
+//			Debug::vector(point->cur.co, root_nor, 1,1,0, hash_int_2d(k_tot, 345));
+			Debug::vector(point->cur.co, frame_iter.frame().normal, 1.0f, 0.0f, 0.0f, hash_int_2d(hash_int_2d(i, k), 61));
+			Debug::vector(point->cur.co, frame_iter.frame().tangent, 0.0f, 1.0f, 0.0f, hash_int_2d(hash_int_2d(i, k), 71));
+			Debug::vector(point->cur.co, frame_iter.frame().cotangent, 0.0f, 0.0f, 1.0f, hash_int_2d(hash_int_2d(i, k), 81));
+			Debug::vector(point->cur.co, rest_bend, 1,1,1, hash_int_2d(k_tot, 345));
 		}
 		
 		frame_iter.next();




More information about the Bf-blender-cvs mailing list