42 #include <gtest/gtest.h> 44 #include <ACG/GL/VertexDeclaration.hh> 45 #include <ACG/GL/MeshCompiler.hh> 47 #include "MeshCompiler_testData.hh" 55 explicit SBFReader(
const char* szObjFile);
58 int getNumVertices() {
return m_Vertices.size() / 3;}
59 int getNumTexcoords() {
return m_TexCoords.size() / 2;}
60 int getNumNormals() {
return m_Normals.size() / 3;}
62 float* getVertices() {
return m_Vertices.empty() ? 0 : &m_Vertices[0];}
63 float* getNormals() {
return m_Normals.empty() ? 0 : &m_Normals[0];}
64 float* getTexCoords() {
return m_TexCoords.empty() ? 0 : &m_TexCoords[0];}
68 if (m_AdjVertexCount.size())
return m_AdjVertexCount[_vertexID];
73 if (m_AdjVertexOffset.size())
return m_AdjVertexBuf[m_AdjVertexOffset[_vertexID] + _k];
76 virtual int getFaceAdjCount(
int _faceID)
78 if (m_AdjFaceCount.size())
return m_AdjFaceCount[_faceID];
81 virtual int getFaceAdjFace(
int _faceID,
int _k)
83 if (m_AdjFaceOffset.size())
return m_AdjFaceBuf[m_AdjFaceOffset[_faceID] + _k];
87 void writeFile(
const char* szFile);
96 std::vector<float> m_Vertices;
97 std::vector<float> m_Normals;
98 std::vector<float> m_TexCoords;
107 std::vector<unsigned char> m_AdjVertexCount;
108 std::vector<int> m_AdjVertexOffset;
109 std::vector<int> m_AdjVertexBuf;
111 std::vector<int> m_AdjFaceOffset;
112 std::vector<unsigned char> m_AdjFaceCount;
113 std::vector<int> m_AdjFaceBuf;
116 SBFReader::SBFReader(
const char* szObjFile)
117 : MeshCompilerDefaultFaceInput(0, 0),
118 m_NumVerts(0), m_NumNormals(0), m_NumTexCoords(0),
119 m_PosAttrID(0), m_NormAttrID(-1), m_TexCAttrID(-1)
123 FILE* pFile = fopen(szObjFile,
"rb");
128 m_NumVerts = 0; m_NumNormals = 0; m_NumTexCoords = 0;
132 fread(&numFaces_, 4, 1, pFile);
133 fread(&m_NumVerts, 4, 1, pFile);
134 fread(&m_NumNormals, 4, 1, pFile);
135 fread(&m_NumTexCoords, 4, 1, pFile);
138 fread(&faceBufSize, 4, 1, pFile);
141 m_Vertices.resize(m_NumVerts * 3);
142 m_Normals.resize(m_NumNormals * 3);
143 m_TexCoords.resize(m_NumTexCoords * 3);
144 faceOffset_.resize(numFaces_);
145 faceSize_.resize(numFaces_);
147 fread(&faceSize_[0], 4, numFaces_, pFile);
150 for (
int i = 1; i < numFaces_; ++i)
151 faceOffset_[i] = faceOffset_[i-1] + faceSize_[i-1];
155 faceData_[m_PosAttrID].resize(faceBufSize);
156 fread(&faceData_[m_PosAttrID][0], 4, faceBufSize, pFile);
162 faceData_[m_TexCAttrID].resize(faceBufSize);
163 fread(&faceData_[m_TexCAttrID][0], 4, faceBufSize, pFile);
168 m_NormAttrID = m_TexCAttrID >= 0 ? m_TexCAttrID + 1 : m_PosAttrID + 1;
169 faceData_[m_NormAttrID].resize(faceBufSize);
170 fread(&faceData_[m_NormAttrID][0], 4, faceBufSize, pFile);
175 fread(&m_Vertices[0], 12, m_NumVerts, pFile);
178 fread(&m_TexCoords[0], 8, m_NumTexCoords, pFile);
181 fread(&m_Normals[0], 12, m_NumNormals, pFile);
184 int numVertAdj, numFaceAdj, vertAdjSize, faceAdjSize;
186 if (fread(&numVertAdj, 4, 1, pFile) == 1)
188 fread(&vertAdjSize, 4, 1, pFile);
190 m_AdjVertexOffset.resize(numVertAdj);
191 m_AdjVertexCount.resize(numVertAdj);
192 m_AdjVertexBuf.resize(vertAdjSize);
194 fread(&m_AdjVertexOffset[0], 4, numVertAdj, pFile);
195 fread(&m_AdjVertexCount[0], 1, numVertAdj, pFile);
196 fread(&m_AdjVertexBuf[0], 4, vertAdjSize, pFile);
198 if (fread(&numFaceAdj, 4, 1, pFile) == 1)
200 fread(&faceAdjSize, 4, 1, pFile);
202 m_AdjFaceOffset.resize(numFaceAdj);
203 m_AdjFaceCount.resize(numFaceAdj);
204 m_AdjFaceBuf.resize(faceAdjSize);
206 fread(&m_AdjFaceOffset[0], 4, numFaceAdj, pFile);
207 fread(&m_AdjFaceCount[0], 1, numFaceAdj, pFile);
208 fread(&m_AdjFaceBuf[0], 4, faceAdjSize, pFile);
228 MeshCompilerTest_GetInput0(&input0);
229 mesh0_ = CreateMesh(input0);
233 MeshCompilerTest_GetInput1(&input1);
234 mesh1_ = CreateMesh(input1);
240 virtual void SetUp() {
245 virtual void TearDown() {
247 delete mesh0_; mesh0_ = 0;
248 delete mesh1_; mesh1_ = 0;
256 if (input.numTexcoords_)
258 if (input.numNormals_)
265 mesh->
setVertices(input.numVerts_, input.vdata_pos);
267 mesh->
setNormals(input.numNormals_, input.vdata_n);
270 mesh->
setNumFaces(input.numFaces_, input.numIndices_);
273 for (
int i = 0; i < input.numFaces_; ++i)
275 int fsize = input.fsize_[i];
276 mesh->
setFaceVerts(i, fsize, ((
int*)input.fdata_pos) + offset);
278 if (input.numTexcoords_ && input.fdata_t)
281 if (input.numNormals_ && input.fdata_n)
289 const int numGroups = 5;
293 for (
int i = 0; i < input.numFaces_; ++i)
308 mesh0_->build(
false,
false,
false);
309 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
314 mesh0_->build(
true,
false,
false);
316 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
321 mesh0_->build(
false,
true,
false);
323 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
328 mesh0_->build(
true,
true,
false);
330 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
339 mesh0_->build(
false,
false,
true);
341 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
346 mesh0_->build(
true,
false,
true);
348 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
353 mesh0_->build(
false,
true,
true);
355 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
360 mesh0_->build(
true,
true,
true);
362 EXPECT_EQ(mesh0_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
371 mesh1_->build(
false,
false,
false);
373 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
378 mesh1_->build(
true,
false,
false);
380 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
385 mesh1_->build(
false,
true,
false);
387 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
392 mesh1_->build(
true,
true,
false);
394 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
403 mesh1_->build(
false,
false,
true);
405 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
410 mesh1_->build(
true,
false,
true);
412 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
417 mesh1_->build(
false,
true,
true);
419 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
424 mesh1_->build(
true,
true,
true);
426 EXPECT_EQ(mesh1_->dbgVerify(0),
true) <<
"compiled mesh contains errors";
Class to define the vertex input layout.
void setFaceGroup(int _i, short _groupID)
Specify face groups.
virtual int getVertexAdjCount(const int _vertexID) const
void setTexCoords(size_t _num, const void *_data, size_t _stride=0, bool _internalCopy=false, GLuint _fmt=0, int _elementSize=-1)
void setNormals(size_t _num, const void *_data, size_t _stride=0, bool _internalCopy=false, GLuint _fmt=0, int _elementSize=-1)
void setVertices(size_t _num, const void *_data, size_t _stride=0, bool _internalCopy=false, GLuint _fmt=0, int _elementSize=-1)
void setNumFaces(const int _numFaces, const int _numIndices)
Set number of faces and indices if known by user.
void addElement(const VertexElement *_pElement)
void setFaceNormals(int _i, int _v0, int _v1, int _v2)
Set normal ids per triangle.
void setFaceTexCoords(int _i, int _v0, int _v1, int _v2)
Set texcoord 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.