Binding to initial bind pose added.
This commit is contained in:
parent
8bd310c891
commit
c9cfb0e738
42
src/models.c
42
src/models.c
|
|
@ -4022,6 +4022,48 @@ static Model LoadGLTF(const char *fileName)
|
|||
|
||||
RL_FREE(fileData);
|
||||
|
||||
// Bind pose setup
|
||||
for (int m = 0; m < model.meshCount; m++)
|
||||
{
|
||||
Vector3 boundVertex = { 0 };
|
||||
Vector3 boundNormal = { 0 };
|
||||
|
||||
Vector3 outTranslation = { 0 };
|
||||
Quaternion outRotation = { 0 };
|
||||
Vector3 outScale = { 0 };
|
||||
|
||||
int vCounter = 0;
|
||||
int boneCounter = 0;
|
||||
int boneId = 0;
|
||||
|
||||
for (int i = 0; i < model.meshes[m].vertexCount; i++)
|
||||
{
|
||||
boneId = model.meshes[m].boneIds[boneCounter];
|
||||
outTranslation = model.bindPose[boneId].translation;
|
||||
outRotation = model.bindPose[boneId].rotation;
|
||||
outScale = model.bindPose[boneId].scale;
|
||||
|
||||
// Vertices processing
|
||||
boundVertex = (Vector3){ model.meshes[m].vertices[vCounter], model.meshes[m].vertices[vCounter + 1], model.meshes[m].vertices[vCounter + 2] };
|
||||
boundVertex = Vector3Multiply(boundVertex, outScale);
|
||||
boundVertex = Vector3RotateByQuaternion(boundVertex, outRotation);
|
||||
boundVertex = Vector3Add(boundVertex, outTranslation);
|
||||
model.meshes[m].vertices[vCounter] = boundVertex.x;
|
||||
model.meshes[m].vertices[vCounter + 1] = boundVertex.y;
|
||||
model.meshes[m].vertices[vCounter + 2] = boundVertex.z;
|
||||
|
||||
// Normals processing
|
||||
boundNormal = (Vector3){ model.meshes[m].normals[vCounter], model.meshes[m].normals[vCounter + 1], model.meshes[m].normals[vCounter + 2] };
|
||||
boundNormal = Vector3RotateByQuaternion(boundNormal, outRotation);
|
||||
model.meshes[m].normals[vCounter] = boundNormal.x;
|
||||
model.meshes[m].normals[vCounter + 1] = boundNormal.y;
|
||||
model.meshes[m].normals[vCounter + 2] = boundNormal.z;
|
||||
vCounter += 3;
|
||||
|
||||
boneCounter += 4;
|
||||
}
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user