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

Integer Attribute Exported As Float #2447

Open
grimace87 opened this issue Dec 19, 2024 · 2 comments
Open

Integer Attribute Exported As Float #2447

grimace87 opened this issue Dec 19, 2024 · 2 comments

Comments

@grimace87
Copy link

Describe the bug

A custom attribute with Data Type of Integer or 8-Bit Integer exports with componentType of 5126, i.e. 32-bit floating point.

To Reproduce

  1. Open Blender and start with the default new project
  2. Go to the Data tab in the Properties window
  3. Expand Attributes and click the '+'
  4. Enter _CUSTOM_INT for the name, leave the domain as Vertex, and change Data Type to Integer (or 8-Bit Integer), then click Add
  5. Go to File -> Export -> glTF 2.0
  6. Change the Format to glTF Separate
  7. Expand Data -> Mesh and check Attributes
  8. Click Export glTF 2.0
  9. Open the exported file in a text editor and note the Cube mesh under "meshes" has the exported attribute pointing to accessor 0
  10. Note accessor 0 has componentType 5126, indicating 32-bit floating point rather than expected integer type

Expected behavior

Accessor componentType is an integer type rather than floating point

Screenshots

blender-data-panel

.blend file/ .gltf (mandatory)

gltf-attribute.zip

Version

  • OS: Linux (Ubuntu)
  • Blender Version 4.3.1

Additional context

As per glTF 2.0 specification signed 32-bit integers are not supported, so a perfect mapping between Blender types and glTF types is not possible for Integer. This case is subjective as to what the exported type should be.

However for 8-Bit Integers this is unexpected, as glTF should export with type 5120 (signed byte).

@scurest
Copy link
Contributor

scurest commented Dec 19, 2024

Note that glTF attributes must be aligned to four byte boundaries, so an int8 attribute would need to be packed as {byte value; byte padding[3];} and have the appropriate byteStride set.

@grimace87
Copy link
Author

Note that glTF attributes must be aligned to four byte boundaries, so an int8 attribute would need to be packed as {byte value; byte padding[3];} and have the appropriate byteStride set.

Wasn't aware of this, thanks for the info. Found it in the spec here: "each element of a vertex attribute MUST be aligned to 4-byte boundaries."

The fallback mechanism to export integers as floats does seem justified, but I'd say doesn't follow the Principle of Least Astonishment (i.e. it is potentially surprising). If would be great if it were documented in the Blender manual.

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

No branches or pull requests

2 participants