Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some update to gltf loading #4373

Merged
merged 1 commit into from
Oct 10, 2024
Merged

Some update to gltf loading #4373

merged 1 commit into from
Oct 10, 2024

Conversation

HarryDC
Copy link
Contributor

@HarryDC HarryDC commented Oct 8, 2024

Hit some small snags when importing from kenneys assets this is just a small update.

  • Allows animations to be imported even if they affect more skins than expected, this allows users to decide if the degraded animations work for them or not
  • Allows unsigned char as an mesh index type

It slightly changes the import macro to correctly cast to the expected type, the old macro is overloaded to maintain the old functionality

Only warns when there are more animations than currently implemented
Allows mesh indices to be unsigned char
#define LOAD_ATTRIBUTE(accesor, numComp, dataType, dstPtr) \
#define LOAD_ATTRIBUTE(accesor, numComp, srcType, dstPtr) LOAD_ATTRIBUTE_CAST(accesor, numComp, srcType, dstPtr, srcType)

#define LOAD_ATTRIBUTE_CAST(accesor, numComp, srcType, dstPtr, dstType) \
Copy link
Contributor Author

@HarryDC HarryDC Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raysan5 mention in discord this would have to change to include something like

if (dstPtr == NULL) { 
  dstPtr = RL_ALLOC(accessor->count * numComp * sizeof(dstType); 
}

This would reduce a lot of the 4-6 line if/else branches to 1 Line

LOAD_ATTRIBUTE(accessor, numpComp, srcType, dstPtr, dstType)

As this touches every if branch in the gltf load i didn't even want to start that before checking

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I don't like that macro at all, it could be confusing and it's difficult/impossible to debug.

Said that, proposed improvement sounds good to me. Feel free to send a PR with the required updates.

@@ -5697,23 +5699,25 @@ static Model LoadGLTF(const char *fileName)
// Load unsigned short data type into mesh.indices
LOAD_ATTRIBUTE(attribute, 1, unsigned short, model.meshes[meshIndex].indices)
}
else if (attribute->component_type == cgltf_component_type_r_8u)
{
// Init raylib mesh indices to copy glTF attribute data
Copy link
Contributor Author

@HarryDC HarryDC Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With allocation inside the macro, this would be one line

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@raysan5 raysan5 merged commit 454acca into raysan5:master Oct 10, 2024
@raysan5
Copy link
Owner

raysan5 commented Oct 10, 2024

@HarryDC Thanks for the improvement! Added a note on proposed macro change: looks fine to me.

psxdev pushed a commit to raylib4Consoles/raylib that referenced this pull request Nov 18, 2024
Only warns when there are more animations than currently implemented
Allows mesh indices to be unsigned char
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants