[Bf-blender-cvs] [9174f22] master: Particles: change material picking from index number in UI to menu with materials.

Geoffroy Krantz noreply at git.blender.org
Sat Dec 7 17:11:46 CET 2013


Commit: 9174f22b3c51b601e6c399bba2b32303f008630d
Author: Geoffroy Krantz
Date:   Sat Dec 7 01:51:44 2013 +0100
http://developer.blender.org/rB9174f22b3c51b601e6c399bba2b32303f008630d

Particles: change material picking from index number in UI to menu with materials.

Also fix material slot index not being properly initialized to 1, this got clamped
from zero only on drawing the UI.

Reviewed By: brecht

Differential Revision: http://developer.blender.org/D55

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

M	release/scripts/startup/bl_ui/properties_particle.py
M	source/blender/blenkernel/intern/particle.c
M	source/blender/makesrna/intern/rna_particle.c

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

diff --git a/release/scripts/startup/bl_ui/properties_particle.py b/release/scripts/startup/bl_ui/properties_particle.py
index c5997eb..206a208 100644
--- a/release/scripts/startup/bl_ui/properties_particle.py
+++ b/release/scripts/startup/bl_ui/properties_particle.py
@@ -797,7 +797,7 @@ class PARTICLE_PT_render(ParticleButtonsPanel, Panel):
         part = particle_get_settings(context)
 
         row = layout.row()
-        row.prop(part, "material")
+        row.prop(part, "material_slot", text="")
         if psys:
             row.prop(psys, "parent")
 
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index a819b73..a76b60f 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -3652,6 +3652,7 @@ static void default_particle_settings(ParticleSettings *part)
 	if (!part->effector_weights)
 		part->effector_weights = BKE_add_effector_weights(NULL);
 
+	part->omat = 1;
 	part->use_modifier_stack = false;
 }
 
diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c
index 5151310..92c567e 100644
--- a/source/blender/makesrna/intern/rna_particle.c
+++ b/source/blender/makesrna/intern/rna_particle.c
@@ -136,6 +136,7 @@ static EnumPropertyItem part_hair_ren_as_items[] = {
 #include "BKE_DerivedMesh.h"
 #include "BKE_cdderivedmesh.h"
 #include "BKE_effect.h"
+#include "BKE_material.h"
 #include "BKE_modifier.h"
 #include "BKE_particle.h"
 #include "BKE_pointcache.h"
@@ -390,6 +391,47 @@ static void rna_ParticleSystem_co_hair(ParticleSystem *particlesystem, Object *o
 
 }
 
+
+static EnumPropertyItem *rna_Particule_Material_itemf(bContext *C, PointerRNA *UNUSED(ptr),
+                                                      PropertyRNA *UNUSED(prop), int *free)
+{
+	Object *ob = CTX_data_active_object(C);
+	Material *ma;
+	EnumPropertyItem *item = NULL;
+	EnumPropertyItem tmp = {0, "", 0, "", ""};
+	int totitem = 0;
+	int i;
+
+	if (ob->totcol > 0){
+		for (i = 1; i<=ob->totcol; i++) {
+			ma = give_current_material(ob, i);
+			tmp.value = i;
+			tmp.icon = ICON_MATERIAL_DATA;
+			if (ma) {
+				tmp.name = ma->id.name + 2;
+				tmp.identifier = tmp.name;
+			}
+			else {
+				tmp.name = "Default Material";
+				tmp.identifier = tmp.name;
+			}
+			RNA_enum_item_add(&item, &totitem, &tmp);
+		}
+	}
+	else {
+		tmp.value = 1;
+		tmp.icon = ICON_MATERIAL_DATA;
+		tmp.name = "Default Material";
+		tmp.identifier = tmp.name;
+		RNA_enum_item_add(&item, &totitem, &tmp);
+	}
+
+	RNA_enum_item_end(&item, &totitem);
+	*free = 1;
+
+	return item;
+}
+
 static void rna_ParticleSystem_uv_on_emitter(ParticleSystem *particlesystem, ReportList *reports,
                                              ParticleSystemModifierData *modifier, ParticleData *particle,
                                              int particle_no, int uv_no,
@@ -2018,6 +2060,11 @@ static void rna_def_particle_settings(BlenderRNA *brna)
 		{0, NULL, 0, NULL, NULL}
 	};
 
+	static EnumPropertyItem part_mat_items[] = {
+		{0, "DUMMY", 0, "Dummy", ""},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	srna = RNA_def_struct(brna, "ParticleSettings", "ID");
 	RNA_def_struct_ui_text(srna, "Particle Settings", "Particle settings, reusable by multiple particle systems");
 	RNA_def_struct_ui_icon(srna, ICON_PARTICLE_DATA);
@@ -2360,7 +2407,14 @@ static void rna_def_particle_settings(BlenderRNA *brna)
 	prop = RNA_def_property(srna, "material", PROP_INT, PROP_NONE);
 	RNA_def_property_int_sdna(prop, NULL, "omat");
 	RNA_def_property_range(prop, 1, 32767);
-	RNA_def_property_ui_text(prop, "Material", "Material used for the particles");
+	RNA_def_property_ui_text(prop, "Material Index", "Index of material slot used for rendering particles");
+	RNA_def_property_update(prop, 0, "rna_Particle_redo");
+
+	prop = RNA_def_property(srna, "material_slot", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "omat");
+	RNA_def_property_enum_items(prop, part_mat_items);
+	RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Particule_Material_itemf");
+	RNA_def_property_ui_text(prop, "Material Slot", "Material slot used for rendering particles");
 	RNA_def_property_update(prop, 0, "rna_Particle_redo");
 
 	prop = RNA_def_property(srna, "integrator", PROP_ENUM, PROP_NONE);




More information about the Bf-blender-cvs mailing list