Conversation
Finally, some working code! Add a test for transformation of vertex attributes (so far it's only tex coords). Transformation of vertex positions and VAT is still TODO
Implemented the vertex positional data conversion from md2 format. Turned out to be easier than expected - instead of reindexing all the vertices in the frames positions, the index in the VAT is passed as the vertex attribute (along with the texture coordinates). Not only this helps to avoid duplication of data, it also makes the code simpler. Added a test.
prepare md2 loader to load VAT
fix shader to accommodate for the vertex index in the VAT (passed instead of the built-in gl_VertexID)
fix missed vertex attribute in the md2 loader Finally, something showes up but clearly it is not correct
shameful bugfix: incorrect order of width / height
completely forgot to unpack triangle strips and fans into independent triangles; fixed
my previous idea about reindexing was flawed - after unpacking triangle strips and fans into the independent triangles we pass all resulting indices in the ascending order to the shader
finally smooth md2 animation!
add the required setup with uniforms and shader initialization
There was a problem hiding this comment.
Pull Request Overview
This PR implements an efficient GPU-based animation system for md2 models by refactoring vertex data preparation, updating shader interfaces, and adjusting model loading routines. Key changes include:
- Renaming and refactoring of functions (e.g. toFloats → toVertexAttributes) to better express functionality.
- Modifications in model frame parsing (using Md2Frame.fromBuffer) and texture creation for vertex animations.
- Updates to shader code and resource handling in the model viewer and test cases.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| qcommon/src/test/kotlin/jake2/qcommon/filesystem/Md2ModelVertexDataTest.kt | Added thorough test data for verifying vertex re-indexing and attribute generation. |
| qcommon/src/test/kotlin/jake2/qcommon/filesystem/Md2ModelTest.kt | Updated test assertions to use the new toVertexAttributes API. |
| qcommon/src/main/kotlin/jake2/qcommon/filesystem/md2.kt | Replaced toFloats with toVertexAttributes and updated frame parsing logic via Md2Frame.fromBuffer. |
| cake/lwjgl3/src/main/kotlin/org/demoth/cake/lwjgl3/Md2ShaderTest.kt | Adjusted animation control, resource loading and input handling for model rendering. |
| cake/core/src/main/kotlin/org/demoth/cake/modelviewer/Md2Shader.kt | Introduced a new shader implementation for md2 vertex animations using VAT. |
| cake/core/src/main/kotlin/org/demoth/cake/modelviewer/Md2ModelLoader.kt | Added loadStaticMd2Model and refactored VAT texture creation and mesh building. |
| cake/core/src/main/kotlin/org/demoth/cake/modelviewer/CustomTextureData.kt | Updated Md2ShaderModel to reflect disposed texture handling. |
| cake/core/src/main/kotlin/org/demoth/cake/modelviewer/CakeModelViewer.kt | Temporarily commented out rendering call with a fixme note for further review. |
| cake/core/src/main/java/org/demoth/cake/stages/Game3dScreen.kt | Updated to use the static model loading approach. |
| assets/shaders/vat.glsl | Adjusted attribute usage to use a_vat_index instead of relying on gl_VertexID. |
| assets/shaders/md2-fragment.glsl | Removed the custom fragment shader in favor of default shader behavior. |
Comments suppressed due to low confidence (2)
qcommon/src/main/kotlin/jake2/qcommon/filesystem/md2.kt:266
- [nitpick] The parameter name 'framePositions' in toVertexAttributes is inconsistent with similar methods which use 'points'. Consider renaming it to 'points' for clarity and consistency.
fun toVertexAttributes(framePositions: List<Md2Point>, returnTexCoords: Boolean = true): List<Float> {
cake/core/src/main/kotlin/org/demoth/cake/modelviewer/Md2ModelLoader.kt:74
- [nitpick] There is legacy commented-out code related to mesh building that is no longer used. Removing these comments could improve code readability and maintainability.
/* ... legacy meshBuilder code commented out ... */
cake/core/src/main/kotlin/org/demoth/cake/modelviewer/CakeModelViewer.kt
Outdated
Show resolved
Hide resolved
demoth
commented
Jun 15, 2025
demoth
commented
Jun 15, 2025
cake/core/src/main/kotlin/org/demoth/cake/modelviewer/CustomTextureData.kt
Show resolved
Hide resolved
demoth
commented
Jun 15, 2025
denolia
approved these changes
Jun 15, 2025
cake/core/src/main/kotlin/org/demoth/cake/modelviewer/CustomTextureData.kt
Outdated
Show resolved
Hide resolved
samoylovfp
reviewed
Jun 16, 2025
samoylovfp
reviewed
Jun 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement efficient GPU based animation for md2 models
Should be smooth as butter and run natively on 144Hz
Some very early attempts with the shaders was already in main, thats why some classes are changed and not added
STATUS: Works flawlessly (
Md2ShaderTest.kt)TODO: switch the model viewer and the game onto the new implementation
This is a complex topic I understand, nevertheless I added people for review to try to start a discussion and raise question.
Pick any line and ask a question