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