mirror of
https://github.com/raysan5/raylib.git
synced 2025-10-21 01:01:50 +00:00
use bone weights for animation (#1728)
This commit is contained in:
28
src/models.c
28
src/models.c
@@ -1425,10 +1425,22 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
|||||||
int vCounter = 0;
|
int vCounter = 0;
|
||||||
int boneCounter = 0;
|
int boneCounter = 0;
|
||||||
int boneId = 0;
|
int boneId = 0;
|
||||||
|
float boneWeight = 0.0;
|
||||||
|
|
||||||
for (int i = 0; i < model.meshes[m].vertexCount; i++)
|
for (int i = 0; i < model.meshes[m].vertexCount; i++)
|
||||||
|
{
|
||||||
|
model.meshes[m].animVertices[vCounter] = 0;
|
||||||
|
model.meshes[m].animVertices[vCounter + 1] = 0;
|
||||||
|
model.meshes[m].animVertices[vCounter + 2] = 0;
|
||||||
|
|
||||||
|
model.meshes[m].animNormals[vCounter] = 0;
|
||||||
|
model.meshes[m].animNormals[vCounter + 1] = 0;
|
||||||
|
model.meshes[m].animNormals[vCounter + 2] = 0;
|
||||||
|
|
||||||
|
for (int j = 0; j < 4; j++)
|
||||||
{
|
{
|
||||||
boneId = model.meshes[m].boneIds[boneCounter];
|
boneId = model.meshes[m].boneIds[boneCounter];
|
||||||
|
boneWeight = model.meshes[m].boneWeights[boneCounter];
|
||||||
inTranslation = model.bindPose[boneId].translation;
|
inTranslation = model.bindPose[boneId].translation;
|
||||||
inRotation = model.bindPose[boneId].rotation;
|
inRotation = model.bindPose[boneId].rotation;
|
||||||
//inScale = model.bindPose[boneId].scale;
|
//inScale = model.bindPose[boneId].scale;
|
||||||
@@ -1443,9 +1455,9 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
|||||||
animVertex = Vector3Subtract(animVertex, inTranslation);
|
animVertex = Vector3Subtract(animVertex, inTranslation);
|
||||||
animVertex = Vector3RotateByQuaternion(animVertex, QuaternionMultiply(outRotation, QuaternionInvert(inRotation)));
|
animVertex = Vector3RotateByQuaternion(animVertex, QuaternionMultiply(outRotation, QuaternionInvert(inRotation)));
|
||||||
animVertex = Vector3Add(animVertex, outTranslation);
|
animVertex = Vector3Add(animVertex, outTranslation);
|
||||||
model.meshes[m].animVertices[vCounter] = animVertex.x;
|
model.meshes[m].animVertices[vCounter] += animVertex.x * boneWeight;
|
||||||
model.meshes[m].animVertices[vCounter + 1] = animVertex.y;
|
model.meshes[m].animVertices[vCounter + 1] += animVertex.y * boneWeight;
|
||||||
model.meshes[m].animVertices[vCounter + 2] = animVertex.z;
|
model.meshes[m].animVertices[vCounter + 2] += animVertex.z * boneWeight;
|
||||||
|
|
||||||
// Normals processing
|
// Normals processing
|
||||||
// NOTE: We use meshes.baseNormals (default normal) to calculate meshes.normals (animated normals)
|
// NOTE: We use meshes.baseNormals (default normal) to calculate meshes.normals (animated normals)
|
||||||
@@ -1453,13 +1465,13 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
|||||||
{
|
{
|
||||||
animNormal = (Vector3){ model.meshes[m].normals[vCounter], model.meshes[m].normals[vCounter + 1], model.meshes[m].normals[vCounter + 2] };
|
animNormal = (Vector3){ model.meshes[m].normals[vCounter], model.meshes[m].normals[vCounter + 1], model.meshes[m].normals[vCounter + 2] };
|
||||||
animNormal = Vector3RotateByQuaternion(animNormal, QuaternionMultiply(outRotation, QuaternionInvert(inRotation)));
|
animNormal = Vector3RotateByQuaternion(animNormal, QuaternionMultiply(outRotation, QuaternionInvert(inRotation)));
|
||||||
model.meshes[m].animNormals[vCounter] = animNormal.x;
|
model.meshes[m].animNormals[vCounter] += animNormal.x * boneWeight;
|
||||||
model.meshes[m].animNormals[vCounter + 1] = animNormal.y;
|
model.meshes[m].animNormals[vCounter + 1] += animNormal.y * boneWeight;
|
||||||
model.meshes[m].animNormals[vCounter + 2] = animNormal.z;
|
model.meshes[m].animNormals[vCounter + 2] += animNormal.z * boneWeight;
|
||||||
|
}
|
||||||
|
boneCounter += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
vCounter += 3;
|
vCounter += 3;
|
||||||
boneCounter += 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload new vertex data to GPU for model drawing
|
// Upload new vertex data to GPU for model drawing
|
||||||
|
Reference in New Issue
Block a user