[Bf-blender-cvs] [c9e8c87] hair_system: Use the actual gravity from the scene for the hair simulation.
Lukas Tönne
noreply at git.blender.org
Mon Jul 28 19:29:05 CEST 2014
Commit: c9e8c875afe33e83f343f66f95e160f73eaeab56
Author: Lukas Tönne
Date: Mon Jul 28 17:47:18 2014 +0200
Branches: hair_system
https://developer.blender.org/rBc9e8c875afe33e83f343f66f95e160f73eaeab56
Use the actual gravity from the scene for the hair simulation.
A new solver struct for forces has been added, this is supposed to
organize all the external influences in some consistent way.
===================================================================
M source/blender/hair/HAIR_capi.cpp
M source/blender/hair/HAIR_capi.h
M source/blender/hair/intern/HAIR_solver.cpp
M source/blender/hair/intern/HAIR_solver.h
M source/blender/modifiers/intern/MOD_hair.c
===================================================================
diff --git a/source/blender/hair/HAIR_capi.cpp b/source/blender/hair/HAIR_capi.cpp
index 39e3017..5dd8cc2 100644
--- a/source/blender/hair/HAIR_capi.cpp
+++ b/source/blender/hair/HAIR_capi.cpp
@@ -29,6 +29,7 @@ extern "C" {
#include "DNA_hair_types.h"
#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
#include "BKE_hair.h"
}
@@ -55,12 +56,14 @@ void HAIR_solver_free(struct HAIR_Solver *csolver)
delete solver;
}
-void HAIR_solver_init(struct HAIR_Solver *csolver, Object *ob, HairSystem *hsys)
+void HAIR_solver_init(struct HAIR_Solver *csolver, Scene *scene, Object *ob, HairSystem *hsys)
{
Solver *solver = (Solver *)csolver;
HairCurve *hair;
int i;
+ solver->forces().gravity = float3(scene->physics_settings.gravity);
+
Transform mat = Transform(ob->obmat);
/* count points */
diff --git a/source/blender/hair/HAIR_capi.h b/source/blender/hair/HAIR_capi.h
index 87d121a..7de4374 100644
--- a/source/blender/hair/HAIR_capi.h
+++ b/source/blender/hair/HAIR_capi.h
@@ -28,6 +28,8 @@
extern "C" {
#endif
+struct Scene;
+struct Object;
struct HairCurve;
struct HairSystem;
@@ -36,7 +38,7 @@ struct HAIR_SmoothingIteratorFloat3;
struct HAIR_Solver *HAIR_solver_new(const struct HairParams *params);
void HAIR_solver_free(struct HAIR_Solver *solver);
-void HAIR_solver_init(struct HAIR_Solver *solver, struct Object *ob, struct HairSystem *hsys);
+void HAIR_solver_init(struct HAIR_Solver *solver, struct Scene *scene, struct Object *ob, struct HairSystem *hsys);
void HAIR_solver_step(struct HAIR_Solver *solver, float timestep);
void HAIR_solver_apply(struct HAIR_Solver *solver, struct Object *ob, struct HairSystem *hsys);
diff --git a/source/blender/hair/intern/HAIR_solver.cpp b/source/blender/hair/intern/HAIR_solver.cpp
index 111b2d3..797962a 100644
--- a/source/blender/hair/intern/HAIR_solver.cpp
+++ b/source/blender/hair/intern/HAIR_solver.cpp
@@ -61,6 +61,13 @@ SolverData::~SolverData()
delete[] points;
}
+
+SolverForces::SolverForces()
+{
+ gravity = float3(0.0f, 0.0f, 0.0f);
+}
+
+
Solver::Solver(const HairParams ¶ms) :
m_params(params),
m_data(NULL)
@@ -107,7 +114,9 @@ float3 Solver::calc_stretch(Curve *curve, Point *point0, Point *point1, float ti
float3 Solver::calc_acceleration(Curve *curve, Point *point, float time, float3 prev_stretch, float3 stretch, Point::State &state) const
{
- float3 acc = float3(0.0f, 0.0f, -0.01f);
+ float3 acc = float3(0.0f, 0.0f, 0.0f);
+
+ acc = acc + m_forces.gravity;
acc = acc - prev_stretch + stretch;
diff --git a/source/blender/hair/intern/HAIR_solver.h b/source/blender/hair/intern/HAIR_solver.h
index 3cd0e45..09798e2 100644
--- a/source/blender/hair/intern/HAIR_solver.h
+++ b/source/blender/hair/intern/HAIR_solver.h
@@ -50,6 +50,12 @@ struct SolverData {
HAIR_CXX_CLASS_ALLOC(SolverData)
};
+struct SolverForces {
+ SolverForces();
+
+ float3 gravity;
+};
+
class Solver
{
public:
@@ -58,6 +64,8 @@ public:
const HairParams ¶ms() const { return m_params; }
+ SolverForces &forces() { return m_forces; }
+
void init_data(int totcurves, int totpoints);
void free_data();
SolverData *data() const { return m_data; }
@@ -71,6 +79,7 @@ protected:
private:
HairParams m_params;
+ SolverForces m_forces;
SolverData *m_data;
HAIR_CXX_CLASS_ALLOC(Solver)
diff --git a/source/blender/modifiers/intern/MOD_hair.c b/source/blender/modifiers/intern/MOD_hair.c
index 7e80141..85afa16 100644
--- a/source/blender/modifiers/intern/MOD_hair.c
+++ b/source/blender/modifiers/intern/MOD_hair.c
@@ -93,7 +93,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
int s;
solver = HAIR_solver_new(&hsys->params);
- HAIR_solver_init(solver, ob, hsys);
+ HAIR_solver_init(solver, scene, ob, hsys);
if (num_steps < 10000) {
for (s = 0; s < num_steps; ++s) {
More information about the Bf-blender-cvs
mailing list