Skip to content

Commit

Permalink
Support for keyframe-animated models.
Browse files Browse the repository at this point in the history
Closes #16
  • Loading branch information
Robadob committed Aug 17, 2022
1 parent 31cefa0 commit 18593c7
Show file tree
Hide file tree
Showing 15 changed files with 1,194 additions and 11 deletions.
6 changes: 5 additions & 1 deletion include/flamegpu/visualiser/config/AgentStateConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ struct AgentStateConfig {
AgentStateConfig(const AgentStateConfig &other);
AgentStateConfig &operator=(const AgentStateConfig &other);

const char *model_path = nullptr;
const char* model_path = nullptr;
/**
* If set, model is treated as 2-frame animated
*/
const char *model_pathB = nullptr;
const char *model_texture = nullptr;
float model_scale[3];
/**
Expand Down
12 changes: 12 additions & 0 deletions include/flamegpu/visualiser/config/Stock.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ const Model PYRAMID{ "resources/pyramid.obj", "" };
* Made with blender by zeyus (https://github.com/zeyus)
*/
const Model ARROWHEAD{ "resources/arrowhead.obj", "" };
/**
* Path to model files and optional texture within integrated resources
*/
struct KeyFrameModel {
const char* modelPathA;
const char* modelPathB;
const char* texturePath;
};
/**
* Two frame pedestrian model
*/
const KeyFrameModel PEDESTRIAN{ "resources/pedestrian_a.obj", "resources/pedestrian_b.obj", "" };
} // namespace Models
} // namespace Stock
} // namespace visualiser
Expand Down
6 changes: 6 additions & 0 deletions include/flamegpu/visualiser/config/TexBufferConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ struct TexBufferConfig {
* (Alternate to individual scale components)
*/
UniformScale,
/**
* Keyframe animation lerp variable
*/
AnimationLerp,
/**
* Some other use, e.g. custom shaders in future
*/
Expand Down Expand Up @@ -80,6 +84,7 @@ struct TexBufferConfig {
case Scale_xy: return "_scale_x";
case Scale_xyz: return "_scale_xyz";
case UniformScale: return "_scale";
case AnimationLerp: return "_animation_lerp";
// These always get name from elsewhere so return empty string
case Color:
case Unknown:
Expand Down Expand Up @@ -115,6 +120,7 @@ struct TexBufferConfig {
case Scale_y:
case Scale_z:
case UniformScale:
case AnimationLerp:
case Color:
case Unknown:
default:
Expand Down
6 changes: 4 additions & 2 deletions resources/instanced_default_Tcolor_Tpos_Tdir_Tscale.vert
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ out vec2 texCoords;
out vec4 colorOverride;
flat out int shaderColor;

vec3 getVertex();
vec3 getNormal();
vec3 getScale();
mat3 getDirection();
vec3 getPosition();
vec4 calculateColor();
void main() {
// Apply model matrix to raw vertex
vec4 vert = _modelMat * vec4(_vertex,1.0f);
vec4 vert = _modelMat * vec4(getVertex(),1.0f);
// Apply a user defined scale multiplier
vert.xyz *= getScale();
// Apply a user defined rotation
Expand All @@ -37,7 +39,7 @@ void main() {
gl_Position = _projectionMat * vec4(eyeVertex, 1.0f);

// Calc eye normal
eyeNormal = normalize(_normalMat * transpose(inverse(directionMat)) * normalize(_normal));
eyeNormal = normalize(_normalMat * transpose(inverse(directionMat)) * normalize(getNormal()));
// Calc tex coords
texCoords = _texCoords;
// Get color
Expand Down
6 changes: 4 additions & 2 deletions resources/instanced_default_Tpos_Tdir_Tscale.vert
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ out vec3 eyeVertex;
out vec3 eyeNormal;
out vec2 texCoords;

vec3 getVertex();
vec3 getNormal();
vec3 getScale();
mat3 getDirection();
vec3 getPosition();
void main()
{
// Apply model matrix to raw vertex
vec4 vert = _modelMat * vec4(_vertex,1.0f);
vec4 vert = _modelMat * vec4(getVertex(),1.0f);
// Apply a user defined scale multiplier
vert.xyz *= getScale();
// Apply a user defined rotation
Expand All @@ -35,7 +37,7 @@ void main()
gl_Position = _projectionMat * vec4(eyeVertex, 1.0f);

// Calc eye normal
eyeNormal = normalize(_normalMat * transpose(inverse(directionMat)) * normalize(_normal));
eyeNormal = normalize(_normalMat * transpose(inverse(directionMat)) * normalize(getNormal()));
// Calc tex coords
texCoords = _texCoords;
}
Loading

0 comments on commit 18593c7

Please sign in to comment.