Files
Collage/include/types/model.h
2024-05-06 08:23:01 -04:00

52 lines
1.4 KiB
C++

#pragma once
#include <vector>
#include <sstream>
#include <fstream>
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra/Vector3.h>
#include<J3ML/Geometry.h>
#include <types/textureInfo.h>
typedef Vector3 Vertex;
enum struct ModelType : uint8_t {
WAVEFRONT_OBJ = 0,
ANIMATED_WAVEFRONT_OBJ = 1,
FBX = 2, //More complicated.
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
};
class Model {
private:
void loadOBJ(const std::string& filename);
void load(const std::string& file);
protected:
std::vector<Vertex> vertices;
std::vector<uint> indices;
std::vector<TextureInformation> textureInfo;
void mapFaces(const FaceIndices& facedata, const std::vector<Vector3>& positions, const std::vector<Vector2>& uvs);
public:
ModelType type;
const std::vector<Vertex>& getVertices();
const std::vector<uint>& getIndices();
const std::vector<TextureInformation>& getTextureInformation();
Model() = default;
explicit Model(const std::string& file);
};
class SkeletalModel : public Model {
protected:
std::vector<SkeletalVertex> vertices;
public:
std::vector<SkeletalVertex>& getSkeletalertices();
};