17#ifndef BT_SPARSE_SDF_H
18#define BT_SPARSE_SDF_H
25#if !defined(get16bits)
26#define get16bits(d) ((((unsigned int)(((const unsigned char*)(d))[1])) << 8) + (unsigned int)(((const unsigned char*)(d))[0]))
42 data += 2 *
sizeof(
unsigned short);
57template <const
int CELLSIZE>
71 btScalar d[CELLSIZE + 1][CELLSIZE + 1][CELLSIZE + 1];
100 void Initialize(
int hashsize = 2383,
int clampCells = 256 * 1024)
105 cells.resize(hashsize, 0);
118 for (
int i = 0, ni =
cells.size();
i < ni; ++
i)
138 const int life =
puid - lifetime;
139 for (
int i = 0;
i <
cells.size(); ++
i)
171 for (
int i = 0;
i <
cells.size(); ++
i)
206 const unsigned h =
Hash(ix.
b, iy.
b, iz.
b, shape);
213 if ((c->
hash == h) &&
236 static int numResets = 0;
254 const int o[] = {ix.
i, iy.
i, iz.
i};
255 const btScalar d[] = {c->
d[o[0] + 0][o[1] + 0][o[2] + 0],
256 c->
d[o[0] + 1][o[1] + 0][o[2] + 0],
257 c->
d[o[0] + 1][o[1] + 1][o[2] + 0],
258 c->
d[o[0] + 0][o[1] + 1][o[2] + 0],
259 c->
d[o[0] + 0][o[1] + 0][o[2] + 1],
260 c->
d[o[0] + 1][o[1] + 0][o[2] + 1],
261 c->
d[o[0] + 1][o[1] + 1][o[2] + 1],
262 c->
d[o[0] + 0][o[1] + 1][o[2] + 1]};
265 const btScalar gx[] = {d[1] - d[0], d[2] - d[3],
266 d[5] - d[4], d[6] - d[7]};
267 const btScalar gy[] = {d[3] - d[0], d[2] - d[1],
268 d[7] - d[4], d[6] - d[5]};
269 const btScalar gz[] = {d[4] - d[0], d[5] - d[1],
270 d[7] - d[3], d[6] - d[2]};
271 normal.setX(
Lerp(
Lerp(gx[0], gx[1], iy.
f),
272 Lerp(gx[2], gx[3], iy.
f), iz.
f));
273 normal.setY(
Lerp(
Lerp(gy[0], gy[1], ix.
f),
274 Lerp(gy[2], gy[3], ix.
f), iz.
f));
275 normal.setZ(
Lerp(
Lerp(gz[0], gz[1], ix.
f),
276 Lerp(gz[2], gz[3], ix.
f), iy.
f));
277 normal.safeNormalize();
279 normal =
btVector3(d[1] - d[0], d[3] - d[0], d[4] - d[0]).normalized();
283 Lerp(d[3], d[2], ix.
f), iy.
f);
285 Lerp(d[7], d[6], ix.
f), iy.
f);
286 return (
Lerp(d0, d1, iz.
f) - margin);
295 for (
int k = 0; k <= CELLSIZE; ++k)
298 for (
int j = 0; j <= CELLSIZE; ++j)
301 for (
int i = 0;
i <= CELLSIZE; ++
i)
316 if (shape->isConvex())
331 const int o =
x < 0 ? (int)(-
x + 1) : 0;
343 return (a + (
b - a) * t);
363 myset.p = (
void*)shape;
364 const char*
ptr = (
const char*)&myset;
BMesh const char void * data
btCollisionShape
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
btConvexShape()
not supported on IBM SDK, until we fix the alignment of btVector3
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
unsigned int HsiehHash(const char *data, int len)
#define get16bits(d)
btSparseSdf implementation by Nathanael Presson
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
static btScalar SignedDistance(const btVector3 &position, btScalar margin, const btConvexShape *shape, const btTransform &wtrs, sResults &results)
const btCollisionShape * pclient
btScalar d[CELLSIZE+1][CELLSIZE+1][CELLSIZE+1]
void GarbageCollect(int lifetime=256)
static IntFrac Decompose(btScalar x)
static btScalar DistanceToShape(const btVector3 &x, const btCollisionShape *shape)
int RemoveReferences(btCollisionShape *pcs)
btScalar m_defaultVoxelsz
btAlignedObjectArray< Cell * > cells
btScalar Evaluate(const btVector3 &x, const btCollisionShape *shape, btVector3 &normal, btScalar margin)
static btScalar Lerp(btScalar a, btScalar b, btScalar t)
static unsigned int Hash(int x, int y, int z, const btCollisionShape *shape)
void setDefaultVoxelsz(btScalar sz)
void Initialize(int hashsize=2383, int clampCells=256 *1024)