diff --git a/attachable.h b/attachable.h new file mode 100644 index 0000000..97837c0 --- /dev/null +++ b/attachable.h @@ -0,0 +1,20 @@ +#ifndef ATTACHABLE_H +#define ATTACHABLE_H + +#include + +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 diff --git a/light.h b/light.h index fb517b8..1732d94 100755 --- a/light.h +++ b/light.h @@ -3,6 +3,7 @@ #include "vector.h" #include "animatable.h" +#include "attachable.h" #include #include @@ -13,14 +14,13 @@ namespace vb01{ class Shader; class Material; - class Light : public Animatable{ + class Light : public Animatable, public Attachable{ public: enum Type{POINT, DIRECTIONAL, SPOT, AMBIENT}; Light(Type, std::string = ""); ~Light(); void update(); - inline void setNode(Node *node){this->node = node;} inline void setColor(Vector3 color){this->color = color;} inline void setAttenuationValues(float a, float b, float c){ attenuationValues.x = a; @@ -36,7 +36,6 @@ namespace vb01{ inline float getOuterAngle(){return outerAngle;} inline float getShadowNearPlane(){return nearPlane;} inline float getShadowFarPlane(){return farPlane;} - inline Node* getNode(){return node;} private: void animate(float, KeyframeChannel); void initDepthMap(); @@ -46,7 +45,6 @@ namespace vb01{ Type type; Shader *depthMapShader; Texture *depthMap = nullptr; - Node *node = nullptr; Vector3 color = Vector3::VEC_IJK, attenuationValues = Vector3(1.8, .7, 1); float innerAngle = .707, outerAngle = .714, nearPlane = .1, farPlane = 100; unsigned int depthmapFBO, depthMapSize = 1024; diff --git a/mesh.h b/mesh.h index 66cee19..3965b8a 100755 --- a/mesh.h +++ b/mesh.h @@ -4,7 +4,7 @@ #include "vector.h" #include "util.h" #include "material.h" -#include "animatable.h" +#include "attachable.h" #include "meshData.h" #include @@ -16,7 +16,7 @@ namespace vb01{ class Texture; class Skeleton; - class Mesh{ + class Mesh : public Attachable{ public: Mesh(MeshData); ~Mesh(); @@ -24,13 +24,11 @@ namespace vb01{ virtual void update(); void render(); 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 setReflect(bool r){this->reflect = r;} inline void setReflective(bool r){this->reflective = r;} inline void setWireframe(bool w){this->wireframe = w;} inline void setSkeleton(Skeleton *sk){this->skeleton = sk;} - inline Node* getNode(){return node;} inline Material* getMaterial(){return material;} inline bool isReflective(){return reflective;} inline bool isCastShadow(){return castShadow;} @@ -59,7 +57,6 @@ namespace vb01{ Shader *environmentShader = nullptr, *irradianceShader = nullptr, *brdfIntegrationShader = nullptr; u32 preFilterFramebuffer, preFilterRenderbuffer, irrandianceFramebuffer, irradianceRenderbuffer, postFilterFramebuffer, postFilterRenderbuffer, brdfFramebuffer, brdfRenderbuffer; Material *material = nullptr; - Node *node = nullptr; std::vector meshes; Skeleton *skeleton = nullptr; protected: diff --git a/meshData.cpp b/meshData.cpp index e4239f5..b5223c9 100644 --- a/meshData.cpp +++ b/meshData.cpp @@ -24,10 +24,11 @@ namespace vb01{ 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->indices = indices; this->numTris = numTris; + this->attachableName = attachableName; this->vertexGroups = vertexGroups; this->numVertexGroups = numVertexGroups; this->fullSkeletonName = fullSkeletonName; diff --git a/meshData.h b/meshData.h index 9a005ff..783f60d 100644 --- a/meshData.h +++ b/meshData.h @@ -32,10 +32,10 @@ namespace vb01{ ShapeKey *shapeKeys = nullptr; u32 *indices, VAO, VBO, EBO; int numTris, numVertexGroups = 0, numShapeKeys = 0; - std::string fullSkeletonName = ""; + std::string attachableName = "", fullSkeletonName = ""; 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); }; } diff --git a/particleEmitter.h b/particleEmitter.h index 59b3037..b6523f8 100755 --- a/particleEmitter.h +++ b/particleEmitter.h @@ -4,6 +4,7 @@ #include "vector.h" #include "util.h" #include "animatable.h" +#include "attachable.h" #include @@ -12,7 +13,7 @@ namespace vb01{ class Node; class Material; - class ParticleEmitter : public Animatable{ + class ParticleEmitter : public Animatable, public Attachable{ public: ParticleEmitter(int); ParticleEmitter() : Animatable(Animatable::NONE){} @@ -28,7 +29,6 @@ namespace vb01{ inline void setHighLife(float h){this->highLife = h;} inline void setGravity(Vector3 g){this->gravity = g;} inline void setSpeed(float s){this->speed = s;} - inline Node* getNode(){return node;} private: struct Vertex{ Vector3 pos; diff --git a/script.py b/script.py index 3cab6b8..39a98b8 100644 --- a/script.py +++ b/script.py @@ -162,6 +162,7 @@ def export(node, parentTag): numShapeKeys = len(mesh.shape_keys.key_blocks) - 1 meshTag = ET.SubElement(nodeTag, 'mesh') + meshTag.set('name', node.name + mesh.name_full) meshTag.set('num_faces', str(numFaces)) meshTag.set('num_vertex_groups', str(numGroups)) meshTag.set('num_shape_keys', str(numShapeKeys)) diff --git a/skeleton.cpp b/skeleton.cpp index 47e4a38..3a1c374 100644 --- a/skeleton.cpp +++ b/skeleton.cpp @@ -11,10 +11,6 @@ using namespace std; using namespace glm; namespace vb01{ - Skeleton::Skeleton(string name){ - this->name = name; - } - void Skeleton::update(){ updateIk(); } diff --git a/skeleton.h b/skeleton.h index 9674347..4743c55 100644 --- a/skeleton.h +++ b/skeleton.h @@ -5,20 +5,20 @@ #include #include "bone.h" +#include "attachable.h" namespace vb01{ class Animation; - class Skeleton{ + class Skeleton : public Attachable{ public: - Skeleton(std::string = ""); + Skeleton(std::string name = "") : Attachable(name){} void update(); void addBone(Bone*, Bone*); Bone* getBone(std::string); inline Bone* getBone(int i){return bones[i];} inline Bone* getRootBone(){return bones[0];} inline std::vector& getBones(){return bones;} - inline std::string getName(){return name;} inline int getNumBones(){return bones.size();} private: void updateIk(); @@ -26,7 +26,6 @@ namespace vb01{ void transformIkChain(int, Bone*[], Vector3[], Bone*); Bone** getIkBoneChain(Bone*); - std::string name; std::vector bones; }; } diff --git a/text.h b/text.h index e7ec20e..9dd559a 100755 --- a/text.h +++ b/text.h @@ -3,6 +3,8 @@ #include #include + +#include "attachable.h" #include "vector.h" #include "util.h" @@ -12,7 +14,7 @@ namespace vb01{ class Shader; class Material; - class Text{ + class Text : public Attachable{ public: struct Glyph{ u16 ch; diff --git a/xmlModelReader.cpp b/xmlModelReader.cpp index 9cb5bfa..2855925 100644 --- a/xmlModelReader.cpp +++ b/xmlModelReader.cpp @@ -162,7 +162,8 @@ namespace vb01{ } 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; }