GothicKit / ZenKit

A re-implementation of file formats used by the early 2000's ZenGin
http://zk.gothickit.dev/
MIT License
44 stars 9 forks source link

Added XZEN support #83

Closed ThielHater closed 10 months ago

ThielHater commented 10 months ago

This pull request will add support for XZEN, a variation of the Gothic 1 mesh format that uses a wider vertex index like Gothic 2 does.

The Gothic Reloaded Mod aims to improve the graphics of Gothic 1 and when we added more details to the level mesh, it became too complex. Years ago, even before Union, @ataulien wrote a plugin to patch the engine at runtime to read and write wider vertex indizes. To indicate this format, he set the user name in the header of the .ZEN file to XZEN, giving it the name.

We shared this solution with the community, so it is probably used by other Gothic 1 mods too. The GothicZEN converter tool of @withmorten also supports it.

I came across this issue when I tried to run the mod on OpenGothic, which uses phoenix.

ThielHater commented 10 months ago

Phoenix does some special case handling in that part of the code and I have to say that I am not 100 percent sure if the fix is accurate but it yields the expected vertex count and OpenGothic will load and render the mesh properly now. 😄

lmichaelis commented 10 months ago

Hi and thanks for the PR :) Am I understanding correctly that all that XZEN does is extend the size of vertex indices in meshes (and only bare meshes) by two bytes, from an uint16_t to a uint32_t? It does not touch anything else, like the polygon flags?

ThielHater commented 10 months ago

Yep. You may have a look at the plugin code, the comments are very insightful:

https://github.com/ThielHater/GRMFixes_Union/blob/master/GRMFixes/XZenFileFormat/Plugin_Source.hpp#L86

lmichaelis commented 10 months ago

Okay. Could you verify that it still works fine with these changes @ThielHater, please?

ThielHater commented 10 months ago

I pulled your changes and rebuild OpenGothic, then I verified that it works with G1 and G2 as well as our mod.

lmichaelis commented 10 months ago

Cool, thanks! Merged!