mirror of
https://github.com/raysan5/raylib.git
synced 2026-04-11 09:39:09 -04:00
WARNING: BREAKING: REDESIGNED: **Animation System** #4606
REVIEWED: Reorganized structures for a clearer distinction between "skeleton", "skin" and "skinning" data ADDED: New structures: `ModelSkeleton`, `ModelAnimPose` (alias `Transform*`) ADDED: Runtime data `currentPose` and `boneMatrices` to `Model` structure ADDED: Support animation frames-blending, for timing control ADDED: Support animations blending, between two animations REVIEWED: All models animation loading functions ADDED: `UpdateModelAnimationEx()` for two animations blending REMOVED: `UpdateModelAnimationBones*()`, simplified API REVIEWED: Shader attributes/uniforms names for animations, for consistency REVIEWED: Multiple tweaks on animations loading for consistency between formats ADDED: example: `models_animation_timing` ADDED: example: `models_animation_blending` REVIEWED: example: `models_animation_gpu_skinning` REVIEWED: example: `models_animation_blend_custom` REVIEWED: All animated models loading examples
This commit is contained in:
59
src/raylib.h
59
src/raylib.h
@ -353,13 +353,15 @@ typedef struct Mesh {
|
||||
unsigned char *colors; // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
|
||||
unsigned short *indices; // Vertex indices (in case vertex data comes indexed)
|
||||
|
||||
// Animation vertex data
|
||||
// Skin data for animation
|
||||
int boneCount; // Number of bones (MAX: 256 bones)
|
||||
unsigned char *boneIndices; // Vertex bone indices, up to 4 bones influence by vertex (skinning) (shader-location = 6)
|
||||
float *boneWeights; // Vertex bone weight, up to 4 bones influence by vertex (skinning) (shader-location = 7)
|
||||
|
||||
// Runtime animation vertex data (CPU skinning)
|
||||
// NOTE: In case of GPU skinning, not used, pointers are NULL
|
||||
float *animVertices; // Animated vertex positions (after bones transformations)
|
||||
float *animNormals; // Animated normals (after bones transformations)
|
||||
unsigned char *boneIds; // Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning) (shader-location = 6)
|
||||
float *boneWeights; // Vertex bone weight, up to 4 bones influence by vertex (skinning) (shader-location = 7)
|
||||
Matrix *boneMatrices; // Bones animated transformation matrices
|
||||
int boneCount; // Number of bones
|
||||
|
||||
// OpenGL identifiers
|
||||
unsigned int vaoId; // OpenGL Vertex Array Object id
|
||||
@ -393,12 +395,22 @@ typedef struct Transform {
|
||||
Vector3 scale; // Scale
|
||||
} Transform;
|
||||
|
||||
// Anim pose, an array of Transform[]
|
||||
typedef Transform *ModelAnimPose;
|
||||
|
||||
// Bone, skeletal animation bone
|
||||
typedef struct BoneInfo {
|
||||
char name[32]; // Bone name
|
||||
int parent; // Bone parent
|
||||
} BoneInfo;
|
||||
|
||||
// Skeleton, animation bones hierarchy
|
||||
typedef struct ModelSkeleton {
|
||||
int boneCount; // Number of bones
|
||||
BoneInfo *bones; // Bones information (skeleton)
|
||||
ModelAnimPose bindPose; // Bones base transformation (Transform[])
|
||||
} ModelSkeleton;
|
||||
|
||||
// Model, meshes, materials and animation data
|
||||
typedef struct Model {
|
||||
Matrix transform; // Local transform matrix
|
||||
@ -410,18 +422,20 @@ typedef struct Model {
|
||||
int *meshMaterial; // Mesh material number
|
||||
|
||||
// Animation data
|
||||
int boneCount; // Number of bones
|
||||
BoneInfo *bones; // Bones information (skeleton)
|
||||
Transform *bindPose; // Bones base transformation (pose)
|
||||
ModelSkeleton skeleton; // Skeleton for animation
|
||||
|
||||
// Runtime animation data (CPU/GPU skinning)
|
||||
ModelAnimPose currentPose; // Current animation pose (Transform[])
|
||||
Matrix *boneMatrices; // Bones animated transformation matrices
|
||||
} Model;
|
||||
|
||||
// ModelAnimation
|
||||
// ModelAnimation, contains a full animation sequence
|
||||
typedef struct ModelAnimation {
|
||||
char name[32]; // Animation name
|
||||
int boneCount; // Number of bones
|
||||
int frameCount; // Number of animation frames
|
||||
BoneInfo *bones; // Bones information (skeleton)
|
||||
Transform **framePoses; // Poses array by frame
|
||||
|
||||
int boneCount; // Number of bones (per pose)
|
||||
int keyframeCount; // Number of animation key frames
|
||||
ModelAnimPose *keyframePoses; // Animation sequence keyframe poses [keyframe][pose]
|
||||
} ModelAnimation;
|
||||
|
||||
// Ray, ray for raycasting
|
||||
@ -768,6 +782,8 @@ typedef enum {
|
||||
#define MATERIAL_MAP_SPECULAR MATERIAL_MAP_METALNESS
|
||||
|
||||
// Shader location index
|
||||
// NOTE: Some locations are tried to be set automatically on shader loading,
|
||||
// but only if default attributes/uniforms names are found, check config.h for names
|
||||
typedef enum {
|
||||
SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position
|
||||
SHADER_LOC_VERTEX_TEXCOORD01, // Shader location: vertex attribute: texcoord01
|
||||
@ -790,15 +806,15 @@ typedef enum {
|
||||
SHADER_LOC_MAP_ROUGHNESS, // Shader location: sampler2d texture: roughness
|
||||
SHADER_LOC_MAP_OCCLUSION, // Shader location: sampler2d texture: occlusion
|
||||
SHADER_LOC_MAP_EMISSION, // Shader location: sampler2d texture: emission
|
||||
SHADER_LOC_MAP_HEIGHT, // Shader location: sampler2d texture: height
|
||||
SHADER_LOC_MAP_HEIGHT, // Shader location: sampler2d texture: heightmap
|
||||
SHADER_LOC_MAP_CUBEMAP, // Shader location: samplerCube texture: cubemap
|
||||
SHADER_LOC_MAP_IRRADIANCE, // Shader location: samplerCube texture: irradiance
|
||||
SHADER_LOC_MAP_PREFILTER, // Shader location: samplerCube texture: prefilter
|
||||
SHADER_LOC_MAP_BRDF, // Shader location: sampler2d texture: brdf
|
||||
SHADER_LOC_VERTEX_BONEIDS, // Shader location: vertex attribute: boneIds
|
||||
SHADER_LOC_VERTEX_BONEWEIGHTS, // Shader location: vertex attribute: boneWeights
|
||||
SHADER_LOC_BONE_MATRICES, // Shader location: array of matrices uniform: boneMatrices
|
||||
SHADER_LOC_VERTEX_INSTANCE_TX // Shader location: vertex attribute: instanceTransform
|
||||
SHADER_LOC_VERTEX_BONEIDS, // Shader location: vertex attribute: bone indices
|
||||
SHADER_LOC_VERTEX_BONEWEIGHTS, // Shader location: vertex attribute: bone weights
|
||||
SHADER_LOC_MATRIX_BONETRANSFORMS, // Shader location: matrix attribute: bone transforms (animation)
|
||||
SHADER_LOC_VERTEX_INSTANCETRANSFORMS // Shader location: vertex attribute: instance transforms
|
||||
} ShaderLocationIndex;
|
||||
|
||||
#define SHADER_LOC_MAP_DIFFUSE SHADER_LOC_MAP_ALBEDO
|
||||
@ -1619,11 +1635,8 @@ RLAPI void SetModelMeshMaterial(Model *model, int meshId, int materialId);
|
||||
|
||||
// Model animations loading/unloading functions
|
||||
RLAPI ModelAnimation *LoadModelAnimations(const char *fileName, int *animCount); // Load model animations from file
|
||||
RLAPI void UpdateModelAnimation(Model model, ModelAnimation anim, int frame); // Update model animation pose (CPU)
|
||||
RLAPI void UpdateModelAnimationBones(Model model, ModelAnimation anim, int frame); // Update model animation mesh bone matrices (GPU skinning)
|
||||
RLAPI void UpdateModelAnimationBonesLerp(Model model, ModelAnimation animA, int frameA, ModelAnimation animB, int frameB, float value); // Update model animation mesh bone matrices with interpolation between two poses(GPU skinning)
|
||||
RLAPI void UpdateModelVertsToCurrentBones(Model model); // Update model vertices according to mesh bone matrices (CPU)
|
||||
RLAPI void UnloadModelAnimation(ModelAnimation anim); // Unload animation data
|
||||
RLAPI void UpdateModelAnimation(Model model, ModelAnimation anim, float frame); // Update model animation pose (vertex buffers and bone matrices)
|
||||
RLAPI void UpdateModelAnimationEx(Model model, ModelAnimation animA, float frameA, ModelAnimation animB, float frameB, float blend); // Update model animation pose, blending two animations
|
||||
RLAPI void UnloadModelAnimations(ModelAnimation *animations, int animCount); // Unload animation array data
|
||||
RLAPI bool IsModelAnimationValid(Model model, ModelAnimation anim); // Check model animation skeleton match
|
||||
|
||||
|
||||
Reference in New Issue
Block a user