[Bf-blender-cvs] [2190277] hair_system: Some cleanup and restructuring of the integrator code.
Lukas Tönne
noreply at git.blender.org
Thu Aug 7 19:11:33 CEST 2014
Commit: 2190277e7249e91e7b8cc74099d71fa50284bdf6
Author: Lukas Tönne
Date: Thu Aug 7 19:08:27 2014 +0200
Branches: hair_system
https://developer.blender.org/rB2190277e7249e91e7b8cc74099d71fa50284bdf6
Some cleanup and restructuring of the integrator code.
This divides the integrator loop more clearly into distinct steps, i.e.
= Outer Loop =
> detect collisions (todo)
= Inner Loop =
* calculate internal forces
* calculate external forces
* handle collision responses
* calculate damping
> update state
> synchronize threads (not needed yet)
===================================================================
M source/blender/editors/space_view3d/drawhair.c
M source/blender/hair/CMakeLists.txt
A source/blender/hair/intern/HAIR_collision.cpp
M source/blender/hair/intern/HAIR_math.h
M source/blender/hair/intern/HAIR_solver.cpp
M source/blender/hair/intern/HAIR_solver.h
===================================================================
diff --git a/source/blender/editors/space_view3d/drawhair.c b/source/blender/editors/space_view3d/drawhair.c
index 6f9bda9..a6a8be9 100644
--- a/source/blender/editors/space_view3d/drawhair.c
+++ b/source/blender/editors/space_view3d/drawhair.c
@@ -104,12 +104,12 @@ bool draw_hair_system(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar, Ba
/* ---------------- debug drawing ---------------- */
-#define SHOW_POINTS
+//#define SHOW_POINTS
//#define SHOW_ROOTS
-#define SHOW_FRAMES
+//#define SHOW_FRAMES
//#define SHOW_SMOOTHING
//#define SHOW_CYLINDERS
-//#define SHOW_CONTACTS
+#define SHOW_CONTACTS
static void draw_hair_debug_points(HairSystem *hsys, HAIR_SolverDebugPoint *dpoints, int dtotpoints)
{
diff --git a/source/blender/hair/CMakeLists.txt b/source/blender/hair/CMakeLists.txt
index 15a0f5f..858a236 100644
--- a/source/blender/hair/CMakeLists.txt
+++ b/source/blender/hair/CMakeLists.txt
@@ -53,6 +53,7 @@ set(SRC
intern/HAIR_smoothing.cpp
intern/HAIR_solver.h
intern/HAIR_solver.cpp
+ intern/HAIR_collision.cpp
intern/HAIR_types.h
intern/HAIR_types.cpp
)
diff --git a/source/blender/hair/intern/HAIR_collision.cpp b/source/blender/hair/intern/HAIR_collision.cpp
new file mode 100644
index 0000000..a1c0eaf
--- /dev/null
+++ b/source/blender/hair/intern/HAIR_collision.cpp
@@ -0,0 +1,187 @@
+/*
+ * ***** 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 *****
+ */
+
+#include <vector>
+
+extern "C" {
+#include "RBI_api.h"
+}
+
+#include "HAIR_debug.h"
+#include "HAIR_math.h"
+#include "HAIR_solver.h"
+
+HAIR_NAMESPACE_BEGIN
+
+#if 0
+PointContactInfo::PointContactInfo(const btManifoldPoint &bt_point) :
+ local_point_hair(bt_point.m_localPointA),
+ local_point_body(bt_point.m_localPointB),
+ world_point_hair(bt_point.m_positionWorldOnA),
+ world_point_body(bt_point.m_positionWorldOnB),
+ world_normal_body(bt_point.m_normalWorldOnB),
+ distance(bt_point.m_distance1),
+ friction(bt_point.m_combinedFriction),
+ restitution(bt_point.m_combinedRestitution)
+{
+}
+#endif
+
+struct HairContactResultCallback : btCollisionWorld::ContactResultCallback {
+ btScalar addSingleResult(btManifoldPoint &cp,
+ const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0,
+ const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1)
+ {
+ if (cp.getDistance() < 0.f) {
+
+
+
+// const btVector3 &ptA = cp.getPositionWorldOnA();
+// const btVector3 &ptB = cp.getPositionWorldOnB();
+// const btVector3 &normalOnB = cp.m_normalWorldOnB;
+
+// Debug::collision_contact(float3(ptA.x(), ptA.y(), ptA.z()), float3(ptB.x(), ptB.y(), ptB.z()));
+ }
+
+ /* note: return value is unused
+ * http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20990#p20990
+ */
+ return 0.0f;
+ }
+};
+
+#if 0
+struct HairContactResultCallback : btCollisionWorld::ContactResultCallback {
+ btScalar addSingleResult(btManifoldPoint &cp,
+ const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0,
+ const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1)
+ {
+ if (cp.getDistance() < 0.f) {
+ const btVector3 &ptA = cp.getPositionWorldOnA();
+ const btVector3 &ptB = cp.getPositionWorldOnB();
+// const btVector3 &normalOnB = cp.m_normalWorldOnB;
+
+ Debug::collision_contact(float3(ptA.x(), ptA.y(), ptA.z()), float3(ptB.x(), ptB.y(), ptB.z()));
+ }
+
+ /* note: return value is unused
+ * http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20990#p20990
+ */
+ return 0.0f;
+ }
+};
+
+static void debug_ghost_contacts(SolverData *data, btDynamicsWorld *dworld, rbGhostObject *object)
+{
+ btPairCachingGhostObject *ghost = &object->ghost;
+
+ btManifoldArray manifold_array;
+ const btBroadphasePairArray& pairs = ghost->getOverlappingPairCache()->getOverlappingPairArray();
+ int num_pairs = pairs.size();
+
+ for (int i = 0; i < num_pairs; i++) {
+ manifold_array.clear();
+
+ const btBroadphasePair& pair = pairs[i];
+
+ /* unless we manually perform collision detection on this pair, the contacts are in the dynamics world paircache */
+ btBroadphasePair* collision_pair = dworld->getPairCache()->findPair(pair.m_pProxy0,pair.m_pProxy1);
+ if (!collision_pair)
+ continue;
+
+ btCollisionObject *ob0 = (btCollisionObject *)pair.m_pProxy0->m_clientObject;
+ btCollisionObject *ob1 = (btCollisionObject *)pair.m_pProxy1->m_clientObject;
+ btCollisionObject *other = ob0 == ghost ? ob1 : ob0;
+
+ HairContactResultCallback cb;
+
+ Curve *curve = data->curves;
+ for (int i = 0; i < data->totcurves; ++i, ++curve) {
+ Point *pt = curve->points;
+ for (int k = 0; k < curve->totpoints; ++k, ++pt) {
+ dworld->contactPairTest(&pt->rb_ghost.ghost, other, cb);
+ }
+ }
+
+#if 0
+ if (collision_pair->m_algorithm)
+ collision_pair->m_algorithm->getAllContactManifolds(manifold_array);
+
+ for (int j = 0; j < manifold_array.size(); j++) {
+ btPersistentManifold* manifold = manifold_array[j];
+ btScalar direction_sign = manifold->getBody0() == ghost ? btScalar(-1.0) : btScalar(1.0);
+ for (int p = 0; p < manifold->getNumContacts(); p++) {
+ const btManifoldPoint &pt = manifold->getContactPoint(p);
+ if (pt.getDistance() < 0.f) {
+ const btVector3 &ptA = pt.getPositionWorldOnA();
+ const btVector3 &ptB = pt.getPositionWorldOnB();
+ const btVector3 &normalOnB = pt.m_normalWorldOnB;
+
+ Debug::collision_contact(float3(ptA.x(), ptA.y(), ptA.z()), float3(ptB.x(), ptB.y(), ptB.z()));
+ }
+ }
+ }
+#endif
+ }
+}
+
+void SolverData::debug_contacts(rbDynamicsWorld *world)
+{
+ btDynamicsWorld *dworld = world->dynamicsWorld;
+
+ debug_ghost_contacts(this, dworld, &rb_ghost);
+
+#if 0 /* collision shape / bounding box used for main collision detection */
+ if (rb_ghost.ghost.getBroadphaseHandle()) {
+ float3 c[8];
+ c[0] = float3((float *)rb_ghost.ghost.getBroadphaseHandle()->m_aabbMin.m_floats);
+ c[7] = float3((float *)rb_ghost.ghost.getBroadphaseHandle()->m_aabbMax.m_floats);
+ c[1] = float3(c[7].x, c[0].y, c[0].z);
+ c[2] = float3(c[0].x, c[7].y, c[0].z);
+ c[3] = float3(c[7].x, c[7].y, c[0].z);
+ c[4] = float3(c[0].x, c[0].y, c[7].z);
+ c[5] = float3(c[7].x, c[0].y, c[7].z);
+ c[6] = float3(c[0].x, c[7].y, c[7].z);
+ Debug::collision_contact(c[0], c[1]);
+ Debug::collision_contact(c[1], c[3]);
+ Debug::collision_contact(c[3], c[2]);
+ Debug::collision_contact(c[2], c[0]);
+
+ Debug::collision_contact(c[0], c[4]);
+ Debug::collision_contact(c[1], c[5]);
+ Debug::collision_contact(c[2], c[6]);
+ Debug::collision_contact(c[3], c[7]);
+
+ Debug::collision_contact(c[4], c[5]);
+ Debug::collision_contact(c[5], c[7]);
+ Debug::collision_contact(c[7], c[6]);
+ Debug::collision_contact(c[6], c[4]);
+ }
+#endif
+}
+#endif
+
+HAIR_NAMESPACE_END
diff --git a/source/blender/hair/intern/HAIR_math.h b/source/blender/hair/intern/HAIR_math.h
index b232b3e..d503f21 100644
--- a/source/blender/hair/intern/HAIR_math.h
+++ b/source/blender/hair/intern/HAIR_math.h
@@ -61,6 +61,11 @@ __forceinline float2 operator - (const float2 &a, const float2 &b)
return float2(a.x - b.x, a.y - b.y);
}
+__forceinline float2 operator - (const float2 &a)
+{
+ return float2(-a.x, -a.y);
+}
+
__forceinline float2 operator * (float fac, const float2 &a)
{
return float2(fac * a.x, fac * a.y);
@@ -87,6 +92,11 @@ __forceinline float3 operator - (const float3 &a, const float3 &b)
return float3(a.x - b.x, a.y - b.y, a.z - b.z);
}
+__forceinline float3 operator - (const float3 &a)
+{
+ return float3(-a.x, -a.y, -a.z);
+}
+
__forceinline float3 operator * (float fac, const float3 &a)
{
return float3(fac * a.x, fac * a.y, fac * a.z);
diff --git a/source/blender/hair/intern/HAIR_solver.cpp b/source/blender/hair/intern/HAIR_solver.cpp
index 174ba35..84b5753 100644
--- a/source/blender/hair/intern/HAIR_solver.cpp
+++ b/source/blender/hair/intern/HAIR_solver.cpp
@@ -145,113 +145,6 @@ void SolverData::precompute_rest_bend(const HairParams ¶ms)
}
}
-struct HairContactResultCallback : btCollisionWorld::ContactResultCallback {
- btScalar addSingleResult(btManifoldPoint &cp,
- const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0,
- const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1)
- {
- if (cp.getDistance() < 0.f) {
- const btVector3 &ptA = cp.getPositionWorldOnA();
- const btVector3 &ptB = cp.getPositionWorldOnB();
-// const btVector3 &normalOnB = cp.m_normalWorldOnB;
-
- Debug::collision_contact(float3(ptA.x(), ptA.y(), ptA.z()), float3(ptB.x(), ptB.y(), ptB.z()));
- }
-
- /* note: return value is unused
- * http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20990#p20990
- */
- return 0.0f;
- }
-};
-
-static void debug_ghost_contacts(SolverData *data, btDynamicsWorld *dworld, rbGhostObject *object)
-{
- btPairCachingGhostObject *ghost = &object->ghost;
-
- btManifoldArray manifold_array;
- const btBroadphasePairArray& pairs = ghost->getOverlappingPairCache()->getOverlappingPairArray();
- int num_pairs = pairs.size();
-
- for (int i = 0; i < num_pairs; i++) {
- manifold_array.clear();
-
- const btBroadphasePair& pai
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list