From d13d101397c11576a2e9d174befc6258f6c490f6 Mon Sep 17 00:00:00 2001 From: Lyuma Date: Tue, 24 Dec 2024 02:53:37 -0800 Subject: [PATCH] Expose get_registered_gltf_document_extensions --- modules/gltf/doc_classes/GLTFDocument.xml | 11 ++++++++++- .../GLTFDocumentExtensionConvertImporterMesh.xml | 4 ++++ modules/gltf/gltf_document.cpp | 9 +++++++++ modules/gltf/gltf_document.h | 1 + 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/gltf/doc_classes/GLTFDocument.xml b/modules/gltf/doc_classes/GLTFDocument.xml index 47ffc624bad9..3ba5b6bd5c2a 100644 --- a/modules/gltf/doc_classes/GLTFDocument.xml +++ b/modules/gltf/doc_classes/GLTFDocument.xml @@ -73,11 +73,18 @@ The [param bake_fps] parameter overrides the bake_fps in [param state]. + + + + Returns all registered [GLTFDocumentExtension] instances, including a default [GLTFDocumentExtensionConvertImporterMesh] instance at runtime. + [b]Note:[/b] This method is static: Registered instances will be shared by all [GLTFDocument] instances. Consider using this method to check if a given [GLTFDocumentExtension] is already registered. + + Returns a list of all support glTF extensions, including extensions supported directly by the engine, and extensions supported by user plugins registering [GLTFDocumentExtension] classes. - [b]Note:[/b] If this method is run before a GLTFDocumentExtension is registered, its extensions won't be included in the list. Be sure to only run this method after all extensions are registered. If you run this when the engine starts, consider waiting a frame before calling this method to ensure all extensions are registered. + [b]Note:[/b] This method is static: Registered instances will be shared by all [GLTFDocument] instances. Consider using this method to check if a given [GLTFDocumentExtension] is already registered. If this method is run before a GLTFDocumentExtension is registered, its extensions won't be included in the list. Be sure to only run this method after all extensions are registered. If you run this when the engine starts, consider waiting a frame before calling this method to ensure all extensions are registered. @@ -95,6 +102,7 @@ Registers the given [GLTFDocumentExtension] instance with GLTFDocument. If [param first_priority] is [code]true[/code], this extension will be run first. Otherwise, it will be run last. [b]Note:[/b] Like GLTFDocument itself, all GLTFDocumentExtension classes must be stateless in order to function properly. If you need to store data, use the [code]set_additional_data[/code] and [code]get_additional_data[/code] methods in [GLTFState] or [GLTFNode]. + [b]Note:[/b] This method is static: Registered instances will be shared by all [GLTFDocument] instances. Beware that multiple instances of a single [GLTFDocumentExtension] class can often lead to unexpected behavior, and consider using [method get_registered_gltf_document_extensions] or [method get_supported_gltf_extensions] to verify that only one instance of a given extension is registered. @@ -102,6 +110,7 @@ Unregisters the given [GLTFDocumentExtension] instance. + [b]Note:[/b] This method is static: Registering and unregistering instances will affect all [GLTFDocument] instances. diff --git a/modules/gltf/doc_classes/GLTFDocumentExtensionConvertImporterMesh.xml b/modules/gltf/doc_classes/GLTFDocumentExtensionConvertImporterMesh.xml index 04075caba5b8..0c30c3f428c3 100644 --- a/modules/gltf/doc_classes/GLTFDocumentExtensionConvertImporterMesh.xml +++ b/modules/gltf/doc_classes/GLTFDocumentExtensionConvertImporterMesh.xml @@ -1,8 +1,12 @@ + A default [GLTFDocumentExtension] to convert [ImporterMeshInstance3D] nodes to [MeshInstance3D]. + This [GLTFDocumentExtension] is installed by default at runtime, but not in the editor. It converts all [ImporterMeshInstance3D] nodes and related [ImporterMesh] resources to [MeshInstance3D] nodes with [ArrayMesh] resources. + + If it is important for a custom [GLTFDocumentExtension] to work with [ImporterMesh] at runtime, it is recommended to call [method GLTFDocument.register_gltf_document_extension] with the [code]true[/code] argument to prepend it to this default extension. $DOCS_URL/tutorials/io/runtime_file_loading_and_saving.html diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 6da56616b715..4d3011509b29 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -8152,6 +8152,7 @@ void GLTFDocument::_bind_methods() { &GLTFDocument::register_gltf_document_extension, DEFVAL(false)); ClassDB::bind_static_method("GLTFDocument", D_METHOD("unregister_gltf_document_extension", "extension"), &GLTFDocument::unregister_gltf_document_extension); + ClassDB::bind_static_method("GLTFDocument", D_METHOD("get_registered_gltf_document_extensions"), &GLTFDocument::get_registered_gltf_document_extensions); ClassDB::bind_static_method("GLTFDocument", D_METHOD("get_supported_gltf_extensions"), &GLTFDocument::get_supported_gltf_extensions); } @@ -8194,6 +8195,14 @@ Vector> GLTFDocument::get_all_gltf_document_extension return all_document_extensions; } +TypedArray GLTFDocument::get_registered_gltf_document_extensions() { + TypedArray ret; + for (Ref ext : all_document_extensions) { + ret.append(ext); + } + return ret; +} + Vector GLTFDocument::get_supported_gltf_extensions() { HashSet set = get_supported_gltf_extensions_hashset(); Vector vec; diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h index a6d6caa3f0a7..3821e0ccf300 100644 --- a/modules/gltf/gltf_document.h +++ b/modules/gltf/gltf_document.h @@ -85,6 +85,7 @@ class GLTFDocument : public Resource { static void unregister_gltf_document_extension(Ref p_extension); static void unregister_all_gltf_document_extensions(); static Vector> get_all_gltf_document_extensions(); + static TypedArray get_registered_gltf_document_extensions(); static Vector get_supported_gltf_extensions(); static HashSet get_supported_gltf_extensions_hashset();