2009-01-12 22:06:54 +00:00
|
|
|
#include "UnitTestPCH.h"
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
#include <assimp/scene.h>
|
|
|
|
#include <LimitBoneWeightsProcess.h>
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Assimp;
|
|
|
|
|
|
|
|
class LimitBoneWeightsTest : public ::testing::Test {
|
|
|
|
public:
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2014-09-07 23:52:03 +00:00
|
|
|
virtual void SetUp();
|
|
|
|
virtual void TearDown();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
LimitBoneWeightsProcess* piProcess;
|
|
|
|
aiMesh* pcMesh;
|
|
|
|
};
|
2008-07-22 22:52:16 +00:00
|
|
|
|
2009-01-12 22:06:54 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2014-09-07 23:52:03 +00:00
|
|
|
void LimitBoneWeightsTest::SetUp()
|
2008-07-22 22:52:16 +00:00
|
|
|
{
|
|
|
|
// construct the process
|
|
|
|
this->piProcess = new LimitBoneWeightsProcess();
|
|
|
|
|
|
|
|
// now need to create a nice mesh for testing purposes
|
|
|
|
this->pcMesh = new aiMesh();
|
|
|
|
|
|
|
|
pcMesh->mNumVertices = 500;
|
|
|
|
pcMesh->mVertices = new aiVector3D[500]; // uninit.
|
|
|
|
pcMesh->mNumBones = 30;
|
|
|
|
pcMesh->mBones = new aiBone*[30];
|
|
|
|
unsigned int iCur = 0;
|
|
|
|
for (unsigned int i = 0; i < 30;++i)
|
|
|
|
{
|
|
|
|
aiBone* pc = pcMesh->mBones[i] = new aiBone();
|
|
|
|
pc->mNumWeights = 250;
|
|
|
|
pc->mWeights = new aiVertexWeight[pc->mNumWeights];
|
|
|
|
for (unsigned int qq = 0; qq < pc->mNumWeights;++qq)
|
|
|
|
{
|
|
|
|
aiVertexWeight& v = pc->mWeights[qq];
|
|
|
|
v.mVertexId = iCur++;
|
|
|
|
if (500 == iCur)iCur = 0;
|
|
|
|
v.mWeight = 1.0f / 15; // each vertex should occur once in two bones
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-12 22:06:54 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2014-09-07 23:52:03 +00:00
|
|
|
void LimitBoneWeightsTest::TearDown()
|
2008-07-22 22:52:16 +00:00
|
|
|
{
|
2010-03-02 17:38:01 +00:00
|
|
|
delete pcMesh;
|
|
|
|
delete piProcess;
|
2008-07-22 22:52:16 +00:00
|
|
|
}
|
|
|
|
|
2009-01-12 22:06:54 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2014-09-07 23:52:03 +00:00
|
|
|
TEST_F(LimitBoneWeightsTest, testProcess)
|
2008-07-22 22:52:16 +00:00
|
|
|
{
|
|
|
|
// execute the step on the given data
|
2010-03-02 17:38:01 +00:00
|
|
|
piProcess->ProcessMesh(pcMesh);
|
2008-07-22 22:52:16 +00:00
|
|
|
|
|
|
|
// check whether everything is ok ...
|
|
|
|
typedef std::vector<LimitBoneWeightsProcess::Weight> VertexWeightList;
|
|
|
|
VertexWeightList* asWeights = new VertexWeightList[pcMesh->mNumVertices];
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < pcMesh->mNumVertices;++i)
|
|
|
|
asWeights[i].reserve(4);
|
|
|
|
|
|
|
|
// sort back as per-vertex lists
|
|
|
|
for (unsigned int i = 0; i < pcMesh->mNumBones;++i)
|
|
|
|
{
|
|
|
|
aiBone& pcBone = **(pcMesh->mBones+i);
|
|
|
|
for (unsigned int q = 0; q < pcBone.mNumWeights;++q)
|
|
|
|
{
|
|
|
|
aiVertexWeight weight = pcBone.mWeights[q];
|
|
|
|
asWeights[weight.mVertexId].push_back(LimitBoneWeightsProcess::Weight (i,weight.mWeight));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now validate the size of the lists and check whether all weights sum to 1.0f
|
|
|
|
for (unsigned int i = 0; i < pcMesh->mNumVertices;++i)
|
|
|
|
{
|
2014-09-07 23:52:03 +00:00
|
|
|
EXPECT_LE(asWeights[i].size(), 4U);
|
2008-07-22 22:52:16 +00:00
|
|
|
float fSum = 0.0f;
|
|
|
|
for (VertexWeightList::const_iterator
|
|
|
|
iter = asWeights[i].begin();
|
|
|
|
iter != asWeights[i].end();++iter)
|
|
|
|
{
|
|
|
|
fSum += (*iter).mWeight;
|
|
|
|
}
|
2014-09-07 23:52:03 +00:00
|
|
|
EXPECT_GE(fSum, 0.95F);
|
|
|
|
EXPECT_LE(fSum, 1.04F);
|
2008-07-22 22:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// delete allocated storage
|
|
|
|
delete[] asWeights;
|
|
|
|
|
|
|
|
// everything seems to be OK
|
2014-09-07 23:52:03 +00:00
|
|
|
}
|