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

Support for UVs as Vector3+Vector4 requested #720

Open
JaXt0r opened this issue Sep 27, 2024 · 1 comment
Open

Support for UVs as Vector3+Vector4 requested #720

JaXt0r opened this issue Sep 27, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@JaXt0r
Copy link

JaXt0r commented Sep 27, 2024

Is your feature request related to a problem? Please describe.
Our project leverages Export and Import of glTF files at runtime. To enhance our performance, we already implemented usage of Unity Texture Arrays and MipMaps. It means our texture coordinates (UVs) are of type Vector4 (x, y, textureArrayIndex, mipMapLevel). When we store a mesh, it saves Vector2 for UVs only and the textureArrayIndex+mipMapLevel information get removed.

Out-of-scope:
The feature request asks for Vector4 on UVs only. Texture Array support for Materials isn't needed as we retrieve the Arrays manually after Mesh restore from glTF.

Describe the solution you'd like
It would be great if glTFast can support UVs as Vector2, Vector3, and Vector4. It would be fine, if you add a parameter which tells the Exporter/Importer which version to use.

Example usage we could think of:

// Exporting
var exportSettings = new ExportSettings
{
   TextureCoordinateType = typeof(Vector4) // Defaults to typeof(Vector2) for backwards compatibility
   ...
 };
var export = new GameObjectExport(exportSettings);
export.AddScene(...);
...
export.SaveToFileAndDispose();

// Importing
// No parameter for UV=Vector4 needed, if this information is stored inside gltf file itself.
// Otherwise we could leverage an ImportSettings property.
var import = new GltfImport();

Describe alternatives you've considered
If glTF isn't providing a native solution, we need to store additional metadata in a JSON (etc.) file. After the meshes are loaded, we need to fetch all vertices and merge the missing two vector data points for all UV elements.
Doable, but not preferred as:

  1. We need to store additional metadata (additional file handling for mesh based data)
  2. We need to loop through all the UVs (additional CPU cycles to iterate through the data again)
  3. Unity doesn't allow updating UVs, but only to set them altogether. Which means we need to create a new UV array and store it in one chunk at the end of the loop (More RAM usage during execution)

Additional context

Unity's UV getter: for various Vector* implementations:

Test images from our project:

  • 1: Before saving glT file
    Before saving

  • 2: After loading the glT file
    After loading

@JaXt0r JaXt0r added the enhancement New feature or request label Sep 27, 2024
@JaXt0r JaXt0r changed the title Support for UVs as Vector4 requestesd Support for UVs as Vector4 requested Sep 27, 2024
@JaXt0r JaXt0r changed the title Support for UVs as Vector4 requested Support for UVs as Vector3+Vector4 requested Sep 27, 2024
@atteneder
Copy link
Owner

Hi @JaXt0r ,

I investigated that a Vector4 texture coordinate is not covered by the glTF 2.0 specification.

I manually crafted such a file and the validation failed with the following error:

Invalid accessor format '{VEC4, FLOAT}' for this attribute semantic. Must be one of ('{VEC2, FLOAT}', '{VEC2, UNSIGNED_BYTE normalized}', '{VEC2, UNSIGNED_SHORT normalized}').glTF Validator(MESH_PRIMITIVE_ATTRIBUTES_ACCESSOR_INVALID_FORMAT)

That being said, that does not prevent anyone from implementing support for VEC4 UVs and optionally crafting a custom extension around it.

I don't think that would be too hard to implement, but given that this is a very narrow use-case I won't put a high priority on it.

However, I can offer guidance if you decide to beat me to it when it comes to implementation.

As a starting point, could you provide a mesh that has 4 dimensional UVs? Frankly I lack the knowledge/tools to do it quickly.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants