[Bf-blender-cvs] [8296f3d] hair_system: Moved Blender hair data conversion for the solver to a dedicated SceneConverter class.
Lukas Tönne
noreply at git.blender.org
Wed Jul 30 12:12:28 CEST 2014
Commit: 8296f3d25f58b0415870cad6fbbf670eb6e457a4
Author: Lukas Tönne
Date: Wed Jul 30 11:51:55 2014 +0200
Branches: hair_system
https://developer.blender.org/rB8296f3d25f58b0415870cad6fbbf670eb6e457a4
Moved Blender hair data conversion for the solver to a dedicated
SceneConverter class.
This should handle all the details of the DNA/SolverData differences
and keep the rest of the solver code clean.
===================================================================
M source/blender/hair/CMakeLists.txt
M source/blender/hair/HAIR_capi.cpp
A source/blender/hair/intern/HAIR_scene.cpp
A source/blender/hair/intern/HAIR_scene.h
M source/blender/hair/intern/HAIR_solver.cpp
M source/blender/hair/intern/HAIR_solver.h
===================================================================
diff --git a/source/blender/hair/CMakeLists.txt b/source/blender/hair/CMakeLists.txt
index e5cd991..341207d 100644
--- a/source/blender/hair/CMakeLists.txt
+++ b/source/blender/hair/CMakeLists.txt
@@ -45,6 +45,8 @@ set(SRC
intern/HAIR_math.h
intern/HAIR_math.cpp
intern/HAIR_memalloc.h
+ intern/HAIR_scene.h
+ intern/HAIR_scene.cpp
intern/HAIR_smoothing.h
intern/HAIR_smoothing.cpp
intern/HAIR_solver.h
diff --git a/source/blender/hair/HAIR_capi.cpp b/source/blender/hair/HAIR_capi.cpp
index a30ee0e..56a7ca8 100644
--- a/source/blender/hair/HAIR_capi.cpp
+++ b/source/blender/hair/HAIR_capi.cpp
@@ -36,6 +36,7 @@ extern "C" {
#include "HAIR_capi.h"
+#include "HAIR_scene.h"
#include "HAIR_smoothing.h"
#include "HAIR_solver.h"
#include "HAIR_types.h"
@@ -64,35 +65,8 @@ void HAIR_solver_init(struct HAIR_Solver *csolver, Scene *scene, Object *ob, Hai
solver->forces().gravity = float3(scene->physics_settings.gravity);
- Transform mat = Transform(ob->obmat);
-
- /* count points */
- int totpoints = 0;
- for (hair = hsys->curves, i = 0; i < hsys->totcurves; ++hair, ++i) {
- totpoints += hair->totpoints;
- }
-
- /* allocate data */
- solver->init_data(hsys->totcurves, totpoints);
- Curve *solver_curves = solver->data()->curves;
- Point *solver_points = solver->data()->points;
-
- /* copy data to solver data */
- Point *point = solver_points;
- for (hair = hsys->curves, i = 0; i < hsys->totcurves; ++hair, ++i) {
- solver_curves[i] = Curve(hair->totpoints, point);
-
- for (int k = 0; k < hair->totpoints; ++k, ++point) {
- HairPoint *hair_pt = hair->points + k;
-
- *point = Point(transform_point(mat, hair_pt->rest_co));
- point->cur.co = transform_point(mat, hair_pt->co);
- point->cur.vel = transform_direction(mat, hair_pt->vel);
- }
- }
-
- /* finalize */
- solver->prepare_data();
+ SolverData *data = SceneConverter::build_solver_data(scene, ob, hsys);
+ solver->set_data(data);
}
void HAIR_solver_step(struct HAIR_Solver *csolver, float timestep)
diff --git a/source/blender/hair/intern/HAIR_scene.cpp b/source/blender/hair/intern/HAIR_scene.cpp
new file mode 100644
index 0000000..76cae2d
--- /dev/null
+++ b/source/blender/hair/intern/HAIR_scene.cpp
@@ -0,0 +1,78 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation,
+ * Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+extern "C" {
+#include "DNA_hair_types.h"
+#include "DNA_object_types.h"
+}
+
+#include "HAIR_curve.h"
+#include "HAIR_math.h"
+#include "HAIR_memalloc.h"
+#include "HAIR_scene.h"
+#include "HAIR_solver.h"
+
+HAIR_NAMESPACE_BEGIN
+
+SolverData *SceneConverter::build_solver_data(Scene *scene, Object *ob, HairSystem *hsys)
+{
+ HairCurve *hair;
+ int i;
+
+ Transform mat = Transform(ob->obmat);
+
+ /* count points */
+ int totpoints = 0;
+ for (hair = hsys->curves, i = 0; i < hsys->totcurves; ++hair, ++i) {
+ totpoints += hair->totpoints;
+ }
+
+ /* allocate data */
+ SolverData *data = new SolverData(hsys->totcurves, totpoints);
+ Curve *solver_curves = data->curves;
+ Point *solver_points = data->points;
+
+ /* copy scene data to solver data */
+ Point *point = solver_points;
+ for (hair = hsys->curves, i = 0; i < hsys->totcurves; ++hair, ++i) {
+ solver_curves[i] = Curve(hair->totpoints, point);
+
+ for (int k = 0; k < hair->totpoints; ++k, ++point) {
+ HairPoint *hair_pt = hair->points + k;
+
+ *point = Point(transform_point(mat, hair_pt->rest_co));
+ point->cur.co = transform_point(mat, hair_pt->co);
+ point->cur.vel = transform_direction(mat, hair_pt->vel);
+ }
+ }
+
+ /* finalize */
+ data->precompute_rest_bend();
+
+ return data;
+}
+
+HAIR_NAMESPACE_END
diff --git a/source/blender/hair/intern/HAIR_scene.h b/source/blender/hair/intern/HAIR_scene.h
new file mode 100644
index 0000000..e8548a0
--- /dev/null
+++ b/source/blender/hair/intern/HAIR_scene.h
@@ -0,0 +1,44 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation,
+ * Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __HAIR_SCENE_H__
+#define __HAIR_SCENE_H__
+
+struct Scene;
+struct Object;
+struct HairSystem;
+
+HAIR_NAMESPACE_BEGIN
+
+struct SolverData;
+
+struct SceneConverter {
+ static SolverData *build_solver_data(Scene *scene, Object *ob, HairSystem *hsys);
+};
+
+HAIR_NAMESPACE_END
+
+#endif
diff --git a/source/blender/hair/intern/HAIR_solver.cpp b/source/blender/hair/intern/HAIR_solver.cpp
index 433fecd..54685b4 100644
--- a/source/blender/hair/intern/HAIR_solver.cpp
+++ b/source/blender/hair/intern/HAIR_solver.cpp
@@ -121,19 +121,11 @@ Solver::~Solver()
delete m_data;
}
-void Solver::init_data(int totcurves, int totpoints)
+void Solver::set_data(SolverData *data)
{
- if (!m_data) {
- m_data = new SolverData(totcurves, totpoints);
- }
-}
-
-void Solver::prepare_data()
-{
- if (!m_data)
- return;
-
- m_data->precompute_rest_bend();
+ if (m_data)
+ delete m_data;
+ m_data = data;
}
void Solver::free_data()
diff --git a/source/blender/hair/intern/HAIR_solver.h b/source/blender/hair/intern/HAIR_solver.h
index 8ff5f11..01b40d3 100644
--- a/source/blender/hair/intern/HAIR_solver.h
+++ b/source/blender/hair/intern/HAIR_solver.h
@@ -68,8 +68,7 @@ public:
SolverForces &forces() { return m_forces; }
- void init_data(int totcurves, int totpoints);
- void prepare_data();
+ void set_data(SolverData *data);
void free_data();
SolverData *data() const { return m_data; }
More information about the Bf-blender-cvs
mailing list