Attachable super class

This commit is contained in:
devZoGok
2022-03-26 15:47:21 +02:00
parent 56e1b2990a
commit fdf751cde5
11 changed files with 39 additions and 24 deletions
+20
View File
@@ -0,0 +1,20 @@
#ifndef ATTACHABLE_H
#define ATTACHABLE_H
#include <string>
namespace vb01{
class Node;
struct Attachable{
std::string fullName = "";
Node *node = nullptr;
Attachable(std::string fullName){this->fullName = fullName;}
Attachable(){}
virtual void onAttached(Node*){}
std::string getFullName(){return fullName;}
};
}
#endif
+2 -4
View File
@@ -3,6 +3,7 @@
#include "vector.h" #include "vector.h"
#include "animatable.h" #include "animatable.h"
#include "attachable.h"
#include <vector> #include <vector>
#include <glm.hpp> #include <glm.hpp>
@@ -13,14 +14,13 @@ namespace vb01{
class Shader; class Shader;
class Material; class Material;
class Light : public Animatable{ class Light : public Animatable, public Attachable{
public: public:
enum Type{POINT, DIRECTIONAL, SPOT, AMBIENT}; enum Type{POINT, DIRECTIONAL, SPOT, AMBIENT};
Light(Type, std::string = ""); Light(Type, std::string = "");
~Light(); ~Light();
void update(); void update();
inline void setNode(Node *node){this->node = node;}
inline void setColor(Vector3 color){this->color = color;} inline void setColor(Vector3 color){this->color = color;}
inline void setAttenuationValues(float a, float b, float c){ inline void setAttenuationValues(float a, float b, float c){
attenuationValues.x = a; attenuationValues.x = a;
@@ -36,7 +36,6 @@ namespace vb01{
inline float getOuterAngle(){return outerAngle;} inline float getOuterAngle(){return outerAngle;}
inline float getShadowNearPlane(){return nearPlane;} inline float getShadowNearPlane(){return nearPlane;}
inline float getShadowFarPlane(){return farPlane;} inline float getShadowFarPlane(){return farPlane;}
inline Node* getNode(){return node;}
private: private:
void animate(float, KeyframeChannel); void animate(float, KeyframeChannel);
void initDepthMap(); void initDepthMap();
@@ -46,7 +45,6 @@ namespace vb01{
Type type; Type type;
Shader *depthMapShader; Shader *depthMapShader;
Texture *depthMap = nullptr; Texture *depthMap = nullptr;
Node *node = nullptr;
Vector3 color = Vector3::VEC_IJK, attenuationValues = Vector3(1.8, .7, 1); Vector3 color = Vector3::VEC_IJK, attenuationValues = Vector3(1.8, .7, 1);
float innerAngle = .707, outerAngle = .714, nearPlane = .1, farPlane = 100; float innerAngle = .707, outerAngle = .714, nearPlane = .1, farPlane = 100;
unsigned int depthmapFBO, depthMapSize = 1024; unsigned int depthmapFBO, depthMapSize = 1024;
+2 -5
View File
@@ -4,7 +4,7 @@
#include "vector.h" #include "vector.h"
#include "util.h" #include "util.h"
#include "material.h" #include "material.h"
#include "animatable.h" #include "attachable.h"
#include "meshData.h" #include "meshData.h"
#include <vector> #include <vector>
@@ -16,7 +16,7 @@ namespace vb01{
class Texture; class Texture;
class Skeleton; class Skeleton;
class Mesh{ class Mesh : public Attachable{
public: public:
Mesh(MeshData); Mesh(MeshData);
~Mesh(); ~Mesh();
@@ -24,13 +24,11 @@ namespace vb01{
virtual void update(); virtual void update();
void render(); void render();
void setMaterial(Material *mat){this->material = mat;} void setMaterial(Material *mat){this->material = mat;}
inline void setNode(Node *node){this->node = node;}
inline void setCastShadow(bool castShadow){this->castShadow = castShadow;} inline void setCastShadow(bool castShadow){this->castShadow = castShadow;}
inline void setReflect(bool r){this->reflect = r;} inline void setReflect(bool r){this->reflect = r;}
inline void setReflective(bool r){this->reflective = r;} inline void setReflective(bool r){this->reflective = r;}
inline void setWireframe(bool w){this->wireframe = w;} inline void setWireframe(bool w){this->wireframe = w;}
inline void setSkeleton(Skeleton *sk){this->skeleton = sk;} inline void setSkeleton(Skeleton *sk){this->skeleton = sk;}
inline Node* getNode(){return node;}
inline Material* getMaterial(){return material;} inline Material* getMaterial(){return material;}
inline bool isReflective(){return reflective;} inline bool isReflective(){return reflective;}
inline bool isCastShadow(){return castShadow;} inline bool isCastShadow(){return castShadow;}
@@ -59,7 +57,6 @@ namespace vb01{
Shader *environmentShader = nullptr, *irradianceShader = nullptr, *brdfIntegrationShader = nullptr; Shader *environmentShader = nullptr, *irradianceShader = nullptr, *brdfIntegrationShader = nullptr;
u32 preFilterFramebuffer, preFilterRenderbuffer, irrandianceFramebuffer, irradianceRenderbuffer, postFilterFramebuffer, postFilterRenderbuffer, brdfFramebuffer, brdfRenderbuffer; u32 preFilterFramebuffer, preFilterRenderbuffer, irrandianceFramebuffer, irradianceRenderbuffer, postFilterFramebuffer, postFilterRenderbuffer, brdfFramebuffer, brdfRenderbuffer;
Material *material = nullptr; Material *material = nullptr;
Node *node = nullptr;
std::vector<Mesh*> meshes; std::vector<Mesh*> meshes;
Skeleton *skeleton = nullptr; Skeleton *skeleton = nullptr;
protected: protected:
+2 -1
View File
@@ -24,10 +24,11 @@ namespace vb01{
this->maxValue = maxValue; this->maxValue = maxValue;
} }
MeshData::MeshData(Vertex *vertices, u32 *indices, int numTris, string *vertexGroups, int numVertexGroups, string fullSkeletonName, ShapeKey *shapeKeys, int numShapeKeys){ MeshData::MeshData(Vertex *vertices, u32 *indices, int numTris, string attachableName, string *vertexGroups, int numVertexGroups, string fullSkeletonName, ShapeKey *shapeKeys, int numShapeKeys){
this->vertices = vertices; this->vertices = vertices;
this->indices = indices; this->indices = indices;
this->numTris = numTris; this->numTris = numTris;
this->attachableName = attachableName;
this->vertexGroups = vertexGroups; this->vertexGroups = vertexGroups;
this->numVertexGroups = numVertexGroups; this->numVertexGroups = numVertexGroups;
this->fullSkeletonName = fullSkeletonName; this->fullSkeletonName = fullSkeletonName;
+2 -2
View File
@@ -32,10 +32,10 @@ namespace vb01{
ShapeKey *shapeKeys = nullptr; ShapeKey *shapeKeys = nullptr;
u32 *indices, VAO, VBO, EBO; u32 *indices, VAO, VBO, EBO;
int numTris, numVertexGroups = 0, numShapeKeys = 0; int numTris, numVertexGroups = 0, numShapeKeys = 0;
std::string fullSkeletonName = ""; std::string attachableName = "", fullSkeletonName = "";
MeshData(){} MeshData(){}
MeshData(Vertex*, u32*, int, std::string *vg = nullptr, int = 0, std::string = "", ShapeKey *sk = nullptr, int = 0); MeshData(Vertex*, u32*, int, std::string = "", std::string *vg = nullptr, int = 0, std::string = "", ShapeKey *sk = nullptr, int = 0);
}; };
} }
+2 -2
View File
@@ -4,6 +4,7 @@
#include "vector.h" #include "vector.h"
#include "util.h" #include "util.h"
#include "animatable.h" #include "animatable.h"
#include "attachable.h"
#include <glm.hpp> #include <glm.hpp>
@@ -12,7 +13,7 @@ namespace vb01{
class Node; class Node;
class Material; class Material;
class ParticleEmitter : public Animatable{ class ParticleEmitter : public Animatable, public Attachable{
public: public:
ParticleEmitter(int); ParticleEmitter(int);
ParticleEmitter() : Animatable(Animatable::NONE){} ParticleEmitter() : Animatable(Animatable::NONE){}
@@ -28,7 +29,6 @@ namespace vb01{
inline void setHighLife(float h){this->highLife = h;} inline void setHighLife(float h){this->highLife = h;}
inline void setGravity(Vector3 g){this->gravity = g;} inline void setGravity(Vector3 g){this->gravity = g;}
inline void setSpeed(float s){this->speed = s;} inline void setSpeed(float s){this->speed = s;}
inline Node* getNode(){return node;}
private: private:
struct Vertex{ struct Vertex{
Vector3 pos; Vector3 pos;
+1
View File
@@ -162,6 +162,7 @@ def export(node, parentTag):
numShapeKeys = len(mesh.shape_keys.key_blocks) - 1 numShapeKeys = len(mesh.shape_keys.key_blocks) - 1
meshTag = ET.SubElement(nodeTag, 'mesh') meshTag = ET.SubElement(nodeTag, 'mesh')
meshTag.set('name', node.name + mesh.name_full)
meshTag.set('num_faces', str(numFaces)) meshTag.set('num_faces', str(numFaces))
meshTag.set('num_vertex_groups', str(numGroups)) meshTag.set('num_vertex_groups', str(numGroups))
meshTag.set('num_shape_keys', str(numShapeKeys)) meshTag.set('num_shape_keys', str(numShapeKeys))
-4
View File
@@ -11,10 +11,6 @@ using namespace std;
using namespace glm; using namespace glm;
namespace vb01{ namespace vb01{
Skeleton::Skeleton(string name){
this->name = name;
}
void Skeleton::update(){ void Skeleton::update(){
updateIk(); updateIk();
} }
+3 -4
View File
@@ -5,20 +5,20 @@
#include <string> #include <string>
#include "bone.h" #include "bone.h"
#include "attachable.h"
namespace vb01{ namespace vb01{
class Animation; class Animation;
class Skeleton{ class Skeleton : public Attachable{
public: public:
Skeleton(std::string = ""); Skeleton(std::string name = "") : Attachable(name){}
void update(); void update();
void addBone(Bone*, Bone*); void addBone(Bone*, Bone*);
Bone* getBone(std::string); Bone* getBone(std::string);
inline Bone* getBone(int i){return bones[i];} inline Bone* getBone(int i){return bones[i];}
inline Bone* getRootBone(){return bones[0];} inline Bone* getRootBone(){return bones[0];}
inline std::vector<Bone*>& getBones(){return bones;} inline std::vector<Bone*>& getBones(){return bones;}
inline std::string getName(){return name;}
inline int getNumBones(){return bones.size();} inline int getNumBones(){return bones.size();}
private: private:
void updateIk(); void updateIk();
@@ -26,7 +26,6 @@ namespace vb01{
void transformIkChain(int, Bone*[], Vector3[], Bone*); void transformIkChain(int, Bone*[], Vector3[], Bone*);
Bone** getIkBoneChain(Bone*); Bone** getIkBoneChain(Bone*);
std::string name;
std::vector<Bone*> bones; std::vector<Bone*> bones;
}; };
} }
+3 -1
View File
@@ -3,6 +3,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "attachable.h"
#include "vector.h" #include "vector.h"
#include "util.h" #include "util.h"
@@ -12,7 +14,7 @@ namespace vb01{
class Shader; class Shader;
class Material; class Material;
class Text{ class Text : public Attachable{
public: public:
struct Glyph{ struct Glyph{
u16 ch; u16 ch;
+2 -1
View File
@@ -162,7 +162,8 @@ namespace vb01{
} }
const char *fullSkeletonName = meshEl->Attribute("skeleton"); const char *fullSkeletonName = meshEl->Attribute("skeleton");
Mesh *mesh = new Mesh(MeshData(vertices, indices, numVertices / 3, vertexGroups, numVertexGroups, (fullSkeletonName ? fullSkeletonName : ""), shapeKeys, numShapeKeys)); string name = string(meshEl->Parent()->ToElement()->Attribute("name")) + string(meshEl->Attribute("name"));
Mesh *mesh = new Mesh(MeshData(vertices, indices, numVertices / 3, name, vertexGroups, numVertexGroups, (fullSkeletonName ? fullSkeletonName : ""), shapeKeys, numShapeKeys));
return mesh; return mesh;
} }