fix the very last material color variant not displaying

This commit is contained in:
Kae 2024-06-27 14:29:43 +10:00
parent c90e738730
commit 64adc28658

View File

@ -80,7 +80,7 @@ MaterialRenderProfile parseMaterialRenderProfile(Json const& spec, String const&
bool lightTransparent = spec.getBool("lightTransparent", false); bool lightTransparent = spec.getBool("lightTransparent", false);
profile.foregroundLightTransparent = spec.getBool("foregroundLightTransparent", lightTransparent); profile.foregroundLightTransparent = spec.getBool("foregroundLightTransparent", lightTransparent);
profile.backgroundLightTransparent = spec.getBool("backgroundLightTransparent", lightTransparent); profile.backgroundLightTransparent = spec.getBool("backgroundLightTransparent", lightTransparent);
profile.colorVariants = spec.getBool("multiColored", false) ? spec.getUInt("colorVariants", MaxMaterialColorVariant) : 0; profile.colorVariants = spec.getBool("multiColored", false) ? spec.getUInt("colorVariants", (uint64_t)MaxMaterialColorVariant + 1) : 0;
for (auto& entry : spec.getArray("colorDirectives", JsonArray())) for (auto& entry : spec.getArray("colorDirectives", JsonArray()))
profile.colorDirectives.append(entry.toString()); profile.colorDirectives.append(entry.toString());
profile.occludesBehind = spec.getBool("occludesBelow", true); profile.occludesBehind = spec.getBool("occludesBelow", true);
@ -128,14 +128,12 @@ MaterialRenderProfile parseMaterialRenderProfile(Json const& spec, String const&
auto flipTextureCoordinates = [imageHeight]( auto flipTextureCoordinates = [imageHeight](
RectF const& rect) { return RectF::withSize(Vec2F(rect.xMin(), imageHeight - rect.yMax()), rect.size()); }; RectF const& rect) { return RectF::withSize(Vec2F(rect.xMin(), imageHeight - rect.yMax()), rect.size()); };
for (unsigned v = 0; v < variants; ++v) { for (unsigned v = 0; v < variants; ++v) {
if (profile.colorVariants > 0) { auto i = DefaultMaterialColorVariant;
for (MaterialColorVariant c = 0; c <= profile.colorVariants; ++c) {
RectF textureRect = RectF::withSize(texturePosition + variantStride * v + colorStride * c, textureSize);
renderPiece->variants[c].append(flipTextureCoordinates(textureRect));
}
} else {
RectF textureRect = RectF::withSize(texturePosition + variantStride * v, textureSize); RectF textureRect = RectF::withSize(texturePosition + variantStride * v, textureSize);
renderPiece->variants[DefaultMaterialColorVariant].append(flipTextureCoordinates(textureRect)); renderPiece->variants[i].append(flipTextureCoordinates(textureRect));
for (MaterialColorVariant c = 0; c != profile.colorVariants; ++c) {
RectF textureRect = RectF::withSize(texturePosition + variantStride * v + colorStride * ++i, textureSize);
renderPiece->variants[i].append(flipTextureCoordinates(textureRect));
} }
} }