49 #include <gtest/gtest.h>
51 #include <ACG/GL/VertexDeclaration.hh>
52 #include <ACG/GL/MeshCompiler.hh>
54 #include "MeshCompiler_testData.hh"
65 int getNumVertices() {
return m_Vertices.size() / 3;}
66 int getNumTexcoords() {
return m_TexCoords.size() / 2;}
67 int getNumNormals() {
return m_Normals.size() / 3;}
69 float* getVertices() {
return m_Vertices.empty() ? 0 : &m_Vertices[0];}
70 float* getNormals() {
return m_Normals.empty() ? 0 : &m_Normals[0];}
71 float* getTexCoords() {
return m_TexCoords.empty() ? 0 : &m_TexCoords[0];}
75 if (m_AdjVertexCount.size())
return m_AdjVertexCount[_vertexID];
80 if (m_AdjVertexOffset.size())
return m_AdjVertexBuf[m_AdjVertexOffset[_vertexID] + _k];
83 virtual int getFaceAdjCount(
int _faceID)
85 if (m_AdjFaceCount.size())
return m_AdjFaceCount[_faceID];
88 virtual int getFaceAdjFace(
int _faceID,
int _k)
90 if (m_AdjFaceOffset.size())
return m_AdjFaceBuf[m_AdjFaceOffset[_faceID] + _k];
94 void writeFile(
const char* szFile);
103 std::vector<float> m_Vertices;
104 std::vector<float> m_Normals;
105 std::vector<float> m_TexCoords;
114 std::vector<unsigned char> m_AdjVertexCount;
115 std::vector<int> m_AdjVertexOffset;
116 std::vector<int> m_AdjVertexBuf;
118 std::vector<int> m_AdjFaceOffset;
119 std::vector<unsigned char> m_AdjFaceCount;
120 std::vector<int> m_AdjFaceBuf;
123 SBFReader::SBFReader(
const char* szObjFile)
124 : MeshCompilerDefaultFaceInput(0, 0),
125 m_NumVerts(0), m_NumNormals(0), m_NumTexCoords(0),
126 m_PosAttrID(0), m_NormAttrID(-1), m_TexCAttrID(-1)
130 FILE* pFile = fopen(szObjFile,
"rb");
135 m_NumVerts = 0; m_NumNormals = 0; m_NumTexCoords = 0;
139 fread(&numFaces_, 4, 1, pFile);
140 fread(&m_NumVerts, 4, 1, pFile);
141 fread(&m_NumNormals, 4, 1, pFile);
142 fread(&m_NumTexCoords, 4, 1, pFile);
145 fread(&faceBufSize, 4, 1, pFile);
148 m_Vertices.resize(m_NumVerts * 3);
149 m_Normals.resize(m_NumNormals * 3);
150 m_TexCoords.resize(m_NumTexCoords * 3);
151 faceOffset_.resize(numFaces_);
152 faceSize_.resize(numFaces_);
154 fread(&faceSize_[0], 4, numFaces_, pFile);
157 for (
int i = 1; i < numFaces_; ++i)
158 faceOffset_[i] = faceOffset_[i-1] + faceSize_[i-1];
162 faceData_[m_PosAttrID].resize(faceBufSize);
163 fread(&faceData_[m_PosAttrID][0], 4, faceBufSize, pFile);
169 faceData_[m_TexCAttrID].resize(faceBufSize);
170 fread(&faceData_[m_TexCAttrID][0], 4, faceBufSize, pFile);
175 m_NormAttrID = m_TexCAttrID >= 0 ? m_TexCAttrID + 1 : m_PosAttrID + 1;
176 faceData_[m_NormAttrID].resize(faceBufSize);
177 fread(&faceData_[m_NormAttrID][0], 4, faceBufSize, pFile);
182 fread(&m_Vertices[0], 12, m_NumVerts, pFile);
185 fread(&m_TexCoords[0], 8, m_NumTexCoords, pFile);
188 fread(&m_Normals[0], 12, m_NumNormals, pFile);
191 int numVertAdj, numFaceAdj, vertAdjSize, faceAdjSize;
193 if (fread(&numVertAdj, 4, 1, pFile) == 1)
195 fread(&vertAdjSize, 4, 1, pFile);
197 m_AdjVertexOffset.resize(numVertAdj);
198 m_AdjVertexCount.resize(numVertAdj);
199 m_AdjVertexBuf.resize(vertAdjSize);
201 fread(&m_AdjVertexOffset[0], 4, numVertAdj, pFile);
202 fread(&m_AdjVertexCount[0], 1, numVertAdj, pFile);
203 fread(&m_AdjVertexBuf[0], 4, vertAdjSize, pFile);
205 if (fread(&numFaceAdj, 4, 1, pFile) == 1)
207 fread(&faceAdjSize, 4, 1, pFile);
209 m_AdjFaceOffset.resize(numFaceAdj);
210 m_AdjFaceCount.resize(numFaceAdj);
211 m_AdjFaceBuf.resize(faceAdjSize);
213 fread(&m_AdjFaceOffset[0], 4, numFaceAdj, pFile);
214 fread(&m_AdjFaceCount[0], 1, numFaceAdj, pFile);
215 fread(&m_AdjFaceBuf[0], 4, faceAdjSize, pFile);
235 MeshCompilerTest_GetInput0(&input0);
236 mesh0_ = CreateMesh(input0);
240 MeshCompilerTest_GetInput1(&input1);
241 mesh1_ = CreateMesh(input1);
247 virtual void SetUp() {
252 virtual void TearDown() {
254 delete mesh0_; mesh0_ = 0;
255 delete mesh1_; mesh1_ = 0;
263 if (input.numTexcoords_)
265 if (input.numNormals_)
272 mesh->
setVertices(input.numVerts_, input.vdata_pos);
274 mesh->
setNormals(input.numNormals_, input.vdata_n);
277 mesh->
setNumFaces(input.numFaces_, input.numIndices_);
280 for (
int i = 0; i < input.numFaces_; ++i)
282 int fsize = input.fsize_[i];
283 mesh->
setFaceVerts(i, fsize, ((
int*)input.fdata_pos) + offset);
285 if (input.numTexcoords_ && input.fdata_t)
288 if (input.numNormals_ && input.fdata_n)
296 const int numGroups = 5;
300 for (
int i = 0; i < input.numFaces_; ++i)
315 mesh0_->build(
false,
false,
false);
316 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
321 mesh0_->build(
true,
false,
false);
323 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
328 mesh0_->build(
false,
true,
false);
330 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
335 mesh0_->build(
true,
true,
false);
337 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
346 mesh0_->build(
false,
false,
true);
348 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
353 mesh0_->build(
true,
false,
true);
355 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
360 mesh0_->build(
false,
true,
true);
362 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
367 mesh0_->build(
true,
true,
true);
369 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
378 mesh1_->build(
false,
false,
false);
380 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
385 mesh1_->build(
true,
false,
false);
387 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
392 mesh1_->build(
false,
true,
false);
394 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
399 mesh1_->build(
true,
true,
false);
401 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
410 mesh1_->build(
false,
false,
true);
412 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
417 mesh1_->build(
true,
false,
true);
419 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
424 mesh1_->build(
false,
true,
true);
426 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
431 mesh1_->build(
true,
true,
true);
433 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
void setNormals(int _num, const void *_data, int _stride=0, bool _internalCopy=false, GLuint _fmt=0, int _elementSize=-1)
void setTexCoords(int _num, const void *_data, int _stride=0, bool _internalCopy=false, GLuint _fmt=0, int _elementSize=-1)
virtual int getVertexAdjCount(const int _vertexID) const
void setFaceNormals(int _i, int _v0, int _v1, int _v2)
Set normal ids per triangle.
virtual int getVertexAdjFace(const int _vertexID, const int _k) const
void setFaceVerts(int _i, int _v0, int _v1, int _v2)
Set vertex ids per triangle.
void setFaceGroup(int _i, short _groupID)
Specify face groups.
void setVertices(int _num, const void *_data, int _stride=0, bool _internalCopy=false, GLuint _fmt=0, int _elementSize=-1)
Class to define the vertex input layout.
void setFaceTexCoords(int _i, int _v0, int _v1, int _v2)
Set texcoord ids per triangle.
void setNumFaces(const int _numFaces, const int _numIndices)
Set number of faces and indices if known by user.
void addElement(const VertexElement *_pElement)