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:
authorHans Goudey <h.goudey@me.com>2022-05-03 10:28:35 +0300
committerHans Goudey <h.goudey@me.com>2022-05-03 10:47:40 +0300
commitf80e4f0046ed93714c1c71a60264e9d012237654 (patch)
treeadf2a19c324f29823a128967d6f0126c31409a79 /source/blender/nodes/geometry
parentaf2740abc0b003fd9d307933480ace3a99803669 (diff)
Fix T93272: Material index mapping missing for mesh boolean node
This commit implements copying of materials and material indices from all of the boolean node's input meshes. The materials are added to the final mesh in the order that they appear when looking through the materials of the input meshes in the same order of the multi-socket input node. All material remapping is done with mesh-level materials. Object-level materials are not considered, since the meshes don't come from objects. Merging all materials rather than just the materials on the first mesh requires a change to the boolean-mesh conversion. This subtly changes the behavior for object linked materials, but in a good way I think; now the material remap arrays are respected no matter the number of materials on the first mesh input. Differential Revision: https://developer.blender.org/D14788
Diffstat (limited to 'source/blender/nodes/geometry')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_boolean.cc40
1 files changed, 38 insertions, 2 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_boolean.cc b/source/blender/nodes/geometry/nodes/node_geo_boolean.cc
index 34256f23175..df2be8e7d37 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_boolean.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_boolean.cc
@@ -68,6 +68,9 @@ static void node_geo_exec(GeoNodeExecParams params)
Vector<const Mesh *> meshes;
Vector<const float4x4 *> transforms;
+ VectorSet<Material *> materials;
+ Vector<Array<short>> material_remaps;
+
GeometrySet set_a;
if (operation == GEO_NODE_BOOLEAN_DIFFERENCE) {
set_a = params.extract_input<GeometrySet>("Mesh 1");
@@ -78,6 +81,10 @@ static void node_geo_exec(GeoNodeExecParams params)
if (mesh_in_a != nullptr) {
meshes.append(mesh_in_a);
transforms.append(nullptr);
+ for (Material *material : Span(mesh_in_a->mat, mesh_in_a->totcol)) {
+ materials.add(material);
+ }
+ material_remaps.append({});
}
}
@@ -90,6 +97,25 @@ static void node_geo_exec(GeoNodeExecParams params)
}
for (const bke::GeometryInstanceGroup &set_group : set_groups) {
+ const Mesh *mesh = set_group.geometry_set.get_mesh_for_read();
+ if (mesh != nullptr) {
+ for (Material *material : Span(mesh->mat, mesh->totcol)) {
+ materials.add(material);
+ }
+ }
+ }
+ for (const bke::GeometryInstanceGroup &set_group : set_groups) {
+ const Mesh *mesh = set_group.geometry_set.get_mesh_for_read();
+ if (mesh != nullptr) {
+ Array<short> map(mesh->totcol);
+ for (const int i : IndexRange(mesh->totcol)) {
+ map[i] = materials.index_of(mesh->mat[i]);
+ }
+ material_remaps.append(std::move(map));
+ }
+ }
+
+ for (const bke::GeometryInstanceGroup &set_group : set_groups) {
const Mesh *mesh_in = set_group.geometry_set.get_mesh_for_read();
if (mesh_in != nullptr) {
meshes.append_n_times(mesh_in, set_group.transforms.size());
@@ -99,8 +125,18 @@ static void node_geo_exec(GeoNodeExecParams params)
}
}
- Mesh *result = blender::meshintersect::direct_mesh_boolean(
- meshes, transforms, float4x4::identity(), {}, use_self, hole_tolerant, operation);
+ Mesh *result = blender::meshintersect::direct_mesh_boolean(meshes,
+ transforms,
+ float4x4::identity(),
+ material_remaps,
+ use_self,
+ hole_tolerant,
+ operation);
+
+ MEM_SAFE_FREE(result->mat);
+ result->mat = (Material **)MEM_malloc_arrayN(materials.size(), sizeof(Material *), __func__);
+ result->totcol = materials.size();
+ MutableSpan(result->mat, result->totcol).copy_from(materials);
params.set_output("Mesh", GeometrySet::create_with_mesh(result));
}