mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
broken up class methods
This commit is contained in:
+2
-2
@@ -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)
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include"mesh.h"
|
||||
#include<glad.h>
|
||||
#include<glfw3.h>
|
||||
#include<glm.hpp>
|
||||
#include<ext.hpp>
|
||||
#include<iostream>
|
||||
|
||||
@@ -52,11 +51,9 @@ namespace vb01{
|
||||
void Light::update(){
|
||||
Root *root=Root::getSingleton();
|
||||
Node *rootNode=root->getRootNode();
|
||||
Camera *cam=root->getCamera();
|
||||
std::vector<Node*> descendants;
|
||||
std::vector<Material*> 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<Node*> 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<Material*> materials, int thisId, mat4 &proj, mat4 &view){
|
||||
for(Material *m : materials){
|
||||
Shader *shader=m->getShader();
|
||||
shader->use();
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
#define LIGHT_H
|
||||
|
||||
#include"vector.h"
|
||||
#include<vector>
|
||||
#include<glm.hpp>
|
||||
|
||||
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<Node*>, glm::mat4&, glm::mat4&);
|
||||
void updateShader(std::vector<Material*>, int, glm::mat4&, glm::mat4&);
|
||||
|
||||
Type type;
|
||||
Shader *depthMapShader;
|
||||
Texture *depthMap=nullptr;
|
||||
|
||||
@@ -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<Node*> 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],1<i&&i<4?vec3(0,0,-1):vec3(0,-1,0)),"shadowMat["+to_string(i)+"]");
|
||||
m->render();
|
||||
}
|
||||
}
|
||||
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;i<skeleton->getNumBones();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;j<numVertexGroups;j++)
|
||||
if(bone->getName() == 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;i<skeleton->getNumBones();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;j<numVertexGroups;j++)
|
||||
if(bone->getName() == 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<Node*> 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],1<i&&i<4?vec3(0,0,-1):vec3(0,-1,0)),"shadowMat["+to_string(i)+"]");
|
||||
m->render();
|
||||
}
|
||||
}
|
||||
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){
|
||||
|
||||
@@ -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;
|
||||
|
||||
+27
-24
@@ -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;i<numParticles;i++){
|
||||
@@ -52,6 +55,10 @@ namespace vb01{
|
||||
matrices[i]=mat4(1.f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ParticleEmitter::setupDisplay(Vertex vertices[], u32 indices[]){
|
||||
u32 MBO;
|
||||
glGenVertexArrays(1,&VAO);
|
||||
glGenBuffers(1,&VBO);
|
||||
glGenBuffers(1,&EBO);
|
||||
@@ -59,7 +66,7 @@ namespace vb01{
|
||||
glBindBuffer(GL_ARRAY_BUFFER,VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER,6*sizeof(Vertex),vertices,GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,EBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER,6*sizeof(unsigned int),indices,GL_STATIC_DRAW);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER,6*sizeof(u32),indices,GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(Vertex),(void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,sizeof(Vertex),(void*)(offsetof(Vertex,texCoords)));
|
||||
@@ -172,15 +179,11 @@ namespace vb01{
|
||||
Vector3 v0=particles[i]->trans;
|
||||
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<numParticles;i++){
|
||||
}
|
||||
|
||||
//glDisable(GL_CULL_FACE);
|
||||
//glEnable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
void ParticleEmitter::setDirection(Vector3 dir){
|
||||
|
||||
@@ -44,6 +44,8 @@ namespace vb01{
|
||||
|
||||
void makeHeap(int);
|
||||
void heapSort();
|
||||
void setupParticles(Vertex[]);
|
||||
void setupDisplay(Vertex[], u32[]);
|
||||
|
||||
unsigned int VAO,VBO,EBO,MBO;
|
||||
glm::mat4 *matrices;
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#include"rectangle.h"
|
||||
|
||||
namespace vb01{
|
||||
Rectangle::Rectangle(Vector3 size){
|
||||
|
||||
}
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
#ifndef RECTANGLE_H
|
||||
#define RECTANGLE_H
|
||||
|
||||
#include"vector.h"
|
||||
|
||||
namespace vb01{
|
||||
class Rectangle{
|
||||
public:
|
||||
Rectangle(Vector3);
|
||||
~Rectangle();
|
||||
void update();
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
+119
-96
@@ -74,25 +74,11 @@ namespace vb01{
|
||||
VbModelReader::~VbModelReader(){
|
||||
}
|
||||
|
||||
void VbModelReader::readSkeletons(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];
|
||||
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<string> &meshData, Skeleton *skeleton, int boneStartLine, int numBones){
|
||||
meshData.clear();
|
||||
readFile(path, meshData, boneStartLine, boneStartLine + numBones);
|
||||
vector<string> 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<string> &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<string> 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<string> &meshData,
|
||||
vector<Vector3> &vertPos,
|
||||
vector<Vector3> &vertNorm,
|
||||
vector<float> &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<string> &meshData,
|
||||
vector<Vector3> &vertPos,
|
||||
vector<Vector3> &vertNorm,
|
||||
vector<float> &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<string> 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();
|
||||
|
||||
|
||||
+6
-1
@@ -2,13 +2,14 @@
|
||||
#define VB_MODEL_READER
|
||||
|
||||
#include"modelReader.h"
|
||||
#include"util.h"
|
||||
#include"mesh.h"
|
||||
#include<string>
|
||||
#include<vector>
|
||||
|
||||
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<std::string>&, Skeleton*, int, int);
|
||||
void readAnimations(std::vector<std::string>&, Skeleton*, int, int);
|
||||
void readSkeletons(int, int);
|
||||
void readVertices(std::vector<std::string>&, std::vector<Vector3>&, std::vector<Vector3>&, std::vector<float>&, int, int, int);
|
||||
void readFaces(std::vector<std::string>&, std::vector<Vector3>&, std::vector<Vector3>&, std::vector<float>&, int, int, int, int, Mesh::Vertex*, u32*);
|
||||
void readMeshes(int, int);
|
||||
void readLights(int, int);
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#include"waterPlane.h"
|
||||
|
||||
namespace vb01{
|
||||
WaterPlane::WaterPlane(){}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
#ifndef WATER_PLANE_H
|
||||
#define WATER_PLANE_H
|
||||
|
||||
namespace vb01{
|
||||
class WaterPlane{
|
||||
public:
|
||||
WaterPlane();
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user