X Tutup
Skip to content

Allow converting from Mesh to ImporterMesh#113202

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
aaronfranke:importer-mesh-convert
Dec 2, 2025
Merged

Allow converting from Mesh to ImporterMesh#113202
Repiteo merged 1 commit intogodotengine:masterfrom
aaronfranke:importer-mesh-convert

Conversation

@aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Nov 26, 2025

ImporterMesh is designed primarily for use during the import process, as the name implies. However, the GLTF module needs to do the reverse as well, when exporting a glTF file from Godot.

In master, GLTFDocument contained duplicate code for converting ImporterMesh to Mesh. I could just deduplicate this within GLTFDocument, but in the near future, I will need to reference this function outside of GLTFDocument (specifically, GLTFDocumentExtensionMultiMesh in PR #112866). This PR moves this functionality to ImporterMesh, and exposes it.

This PR also fixes a minor bug where the material name was used as the surface name, taking priority over the... actual surface name. To make this clearer, I also renamed the ImporterMesh::add_surface parameter p_name to p_surface_name to explicitly indicate that this should be the surface name and not the material name.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me.

It may be worth adding unit tests for this in the future. I noticed we don't have test_mesh.h or test_importer_mesh.h yet though, only test_arraymesh.h and test_triangle_mesh.h.

@lyuma
Copy link
Contributor

lyuma commented Nov 27, 2025

A round trip test could be ideal, making sure all of the properties are present after converting to and from ImporterMesh.

@aaronfranke
Copy link
Member Author

aaronfranke commented Nov 28, 2025

I attempted to start to write a minimal test:

TEST_CASE("[ImporterMesh] Round-trip from BoxMesh to ImporterMesh to ArrayMesh") {
	Ref<BoxMesh> box_mesh;
	box_mesh.instantiate();
	//Ref<ImporterMesh> importer_mesh = ImporterMesh::from_mesh(box_mesh);
}

But it fails to construct the BoxMesh on this check: ERR_FAIL_NULL(RenderingServer::get_singleton()); and if I uncomment that ImporterMesh line then Godot crashes. So I'm not sure how to add a test for meshes if these classes depend on RenderingServer which isn't available in the testing environment. Either way, I don't think it should block this PR.

Copy link
Contributor

@lyuma lyuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

I would assume that the unit tests would use a dummy driver for the RenderingServer, and also that the dummy driver would support primitive mesh types... but I don't know enough about the testing infrastructure to understand why this would fail nor how to fix it. So my suggestion is to merge this without adding the round trip test.

@akien-mga akien-mga modified the milestones: 4.x, 4.6 Dec 1, 2025
@Repiteo Repiteo merged commit 1577061 into godotengine:master Dec 2, 2025
20 checks passed
@github-project-automation github-project-automation bot moved this from Ready for review to Done in Asset Pipeline Issue Triage Dec 2, 2025
@Repiteo
Copy link
Contributor

Repiteo commented Dec 2, 2025

Thanks!

@aaronfranke aaronfranke deleted the importer-mesh-convert branch December 2, 2025 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

7 participants

X Tutup