[Bf-blender-cvs] [89d032d] hair_system: Implemented materials for hair systems.
Lukas Tönne
noreply at git.blender.org
Fri Aug 15 14:30:48 CEST 2014
Commit: 89d032d102da32e284911d0c6b01c2207c105d07
Author: Lukas Tönne
Date: Fri Aug 15 14:29:53 2014 +0200
Branches: hair_system
https://developer.blender.org/rB89d032d102da32e284911d0c6b01c2207c105d07
Implemented materials for hair systems.
This uses basically the same system as current particle hair: the hair
system is linked to the material via a slot index, which refers
to the object material slots. Unlike particle settings the hair system
is (for now) not a separate datablock, so the mapping is a bit more
consistent.
===================================================================
M intern/cycles/blender/blender_curves.cpp
M release/scripts/startup/bl_ui/properties_physics_hair.py
M source/blender/makesdna/DNA_hair_types.h
M source/blender/makesrna/intern/rna_hair.c
===================================================================
diff --git a/intern/cycles/blender/blender_curves.cpp b/intern/cycles/blender/blender_curves.cpp
index 1daeacf..d4597dd 100644
--- a/intern/cycles/blender/blender_curves.cpp
+++ b/intern/cycles/blender/blender_curves.cpp
@@ -737,7 +737,7 @@ static void ExportHairCurveTrianglePlanes(Mesh *mesh, BL::HairSystem b_hsys, flo
float root_width = b_render.root_width() * b_render.radius_scale();
float tip_width = b_render.tip_width() * b_render.radius_scale();
bool closetip = b_render.use_closetip();
- int shader = 0; // XXX TODO
+ int shader = mesh->used_shaders[clamp(b_render.material_slot()-1, 0, mesh->used_shaders.size()-1)];
int vertexno = mesh->verts.size();
int vertexindex = vertexno;
@@ -806,7 +806,7 @@ static void ExportHairCurveTriangleGeometry(Mesh *mesh, BL::HairSystem b_hsys, i
float root_width = b_render.root_width() * b_render.radius_scale();
float tip_width = b_render.tip_width() * b_render.radius_scale();
bool closetip = b_render.use_closetip();
- int shader = 0; // XXX TODO
+ int shader = mesh->used_shaders[clamp(b_render.material_slot()-1, 0, mesh->used_shaders.size()-1)];
int vertexno = mesh->verts.size();
int vertexindex = vertexno;
@@ -884,7 +884,7 @@ static void ExportHairCurveSegments(Scene *scene, Mesh *mesh, BL::HairSystem b_h
float root_width = b_render.root_width() * b_render.radius_scale();
float tip_width = b_render.tip_width() * b_render.radius_scale();
bool closetip = b_render.use_closetip();
- int shader = 0; // XXX TODO
+ int shader = mesh->used_shaders[clamp(b_render.material_slot()-1, 0, mesh->used_shaders.size()-1)];
int num_keys = 0;
int num_curves = 0;
diff --git a/release/scripts/startup/bl_ui/properties_physics_hair.py b/release/scripts/startup/bl_ui/properties_physics_hair.py
index d30fe96..98b63c8 100644
--- a/release/scripts/startup/bl_ui/properties_physics_hair.py
+++ b/release/scripts/startup/bl_ui/properties_physics_hair.py
@@ -108,6 +108,11 @@ class PHYSICS_PT_hair_render(PhysicButtonsPanel, Panel):
render = params.render
col = layout.column()
+
+ col.prop(render, "material_slot")
+
+ col.separator()
+
col.prop(render, "render_hairs")
col.prop(render, "interpolation_steps")
diff --git a/source/blender/makesdna/DNA_hair_types.h b/source/blender/makesdna/DNA_hair_types.h
index cafa2cf..3791430 100644
--- a/source/blender/makesdna/DNA_hair_types.h
+++ b/source/blender/makesdna/DNA_hair_types.h
@@ -56,6 +56,7 @@ typedef struct HairCurve {
typedef struct HairRenderSettings {
int flag;
+ int material_slot; /* index of the object's material slot */
int num_render_hairs; /* render hairs per simulation hair */
@@ -67,6 +68,7 @@ typedef struct HairRenderSettings {
float shape;
float curl_smoothing;
+ int pad;
} HairRenderSettings;
typedef enum eHairRenderSettings_Flag {
diff --git a/source/blender/makesrna/intern/rna_hair.c b/source/blender/makesrna/intern/rna_hair.c
index 958159c..eab255a 100644
--- a/source/blender/makesrna/intern/rna_hair.c
+++ b/source/blender/makesrna/intern/rna_hair.c
@@ -44,6 +44,10 @@
#ifdef RNA_RUNTIME
#include "BKE_hair.h"
+#include "BKE_material.h"
+
+#include "DNA_object_types.h"
+#include "DNA_material_types.h"
#include "RNA_access.h"
@@ -84,6 +88,46 @@ static PointerRNA rna_HairSystem_render_get(PointerRNA *ptr)
return r_ptr;
}
+static EnumPropertyItem *rna_HairRenderSettings_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;
+}
+
static void rna_HairRenderIterator_init(HairRenderIterator *iter)
{
/* make sure the iterator is uninitialized first */
@@ -261,10 +305,28 @@ static void rna_def_hair_params(BlenderRNA *brna)
static void rna_def_hair_render_settings(BlenderRNA *brna) {
StructRNA *srna;
PropertyRNA *prop;
+
+ static EnumPropertyItem material_slot_items[] = {
+ {0, "DUMMY", 0, "Dummy", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
srna = RNA_def_struct(brna, "HairRenderSettings", NULL);
RNA_def_struct_ui_text(srna, "Hair Render Settings", "Hair render settings");
+ prop = RNA_def_property(srna, "material_index", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "material_slot");
+ RNA_def_property_range(prop, 1, 32767);
+ RNA_def_property_ui_text(prop, "Material Index", "Index of material slot used for rendering");
+ RNA_def_property_update(prop, 0, "rna_HairParams_render_update");
+
+ prop = RNA_def_property(srna, "material_slot", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "material_slot");
+ RNA_def_property_enum_items(prop, material_slot_items);
+ RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_HairRenderSettings_material_slot_itemf");
+ RNA_def_property_ui_text(prop, "Material Slot", "Material slot used for rendering");
+ RNA_def_property_update(prop, 0, "rna_HairParams_render_update");
+
prop = RNA_def_property(srna, "render_hairs", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "num_render_hairs");
RNA_def_property_range(prop, 1, 10000);
More information about the Bf-blender-cvs
mailing list