Fix #109491: Erratic behavior of materials for text objects #109746

Closed
Philipp Oeser wants to merge 4 commits from lichtwerk/blender:109491 into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
4 changed files with 34 additions and 7 deletions

View File

@ -27,7 +27,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 11
#define BLENDER_FILE_SUBVERSION 12
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and show a warning if the file

View File

@ -400,6 +400,11 @@ void BKE_curve_init(Curve *cu, const short curve_type)
BLI_strncpy(cu->str, "Text", 12);
cu->len = cu->len_char32 = cu->pos = 4;
cu->strinfo = (CharInfo *)MEM_calloc_arrayN(12, sizeof(CharInfo), "strinfo new");
/* Initialize CharInfo mat_nr to 1, since index starts at 1, unlike mesh or nurbs. */
CharInfo *info = cu->strinfo;
for (int i = cu->len_char32 - 1; i >= 0; i--, info++) {
info->mat_nr = 1;
}
cu->totbox = cu->actbox = 1;
cu->tb = (TextBox *)MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), "textbox");
cu->tb[0].w = cu->tb[0].h = 0.0;
@ -5322,7 +5327,8 @@ void BKE_curve_material_index_remove(Curve *cu, int index)
if (curvetype == OB_FONT) {
CharInfo *info = cu->strinfo;
for (int i = cu->len_char32 - 1; i >= 0; i--, info++) {
if (info->mat_nr && info->mat_nr >= index) {
/* CharInfo mat_nr starts at 1, unlike mesh & nurbs. */
if (info->mat_nr && info->mat_nr > index) {
info->mat_nr--;
}
}
@ -5342,8 +5348,9 @@ bool BKE_curve_material_index_used(const Curve *cu, int index)
if (curvetype == OB_FONT) {
const CharInfo *info = cu->strinfo;
/* CharInfo mat_nr starts at 1, unlike mesh & nurbs. */
for (int i = cu->len_char32 - 1; i >= 0; i--, info++) {
if (info->mat_nr == index) {
if (info->mat_nr == index + 1) {
return true;
}
}
@ -5366,7 +5373,8 @@ void BKE_curve_material_index_clear(Curve *cu)
if (curvetype == OB_FONT) {
CharInfo *info = cu->strinfo;
for (int i = cu->len_char32 - 1; i >= 0; i--, info++) {
info->mat_nr = 0;
/* CharInfo mat_nr starts at 1, unlike mesh & nurbs. */
info->mat_nr = 1;
}
}
else {
@ -5387,7 +5395,8 @@ bool BKE_curve_material_index_validate(Curve *cu)
int i;
for (i = cu->len_char32 - 1; i >= 0; i--, info++) {
if (info->mat_nr > max_idx) {
info->mat_nr = 0;
/* CharInfo mat_nr starts at 1, unlike mesh & nurbs. */
info->mat_nr = 1;
is_valid = false;
}
}

View File

@ -1684,8 +1684,9 @@ static bool vfont_to_curve(Object *ob,
* time that code is called without an object. */
if (ob != nullptr && (info->mat_nr > (ob->totcol))) {
// CLOG_ERROR(
// &LOG, "Illegal material index (%d) in text object, setting to 0", info->mat_nr);
info->mat_nr = 0;
// &LOG, "Illegal material index (%d) in text object, setting to 1", info->mat_nr);
/* CharInfo mat_nr starts at 1, unlike mesh & nurbs. */
info->mat_nr = 1;
}
/* We don't want to see any character for '\n'. */
if (cha != '\n') {

View File

@ -13,6 +13,7 @@
#include "CLG_log.h"
#include "DNA_brush_types.h"
#include "DNA_curve_types.h"
#include "DNA_light_types.h"
#include "DNA_lightprobe_types.h"
#include "DNA_modifier_types.h"
@ -28,6 +29,7 @@
#include "BLI_set.hh"
#include "BLI_string_ref.hh"
#include "BKE_curve.h"
#include "BKE_grease_pencil.hh"
#include "BKE_idprop.hh"
#include "BKE_main.h"
@ -363,6 +365,21 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
version_vertex_weight_edit_preserve_threshold_exclusivity(bmain);
}
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 400, 12)) {
LISTBASE_FOREACH (Curve *, curve, &bmain->curves) {
const int curvetype = BKE_curve_type_get(curve);
if (curvetype == OB_FONT) {
CharInfo *info = curve->strinfo;
for (int i = curve->len_char32 - 1; i >= 0; i--, info++) {
if (info->mat_nr == 0) {
/** CharInfo mat_nr starts at 1, unlike mesh & nurbs. */
info->mat_nr = 1;
}
}
}
}
}
/**
* Versioning code until next subversion bump goes here.
*