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

Add support for importing custom glTF attributes #10892

Open
huwpascoe opened this issue Oct 4, 2024 · 2 comments
Open

Add support for importing custom glTF attributes #10892

huwpascoe opened this issue Oct 4, 2024 · 2 comments

Comments

@huwpascoe
Copy link

huwpascoe commented Oct 4, 2024

Describe the project you are working on

This can apply to any project.

Describe the problem or limitation you are having in your project

There is not any way to import custom attributes from .gltf or .blend files. These are invaluable for use in shaders.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

GLTF supports Application Specific Attributes.

Application-specific attribute semantics MUST start with an underscore, e.g., _TEMPERATURE. Application-specific attribute semantics MUST NOT use unsigned int component type.

Name Accessor Type(s)
POSITION VEC3
NORMAL VEC3
TANGENT VEC4
TEXCOORD_n VEC2
COLOR_n VEC3
VEC4
JOINTS_n VEC4
WEIGHTS_n VEC4
_MY_CUSTOM_ATTRIB SCALAR
VEC2
VEC3
VEC4

These attributes can be exported by 3D modelling software where supported.
Blender, when "export attributes" is enabled, will export any attributes that begin with an underscore.
Names will be converted to upper-case to conform with the spec.

image

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Add a virtual method to GLTFDocumentExtension that can map these application-specific attributes to Mesh.ARRAY_CUSTOM#

extends GLTFDocumentExtension

func _remap_custom_attribute(p_name: String) -> int:
	if p_name == "_LAYERS": return Mesh.ARRAY_CUSTOM0
	if p_name == "_BLEND": return Mesh.ARRAY_CUSTOM1
	return -1

Potentially other attributes could also be remapped. Currently, only COLOR_0 is supported, for example:

if p_name == "COLOR_1": return Mesh.ARRAY_CUSTOM3

Blender will need to enable "export_attributes" when exporting to GTLF. This would require an extra checkbox, but alternatively be enabled by default as only attributes with underscores are exported, and unless the GLTFDocumentExtension method is implemented, would be ignored.

Because other attributes such as extra UV data may also be mapped to ARRAY_CUSTOM#, the importer should reject any ARRAY_CUSTOM# that already has data assigned and print a warning.

If this enhancement will not be used often, can it be worked around with a few lines of script?

It can't be realistically achieved with GLTFDocumentExtension without going to great lengths to re-implement much of the importer logic in GDScript.

Is there a reason why this should be core and not an add-on in the asset library?

GLTFDocumentExtension does not currently have the necessary hooks.

@Calinou Calinou changed the title Custom GLTF Attributes Add support for importing custom glTF attributes Oct 4, 2024
@Flynsarmy
Copy link

Since godotengine/godot#97756 (comment) was asking for use cases, I'll tack mine on.

I have various hair meshes in Blender and I'd like to use color vertex attributes to create an automated workflow that will determine which vertices are pinned and unpinned on a SoftBody3D in Godot using the meshes.

Example workflow:

Here in Blender I have a PinColor attribute. I painted black where I want the mesh pinned, white for unpinned.
image

On the Godot end, I will write an import script for my hair mesh that

  • Creates a SoftBody scene and adds the mesh
  • Loops through the vertices, grabs my PinColor attribute for that vert and sets the SoftBody pin for that vert accordingly
    image

The end result is that I can simply export my GLB file of hair meshes from Blender, and Godot will automatically create SoftBody scenes for them with correct configuration of pinned/unpinned verts.

@donn-xx
Copy link

donn-xx commented Mar 21, 2025

Another use-case: An attribute to hold a transform per instance in a scattered mesh system (in Blender) so that, in Godot, one can go through the mesh and with some work create a multimesh instead.

So, in Blender, I'd place store a name "_XFORM" on each instance of the repeated mesh, with the transform matrix as data. In Godot, in some import plugin, go through the surfaces in that mesh and seek that attribute etc.

Right now that is, or seems to be, impossible.

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

No branches or pull requests

5 participants