From 36eade4356d7399f75506abe6552ed0cf2e1ce43 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Fri, 18 Dec 2020 21:30:02 +0200 Subject: [PATCH] beginning of .vb reader test class preparation for testing --- CMakeLists.txt | 9 +++-- assimpModelReader.cpp | 8 +++-- boneTest.cpp | 1 - boneTest.h | 2 +- light.cpp | 72 +++++++++++++++++-------------------- main.cpp | 2 ++ mesh.cpp | 49 +++++++++++++------------ modelReader.h | 1 + nodeTest.cpp | 12 ++++--- root.cpp | 1 - text.cpp | 66 +++++++++++++++++----------------- text.h | 4 ++- vbModelReader.cpp | 83 ++++++++++++++++++++++++------------------- vbModelReader.h | 10 ++++-- vbModelReaderTest.cpp | 53 +++++++++++++++++++++++++++ vbModelReaderTest.h | 36 +++++++++++++++++++ 16 files changed, 261 insertions(+), 148 deletions(-) create mode 100644 vbModelReaderTest.cpp create mode 100644 vbModelReaderTest.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 819ecbf..9cfe53d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/assimpModelReader.cpp b/assimpModelReader.cpp index 8ee55ba..0817afa 100644 --- a/assimpModelReader.cpp +++ b/assimpModelReader.cpp @@ -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)); } } diff --git a/boneTest.cpp b/boneTest.cpp index 0ee8023..998541d 100644 --- a/boneTest.cpp +++ b/boneTest.cpp @@ -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(); diff --git a/boneTest.h b/boneTest.h index af05131..8d290ac 100644 --- a/boneTest.h +++ b/boneTest.h @@ -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: diff --git a/light.cpp b/light.cpp index 5e409f6..435a06f 100755 --- a/light.cpp +++ b/light.cpp @@ -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 descendants; - vector lights; - rootNode->getDescendants(descendants); - descendants.push_back(rootNode); - std::vector materials; - Camera *cam=root->getCamera(); - int thisId = -1; + Camera *cam=root->getCamera(); float fov = cam->getFov(), width = root->getWidth(), height = root->getHeight(); + vector descendants; + rootNode->getDescendants(descendants); + descendants.push_back(rootNode); + vector lights; + vector 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 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(); } } diff --git a/main.cpp b/main.cpp index fffb9e1..b5417cf 100755 --- a/main.cpp +++ b/main.cpp @@ -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; } diff --git a/mesh.cpp b/mesh.cpp index 8142b6f..9fc0af9 100755 --- a/mesh.cpp +++ b/mesh.cpp @@ -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 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()); diff --git a/modelReader.h b/modelReader.h index 35e163a..8695c3f 100644 --- a/modelReader.h +++ b/modelReader.h @@ -8,6 +8,7 @@ namespace vb01{ class ModelReader{ public: protected: + ModelReader(){} ModelReader(Model*, std::string); ~ModelReader(); Model *model = nullptr; diff --git a/nodeTest.cpp b/nodeTest.cpp index 5009b78..465f108 100644 --- a/nodeTest.cpp +++ b/nodeTest.cpp @@ -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 parentCDescendants; vector 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); diff --git a/root.cpp b/root.cpp index ec2e8fc..2ed46b5 100755 --- a/root.cpp +++ b/root.cpp @@ -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); diff --git a/text.cpp b/text.cpp index b296d7b..3ade0b8 100755 --- a/text.cpp +++ b/text.cpp @@ -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; } } diff --git a/text.h b/text.h index 1a928cd..c52e6e2 100755 --- a/text.h +++ b/text.h @@ -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; diff --git a/vbModelReader.cpp b/vbModelReader.cpp index 3e0b8cb..78c52b5 100644 --- a/vbModelReader.cpp +++ b/vbModelReader.cpp @@ -22,17 +22,24 @@ namespace vb01{ getObjectBounds(meshBracketIds, skeletonBracketIds, lightBracketIds); map::iterator it; + vector 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 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 &skeletonData){ + //vector 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 *skeletonSubData = new vector(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(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(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(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 meshData; - readFile(path, meshData, startLine + 1, startLine + 8); + void VbModelReader::readMeshes(vector &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 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 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 vertexGroupData(meshData.begin() + vertexGroupStartLine, meshData.begin() + vertexGroupStartLine + numBones); + readVertexGroups(groups, vertexGroupData, numBones); + vertexGroupData.clear(); - meshData.clear(); - readFile(path, meshData, shapeKeyStartLine, shapeKeyStartLine + numShapes); + vector 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 &lightData){ } } diff --git a/vbModelReader.h b/vbModelReader.h index f24e91d..540aa88 100644 --- a/vbModelReader.h +++ b/vbModelReader.h @@ -4,6 +4,7 @@ #include"modelReader.h" #include"util.h" #include"mesh.h" + #include #include #include @@ -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&); void readKeyframesGroups(Skeleton*, std::vector&); void readKeyframes(Skeleton*, std::vector&); - void readSkeleton(int, int); + void readSkeleton(std::vector&); void readVertices(std::vector&, std::vector&, std::vector&, std::vector&, int); void readFaces(std::vector&, std::vector&, std::vector&, std::vector&, int, Mesh::Vertex*, u32*); void readVertexGroups(std::string*, std::vector&, int); void readShapeKeys(int, int); - void readMeshes(int, int); - void readLights(int, int); + void readMeshes(std::vector&); + void readLights(std::vector&); std::vector relationships; std::vector skeletons; std::vector meshes; std::vector nodes; + + friend class VbModelReaderTest; }; } diff --git a/vbModelReaderTest.cpp b/vbModelReaderTest.cpp new file mode 100644 index 0000000..c18d180 --- /dev/null +++ b/vbModelReaderTest.cpp @@ -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"); + } +} diff --git a/vbModelReaderTest.h b/vbModelReaderTest.h new file mode 100644 index 0000000..8a2c8f9 --- /dev/null +++ b/vbModelReaderTest.h @@ -0,0 +1,36 @@ +#ifndef VB_MODEL_READER_TEST +#define VB_MODEL_READER_TEST + +#include +#include +#include +#include + +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 skeletonData, meshData; + int numBones = 0; + }; +} + +#endif