[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41876] trunk/blender/source/blender/ makesrna/intern/rna_mesh.c: patch [#27708] API for adding mesh properties

Campbell Barton ideasman42 at gmail.com
Tue Nov 15 13:28:13 CET 2011


Revision: 41876
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41876
Author:   campbellbarton
Date:     2011-11-15 12:28:13 +0000 (Tue, 15 Nov 2011)
Log Message:
-----------
patch [#27708] API for adding mesh properties
from Geoffrey Bantle (briggs)

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_mesh.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_mesh.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_mesh.c	2011-11-15 12:20:58 UTC (rev 41875)
+++ trunk/blender/source/blender/makesrna/intern/rna_mesh.c	2011-11-15 12:28:13 UTC (rev 41876)
@@ -1146,6 +1146,45 @@
 	return cdl;
 }
 
+static CustomDataLayer *rna_Mesh_int_property_new(struct Mesh *me, struct bContext *C, const char *name)
+{
+	CustomDataLayer *cdl = NULL;
+	int index;
+
+	CustomData_add_layer_named(&me->fdata, CD_PROP_INT, CD_DEFAULT, NULL, me->totface, name);
+	index = CustomData_get_named_layer_index(&me->fdata, CD_PROP_INT, name);
+
+	cdl = (index == -1) ? NULL : &(me->fdata.layers[index]);
+
+	return cdl;
+}
+
+static CustomDataLayer *rna_Mesh_float_property_new(struct Mesh *me, struct bContext *C, const char *name)
+{
+	CustomDataLayer *cdl = NULL;
+	int index;
+
+	CustomData_add_layer_named(&me->fdata, CD_PROP_FLT, CD_DEFAULT, NULL, me->totface, name);
+	index = CustomData_get_named_layer_index(&me->fdata, CD_PROP_FLT, name);
+
+	cdl = (index == -1) ? NULL : &(me->fdata.layers[index]);
+
+	return cdl;
+}
+
+static CustomDataLayer *rna_Mesh_string_property_new(struct Mesh *me, struct bContext *C, const char *name)
+{
+	CustomDataLayer *cdl = NULL;
+	int index;
+
+	CustomData_add_layer_named(&me->fdata, CD_PROP_STR, CD_DEFAULT, NULL, me->totface, name);
+	index = CustomData_get_named_layer_index(&me->fdata, CD_PROP_STR, name);
+
+	cdl = (index == -1) ? NULL : &(me->fdata.layers[index]);
+
+	return cdl;
+}
+
 static CustomDataLayer *rna_Mesh_uv_texture_new(struct Mesh *me, struct bContext *C, const char *name)
 {
 	CustomData *fdata;
@@ -1750,6 +1789,69 @@
 	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
 }
 
+/* mesh int layers */
+static void rna_def_int_layers(BlenderRNA *brna, PropertyRNA *cprop)
+{
+	StructRNA *srna;
+
+	FunctionRNA *func;
+	PropertyRNA *parm;
+
+	RNA_def_property_srna(cprop, "IntProperties");
+	srna= RNA_def_struct(brna, "IntProperties", NULL);
+	RNA_def_struct_sdna(srna, "Mesh");
+	RNA_def_struct_ui_text(srna, "Int Properties", "Collection of int properties");
+
+	func= RNA_def_function(srna, "new", "rna_Mesh_int_property_new");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+	RNA_def_function_ui_description(func, "Add a integer property layer to Mesh");
+	RNA_def_string(func, "name", "Int Prop", 0, "",  "Int property name");
+	parm= RNA_def_pointer(func, "layer", "MeshIntPropertyLayer", "", "The newly created layer");
+	RNA_def_function_return(func, parm);
+}
+
+/* mesh float layers */
+static void rna_def_float_layers(BlenderRNA *brna, PropertyRNA *cprop)
+{
+	StructRNA *srna;
+
+	FunctionRNA *func;
+	PropertyRNA *parm;
+
+	RNA_def_property_srna(cprop, "FloatProperties");
+	srna= RNA_def_struct(brna, "FloatProperties", NULL);
+	RNA_def_struct_sdna(srna, "Mesh");
+	RNA_def_struct_ui_text(srna, "Float Properties", "Collection of float properties");
+
+	func= RNA_def_function(srna, "new", "rna_Mesh_float_property_new");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+	RNA_def_function_ui_description(func, "Add a float property layer to Mesh");
+	RNA_def_string(func, "name", "Float Prop", 0, "", "Float property name");
+	parm= RNA_def_pointer(func, "layer", "MeshFloatPropertyLayer", "", "The newly created layer");
+	RNA_def_function_return(func, parm);
+}
+
+/* mesh string layers */
+static void rna_def_string_layers(BlenderRNA *brna, PropertyRNA *cprop)
+{
+	StructRNA *srna;
+
+	FunctionRNA *func;
+	PropertyRNA *parm;
+
+	RNA_def_property_srna(cprop, "StringProperties");
+	srna= RNA_def_struct(brna, "StringProperties", NULL);
+	RNA_def_struct_sdna(srna, "Mesh");
+	RNA_def_struct_ui_text(srna, "String Properties", "Collection of string properties");
+
+	func= RNA_def_function(srna, "new", "rna_Mesh_string_property_new");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+	RNA_def_function_ui_description(func, "Add a string property layer to Mesh");
+	RNA_def_string(func, "name", "String Prop", 0, "", "String property name");
+	parm= RNA_def_pointer(func, "layer", "MeshStringPropertyLayer", "", "The newly created layer");
+	RNA_def_function_return(func, parm);
+}
+
 /* mesh.uv_layers */
 static void rna_def_uv_textures(BlenderRNA *brna, PropertyRNA *cprop)
 {
@@ -1876,6 +1978,7 @@
 	                                  "rna_Mesh_float_layers_length", NULL, NULL, NULL);
 	RNA_def_property_struct_type(prop, "MeshFloatPropertyLayer");
 	RNA_def_property_ui_text(prop, "Float Property Layers", "");
+	rna_def_float_layers(brna, prop);
 
 	prop= RNA_def_property(srna, "layers_int", PROP_COLLECTION, PROP_NONE);
 	RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer");
@@ -1883,6 +1986,7 @@
 	                                  "rna_Mesh_int_layers_length", NULL, NULL, NULL);
 	RNA_def_property_struct_type(prop, "MeshIntPropertyLayer");
 	RNA_def_property_ui_text(prop, "Int Property Layers", "");
+	rna_def_int_layers(brna, prop);
 
 	prop= RNA_def_property(srna, "layers_string", PROP_COLLECTION, PROP_NONE);
 	RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer");
@@ -1890,6 +1994,7 @@
 	                                  "rna_Mesh_string_layers_length", NULL, NULL, NULL);
 	RNA_def_property_struct_type(prop, "MeshStringPropertyLayer");
 	RNA_def_property_ui_text(prop, "String Property Layers", "");
+	rna_def_string_layers(brna, prop);
 
 	prop= RNA_def_property(srna, "use_auto_smooth", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_AUTOSMOOTH);




More information about the Bf-blender-cvs mailing list