mirror of
https://github.com/ApfelTeeSaft/vb01.git
synced 2026-08-26 19:33:45 +00:00
compilation fixes
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ set(MATH quaternion.cpp vector.cpp matrix.cpp ray.cpp)
|
||||
set(RENDER lineRenderer.cpp particleEmitter.cpp camera.cpp light.cpp material.cpp mesh.cpp meshData.cpp model.cpp node.cpp quad.cpp box.cpp root.cpp shader.cpp texture.cpp)
|
||||
set(ANIM animationController.cpp animationChannel.cpp animation.cpp animatable.cpp keyframeChannel.cpp driver.cpp)
|
||||
set(ARMATURE skeleton.cpp bone.cpp ikSolver.cpp)
|
||||
set(ASSET_READERS abstractAssetReader.cpp imageReader.cpp fontReader.cpp modelReader.cpp assimpModelReader.cpp xmlModelReader.cpp)
|
||||
set(ASSET_READERS imageReader.cpp fontReader.cpp modelReader.cpp assimpModelReader.cpp xmlModelReader.cpp)
|
||||
set(ASSET_MANAGER assetManager.cpp textAsset.h imageAsset.h modelAsset.h fontAsset.h)
|
||||
set(LIB_SRC ${RENDER} ${MATH} ${UTILS} ${GUI} ${ARMATURE} ${ASSET_MANAGER} ${ASSET_READERS} ${ANIM})
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "util.h"
|
||||
#include "imageReader.h"
|
||||
#include "fontReader.h"
|
||||
#include "xmlModelReader.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -34,6 +35,11 @@ namespace vb01{
|
||||
if(find(fontFormats.begin(), fontFormats.end(), format) != fontFormats.end())
|
||||
assetReader = FontReader::getSingleton();
|
||||
|
||||
vector<string> modelFormats = vector<string>{"xml"};
|
||||
|
||||
if(find(modelFormats.begin(), modelFormats.end(), format) != modelFormats.end())
|
||||
assetReader = XmlModelReader::getSingleton();
|
||||
|
||||
assets.push_back(assetReader->readAsset(path));
|
||||
}
|
||||
|
||||
|
||||
+19
-4
@@ -1,5 +1,7 @@
|
||||
#include "assimpModelReader.h"
|
||||
#include "mesh.h"
|
||||
#include "modelAsset.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <Importer.hpp>
|
||||
#include <scene.h>
|
||||
@@ -9,16 +11,30 @@ using namespace std;
|
||||
using namespace Assimp;
|
||||
|
||||
namespace vb01{
|
||||
AssimpModelReader::AssimpModelReader(Model *model, string path) : ModelReader(model, path){
|
||||
AssimpModelReader *assimpModelReader = nullptr;
|
||||
|
||||
AssimpModelReader* AssimpModelReader::getSingleton(){
|
||||
if(!assimpModelReader)
|
||||
assimpModelReader = new AssimpModelReader();
|
||||
|
||||
return assimpModelReader;
|
||||
}
|
||||
|
||||
Asset* AssimpModelReader::readAsset(string path){
|
||||
Importer importer;
|
||||
const aiScene *scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals | aiProcess_CalcTangentSpace);
|
||||
|
||||
if(!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode){
|
||||
cout<<"Failed to load model:"<<importer.GetErrorString()<<endl;
|
||||
cout << "Failed to load model:" << importer.GetErrorString() << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
processNode(scene->mRootNode, scene, model);
|
||||
ModelAsset *asset = new ModelAsset();
|
||||
asset->path = path;
|
||||
asset->rootNode = new Node();
|
||||
processNode(scene->mRootNode, scene, asset->rootNode);
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
void AssimpModelReader::processNode(aiNode *node, const aiScene *scene, Node *currentNode){
|
||||
@@ -78,7 +94,6 @@ namespace vb01{
|
||||
}
|
||||
*/
|
||||
Mesh *vbMesh = new Mesh(MeshData(vertices, indices, numTris));
|
||||
vbMesh ->construct();
|
||||
currentNode->attachMesh(vbMesh);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-3
@@ -1,17 +1,22 @@
|
||||
#ifndef ASSIMP_MODEL_READER_H
|
||||
#define ASSIMP_MODEL_READER_H
|
||||
|
||||
#include "modelReader.h"
|
||||
#include "abstractAssetReader.h"
|
||||
|
||||
class aiNode;
|
||||
class aiMesh;
|
||||
class aiScene;
|
||||
|
||||
namespace vb01{
|
||||
class AssimpModelReader : public ModelReader{
|
||||
struct Asset;
|
||||
class Node;
|
||||
|
||||
class AssimpModelReader : public AbstractAssetReader{
|
||||
public:
|
||||
AssimpModelReader(Model*, std::string);
|
||||
static AssimpModelReader* getSingleton();
|
||||
Asset* readAsset(std::string);
|
||||
private:
|
||||
AssimpModelReader(){}
|
||||
void processNode(aiNode*, const aiScene*, Node*);
|
||||
void processMesh(aiMesh*, const aiScene*, Node*);
|
||||
void processMaterial();
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#include "root.h"
|
||||
#include "skeleton.h"
|
||||
#include "animation.h"
|
||||
#include "xmlModelReader.h"
|
||||
#include "assimpModelReader.h"
|
||||
#include "modelAsset.h"
|
||||
#include "assetManager.h"
|
||||
|
||||
#include <vector>
|
||||
#include <Importer.hpp>
|
||||
@@ -20,15 +20,14 @@ using namespace std;
|
||||
using namespace Assimp;
|
||||
|
||||
namespace vb01{
|
||||
Model::Model(string path) : Node(){
|
||||
int dotId = getCharId(path, '.', true);
|
||||
string extension = path.substr(dotId + 1, string::npos);
|
||||
ModelReader *modelReader = nullptr;
|
||||
Model::Model(string path) : Node(((ModelAsset*)AssetManager::getSingleton()->getAsset(path))->rootNode){
|
||||
vector<Node*> descendants;
|
||||
getDescendants(descendants);
|
||||
|
||||
if(extension == "xml")
|
||||
modelReader = new XmlModelReader(this, path);
|
||||
else
|
||||
modelReader = new AssimpModelReader(this, path);
|
||||
for(Node *desc : descendants)
|
||||
for(Mesh *mesh : desc->getMeshes()){
|
||||
mesh->construct();
|
||||
}
|
||||
}
|
||||
|
||||
Model::~Model(){
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ namespace vb01{
|
||||
class Node;
|
||||
|
||||
struct ModelAsset : public Asset{
|
||||
Node *rootNode;
|
||||
Node *rootNode = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "root.h"
|
||||
#include "node.h"
|
||||
#include "bone.h"
|
||||
#include "mesh.h"
|
||||
#include "particleEmitter.h"
|
||||
#include "light.h"
|
||||
@@ -20,10 +20,24 @@ namespace vb01{
|
||||
this->pos = pos;
|
||||
this->scale = scale;
|
||||
this->orientation = orientation;
|
||||
}
|
||||
|
||||
globalAxis[0] = Vector3::VEC_I;
|
||||
globalAxis[1] = Vector3::VEC_J;
|
||||
globalAxis[2] = Vector3::VEC_K;
|
||||
Node::Node(Node *node) : Animatable(node->getName()){
|
||||
for(Mesh *m : node->getMeshes())
|
||||
attachMesh(new Mesh(m->getMeshBase()));
|
||||
|
||||
for(Skeleton *skel : node->getSkeletons()){
|
||||
Skeleton *sk = new Skeleton();
|
||||
vector<Bone*> bones = skel->getBones();
|
||||
|
||||
for(Bone *b : bones)
|
||||
sk->addBone(b, nullptr);
|
||||
|
||||
addSkeleton(sk);
|
||||
}
|
||||
|
||||
for(Node *child : node->getChildren())
|
||||
attachChild(new Node(child));
|
||||
}
|
||||
|
||||
Node::~Node(){
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace vb01{
|
||||
class Node : public Animatable{
|
||||
public:
|
||||
Node(Vector3 = Vector3::VEC_ZERO, Quaternion = Quaternion::QUAT_W, Vector3 = Vector3::VEC_IJK, std::string = "");
|
||||
Node(Node*);
|
||||
virtual ~Node();
|
||||
void addSkeleton(Skeleton*);
|
||||
void attachMesh(Mesh*);
|
||||
@@ -78,7 +79,7 @@ namespace vb01{
|
||||
virtual float getDriverValue(Driver::VariableType);
|
||||
|
||||
bool visible = true;
|
||||
Vector3 pos, scale, globalAxis[3];
|
||||
Vector3 pos, scale, globalAxis[3]{Vector3::VEC_I, Vector3::VEC_J, Vector3::VEC_K};
|
||||
Quaternion orientation;
|
||||
std::vector<Mesh*> meshes;
|
||||
std::vector<ParticleEmitter*> emitters;
|
||||
|
||||
+24
-10
@@ -6,7 +6,7 @@
|
||||
#include "vector.h"
|
||||
#include "animationController.h"
|
||||
#include "animatable.h"
|
||||
#include "keyframeChannel.h"
|
||||
#include "modelAsset.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -16,17 +16,30 @@ using namespace std;
|
||||
using namespace tinyxml2;
|
||||
|
||||
namespace vb01{
|
||||
XmlModelReader::XmlModelReader(Model *model, string path) : ModelReader(model, path){
|
||||
XmlModelReader *xmlModelReader = nullptr;
|
||||
|
||||
XmlModelReader* XmlModelReader::getSingleton(){
|
||||
if(!xmlModelReader)
|
||||
xmlModelReader = new XmlModelReader();
|
||||
|
||||
return xmlModelReader;
|
||||
}
|
||||
|
||||
Asset* XmlModelReader::readAsset(string path){
|
||||
XMLDocument *doc = new XMLDocument();
|
||||
doc->LoadFile(path.c_str());
|
||||
|
||||
XMLElement *root = doc->FirstChildElement();
|
||||
ModelAsset *asset = new ModelAsset();
|
||||
asset->path = path;
|
||||
asset->rootNode = new Node();
|
||||
assetRootNode = asset->rootNode;
|
||||
|
||||
for(XMLElement *ch = root->FirstChildElement(); ch; ch = ch->NextSiblingElement())
|
||||
model->attachChild(processNode(model, ch));
|
||||
assetRootNode->attachChild(processNode(assetRootNode, ch));
|
||||
|
||||
vector<Node*> descendants;
|
||||
model->getDescendants(descendants);
|
||||
assetRootNode->getDescendants(descendants);
|
||||
setupDrivers(descendants);
|
||||
|
||||
vector<Mesh*> meshes;
|
||||
@@ -43,6 +56,8 @@ namespace vb01{
|
||||
delete m->getSkeleton();
|
||||
m->setSkeleton(sk);
|
||||
}
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
void XmlModelReader::setupDrivers(vector<Node*> descendants){
|
||||
@@ -87,7 +102,7 @@ namespace vb01{
|
||||
|
||||
i = 0;
|
||||
int numVertices = 3 * atoi(meshEl->Attribute("num_faces"));
|
||||
Mesh::Vertex *vertices = new Mesh::Vertex[numVertices];
|
||||
MeshData::Vertex *vertices = new MeshData::Vertex[numVertices];
|
||||
tagName = "vert";
|
||||
vector<u32> vertIds;
|
||||
u32 *indices = new u32[numVertices];
|
||||
@@ -110,7 +125,7 @@ namespace vb01{
|
||||
float biTanZ = atof(vertEl->Attribute("bz"));
|
||||
Vector3 biTan = Vector3(biTanX, biTanY, biTanZ);
|
||||
|
||||
Mesh::Vertex vertex;
|
||||
MeshData::Vertex vertex;
|
||||
vertex.pos = vertPos[id];
|
||||
vertex.norm = vertNorm[id];
|
||||
vertex.uv = uv;
|
||||
@@ -133,7 +148,7 @@ namespace vb01{
|
||||
tagName = "shapekey";
|
||||
i = 0;
|
||||
int numShapeKeys = atoi(meshEl->Attribute("num_shape_keys"));
|
||||
Mesh::ShapeKey *shapeKeys = new Mesh::ShapeKey[numShapeKeys];
|
||||
MeshData::ShapeKey *shapeKeys = new MeshData::ShapeKey[numShapeKeys];
|
||||
|
||||
for(XMLElement *shapeKeyEl = meshEl->FirstChildElement(tagName); shapeKeyEl && strcmp(shapeKeyEl->Name(), tagName) == 0; shapeKeyEl = shapeKeyEl->NextSiblingElement(), i++){
|
||||
shapeKeys[i].name = shapeKeyEl->Attribute("name");
|
||||
@@ -160,8 +175,7 @@ namespace vb01{
|
||||
vertices[j].shapeKeyOffsets[i] = shapeKeyPos[vertIds[j]] - vertPos[vertIds[j]];
|
||||
}
|
||||
|
||||
Mesh *mesh = new Mesh(vertices, indices, numVertices / 3, vertexGroups, numVertexGroups, shapeKeys, numShapeKeys);
|
||||
mesh->construct();
|
||||
Mesh *mesh = new Mesh(MeshData(vertices, indices, numVertices / 3, vertexGroups, numVertexGroups, shapeKeys, numShapeKeys));
|
||||
|
||||
const char *skeletonName = meshEl->Attribute("skeleton");
|
||||
|
||||
@@ -261,7 +275,7 @@ namespace vb01{
|
||||
Vector3 pos = head;
|
||||
|
||||
if(strcmp(xmlEl->Parent()->ToElement()->Name(), "skeleton") == 0){
|
||||
parent = model;
|
||||
parent = assetRootNode;
|
||||
swap(pos.y, pos.z);
|
||||
pos.z = -pos.z;
|
||||
swap(yAxis.y, yAxis.z);
|
||||
|
||||
+8
-3
@@ -1,7 +1,8 @@
|
||||
#ifndef XML_MODEL_READER_H
|
||||
#define XML_MODEL_READER_H
|
||||
|
||||
#include "modelReader.h"
|
||||
#include "abstractAssetReader.h"
|
||||
#include "keyframeChannel.h"
|
||||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
@@ -17,11 +18,14 @@ namespace vb01{
|
||||
class Animatable;
|
||||
class Animation;
|
||||
class Driver;
|
||||
struct Asset;
|
||||
|
||||
class XmlModelReader : public ModelReader{
|
||||
class XmlModelReader : public AbstractAssetReader{
|
||||
public:
|
||||
XmlModelReader(Model*, std::string);
|
||||
static XmlModelReader* getSingleton();
|
||||
Asset* readAsset(std::string);
|
||||
private:
|
||||
XmlModelReader(){};
|
||||
Node* processNode(Node*, tinyxml2::XMLElement*, bool = false);
|
||||
Mesh* processMesh(tinyxml2::XMLElement*);
|
||||
std::vector<KeyframeChannel> processKeyframeChannells(tinyxml2::XMLElement*);
|
||||
@@ -30,6 +34,7 @@ namespace vb01{
|
||||
void setupDrivers(std::vector<Node*>);
|
||||
|
||||
std::vector<std::pair<std::string, Driver*>> driversByNodeNames;
|
||||
Node *assetRootNode = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user