mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-16 02:55:55 +08:00
Merge pull request #310 from syoyo/write-assert-version
`asset.version` is a required field
This commit is contained in:
commit
298c37a954
@ -432,7 +432,6 @@ TEST_CASE("serialize-empty-material", "[issue-294]") {
|
|||||||
nlohmann::json j = nlohmann::json::parse(os.str());
|
nlohmann::json j = nlohmann::json::parse(os.str());
|
||||||
|
|
||||||
REQUIRE(1 == j["materials"].size());
|
REQUIRE(1 == j["materials"].size());
|
||||||
REQUIRE(j["asset"].is_null());
|
|
||||||
REQUIRE(j["materials"][0].is_object());
|
REQUIRE(j["materials"][0].is_object());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
13
tiny_gltf.h
13
tiny_gltf.h
@ -4,7 +4,7 @@
|
|||||||
//
|
//
|
||||||
// The MIT License (MIT)
|
// The MIT License (MIT)
|
||||||
//
|
//
|
||||||
// Copyright (c) 2015 - 2020 Syoyo Fujita, Aurélien Chatelain and many
|
// Copyright (c) 2015 - Present Syoyo Fujita, Aurélien Chatelain and many
|
||||||
// contributors.
|
// contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@ -1071,7 +1071,7 @@ struct Buffer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Asset {
|
struct Asset {
|
||||||
std::string version; // required
|
std::string version = "2.0"; // required
|
||||||
std::string generator;
|
std::string generator;
|
||||||
std::string minVersion;
|
std::string minVersion;
|
||||||
std::string copyright;
|
std::string copyright;
|
||||||
@ -6760,10 +6760,15 @@ static void SerializeGltfAsset(Asset &asset, json &o) {
|
|||||||
SerializeStringProperty("copyright", asset.copyright, o);
|
SerializeStringProperty("copyright", asset.copyright, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!asset.version.empty()) {
|
if (asset.version.empty()) {
|
||||||
SerializeStringProperty("version", asset.version, o);
|
// Just in case
|
||||||
|
// `version` must be defined
|
||||||
|
asset.version = "2.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(syoyo): Do we need to check if `version` is greater or equal to 2.0?
|
||||||
|
SerializeStringProperty("version", asset.version, o);
|
||||||
|
|
||||||
if (asset.extras.Keys().size()) {
|
if (asset.extras.Keys().size()) {
|
||||||
SerializeValue("extras", asset.extras, o);
|
SerializeValue("extras", asset.extras, o);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user