Skip to content

Commit

Permalink
Expose unregister_all_ and get_all_gltf_document_extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
lyuma committed Dec 24, 2024
1 parent 0f95e9f commit c905e9b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions modules/gltf/doc_classes/GLTFDocument.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,29 @@
<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_all_gltf_document_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="get_all_gltf_document_extensions" qualifiers="static">
<return type="Array[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="unregister_all_gltf_document_extensions" qualifiers="static">
<return type="void" />
<description>
Unregisters all [GLTFDocumentExtension] instances, including the default [GLTFDocumentExtensionConvertImporterMesh] instance at runtime.
[b]Note:[/b] This method is static: 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
10 changes: 10 additions & 0 deletions modules/gltf/gltf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8152,6 +8152,8 @@ 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("unregister_all_gltf_document_extensions"), &GLTFDocument::unregister_all_gltf_document_extensions);
ClassDB::bind_static_method("GLTFDocument", D_METHOD("get_all_gltf_document_extensions"), &GLTFDocument::_get_all_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 +8196,14 @@ Vector<Ref<GLTFDocumentExtension>> GLTFDocument::get_all_gltf_document_extension
return all_document_extensions;
}

TypedArray<Ref<GLTFDocumentExtension>> GLTFDocument::_get_all_gltf_document_extensions() {
TypedArray<Ref<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<Ref<GLTFDocumentExtension>> _get_all_gltf_document_extensions();
static Vector<String> get_supported_gltf_extensions();
static HashSet<String> get_supported_gltf_extensions_hashset();

Expand Down

0 comments on commit c905e9b

Please sign in to comment.