From 910833cc4d93828ef87d2f25f6eb1f723a1569ac Mon Sep 17 00:00:00 2001 From: devZoGok Date: Mon, 21 Mar 2022 19:14:31 +0200 Subject: [PATCH] animatable types --- animatable.cpp | 3 ++- animatable.h | 15 ++++++++++++++- bone.cpp | 3 ++- light.cpp | 2 +- material.h | 4 ++-- meshData.cpp | 7 +++++++ meshData.h | 2 ++ node.cpp | 5 ++++- node.h | 2 +- particleEmitter.cpp | 2 +- particleEmitter.h | 2 +- particleEmitterTest.cpp | 2 ++ texture.cpp | 8 ++++---- xmlModelReader.cpp | 7 ++++--- 14 files changed, 47 insertions(+), 17 deletions(-) diff --git a/animatable.cpp b/animatable.cpp index 4aa647b..96bc8aa 100644 --- a/animatable.cpp +++ b/animatable.cpp @@ -3,7 +3,8 @@ namespace vb01{ using namespace std; - Animatable::Animatable(string name){ + Animatable::Animatable(Type type, string name){ + this->type = type; this->name = name; } } diff --git a/animatable.h b/animatable.h index 27a06d7..3ae3e14 100644 --- a/animatable.h +++ b/animatable.h @@ -6,11 +6,24 @@ namespace vb01{ class Animatable{ public: - Animatable(std::string = ""); + enum Type{ + NONE, + NODE, + BONE, + SHAPE_KEY, + LIGHT, + PARTICLE_EMITTER, + MATERIAL_UNIFORM, + TEXTURE + }; + + Animatable(Type, std::string = ""); virtual void animate(float, KeyframeChannel){} inline std::string getName(){return name;} + inline Type getType(){return type;} protected: std::string name; + Type type = Type::NONE; }; } diff --git a/bone.cpp b/bone.cpp index 1434731..32caea6 100644 --- a/bone.cpp +++ b/bone.cpp @@ -4,9 +4,10 @@ using namespace std; namespace vb01{ - Bone::Bone(string name, float length, Vector3 pos, Quaternion rot, Vector3 scale) : Node(pos, rot, scale, name){ + Bone::Bone(string name, float length, Vector3 pos, Quaternion rot, Vector3 scale) : Node(pos, rot, scale, name, Animatable::BONE){ this->name = name; this->length = length; + this->type = Animatable::BONE; } void Bone::lookAt(Vector3 newDir, Vector3 newUp){ diff --git a/light.cpp b/light.cpp index 7f28421..4984e62 100755 --- a/light.cpp +++ b/light.cpp @@ -15,7 +15,7 @@ using namespace glm; using namespace std; namespace vb01{ - Light::Light(Type t, string name) : Animatable(name){ + Light::Light(Type t, string name) : Animatable(Animatable::LIGHT, name){ this->type = t; initDepthMap(); diff --git a/material.h b/material.h index d93f587..2821d7b 100755 --- a/material.h +++ b/material.h @@ -12,7 +12,7 @@ namespace vb01{ class Texture; - class Material : public Animatable{ + class Material{ public: struct Uniform : public Animatable{ enum Type{ @@ -25,7 +25,7 @@ namespace vb01{ TEXTURE }; - Uniform(std::string name, Type type) : Animatable(name){ + Uniform(std::string name, Type type) : Animatable(Animatable::MATERIAL_UNIFORM, name){ this->name = name; this->type = type; } diff --git a/meshData.cpp b/meshData.cpp index c032ae3..e4239f5 100644 --- a/meshData.cpp +++ b/meshData.cpp @@ -17,6 +17,13 @@ namespace vb01{ } } + MeshData::ShapeKey::ShapeKey(string name, float value, float minValue, float maxValue) : Animatable(Animatable::SHAPE_KEY, name){ + this->name = name; + this->value = value; + this->minValue = minValue; + this->maxValue = maxValue; + } + MeshData::MeshData(Vertex *vertices, u32 *indices, int numTris, string *vertexGroups, int numVertexGroups, string fullSkeletonName, ShapeKey *shapeKeys, int numShapeKeys){ this->vertices = vertices; this->indices = indices; diff --git a/meshData.h b/meshData.h index 3a11e1a..9a005ff 100644 --- a/meshData.h +++ b/meshData.h @@ -14,6 +14,8 @@ namespace vb01{ std::string name; float minValue, value, maxValue; + ShapeKey(std::string, float, float, float); + ShapeKey() : Animatable(Animatable::SHAPE_KEY){} void animate(float, KeyframeChannel); }; diff --git a/node.cpp b/node.cpp index df88041..c61e9d9 100755 --- a/node.cpp +++ b/node.cpp @@ -16,10 +16,13 @@ using namespace std; using namespace glm; namespace vb01{ - Node::Node(Vector3 pos, Quaternion orientation, Vector3 scale, string name) : Animatable(name){ + Node::Node(Vector3 pos, Quaternion orientation, Vector3 scale, string name, Animatable::Type type) : Animatable(type, name){ this->pos = pos; this->scale = scale; this->orientation = orientation; + + if(type == Animatable::NONE) + type = Animatable::NODE; } Node::~Node(){ diff --git a/node.h b/node.h index 7ab7db7..9523e70 100755 --- a/node.h +++ b/node.h @@ -20,7 +20,7 @@ namespace vb01{ class Node : public Animatable{ 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 = "", Animatable::Type = Animatable::NODE); virtual ~Node(); Node* clone(); void addSkeleton(Skeleton*); diff --git a/particleEmitter.cpp b/particleEmitter.cpp index 718fe2c..fdf78e7 100755 --- a/particleEmitter.cpp +++ b/particleEmitter.cpp @@ -15,7 +15,7 @@ using namespace glm; using namespace std; namespace vb01{ - ParticleEmitter::ParticleEmitter(int numParticles){ + ParticleEmitter::ParticleEmitter(int numParticles) : Animatable(Animatable::PARTICLE_EMITTER){ this->numParticles = numParticles; Vertex v1, v2, v3, v4, v5, v6; diff --git a/particleEmitter.h b/particleEmitter.h index d3c9e39..59b3037 100755 --- a/particleEmitter.h +++ b/particleEmitter.h @@ -14,8 +14,8 @@ namespace vb01{ class ParticleEmitter : public Animatable{ public: - ParticleEmitter(){} ParticleEmitter(int); + ParticleEmitter() : Animatable(Animatable::NONE){} ~ParticleEmitter(); void update(); inline void setMaterial(Material *mat){this->material = mat;} diff --git a/particleEmitterTest.cpp b/particleEmitterTest.cpp index a9b8f9f..ebd53cf 100644 --- a/particleEmitterTest.cpp +++ b/particleEmitterTest.cpp @@ -10,6 +10,7 @@ namespace vb01{ particleEmitter = new ParticleEmitter(); particleEmitter->numParticles = numParticles; particleEmitter->particles = new ParticleEmitter::Particle*[numParticles]; + for(int i = 0; i < numParticles; i++){ ParticleEmitter::Particle *particle = new ParticleEmitter::Particle; particle->distToCamPlane = rand() % 1000; @@ -22,6 +23,7 @@ namespace vb01{ void ParticleEmitterTest::testHeapSort(){ particleEmitter->heapSort(); + for(int i = 1; i < numParticles; i++){ ParticleEmitter::Particle *prevPart = particleEmitter->particles[i - 1]; ParticleEmitter::Particle *currPart = particleEmitter->particles[i]; diff --git a/texture.cpp b/texture.cpp index cf0f311..46cbb20 100755 --- a/texture.cpp +++ b/texture.cpp @@ -15,7 +15,7 @@ using namespace std; namespace vb01{ - Texture::Texture(int width, int height, bool shadowMap) : Animatable(){ + Texture::Texture(int width, int height, bool shadowMap) : Animatable(Animatable::TEXTURE){ this->width = width; this->height = height; texture = new u32; @@ -42,7 +42,7 @@ namespace vb01{ } } - Texture::Texture(string paths[], int numPaths, bool cubemap, int mipmapLevel, bool flip, string name) : Animatable(name){ + Texture::Texture(string paths[], int numPaths, bool cubemap, int mipmapLevel, bool flip, string name) : Animatable(Animatable::TEXTURE, name){ this->cubemap = cubemap; this->paths = new string[numPaths]; @@ -86,7 +86,7 @@ namespace vb01{ } } - Texture::Texture(int width, bool depth, int mipmapLevel, string name) : Animatable(name){ + Texture::Texture(int width, bool depth, int mipmapLevel, string name) : Animatable(Animatable::TEXTURE, name){ this->width = width; this->mipmapLevel = mipmapLevel; this->cubemap = true; @@ -127,7 +127,7 @@ namespace vb01{ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } - Texture::Texture(FT_Face face) : Animatable(){ + Texture::Texture(FT_Face face) : Animatable(Animatable::TEXTURE){ texture = new u32; glGenTextures(1, &texture[0]); diff --git a/xmlModelReader.cpp b/xmlModelReader.cpp index 9cc1596..9cb5bfa 100644 --- a/xmlModelReader.cpp +++ b/xmlModelReader.cpp @@ -136,9 +136,10 @@ namespace vb01{ 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"); - shapeKeys[i].minValue = atof(shapeKeyEl->Attribute("min")); - shapeKeys[i].maxValue = atof(shapeKeyEl->Attribute("max")); + string name = shapeKeyEl->Attribute("name"); + float minValue = atof(shapeKeyEl->Attribute("min")); + float maxValue = atof(shapeKeyEl->Attribute("max")); + shapeKeys[i] = MeshData::ShapeKey(name, minValue, minValue, maxValue); XMLElement *driverEl = shapeKeyEl->FirstChildElement("driver"); KeyframeChannel channel = processKeyframeChannells(driverEl)[0];