Xiaohong Bao 2011-05-24 17:37:21 -06:00
commit cb797532c0
6 changed files with 90 additions and 21 deletions

View File

@ -1778,7 +1778,7 @@ void LLModel::updateHullCenters()
if (mHullPoints > 0)
{
mCenterOfHullCenters *= 1.f / mHullPoints;
llassert(mPhysics.asLLSD().has("HullList"));
llassert(mPhysics.hasHullList());
}
}
@ -2127,6 +2127,11 @@ void LLModel::Decomposition::fromLLSD(LLSD& decomp)
}
}
bool LLModel::Decomposition::hasHullList() const
{
return !mHull.empty() ;
}
LLSD LLModel::Decomposition::asLLSD() const
{
LLSD ret;
@ -2208,14 +2213,17 @@ LLSD LLModel::Decomposition::asLLSD() const
//convert to 16-bit normalized across domain
U16 val = (U16) (((mHull[i][j].mV[k]-min.mV[k])/range.mV[k])*65535);
switch (k)
if(valid.size() < 3)
{
case 0: test = test | (U64) val; break;
case 1: test = test | ((U64) val << 16); break;
case 2: test = test | ((U64) val << 32); break;
};
switch (k)
{
case 0: test = test | (U64) val; break;
case 1: test = test | ((U64) val << 16); break;
case 2: test = test | ((U64) val << 32); break;
};
valid.insert(test);
valid.insert(test);
}
U8* buff = (U8*) &val;
//write to binary buffer
@ -2227,8 +2235,8 @@ LLSD LLModel::Decomposition::asLLSD() const
}
}
//must have at least 4 unique points
llassert(valid.size() > 3);
//must have at least 3 unique points
llassert(valid.size() > 2);
}
ret["Position"] = p;
@ -2290,10 +2298,5 @@ void LLModel::Decomposition::merge(const LLModel::Decomposition* rhs)
{ //take physics shape mesh from rhs
mPhysicsShapeMesh = rhs->mPhysicsShapeMesh;
}
if (!mHull.empty())
{ //verify
llassert(asLLSD().has("HullList"));
}
}

View File

@ -106,6 +106,7 @@ public:
Decomposition(LLSD& data);
void fromLLSD(LLSD& data);
LLSD asLLSD() const;
bool hasHullList() const;
void merge(const Decomposition* rhs);

View File

@ -4962,9 +4962,12 @@ LLFloaterModelPreview::DecompRequest::DecompRequest(const std::string& stage, LL
if (mdl)
{
U16 index_offset = 0;
U16 tri[3] ;
mPositions.clear();
mIndices.clear();
mBBox[1] = LLVector3(F32_MIN, F32_MIN, F32_MIN) ;
mBBox[0] = LLVector3(F32_MAX, F32_MAX, F32_MAX) ;
//queue up vertex positions and indices
for (S32 i = 0; i < mdl->getNumVolumeFaces(); ++i)
@ -4978,12 +4981,28 @@ LLFloaterModelPreview::DecompRequest::DecompRequest(const std::string& stage, LL
for (U32 j = 0; j < face.mNumVertices; ++j)
{
mPositions.push_back(LLVector3(face.mPositions[j].getF32ptr()));
for(U32 k = 0 ; k < 3 ; k++)
{
mBBox[0].mV[k] = llmin(mBBox[0].mV[k], mPositions[j].mV[k]) ;
mBBox[1].mV[k] = llmax(mBBox[1].mV[k], mPositions[j].mV[k]) ;
}
}
for (U32 j = 0; j < face.mNumIndices; ++j)
updateTriangleAreaThreshold() ;
for (U32 j = 0; j+2 < face.mNumIndices; j += 3)
{
mIndices.push_back(face.mIndices[j]+index_offset);
}
tri[0] = face.mIndices[j] + index_offset ;
tri[1] = face.mIndices[j + 1] + index_offset ;
tri[2] = face.mIndices[j + 2] + index_offset ;
if(isValidTriangle(tri[0], tri[1], tri[2]))
{
mIndices.push_back(tri[0]);
mIndices.push_back(tri[1]);
mIndices.push_back(tri[2]);
}
}
index_offset += face.mNumVertices;
}

View File

@ -441,10 +441,13 @@ LLFloaterModelWizard::DecompRequest::DecompRequest(const std::string& stage, LLM
if (mdl)
{
U16 index_offset = 0;
U16 tri[3] ;
mPositions.clear();
mIndices.clear();
mBBox[1] = LLVector3(F32_MIN, F32_MIN, F32_MIN) ;
mBBox[0] = LLVector3(F32_MAX, F32_MAX, F32_MAX) ;
//queue up vertex positions and indices
for (S32 i = 0; i < mdl->getNumVolumeFaces(); ++i)
{
@ -457,11 +460,27 @@ LLFloaterModelWizard::DecompRequest::DecompRequest(const std::string& stage, LLM
for (U32 j = 0; j < face.mNumVertices; ++j)
{
mPositions.push_back(LLVector3(face.mPositions[j].getF32ptr()));
for(U32 k = 0 ; k < 3 ; k++)
{
mBBox[0].mV[k] = llmin(mBBox[0].mV[k], mPositions[j].mV[k]) ;
mBBox[1].mV[k] = llmax(mBBox[1].mV[k], mPositions[j].mV[k]) ;
}
}
for (U32 j = 0; j < face.mNumIndices; ++j)
updateTriangleAreaThreshold() ;
for (U32 j = 0; j+2 < face.mNumIndices; j += 3)
{
mIndices.push_back(face.mIndices[j]+index_offset);
tri[0] = face.mIndices[j] + index_offset ;
tri[1] = face.mIndices[j + 1] + index_offset ;
tri[2] = face.mIndices[j + 2] + index_offset ;
if(isValidTriangle(tri[0], tri[1], tri[2]))
{
mIndices.push_back(tri[0]);
mIndices.push_back(tri[1]);
mIndices.push_back(tri[2]);
}
}
index_offset += face.mNumVertices;

View File

@ -3820,6 +3820,25 @@ void LLPhysicsDecomp::run()
mDone = true;
}
void LLPhysicsDecomp::Request::updateTriangleAreaThreshold()
{
F32 range = mBBox[1].mV[0] - mBBox[0].mV[0] ;
range = llmin(range, mBBox[1].mV[1] - mBBox[0].mV[1]) ;
range = llmin(range, mBBox[1].mV[2] - mBBox[0].mV[2]) ;
mTriangleAreaThreshold = llmin(0.0002f, range * 0.000002f) ;
}
//check if the triangle area is large enough to qualify for a valid triangle
bool LLPhysicsDecomp::Request::isValidTriangle(U16 idx1, U16 idx2, U16 idx3)
{
LLVector3 a = mPositions[idx2] - mPositions[idx1] ;
LLVector3 b = mPositions[idx3] - mPositions[idx1] ;
F32 c = a * b ;
return ((a*a) * (b*b) - c * c) > mTriangleAreaThreshold ;
}
void LLPhysicsDecomp::Request::setStatusMessage(const std::string& msg)
{
mStatusMessage = msg;

View File

@ -152,7 +152,7 @@ public:
std::string mStatusMessage;
std::vector<LLModel::PhysicsMesh> mHullMesh;
LLModel::convex_hull_decomposition mHull;
//status message callback, called from decomposition thread
virtual S32 statusCallback(const char* status, S32 p1, S32 p2) = 0;
@ -160,6 +160,14 @@ public:
virtual void completed() = 0;
virtual void setStatusMessage(const std::string& msg);
protected:
//internal use
LLVector3 mBBox[2] ;
F32 mTriangleAreaThreshold ;
void updateTriangleAreaThreshold() ;
bool isValidTriangle(U16 idx1, U16 idx2, U16 idx3) ;
};
LLCondition* mSignal;