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

Import custom attributes with GLTFDocumentExtension #97756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

huwpascoe
Copy link
Contributor

@huwpascoe huwpascoe commented Oct 3, 2024

Proposal

Import ARRAY_CUSTOM# attributes with GLTFDocumentExtension using a function to specify layer name. Also added "Export Attributes" checkbox to the blender importer.
godotengine/godot-proposals#10892

Test Project

image
custom_attrib_test.zip

changes

  • Swapped the function around, accepts Mesh.ArrayType, returns a string. (empty string for default behavior)
  • Added the GLTFState and current mesh index to the function
extends GLTFDocumentExtension

func _get_attribute_for_mesh_array(state: GLTFState, mesh_index: int, mesh_array: Mesh.ArrayType) -> String:
	var mesh_name: String = state.json["meshes"][mesh_index]["name"]

	if mesh_array == Mesh.ARRAY_COLOR:
		match mesh_name:
			"mesh_1": return "COLOR_1"
			"mesh_2": return "_MY_DATA"

	if mesh_name == "custom":
		match mesh_array:
			Mesh.ARRAY_TEX_UV: return "TEXCOORD_1"
			Mesh.ARRAY_CUSTOM0: return "_ROCK"
			Mesh.ARRAY_CUSTOM1: return "_MUD"
			Mesh.ARRAY_CUSTOM2: return "_GRASS"
			Mesh.ARRAY_CUSTOM3: return "_SNOW"

	return ""

Supported attributes

  • Mesh.ARRAY_TEX_UV (vec2)
  • Mesh.ARRAY_TEX_UV2 (vec2)
  • Mesh.ARRAY_COLOR (vec3, vec4)
  • Mesh.ARRAY_CUSTOM# (scalar, vec2, vec3, vec4)

@fire
Copy link
Member

fire commented Oct 3, 2024

I'm having a hard time understanding the extension. Can you link or write a proposal in https://github.com/godotengine/godot-proposals?

Something like: I have a game workflow that uses blender I want the vertex attributes to import from blender, but it needs this pr. I can use the attributes for a shader effect.

@huwpascoe
Copy link
Contributor Author

godotengine/godot-proposals#10892

@huwpascoe
Copy link
Contributor Author

Refactored and removed like a hundred duplicate lines of code.

_decode_accessor_as_floats();
_decode_accessor_as_ints();
_decode_accessor_as_vec2();
_decode_accessor_as_vec3();
_decode_accessor_as_color();
_decode_accessor_as_quaternion();
_decode_accessor_as_xform2d();
_decode_accessor_as_basis();
_decode_accessor_as_xform();

// VVV

_decode_accessor<T>();

Multi-element scalars are now decoded with _decode_accessor<T, N>()

array[Mesh::ARRAY_TANGENT] = _decode_accessor<float, 4>(p_state, a["TANGENT"], true, indices_mapping);

@aaronfranke
Copy link
Member

Since this PR alters the accessor code, it will have to wait until after #94165 which also touches this code.

@Flynsarmy
Copy link
Contributor

Since this PR alters the accessor code, it will have to wait until after #94165 which also touches this code.

PR in question was just merged so we should be good to continue here.

@fire
Copy link
Member

fire commented Nov 6, 2024

@huwpascoe Many people think this is a good enhancement. Would you happen to have time to rebase it? <3

@huwpascoe
Copy link
Contributor Author

huwpascoe commented Nov 7, 2024

@fire

Would it be better to keep as an extension or promote it to import options?
https://github.com/user-attachments/assets/52dc1357-7b32-49c2-a2ce-216343f69d60

There are trade-offs for each.

@fire
Copy link
Member

fire commented Nov 7, 2024

I am trending towards promoting it to import options

@Flynsarmy
Copy link
Contributor

Remember to take this PR out of draft if it's ready :)

@huwpascoe
Copy link
Contributor Author

Remember to take this PR out of draft if it's ready :)

Don't worry! I haven't forgotten.

I am trending towards promoting it to import options

Right, I've determined that the UI approach is just too much of a mess for what is a technical feature. So I'll be moving forward with the original plan to add the method to DocumentExtension.

@huwpascoe huwpascoe force-pushed the custom_attrib branch 2 times, most recently from fd4dff7 to 4db4bdb Compare December 15, 2024 05:59
@huwpascoe huwpascoe marked this pull request as ready for review December 15, 2024 06:46
@huwpascoe huwpascoe requested review from a team as code owners December 15, 2024 06:46
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.

5 participants