Change object culling attribute to a choices list

This commit is contained in:
Emmanuel Durand
2025-07-03 15:42:55 -04:00
parent 37c8208d52
commit fa29fa44c8
3 changed files with 66 additions and 6 deletions
+2 -2
View File
@@ -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" : [ "" ],
+38 -4
View File
@@ -625,12 +625,46 @@ void Object::registerAttributes()
addAttribute(
"culling",
[&](const Values& args) {
_culling = static_cast<Shader::Culling>(args[0].as<int>());
const auto mode = args[0].as<std::string>();
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",
+26
View File
@@ -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);