mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-14 00:05:52 +08:00
Merge pull request #322 from syoyo/fix-negative-skeleton-id
Do not serialize skeleton id -1
This commit is contained in:
commit
bc753d4ac5
267
models/regression/unassigned-skeleton.gltf
Normal file
267
models/regression/unassigned-skeleton.gltf
Normal file
File diff suppressed because one or more lines are too long
@ -436,6 +436,36 @@ TEST_CASE("serialize-empty-material", "[issue-294]") {
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("empty-skeleton-id", "[issue-321]") {
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
bool ret = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/regression/unassigned-skeleton.gltf");
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
REQUIRE(true == ret);
|
||||
|
||||
REQUIRE(model.skins.size() == 1);
|
||||
REQUIRE(model.skins[0].skeleton == -1); // unassigned
|
||||
|
||||
std::stringstream os;
|
||||
|
||||
ctx.WriteGltfSceneToStream(&model, os, false, false);
|
||||
|
||||
// use nlohmann json
|
||||
nlohmann::json j = nlohmann::json::parse(os.str());
|
||||
|
||||
// Ensure `skeleton` property is not written to .gltf(was serialized as -1)
|
||||
REQUIRE(1 == j["skins"].size());
|
||||
REQUIRE(j["skins"][0].is_object());
|
||||
REQUIRE(j["skins"][0].count("skeleton") == 0);
|
||||
|
||||
}
|
||||
|
||||
#ifndef TINYGLTF_NO_FS
|
||||
TEST_CASE("expandpath-utf-8", "[pr-226]") {
|
||||
|
||||
|
14
tiny_gltf.h
14
tiny_gltf.h
@ -7243,11 +7243,17 @@ static void SerializeGltfScene(Scene &scene, json &o) {
|
||||
}
|
||||
|
||||
static void SerializeGltfSkin(Skin &skin, json &o) {
|
||||
if (skin.inverseBindMatrices != -1)
|
||||
SerializeNumberProperty("inverseBindMatrices", skin.inverseBindMatrices, o);
|
||||
|
||||
// required
|
||||
SerializeNumberArrayProperty<int>("joints", skin.joints, o);
|
||||
SerializeNumberProperty("skeleton", skin.skeleton, o);
|
||||
|
||||
if (skin.inverseBindMatrices >= 0) {
|
||||
SerializeNumberProperty("inverseBindMatrices", skin.inverseBindMatrices, o);
|
||||
}
|
||||
|
||||
if (skin.skeleton >= 0) {
|
||||
SerializeNumberProperty("skeleton", skin.skeleton, o);
|
||||
}
|
||||
|
||||
if (skin.name.size()) {
|
||||
SerializeStringProperty("name", skin.name, o);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user