Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Oeser <info@graphics-engineer.com>2022-09-05 13:22:51 +0300
committerPhilipp Oeser <info@graphics-engineer.com>2022-09-08 10:06:50 +0300
commitecf3287533c8adc90250bc13957eddb7b2e22fc6 (patch)
tree4303615b4c9a9bbb6243bb459e3c5f04ad335200 /source/blender/editors
parenta3ddcc6b4d11ae45ab3f55afefbfc57fb975d592 (diff)
Fix T100822: Merging objects does not assign materials correctly
Caused by {rBf1c0249f34c4} This is what (I think) went wrong in the above commit: - `join_mesh_single` was writing material indices to the custom data / attribute of the source mesh - the `polyofs` of each mesh that was joined was not taken into account Now, instead of using the AttributeWriter on a particular mesh, use the CustomData (`pdata`) - that is constantly changed during joining - directly for writing. Otherwise we end up writing into customdata that has not been "extended" yet (even if we use the destination mesh). Also note that even on the destination mesh, CustomData would be freed anyways after all calls to `join_mesh_single` took place, to be replaced with the mentioned `pdata` which should be the single customdata to write to here. When doing this (writing to `pdata`), we also need to take into account the poly offset of each contributing mesh. Maniphest Tasks: T100822 Differential Revision: https://developer.blender.org/D15878
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/mesh/meshtools.cc17
1 files changed, 10 insertions, 7 deletions
diff --git a/source/blender/editors/mesh/meshtools.cc b/source/blender/editors/mesh/meshtools.cc
index d6713724e15..58702d9e966 100644
--- a/source/blender/editors/mesh/meshtools.cc
+++ b/source/blender/editors/mesh/meshtools.cc
@@ -253,15 +253,18 @@ static void join_mesh_single(Depsgraph *depsgraph,
CustomData_merge(&me->pdata, pdata, CD_MASK_MESH.pmask, CD_SET_DEFAULT, totpoly);
CustomData_copy_data_named(&me->pdata, pdata, 0, *polyofs, me->totpoly);
- blender::bke::AttributeWriter<int> material_indices =
- me->attributes_for_write().lookup_for_write<int>("material_index");
+ /* Apply matmap. In case we dont have material indices yet, create them if more than one
+ * material is the result of joining. */
+ int *material_indices = static_cast<int *>(
+ CustomData_get_layer_named(pdata, CD_PROP_INT32, "material_index"));
+ if (!material_indices && totcol > 1) {
+ material_indices = (int *)CustomData_add_layer_named(
+ pdata, CD_PROP_INT32, CD_SET_DEFAULT, NULL, totpoly, "material_index");
+ }
if (material_indices) {
- blender::MutableVArraySpan<int> material_indices_span(material_indices.varray);
- for (const int i : material_indices_span.index_range()) {
- material_indices_span[i] = matmap ? matmap[material_indices_span[i]] : 0;
+ for (a = 0; a < me->totpoly; a++) {
+ material_indices[a + *polyofs] = matmap ? matmap[material_indices[a + *polyofs]] : 0;
}
- material_indices_span.save();
- material_indices.finish();
}
for (a = 0; a < me->totpoly; a++, mpoly++) {