GlistEngine
Loading...
Searching...
No Matches
gMorphingMesh.h
Go to the documentation of this file.
1/*
2 * gMorphingMesh.h
3 *
4 * Created on: 10 Tem 2023
5 * Author: Deniz Hatipoglu
6 */
7
8#ifndef GRAPHICS_GMORPHINGMESH_H_
9#define GRAPHICS_GMORPHINGMESH_H_
10
11#define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES
12#include <glm/glm.hpp>
13#include <glm/gtc/matrix_transform.hpp>
14#include <assimp/Importer.hpp>
15#include <assimp/scene.h>
16#include <assimp/postprocess.h>
17#include <assimp/cimport.h>
18
19#include <string>
20#include <fstream>
21#include <sstream>
22#include <iostream>
23#include <vector>
24#include "gMesh.h"
25
26
27class gMorphingMesh : public gMesh {
28public:
30 ~gMorphingMesh() override;
31
32 void draw() override;
33
35
36 /*
37 * @brief adds the given targetmesh's specific attributes to the vectors.
38 * @param targetMesh is a pointer to the desired target mesh.
39 */
40 int addTargetMesh(gMesh *targetMesh);
41
42 /*
43 * @brief sets the base mesh which is going to be used during interpolation.
44 * @param baseMesh is the base mesh's pointer.
45 */
46 void setBaseMesh(gMesh *baseMesh);
47
48 /*
49 * @brief sets the current target mesh id to the given id if it is valid. Else it doesn't set.
50 * @param targetMeshId is the id of the desired target mesh.
51 */
52 void setCurrentTargetMeshId(int targetMeshId);
53
54 /*
55 * @brief sets the current frame id to the desired id.
56 * @param frameId is the desired frame id.
57 */
58 void setCurrentFrameId(int frameId);
59
60 /*
61 * @brief sets the desired target mesh's frame count which is the beyond of interpolation.
62 * @param targetMeshId is the target mesh which will be affected by this function.
63 * @param frameCount is the desired framecount.
64 */
65 void setFrameCount(int targetMeshId, int frameCount);
66
67 /*
68 * @brief sets the frame jump speed.
69 * @param speed is the desired speed.
70 */
71 void setSpeed(int speed);
72
73 /*
74 * @brief sets position at the given indices to the new one.
75 * @param targetId is the target mesh's index.
76 * @param positionId is one of the target mesh's position's index.
77 * @param newPosition is the desired position.
78 */
79 void setTargetPosition(int targetId, int positionId, glm::vec3 newPosition);
80
81 /*
82 * @brief sets normal at the given indices to the new one.
83 * @param targetId is the target mesh's index.
84 * @param normalId is one of the target mesh's normal's index.
85 * @param newNormal is the desired normal.
86 */
87 void setTargetNormal(int targetId, int normalId, glm::vec3 newNormal);
88
89 /*
90 * @brief sets the member ismorphinganimated as the desired value.
91 * @param isMorphingAnimated is the desired value.
92 */
93 void setMorphingAnimated(bool isMorphingAnimated);
94
95 /*
96 * @brief sets the member ismorphinganimationstoredonvram as the desired value.
97 * @param isMorphingAnimationStoredOnVram is the desired value.
98 */
99 void setMorphingAnimationStoredOnVram(bool isMorphingAnimationStoredOnVram);
100
101 /*
102 * @brief sets all the glm vectors of normals and positions to zero vector.
103 * @param targetId is the target mesh's index.
104 */
105 void resetTargetData(int targetId);
106
107 /*
108 * @brief jumps frames as many as the given value of the speed variable.
109 */
111
112 /*
113 * @brief returns the current target mesh's id.
114 */
116
117 /*
118 * @brief returns the current frame's id.
119 */
120 int getCurrentFrameId() const;
121
122 /*
123 * @brief returns the desired target mesh's frame count.
124 * @param targetMeshId is the desired target mesh id.
125 */
126 int getFrameCount(int targetMeshId) const;
127
128 /*
129 * @brief returns the current target mesh's frame count.
130 */
131 int getFrameCount() const;
132
133 /*
134 * @brief returns the target mesh's count.
135 */
137
138 /*
139 * @brief returns the current frame jump speed.
140 */
141 int getSpeed() const;
142
143 /*
144 * @brief returns the desired target position.
145 * @param targetId is the desired target mesh's id.
146 * @param positionId is the desired position's id.
147 * @return returns the constant reference of the desired position as a glm::vec3.
148 */
149 const glm::vec3& getTargetPosition(int targetId, int positionId) const;
150
151 /*
152 * @brief returns the desired target normal.
153 * @param targetId is the desired target mesh's id.
154 * @param positionId is the desired normal's id.
155 * @return returns the constant reference of the desired normal as a glm::vec3.
156 */
157 const glm::vec3& getTargetNormal(int targetId, int normalId) const;
158
159 /*
160 * @brief interpolates the vertices in base and target meshes' from base's to target's meshes.
161 * @param forceInterpolation is an indicator if it checks the current target mesh and current frame are as last interpolate.
162 */
163 void interpolate(bool forceInterpolation = true);
164
165private:
166 //The loaded target meshes' positions which are the end points of interpolation.
167 std::vector<std::vector<glm::vec3>> targetpositions, targetnormals;
168 //The base mesh's vertices' spare.
169 std::shared_ptr<std::vector<gVertex>> basevertices;
170 //The animated frames' data.
171 std::vector<std::vector<std::vector<glm::vec3>>> framepositions, framenormals;
172 //The frames data on vram.
173 std::vector<std::vector<std::unique_ptr<gVbo>>> vboframes;
174 //The current target mesh(that is going to be end point of interpolation)'s index on the targetpositions vector.
175 //The current frame id indicates how much should the interpolation progress.
176 //The speed is used in function nextFrame which adjusts the frame automatically as a jump indicator.
177 int currenttargetmeshid, currentframeid, speed, oldtargetmeshid, oldframeid;
178 //ismorphinganimated is an indicator of the holding state of frames. If it is true then the whole frames' positions and normals will be held in vectors those occupies memory in RAM.
179 //ismorphinganimationstoredonvram is an indicator of the holding state of frames. If it is true all the frames will be held in vbos which are stored in VRAM.
180 //They initialized as false.
181 bool ismorphinganimated, ismorphinganimationstoredonvram;
182 std::vector<int> framecounts;
183 //The base mesh which is the begin point of interpolation.
184 gMesh *basemesh;
185
186 //Private Functions
187 /*
188 * @brief extracts the positions from the given vertices to the targetpositions vector.
189 * @param targetvertices is the vertex vector of target.
190 */
191 void addTargetPositions(const std::vector<gVertex>& targetvertices);
192
193 /*
194 * @brief extracts the normals from the given vertices to the targetnormals vector.
195 * @param targetvertices is the vertex vector of target.
196 */
197 void addTargetNormals(const std::vector<gVertex>& targetvertices);
198};
199
200#endif /* GRAPHICS_GMORPHINGMESH_H_ */
Definition gMesh.h:27
Definition gMorphingMesh.h:27
int getCurrentTargetMeshId() const
void setMorphingAnimationStoredOnVram(bool isMorphingAnimationStoredOnVram)
void setTargetPosition(int targetId, int positionId, glm::vec3 newPosition)
void setTargetNormal(int targetId, int normalId, glm::vec3 newNormal)
int getCurrentFrameId() const
void resetTargetData(int targetId)
void interpolate(bool forceInterpolation=true)
void setSpeed(int speed)
void setMorphingAnimated(bool isMorphingAnimated)
const glm::vec3 & getTargetNormal(int targetId, int normalId) const
int getTargetMeshCount() const
const glm::vec3 & getTargetPosition(int targetId, int positionId) const
int getFrameCount(int targetMeshId) const
void setCurrentFrameId(int frameId)
void draw() override
void setBaseMesh(gMesh *baseMesh)
void setCurrentTargetMeshId(int targetMeshId)
int getSpeed() const
int addTargetMesh(gMesh *targetMesh)
void drawVboFrames()
void nextFrameId()
int getFrameCount() const
~gMorphingMesh() override
void setFrameCount(int targetMeshId, int frameCount)