8#ifndef ENGINE_GRAPHICS_GMODEL_H_
9#define ENGINE_GRAPHICS_GMODEL_H_
11#define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES
13#include <glm/gtc/matrix_inverse.hpp>
14#include <glm/gtc/matrix_transform.hpp>
15#include <assimp/Importer.hpp>
16#include <assimp/scene.h>
17#include <assimp/postprocess.h>
18#include <assimp/cimport.h>
29#include <unordered_map>
48 void load(
const std::string& fullPath);
60 void move(
float dx,
float dy,
float dz) {
move(glm::vec3(dx, dy, dz)); }
61 void move(
const glm::vec3& dv);
63 void rotate(
float radians,
float ax,
float ay,
float az);
64 void rotateDeg(
float degrees,
float ax,
float ay,
float az) {
rotate(glm::radians(degrees), ax, ay, az); }
65 void rotateAround(
float radians,
const glm::vec3& axis,
const glm::vec3& point);
67 void scale(
float sx,
float sy,
float sz);
74 void pan(
float radians);
75 void panDeg(
float degrees) {
pan(glm::radians(degrees)); }
125 struct SharedVertexIndex {
126 std::shared_ptr<std::vector<gVertex>> vertices;
127 std::shared_ptr<std::vector<gIndex>> indices;
129 std::unordered_map<const aiMesh*, SharedVertexIndex> mesh2svimap;
131 const aiScene* scene;
132 std::vector<const aiScene*> morphingtargetscenes;
133 void loadModelFile(
const std::string& fullPath);
134 void loadModelFileWithOriginalVertices(
const std::string& fullPath);
135 void loadMorphingTargetModelFile(
const std::string& fullPath);
136 void processNode(aiNode* node,
const aiScene* scene);
137 gSkinnedMesh* processMesh(
const aiMesh* mesh,
const aiScene* scene, aiMatrix4x4 matrix);
139 void processMorphingNode(
const aiNode* node,
const aiScene* scene);
140 gMesh* processMorphingMesh(
const aiMesh* mesh,
const aiScene* scene, aiMatrix4x4 matrix);
143 void updateBones(
gSkinnedMesh* gmesh,
const aiMesh* aimesh);
145 void updateAnimationNodes();
146 void generateAnimationKeys();
149 aiNode* findNodeFast(
const std::string& name) {
150 auto it = nodemap.find(name);
151 return (it != nodemap.end()) ? it->second :
nullptr;
154 std::string filename;
157 float animationposition, animationpositionold;
158 float animationframerate;
159 int animationframenum;
160 std::vector<float> animationkeys;
161 int animationframeno;
163 void prepareVertexAnimationData();
164 bool isvertexanimated;
165 bool isvertexanimationstoredonvram;
168 std::unordered_map<std::string, aiNode*> nodemap;
169 std::vector<unsigned int> meshindices;
171 glm::mat4 convertMatrix(
const aiMatrix4x4 &aiMat);
174 bool isenablefrustumculling;
175 bool needsboundingboxrecalculation;
Definition gBoundingBox.h:36
gSkinnedMesh & getMesh(int meshNo)
void processTransformationMatrix() override
void makeVertexAnimated(bool storeOnVram=true)
std::string directory
Definition gModel.h:37
void rotateAround(float radians, const glm::vec3 &axis, const glm::vec3 &point)
float getAnimationPosition() const
void boom(float distance)
int getMorphingFrameNum() const
int getMorphingFrameNo() const
void setPosition(float px, float py, float pz)
Definition gModel.h:79
gBoundingBox & getInitialBoundingBox()
int getAnimationNum() const
void setOrientation(const glm::vec3 &angles)
void animate(float animationPosition)
std::deque< gTexture * > textures_loaded
Definition gModel.h:35
void truck(float distance)
void setScale(float s)
Definition gModel.h:85
void rotateDeg(float degrees, float ax, float ay, float az)
Definition gModel.h:64
void setMorphingTarget(int morphingTargetId)
void rotate(const glm::quat &q)
void load(const std::string &fullPath)
int getAnimationFrameNum() const
const gBoundingBox & getBoundingBox()
void setAnimationFrameNo(int frameNo)
gSkinnedMesh * getMeshPtr(int meshNo)
void setAnimationFramerate(float animationFramerate)
int getMeshNo(const std::string &meshName) const
float getAnimationDuration(int animationNo=0) const
void setPosition(const glm::vec3 &p)
float getAnimationFramerate() const
const std::string & getFilename() const
void setMorphingFrameNo(int morphingAnimationNo)
void recalculateBoundingBox()
void loadModelWithOriginalVertices(const std::string &modelPath)
bool isVertexAnimationStoredOnVram() const
void dolly(float distance)
void rollDeg(float degrees)
Definition gModel.h:77
int getMorphingSpeed() const
void move(const glm::vec3 &dv)
void panDeg(float degrees)
Definition gModel.h:75
void nextAnimationFrame()
void tiltDeg(float degrees)
Definition gModel.h:73
void setMorphingSpeed(int speed)
int getAnimationFrameNo() const
void loadMorphingTargetModel(const std::string &modelPath)
void setOrientation(const glm::quat &o)
std::deque< gSkinnedMesh * > meshes
Definition gModel.h:36
const std::string getFullpath() const
void rotateAroundDeg(float degrees, const glm::vec3 &axis, const glm::vec3 &point)
Definition gModel.h:66
void move(float dx, float dy, float dz)
Definition gModel.h:60
void setTransformationMatrix(const glm::mat4 &transformationMatrix)
void setAnimationFrameNum(int animationKeyNum)
void setEnableFrustumCulling(bool enable)
void setScale(float sx, float sy, float sz)
Definition gModel.h:84
std::string getMeshName(int meshNo) const
void setMorphingFrameNum(int morphingFrameNum)
void rotate(float radians, float ax, float ay, float az)
int getMorphingTarget() const
void setScale(const glm::vec3 &s)
void loadModel(const std::string &modelPath)
void scale(float sx, float sy, float sz)
bool isVertexAnimated() const
Definition gSkinnedMesh.h:15
TextureType
Definition gTexture.h:19