[Bf-blender-cvs] [a766270] hair_system: Placed debug info structs in their own header, so they can be shared between C and C++ code.
Lukas Tönne
noreply at git.blender.org
Mon Aug 18 12:08:34 CEST 2014
Commit: a7662701b80d35e7cf3dfd2cf24f1e1dcbdccd5d
Author: Lukas Tönne
Date: Mon Aug 18 09:48:29 2014 +0200
Branches: hair_system
https://developer.blender.org/rBa7662701b80d35e7cf3dfd2cf24f1e1dcbdccd5d
Placed debug info structs in their own header, so they can be shared
between C and C++ code.
This is straightforward data, no member functions or anything needed.
Sharing the structs avoids redundancy and bloated code from copying.
Also now store a debug data list for threads when enabled.
===================================================================
M source/blender/editors/space_view3d/drawhair.c
M source/blender/hair/CMakeLists.txt
M source/blender/hair/HAIR_capi.cpp
M source/blender/hair/HAIR_capi.h
A source/blender/hair/HAIR_debug_types.h
M source/blender/hair/intern/HAIR_debug.h
M source/blender/hair/intern/HAIR_solver.cpp
===================================================================
diff --git a/source/blender/editors/space_view3d/drawhair.c b/source/blender/editors/space_view3d/drawhair.c
index 1f2ea99..617b187 100644
--- a/source/blender/editors/space_view3d/drawhair.c
+++ b/source/blender/editors/space_view3d/drawhair.c
@@ -53,7 +53,7 @@
#include "UI_resources.h"
-#include "HAIR_capi.h"
+#include "HAIR_debug_types.h"
/* ******** Hair Drawing ******** */
diff --git a/source/blender/hair/CMakeLists.txt b/source/blender/hair/CMakeLists.txt
index 858a236..5a97154 100644
--- a/source/blender/hair/CMakeLists.txt
+++ b/source/blender/hair/CMakeLists.txt
@@ -39,6 +39,7 @@ set(INC_SYS
set(SRC
HAIR_capi.h
HAIR_capi.cpp
+ HAIR_debug_types.h
intern/HAIR_curve.h
intern/HAIR_curve.cpp
diff --git a/source/blender/hair/HAIR_capi.cpp b/source/blender/hair/HAIR_capi.cpp
index 91e5030..2a63b8f 100644
--- a/source/blender/hair/HAIR_capi.cpp
+++ b/source/blender/hair/HAIR_capi.cpp
@@ -38,6 +38,7 @@ extern "C" {
#include "HAIR_capi.h"
#include "HAIR_debug.h"
+#include "HAIR_debug_types.h"
#include "HAIR_scene.h"
#include "HAIR_smoothing.h"
#include "HAIR_solver.h"
@@ -111,7 +112,6 @@ void HAIR_solver_step_debug(struct HAIR_Solver *csolver, float time, float times
HAIR_SolverDebugContact **contacts, int *totcontacts)
{
Solver *solver = (Solver *)csolver;
- Transform itfm(ob_imat);
DebugThreadDataVector thread_data_list;
solver->step_threaded(time, timestep, &thread_data_list);
@@ -122,7 +122,6 @@ void HAIR_solver_step_debug(struct HAIR_Solver *csolver, float time, float times
*points = (HAIR_SolverDebugPoint *)MEM_mallocN(sizeof(HAIR_SolverDebugPoint) * tot, "hair solver point debug data");
}
- HAIR_SolverDebugContact *contact;
if (contacts && totcontacts) {
*totcontacts = 0;
for (int d = 0; d < thread_data_list.size(); ++d) {
@@ -130,34 +129,39 @@ void HAIR_solver_step_debug(struct HAIR_Solver *csolver, float time, float times
*totcontacts += data.contacts.size();
}
*contacts = (HAIR_SolverDebugContact *)MEM_mallocN(sizeof(HAIR_SolverDebugContact) * (*totcontacts), "hair solver contact debug data");
- contact = *contacts;
}
- else
- contact = NULL;
+ HAIR_SolverDebugContact *pcontact = contacts ? *contacts : NULL;
for (int d = 0; d < thread_data_list.size(); ++d) {
const DebugThreadData &data = thread_data_list[d];
if (points && totpoints) {
int tot = solver->data()->totpoints;
for (int i = 0; i < data.points.size(); ++i) {
- const DebugPoint &dbg_point = data.points[i];
- if (dbg_point.index < 0 || dbg_point.index >= tot)
+ const HAIR_SolverDebugPoint &dp = data.points[i];
+ if (dp.index < 0 || dp.index >= tot)
continue;
- HAIR_SolverDebugPoint *p = (*points) + dbg_point.index;
- copy_v3_v3(p->bend, transform_direction(itfm, dbg_point.bend).data());
- copy_v3_v3(p->frame[0], transform_direction(itfm, dbg_point.frame.normal).data());
- copy_v3_v3(p->frame[1], transform_direction(itfm, dbg_point.frame.tangent).data());
- copy_v3_v3(p->frame[2], transform_direction(itfm, dbg_point.frame.cotangent).data());
+ HAIR_SolverDebugPoint &p = (*points)[dp.index];
+ p = dp;
+
+ /* transform to object space for display */
+ mul_m4_v3(ob_imat, p.co);
+ mul_mat3_m4_v3(ob_imat, p.bend);
+ mul_mat3_m4_v3(ob_imat, p.frame[0]);
+ mul_mat3_m4_v3(ob_imat, p.frame[1]);
+ mul_mat3_m4_v3(ob_imat, p.frame[2]);
}
}
if (contacts && totcontacts) {
- for (int i = 0; i < data.contacts.size(); ++i, ++contact) {
- HAIR_SolverDebugContact *c = contact;
- copy_v3_v3(c->coA, transform_point(itfm, data.contacts[i].coA).data());
- copy_v3_v3(c->coB, transform_point(itfm, data.contacts[i].coB).data());
+ for (int i = 0; i < data.contacts.size(); ++i) {
+ const HAIR_SolverDebugContact &dc = data.contacts[i];
+ HAIR_SolverDebugContact &c = *(pcontact++);
+ c = dc;
+
+ mul_m4_v3(ob_imat, c.coA);
+ mul_m4_v3(ob_imat, c.coB);
}
}
}
diff --git a/source/blender/hair/HAIR_capi.h b/source/blender/hair/HAIR_capi.h
index 0037384..d6618f4 100644
--- a/source/blender/hair/HAIR_capi.h
+++ b/source/blender/hair/HAIR_capi.h
@@ -24,6 +24,9 @@
* ***** END GPL LICENSE BLOCK *****
*/
+#ifndef __HAIR_CAPI_H__
+#define __HAIR_CAPI_H__
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -38,6 +41,9 @@ struct rbDynamicsWorld;
struct HAIR_Solver;
struct HAIR_SmoothingIteratorFloat3;
struct HAIR_FrameIterator;
+struct HAIR_SolverDebugContact;
+struct HAIR_SolverDebugPoint;
+
struct HAIR_Solver *HAIR_solver_new(void);
void HAIR_solver_free(struct HAIR_Solver *solver);
@@ -46,15 +52,6 @@ void HAIR_solver_build_data(struct HAIR_Solver *solver, struct Scene *scene, str
void HAIR_solver_update_externals(struct HAIR_Solver *solver, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, struct HairSystem *hsys, float time);
void HAIR_solver_rebuild_rigidbodyworld(struct HAIR_Solver *solver, struct rbDynamicsWorld *world);
-typedef struct HAIR_SolverDebugContact {
- float coA[3], coB[3];
-} HAIR_SolverDebugContact;
-
-typedef struct HAIR_SolverDebugPoint {
- float bend[3];
- float frame[3][3];
-} HAIR_SolverDebugPoint;
-
void HAIR_solver_step(struct HAIR_Solver *solver, float time, float timestep);
void HAIR_solver_step_debug(struct HAIR_Solver *csolver, float time, float timestep,
float ob_imat[4][4],
@@ -80,3 +77,5 @@ void HAIR_frame_iter_next(struct HAIR_FrameIterator *iter);
#ifdef __cplusplus
}
#endif
+
+#endif
diff --git a/source/blender/hair/HAIR_debug_types.h b/source/blender/hair/HAIR_debug_types.h
new file mode 100644
index 0000000..988c966
--- /dev/null
+++ b/source/blender/hair/HAIR_debug_types.h
@@ -0,0 +1,53 @@
+/*
+ * ***** 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_DEBUG_TYPES_H__
+#define __HAIR_DEBUG_TYPES_H__
+
+/** Struct types for debugging info,
+ * shared between C and C++ code to avoid redundancy
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct HAIR_SolverDebugContact {
+ float coA[3], coB[3];
+} HAIR_SolverDebugContact;
+
+typedef struct HAIR_SolverDebugPoint {
+ int index;
+ float co[3];
+ float bend[3];
+ float frame[3][3];
+} HAIR_SolverDebugPoint;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/source/blender/hair/intern/HAIR_debug.h b/source/blender/hair/intern/HAIR_debug.h
index e9769e9..2fea6cd 100644
--- a/source/blender/hair/intern/HAIR_debug.h
+++ b/source/blender/hair/intern/HAIR_debug.h
@@ -29,6 +29,11 @@
#include <vector>
+extern "C" {
+#include "BLI_math.h"
+}
+
+#include "HAIR_debug_types.h"
#include "HAIR_smoothing.h"
#include "HAIR_types.h"
@@ -40,21 +45,10 @@ HAIR_NAMESPACE_BEGIN
struct SolverData;
-struct DebugPoint {
- int index;
-
- float3 bend;
- Frame frame;
-};
-
-struct DebugContact {
- float3 coA, coB;
-};
-
struct DebugThreadData
{
- typedef std::vector<DebugPoint> Points;
- typedef std::vector<DebugContact> CollisionContacts;
+ typedef std::vector<HAIR_SolverDebugPoint> Points;
+ typedef std::vector<HAIR_SolverDebugContact> CollisionContacts;
CollisionContacts contacts;
Points points;
@@ -62,19 +56,23 @@ struct DebugThreadData
struct Debug {
- static void point(DebugThreadData *data, int index, const float3 &bend, const Frame &frame)
+ static void point(DebugThreadData *data, int index, const float3 &co, const float3 &bend, const Frame &frame)
{
#ifdef HAIR_DEBUG
if (data) {
- DebugPoint p;
+ HAIR_SolverDebugPoint p;
p.index = index;
- p.bend = bend;
- p.frame = frame;
+ copy_v3_v3(p.co, co.data());
+ copy_v3_v3(p.bend, bend.data());
+ copy_v3_v3(p.frame[0], frame.normal.data());
+ copy_v3_v3(p.frame[1], frame.tangent.data());
+ copy_v3_v3(p.frame[2], frame.cotangent.data());
data->points.push_back(p);
}
#else
(void)data;
(void)index;
+ (void)co;
(void)bend;
(void)frame;
#endif
@@ -84,9 +82,9 @@ struct Debug {
{
#ifdef HAIR_DEBUG
if (data) {
- DebugContact c;
- c.coA = coA;
- c.coB = coB;
+ HAIR_SolverDebugContact c;
+ copy_v3_v3(c.coA, coA.data());
+ copy_v3_v3(c.coB, coB.data());
data->contacts.push_back(c);
}
#else
diff --git a/source/blender/hair/intern/HAIR_solver.cpp b/source/blender/hair/intern/HAIR_solver.cpp
index b90a148..2fc6159 100644
--- a/source/blender/hair/intern/HAIR_solver.cpp
+++ b/source/blender/hair/intern/HAIR_solver.cpp
@@ -274,6 +274,8 @@ struct SolverTaskData {
Point *points;
int startcurve, totcurves;
int startpoint, totpoints;
+
+ DebugThreadData *debug_data;
};
static void accum_internal_forces(const HairParams ¶ms, const SolverForces &forces, float time, float timestep, const Point *point0, const Point *point1, const Frame &frame,
@@ -567,15 +569,21 @@ static void advance_state(SolverData *data)
void Solver::step_threaded(float time, float timestep, DebugThreadDataVector *debug_thread_data)
{
+ /* global debug data for the host thread */
+ DebugThreadData *debug_data = NULL;
+ if (debug_thread_data) {
+ debug_thread_data->push_back(DebugThreadData());
+ debug_data = &debug_thread_data->back();
+ }
+
/* filter and cache Bullet contact information */
PointContactCache contacts;
cache_point_contacts(contacts);
- if (debug_thread_data) {
- debug
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list