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

Dread BCTEX export to dds #240

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

steven11sjf
Copy link
Contributor

  • added a RawTexture class that can parse all images, arrays, surfaces and mipmaps from Dread .bctex formats
  • added a DdsExporter class that can convert a RawTexture class into a Direct Draw Surface file (byte matching with SwitchToolbox exports)
  • added tests to validate the SHA256 of (one of) each used XTX format

Notes:

  • I probably overengineered the DDS, was going to make a complete parser but ended up changing how some stuff works to get bytematching with STB exports
  • I know something is wrong with the construct Enums because I couldn't get it to be the actual enum value, just the name.

Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 91.13924% with 21 lines in your changes missing coverage. Please review.

Project coverage is 77.65%. Comparing base (4c40dc6) to head (669fc93).

Files with missing lines Patch % Lines
...rc/mercury_engine_data_structures/exporters/dds.py 87.17% 15 Missing ⚠️
...ry_engine_data_structures/exporters/raw_texture.py 93.61% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #240      +/-   ##
==========================================
+ Coverage   76.84%   77.65%   +0.81%     
==========================================
  Files          78       80       +2     
  Lines        3874     4109     +235     
==========================================
+ Hits         2977     3191     +214     
- Misses        897      918      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

- added a RawTexture class that can parse all images, arrays, surfaces
  and mipmaps from Dread .bctex formats
- added a DdsExporter class that can convert a RawTexture class into a
  Direct Draw Surface file (byte matching with SwitchToolbox exports)
- added tests to validate the SHA256 of (one of) each used XTX format
width_blks, height_blks, depth_blks, data, height_mip0, mip0.format.bytes_per_pixel
)
return res
except Exception:
Copy link
Member

Choose a reason for hiding this comment

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

What kind of situations can cause this to fail, and why not just let the exception "leak"?

If it's expected to fail sometimes, then return type must indicate it can be None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it outputs an ugly Rust exception, and after spending a day trying to get rust interop working I didn't bother figuring out the proper exception wrapper haha. If it fails, it would basically mean invalid data in the texture.

I can go back and fix it, just want to wrap up some stuff on navmesh tonight.

return Texture2D(mips)

def _deswizzle(self, width: int, height: int, depth: int, mip0: Mip0Data, heightLog2: int, data: bytes) -> bytes:
height_mip0 = 1 << max(min(heightLog2, 5), 0)
Copy link
Member

Choose a reason for hiding this comment

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

height_log2


folder.mkdir(parents=True, exist_ok=True)
if not name:
name = self.raw.name + ".dds"
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test for this method?


return Texture2D(mips)

def _deswizzle(self, width: int, height: int, depth: int, mip0: Mip0Data, heightLog2: int, data: bytes) -> bytes:
Copy link
Member

Choose a reason for hiding this comment

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

Please add a docstring


self.parse()

def parse(self):
Copy link
Member

Choose a reason for hiding this comment

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

Is this method supposed to be called multiple times? If it's just the constructor, make it private.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants