Skip to content

Commit faa3688

Browse files
committed
Merge pull request godotengine#96251 from aaronfranke/gltf-get-supported-ext
Add `get_supported_gltf_extensions` to GLTFDocument
2 parents ba0b93c + ee5e977 commit faa3688

File tree

4 files changed

+43
-13
lines changed

4 files changed

+43
-13
lines changed

modules/gdscript/gdscript_parser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ void GDScriptParser::override_completion_context(const Node *p_for_node, Complet
260260
context.current_line = tokenizer->get_cursor_line();
261261
context.current_argument = p_argument;
262262
context.node = p_node;
263+
context.parser = this;
263264
completion_context = context;
264265
}
265266

modules/gltf/doc_classes/GLTFDocument.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@
6363
The [param bake_fps] parameter overrides the bake_fps in [param state].
6464
</description>
6565
</method>
66+
<method name="get_supported_gltf_extensions" qualifiers="static">
67+
<return type="PackedStringArray" />
68+
<description>
69+
Returns a list of all support glTF extensions, including extensions supported directly by the engine, and extensions supported by user plugins registering [GLTFDocumentExtension] classes.
70+
[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.
71+
</description>
72+
</method>
6673
<method name="register_gltf_document_extension" qualifiers="static">
6774
<return type="void" />
6875
<param index="0" name="extension" type="GLTFDocumentExtension" />

modules/gltf/gltf_document.cpp

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

70657067
void 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+
71037135
PackedByteArray 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])) {

modules/gltf/gltf_document.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class GLTFDocument : public Resource {
9292
static void unregister_gltf_document_extension(Ref<GLTFDocumentExtension> p_extension);
9393
static void unregister_all_gltf_document_extensions();
9494
static Vector<Ref<GLTFDocumentExtension>> get_all_gltf_document_extensions();
95+
static Vector<String> get_supported_gltf_extensions();
96+
static HashSet<String> get_supported_gltf_extensions_hashset();
9597

9698
void set_naming_version(int p_version);
9799
int get_naming_version() const;

0 commit comments

Comments
 (0)