Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/extern
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2006-01-11 01:10:14 +0300
committerTon Roosendaal <ton@blender.org>2006-01-11 01:10:14 +0300
commite7285229b824f959f84efe6774c506034cf0f98e (patch)
treef4c96dae29629cc5e5b1c335d93abc82647a11c5 /extern
parentd594594cbe9c9eb3bc3c8a7708601e68693d324d (diff)
parent185c6bb49ce994d66fc67673b01a014161fa307d (diff)
Tuesday merger of bf-blender into orange branch.
Diffstat (limited to 'extern')
-rw-r--r--extern/bullet/Bullet/CollisionShapes/BvhTriangleMeshShape.cpp134
-rw-r--r--extern/bullet/Bullet/CollisionShapes/BvhTriangleMeshShape.h53
-rw-r--r--extern/bullet/Bullet/CollisionShapes/CollisionMargin.h11
-rw-r--r--extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.cpp86
-rw-r--r--extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.h49
-rw-r--r--extern/bullet/Bullet/CollisionShapes/EmptyShape.cpp45
-rw-r--r--extern/bullet/Bullet/CollisionShapes/EmptyShape.h75
-rw-r--r--extern/bullet/Bullet/CollisionShapes/OptimizedBvh.cpp268
-rw-r--r--extern/bullet/Bullet/CollisionShapes/OptimizedBvh.h92
-rw-r--r--extern/bullet/Bullet/CollisionShapes/TriangleCallback.cpp23
-rw-r--r--extern/bullet/Bullet/CollisionShapes/TriangleIndexVertexArray.cpp49
-rw-r--r--extern/bullet/Bullet/CollisionShapes/TriangleIndexVertexArray.h46
-rw-r--r--extern/bullet/Bullet/NarrowPhaseCollision/ManifoldContactAddResult.cpp33
-rw-r--r--extern/bullet/Bullet/NarrowPhaseCollision/ManifoldContactAddResult.h32
14 files changed, 996 insertions, 0 deletions
diff --git a/extern/bullet/Bullet/CollisionShapes/BvhTriangleMeshShape.cpp b/extern/bullet/Bullet/CollisionShapes/BvhTriangleMeshShape.cpp
new file mode 100644
index 00000000000..0c94b884597
--- /dev/null
+++ b/extern/bullet/Bullet/CollisionShapes/BvhTriangleMeshShape.cpp
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2006 Erwin Coumans http://continuousphysics.com/Bullet/
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies.
+ * Erwin Coumans makes no representations about the suitability
+ * of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+*/
+
+//#define DISABLE_BVH
+
+
+#include "CollisionShapes/BvhTriangleMeshShape.h"
+#include "CollisionShapes/OptimizedBvh.h"
+
+///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization.
+///Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
+BvhTriangleMeshShape::BvhTriangleMeshShape(StridingMeshInterface* meshInterface)
+:TriangleMeshShape(meshInterface)
+{
+ //construct bvh from meshInterface
+#ifndef DISABLE_BVH
+
+ m_bvh = new OptimizedBvh();
+ m_bvh->Build(meshInterface);
+
+#endif //DISABLE_BVH
+
+}
+
+BvhTriangleMeshShape::~BvhTriangleMeshShape()
+{
+ delete m_bvh;
+}
+
+//perform bvh tree traversal and report overlapping triangles to 'callback'
+void BvhTriangleMeshShape::ProcessAllTriangles(TriangleCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
+{
+
+#ifdef DISABLE_BVH
+ //brute force traverse all triangles
+ TriangleMeshShape::ProcessAllTriangles(callback,aabbMin,aabbMax);
+#else
+
+ //first get all the nodes
+
+
+ struct MyNodeOverlapCallback : public NodeOverlapCallback
+ {
+ StridingMeshInterface* m_meshInterface;
+ TriangleCallback* m_callback;
+ SimdVector3 m_triangle[3];
+
+
+ MyNodeOverlapCallback(TriangleCallback* callback,StridingMeshInterface* meshInterface)
+ :m_callback(callback),
+ m_meshInterface(meshInterface)
+ {
+ }
+
+ virtual void ProcessNode(const OptimizedBvhNode* node)
+ {
+ const unsigned char *vertexbase;
+ int numverts;
+ PHY_ScalarType type;
+ int stride;
+ const unsigned char *indexbase;
+ int indexstride;
+ int numfaces;
+ PHY_ScalarType indicestype;
+
+
+ m_meshInterface->getLockedReadOnlyVertexIndexBase(
+ &vertexbase,
+ numverts,
+ type,
+ stride,
+ &indexbase,
+ indexstride,
+ numfaces,
+ indicestype,
+ node->m_subPart);
+
+ int* gfxbase = (int*)(indexbase+node->m_triangleIndex*indexstride);
+
+ const SimdVector3& meshScaling = m_meshInterface->getScaling();
+ for (int j=2;j>=0;j--)
+ {
+
+ int graphicsindex = gfxbase[j];
+#ifdef DEBUG_TRIANGLE_MESH
+ printf("%d ,",graphicsindex);
+#endif //DEBUG_TRIANGLE_MESH
+ float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
+
+ m_triangle[j] = SimdVector3(
+ graphicsbase[0]*meshScaling.getX(),
+ graphicsbase[1]*meshScaling.getY(),
+ graphicsbase[2]*meshScaling.getZ());
+#ifdef DEBUG_TRIANGLE_MESH
+ printf("triangle vertices:%f,%f,%f\n",triangle[j].x(),triangle[j].y(),triangle[j].z());
+#endif //DEBUG_TRIANGLE_MESH
+ }
+
+ m_callback->ProcessTriangle(m_triangle);
+ m_meshInterface->unLockReadOnlyVertexBase(node->m_subPart);
+ }
+
+ };
+
+ MyNodeOverlapCallback myNodeCallback(callback,m_meshInterface);
+
+ m_bvh->ReportAabbOverlappingNodex(&myNodeCallback,aabbMin,aabbMax);
+
+
+#endif//DISABLE_BVH
+
+
+}
+
+
+void BvhTriangleMeshShape::setLocalScaling(const SimdVector3& scaling)
+{
+ if ((getLocalScaling() -scaling).length2() > SIMD_EPSILON)
+ {
+ TriangleMeshShape::setLocalScaling(scaling);
+ delete m_bvh;
+ m_bvh = new OptimizedBvh();
+ m_bvh->Build(m_meshInterface);
+ //rebuild the bvh...
+ }
+}
diff --git a/extern/bullet/Bullet/CollisionShapes/BvhTriangleMeshShape.h b/extern/bullet/Bullet/CollisionShapes/BvhTriangleMeshShape.h
new file mode 100644
index 00000000000..86cd1e56485
--- /dev/null
+++ b/extern/bullet/Bullet/CollisionShapes/BvhTriangleMeshShape.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2006 Erwin Coumans http://continuousphysics.com/Bullet/
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies.
+ * Erwin Coumans makes no representations about the suitability
+ * of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+*/
+#ifndef BVH_TRIANGLE_MESH_SHAPE_H
+#define BVH_TRIANGLE_MESH_SHAPE_H
+
+#include "CollisionShapes/TriangleMeshShape.h"
+#include "CollisionShapes/OptimizedBvh.h"
+
+///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization.
+///Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
+class BvhTriangleMeshShape : public TriangleMeshShape
+{
+
+ OptimizedBvh* m_bvh;
+
+
+public:
+ BvhTriangleMeshShape(StridingMeshInterface* meshInterface);
+
+ virtual ~BvhTriangleMeshShape();
+
+
+ /*
+ virtual int GetShapeType() const
+ {
+ return TRIANGLE_MESH_SHAPE_PROXYTYPE;
+ }
+ */
+
+
+
+ virtual void ProcessAllTriangles(TriangleCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
+
+
+ //debugging
+ virtual char* GetName()const {return "BVHTRIANGLEMESH";}
+
+
+ virtual void setLocalScaling(const SimdVector3& scaling);
+
+
+
+};
+
+#endif //BVH_TRIANGLE_MESH_SHAPE_H
diff --git a/extern/bullet/Bullet/CollisionShapes/CollisionMargin.h b/extern/bullet/Bullet/CollisionShapes/CollisionMargin.h
new file mode 100644
index 00000000000..41009dcd110
--- /dev/null
+++ b/extern/bullet/Bullet/CollisionShapes/CollisionMargin.h
@@ -0,0 +1,11 @@
+#ifndef COLLISION_MARGIN_H
+#define COLLISION_MARGIN_H
+
+//used by Gjk and some other algorithms
+
+#define CONVEX_DISTANCE_MARGIN 0.04f// 0.1f//;//0.01f
+
+
+
+#endif //COLLISION_MARGIN_H
+
diff --git a/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.cpp b/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.cpp
new file mode 100644
index 00000000000..dbaaaf243fa
--- /dev/null
+++ b/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.cpp
@@ -0,0 +1,86 @@
+#include "ConvexTriangleCallback.h"
+#include "NarrowPhaseCollision/PersistentManifold.h"
+#include "NarrowPhaseCollision/ManifoldContactAddResult.h"
+#include "NarrowPhaseCollision/GjkPairDetector.h"
+#include "NarrowPhaseCollision/MinkowskiPenetrationDepthSolver.h"
+
+
+
+#include "TriangleShape.h"
+
+//m_manifoldPtr = m_dispatcher->GetNewManifold(proxy0->m_clientObject,proxy1->m_clientObject);
+ //m_dispatcher->ReleaseManifold( m_manifoldPtr );
+
+ConvexTriangleCallback::ConvexTriangleCallback(PersistentManifold* manifold,ConvexShape* convexShape,const SimdTransform&convexTransform,const SimdTransform& triangleMeshTransform)
+:m_triangleMeshTransform(triangleMeshTransform),
+ m_convexTransform(convexTransform),
+ m_convexShape(convexShape),
+ m_manifoldPtr(manifold),
+ m_triangleCount(0)
+{
+}
+
+ConvexTriangleCallback::~ConvexTriangleCallback()
+{
+
+}
+
+
+void ConvexTriangleCallback::ClearCache()
+{
+ m_manifoldPtr->ClearManifold();
+};
+
+
+
+void ConvexTriangleCallback::ProcessTriangle(SimdVector3* triangle)
+{
+
+ //triangle, convex
+ TriangleShape tm(triangle[0],triangle[1],triangle[2]);
+ tm.SetMargin(m_collisionMarginTriangle);
+ GjkPairDetector::ClosestPointInput input;
+ input.m_transformA = m_triangleMeshTransform;
+ input.m_transformB = m_convexTransform;
+
+ ManifoldContactAddResult output(m_triangleMeshTransform,m_convexTransform,m_manifoldPtr);
+
+
+ VoronoiSimplexSolver simplexSolver;
+ MinkowskiPenetrationDepthSolver penetrationDepthSolver;
+
+ GjkPairDetector gjkDetector(&tm,m_convexShape,&simplexSolver,&penetrationDepthSolver);
+
+ gjkDetector.SetMinkowskiA(&tm);
+ gjkDetector.SetMinkowskiB(m_convexShape);
+ input.m_maximumDistanceSquared = tm.GetMargin()+ m_convexShape->GetMargin() + m_manifoldPtr->GetManifoldMargin();
+ input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared;
+
+ input.m_maximumDistanceSquared = 1e30f;//?
+
+
+ gjkDetector.GetClosestPoints(input,output);
+
+
+}
+
+
+
+void ConvexTriangleCallback::Update(float collisionMarginTriangle)
+{
+ m_triangleCount = 0;
+ m_collisionMarginTriangle = collisionMarginTriangle;
+
+ SimdTransform boxInTriangleSpace;
+ boxInTriangleSpace = m_triangleMeshTransform.inverse() * m_convexTransform;
+
+ m_convexShape->GetAabb(boxInTriangleSpace,m_aabbMin,m_aabbMax);
+
+ float extraMargin = CONVEX_DISTANCE_MARGIN;
+
+ SimdVector3 extra(extraMargin,extraMargin,extraMargin);
+
+ m_aabbMax += extra;
+ m_aabbMin -= extra;
+
+}
diff --git a/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.h b/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.h
new file mode 100644
index 00000000000..8e0e446a549
--- /dev/null
+++ b/extern/bullet/Bullet/CollisionShapes/ConvexTriangleCallback.h
@@ -0,0 +1,49 @@
+#ifndef CONVEX_TRIANGLE_CALLBACK_H
+#define CONVEX_TRIANGLE_CALLBACK_H
+
+#include "TriangleCallback.h"
+class ConvexShape;
+class PersistentManifold;
+#include "SimdTransform.h"
+///ConvexTriangleCallback processes the narrowphase convex-triangle collision detection
+class ConvexTriangleCallback: public TriangleCallback
+{
+ SimdVector3 m_aabbMin;
+ SimdVector3 m_aabbMax ;
+
+ SimdTransform m_triangleMeshTransform;
+ SimdTransform m_convexTransform;
+
+// bool m_useContinuous;
+ float m_collisionMarginTriangle;
+
+public:
+int m_triangleCount;
+
+ ConvexShape* m_convexShape;
+
+ PersistentManifold* m_manifoldPtr;
+
+ ConvexTriangleCallback(PersistentManifold* manifold,ConvexShape* convexShape,const SimdTransform&convexTransform,const SimdTransform& triangleMeshTransform);
+
+ void Update(float collisionMarginTriangle);
+
+ virtual ~ConvexTriangleCallback();
+
+ virtual void ProcessTriangle(SimdVector3* triangle);
+
+ void ClearCache();
+
+ inline const SimdVector3& GetAabbMin() const
+ {
+ return m_aabbMin;
+ }
+ inline const SimdVector3& GetAabbMax() const
+ {
+ return m_aabbMax;
+ }
+
+};
+
+
+#endif //CONVEX_TRIANGLE_CALLBACK_H \ No newline at end of file
diff --git a/extern/bullet/Bullet/CollisionShapes/EmptyShape.cpp b/extern/bullet/Bullet/CollisionShapes/EmptyShape.cpp
new file mode 100644
index 00000000000..04954dd750e
--- /dev/null
+++ b/extern/bullet/Bullet/CollisionShapes/EmptyShape.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies.
+ * Erwin Coumans makes no representations about the suitability
+ * of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ */
+
+#include "EmptyShape.h"
+
+
+#include "CollisionShape.h"
+
+
+EmptyShape::EmptyShape()
+{
+}
+
+
+EmptyShape::~EmptyShape()
+{
+}
+
+
+ ///GetAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
+void EmptyShape::GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const
+{
+ SimdVector3 margin(GetMargin(),GetMargin(),GetMargin());
+
+ aabbMin = t.getOrigin() - margin;
+
+ aabbMax = t.getOrigin() + margin;
+
+}
+
+void EmptyShape::CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia)
+{
+ assert(0);
+}
+
+
+
diff --git a/extern/bullet/Bullet/CollisionShapes/EmptyShape.h b/extern/bullet/Bullet/CollisionShapes/EmptyShape.h
new file mode 100644
index 00000000000..7ecbb05f4cc
--- /dev/null
+++ b/extern/bullet/Bullet/CollisionShapes/EmptyShape.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies.
+ * Erwin Coumans makes no representations about the suitability
+ * of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef EMPTY_SHAPE_H
+#define EMPTY_SHAPE_H
+
+#include "CollisionShape.h"
+
+#include "SimdVector3.h"
+#include "SimdTransform.h"
+#include "SimdMatrix3x3.h"
+#include <vector>
+#include "CollisionShapes/CollisionMargin.h"
+
+
+
+
+/// EmptyShape is a collision shape without actual collision detection. It can be replaced by another shape during runtime
+class EmptyShape : public CollisionShape
+{
+public:
+ EmptyShape();
+
+ virtual ~EmptyShape();
+
+
+ ///GetAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
+ void GetAabb(const SimdTransform& t,SimdVector3& aabbMin,SimdVector3& aabbMax) const;
+
+
+ virtual void setLocalScaling(const SimdVector3& scaling)
+ {
+ m_localScaling = scaling;
+ }
+ virtual const SimdVector3& getLocalScaling() const
+ {
+ return m_localScaling;
+ }
+
+ virtual void CalculateLocalInertia(SimdScalar mass,SimdVector3& inertia);
+
+ virtual int GetShapeType() const { return EMPTY_SHAPE_PROXYTYPE;}
+
+ virtual void SetMargin(float margin)
+ {
+ m_collisionMargin = margin;
+ }
+ virtual float GetMargin() const
+ {
+ return m_collisionMargin;
+ }
+ virtual char* GetName()const
+ {
+ return "Empty";
+ }
+
+
+private:
+ SimdScalar m_collisionMargin;
+protected:
+ SimdVector3 m_localScaling;
+
+};
+
+
+
+#endif //EMPTY_SHAPE_H
diff --git a/extern/bullet/Bullet/CollisionShapes/OptimizedBvh.cpp b/extern/bullet/Bullet/CollisionShapes/OptimizedBvh.cpp
new file mode 100644
index 00000000000..fe3a51883ec
--- /dev/null
+++ b/extern/bullet/Bullet/CollisionShapes/OptimizedBvh.cpp
@@ -0,0 +1,268 @@
+/*
+ * Copyright (c) 2006 Erwin Coumans http://continuousphysics.com/Bullet/
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies.
+ * Erwin Coumans makes no representations about the suitability
+ * of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+*/
+
+#include "OptimizedBvh.h"
+#include "StridingMeshInterface.h"
+#include "AabbUtil2.h"
+
+
+
+void OptimizedBvh::Build(StridingMeshInterface* triangles)
+{
+ int countTriangles = 0;
+
+
+
+ // NodeArray triangleNodes;
+
+ struct NodeTriangleCallback : public InternalTriangleIndexCallback
+ {
+ NodeArray& m_triangleNodes;
+
+ NodeTriangleCallback(NodeArray& triangleNodes)
+ :m_triangleNodes(triangleNodes)
+ {
+
+ }
+
+ virtual void InternalProcessTriangleIndex(SimdVector3* triangle,int partId,int triangleIndex)
+ {
+
+ OptimizedBvhNode node;
+ node.m_aabbMin = SimdVector3(1e30f,1e30f,1e30f);
+ node.m_aabbMax = SimdVector3(-1e30f,-1e30f,-1e30f);
+ node.m_aabbMin.setMin(triangle[0]);
+ node.m_aabbMax.setMax(triangle[0]);
+ node.m_aabbMin.setMin(triangle[1]);
+ node.m_aabbMax.setMax(triangle[1]);
+ node.m_aabbMin.setMin(triangle[2]);
+ node.m_aabbMax.setMax(triangle[2]);
+
+ node.m_escapeIndex = -1;
+ node.m_leftChild = 0;
+ node.m_rightChild = 0;
+
+
+ //for child nodes
+ node.m_subPart = partId;
+ node.m_triangleIndex = triangleIndex;
+
+
+ m_triangleNodes.push_back(node);
+ }
+ };
+
+
+
+ NodeTriangleCallback callback(m_leafNodes);
+
+ SimdVector3 aabbMin(-1e30f,-1e30f,-1e30f);
+ SimdVector3 aabbMax(1e30f,1e30f,1e30f);
+
+ triangles->InternalProcessAllTriangles(&callback,aabbMin,aabbMax);
+
+ //now we have an array of leafnodes in m_leafNodes
+
+ m_contiguousNodes = new OptimizedBvhNode[2*m_leafNodes.size()];
+ m_curNodeIndex = 0;
+
+ m_rootNode1 = BuildTree(m_leafNodes,0,m_leafNodes.size());
+
+
+ ///create the leafnodes first
+// OptimizedBvhNode* leafNodes = new OptimizedBvhNode;
+}
+
+
+OptimizedBvhNode* OptimizedBvh::BuildTree (NodeArray& leafNodes,int startIndex,int endIndex)
+{
+
+ int numIndices =endIndex-startIndex;
+ assert(numIndices>0);
+
+ int curIndex = m_curNodeIndex;
+
+ if (numIndices==1)
+ {
+ return new (&m_contiguousNodes[m_curNodeIndex++]) OptimizedBvhNode(leafNodes[startIndex]);
+ }
+ //calculate Best Splitting Axis and where to split it. Sort the incoming 'leafNodes' array within range 'startIndex/endIndex'.
+
+ int splitAxis = CalcSplittingAxis(leafNodes,startIndex,endIndex);
+
+ int splitIndex = SortAndCalcSplittingIndex(leafNodes,startIndex,endIndex,splitAxis);
+
+ OptimizedBvhNode* internalNode = &m_contiguousNodes[m_curNodeIndex++];
+
+ internalNode->m_aabbMax.setValue(-1e30f,-1e30f,-1e30f);
+ internalNode->m_aabbMin.setValue(1e30f,1e30f,1e30f);
+
+ for (int i=startIndex;i<endIndex;i++)
+ {
+ internalNode->m_aabbMax.setMax(leafNodes[i].m_aabbMax);
+ internalNode->m_aabbMin.setMin(leafNodes[i].m_aabbMin);
+ }
+
+
+
+ //internalNode->m_escapeIndex;
+ internalNode->m_leftChild = BuildTree(leafNodes,startIndex,splitIndex);
+ internalNode->m_rightChild = BuildTree(leafNodes,splitIndex,endIndex);
+
+ internalNode->m_escapeIndex = m_curNodeIndex - curIndex;
+ return internalNode;
+}
+
+int OptimizedBvh::SortAndCalcSplittingIndex(NodeArray& leafNodes,int startIndex,int endIndex,int splitAxis)
+{
+ int splitIndex =startIndex;
+ int numIndices = endIndex - startIndex;
+
+ SimdVector3 means(0.f,0.f,0.f);
+ for (int i=startIndex;i<endIndex;i++)
+ {
+ SimdVector3 center = 0.5f*(leafNodes[i].m_aabbMax+leafNodes[i].m_aabbMin);
+ means+=center;
+ }
+ means *= (1.f/(float)numIndices);
+
+ float splitValue = means[splitAxis];
+
+ //sort leafNodes so all values larger then splitValue comes first, and smaller values start from 'splitIndex'.
+ for (int i=startIndex;i<endIndex;i++)
+ {
+ SimdVector3 center = 0.5f*(leafNodes[i].m_aabbMax+leafNodes[i].m_aabbMin);
+ if (center[splitAxis] > splitValue)
+ {
+ //swap
+ OptimizedBvhNode tmp = leafNodes[i];
+ leafNodes[i] = leafNodes[splitIndex];
+ leafNodes[splitIndex] = tmp;
+ splitIndex++;
+ }
+ }
+ if ((splitIndex==startIndex) || (splitIndex == (endIndex-1)))
+ {
+ splitIndex = startIndex+ (numIndices>>1);
+ }
+ return splitIndex;
+}
+
+
+int OptimizedBvh::CalcSplittingAxis(NodeArray& leafNodes,int startIndex,int endIndex)
+{
+ SimdVector3 means(0.f,0.f,0.f);
+ int numIndices = endIndex-startIndex;
+
+ for (int i=startIndex;i<endIndex;i++)
+ {
+ SimdVector3 center = 0.5f*(leafNodes[i].m_aabbMax+leafNodes[i].m_aabbMin);
+ means+=center;
+ }
+ means *= (1.f/(float)numIndices);
+
+ SimdVector3 variance(0.f,0.f,0.f);
+
+ for (int i=startIndex;i<endIndex;i++)
+ {
+ SimdVector3 center = 0.5f*(leafNodes[i].m_aabbMax+leafNodes[i].m_aabbMin);
+ SimdVector3 diff2 = center-means;
+ diff2 = diff2 * diff2;
+ variance += diff2;
+ }
+ variance *= (1.f/ ((float)numIndices-1) );
+
+ int biggestAxis = variance.maxAxis();
+ return biggestAxis;
+
+}
+
+
+
+void OptimizedBvh::ReportAabbOverlappingNodex(NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
+{
+ if (aabbMin.length() > 1000.f)
+ {
+ for (int i=0;i<m_leafNodes.size();i++)
+ {
+ const OptimizedBvhNode& node = m_leafNodes[i];
+ nodeCallback->ProcessNode(&node);
+ }
+ } else
+ {
+ //WalkTree(m_rootNode1,nodeCallback,aabbMin,aabbMax);
+ WalkStacklessTree(m_rootNode1,nodeCallback,aabbMin,aabbMax);
+ }
+}
+
+void OptimizedBvh::WalkTree(OptimizedBvhNode* rootNode,NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
+{
+ bool aabbOverlap = TestAabbAgainstAabb2(aabbMin,aabbMax,rootNode->m_aabbMin,rootNode->m_aabbMax);
+ if (aabbOverlap)
+ {
+ bool isLeafNode = (!rootNode->m_leftChild && !rootNode->m_rightChild);
+ if (isLeafNode)
+ {
+ nodeCallback->ProcessNode(rootNode);
+ } else
+ {
+ WalkTree(rootNode->m_leftChild,nodeCallback,aabbMin,aabbMax);
+ WalkTree(rootNode->m_rightChild,nodeCallback,aabbMin,aabbMax);
+ }
+ }
+
+}
+
+int maxIterations = 0;
+
+void OptimizedBvh::WalkStacklessTree(OptimizedBvhNode* rootNode,NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
+{
+ int curIndex = 0;
+ int walkIterations = 0;
+
+ while (curIndex < m_curNodeIndex)
+ {
+ //catch bugs in tree data
+ assert (walkIterations < m_curNodeIndex);
+
+ walkIterations++;
+ bool aabbOverlap = TestAabbAgainstAabb2(aabbMin,aabbMax,rootNode->m_aabbMin,rootNode->m_aabbMax);
+ bool isLeafNode = (!rootNode->m_leftChild && !rootNode->m_rightChild);
+
+ if (isLeafNode && aabbOverlap)
+ {
+ nodeCallback->ProcessNode(rootNode);
+ }
+
+ if (aabbOverlap || isLeafNode)
+ {
+ rootNode++;
+ curIndex++;
+ } else
+ {
+ int escapeIndex = rootNode->m_escapeIndex;
+ rootNode += escapeIndex;
+ curIndex += escapeIndex;
+ }
+
+ }
+
+ if (maxIterations < walkIterations)
+ maxIterations = walkIterations;
+
+}
+
+
+void OptimizedBvh::ReportSphereOverlappingNodex(NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
+{
+
+}
+
diff --git a/extern/bullet/Bullet/CollisionShapes/OptimizedBvh.h b/extern/bullet/Bullet/CollisionShapes/OptimizedBvh.h
new file mode 100644
index 00000000000..911bb9af432
--- /dev/null
+++ b/extern/bullet/Bullet/CollisionShapes/OptimizedBvh.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2006 Erwin Coumans http://continuousphysics.com/Bullet/
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies.
+ * Erwin Coumans makes no representations about the suitability
+ * of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+*/
+
+#ifndef OPTIMIZED_BVH_H
+#define OPTIMIZED_BVH_H
+#include "SimdVector3.h"
+#include <vector>
+
+class StridingMeshInterface;
+
+/// OptimizedBvhNode contains both internal and leaf node information.
+/// It hasn't been optimized yet for storage. Some obvious optimizations are:
+/// Removal of the pointers (can already be done, they are not used for traversal)
+/// and storing aabbmin/max as quantized integers.
+/// 'subpart' doesn't need an integer either. It allows to re-use graphics triangle
+/// meshes stored in a non-uniform way (like batches/subparts of triangle-fans
+struct OptimizedBvhNode
+{
+
+ SimdVector3 m_aabbMin;
+ SimdVector3 m_aabbMax;
+
+//these 2 pointers are obsolete, the stackless traversal just uses the escape index
+ OptimizedBvhNode* m_leftChild;
+ OptimizedBvhNode* m_rightChild;
+
+ int m_escapeIndex;
+
+ //for child nodes
+ int m_subPart;
+ int m_triangleIndex;
+
+};
+
+class NodeOverlapCallback
+{
+public:
+ virtual void ProcessNode(const OptimizedBvhNode* node) = 0;
+};
+
+typedef std::vector<OptimizedBvhNode> NodeArray;
+
+
+///OptimizedBvh store an AABB tree that can be quickly traversed on CPU (and SPU,GPU in future)
+class OptimizedBvh
+{
+ OptimizedBvhNode* m_rootNode1;
+
+ OptimizedBvhNode* m_contiguousNodes;
+ int m_curNodeIndex;
+
+ int m_numNodes;
+
+ NodeArray m_leafNodes;
+
+public:
+ OptimizedBvh() :m_rootNode1(0), m_numNodes(0) { }
+
+ void Build(StridingMeshInterface* triangles);
+
+ OptimizedBvhNode* BuildTree (NodeArray& leafNodes,int startIndex,int endIndex);
+
+ int CalcSplittingAxis(NodeArray& leafNodes,int startIndex,int endIndex);
+
+ int SortAndCalcSplittingIndex(NodeArray& leafNodes,int startIndex,int endIndex,int splitAxis);
+
+ void WalkTree(OptimizedBvhNode* rootNode,NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
+
+ void WalkStacklessTree(OptimizedBvhNode* rootNode,NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
+
+
+ //OptimizedBvhNode* GetRootNode() { return m_rootNode1;}
+
+ int GetNumNodes() { return m_numNodes;}
+
+ void ReportAabbOverlappingNodex(NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
+
+ void ReportSphereOverlappingNodex(NodeOverlapCallback* nodeCallback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const;
+
+
+};
+
+
+#endif //OPTIMIZED_BVH_H \ No newline at end of file
diff --git a/extern/bullet/Bullet/CollisionShapes/TriangleCallback.cpp b/extern/bullet/Bullet/CollisionShapes/TriangleCallback.cpp
new file mode 100644
index 00000000000..6fc69355c2d
--- /dev/null
+++ b/extern/bullet/Bullet/CollisionShapes/TriangleCallback.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2006 Erwin Coumans http://continuousphysics.com/Bullet/
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies.
+ * Erwin Coumans makes no representations about the suitability
+ * of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+*/
+
+#include "TriangleCallback.h"
+
+TriangleCallback::~TriangleCallback()
+{
+
+}
+
+
+InternalTriangleIndexCallback::~InternalTriangleIndexCallback()
+{
+
+} \ No newline at end of file
diff --git a/extern/bullet/Bullet/CollisionShapes/TriangleIndexVertexArray.cpp b/extern/bullet/Bullet/CollisionShapes/TriangleIndexVertexArray.cpp
new file mode 100644
index 00000000000..711a9128048
--- /dev/null
+++ b/extern/bullet/Bullet/CollisionShapes/TriangleIndexVertexArray.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2006 Erwin Coumans http://continuousphysics.com/Bullet/
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies.
+ * Erwin Coumans makes no representations about the suitability
+ * of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+*/
+
+#include "TriangleIndexVertexArray.h"
+
+TriangleIndexVertexArray::TriangleIndexVertexArray(int numTriangleIndices,int* triangleIndexBase,int triangleIndexStride,int numVertices,float* vertexBase,int vertexStride)
+:m_numTriangleIndices(numTriangleIndices),
+m_triangleIndexBase(triangleIndexBase),
+m_triangleIndexStride(triangleIndexStride),
+m_numVertices(numVertices),
+m_vertexBase(vertexBase),
+m_vertexStride(vertexStride)
+{
+}
+
+void TriangleIndexVertexArray::getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart)
+{
+ numverts = m_numVertices;
+ (*vertexbase) = (unsigned char *)m_vertexBase;
+ type = PHY_FLOAT;
+ vertexStride = m_vertexStride;
+
+ numfaces = m_numTriangleIndices;
+ (*indexbase) = (unsigned char *)m_triangleIndexBase;
+ indexstride = m_triangleIndexStride;
+ indicestype = PHY_INTEGER;
+}
+
+void TriangleIndexVertexArray::getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart) const
+{
+ numverts = m_numVertices;
+ (*vertexbase) = (unsigned char *)m_vertexBase;
+ type = PHY_FLOAT;
+ vertexStride = m_vertexStride;
+
+ numfaces = m_numTriangleIndices;
+ (*indexbase) = (unsigned char *)m_triangleIndexBase;
+ indexstride = m_triangleIndexStride;
+ indicestype = PHY_INTEGER;
+}
+
diff --git a/extern/bullet/Bullet/CollisionShapes/TriangleIndexVertexArray.h b/extern/bullet/Bullet/CollisionShapes/TriangleIndexVertexArray.h
new file mode 100644
index 00000000000..4784dc3938f
--- /dev/null
+++ b/extern/bullet/Bullet/CollisionShapes/TriangleIndexVertexArray.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2006 Erwin Coumans http://continuousphysics.com/Bullet/
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies.
+ * Erwin Coumans makes no representations about the suitability
+ * of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+*/
+
+#include "StridingMeshInterface.h"
+
+
+class TriangleIndexVertexArray : public StridingMeshInterface
+{
+
+ int m_numTriangleIndices;
+ int* m_triangleIndexBase;
+ int m_triangleIndexStride;
+ int m_numVertices;
+ float* m_vertexBase;
+ int m_vertexStride;
+
+public:
+
+ TriangleIndexVertexArray(int numTriangleIndices,int* triangleIndexBase,int triangleIndexStride,int numVertices,float* vertexBase,int vertexStride);
+
+ virtual void getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0);
+
+ virtual void getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0) const;
+
+ /// unLockVertexBase finishes the access to a subpart of the triangle mesh
+ /// make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished
+ virtual void unLockVertexBase(int subpart) {}
+
+ virtual void unLockReadOnlyVertexBase(int subpart) const {}
+
+ /// getNumSubParts returns the number of seperate subparts
+ /// each subpart has a continuous array of vertices and indices
+ virtual int getNumSubParts() const { return 1;}
+
+ virtual void preallocateVertices(int numverts){}
+ virtual void preallocateIndices(int numindices){}
+
+}; \ No newline at end of file
diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/ManifoldContactAddResult.cpp b/extern/bullet/Bullet/NarrowPhaseCollision/ManifoldContactAddResult.cpp
new file mode 100644
index 00000000000..bb45e5215f3
--- /dev/null
+++ b/extern/bullet/Bullet/NarrowPhaseCollision/ManifoldContactAddResult.cpp
@@ -0,0 +1,33 @@
+
+#include "ManifoldContactAddResult.h"
+#include "NarrowPhaseCollision/PersistentManifold.h"
+
+ManifoldContactAddResult::ManifoldContactAddResult(SimdTransform transA,SimdTransform transB,PersistentManifold* manifoldPtr)
+ :m_manifoldPtr(manifoldPtr)
+{
+ m_transAInv = transA.inverse();
+ m_transBInv = transB.inverse();
+
+}
+
+
+void ManifoldContactAddResult::AddContactPoint(const SimdVector3& normalOnBInWorld,const SimdVector3& pointInWorld,float depth)
+{
+ if (depth > m_manifoldPtr->GetManifoldMargin())
+ return;
+
+
+ SimdVector3 pointA = pointInWorld + normalOnBInWorld * depth;
+ SimdVector3 localA = m_transAInv(pointA );
+ SimdVector3 localB = m_transBInv(pointInWorld);
+ ManifoldPoint newPt(localA,localB,normalOnBInWorld,depth);
+
+ int insertIndex = m_manifoldPtr->GetCacheEntry(newPt);
+ if (insertIndex >= 0)
+ {
+ m_manifoldPtr->ReplaceContactPoint(newPt,insertIndex);
+ } else
+ {
+ m_manifoldPtr->AddManifoldPoint(newPt);
+ }
+} \ No newline at end of file
diff --git a/extern/bullet/Bullet/NarrowPhaseCollision/ManifoldContactAddResult.h b/extern/bullet/Bullet/NarrowPhaseCollision/ManifoldContactAddResult.h
new file mode 100644
index 00000000000..1d019f97cd0
--- /dev/null
+++ b/extern/bullet/Bullet/NarrowPhaseCollision/ManifoldContactAddResult.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies.
+ * Erwin Coumans makes no representations about the suitability
+ * of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+*/
+
+#ifndef MANIFOLD_CONTACT_ADD_RESULT_H
+#define MANIFOLD_CONTACT_ADD_RESULT_H
+
+#include "NarrowPhaseCollision/DiscreteCollisionDetectorInterface.h"
+class PersistentManifold;
+
+class ManifoldContactAddResult : public DiscreteCollisionDetectorInterface::Result
+{
+ PersistentManifold* m_manifoldPtr;
+ SimdTransform m_transAInv;
+ SimdTransform m_transBInv;
+
+public:
+
+ ManifoldContactAddResult(SimdTransform transA,SimdTransform transB,PersistentManifold* manifoldPtr);
+
+ virtual void AddContactPoint(const SimdVector3& normalOnBInWorld,const SimdVector3& pointInWorld,float depth);
+
+};
+
+#endif //MANIFOLD_CONTACT_ADD_RESULT_H