feat(procgen): share schemas across material recipes

This commit is contained in:
西风逍遥游 committed 2026-08-25 06:09:09 +08:00
1 parent 1acb447d1d
commit a8e92479ed
16 files changed
+730 -240

No files matched your search

+37
View File
@@ -34,6 +34,32 @@ TEST_CASE("procgen.script.reflects_schema_and_generates_from_dynamic_values") {
fillMax <- fillIndex < 0 ? -1.0 : procgen.getAlgorithmParamMaximum(algorithm, fillIndex);
wfcChoiceCount <- procgen.getAlgorithmParamChoiceCount("wfc.simple", 3);
wfcFirstChoice <- procgen.getAlgorithmParamChoice("wfc.simple", 3, 0);
algorithmSchema <- procgen.getAlgorithmSchema(algorithm);
genericAlgorithmId <- algorithmSchema.getId();
textureParams <- procgen.newParams();
textureDefaultsApplied <- procgen.applyTextureRecipeDefaults("tex.rock", textureParams);
textureSchema <- procgen.getTextureRecipeSchema("tex.rock");
textureCategory <- textureSchema.getCategory();
textureScaleFound <- false;
for (local i = 0; i < textureSchema.getParamCount(); ++i)
if (textureSchema.getParamKey(i) == "scale") textureScaleFound = true;
pbrParams <- procgen.newParams();
pbrParams.setSize(16, 12);
pbrDefaultsApplied <- procgen.applyPbrRecipeDefaults("pbr.rock", pbrParams);
pbrSchema <- procgen.getPbrRecipeSchema("pbr.rock");
pbrMetallicFound <- false;
pbrNormalFound <- false;
for (local i = 0; i < pbrSchema.getParamCount(); ++i) {
local key = pbrSchema.getParamKey(i);
if (key == "metallic") pbrMetallicFound = true;
if (key == "normalStrength") pbrNormalFound = true;
}
pbrSet <- procgen.generatePbrMaterial("pbr.rock", pbrParams);
pbrHasAllMaps <- pbrSet != null && pbrSet.hasAllMaps();
pbrAlbedoWidth <- pbrSet == null ? 0 : pbrSet.getAlbedo().getWidth();
pbrNormalWidth <- pbrSet == null ? 0 : pbrSet.getNormal().getWidth();
pbrHeightWidth <- pbrSet == null ? 0 : pbrSet.getHeight().getWidth();
if (pbrSet != null) pbrSet.destroy();
)"));
CHECK(vm.find("defaultsApplied").toBool());
@@ -46,4 +72,15 @@ TEST_CASE("procgen.script.reflects_schema_and_generates_from_dynamic_values") {
CHECK_EQ(vm.find("height").toInt(), 24);
CHECK_EQ(vm.find("wfcChoiceCount").toInt(), 3);
CHECK_EQ(vm.find("wfcFirstChoice").toString(), std::string("dungeon"));
CHECK_EQ(vm.find("genericAlgorithmId").toString(), std::string("cave.cellular"));
CHECK(vm.find("textureDefaultsApplied").toBool());
CHECK_EQ(vm.find("textureCategory").toString(), std::string("Texture"));
CHECK(vm.find("textureScaleFound").toBool());
CHECK(vm.find("pbrDefaultsApplied").toBool());
CHECK(vm.find("pbrMetallicFound").toBool());
CHECK(vm.find("pbrNormalFound").toBool());
CHECK(vm.find("pbrHasAllMaps").toBool());
CHECK_EQ(vm.find("pbrAlbedoWidth").toInt(), 16);
CHECK_EQ(vm.find("pbrNormalWidth").toInt(), 16);
CHECK_EQ(vm.find("pbrHeightWidth").toInt(), 16);
}