fix double-precision support

improve serialization, better search for SDNA1 tag
This commit is contained in:
erwin.coumans
2010-07-21 23:59:41 +00:00
parent 0d53b77e41
commit e3f4f6f1c5
3 changed files with 54 additions and 9 deletions

View File

@@ -183,7 +183,8 @@ void bFile::parseInternal(bool verboseDumpAllTypes, char* memDna,int memDnaLengt
return; return;
char *blenderData = mFileBuffer; char *blenderData = mFileBuffer;
int sdnaPos=0; bChunkInd dna;
dna.oldPtr = 0;
char *tempBuffer = blenderData; char *tempBuffer = blenderData;
for (int i=0; i<mFileLen; i++) for (int i=0; i<mFileLen; i++)
@@ -193,15 +194,33 @@ void bFile::parseInternal(bool verboseDumpAllTypes, char* memDna,int memDnaLengt
if (!mDataStart && strncmp(tempBuffer, "REND", 4)==0) if (!mDataStart && strncmp(tempBuffer, "REND", 4)==0)
mDataStart = i; mDataStart = i;
if (!sdnaPos && strncmp(tempBuffer, "SDNANAME", 8)==0)
sdnaPos = i;
if (mDataStart && sdnaPos) break; if (strncmp(tempBuffer, "DNA1", 4)==0)
{
// read the DNA1 block and extract SDNA
if (getNextBlock(&dna, tempBuffer, mFlags) > 0)
{
if (strncmp((tempBuffer + ChunkUtils::getOffset(mFlags)), "SDNANAME", 8) ==0)
dna.oldPtr = (tempBuffer + ChunkUtils::getOffset(mFlags));
else dna.oldPtr = 0;
}
else
dna.oldPtr = 0;
}
if (mDataStart && dna.oldPtr) break;
tempBuffer++; tempBuffer++;
} }
if (!dna.oldPtr || !dna.len)
{
printf("Failed to find DNA1+SDNA pair\n");
mFlags &= ~FD_OK;
return;
}
mFileDNA = new bDNA(); mFileDNA = new bDNA();
mFileDNA->init(blenderData+sdnaPos, mFileLen-sdnaPos, (mFlags & FD_ENDIAN_SWAP)!=0); mFileDNA->init((char*)dna.oldPtr, dna.len, (mFlags & FD_ENDIAN_SWAP)!=0);
if (mVersion==276) if (mVersion==276)
{ {
@@ -348,9 +367,10 @@ char* bFile::readStruct(char *head, bChunkInd& dataChunk)
numallocs++; numallocs++;
// numBlocks * length // numBlocks * length
int allocLen = curLen > oldLen ? curLen : oldLen;
int allocLen = (curLen);
char *dataAlloc = new char[(dataChunk.nr*allocLen)+1]; char *dataAlloc = new char[(dataChunk.nr*allocLen)+1];
memset(dataAlloc, 0, (dataChunk.nr*allocLen)+1); memset(dataAlloc, 0, (dataChunk.nr*allocLen));
// track allocated // track allocated
addDataBlock(dataAlloc); addDataBlock(dataAlloc);

View File

@@ -99,11 +99,11 @@ void pfxSolveLinearConstraintRow(PfxConstraintRow &constraint,
float massInvB,const vmMatrix3 &inertiaInvB,const vmVector3 &rB) float massInvB,const vmMatrix3 &inertiaInvB,const vmVector3 &rB)
{ {
const vmVector3 normal(btReadVector3(constraint.mNormal)); const vmVector3 normal(btReadVector3(constraint.mNormal));
float deltaImpulse = constraint.mRhs; btScalar deltaImpulse = constraint.mRhs;
vmVector3 dVA = deltaLinearVelocityA + cross(deltaAngularVelocityA,rA); vmVector3 dVA = deltaLinearVelocityA + cross(deltaAngularVelocityA,rA);
vmVector3 dVB = deltaLinearVelocityB + cross(deltaAngularVelocityB,rB); vmVector3 dVB = deltaLinearVelocityB + cross(deltaAngularVelocityB,rB);
deltaImpulse -= constraint.mJacDiagInv * dot(normal,dVA-dVB); deltaImpulse -= constraint.mJacDiagInv * dot(normal,dVA-dVB);
float oldImpulse = constraint.mAccumImpulse; btScalar oldImpulse = constraint.mAccumImpulse;
constraint.mAccumImpulse = btClamped(oldImpulse + deltaImpulse,constraint.mLowerLimit,constraint.mUpperLimit); constraint.mAccumImpulse = btClamped(oldImpulse + deltaImpulse,constraint.mLowerLimit,constraint.mUpperLimit);
deltaImpulse = constraint.mAccumImpulse - oldImpulse; deltaImpulse = constraint.mAccumImpulse - oldImpulse;
deltaLinearVelocityA += deltaImpulse * massInvA * normal; deltaLinearVelocityA += deltaImpulse * massInvA * normal;

View File

@@ -133,6 +133,31 @@ ATTRIBUTE_ALIGNED16(struct) PfxSolverBody {
#include "SpuDispatch/BulletPE2ConstraintSolverSpursSupport.h" #include "SpuDispatch/BulletPE2ConstraintSolverSpursSupport.h"
#endif #endif
static SIMD_FORCE_INLINE vmVector3 btReadVector3(const double* p)
{
float tmp[3] = {p[0],p[1],p[2]};
vmVector3 v;
loadXYZ(v, tmp);
return v;
}
static SIMD_FORCE_INLINE vmQuat btReadQuat(const double* p)
{
float tmp[4] = {p[0],p[1],p[2],p[4]};
vmQuat vq;
loadXYZW(vq, tmp);
return vq;
}
static SIMD_FORCE_INLINE void btStoreVector3(const vmVector3 &src, double* p)
{
float tmp[3];
vmVector3 v = src;
storeXYZ(v, tmp);
p[0] = tmp[0];
p[1] = tmp[1];
p[2] = tmp[2];
}
static SIMD_FORCE_INLINE vmVector3 btReadVector3(const float* p) static SIMD_FORCE_INLINE vmVector3 btReadVector3(const float* p)