diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f84b2f..60b45b2 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,10 +10,10 @@ include_directories(/usr/include/freetype2) link_directories(/usr/lib/) set(CMAKE_BUILD_TYPE Debug) -set(gui text.cpp rectangle.cpp) +set(gui text.cpp) set(utils util.cpp) set(math quaternion.cpp vector.cpp matrix.cpp ray.cpp) -set(render waterPlane.cpp particleEmitter.cpp camera.cpp light.cpp material.cpp mesh.cpp model.cpp node.cpp quad.cpp box.cpp root.cpp shader.cpp texture.cpp) +set(render particleEmitter.cpp camera.cpp light.cpp material.cpp mesh.cpp model.cpp node.cpp quad.cpp box.cpp root.cpp shader.cpp texture.cpp) set(model modelReader.cpp assimpModelReader.cpp vbModelReader.cpp) set(anim animationController.cpp animationChannel.cpp animation.cpp) set(armature skeleton.cpp bone.cpp) diff --git a/light.cpp b/light.cpp index 415c47c..a76e4cc 100755 --- a/light.cpp +++ b/light.cpp @@ -7,7 +7,6 @@ #include"mesh.h" #include #include -#include #include #include @@ -52,11 +51,9 @@ namespace vb01{ void Light::update(){ Root *root=Root::getSingleton(); Node *rootNode=root->getRootNode(); - Camera *cam=root->getCamera(); std::vector descendants; std::vector materials; - rootNode->getDescendants(rootNode,descendants); - descendants.push_back(rootNode); + Camera *cam=root->getCamera(); int thisId=-1; float fov=cam->getFov(),width=root->getWidth(),height=root->getHeight(); @@ -69,6 +66,14 @@ namespace vb01{ for(Mesh *m : d->getMeshes()) materials.push_back(m->getMaterial()); } + 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), @@ -77,7 +82,8 @@ namespace vb01{ vec3(0,0,1), vec3(0,0,-1) }; - mat4 proj=mat4(1.),view=mat4(1.); + Root *root = Root::getSingleton(); + glViewport(0,0,depthMapSize,depthMapSize); glBindFramebuffer(GL_FRAMEBUFFER,depthmapFBO); glClear(GL_DEPTH_BUFFER_BIT); @@ -127,7 +133,9 @@ namespace vb01{ } glBindFramebuffer(GL_FRAMEBUFFER,*(root->getFBO())); glViewport(0,0,root->getWidth(),root->getHeight()); + } + void Light::updateShader(vector materials, int thisId, mat4 &proj, mat4 &view){ for(Material *m : materials){ Shader *shader=m->getShader(); shader->use(); diff --git a/light.h b/light.h index e256f73..db7735b 100755 --- a/light.h +++ b/light.h @@ -2,11 +2,15 @@ #define LIGHT_H #include"vector.h" +#include +#include namespace vb01{ class Node; class Texture; class Shader; + class Material; + class Light{ public: @@ -36,6 +40,9 @@ namespace vb01{ inline float getShadowFarPlane(){return farPlane;} inline Node* getNode(){return node;} private: + void renderShadow(std::vector, glm::mat4&, glm::mat4&); + void updateShader(std::vector, int, glm::mat4&, glm::mat4&); + Type type; Shader *depthMapShader; Texture *depthMap=nullptr; diff --git a/mesh.cpp b/mesh.cpp index 82a2980..3df22fb 100755 --- a/mesh.cpp +++ b/mesh.cpp @@ -110,49 +110,6 @@ namespace vb01{ camPos=cam->getPosition(); } - if(reflect){ - glViewport(0,0,width,width); - glBindFramebuffer(GL_FRAMEBUFFER,environmentBuffer); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - 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) - }; - environmentShader->use(); - Node *rootNode=root->getRootNode(); - vector descendants; - rootNode->getDescendants(rootNode,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); - 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],1render(); - } - } - glBindFramebuffer(GL_FRAMEBUFFER,*(root->getFBO())); - glViewport(0,0,root->getWidth(),root->getHeight()); - } - Vector3 rotAxis=orient.getAxis(); if(rotAxis==Vector3::VEC_ZERO) rotAxis=Vector3::VEC_I; @@ -166,6 +123,13 @@ namespace vb01{ material->update(); Shader *shader=material->getShader(); + + if(reflect) + updateReflection(shader, pos, width, height); + + if(skeleton) + updateSkeleton(shader); + shader->setBool(castShadow,"castShadow"); shader->setBool(skeleton,"animated"); shader->setBool(false,"environment"); @@ -174,52 +138,6 @@ namespace vb01{ shader->setVec3(camPos,"camPos"); shader->setMat4(model,"model"); - if(skeleton){ - skeleton->update(); - - shader->editShader(Shader::VERTEX_SHADER,2,"const int numBones="+to_string(skeleton->getNumBones())+";"); - shader->editShader(Shader::VERTEX_SHADER,3,"const int numVertGroups="+to_string(numVertexGroups)+";"); - - Node *modelNode = skeleton->getRootBone()->getParent(); - for(int i=0;igetNumBones();i++){ - Bone *bone = skeleton->getBone(i), *parent = (Bone*)bone->getParent(); - Vector3 boneAxis[]{ - bone->getInitAxis(0), - bone->getInitAxis(1), - bone->getInitAxis(2) - }; - Vector3 posePos = bone->getPosePos(); - Quaternion poseRot = bone->getPoseRot(); - Vector3 trans = boneAxis[0]*posePos.x+boneAxis[1]*posePos.y+boneAxis[2]*posePos.z; - Vector3 scale = bone->getPoseScale(); - Vector3 bonePos = bone->getModelSpacePos(); - - int vertGroupId = -1, parentId = -1; - for(int j=0;jgetName() == vertexGroups[j]) - vertGroupId = j; - for(int j = 0;j < skeleton->getNumBones();j++) - if(skeleton->getBone(j) == parent){ - parentId = j; - break; - } - - shader->setVec3(bonePos,"bones["+to_string(i)+"].pos"); - shader->setVec3(trans,"bones["+to_string(i)+"].trans"); - shader->setVec3(poseRot.getAxis(),"bones["+to_string(i)+"].rotAxis"); - shader->setFloat(poseRot.getAngle(),"bones["+to_string(i)+"].angle"); - shader->setVec3(scale,"bones["+to_string(i)+"].scale"); - shader->setInt(vertGroupId,"bones["+to_string(i)+"].vertGroup"); - shader->setInt(parentId,"bones["+to_string(i)+"].parent"); - } - } - - if(reflect){ - shader->setBool(reflect,"environmentMapEnabled"); - root->getSkybox()->getMaterial()->getDiffuseMap(0)->select(4); - environmentMap->select(4); - } - if(material->getType()==Material::MATERIAL_GUI){ shader->setVec2(Vector2((float)width,(float)height),"screen"); if(node) @@ -229,6 +147,95 @@ namespace vb01{ render(); } + void Mesh::updateSkeleton(Shader *shader){ + skeleton->update(); + + shader->editShader(Shader::VERTEX_SHADER,2,"const int numBones="+to_string(skeleton->getNumBones())+";"); + shader->editShader(Shader::VERTEX_SHADER,3,"const int numVertGroups="+to_string(numVertexGroups)+";"); + + Node *modelNode = skeleton->getRootBone()->getParent(); + for(int i=0;igetNumBones();i++){ + Bone *bone = skeleton->getBone(i), *parent = (Bone*)bone->getParent(); + Vector3 boneAxis[]{ + bone->getInitAxis(0), + bone->getInitAxis(1), + bone->getInitAxis(2) + }; + Vector3 posePos = bone->getPosePos(); + Quaternion poseRot = bone->getPoseRot(); + Vector3 trans = boneAxis[0]*posePos.x+boneAxis[1]*posePos.y+boneAxis[2]*posePos.z; + Vector3 scale = bone->getPoseScale(); + Vector3 bonePos = bone->getModelSpacePos(); + + int vertGroupId = -1, parentId = -1; + for(int j=0;jgetName() == vertexGroups[j]) + vertGroupId = j; + for(int j = 0;j < skeleton->getNumBones();j++) + if(skeleton->getBone(j) == parent){ + parentId = j; + break; + } + + shader->setVec3(bonePos,"bones["+to_string(i)+"].pos"); + shader->setVec3(trans,"bones["+to_string(i)+"].trans"); + shader->setVec3(poseRot.getAxis(),"bones["+to_string(i)+"].rotAxis"); + shader->setFloat(poseRot.getAngle(),"bones["+to_string(i)+"].angle"); + shader->setVec3(scale,"bones["+to_string(i)+"].scale"); + shader->setInt(vertGroupId,"bones["+to_string(i)+"].vertGroup"); + shader->setInt(parentId,"bones["+to_string(i)+"].parent"); + } + } + + 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(rootNode,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); + 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],1render(); + } + } + glBindFramebuffer(GL_FRAMEBUFFER,*(root->getFBO())); + glViewport(0,0,root->getWidth(),root->getHeight()); + + shader->setBool(reflect,"environmentMapEnabled"); + root->getSkybox()->getMaterial()->getDiffuseMap(0)->select(4); + environmentMap->select(4); + } + void Mesh::render(){ glBindVertexArray(VAO); if(!staticVerts){ diff --git a/mesh.h b/mesh.h index cbaecb3..06e13a1 100755 --- a/mesh.h +++ b/mesh.h @@ -46,6 +46,9 @@ namespace vb01{ inline Skeleton* getSkeleton(){return skeleton;} inline unsigned int* getIndices(){return indices;} private: + void updateSkeleton(Shader*); + void updateReflection(Shader*, Vector3, int, int); + Shader *environmentShader=nullptr; u32 environmentBuffer; Texture *environmentMap; diff --git a/particleEmitter.cpp b/particleEmitter.cpp index a9e9de5..d36c09b 100755 --- a/particleEmitter.cpp +++ b/particleEmitter.cpp @@ -15,34 +15,37 @@ using namespace std; namespace vb01{ ParticleEmitter::ParticleEmitter(int numParticles){ - this->numParticles=numParticles; + this->numParticles = numParticles; + Vertex v1, v2, v3, v4, v5, v6; + ParticleEmitter::Vertex vertices[] = {v1, v2, v3, v4, v5, v6}; + u32 indices[] = {0, 1, 2, 3, 4, 5}; + setupParticles(vertices); + setupDisplay(vertices, indices); + } + + void ParticleEmitter::setupParticles(Vertex vertices[]){ particles=new Particle*[numParticles]; - Vertex v1,v2,v3,v4,v5,v6; Vector2 size=Vector2(.5,.5); - v1.pos=Vector3(size.x/2,size.y/2,0); - v1.texCoords=Vector2(1,1); + vertices[0].pos=Vector3(size.x/2,size.y/2,0); + vertices[0].texCoords=Vector2(1,1); - v2.pos=Vector3(-size.x/2,size.y/2,0); - v2.texCoords=Vector2(0,1); + vertices[1].pos=Vector3(-size.x/2,size.y/2,0); + vertices[1].texCoords=Vector2(0,1); - v3.pos=Vector3(-size.x/2,-size.y/2,0); - v3.texCoords=Vector2(0,0); + vertices[2].pos=Vector3(-size.x/2,-size.y/2,0); + vertices[2].texCoords=Vector2(0,0); - v4.pos=Vector3(-size.x/2,-size.y/2,0); - v4.texCoords=Vector2(0,0); + vertices[3].pos=Vector3(-size.x/2,-size.y/2,0); + vertices[3].texCoords=Vector2(0,0); - v5.pos=Vector3(size.x/2,-size.y/2,0); - v5.texCoords=Vector2(1,0); + vertices[4].pos=Vector3(size.x/2,-size.y/2,0); + vertices[4].texCoords=Vector2(1,0); - v6.pos=Vector3(size.x/2,size.y/2,0); - v6.texCoords=Vector2(1,1); + vertices[5].pos=Vector3(size.x/2,size.y/2,0); + vertices[5].texCoords=Vector2(1,1); - ParticleEmitter::Vertex vertices[]={v1,v2,v3,v4,v5,v6}; - unsigned int indices[]={0,1,2,3,4,5}; - - u32 MBO; mat4 *matrices=new mat4[numParticles]; for(int i=0;itrans; particles[i]->d=cos(camDir.getAngleBetween((v0-camPos).norm()))*camPos.getDistanceFrom(v0); } + heapSort(); glBindVertexArray(VAO); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glDrawElementsInstanced(GL_TRIANGLES,6,GL_UNSIGNED_INT,0,numParticles); - for(int i=0;i meshData; - readFile(path, meshData, startLine + 1, startLine + 7); - string name = meshData[0].substr(getCharId(meshData[0], ':') + 2, string::npos); - string line = meshData[5]; - string data[3]; - getLineData(line, data, 3); - - int numBones = atoi(data[1].c_str()); - int numAnimations = atoi(data[2].c_str()); - int boneStartLine = startLine + 7; - int animationStartLine = boneStartLine + numBones + 1; - - Skeleton *skeleton = new Skeleton(name); - skeletons.push_back(skeleton); - + void VbModelReader::readBones(vector &meshData, Skeleton *skeleton, int boneStartLine, int numBones){ meshData.clear(); readFile(path, meshData, boneStartLine, boneStartLine + numBones); vector ikRelationships; + for(string line : meshData){ int colonId = getCharId(line, ':'); string preColon = line.substr(0, colonId); @@ -136,19 +122,23 @@ namespace vb01{ if(ikTarget != "-") ikRelationships.push_back(preColon + " " + ikTarget); } + for(string ikRelationship : ikRelationships){ int spaceId = getCharId(ikRelationship, ' '); string targetBoneName = ikRelationship.substr(0, spaceId); string ikTargetBoneName = ikRelationship.substr(spaceId + 1); skeleton->getBone(targetBoneName)->setIkTarget(skeleton->getBone(ikTargetBoneName)); } + } + void VbModelReader::readAnimations(vector &meshData, Skeleton *skeleton, int animationStartLine, int endLine){ AnimationController *controller = skeleton->getAnimationController(); string animName = ""; Bone *animBone = nullptr; Animation::KeyframeGroup::KeyframeChannel::Type type; meshData.clear(); readFile(path, meshData, animationStartLine, endLine + 1); + for(string l : meshData){ int colonId = getCharId(l, ':'); string preColon = l.substr(0, colonId); @@ -163,6 +153,7 @@ namespace vb01{ animBone = b; Animation *anim = controller->getAnimation(animName); Animation::KeyframeGroup *group = anim->getKeyframeGroup(animBone); + if(!group){ Animation::KeyframeGroup kg; kg.bone = animBone; @@ -176,38 +167,22 @@ namespace vb01{ if(l == "}") break; - else if(preColon == "pos_x"){ - type = KeyframeChannelType::POS_X; - channel.type = type; - keyframeGroup->keyframeChannels.push_back(channel); - } - else if(preColon == "pos_y"){ - type = KeyframeChannelType::POS_Y; - channel.type = type; - keyframeGroup->keyframeChannels.push_back(channel); - } - else if(preColon == "pos_z"){ - type = KeyframeChannelType::POS_Z; - channel.type = type; - keyframeGroup->keyframeChannels.push_back(channel); - } - else if(preColon == "rot_w"){ - type = KeyframeChannelType::ROT_W; - channel.type = type; - keyframeGroup->keyframeChannels.push_back(channel); - } - else if(preColon == "rot_x"){ - type = KeyframeChannelType::ROT_X; - channel.type = type; - keyframeGroup->keyframeChannels.push_back(channel); - } - else if(preColon == "rot_y"){ - type = KeyframeChannelType::ROT_Y; - channel.type = type; - keyframeGroup->keyframeChannels.push_back(channel); - } - else if(preColon == "rot_z"){ - type = KeyframeChannelType::ROT_Z; + else if(preColon == "pos_x" || preColon == "pos_y" || preColon == "pos_z" || preColon == "rot_w" || preColon == "rot_x" || preColon == "rot_y" || preColon == "rot_z"){ + if(preColon == "pos_x") + type = KeyframeChannelType::POS_X; + else if(preColon == "pos_y") + type = KeyframeChannelType::POS_Y; + else if(preColon == "pos_z") + type = KeyframeChannelType::POS_Z; + else if(preColon == "rot_w") + type = KeyframeChannelType::ROT_W; + else if(preColon == "rot_x") + type = KeyframeChannelType::ROT_X; + else if(preColon == "rot_y") + type = KeyframeChannelType::ROT_Y; + else if(preColon == "rot_z") + type = KeyframeChannelType::ROT_Z; + channel.type = type; keyframeGroup->keyframeChannels.push_back(channel); } @@ -234,6 +209,100 @@ namespace vb01{ } } + void VbModelReader::readSkeletons(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]; + string data[3]; + getLineData(line, data, 3); + + int numBones = atoi(data[1].c_str()); + int numAnimations = atoi(data[2].c_str()); + int boneStartLine = startLine + 7; + int animationStartLine = boneStartLine + numBones + 1; + + Skeleton *skeleton = new Skeleton(name); + skeletons.push_back(skeleton); + + readBones(meshData, skeleton, boneStartLine, numBones); + + readAnimations(meshData, skeleton, animationStartLine, endLine); + + } + + void VbModelReader::readVertices( + vector &meshData, + vector &vertPos, + vector &vertNorm, + vector &vertWeights, + int vertexStartLine, + int numVertices, + int numBones + ){ + meshData.clear(); + readFile(path, meshData, vertexStartLine, vertexStartLine + numVertices); + for(string line : meshData){ + int numData = 6 + numBones; + string data[numData]; + getLineData(line, data, numData); + Vector3 vPos = Vector3(atof(data[0].c_str()), atof(data[2].c_str()), -atof(data[1].c_str())); + Vector3 vNorm = Vector3(atof(data[3].c_str()), atof(data[5].c_str()), -atof(data[4].c_str())); + vertPos.push_back(vPos); + vertNorm.push_back(vNorm); + + for(int j = 0; j < numBones; j++) + vertWeights.push_back(atof(data[6 + j].c_str())); + } + } + + void VbModelReader::readFaces( + vector &meshData, + vector &vertPos, + vector &vertNorm, + vector &vertWeights, + int faceStartLine, + int numFaces, + int numVertsPerFace, + int numBones, + Mesh::Vertex *vertices, + u32 *indices + ){ + int i = 0; + meshData.clear(); + readFile(path, meshData, faceStartLine, faceStartLine + numFaces * numVertsPerFace); + for(string line : meshData){ + int numData = 9; + string data[numData]; + getLineData(line,data,numData); + int index = atoi(data[0].c_str()); + + Vector2 uv = Vector2(atof(data[1].c_str()), atof(data[2].c_str())); + Vector3 tan = Vector3(atof(data[3].c_str()), atof(data[5].c_str()), -atof(data[4].c_str())); + Vector3 biTan = Vector3(atof(data[6].c_str()), atof(data[8].c_str()), -atof(data[7].c_str())); + + Mesh::Vertex vert; + vert.pos = vertPos[index]; + vert.norm = vertNorm[index]; + vert.tan = tan; + vert.biTan = biTan; + vert.uv = uv; + + for(int j = 0, boneIndex = 0; j < numBones; j++){ + if(vertWeights[index * numBones + j] > 0){ + vert.boneIndices[boneIndex] = j; + vert.weights[boneIndex] = vertWeights[index * numBones + j]; + boneIndex++; + } + } + + vertices[i] = vert; + indices[i] = i; + + i++; + } + } + void VbModelReader::readMeshes(int startLine, int endLine){ vector meshData; readFile(path, meshData, startLine + 1, startLine + 8); @@ -283,54 +352,8 @@ namespace vb01{ groups[i] = meshData[i]; } - meshData.clear(); - readFile(path, meshData, vertexStartLine, vertexStartLine + numVertices); - for(string line : meshData){ - int numData = 6 + numBones; - string data[numData]; - getLineData(line, data, numData); - Vector3 vPos = Vector3(atof(data[0].c_str()), atof(data[2].c_str()), -atof(data[1].c_str())); - Vector3 vNorm = Vector3(atof(data[3].c_str()), atof(data[5].c_str()), -atof(data[4].c_str())); - vertPos.push_back(vPos); - vertNorm.push_back(vNorm); - - for(int j = 0; j < numBones; j++) - vertWeights.push_back(atof(data[6 + j].c_str())); - } - - meshData.clear(); - readFile(path, meshData, faceStartLine, faceStartLine + numFaces * numVertsPerFace); - int i = 0; - for(string line : meshData){ - int numData = 9; - string data[numData]; - getLineData(line,data,numData); - int index = atoi(data[0].c_str()); - - Vector2 uv = Vector2(atof(data[1].c_str()), atof(data[2].c_str())); - Vector3 tan = Vector3(atof(data[3].c_str()), atof(data[5].c_str()), -atof(data[4].c_str())); - Vector3 biTan = Vector3(atof(data[6].c_str()), atof(data[8].c_str()), -atof(data[7].c_str())); - - Mesh::Vertex vert; - vert.pos = vertPos[index]; - vert.norm = vertNorm[index]; - vert.tan = tan; - vert.biTan = biTan; - vert.uv = uv; - - for(int j = 0, boneIndex = 0; j < numBones; j++){ - if(vertWeights[index * numBones + j] > 0){ - vert.boneIndices[boneIndex] = j; - vert.weights[boneIndex] = vertWeights[index * numBones + j]; - boneIndex++; - } - } - - vertices[i] = vert; - indices[i] = i; - - i++; - } + readVertices(meshData, vertPos, vertNorm, vertWeights, vertexGroupStartLine, numVertices, numBones); + readFaces(meshData, vertPos, vertNorm, vertWeights, faceStartLine, numFaces, numVertsPerFace, numBones, vertices, indices); meshData.clear(); diff --git a/vbModelReader.h b/vbModelReader.h index 5cc4b7e..6fd7e83 100644 --- a/vbModelReader.h +++ b/vbModelReader.h @@ -2,13 +2,14 @@ #define VB_MODEL_READER #include"modelReader.h" +#include"util.h" +#include"mesh.h" #include #include namespace vb01{ class Model; class Node; - class Mesh; class Skeleton; class VbModelReader : public ModelReader{ @@ -16,7 +17,11 @@ namespace vb01{ VbModelReader(Model*, std::string); ~VbModelReader(); private: + void readBones(std::vector&, Skeleton*, int, int); + void readAnimations(std::vector&, Skeleton*, int, int); void readSkeletons(int, int); + void readVertices(std::vector&, std::vector&, std::vector&, std::vector&, int, int, int); + void readFaces(std::vector&, std::vector&, std::vector&, std::vector&, int, int, int, int, Mesh::Vertex*, u32*); void readMeshes(int, int); void readLights(int, int); diff --git a/waterPlane.cpp b/waterPlane.cpp deleted file mode 100755 index 6bb5321..0000000 --- a/waterPlane.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include"waterPlane.h" - -namespace vb01{ - WaterPlane::WaterPlane(){} -} diff --git a/waterPlane.h b/waterPlane.h deleted file mode 100755 index e510694..0000000 --- a/waterPlane.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef WATER_PLANE_H -#define WATER_PLANE_H - -namespace vb01{ - class WaterPlane{ - public: - WaterPlane(); - private: - }; -} - -#endif