Merge remote-tracking branch 'origin/master'

This commit is contained in:
Xuchen Han
2019-11-25 15:29:25 -08:00
15 changed files with 524 additions and 142 deletions

View File

@@ -2567,7 +2567,8 @@ void btSoftBody::updateNormals()
btSoftBody::Face& f = m_faces[i];
const btVector3 n = btCross(f.m_n[1]->m_x - f.m_n[0]->m_x,
f.m_n[2]->m_x - f.m_n[0]->m_x);
f.m_normal = n.normalized();
f.m_normal = n;
f.m_normal.safeNormalize();
f.m_n[0]->m_n += n;
f.m_n[1]->m_n += n;
f.m_n[2]->m_n += n;
@@ -3377,7 +3378,10 @@ void btSoftBody::interpolateRenderMesh()
n.m_x.setZero();
for (int j = 0; j < 4; ++j)
{
n.m_x += m_renderNodesParents[i][j]->m_x * m_renderNodesInterpolationWeights[i][j];
if (m_renderNodesParents[i].size())
{
n.m_x += m_renderNodesParents[i][j]->m_x * m_renderNodesInterpolationWeights[i][j];
}
}
}
}
@@ -3966,7 +3970,7 @@ const char* btSoftBody::serialize(void* dataBuffer, class btSerializer* serializ
for (int j = 0; j < 4; j++)
{
m_tetras[i].m_c0[j].serializeFloat(memPtr->m_c0[j]);
memPtr->m_nodeIndices[j] = m_tetras[j].m_n[j] ? m_tetras[j].m_n[j] - &m_nodes[0] : -1;
memPtr->m_nodeIndices[j] = m_tetras[i].m_n[j] ? m_tetras[i].m_n[j] - &m_nodes[0] : -1;
}
memPtr->m_c1 = m_tetras[i].m_c1;
memPtr->m_c2 = m_tetras[i].m_c2;

View File

@@ -1500,44 +1500,6 @@ void btSoftBodyHelpers::getBarycentricWeights(const btVector3& a, const btVector
bary = btVector4(va6*v6, vb6*v6, vc6*v6, vd6*v6);
}
void btSoftBodyHelpers::readRenderMeshFromObj(const char* file, btSoftBody* psb)
{
std::ifstream fs;
fs.open(file);
std::string line;
btVector3 pos;
while (std::getline(fs, line))
{
std::stringstream ss(line);
if (line.length()>1)
{
if (line[0] == 'v' && line[1] != 't' && line[1] != 'n')
{
ss.ignore();
for (size_t i = 0; i < 3; i++)
ss >> pos[i];
btSoftBody::Node n;
n.m_x = pos;
psb->m_renderNodes.push_back(n);
}
else if (line[0] == 'f')
{
ss.ignore();
int id0, id1, id2;
ss >> id0;
ss >> id1;
ss >> id2;
btSoftBody::Face f;
f.m_n[0] = &psb->m_renderNodes[id0-1];
f.m_n[1] = &psb->m_renderNodes[id1-1];
f.m_n[2] = &psb->m_renderNodes[id2-1];
psb->m_renderFaces.push_back(f);
}
}
}
fs.close();
}
// Iterate through all render nodes to find the simulation tetrahedron that contains the render node and record the barycentric weights
// If the node is not inside any tetrahedron, assign it to the tetrahedron in which the node has the least negative barycentric weight
void btSoftBodyHelpers::interpolateBarycentricWeights(btSoftBody* psb)

View File

@@ -148,8 +148,6 @@ struct btSoftBodyHelpers
static void getBarycentricWeights(const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& d, const btVector3& p, btVector4& bary);
static void readRenderMeshFromObj(const char* file, btSoftBody* psb);
static void interpolateBarycentricWeights(btSoftBody* psb);
static void generateBoundaryFaces(btSoftBody* psb);

View File

@@ -20,27 +20,38 @@ subject to the following restrictions:
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
#include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
// Modified Paul Hsieh hash
template <const int DWORDLEN>
unsigned int HsiehHash(const void* pdata)
{
const unsigned short* data = (const unsigned short*)pdata;
unsigned hash = DWORDLEN << 2, tmp;
for (int i = 0; i < DWORDLEN; ++i)
{
hash += data[0];
tmp = (data[1] << 11) ^ hash;
hash = (hash << 16) ^ tmp;
data += 2;
hash += hash >> 11;
}
hash ^= hash << 3;
hash += hash >> 5;
hash ^= hash << 4;
hash += hash >> 17;
hash ^= hash << 25;
hash += hash >> 6;
return (hash);
// Fast Hash
#if !defined (get16bits)
#define get16bits(d) ((((unsigned int)(((const unsigned char *)(d))[1])) << 8)\
+(unsigned int)(((const unsigned char *)(d))[0]) )
#endif
//
// super hash function by Paul Hsieh
//
inline unsigned int HsiehHash (const char * data, int len) {
unsigned int hash = len, tmp;
len>>=2;
/* Main loop */
for (;len > 0; len--) {
hash += get16bits (data);
tmp = (get16bits (data+2) << 11) ^ hash;
hash = (hash << 16) ^ tmp;
data += 2*sizeof (unsigned short);
hash += hash >> 11;
}
/* Force "avalanching" of final 127 bits */
hash ^= hash << 3;
hash += hash >> 5;
hash ^= hash << 4;
hash += hash >> 17;
hash ^= hash << 25;
hash += hash >> 6;
return hash;
}
template <const int CELLSIZE>
@@ -209,6 +220,9 @@ struct btSparseSdf
}
else
{
// printf("c->hash/c[0][1][2]=%d,%d,%d,%d\n", c->hash, c->c[0], c->c[1],c->c[2]);
//printf("h,ixb,iyb,izb=%d,%d,%d,%d\n", h,ix.b, iy.b, iz.b);
c = c->next;
}
}
@@ -260,7 +274,7 @@ struct btSparseSdf
Lerp(gy[2], gy[3], ix.f), iz.f));
normal.setZ(Lerp(Lerp(gz[0], gz[1], ix.f),
Lerp(gz[2], gz[3], ix.f), iy.f));
normal = normal.normalized();
normal.safeNormalize();
#else
normal = btVector3(d[1] - d[0], d[3] - d[0], d[4] - d[0]).normalized();
#endif
@@ -340,16 +354,16 @@ struct btSparseSdf
btS myset;
//memset may be needed in case of additional (uninitialized) padding!
//memset(myset, 0, sizeof(btS));
//memset(&myset, 0, sizeof(btS));
myset.x = x;
myset.y = y;
myset.z = z;
myset.w = 0;
myset.p = (void*)shape;
const void* ptr = &myset;
const char* ptr = (const char*)&myset;
unsigned int result = HsiehHash<sizeof(btS) / 4>(ptr);
unsigned int result = HsiehHash(ptr, sizeof(btS) );
return result;
}