Some functions
This commit is contained in:
@@ -5,10 +5,11 @@ class Bone {
|
||||
protected:
|
||||
std::string name;
|
||||
Matrix4x4 matrix;
|
||||
float weight;
|
||||
//float weight;
|
||||
Bone* parent;
|
||||
std::vector<Bone*> children;
|
||||
public:
|
||||
int index;
|
||||
bool isRootBone();
|
||||
bool hasChildren();
|
||||
const Matrix4x4& getMatrix();
|
||||
@@ -16,7 +17,11 @@ public:
|
||||
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();
|
||||
void setParent(Bone* b);
|
||||
Bone* getChildByName(const std::string& bName);
|
||||
Bone* getChildByNameRecursive(const std::string& bName);
|
||||
Bone* getChildByIndexRecursive(int i);
|
||||
Bone* getFirstChild();
|
||||
const std::string& getName();
|
||||
void setName(const std::string& n);
|
||||
};
|
@@ -7,6 +7,7 @@
|
||||
#include <Collage/types/bone.h>
|
||||
|
||||
typedef Vector3 Vertex;
|
||||
typedef Vector3 TextureCoordinate;
|
||||
|
||||
enum struct ModelType : uint8_t {
|
||||
WAVEFRONT_OBJ = 0,
|
||||
@@ -15,26 +16,30 @@ enum struct ModelType : uint8_t {
|
||||
COLLADA = 3, //*Very* complicated.
|
||||
};
|
||||
|
||||
class SkeletalVertex : public Vertex {
|
||||
std::vector<int> bones; //The index of bones that can effect the vertex. 0 represents an empty slot. -1 represents the root bone.
|
||||
std::vector<float> weights; //The 4 weights must total to 1.0
|
||||
};
|
||||
|
||||
class Model {
|
||||
protected:
|
||||
void load(const std::string& file);
|
||||
void loadOBJ(const std::string& filename);
|
||||
void loadAMO(const std::string& filename);
|
||||
public:
|
||||
std::string name;
|
||||
ModelType type;
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<uint> indices;
|
||||
std::vector<TextureInformation> textureInfo;
|
||||
std::vector<TextureCoordinate> textureCoords;
|
||||
//std::vector<TextureInformation> textureInfo;
|
||||
Model() = default;
|
||||
explicit Model(const std::string& file);
|
||||
};
|
||||
|
||||
class SkeletalVertex : public Vertex {
|
||||
public:
|
||||
std::vector<int> bones; //The index of bones that can effect the vertex. 0 represents an empty slot. -1 represents the root bone.
|
||||
std::vector<float> weights;
|
||||
};
|
||||
|
||||
class SkeletalModel : public Model {
|
||||
protected:
|
||||
void loadAMO(const std::string& filename);
|
||||
public:
|
||||
std::vector<SkeletalVertex> vertices;
|
||||
Bone boneMap;
|
||||
|
@@ -33,12 +33,22 @@ Bone* Bone::getChildByName(const std::string& bName) {
|
||||
for (auto& bone : children)
|
||||
if (bone->name == bName)
|
||||
return bone;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Bone *Bone::getChildByNameRecursive(const std::string &bName) {
|
||||
Bone* Bone::getChildByNameRecursive(const std::string& bName) {
|
||||
if (children.empty())
|
||||
return nullptr;
|
||||
|
||||
for (auto& bone : children) {
|
||||
if (bone->name == bName)
|
||||
return bone;
|
||||
|
||||
Bone* result = bone->getChildByNameRecursive(bName);
|
||||
if (result != nullptr)
|
||||
return result;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Bone::hasChildren() {
|
||||
@@ -67,3 +77,29 @@ uint Bone::getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
const std::string &Bone::getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
void Bone::setName(const std::string &n) {
|
||||
name = n;
|
||||
}
|
||||
|
||||
void Bone::setParent(Bone * b) {
|
||||
parent = b;
|
||||
}
|
||||
|
||||
Bone* Bone::getChildByIndexRecursive(int ind) {
|
||||
if (children.empty())
|
||||
return nullptr;
|
||||
|
||||
for (auto& bone : children) {
|
||||
if (bone->index == ind)
|
||||
return bone;
|
||||
|
||||
Bone* result = bone->getChildByIndexRecursive(ind);
|
||||
if (result != nullptr)
|
||||
return result;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
Reference in New Issue
Block a user