Skip to content

Commit

Permalink
Expose get_registered_gltf_document_extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
lyuma committed Dec 25, 2024
1 parent 0f95e9f commit d13d101
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion modules/gltf/doc_classes/GLTFDocument.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,18 @@
The [param bake_fps] parameter overrides the bake_fps in [param state].
</description>
</method>
<method name="get_registered_gltf_document_extensions" qualifiers="static">
<return type="GLTFDocumentExtension[]" />
<description>
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.
</description>
</method>
<method name="get_supported_gltf_extensions" qualifiers="static">
<return type="PackedStringArray" />
<description>
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.
</description>
</method>
<method name="import_object_model_property" qualifiers="static">
Expand All @@ -95,13 +102,15 @@
<description>
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.
</description>
</method>
<method name="unregister_gltf_document_extension" qualifiers="static">
<return type="void" />
<param index="0" name="extension" type="GLTFDocumentExtension" />
<description>
Unregisters the given [GLTFDocumentExtension] instance.
[b]Note:[/b] This method is static: Registering and unregistering instances will affect all [GLTFDocument] instances.
</description>
</method>
<method name="write_to_filesystem">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="GLTFDocumentExtensionConvertImporterMesh" inherits="GLTFDocumentExtension" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A default [GLTFDocumentExtension] to convert [ImporterMeshInstance3D] nodes to [MeshInstance3D].
</brief_description>
<description>
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.
</description>
<tutorials>
<link title="Runtime file loading and saving">$DOCS_URL/tutorials/io/runtime_file_loading_and_saving.html</link>
Expand Down
9 changes: 9 additions & 0 deletions modules/gltf/gltf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -8194,6 +8195,14 @@ Vector<Ref<GLTFDocumentExtension>> GLTFDocument::get_all_gltf_document_extension
return all_document_extensions;
}

TypedArray<GLTFDocumentExtension> GLTFDocument::get_registered_gltf_document_extensions() {
TypedArray<GLTFDocumentExtension> ret;
for (Ref<GLTFDocumentExtension> ext : all_document_extensions) {
ret.append(ext);
}
return ret;
}

Vector<String> GLTFDocument::get_supported_gltf_extensions() {
HashSet<String> set = get_supported_gltf_extensions_hashset();
Vector<String> vec;
Expand Down
1 change: 1 addition & 0 deletions modules/gltf/gltf_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class GLTFDocument : public Resource {
static void unregister_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension);
static void unregister_all_gltf_document_extensions();
static Vector<Ref<GLTFDocumentExtension>> get_all_gltf_document_extensions();
static TypedArray<GLTFDocumentExtension> get_registered_gltf_document_extensions();
static Vector<String> get_supported_gltf_extensions();
static HashSet<String> get_supported_gltf_extensions_hashset();

Expand Down

0 comments on commit d13d101

Please sign in to comment.