Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
5a65f57ad7 | |||
c294f6e50a | |||
9e1dce1a2a | |||
874abdc26d |
15
README.md
Normal file
15
README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
## Collage
|
||||
#### [](http://unlicense.org/)
|
||||
|
||||
Another model loader for Linux & Windows.
|
||||
|
||||
### Supported Formats
|
||||
- Wavefront OBJ
|
||||
- Animated Wavefront OBJ
|
||||
- Collada (maybe)
|
||||
- FBX
|
||||
|
||||
### Building The Demo
|
||||
```bash
|
||||
git clone https://git.redacted.cc/Redacted/Collage.git && cd Collage && mkdir build && cd build && cmake .. && make -j8
|
||||
```
|
2
include/Collage/collage.h
Normal file
2
include/Collage/collage.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#pragma once
|
||||
#include <Collage/types/model.h>
|
10
include/Collage/types/animation.h
Normal file
10
include/Collage/types/animation.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <Collage/types/bone.h>
|
||||
|
||||
struct KeyFrame {
|
||||
uint index;
|
||||
Bone bone;
|
||||
};
|
||||
|
||||
typedef std::vector<KeyFrame> Animation;
|
@@ -14,6 +14,7 @@ public:
|
||||
const Matrix4x4& getMatrix();
|
||||
void setMatrix(const Matrix4x4& m);
|
||||
void appendChild(const Bone& bone);
|
||||
uint getDepth(); //The "depth" refers to how far in the bone is on the bonemap. For ex, the fingers would be deeper than the elbow.
|
||||
Bone* getParent();
|
||||
Bone* getChildByName(const std::string& bName);
|
||||
Bone* getChildByNameRecursive(const std::string& bName);
|
2
include/Collage/types/keyFrame.h
Normal file
2
include/Collage/types/keyFrame.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#pragma once
|
||||
#include <Collage/types/bone.h>
|
@@ -5,7 +5,7 @@
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include<J3ML/Geometry.h>
|
||||
#include <types/textureInfo.h>
|
||||
#include <Collage/types/textureInfo.h>
|
||||
|
||||
typedef Vector3 Vertex;
|
||||
|
||||
@@ -16,6 +16,11 @@ enum struct ModelType : uint8_t {
|
||||
COLLADA = 3, //*Very* complicated.
|
||||
};
|
||||
|
||||
struct FaceIndices {
|
||||
unsigned int vertexIndex[3];
|
||||
unsigned int texCoordIndex[3];
|
||||
};
|
||||
|
||||
class SkeletalVertex : public Vertex {
|
||||
int8_t joints[3]; //The index of 4 bones that can effect the vertex. 0 represents an empty slot. -1 represents the root bone.
|
||||
Vector4 weights; //The 4 weights must total to 1.0
|
||||
@@ -23,23 +28,23 @@ class SkeletalVertex : public Vertex {
|
||||
|
||||
class Model {
|
||||
protected:
|
||||
void load(const std::string& file);
|
||||
void loadOBJ(const std::string& filename);
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<uint> indices;
|
||||
std::vector<TextureInformation> textureInfo;
|
||||
void load(const std::string& file);
|
||||
void load(const std::string& file, const ModelType& type);
|
||||
public:
|
||||
ModelType type;
|
||||
const std::vector<Vertex>& getVertices();
|
||||
const std::vector<uint>& getIndices();
|
||||
const std::vector<TextureInformation>& getTextureInformation();
|
||||
Model() = default;
|
||||
Model(const std::string& file);
|
||||
explicit Model(const std::string& file);
|
||||
};
|
||||
|
||||
class SkeletalModel : public Model {
|
||||
protected:
|
||||
std::vector<SkeletalVertex> vertices;
|
||||
public:
|
||||
std::vector<SkeletalVertex>& getSkeletalertices();
|
||||
std::vector<SkeletalVertex>& getSkeletalVertices();
|
||||
};
|
@@ -3,6 +3,6 @@
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
|
||||
struct TextureInformation {
|
||||
std::string name;
|
||||
std::string path;
|
||||
std::vector<Vector2> textureCoordinates;
|
||||
};
|
@@ -1,2 +0,0 @@
|
||||
#pragma once
|
||||
#include <types/model.h>
|
@@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <types/keyFrame.h>
|
||||
|
||||
typedef std::vector<KeyFrame> Animation;
|
@@ -1,7 +0,0 @@
|
||||
#pragma once
|
||||
#include <types/bone.h>
|
||||
|
||||
struct KeyFrame {
|
||||
uint index;
|
||||
Bone bone;
|
||||
};
|
45
src/obj.cpp
Normal file
45
src/obj.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <iostream>
|
||||
#include <Collage/types/model.h>
|
||||
|
||||
void Model::loadOBJ(const std::string& filename) {
|
||||
std::ifstream file(filename);
|
||||
std::vector<Vector3> positions;
|
||||
std::vector<Vector2> uvs;
|
||||
TextureInformation tInfo = {};
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
std::istringstream stream(line);
|
||||
std::string prefix;
|
||||
stream >> prefix;
|
||||
|
||||
if (prefix == "v") {
|
||||
float x, y, z;
|
||||
stream >> x >> y >> z;
|
||||
positions.emplace_back(x, y, z);
|
||||
} else if (prefix == "vt") {
|
||||
float u, v;
|
||||
stream >> u >> v;
|
||||
uvs.emplace_back(u, v);
|
||||
} else if (prefix == "f") {
|
||||
unsigned int vertexIndex[3], texCoordIndex[3];
|
||||
char slash;
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
stream >> vertexIndex[i] >> slash >> texCoordIndex[i];
|
||||
vertexIndex[i]--;
|
||||
texCoordIndex[i]--;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
Vertex vertex;
|
||||
Vector2 textureCoordinate;
|
||||
vertex = positions[vertexIndex[i]];
|
||||
textureCoordinate = uvs[texCoordIndex[i]];
|
||||
vertices.push_back(vertex);
|
||||
tInfo.textureCoordinates.push_back(textureCoordinate);
|
||||
indices.push_back(static_cast<unsigned int>(indices.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
textureInfo.push_back(tInfo);
|
||||
file.close();
|
||||
};
|
@@ -1,2 +1,2 @@
|
||||
#include <types/animation.h>
|
||||
#include <types/keyFrame.h>
|
||||
#include <Collage/types/animation.h>
|
||||
#include <Collage/types/keyFrame.h>
|
@@ -1,4 +1,4 @@
|
||||
#include <types/bone.h>
|
||||
#include <Collage/types/bone.h>
|
||||
|
||||
const Matrix4x4& Bone::getMatrix() {
|
||||
return matrix;
|
||||
@@ -53,3 +53,17 @@ Bone* Bone::getParent() {
|
||||
return this;
|
||||
return parent;
|
||||
}
|
||||
|
||||
uint Bone::getDepth() {
|
||||
if (isRootBone())
|
||||
return 0;
|
||||
|
||||
Bone* b = parent;
|
||||
uint depth = 1;
|
||||
while (b != nullptr && !b->isRootBone()) {
|
||||
b = b->getParent();
|
||||
depth++;
|
||||
}
|
||||
return depth;
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include <types/bone.h>
|
||||
#include <Collage/types/bone.h>
|
||||
struct BoneMap {
|
||||
std::vector<Bone> bones;
|
||||
};
|
@@ -1,64 +1,8 @@
|
||||
#include <types/model.h>
|
||||
|
||||
struct FaceIndices {
|
||||
unsigned int vertexIndex[3];
|
||||
unsigned int texCoordIndex[3];
|
||||
};
|
||||
|
||||
Vector3 ParseVertexCoordinatesFromOBJ(std::istringstream& stream) {
|
||||
float x, y, z;
|
||||
stream >> x >> y >> z;
|
||||
return {x,y,z};
|
||||
}
|
||||
|
||||
Vector2 ParseVertexTextureCoordinatesFromOBJ(std::istringstream& stream) {
|
||||
float u, v;
|
||||
stream >> u >> v;
|
||||
return {u,v};
|
||||
}
|
||||
|
||||
FaceIndices ParseFaceIndicesFromOBJ(std::istringstream& stream) {
|
||||
FaceIndices face{};
|
||||
char slash;
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
unsigned int vI;
|
||||
unsigned int tCI;
|
||||
|
||||
stream >> vI >> slash >> tCI;
|
||||
|
||||
face.vertexIndex[i] = vI;
|
||||
face.texCoordIndex[i] = tCI;
|
||||
|
||||
// Shift vertexindex by 1
|
||||
face.vertexIndex[i]--;
|
||||
// shift texcoordindex by 1
|
||||
face.texCoordIndex[i]--;
|
||||
}
|
||||
return face;
|
||||
}
|
||||
|
||||
/*
|
||||
// map face of model to positions and texture coords
|
||||
void Model::mapfaces(const FaceIndices& facedata, const std::vector<Vector3>& positions, const std::vector<Vector2>& uvs) {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
Vector3 vertex;
|
||||
Vector2 textureCoordinate;
|
||||
vertex = positions[facedata.vertexIndex[i]];
|
||||
textureCoordinate = uvs[facedata.texCoordIndex[i]];
|
||||
|
||||
vertices.push_back(vertex);
|
||||
textureCoor.push_back(textureCoordinate);
|
||||
indices.push_back(static_cast<unsigned int>(indices.size()));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void Model::load(const std::string& file, const ModelType& modelType) {
|
||||
//TODO: Call correct func.
|
||||
}
|
||||
#include <Collage/types/model.h>
|
||||
|
||||
void Model::load(const std::string& file) {
|
||||
//TODO: Determine model type and call correct func.
|
||||
if (file.ends_with(".obj"))
|
||||
loadOBJ(file);
|
||||
}
|
||||
|
||||
const std::vector<Vector3>& Model::getVertices() {
|
||||
@@ -77,6 +21,6 @@ Model::Model(const std::string &file) {
|
||||
load(file);
|
||||
}
|
||||
|
||||
std::vector<SkeletalVertex> &SkeletalModel::getSkeletalertices() {
|
||||
std::vector<SkeletalVertex>& SkeletalModel::getSkeletalVertices() {
|
||||
return vertices;
|
||||
}
|
||||
|
Reference in New Issue
Block a user