From 07400f2065c3674b695237e7ada9ef6f64acc11c Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Mon, 10 Jul 2023 00:18:55 -0500 Subject: Add copyright to GLTFState --- modules/gltf/gltf_document.cpp | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'modules/gltf/gltf_document.cpp') diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 00bf3e58b0..b5cf485286 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -205,7 +205,7 @@ Error GLTFDocument::_serialize(Ref p_state, const String &p_path) { } /* STEP SERIALIZE VERSION */ - err = _serialize_version(p_state); + err = _serialize_asset_header(p_state); if (err != OK) { return Error::FAILED; } @@ -6984,20 +6984,8 @@ Error GLTFDocument::_parse(Ref p_state, String p_path, Refjson = json.get_data(); } - if (!p_state->json.has("asset")) { - return ERR_PARSE_ERROR; - } - - Dictionary asset = p_state->json["asset"]; - - if (!asset.has("version")) { - return ERR_PARSE_ERROR; - } - - String version = asset["version"]; - - p_state->major_version = version.get_slice(".", 0).to_int(); - p_state->minor_version = version.get_slice(".", 1).to_int(); + err = _parse_asset_header(p_state); + ERR_FAIL_COND_V(err != OK, err); document_extensions.clear(); for (Ref ext : all_document_extensions) { @@ -7054,13 +7042,15 @@ Dictionary GLTFDocument::_serialize_texture_transform_uv2(Ref p_ return _serialize_texture_transform_uv(Vector2(offset.x, offset.y), Vector2(scale.x, scale.y)); } -Error GLTFDocument::_serialize_version(Ref p_state) { +Error GLTFDocument::_serialize_asset_header(Ref p_state) { const String version = "2.0"; p_state->major_version = version.get_slice(".", 0).to_int(); p_state->minor_version = version.get_slice(".", 1).to_int(); Dictionary asset; asset["version"] = version; - + if (!p_state->copyright.is_empty()) { + asset["copyright"] = p_state->copyright; + } String hash = String(VERSION_HASH); asset["generator"] = String(VERSION_FULL_NAME) + String("@") + (hash.is_empty() ? String("unknown") : hash); p_state->json["asset"] = asset; @@ -7323,6 +7313,23 @@ Error GLTFDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_pa return OK; } +Error GLTFDocument::_parse_asset_header(Ref p_state) { + if (!p_state->json.has("asset")) { + return ERR_PARSE_ERROR; + } + Dictionary asset = p_state->json["asset"]; + if (!asset.has("version")) { + return ERR_PARSE_ERROR; + } + String version = asset["version"]; + p_state->major_version = version.get_slice(".", 0).to_int(); + p_state->minor_version = version.get_slice(".", 1).to_int(); + if (asset.has("copyright")) { + p_state->copyright = asset["copyright"]; + } + return OK; +} + Error GLTFDocument::_parse_gltf_state(Ref p_state, const String &p_search_path) { Error err; -- cgit v1.2.3