Skip to content

Implement md2 model animation (VAT) #117 [DRAFT]#138

Merged
demoth merged 24 commits intomainfrom
develop
Jun 16, 2025
Merged

Implement md2 model animation (VAT) #117 [DRAFT]#138
demoth merged 24 commits intomainfrom
develop

Conversation

@demoth
Copy link
Owner

@demoth demoth commented Jun 15, 2025

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

demoth added 22 commits June 7, 2025 21:54
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.
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
add the required setup with uniforms and shader initialization
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 ... */

@demoth demoth marked this pull request as ready for review June 16, 2025 21:54
@demoth demoth merged commit 4a49af5 into main Jun 16, 2025
1 check passed
@demoth demoth deleted the develop branch June 16, 2025 21:54
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.

4 participants