[Bf-blender-cvs] [dcd9cb72f57] hair_guides: Test API in the fur modifier for creating custom guide curves with python.

Lukas Tönne noreply at git.blender.org
Wed Apr 18 09:59:47 CEST 2018


Commit: dcd9cb72f57493daa55d054b98c05ee811c03da1
Author: Lukas Tönne
Date:   Wed Apr 18 08:57:52 2018 +0100
Branches: hair_guides
https://developer.blender.org/rBdcd9cb72f57493daa55d054b98c05ee811c03da1

Test API in the fur modifier for creating custom guide curves with python.

The fur modifier is just a testbed for the underlying hair system.
The API is intended to allow specifying guide curves with python scripts
without having to worry about inconsistent state. All curves are first
defined in a python-friendly way, then applied to the hair system in one step.

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

M	source/blender/blenloader/intern/readfile.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_hair.c
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_fur.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 452ce42d5a3..2f11797cddd 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5564,6 +5564,8 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
 			direct_link_hair(fd, fmd->hair_system);
 			
 			fmd->draw_settings = newdataadr(fd, fmd->draw_settings);
+
+			BLI_listbase_clear(&fmd->guide_curves); // runtime
 		}
 	}
 }
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 44627812a21..f3f507bf95a 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1624,6 +1624,17 @@ enum {
 	(MOD_MESHSEQ_READ_VERT | MOD_MESHSEQ_READ_POLY | MOD_MESHSEQ_READ_UV | MOD_MESHSEQ_READ_COLOR)
 
 /* Fur modifier */
+typedef struct FurModifierGuideCurve {
+	struct FurModifierGuideCurve *next, *prev;
+	
+	/* Index for the mesh sample buffer */
+	int mesh_sample_index;
+	/* Number of vertices in the curve */
+	int numverts;
+	/* Vertex array */
+	struct HairGuideVertex *verts;
+} FurModifierGuideCurve;
+
 typedef struct FurModifierData {
 	ModifierData modifier;
 	
@@ -1639,6 +1650,8 @@ typedef struct FurModifierData {
 
 	int guides_count;
 	int pad2;
+
+	ListBase guide_curves;
 } FurModifierData;
 
 #endif  /* __DNA_MODIFIER_TYPES_H__ */
diff --git a/source/blender/makesrna/intern/rna_hair.c b/source/blender/makesrna/intern/rna_hair.c
index 079ce5c6a07..db641c35dce 100644
--- a/source/blender/makesrna/intern/rna_hair.c
+++ b/source/blender/makesrna/intern/rna_hair.c
@@ -208,7 +208,7 @@ static void rna_def_hair_draw_settings(BlenderRNA *brna)
 	    {HAIR_DRAW_FOLLICLE_NONE, "NONE", 0, "None", ""},
 	    {HAIR_DRAW_FOLLICLE_POINTS, "POINTS", 0, "Points", "Draw a point for each follicle"},
 	    {HAIR_DRAW_FOLLICLE_AXES, "AXES", 0, "Axes", "Draw direction of hair for each follicle"},
-		{0, NULL, 0, NULL, NULL}
+	    {0, NULL, 0, NULL, NULL}
 	};
 	
 	srna = RNA_def_struct(brna, "HairDrawSettings", NULL);
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 579c865e679..8dd3caa60ef 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -281,12 +281,17 @@ const EnumPropertyItem rna_enum_axis_flag_xyz_items[] = {
 
 #ifdef RNA_RUNTIME
 
+#include "BLI_listbase.h"
+
 #include "DNA_particle_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_smoke_types.h"
+#include "DNA_hair_types.h"
+#include "DNA_meshdata_types.h"
 
 #include "BKE_cachefile.h"
 #include "BKE_context.h"
+#include "BKE_hair.h"
 #include "BKE_library.h"
 #include "BKE_modifier.h"
 #include "BKE_object.h"
@@ -1160,6 +1165,53 @@ static void rna_MeshSequenceCache_object_path_update(Main *bmain, Scene *scene,
 	rna_Modifier_update(bmain, scene, ptr);
 }
 
+static void rna_Fur_guide_curves_clear(FurModifierData *fmd)
+{
+	for (FurModifierGuideCurve* curve = fmd->guide_curves.first; curve; curve = curve->next)
+	{
+		if (curve->verts)
+		{
+			MEM_freeN(curve->verts);
+		}
+	}
+	BLI_freelistN(&fmd->guide_curves);
+}
+
+static void rna_Fur_guide_curves_new(FurModifierData *fmd, ReportList *UNUSED(reports), int numverts)
+{
+	FurModifierGuideCurve *curve = MEM_callocN(sizeof(FurModifierGuideCurve), "fur guide curve");
+	curve->numverts = numverts;
+	curve->verts = MEM_callocN(sizeof(HairGuideVertex) * numverts, "fur guide curve vertices");
+	
+	BLI_addtail(&fmd->guide_curves, curve);
+}
+
+static void rna_Fur_guide_curves_apply(FurModifierData *fmd, ReportList *UNUSED(reports))
+{
+	const int totcurves = BLI_listbase_count(&fmd->guide_curves);
+	int i = 0;
+	
+	MeshSample msample;
+	memset(&msample, 0, sizeof(msample));
+	
+	BKE_hair_guide_curves_begin(fmd->hair_system, totcurves);
+	i = 0;
+	for (FurModifierGuideCurve *curve = fmd->guide_curves.first; curve; curve = curve->next, ++i)
+	{
+		BKE_hair_set_guide_curve(fmd->hair_system, i, &msample, curve->numverts);
+	}
+	BKE_hair_guide_curves_end(fmd->hair_system);
+	
+	i = 0;
+	for (FurModifierGuideCurve *curve = fmd->guide_curves.first; curve; curve = curve->next)
+	{
+		for (int j = 0; j < curve->numverts; ++j, ++i)
+		{
+			BKE_hair_set_guide_vertex(fmd->hair_system, i, curve->verts[j].flag, curve->verts[j].co);
+		}
+	}
+}
+
 #else
 
 static PropertyRNA *rna_def_property_subdivision_common(StructRNA *srna, const char type[])
@@ -4809,6 +4861,52 @@ static void rna_def_modifier_surfacedeform(BlenderRNA *brna)
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 }
 
+static void rna_def_modifier_fur_guide_curve(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+	srna = RNA_def_struct(brna, "FurModifierGuideCurve", NULL);
+	RNA_def_struct_ui_text(srna, "Fur Modifier Guide Curve", "");
+	RNA_def_struct_sdna(srna, "FurModifierGuideCurve");
+	
+	prop = RNA_def_property(srna, "vertices", PROP_COLLECTION, PROP_NONE);
+	RNA_def_property_collection_sdna(prop, NULL, "verts", "numverts");
+	RNA_def_property_struct_type(prop, "FurModifierGuideVertex");
+	RNA_def_property_ui_text(prop, "Vertices", "Guide vertices");
+
+
+	srna = RNA_def_struct(brna, "FurModifierGuideVertex", NULL);
+	RNA_def_struct_ui_text(srna, "Fur Modifier Guide Vertex", "");
+	RNA_def_struct_sdna(srna, "HairGuideVertex");
+	
+	prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
+	RNA_def_property_float_sdna(prop, NULL, "co");
+	RNA_def_property_ui_text(prop, "Location", "Location of the vertex relative to the root");
+}
+
+static void rna_def_modifier_fur_guide_curves_api(BlenderRNA *brna, PropertyRNA *cprop)
+{
+	StructRNA *srna;
+	FunctionRNA *func;
+	PropertyRNA *parm;
+	
+	RNA_def_property_srna(cprop, "FurModifierGuideCurves");
+	srna = RNA_def_struct(brna, "FurModifierGuideCurves", NULL);
+	RNA_def_struct_ui_text(srna, "Fur Modifier Guide Curves", "");
+	RNA_def_struct_sdna(srna, "FurModifierData");
+	
+	/*func =*/ RNA_def_function(srna, "clear", "rna_Fur_guide_curves_clear");
+	
+	func = RNA_def_function(srna, "new", "rna_Fur_guide_curves_new");
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
+	parm = RNA_def_int(func, "vertex_count", 2, 0, INT_MAX, "Vertex Count", "Number of vertices", 2, 1000);
+	RNA_def_property_flag(parm, PARM_REQUIRED);
+	
+	func = RNA_def_function(srna, "apply", "rna_Fur_guide_curves_apply");
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
+}
+
 static void rna_def_modifier_fur(BlenderRNA *brna)
 {
 	StructRNA *srna;
@@ -4842,6 +4940,14 @@ static void rna_def_modifier_fur(BlenderRNA *brna)
 	prop = RNA_def_property(srna, "draw_settings", PROP_POINTER, PROP_NONE);
 	RNA_def_property_ui_text(prop, "Draw Settings", "Hair draw settings");
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
+	prop = RNA_def_property(srna, "guide_curves", PROP_COLLECTION, PROP_NONE);
+	RNA_def_property_collection_sdna(prop, NULL, "guide_curves", NULL);
+	RNA_def_property_struct_type(prop, "FurModifierGuideCurve");
+	RNA_def_property_ui_text(prop, "Guide Curves", "Guide curve data");
+	rna_def_modifier_fur_guide_curves_api(brna, prop);
+
+	rna_def_modifier_fur_guide_curve(brna);
 }
 
 void RNA_def_modifier(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_fur.c b/source/blender/modifiers/intern/MOD_fur.c
index 3334a60d735..4197e69b7ef 100644
--- a/source/blender/modifiers/intern/MOD_fur.c
+++ b/source/blender/modifiers/intern/MOD_fur.c
@@ -35,6 +35,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_utildefines.h"
+#include "BLI_listbase.h"
 
 #include "DNA_object_types.h"
 #include "DNA_hair_types.h"
@@ -99,6 +100,14 @@ static void freeData(ModifierData *md)
 	{
 		BKE_hair_draw_settings_free(fmd->draw_settings);
 	}
+	for (FurModifierGuideCurve *curve = fmd->guide_curves.first; curve; curve = curve->next)
+	{
+		if (curve->verts)
+		{
+			MEM_freeN(curve->verts);
+		}
+	}
+	BLI_freelistN(&fmd->guide_curves);
 }
 
 static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx),



More information about the Bf-blender-cvs mailing list