From fa29fa44c85ff2cf066dd501c55ff9725e8b3cff Mon Sep 17 00:00:00 2001 From: Emmanuel Durand Date: Thu, 3 Jul 2025 15:42:55 -0400 Subject: [PATCH] Change object culling attribute to a choices list --- data/share/splash/splash.json | 4 ++-- src/graphics/object.cpp | 42 +++++++++++++++++++++++++++++++---- src/utils/jsonutils.cpp | 26 ++++++++++++++++++++++ 3 files changed, 66 insertions(+), 6 deletions(-) diff --git a/data/share/splash/splash.json b/data/share/splash/splash.json index e3dc323c..6e8507ab 100644 --- a/data/share/splash/splash.json +++ b/data/share/splash/splash.json @@ -135,7 +135,7 @@ "rotation" : [ 0, 0, 0 ], "savable" : [ true ], "scale" : [ 1, 1, 1 ], - "culling" : [ 0 ], + "culling" : [ "double sided" ], "timestamp" : [ 1853296687 ], "type" : "object" }, @@ -211,7 +211,7 @@ "swapInterval" : [ 1 ] } }, - "version" : "0.11.5", + "version" : "0.11.7", "world" : { "clock" : [ 1884832083 ], "clockDeviceName" : [ "" ], diff --git a/src/graphics/object.cpp b/src/graphics/object.cpp index 0638b927..a612f611 100644 --- a/src/graphics/object.cpp +++ b/src/graphics/object.cpp @@ -625,12 +625,46 @@ void Object::registerAttributes() addAttribute( "culling", [&](const Values& args) { - _culling = static_cast(args[0].as()); + const auto mode = args[0].as(); + if (mode == "double sided") + _culling = Shader::Culling::doubleSided; + else if (mode == "front-face culling") + _culling = Shader::Culling::singleSided; + else if (mode == "back-face culling") + _culling = Shader::Culling::inverted; + else + _culling = Shader::Culling::doubleSided; return true; }, - [&]() -> Values { return {_culling}; }, - {'i'}); - setAttributeDescription("culling", "Set the side culling for the object: 0 for double sided, 1 for front-face visible, 2 for back-face visible"); + [&]() -> Values { + Values values; + switch(_culling) + { + default: + assert(false); + values.push_back("double sided"); + break; + case Shader::Culling::doubleSided: + values.push_back("double sided"); + break; + case Shader::Culling::singleSided: + values.push_back("front-face culling"); + break; + case Shader::Culling::inverted: + values.push_back("back-face culling"); + break; + } + + // Possible values + values.push_back("double sided"); + values.push_back("front-face culling"); + values.push_back("back-face culling"); + + return values; + }, + {'s'}, + Attribute::Choices::Generated); + setAttributeDescription("culling", "Set the side culling for the object"); addAttribute( "fill", diff --git a/src/utils/jsonutils.cpp b/src/utils/jsonutils.cpp index b6b67192..4d47f033 100644 --- a/src/utils/jsonutils.cpp +++ b/src/utils/jsonutils.cpp @@ -275,6 +275,32 @@ bool checkAndUpgradeConfiguration(Json::Value& configuration) configuration = newConfig; } + if ((versionMajor == 0 && versionMinor < 11) || (versionMajor == 0 && versionMinor == 11 && versionMaintainance < 7)) + { + Json::Value newConfig = configuration; + for (auto& scene : newConfig["scenes"]) + { + if (!scene.isMember("objects")) + continue; + + for (auto& object : scene["objects"]) + { + if (object["type"] != "object" && !object.isMember("culling")) + continue; + + const auto culling = object["culling"][0].asInt(); + if (culling == 0) + object["culling"] = "double sided"; + else if (culling == 1) + object["culling"] = "front-face culling"; + else if (culling == 1) + object["culling"] = "back-face culling"; + else + object["culling"] = "double sided"; + } + } + configuration = newConfig; + } configuration["version"] = std::string(PACKAGE_VERSION);