@@ -7060,6 +7060,8 @@ void GLTFDocument::_bind_methods() {
70607060 &GLTFDocument::register_gltf_document_extension, DEFVAL (false ));
70617061 ClassDB::bind_static_method (" GLTFDocument" , D_METHOD (" unregister_gltf_document_extension" , " extension" ),
70627062 &GLTFDocument::unregister_gltf_document_extension);
7063+ ClassDB::bind_static_method (" GLTFDocument" , D_METHOD (" get_supported_gltf_extensions" ),
7064+ &GLTFDocument::get_supported_gltf_extensions);
70637065}
70647066
70657067void GLTFDocument::_build_parent_hierachy (Ref<GLTFState> p_state) {
@@ -7100,6 +7102,36 @@ Vector<Ref<GLTFDocumentExtension>> GLTFDocument::get_all_gltf_document_extension
71007102 return all_document_extensions;
71017103}
71027104
7105+ Vector<String> GLTFDocument::get_supported_gltf_extensions () {
7106+ HashSet<String> set = get_supported_gltf_extensions_hashset ();
7107+ Vector<String> vec;
7108+ for (const String &s : set) {
7109+ vec.append (s);
7110+ }
7111+ vec.sort ();
7112+ return vec;
7113+ }
7114+
7115+ HashSet<String> GLTFDocument::get_supported_gltf_extensions_hashset () {
7116+ HashSet<String> supported_extensions;
7117+ // If the extension is supported directly in GLTFDocument, list it here.
7118+ // Other built-in extensions are supported by GLTFDocumentExtension classes.
7119+ supported_extensions.insert (" GODOT_single_root" );
7120+ supported_extensions.insert (" KHR_lights_punctual" );
7121+ supported_extensions.insert (" KHR_materials_emissive_strength" );
7122+ supported_extensions.insert (" KHR_materials_pbrSpecularGlossiness" );
7123+ supported_extensions.insert (" KHR_materials_unlit" );
7124+ supported_extensions.insert (" KHR_texture_transform" );
7125+ for (Ref<GLTFDocumentExtension> ext : all_document_extensions) {
7126+ ERR_CONTINUE (ext.is_null ());
7127+ Vector<String> ext_supported_extensions = ext->get_supported_extensions ();
7128+ for (int i = 0 ; i < ext_supported_extensions.size (); ++i) {
7129+ supported_extensions.insert (ext_supported_extensions[i]);
7130+ }
7131+ }
7132+ return supported_extensions;
7133+ }
7134+
71037135PackedByteArray GLTFDocument::_serialize_glb_buffer (Ref<GLTFState> p_state, Error *r_err) {
71047136 Error err = _encode_buffer_glb (p_state, " " );
71057137 if (r_err) {
@@ -7452,19 +7484,7 @@ Error GLTFDocument::_parse_gltf_extensions(Ref<GLTFState> p_state) {
74527484 Vector<String> ext_array = p_state->json [" extensionsRequired" ];
74537485 p_state->extensions_required = ext_array;
74547486 }
7455- HashSet<String> supported_extensions;
7456- supported_extensions.insert (" KHR_lights_punctual" );
7457- supported_extensions.insert (" KHR_materials_pbrSpecularGlossiness" );
7458- supported_extensions.insert (" KHR_texture_transform" );
7459- supported_extensions.insert (" KHR_materials_unlit" );
7460- supported_extensions.insert (" KHR_materials_emissive_strength" );
7461- for (Ref<GLTFDocumentExtension> ext : document_extensions) {
7462- ERR_CONTINUE (ext.is_null ());
7463- Vector<String> ext_supported_extensions = ext->get_supported_extensions ();
7464- for (int i = 0 ; i < ext_supported_extensions.size (); ++i) {
7465- supported_extensions.insert (ext_supported_extensions[i]);
7466- }
7467- }
7487+ HashSet<String> supported_extensions = get_supported_gltf_extensions_hashset ();
74687488 Error ret = OK;
74697489 for (int i = 0 ; i < p_state->extensions_required .size (); i++) {
74707490 if (!supported_extensions.has (p_state->extensions_required [i])) {
0 commit comments