[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20615] branches/blender2.5/blender/source /blender/makesrna: RNA:
Brecht Van Lommel
brecht at blender.org
Thu Jun 4 01:22:43 CEST 2009
Revision: 20615
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20615
Author: blendix
Date: 2009-06-04 01:22:43 +0200 (Thu, 04 Jun 2009)
Log Message:
-----------
RNA:
* Added a MaterialSlot collection in Object rather than giving
the list of materials immediately. This should more correctly
reflect how this data is organized, even though there is no
equivalent C struct.
* Added name properties to MaterialSlot/TextureSlot/ParticleSystem.
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
branches/blender2.5/blender/source/blender/makesrna/intern/rna_object.c
branches/blender2.5/blender/source/blender/makesrna/intern/rna_particle.c
branches/blender2.5/blender/source/blender/makesrna/intern/rna_texture.c
Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_access.h 2009-06-03 23:16:51 UTC (rev 20614)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_access.h 2009-06-03 23:22:43 UTC (rev 20615)
@@ -156,6 +156,7 @@
extern StructRNA RNA_MaterialHalo;
extern StructRNA RNA_MaterialRaytraceMirror;
extern StructRNA RNA_MaterialRaytraceTransparency;
+extern StructRNA RNA_MaterialSlot;
extern StructRNA RNA_MaterialStrand;
extern StructRNA RNA_MaterialSubsurfaceScattering;
extern StructRNA RNA_MaterialTextureSlot;
Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_object.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_object.c 2009-06-03 23:16:51 UTC (rev 20614)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_object.c 2009-06-03 23:22:43 UTC (rev 20615)
@@ -22,6 +22,7 @@
* ***** END GPL LICENSE BLOCK *****
*/
+#include <stdio.h>
#include <stdlib.h>
#include "RNA_define.h"
@@ -30,6 +31,7 @@
#include "rna_internal.h"
#include "DNA_customdata_types.h"
+#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_property_types.h"
@@ -175,7 +177,7 @@
static PointerRNA rna_Object_active_material_get(PointerRNA *ptr)
{
Object *ob= (Object*)ptr->id.data;
- return rna_pointer_inherit_refine(ptr, &RNA_Material, give_current_material(ob, ob->actcol));
+ return rna_pointer_inherit_refine(ptr, &RNA_MaterialSlot, ob->mat+ob->actcol);
}
#if 0
@@ -187,22 +189,70 @@
}
#endif
-static int rna_Object_active_material_link_get(PointerRNA *ptr)
+static PointerRNA rna_MaterialSlot_material_get(PointerRNA *ptr)
{
Object *ob= (Object*)ptr->id.data;
- return (ob->colbits & 1<<(ob->actcol)) != 0;
+ Material *ma;
+ int index= (Material**)ptr->data - ob->mat;
+
+ ma= give_current_material(ob, index+1);
+ return rna_pointer_inherit_refine(ptr, &RNA_Material, ma);
}
-static void rna_Object_active_material_link_set(PointerRNA *ptr, int value)
+static void rna_MaterialSlot_material_set(PointerRNA *ptr, PointerRNA value)
{
Object *ob= (Object*)ptr->id.data;
+ int index= (Material**)ptr->data - ob->mat;
+
+ assign_material(ob, value.data, index+1);
+}
+
+static int rna_MaterialSlot_link_get(PointerRNA *ptr)
+{
+ Object *ob= (Object*)ptr->id.data;
+ int index= (Material**)ptr->data - ob->mat;
+
+ return (ob->colbits & (1<<index)) != 0;
+}
+
+static void rna_MaterialSlot_link_set(PointerRNA *ptr, int value)
+{
+ Object *ob= (Object*)ptr->id.data;
+ int index= (Material**)ptr->data - ob->mat;
if(value)
- ob->colbits |= (1<<(ob->actcol));
+ ob->colbits |= (1<<index);
else
- ob->colbits &= ~(1<<(ob->actcol));
+ ob->colbits &= ~(1<<index);
}
+static int rna_MaterialSlot_name_length(PointerRNA *ptr)
+{
+ Object *ob= (Object*)ptr->id.data;
+ Material *ma;
+ int index= (Material**)ptr->data - ob->mat;
+
+ ma= give_current_material(ob, index+1);
+
+ if(ma)
+ return strlen(ma->id.name+2) + 10;
+
+ return 10;
+}
+
+static void rna_MaterialSlot_name_get(PointerRNA *ptr, char *str)
+{
+ Object *ob= (Object*)ptr->id.data;
+ Material *ma;
+ int index= (Material**)ptr->data - ob->mat;
+
+ sprintf(str, "%d: ", index+1);
+
+ ma= give_current_material(ob, index+1);
+ if(ma)
+ strcat(str, ma->id.name+2);
+}
+
static PointerRNA rna_Object_active_particle_system_get(PointerRNA *ptr)
{
Object *ob= (Object*)ptr->id.data;
@@ -275,6 +325,42 @@
RNA_def_property_ui_text(prop, "Index", "Index number of the vertex group.");
}
+static void rna_def_material_slot(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ static EnumPropertyItem link_items[] = {
+ {0, "DATA", "Data", ""},
+ {1, "OBJECT", "Object", ""},
+ {0, NULL, NULL, NULL}};
+
+ /* NOTE: there is no MaterialSlot equivalent in DNA, so the internal
+ * pointer data points to ob->mat + index, and we manually implement
+ * get/set for the properties. */
+
+ srna= RNA_def_struct(brna, "MaterialSlot", NULL);
+ RNA_def_struct_ui_text(srna, "Material Slot", "Material slot in an object.");
+ RNA_def_struct_ui_icon(srna, ICON_MATERIAL_DATA);
+
+ prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "Material");
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_pointer_funcs(prop, "rna_MaterialSlot_material_get", "rna_MaterialSlot_material_set");
+ RNA_def_property_ui_text(prop, "Material", "Material datablock used by this material slot.");
+
+ prop= RNA_def_property(srna, "link", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, link_items);
+ RNA_def_property_enum_funcs(prop, "rna_MaterialSlot_link_get", "rna_MaterialSlot_link_set", NULL);
+ RNA_def_property_ui_text(prop, "Link", "Link material to object or the object's data.");
+
+ prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop, "rna_MaterialSlot_name_get", "rna_MaterialSlot_name_length", NULL);
+ RNA_def_property_ui_text(prop, "Name", "Material slot name.");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_struct_name_property(srna, prop);
+}
+
static void rna_def_object_game_settings(BlenderRNA *brna)
{
StructRNA *srna;
@@ -508,11 +594,6 @@
{OB_BOUND_POLYH, "POLYHEDER", "Polyheder", ""},
{0, NULL, NULL, NULL}};
- static EnumPropertyItem material_link_items[] = {
- {0, "DATA", "Data", ""},
- {1, "OBJECT", "Object", ""},
- {0, NULL, NULL, NULL}};
-
static EnumPropertyItem dupli_items[] = {
{0, "NONE", "None", ""},
{OB_DUPLIFRAMES, "FRAMES", "Frames", "Make copy of object for every frame."},
@@ -590,27 +671,22 @@
RNA_def_property_ui_text(prop, "Proxy Group", "Library group duplicator object this proxy object controls.");
/* materials */
-
prop= RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol");
- RNA_def_property_struct_type(prop, "Material");
- RNA_def_property_ui_text(prop, "Materials", "");
+ RNA_def_property_struct_type(prop, "MaterialSlot");
+ RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_iterator_array_get", 0, 0, 0); /* don't dereference pointer! */
+ RNA_def_property_ui_text(prop, "Materials", "Material slots in the object.");
prop= RNA_def_property(srna, "active_material", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Material");
+ RNA_def_property_struct_type(prop, "MaterialSlot");
RNA_def_property_pointer_funcs(prop, "rna_Object_active_material_get", NULL);
RNA_def_property_ui_text(prop, "Active Material", "Active material being displayed.");
prop= RNA_def_property(srna, "active_material_index", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "actcol");
RNA_def_property_int_funcs(prop, NULL, NULL, "rna_Object_active_material_index_range");
- RNA_def_property_ui_text(prop, "Active Material Index", "Index of active material.");
+ RNA_def_property_ui_text(prop, "Active Material Index", "Index of active material slot.");
- prop= RNA_def_property(srna, "active_material_link", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_items(prop, material_link_items);
- RNA_def_property_enum_funcs(prop, "rna_Object_active_material_link_get", "rna_Object_active_material_link_set", NULL);
- RNA_def_property_ui_text(prop, "Active Material Link", "Use material from object or data for the active material.");
-
/* transform */
prop= RNA_def_property(srna, "location", PROP_FLOAT, PROP_VECTOR);
@@ -971,6 +1047,7 @@
rna_def_object(brna);
rna_def_object_game_settings(brna);
rna_def_vertex_group(brna);
+ rna_def_material_slot(brna);
}
#endif
Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_particle.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_particle.c 2009-06-03 23:16:51 UTC (rev 20614)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_particle.c 2009-06-03 23:22:43 UTC (rev 20615)
@@ -22,6 +22,7 @@
* ***** END GPL LICENSE BLOCK *****
*/
+#include <stdio.h>
#include <stdlib.h>
#include "limits.h"
@@ -33,6 +34,7 @@
#include "DNA_particle_types.h"
#include "DNA_object_force.h"
+#include "DNA_object_types.h"
#ifdef RNA_RUNTIME
@@ -86,6 +88,29 @@
ParticleSettings *settings = (ParticleSettings*)ptr->data;
return settings->draw_line[1];
}
+
+static int rna_ParticleSystem_name_length(PointerRNA *ptr)
+{
+ ParticleSystem *psys= ptr->data;
+
+ if(psys->part)
+ return strlen(psys->part->id.name+2) + 10;
+
+ return 10;
+}
+
+static void rna_ParticleSystem_name_get(PointerRNA *ptr, char *str)
+{
+ Object *ob= ptr->id.data;
+ ParticleSystem *psys= ptr->data;
+ int index= BLI_findindex(&ob->particlesystem, psys);
+
+ sprintf(str, "%d: ", index+1);
+
+ if(psys->part)
+ strcat(str, psys->part->id.name+2);
+}
+
#else
static void rna_def_particle_hair_key(BlenderRNA *brna)
@@ -1176,7 +1201,14 @@
srna= RNA_def_struct(brna, "ParticleSystem", NULL);
RNA_def_struct_ui_text(srna, "Particle System", "Particle system in an object.");
+ RNA_def_struct_ui_icon(srna, ICON_PARTICLE_DATA);
+ prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop, "rna_ParticleSystem_name_get", "rna_ParticleSystem_name_length", NULL);
+ RNA_def_property_ui_text(prop, "Name", "Particle system name.");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_struct_name_property(srna, prop);
+
prop= RNA_def_property(srna, "settings", PROP_POINTER, PROP_NEVER_NULL);
RNA_def_property_pointer_sdna(prop, NULL, "part");
RNA_def_property_ui_text(prop, "Settings", "Particle system settings.");
Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_texture.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_texture.c 2009-06-03 23:16:51 UTC (rev 20614)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_texture.c 2009-06-03 23:22:43 UTC (rev 20615)
@@ -23,6 +23,7 @@
*/
#include <float.h>
+#include <stdio.h>
#include <stdlib.h>
#include "RNA_define.h"
@@ -30,8 +31,11 @@
#include "rna_internal.h"
+#include "DNA_brush_types.h"
+#include "DNA_lamp_types.h"
#include "DNA_material_types.h"
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list