Make used extensions stored in GLTFState
This allows GLTFDocumentExtension classes to add to the used extensions array.
This commit is contained in:
parent
ca1ebf9fee
commit
b72dc0de89
5 changed files with 42 additions and 11 deletions
|
@ -7,6 +7,14 @@
|
|||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="add_used_extension">
|
||||
<return type="void" />
|
||||
<param index="0" name="extension_name" type="String" />
|
||||
<param index="1" name="required" type="bool" />
|
||||
<description>
|
||||
Appends an extension to the list of extensions used by this GLTF file during serialization. If [param required] is true, the extension will also be added to the list of required extensions. Do not run this in [method GLTFDocumentExtension._export_post], as that stage is too late to add extensions. The final list is sorted alphabetically.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_accessors">
|
||||
<return type="GLTFAccessor[]" />
|
||||
<description>
|
||||
|
|
|
@ -198,7 +198,7 @@ Error GLTFDocument::_serialize(Ref<GLTFState> state, const String &p_path) {
|
|||
}
|
||||
|
||||
/* STEP SERIALIZE EXTENSIONS */
|
||||
err = _serialize_extensions(state);
|
||||
err = _serialize_gltf_extensions(state);
|
||||
if (err != OK) {
|
||||
return Error::FAILED;
|
||||
}
|
||||
|
@ -219,9 +219,9 @@ Error GLTFDocument::_serialize(Ref<GLTFState> state, const String &p_path) {
|
|||
return OK;
|
||||
}
|
||||
|
||||
Error GLTFDocument::_serialize_extensions(Ref<GLTFState> state) const {
|
||||
Array extensions_used;
|
||||
Array extensions_required;
|
||||
Error GLTFDocument::_serialize_gltf_extensions(Ref<GLTFState> state) const {
|
||||
Vector<String> extensions_used = state->extensions_used;
|
||||
Vector<String> extensions_required = state->extensions_required;
|
||||
if (!state->lights.is_empty()) {
|
||||
extensions_used.push_back("KHR_lights_punctual");
|
||||
}
|
||||
|
@ -230,9 +230,11 @@ Error GLTFDocument::_serialize_extensions(Ref<GLTFState> state) const {
|
|||
extensions_required.push_back("KHR_texture_transform");
|
||||
}
|
||||
if (!extensions_used.is_empty()) {
|
||||
extensions_used.sort();
|
||||
state->json["extensionsUsed"] = extensions_used;
|
||||
}
|
||||
if (!extensions_required.is_empty()) {
|
||||
extensions_required.sort();
|
||||
state->json["extensionsRequired"] = extensions_required;
|
||||
}
|
||||
return OK;
|
||||
|
@ -6917,12 +6919,17 @@ Error GLTFDocument::append_from_file(String p_path, Ref<GLTFState> r_state, uint
|
|||
|
||||
Error GLTFDocument::_parse_gltf_extensions(Ref<GLTFState> state) {
|
||||
ERR_FAIL_NULL_V(state, ERR_PARSE_ERROR);
|
||||
if (state->json.has("extensionsRequired") && state->json["extensionsRequired"].get_type() == Variant::ARRAY) {
|
||||
Array extensions_required = state->json["extensionsRequired"];
|
||||
if (extensions_required.find("KHR_draco_mesh_compression") != -1) {
|
||||
ERR_PRINT("glTF2 extension KHR_draco_mesh_compression is not supported.");
|
||||
return ERR_UNAVAILABLE;
|
||||
}
|
||||
if (state->json.has("extensionsUsed")) {
|
||||
Vector<String> ext_array = state->json["extensionsUsed"];
|
||||
state->extensions_used = ext_array;
|
||||
}
|
||||
if (state->json.has("extensionsRequired")) {
|
||||
Vector<String> ext_array = state->json["extensionsRequired"];
|
||||
state->extensions_required = ext_array;
|
||||
}
|
||||
if (state->extensions_required.find("KHR_draco_mesh_compression") != -1) {
|
||||
ERR_PRINT("glTF2 extension KHR_draco_mesh_compression is not supported.");
|
||||
return ERR_UNAVAILABLE;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
|
|
@ -265,7 +265,7 @@ private:
|
|||
Dictionary _serialize_texture_transform_uv2(Ref<BaseMaterial3D> p_material);
|
||||
Error _serialize_version(Ref<GLTFState> state);
|
||||
Error _serialize_file(Ref<GLTFState> state, const String p_path);
|
||||
Error _serialize_extensions(Ref<GLTFState> state) const;
|
||||
Error _serialize_gltf_extensions(Ref<GLTFState> state) const;
|
||||
|
||||
public:
|
||||
// https://www.itu.int/rec/R-REC-BT.601
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "gltf_state.h"
|
||||
|
||||
void GLTFState::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("add_used_extension", "extension_name", "required"), &GLTFState::add_used_extension);
|
||||
ClassDB::bind_method(D_METHOD("get_json"), &GLTFState::get_json);
|
||||
ClassDB::bind_method(D_METHOD("set_json", "json"), &GLTFState::set_json);
|
||||
ClassDB::bind_method(D_METHOD("get_major_version"), &GLTFState::get_major_version);
|
||||
|
@ -112,6 +113,17 @@ void GLTFState::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "animations", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_animations", "get_animations"); // Vector<Ref<GLTFAnimation>>
|
||||
}
|
||||
|
||||
void GLTFState::add_used_extension(const String &p_extension_name, bool p_required) {
|
||||
if (!extensions_used.has(p_extension_name)) {
|
||||
extensions_used.push_back(p_extension_name);
|
||||
}
|
||||
if (p_required) {
|
||||
if (!extensions_required.has(p_extension_name)) {
|
||||
extensions_required.push_back(p_extension_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary GLTFState::get_json() {
|
||||
return json;
|
||||
}
|
||||
|
|
|
@ -78,6 +78,8 @@ class GLTFState : public Resource {
|
|||
Vector<int> root_nodes;
|
||||
Vector<Ref<GLTFTexture>> textures;
|
||||
Vector<Ref<Texture2D>> images;
|
||||
Vector<String> extensions_used;
|
||||
Vector<String> extensions_required;
|
||||
|
||||
Vector<Ref<GLTFSkin>> skins;
|
||||
Vector<Ref<GLTFCamera>> cameras;
|
||||
|
@ -97,6 +99,8 @@ protected:
|
|||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void add_used_extension(const String &p_extension, bool p_required = false);
|
||||
|
||||
Dictionary get_json();
|
||||
void set_json(Dictionary p_json);
|
||||
|
||||
|
|
Loading…
Reference in a new issue