[Bf-blender-cvs] [6d31eb015c6] master: Array Modifier: option to offset UV's

Campbell Barton noreply at git.blender.org
Wed Dec 6 18:22:24 CET 2017


Commit: 6d31eb015c6a3f6c3ff2a998fc52416c25c4e5b6
Author: Campbell Barton
Date:   Thu Dec 7 04:33:52 2017 +1100
Branches: master
https://developer.blender.org/rB6d31eb015c6a3f6c3ff2a998fc52416c25c4e5b6

Array Modifier: option to offset UV's

D2912 by @Zuorion

===================================================================

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_array.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 8f6e5f2df39..7388dea2158 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -115,6 +115,13 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         sub.active = md.use_object_offset
         sub.prop(md, "offset_object", text="")
 
+        row = layout.row()
+        split = row.split()
+        col = split.column()
+        col.label(text="UVs:")
+        sub = col.column(align=True)
+        sub.prop(md, "offset_u")
+        sub.prop(md, "offset_v")
         layout.separator()
 
         layout.prop(md, "start_cap")
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 7f0547188e9..fc0bf59518c 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -249,6 +249,7 @@ typedef struct ArrayModifierData {
 	int flags;
 	/* the number of duplicates to generate for MOD_ARR_FIXEDCOUNT */
 	int count;
+	float uv_offset[2];
 } ArrayModifierData;
 
 /* ArrayModifierData->fit_type */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 62b917897ba..a99c9f9d89e 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -2122,6 +2122,20 @@ static void rna_def_modifier_array(BlenderRNA *brna)
 	RNA_def_property_pointer_funcs(prop, NULL, "rna_ArrayModifier_end_cap_set", NULL, "rna_Mesh_object_poll");
 	RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
 	RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
+	
+	prop = RNA_def_property(srna, "offset_u", PROP_FLOAT, PROP_FACTOR);
+	RNA_def_property_float_sdna(prop, NULL, "uv_offset[0]");
+	RNA_def_property_range(prop, -1, 1);
+	RNA_def_property_ui_range(prop, -1, 1, 2, 4);
+	RNA_def_property_ui_text(prop, "U Offset", "Amount to offset array UVs on the U axis");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "offset_v", PROP_FLOAT, PROP_FACTOR);
+	RNA_def_property_float_sdna(prop, NULL, "uv_offset[1]");
+	RNA_def_property_range(prop, -1, 1);
+	RNA_def_property_ui_range(prop, -1, 1, 2, 4);
+	RNA_def_property_ui_text(prop, "V Offset", "Amount to offset array UVs on the V axis");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
 static void rna_def_modifier_edgesplit(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c
index 874ac34b613..a3f3af0c748 100644
--- a/source/blender/modifiers/intern/MOD_array.c
+++ b/source/blender/modifiers/intern/MOD_array.c
@@ -655,6 +655,26 @@ static DerivedMesh *arrayModifier_doArray(
 		}
 	}
 
+	/* handle UVs */
+	if (chunk_nloops > 0 && is_zero_v2(amd->uv_offset) == false) {
+		const int totuv = CustomData_number_of_layers(&result->loopData, CD_MLOOPUV);
+		for (i = 0; i < totuv; i++) {
+			MLoopUV *dmloopuv = CustomData_get_layer_n(&result->loopData, CD_MLOOPUV, i);
+			dmloopuv += chunk_nloops;
+			for (c = 1; c < count; c++) {
+				const float uv_offset[2] = {
+					amd->uv_offset[0] * (float)c,
+					amd->uv_offset[1] * (float)c,
+				};
+				int l_index = chunk_nloops;
+				for (; l_index-- != 0; dmloopuv++) {
+					dmloopuv->uv[0] += uv_offset[0];
+					dmloopuv->uv[1] += uv_offset[1];
+				}
+			}
+		}
+	}
+
 	last_chunk_start = (count - 1) * chunk_nverts;
 	last_chunk_nverts = chunk_nverts;



More information about the Bf-blender-cvs mailing list