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);
profile.foregroundLightTransparent = spec.getBool("foregroundLightTransparent", 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()))
profile.colorDirectives.append(entry.toString());
profile.occludesBehind = spec.getBool("occludesBelow", true);
@ -128,14 +128,12 @@ MaterialRenderProfile parseMaterialRenderProfile(Json const& spec, String const&
auto flipTextureCoordinates = [imageHeight](
RectF const& rect) { return RectF::withSize(Vec2F(rect.xMin(), imageHeight - rect.yMax()), rect.size()); };
for (unsigned v = 0; v < variants; ++v) {
if (profile.colorVariants > 0) {
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);
renderPiece->variants[DefaultMaterialColorVariant].append(flipTextureCoordinates(textureRect));
auto i = DefaultMaterialColorVariant;
RectF textureRect = RectF::withSize(texturePosition + variantStride * v, textureSize);
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));
}
}