[Bf-blender-cvs] [35f4842] hair_system: Time stepping operator for the hair system.
Lukas Tönne
noreply at git.blender.org
Sun Jul 27 17:05:37 CEST 2014
Commit: 35f4842b613f7ed9c9c25b3a582fbfe3dc2622f5
Author: Lukas Tönne
Date: Sun Jul 27 15:16:59 2014 +0200
Branches: hair_system
https://developer.blender.org/rB35f4842b613f7ed9c9c25b3a582fbfe3dc2622f5
Time stepping operator for the hair system.
===================================================================
M source/blender/editors/physics/CMakeLists.txt
M source/blender/editors/physics/hair_ops.c
M source/blender/editors/physics/physics_intern.h
M source/blender/editors/physics/physics_ops.c
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
===================================================================
diff --git a/source/blender/editors/physics/CMakeLists.txt b/source/blender/editors/physics/CMakeLists.txt
index 5a07d55..de82062 100644
--- a/source/blender/editors/physics/CMakeLists.txt
+++ b/source/blender/editors/physics/CMakeLists.txt
@@ -23,6 +23,7 @@ set(INC
../../blenfont
../../blenkernel
../../blenlib
+ ../../hair
../../makesdna
../../makesrna
../../windowmanager
diff --git a/source/blender/editors/physics/hair_ops.c b/source/blender/editors/physics/hair_ops.c
index db0dd85..d9a578c 100644
--- a/source/blender/editors/physics/hair_ops.c
+++ b/source/blender/editors/physics/hair_ops.c
@@ -48,6 +48,8 @@
#include "BKE_particle.h"
#include "BKE_report.h"
+#include "HAIR_capi.h"
+
#include "ED_screen.h"
#include "WM_types.h"
@@ -78,6 +80,45 @@ static int ED_hair_active_poll(bContext *C)
return ED_hair_get(C, NULL, NULL);
}
+/************************ run simulation *********************/
+
+static int hair_simulate_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Object *ob;
+ HairSystem *hsys;
+ struct HAIR_Solver *solver;
+ ED_hair_get(C, &ob, &hsys);
+
+ solver = HAIR_solver_new();
+ HAIR_solver_init(solver, hsys);
+
+
+
+ HAIR_solver_apply(solver, hsys);
+
+ HAIR_solver_free(solver);
+
+ WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+ return OPERATOR_FINISHED;
+}
+
+void HAIR_OT_simulate(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->idname = "HAIR_OT_simulate";
+ ot->name = "Simulate Hair";
+ ot->description = "Evaluate a number of discrete simulation time steps in the hair system";
+
+ /* callbacks */
+ ot->exec = hair_simulate_exec;
+ ot->poll = ED_hair_active_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+/************************ copy hair data from old particles *********************/
+
static void hair_copy_from_particles_psys(Object *ob, HairSystem *hsys, Object *UNUSED(pob), ParticleSystem *psys)
{
HairCurve *hairs;
diff --git a/source/blender/editors/physics/physics_intern.h b/source/blender/editors/physics/physics_intern.h
index 4b69c56..073a376 100644
--- a/source/blender/editors/physics/physics_intern.h
+++ b/source/blender/editors/physics/physics_intern.h
@@ -125,6 +125,7 @@ void RIGIDBODY_OT_world_remove(struct wmOperatorType *ot);
void RIGIDBODY_OT_world_export(struct wmOperatorType *ot);
/* hair_ops.c */
+void HAIR_OT_simulate(struct wmOperatorType *ot);
void HAIR_OT_copy_from_particles(struct wmOperatorType *ot);
#endif /* __PHYSICS_INTERN_H__ */
diff --git a/source/blender/editors/physics/physics_ops.c b/source/blender/editors/physics/physics_ops.c
index 32d27a2..be7be06 100644
--- a/source/blender/editors/physics/physics_ops.c
+++ b/source/blender/editors/physics/physics_ops.c
@@ -104,6 +104,7 @@ static void operatortypes_particle(void)
// WM_operatortype_append(RIGIDBODY_OT_world_export);
WM_operatortype_append(HAIR_OT_copy_from_particles);
+ WM_operatortype_append(HAIR_OT_simulate);
}
static void keymap_particle(wmKeyConfig *keyconf)
diff --git a/source/blender/hair/HAIR_capi.cpp b/source/blender/hair/HAIR_capi.cpp
index 8197976..0345e1c 100644
--- a/source/blender/hair/HAIR_capi.cpp
+++ b/source/blender/hair/HAIR_capi.cpp
@@ -38,7 +38,7 @@ extern "C" {
using namespace HAIR_NAMESPACE;
-struct HAIR_Solver *HAIR_solver_new()
+struct HAIR_Solver *HAIR_solver_new(void)
{
Solver *solver = new Solver();
@@ -66,8 +66,8 @@ void HAIR_solver_init(struct HAIR_Solver *csolver, HairSystem *hsys)
/* allocate data */
solver->init_data(hsys->totcurves, totpoints);
- Curve *solver_curves = solver->data().curves;
- Point *solver_points = solver->data().points;
+ Curve *solver_curves = solver->data()->curves;
+ Point *solver_points = solver->data()->points;
/* copy data to solver data */
Point *point = solver_points;
@@ -86,8 +86,8 @@ void HAIR_solver_apply(struct HAIR_Solver *csolver, HairSystem *hsys)
Solver *solver = (Solver *)csolver;
int i;
- Curve *solver_curves = solver->data().curves;
- int totcurves = solver->data().totcurves;
+ Curve *solver_curves = solver->data()->curves;
+ int totcurves = solver->data()->totcurves;
/* copy solver data to DNA */
for (i = 0; i < totcurves && i < hsys->totcurves; ++i) {
diff --git a/source/blender/hair/HAIR_capi.h b/source/blender/hair/HAIR_capi.h
index 8ccb2ae..d6a9581 100644
--- a/source/blender/hair/HAIR_capi.h
+++ b/source/blender/hair/HAIR_capi.h
@@ -34,7 +34,7 @@ struct HairSystem;
struct HAIR_Solver;
struct HAIR_SmoothingIteratorFloat3;
-struct HAIR_Solver *HAIR_solver_new();
+struct HAIR_Solver *HAIR_solver_new(void);
void HAIR_solver_free(struct HAIR_Solver *solver);
void HAIR_solver_init(struct HAIR_Solver *solver, struct HairSystem *hsys);
void HAIR_solver_apply(struct HAIR_Solver *solver, struct HairSystem *hsys);
diff --git a/source/blender/hair/intern/HAIR_solver.cpp b/source/blender/hair/intern/HAIR_solver.cpp
index 7c2530b..834133c 100644
--- a/source/blender/hair/intern/HAIR_solver.cpp
+++ b/source/blender/hair/intern/HAIR_solver.cpp
@@ -54,26 +54,36 @@ SolverData::SolverData(const SolverData &other) :
SolverData::~SolverData()
{
- delete curves;
- delete points;
+ if (curves)
+ delete[] curves;
+ if (points)
+ delete[] points;
}
-Solver::Solver()
+Solver::Solver() :
+ m_data(NULL)
{
}
Solver::~Solver()
{
+ if (m_data)
+ delete m_data;
}
void Solver::init_data(int totcurves, int totpoints)
{
- m_data = SolverData(totcurves, totpoints);
+ if (!m_data) {
+ m_data = new SolverData(totcurves, totpoints);
+ }
}
void Solver::free_data()
{
- m_data = SolverData();
+ if (m_data) {
+ delete m_data;
+ m_data = NULL;
+ }
}
HAIR_NAMESPACE_END
diff --git a/source/blender/hair/intern/HAIR_solver.h b/source/blender/hair/intern/HAIR_solver.h
index d7f64ef..387570a 100644
--- a/source/blender/hair/intern/HAIR_solver.h
+++ b/source/blender/hair/intern/HAIR_solver.h
@@ -54,13 +54,12 @@ public:
void init_data(int totcurves, int totpoints);
void free_data();
- SolverData &data() { return m_data; }
- const SolverData &data() const { return m_data; }
+ SolverData *data() const { return m_data; }
void step(float timestep);
private:
- SolverData m_data;
+ SolverData *m_data;
HAIR_CXX_CLASS_ALLOC(Solver)
};
More information about the Bf-blender-cvs
mailing list