Added One Material per Mesh Func & "GlobalBounding" Splitting Strategy - #99
Added One Material per Mesh Func & "GlobalBounding" Splitting Strategy#99gojushin wants to merge 5 commits into
Conversation
|
Sooo. The issue is that the current BinPacking algorithm, which I reused for this, can't handle the massively higher amount of charts very well, with its O(N²) - O(N³) speed.... I implemented shelf packing, which under O(N log N), handles packing within seconds but is a clear degradation in quality. I am currently looking into how I can combine the two... but this could take a bit of time to get right. Please hang tight :) |
|
In the long run, the only correct way to do this is probably to re-unwrap & bake the reduced parts. But that is likely out of scope here (and not really the point of the repo anyways). |
- Implemented Skyline Packing - Adjusted MeshT.MergeMaterialsIntoSingleAtlas to use SkylinePacking instead of ShelfPacking - Implemented various Edge Case Mitigations in MeshT.MergeMaterialsIntoSingleAtlas - Added Tests for the new logic
|
Well, this was an unexpected deep dive into rectangle packing algorithms. It turns out shelf packing never achieved what I was looking for. Therefore I made the following changes to finally achieve what I wanted:
Edge cases:
At any point a edge case is reached (which happens quickly), the user gets a WARNING printed to the terminal with the relevant stats. This should indicate a change in input parameters as a lot of quality is lost at that point. For example even .jpg compression actually starts to have a noticeable overall impact, when charts become 1px in size. In my testing it visually looks..... okay enough, given that charts will be very far away at that point. Also. Noteworthy for a PR review: There are a couple instances, where I changed minor things, including:
This has become quite the big PR at this point... sorry for that😋. Anyhow. Everything's ready for review. |
|
Great work! Before merging I need to make sure it doesn't collide with #100 |

PR Summary
Adds support for
--single-material-per-parta newGlobalBoundingsplit strategy (--split-strategy GlobalBounding)Single-material mode repacks each tile’s used diffuse and normal textures into a shared atlas, remaps UVs, and emits one material per part.
This is especially useful if the source mesh has UDIMs that are vastly scattered across the mesh.
The
GlobalBoundingsplit strategy creates a stable, source-derived square grid shared across LODs, with optional Z splitting based on the source bounds.Both options are non-breaking changes, as they only extend existing functionality by providing additional CLI args.
Related Issue: None
What I did so far
Remarks
The Atlas Merge does not take into account tint or opacity/alpha values from the .mtl.
In theory the other implementations could handle this better as materials are treated individually, but as far as I can tell the implementations mostly disregarded these too, which... assuming the kind of input we are working with... is fair.
GlobalBoundingSplitting also supportsz-splitting, but functionality for it might work counterintuitively.Inputs are usually way larger in width and height, then in depth. Using
--zsplitwould create a longestSide³ Volume, which would almost always encapsulate all parts of one mesh in height and not perform any splits onz.To provide meaning to
--zsplit, it usessourceBounds.Min.ZandsourceBounds.Max.Z, splitting across the entire height of the mesh.(I documented this in both the code and in the README)