[Bf-blender-cvs] [1b9328a] hair_system: Another partial fix for bending problems.

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


Commit: 1b9328a50d629aefa715e308aa193657084dbb67
Author: Lukas Tönne
Date:   Thu Aug 21 18:19:50 2014 +0200
Branches: hair_system
https://developer.blender.org/rB1b9328a50d629aefa715e308aa193657084dbb67

Another partial fix for bending problems.

Main requirement is that the frame iterator rotates the initial frame
already for the first curve segment.

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

M	source/blender/editors/physics/hair_ops.c
M	source/blender/editors/space_view3d/drawhair.c
M	source/blender/hair/intern/HAIR_math.cpp
M	source/blender/hair/intern/HAIR_math.h
M	source/blender/hair/intern/HAIR_scene.cpp
M	source/blender/hair/intern/HAIR_smoothing.h
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 ef23893..0a6076d 100644
--- a/source/blender/editors/physics/hair_ops.c
+++ b/source/blender/editors/physics/hair_ops.c
@@ -186,10 +186,22 @@ 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 loc[3], tan[3];
+	float nor[3], tan[3];
 	
 	hair_copy_particle_emitter_location(ob, psys, root, dm, &hair->root);
-	BKE_mesh_sample_eval(dm, &hair->root, loc, hair->rest_nor);
+	
+	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);
+	}
+	
+	copy_v3_v3(hair->rest_nor, nor);
+	
 	tan[0] = 0.0f; tan[1] = 0.0f; tan[2] = 1.0f;
 	madd_v3_v3v3fl(hair->rest_tan, tan, hair->rest_nor, -dot_v3v3(tan, hair->rest_nor));
 	normalize_v3(hair->rest_tan);
diff --git a/source/blender/editors/space_view3d/drawhair.c b/source/blender/editors/space_view3d/drawhair.c
index e757d42..7b657a2 100644
--- a/source/blender/editors/space_view3d/drawhair.c
+++ b/source/blender/editors/space_view3d/drawhair.c
@@ -565,7 +565,8 @@ static void draw_hair_debug_roots(HairSystem *hsys, struct DerivedMesh *dm)
 			float loc[3], nor[3];
 			if (BKE_mesh_sample_eval(dm, &hair->root, loc, nor)) {
 				glVertex3f(loc[0], loc[1], loc[2]);
-				madd_v3_v3fl(loc, nor, 0.1f);
+//				madd_v3_v3fl(loc, nor, 0.1f);
+				add_v3_v3(loc, hair->rest_nor);
 				glVertex3f(loc[0], loc[1], loc[2]);
 			}
 		}
diff --git a/source/blender/hair/intern/HAIR_math.cpp b/source/blender/hair/intern/HAIR_math.cpp
index 8255c31..30e5145 100644
--- a/source/blender/hair/intern/HAIR_math.cpp
+++ b/source/blender/hair/intern/HAIR_math.cpp
@@ -29,6 +29,11 @@
 #include <limits>
 #include <cfloat>
 
+extern "C" {
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+}
+
 #include "HAIR_math.h"
 
 HAIR_NAMESPACE_BEGIN
@@ -189,4 +194,25 @@ Transform transform_inverse(const Transform& tfm)
 	return tfmR;
 }
 
+#if 0
+float3 mul_qt_v3(const float4 &q, const float3 &v)
+{
+	float quat[4] = {q.w, q.x, q.y, q.z}, vec[3];
+	copy_v3_v3(vec, v.data());
+	::mul_qt_v3(quat, vec);
+	return float3(vec);
+}
+#endif
+
+#if 0
+float4 rotation_between_vecs_to_quat(const float3 a, const float3 b)
+{
+	float q[4], v1[3], v2[3];
+	::normalize_v3_v3(v1, a.data());
+	::normalize_v3_v3(v2, b.data());
+	::rotation_between_vecs_to_quat(q, v1, v2);
+	return float4(q[1], q[2], q[3], q[0]);
+}
+#endif
+
 HAIR_NAMESPACE_END
diff --git a/source/blender/hair/intern/HAIR_math.h b/source/blender/hair/intern/HAIR_math.h
index 6310e7d..6832281 100644
--- a/source/blender/hair/intern/HAIR_math.h
+++ b/source/blender/hair/intern/HAIR_math.h
@@ -33,10 +33,6 @@
 
 #include <math.h>
 
-extern "C" {
-#include "BLI_utildefines.h"
-}
-
 #include "HAIR_types.h"
 
 HAIR_NAMESPACE_BEGIN
@@ -178,6 +174,7 @@ bool interp_v3v3_slerp(float3 &r, const float3 &a, const float3 &b, float t);
 
 /* quaternion functions */
 
+#if 1
 __forceinline float3 mul_qt_v3(const float4 &q, const float3 &v)
 {
 	float t0, t1, t2;
@@ -220,7 +217,11 @@ __forceinline float4 mul_qt_v4(const float4 &q, const float4 &v)
 	
 	return r;
 }
+#else
+float3 mul_qt_v3(const float4 &q, const float3 &v);
+#endif
 
+#if 1
 __forceinline float4 rotation_between_vecs_to_quat(const float3 a, const float3 b)
 {
 	static const float epsilon = 1.0e-6;
@@ -241,6 +242,9 @@ __forceinline float4 rotation_between_vecs_to_quat(const float3 a, const float3
 	else
 		return unit_qt;
 }
+#else
+float4 rotation_between_vecs_to_quat(const float3 a, const float3 b);
+#endif
 
 /* matrix arithmetic */
 
diff --git a/source/blender/hair/intern/HAIR_scene.cpp b/source/blender/hair/intern/HAIR_scene.cpp
index 25aab84..5f93ea1 100644
--- a/source/blender/hair/intern/HAIR_scene.cpp
+++ b/source/blender/hair/intern/HAIR_scene.cpp
@@ -90,7 +90,14 @@ SolverData *SceneConverter::build_solver_data(Scene *scene, Object *ob, DerivedM
 		Curve *curve = solver_curves + i;
 		*curve = Curve(hair->totpoints, point);
 		
-		mesh_sample_eval_transformed(dm, mat, &hair->root, curve->root1.co, curve->root1.nor);
+		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;
 		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;
@@ -98,8 +105,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);
+		transform_direction(mat, curve->rest_root_normal);
+		transform_direction(mat, curve->rest_root_tangent);
 		
 		for (int k = 0; k < hair->totpoints; ++k, ++point) {
 			HairPoint *hair_pt = hair->points + k;
@@ -222,11 +229,18 @@ void SceneConverter::update_solver_data_externals(SolverData *data, SolverForces
 	data->t1 = time;
 	
 	for (i = 0; i < totcurves; ++i) {
-		HairCurve *hcurve = hsys->curves + i;
+		HairCurve *hair = hsys->curves + i;
 		Curve *curve = solver_curves + i;
 		
 		curve->root0 = curve->root1;
-		mesh_sample_eval_transformed(dm, mat, &hcurve->root, curve->root1.co, curve->root1.nor);
+		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;
 		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_smoothing.h b/source/blender/hair/intern/HAIR_smoothing.h
index 04b129f..b7905cd 100644
--- a/source/blender/hair/intern/HAIR_smoothing.h
+++ b/source/blender/hair/intern/HAIR_smoothing.h
@@ -139,22 +139,26 @@ struct FrameIterator {
 	
 	void next()
 	{
-		if (m_loc_iter.index() == 0) {
-			float3 prev_co = m_loc_iter.get();
-			m_loc_iter.next();
-			float3 co = m_loc_iter.get();
-			normalize_v3_v3(m_dir, co - prev_co);
-		}
-		else {
-			float3 prev_dir = m_dir;
+//		if (m_loc_iter.index() == 0) {
+//			float3 prev_co = m_loc_iter.get();
+//			m_loc_iter.next();
+//			float3 co = m_loc_iter.get();
+//			normalize_v3_v3(m_dir, co - prev_co);
+//		}
+//		else {
+//			float3 prev_dir = m_dir;
 			
 			float3 prev_co = m_loc_iter.get();
 			m_loc_iter.next();
 			float3 co = m_loc_iter.get();
-			normalize_v3_v3(m_dir, co - prev_co);
+//			normalize_v3_v3(m_dir, co - prev_co);
+			
+			float3 dir;
+			normalize_v3_v3(dir, co - prev_co);
 			
 			/* construct rotation from one segment to the next */
-			float4 rot = rotation_between_vecs_to_quat(prev_dir, m_dir);
+//			float4 rot = rotation_between_vecs_to_quat(prev_dir, m_dir);
+			float4 rot = rotation_between_vecs_to_quat(m_frame.normal, dir);
 			/* apply the local rotation to the frame axes */
 			m_frame.normal = mul_qt_v3(rot, m_frame.normal);
 			m_frame.tangent = mul_qt_v3(rot, m_frame.tangent);
@@ -162,14 +166,15 @@ struct FrameIterator {
 			normalize_v3_v3(m_frame.normal, m_frame.normal);
 			normalize_v3_v3(m_frame.tangent, m_frame.tangent);
 			normalize_v3_v3(m_frame.cotangent, m_frame.cotangent);
-		}
+//		}
 	}
 	
 	const Frame &frame() const { return m_frame; }
+	Frame &frame() { return m_frame; }
 	
 protected:
 	SmoothingIterator<WalkerT> m_loc_iter;
-	float3 m_dir;
+//	float3 m_dir;
 	
 	Frame m_frame;
 	
diff --git a/source/blender/hair/intern/HAIR_solver.cpp b/source/blender/hair/intern/HAIR_solver.cpp
index ef52129..bac867f 100644
--- a/source/blender/hair/intern/HAIR_solver.cpp
+++ b/source/blender/hair/intern/HAIR_solver.cpp
@@ -373,14 +373,19 @@ static void calc_forces(const HairParams &params, const SolverForces &forces, fl
 		float3 root_nor, root_tan;
 		get_root_frame(t0, t1, time + timestep, curve, root_nor, root_tan);
 		
+#if 0
+		float4 rest_rot;
 		if (point_next) {
 			/* rest frame must be rotated according so the first segment is aligned with the rest direction */
-			float4 rot = rotation_between_vecs_to_quat(point_next->rest_co - point->rest_co, point_next->cur.co - point->cur.co);
-			root_nor = mul_qt_v3(rot, root_nor);
-			root_tan = mul_qt_v3(rot, root_tan);
-			normalize_v3_v3(root_nor, root_nor);
-			normalize_v3_v3(root_tan, root_tan);
+			rest_rot = rotation_between_vecs_to_quat(point_next->rest_co - point->rest_co, point_next->cur.co - point->cur.co);
+//			root_nor = mul_qt_v3(rot, root_nor);
+//			root_tan = mul_qt_v3(rot, root_tan);
+//			normalize_v3_v3(root_nor, root_nor);
+//			normalize_v3_v3(root_tan, root_tan);
 		}
+		else
+			rest_rot = unit_qt;
+#endif
 		
 		Frame rest_frame(root_nor, root_tan, cross_v3_v3(root_nor, root_tan));
 		FrameIterator<SolverDataLocWalker> frame_iter(SolverDataLocWalker(curve), curve->avg_rest_length, params.bend_smoothing, rest_frame);
@@ -391,6 +396,9 @@ 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 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->

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list