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:
authorSergey Sharybin <sergey.vfx@gmail.com>2012-01-27 12:04:03 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2012-01-27 12:04:03 +0400
commitb35446c3fa84ec0b817be1aaf356c3e3a5071285 (patch)
treec36b2a0b6f0c83b1f6b3b10035a3338a3b222ab0 /source/blender/modifiers/intern/MOD_boolean_util.c
parent959f2624ca58839ae8cc5ac6e13162759e5dc759 (diff)
Fix #30000: Boolean modifier messing up multi material
Issue was caused by resetting face's mat_nr to zero if there's no material map sent to ConvertCSGDescriptorsToDerivedMesh. In case of boolean modifier we can't use such map because we can't affect on materials present in object. So the only way which can give reasonable result is: - Dot change mat_nr for faces from left operand (they should be fine, because materials aren't deleting by modifier) - For faces from right operand check if needed material exists in left operand and if so, use it's index as new mat_nr. - If there are materials in right operand which doesn't exist in left operand, they'll be changed to first material from left operand.
Diffstat (limited to 'source/blender/modifiers/intern/MOD_boolean_util.c')
-rw-r--r--source/blender/modifiers/intern/MOD_boolean_util.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/source/blender/modifiers/intern/MOD_boolean_util.c b/source/blender/modifiers/intern/MOD_boolean_util.c
index f6a2e4451b2..4b380efa95b 100644
--- a/source/blender/modifiers/intern/MOD_boolean_util.c
+++ b/source/blender/modifiers/intern/MOD_boolean_util.c
@@ -374,10 +374,10 @@ static DerivedMesh *ConvertCSGDescriptorsToDerivedMesh(
}
// a hash table to remap materials to indices
- if (mat) {
- material_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "CSG_mat gh");
+ material_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "CSG_mat gh");
+
+ if (mat)
*totmat = 0;
- }
origindex_layer = result->getFaceDataArray(result, CD_ORIGINDEX);
@@ -422,6 +422,32 @@ static DerivedMesh *ConvertCSGDescriptorsToDerivedMesh(
else
mface->mat_nr = GET_INT_FROM_POINTER(BLI_ghash_lookup(material_hash, orig_mat));
}
+ else if(orig_mat) {
+ if(orig_ob == ob1) {
+ // No need to change materian index for faces from left operand
+ }
+ else {
+ // for faces from right operand checn if there's needed material in left operand and if it is,
+ // use index of that material, otherwise fallback to first material (material with index=0)
+ if (!BLI_ghash_haskey(material_hash, orig_mat)) {
+ int a;
+
+ mat_nr = 0;
+ for(a = 0; a < ob1->totcol; a++) {
+ if(give_current_material(ob1, a+1) == orig_mat) {
+ mat_nr = a;
+ break;
+ }
+ }
+
+ BLI_ghash_insert(material_hash, orig_mat, SET_INT_IN_POINTER(mat_nr));
+
+ mface->mat_nr = mat_nr;
+ }
+ else
+ mface->mat_nr = GET_INT_FROM_POINTER(BLI_ghash_lookup(material_hash, orig_mat));
+ }
+ }
else
mface->mat_nr = 0;