Review some warnings and formatting
This commit is contained in:
parent
4e68524871
commit
9619e5cbf8
1 changed files with 28 additions and 28 deletions
56
src/models.c
56
src/models.c
|
@ -3738,7 +3738,7 @@ static Model LoadGLTF(const char *fileName)
|
||||||
|
|
||||||
for (unsigned int i = 0; i < data->nodes_count; i++)
|
for (unsigned int i = 0; i < data->nodes_count; i++)
|
||||||
{
|
{
|
||||||
if(data->nodes[i].has_translation)
|
if (data->nodes[i].has_translation)
|
||||||
{
|
{
|
||||||
memcpy(&model.bindPose[i].translation, data->nodes[i].translation, 3 * sizeof(float));
|
memcpy(&model.bindPose[i].translation, data->nodes[i].translation, 3 * sizeof(float));
|
||||||
}
|
}
|
||||||
|
@ -3747,7 +3747,7 @@ static Model LoadGLTF(const char *fileName)
|
||||||
model.bindPose[i].translation = Vector3Zero();
|
model.bindPose[i].translation = Vector3Zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data->nodes[i].has_rotation)
|
if (data->nodes[i].has_rotation)
|
||||||
{
|
{
|
||||||
memcpy(&model.bindPose[i].rotation, data->nodes[i].rotation, 4 * sizeof(float));
|
memcpy(&model.bindPose[i].rotation, data->nodes[i].rotation, 4 * sizeof(float));
|
||||||
}
|
}
|
||||||
|
@ -3757,7 +3757,7 @@ static Model LoadGLTF(const char *fileName)
|
||||||
}
|
}
|
||||||
model.bindPose[i].rotation = QuaternionNormalize(model.bindPose[i].rotation);
|
model.bindPose[i].rotation = QuaternionNormalize(model.bindPose[i].rotation);
|
||||||
|
|
||||||
if(data->nodes[i].has_scale)
|
if (data->nodes[i].has_scale)
|
||||||
{
|
{
|
||||||
memcpy(&model.bindPose[i].scale, data->nodes[i].scale, 3 * sizeof(float));
|
memcpy(&model.bindPose[i].scale, data->nodes[i].scale, 3 * sizeof(float));
|
||||||
}
|
}
|
||||||
|
@ -3898,19 +3898,19 @@ static Model LoadGLTF(const char *fileName)
|
||||||
{
|
{
|
||||||
cgltf_accessor *acc = data->meshes[i].primitives[p].attributes[j].data;
|
cgltf_accessor *acc = data->meshes[i].primitives[p].attributes[j].data;
|
||||||
|
|
||||||
if(acc->component_type == cgltf_component_type_r_16u)
|
if (acc->component_type == cgltf_component_type_r_16u)
|
||||||
{
|
{
|
||||||
model.meshes[primitiveIndex].boneIds = RL_MALLOC(sizeof(int) * acc->count * 4);
|
model.meshes[primitiveIndex].boneIds = RL_MALLOC(sizeof(int) * acc->count * 4);
|
||||||
short* bones = RL_MALLOC(sizeof(short) * acc->count * 4);
|
short* bones = RL_MALLOC(sizeof(short) * acc->count * 4);
|
||||||
|
|
||||||
LOAD_ACCESSOR(short, 4, acc, bones);
|
LOAD_ACCESSOR(short, 4, acc, bones);
|
||||||
for(int a = 0; a < acc->count * 4; a ++)
|
for (unsigned int a = 0; a < acc->count * 4; a ++)
|
||||||
{
|
{
|
||||||
cgltf_node* skinJoint = data->skins->joints[bones[a]];
|
cgltf_node* skinJoint = data->skins->joints[bones[a]];
|
||||||
|
|
||||||
for(int k = 0; k < data->nodes_count; k++)
|
for (unsigned int k = 0; k < data->nodes_count; k++)
|
||||||
{
|
{
|
||||||
if(&(data->nodes[k]) == skinJoint)
|
if (&(data->nodes[k]) == skinJoint)
|
||||||
{
|
{
|
||||||
model.meshes[primitiveIndex].boneIds[a] = k;
|
model.meshes[primitiveIndex].boneIds[a] = k;
|
||||||
break;
|
break;
|
||||||
|
@ -3967,7 +3967,7 @@ static Model LoadGLTF(const char *fileName)
|
||||||
model.meshMaterial[primitiveIndex] = model.materialCount - 1;;
|
model.meshMaterial[primitiveIndex] = model.materialCount - 1;;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(data->meshes[i].)
|
// if (data->meshes[i].)
|
||||||
|
|
||||||
primitiveIndex++;
|
primitiveIndex++;
|
||||||
}
|
}
|
||||||
|
@ -3985,9 +3985,9 @@ static Model LoadGLTF(const char *fileName)
|
||||||
|
|
||||||
static bool GltfReadFloat(cgltf_accessor* acc, unsigned int index, float* variable, unsigned int elements)
|
static bool GltfReadFloat(cgltf_accessor* acc, unsigned int index, float* variable, unsigned int elements)
|
||||||
{
|
{
|
||||||
if(acc->count == 2)
|
if (acc->count == 2)
|
||||||
{
|
{
|
||||||
if(index > 1)
|
if (index > 1)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -4058,18 +4058,18 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo
|
||||||
float animationDuration = 0.0f;
|
float animationDuration = 0.0f;
|
||||||
|
|
||||||
// Getting the max animation time to consider for animation duration
|
// Getting the max animation time to consider for animation duration
|
||||||
for (int i = 0; i < animation->channels_count; i++)
|
for (unsigned int i = 0; i < animation->channels_count; i++)
|
||||||
{
|
{
|
||||||
cgltf_animation_channel* channel = animation->channels + i;
|
cgltf_animation_channel* channel = animation->channels + i;
|
||||||
int frameCounts = channel->sampler->input->count;
|
int frameCounts = channel->sampler->input->count;
|
||||||
float lastFrameTime = 0.0f;
|
float lastFrameTime = 0.0f;
|
||||||
if(GltfReadFloat(channel->sampler->input, frameCounts - 1, &lastFrameTime, 1))
|
if (GltfReadFloat(channel->sampler->input, frameCounts - 1, &lastFrameTime, 1))
|
||||||
{
|
{
|
||||||
animationDuration = fmaxf(lastFrameTime, animationDuration);
|
animationDuration = fmaxf(lastFrameTime, animationDuration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output->frameCount = animationDuration / TIMESTEP;
|
output->frameCount = (int)(animationDuration / TIMESTEP);
|
||||||
output->boneCount = data->nodes_count;
|
output->boneCount = data->nodes_count;
|
||||||
output->bones = RL_MALLOC(output->boneCount*sizeof(BoneInfo));
|
output->bones = RL_MALLOC(output->boneCount*sizeof(BoneInfo));
|
||||||
output->framePoses = RL_MALLOC(output->frameCount*sizeof(Transform *));
|
output->framePoses = RL_MALLOC(output->frameCount*sizeof(Transform *));
|
||||||
|
@ -4084,7 +4084,7 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo
|
||||||
|
|
||||||
// Allocate data for frames
|
// Allocate data for frames
|
||||||
// Initiate with zero bone translations
|
// Initiate with zero bone translations
|
||||||
for (unsigned int frame = 0; frame < output->frameCount; frame++)
|
for (int frame = 0; frame < output->frameCount; frame++)
|
||||||
{
|
{
|
||||||
output->framePoses[frame] = RL_MALLOC(output->frameCount*data->nodes_count*sizeof(Transform));
|
output->framePoses[frame] = RL_MALLOC(output->frameCount*data->nodes_count*sizeof(Transform));
|
||||||
|
|
||||||
|
@ -4098,14 +4098,14 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo
|
||||||
}
|
}
|
||||||
|
|
||||||
// for each single transformation type on single bone
|
// for each single transformation type on single bone
|
||||||
for(int channelId = 0; channelId < animation->channels_count; channelId++)
|
for (unsigned int channelId = 0; channelId < animation->channels_count; channelId++)
|
||||||
{
|
{
|
||||||
cgltf_animation_channel* channel = animation->channels + channelId;
|
cgltf_animation_channel* channel = animation->channels + channelId;
|
||||||
cgltf_animation_sampler* sampler = channel->sampler;
|
cgltf_animation_sampler* sampler = channel->sampler;
|
||||||
|
|
||||||
int boneId = channel->target_node - data->nodes;
|
int boneId = channel->target_node - data->nodes;
|
||||||
|
|
||||||
for(int frame = 0; frame < output->frameCount; frame++)
|
for (int frame = 0; frame < output->frameCount; frame++)
|
||||||
{
|
{
|
||||||
bool shouldSkipFurtherTransformation = true;
|
bool shouldSkipFurtherTransformation = true;
|
||||||
int outputMin = 0;
|
int outputMin = 0;
|
||||||
|
@ -4116,19 +4116,19 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo
|
||||||
// For this transformation:
|
// For this transformation:
|
||||||
// getting between which input values the current frame time position
|
// getting between which input values the current frame time position
|
||||||
// and also what is the percent to use in the linear interpolation later
|
// and also what is the percent to use in the linear interpolation later
|
||||||
for(int j = 0; j < sampler->input->count; j++)
|
for (unsigned int j = 0; j < sampler->input->count; j++)
|
||||||
{
|
{
|
||||||
float inputFrameTime;
|
float inputFrameTime;
|
||||||
if(GltfReadFloat(sampler->input, j, (float*)&inputFrameTime, 1))
|
if (GltfReadFloat(sampler->input, j, (float*)&inputFrameTime, 1))
|
||||||
{
|
{
|
||||||
if(frameTime < inputFrameTime)
|
if (frameTime < inputFrameTime)
|
||||||
{
|
{
|
||||||
shouldSkipFurtherTransformation = false;
|
shouldSkipFurtherTransformation = false;
|
||||||
outputMin = j - 1;
|
outputMin = j - 1;
|
||||||
outputMax = j;
|
outputMax = j;
|
||||||
|
|
||||||
float previousInputTime = 0.0f;
|
float previousInputTime = 0.0f;
|
||||||
if(GltfReadFloat(sampler->input, j - 1, (float*)&previousInputTime, 1))
|
if (GltfReadFloat(sampler->input, j - 1, (float*)&previousInputTime, 1))
|
||||||
{
|
{
|
||||||
lerpPercent = (frameTime - previousInputTime) / (inputFrameTime - previousInputTime);
|
lerpPercent = (frameTime - previousInputTime) / (inputFrameTime - previousInputTime);
|
||||||
}
|
}
|
||||||
|
@ -4140,44 +4140,44 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the current transformation has no information for the current frame time point
|
// If the current transformation has no information for the current frame time point
|
||||||
if(shouldSkipFurtherTransformation) {
|
if (shouldSkipFurtherTransformation) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(channel->target_path == cgltf_animation_path_type_translation) {
|
if (channel->target_path == cgltf_animation_path_type_translation) {
|
||||||
Vector3 translationStart;
|
Vector3 translationStart;
|
||||||
Vector3 translationEnd;
|
Vector3 translationEnd;
|
||||||
|
|
||||||
bool success = GltfReadFloat(sampler->output, outputMin, (float*)&translationStart, 3);
|
bool success = GltfReadFloat(sampler->output, outputMin, (float*)&translationStart, 3);
|
||||||
success = GltfReadFloat(sampler->output, outputMax, (float*)&translationEnd, 3) || success;
|
success = GltfReadFloat(sampler->output, outputMax, (float*)&translationEnd, 3) || success;
|
||||||
|
|
||||||
if(success)
|
if (success)
|
||||||
{
|
{
|
||||||
output->framePoses[frame][boneId].translation = Vector3Lerp(translationStart, translationEnd, lerpPercent);
|
output->framePoses[frame][boneId].translation = Vector3Lerp(translationStart, translationEnd, lerpPercent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(channel->target_path == cgltf_animation_path_type_rotation) {
|
if (channel->target_path == cgltf_animation_path_type_rotation) {
|
||||||
Quaternion rotationStart;
|
Quaternion rotationStart;
|
||||||
Quaternion rotationEnd;
|
Quaternion rotationEnd;
|
||||||
|
|
||||||
bool success = GltfReadFloat(sampler->output, outputMin, (float*)&rotationStart, 4);
|
bool success = GltfReadFloat(sampler->output, outputMin, (float*)&rotationStart, 4);
|
||||||
success = GltfReadFloat(sampler->output, outputMax, (float*)&rotationEnd, 4) || success;
|
success = GltfReadFloat(sampler->output, outputMax, (float*)&rotationEnd, 4) || success;
|
||||||
|
|
||||||
if(success)
|
if (success)
|
||||||
{
|
{
|
||||||
output->framePoses[frame][boneId].rotation = QuaternionLerp(rotationStart, rotationEnd, lerpPercent);
|
output->framePoses[frame][boneId].rotation = QuaternionLerp(rotationStart, rotationEnd, lerpPercent);
|
||||||
output->framePoses[frame][boneId].rotation = QuaternionNormalize(output->framePoses[frame][boneId].rotation);
|
output->framePoses[frame][boneId].rotation = QuaternionNormalize(output->framePoses[frame][boneId].rotation);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(channel->target_path == cgltf_animation_path_type_scale) {
|
if (channel->target_path == cgltf_animation_path_type_scale) {
|
||||||
Vector3 scaleStart;
|
Vector3 scaleStart;
|
||||||
Vector3 scaleEnd;
|
Vector3 scaleEnd;
|
||||||
|
|
||||||
bool success = GltfReadFloat(sampler->output, outputMin, (float*)&scaleStart, 3);
|
bool success = GltfReadFloat(sampler->output, outputMin, (float*)&scaleStart, 3);
|
||||||
success = GltfReadFloat(sampler->output, outputMax, (float*)&scaleEnd, 3) || success;
|
success = GltfReadFloat(sampler->output, outputMax, (float*)&scaleEnd, 3) || success;
|
||||||
|
|
||||||
if(success)
|
if (success)
|
||||||
{
|
{
|
||||||
output->framePoses[frame][boneId].scale = Vector3Lerp(scaleStart, scaleEnd, lerpPercent);
|
output->framePoses[frame][boneId].scale = Vector3Lerp(scaleStart, scaleEnd, lerpPercent);
|
||||||
}
|
}
|
||||||
|
@ -4186,7 +4186,7 @@ static ModelAnimation* LoadGLTFModelAnimations(const char *fileName, int *animCo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build frameposes
|
// Build frameposes
|
||||||
for (unsigned int frame = 0; frame < output->frameCount; frame++)
|
for (int frame = 0; frame < output->frameCount; frame++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < output->boneCount; i++)
|
for (int i = 0; i < output->boneCount; i++)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue