beginning of .vb reader test

class preparation for testing
This commit is contained in:
devZoGok
2021-10-19 19:06:41 +03:00
parent bae1b7a9cc
commit 36eade4356
16 changed files with 261 additions and 148 deletions
+6 -3
View File
@@ -20,15 +20,18 @@ set(anim animationController.cpp animationChannel.cpp animation.cpp)
set(armature skeleton.cpp bone.cpp)
set(library ${render} ${math} ${model} ${utils} ${gui} ${armature} ${anim})
set(test cameraTest.cpp nodeTest.cpp boneTest.cpp)
add_library(vb01 SHARED ${library})
target_link_libraries(vb01 glfw)
target_link_libraries(vb01 glad)
target_link_libraries(vb01 assimp)
target_link_libraries(vb01 freetype)
add_executable(vb01Tests main.cpp ${test} ${library})
set(renderTest nodeTest.cpp cameraTest.cpp)
set(armatureTest boneTest.cpp)
set(modelTest vbModelReaderTest.cpp)
set(test ${library} ${renderTest} ${armatureTest} ${modelTest})
add_executable(vb01Tests main.cpp ${test})
target_link_libraries(vb01Tests cppunit)
target_link_libraries(vb01Tests glfw)
target_link_libraries(vb01Tests glad)
+5 -3
View File
@@ -66,9 +66,11 @@ namespace vb01{
indices[numFaceIndices * i + j] = mesh->mFaces[i].mIndices[j];
}
}
//if(mesh->mMaterialIndex>=0){
// aiMaterial *material=scene->mMaterial[mesh->mMaterialIndex];
//}
/*
if(mesh->mMaterialIndex>=0){
aiMaterial *material=scene->mMaterial[mesh->mMaterialIndex];
}
*/
currentNode->attachMesh(new Mesh(vertices, indices, numTris));
}
}
-1
View File
@@ -16,7 +16,6 @@ namespace vb01{
string PATH="/home/dominykas/c++/v/";
Root *root = Root::getSingleton();
root->setBasePath("../");
rootNode = root->getRootNode();
model = new Model(PATH + "../vb01/test.vb");
Material *glMat=new Material();
+1 -1
View File
@@ -10,7 +10,7 @@ namespace vb01{
class BoneTest : public CppUnit::TestFixture{
CPPUNIT_TEST_SUITE(BoneTest);
CPPUNIT_TEST(testGetModelSpacePos);
//CPPUNIT_TEST(testGetModelSpacePos);
CPPUNIT_TEST_SUITE_END();
public:
+33 -39
View File
@@ -47,48 +47,41 @@ namespace vb01{
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
cout<<"Not complete\n";
cout << "Not complete\n";
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void Light::update(){
Root *root = Root::getSingleton();
Node *rootNode = root->getRootNode();
vector<Node*> descendants;
vector<Light*> lights;
rootNode->getDescendants(descendants);
descendants.push_back(rootNode);
std::vector<Material*> materials;
Camera *cam=root->getCamera();
int thisId = -1;
Camera *cam=root->getCamera();
float fov = cam->getFov(), width = root->getWidth(), height = root->getHeight();
vector<Node*> descendants;
rootNode->getDescendants(descendants);
descendants.push_back(rootNode);
vector<Light*> lights;
vector<Material*> materials;
for(Node *d : descendants){
for(Light *l : d->getLights())
lights.push_back(l);
for(Mesh *m : d->getMeshes())
materials.push_back(m->getMaterial());
}
int thisId = -1;
for(int i = 0; i < lights.size(); i++)
if(lights[i] == this)
thisId = i;
mat4 proj = mat4(1.), view = mat4(1.);
mat4 proj = mat4(1.), view = mat4(1.);
renderShadow(descendants, proj, view);
updateShader(materials, thisId, proj, view);
}
void Light::renderShadow(std::vector<Node*> descendants, mat4 &proj, mat4 &view){
vec3 dirs[]{
vec3(1, 0, 0),
vec3(-1, 0, 0),
vec3(0, 1, 0),
vec3(0, -1, 0),
vec3(0, 0, 1),
vec3(0, 0, -1)
};
Root *root = Root::getSingleton();
glViewport(0, 0, depthMapSize, depthMapSize);
@@ -106,48 +99,49 @@ namespace vb01{
if(rotAxis == Vector3::VEC_ZERO)
rotAxis = Vector3::VEC_I;
mat4 model = translate(mat4(1.f), vec3(pos.x, pos.y, pos.z));
model = rotate(model, rot.getAngle(), vec3(rotAxis.x, rotAxis.y, rotAxis.z));
Vector3 upDir = direction.cross(Vector3(0, 1, 0));
if(upDir == Vector3::VEC_ZERO)
upDir=Vector3::VEC_I;
vec3 dir = vec3(direction.x, direction.y, direction.z);
vec3 up = vec3(upDir.x, upDir.y, upDir.z);
vec3 p;
vec3 lightPos, dir = vec3(direction.x, direction.y, direction.z);
if(type == DIRECTIONAL){
p = vec3(pos.x, pos.y, pos.z) - .5f * farPlane * dir;
lightPos = vec3(pos.x, pos.y, pos.z) - .5f * farPlane * dir;
float orthoCorner = 10.f;
proj = ortho(-orthoCorner, orthoCorner, -orthoCorner, orthoCorner, nearPlane, farPlane);
}
else{
p = vec3(position.x, position.y, position.z);
lightPos = vec3(position.x, position.y, position.z);
proj = perspective(radians(90.f), 1.f, nearPlane, farPlane);
}
view = lookAt(p, p + dir, up);
mat4 model = translate(mat4(1.f), vec3(pos.x, pos.y, pos.z));
model = rotate(model, rot.getAngle(), vec3(rotAxis.x, rotAxis.y, rotAxis.z));
Vector3 upDir = direction.cross(Vector3(0, 1, 0));
if(upDir == Vector3::VEC_ZERO)
upDir = Vector3::VEC_I;
vec3 up = vec3(upDir.x, upDir.y, upDir.z);
view = lookAt(lightPos, lightPos + dir, up);
depthMapShader->use();
depthMapShader->setBool(type == POINT, "point");
depthMapShader->setMat4(model, "model");
depthMapShader->setFloat(farPlane, "farPlane");
depthMapShader->setVec3(position, "lightPos");
if(type == POINT){
depthMapShader->setFloat(farPlane, "farPlane");
depthMapShader->setVec3(position, "lightPos");
for(int j = 0; j < 6; j++){
vec3 v;
if(1 < j && j < 4)
v = vec3(0, 0, -1);
for(int i = 0; i < 6; i++){
vec3 upVec;
if(1 < i && i < 4)
upVec = vec3(0, 0, -1);
else
v = vec3(0, -1, 0);
upVec = vec3(0, -1, 0);
depthMapShader->setMat4(proj * lookAt(p, p + dirs[j], v), "shadowMat[" + to_string(j) + "]");
vec3 dirs[] = {
vec3(1, 0, 0), vec3(-1, 0, 0), vec3(0, 1, 0), vec3(0, -1, 0), vec3(0, 0, 1), vec3(0, 0, -1)
};
depthMapShader->setMat4(proj * lookAt(lightPos, lightPos + dirs[i], upVec), "shadowMat[" + to_string(i) + "]");
}
}
else
depthMapShader->setMat4(proj * view, "lightMat");
mesh->render();
}
}
+2
View File
@@ -6,6 +6,7 @@
#include "cameraTest.h"
#include "nodeTest.h"
#include "boneTest.h"
#include "vbModelReaderTest.h"
using namespace CppUnit;
using namespace vb01;
@@ -15,6 +16,7 @@ int main(){
runner.addTest(CameraTest::suite());
runner.addTest(NodeTest::suite());
runner.addTest(BoneTest::suite());
runner.addTest(VbModelReaderTest::suite());
runner.run();
return 0;
}
+27 -22
View File
@@ -130,9 +130,9 @@ namespace vb01{
material->update();
Shader *shader = material->getShader();
if(reflect)
if(reflect){
updateReflection(shader, pos, width, height);
}
if(skeleton)
updateSkeleton(shader);
@@ -196,45 +196,50 @@ namespace vb01{
void Mesh::updateReflection(Shader *shader, Vector3 pos, int width, int height){
Root *root = Root::getSingleton();
vec3 dirs[]{
vec3(1, 0, 0),
vec3(-1, 0, 0),
vec3(0, 1, 0),
vec3(0, -1, 0),
vec3(0, 0, 1),
vec3(0, 0, -1)
};
glViewport(0, 0, width, width);
glBindFramebuffer(GL_FRAMEBUFFER, environmentBuffer);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
environmentShader->use();
Node *rootNode = root->getRootNode();
vector<Node*> descendants;
rootNode->getDescendants(descendants);
for(Node *n : descendants){
for(Mesh *m : n->getMeshes())
if(m != this){
Vector3 position = n->localToGlobalPosition(Vector3::VEC_ZERO);
Quaternion rotation = n->localToGlobalOrientation(Quaternion::QUAT_W);
for(Node *node : descendants){
for(Mesh *mesh : node->getMeshes())
if(mesh != this){
Vector3 position = node->localToGlobalPosition(Vector3::VEC_ZERO);
Quaternion rotation = node->localToGlobalOrientation(Quaternion::QUAT_W);
float far = 100;
vec3 p = vec3(position.x, position.y, position.z);
mat4 proj = perspective(radians(90.f), 1.f, .1f, far);
mat4 model = translate(mat4(1.), p);
Vector3 rotAxis = rotation.norm().getAxis();
if(rotAxis == Vector3::VEC_ZERO)
rotAxis = Vector3::VEC_I;
float far = 100;
vec3 p = vec3(position.x, position.y, position.z);
mat4 proj = perspective(radians(90.f), 1.f, .1f, far);
mat4 model = translate(mat4(1.), p);
model = rotate(model, rotation.norm().getAngle(), vec3(rotAxis.x, rotAxis.y, rotAxis.z));
environmentShader->setMat4(model, "model");
environmentShader->setBool(true, "point");
environmentShader->setVec3(pos, "lightPos");
environmentShader->setFloat(far, "farPlane");
for(int i = 0; i < 6; i++)
environmentShader->setMat4(proj * lookAt(p, p + dirs[i], 1 < i && i < 4 ? vec3(0, 0, -1) : vec3(0, -1, 0)), "shadowMat[" + to_string(i) + "]");
m->render();
vec3 dirs[]{
vec3(1, 0, 0), vec3(-1, 0, 0), vec3(0, 1, 0), vec3(0, -1, 0), vec3(0, 0, 1), vec3(0, 0, -1)
};
for(int i = 0; i < 6; i++){
vec3 upVec;
if(1 < i && i < 4)
upVec = vec3(0, 0, -1);
else
upVec = vec3(0, -1, 0);
environmentShader->setMat4(proj * lookAt(p, p + dirs[i], upVec), "shadowMat[" + to_string(i) + "]");
}
mesh->render();
}
}
glBindFramebuffer(GL_FRAMEBUFFER, *(root->getFBO()));
glViewport(0, 0, root->getWidth(), root->getHeight());
+1
View File
@@ -8,6 +8,7 @@ namespace vb01{
class ModelReader{
public:
protected:
ModelReader(){}
ModelReader(Model*, std::string);
~ModelReader();
Model *model = nullptr;
+7 -5
View File
@@ -58,11 +58,13 @@ namespace vb01{
}
void NodeTest::tearDown(){
/*
delete nodeD;
delete nodeC;
delete nodeB;
nodeA->dettachChild(nodeB);
delete nodeA;
*/
}
void NodeTest::testDetachChild(){
@@ -115,12 +117,12 @@ namespace vb01{
vector<Node*> parentCDescendants;
vector<Node*> parentDDescendants;
parentA->getDescendants(parentA, parentADescendants);
parentB->getDescendants(parentB, parentBDescendants);
parentC->getDescendants(parentC, parentCDescendants);
parentD->getDescendants(parentD, parentDDescendants);
parentA->getDescendants(parentADescendants);
parentB->getDescendants(parentBDescendants);
parentC->getDescendants(parentCDescendants);
parentD->getDescendants(parentDDescendants);
parentD->getDescendants(parentD, parentDDescendants);
parentD->getDescendants(parentDDescendants);
CPPUNIT_ASSERT(parentDDescendants[0] == childD0);
CPPUNIT_ASSERT(parentDDescendants[1] == childD1);
CPPUNIT_ASSERT(parentDDescendants[2] == childD2);
-1
View File
@@ -100,7 +100,6 @@ namespace vb01{
}
void Root::initGuiPlane(Texture *fragTexture, Texture *brightTexture){
guiPlane = new Quad(Vector3(width, height, -1), false);
Material *mat = new Material(Material::MATERIAL_POST);
mat->addDiffuseMap(fragTexture);
+34 -32
View File
@@ -59,47 +59,43 @@ namespace vb01{
void Text::update(){
Root *root = Root::getSingleton();
int width = root->getWidth(), height=root->getHeight();
int width = root->getWidth(), height = root->getHeight();
shader->use();
shader->setVec4(color, "color");
shader->setVec2(Vector2(width, height), "screen");
shader->setVec3(node->getPosition(), "pos");
renderGlyphs();
for(int i = 0; i < entry.length(); i++){
prepareGlyphs(entry[i]);
}
}
void Text::renderGlyphs(){
void Text::prepareGlyphs(char c){
Vector3 origin = node->getPosition();
for(int i = 0; i < entry.length(); i++){
Glyph ch;
bool foundChar = false;
for(Glyph c : characters)
if(entry.c_str()[i] == c.ch){
ch = c;
foundChar = true;
}
if(!foundChar)
continue;
Glyph glyph = getGlyph(c);
Vector2 size = ch.size * scale, bearing = ch.bearing * scale;
float data[] = {
origin.x + bearing.x, origin.y - bearing.y, 0, 0,
origin.x + bearing.x + size.x, origin.y - bearing.y, 1, 0,
origin.x + bearing.x + size.x, origin.y - bearing.y + size.y, 1, 1,
Vector2 size = glyph.size * scale, bearing = glyph.bearing * scale;
float data[] = {
origin.x + bearing.x, origin.y - bearing.y, 0, 0,
origin.x + bearing.x + size.x, origin.y - bearing.y, 1, 0,
origin.x + bearing.x + size.x, origin.y - bearing.y + size.y, 1, 1,
origin.x + bearing.x + size.x, origin.y - bearing.y + size.y, 1, 1,
origin.x + bearing.x, origin.y - bearing.y + size.y, 0, 1,
origin.x + bearing.x, origin.y - bearing.y, 0, 0
};
origin.x + bearing.x + size.x, origin.y - bearing.y + size.y, 1, 1,
origin.x + bearing.x, origin.y - bearing.y + size.y, 0, 1,
origin.x + bearing.x, origin.y - bearing.y, 0, 0
};
//origin.x += (glyph.advance >> 6) * scale;
origin.x += (ch.advance >> 6) * scale;
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(data), data);
ch.texture->select();
glDrawArrays(GL_TRIANGLES, 0, 6);
}
renderGlyphs(glyph, data, sizeof(data));
}
void Text::renderGlyphs(Glyph glyph, float data[], u32 dataSize){
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferSubData(GL_ARRAY_BUFFER, 0, dataSize, data);
glyph.texture->select();
glDrawArrays(GL_TRIANGLES, 0, 6);
}
void Text::setText(string text){
@@ -116,9 +112,15 @@ namespace vb01{
glBindVertexArray(0);
}
float Text::getCharWidth(char c){
Text::Glyph Text::getGlyph(char ch){
Glyph glyph;
for(Glyph g : characters)
if(g.ch == c)
return g.size.x * scale;
if(g.ch == ch)
glyph = g;
return glyph;
}
float Text::getCharWidth(char c){
return getGlyph(c).size.x * scale;
}
}
+3 -1
View File
@@ -33,7 +33,9 @@ namespace vb01{
inline std::string getText(){return entry;}
private:
void initFont(std::string);
void renderGlyphs();
void prepareGlyphs(char);
void renderGlyphs(Glyph, float[], u32);
Glyph getGlyph(char);
Node *node = nullptr;
std::string entry;
+46 -37
View File
@@ -22,17 +22,24 @@ namespace vb01{
getObjectBounds(meshBracketIds, skeletonBracketIds, lightBracketIds);
map<int, int>::iterator it;
vector<string> data;
for(it = skeletonBracketIds.begin(); it != skeletonBracketIds.end(); ++it){
int key = it->first;
readSkeleton(key, skeletonBracketIds[key]);
readFile(path, data, key, skeletonBracketIds[key]);
readSkeleton(data);
data.clear();
}
for(it = meshBracketIds.begin(); it != meshBracketIds.end(); ++it){
int key = it->first;
readMeshes(key, meshBracketIds[key]);
readFile(path, data, key, meshBracketIds[key]);
readMeshes(data);
data.clear();
}
for(it = lightBracketIds.begin(); it != lightBracketIds.end(); ++it){
int key = it->first;
readLights(key, lightBracketIds[key]);
readFile(path, data, key, lightBracketIds[key]);
readLights(data);
data.clear();
}
connectNodes();
@@ -211,11 +218,10 @@ namespace vb01{
}
}
void VbModelReader::readSkeleton(int startLine, int endLine){
vector<string> meshData;
readFile(path, meshData, startLine + 1, startLine + 7);
string name = meshData[0].substr(getCharId(meshData[0], ':') + 2, string::npos);
string line = meshData[5];
void VbModelReader::readSkeleton(vector<string> &skeletonData){
//vector<string> skeletonMetaData(skeletonData.begin() + 1, skeletonData.begin() + 7);
string name = skeletonData[0].substr(getCharId(skeletonData[0], ':') + 2, string::npos);
string line = skeletonData[5];
string data[3];
getLineData(line, data, 3);
@@ -223,7 +229,7 @@ namespace vb01{
int numKeyframeGroups = -2;
int numAnimations = atoi(data[2].c_str());
int boneStartLine = startLine + 7;
int boneStartLine = 7;
int animationStartLine = boneStartLine + numBones + 1;
int keyframeGroupStartLine = animationStartLine + numKeyframeGroups + 1;
int keyframeStartLine = animationStartLine + numAnimations + 1;
@@ -231,21 +237,25 @@ namespace vb01{
Skeleton *skeleton = new Skeleton(name);
skeletons.push_back(skeleton);
meshData.clear();
readFile(path, meshData, boneStartLine, boneStartLine + numBones);
createBones(skeleton, meshData);
vector<string> *skeletonSubData = new vector<string>(skeletonData.begin() + boneStartLine, skeletonData.begin() + boneStartLine + numBones);
createBones(skeleton, *skeletonSubData);
skeletonSubData->clear();
delete skeletonSubData;
meshData.clear();
readFile(path, meshData, animationStartLine, animationStartLine + numAnimations);
readAnimations(skeleton, meshData);
skeletonSubData = new vector<string>(skeletonData.begin() + animationStartLine, skeletonData.begin() + animationStartLine + numAnimations);
readAnimations(skeleton, *skeletonSubData);
skeletonSubData->clear();
delete skeletonSubData;
meshData.clear();
readFile(path, meshData, keyframeGroupStartLine, keyframeGroupStartLine + numKeyframeGroups);
readKeyframesGroups(skeleton, meshData);
skeletonSubData = new vector<string>(skeletonData.begin() + keyframeGroupStartLine, skeletonData.begin() + keyframeGroupStartLine + numKeyframeGroups);
readKeyframesGroups(skeleton, *skeletonSubData);
skeletonSubData->clear();
delete skeletonSubData;
meshData.clear();
readFile(path, meshData, keyframeStartLine);
readKeyframes(skeleton, meshData);
skeletonSubData = new vector<string>(skeletonData.begin() + keyframeGroupStartLine, skeletonData.end());
readKeyframes(skeleton, *skeletonSubData);
skeletonSubData->clear();
delete skeletonSubData;
}
void VbModelReader::readVertices(
@@ -320,9 +330,8 @@ namespace vb01{
}
}
void VbModelReader::readMeshes(int startLine, int endLine){
vector<string> meshData;
readFile(path, meshData, startLine + 1, startLine + 8);
void VbModelReader::readMeshes(vector<string> &meshData){
//readFile(path, meshData, startLine + 1, startLine + 8);
string nameLine = meshData[0];
int nameLineColonId = getCharId(nameLine, ':');
@@ -348,7 +357,7 @@ namespace vb01{
int numFaces = atoi(data[1].c_str());
int numBones = atoi(data[2].c_str());
int numShapes = atoi(data[3].c_str());
int vertexGroupStartLine = startLine + 9;
int vertexGroupStartLine = 8;
int vertexStartLine = vertexGroupStartLine + numBones + 1;
int faceStartLine = vertexStartLine + numVertices + 1;
int shapeKeyStartLine = faceStartLine + numFaces + 1;
@@ -359,21 +368,21 @@ namespace vb01{
u32 *indices = new u32[numFaces * numVertsPerFace];
string *groups = new string[numBones];
meshData.clear();
readFile(path, meshData, vertexStartLine, vertexStartLine + numVertices);
readVertices(vertPos, vertNorm, vertWeights, meshData, numBones);
vector<string> vertexData(meshData.begin() + vertexStartLine, meshData.begin() + vertexStartLine + numVertices);
readVertices(vertPos, vertNorm, vertWeights, vertexData, numBones);
vertexData.clear();
meshData.clear();
readFile(path, meshData, faceStartLine, faceStartLine + numFaces * numVertsPerFace);
readFaces(vertPos, vertNorm, vertWeights, meshData, numBones, vertices, indices);
vector<string> faceData(meshData.begin() + faceStartLine, meshData.begin() + faceStartLine + numFaces * numVertsPerFace);
readFaces(vertPos, vertNorm, vertWeights, faceData, numBones, vertices, indices);
faceData.clear();
meshData.clear();
readFile(path, meshData, vertexGroupStartLine, vertexGroupStartLine + numBones);
readVertexGroups(groups, meshData, numBones);
vector<string> vertexGroupData(meshData.begin() + vertexGroupStartLine, meshData.begin() + vertexGroupStartLine + numBones);
readVertexGroups(groups, vertexGroupData, numBones);
vertexGroupData.clear();
meshData.clear();
readFile(path, meshData, shapeKeyStartLine, shapeKeyStartLine + numShapes);
vector<string> shapeKeyData(meshData.begin() + shapeKeyStartLine, meshData.begin() + shapeKeyStartLine + numShapes);
readShapeKeys(shapeKeyStartLine, numShapes);
shapeKeyData.clear();
string skeletonLine = meshData[5];
int skeletonLineColonId = getCharId(skeletonLine, ':');
@@ -392,7 +401,7 @@ namespace vb01{
nodes.push_back(node);
}
void VbModelReader::readLights(int startLine, int endLine){
void VbModelReader::readLights(vector<string> &lightData){
}
}
+7 -3
View File
@@ -4,6 +4,7 @@
#include"modelReader.h"
#include"util.h"
#include"mesh.h"
#include<string>
#include<vector>
#include<iterator>
@@ -16,6 +17,7 @@ namespace vb01{
class VbModelReader : public ModelReader{
public:
VbModelReader(){}
VbModelReader(Model*, std::string);
~VbModelReader();
private:
@@ -26,18 +28,20 @@ namespace vb01{
void readAnimations(Skeleton*, std::vector<std::string>&);
void readKeyframesGroups(Skeleton*, std::vector<std::string>&);
void readKeyframes(Skeleton*, std::vector<std::string>&);
void readSkeleton(int, int);
void readSkeleton(std::vector<std::string>&);
void readVertices(std::vector<Vector3>&, std::vector<Vector3>&, std::vector<float>&, std::vector<std::string>&, int);
void readFaces(std::vector<Vector3>&, std::vector<Vector3>&, std::vector<float>&, std::vector<std::string>&, int, Mesh::Vertex*, u32*);
void readVertexGroups(std::string*, std::vector<std::string>&, int);
void readShapeKeys(int, int);
void readMeshes(int, int);
void readLights(int, int);
void readMeshes(std::vector<std::string>&);
void readLights(std::vector<std::string>&);
std::vector<std::string> relationships;
std::vector<Skeleton*> skeletons;
std::vector<Mesh*> meshes;
std::vector<Node*> nodes;
friend class VbModelReaderTest;
};
}
+53
View File
@@ -0,0 +1,53 @@
#include "vbModelReaderTest.h"
#include "vbModelReader.h"
using namespace std;
namespace vb01{
VbModelReaderTest::VbModelReaderTest(){}
VbModelReaderTest::~VbModelReaderTest(){}
void VbModelReaderTest::setUp(){
modelReader = new VbModelReader();
setupSkeleton();
setupMesh();
}
void VbModelReaderTest::tearDown(){
delete modelReader;
}
void VbModelReaderTest::setupSkeleton(){
}
void VbModelReaderTest::setupMesh(){
meshData.push_back("MESH: mg42");
meshData.push_back("pos: 0.0 0.0 0.0");
meshData.push_back("rot: 1.0 0.0 0.0 -0.0");
meshData.push_back("scale: 1.0 1.0 1.0");
meshData.push_back("parent: -");
meshData.push_back("skeleton: MG42");
meshData.push_back("numElements: 3 1 2 0 ");
meshData.push_back("groups:");
meshData.push_back("clip");
meshData.push_back("trigger");
meshData.push_back("vertices:");
meshData.push_back("0 1 2 3 4 5 1 0.5 ");
meshData.push_back("1 1 2 3 4 5 1 0.5 ");
meshData.push_back("2 1 2 3 4 5 1 0.5 ");
meshData.push_back("faces:");
meshData.push_back("0 1 1 1 2 3 3 2 1");
meshData.push_back("1 0 0 1 2 3 3 2 1");
meshData.push_back("2 1 0 1 2 3 3 2 1");
}
void VbModelReaderTest::testReadSkeletons(){
}
void VbModelReaderTest::testReadMeshes(){
modelReader->readMeshes(meshData);
Mesh *mesh = modelReader->meshes[0];
CPPUNIT_ASSERT(mesh->getName() == "mg42");
}
}
+36
View File
@@ -0,0 +1,36 @@
#ifndef VB_MODEL_READER_TEST
#define VB_MODEL_READER_TEST
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <vector>
#include <string>
namespace vb01{
class VbModelReader;
class VbModelReaderTest : public CppUnit::TestFixture{
CPPUNIT_TEST_SUITE(VbModelReaderTest);
CPPUNIT_TEST(testReadSkeletons);
CPPUNIT_TEST(testReadMeshes);
CPPUNIT_TEST_SUITE_END();
public:
VbModelReaderTest();
~VbModelReaderTest();
void setUp();
void tearDown();
private:
void setupSkeleton();
void testReadSkeletons();
void setupMesh();
void testReadMeshes();
void testReadLights();
VbModelReader *modelReader = nullptr;
std::vector<std::string> skeletonData, meshData;
int numBones = 0;
};
}
#endif