Skip to content

Commit

Permalink
Expose get_all_gltf_document_extensions and unregister_ APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
lyuma committed Dec 24, 2024
1 parent 0f95e9f commit 3dafec4
Show file tree
Hide file tree
Showing 3 changed files with 27 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
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 3dafec4

Please sign in to comment.