Code-style consistency improvement:

Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files.
make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type.
This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
erwincoumans
2018-09-23 14:17:31 -07:00
parent b73b05e9fb
commit ab8f16961e
1773 changed files with 1081087 additions and 474249 deletions

View File

@@ -34,8 +34,6 @@ CHull::CHull(const ConvexDecomposition::ConvexResult &result)
mMax[0] += dx;
mMax[1] += dy;
mMax[2] += dz;
}
CHull::~CHull(void)
@@ -48,9 +46,6 @@ bool CHull::overlap(const CHull &h) const
return overlapAABB(mMin, mMax, h.mMin, h.mMax);
}
ConvexBuilder::ConvexBuilder(ConvexDecompInterface *callback)
{
mCallback = callback;
@@ -122,13 +117,11 @@ void ConvexBuilder::getMesh(const ConvexDecomposition::ConvexResult &cr,VertexLo
indices.push_back(i3);
}
#endif
}
}
CHull *ConvexBuilder::canMerge(CHull *a, CHull *b)
{
if (!a->overlap(*b)) return 0; // if their AABB's (with a little slop) don't overlap, then return.
CHull *ret = 0;
@@ -168,7 +161,6 @@ CHull * ConvexBuilder::canMerge(CHull *a,CHull *b)
if (hret == ConvexDecomposition::QE_OK)
{
float combineVolume = computeMeshVolume(hresult.mOutputVertices, hresult.mNumFaces, hresult.mIndices);
float sumVolume = a->mVolume + b->mVolume;
@@ -180,7 +172,6 @@ CHull * ConvexBuilder::canMerge(CHull *a,CHull *b)
}
}
Vl_releaseVertexLookup(vc);
return ret;
@@ -188,14 +179,12 @@ CHull * ConvexBuilder::canMerge(CHull *a,CHull *b)
bool ConvexBuilder::combineHulls(void)
{
bool combine = false;
sortChulls(mChulls); // sort the convex hulls, largest volume to least...
CHullVector output; // the output hulls...
int i;
for (i = 0; i < mChulls.size() && !combine; ++i)
@@ -209,15 +198,12 @@ bool ConvexBuilder::combineHulls(void)
if (cr != match) // don't try to merge a hull with itself, that be stoopid
{
CHull *merge = canMerge(cr, match); // if we can merge these two....
if (merge)
{
output.push_back(merge);
++i;
while (i != mChulls.size())
{
@@ -245,7 +231,6 @@ bool ConvexBuilder::combineHulls(void)
{
output.push_back(cr);
}
}
if (combine)
@@ -255,24 +240,21 @@ bool ConvexBuilder::combineHulls(void)
output.clear();
}
return combine;
}
unsigned int ConvexBuilder::process(const ConvexDecomposition::DecompDesc &desc)
{
unsigned int ret = 0;
MAXDEPTH = desc.mDepth;
CONCAVE_PERCENT = desc.mCpercent;
MERGE_PERCENT = desc.mPpercent;
calcConvexDecomposition(desc.mVcount, desc.mVertices, desc.mTcount, desc.mIndices, this, 0, 0);
while ( combineHulls() ); // keep combinging hulls until I can't combine any more...
while (combineHulls())
; // keep combinging hulls until I can't combine any more...
int i;
for (i = 0; i < mChulls.size(); i++)
@@ -321,13 +303,11 @@ unsigned int ConvexBuilder::process(const ConvexDecomposition::DecompDesc &desc)
r.mSphereRadius = computeBoundingSphere(result.mNumOutputVertices, result.mOutputVertices, r.mSphereCenter);
r.mSphereVolume = fm_sphereVolume(r.mSphereRadius);
mCallback->ConvexDecompResult(r);
}
hl.ReleaseResult(result);
delete cr;
}
@@ -338,7 +318,6 @@ unsigned int ConvexBuilder::process(const ConvexDecomposition::DecompDesc &desc)
return ret;
}
void ConvexBuilder::ConvexDebugTri(const float *p1, const float *p2, const float *p3, unsigned int color)
{
mCallback->ConvexDebugTri(p1, p2, p3, color);
@@ -369,5 +348,3 @@ void ConvexBuilder::sortChulls(CHullVector &hulls)
hulls.quickSort(CHullSort());
//hulls.heapSort(CHullSort());
}

View File

@@ -35,12 +35,10 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// http://www.amillionpixels.us
//
#include "ConvexDecomposition.h"
#include "vlookup.h"
#include "LinearMath/btAlignedObjectArray.h"
class CHull
{
public:
@@ -61,18 +59,14 @@ public:
class CHullSort
{
public:
inline bool operator()(const CHull *a, const CHull *b) const
{
return a->mVolume < b->mVolume;
}
};
typedef btAlignedObjectArray<CHull *> CHullVector;
class ConvexBuilder : public ConvexDecomposition::ConvexDecompInterface
{
public:
@@ -107,4 +101,3 @@ public:
};
#endif //CONVEX_BUILDER_H

View File

@@ -5,7 +5,6 @@
#include <string.h>
#include <assert.h>
/*----------------------------------------------------------------------
Copyright (c) 2004 Open Dynamics Framework Group
www.physicstools.org
@@ -56,14 +55,10 @@
#define SHOW_MESH 0
#define MAKE_MESH 1
using namespace ConvexDecomposition;
namespace ConvexDecomposition
{
class FaceTri
{
public:
@@ -79,10 +74,8 @@ public:
Vector3d mP2;
Vector3d mP3;
Vector3d mNormal;
};
void addTri(VertexLookup vl, UintVector &list, const Vector3d &p1, const Vector3d &p2, const Vector3d &p3)
{
unsigned int i1 = Vl_getIndex(vl, p1.Ptr());
@@ -99,7 +92,6 @@ void addTri(VertexLookup vl,UintVector &list,const Vector3d &p1,const Vector3d &
}
}
void calcConvexDecomposition(unsigned int vcount,
const float *vertices,
unsigned int tcount,
@@ -109,15 +101,12 @@ void calcConvexDecomposition(unsigned int vcount,
unsigned int depth)
{
float plane[4];
bool split = false;
if (depth < MAXDEPTH)
{
float volume;
float c = computeConcavity(vcount, vertices, tcount, indices, callback, plane, volume);
@@ -132,12 +121,10 @@ void calcConvexDecomposition(unsigned int vcount,
{
split = true;
}
}
if (depth >= MAXDEPTH || !split)
{
#if 1
HullResult result;
@@ -154,14 +141,11 @@ void calcConvexDecomposition(unsigned int vcount,
if (ret == QE_OK)
{
ConvexResult r(result.mNumOutputVertices, result.mOutputVertices, result.mNumFaces, result.mIndices);
callback->ConvexDecompResult(r);
}
#else
static unsigned int colors[8] =
@@ -173,8 +157,7 @@ void calcConvexDecomposition(unsigned int vcount,
0x00FFFF,
0xFF00FF,
0xFFFFFF,
0xFF8040
};
0xFF8040};
static int count = 0;
@@ -190,7 +173,6 @@ void calcConvexDecomposition(unsigned int vcount,
for (unsigned int i = 0; i < tcount; i++)
{
unsigned int i1 = *source++;
unsigned int i2 = *source++;
unsigned int i3 = *source++;
@@ -198,13 +180,11 @@ void calcConvexDecomposition(unsigned int vcount,
FaceTri t(vertices, i1, i2, i3);
callback->ConvexDebugTri(t.mP1.Ptr(), t.mP2.Ptr(), t.mP3.Ptr(), color);
}
#endif
hl.ReleaseResult(result);
return;
}
UintVector ifront;
@@ -213,7 +193,6 @@ void calcConvexDecomposition(unsigned int vcount,
VertexLookup vfront = Vl_createVertexLookup();
VertexLookup vback = Vl_createVertexLookup();
bool showmesh = false;
#if SHOW_MESH
showmesh = true;
@@ -279,7 +258,6 @@ void calcConvexDecomposition(unsigned int vcount,
addTri(vfront, ifront, front[0], front[1], front[2]);
#endif
break;
@@ -306,7 +284,6 @@ void calcConvexDecomposition(unsigned int vcount,
addTri(vfront, ifront, front[0], front[1], front[2]);
addTri(vback, iback, back[0], back[1], back[2]);
if (fcount == 4)
{
addTri(vfront, ifront, front[0], front[2], front[3]);
@@ -346,7 +323,6 @@ void calcConvexDecomposition(unsigned int vcount,
unsigned int tcount = ifront.size() / 3;
calcConvexDecomposition(vcount, vertices, tcount, &ifront[0], callback, masterVolume, depth + 1);
}
ifront.clear();
@@ -360,16 +336,11 @@ void calcConvexDecomposition(unsigned int vcount,
unsigned int tcount = iback.size() / 3;
calcConvexDecomposition(vcount, vertices, tcount, &iback[0], callback, masterVolume, depth + 1);
}
iback.clear();
Vl_releaseVertexLookup(vback);
}
}
}
} // namespace ConvexDecomposition

View File

@@ -36,7 +36,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// http://www.amillionpixels.us
//
#ifdef _WIN32
#include <memory.h> //memcpy
#endif
@@ -44,20 +43,14 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h>
#include "LinearMath/btAlignedObjectArray.h"
extern unsigned int MAXDEPTH;
extern float CONCAVE_PERCENT;
extern float MERGE_PERCENT;
typedef btAlignedObjectArray<unsigned int> UintVector;
namespace ConvexDecomposition
{
class ConvexResult
{
public:
@@ -93,7 +86,6 @@ namespace ConvexDecomposition
{
mHullIndices = 0;
}
}
ConvexResult(const ConvexResult &r)
@@ -143,9 +135,6 @@ namespace ConvexDecomposition
float mSphereRadius; // radius and center of best fit sphere
float mSphereCenter[3];
float mSphereVolume; // volume of the best fit sphere
};
class ConvexDecompInterface
@@ -158,9 +147,6 @@ namespace ConvexDecomposition
virtual void ConvexDebugOBB(const float *sides, const float *matrix, unsigned int color){};
virtual void ConvexDecompResult(ConvexResult &result) = 0;
};
// just to avoid passing a zillion parameters to the method the
@@ -198,13 +184,11 @@ namespace ConvexDecomposition
float mSkinWidth; // a skin width to apply to the output hulls.
ConvexDecompInterface *mCallback; // the interface to receive back the results.
};
// perform approximate convex decomposition on a mesh.
unsigned int performConvexDecomposition(const DecompDesc &desc); // returns the number of hulls produced.
void calcConvexDecomposition(unsigned int vcount,
const float *vertices,
unsigned int tcount,
@@ -213,8 +197,6 @@ namespace ConvexDecomposition
float masterVolume,
unsigned int depth);
}
} // namespace ConvexDecomposition
#endif

View File

@@ -52,13 +52,16 @@
namespace BestFit
{
class Vec3
{
public:
Vec3(void){};
Vec3(float _x,float _y,float _z) { x = _x; y = _y; z = _z; };
Vec3(float _x, float _y, float _z)
{
x = _x;
y = _y;
z = _z;
};
float dot(const Vec3 &v)
{
@@ -70,12 +73,9 @@ public:
float z;
};
class Eigen
{
public:
void DecrSortEigenStuff(void)
{
Tridiagonal(); //diagonalize the matrix.
@@ -247,7 +247,6 @@ public:
}
}
void GuaranteeRotation(void)
{
if (!m_bIsRotation)
@@ -266,12 +265,10 @@ public:
bool m_bIsRotation;
};
}
} // namespace BestFit
using namespace BestFit;
bool getBestFitPlane(unsigned int vcount,
const float *points,
unsigned int vstride,
@@ -292,7 +289,6 @@ bool getBestFitPlane(unsigned int vcount,
for (unsigned int i = 0; i < vcount; i++)
{
const float *p = (const float *)source;
float w = 1;
@@ -320,7 +316,6 @@ bool getBestFitPlane(unsigned int vcount,
kOrigin.y *= recip;
kOrigin.z *= recip;
float fSumXX = 0;
float fSumXY = 0;
float fSumXZ = 0;
@@ -329,7 +324,6 @@ bool getBestFitPlane(unsigned int vcount,
float fSumYZ = 0;
float fSumZZ = 0;
if (1)
{
const char *source = (const char *)points;
@@ -337,7 +331,6 @@ bool getBestFitPlane(unsigned int vcount,
for (unsigned int i = 0; i < vcount; i++)
{
const float *p = (const float *)source;
float w = 1;
@@ -363,7 +356,6 @@ bool getBestFitPlane(unsigned int vcount,
fSumYZ += kDiff.y * kDiff.z;
fSumZZ += kDiff.z * kDiff.z;
source += vstride;
}
}
@@ -409,11 +401,8 @@ bool getBestFitPlane(unsigned int vcount,
return ret;
}
float getBoundingRegion(unsigned int vcount, const float *points, unsigned int pstride, float *bmin, float *bmax) // returns the diagonal distance
{
const unsigned char *source = (const unsigned char *)points;
bmin[0] = points[0];
@@ -424,7 +413,6 @@ float getBoundingRegion(unsigned int vcount,const float *points,unsigned int pst
bmax[1] = points[1];
bmax[2] = points[2];
for (unsigned int i = 1; i < vcount; i++)
{
source += pstride;
@@ -437,7 +425,6 @@ float getBoundingRegion(unsigned int vcount,const float *points,unsigned int pst
if (p[0] > bmax[0]) bmax[0] = p[0];
if (p[1] > bmax[1]) bmax[1] = p[1];
if (p[2] > bmax[2]) bmax[2] = p[2];
}
float dx = bmax[0] - bmin[0];
@@ -445,10 +432,8 @@ float getBoundingRegion(unsigned int vcount,const float *points,unsigned int pst
float dz = bmax[2] - bmin[2];
return sqrtf(dx * dx + dy * dy + dz * dz);
}
bool overlapAABB(const float *bmin1, const float *bmax1, const float *bmin2, const float *bmax2) // return true if the two AABB's overlap.
{
if (bmax2[0] < bmin1[0]) return false; // if the maximum is less than our minimum on any axis
@@ -459,8 +444,5 @@ bool overlapAABB(const float *bmin1,const float *bmax1,const float *bmin2,const
if (bmin2[1] > bmax1[1]) return false; // if the minimum is greater than our maximum on any axis
if (bmin2[2] > bmax1[2]) return false; // if the minimum is greater than our maximum on any axis
return true; // the extents overlap
}

View File

@@ -36,7 +36,6 @@
// http://www.amillionpixels.us
//
// This routine was released in 'snippet' form
// by John W. Ratcliff mailto:jratcliff@infiniplex.net
// on March 22, 2006.
@@ -58,7 +57,6 @@ bool getBestFitPlane(unsigned int vcount, // number of input data points
unsigned int wstride, // weight stride for each vertex.
float *plane);
float getBoundingRegion(unsigned int vcount, const float *points, unsigned int pstride, float *bmin, float *bmax); // returns the diagonal distance
bool overlapAABB(const float *bmin1, const float *bmax1, const float *bmin2, const float *bmax2); // return true if the two AABB's overlap.

View File

@@ -69,7 +69,6 @@ void computeOBB(unsigned int vcount,const float *points,unsigned int pstride,flo
src += pstride;
}
sides[0] = bmax[0];
sides[1] = bmax[1];
sides[2] = bmax[2];
@@ -81,12 +80,10 @@ void computeOBB(unsigned int vcount,const float *points,unsigned int pstride,flo
sides[0] *= 2.0f;
sides[1] *= 2.0f;
sides[2] *= 2.0f;
}
void computeBestFitOBB(unsigned int vcount, const float *points, unsigned int pstride, float *sides, float *matrix)
{
float bmin[3];
float bmax[3];
@@ -110,7 +107,6 @@ void computeBestFitOBB(unsigned int vcount,const float *points,unsigned int pstr
while (sweep >= 1)
{
bool found = false;
float stepsize = sweep / steps;
@@ -156,7 +152,6 @@ void computeBestFitOBB(unsigned int vcount,const float *points,unsigned int pstr
if (found)
{
ax = angle[0];
ay = angle[1];
az = angle[2];
@@ -167,7 +162,5 @@ void computeBestFitOBB(unsigned int vcount,const float *points,unsigned int pstr
{
break; // no improvement, so just
}
}
}

View File

@@ -36,8 +36,6 @@
// http://www.amillionpixels.us
//
void computeBestFitOBB(unsigned int vcount, const float *points, unsigned int pstride, float *sides, float *matrix);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -31,7 +31,6 @@
namespace ConvexDecomposition
{
class HullResult
{
public:
@@ -63,7 +62,6 @@ enum HullFlag
QF_DEFAULT = 0
};
class HullDesc
{
public:
@@ -128,14 +126,12 @@ enum HullError
class HullLibrary
{
public:
HullError CreateConvexHull(const HullDesc &desc, // describes the input request
HullResult &result); // contains the resulst
HullError ReleaseResult(HullResult &result); // release memory allocated for this result, we are done with it.
private:
void BringOutYourDead(const float *verts, unsigned int vcount, float *overts, unsigned int &ocount, unsigned int *indices, unsigned indexcount);
bool CleanupVertices(unsigned int svcount,
@@ -147,7 +143,6 @@ private:
float *scale);
};
}
} // namespace ConvexDecomposition
#endif

View File

@@ -36,7 +36,6 @@
// http://www.amillionpixels.us
//
#pragma warning(disable : 4786)
#include <math.h>
@@ -45,8 +44,6 @@
namespace ConvexDecomposition
{
const float DEG_TO_RAD = ((2.0f * 3.14152654f) / 360.0f);
const float RAD_TO_DEG = (360.0f / (2.0f * 3.141592654f));
@@ -95,28 +92,36 @@ public:
// Operators
Vector3d &operator=(const Vector3d &A) // ASSIGNMENT (=)
{ x=A.x; y=A.y; z=A.z;
return(*this); };
{
x = A.x;
y = A.y;
z = A.z;
return (*this);
};
Vector3d operator+(const Vector3d &A) const // ADDITION (+)
{ Vector3d Sum(x+A.x, y+A.y, z+A.z);
return(Sum); };
{
Vector3d Sum(x + A.x, y + A.y, z + A.z);
return (Sum);
};
Vector3d operator-(const Vector3d &A) const // SUBTRACTION (-)
{ Vector3d Diff(x-A.x, y-A.y, z-A.z);
return(Diff); };
{
Vector3d Diff(x - A.x, y - A.y, z - A.z);
return (Diff);
};
Vector3d operator*(const float s) const // MULTIPLY BY SCALAR (*)
{ Vector3d Scaled(x*s, y*s, z*s);
return(Scaled); };
{
Vector3d Scaled(x * s, y * s, z * s);
return (Scaled);
};
Vector3d operator+(const float s) const // ADD CONSTANT TO ALL 3 COMPONENTS (*)
{ Vector3d Scaled(x+s, y+s, z+s);
return(Scaled); };
{
Vector3d Scaled(x + s, y + s, z + s);
return (Scaled);
};
Vector3d operator/(const float s) const // DIVIDE BY SCALAR (/)
{
@@ -126,27 +131,52 @@ public:
};
void operator/=(float A) // ACCUMULATED VECTOR ADDITION (/=)
{ x/=A; y/=A; z/=A; };
{
x /= A;
y /= A;
z /= A;
};
void operator+=(const Vector3d A) // ACCUMULATED VECTOR ADDITION (+=)
{ x+=A.x; y+=A.y; z+=A.z; };
{
x += A.x;
y += A.y;
z += A.z;
};
void operator-=(const Vector3d A) // ACCUMULATED VECTOR SUBTRACTION (+=)
{ x-=A.x; y-=A.y; z-=A.z; };
{
x -= A.x;
y -= A.y;
z -= A.z;
};
void operator*=(const float s) // ACCUMULATED SCALAR MULTIPLICATION (*=) (bpc 4/24/2000)
{x*=s; y*=s; z*=s;}
{
x *= s;
y *= s;
z *= s;
}
void operator+=(const float A) // ACCUMULATED VECTOR ADDITION (+=)
{ x+=A; y+=A; z+=A; };
{
x += A;
y += A;
z += A;
};
Vector3d operator-(void) const // NEGATION (-)
{ Vector3d Negated(-x, -y, -z);
return(Negated); };
{
Vector3d Negated(-x, -y, -z);
return (Negated);
};
float operator[](const int i) const // ALLOWS VECTOR ACCESS AS AN ARRAY.
{ return( (i==0)?x:((i==1)?y:z) ); };
{
return ((i == 0) ? x : ((i == 1) ? y : z));
};
float &operator[](const int i)
{ return( (i==0)?x:((i==1)?y:z) ); };
{
return ((i == 0) ? x : ((i == 1) ? y : z));
};
//
// accessor methods.
@@ -173,7 +203,6 @@ public:
return true;
}
float ComputeNormal(const Vector3d &A,
const Vector3d &B,
const Vector3d &C)
@@ -210,7 +239,6 @@ public:
return mag;
}
void ScaleSumScale(float c0, float c1, const Vector3d &pos)
{
x = (x * c0) + (pos.x * c1);
@@ -246,7 +274,6 @@ public:
z = (float)p[2];
}
void Set(float a, float b, float c)
{
x = a;
@@ -262,7 +289,6 @@ public:
const float *Ptr() const { return &x; }
float *Ptr() { return &x; }
// return -(*this).
Vector3d negative(void) const
{
@@ -335,8 +361,6 @@ public:
}
*/
/** Computes the reflection vector between two vectors.*/
void Reflection(const Vector3d &a, const Vector3d &b) // compute reflection vector.
{
@@ -366,7 +390,6 @@ public:
return float(sqrt(x * x + y * y + z * z));
};
float ComputePlane(const Vector3d &A,
const Vector3d &B,
const Vector3d &C)
@@ -400,19 +423,16 @@ public:
y = vw_y * mag;
z = vw_z * mag;
float D = 0.0f - ((x * A.x) + (y * A.y) + (z * A.z));
return D;
}
float FastLength(void) const // length of vector.
{
return float(sqrtf(x * x + y * y + z * z));
};
float FasterLength(void) const // length of vector.
{
return float(sqrtf(x * x + y * y + z * z));
@@ -442,7 +462,6 @@ public:
return d.FasterLength();
}
float DistanceXY(const Vector3d &a) const
{
float dx = a.x - x;
@@ -523,15 +542,11 @@ public:
return d;
};
float Dot(const Vector3d &a) const // computes dot product.
{
return (x * a.x + y * a.y + z * a.z);
};
Vector3d Cross(const Vector3d &other) const
{
Vector3d result(y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x);
@@ -662,7 +677,6 @@ public:
return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
};
// test to see if this point is inside the triangle specified by
// these three points on the X/Y plane.
bool PointInTriXZ(const Vector3d &p1,
@@ -863,7 +877,6 @@ public:
}
}
//private:
float x;
@@ -871,7 +884,6 @@ public:
float z;
};
class Vector2d
{
public:
@@ -889,7 +901,6 @@ public:
y = t[1];
};
Vector2d(float a, float b) // construct with initial point.
{
x = a;
@@ -982,7 +993,6 @@ public:
return a;
};
float Dot(const Vector2d &a) const // computes dot product.
{
return (x * a.x + y * a.y);
@@ -1087,7 +1097,6 @@ public:
y = ((to.y - from.y) * slerp) + from.y;
};
void Cross(const Vector2d &a, const Vector2d &b) // cross two vectors result in this one.
{
x = a.y * b.x - a.x * b.y;
@@ -1142,7 +1151,6 @@ public:
return l;
};
float x;
float y;
};
@@ -1158,13 +1166,12 @@ public:
// JWR Test for the intersection of two lines.
bool Intersect(const Line &src, Vector3d &sect);
private:
Vector3d mP1;
Vector3d mP2;
};
typedef std::vector<Vector3d> Vector3dVector;
typedef std::vector<Vector2d> Vector2dVector;
@@ -1180,6 +1187,6 @@ inline Vector2d operator * (float s, const Vector2d &v )
return (Scaled);
}
}
} // namespace ConvexDecomposition
#endif

View File

@@ -41,7 +41,6 @@
#include "cd_wavefront.h"
using namespace ConvexDecomposition;
/*----------------------------------------------------------------------
@@ -75,7 +74,6 @@ using namespace ConvexDecomposition;
namespace ConvexDecomposition
{
typedef std::vector<int> IntVector;
typedef std::vector<float> FloatVector;
@@ -168,7 +166,6 @@ public:
mHard[(int)c] = ST_HARD;
}
void SetCommentSymbol(char c) // comment character, treated as 'end of string'
{
mHard[(int)c] = ST_EOS;
@@ -179,7 +176,6 @@ public:
mHard[(int)c] = ST_DATA;
}
void DefaultSymbols(void); // set up default symbols for hard seperator and comment symbol of the '#' character.
bool EOS(char c)
@@ -197,8 +193,6 @@ public:
}
private:
inline char *AddHard(int &argc, const char **argv, char *foo);
inline bool IsHard(char c);
inline char *SkipSpaces(char *foo);
@@ -226,7 +220,6 @@ void InPlaceParser::SetFile(const char *fname)
mLen = 0;
mMyAlloc = false;
FILE *fph = fopen(fname, "rb");
if (fph)
{
@@ -298,7 +291,6 @@ bool InPlaceParser::IsNonSeparator(char c)
return false;
}
int InPlaceParser::ProcessLine(int lineno, char *line, InPlaceParserInterface *callback)
{
int ret = 0;
@@ -310,7 +302,6 @@ int InPlaceParser::ProcessLine(int lineno,char *line,InPlaceParserInterface *cal
while (!EOS(*foo) && argc < MAXARGS)
{
foo = SkipSpaces(foo); // skip any leading spaces
if (EOS(*foo)) break;
@@ -331,7 +322,6 @@ int InPlaceParser::ProcessLine(int lineno,char *line,InPlaceParserInterface *cal
}
else
{
foo = AddHard(argc, argv, foo); // add any hard separators, skip any spaces
if (IsNonSeparator(*foo)) // add non-hard argument.
@@ -400,7 +390,6 @@ int InPlaceParser::Parse(InPlaceParserInterface *callback) // returns true if e
char *foo = mData;
char *begin = foo;
while (*foo)
{
if (*foo == 10 || *foo == 13)
@@ -431,7 +420,6 @@ int InPlaceParser::Parse(InPlaceParserInterface *callback) // returns true if e
return ret;
}
void InPlaceParser::DefaultSymbols(void)
{
SetHardSeparator(',');
@@ -445,7 +433,6 @@ void InPlaceParser::DefaultSymbols(void)
SetCommentSymbol('#');
}
const char **InPlaceParser::GetArglist(char *line, int &count) // convert source string into an arg list, this is a destructive parse.
{
const char **ret = 0;
@@ -457,7 +444,6 @@ const char ** InPlaceParser::GetArglist(char *line,int &count) // convert source
while (!EOS(*foo) && argc < MAXARGS)
{
foo = SkipSpaces(foo); // skip any leading spaces
if (EOS(*foo)) break;
@@ -478,7 +464,6 @@ const char ** InPlaceParser::GetArglist(char *line,int &count) // convert source
}
else
{
foo = AddHard(argc, argv, foo); // add any hard separators, skip any spaces
if (IsNonSeparator(*foo)) // add non-hard argument.
@@ -548,29 +533,24 @@ public:
float mTexel[2];
};
class GeometryInterface
{
public:
virtual void NodeTriangle(const GeometryVertex *v1, const GeometryVertex *v2, const GeometryVertex *v3) {}
virtual ~GeometryInterface() {}
};
/*******************************************************************/
/******************** Obj.h ********************************/
/*******************************************************************/
class OBJ : public InPlaceParserInterface
{
public:
int LoadMesh(const char *fname, GeometryInterface *callback);
int ParseLine(int lineno, int argc, const char **argv); // return TRUE to continue parsing, return FALSE to abort parsing process
private:
void getVertex(GeometryVertex &v, const char *face) const;
FloatVector mVerts;
@@ -580,7 +560,6 @@ private:
GeometryInterface *mCallback;
};
/*******************************************************************/
/******************** Obj.cpp ********************************/
/*******************************************************************/
@@ -599,7 +578,6 @@ int OBJ::LoadMesh(const char *fname,GeometryInterface *iface)
ipp.Parse(this);
return ret;
}
@@ -637,7 +615,6 @@ void OBJ::getVertex(GeometryVertex &v,const char *face) const
v.mTexel[0] = t[0];
v.mTexel[1] = t[1];
}
const char *normal = strstr(texel + 1, "/");
@@ -658,14 +635,12 @@ void OBJ::getVertex(GeometryVertex &v,const char *face) const
if (index >= 0 && index < (int)(mVerts.size() / 3))
{
const float *p = &mVerts[index * 3];
v.mPos[0] = p[0];
v.mPos[1] = p[1];
v.mPos[2] = p[2];
}
}
int OBJ::ParseLine(int lineno, int argc, const char **argv) // return TRUE to continue parsing, return FALSE to abort parsing process
@@ -751,7 +726,6 @@ int OBJ::ParseLine(int lineno,int argc,const char **argv) // return TRUE to con
mCallback->NodeTriangle(&v[0], &v[i], &v[i + 1]);
}
}
}
}
}
@@ -759,16 +733,11 @@ int OBJ::ParseLine(int lineno,int argc,const char **argv) // return TRUE to con
return ret;
}
class BuildMesh : public GeometryInterface
{
public:
int getIndex(const float *p)
{
int vcount = mVertices.size() / 3;
if (vcount > 0)
@@ -805,7 +774,6 @@ private:
IntVector mIndices;
};
WavefrontObj::WavefrontObj(void)
{
mVertexCount = 0;
@@ -822,7 +790,6 @@ WavefrontObj::~WavefrontObj(void)
unsigned int WavefrontObj::loadObj(const char *fname) // load a wavefront obj returns number of triangles that were loaded. Data is persists until the class is destructed.
{
unsigned int ret = 0;
delete[] mVertices;
@@ -832,14 +799,12 @@ unsigned int WavefrontObj::loadObj(const char *fname) // load a wavefront obj re
mVertexCount = 0;
mTriCount = 0;
BuildMesh bm;
OBJ obj;
obj.LoadMesh(fname, &bm);
const FloatVector &vlist = bm.GetVertices();
const IntVector &indices = bm.GetIndices();
if (vlist.size())
@@ -853,8 +818,7 @@ unsigned int WavefrontObj::loadObj(const char *fname) // load a wavefront obj re
ret = mTriCount;
}
return ret;
}
}
} // namespace ConvexDecomposition

View File

@@ -1,9 +1,7 @@
#ifndef CD_WAVEFRONT_OBJ_H
#define CD_WAVEFRONT_OBJ_H
/*----------------------------------------------------------------------
Copyright (c) 2004 Open Dynamics Framework Group
www.physicstools.org
@@ -38,14 +36,11 @@
// http://www.amillionpixels.us
//
namespace ConvexDecomposition
{
class WavefrontObj
{
public:
WavefrontObj(void);
~WavefrontObj(void);
@@ -57,6 +52,6 @@ public:
float *mVertices;
};
}
} // namespace ConvexDecomposition
#endif

View File

@@ -49,13 +49,11 @@
#include "splitplane.h"
#include "ConvexDecomposition.h"
#define WSCALE 4
#define CONCAVE_THRESH 0.05f
namespace ConvexDecomposition
{
unsigned int getDebugColor(void)
{
static unsigned int colors[8] =
@@ -67,8 +65,7 @@ unsigned int getDebugColor(void)
0x00FFFF,
0xFF00FF,
0xFFFFFF,
0xFF8040
};
0xFF8040};
static int count = 0;
@@ -81,7 +78,6 @@ unsigned int getDebugColor(void)
unsigned int color = colors[count];
return color;
}
class Wpoint
@@ -99,7 +95,6 @@ public:
typedef std::vector<Wpoint> WpointVector;
static inline float DistToPt(const float *p, const float *plane)
{
float x = p[0];
@@ -109,10 +104,8 @@ static inline float DistToPt(const float *p,const float *plane)
return d;
}
static void intersect(const float *p1, const float *p2, float *split, const float *plane)
{
float dp1 = DistToPt(p1, plane);
float dir[3];
@@ -131,7 +124,6 @@ static void intersect(const float *p1,const float *p2,float *split,const float *
split[2] = (dir[2] * t) + p1[2];
}
class CTri
{
public:
@@ -190,7 +182,6 @@ public:
{
unsigned int indices[8 * 3];
unsigned int tcount = 0;
addTri(indices, 0, 1, 2, tcount);
@@ -239,7 +230,6 @@ public:
const float *p3 = &vertices[i3 * 3];
callback->ConvexDebugTri(p1, p2, p3, color);
}
#endif
}
@@ -247,7 +237,6 @@ public:
float v = computeMeshVolume(mP1.Ptr(), tcount, indices);
return v;
}
float raySect(const Vector3d &p, const Vector3d &dir, Vector3d &sect) const
@@ -264,7 +253,6 @@ public:
intersect(p.Ptr(), dest.Ptr(), sect.Ptr(), plane);
return sect.Distance(p); // return the intersection distance.
}
float planeDistance(const Vector3d &p) const
@@ -277,7 +265,6 @@ public:
plane[3] = mPlaneD;
return DistToPt(p.Ptr(), plane);
}
bool samePlane(const CTri &t) const
@@ -333,7 +320,6 @@ public:
void addWeighted(WpointVector &list, ConvexDecompInterface *callback)
{
Wpoint p1(mP1, mC1);
Wpoint p2(mP2, mC2);
Wpoint p3(mP3, mC3);
@@ -387,9 +373,6 @@ public:
callback->ConvexDebugPoint( np3.Ptr(), 0.01F, 0XFF00FF );
#endif
}
Vector3d mP1;
@@ -414,7 +397,6 @@ typedef std::vector< CTri > CTriVector;
bool featureMatch(CTri &m, const CTriVector &tris, ConvexDecompInterface *callback, const CTriVector &input_mesh)
{
bool ret = false;
float neardot = 0.707f;
@@ -429,12 +411,10 @@ bool featureMatch(CTri &m,const CTriVector &tris,ConvexDecompInterface *callback
CTri nearest;
for (i = tris.begin(); i != tris.end(); ++i)
{
const CTri &t = (*i);
//gLog->Display(" HullPlane: %0.4f,%0.4f,%0.4f %0.4f\r\n", t.mNormal.x, t.mNormal.y, t.mNormal.z, t.mPlaneD );
if (t.samePlane(m))
@@ -448,14 +428,12 @@ bool featureMatch(CTri &m,const CTriVector &tris,ConvexDecompInterface *callback
if (dot > neardot)
{
float d1 = t.planeDistance(m.mP1);
float d2 = t.planeDistance(m.mP2);
float d3 = t.planeDistance(m.mP3);
if (d1 > 0.001f || d2 > 0.001f || d3 > 0.001f) // can't be near coplaner!
{
neardot = dot;
Vector3d n1, n2, n3;
@@ -468,7 +446,6 @@ bool featureMatch(CTri &m,const CTriVector &tris,ConvexDecompInterface *callback
ret = true;
}
}
}
@@ -509,7 +486,6 @@ bool featureMatch(CTri &m,const CTriVector &tris,ConvexDecompInterface *callback
callback->ConvexDebugTri( m.mP2.Ptr(), m.mP2.Ptr(), m.mNear2.Ptr(), 0xFFFF00 );
callback->ConvexDebugTri( m.mP3.Ptr(), m.mP3.Ptr(), m.mNear3.Ptr(), 0xFFFF00 );
#endif
}
else
{
@@ -526,7 +502,6 @@ bool isFeatureTri(CTri &t,CTriVector &flist,float fc,ConvexDecompInterface *call
if (t.mProcessed == 0) // if not already processed
{
float c = t.mConcavity / fc; // must be within 80% of the concavity of the parent.
if (c > 0.85f)
@@ -562,7 +537,6 @@ bool isFeatureTri(CTri &t,CTriVector &flist,float fc,ConvexDecompInterface *call
{
t.mProcessed = 1; // eliminated for this feature, but might be valid for the next one..
}
}
return ret;
}
@@ -575,8 +549,6 @@ float computeConcavity(unsigned int vcount,
float *plane, // plane equation to split on
float &volume)
{
float cret = 0;
volume = 1;
@@ -588,7 +560,6 @@ float computeConcavity(unsigned int vcount,
desc.mMaxVertices = 256;
desc.SetHullFlag(QF_TRIANGLES);
desc.mVcount = vcount;
desc.mVertices = vertices;
desc.mVertexStride = sizeof(float) * 3;
@@ -645,10 +616,8 @@ float computeConcavity(unsigned int vcount,
const unsigned int *src = indices;
float maxc = 0;
if (1)
{
CTriVector input_mesh;
@@ -657,7 +626,6 @@ float computeConcavity(unsigned int vcount,
const unsigned int *src = indices;
for (unsigned int i = 0; i < tcount; i++)
{
unsigned int i1 = *src++;
unsigned int i2 = *src++;
unsigned int i3 = *src++;
@@ -675,7 +643,6 @@ float computeConcavity(unsigned int vcount,
for (unsigned int i = 0; i < tcount; i++)
{
unsigned int i1 = *src++;
unsigned int i2 = *src++;
unsigned int i3 = *src++;
@@ -690,7 +657,6 @@ float computeConcavity(unsigned int vcount,
if (t.mConcavity > CONCAVE_THRESH)
{
if (t.mConcavity > maxc)
{
maxc = t.mConcavity;
@@ -701,7 +667,6 @@ float computeConcavity(unsigned int vcount,
totalVolume += v;
ftris.push_back(t);
}
}
}
@@ -793,5 +758,4 @@ float computeConcavity(unsigned int vcount,
return cret;
}
}
} // namespace ConvexDecomposition

View File

@@ -36,11 +36,8 @@
// http://www.amillionpixels.us
//
namespace ConvexDecomposition
{
class ConvexDecompInterface;
// compute's how 'concave' this object is and returns the total volume of the
@@ -53,8 +50,6 @@ float computeConcavity(unsigned int vcount,
float *plane,
float &volume);
}
} // namespace ConvexDecomposition
#endif

View File

@@ -6,7 +6,6 @@
#include "fitsphere.h"
/*----------------------------------------------------------------------
Copyright (c) 2004 Open Dynamics Framework Group
www.physicstools.org
@@ -71,7 +70,6 @@ static inline void Copy(float *dest,const float *source)
float computeBoundingSphere(unsigned int vcount, const float *points, float *center)
{
float mRadius;
float mRadius2;
@@ -145,7 +143,6 @@ float computeBoundingSphere(unsigned int vcount,const float *points,float *cente
Copy(dia2, zmax);
}
/* dia1,dia2 is a diameter of initial sphere */
/* calc initial center */
center[0] = (dia1[0] + dia2[0]) * 0.5f;
@@ -198,5 +195,3 @@ float computeBoundingSphere(unsigned int vcount,const float *points,float *cente
return mRadius;
}

View File

@@ -36,8 +36,6 @@
// http://www.amillionpixels.us
//
float computeBoundingSphere(unsigned int vcount, const float *points, float *center);
#endif

View File

@@ -6,7 +6,6 @@
#include <assert.h>
#include <math.h>
/*----------------------------------------------------------------------
Copyright (c) 2004 Open Dynamics Framework Group
www.physicstools.org
@@ -43,7 +42,6 @@
void fm_inverseRT(const float *matrix, const float *pos, float *t) // inverse rotate translate the point.
{
float _x = pos[0] - matrix[3 * 4 + 0];
float _y = pos[1] - matrix[3 * 4 + 1];
float _z = pos[2] - matrix[3 * 4 + 2];
@@ -53,10 +51,8 @@ void fm_inverseRT(const float *matrix,const float *pos,float *t) // inverse rota
t[0] = (matrix[0 * 4 + 0] * _x) + (matrix[0 * 4 + 1] * _y) + (matrix[0 * 4 + 2] * _z);
t[1] = (matrix[1 * 4 + 0] * _x) + (matrix[1 * 4 + 1] * _y) + (matrix[1 * 4 + 2] * _z);
t[2] = (matrix[2 * 4 + 0] * _x) + (matrix[2 * 4 + 1] * _y) + (matrix[2 * 4 + 2] * _z);
}
void fm_identity(float *matrix) // set 4x4 matrix to identity.
{
matrix[0 * 4 + 0] = 1;
@@ -79,7 +75,6 @@ void fm_identity(float *matrix) // set 4x4 matrix to identity.
matrix[0 * 4 + 3] = 0;
matrix[1 * 4 + 3] = 0;
matrix[2 * 4 + 3] = 0;
}
void fm_eulerMatrix(float ax, float ay, float az, float *matrix) // convert euler (in radians) to a dest 4x4 matrix (translation set to zero)
@@ -91,7 +86,6 @@ void fm_eulerMatrix(float ax,float ay,float az,float *matrix) // convert euler (
void fm_getAABB(unsigned int vcount, const float *points, unsigned int pstride, float *bmin, float *bmax)
{
const unsigned char *source = (const unsigned char *)points;
bmin[0] = points[0];
@@ -102,7 +96,6 @@ void fm_getAABB(unsigned int vcount,const float *points,unsigned int pstride,flo
bmax[1] = points[1];
bmax[2] = points[2];
for (unsigned int i = 1; i < vcount; i++)
{
source += pstride;
@@ -115,11 +108,9 @@ void fm_getAABB(unsigned int vcount,const float *points,unsigned int pstride,flo
if (p[0] > bmax[0]) bmax[0] = p[0];
if (p[1] > bmax[1]) bmax[1] = p[1];
if (p[2] > bmax[2]) bmax[2] = p[2];
}
}
void fm_eulerToQuat(float roll, float pitch, float yaw, float *quat) // convert euler angles to quaternion.
{
roll *= 0.5f;
@@ -147,7 +138,6 @@ void fm_eulerToQuat(float roll,float pitch,float yaw,float *quat) // convert eul
void fm_quatToMatrix(const float *quat, float *matrix) // convert quaterinion rotation to matrix, zeros out the translation component.
{
float xx = quat[0] * quat[0];
float yy = quat[1] * quat[1];
float zz = quat[2] * quat[2];
@@ -173,10 +163,8 @@ void fm_quatToMatrix(const float *quat,float *matrix) // convert quaterinion rot
matrix[3 * 4 + 0] = matrix[3 * 4 + 1] = matrix[3 * 4 + 2] = 0.0f;
matrix[0 * 4 + 3] = matrix[1 * 4 + 3] = matrix[2 * 4 + 3] = 0.0f;
matrix[3 * 4 + 3] = 1.0f;
}
void fm_quatRotate(const float *quat, const float *v, float *r) // rotate a vector directly by a quaternion.
{
float left[4];
@@ -189,10 +177,8 @@ void fm_quatRotate(const float *quat,const float *v,float *r) // rotate a vector
r[0] = (left[3] * -quat[0]) + (quat[3] * left[0]) + (left[1] * -quat[2]) - (-quat[1] * left[2]);
r[1] = (left[3] * -quat[1]) + (quat[3] * left[1]) + (left[2] * -quat[0]) - (-quat[2] * left[0]);
r[2] = (left[3] * -quat[2]) + (quat[3] * left[2]) + (left[0] * -quat[1]) - (-quat[0] * left[1]);
}
void fm_getTranslation(const float *matrix, float *t)
{
t[0] = matrix[3 * 4 + 0];
@@ -202,7 +188,6 @@ void fm_getTranslation(const float *matrix,float *t)
void fm_matrixToQuat(const float *matrix, float *quat) // convert the 3x3 portion of a 4x4 matrix into a quaterion as x,y,z,w
{
float tr = matrix[0 * 4 + 0] + matrix[1 * 4 + 1] + matrix[2 * 4 + 2];
// check the diagonal
@@ -215,7 +200,6 @@ void fm_matrixToQuat(const float *matrix,float *quat) // convert the 3x3 portion
quat[0] = (matrix[1 * 4 + 2] - matrix[2 * 4 + 1]) * s;
quat[1] = (matrix[2 * 4 + 0] - matrix[0 * 4 + 2]) * s;
quat[2] = (matrix[0 * 4 + 1] - matrix[1 * 4 + 0]) * s;
}
else
{
@@ -246,11 +230,8 @@ void fm_matrixToQuat(const float *matrix,float *quat) // convert the 3x3 portion
quat[2] = qa[2];
quat[3] = qa[3];
}
}
float fm_sphereVolume(float radius) // return's the volume of a sphere of this radius (4/3 PI * R cubed )
{
return (4.0f / 3.0f) * FM_PI * radius * radius * radius;

View File

@@ -45,7 +45,6 @@
// http://www.amillionpixels.us
//
// a set of routines that last you do common 3d math
// operations without any vector, matrix, or quaternion
// classes or templates.

View File

@@ -46,7 +46,6 @@ float computeMeshVolume(const float *vertices,unsigned int tcount,const unsigned
for (unsigned int i = 0; i < tcount; i++, indices += 3)
{
const float *p1 = &vertices[indices[0] * 3];
const float *p2 = &vertices[indices[1] * 3];
const float *p3 = &vertices[indices[2] * 3];
@@ -60,7 +59,6 @@ float computeMeshVolume(const float *vertices,unsigned int tcount,const unsigned
return volume;
}
inline void CrossProduct(const float *a, const float *b, float *cross)
{
cross[0] = a[1] * b[2] - a[2] * b[1];
@@ -115,7 +113,6 @@ float computeMeshVolume2(const float *vertices,unsigned int tcount,const unsigne
const float *p0 = vertices;
for (unsigned int i = 0; i < tcount; i++, indices += 3)
{
const float *p1 = &vertices[indices[0] * 3];
const float *p2 = &vertices[indices[1] * 3];
const float *p3 = &vertices[indices[2] * 3];
@@ -125,4 +122,3 @@ float computeMeshVolume2(const float *vertices,unsigned int tcount,const unsigne
return volume * (1.0f / 6.0f);
}

View File

@@ -36,10 +36,7 @@
// http://www.amillionpixels.us
//
float computeMeshVolume(const float *vertices, unsigned int tcount, const unsigned int *indices);
float computeMeshVolume2(const float *vertices, unsigned int tcount, const unsigned int *indices);
#endif

View File

@@ -49,10 +49,8 @@ static inline float DistToPt(const float *p,const float *plane)
return d;
}
static PlaneTriResult getSidePlane(const float *p, const float *plane, float epsilon)
{
float d = DistToPt(p, plane);
if ((d + epsilon) > 0)
@@ -73,11 +71,9 @@ static void add(const float *p,float *dest,unsigned int tstride,unsigned int &pc
assert(pcount <= 4);
}
// assumes that the points are on opposite sides of the plane!
static void intersect(const float *p1, const float *p2, float *split, const float *plane)
{
float dp1 = DistToPt(p1, plane);
float dir[3];
@@ -94,7 +90,6 @@ static void intersect(const float *p1,const float *p2,float *split,const float *
split[0] = (dir[0] * t) + p1[0];
split[1] = (dir[1] * t) + p1[1];
split[2] = (dir[2] * t) + p1[2];
}
PlaneTriResult planeTriIntersection(const float *plane, // the plane equation in Ax+By+Cz+D format
@@ -116,7 +111,6 @@ PlaneTriResult planeTriIntersection(const float *plane, // the plane equation
const float *p2 = (const float *)(tsource + tstride);
const float *p3 = (const float *)(tsource + tstride * 2);
PlaneTriResult r1 = getSidePlane(p1, plane, epsilon); // compute the side of the plane each vertex is on
PlaneTriResult r2 = getSidePlane(p2, plane, epsilon);
PlaneTriResult r3 = getSidePlane(p3, plane, epsilon);
@@ -161,13 +155,11 @@ PlaneTriResult planeTriIntersection(const float *plane, // the plane equation
if (r1 == PTR_FRONT)
{
add(p1, front, tstride, fcount);
add(split, front, tstride, fcount);
add(split, back, tstride, bcount);
add(p2, back, tstride, bcount);
}
else
{
@@ -177,7 +169,6 @@ PlaneTriResult planeTriIntersection(const float *plane, // the plane equation
add(split, front, tstride, fcount);
add(p2, front, tstride, fcount);
}
}
// Next test ray segment P2 to P3
@@ -232,7 +223,5 @@ PlaneTriResult planeTriIntersection(const float *plane, // the plane equation
}
}
return PTR_SPLIT;
}

View File

@@ -36,8 +36,6 @@
// http://www.amillionpixels.us
//
enum PlaneTriResult
{
PTR_FRONT,
@@ -54,5 +52,4 @@ PlaneTriResult planeTriIntersection(const float *plane, // the plane equation
float *back, // the triangle in back of the plane
unsigned int &bcount); // the number of vertices in the 'back' triangle.
#endif

View File

@@ -41,15 +41,12 @@
// http://www.amillionpixels.us
//
/* a = b - c */
#define vector(a, b, c) \
(a)[0] = (b)[0] - (c)[0]; \
(a)[1] = (b)[1] - (c)[1]; \
(a)[2] = (b)[2] - (c)[2];
#define innerProduct(v, q) \
((v)[0] * (q)[0] + \
(v)[1] * (q)[1] + \
@@ -62,7 +59,6 @@
bool rayIntersectsTriangle(const float *p, const float *d, const float *v0, const float *v1, const float *v2, float &t)
{
float e1[3], e2[3], h[3], s[3], q[3];
float a, f, u, v;
@@ -95,7 +91,6 @@ bool rayIntersectsTriangle(const float *p,const float *d,const float *v0,const f
return (false);
}
bool lineIntersectsTriangle(const float *rayStart, const float *rayEnd, const float *p1, const float *p2, const float *p3, float *sect)
{
float dir[3];
@@ -111,7 +106,6 @@ bool lineIntersectsTriangle(const float *rayStart,const float *rayEnd,const floa
dir[1] *= r;
dir[2] *= r;
float t;
bool ret = rayIntersectsTriangle(rayStart, dir, p1, p2, p3, t);

View File

@@ -36,8 +36,6 @@
// http://www.amillionpixels.us
//
// returns true if the ray intersects the triangle.
bool lineIntersectsTriangle(const float *rayStart, const float *rayEnd, const float *p1, const float *p2, const float *p3, float *sect);
bool rayIntersectsTriangle(const float *p, const float *d, const float *v0, const float *v1, const float *v2, float &t);

View File

@@ -6,7 +6,6 @@
#include <float.h>
#include <math.h>
/*----------------------------------------------------------------------
Copyright (c) 2004 Open Dynamics Framework Group
www.physicstools.org
@@ -53,10 +52,8 @@
namespace ConvexDecomposition
{
static void computePlane(const float *A, const float *B, const float *C, float *plane)
{
float vx = (B[0] - C[0]);
float vy = (B[1] - C[1]);
float vz = (B[2] - C[2]);
@@ -84,14 +81,12 @@ static void computePlane(const float *A,const float *B,const float *C,float *pla
float y = vw_y * mag;
float z = vw_z * mag;
float D = 0.0f - ((x * A[0]) + (y * A[1]) + (z * A[2]));
plane[0] = x;
plane[1] = y;
plane[2] = z;
plane[3] = D;
}
class Rect3d
@@ -101,7 +96,6 @@ public:
Rect3d(const float *bmin, const float *bmax)
{
mMin[0] = bmin[0];
mMin[1] = bmin[1];
mMin[2] = bmin[2];
@@ -109,7 +103,6 @@ public:
mMax[0] = bmax[0];
mMax[1] = bmax[1];
mMax[2] = bmax[2];
}
void SetMin(const float *bmin)
@@ -200,14 +193,12 @@ bool computeSplitPlane(unsigned int vcount,
if (p[0] > bmax[0]) bmax[0] = p[0];
if (p[1] > bmax[1]) bmax[1] = p[1];
if (p[2] > bmax[2]) bmax[2] = p[2];
}
float dx = bmax[0] - bmin[0];
float dy = bmax[1] - bmin[1];
float dz = bmax[2] - bmin[2];
float laxis = dx;
unsigned int axis = 0;
@@ -238,7 +229,6 @@ bool computeSplitPlane(unsigned int vcount,
splitRect(axis, b, b1, b2, p1);
// callback->ConvexDebugBound(b1.mMin,b1.mMax,0x00FF00);
// callback->ConvexDebugBound(b2.mMin,b2.mMax,0xFFFF00);
@@ -299,8 +289,6 @@ bool computeSplitPlane(unsigned int vcount,
computePlane(p1, p2, p3, plane);
return true;
}
}
} // namespace ConvexDecomposition

View File

@@ -39,11 +39,8 @@
// http://www.amillionpixels.us
//
namespace ConvexDecomposition
{
class ConvexDecompInterface;
bool computeSplitPlane(unsigned int vcount,
@@ -53,7 +50,6 @@ bool computeSplitPlane(unsigned int vcount,
ConvexDecompInterface *callback,
float *plane);
}
} // namespace ConvexDecomposition
#endif

View File

@@ -10,7 +10,6 @@
#include <map>
#include <set>
/*----------------------------------------------------------------------
Copyright (c) 2004 Open Dynamics Framework Group
www.physicstools.org
@@ -107,14 +106,10 @@
// You could easily modify this code to support other vertex
// formats with any number of interpolants.
#include "vlookup.h"
namespace Vlookup
{
class VertexPosition
{
public:
@@ -133,7 +128,6 @@ public:
mPos[0] = p[0];
mPos[1] = p[1];
mPos[2] = p[2];
};
float GetX(void) const { return mPos[0]; };
@@ -177,7 +171,6 @@ struct VertexID
class VertexLess
{
public:
bool operator()(VertexID v1, VertexID v2) const;
private:
@@ -189,7 +182,8 @@ private:
}
};
template <class Type> class VertexPool
template <class Type>
class VertexPool
{
public:
typedef std::set<VertexID, VertexLess> VertexSet;
@@ -210,7 +204,6 @@ public:
return idx;
};
const float *GetPos(int idx) const
{
return mVtxs[idx].mPos;
@@ -245,7 +238,6 @@ public:
return mVtxs.size();
};
Type *getBuffer(void)
{
return &mVtxs[0];
@@ -257,10 +249,8 @@ private:
Tracker mTracker;
};
bool VertexLess::operator()(VertexID v1, VertexID v2) const
{
const VertexPosition &a = Get(v1);
const VertexPosition &b = Get(v2);
@@ -282,14 +272,10 @@ bool VertexLess::operator()(VertexID v1,VertexID v2) const
if (izA < izB) return true;
if (izA > izB) return false;
return false;
}
}
} // namespace Vlookup
using namespace Vlookup;
@@ -318,7 +304,6 @@ const float * Vl_getVertices(VertexLookup vlook)
return vp->GetPos(0);
}
unsigned int Vl_getVcount(VertexLookup vlook)
{
VertexPool<VertexPosition> *vp = (VertexPool<VertexPosition> *)vlook;

View File

@@ -2,7 +2,6 @@
#define VLOOKUP_H
/*----------------------------------------------------------------------
Copyright (c) 2004 Open Dynamics Framework Group
www.physicstools.org
@@ -37,7 +36,6 @@
// http://www.amillionpixels.us
//
// CodeSnippet provided by John W. Ratcliff
// on March 23, 2006.
//
@@ -105,7 +103,6 @@
// Uses an STL set to create an index table for a bunch of vertex positions
// used typically to re-index a collection of raw triangle data.
typedef void *VertexLookup;
VertexLookup Vl_createVertexLookup(void);
@@ -115,5 +112,4 @@ unsigned int Vl_getIndex(VertexLookup vlook,const float *pos); // get index.
const float *Vl_getVertices(VertexLookup vlook);
unsigned int Vl_getVcount(VertexLookup vlook);
#endif

View File

@@ -30,7 +30,6 @@ protected:
btAlignedObjectArray<btCollisionShape*> m_convexShapes;
public:
int mBaseCount;
int mHullCount;
@@ -52,26 +51,22 @@ public:
btCollisionShape* shape = m_convexShapes[i];
delete shape;
}
}
virtual void ConvexDecompResult(ConvexDecomposition::ConvexResult& result)
{
//calc centroid, to shift vertices around center of mass
btVector3 centroid(0, 0, 0);
btAlignedObjectArray<btVector3> vertices;
if (m_transformSubShapes)
{
//const unsigned int *src = result.mHullIndices;
for (unsigned int i = 0; i < result.mHullVcount; i++)
{
btVector3 vertex(result.mHullVertices[i * 3], result.mHullVertices[i * 3 + 1], result.mHullVertices[i * 3 + 2]);
centroid += vertex;
}
centroid *= 1.f / (float(result.mHullVcount));
}
@@ -125,7 +120,6 @@ public:
btGImpactMeshShapePart::TrimeshPrimitiveManager* trimeshInterface =
m_compoundShape->getTrimeshInterface(part);
trimeshInterface->lock();
//collect vertices
@@ -141,12 +135,10 @@ public:
vertices.push_back(vec[2]);
}
//collect indices
btAlignedObjectArray<unsigned int> indices;
indices.reserve(trimeshInterface->get_primitive_count() * 3);
for (int i = 0; i < trimeshInterface->get_primitive_count(); i++)
{
unsigned int i0, i1, i2;
@@ -158,15 +150,12 @@ public:
trimeshInterface->unlock();
unsigned int depth = 5;
float cpercent = 5;
float ppercent = 15;
unsigned int maxv = 16;
float skinWidth = 0.0f;
ConvexDecomposition::DecompDesc desc;
desc.mVcount = trimeshInterface->get_vertex_count();
desc.mVertices = &vertices[0];
@@ -184,17 +173,10 @@ public:
ConvexBuilder cb(desc.mCallback);
cb.process(desc);
}
};
void btGImpactConvexDecompositionShape::buildConvexDecomposition(bool transformSubShapes)
{
m_decomposition = new GIM_ConvexDecomposition(this, transformSubShapes);
int part_count = m_trimeshInterfaces.size();
@@ -212,7 +194,6 @@ btGImpactConvexDecompositionShape::~btGImpactConvexDecompositionShape()
}
void btGImpactConvexDecompositionShape::processAllTriangles(btTriangleCallback* callback, const btVector3& aabbMin, const btVector3& aabbMax) const
{
int part_count = m_trimeshInterfaces.size();
for (int part = 0; part < part_count; part++)
{
@@ -225,7 +206,6 @@ void btGImpactConvexDecompositionShape::processAllTriangles(btTriangleCallback*
btPrimitiveTriangle triangle;
int i = trimeshInterface->get_primitive_count();
while (i--)
{
@@ -235,6 +215,4 @@ void btGImpactConvexDecompositionShape::processAllTriangles(btTriangleCallback*
trimeshInterface->unlock();
}
}

View File

@@ -24,11 +24,8 @@ subject to the following restrictions:
#ifndef GIMPACT_CONVEX_DECOMPOSITION_SHAPE_H
#define GIMPACT_CONVEX_DECOMPOSITION_SHAPE_H
#include "BulletCollision/Gimpact/btGImpactShape.h" // box tree class
//! This class creates a decomposition from a trimesh.
/*!
@@ -41,15 +38,14 @@ protected:
class GIM_ConvexDecomposition* m_decomposition;
void buildConvexDecomposition(bool transformSubShapes);
public:
public:
btGImpactConvexDecompositionShape(
btStridingMeshInterface* meshInterface,
const btVector3& mesh_scale,
btScalar margin = btScalar(0.01), bool children_has_transform = true)
: btGImpactCompoundShape(children_has_transform)
{
m_collisionMargin = margin;
btGImpactMeshShapePart::TrimeshPrimitiveManager triInterface;
@@ -78,10 +74,6 @@ public:
}
virtual void processAllTriangles(btTriangleCallback* callback, const btVector3& aabbMin, const btVector3& aabbMax) const;
};
#endif //GIMPACT_MESH_SHAPE_H

View File

@@ -20,7 +20,8 @@
namespace HACD
{
//! CircularListElement class.
template < typename T > class CircularListElement
template <typename T>
class CircularListElement
{
public:
T& GetData() { return m_data; }
@@ -34,6 +35,7 @@ namespace HACD
CircularListElement(void) {}
//! Destructor
~CircularListElement(void) {}
private:
T m_data;
CircularListElement<T>* m_next;
@@ -42,9 +44,9 @@ namespace HACD
CircularListElement(const CircularListElement& rhs);
};
//! CircularList class.
template < typename T > class CircularList
template <typename T>
class CircularList
{
public:
CircularListElement<T>*& GetHead() { return m_head; }
@@ -59,7 +61,11 @@ namespace HACD
CircularListElement<T>* Add(const T& data);
bool Next();
bool Prev();
void Clear() { while(Delete());};
void Clear()
{
while (Delete())
;
};
const CircularList& operator=(const CircularList& rhs);
//! Constructor
CircularList()
@@ -70,11 +76,11 @@ namespace HACD
CircularList(const CircularList& rhs);
//! Destructor
virtual ~CircularList(void) { Clear(); };
private:
CircularListElement<T>* m_head; //!< a pointer to the head of the circular list
size_t m_size; //!< number of element in the circular list
};
}
} // namespace HACD
#include "hacdCircularList.inl"
#endif

View File

@@ -15,7 +15,6 @@
#include "hacdGraph.h"
namespace HACD
{
GraphEdge::GraphEdge()
{
m_convexHull = 0;
@@ -207,7 +206,6 @@ namespace HACD
const GraphVertex& currentVertex = m_vertices[v];
if (!m_vertices[v].m_deleted)
{
std::cout << currentVertex.m_name << "\t";
std::set<long>::const_iterator ed(currentVertex.m_edges.begin());
std::set<long>::const_iterator itEnd(currentVertex.m_edges.end());
@@ -289,4 +287,4 @@ namespace HACD
}
return static_cast<long>(m_nCCs);
}
}
} // namespace HACD

View File

@@ -40,6 +40,7 @@ namespace HACD
bool DeleteEdge(long name);
GraphVertex();
~GraphVertex() { delete m_convexHull; };
private:
long m_name;
long m_cc;
@@ -56,7 +57,6 @@ namespace HACD
ICHull* m_convexHull;
std::set<unsigned long long> m_boudaryEdges;
friend class GraphEdge;
friend class Graph;
friend class HACD;
@@ -67,6 +67,7 @@ namespace HACD
public:
GraphEdge();
~GraphEdge() { delete m_convexHull; };
private:
long m_name;
long m_v1;
@@ -81,8 +82,6 @@ namespace HACD
std::set<unsigned long long> m_boudaryEdges;
bool m_deleted;
friend class GraphVertex;
friend class Graph;
friend class HACD;
@@ -116,5 +115,5 @@ namespace HACD
friend class HACD;
};
}
} // namespace HACD
#endif

View File

@@ -169,7 +169,6 @@ namespace HACD
}
if (distC1C2 <= m_ccConnectDist && t1 > 0 && t2 > 0)
{
m_graph.AddEdge(t1, t2);
}
}
@@ -268,7 +267,6 @@ namespace HACD
distMin = distance;
faceIndex = f1;
}
}
}
if (faceIndex < m_nTriangles)
@@ -308,12 +306,18 @@ namespace HACD
x = m_points[v].X();
y = m_points[v].Y();
z = m_points[v].Z();
if ( x < min.X()) min.X() = x;
else if ( x > max.X()) max.X() = x;
if ( y < min.Y()) min.Y() = y;
else if ( y > max.Y()) max.Y() = y;
if ( z < min.Z()) min.Z() = z;
else if ( z > max.Z()) max.Z() = z;
if (x < min.X())
min.X() = x;
else if (x > max.X())
max.X() = x;
if (y < min.Y())
min.Y() = y;
else if (y > max.Y())
max.Y() = y;
if (z < min.Z())
min.Z() = z;
else if (z > max.Z())
max.Z() = z;
}
m_barycenter /= static_cast<Real>(m_nPoints);
m_diag = (max - min).GetNorm();
@@ -535,7 +539,8 @@ namespace HACD
for (; itBE != itBEEnd; ++itBE)
{
perimeter += (m_points[static_cast<long>((*itBE) >> 32)] -
m_points[static_cast<long>((*itBE) & 0xFFFFFFFFULL)]).GetNorm();
m_points[static_cast<long>((*itBE) & 0xFFFFFFFFULL)])
.GetNorm();
}
surf = gV1.m_surf + gV2.m_surf;
}
@@ -597,11 +602,9 @@ namespace HACD
}
currentEdge = m_pqueue.top();
m_pqueue.pop();
}
while ( m_graph.m_edges[currentEdge.m_name].m_deleted ||
} while (m_graph.m_edges[currentEdge.m_name].m_deleted ||
m_graph.m_edges[currentEdge.m_name].m_error != currentEdge.m_priority);
if (m_graph.m_edges[currentEdge.m_name].m_concavity < m_concavity && !done)
{
globalConcavity = std::max<double>(globalConcavity, m_graph.m_edges[currentEdge.m_name].m_concavity);
@@ -663,7 +666,6 @@ namespace HACD
sprintf(msg, "# clusters = %lu \t C = %f\n", static_cast<unsigned long>(m_nClusters), globalConcavity);
(*m_callBack)(msg, progress, globalConcavity, m_graph.GetNVertices());
}
}
bool HACD::Compute(bool fullCH, bool exportDistPoints)
@@ -846,6 +848,4 @@ namespace HACD
return false;
}
}
}
} // namespace HACD

View File

@@ -35,6 +35,7 @@ namespace HACD
class reservable_priority_queue : public std::priority_queue<_Ty, _Container, _Pr>
{
typedef typename std::priority_queue<_Ty, _Container, _Pr>::size_type size_type;
public:
reservable_priority_queue(size_type capacity = 0) { reserve(capacity); };
void reserve(size_type capacity) { this->c.reserve(capacity); }
@@ -55,6 +56,7 @@ namespace HACD
}
//! Destructor
~GraphEdgePriorityQueue(void) {}
private:
long m_name; //!< edge name
Real m_priority; //!< priority
@@ -78,7 +80,6 @@ namespace HACD
class HACD
{
public:
//! Gives the triangles partitionas an array of size m_nTriangles where the i-th element specifies the cluster to which belong the i-th triangle
//! @return triangles partition
const long *GetPartition() const { return m_partition; }
@@ -213,8 +214,10 @@ namespace HACD
//! @return edge's index
static unsigned long long GetEdgeIndex(unsigned long long a, unsigned long long b)
{
if (a > b) return (a << 32) + b;
else return (b << 32) + a;
if (a > b)
return (a << 32) + b;
else
return (b << 32) + a;
}
//! Computes the concavity of a cluster.
//! @param ch the cluster's convex-hull
@@ -269,14 +272,14 @@ namespace HACD
size_t m_nVerticesPerCH; //>! maximum number of vertices per convex-hull
reservable_priority_queue<GraphEdgePriorityQueue,
std::vector<GraphEdgePriorityQueue>,
std::greater<std::vector<GraphEdgePriorityQueue>::value_type> > m_pqueue; //!> priority queue
std::greater<std::vector<GraphEdgePriorityQueue>::value_type> >
m_pqueue; //!> priority queue
HACD(const HACD &rhs);
CallBackFunction m_callBack; //>! call-back function
long *m_partition; //>! array of size m_nTriangles where the i-th element specifies the cluster to which belong the i-th triangle
bool m_addFacesPoints; //>! specifies whether to add faces points or not
bool m_addExtraDistPoints; //>! specifies whether to add extra points for concave shapes or not
bool m_addNeighboursDistPoints; //>! specifies whether to add extra points from adjacent clusters or not
};
}
} // namespace HACD
#endif

View File

@@ -370,7 +370,6 @@ namespace HACD
vHead->GetData().m_name = id;
}
return true;
}
ICHullError ICHull::DoubleTriangle()
@@ -415,8 +414,7 @@ namespace HACD
do
{
bary += vBary->GetData().m_pos;
}
while ( (vBary = vBary->GetNext()) != v0);
} while ((vBary = vBary->GetNext()) != v0);
bary /= static_cast<Real>(vertices.GetSize());
// Compute the normal to the plane
@@ -469,13 +467,20 @@ namespace HACD
e2 = fold->GetData().m_edges[0];
index = 1;
}
e0->GetData().m_vertices[0] = v0; e0->GetData().m_vertices[1] = v1;
e1->GetData().m_vertices[0] = v1; e1->GetData().m_vertices[1] = v2;
e2->GetData().m_vertices[0] = v2; e2->GetData().m_vertices[1] = v0;
e0->GetData().m_vertices[0] = v0;
e0->GetData().m_vertices[1] = v1;
e1->GetData().m_vertices[0] = v1;
e1->GetData().m_vertices[1] = v2;
e2->GetData().m_vertices[0] = v2;
e2->GetData().m_vertices[1] = v0;
// create the new face
CircularListElement<TMMTriangle> *f = m_mesh.AddTriangle();
f->GetData().m_edges[0] = e0; f->GetData().m_edges[1] = e1; f->GetData().m_edges[2] = e2;
f->GetData().m_vertices[0] = v0; f->GetData().m_vertices[1] = v1; f->GetData().m_vertices[2] = v2;
f->GetData().m_edges[0] = e0;
f->GetData().m_edges[1] = e1;
f->GetData().m_edges[2] = e2;
f->GetData().m_vertices[0] = v0;
f->GetData().m_vertices[1] = v1;
f->GetData().m_vertices[2] = v2;
// link edges to face f
e0->GetData().m_triangles[index] = e1->GetData().m_triangles[index] = e2->GetData().m_triangles[index] = f;
return f;
@@ -551,8 +556,7 @@ namespace HACD
visible = true;
}
f = f->GetNext();
}
while (f != fHead);
} while (f != fHead);
if (m_trianglesToDelete.size() == m_mesh.m_triangles.GetSize())
{
@@ -610,8 +614,7 @@ namespace HACD
m_edgesToUpdate.push_back(e);
}
e = tmp;
}
while (e != eHead);
} while (e != eHead);
return true;
}
bool ICHull::MakeCCW(CircularListElement<TMMTriangle> *f,
@@ -633,7 +636,8 @@ namespace HACD
long i; // index of e->m_vertices[0] in fv
CircularListElement<TMMVertex> *v0 = e->GetData().m_vertices[0];
CircularListElement<TMMVertex> *v1 = e->GetData().m_vertices[1];
for(i = 0; fv->GetData().m_vertices[i] != v0; i++);
for (i = 0; fv->GetData().m_vertices[i] != v0; i++)
;
if (fv->GetData().m_vertices[(i + 1) % 3] != e->GetData().m_vertices[1])
{
@@ -757,8 +761,7 @@ namespace HACD
v->GetData().m_onHull = false;
v = v->GetPrev();
}
}
while (v->GetData().m_tag && v != vHead);
} while (v->GetData().m_tag && v != vHead);
return true;
}
void ICHull::Clear()
@@ -1014,6 +1017,4 @@ namespace HACD
return distance;
}
}
}
} // namespace HACD

View File

@@ -98,6 +98,7 @@ namespace HACD
CircularListElement<TMMEdge> *e,
CircularListElement<TMMVertex> *v);
void Clear();
private:
static const long sc_dummyIndex;
static const double sc_distMin;
@@ -110,11 +111,10 @@ namespace HACD
Vec3<Real> m_normal;
bool m_isFlat;
ICHull(const ICHull &rhs);
friend class HACD;
};
}
} // namespace HACD
#endif

View File

@@ -15,7 +15,6 @@
#include "hacdManifoldMesh.h"
using namespace std;
namespace HACD
{
Material::Material(void)
@@ -91,7 +90,6 @@ namespace HACD
m_vertices.Next();
}
size_t nE = m_edges.GetSize();
std::cout << "edges (" << nE << ")" << std::endl;
for (size_t e = 0; e < nE; e++)
@@ -183,7 +181,8 @@ namespace HACD
fout << " ccw TRUE" << std::endl;
fout << " solid TRUE" << std::endl;
fout << " convex TRUE" << std::endl;
if (GetNVertices() > 0) {
if (GetNVertices() > 0)
{
fout << " coord DEF co Coordinate {" << std::endl;
fout << " point [" << std::endl;
for (size_t v = 0; v < nV; v++)
@@ -198,7 +197,8 @@ namespace HACD
fout << " ]" << std::endl;
fout << " }" << std::endl;
}
if (GetNTriangles() > 0) {
if (GetNTriangles() > 0)
{
fout << " coordIndex [ " << std::endl;
for (size_t f = 0; f < nT; f++)
{
@@ -259,7 +259,6 @@ namespace HACD
{
mesh.m_edges.GetData().m_id = e;
mesh.m_edges.Next();
}
for (size_t f = 0; f < nT; f++)
{
@@ -346,7 +345,6 @@ namespace HACD
delete[] vertexMap;
delete[] edgeMap;
delete[] triangleMap;
}
long IntersectRayTriangle(const Vec3<double> &P0, const Vec3<double> &dir,
const Vec3<double> &V0, const Vec3<double> &V1,
@@ -445,10 +443,12 @@ namespace HACD
w0 = P0 - V0;
a = -n * w0;
b = n * dir;
if (fabs(b) <= 0.0) { // ray is parallel to triangle plane
if (fabs(b) <= 0.0)
{ // ray is parallel to triangle plane
if (a == 0.0) // ray lies in triangle plane
return 2;
else return 0; // ray disjoint from plane
else
return 0; // ray disjoint from plane
}
// get intersect point of ray with triangle plane
@@ -480,7 +480,6 @@ namespace HACD
return 1; // I is in T
}
bool TMMesh::CheckConsistancy()
{
size_t nE = m_edges.GetSize();
@@ -536,12 +535,18 @@ namespace HACD
x = m_vertices.GetHead()->GetData().m_pos.X();
y = m_vertices.GetHead()->GetData().m_pos.Y();
z = m_vertices.GetHead()->GetData().m_pos.Z();
if ( x < min.X()) min.X() = x;
else if ( x > max.X()) max.X() = x;
if ( y < min.Y()) min.Y() = y;
else if ( y > max.Y()) max.Y() = y;
if ( z < min.Z()) min.Z() = z;
else if ( z > max.Z()) max.Z() = z;
if (x < min.X())
min.X() = x;
else if (x > max.X())
max.X() = x;
if (y < min.Y())
min.Y() = y;
else if (y > max.Y())
max.Y() = y;
if (z < min.Z())
min.Z() = z;
else if (z > max.Z())
max.Z() = z;
m_vertices.Next();
}
m_barycenter /= static_cast<Real>(nV);
@@ -574,4 +579,4 @@ namespace HACD
}
return false;
}
}
} // namespace HACD

View File

@@ -52,6 +52,7 @@ namespace HACD
m_computed(computed),
m_distOnly(distOnly){};
~DPoint(){};
private:
Real m_dist;
bool m_computed;
@@ -94,13 +95,13 @@ namespace HACD
public:
TMMEdge(void);
~TMMEdge(void);
private:
size_t m_id;
CircularListElement<TMMTriangle> *m_triangles[2];
CircularListElement<TMMVertex> *m_vertices[2];
CircularListElement<TMMTriangle> *m_newFace;
TMMEdge(const TMMEdge &rhs);
friend class HACD;
@@ -116,6 +117,7 @@ namespace HACD
public:
TMMTriangle(void);
~TMMTriangle(void);
private:
size_t m_id;
CircularListElement<TMMEdge> *m_edges[3];
@@ -153,7 +155,6 @@ namespace HACD
class TMMesh
{
public:
//! Returns the number of vertices>
inline size_t GetNVertices() const { return m_vertices.GetSize(); }
//! Returns the number of edges
@@ -246,5 +247,5 @@ namespace HACD
const Vec3<double> &p3, const Vec3<double> &p4,
Vec3<double> &pa, Vec3<double> &pb,
double &mua, double &mub);
}
} // namespace HACD
#endif

View File

@@ -23,7 +23,8 @@ namespace HACD
{
typedef double Real;
//! Vector dim 3.
template < typename T > class Vec3
template <typename T>
class Vec3
{
public:
T& X();
@@ -62,6 +63,6 @@ namespace HACD
template <typename T>
const T Volume(const Vec3<T>& a, const Vec3<T>& b, const Vec3<T>& c, const Vec3<T>& d);
}
} // namespace HACD
#include "hacdVector.inl" // template implementation
#endif

View File

@@ -13,5 +13,3 @@
#include "User2InternalIndex.hpp"
#endif //BULLET_INVERSE_DYNAMICS_UTILS_COMMON_H

View File

@@ -2,27 +2,36 @@
#include <cstdio>
namespace btInverseDynamics {
namespace btInverseDynamics
{
#define CHECK_NULLPTR() \
do { \
if (m_reference == 0x0) { \
do \
{ \
if (m_reference == 0x0) \
{ \
bt_id_error_message("m_reference == 0x0\n"); \
return -1; \
} \
} while (0)
#define TRY(x) \
do { \
if (x == -1) { \
do \
{ \
if (x == -1) \
{ \
bt_id_error_message("error calling " #x "\n"); \
return -1; \
} \
} while (0)
CloneTreeCreator::CloneTreeCreator(const MultiBodyTree* reference) { m_reference = reference; }
CloneTreeCreator::CloneTreeCreator(const MultiBodyTree* reference)
{
m_reference = reference;
}
CloneTreeCreator::~CloneTreeCreator() {}
int CloneTreeCreator::getNumBodies(int* num_bodies) const {
int CloneTreeCreator::getNumBodies(int* num_bodies) const
{
CHECK_NULLPTR();
*num_bodies = m_reference->numBodies();
return 0;
@@ -31,7 +40,8 @@ int CloneTreeCreator::getNumBodies(int* num_bodies) const {
int CloneTreeCreator::getBody(const int body_index, int* parent_index, JointType* joint_type,
vec3* parent_r_parent_body_ref, mat33* body_T_parent_ref,
vec3* body_axis_of_motion, idScalar* mass, vec3* body_r_body_com,
mat33* body_I_body, int* user_int, void** user_ptr) const {
mat33* body_I_body, int* user_int, void** user_ptr) const
{
CHECK_NULLPTR();
TRY(m_reference->getParentIndex(body_index, parent_index));
TRY(m_reference->getJointType(body_index, joint_type));
@@ -46,4 +56,4 @@ int CloneTreeCreator::getBody(const int body_index, int* parent_index, JointType
return 0;
}
}
} // namespace btInverseDynamics

View File

@@ -4,9 +4,11 @@
#include "BulletInverseDynamics/IDConfig.hpp"
#include "MultiBodyTreeCreator.hpp"
namespace btInverseDynamics {
namespace btInverseDynamics
{
/// Generate an identical multibody tree from a reference system.
class CloneTreeCreator : public MultiBodyTreeCreator {
class CloneTreeCreator : public MultiBodyTreeCreator
{
public:
/// ctor
/// @param reference the MultiBodyTree to clone
@@ -23,5 +25,5 @@ public:
private:
const MultiBodyTree* m_reference;
};
}
} // namespace btInverseDynamics
#endif // CLONETREE_CREATOR_HPP_

View File

@@ -2,9 +2,12 @@
#include "CoilCreator.hpp"
namespace btInverseDynamics {
CoilCreator::CoilCreator(int n) : m_num_bodies(n), m_parent(n) {
for (int i = 0; i < m_num_bodies; i++) {
namespace btInverseDynamics
{
CoilCreator::CoilCreator(int n) : m_num_bodies(n), m_parent(n)
{
for (int i = 0; i < m_num_bodies; i++)
{
m_parent[i] = i - 1;
}
@@ -38,7 +41,8 @@ CoilCreator::CoilCreator(int n) : m_num_bodies(n), m_parent(n) {
CoilCreator::~CoilCreator() {}
int CoilCreator::getNumBodies(int* num_bodies) const {
int CoilCreator::getNumBodies(int* num_bodies) const
{
*num_bodies = m_num_bodies;
return 0;
}
@@ -46,8 +50,10 @@ int CoilCreator::getNumBodies(int* num_bodies) const {
int CoilCreator::getBody(int body_index, int* parent_index, JointType* joint_type,
vec3* parent_r_parent_body_ref, mat33* body_T_parent_ref,
vec3* body_axis_of_motion, idScalar* mass, vec3* body_r_body_com,
mat33* body_I_body, int* user_int, void** user_ptr) const {
if (body_index < 0 || body_index >= m_num_bodies) {
mat33* body_I_body, int* user_int, void** user_ptr) const
{
if (body_index < 0 || body_index >= m_num_bodies)
{
bt_id_error_message("invalid body index %d\n", body_index);
return -1;
}
@@ -64,4 +70,4 @@ int CoilCreator::getBody(int body_index, int* parent_index, JointType* joint_typ
*user_ptr = 0;
return 0;
}
}
} // namespace btInverseDynamics

View File

@@ -3,15 +3,16 @@
#include "MultiBodyTreeCreator.hpp"
namespace btInverseDynamics {
namespace btInverseDynamics
{
/// Creator class for building a "coil" system as intruduced as benchmark example in
/// Featherstone (1999), "A Divide-and-Conquer Articulated-Body Algorithm for Parallel O(log(n))
/// Calculation of Rigid-Body Dynamics. Part 2: Trees, Loops, and Accuracy.", The International
/// Journal of Robotics Research 18 (9): 876892. doi : 10.1177 / 02783649922066628.
///
/// This is a serial chain, with an initial configuration resembling a coil.
class CoilCreator : public MultiBodyTreeCreator {
class CoilCreator : public MultiBodyTreeCreator
{
public:
/// ctor.
/// @param n the number of bodies in the system
@@ -36,5 +37,5 @@ private:
vec3 m_body_r_body_com;
mat33 m_body_I_body;
};
}
} // namespace btInverseDynamics
#endif

View File

@@ -1,7 +1,7 @@
#include "DillCreator.hpp"
#include <cmath>
namespace btInverseDynamics {
namespace btInverseDynamics
{
DillCreator::DillCreator(int level)
: m_level(level),
m_num_bodies(BT_ID_POW(2, level))
@@ -15,7 +15,8 @@ DillCreator::DillCreator(int level)
m_body_I_body.resize(m_num_bodies);
// generate names (for debugging)
for (int i = 0; i < m_num_bodies; i++) {
for (int i = 0; i < m_num_bodies; i++)
{
m_parent[i] = i - 1;
// all z-axis (DH convention)
@@ -31,7 +32,8 @@ DillCreator::DillCreator(int level)
const idScalar a_DH = 0.0;
const idScalar alpha_DH = 0.0;
if (-1 == recurseDill(m_level, parent, d_DH, a_DH, alpha_DH)) {
if (-1 == recurseDill(m_level, parent, d_DH, a_DH, alpha_DH))
{
bt_id_error_message("recurseDill failed\n");
abort();
}
@@ -39,7 +41,8 @@ DillCreator::DillCreator(int level)
DillCreator::~DillCreator() {}
int DillCreator::getNumBodies(int* num_bodies) const {
int DillCreator::getNumBodies(int* num_bodies) const
{
*num_bodies = m_num_bodies;
return 0;
}
@@ -47,8 +50,10 @@ int DillCreator::getNumBodies(int* num_bodies) const {
int DillCreator::getBody(const int body_index, int* parent_index, JointType* joint_type,
vec3* parent_r_parent_body_ref, mat33* body_T_parent_ref,
vec3* body_axis_of_motion, idScalar* mass, vec3* body_r_body_com,
mat33* body_I_body, int* user_int, void** user_ptr) const {
if (body_index < 0 || body_index >= m_num_bodies) {
mat33* body_I_body, int* user_int, void** user_ptr) const
{
if (body_index < 0 || body_index >= m_num_bodies)
{
bt_id_error_message("invalid body index %d\n", body_index);
return -1;
}
@@ -67,13 +72,16 @@ int DillCreator::getBody(const int body_index, int* parent_index, JointType* joi
}
int DillCreator::recurseDill(const int level, const int parent, const idScalar d_DH_in,
const idScalar a_DH_in, const idScalar alpha_DH_in) {
if (level < 0) {
const idScalar a_DH_in, const idScalar alpha_DH_in)
{
if (level < 0)
{
bt_id_error_message("invalid level parameter (%d)\n", level);
return -1;
}
if (m_current_body >= m_num_bodies || m_current_body < 0) {
if (m_current_body >= m_num_bodies || m_current_body < 0)
{
bt_id_error_message("invalid body parameter (%d, num_bodies: %d)\n", m_current_body,
m_num_bodies);
return -1;
@@ -92,9 +100,11 @@ int DillCreator::recurseDill(const int level, const int parent, const idScalar d
m_body_r_body_com[body](1) = 0;
m_body_r_body_com[body](2) = 0;
// initialization
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++)
{
m_parent_r_parent_body_ref[body](i) = 0;
for (int j = 0; j < 3; j++) {
for (int j = 0; j < 3; j++)
{
m_body_I_body[body](i, j) = 0.0;
m_body_T_parent_ref[body](i, j) = 0.0;
}
@@ -108,9 +118,11 @@ int DillCreator::recurseDill(const int level, const int parent, const idScalar d
&m_body_T_parent_ref[body]);
// attach "level" Dill systems of levels 1...level
for (int i = 1; i <= level; i++) {
for (int i = 1; i <= level; i++)
{
idScalar d_DH = 0.01 * size;
if (i == level) {
if (i == level)
{
d_DH = 0.0;
}
const idScalar a_DH = i * 0.1;
@@ -121,4 +133,4 @@ int DillCreator::recurseDill(const int level, const int parent, const idScalar d
return 0; // ok!
}
}
} // namespace btInverseDynamics

View File

@@ -3,16 +3,16 @@
#include "MultiBodyTreeCreator.hpp"
namespace btInverseDynamics {
namespace btInverseDynamics
{
/// Creator class for building a "Dill" system as intruduced as benchmark example in
/// Featherstone (1999), "A Divide-and-Conquer Articulated-Body Algorithm for Parallel O(log(n))
/// Calculation of Rigid-Body Dynamics. Part 2: Trees, Loops, and Accuracy.", The International
/// Journal of Robotics Research 18 (9): 876892. doi : 10.1177 / 02783649922066628.
///
/// This is a self-similar branched tree, somewhat resembling a dill plant
class DillCreator : public MultiBodyTreeCreator {
class DillCreator : public MultiBodyTreeCreator
{
public:
/// ctor
/// @param levels the number of dill levels
@@ -43,5 +43,5 @@ private:
idArray<mat33>::type m_body_I_body;
int m_current_body;
};
}
} // namespace btInverseDynamics
#endif

View File

@@ -6,9 +6,8 @@
#include "BulletInverseDynamics/IDMath.hpp"
#include "IDRandomUtil.hpp"
namespace btInverseDynamics {
namespace btInverseDynamics
{
// constants for random mass and inertia generation
// these are arbitrary positive values.
static const float mass_min = 0.001;
@@ -19,15 +18,18 @@ void randomInit(unsigned seed) { srand(seed); }
int randomInt(int low, int high) { return rand() % (high + 1 - low) + low; }
float randomFloat(float low, float high) {
float randomFloat(float low, float high)
{
return low + static_cast<float>(rand()) / RAND_MAX * (high - low);
}
float randomMass() { return randomFloat(mass_min, mass_max); }
vec3 randomInertiaPrincipal() {
vec3 randomInertiaPrincipal()
{
vec3 inertia;
do {
do
{
inertia(0) = randomFloat(mass_min, mass_max);
inertia(1) = randomFloat(mass_min, mass_max);
inertia(2) = randomFloat(mass_min, mass_max);
@@ -36,7 +38,8 @@ vec3 randomInertiaPrincipal() {
return inertia;
}
mat33 randomInertiaMatrix() {
mat33 randomInertiaMatrix()
{
// generate random valid inertia matrix by first getting valid components
// along major axes and then rotating by random amount
vec3 principal = randomInertiaPrincipal();
@@ -55,10 +58,12 @@ mat33 randomInertiaMatrix() {
return rot * inertia * rot.transpose();
}
vec3 randomAxis() {
vec3 randomAxis()
{
vec3 axis;
idScalar length;
do {
do
{
axis(0) = randomFloat(-1.0, 1.0);
axis(1) = randomFloat(-1.0, 1.0);
axis(2) = randomFloat(-1.0, 1.0);
@@ -68,4 +73,4 @@ vec3 randomAxis() {
return axis / length;
}
}
} // namespace btInverseDynamics

View File

@@ -1,7 +1,8 @@
#ifndef ID_RANDOM_UTIL_HPP_
#define ID_RANDOM_UTIL_HPP_
#include "BulletInverseDynamics/IDConfig.hpp"
namespace btInverseDynamics {
namespace btInverseDynamics
{
/// seed random number generator using time()
void randomInit();
/// seed random number generator with identical value to get repeatable results
@@ -32,5 +33,5 @@ vec3 randomInertiaPrincipal();
mat33 randomInertiaMatrix();
/// generate a random unit vector
vec3 randomAxis();
}
} // namespace btInverseDynamics
#endif

View File

@@ -1,15 +1,18 @@
#include "MultiBodyNameMap.hpp"
namespace btInverseDynamics {
namespace btInverseDynamics
{
MultiBodyNameMap::MultiBodyNameMap() {}
int MultiBodyNameMap::addBody(const int index, const std::string& name) {
if (m_index_to_body_name.count(index) > 0) {
int MultiBodyNameMap::addBody(const int index, const std::string& name)
{
if (m_index_to_body_name.count(index) > 0)
{
bt_id_error_message("trying to add index %d again\n", index);
return -1;
}
if (m_body_name_to_index.count(name) > 0) {
if (m_body_name_to_index.count(name) > 0)
{
bt_id_error_message("trying to add name %s again\n", name.c_str());
return -1;
}
@@ -20,12 +23,15 @@ int MultiBodyNameMap::addBody(const int index, const std::string& name) {
return 0;
}
int MultiBodyNameMap::addJoint(const int index, const std::string& name) {
if (m_index_to_joint_name.count(index) > 0) {
int MultiBodyNameMap::addJoint(const int index, const std::string& name)
{
if (m_index_to_joint_name.count(index) > 0)
{
bt_id_error_message("trying to add index %d again\n", index);
return -1;
}
if (m_joint_name_to_index.count(name) > 0) {
if (m_joint_name_to_index.count(name) > 0)
{
bt_id_error_message("trying to add name %s again\n", name.c_str());
return -1;
}
@@ -36,9 +42,11 @@ int MultiBodyNameMap::addJoint(const int index, const std::string& name) {
return 0;
}
int MultiBodyNameMap::getBodyName(const int index, std::string* name) const {
int MultiBodyNameMap::getBodyName(const int index, std::string* name) const
{
std::map<int, std::string>::const_iterator it = m_index_to_body_name.find(index);
if (it == m_index_to_body_name.end()) {
if (it == m_index_to_body_name.end())
{
bt_id_error_message("index %d not known\n", index);
return -1;
}
@@ -46,9 +54,11 @@ int MultiBodyNameMap::getBodyName(const int index, std::string* name) const {
return 0;
}
int MultiBodyNameMap::getJointName(const int index, std::string* name) const {
int MultiBodyNameMap::getJointName(const int index, std::string* name) const
{
std::map<int, std::string>::const_iterator it = m_index_to_joint_name.find(index);
if (it == m_index_to_joint_name.end()) {
if (it == m_index_to_joint_name.end())
{
bt_id_error_message("index %d not known\n", index);
return -1;
}
@@ -56,9 +66,11 @@ int MultiBodyNameMap::getJointName(const int index, std::string* name) const {
return 0;
}
int MultiBodyNameMap::getBodyIndex(const std::string& name, int* index) const {
int MultiBodyNameMap::getBodyIndex(const std::string& name, int* index) const
{
std::map<std::string, int>::const_iterator it = m_body_name_to_index.find(name);
if (it == m_body_name_to_index.end()) {
if (it == m_body_name_to_index.end())
{
bt_id_error_message("name %s not known\n", name.c_str());
return -1;
}
@@ -66,13 +78,15 @@ int MultiBodyNameMap::getBodyIndex(const std::string& name, int* index) const {
return 0;
}
int MultiBodyNameMap::getJointIndex(const std::string& name, int* index) const {
int MultiBodyNameMap::getJointIndex(const std::string& name, int* index) const
{
std::map<std::string, int>::const_iterator it = m_joint_name_to_index.find(name);
if (it == m_joint_name_to_index.end()) {
if (it == m_joint_name_to_index.end())
{
bt_id_error_message("name %s not known\n", name.c_str());
return -1;
}
*index = it->second;
return 0;
}
}
} // namespace btInverseDynamics

View File

@@ -5,11 +5,12 @@
#include <string>
#include <map>
namespace btInverseDynamics {
namespace btInverseDynamics
{
/// \brief The MultiBodyNameMap class
/// Utility class that stores a maps from body/joint indices to/from body and joint names
class MultiBodyNameMap {
class MultiBodyNameMap
{
public:
MultiBodyNameMap();
/// add a body to the map
@@ -50,5 +51,5 @@ private:
std::map<std::string, int> m_joint_name_to_index;
std::map<std::string, int> m_body_name_to_index;
};
}
} // namespace btInverseDynamics
#endif // MULTIBODYNAMEMAP_HPP_

View File

@@ -1,8 +1,9 @@
#include "MultiBodyTreeCreator.hpp"
namespace btInverseDynamics {
MultiBodyTree* CreateMultiBodyTree(const MultiBodyTreeCreator& creator) {
namespace btInverseDynamics
{
MultiBodyTree* CreateMultiBodyTree(const MultiBodyTreeCreator& creator)
{
int num_bodies;
int parent_index;
JointType joint_type;
@@ -16,7 +17,8 @@ MultiBodyTree* CreateMultiBodyTree(const MultiBodyTreeCreator& creator) {
void* user_ptr;
MultiBodyTree* tree = new MultiBodyTree();
if (0x0 == tree) {
if (0x0 == tree)
{
bt_id_error_message("cannot allocate tree\n");
return 0x0;
}
@@ -25,19 +27,22 @@ MultiBodyTree* CreateMultiBodyTree(const MultiBodyTreeCreator& creator) {
tree->setAcceptInvalidMassParameters(false);
// get number of bodies in the system
if (-1 == creator.getNumBodies(&num_bodies)) {
if (-1 == creator.getNumBodies(&num_bodies))
{
bt_id_error_message("getting body indices\n");
delete tree;
return 0x0;
}
// get data for all bodies
for (int index = 0; index < num_bodies; index++) {
for (int index = 0; index < num_bodies; index++)
{
// get body parameters from user callbacks
if (-1 ==
creator.getBody(index, &parent_index, &joint_type, &body_r_parent_body_ref,
&body_R_parent_ref, &body_axis_of_motion, &mass, &body_r_body_com,
&body_I_body, &user_int, &user_ptr)) {
&body_I_body, &user_int, &user_ptr))
{
bt_id_error_message("getting data for body %d\n", index);
delete tree;
return 0x0;
@@ -46,14 +51,16 @@ MultiBodyTree* CreateMultiBodyTree(const MultiBodyTreeCreator& creator) {
if (-1 ==
tree->addBody(index, parent_index, joint_type, body_r_parent_body_ref,
body_R_parent_ref, body_axis_of_motion, mass, body_r_body_com,
body_I_body, user_int, user_ptr)) {
body_I_body, user_int, user_ptr))
{
bt_id_error_message("adding body %d\n", index);
delete tree;
return 0x0;
}
}
// finalize initialization
if (-1 == tree->finalize()) {
if (-1 == tree->finalize())
{
bt_id_error_message("building system\n");
delete tree;
return 0x0;
@@ -61,4 +68,4 @@ MultiBodyTree* CreateMultiBodyTree(const MultiBodyTreeCreator& creator) {
return tree;
}
}
} // namespace btInverseDynamics

View File

@@ -8,12 +8,14 @@
#include "BulletInverseDynamics/MultiBodyTree.hpp"
#include "MultiBodyNameMap.hpp"
namespace btInverseDynamics {
namespace btInverseDynamics
{
/// Interface class for initializing a MultiBodyTree instance.
/// Data to be provided is modeled on the URDF specification.
/// The user can derive from this class in order to programmatically
/// initialize a system.
class MultiBodyTreeCreator {
class MultiBodyTreeCreator
{
public:
/// the dtor
virtual ~MultiBodyTreeCreator() {}
@@ -38,7 +40,7 @@ public:
/// @return A pointer to an allocated multibodytree instance, or
/// 0x0 if an error occured.
MultiBodyTree* CreateMultiBodyTree(const MultiBodyTreeCreator& creator);
}
} // namespace btInverseDynamics
// does urdf have gravity direction ??

View File

@@ -2,56 +2,69 @@
#include <cstdio>
namespace btInverseDynamics {
namespace btInverseDynamics
{
int writeGraphvizDotFile(const MultiBodyTree* tree, const MultiBodyNameMap* map,
const char* filename) {
if (0x0 == tree) {
const char* filename)
{
if (0x0 == tree)
{
bt_id_error_message("tree pointer is null\n");
return -1;
}
if (0x0 == filename) {
if (0x0 == filename)
{
bt_id_error_message("filename is null\n");
return -1;
}
FILE* fp = fopen(filename, "w");
if (NULL == fp) {
if (NULL == fp)
{
bt_id_error_message("cannot open file %s for writing\n", filename);
return -1;
}
fprintf(fp, "// to generate postscript file, run dot -Tps %s -o %s.ps\n"
fprintf(fp,
"// to generate postscript file, run dot -Tps %s -o %s.ps\n"
"// details see graphviz documentation at http://graphviz.org\n"
"digraph tree {\n",
filename, filename);
for (int body = 0; body < tree->numBodies(); body++) {
for (int body = 0; body < tree->numBodies(); body++)
{
std::string name;
if (0x0 != map) {
if (-1 == map->getBodyName(body, &name)) {
if (0x0 != map)
{
if (-1 == map->getBodyName(body, &name))
{
bt_id_error_message("can't get name of body %d\n", body);
return -1;
}
fprintf(fp, " %d [label=\"%d/%s\"];\n", body, body, name.c_str());
}
}
for (int body = 0; body < tree->numBodies(); body++) {
for (int body = 0; body < tree->numBodies(); body++)
{
int parent;
const char* joint_type;
int qi;
if (-1 == tree->getParentIndex(body, &parent)) {
if (-1 == tree->getParentIndex(body, &parent))
{
bt_id_error_message("indexing error\n");
return -1;
}
if (-1 == tree->getJointTypeStr(body, &joint_type)) {
if (-1 == tree->getJointTypeStr(body, &joint_type))
{
bt_id_error_message("indexing error\n");
return -1;
}
if (-1 == tree->getDoFOffset(body, &qi)) {
if (-1 == tree->getDoFOffset(body, &qi))
{
bt_id_error_message("indexing error\n");
return -1;
}
if (-1 != parent) {
if (-1 != parent)
{
fprintf(fp, " %d -> %d [label= \"type:%s, q=%d\"];\n", parent, body,
joint_type, qi);
}
@@ -61,4 +74,4 @@ int writeGraphvizDotFile(const MultiBodyTree* tree, const MultiBodyNameMap* map,
fclose(fp);
return 0;
}
}
} // namespace btInverseDynamics

View File

@@ -4,7 +4,8 @@
#include "BulletInverseDynamics/MultiBodyTree.hpp"
#include "MultiBodyNameMap.hpp"
namespace btInverseDynamics {
namespace btInverseDynamics
{
/// generate a dot-file of the multibody tree for generating a graph using graphviz' dot tool
/// @param tree the multibody tree
/// @param map to add names of links (if 0x0, no names will be added)
@@ -12,6 +13,6 @@ namespace btInverseDynamics {
/// @return 0 on success, -1 on error
int writeGraphvizDotFile(const MultiBodyTree* tree, const MultiBodyNameMap* map,
const char* filename);
}
} // namespace btInverseDynamics
#endif // MULTIBODYTREEDEBUGGRAPH_HPP

View File

@@ -4,13 +4,17 @@
#include "IDRandomUtil.hpp"
namespace btInverseDynamics {
RandomTreeCreator::RandomTreeCreator(const int max_bodies, bool random_seed) {
namespace btInverseDynamics
{
RandomTreeCreator::RandomTreeCreator(const int max_bodies, bool random_seed)
{
// seed generator
if(random_seed) {
if (random_seed)
{
randomInit(); // seeds with time()
} else {
}
else
{
randomInit(1); // seeds with 1
}
m_num_bodies = randomInt(1, max_bodies);
@@ -18,7 +22,8 @@ RandomTreeCreator::RandomTreeCreator(const int max_bodies, bool random_seed) {
RandomTreeCreator::~RandomTreeCreator() {}
int RandomTreeCreator::getNumBodies(int* num_bodies) const {
int RandomTreeCreator::getNumBodies(int* num_bodies) const
{
*num_bodies = m_num_bodies;
return 0;
}
@@ -26,14 +31,19 @@ int RandomTreeCreator::getNumBodies(int* num_bodies) const {
int RandomTreeCreator::getBody(const int body_index, int* parent_index, JointType* joint_type,
vec3* parent_r_parent_body_ref, mat33* body_T_parent_ref,
vec3* body_axis_of_motion, idScalar* mass, vec3* body_r_body_com,
mat33* body_I_body, int* user_int, void** user_ptr) const {
if(0 == body_index) { //root body
mat33* body_I_body, int* user_int, void** user_ptr) const
{
if (0 == body_index)
{ //root body
*parent_index = -1;
} else {
}
else
{
*parent_index = randomInt(0, body_index - 1);
}
switch (randomInt(0, 3)) {
switch (randomInt(0, 3))
{
case 0:
*joint_type = FIXED;
break;
@@ -78,4 +88,4 @@ int RandomTreeCreator::getBody(const int body_index, int* parent_index, JointTyp
return 0;
}
}
} // namespace btInverseDynamics

View File

@@ -4,11 +4,13 @@
#include "BulletInverseDynamics/IDConfig.hpp"
#include "MultiBodyTreeCreator.hpp"
namespace btInverseDynamics {
namespace btInverseDynamics
{
/// Generate a random MultiBodyTree with fixed or floating base and fixed, prismatic or revolute
/// joints
/// Uses a pseudo random number generator seeded from a random device.
class RandomTreeCreator : public MultiBodyTreeCreator {
class RandomTreeCreator : public MultiBodyTreeCreator
{
public:
/// ctor
/// @param max_bodies maximum number of bodies
@@ -27,5 +29,5 @@ public:
private:
int m_num_bodies;
};
}
} // namespace btInverseDynamics
#endif // RANDOMTREE_CREATOR_HPP_

View File

@@ -2,9 +2,11 @@
#include <cstdio>
namespace btInverseDynamics {
namespace btInverseDynamics
{
/// minimal "tree" (chain)
SimpleTreeCreator::SimpleTreeCreator(int dim) : m_num_bodies(dim) {
SimpleTreeCreator::SimpleTreeCreator(int dim) : m_num_bodies(dim)
{
m_mass = 1.0;
m_body_T_parent_ref(0, 0) = 1;
m_body_T_parent_ref(0, 1) = 0;
@@ -38,7 +40,8 @@ SimpleTreeCreator::SimpleTreeCreator(int dim) : m_num_bodies(dim) {
m_axis(1) = 0;
m_axis(2) = 1;
}
int SimpleTreeCreator::getNumBodies(int* num_bodies) const {
int SimpleTreeCreator::getNumBodies(int* num_bodies) const
{
*num_bodies = m_num_bodies;
return 0;
}
@@ -46,15 +49,20 @@ int SimpleTreeCreator::getNumBodies(int* num_bodies) const {
int SimpleTreeCreator::getBody(const int body_index, int* parent_index, JointType* joint_type,
vec3* parent_r_parent_body_ref, mat33* body_T_parent_ref,
vec3* body_axis_of_motion, idScalar* mass, vec3* body_r_body_com,
mat33* body_I_body, int* user_int, void** user_ptr) const {
mat33* body_I_body, int* user_int, void** user_ptr) const
{
*parent_index = body_index - 1;
if (body_index % 2) {
if (body_index % 2)
{
*joint_type = PRISMATIC;
} else {
}
else
{
*joint_type = REVOLUTE;
}
*parent_r_parent_body_ref = m_parent_r_parent_body_ref;
if (0 == body_index) {
if (0 == body_index)
{
(*parent_r_parent_body_ref)(2) = 1.0;
}
*body_T_parent_ref = m_body_T_parent_ref;
@@ -66,4 +74,4 @@ int SimpleTreeCreator::getBody(const int body_index, int* parent_index, JointTyp
*user_ptr = 0;
return 0;
}
}
} // namespace btInverseDynamics

View File

@@ -3,10 +3,11 @@
#include "MultiBodyTreeCreator.hpp"
namespace btInverseDynamics {
namespace btInverseDynamics
{
/// minimal "tree" (chain)
class SimpleTreeCreator : public MultiBodyTreeCreator {
class SimpleTreeCreator : public MultiBodyTreeCreator
{
public:
/// ctor
/// @param dim number of bodies
@@ -30,5 +31,5 @@ private:
mat33 m_body_I_body;
vec3 m_axis;
};
}
} // namespace btInverseDynamics
#endif // SIMPLETREECREATOR_HPP_

View File

@@ -1,14 +1,18 @@
#include "User2InternalIndex.hpp"
namespace btInverseDynamics {
namespace btInverseDynamics
{
User2InternalIndex::User2InternalIndex() : m_map_built(false) {}
void User2InternalIndex::addBody(const int body, const int parent) {
void User2InternalIndex::addBody(const int body, const int parent)
{
m_user_parent_index_map[body] = parent;
}
int User2InternalIndex::findRoot(int index) {
if (0 == m_user_parent_index_map.count(index)) {
int User2InternalIndex::findRoot(int index)
{
if (0 == m_user_parent_index_map.count(index))
{
return index;
}
return findRoot(m_user_parent_index_map[index]);
@@ -17,24 +21,32 @@ int User2InternalIndex::findRoot(int index) {
// modelled after URDF2Bullet.cpp:void ComputeParentIndices(const
// URDFImporterInterface& u2b, URDF2BulletCachedData& cache, int urdfLinkIndex,
// int urdfParentIndex)
void User2InternalIndex::recurseIndexSets(const int user_body_index) {
void User2InternalIndex::recurseIndexSets(const int user_body_index)
{
m_user_to_internal[user_body_index] = m_current_index;
m_current_index++;
for (size_t i = 0; i < m_user_child_indices[user_body_index].size(); i++) {
for (size_t i = 0; i < m_user_child_indices[user_body_index].size(); i++)
{
recurseIndexSets(m_user_child_indices[user_body_index][i]);
}
}
int User2InternalIndex::buildMapping() {
int User2InternalIndex::buildMapping()
{
// find root index
int user_root_index = -1;
for (std::map<int, int>::iterator it = m_user_parent_index_map.begin();
it != m_user_parent_index_map.end(); it++) {
it != m_user_parent_index_map.end(); it++)
{
int current_root_index = findRoot(it->second);
if (it == m_user_parent_index_map.begin()) {
if (it == m_user_parent_index_map.begin())
{
user_root_index = current_root_index;
} else {
if (user_root_index != current_root_index) {
}
else
{
if (user_root_index != current_root_index)
{
bt_id_error_message("multiple roots (at least) %d and %d\n", user_root_index,
current_root_index);
return -1;
@@ -44,7 +56,8 @@ int User2InternalIndex::buildMapping() {
// build child index map
for (std::map<int, int>::iterator it = m_user_parent_index_map.begin();
it != m_user_parent_index_map.end(); it++) {
it != m_user_parent_index_map.end(); it++)
{
m_user_child_indices[it->second].push_back(it->first);
}
@@ -55,7 +68,8 @@ int User2InternalIndex::buildMapping() {
// reverse mapping
for (std::map<int, int>::iterator it = m_user_to_internal.begin();
it != m_user_to_internal.end(); it++) {
it != m_user_to_internal.end(); it++)
{
m_internal_to_user[it->second] = it->first;
}
@@ -63,37 +77,45 @@ int User2InternalIndex::buildMapping() {
return 0;
}
int User2InternalIndex::user2internal(const int user, int *internal) const {
if (!m_map_built) {
int User2InternalIndex::user2internal(const int user, int *internal) const
{
if (!m_map_built)
{
return -1;
}
std::map<int, int>::const_iterator it;
it = m_user_to_internal.find(user);
if (it != m_user_to_internal.end()) {
if (it != m_user_to_internal.end())
{
*internal = it->second;
return 0;
} else {
}
else
{
bt_id_error_message("no user index %d\n", user);
return -1;
}
}
int User2InternalIndex::internal2user(const int internal, int *user) const {
if (!m_map_built) {
int User2InternalIndex::internal2user(const int internal, int *user) const
{
if (!m_map_built)
{
return -1;
}
std::map<int, int>::const_iterator it;
it = m_internal_to_user.find(internal);
if (it != m_internal_to_user.end()) {
if (it != m_internal_to_user.end())
{
*user = it->second;
return 0;
} else {
}
else
{
bt_id_error_message("no internal index %d\n", internal);
return -1;
}
}
}
} // namespace btInverseDynamics

View File

@@ -5,11 +5,12 @@
#include "BulletInverseDynamics/IDConfig.hpp"
namespace btInverseDynamics {
namespace btInverseDynamics
{
/// Convert arbitrary indexing scheme to internal indexing
/// used for MultiBodyTree
class User2InternalIndex {
class User2InternalIndex
{
public:
/// Ctor
User2InternalIndex();
@@ -41,6 +42,6 @@ private:
std::map<int, std::vector<int> > m_user_child_indices;
int m_current_index;
};
}
} // namespace btInverseDynamics
#endif // USER2INTERNALINDEX_HPP

View File

@@ -14,14 +14,16 @@
/// Create a btMultiBody model from URDF.
/// This is adapted from Bullet URDF loader example
class MyBtMultiBodyFromURDF {
class MyBtMultiBodyFromURDF
{
public:
/// ctor
/// @param gravity gravitational acceleration (in world frame)
/// @param base_fixed if true, the root body is treated as fixed,
/// if false, it is treated as floating
MyBtMultiBodyFromURDF(const btVector3 &gravity, const bool base_fixed)
: m_gravity(gravity), m_base_fixed(base_fixed) {
: m_gravity(gravity), m_base_fixed(base_fixed)
{
m_broadphase = 0x0;
m_dispatcher = 0x0;
m_solver = 0x0;
@@ -30,7 +32,8 @@ public:
m_multibody = 0x0;
}
/// dtor
~MyBtMultiBodyFromURDF() {
~MyBtMultiBodyFromURDF()
{
delete m_dynamicsWorld;
delete m_solver;
delete m_broadphase;
@@ -41,14 +44,16 @@ public:
/// @param name path to urdf file
void setFileName(const std::string name) { m_filename = name; }
/// load urdf file and build btMultiBody model
void init() {
void init()
{
this->createEmptyDynamicsWorld();
m_dynamicsWorld->setGravity(m_gravity);
BulletURDFImporter urdf_importer(&m_nogfx, 0, 1, 0);
URDFImporterInterface &u2b(urdf_importer);
bool loadOk = u2b.loadURDF(m_filename.c_str(), m_base_fixed);
if (loadOk) {
if (loadOk)
{
btTransform identityTrans;
identityTrans.setIdentity();
MyMultiBodyCreator creation(&m_nogfx);
@@ -64,7 +69,8 @@ public:
private:
// internal utility function
void createEmptyDynamicsWorld() {
void createEmptyDynamicsWorld()
{
m_collisionConfiguration = new btDefaultCollisionConfiguration();
/// use the default collision dispatcher. For parallel processing you can use a diffent

View File

@@ -1,11 +1,13 @@
#include "btMultiBodyTreeCreator.hpp"
namespace btInverseDynamics {
namespace btInverseDynamics
{
btMultiBodyTreeCreator::btMultiBodyTreeCreator() : m_initialized(false) {}
int btMultiBodyTreeCreator::createFromBtMultiBody(const btMultiBody *btmb, const bool verbose) {
if (0x0 == btmb) {
int btMultiBodyTreeCreator::createFromBtMultiBody(const btMultiBody *btmb, const bool verbose)
{
if (0x0 == btmb)
{
bt_id_error_message("cannot create MultiBodyTree from null pointer\n");
return -1;
}
@@ -22,9 +24,12 @@ int btMultiBodyTreeCreator::createFromBtMultiBody(const btMultiBody *btmb, const
LinkData &link = m_data[0];
link.parent_index = -1;
if (btmb->hasFixedBase()) {
if (btmb->hasFixedBase())
{
link.joint_type = FIXED;
} else {
}
else
{
link.joint_type = FLOATING;
}
btTransform transform = (btmb->getBaseWorldTransform());
@@ -70,8 +75,10 @@ int btMultiBodyTreeCreator::createFromBtMultiBody(const btMultiBody *btmb, const
// shift reference point to link origin (in joint axis)
mat33 tilde_r_com = tildeOperator(link.body_r_body_com);
link.body_I_body = link.body_I_body - link.mass * tilde_r_com * tilde_r_com;
if (verbose) {
id_printf("base: mass= %f, bt_inertia= [%f %f %f]\n"
if (verbose)
{
id_printf(
"base: mass= %f, bt_inertia= [%f %f %f]\n"
"Io= [%f %f %f;\n"
" %f %f %f;\n"
" %f %f %f]\n",
@@ -83,8 +90,10 @@ int btMultiBodyTreeCreator::createFromBtMultiBody(const btMultiBody *btmb, const
}
}
for (int bt_index = 0; bt_index < btmb->getNumLinks(); bt_index++) {
if (verbose) {
for (int bt_index = 0; bt_index < btmb->getNumLinks(); bt_index++)
{
if (verbose)
{
id_printf("bt->id: converting link %d\n", bt_index);
}
const btMultibodyLink &bt_link = btmb->getLink(bt_index);
@@ -93,14 +102,16 @@ int btMultiBodyTreeCreator::createFromBtMultiBody(const btMultiBody *btmb, const
link.parent_index = bt_link.m_parent + 1;
link.mass = bt_link.m_mass;
if (verbose) {
if (verbose)
{
id_printf("mass= %f\n", link.mass);
}
// from this body's pivot to this body's com in this body's frame
link.body_r_body_com[0] = bt_link.m_dVector[0];
link.body_r_body_com[1] = bt_link.m_dVector[1];
link.body_r_body_com[2] = bt_link.m_dVector[2];
if (verbose) {
if (verbose)
{
id_printf("com= %f %f %f\n", link.body_r_body_com[0], link.body_r_body_com[1],
link.body_r_body_com[2]);
}
@@ -118,8 +129,10 @@ int btMultiBodyTreeCreator::createFromBtMultiBody(const btMultiBody *btmb, const
mat33 tilde_r_com = tildeOperator(link.body_r_body_com);
link.body_I_body = link.body_I_body - link.mass * tilde_r_com * tilde_r_com;
if (verbose) {
id_printf("link %d: mass= %f, bt_inertia= [%f %f %f]\n"
if (verbose)
{
id_printf(
"link %d: mass= %f, bt_inertia= [%f %f %f]\n"
"Io= [%f %f %f;\n"
" %f %f %f;\n"
" %f %f %f]\n",
@@ -140,17 +153,21 @@ int btMultiBodyTreeCreator::createFromBtMultiBody(const btMultiBody *btmb, const
link.body_T_parent_ref(2, 0) = basis[2][0];
link.body_T_parent_ref(2, 1) = basis[2][1];
link.body_T_parent_ref(2, 2) = basis[2][2];
if (verbose) {
id_printf("body_T_parent_ref= %f %f %f\n"
if (verbose)
{
id_printf(
"body_T_parent_ref= %f %f %f\n"
" %f %f %f\n"
" %f %f %f\n",
basis[0][0], basis[0][1], basis[0][2], basis[1][0], basis[1][1], basis[1][2],
basis[2][0], basis[2][1], basis[2][2]);
}
switch (bt_link.m_jointType) {
switch (bt_link.m_jointType)
{
case btMultibodyLink::eRevolute:
link.joint_type = REVOLUTE;
if (verbose) {
if (verbose)
{
id_printf("type= revolute\n");
}
link.body_axis_of_motion(0) = bt_link.m_axes[0].m_topVec[0];
@@ -166,7 +183,8 @@ int btMultiBodyTreeCreator::createFromBtMultiBody(const btMultiBody *btmb, const
break;
case btMultibodyLink::ePrismatic:
link.joint_type = PRISMATIC;
if (verbose) {
if (verbose)
{
id_printf("type= prismatic\n");
}
link.body_axis_of_motion(0) = bt_link.m_axes[0].m_bottomVec[0];
@@ -207,18 +225,22 @@ int btMultiBodyTreeCreator::createFromBtMultiBody(const btMultiBody *btmb, const
bt_link.m_jointType);
return -1;
}
if (link.parent_index > 0) { // parent body isn't the root
if (link.parent_index > 0)
{ // parent body isn't the root
const btMultibodyLink &bt_parent_link = btmb->getLink(link.parent_index - 1);
// from parent pivot to parent com, in parent frame
link.parent_r_parent_body_ref(0) += bt_parent_link.m_dVector[0];
link.parent_r_parent_body_ref(1) += bt_parent_link.m_dVector[1];
link.parent_r_parent_body_ref(2) += bt_parent_link.m_dVector[2];
} else {
}
else
{
// parent is root body. btMultiBody only knows 6-DoF or 0-DoF root bodies,
// whose link frame is in the CoM (ie, no notion of a pivot point)
}
if (verbose) {
if (verbose)
{
id_printf("parent_r_parent_body_ref= %f %f %f\n", link.parent_r_parent_body_ref[0],
link.parent_r_parent_body_ref[1], link.parent_r_parent_body_ref[2]);
}
@@ -229,8 +251,10 @@ int btMultiBodyTreeCreator::createFromBtMultiBody(const btMultiBody *btmb, const
return 0;
}
int btMultiBodyTreeCreator::getNumBodies(int *num_bodies) const {
if (false == m_initialized) {
int btMultiBodyTreeCreator::getNumBodies(int *num_bodies) const
{
if (false == m_initialized)
{
bt_id_error_message("btMultiBody not converted yet\n");
return -1;
}
@@ -243,13 +267,16 @@ int btMultiBodyTreeCreator::getBody(const int body_index, int *parent_index, Joi
vec3 *parent_r_parent_body_ref, mat33 *body_T_parent_ref,
vec3 *body_axis_of_motion, idScalar *mass,
vec3 *body_r_body_com, mat33 *body_I_body, int *user_int,
void **user_ptr) const {
if (false == m_initialized) {
void **user_ptr) const
{
if (false == m_initialized)
{
bt_id_error_message("MultiBodyTree not created yet\n");
return -1;
}
if (body_index < 0 || body_index >= static_cast<int>(m_data.size())) {
if (body_index < 0 || body_index >= static_cast<int>(m_data.size()))
{
bt_id_error_message("index out of range (got %d but only %zu bodies)\n", body_index,
m_data.size());
return -1;
@@ -269,4 +296,4 @@ int btMultiBodyTreeCreator::getBody(const int body_index, int *parent_index, Joi
return 0;
}
}
} // namespace btInverseDynamics

View File

@@ -7,11 +7,12 @@
#include "MultiBodyTreeCreator.hpp"
#include "BulletDynamics/Featherstone/btMultiBody.h"
namespace btInverseDynamics {
namespace btInverseDynamics
{
/// MultiBodyTreeCreator implementation for converting
/// a btMultiBody forward dynamics model into a MultiBodyTree inverse dynamics model
class btMultiBodyTreeCreator : public MultiBodyTreeCreator {
class btMultiBodyTreeCreator : public MultiBodyTreeCreator
{
public:
/// ctor
btMultiBodyTreeCreator();
@@ -32,7 +33,8 @@ public:
private:
// internal struct holding data extracted from btMultiBody
struct LinkData {
struct LinkData
{
int parent_index;
JointType joint_type;
vec3 parent_r_parent_body_ref;
@@ -45,6 +47,6 @@ private:
idArray<LinkData>::type m_data;
bool m_initialized;
};
}
} // namespace btInverseDynamics
#endif // BTMULTIBODYTREECREATOR_HPP_

View File

@@ -8,20 +8,25 @@
#include "BulletDynamics/Featherstone/btMultiBodyLinkCollider.h"
#include "BulletDynamics/Featherstone/btMultiBodyPoint2Point.h"
namespace btInverseDynamics {
namespace btInverseDynamics
{
int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &gravity, bool verbose,
btMultiBody *btmb, MultiBodyTree *id_tree, double *pos_error,
double *acc_error) {
double *acc_error)
{
// call function and return -1 if it does, printing an bt_id_error_message
#define RETURN_ON_FAILURE(x) \
do { \
if (-1 == x) { \
do \
{ \
if (-1 == x) \
{ \
bt_id_error_message("calling " #x "\n"); \
return -1; \
} \
} while (0)
if (verbose) {
if (verbose)
{
printf("\n ===================================== \n");
}
vecx joint_forces(q.size());
@@ -50,37 +55,47 @@ int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &g
// remaining links
int q_index;
if (btmb->hasFixedBase()) {
if (btmb->hasFixedBase())
{
q_index = 0;
} else {
}
else
{
q_index = 6;
}
if (verbose) {
if (verbose)
{
printf("bt:num_links= %d, num_dofs= %d\n", btmb->getNumLinks(), btmb->getNumDofs());
}
for (int l = 0; l < btmb->getNumLinks(); l++) {
for (int l = 0; l < btmb->getNumLinks(); l++)
{
const btMultibodyLink &link = btmb->getLink(l);
if (verbose) {
if (verbose)
{
printf("link %d, pos_var_count= %d, dof_count= %d\n", l, link.m_posVarCount,
link.m_dofCount);
}
if (link.m_posVarCount == 1) {
if (link.m_posVarCount == 1)
{
btmb->setJointPosMultiDof(l, &q(q_index));
btmb->setJointVelMultiDof(l, &u(q_index));
if (verbose) {
if (verbose)
{
printf("set q[%d]= %f, u[%d]= %f\n", q_index, q(q_index), q_index, u(q_index));
}
q_index++;
}
}
// sanity check
if (q_index != q.size()) {
if (q_index != q.size())
{
bt_id_error_message("error in number of dofs for btMultibody and MultiBodyTree\n");
return -1;
}
// run inverse dynamics to determine joint_forces for given q, u, dot_u
if (-1 == id_tree->calculateInverseDynamics(q, u, dot_u, &joint_forces)) {
if (-1 == id_tree->calculateInverseDynamics(q, u, dot_u, &joint_forces))
{
bt_id_error_message("calculating inverse dynamics\n");
return -1;
}
@@ -95,9 +110,11 @@ int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &g
// apply gravity forces for btMultiBody model. Must be done manually.
btmb->addBaseForce(btmb->getBaseMass() * gravity);
for (int link = 0; link < btmb->getNumLinks(); link++) {
for (int link = 0; link < btmb->getNumLinks(); link++)
{
btmb->addLinkForce(link, gravity * btmb->getLinkMass(link));
if (verbose) {
if (verbose)
{
printf("link %d, applying gravity %f %f %f\n", link,
gravity[0] * btmb->getLinkMass(link), gravity[1] * btmb->getLinkMass(link),
gravity[2] * btmb->getLinkMass(link));
@@ -105,9 +122,12 @@ int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &g
}
// apply generalized forces
if (btmb->hasFixedBase()) {
if (btmb->hasFixedBase())
{
q_index = 0;
} else {
}
else
{
vec3 base_force;
base_force(0) = joint_forces(3);
base_force(1) = joint_forces(4);
@@ -120,7 +140,8 @@ int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &g
btmb->addBaseForce(world_T_base * base_force);
btmb->addBaseTorque(world_T_base * base_moment);
if (verbose) {
if (verbose)
{
printf("base force from id: %f %f %f\n", joint_forces(3), joint_forces(4),
joint_forces(5));
printf("base moment from id: %f %f %f\n", joint_forces(0), joint_forces(1),
@@ -129,10 +150,13 @@ int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &g
q_index = 6;
}
for (int l = 0; l < btmb->getNumLinks(); l++) {
for (int l = 0; l < btmb->getNumLinks(); l++)
{
const btMultibodyLink &link = btmb->getLink(l);
if (link.m_posVarCount == 1) {
if (verbose) {
if (link.m_posVarCount == 1)
{
if (verbose)
{
printf("id:joint_force[%d]= %f, applied to link %d\n", q_index,
joint_forces(q_index), l);
}
@@ -142,7 +166,8 @@ int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &g
}
// sanity check
if (q_index != q.size()) {
if (q_index != q.size())
{
bt_id_error_message("error in number of dofs for btMultibody and MultiBodyTree\n");
return -1;
}
@@ -160,21 +185,29 @@ int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &g
btScalar *joint_accel = base_accel + 6;
*acc_error = 0;
int dot_u_offset = 0;
if (btmb->hasFixedBase()) {
if (btmb->hasFixedBase())
{
dot_u_offset = 0;
} else {
}
else
{
dot_u_offset = 6;
}
if (true == btmb->hasFixedBase()) {
for (int i = 0; i < btmb->getNumDofs(); i++) {
if (verbose) {
if (true == btmb->hasFixedBase())
{
for (int i = 0; i < btmb->getNumDofs(); i++)
{
if (verbose)
{
printf("bt:ddot_q[%d]= %f, id:ddot_q= %e, diff= %e\n", i, joint_accel[i],
dot_u(i + dot_u_offset), joint_accel[i] - dot_u(i));
}
*acc_error += BT_ID_POW(joint_accel[i] - dot_u(i + dot_u_offset), 2);
}
} else {
}
else
{
vec3 base_dot_omega;
vec3 world_dot_omega;
world_dot_omega(0) = base_accel[0];
@@ -191,23 +224,29 @@ int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &g
world_ddot_com(2) = base_accel[5];
base_ddot_com = world_T_base.transpose() * world_ddot_com;
for (int i = 0; i < 3; i++) {
if (verbose) {
for (int i = 0; i < 3; i++)
{
if (verbose)
{
printf("bt::base_dot_omega(%d)= %e dot_u[%d]= %e, diff= %e\n", i, base_dot_omega(i),
i, dot_u[i], base_dot_omega(i) - dot_u[i]);
}
*acc_error += BT_ID_POW(base_dot_omega(i) - dot_u(i), 2);
}
for (int i = 0; i < 3; i++) {
if (verbose) {
for (int i = 0; i < 3; i++)
{
if (verbose)
{
printf("bt::base_ddot_com(%d)= %e dot_u[%d]= %e, diff= %e\n", i, base_ddot_com(i),
i, dot_u[i + 3], base_ddot_com(i) - dot_u[i + 3]);
}
*acc_error += BT_ID_POW(base_ddot_com(i) - dot_u(i + 3), 2);
}
for (int i = 0; i < btmb->getNumDofs(); i++) {
if (verbose) {
for (int i = 0; i < btmb->getNumDofs(); i++)
{
if (verbose)
{
printf("bt:ddot_q[%d]= %f, id:ddot_q= %e, diff= %e\n", i, joint_accel[i],
dot_u(i + 6), joint_accel[i] - dot_u(i + 6));
}
@@ -215,26 +254,31 @@ int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &g
}
}
*acc_error = std::sqrt(*acc_error);
if (verbose) {
if (verbose)
{
printf("======dynamics-err: %e\n", *acc_error);
}
*pos_error = 0.0;
{
mat33 world_T_body;
if (-1 == id_tree->getBodyTransform(0, &world_T_body)) {
if (-1 == id_tree->getBodyTransform(0, &world_T_body))
{
bt_id_error_message("getting transform for body %d\n", 0);
return -1;
}
vec3 world_com;
if (-1 == id_tree->getBodyCoM(0, &world_com)) {
if (-1 == id_tree->getBodyCoM(0, &world_com))
{
bt_id_error_message("getting com for body %d\n", 0);
return -1;
}
if (verbose) {
if (verbose)
{
printf("id:com: %f %f %f\n", world_com(0), world_com(1), world_com(2));
printf("id:transform: %f %f %f\n"
printf(
"id:transform: %f %f %f\n"
" %f %f %f\n"
" %f %f %f\n",
world_T_body(0, 0), world_T_body(0, 1), world_T_body(0, 2), world_T_body(1, 0),
@@ -243,15 +287,18 @@ int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &g
}
}
for (int l = 0; l < btmb->getNumLinks(); l++) {
for (int l = 0; l < btmb->getNumLinks(); l++)
{
const btMultibodyLink &bt_link = btmb->getLink(l);
vec3 bt_origin = bt_link.m_cachedWorldTransform.getOrigin();
mat33 bt_basis = bt_link.m_cachedWorldTransform.getBasis();
if (verbose) {
if (verbose)
{
printf("------------- link %d\n", l + 1);
printf("bt:com: %f %f %f\n", bt_origin(0), bt_origin(1), bt_origin(2));
printf("bt:transform: %f %f %f\n"
printf(
"bt:transform: %f %f %f\n"
" %f %f %f\n"
" %f %f %f\n",
bt_basis(0, 0), bt_basis(0, 1), bt_basis(0, 2), bt_basis(1, 0), bt_basis(1, 1),
@@ -260,18 +307,22 @@ int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &g
mat33 id_world_T_body;
vec3 id_world_com;
if (-1 == id_tree->getBodyTransform(l + 1, &id_world_T_body)) {
if (-1 == id_tree->getBodyTransform(l + 1, &id_world_T_body))
{
bt_id_error_message("getting transform for body %d\n", l);
return -1;
}
if (-1 == id_tree->getBodyCoM(l + 1, &id_world_com)) {
if (-1 == id_tree->getBodyCoM(l + 1, &id_world_com))
{
bt_id_error_message("getting com for body %d\n", l);
return -1;
}
if (verbose) {
if (verbose)
{
printf("id:com: %f %f %f\n", id_world_com(0), id_world_com(1), id_world_com(2));
printf("id:transform: %f %f %f\n"
printf(
"id:transform: %f %f %f\n"
" %f %f %f\n"
" %f %f %f\n",
id_world_T_body(0, 0), id_world_T_body(0, 1), id_world_T_body(0, 2),
@@ -280,7 +331,8 @@ int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &g
}
vec3 diff_com = bt_origin - id_world_com;
mat33 diff_basis = bt_basis - id_world_T_body;
if (verbose) {
if (verbose)
{
printf("diff-com: %e %e %e\n", diff_com(0), diff_com(1), diff_com(2));
printf("diff-transform: %e %e %e %e %e %e %e %e %e\n", diff_basis(0, 0),
@@ -294,14 +346,16 @@ int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &g
BT_ID_POW(diff_basis(1, 0), 2) + BT_ID_POW(diff_basis(1, 1), 2) +
BT_ID_POW(diff_basis(1, 2), 2) + BT_ID_POW(diff_basis(2, 0), 2) +
BT_ID_POW(diff_basis(2, 1), 2) + BT_ID_POW(diff_basis(2, 2), 2));
if (verbose) {
if (verbose)
{
printf("======kin-pos-err: %e\n", total_pos_err);
}
if (total_pos_err > *pos_error) {
if (total_pos_err > *pos_error)
{
*pos_error = total_pos_err;
}
}
return 0;
}
}
} // namespace btInverseDynamics

View File

@@ -6,7 +6,8 @@
class btMultiBody;
class btVector3;
namespace btInverseDynamics {
namespace btInverseDynamics
{
class MultiBodyTree;
/// this function compares the forward dynamics computations implemented in btMultiBody to
@@ -31,5 +32,5 @@ class MultiBodyTree;
int compareInverseAndForwardDynamics(vecx &q, vecx &u, vecx &dot_u, btVector3 &gravity, bool verbose,
btMultiBody *btmb, MultiBodyTree *id_tree, double *pos_error,
double *acc_error);
}
} // namespace btInverseDynamics
#endif // INVDYN_BULLET_COMPARISON_HPP

View File

@@ -27,7 +27,6 @@ extern int DNAlen;
extern unsigned char DNAstr64[];
extern int DNAlen64;
using namespace bParse;
bBlenderFile::bBlenderFile(const char *fileName)
@@ -36,8 +35,6 @@ bBlenderFile::bBlenderFile(const char* fileName)
mMain = new bMain(this, fileName, mVersion);
}
bBlenderFile::bBlenderFile(char *memoryBuffer, int len)
: bFile(memoryBuffer, len, "BLENDER"),
mMain(0)
@@ -45,13 +42,11 @@ mMain(0)
mMain = new bMain(this, "memoryBuf", mVersion);
}
bBlenderFile::~bBlenderFile()
{
delete mMain;
}
bMain *bBlenderFile::getMain()
{
return mMain;
@@ -66,14 +61,11 @@ void bBlenderFile::parseData()
const bool swap = (mFlags & FD_ENDIAN_SWAP) != 0;
char *dataPtr = mFileBuffer + mDataStart;
bChunkInd dataChunk;
dataChunk.code = 0;
//dataPtr += ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags);
int seek = getNextBlock(&dataChunk, dataPtr, mFlags);
//dataPtr += ChunkUtils::getOffset(mFlags);
@@ -81,10 +73,6 @@ void bBlenderFile::parseData()
while (dataChunk.code != DNA1)
{
// one behind
if (dataChunk.code == SDNA) break;
//if (dataChunk.code == DNA1) break;
@@ -118,7 +106,6 @@ void bBlenderFile::parseData()
if (seek < 0)
break;
}
}
void bBlenderFile::addDataBlock(char *dataBlock)
@@ -126,10 +113,6 @@ void bBlenderFile::addDataBlock(char* dataBlock)
mMain->addDatablock(dataBlock);
}
// 32 && 64 bit versions
extern unsigned char DNAstr[];
extern int DNAlen;
@@ -137,14 +120,11 @@ extern int DNAlen;
//unsigned char DNAstr[]={0};
//int DNAlen=0;
extern unsigned char DNAstr64[];
extern int DNAlen64;
void bBlenderFile::writeDNA(FILE *fp)
{
bChunkInd dataChunk;
dataChunk.code = DNA1;
dataChunk.dna_nr = 0;
@@ -192,14 +172,16 @@ int bBlenderFile::write(const char* fileName, bool fixupPointers)
if (endian)
{
header[7] = '_';
} else
}
else
{
header[7] = '-';
}
if (VOID_IS_8)
{
header[8] = 'V';
} else
}
else
{
header[8] = 'v';
}
@@ -215,8 +197,8 @@ int bBlenderFile::write(const char* fileName, bool fixupPointers)
writeDNA(fp);
fclose(fp);
} else
}
else
{
printf("Error: cannot open file %s for writing\n", fileName);
return 0;

View File

@@ -16,23 +16,19 @@ subject to the following restrictions:
#ifndef B_BLENDER_FILE_H
#define B_BLENDER_FILE_H
#include "bFile.h"
namespace bParse {
namespace bParse
{
// ----------------------------------------------------- //
class bBlenderFile : public bFile
{
protected:
bMain* mMain;
bStructHandle* m_glob;
public:
bBlenderFile(const char* fileName);
bBlenderFile(char* memoryBuffer, int len);
@@ -56,8 +52,7 @@ namespace bParse {
virtual void parseData();
virtual void writeDNA(FILE* fp);
};
};
}; // namespace bParse
#endif //B_BLENDER_FILE_H

View File

@@ -21,7 +21,6 @@ subject to the following restrictions:
using namespace bParse;
// ----------------------------------------------------- //
bMain::bMain(bBlenderFile *filePtr, const char *baseName, int fileVersion)
: mFP(filePtr),
@@ -56,7 +55,6 @@ bMain::bMain(bBlenderFile *filePtr, const char *baseName, int fileVersion)
mData.insert(ID_SCRIPT, bListBasePtr());
}
// ----------------------------------------------------- //
bMain::~bMain()
{
@@ -88,13 +86,9 @@ void bMain::addDatablock(void *allocated)
mPool.push_back((bStructHandle *)allocated);
}
// ------------------------------------------------------------//
void bMain::linkList(void *listBasePtr)
{
struct ListBase // local Blender::ListBase
{
void *first;
@@ -107,7 +101,6 @@ void bMain::linkList(void *listBasePtr)
void *prev;
};
ListBase *base = (ListBase *)listBasePtr;
if (!base || !base->first)
@@ -143,12 +136,10 @@ bListBasePtr* bMain::getListBasePtr(int listBaseCode)
// ------------------------------------------------------------//
bListBasePtr *bMain::_findCode(int code)
{
bListBasePtr *lbPtr = mData.find(code);
return lbPtr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getScene()
{
@@ -193,8 +184,6 @@ bListBasePtr *bMain::getCurve()
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getMball()
{
@@ -222,7 +211,6 @@ bListBasePtr *bMain::getTex()
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getImage()
{
@@ -295,7 +283,6 @@ bListBasePtr *bMain::getWorld()
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getScreen()
{
@@ -368,7 +355,6 @@ bListBasePtr *bMain::getAction()
return ptr;
}
// ------------------------------------------------------------//
bListBasePtr *bMain::getNodetree()
{
@@ -387,6 +373,4 @@ bListBasePtr *bMain::getBrush()
return ptr;
}
//eof

View File

@@ -20,25 +20,19 @@ subject to the following restrictions:
#include "bChunk.h"
#include "LinearMath/btHashMap.h"
namespace bParse
{
class bDNA;
class bBlenderFile;
};
namespace bParse {
}; // namespace bParse
namespace bParse
{
// ----------------------------------------------------- //
typedef btHashMap<btHashInt, bListBasePtr> bMainDataMap;
// ----------------------------------------------------- //
class bMain
{
@@ -52,9 +46,6 @@ namespace bParse {
bMainDataMap mData;
bListBasePtr *_findCode(int code);
public:
@@ -66,7 +57,6 @@ namespace bParse {
bListBasePtr *getListBasePtr(int listBaseCode);
bListBasePtr *getScene();
bListBasePtr *getLibrary();
bListBasePtr *getObject();
@@ -94,17 +84,13 @@ namespace bParse {
bListBasePtr *getNodetree();
bListBasePtr *getBrush();
// tracking allocated memory
void addDatablock(void *allocated);
// --
void linkList(void *listBasePtr);
};
}
} // namespace bParse
#endif //__BMAIN_H__

View File

@@ -1406,6 +1406,5 @@ unsigned char DNAstr64[]= {
0, 20, 0, 98, 1, 5, 0, 98, 1, 0, 0, 98, 1, 1, 0, 12, 0, 111, 9, 4, 0, 112, 9, 4, 0, 20, 0, 99, 1, 9, 0, 99,
1, 0, 0, 99, 1, 1, 0, 12, 0, -128, 0, 98, 1, 113, 9, 4, 0, 20, 0, 2, 0, 110, 9, 2, 0, 114, 9, 7, 0, 94, 0, 0,
0, 115, 9, -70, 0, 5, 0, 12, 0, 125, 4, 4, 0, 20, 0, 2, 0, 116, 9, 2, 0, 117, 9, 9, 0, 118, 9, 69, 78, 68, 66, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int DNAlen64 = sizeof(DNAstr64);

View File

@@ -1406,6 +1406,5 @@ unsigned char DNAstr[]= {
0, 20, 0, 98, 1, 5, 0, 98, 1, 0, 0, 98, 1, 1, 0, 12, 0, 111, 9, 4, 0, 112, 9, 4, 0, 20, 0, 99, 1, 9, 0, 99,
1, 0, 0, 99, 1, 1, 0, 12, 0, -128, 0, 98, 1, 113, 9, 4, 0, 20, 0, 2, 0, 110, 9, 2, 0, 114, 9, 7, 0, 94, 0, 0,
0, 115, 9, -70, 0, 5, 0, 12, 0, 125, 4, 4, 0, 20, 0, 2, 0, 116, 9, 2, 0, 117, 9, 9, 0, 118, 9, 69, 78, 68, 66, 0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int DNAlen = sizeof(DNAstr);

View File

@@ -19,10 +19,11 @@
// Auto generated from Bullet/Extras/HeaderGenerator/bulletGenerate.py
#ifndef __BULLET_H__
#define __BULLET_H__
namespace Bullet {
namespace Bullet
{
// put an empty struct in the case
typedef struct bInvalidHandle {
typedef struct bInvalidHandle
{
int unused;
} bInvalidHandle;
@@ -123,7 +124,6 @@ typedef struct bInvalidHandle {
void *m_data;
};
// -------------------------------------------------- //
class btPhysicsSystem
{
@@ -133,7 +133,6 @@ typedef struct bInvalidHandle {
PointerArray m_constraints;
};
// -------------------------------------------------- //
class ListBase
{
@@ -142,7 +141,6 @@ typedef struct bInvalidHandle {
void *last;
};
// -------------------------------------------------- //
class btVector3FloatData
{
@@ -150,7 +148,6 @@ typedef struct bInvalidHandle {
float m_floats[4];
};
// -------------------------------------------------- //
class btVector3DoubleData
{
@@ -158,7 +155,6 @@ typedef struct bInvalidHandle {
double m_floats[4];
};
// -------------------------------------------------- //
class btQuaternionFloatData
{
@@ -166,7 +162,6 @@ typedef struct bInvalidHandle {
float m_floats[4];
};
// -------------------------------------------------- //
class btQuaternionDoubleData
{
@@ -174,7 +169,6 @@ typedef struct bInvalidHandle {
double m_floats[4];
};
// -------------------------------------------------- //
class btMatrix3x3FloatData
{
@@ -182,7 +176,6 @@ typedef struct bInvalidHandle {
btVector3FloatData m_el[3];
};
// -------------------------------------------------- //
class btMatrix3x3DoubleData
{
@@ -190,7 +183,6 @@ typedef struct bInvalidHandle {
btVector3DoubleData m_el[3];
};
// -------------------------------------------------- //
class btTransformFloatData
{
@@ -199,7 +191,6 @@ typedef struct bInvalidHandle {
btVector3FloatData m_origin;
};
// -------------------------------------------------- //
class btTransformDoubleData
{
@@ -208,7 +199,6 @@ typedef struct bInvalidHandle {
btVector3DoubleData m_origin;
};
// -------------------------------------------------- //
class btBvhSubtreeInfoData
{
@@ -219,7 +209,6 @@ typedef struct bInvalidHandle {
short m_quantizedAabbMax[3];
};
// -------------------------------------------------- //
class btOptimizedBvhNodeFloatData
{
@@ -232,7 +221,6 @@ typedef struct bInvalidHandle {
char m_pad[4];
};
// -------------------------------------------------- //
class btOptimizedBvhNodeDoubleData
{
@@ -245,7 +233,6 @@ typedef struct bInvalidHandle {
char m_pad[4];
};
// -------------------------------------------------- //
class btQuantizedBvhNodeData
{
@@ -255,7 +242,6 @@ typedef struct bInvalidHandle {
int m_escapeIndexOrTriangleIndex;
};
// -------------------------------------------------- //
class btQuantizedBvhFloatData
{
@@ -274,7 +260,6 @@ typedef struct bInvalidHandle {
int m_numSubtreeHeaders;
};
// -------------------------------------------------- //
class btQuantizedBvhDoubleData
{
@@ -293,7 +278,6 @@ typedef struct bInvalidHandle {
btBvhSubtreeInfoData *m_subTreeInfoPtr;
};
// -------------------------------------------------- //
class btCollisionShapeData
{
@@ -303,7 +287,6 @@ typedef struct bInvalidHandle {
char m_padding[4];
};
// -------------------------------------------------- //
class btStaticPlaneShapeData
{
@@ -315,7 +298,6 @@ typedef struct bInvalidHandle {
char m_pad[4];
};
// -------------------------------------------------- //
class btConvexInternalShapeData
{
@@ -327,7 +309,6 @@ typedef struct bInvalidHandle {
int m_padding;
};
// -------------------------------------------------- //
class btPositionAndRadius
{
@@ -336,7 +317,6 @@ typedef struct bInvalidHandle {
float m_radius;
};
// -------------------------------------------------- //
class btMultiSphereShapeData
{
@@ -347,7 +327,6 @@ typedef struct bInvalidHandle {
char m_padding[4];
};
// -------------------------------------------------- //
class btIntIndexData
{
@@ -355,7 +334,6 @@ typedef struct bInvalidHandle {
int m_value;
};
// -------------------------------------------------- //
class btShortIntIndexData
{
@@ -364,7 +342,6 @@ typedef struct bInvalidHandle {
char m_pad[2];
};
// -------------------------------------------------- //
class btShortIntIndexTripletData
{
@@ -373,7 +350,6 @@ typedef struct bInvalidHandle {
char m_pad[2];
};
// -------------------------------------------------- //
class btCharIndexTripletData
{
@@ -382,7 +358,6 @@ typedef struct bInvalidHandle {
char m_pad;
};
// -------------------------------------------------- //
class btMeshPartData
{
@@ -397,7 +372,6 @@ typedef struct bInvalidHandle {
int m_numVertices;
};
// -------------------------------------------------- //
class btStridingMeshInterfaceData
{
@@ -408,7 +382,6 @@ typedef struct bInvalidHandle {
char m_padding[4];
};
// -------------------------------------------------- //
class btTriangleMeshShapeData
{
@@ -422,7 +395,6 @@ typedef struct bInvalidHandle {
char m_pad3[4];
};
// -------------------------------------------------- //
class btScaledTriangleMeshShapeData
{
@@ -431,7 +403,6 @@ typedef struct bInvalidHandle {
btVector3FloatData m_localScaling;
};
// -------------------------------------------------- //
class btCompoundShapeChildData
{
@@ -442,7 +413,6 @@ typedef struct bInvalidHandle {
float m_childMargin;
};
// -------------------------------------------------- //
class btCompoundShapeData
{
@@ -453,7 +423,6 @@ typedef struct bInvalidHandle {
float m_collisionMargin;
};
// -------------------------------------------------- //
class btCylinderShapeData
{
@@ -463,7 +432,6 @@ typedef struct bInvalidHandle {
char m_padding[4];
};
// -------------------------------------------------- //
class btConeShapeData
{
@@ -473,7 +441,6 @@ typedef struct bInvalidHandle {
char m_padding[4];
};
// -------------------------------------------------- //
class btCapsuleShapeData
{
@@ -483,7 +450,6 @@ typedef struct bInvalidHandle {
char m_padding[4];
};
// -------------------------------------------------- //
class btTriangleInfoData
{
@@ -494,7 +460,6 @@ typedef struct bInvalidHandle {
float m_edgeV2V0Angle;
};
// -------------------------------------------------- //
class btTriangleInfoMapData
{
@@ -515,7 +480,6 @@ typedef struct bInvalidHandle {
char m_padding[4];
};
// -------------------------------------------------- //
class btPersistentManifoldDoubleData
{
@@ -560,7 +524,6 @@ typedef struct bInvalidHandle {
btCollisionObjectDoubleData *m_body1;
};
// -------------------------------------------------- //
class btPersistentManifoldFloatData
{
@@ -605,7 +568,6 @@ typedef struct bInvalidHandle {
btCollisionObjectFloatData *m_body1;
};
// -------------------------------------------------- //
class btGImpactMeshShapeData
{
@@ -617,7 +579,6 @@ typedef struct bInvalidHandle {
int m_gimpactSubType;
};
// -------------------------------------------------- //
class btConvexHullShapeData
{
@@ -629,7 +590,6 @@ typedef struct bInvalidHandle {
char m_padding3[4];
};
// -------------------------------------------------- //
class btCollisionObjectDoubleData
{
@@ -665,7 +625,6 @@ typedef struct bInvalidHandle {
int m_uniqueId;
};
// -------------------------------------------------- //
class btCollisionObjectFloatData
{
@@ -701,7 +660,6 @@ typedef struct bInvalidHandle {
int m_uniqueId;
};
// -------------------------------------------------- //
class btContactSolverInfoDoubleData
{
@@ -730,7 +688,6 @@ typedef struct bInvalidHandle {
char m_padding[4];
};
// -------------------------------------------------- //
class btContactSolverInfoFloatData
{
@@ -759,7 +716,6 @@ typedef struct bInvalidHandle {
char m_padding[4];
};
// -------------------------------------------------- //
class btDynamicsWorldDoubleData
{
@@ -768,7 +724,6 @@ typedef struct bInvalidHandle {
btVector3DoubleData m_gravity;
};
// -------------------------------------------------- //
class btDynamicsWorldFloatData
{
@@ -777,7 +732,6 @@ typedef struct bInvalidHandle {
btVector3FloatData m_gravity;
};
// -------------------------------------------------- //
class btRigidBodyFloatData
{
@@ -805,7 +759,6 @@ typedef struct bInvalidHandle {
int m_additionalDamping;
};
// -------------------------------------------------- //
class btRigidBodyDoubleData
{
@@ -834,7 +787,6 @@ typedef struct bInvalidHandle {
char m_padding[4];
};
// -------------------------------------------------- //
class btConstraintInfo1
{
@@ -843,7 +795,6 @@ typedef struct bInvalidHandle {
int nub;
};
// -------------------------------------------------- //
class btTypedConstraintFloatData
{
@@ -863,7 +814,6 @@ typedef struct bInvalidHandle {
int m_isEnabled;
};
// -------------------------------------------------- //
class btTypedConstraintData
{
@@ -883,7 +833,6 @@ typedef struct bInvalidHandle {
int m_isEnabled;
};
// -------------------------------------------------- //
class btTypedConstraintDoubleData
{
@@ -904,7 +853,6 @@ typedef struct bInvalidHandle {
char padding[4];
};
// -------------------------------------------------- //
class btPoint2PointConstraintFloatData
{
@@ -914,7 +862,6 @@ typedef struct bInvalidHandle {
btVector3FloatData m_pivotInB;
};
// -------------------------------------------------- //
class btPoint2PointConstraintDoubleData2
{
@@ -924,7 +871,6 @@ typedef struct bInvalidHandle {
btVector3DoubleData m_pivotInB;
};
// -------------------------------------------------- //
class btPoint2PointConstraintDoubleData
{
@@ -934,7 +880,6 @@ typedef struct bInvalidHandle {
btVector3DoubleData m_pivotInB;
};
// -------------------------------------------------- //
class btHingeConstraintDoubleData
{
@@ -954,7 +899,6 @@ typedef struct bInvalidHandle {
float m_relaxationFactor;
};
// -------------------------------------------------- //
class btHingeConstraintFloatData
{
@@ -974,7 +918,6 @@ typedef struct bInvalidHandle {
float m_relaxationFactor;
};
// -------------------------------------------------- //
class btHingeConstraintDoubleData2
{
@@ -995,7 +938,6 @@ typedef struct bInvalidHandle {
char m_padding1[4];
};
// -------------------------------------------------- //
class btConeTwistConstraintDoubleData
{
@@ -1012,7 +954,6 @@ typedef struct bInvalidHandle {
double m_damping;
};
// -------------------------------------------------- //
class btConeTwistConstraintData
{
@@ -1030,7 +971,6 @@ typedef struct bInvalidHandle {
char m_pad[4];
};
// -------------------------------------------------- //
class btGeneric6DofConstraintData
{
@@ -1046,7 +986,6 @@ typedef struct bInvalidHandle {
int m_useOffsetForConstraintFrame;
};
// -------------------------------------------------- //
class btGeneric6DofConstraintDoubleData2
{
@@ -1062,7 +1001,6 @@ typedef struct bInvalidHandle {
int m_useOffsetForConstraintFrame;
};
// -------------------------------------------------- //
class btGeneric6DofSpringConstraintData
{
@@ -1074,7 +1012,6 @@ typedef struct bInvalidHandle {
float m_springDamping[6];
};
// -------------------------------------------------- //
class btGeneric6DofSpringConstraintDoubleData2
{
@@ -1086,7 +1023,6 @@ typedef struct bInvalidHandle {
double m_springDamping[6];
};
// -------------------------------------------------- //
class btGeneric6DofSpring2ConstraintData
{
@@ -1134,7 +1070,6 @@ typedef struct bInvalidHandle {
int m_rotateOrder;
};
// -------------------------------------------------- //
class btGeneric6DofSpring2ConstraintDoubleData2
{
@@ -1182,7 +1117,6 @@ typedef struct bInvalidHandle {
int m_rotateOrder;
};
// -------------------------------------------------- //
class btSliderConstraintData
{
@@ -1198,7 +1132,6 @@ typedef struct bInvalidHandle {
int m_useOffsetForConstraintFrame;
};
// -------------------------------------------------- //
class btSliderConstraintDoubleData
{
@@ -1214,7 +1147,6 @@ typedef struct bInvalidHandle {
int m_useOffsetForConstraintFrame;
};
// -------------------------------------------------- //
class btGearConstraintFloatData
{
@@ -1226,7 +1158,6 @@ typedef struct bInvalidHandle {
char m_padding[4];
};
// -------------------------------------------------- //
class btGearConstraintDoubleData
{
@@ -1237,7 +1168,6 @@ typedef struct bInvalidHandle {
double m_ratio;
};
// -------------------------------------------------- //
class SoftBodyMaterialData
{
@@ -1248,7 +1178,6 @@ typedef struct bInvalidHandle {
int m_flags;
};
// -------------------------------------------------- //
class SoftBodyNodeData
{
@@ -1265,7 +1194,6 @@ typedef struct bInvalidHandle {
int m_pad;
};
// -------------------------------------------------- //
class SoftBodyLinkData
{
@@ -1276,7 +1204,6 @@ typedef struct bInvalidHandle {
int m_bbending;
};
// -------------------------------------------------- //
class SoftBodyFaceData
{
@@ -1287,7 +1214,6 @@ typedef struct bInvalidHandle {
float m_restArea;
};
// -------------------------------------------------- //
class SoftBodyTetraData
{
@@ -1301,7 +1227,6 @@ typedef struct bInvalidHandle {
int m_pad;
};
// -------------------------------------------------- //
class SoftRigidAnchorData
{
@@ -1314,7 +1239,6 @@ typedef struct bInvalidHandle {
float m_c2;
};
// -------------------------------------------------- //
class SoftBodyConfigData
{
@@ -1347,7 +1271,6 @@ typedef struct bInvalidHandle {
int m_collisionFlags;
};
// -------------------------------------------------- //
class SoftBodyPoseData
{
@@ -1366,7 +1289,6 @@ typedef struct bInvalidHandle {
int m_pad;
};
// -------------------------------------------------- //
class SoftBodyClusterData
{
@@ -1400,7 +1322,6 @@ typedef struct bInvalidHandle {
int m_clusterIndex;
};
// -------------------------------------------------- //
class btSoftBodyJointData
{
@@ -1419,7 +1340,6 @@ typedef struct bInvalidHandle {
int m_pad;
};
// -------------------------------------------------- //
class btSoftBodyFloatData
{
@@ -1445,7 +1365,6 @@ typedef struct bInvalidHandle {
SoftBodyConfigData m_config;
};
// -------------------------------------------------- //
class btMultiBodyLinkDoubleData
{
@@ -1480,7 +1399,6 @@ typedef struct bInvalidHandle {
char *m_paddingPtr;
};
// -------------------------------------------------- //
class btMultiBodyLinkFloatData
{
@@ -1515,7 +1433,6 @@ typedef struct bInvalidHandle {
char *m_paddingPtr;
};
// -------------------------------------------------- //
class btMultiBodyDoubleData
{
@@ -1533,7 +1450,6 @@ typedef struct bInvalidHandle {
btCollisionObjectDoubleData *m_baseCollider;
};
// -------------------------------------------------- //
class btMultiBodyFloatData
{
@@ -1550,7 +1466,6 @@ typedef struct bInvalidHandle {
btCollisionObjectFloatData *m_baseCollider;
};
// -------------------------------------------------- //
class btMultiBodyLinkColliderFloatData
{
@@ -1561,7 +1476,6 @@ typedef struct bInvalidHandle {
char m_padding[4];
};
// -------------------------------------------------- //
class btMultiBodyLinkColliderDoubleData
{
@@ -1572,6 +1486,5 @@ typedef struct bInvalidHandle {
char m_padding[4];
};
}
} // namespace Bullet
#endif //__BULLET_H__

View File

@@ -22,10 +22,8 @@ subject to the following restrictions:
#endif
#include <string.h>
using namespace bParse;
// ----------------------------------------------------- //
short ChunkUtils::swapShort(short sht)
{
@@ -68,8 +66,4 @@ int ChunkUtils::getOffset(int flags)
return res;
}
//eof

View File

@@ -25,10 +25,8 @@ subject to the following restrictions:
#define long64 long long
#endif
namespace bParse {
namespace bParse
{
// ----------------------------------------------------- //
class bChunkPtr4
{
@@ -36,8 +34,7 @@ namespace bParse {
bChunkPtr4() {}
int code;
int len;
union
{
union {
int m_uniqueInt;
};
int dna_nr;
@@ -50,8 +47,7 @@ namespace bParse {
public:
bChunkPtr8() {}
int code, len;
union
{
union {
long64 oldPrev;
int m_uniqueInts[2];
};
@@ -68,12 +64,10 @@ namespace bParse {
int dna_nr, nr;
};
// ----------------------------------------------------- //
class ChunkUtils
{
public:
// file chunk offset
static int getOffset(int flags);
@@ -81,12 +75,10 @@ namespace bParse {
static short swapShort(short sht);
static int swapInt(int inte);
static long64 swapLong64(long64 lng);
};
const int CHUNK_HEADER_LEN = ((sizeof(bChunkInd)));
const bool VOID_IS_8 = ((sizeof(void *) == 8));
}
} // namespace bParse
#endif //__BCHUNK_H__

View File

@@ -16,24 +16,25 @@ subject to the following restrictions:
#ifndef __BCOMMON_H__
#define __BCOMMON_H__
#include <assert.h>
//#include "bLog.h"
#include "LinearMath/btAlignedObjectArray.h"
#include "LinearMath/btHashMap.h"
namespace bParse {
namespace bParse
{
class bMain;
class bFileData;
class bFile;
class bDNA;
// delete void* undefined
typedef struct bStructHandle {int unused;}bStructHandle;
typedef struct bStructHandle
{
int unused;
} bStructHandle;
typedef btAlignedObjectArray<bStructHandle*> bListBasePtr;
typedef btHashMap<btHashPtr, bStructHandle*> bPtrMap;
}
} // namespace bParse
#endif //__BCOMMON_H__

View File

@@ -23,10 +23,8 @@ subject to the following restrictions:
//this define will force traversal of structures, to check backward (and forward) compatibility
//#define TEST_BACKWARD_FORWARD_COMPATIBILITY
using namespace bParse;
// ----------------------------------------------------- //
bDNA::bDNA()
: mPtrLen(0)
@@ -53,7 +51,6 @@ char *bDNA::getName(int ind)
return m_Names[ind].m_name;
}
// ----------------------------------------------------- //
char *bDNA::getType(int ind)
{
@@ -61,7 +58,6 @@ char *bDNA::getType(int ind)
return mTypes[ind];
}
// ----------------------------------------------------- //
short *bDNA::getStruct(int ind)
{
@@ -69,7 +65,6 @@ short *bDNA::getStruct(int ind)
return mStructs[ind];
}
// ----------------------------------------------------- //
short bDNA::getLength(int ind)
{
@@ -77,11 +72,9 @@ short bDNA::getLength(int ind)
return mTlens[ind];
}
// ----------------------------------------------------- //
int bDNA::getReverseType(short type)
{
int *intPtr = mStructReverse.find(type);
if (intPtr)
return *intPtr;
@@ -92,7 +85,6 @@ int bDNA::getReverseType(short type)
// ----------------------------------------------------- //
int bDNA::getReverseType(const char *type)
{
btHashString key(type);
int *valuePtr = mTypeLookup.find(key);
if (valuePtr)
@@ -171,17 +163,13 @@ void bDNA::initRecurseCmpFlags(int iter)
// ----------------------------------------------------- //
void bDNA::initCmpFlags(bDNA *memDNA)
{
// compare the file to memory
// this ptr should be the file data
assert(!(m_Names.size() == 0)); //DNA empty!
mCMPFlags.resize(mStructs.size(), FDF_NONE);
int i;
for (i = 0; i < (int)mStructs.size(); i++)
{
@@ -213,8 +201,6 @@ void bDNA::initCmpFlags(bDNA *memDNA)
short *curStruct = memDNA->mStructs[oldLookup];
#endif
// rebuild...
mCMPFlags[i] = FDF_STRUCT_NEQU;
@@ -228,11 +214,9 @@ void bDNA::initCmpFlags(bDNA *memDNA)
bool isSame = true;
int elementLength = oldStruct[1];
curStruct += 2;
oldStruct += 2;
for (int j = 0; j < elementLength; j++, curStruct += 2, oldStruct += 2)
{
// type the same
@@ -260,10 +244,6 @@ void bDNA::initCmpFlags(bDNA *memDNA)
}
}
// recurse in
for (i = 0; i < (int)mStructs.size(); i++)
{
@@ -272,10 +252,8 @@ void bDNA::initCmpFlags(bDNA *memDNA)
}
}
static int name_is_array(char* name, int* dim1, int* dim2) {
static int name_is_array(char *name, int *dim1, int *dim2)
{
int len = strlen(name);
/*fprintf(stderr,"[%s]",name);*/
/*if (len >= 1) {
@@ -285,58 +263,77 @@ static int name_is_array(char* name, int* dim1, int* dim2) {
return 0;*/
char *bp;
int num;
if (dim1) {
if (dim1)
{
*dim1 = 1;
}
if (dim2) {
if (dim2)
{
*dim2 = 1;
}
bp = strchr(name, '[');
if (!bp) {
if (!bp)
{
return 0;
}
num = 0;
while (++bp < name+len-1) {
while (++bp < name + len - 1)
{
const char c = *bp;
if (c == ']') {
if (c == ']')
{
break;
}
if (c <= '9' && c >= '0') {
if (c <= '9' && c >= '0')
{
num *= 10;
num += (c - '0');
} else {
}
else
{
printf("array parse error.\n");
return 0;
}
}
if (dim2) {
if (dim2)
{
*dim2 = num;
}
/* find second dim, if any. */
bp = strchr(bp, '[');
if (!bp) {
if (!bp)
{
return 1; /* at least we got the first dim. */
}
num = 0;
while (++bp < name+len-1) {
while (++bp < name + len - 1)
{
const char c = *bp;
if (c == ']') {
if (c == ']')
{
break;
}
if (c <= '9' && c >= '0') {
if (c <= '9' && c >= '0')
{
num *= 10;
num += (c - '0');
} else {
}
else
{
printf("array2 parse error.\n");
return 1;
}
}
if (dim1) {
if (dim2) {
if (dim1)
{
if (dim2)
{
*dim1 = *dim2;
*dim2 = num;
} else {
}
else
{
*dim1 = num;
}
}
@@ -344,12 +341,13 @@ static int name_is_array(char* name, int* dim1, int* dim2) {
return 1;
}
// ----------------------------------------------------- //
void bDNA::init(char *data, int len, bool swap)
{
int *intPtr=0;short *shtPtr=0;
char *cp = 0;int dataLen =0;
int *intPtr = 0;
short *shtPtr = 0;
char *cp = 0;
int dataLen = 0;
//long nr=0;
intPtr = (int *)data;
@@ -364,11 +362,10 @@ void bDNA::init(char *data, int len, bool swap)
if (strncmp(data, "SDNA", 4) == 0)
{
// skip ++ NAME
intPtr++; intPtr++;
intPtr++;
intPtr++;
}
// Parse names
if (swap)
{
@@ -390,8 +387,6 @@ void bDNA::init(char *data, int len, bool swap)
cp++;
}
cp = btAlignPointer(cp, 4);
/*
@@ -402,7 +397,8 @@ void bDNA::init(char *data, int len, bool swap)
*/
intPtr = (int *)cp;
assert(strncmp(cp, "TYPE", 4)==0); intPtr++;
assert(strncmp(cp, "TYPE", 4) == 0);
intPtr++;
if (swap)
{
@@ -429,7 +425,8 @@ void bDNA::init(char *data, int len, bool swap)
// Parse type lens
intPtr = (int *)cp;
assert(strncmp(cp, "TLEN", 4)==0); intPtr++;
assert(strncmp(cp, "TLEN", 4) == 0);
intPtr++;
dataLen = (int)mTypes.size();
@@ -456,7 +453,8 @@ void bDNA::init(char *data, int len, bool swap)
intPtr = (int *)shtPtr;
cp = (char *)intPtr;
assert(strncmp(cp, "STRC", 4)==0); intPtr++;
assert(strncmp(cp, "STRC", 4) == 0);
intPtr++;
if (swap)
{
@@ -465,7 +463,6 @@ void bDNA::init(char *data, int len, bool swap)
dataLen = *intPtr;
intPtr++;
shtPtr = (short *)intPtr;
for (i = 0; i < dataLen; i++)
{
@@ -488,7 +485,6 @@ void bDNA::init(char *data, int len, bool swap)
shtPtr += (2 * shtPtr[1]) + 2;
}
// build reverse lookups
for (i = 0; i < (int)mStructs.size(); i++)
{
@@ -503,14 +499,12 @@ void bDNA::init(char *data, int len, bool swap)
}
}
// ----------------------------------------------------- //
int bDNA::getArraySize(char *string)
{
int ret = 1;
int len = strlen(string);
char *next = 0;
for (int i = 0; i < len; i++)
{
@@ -527,7 +521,6 @@ int bDNA::getArraySize(char* string)
return ret;
}
void bDNA::dumpTypeDefinitions()
{
int i;
@@ -536,7 +529,6 @@ void bDNA::dumpTypeDefinitions()
for (i = 0; i < numTypes; i++)
{
}
for (i = 0; i < (int)mStructs.size(); i++)
@@ -562,7 +554,8 @@ void bDNA::dumpTypeDefinitions()
printf("{");
int j;
for (j=0; j<len; ++j,oldStruct+=2) {
for (j = 0; j < len; ++j, oldStruct += 2)
{
const char *name = m_Names[oldStruct[1]].m_name;
printf("%s %s", mTypes[oldStruct[0]], name);
int elemNumBytes = 0;
@@ -571,25 +564,26 @@ void bDNA::dumpTypeDefinitions()
if (m_Names[oldStruct[1]].m_isPointer)
{
elemNumBytes = VOID_IS_8 ? 8 : 4;
} else
}
else
{
elemNumBytes = getLength(oldStruct[0]);
}
printf(" /* %d bytes */", elemNumBytes * arrayDimensions);
if (j == len-1) {
if (j == len - 1)
{
printf(";}");
} else {
}
else
{
printf("; ");
}
totalBytes += elemNumBytes * arrayDimensions;
}
printf("\ntotalBytes=%d\n\n", totalBytes);
}
#if 0
/* dump out display of types and their sizes */
for (i=0; i<bf->types_count; ++i) {
@@ -618,12 +612,6 @@ void bDNA::dumpTypeDefinitions()
}
}
#endif
}
//eof

View File

@@ -16,11 +16,10 @@ subject to the following restrictions:
#ifndef __BDNA_H__
#define __BDNA_H__
#include "bCommon.h"
namespace bParse {
namespace bParse
{
struct bNameInfo
{
char *m_name;
@@ -62,7 +61,6 @@ namespace bParse {
int getReverseType(short type);
int getReverseType(const char *type);
int getNumStructs();
//
@@ -73,12 +71,10 @@ namespace bParse {
bool flagEqual(int dna_nr);
bool flagNone(int dna_nr);
int getPointerSize();
void dumpTypeDefinitions();
private:
enum FileDNAFlags
{
@@ -99,12 +95,7 @@ namespace bParse {
btHashMap<btHashString, int> mTypeLookup;
int mPtrLen;
};
}
} // namespace bParse
#endif //__BDNA_H__

View File

@@ -19,11 +19,9 @@
#ifndef __B_DEFINES_H__
#define __B_DEFINES_H__
// MISC defines, see BKE_global.h, BKE_utildefines.h
#define SIZEOFBLENDERHEADER 12
// ------------------------------------------------------------
#if defined(__sgi) || defined(__sparc) || defined(__sparc__) || defined(__PPC__) || defined(__ppc__) || defined(__BIG_ENDIAN__)
#define MAKE_ID(a, b, c, d) ((int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d))
@@ -31,7 +29,6 @@
#define MAKE_ID(a, b, c, d) ((int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a))
#endif
// ------------------------------------------------------------
#if defined(__sgi) || defined(__sparc) || defined(__sparc__) || defined(__PPC__) || defined(__ppc__) || defined(__BIG_ENDIAN__)
#define MAKE_ID2(c, d) ((c) << 8 | (d))
@@ -77,7 +74,6 @@
#define ID_NT MAKE_ID2('N', 'T')
#define ID_BR MAKE_ID2('B', 'R')
#define ID_SEQ MAKE_ID2('S', 'Q')
#define ID_CO MAKE_ID2('C', 'O')
#define ID_PO MAKE_ID2('A', 'C')
@@ -86,7 +82,6 @@
#define ID_VS MAKE_ID2('V', 'S')
#define ID_VN MAKE_ID2('V', 'N')
// ------------------------------------------------------------
#define FORM MAKE_ID('F', 'O', 'R', 'M')
#define DDG1 MAKE_ID('3', 'D', 'G', '1')
@@ -102,7 +97,6 @@
#define IMAG MAKE_ID('I', 'M', 'A', 'G')
#define USER MAKE_ID('U', 'S', 'E', 'R')
// ------------------------------------------------------------
#define DNA1 MAKE_ID('D', 'N', 'A', '1')
#define REND MAKE_ID('R', 'E', 'N', 'D')
@@ -113,27 +107,46 @@
#define TLEN MAKE_ID('T', 'L', 'E', 'N')
#define STRC MAKE_ID('S', 'T', 'R', 'C')
// ------------------------------------------------------------
#define SWITCH_INT(a) { \
#define SWITCH_INT(a) \
{ \
char s_i, *p_i; \
p_i = (char *)&(a); \
s_i=p_i[0]; p_i[0]=p_i[3]; p_i[3]=s_i; \
s_i=p_i[1]; p_i[1]=p_i[2]; p_i[2]=s_i; }
s_i = p_i[0]; \
p_i[0] = p_i[3]; \
p_i[3] = s_i; \
s_i = p_i[1]; \
p_i[1] = p_i[2]; \
p_i[2] = s_i; \
}
// ------------------------------------------------------------
#define SWITCH_SHORT(a) { \
#define SWITCH_SHORT(a) \
{ \
char s_i, *p_i; \
p_i = (char *)&(a); \
s_i=p_i[0]; p_i[0]=p_i[1]; p_i[1]=s_i; }
s_i = p_i[0]; \
p_i[0] = p_i[1]; \
p_i[1] = s_i; \
}
// ------------------------------------------------------------
#define SWITCH_LONGINT(a) { \
#define SWITCH_LONGINT(a) \
{ \
char s_i, *p_i; \
p_i = (char *)&(a); \
s_i=p_i[0]; p_i[0]=p_i[7]; p_i[7]=s_i; \
s_i=p_i[1]; p_i[1]=p_i[6]; p_i[6]=s_i; \
s_i=p_i[2]; p_i[2]=p_i[5]; p_i[5]=s_i; \
s_i=p_i[3]; p_i[3]=p_i[4]; p_i[4]=s_i; }
s_i = p_i[0]; \
p_i[0] = p_i[7]; \
p_i[7] = s_i; \
s_i = p_i[1]; \
p_i[1] = p_i[6]; \
p_i[6] = s_i; \
s_i = p_i[2]; \
p_i[2] = p_i[5]; \
p_i[5] = s_i; \
s_i = p_i[3]; \
p_i[3] = p_i[4]; \
p_i[4] = s_i; \
}
#endif //__B_DEFINES_H__

View File

@@ -39,7 +39,8 @@ const char* getCleanName(const char* memName, char* buffer)
if (memName[i] == ']' || memName[i] == '[')
{
buffer[i] = 0; //'_';
} else
}
else
{
buffer[i] = memName[i];
}
@@ -48,7 +49,6 @@ const char* getCleanName(const char* memName, char* buffer)
return buffer;
}
int numallocs = 0;
// ----------------------------------------------------- //
@@ -82,7 +82,6 @@ bFile::bFile(const char *filename, const char headerString[7])
//
parseHeader();
}
}
@@ -105,10 +104,8 @@ bFile::bFile( char *memoryBuffer, int len, const char headerString[7])
mFileLen = len;
parseHeader();
}
// ----------------------------------------------------- //
bFile::~bFile()
{
@@ -118,15 +115,10 @@ bFile::~bFile()
mFileBuffer = 0;
}
delete mMemoryDNA;
delete mFileDNA;
}
// ----------------------------------------------------- //
void bFile::parseHeader()
{
@@ -166,7 +158,8 @@ void bFile::parseHeader()
if (!VOID_IS_8)
mFlags |= FD_BITS_VARIES;
}
else if (VOID_IS_8) mFlags |= FD_BITS_VARIES;
else if (VOID_IS_8)
mFlags |= FD_BITS_VARIES;
// swap endian...
if (header[8] == 'V')
@@ -174,11 +167,9 @@ void bFile::parseHeader()
if (littleEndian == 1)
mFlags |= FD_ENDIAN_SWAP;
}
else
if (littleEndian==0)
else if (littleEndian == 0)
mFlags |= FD_ENDIAN_SWAP;
mFlags |= FD_OK;
}
@@ -232,9 +223,11 @@ void bFile::parseInternal(int verboseMode, char* memDna,int memDnaLength)
{
if (strncmp((tempBuffer + ChunkUtils::getOffset(mFlags)), "SDNANAME", 8) == 0)
dna.oldPtr = (tempBuffer + ChunkUtils::getOffset(mFlags));
else dna.oldPtr = 0;
else
dna.oldPtr = 0;
}
else dna.oldPtr = 0;
else
dna.oldPtr = 0;
}
// Some Bullet files are missing the DNA1 block
// In Blender it's DNA1 + ChunkUtils::getOffset() + SDNA + NAME
@@ -258,14 +251,11 @@ void bFile::parseInternal(int verboseMode, char* memDna,int memDnaLength)
return;
}
mFileDNA = new bDNA();
///mFileDNA->init will convert part of DNA file endianness to current CPU endianness if necessary
mFileDNA->init((char *)dna.oldPtr, dna.len, (mFlags & FD_ENDIAN_SWAP) != 0);
if (mVersion == 276)
{
int i;
@@ -282,8 +272,6 @@ void bFile::parseInternal(int verboseMode, char* memDna,int memDnaLength)
}
}
if (verboseMode & FD_VERBOSE_DUMP_DNA_TYPE_DEFINITIONS)
mFileDNA->dumpTypeDefinitions();
}
@@ -293,9 +281,6 @@ void bFile::parseInternal(int verboseMode, char* memDna,int memDnaLength)
mMemoryDNA->init(memDna, memDnaLength, littleEndian == 0);
///@todo we need a better version check, add version/sub version info from FileGlobal into memory DNA/header files
if (mMemoryDNA->getNumNames() != mFileDNA->getNumNames())
{
@@ -309,7 +294,6 @@ void bFile::parseInternal(int verboseMode, char* memDna,int memDnaLength)
//printf ("Warning, file DNA is newer than built in.");
}
mFileDNA->initCmpFlags(mMemoryDNA);
parseData();
@@ -317,20 +301,14 @@ void bFile::parseInternal(int verboseMode, char* memDna,int memDnaLength)
resolvePointers(verboseMode);
updateOldPointers();
}
// ----------------------------------------------------- //
void bFile::swap(char *head, bChunkInd &dataChunk, bool ignoreEndianFlag)
{
char *data = head;
short *strc = mFileDNA->getStruct(dataChunk.dna_nr);
const char s[] = "SoftBodyMaterialData";
int szs = sizeof(s);
if (strncmp((char *)&dataChunk.code, "ARAY", 4) == 0)
@@ -343,7 +321,6 @@ void bFile::swap(char *head, bChunkInd& dataChunk, bool ignoreEndianFlag)
}
}
int len = mFileDNA->getLength(strc[0]);
for (int i = 0; i < dataChunk.nr; i++)
@@ -366,7 +343,8 @@ void bFile::swapLen(char *dataPtr)
SWITCH_INT(c->len);
SWITCH_INT(c->dna_nr);
SWITCH_INT(c->nr);
} else
}
else
{
bChunkPtr8 *c = (bChunkPtr8 *)dataPtr;
if ((c->code & 0xFFFF) == 0)
@@ -374,9 +352,9 @@ void bFile::swapLen(char *dataPtr)
SWITCH_INT(c->len);
SWITCH_INT(c->dna_nr);
SWITCH_INT(c->nr);
}
} else
}
else
{
if (mFlags & FD_BITS_VARIES)
{
@@ -386,8 +364,8 @@ void bFile::swapLen(char *dataPtr)
SWITCH_INT(c->len);
SWITCH_INT(c->dna_nr);
SWITCH_INT(c->nr);
} else
}
else
{
bChunkPtr4 *c = (bChunkPtr4 *)dataPtr;
if ((c->code & 0xFFFF) == 0)
@@ -396,13 +374,10 @@ void bFile::swapLen(char *dataPtr)
SWITCH_INT(c->dna_nr);
SWITCH_INT(c->nr);
}
}
}
void bFile::swapDNA(char *ptr)
{
bool swap = ((mFlags & FD_ENDIAN_SWAP) != 0);
@@ -411,8 +386,10 @@ void bFile::swapDNA(char* ptr)
char *data = &ptr[offset];
// void bDNA::init(char *data, int len, bool swap)
int *intPtr=0;short *shtPtr=0;
char *cp = 0;int dataLen =0;
int *intPtr = 0;
short *shtPtr = 0;
char *cp = 0;
int dataLen = 0;
intPtr = (int *)data;
/*
@@ -428,9 +405,9 @@ void bFile::swapDNA(char* ptr)
// skip ++ NAME
intPtr++;
intPtr++;
} else
}
else
{
if (strncmp(data + 4, "SDNA", 4) == 0)
{
// skip ++ NAME
@@ -440,9 +417,6 @@ void bFile::swapDNA(char* ptr)
}
}
// Parse names
if (swap)
dataLen = ChunkUtils::swapInt(*intPtr);
@@ -460,10 +434,8 @@ void bFile::swapDNA(char* ptr)
cp++;
}
cp = btAlignPointer(cp, 4);
/*
TYPE (4 bytes)
<nr> amount of types (int)
@@ -472,7 +444,8 @@ void bFile::swapDNA(char* ptr)
*/
intPtr = (int *)cp;
assert(strncmp(cp, "TYPE", 4)==0); intPtr++;
assert(strncmp(cp, "TYPE", 4) == 0);
intPtr++;
if (swap)
dataLen = ChunkUtils::swapInt(*intPtr);
@@ -500,8 +473,8 @@ void bFile::swapDNA(char* ptr)
// Parse type lens
intPtr = (int *)cp;
assert(strncmp(cp, "TLEN", 4)==0); intPtr++;
assert(strncmp(cp, "TLEN", 4) == 0);
intPtr++;
shtPtr = (short *)intPtr;
for (i = 0; i < dataLen; i++, shtPtr++)
@@ -538,11 +511,9 @@ void bFile::swapDNA(char* ptr)
intPtr++;
shtPtr = (short *)intPtr;
for (i = 0; i < dataLen; i++)
{
//if (swap)
{
int len = shtPtr[1];
@@ -561,7 +532,6 @@ void bFile::swapDNA(char* ptr)
// else
// shtPtr+= (2*shtPtr[1])+2;
}
}
void bFile::writeFile(const char *fileName)
@@ -573,14 +543,12 @@ void bFile::writeFile(const char* fileName)
void bFile::preSwap()
{
//const bool brokenDNA = (mFlags&FD_BROKEN_DNA)!=0;
//FD_ENDIAN_SWAP
//byte 8 determines the endianness of the file, little (v) versus big (V)
int littleEndian = 1;
littleEndian = ((char *)&littleEndian)[0];
if (mFileBuffer[8] == 'V')
{
mFileBuffer[8] = 'v';
@@ -590,11 +558,6 @@ void bFile::preSwap()
mFileBuffer[8] = 'V';
}
mDataStart = 12;
char *dataPtr = mFileBuffer + mDataStart;
@@ -614,10 +577,10 @@ void bFile::preSwap()
// one behind
if (dataChunk.code == SDNA || dataChunk.code == DNA1 || dataChunk.code == TYPE || dataChunk.code == TLEN || dataChunk.code == STRC)
{
swapDNA(dataPtr);
break;
} else
}
else
{
//if (dataChunk.code == DNA1) break;
dataPtrHead = dataPtr + ChunkUtils::getOffset(mFlags);
@@ -626,7 +589,8 @@ void bFile::preSwap()
if (dataChunk.dna_nr >= 0)
{
swap(dataPtrHead, dataChunk, ignoreEndianFlag);
} else
}
else
{
//printf("unknown chunk\n");
}
@@ -643,16 +607,13 @@ void bFile::preSwap()
if (mFlags & FD_ENDIAN_SWAP)
{
mFlags &= ~FD_ENDIAN_SWAP;
} else
}
else
{
mFlags |= FD_ENDIAN_SWAP;
}
}
// ----------------------------------------------------- //
char *bFile::readStruct(char *head, bChunkInd &dataChunk)
{
@@ -661,8 +622,6 @@ char* bFile::readStruct(char *head, bChunkInd& dataChunk)
if (mFlags & FD_ENDIAN_SWAP)
swap(head, dataChunk, ignoreEndianFlag);
if (!mFileDNA->flagEqual(dataChunk.dna_nr))
{
// Ouch! need to rebuild the struct
@@ -670,7 +629,6 @@ char* bFile::readStruct(char *head, bChunkInd& dataChunk)
char *oldType, *newType;
int oldLen, curLen, reverseOld;
oldStruct = mFileDNA->getStruct(dataChunk.dna_nr);
oldType = mFileDNA->getType(oldStruct[0]);
@@ -702,8 +660,6 @@ char* bFile::readStruct(char *head, bChunkInd& dataChunk)
}
}
///don't try to convert Link block data, just memcpy it. Other data can be converted.
if (strcmp("Link", oldType) != 0)
{
@@ -719,12 +675,9 @@ char* bFile::readStruct(char *head, bChunkInd& dataChunk)
newType = mMemoryDNA->getType(curStruct[0]);
curLen = mMemoryDNA->getLength(curStruct[0]);
// make sure it's the same
assert((strcmp(oldType, newType) == 0) && "internal error, struct mismatch!");
numallocs++;
// numBlocks * length
@@ -748,11 +701,13 @@ char* bFile::readStruct(char *head, bChunkInd& dataChunk)
}
return dataAlloc;
}
} else
}
else
{
//printf("Link found\n");
}
} else
}
else
{
//#define DEBUG_EQUAL_STRUCTS
#ifdef DEBUG_EQUAL_STRUCTS
@@ -764,20 +719,16 @@ char* bFile::readStruct(char *head, bChunkInd& dataChunk)
#endif //
}
char *dataAlloc = new char[(dataChunk.len) + 1];
memset(dataAlloc, 0, dataChunk.len + 1);
// track allocated
addDataBlock(dataAlloc);
memcpy(dataAlloc, head, dataChunk.len);
return dataAlloc;
}
// ----------------------------------------------------- //
void bFile::parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bool fixupPointers)
{
@@ -800,13 +751,11 @@ void bFile::parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bo
int elementLength, size, revType, old_nr, new_nr, fpLen;
short firstStructType;
// File to memory lookup
memoryStruct = mMemoryDNA->getStruct(new_dna);
fileStruct = mFileDNA->getStruct(old_dna);
firstStruct = fileStruct;
filePtrOld = fileStruct;
firstStructType = mMemoryDNA->getStruct(0)[0];
@@ -814,13 +763,13 @@ void bFile::parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bo
elementLength = memoryStruct[1];
memoryStruct += 2;
cpc = strcPtr; cpo = 0;
cpc = strcPtr;
cpo = 0;
for (int ele = 0; ele < elementLength; ele++, memoryStruct += 2)
{
memType = mMemoryDNA->getType(memoryStruct[0]);
memName = mMemoryDNA->getName(memoryStruct[1]);
size = mMemoryDNA->getElementSize(memoryStruct[0], memoryStruct[1]);
revType = mMemoryDNA->getReverseType(memoryStruct[0]);
@@ -836,7 +785,8 @@ void bFile::parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bo
if (arrayLen == 1)
{
parseStruct(cpc, cpo, old_nr, new_nr, fixupPointers);
} else
}
else
{
char *tmpCpc = cpc;
char *tmpCpo = cpo;
@@ -859,11 +809,9 @@ void bFile::parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bo
getMatchingFileDNA(fileStruct, memName, memType, cpc, dtPtr, fixupPointers);
cpc += size;
}
}
}
// ----------------------------------------------------- //
static void getElement(int arrayLen, const char *cur, const char *old, char *oldPtr, char *curData)
{
@@ -901,7 +849,6 @@ static void getElement(int arrayLen, const char *cur, const char *old, char *old
}
}
// ----------------------------------------------------- //
void bFile::swapData(char *data, short type, int arraySize, bool ignoreEndianFlag)
{
@@ -934,8 +881,6 @@ void bFile::swapData(char *data, short type, int arraySize,bool ignoreEndianFlag
}
}
void bFile::safeSwapPtr(char *dst, const char *src)
{
int ptrFile = mFileDNA->getPointerSize();
@@ -944,7 +889,6 @@ void bFile::safeSwapPtr(char *dst, const char *src)
if (!src && !dst)
return;
if (ptrFile == ptrMem)
{
memcpy(dst, src, ptrMem);
@@ -959,7 +903,8 @@ void bFile::safeSwapPtr(char *dst, const char *src)
//Bullet stores the 32bit unique ID in both upper and lower part of 64bit pointers
//so it can be used to distinguish between .blend and .bullet
newPtr->m_uniqueIds[0] = oldPtr->m_uniqueIds[0];
} else
}
else
{
//deal with pointers the Blender .blend style way, see
//readfile.c in the Blender source tree
@@ -969,7 +914,6 @@ void bFile::safeSwapPtr(char *dst, const char *src)
SWITCH_LONGINT(longValue);
*((int *)dst) = (int)(longValue >> 3);
}
}
else if (ptrMem == 8 && ptrFile == 4)
{
@@ -979,7 +923,8 @@ void bFile::safeSwapPtr(char *dst, const char *src)
{
newPtr->m_uniqueIds[0] = oldPtr->m_uniqueIds[0];
newPtr->m_uniqueIds[1] = 0;
} else
}
else
{
*((long64 *)dst) = *((int *)src);
}
@@ -989,11 +934,8 @@ void bFile::safeSwapPtr(char *dst, const char *src)
printf("%d %d\n", ptrFile, ptrMem);
assert(0 && "Invalid pointer len");
}
}
// ----------------------------------------------------- //
void bFile::getMatchingFileDNA(short *dna_addr, const char *lookupName, const char *lookupType, char *strcData, char *data, bool fixupPointers)
{
@@ -1009,8 +951,6 @@ void bFile::getMatchingFileDNA(short* dna_addr, const char* lookupName, const c
const char *type = mFileDNA->getType(dna_addr[0]);
const char *name = mFileDNA->getName(dna_addr[1]);
int eleLen = mFileDNA->getElementSize(dna_addr[0], dna_addr[1]);
if ((mFlags & FD_BROKEN_DNA) != 0)
@@ -1065,7 +1005,6 @@ void bFile::getMatchingFileDNA(short* dna_addr, const char* lookupName, const c
{
// printf("skipped %s %s : %x\n",type.c_str(),name.c_str(),strcData);
}
}
else if (strcmp(type, lookupType) == 0)
@@ -1080,7 +1019,6 @@ void bFile::getMatchingFileDNA(short* dna_addr, const char* lookupName, const c
}
}
// ----------------------------------------------------- //
char *bFile::getFileElement(short *firstStruct, char *lookupName, char *lookupType, char *data, short **foundPos)
{
@@ -1109,7 +1047,6 @@ char* bFile::getFileElement(short *firstStruct, char *lookupName, char *lookupTy
return 0;
}
// ----------------------------------------------------- //
void bFile::swapStruct(int dna_nr, char *data, bool ignoreEndianFlag)
{
@@ -1137,7 +1074,8 @@ void bFile::swapStruct(int dna_nr, char *data,bool ignoreEndianFlag)
if (arrayLen == 1)
{
swapStruct(old_nr, buf, ignoreEndianFlag);
} else
}
else
{
char *tmpBuf = buf;
for (int i = 0; i < arrayLen; i++)
@@ -1174,13 +1112,13 @@ void bFile::resolvePointersMismatch()
{
//printf("Fixup pointer!\n");
*(ptrptr) = ptr;
} else
}
else
{
// printf("pointer not found: %x\n",cur);
}
}
for (i = 0; i < m_pointerPtrFixupArray.size(); i++)
{
char *cur = m_pointerPtrFixupArray.at(i);
@@ -1192,7 +1130,6 @@ void bFile::resolvePointersMismatch()
int ptrMem = mMemoryDNA->getPointerSize();
int ptrFile = mFileDNA->getPointerSize();
int blockLen = block->len / ptrFile;
void *onptr = findLibPointer(*ptrptr);
@@ -1224,7 +1161,6 @@ void bFile::resolvePointersMismatch()
}
}
///this loop only works fine if the Blender DNA structure of the file matches the headerfiles
void bFile::resolvePointersChunk(const bChunkInd &dataChunk, int verboseMode)
{
@@ -1242,17 +1178,14 @@ void bFile::resolvePointersChunk(const bChunkInd& dataChunk, int verboseMode)
}
}
int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verboseMode, int recursion)
{
bParse::bDNA *fileDna = mFileDNA ? mFileDNA : mMemoryDNA;
char *memType;
char *memName;
short firstStructType = fileDna->getStruct(0)[0];
char *elemPtr = strcPtr;
short int *oldStruct = fileDna->getStruct(dna_nr);
@@ -1264,12 +1197,9 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
for (int ele = 0; ele < elementLength; ele++, oldStruct += 2)
{
memType = fileDna->getType(oldStruct[0]);
memName = fileDna->getName(oldStruct[1]);
int arrayLen = fileDna->getArraySizeNew(oldStruct[1]);
if (memName[0] == '*')
{
@@ -1326,12 +1256,14 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
n++;
}
}
} else
}
else
{
// printf("Cannot fixup pointer at 0x%x from 0x%x to 0x%x!\n",ptrptr,*ptrptr,ptr);
}
}
} else
}
else
{
int revType = fileDna->getReverseType(oldStruct[0]);
if (oldStruct[0] >= firstStructType) //revType != -1 &&
@@ -1352,7 +1284,8 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
if (arrayLen > 1)
{
printf("<%s type=\"%s\" count=%d>\n", cleanName, memType, arrayLen);
} else
}
else
{
printf("<%s type=\"%s\">\n", cleanName, memType);
}
@@ -1370,16 +1303,17 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
}
printf("</%s>\n", cleanName);
}
} else
}
else
{
//export a simple type
if (verboseMode & FD_VERBOSE_EXPORT_XML)
{
if (arrayLen > MAX_ARRAY_LENGTH)
{
printf("too long\n");
} else
}
else
{
//printf("%s %s\n",memType,memName);
@@ -1409,7 +1343,8 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
printf(" %d ", dbPtr[i]);
printf("</%s>\n", cleanName);
}
} else
}
else
{
const char *newtype = "double";
double dbarray[MAX_ARRAY_LENGTH];
@@ -1439,7 +1374,6 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
}
}
}
}
}
}
@@ -1447,13 +1381,11 @@ int bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, int verbose
int size = fileDna->getElementSize(oldStruct[0], oldStruct[1]);
totalSize += size;
elemPtr += size;
}
return totalSize;
}
///Resolve pointers replaces the original pointers in structures, and linked lists by the new in-memory structures
void bFile::resolvePointers(int verboseMode)
{
@@ -1467,7 +1399,6 @@ void bFile::resolvePointers(int verboseMode)
}
{
if (verboseMode & FD_VERBOSE_EXPORT_XML)
{
printf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
@@ -1491,7 +1422,8 @@ void bFile::resolvePointers(int verboseMode)
if (verboseMode & FD_VERBOSE_EXPORT_XML)
printf(" </%s>\n", oldType);
} else
}
else
{
//printf("skipping mStruct\n");
}
@@ -1501,22 +1433,17 @@ void bFile::resolvePointers(int verboseMode)
printf("</bullet_physics>\n");
}
}
}
// ----------------------------------------------------- //
void *bFile::findLibPointer(void *ptr)
{
bStructHandle **ptrptr = getLibPointers().find(ptr);
if (ptrptr)
return *ptrptr;
return 0;
}
void bFile::updateOldPointers()
{
int i;
@@ -1551,10 +1478,6 @@ void bFile::dumpChunks(bParse::bDNA* dna)
printf("not 1\n");
}
printf("\n");
}
#if 0
@@ -1570,10 +1493,8 @@ void bFile::dumpChunks(bParse::bDNA* dna)
printf("\n");
}
#endif
}
void bFile::writeChunks(FILE *fp, bool fixupPointers)
{
bParse::bDNA *fileDna = mFileDNA ? mFileDNA : mMemoryDNA;
@@ -1593,7 +1514,6 @@ void bFile::writeChunks(FILE* fp, bool fixupPointers)
///don't try to convert Link block data, just memcpy it. Other data can be converted.
reverseOld = mMemoryDNA->getReverseType(oldType);
if ((reverseOld != -1))
{
// make sure it's here
@@ -1604,13 +1524,13 @@ void bFile::writeChunks(FILE* fp, bool fixupPointers)
// make sure it's the same
assert((strcmp(oldType, newType) == 0) && "internal error, struct mismatch!");
curLen = mMemoryDNA->getLength(curStruct[0]);
dataChunk.dna_nr = reverseOld;
if (strcmp("Link", oldType) != 0)
{
dataChunk.len = curLen * dataChunk.nr;
} else
}
else
{
// printf("keep length of link = %d\n",dataChunk.len);
}
@@ -1618,8 +1538,6 @@ void bFile::writeChunks(FILE* fp, bool fixupPointers)
//write the structure header
fwrite(&dataChunk, sizeof(bChunkInd), 1, fp);
short int *curStruct1;
curStruct1 = mMemoryDNA->getStruct(dataChunk.dna_nr);
assert(curStruct1 == curStruct);
@@ -1628,15 +1546,14 @@ void bFile::writeChunks(FILE* fp, bool fixupPointers)
//write the actual contents of the structure(s)
fwrite(cur, dataChunk.len, 1, fp);
} else
}
else
{
printf("serious error, struct mismatch: don't write\n");
}
}
}
// ----------------------------------------------------- //
int bFile::getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int flags)
{
@@ -1655,7 +1572,6 @@ int bFile::getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int fl
bChunkPtr4 head;
memcpy(&head, dataPtr, sizeof(bChunkPtr4));
bChunkPtr8 chunk;
chunk.code = head.code;
@@ -1675,7 +1591,6 @@ int bFile::getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int fl
SWITCH_INT(chunk.nr);
}
memcpy(dataChunk, &chunk, sizeof(bChunkInd));
}
else
@@ -1703,7 +1618,6 @@ int bFile::getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int fl
bChunkPtr8 head;
memcpy(&head, dataPtr, sizeof(bChunkPtr8));
bChunkPtr4 chunk;
chunk.code = head.code;
chunk.len = head.len;
@@ -1711,7 +1625,8 @@ int bFile::getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int fl
if (head.m_uniqueInts[0] == head.m_uniqueInts[1])
{
chunk.m_uniqueInt = head.m_uniqueInts[0];
} else
}
else
{
long64 oldPtr = 0;
memcpy(&oldPtr, &head.m_uniqueInts[0], 8);
@@ -1720,7 +1635,6 @@ int bFile::getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int fl
chunk.m_uniqueInt = (int)(oldPtr >> 3);
}
chunk.dna_nr = head.dna_nr;
chunk.nr = head.nr;
@@ -1768,6 +1682,4 @@ int bFile::getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int fl
return (dataChunk->len + ChunkUtils::getOffset(flags));
}
//eof

View File

@@ -20,8 +20,8 @@ subject to the following restrictions:
#include "bChunk.h"
#include <stdio.h>
namespace bParse {
namespace bParse
{
// ----------------------------------------------------- //
enum bFileFlags
{
@@ -48,7 +48,6 @@ namespace bParse {
class bFile
{
protected:
char m_headerString[7];
bool mOwnsBuffer;
@@ -56,7 +55,6 @@ namespace bParse {
int mFileLen;
int mVersion;
bPtrMap mLibPointers;
int mDataStart;
@@ -73,7 +71,6 @@ namespace bParse {
bPtrMap mDataPointers;
int mFlags;
// ////////////////////////////////////////////////////////////////////////////
@@ -96,14 +93,12 @@ namespace bParse {
void getMatchingFileDNA(short* old, const char* lookupName, const char* lookupType, char* strcData, char* data, bool fixupPointers);
char* getFileElement(short* firstStruct, char* lookupName, char* lookupType, char* data, short** foundPos);
void swap(char* head, class bChunkInd& ch, bool ignoreEndianFlag);
void swapData(char* data, short type, int arraySize, bool ignoreEndianFlag);
void swapStruct(int dna_nr, char* data, bool ignoreEndianFlag);
void swapLen(char* dataPtr);
void swapDNA(char* ptr);
char* readStruct(char* head, class bChunkInd& chunk);
char* getAsString(int code);
@@ -165,11 +160,7 @@ namespace bParse {
//pre-swap the endianness, so that data loaded on a target with different endianness doesn't need to be swapped
void preSwap();
void writeFile(const char* fileName);
};
}
} // namespace bParse
#endif //__BFILE_H__

View File

@@ -22,7 +22,6 @@ subject to the following restrictions:
#endif
#include <string.h>
// 32 && 64 bit versions
#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
#ifdef _WIN64
@@ -50,7 +49,6 @@ btBulletFile::btBulletFile()
m_DnaCopy = 0;
#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
#ifdef _WIN64
m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen64, 16);
@@ -77,40 +75,31 @@ btBulletFile::btBulletFile()
#endif //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
}
btBulletFile::btBulletFile(const char* fileName)
: bFile(fileName, "BULLET ")
{
m_DnaCopy = 0;
}
btBulletFile::btBulletFile(char* memoryBuffer, int len)
: bFile(memoryBuffer, len, "BULLET ")
{
m_DnaCopy = 0;
}
btBulletFile::~btBulletFile()
{
if (m_DnaCopy)
btAlignedFree(m_DnaCopy);
while (m_dataBlocks.size())
{
char* dataBlock = m_dataBlocks[m_dataBlocks.size() - 1];
delete[] dataBlock;
m_dataBlocks.pop_back();
}
}
// ----------------------------------------------------- //
void btBulletFile::parseData()
{
@@ -122,7 +111,6 @@ void btBulletFile::parseData()
//const bool swap = (mFlags&FD_ENDIAN_SWAP)!=0;
int remain = mFileLen;
mDataStart = 12;
@@ -137,11 +125,9 @@ void btBulletFile::parseData()
bChunkInd dataChunk;
dataChunk.code = 0;
//dataPtr += ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags);
int seek = getNextBlock(&dataChunk, dataPtr, mFlags);
if (mFlags & FD_ENDIAN_SWAP)
swapLen(dataPtr);
@@ -152,7 +138,6 @@ void btBulletFile::parseData()
{
if (!brokenDNA || (dataChunk.code != BT_QUANTIZED_BVH_CODE))
{
// one behind
if (dataChunk.code == SDNA) break;
//if (dataChunk.code == DNA1) break;
@@ -234,18 +219,19 @@ void btBulletFile::parseData()
// {
// m_glob = (bStructHandle*) id;
// }
} else
}
else
{
//printf("unknown chunk\n");
mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)dataPtrHead);
}
} else
}
else
{
printf("skipping BT_QUANTIZED_BVH_CODE due to broken DNA\n");
}
dataPtr += seek;
remain -= seek;
if (remain <= 0)
@@ -258,21 +244,15 @@ void btBulletFile::parseData()
if (seek < 0)
break;
}
}
void btBulletFile::addDataBlock(char* dataBlock)
{
m_dataBlocks.push_back(dataBlock);
}
void btBulletFile::writeDNA(FILE* fp)
{
bChunkInd dataChunk;
dataChunk.code = DNA1;
dataChunk.dna_nr = 0;
@@ -318,7 +298,6 @@ void btBulletFile::writeDNA(FILE* fp)
#endif //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
}
void btBulletFile::parse(int verboseMode)
{
#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
@@ -374,7 +353,6 @@ void btBulletFile::parse(int verboseMode)
littleEndian = ((char*)&littleEndian)[0];
mFileBuffer[8] = littleEndian ? 'v' : 'V';
}
// experimental
@@ -391,14 +369,16 @@ int btBulletFile::write(const char* fileName, bool fixupPointers)
if (endian)
{
header[7] = '_';
} else
}
else
{
header[7] = '-';
}
if (VOID_IS_8)
{
header[8] = 'V';
} else
}
else
{
header[8] = 'v';
}
@@ -414,8 +394,8 @@ int btBulletFile::write(const char* fileName, bool fixupPointers)
writeDNA(fp);
fclose(fp);
} else
}
else
{
printf("Error: cannot open file %s for writing\n", fileName);
return 0;
@@ -423,11 +403,8 @@ int btBulletFile::write(const char* fileName, bool fixupPointers)
return 1;
}
void btBulletFile::addStruct(const char* structType, void* data, int len, void* oldPtr, int code)
{
bParse::bChunkInd dataChunk;
dataChunk.code = code;
dataChunk.nr = 1;
@@ -445,4 +422,3 @@ void btBulletFile::addStruct(const char* structType,void* data, int len, void* o
mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)data);
m_chunks.push_back(dataChunk);
}

View File

@@ -16,29 +16,21 @@ subject to the following restrictions:
#ifndef BT_BULLET_FILE_H
#define BT_BULLET_FILE_H
#include "bFile.h"
#include "LinearMath/btAlignedObjectArray.h"
#include "bDefines.h"
#include "LinearMath/btSerializer.h"
namespace bParse {
namespace bParse
{
// ----------------------------------------------------- //
class btBulletFile : public bFile
{
protected:
char* m_DnaCopy;
public:
btAlignedObjectArray<bStructHandle*> m_multiBodies;
btAlignedObjectArray<bStructHandle*> m_multiBodyLinkColliders;
@@ -72,7 +64,6 @@ namespace bParse {
virtual void addDataBlock(char* dataBlock);
// experimental
virtual int write(const char* fileName, bool fixupPointers = false);
@@ -83,8 +74,7 @@ namespace bParse {
virtual void writeDNA(FILE* fp);
void addStruct(const char* structType, void* data, int len, void* oldPtr, int code);
};
};
}; // namespace bParse
#endif //BT_BULLET_FILE_H

View File

@@ -13,7 +13,6 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
#include "btBulletWorldImporter.h"
#include "../BulletFileLoader/btBulletFile.h"
@@ -22,7 +21,6 @@ subject to the following restrictions:
#include "BulletCollision/Gimpact/btGImpactShape.h"
#endif
//#define USE_INTERNAL_EDGE_UTILITY
#ifdef USE_INTERNAL_EDGE_UTILITY
#include "BulletCollision/CollisionDispatch/btInternalEdgeUtility.h"
@@ -37,12 +35,10 @@ btBulletWorldImporter::~btBulletWorldImporter()
{
}
bool btBulletWorldImporter::loadFile(const char* fileName, const char* preSwapFilenameOut)
{
bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile(fileName);
bool result = loadFileFromMemory(bulletFile2);
//now you could save the file in 'native' format using
//bulletFile2->writeFile("native.bullet");
@@ -53,16 +49,12 @@ bool btBulletWorldImporter::loadFile( const char* fileName, const char* preSwapF
bulletFile2->preSwap();
bulletFile2->writeFile(preSwapFilenameOut);
}
}
delete bulletFile2;
return result;
}
bool btBulletWorldImporter::loadFileFromMemory(char* memoryBuffer, int len)
{
bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile(memoryBuffer, len);
@@ -74,9 +66,6 @@ bool btBulletWorldImporter::loadFileFromMemory( char* memoryBuffer, int len)
return result;
}
bool btBulletWorldImporter::loadFileFromMemory(bParse::btBulletFile* bulletFile2)
{
bool ok = (bulletFile2->getFlags() & bParse::FD_OK) != 0;
@@ -92,12 +81,10 @@ bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFil
}
return convertAllObjects(bulletFile2);
}
bool btBulletWorldImporter::convertAllObjects(bParse::btBulletFile* bulletFile2)
{
m_shapeMap.clear();
m_bodyMap.clear();
@@ -111,7 +98,8 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile
{
btQuantizedBvhDoubleData* bvhData = (btQuantizedBvhDoubleData*)bulletFile2->m_bvhs[i];
bvh->deSerializeDouble(*bvhData);
} else
}
else
{
btQuantizedBvhFloatData* bvhData = (btQuantizedBvhFloatData*)bulletFile2->m_bvhs[i];
bvh->deSerializeFloat(*bvhData);
@@ -119,10 +107,6 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile
m_bvhMap.insert(bulletFile2->m_bvhs[i], bvh);
}
for (i = 0; i < bulletFile2->m_collisionShapes.size(); i++)
{
btCollisionShapeData* shapeData = (btCollisionShapeData*)bulletFile2->m_collisionShapes[i];
@@ -141,10 +125,6 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile
}
}
for (int i = 0; i < bulletFile2->m_dynamicsWorldInfo.size(); i++)
{
if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)
@@ -183,7 +163,8 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile
solverInfo.m_splitImpulse = solverInfoData->m_solverInfo.m_splitImpulse;
setDynamicsWorldInfo(gravity, solverInfo);
} else
}
else
{
btDynamicsWorldFloatData* solverInfoData = (btDynamicsWorldFloatData*)bulletFile2->m_dynamicsWorldInfo[i];
btContactSolverInfo solverInfo;
@@ -222,20 +203,18 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile
}
}
for (i = 0; i < bulletFile2->m_rigidBodies.size(); i++)
{
if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)
{
btRigidBodyDoubleData* colObjData = (btRigidBodyDoubleData*)bulletFile2->m_rigidBodies[i];
convertRigidBodyDouble(colObjData);
} else
}
else
{
btRigidBodyFloatData* colObjData = (btRigidBodyFloatData*)bulletFile2->m_rigidBodies[i];
convertRigidBodyFloat(colObjData);
}
}
for (i = 0; i < bulletFile2->m_collisionObjects.size(); i++)
@@ -266,12 +245,13 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile
}
#endif //USE_INTERNAL_EDGE_UTILITY
m_bodyMap.insert(colObjData, body);
} else
}
else
{
printf("error: no shape found\n");
}
} else
}
else
{
btCollisionObjectFloatData* colObjData = (btCollisionObjectFloatData*)bulletFile2->m_collisionObjects[i];
btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionShape);
@@ -295,15 +275,14 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile
}
#endif //USE_INTERNAL_EDGE_UTILITY
m_bodyMap.insert(colObjData, body);
} else
}
else
{
printf("error: no shape found\n");
}
}
}
for (i = 0; i < bulletFile2->m_constraints.size(); i++)
{
btTypedConstraintData2* constraintData = (btTypedConstraintData2*)bulletFile2->m_constraints[i];
@@ -337,14 +316,14 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile
{
btTypedConstraintDoubleData* dc = (btTypedConstraintDoubleData*)constraintData;
convertConstraintDouble(dc, rbA, rbB, bulletFile2->getVersion());
} else
}
else
{
//double-precision constraints were messed up until 2.82, try to recover data...
btTypedConstraintData* oldData = (btTypedConstraintData*)constraintData;
convertConstraintBackwardsCompatible281(oldData, rbA, rbB, bulletFile2->getVersion());
}
}
else
@@ -352,10 +331,7 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile
btTypedConstraintFloatData* dc = (btTypedConstraintFloatData*)constraintData;
convertConstraintFloat(dc, rbA, rbB, bulletFile2->getVersion());
}
}
return true;
}

View File

@@ -13,36 +13,25 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef BULLET_WORLD_IMPORTER_H
#define BULLET_WORLD_IMPORTER_H
#include "btWorldImporter.h"
class btBulletFile;
namespace bParse
{
class btBulletFile;
};
///The btBulletWorldImporter is a starting point to import .bullet files.
///note that not all data is converted yet. You are expected to override or modify this class.
///See Bullet/Demos/SerializeDemo for a derived class that extract btSoftBody objects too.
class btBulletWorldImporter : public btWorldImporter
{
public:
btBulletWorldImporter(btDynamicsWorld* world = 0);
virtual ~btBulletWorldImporter();
@@ -58,11 +47,6 @@ public:
//call make sure bulletFile2 has been parsed, either using btBulletFile::parse or btBulletWorldImporter::loadFileFromMemory
virtual bool convertAllObjects(bParse::btBulletFile* file);
};
#endif //BULLET_WORLD_IMPORTER_H

View File

@@ -21,7 +21,6 @@ btMultiBodyWorldImporter::btMultiBodyWorldImporter(btMultiBodyDynamicsWorld* wor
m_data->m_mbDynamicsWorld = world;
}
btMultiBodyWorldImporter::~btMultiBodyWorldImporter()
{
delete m_data;
@@ -32,7 +31,6 @@ void btMultiBodyWorldImporter::deleteAllData()
btBulletWorldImporter::deleteAllData();
}
static btCollisionObjectDoubleData* getBody0FromContactManifold(btPersistentManifoldDoubleData* manifold)
{
return (btCollisionObjectDoubleData*)manifold->m_body0;
@@ -50,8 +48,8 @@ static btCollisionObjectFloatData* getBody1FromContactManifold(btPersistentManif
return (btCollisionObjectFloatData*)manifold->m_body1;
}
template<class T> void syncContactManifolds(T** contactManifolds, int numContactManifolds, btMultiBodyWorldImporterInternalData* m_data)
template <class T>
void syncContactManifolds(T** contactManifolds, int numContactManifolds, btMultiBodyWorldImporterInternalData* m_data)
{
m_data->m_mbDynamicsWorld->updateAabbs();
m_data->m_mbDynamicsWorld->computeOverlappingPairs();
@@ -59,7 +57,6 @@ template<class T> void syncContactManifolds(T** contactManifolds, int numContact
btDispatcherInfo& dispatchInfo = m_data->m_mbDynamicsWorld->getDispatchInfo();
if (dispatcher)
{
btOverlappingPairCache* pairCache = m_data->m_mbDynamicsWorld->getBroadphase()->getOverlappingPairCache();
@@ -104,10 +101,10 @@ template<class T> void syncContactManifolds(T** contactManifolds, int numContact
}
}
}
}
template<class T> void syncMultiBody(T* mbd, btMultiBody* mb, btMultiBodyWorldImporterInternalData* m_data, btAlignedObjectArray<btQuaternion>& scratchQ, btAlignedObjectArray<btVector3>& scratchM)
template <class T>
void syncMultiBody(T* mbd, btMultiBody* mb, btMultiBodyWorldImporterInternalData* m_data, btAlignedObjectArray<btQuaternion>& scratchQ, btAlignedObjectArray<btVector3>& scratchM)
{
bool isFixedBase = mbd->m_baseMass == 0;
bool canSleep = false;
@@ -129,7 +126,6 @@ template<class T> void syncMultiBody(T* mbd, btMultiBody* mb, btMultiBodyWorldI
for (int i = 0; i < mbd->m_numLinks; i++)
{
mb->getLink(i).m_absFrameTotVelocity.m_topVec.deSerialize(mbd->m_links[i].m_absFrameTotVelocityTop);
mb->getLink(i).m_absFrameTotVelocity.m_bottomVec.deSerialize(mbd->m_links[i].m_absFrameTotVelocityBottom);
mb->getLink(i).m_absFrameLocVelocity.m_topVec.deSerialize(mbd->m_links[i].m_absFrameLocVelocityTop);
@@ -175,7 +171,8 @@ template<class T> void syncMultiBody(T* mbd, btMultiBody* mb, btMultiBodyWorldI
mb->updateCollisionObjectWorldTransforms(scratchQ, scratchM);
}
template<class T> void convertMultiBody(T* mbd, btMultiBodyWorldImporterInternalData* m_data)
template <class T>
void convertMultiBody(T* mbd, btMultiBodyWorldImporterInternalData* m_data)
{
bool isFixedBase = mbd->m_baseMass == 0;
bool canSleep = false;
@@ -208,8 +205,6 @@ template<class T> void convertMultiBody(T* mbd, btMultiBodyWorldImporterInterna
{
case btMultibodyLink::eFixed:
{
mb->setupFixed(i, mbd->m_links[i].m_linkMass, localInertiaDiagonal, mbd->m_links[i].m_parentIndex,
parentRotToThis, parentComToThisPivotOffset, thisPivotToThisComOffset);
//search for the collider
@@ -284,7 +279,6 @@ bool btMultiBodyWorldImporter::convertAllObjects( bParse::btBulletFile* bulletF
//convert all multibodies
if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)
{
//for (int i = 0; i < bulletFile2->m_multiBodies.size(); i++)
for (int i = bulletFile2->m_multiBodies.size() - 1; i >= 0; i--)
{
@@ -352,7 +346,6 @@ bool btMultiBodyWorldImporter::convertAllObjects( bParse::btBulletFile* bulletF
}
}
if (bulletFile2->m_contactManifolds.size())
{
syncContactManifolds((btPersistentManifoldDoubleData**)&bulletFile2->m_contactManifolds[0], bulletFile2->m_contactManifolds.size(), m_data);
@@ -389,23 +382,19 @@ bool btMultiBodyWorldImporter::convertAllObjects( bParse::btBulletFile* bulletF
}
}
if (bulletFile2->m_contactManifolds.size())
{
syncContactManifolds((btPersistentManifoldFloatData**)&bulletFile2->m_contactManifolds[0], bulletFile2->m_contactManifolds.size(), m_data);
}
}
}
else
{
result = btBulletWorldImporter::convertAllObjects(bulletFile2);
//convert all multibodies
for (int i = 0; i < bulletFile2->m_multiBodies.size(); i++)
{
if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)
{
btMultiBodyDoubleData* mbd = (btMultiBodyDoubleData*)bulletFile2->m_multiBodies[i];
@@ -444,7 +433,6 @@ bool btMultiBodyWorldImporter::convertAllObjects( bParse::btBulletFile* bulletF
{
btMultiBody* multiBody = *ptr;
btCollisionShape** shapePtr = m_shapeMap.find(mblcd->m_colObjData.m_collisionShape);
if (shapePtr && *shapePtr)
{
@@ -491,7 +479,6 @@ bool btMultiBodyWorldImporter::convertAllObjects( bParse::btBulletFile* bulletF
#endif
m_data->m_mbDynamicsWorld->addCollisionObject(col, collisionFilterGroup, collisionFilterMask);
}
}
else
{
@@ -503,7 +490,6 @@ bool btMultiBodyWorldImporter::convertAllObjects( bParse::btBulletFile* bulletF
world1->addCollisionObject(col, collisionFilterGroup, collisionFilterMask);
#endif
}
}
}

View File

@@ -8,7 +8,6 @@ class btMultiBodyWorldImporter : public btBulletWorldImporter
struct btMultiBodyWorldImporterInternalData* m_data;
public:
btMultiBodyWorldImporter(class btMultiBodyDynamicsWorld* world);
virtual ~btMultiBodyWorldImporter();

View File

@@ -23,7 +23,6 @@ btWorldImporter::btWorldImporter(btDynamicsWorld* world)
m_verboseMode(0),
m_importerFlags(0)
{
}
btWorldImporter::~btWorldImporter()
@@ -41,7 +40,6 @@ void btWorldImporter::deleteAllData()
}
m_allocatedConstraints.clear();
for (i = 0; i < m_allocatedRigidBodies.size(); i++)
{
if (m_dynamicsWorld)
@@ -51,14 +49,12 @@ void btWorldImporter::deleteAllData()
m_allocatedRigidBodies.clear();
for (i = 0; i < m_allocatedCollisionShapes.size(); i++)
{
delete m_allocatedCollisionShapes[i];
}
m_allocatedCollisionShapes.clear();
for (i = 0; i < m_allocatedBvhs.size(); i++)
{
delete m_allocatedBvhs[i];
@@ -105,7 +101,6 @@ void btWorldImporter::deleteAllData()
if (curPart->m_3indices8)
delete[] curPart->m_3indices8;
}
delete[] curData->m_meshPartsPtr;
delete curData;
@@ -141,12 +136,8 @@ void btWorldImporter::deleteAllData()
btAlignedFree(m_doubleVertexArrays[i]);
}
m_doubleVertexArrays.clear();
}
btCollisionShape* btWorldImporter::convertCollisionShape(btCollisionShapeData* shapeData)
{
btCollisionShape* shape = 0;
@@ -186,7 +177,6 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
btStridingMeshInterfaceData* interfaceData = createStridingMeshInterfaceData(&gimpactData->m_meshInterface);
btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData);
btGImpactMeshShape* gimpactShape = createGimpactShape(meshInterface);
btVector3 localScaling;
localScaling.deSerializeFloat(gimpactData->m_localScaling);
@@ -194,7 +184,8 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
gimpactShape->setMargin(btScalar(gimpactData->m_collisionMargin));
gimpactShape->updateBound();
shape = gimpactShape;
} else
}
else
{
printf("unsupported gimpact sub type\n");
}
@@ -207,7 +198,6 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
{
btCapsuleShapeData* capData = (btCapsuleShapeData*)shapeData;
switch (capData->m_upAxis)
{
case 0:
@@ -229,8 +219,6 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
{
printf("error: wrong up axis for btCapsuleShape\n");
}
};
if (shape)
{
@@ -293,11 +281,8 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
{
printf("unknown Cylinder up axis\n");
}
};
break;
}
case CONE_SHAPE_PROXYTYPE:
@@ -325,11 +310,8 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
{
printf("unknown Cone up axis\n");
}
};
break;
}
case MULTI_SPHERE_SHAPE_PROXYTYPE:
@@ -398,7 +380,6 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
btVector3 localScaling;
localScaling.deSerializeFloat(bsd->m_localScaling);
shape->setLocalScaling(localScaling);
}
break;
}
@@ -412,10 +393,10 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
return 0;
}
btVector3 scaling; scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling);
btVector3 scaling;
scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling);
meshInterface->setScaling(scaling);
btOptimizedBvh* bvh = 0;
#if 1
if (trimesh->m_quantizedFloatBvh)
@@ -424,7 +405,8 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
if (bvhPtr && *bvhPtr)
{
bvh = *bvhPtr;
} else
}
else
{
bvh = createOptimizedBvh();
bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh);
@@ -436,7 +418,8 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
if (bvhPtr && *bvhPtr)
{
bvh = *bvhPtr;
} else
}
else
{
bvh = createOptimizedBvh();
bvh->deSerializeDouble(*trimesh->m_quantizedDoubleBvh);
@@ -444,7 +427,6 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
}
#endif
btBvhTriangleMeshShape* trimeshShape = createBvhTriangleMeshShape(meshInterface, bvh);
trimeshShape->setMargin(trimesh->m_collisionMargin);
shape = trimeshShape;
@@ -458,7 +440,6 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
#ifdef USE_INTERNAL_EDGE_UTILITY
gContactAddedCallback = btAdjustInternalEdgeContactsCallback;
#endif //USE_INTERNAL_EDGE_UTILITY
}
//printf("trimesh->m_collisionMargin=%f\n",trimesh->m_collisionMargin);
@@ -469,11 +450,9 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
btCompoundShapeData* compoundData = (btCompoundShapeData*)shapeData;
btCompoundShape* compoundShape = createCompoundShape();
btAlignedObjectArray<btCollisionShape*> childShapes;
for (int i = 0; i < compoundData->m_numChildShapes; i++)
{
btCollisionShapeData* cd = compoundData->m_childShapePtr[i].m_childShape;
btCollisionShape* childShape = convertCollisionShape(cd);
@@ -482,13 +461,13 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
btTransform localTransform;
localTransform.deSerializeFloat(compoundData->m_childShapePtr[i].m_transform);
compoundShape->addChildShape(localTransform, childShape);
} else
}
else
{
#ifdef _DEBUG
printf("error: couldn't create childShape for compoundShape\n");
#endif
}
}
shape = compoundShape;
@@ -507,11 +486,8 @@ btCollisionShape* btWorldImporter::convertCollisionShape( btCollisionShapeData*
}
return shape;
}
char* btWorldImporter::duplicateName(const char* name)
{
if (name)
@@ -528,7 +504,6 @@ char* btWorldImporter::duplicateName(const char* name)
void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion)
{
btTypedConstraint* constraint = 0;
switch (constraintData->m_objectType)
@@ -542,7 +517,8 @@ void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintD
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
pivotInB.deSerializeDouble(p2pData->m_pivotInB);
constraint = createPoint2PointConstraint(*rbA, *rbB, pivotInA, pivotInB);
} else
}
else
{
btVector3 pivotInA;
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
@@ -561,7 +537,8 @@ void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintD
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
hinge = createHingeConstraint(*rbA, *rbB, rbAFrame, rbBFrame, hingeData->m_useReferenceFrameA != 0);
} else
}
else
{
btTransform rbAFrame;
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
@@ -576,7 +553,6 @@ void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintD
constraint = hinge;
break;
}
case CONETWIST_CONSTRAINT_TYPE:
{
@@ -589,7 +565,8 @@ void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintD
rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
rbBFrame.deSerializeFloat(coneData->m_rbBFrame);
coneTwist = createConeTwistConstraint(*rbA, *rbB, rbAFrame, rbBFrame);
} else
}
else
{
btTransform rbAFrame;
rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
@@ -605,7 +582,6 @@ void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintD
case D6_SPRING_CONSTRAINT_TYPE:
{
btGeneric6DofSpringConstraintData* dofData = (btGeneric6DofSpringConstraintData*)constraintData;
// int sz = sizeof(btGeneric6DofSpringConstraintData);
btGeneric6DofSpringConstraint* dof = 0;
@@ -616,7 +592,8 @@ void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintD
rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame);
rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame);
dof = createGeneric6DofSpringConstraint(*rbA, *rbB, rbAFrame, rbBFrame, dofData->m_6dofData.m_useLinearReferenceFrameA != 0);
} else
}
else
{
printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
}
@@ -650,7 +627,6 @@ void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintD
constraint = dof;
break;
}
case D6_CONSTRAINT_TYPE:
{
@@ -663,14 +639,16 @@ void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintD
rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
dof = createGeneric6DofConstraint(*rbA, *rbB, rbAFrame, rbBFrame, dofData->m_useLinearReferenceFrameA != 0);
} else
}
else
{
if (rbB)
{
btTransform rbBFrame;
rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
dof = createGeneric6DofConstraint(*rbB, rbBFrame, dofData->m_useLinearReferenceFrameA != 0);
} else
}
else
{
printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
}
@@ -703,7 +681,8 @@ void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintD
rbAFrame.deSerializeFloat(sliderData->m_rbAFrame);
rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
slider = createSliderConstraint(*rbA, *rbB, rbAFrame, rbBFrame, sliderData->m_useLinearReferenceFrameA != 0);
} else
}
else
{
btTransform rbBFrame;
rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
@@ -744,7 +723,6 @@ void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintD
if (m_dynamicsWorld)
m_dynamicsWorld->addConstraint(constraint, constraintData->m_disableCollisionsBetweenLinkedBodies != 0);
}
}
void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion)
@@ -762,8 +740,8 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
pivotInA.deSerializeFloat(p2pData->m_pivotInA);
pivotInB.deSerializeFloat(p2pData->m_pivotInB);
constraint = createPoint2PointConstraint(*rbA, *rbB, pivotInA, pivotInB);
} else
}
else
{
btVector3 pivotInA;
pivotInA.deSerializeFloat(p2pData->m_pivotInA);
@@ -781,7 +759,8 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
rbBFrame.deSerializeFloat(hingeData->m_rbBFrame);
hinge = createHingeConstraint(*rbA, *rbB, rbAFrame, rbBFrame, hingeData->m_useReferenceFrameA != 0);
} else
}
else
{
btTransform rbAFrame;
rbAFrame.deSerializeFloat(hingeData->m_rbAFrame);
@@ -796,7 +775,6 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
constraint = hinge;
break;
}
case CONETWIST_CONSTRAINT_TYPE:
{
@@ -809,7 +787,8 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
rbBFrame.deSerializeFloat(coneData->m_rbBFrame);
coneTwist = createConeTwistConstraint(*rbA, *rbB, rbAFrame, rbBFrame);
} else
}
else
{
btTransform rbAFrame;
rbAFrame.deSerializeFloat(coneData->m_rbAFrame);
@@ -824,7 +803,6 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
case D6_SPRING_CONSTRAINT_TYPE:
{
btGeneric6DofSpringConstraintData* dofData = (btGeneric6DofSpringConstraintData*)constraintData;
// int sz = sizeof(btGeneric6DofSpringConstraintData);
btGeneric6DofSpringConstraint* dof = 0;
@@ -835,7 +813,8 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame);
rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame);
dof = createGeneric6DofSpringConstraint(*rbA, *rbB, rbAFrame, rbBFrame, dofData->m_6dofData.m_useLinearReferenceFrameA != 0);
} else
}
else
{
printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
}
@@ -881,14 +860,16 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
dof = createGeneric6DofConstraint(*rbA, *rbB, rbAFrame, rbBFrame, dofData->m_useLinearReferenceFrameA != 0);
} else
}
else
{
if (rbB)
{
btTransform rbBFrame;
rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
dof = createGeneric6DofConstraint(*rbB, rbBFrame, dofData->m_useLinearReferenceFrameA != 0);
} else
}
else
{
printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
}
@@ -921,7 +902,8 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
rbAFrame.deSerializeFloat(sliderData->m_rbAFrame);
rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
slider = createSliderConstraint(*rbA, *rbB, rbAFrame, rbBFrame, sliderData->m_useLinearReferenceFrameA != 0);
} else
}
else
{
btTransform rbBFrame;
rbBFrame.deSerializeFloat(sliderData->m_rbBFrame);
@@ -945,7 +927,8 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
axisInA.deSerializeFloat(gearData->m_axisInA);
axisInB.deSerializeFloat(gearData->m_axisInB);
gear = createGearConstraint(*rbA, *rbB, axisInA, axisInB, gearData->m_ratio);
} else
}
else
{
btAssert(0);
//perhaps a gear against a 'fixed' body, while the 'fixed' body is not serialized?
@@ -956,7 +939,6 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
}
case D6_SPRING_2_CONSTRAINT_TYPE:
{
btGeneric6DofSpring2ConstraintData* dofData = (btGeneric6DofSpring2ConstraintData*)constraintData;
btGeneric6DofSpring2Constraint* dof = 0;
@@ -967,7 +949,8 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
rbAFrame.deSerializeFloat(dofData->m_rbAFrame);
rbBFrame.deSerializeFloat(dofData->m_rbBFrame);
dof = createGeneric6DofSpring2Constraint(*rbA, *rbB, rbAFrame, rbBFrame, dofData->m_rotateOrder);
} else
}
else
{
printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
}
@@ -1004,17 +987,14 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
dof->enableSpring(i + 3, dofData->m_angularEnableSpring[i] != 0);
dof->setDamping(i + 3, dofData->m_angularSpringDamping.m_floats[i], dofData->m_angularSpringDampingLimited[i]);
}
}
}
constraint = dof;
break;
}
case FIXED_CONSTRAINT_TYPE:
{
btGeneric6DofSpring2Constraint* dof = 0;
if (rbA && rbB)
{
@@ -1028,14 +1008,13 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
rbAFrame = rbA->getWorldTransform().inverse() * sharedFrame;
rbBFrame = rbB->getWorldTransform().inverse() * sharedFrame;
dof = createGeneric6DofSpring2Constraint(*rbA, *rbB, rbAFrame, rbBFrame, RO_XYZ);
dof->setLinearUpperLimit(btVector3(0, 0, 0));
dof->setLinearLowerLimit(btVector3(0, 0, 0));
dof->setAngularUpperLimit(btVector3(0, 0, 0));
dof->setAngularLowerLimit(btVector3(0, 0, 0));
} else
}
else
{
printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
}
@@ -1069,12 +1048,8 @@ void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constra
if (m_dynamicsWorld)
m_dynamicsWorld->addConstraint(constraint, constraintData->m_disableCollisionsBetweenLinkedBodies != 0);
}
}
void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion)
{
btTypedConstraint* constraint = 0;
@@ -1090,7 +1065,8 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
pivotInB.deSerializeDouble(p2pData->m_pivotInB);
constraint = createPoint2PointConstraint(*rbA, *rbB, pivotInA, pivotInB);
} else
}
else
{
btVector3 pivotInA;
pivotInA.deSerializeDouble(p2pData->m_pivotInA);
@@ -1109,7 +1085,8 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
rbBFrame.deSerializeDouble(hingeData->m_rbBFrame);
hinge = createHingeConstraint(*rbA, *rbB, rbAFrame, rbBFrame, hingeData->m_useReferenceFrameA != 0);
} else
}
else
{
btTransform rbAFrame;
rbAFrame.deSerializeDouble(hingeData->m_rbAFrame);
@@ -1124,7 +1101,6 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
constraint = hinge;
break;
}
case CONETWIST_CONSTRAINT_TYPE:
{
@@ -1137,7 +1113,8 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
rbAFrame.deSerializeDouble(coneData->m_rbAFrame);
rbBFrame.deSerializeDouble(coneData->m_rbBFrame);
coneTwist = createConeTwistConstraint(*rbA, *rbB, rbAFrame, rbBFrame);
} else
}
else
{
btTransform rbAFrame;
rbAFrame.deSerializeDouble(coneData->m_rbAFrame);
@@ -1153,7 +1130,6 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
case D6_SPRING_CONSTRAINT_TYPE:
{
btGeneric6DofSpringConstraintDoubleData2* dofData = (btGeneric6DofSpringConstraintDoubleData2*)constraintData;
// int sz = sizeof(btGeneric6DofSpringConstraintData);
btGeneric6DofSpringConstraint* dof = 0;
@@ -1164,7 +1140,8 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
rbAFrame.deSerializeDouble(dofData->m_6dofData.m_rbAFrame);
rbBFrame.deSerializeDouble(dofData->m_6dofData.m_rbBFrame);
dof = createGeneric6DofSpringConstraint(*rbA, *rbB, rbAFrame, rbBFrame, dofData->m_6dofData.m_useLinearReferenceFrameA != 0);
} else
}
else
{
printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n");
}
@@ -1210,14 +1187,16 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
rbAFrame.deSerializeDouble(dofData->m_rbAFrame);
rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
dof = createGeneric6DofConstraint(*rbA, *rbB, rbAFrame, rbBFrame, dofData->m_useLinearReferenceFrameA != 0);
} else
}
else
{
if (rbB)
{
btTransform rbBFrame;
rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
dof = createGeneric6DofConstraint(*rbB, rbBFrame, dofData->m_useLinearReferenceFrameA != 0);
} else
}
else
{
printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n");
}
@@ -1250,7 +1229,8 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
rbAFrame.deSerializeDouble(sliderData->m_rbAFrame);
rbBFrame.deSerializeDouble(sliderData->m_rbBFrame);
slider = createSliderConstraint(*rbA, *rbB, rbAFrame, rbBFrame, sliderData->m_useLinearReferenceFrameA != 0);
} else
}
else
{
btTransform rbBFrame;
rbBFrame.deSerializeDouble(sliderData->m_rbBFrame);
@@ -1274,7 +1254,8 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
axisInA.deSerializeDouble(gearData->m_axisInA);
axisInB.deSerializeDouble(gearData->m_axisInB);
gear = createGearConstraint(*rbA, *rbB, axisInA, axisInB, gearData->m_ratio);
} else
}
else
{
btAssert(0);
//perhaps a gear against a 'fixed' body, while the 'fixed' body is not serialized?
@@ -1286,7 +1267,6 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
case D6_SPRING_2_CONSTRAINT_TYPE:
{
btGeneric6DofSpring2ConstraintDoubleData2* dofData = (btGeneric6DofSpring2ConstraintDoubleData2*)constraintData;
btGeneric6DofSpring2Constraint* dof = 0;
@@ -1297,7 +1277,8 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
rbAFrame.deSerializeDouble(dofData->m_rbAFrame);
rbBFrame.deSerializeDouble(dofData->m_rbBFrame);
dof = createGeneric6DofSpring2Constraint(*rbA, *rbB, rbAFrame, rbBFrame, dofData->m_rotateOrder);
} else
}
else
{
printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
}
@@ -1334,17 +1315,14 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
dof->enableSpring(i + 3, dofData->m_angularEnableSpring[i] != 0);
dof->setDamping(i + 3, dofData->m_angularSpringDamping.m_floats[i], (dofData->m_angularSpringDampingLimited[i] != 0));
}
}
}
constraint = dof;
break;
}
case FIXED_CONSTRAINT_TYPE:
{
btGeneric6DofSpring2Constraint* dof = 0;
if (rbA && rbB)
{
@@ -1358,14 +1336,13 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
rbAFrame = rbA->getWorldTransform().inverse() * sharedFrame;
rbBFrame = rbB->getWorldTransform().inverse() * sharedFrame;
dof = createGeneric6DofSpring2Constraint(*rbA, *rbB, rbAFrame, rbBFrame, RO_XYZ);
dof->setLinearUpperLimit(btVector3(0, 0, 0));
dof->setLinearLowerLimit(btVector3(0, 0, 0));
dof->setAngularUpperLimit(btVector3(0, 0, 0));
dof->setAngularLowerLimit(btVector3(0, 0, 0));
} else
}
else
{
printf("Error in btWorldImporter::createGeneric6DofSpring2Constraint: requires rbA && rbB\n");
}
@@ -1400,19 +1377,8 @@ void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* const
if (m_dynamicsWorld)
m_dynamicsWorld->addConstraint(constraint, constraintData->m_disableCollisionsBetweenLinkedBodies != 0);
}
}
btTriangleIndexVertexArray* btWorldImporter::createMeshInterface(btStridingMeshInterfaceData& meshData)
{
btTriangleIndexVertexArray* meshInterface = createTriangleMeshContainer();
@@ -1423,7 +1389,6 @@ btTriangleIndexVertexArray* btWorldImporter::createMeshInterface(btStridingMeshI
meshPart.m_numTriangles = meshData.m_meshPartsPtr[i].m_numTriangles;
meshPart.m_numVertices = meshData.m_meshPartsPtr[i].m_numVertices;
if (meshData.m_meshPartsPtr[i].m_indices32)
{
meshPart.m_indexType = PHY_INTEGER;
@@ -1435,7 +1400,8 @@ btTriangleIndexVertexArray* btWorldImporter::createMeshInterface(btStridingMeshI
indexArray[j] = meshData.m_meshPartsPtr[i].m_indices32[j].m_value;
}
meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
} else
}
else
{
if (meshData.m_meshPartsPtr[i].m_3indices16)
{
@@ -1502,12 +1468,12 @@ btTriangleIndexVertexArray* btWorldImporter::createMeshInterface(btStridingMeshI
vertices[j].m_floats[3] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[3];
}
meshPart.m_vertexBase = (const unsigned char*)vertices;
} else
}
else
{
meshPart.m_vertexType = PHY_DOUBLE;
meshPart.m_vertexStride = sizeof(btVector3DoubleData);
btVector3DoubleData* vertices = (btVector3DoubleData*)btAlignedAlloc(sizeof(btVector3DoubleData) * meshPart.m_numVertices, 16);
m_doubleVertexArrays.push_back(vertices);
@@ -1530,7 +1496,6 @@ btTriangleIndexVertexArray* btWorldImporter::createMeshInterface(btStridingMeshI
return meshInterface;
}
btStridingMeshInterfaceData* btWorldImporter::createStridingMeshInterfaceData(btStridingMeshInterfaceData* interfaceData)
{
//create a new btStridingMeshInterfaceData that is an exact copy of shapedata and store it in the WorldImporter
@@ -1603,7 +1568,6 @@ btStridingMeshInterfaceData* btWorldImporter::createStridingMeshInterfaceData(bt
}
else
curNewPart->m_3indices8 = NULL;
}
m_allocatedbtStridingMeshInterfaceDatas.push_back(newData);
@@ -1616,7 +1580,6 @@ extern ContactAddedCallback gContactAddedCallback;
static bool btAdjustInternalEdgeContactsCallback(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0, int index0, const btCollisionObject* colObj1, int partId1, int index1)
{
btAdjustInternalEdgeContacts(cp, colObj1, colObj0, partId1, index1);
//btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_BACKFACE_MODE);
//btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_DOUBLE_SIDED+BT_TRIANGLE_CONCAVE_DOUBLE_SIDED);
@@ -1624,9 +1587,6 @@ static bool btAdjustInternalEdgeContactsCallback(btManifoldPoint& cp, const btCo
}
#endif //USE_INTERNAL_EDGE_UTILITY
btCollisionObject* btWorldImporter::createCollisionObject(const btTransform& startTransform, btCollisionShape* shape, const char* bodyName)
{
return createRigidBody(false, 0, startTransform, shape, bodyName);
@@ -1639,7 +1599,6 @@ void btWorldImporter::setDynamicsWorldInfo(const btVector3& gravity, const btCon
m_dynamicsWorld->setGravity(gravity);
m_dynamicsWorld->getSolverInfo() = solverInfo;
}
}
btRigidBody* btWorldImporter::createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform, btCollisionShape* shape, const char* bodyName)
@@ -1664,7 +1623,6 @@ btRigidBody* btWorldImporter::createRigidBody(bool isDynamic, btScalar mass, co
}
m_allocatedRigidBodies.push_back(body);
return body;
}
btCollisionShape* btWorldImporter::createPlaneShape(const btVector3& planeNormal, btScalar planeConstant)
@@ -1686,7 +1644,6 @@ btCollisionShape* btWorldImporter::createSphereShape(btScalar radius)
return shape;
}
btCollisionShape* btWorldImporter::createCapsuleShapeX(btScalar radius, btScalar height)
{
btCapsuleShapeX* shape = new btCapsuleShapeX(radius, height);
@@ -1764,7 +1721,6 @@ btOptimizedBvh* btWorldImporter::createOptimizedBvh()
return bvh;
}
btTriangleInfoMap* btWorldImporter::createTriangleInfoMap()
{
btTriangleInfoMap* tim = new btTriangleInfoMap();
@@ -1785,7 +1741,6 @@ btBvhTriangleMeshShape* btWorldImporter::createBvhTriangleMeshShape(btStridingMe
btBvhTriangleMeshShape* ts = new btBvhTriangleMeshShape(trimesh, true);
m_allocatedCollisionShapes.push_back(ts);
return ts;
}
btCollisionShape* btWorldImporter::createConvexTriangleMeshShape(btStridingMeshInterface* trimesh)
{
@@ -1800,7 +1755,6 @@ btGImpactMeshShape* btWorldImporter::createGimpactShape(btStridingMeshInterface*
#else
return 0;
#endif
}
btConvexHullShape* btWorldImporter::createConvexHullShape()
{
@@ -1816,7 +1770,6 @@ btCompoundShape* btWorldImporter::createCompoundShape()
return shape;
}
btScaledBvhTriangleMeshShape* btWorldImporter::createScaledTrangleMeshShape(btBvhTriangleMeshShape* meshShape, const btVector3& localScaling)
{
btScaledBvhTriangleMeshShape* shape = new btScaledBvhTriangleMeshShape(meshShape, localScaling);
@@ -1852,7 +1805,6 @@ btPoint2PointConstraint* btWorldImporter::createPoint2PointConstraint(btRigidBod
return p2p;
}
btHingeConstraint* btWorldImporter::createHingeConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA)
{
btHingeConstraint* hinge = new btHingeConstraint(rbA, rbB, rbAFrame, rbBFrame, useReferenceFrameA);
@@ -1881,7 +1833,6 @@ btConeTwistConstraint* btWorldImporter::createConeTwistConstraint(btRigidBody& r
return cone;
}
btGeneric6DofConstraint* btWorldImporter::createGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB, bool useLinearReferenceFrameA)
{
btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbA, rbB, frameInA, frameInB, useLinearReferenceFrameA);
@@ -1903,8 +1854,6 @@ btGeneric6DofSpring2Constraint* btWorldImporter::createGeneric6DofSpring2Constra
return dof;
}
btGeneric6DofSpringConstraint* btWorldImporter::createGeneric6DofSpringConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB, bool useLinearReferenceFrameA)
{
btGeneric6DofSpringConstraint* dof = new btGeneric6DofSpringConstraint(rbA, rbB, frameInA, frameInB, useLinearReferenceFrameA);
@@ -1912,7 +1861,6 @@ btGeneric6DofSpringConstraint* btWorldImporter::createGeneric6DofSpringConstrain
return dof;
}
btSliderConstraint* btWorldImporter::createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB, bool useLinearReferenceFrameA)
{
btSliderConstraint* slider = new btSliderConstraint(rbA, rbB, frameInA, frameInB, useLinearReferenceFrameA);
@@ -1983,7 +1931,6 @@ const char* btWorldImporter::getNameForPointer(const void* ptr) const
return 0;
}
int btWorldImporter::getNumRigidBodies() const
{
return m_allocatedRigidBodies.size();
@@ -2022,7 +1969,6 @@ btTriangleInfoMap* btWorldImporter::getTriangleInfoMapByIndex(int index) const
return m_allocatedTriangleInfoMaps[index];
}
void btWorldImporter::convertRigidBodyFloat(btRigidBodyFloatData* colObjData)
{
btScalar mass = btScalar(colObjData->m_inverseMass ? 1.f / colObjData->m_inverseMass : 0.f);
@@ -2066,7 +2012,8 @@ void btWorldImporter::convertRigidBodyFloat( btRigidBodyFloatData* colObjData)
}
#endif //USE_INTERNAL_EDGE_UTILITY
m_bodyMap.insert(colObjData, body);
} else
}
else
{
printf("error: no shape found\n");
}
@@ -2104,7 +2051,6 @@ void btWorldImporter::convertRigidBodyDouble( btRigidBodyDoubleData* colObjData)
body->setLinearFactor(linearFactor);
body->setAngularFactor(angularFactor);
#ifdef USE_INTERNAL_EDGE_UTILITY
if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
{
@@ -2116,7 +2062,8 @@ void btWorldImporter::convertRigidBodyDouble( btRigidBodyDoubleData* colObjData)
}
#endif //USE_INTERNAL_EDGE_UTILITY
m_bodyMap.insert(colObjData, body);
} else
}
else
{
printf("error: no shape found\n");
}

View File

@@ -13,7 +13,6 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef BT_WORLD_IMPORTER_H
#define BT_WORLD_IMPORTER_H
@@ -89,7 +88,6 @@ protected:
btAlignedObjectArray<btVector3FloatData*> m_floatVertexArrays;
btAlignedObjectArray<btVector3DoubleData*> m_doubleVertexArrays;
btHashMap<btHashPtr, btOptimizedBvh*> m_bvhMap;
btHashMap<btHashPtr, btTriangleInfoMap*> m_timMap;
@@ -101,7 +99,6 @@ protected:
btHashMap<btHashPtr, btCollisionShape*> m_shapeMap;
btHashMap<btHashPtr, btCollisionObject*> m_bodyMap;
//methods
static btRigidBody& getFixedBody();
@@ -117,7 +114,6 @@ protected:
void convertRigidBodyDouble(btRigidBodyDoubleData* colObjData);
public:
btWorldImporter(btDynamicsWorld* world);
virtual ~btWorldImporter();
@@ -146,8 +142,6 @@ public:
return m_importerFlags;
}
// query for data
int getNumCollisionShapes() const;
btCollisionShape* getCollisionShapeByIndex(int index);
@@ -222,11 +216,6 @@ public:
virtual btSliderConstraint* createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB, bool useLinearReferenceFrameA);
virtual btSliderConstraint* createSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA);
virtual btGearConstraint* createGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA, const btVector3& axisInB, btScalar ratio);
};
#endif //BT_WORLD_IMPORTER_H

View File

@@ -29,18 +29,15 @@ struct MyLocalCaster
}
};
btBulletXmlWorldImporter::btBulletXmlWorldImporter(btDynamicsWorld* world)
: btWorldImporter(world),
m_fileVersion(-1),
m_fileOk(false)
{
}
btBulletXmlWorldImporter::~btBulletXmlWorldImporter()
{
}
#if 0
@@ -88,7 +85,6 @@ void stringToFloatArray(const std::string& string, btAlignedObjectArray<float>&
btAssert(pieces[i] != "");
floats.push_back((float)atof(pieces[i].c_str()));
}
}
static btVector3FloatData TextToVector3Data(const char* txt)
@@ -118,22 +114,18 @@ void btBulletXmlWorldImporter::deSerializeVector3FloatData(XMLNode* pParent,btAl
vectors.push_back(vec4);
flNode = flNode->NextSibling();
}
}
#define SET_INT_VALUE(xmlnode, targetdata, argname) \
btAssert((xmlnode)->FirstChildElement(#argname) && (xmlnode)->FirstChildElement(#argname)->ToElement()); \
if ((xmlnode)->FirstChildElement(#argname) && (xmlnode)->FirstChildElement(#argname)->ToElement()) \
(targetdata)->argname = (int)atof(xmlnode->FirstChildElement(#argname)->ToElement()->GetText());
#define SET_FLOAT_VALUE(xmlnode, targetdata, argname) \
btAssert((xmlnode)->FirstChildElement(#argname) && (xmlnode)->FirstChildElement(#argname)->ToElement()); \
if ((xmlnode)->FirstChildElement(#argname) && (xmlnode)->FirstChildElement(#argname)->ToElement()) \
(targetdata)->argname = (float)atof(xmlnode->FirstChildElement(#argname)->ToElement()->GetText());
#define SET_POINTER_VALUE(xmlnode, targetdata, argname, pointertype) \
{ \
XMLNode* node = xmlnode->FirstChildElement(#argname); \
@@ -162,7 +154,6 @@ void btBulletXmlWorldImporter::deSerializeVector3FloatData(XMLNode* pParent,btAl
} \
}
#define SET_MATRIX33_VALUE(n, targetdata, argname) \
{ \
XMLNode* xmlnode = n->FirstChildElement(#argname); \
@@ -205,7 +196,7 @@ void btBulletXmlWorldImporter::deSerializeVector3FloatData(XMLNode* pParent,btAl
} \
} \
} \
}\
}
#define SET_TRANSFORM_VALUE(n, targetdata, argname) \
{ \
@@ -216,8 +207,7 @@ void btBulletXmlWorldImporter::deSerializeVector3FloatData(XMLNode* pParent,btAl
SET_VECTOR4_VALUE(trNode, &(targetdata)->argname, m_origin) \
SET_MATRIX33_VALUE(trNode, &(targetdata)->argname, m_basis) \
} \
}\
}
void btBulletXmlWorldImporter::deSerializeCollisionShapeData(XMLNode* pParent, btCollisionShapeData* colShapeData)
{
@@ -225,8 +215,6 @@ void btBulletXmlWorldImporter::deSerializeCollisionShapeData(XMLNode* pParent, b
colShapeData->m_name = 0;
}
void btBulletXmlWorldImporter::deSerializeConvexHullShapeData(XMLNode* pParent)
{
MyLocalCaster cast;
@@ -314,7 +302,6 @@ void btBulletXmlWorldImporter::deSerializeCompoundShapeChildData(XMLNode* pParen
}
numChildren = i;
}
btAssert(numChildren);
@@ -324,7 +311,6 @@ void btBulletXmlWorldImporter::deSerializeCompoundShapeChildData(XMLNode* pParen
btCompoundShapeChildData* cd = &compoundChildArrayPtr->at(0);
m_pointerLookup.insert(cast.m_ptr, cd);
}
}
void btBulletXmlWorldImporter::deSerializeCompoundShapeData(XMLNode* pParent)
@@ -344,7 +330,7 @@ void btBulletXmlWorldImporter::deSerializeCompoundShapeData(XMLNode* pParent)
btAssert(xmlShapeData);
{
XMLNode* node = pParent->FirstChildElement("m_childShapePtr");\
XMLNode* node = pParent->FirstChildElement("m_childShapePtr");
btAssert(node);
while (node)
{
@@ -355,13 +341,11 @@ void btBulletXmlWorldImporter::deSerializeCompoundShapeData(XMLNode* pParent)
node = node->NextSiblingElement("m_childShapePtr");
}
//SET_POINTER_VALUE(xmlColShape, *compoundData,m_childShapePtr,btCompoundShapeChildData*);
}
SET_FLOAT_VALUE(pParent, compoundData, m_collisionMargin);
m_collisionShapeData.push_back((btCollisionShapeData*)compoundData);
m_pointerLookup.insert(cast.m_ptr, compoundData);
}
void btBulletXmlWorldImporter::deSerializeStaticPlaneShapeData(XMLNode* pParent)
@@ -381,7 +365,6 @@ void btBulletXmlWorldImporter::deSerializeStaticPlaneShapeData(XMLNode* pParent)
m_collisionShapeData.push_back((btCollisionShapeData*)planeData);
m_pointerLookup.insert(cast.m_ptr, planeData);
}
void btBulletXmlWorldImporter::deSerializeDynamicsWorldData(XMLNode* pParent)
@@ -399,7 +382,6 @@ void btBulletXmlWorldImporter::deSerializeConvexInternalShapeData(XMLNode* pPare
MyLocalCaster cast;
get_int_attribute_by_name(pParent->ToElement(), "pointer", &cast.m_int);
btConvexInternalShapeData* convexShape = (btConvexInternalShapeData*)btAlignedAlloc(sizeof(btConvexInternalShapeData), 16);
memset(convexShape, 0, sizeof(btConvexInternalShapeData));
@@ -408,14 +390,12 @@ void btBulletXmlWorldImporter::deSerializeConvexInternalShapeData(XMLNode* pPare
deSerializeCollisionShapeData(xmlShapeData, &convexShape->m_collisionShapeData);
SET_FLOAT_VALUE(pParent, convexShape, m_collisionMargin)
SET_VECTOR4_VALUE(pParent, convexShape, m_localScaling)
SET_VECTOR4_VALUE(pParent, convexShape, m_implicitShapeDimensions)
m_collisionShapeData.push_back((btCollisionShapeData*)convexShape);
m_pointerLookup.insert(cast.m_ptr, convexShape);
}
/*
@@ -433,7 +413,6 @@ enum btTypedConstraintType
};
*/
void btBulletXmlWorldImporter::deSerializeGeneric6DofConstraintData(XMLNode* pParent)
{
MyLocalCaster cast;
@@ -441,7 +420,6 @@ void btBulletXmlWorldImporter::deSerializeGeneric6DofConstraintData(XMLNode* pPa
btGeneric6DofConstraintData2* dof6Data = (btGeneric6DofConstraintData2*)btAlignedAlloc(sizeof(btGeneric6DofConstraintData2), 16);
XMLNode* n = pParent->FirstChildElement("m_typeConstraintData");
if (n)
{
@@ -458,7 +436,6 @@ void btBulletXmlWorldImporter::deSerializeGeneric6DofConstraintData(XMLNode* pPa
SET_INT_VALUE(n, &dof6Data->m_typeConstraintData, m_overrideNumSolverIterations);
SET_FLOAT_VALUE(n, &dof6Data->m_typeConstraintData, m_breakingImpulseThreshold);
SET_INT_VALUE(n, &dof6Data->m_typeConstraintData, m_isEnabled);
}
SET_TRANSFORM_VALUE(pParent, dof6Data, m_rbAFrame);
@@ -516,7 +493,6 @@ void btBulletXmlWorldImporter::deSerializeRigidBodyFloatData(XMLNode* pParent)
SET_MATRIX33_VALUE(pParent, rbData, m_invInertiaTensorWorld);
SET_VECTOR4_VALUE(pParent, rbData, m_linearVelocity)
SET_VECTOR4_VALUE(pParent, rbData, m_angularVelocity)
SET_VECTOR4_VALUE(pParent, rbData, m_angularFactor)
@@ -537,7 +513,6 @@ void btBulletXmlWorldImporter::deSerializeRigidBodyFloatData(XMLNode* pParent)
SET_FLOAT_VALUE(pParent, rbData, m_linearSleepingThreshold);
SET_INT_VALUE(pParent, rbData, m_additionalDamping);
m_rigidBodyData.push_back(rbData);
m_pointerLookup.insert(cast.m_ptr, rbData);
@@ -607,15 +582,12 @@ void btBulletXmlWorldImporter::fixupConstraintData(btTypedConstraintData2* tcd)
btAssert(ptrptr);
tcd->m_rbB = ptrptr ? *ptrptr : 0;
}
}
void btBulletXmlWorldImporter::fixupCollisionDataPointers(btCollisionShapeData* shapeData)
{
switch (shapeData->m_shapeType)
{
case COMPOUND_SHAPE_PROXYTYPE:
{
btCompoundShapeData* compound = (btCompoundShapeData*)shapeData;
@@ -626,7 +598,8 @@ void btBulletXmlWorldImporter::fixupCollisionDataPointers(btCollisionShapeData*
if (c)
{
compound->m_childShapePtr = *c;
} else
}
else
{
compound->m_childShapePtr = 0;
}
@@ -641,7 +614,8 @@ void btBulletXmlWorldImporter::fixupCollisionDataPointers(btCollisionShapeData*
if (ptrptr)
{
convexData->m_unscaledPointsFloatPtr = *ptrptr;
} else
}
else
{
convexData->m_unscaledPointsFloatPtr = 0;
}
@@ -661,7 +635,6 @@ void btBulletXmlWorldImporter::fixupCollisionDataPointers(btCollisionShapeData*
}
}
void btBulletXmlWorldImporter::auto_serialize_root_level_children(XMLNode* pParent)
{
int numChildren = 0;
@@ -724,7 +697,6 @@ void btBulletXmlWorldImporter::auto_serialize_root_level_children(XMLNode* pPare
continue;
}
if (!strcmp(pChild->Value(), "btConvexInternalShapeData"))
{
deSerializeConvexInternalShapeData(pChild);
@@ -764,7 +736,6 @@ void btBulletXmlWorldImporter::auto_serialize_root_level_children(XMLNode* pPare
{
btCollisionShapeData* shapeData = m_collisionShapeData[i];
fixupCollisionDataPointers(shapeData);
}
///now fixup pointers
@@ -783,13 +754,10 @@ void btBulletXmlWorldImporter::auto_serialize_root_level_children(XMLNode* pPare
}
}
for (int i = 0; i < m_constraintData.size(); i++)
{
btTypedConstraintData2* tcd = m_constraintData[i];
fixupConstraintData(tcd);
}
///=================================================================
///convert data into Bullet data in the right order
@@ -845,7 +813,6 @@ void btBulletXmlWorldImporter::auto_serialize_root_level_children(XMLNode* pPare
btAssert(0); //todo
//convertConstraint(tcd,rbA,rbB,isDoublePrecision, m_fileVersion);
}
}
}
@@ -863,20 +830,17 @@ void btBulletXmlWorldImporter::auto_serialize(XMLNode* pParent)
auto_serialize_root_level_children(pChild);
}
}
} else
}
else
{
printf("ERROR: no bullet_physics element\n");
}
}
bool btBulletXmlWorldImporter::loadFile(const char* fileName)
{
XMLDocument doc;
XMLError loadOkay = doc.LoadFile(fileName);
if (loadOkay == XML_SUCCESS)
@@ -891,13 +855,8 @@ bool btBulletXmlWorldImporter::loadFile(const char* fileName)
auto_serialize(&doc);
return m_fileOk;
}
}
}
return false;
}

View File

@@ -39,17 +39,13 @@ struct btTypedConstraintFloatData;
#define btRigidBodyData btRigidBodyFloatData
#endif //BT_USE_DOUBLE_PRECISION
struct btCompoundShapeChildData;
#include "LinearMath/btAlignedObjectArray.h"
#include "btWorldImporter.h"
class btBulletXmlWorldImporter : public btWorldImporter
{
protected:
btAlignedObjectArray<btCollisionShapeData*> m_collisionShapeData;
btAlignedObjectArray<btAlignedObjectArray<btCompoundShapeChildData>*> m_compoundShapeChildDataArrays;
@@ -88,7 +84,6 @@ protected:
virtual ~btBulletXmlWorldImporter();
bool loadFile(const char* fileName);
};
#endif //BT_BULLET_XML_WORLD_IMPORTER_H

View File

@@ -34,9 +34,7 @@ namespace bullet_utils
str_array_free(strArray);
}
};
}; // namespace bullet_utils
/* Append an item to a dynamically allocated array of strings. On failure,
return NULL, in which case the original array is intact. The item
@@ -50,7 +48,8 @@ char **str_array_append(char **array, size_t nitems, const char *item,
char *copy;
if (item == NULL)
copy = NULL;
else {
else
{
copy = (char *)malloc(itemlen + 1);
if (copy == NULL)
return NULL;
@@ -62,7 +61,8 @@ char **str_array_append(char **array, size_t nitems, const char *item,
in case it did not yet exist. This might mean it is a teeny bit
too big, but we don't care. */
array = (char **)realloc(array, (nitems + 2) * sizeof(array[0]));
if (array == NULL) {
if (array == NULL)
{
free(copy);
return NULL;
}
@@ -73,7 +73,6 @@ char **str_array_append(char **array, size_t nitems, const char *item,
return array;
}
/* Free a dynamic array of dynamic strings. */
void str_array_free(char **array)
{
@@ -84,7 +83,6 @@ void str_array_free(char **array)
free(array);
}
/* Split a string into substrings. Return dynamic array of dynamically
allocated substrings, or NULL if there was an error. Caller is
expected to free the memory, for example with str_array_free. */
@@ -98,29 +96,37 @@ char **str_split(const char *input, const char *sep)
const char *item;
size_t itemlen;
for (;;) {
for (;;)
{
next = strstr(start, sep);
if (next == NULL) {
if (next == NULL)
{
/* Add the remaining string (or empty string, if input ends with
separator. */
char **newstr = str_array_append(array, nitems, start, strlen(start));
if (newstr == NULL) {
if (newstr == NULL)
{
str_array_free(array);
return NULL;
}
array = newstr;
++nitems;
break;
} else if (next == input) {
}
else if (next == input)
{
/* Input starts with separator. */
item = "";
itemlen = 0;
} else {
}
else
{
item = start;
itemlen = next - item;
}
char **newstr = str_array_append(array, nitems, item, itemlen);
if (newstr == NULL) {
if (newstr == NULL)
{
str_array_free(array);
return NULL;
}
@@ -129,7 +135,8 @@ char **str_split(const char *input, const char *sep)
start = next + seplen;
}
if (nitems == 0) {
if (nitems == 0)
{
/* Input does not contain separator at all. */
assert(array == NULL);
array = str_array_append(array, nitems, input, strlen(input));
@@ -138,7 +145,6 @@ char **str_split(const char *input, const char *sep)
return array;
}
/* Return length of a NULL-delimited array of strings. */
size_t str_array_len(char **array)
{
@@ -153,10 +159,10 @@ size_t str_array_len(char **array)
#define MAX_OUTPUT 20
int main(void)
{
struct {
struct
{
const char *input;
const char *sep;
char *output[MAX_OUTPUT];
@@ -208,11 +214,13 @@ int main(void)
errors = false;
for (int i = 0; i < tab_len; ++i) {
for (int i = 0; i < tab_len; ++i)
{
printf("test %d\n", i);
char **output = str_split(tab[i].input, tab[i].sep);
if (output == NULL) {
if (output == NULL)
{
fprintf(stderr, "output is NULL\n");
errors = true;
break;
@@ -221,13 +229,18 @@ int main(void)
printf("num_output %lu\n", (unsigned long)num_output);
size_t num_correct = str_array_len(tab[i].output);
if (num_output != num_correct) {
if (num_output != num_correct)
{
fprintf(stderr, "wrong number of outputs (%lu, not %lu)\n",
(unsigned long)num_output, (unsigned long)num_correct);
errors = true;
} else {
for (size_t j = 0; j < num_output; ++j) {
if (strcmp(tab[i].output[j], output[j]) != 0) {
}
else
{
for (size_t j = 0; j < num_output; ++j)
{
if (strcmp(tab[i].output[j], output[j]) != 0)
{
fprintf(stderr, "output[%lu] is '%s' not '%s'\n",
(unsigned long)j, output[j], tab[i].output[j]);
errors = true;
@@ -246,5 +259,3 @@ int main(void)
}
#endif //

View File

@@ -16,7 +16,6 @@ subject to the following restrictions:
///The string split C code is by Lars Wirzenius
///See http://stackoverflow.com/questions/2531605/how-to-split-a-string-with-a-delimiter-larger-than-one-single-char
#ifndef STRING_SPLIT_H
#define STRING_SPLIT_H
@@ -33,7 +32,6 @@ namespace bullet_utils
///The string split C code is by Lars Wirzenius
///See http://stackoverflow.com/questions/2531605/how-to-split-a-string-with-a-delimiter-larger-than-one-single-char
/* Split a string into substrings. Return dynamic array of dynamically
allocated substrings, or NULL if there was an error. Caller is
expected to free the memory, for example with str_array_free. */
@@ -46,4 +44,3 @@ void str_array_free(char** array);
size_t str_array_len(char** array);
#endif //STRING_SPLIT_H

View File

@@ -36,13 +36,11 @@ typedef std::map<bString, bString> bStringMap;
typedef std::vector<class bVariable> bVariableList;
typedef std::vector<bString> bStringList;
///////////////////////////////////////////////////////////////////////////////
static FILE *dump = 0;
static bDNA *mDNA = 0;
static bStringMap mStructs;
///////////////////////////////////////////////////////////////////////////////
class bVariable
{
@@ -50,11 +48,9 @@ public:
bVariable();
~bVariable();
bString dataType;
bString variableName;
bString functionName;
bString classCtor;
@@ -62,7 +58,6 @@ public:
bString memberDataType;
bString functionArgs;
void initialize(bString dataType, bString variable, bStringMap refDataTable);
bool isPtr;
@@ -114,7 +109,6 @@ void writeTemplate(short *structData)
bVariableList dataTypes;
bStringMap includeFiles;
for (int dataVal = 0; dataVal < thisLen; dataVal++, structData += 2)
{
bString dataType = mDNA->getType(structData[0]);
@@ -148,7 +142,6 @@ void writeTemplate(short *structData)
if (dataName[0] != '*')
{
}
}
}
@@ -160,7 +153,6 @@ void writeTemplate(short *structData)
}
}
bStringMap::iterator include = mStructs.find(dataType);
if (include != mStructs.end())
{
@@ -174,7 +166,6 @@ void writeTemplate(short *structData)
}
}
fprintf(dump, "###############################################################\n");
fprintf(dump, "%s = bStructClass()\n", fileName.c_str());
fprintf(dump, "%s.name = '%s'\n", fileName.c_str(), className.c_str());
@@ -196,7 +187,6 @@ void writeTemplate(short *structData)
fprintf(dump, "DataTypeList.append(%s)\n", fileName.c_str());
}
///////////////////////////////////////////////////////////////////////////////
char data[] = {
"\n"
@@ -207,9 +197,7 @@ char data[]={
" self.includes = []\n"
" self.dataTypes = []\n"
"\n\n"
"DataTypeList = []\n"
};
"DataTypeList = []\n"};
///////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
@@ -217,11 +205,9 @@ int main(int argc,char** argv)
using namespace bParse;
dump = fopen("dump.py", "w");
if (!dump) return 0;
fprintf(dump, "%s\n", data);
#if 0
char* filename = "../../../../data/r2d2_multibody.bullet";
@@ -279,7 +265,6 @@ int main(int argc,char** argv)
int len = sBulletDNAlen;
#endif
char *blenderData = memBuf;
int sdnaPos = 0;
int mDataStart = 12;
@@ -299,8 +284,6 @@ int main(int argc,char** argv)
tempBuffer++;
}
FILE *fpdna = fopen("dnaString.txt", "w");
char buf[1024];
@@ -311,26 +294,22 @@ int main(int argc,char** argv)
if ((i % 32) == 0)
{
sprintf(buf, "%d,\n", dnaval);
} else
}
else
{
sprintf(buf, "%d,", dnaval);
}
fwrite(buf, strlen(buf), 1, fpdna);
}
fclose(fpdna);
mDNA = new bDNA();
//mDNA->initMemory();
mDNA->init(memBuf + sdnaPos, len - sdnaPos, swap);
for (int i = 0; i < mDNA->getNumStructs(); i++)
{
short *structData = mDNA->getStruct(i);
@@ -340,7 +319,6 @@ int main(int argc,char** argv)
mStructs[type] = className;
}
for (int i = 0; i < mDNA->getNumStructs(); i++)
{
short *structData = mDNA->getStruct(i);
@@ -353,7 +331,6 @@ int main(int argc,char** argv)
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
int _getArraySize(char *str)
{
@@ -397,7 +374,6 @@ bVariable::bVariable()
{
}
///////////////////////////////////////////////////////////////////////////////
bVariable::~bVariable()
{
@@ -405,7 +381,6 @@ bVariable::~bVariable()
variableName.clear();
}
///////////////////////////////////////////////////////////////////////////////
void bVariable::initialize(bString type, bString variable, bStringMap refDataTable)
{
@@ -441,7 +416,6 @@ void bVariable::initialize(bString type, bString variable, bStringMap refDataTab
if (dataType[0] == '/' && dataType[1] == '/')
isCommentedOut = true;
if (refDataTable.find(dataType) != refDataTable.end())
isGeneratedType = true;

View File

@@ -85,11 +85,8 @@ void btBulletDataExtractor::convertAllObjects(bParse::btBulletFile* bulletFile2)
printf("converting shape %s\n", shapeData->m_name);
void* shape = convertCollisionShape(shapeData);
}
}
void* btBulletDataExtractor::convertCollisionShape(btCollisionShapeData* shapeData)
{
void* shape = 0;
@@ -321,7 +318,6 @@ void* btBulletDataExtractor::convertCollisionShape( btCollisionShapeData* shape
}
return shape;
}
void* btBulletDataExtractor::createBoxShape(const Bullet::btVector3FloatData& halfDimensions, const Bullet::btVector3FloatData& localScaling, float collisionMargin)
@@ -336,10 +332,8 @@ void* btBulletDataExtractor::createSphereShape( float radius, const Bullet::btVe
return 0;
}
void* btBulletDataExtractor::createPlaneShape(const btVector3FloatData& planeNormal, float planeConstant, const Bullet::btVector3FloatData& localScaling)
{
printf("createPlaneShape with normal %f,%f,%f and planeConstant\n", planeNormal.m_floats[0], planeNormal.m_floats[1], planeNormal.m_floats[2], planeConstant);
return 0;
}

View File

@@ -1,7 +1,6 @@
#ifndef BULLET_DATA_EXTRACTOR_H
#define BULLET_DATA_EXTRACTOR_H
#include "../BulletFileLoader/autogenerated/bullet.h"
namespace bParse
@@ -12,7 +11,6 @@ namespace bParse
class btBulletDataExtractor
{
public:
btBulletDataExtractor();
virtual ~btBulletDataExtractor();
@@ -26,7 +24,6 @@ class btBulletDataExtractor
virtual void* createBoxShape(const Bullet::btVector3FloatData& halfDimensions, const Bullet::btVector3FloatData& localScaling, float collisionMargin);
virtual void* createSphereShape(float radius, const Bullet::btVector3FloatData& localScaling, float collisionMargin);
};
#endif //BULLET_DATA_EXTRACTOR_H

View File

@@ -13,7 +13,6 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
#include <stdio.h>
#include "../BulletFileLoader/btBulletFile.h"
#include "BulletDataExtractor.h"
@@ -51,7 +50,6 @@ int main(int argc, char** argv)
bulletFile2->dumpChunks(bulletFile2->getFileDNA());
}
btBulletDataExtractor extractor;
extractor.convertAllObjects(bulletFile2);
@@ -60,4 +58,3 @@ int main(int argc, char** argv)
return 0;
}

View File

@@ -2,7 +2,6 @@
#ifndef DNA_RIGIDBODY_H
#define DNA_RIGIDBODY_H
struct PointerArray
{
int m_size;
@@ -10,7 +9,6 @@ struct PointerArray
void *m_data;
};
struct btPhysicsSystem
{
PointerArray m_collisionShapes;
@@ -25,5 +23,4 @@ struct ListBase
void *last;
};
#endif

View File

@@ -49,9 +49,9 @@
* numbers give more output.
* */
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
#if defined(_WIN32) && !defined(FREE_WINDOWS)
@@ -80,8 +80,6 @@ typedef unsigned __int64 uint64_t;
typedef intptr_t btintptr_t;
#endif
#elif defined(__linux__) || defined(__NetBSD__)
/* Linux-i386, Linux-Alpha, Linux-ppc */
@@ -108,7 +106,6 @@ typedef intptr_t btintptr_t;
}
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -205,8 +202,7 @@ char *includefiles[] = {
"../../../src/BulletDynamics/Featherstone/btMultiBody.h",
"../../../src/BulletDynamics/Featherstone/btMultiBodyLinkCollider.h",
// empty string to indicate end of includefiles
""
};
""};
void *malloc_and_setzero(int numbytes)
{
@@ -288,8 +284,6 @@ void dna_write(FILE *file, void *pntr, int size);
*/
void printStructLenghts(void);
/* ************************************************************************** */
/* Implementation */
/* ************************************************************************** */
@@ -304,9 +298,12 @@ int add_type(char *str, int len)
if (str[0] == 0) return -1;
/* search through type array */
for(nr=0; nr<nr_types; nr++) {
if(strcmp(str, types[nr])==0) {
if (len) {
for (nr = 0; nr < nr_types; nr++)
{
if (strcmp(str, types[nr]) == 0)
{
if (len)
{
typelens[nr] = len;
alphalens[nr] = len;
}
@@ -315,8 +312,10 @@ int add_type(char *str, int len)
}
/* append new type */
if(nr_types==0) cp= typedata;
else {
if (nr_types == 0)
cp = typedata;
else
{
cp = types[nr_types - 1] + strlen(types[nr_types - 1]) + 1;
}
strcpy(cp, str);
@@ -324,9 +323,11 @@ int add_type(char *str, int len)
typelens[nr_types] = len;
alphalens[nr_types] = len;
if(nr_types>=maxnr) {
if (nr_types >= maxnr)
{
printf("too many types\n");
return nr_types-1;;
return nr_types - 1;
;
}
nr_types++;
@@ -352,13 +353,15 @@ int add_name(char *str)
if ((str[0] == 0) /* || (str[1]==0) */) return -1;
if (str[0] == '(' && str[1] == '*') {
if (str[0] == '(' && str[1] == '*')
{
if (debugSDNA > 3) printf("\t\t\t\t*** Function pointer found\n");
/* functionpointer: transform the type (sometimes) */
i = 0;
j = 0;
while (str[i] != ')') {
while (str[i] != ')')
{
buf[i] = str[i];
i++;
}
@@ -371,27 +374,34 @@ int add_name(char *str)
if (debugSDNA > 3) printf("first brace after offset %d\n", i);
j++; /* j beyond closing brace ? */
while ((str[j] != 0) && (str[j] != ')' )) {
while ((str[j] != 0) && (str[j] != ')'))
{
if (debugSDNA > 3) printf("seen %c ( %d) \n", str[j], str[j]);
j++;
}
if (debugSDNA > 3) printf("seen %c ( %d) \n", str[j], str[j]);
if (debugSDNA > 3) printf("special after offset %d\n", j);
if (str[j] == 0 ) {
if (str[j] == 0)
{
if (debugSDNA > 3) printf("offsetting for space\n");
/* get additional offset */
k = 0;
while (str[j] != ')') {
while (str[j] != ')')
{
j++;
k++;
}
if (debugSDNA > 3) printf("extra offset %d\n", k);
additional_slen_offset = k;
} else if (str[j] == ')' ) {
}
else if (str[j] == ')')
{
if (debugSDNA > 3) printf("offsetting for brace\n");
; /* don't get extra offset */
} else {
}
else
{
printf("Error during tokening function pointer argument list\n");
}
@@ -409,8 +419,8 @@ int add_name(char *str)
* */
buf[i] = 0;
if (debugSDNA > 3) printf("Name before chomping: %s\n", buf);
if ( (strncmp(buf,"(*headdraw", 10) == 0)
|| (strncmp(buf,"(*windraw", 9) == 0) ) {
if ((strncmp(buf, "(*headdraw", 10) == 0) || (strncmp(buf, "(*windraw", 9) == 0))
{
buf[i] = ')';
buf[i + 1] = '(';
buf[i + 2] = 'v';
@@ -419,7 +429,9 @@ int add_name(char *str)
buf[i + 5] = 'd';
buf[i + 6] = ')';
buf[i + 7] = 0;
} else {
}
else
{
buf[i] = ')';
buf[i + 1] = '(';
buf[i + 2] = ')';
@@ -428,27 +440,34 @@ int add_name(char *str)
/* now precede with buf*/
if (debugSDNA > 3) printf("\t\t\t\t\tProposing fp name %s\n", buf);
name = buf;
} else {
}
else
{
/* normal field: old code */
name = str;
}
/* search name array */
for(nr=0; nr<nr_names; nr++) {
if(strcmp(name, names[nr])==0) {
for (nr = 0; nr < nr_names; nr++)
{
if (strcmp(name, names[nr]) == 0)
{
return nr;
}
}
/* append new type */
if(nr_names==0) cp= namedata;
else {
if (nr_names == 0)
cp = namedata;
else
{
cp = names[nr_names - 1] + strlen(names[nr_names - 1]) + 1;
}
strcpy(cp, name);
names[nr_names] = cp;
if(nr_names>=maxnr) {
if (nr_names >= maxnr)
{
printf("too many names\n");
return nr_names - 1;
}
@@ -462,10 +481,12 @@ short *add_struct(int namecode)
int len;
short *sp;
if(nr_structs==0) {
if (nr_structs == 0)
{
structs[0] = structdata;
}
else {
else
{
sp = structs[nr_structs - 1];
len = sp[1];
structs[nr_structs] = sp + 2 * len + 2;
@@ -474,7 +495,8 @@ short *add_struct(int namecode)
sp = structs[nr_structs];
sp[0] = namecode;
if(nr_structs>=maxnr) {
if (nr_structs >= maxnr)
{
printf("too many structs\n");
return sp;
}
@@ -496,39 +518,48 @@ int preprocess_include(char *maindata, int len)
cp = temp;
a = len;
comment = 0;
while(a--) {
if(cp[0]=='/' && cp[1]=='/') {
while (a--)
{
if (cp[0] == '/' && cp[1] == '/')
{
comment = 1;
} else if (*cp<32) {
}
else if (*cp < 32)
{
comment = 0;
}
if (comment || *cp < 32 || *cp > 128) *cp = 32;
cp++;
}
/* data from temp copy to maindata, remove comments and double spaces */
cp = temp;
md = maindata;
newlen = 0;
comment = 0;
a = len;
while(a--) {
if(cp[0]=='/' && cp[1]=='*') {
while (a--)
{
if (cp[0] == '/' && cp[1] == '*')
{
comment = 1;
cp[0] = cp[1] = 32;
}
if(cp[0]=='*' && cp[1]=='/') {
if (cp[0] == '*' && cp[1] == '/')
{
comment = 0;
cp[0] = cp[1] = 32;
}
/* do not copy when: */
if(comment);
else if( cp[0]==' ' && cp[1]==' ' );
else if( cp[-1]=='*' && cp[0]==' ' ); /* pointers with a space */
else {
if (comment)
;
else if (cp[0] == ' ' && cp[1] == ' ')
;
else if (cp[-1] == '*' && cp[0] == ' ')
; /* pointers with a space */
else
{
md[0] = cp[0];
md++;
newlen++;
@@ -549,7 +580,8 @@ static void *read_file_data(char *filename, int *len_r)
#endif
void *data;
if (!fp) {
if (!fp)
{
*len_r = -1;
return NULL;
}
@@ -559,13 +591,15 @@ static void *read_file_data(char *filename, int *len_r)
fseek(fp, 0L, SEEK_SET);
data = malloc_and_setzero(*len_r);
if (!data) {
if (!data)
{
*len_r = -1;
fclose(fp);
return NULL;
}
if (fread(data, *len_r, 1, fp)!=1) {
if (fread(data, *len_r, 1, fp) != 1)
{
*len_r = -1;
free(data);
fclose(fp);
@@ -576,7 +610,6 @@ static void *read_file_data(char *filename, int *len_r)
return data;
}
const char *skipStructTypes[] =
{
"btContactSolverInfoData",
@@ -585,8 +618,7 @@ const char* skipStructTypes[]=
"btConstraintInfo2",
"btConstraintSetting",
"btTriangleInfo",
""
};
""};
int skipStruct(const char *structType)
{
@@ -612,7 +644,8 @@ int convert_include(char *filename)
char *maindata, *mainend, *md, *md1;
md = maindata = (char *)read_file_data(filename, &filelen);
if (filelen==-1) {
if (filelen == -1)
{
printf("Can't read file %s\n", filename);
return 1;
}
@@ -623,28 +656,31 @@ int convert_include(char *filename)
/* we look for '{' and then back to 'struct' */
count = 0;
overslaan = 0;
while(count<filelen) {
while (count < filelen)
{
/* code for skipping a struct: two hashes on 2 lines. (preprocess added a space) */
if(md[0]=='#' && md[1]==' ' && md[2]=='#') {
if (md[0] == '#' && md[1] == ' ' && md[2] == '#')
{
overslaan = 1;
}
if(md[0]=='{') {
if (md[0] == '{')
{
md[0] = 0;
if(overslaan) {
if (overslaan)
{
overslaan = 0;
}
else {
else
{
if (md[-1] == ' ') md[-1] = 0;
md1 = md - 2;
while (*md1 != 32) md1--; /* to beginning of word */
md1++;
/* we've got a struct name when... */
if( strncmp(md1-7, "struct", 6)==0 ) {
if (strncmp(md1 - 7, "struct", 6) == 0)
{
if (!skipStruct(md1))
{
strct = add_type(md1, 0);
@@ -655,7 +691,8 @@ int convert_include(char *filename)
/* first lets make it all nice strings */
md1 = md + 1;
while(*md1 != '}') {
while (*md1 != '}')
{
if (md1 > mainend) break;
if (*md1 == ',' || *md1 == ' ') *md1 = 0;
@@ -664,11 +701,13 @@ int convert_include(char *filename)
/* read types and names until first character that is not '}' */
md1 = md + 1;
while( *md1 != '}' ) {
while (*md1 != '}')
{
if (md1 > mainend) break;
/* skip when it says 'struct' or 'unsigned' or 'const' */
if(*md1) {
if (*md1)
{
if (strncmp(md1, "struct", 6) == 0) md1 += 7;
if (strncmp(md1, "unsigned", 8) == 0) md1 += 9;
if (strncmp(md1, "const", 5) == 0) md1 += 6;
@@ -680,20 +719,21 @@ int convert_include(char *filename)
md1 += strlen(md1);
/* read until ';' */
while( *md1 != ';' ) {
while (*md1 != ';')
{
if (md1 > mainend) break;
if(*md1) {
if (*md1)
{
/* We've got a name. slen needs
* correction for function
* pointers! */
slen = (int)strlen(md1);
if( md1[slen-1]==';' ) {
if (md1[slen - 1] == ';')
{
md1[slen - 1] = 0;
name = add_name(md1);
slen += additional_slen_offset;
sp[0] = type;
@@ -708,7 +748,6 @@ int convert_include(char *filename)
break;
}
name = add_name(md1);
slen += additional_slen_offset;
@@ -725,7 +764,6 @@ int convert_include(char *filename)
}
if (debugSDNA > 1) printf(")\n");
}
md1++;
}
@@ -749,11 +787,14 @@ int arraysize(char *astr, int len)
memcpy(str, astr, len + 1);
for(a=0; a<len; a++) {
if( str[a]== '[' ) {
for (a = 0; a < len; a++)
{
if (str[a] == '[')
{
cp = &(str[a + 1]);
}
else if( str[a]==']' && cp) {
else if (str[a] == ']' && cp)
{
str[a] = 0;
mul *= atoi(cp);
}
@@ -769,110 +810,131 @@ static int calculate_structlens(int firststruct)
char *cp;
int has_pointer, dna_error = 0;
while(unknown) {
while (unknown)
{
lastunknown = unknown;
unknown = 0;
/* check all structs... */
for(a=0; a<nr_structs; a++) {
for (a = 0; a < nr_structs; a++)
{
structpoin = structs[a];
structtype = structpoin[0];
/* when length is not known... */
if(typelens[structtype]==0) {
if (typelens[structtype] == 0)
{
sp = structpoin + 2;
len = 0;
alphalen = 0;
has_pointer = 0;
/* check all elements in struct */
for(b=0; b<structpoin[1]; b++, sp+=2) {
for (b = 0; b < structpoin[1]; b++, sp += 2)
{
type = sp[0];
cp = names[sp[1]];
namelen = (int)strlen(cp);
/* is it a pointer or function pointer? */
if(cp[0]=='*' || cp[1]=='*') {
if (cp[0] == '*' || cp[1] == '*')
{
has_pointer = 1;
/* has the name an extra length? (array) */
mul = 1;
if (cp[namelen - 1] == ']') mul = arraysize(cp, namelen);
/* 4-8 aligned/ */
if(sizeof(void *) == 4) {
if (len % 4) {
if (sizeof(void *) == 4)
{
if (len % 4)
{
printf("Align pointer error in struct (len4): %s %s\n", types[structtype], cp);
dna_error = 1;
}
} else {
if (len % 8) {
}
else
{
if (len % 8)
{
printf("Align pointer error in struct (len8): %s %s\n", types[structtype], cp);
dna_error = 1;
}
}
if (alphalen % 8) {
if (alphalen % 8)
{
printf("Align pointer error in struct (alphalen8): %s %s\n", types[structtype], cp);
dna_error = 1;
}
len += sizeof(void *) * mul;
alphalen += 8 * mul;
} else if( typelens[type] ) {
}
else if (typelens[type])
{
/* has the name an extra length? (array) */
mul = 1;
if (cp[namelen - 1] == ']') mul = arraysize(cp, namelen);
/* struct alignment */
if(type >= firststruct) {
if(sizeof(void *)==8 && (len % 8) ) {
if (type >= firststruct)
{
if (sizeof(void *) == 8 && (len % 8))
{
printf("Align struct error: %s %s\n", types[structtype], cp);
dna_error = 1;
}
}
/* 2-4 aligned/ */
if(typelens[type]>3 && (len % 4) ) {
if (typelens[type] > 3 && (len % 4))
{
printf("Align 4 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len % 4);
dna_error = 1;
}
else if(typelens[type]==2 && (len % 2) ) {
else if (typelens[type] == 2 && (len % 2))
{
printf("Align 2 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len % 2);
dna_error = 1;
}
len += mul * typelens[type];
alphalen += mul * alphalens[type];
} else {
}
else
{
len = 0;
alphalen = 0;
break;
}
}
if (len==0) {
if (len == 0)
{
unknown++;
} else {
}
else
{
typelens[structtype] = len;
alphalens[structtype] = alphalen;
// two ways to detect if a struct contains a pointer:
// has_pointer is set or alphalen != len
if (has_pointer || alphalen != len) {
if (alphalen % 8) {
if (has_pointer || alphalen != len)
{
if (alphalen % 8)
{
printf("alphalen = %d len = %d\n", alphalen, len);
printf("Sizeerror 8 in struct: %s (add %d bytes)\n", types[structtype], alphalen % 8);
dna_error = 1;
}
}
if(len % 4) {
if (len % 4)
{
printf("Sizeerror 4 in struct: %s (add %d bytes)\n", types[structtype], len % 4);
dna_error = 1;
}
}
}
}
@@ -880,32 +942,37 @@ static int calculate_structlens(int firststruct)
if (unknown == lastunknown) break;
}
if(unknown) {
if (unknown)
{
printf("ERROR: still %d structs unknown\n", unknown);
if (debugSDNA) {
if (debugSDNA)
{
printf("*** Known structs : \n");
for(a=0; a<nr_structs; a++) {
for (a = 0; a < nr_structs; a++)
{
structpoin = structs[a];
structtype = structpoin[0];
/* length unknown */
if(typelens[structtype]!=0) {
if (typelens[structtype] != 0)
{
printf(" %s\n", types[structtype]);
}
}
}
printf("*** Unknown structs : \n");
for(a=0; a<nr_structs; a++) {
for (a = 0; a < nr_structs; a++)
{
structpoin = structs[a];
structtype = structpoin[0];
/* length unkown yet */
if(typelens[structtype]==0) {
if (typelens[structtype] == 0)
{
printf(" %s\n", types[structtype]);
}
}
@@ -914,7 +981,6 @@ static int calculate_structlens(int firststruct)
return (dna_error);
}
#define MAX_DNA_LINE_LENGTH 20
void dna_write(FILE *file, void *pntr, int size)
@@ -929,7 +995,8 @@ void dna_write(FILE *file, void *pntr, int size)
{
fprintf(file, "char(%d),", data[i]);
linelength++;
if (linelength >= MAX_DNA_LINE_LENGTH) {
if (linelength >= MAX_DNA_LINE_LENGTH)
{
fprintf(file, "\n");
linelength = 0;
}
@@ -942,12 +1009,14 @@ void printStructLenghts(void)
short *structpoin;
printf("\n\n*** All detected structs:\n");
while(unknown) {
while (unknown)
{
lastunknown = unknown;
unknown = 0;
/* check all structs... */
for(a=0; a<nr_structs; a++) {
for (a = 0; a < nr_structs; a++)
{
structpoin = structs[a];
structtype = structpoin[0];
printf("\t%s\t:%d\n", types[structtype], typelens[structtype]);
@@ -955,10 +1024,8 @@ void printStructLenghts(void)
}
printf("*** End of list\n");
}
int make_structDNA(char *baseDirectory, FILE *file)
{
int len, i;
@@ -968,10 +1035,10 @@ int make_structDNA(char *baseDirectory, FILE *file)
char str[SDNA_MAX_FILENAME_LENGTH], *cp;
int firststruct;
if (debugSDNA > -1) {
if (debugSDNA > -1)
{
fflush(stdout);
printf("Running makesdna at debug level %d\n", debugSDNA);
}
/* the longest known struct is 50k, so we assume 100k is sufficent! */
@@ -1007,21 +1074,23 @@ int make_structDNA(char *baseDirectory, FILE *file)
/* little test first... */
/* Mind the breaking condition here! */
if (debugSDNA) printf("\tStart of header scan:\n");
for (i = 0; strlen(includefiles[i]); i++) {
for (i = 0; strlen(includefiles[i]); i++)
{
sprintf(str, "%s%s", baseDirectory, includefiles[i]);
if (debugSDNA) printf("\t|-- Converting %s\n", str);
if (convert_include(str)) {
if (convert_include(str))
{
return (1);
}
}
if (debugSDNA) printf("\tFinished scanning %d headers.\n", i);
if (calculate_structlens(firststruct)) {
if (calculate_structlens(firststruct))
{
// error
return (1);
}
/* FOR DEBUG */
if (debugSDNA > 1)
{
@@ -1030,24 +1099,28 @@ int make_structDNA(char *baseDirectory, FILE *file)
short num_types;
printf("nr_names %d nr_types %d nr_structs %d\n", nr_names, nr_types, nr_structs);
for(a=0; a<nr_names; a++) {
for (a = 0; a < nr_names; a++)
{
printf(" %s \n", names[a]);
}
printf("\n");
sp = typelens;
for(a=0; a<nr_types; a++, sp++) {
for (a = 0; a < nr_types; a++, sp++)
{
printf(" %s %d\n", types[a], *sp);
}
printf("\n");
for(a=0; a<nr_structs; a++) {
for (a = 0; a < nr_structs; a++)
{
sp = structs[a];
printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], typelens[sp[0]]);
num_types = sp[1];
sp += 2;
/* ? num_types was elem? */
for(b=0; b< num_types; b++, sp+= 2) {
for (b = 0; b < num_types; b++, sp += 2)
{
printf(" %s %s\n", types[sp[0]], names[sp[1]]);
}
}
@@ -1057,8 +1130,10 @@ int make_structDNA(char *baseDirectory, FILE *file)
if (debugSDNA > -1) printf("Writing file ... ");
if(nr_names==0 || nr_structs==0);
else {
if (nr_names == 0 || nr_structs == 0)
;
else
{
strcpy(str, "SDNA");
dna_write(file, str, 4);
@@ -1112,24 +1187,29 @@ int make_structDNA(char *baseDirectory, FILE *file)
dna_write(file, structs[0], len);
/* a simple dna padding test */
if (0) {
if (0)
{
FILE *fp;
int a;
fp = fopen("padding.c", "w");
if(fp==NULL);
else {
if (fp == NULL)
;
else
{
// add all include files defined in the global array
for (i = 0; strlen(includefiles[i]); i++) {
for (i = 0; strlen(includefiles[i]); i++)
{
fprintf(fp, "#include \"%s%s\"\n", baseDirectory, includefiles[i]);
}
fprintf(fp, "main(){\n");
sp = typelens;
sp += firststruct;
for(a=firststruct; a<nr_types; a++, sp++) {
if(*sp) {
for (a = firststruct; a < nr_types; a++, sp++)
{
if (*sp)
{
fprintf(fp, "\tif(sizeof(struct %s) - %d) printf(\"ALIGN ERROR:", types[a], *sp);
fprintf(fp, "%%d %s %d ", types[a], *sp);
fprintf(fp, "\\n\", sizeof(struct %s) - %d);\n", types[a], *sp);
@@ -1142,7 +1222,6 @@ int make_structDNA(char *baseDirectory, FILE *file)
/* end end padding test */
}
free(namedata);
free(typedata);
free(structdata);
@@ -1210,42 +1289,56 @@ int main(int argc, char ** argv)
FILE *file;
int return_status = 0;
if (argc!=2 && argc!=3) {
if (argc != 2 && argc != 3)
{
printf("Usage: %s outfile.c [base directory]\n", argv[0]);
return_status = 1;
} else {
}
else
{
file = fopen(argv[1], "w");
if (!file) {
if (!file)
{
printf("Unable to open file: %s\n", argv[1]);
return_status = 1;
} else {
}
else
{
char baseDirectory[256];
if (argc==3) {
if (argc == 3)
{
strcpy(baseDirectory, argv[2]);
} else {
}
else
{
strcpy(baseDirectory, BASE_HEADER);
}
if (sizeof(void *) == 8)
{
fprintf(file, "char sBulletDNAstr64[]= {\n");
} else
}
else
{
fprintf(file, "char sBulletDNAstr[]= {\n");
}
if (make_structDNA(baseDirectory, file)) {
if (make_structDNA(baseDirectory, file))
{
// error
fclose(file);
make_bad_file(argv[1]);
return_status = 1;
} else {
}
else
{
fprintf(file, "};\n");
if (sizeof(void *) == 8)
{
fprintf(file, "int sBulletDNAlen64= sizeof(sBulletDNAstr64);\n");
} else
}
else
{
fprintf(file, "int sBulletDNAlen= sizeof(sBulletDNAstr);\n");
}
@@ -1255,9 +1348,7 @@ int main(int argc, char ** argv)
}
}
return (return_status);
}
/* end of list */

Some files were not shown because too many files have changed in this diff Show More