[Bf-blender-cvs] [c53c6e99b30] hair_guides: Use material slot index instead of a direct Material pointer.
Lukas Tönne
noreply at git.blender.org
Sun Nov 26 11:35:22 CET 2017
Commit: c53c6e99b30241bbf8f7df2594981a79e3c6fc71
Author: Lukas Tönne
Date: Sun Nov 26 10:33:19 2017 +0000
Branches: hair_guides
https://developer.blender.org/rBc53c6e99b30241bbf8f7df2594981a79e3c6fc71
Use material slot index instead of a direct Material pointer.
A Material pointer would be a nicer way to assign a hair material,
but unfortunately that does not work well with the context-based material
lookup of the node editor. There is no selection of an "active" modifier,
so the node editor will never display the material (unless it is placed
into a material stack as well).
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/blenkernel/intern/hair.c
M source/blender/draw/engines/eevee/eevee_materials.c
M source/blender/makesdna/DNA_hair_types.h
M source/blender/makesrna/intern/rna_hair.c
M source/blender/modifiers/intern/MOD_fur.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 2758fea6c55..71fdc650b46 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1561,7 +1561,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
col.separator()
- col.prop(hsys, "material", text="")
+ col.prop(hsys, "material_slot", text="")
col = layout.column()
col.label("Drawing:")
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index d438e7bb8e2..588bd167f41 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -59,6 +59,8 @@ HairSystem* BKE_hair_new(void)
hair->pattern = MEM_callocN(sizeof(HairPattern), "hair pattern");
+ hair->material_index = 1;
+
return hair;
}
@@ -81,10 +83,6 @@ HairSystem* BKE_hair_copy(HairSystem *hsys)
nhsys->verts = MEM_dupallocN(hsys->verts);
}
- if (nhsys->mat) {
- id_us_plus((ID *)nhsys->mat);
- }
-
nhsys->draw_batch_cache = NULL;
nhsys->draw_texture_cache = NULL;
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
index 8b497681853..0fef4c3abc5 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -1365,7 +1365,7 @@ static void material_hair(
}
GPUTexture **fiber_texture = (GPUTexture **)(&hsys->draw_texture_cache);
- Material *ma = hsys->mat;
+ Material *ma = give_current_material(ob, hsys->material_index);
if (ma == NULL) {
ma = &defmaterial;
}
diff --git a/source/blender/makesdna/DNA_hair_types.h b/source/blender/makesdna/DNA_hair_types.h
index 83a367826bf..9a42259ec2d 100644
--- a/source/blender/makesdna/DNA_hair_types.h
+++ b/source/blender/makesdna/DNA_hair_types.h
@@ -85,7 +85,8 @@ typedef struct HairSystem {
int totverts;
/* Material used for drawing and rendering hair fibers */
- struct Material *mat;
+ int material_index;
+ int pad2;
/* Data buffers for drawing */
void *draw_batch_cache;
diff --git a/source/blender/makesrna/intern/rna_hair.c b/source/blender/makesrna/intern/rna_hair.c
index b697f46d68e..079ce5c6a07 100644
--- a/source/blender/makesrna/intern/rna_hair.c
+++ b/source/blender/makesrna/intern/rna_hair.c
@@ -47,6 +47,7 @@
#include "BKE_DerivedMesh.h"
#include "BKE_hair.h"
#include "BKE_main.h"
+#include "BKE_material.h"
#include "DEG_depsgraph.h"
@@ -82,6 +83,49 @@ static void rna_HairSystem_generate_follicles(
BKE_hair_generate_follicles(hsys, dm, (unsigned int)seed, count);
}
+static const EnumPropertyItem *rna_HairSystem_material_slot_itemf(
+ bContext *C,
+ PointerRNA *UNUSED(ptr),
+ PropertyRNA *UNUSED(prop),
+ bool *r_free)
+{
+ Object *ob = CTX_data_pointer_get(C, "object").data;
+ Material *ma;
+ EnumPropertyItem *item = NULL;
+ EnumPropertyItem tmp = {0, "", 0, "", ""};
+ int totitem = 0;
+ int i;
+
+ if (ob && 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);
+ *r_free = true;
+
+ return item;
+}
+
#else
static void rna_def_hair_follicle(BlenderRNA *brna)
@@ -119,6 +163,11 @@ static void rna_def_hair_system(BlenderRNA *brna)
FunctionRNA *func;
PropertyRNA *prop, *parm;
+ static const EnumPropertyItem material_slot_items[] = {
+ {0, "DUMMY", 0, "Dummy", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
srna = RNA_def_struct(brna, "HairSystem", NULL);
RNA_def_struct_ui_text(srna, "Hair System", "Hair rendering and deformation data");
RNA_def_struct_sdna(srna, "HairSystem");
@@ -128,11 +177,18 @@ static void rna_def_hair_system(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "HairPattern");
RNA_def_property_ui_text(prop, "Pattern", "Hair pattern");
- prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "mat");
- RNA_def_property_ui_text(prop, "Material", "Material used for drawing and rendering hair fibers");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_HairSystem_update");
+ prop = RNA_def_property(srna, "material_index", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "material_index");
+ RNA_def_property_range(prop, 1, 32767);
+ RNA_def_property_ui_text(prop, "Material Index", "Index of material slot used for rendering hair fibers");
+ RNA_def_property_update(prop, 0, "rna_HairSystem_update");
+
+ prop = RNA_def_property(srna, "material_slot", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "material_index");
+ RNA_def_property_enum_items(prop, material_slot_items);
+ RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_HairSystem_material_slot_itemf");
+ RNA_def_property_ui_text(prop, "Material Slot", "Material slot used for rendering particles");
+ RNA_def_property_update(prop, 0, "rna_HairSystem_update");
func = RNA_def_function(srna, "generate_follicles", "rna_HairSystem_generate_follicles");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
diff --git a/source/blender/modifiers/intern/MOD_fur.c b/source/blender/modifiers/intern/MOD_fur.c
index 90bc3b85e1d..3334a60d735 100644
--- a/source/blender/modifiers/intern/MOD_fur.c
+++ b/source/blender/modifiers/intern/MOD_fur.c
@@ -129,11 +129,7 @@ static void foreachIDLink(
void *userData)
{
FurModifierData *fmd = (FurModifierData *) md;
-
- if (fmd->hair_system)
- {
- walk(userData, ob, (ID **)&fmd->hair_system->mat, IDWALK_CB_USER);
- }
+ UNUSED_VARS(fmd);
foreachObjectLink(md, ob, (ObjectWalkFunc)walk, userData);
}
More information about the Bf-blender-cvs
mailing list