[Bf-blender-cvs] [5d4ae82] particles_refactor: Added accessor functions in particle state which allow extending the particle state. These can be used later in python wrappers to support more immediate collection-style access.

Lukas Tönne noreply at git.blender.org
Tue Apr 22 12:05:56 CEST 2014


Commit: 5d4ae82cc0ebef621585b276d5384cee5d61a624
Author: Lukas Tönne
Date:   Mon Dec 16 19:03:59 2013 +0100
https://developer.blender.org/rB5d4ae82cc0ebef621585b276d5384cee5d61a624

Added accessor functions in particle state which allow extending the
particle state. These can be used later in python wrappers to support
more immediate collection-style access.

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

M	source/blender/blenkernel/BKE_nparticle.h
M	source/blender/blenkernel/intern/nparticle.c
M	source/blender/makesrna/intern/rna_nparticle.c

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

diff --git a/source/blender/blenkernel/BKE_nparticle.h b/source/blender/blenkernel/BKE_nparticle.h
index 45ee503..72fa414 100644
--- a/source/blender/blenkernel/BKE_nparticle.h
+++ b/source/blender/blenkernel/BKE_nparticle.h
@@ -57,6 +57,7 @@ struct NParticleAttributeState *BKE_nparticle_state_find_attribute(struct NParti
 int BKE_nparticle_find_index(struct NParticleState *state, NParticleID id);
 bool BKE_nparticle_exists(struct NParticleState *state, NParticleID id);
 int BKE_nparticle_add(struct NParticleState *state, NParticleID id);
+void BKE_nparticle_remove(struct NParticleState *state, NParticleID id);
 
 typedef struct NParticleIterator {
 	struct NParticleState *state;
diff --git a/source/blender/blenkernel/intern/nparticle.c b/source/blender/blenkernel/intern/nparticle.c
index fd40cdd..2e755f9 100644
--- a/source/blender/blenkernel/intern/nparticle.c
+++ b/source/blender/blenkernel/intern/nparticle.c
@@ -325,6 +325,18 @@ int BKE_nparticle_add(NParticleState *state, NParticleID id)
 	return index;
 }
 
+void BKE_nparticle_remove(NParticleState *state, NParticleID id)
+{
+	int index = BKE_nparticle_find_index(state, id);
+	if (index >= 0) {
+		NParticleAttributeState *attrstate;
+		for (attrstate = state->attributes; attrstate->hashkey; ++attrstate) {
+			/* XXX TODO paged buffer doesn't support removing yet */
+//			BLI_pbuf_remove_elements(&attrstate->data, index);
+		}
+	}
+}
+
 
 void BKE_nparticle_iter_init(NParticleState *state, NParticleIterator *it)
 {
diff --git a/source/blender/makesrna/intern/rna_nparticle.c b/source/blender/makesrna/intern/rna_nparticle.c
index d15f9fb..ef1b295 100644
--- a/source/blender/makesrna/intern/rna_nparticle.c
+++ b/source/blender/makesrna/intern/rna_nparticle.c
@@ -322,6 +322,21 @@ int rna_NParticleState_particles_lookup_int(PointerRNA *ptr, int key, PointerRNA
 }
 #endif
 
+static int rna_NParticleState_find_particle(NParticleState *state, int id)
+{
+	return BKE_nparticle_find_index(state, (NParticleID)id);
+}
+
+static int rna_NParticleState_add_particle(NParticleState *state, int id)
+{
+	return BKE_nparticle_add(state, (NParticleID)id);
+}
+
+static void rna_NParticleState_remove_particle(NParticleState *state, int id)
+{
+	BKE_nparticle_remove(state, (NParticleID)id);
+}
+
 
 static NParticleAttribute *rna_NParticleSystem_attributes_new(NParticleSystem *psys, ReportList *reports, const char *name, int datatype)
 {
@@ -525,7 +540,8 @@ static void rna_def_nparticle_iterator(BlenderRNA *brna)
 static void rna_def_nparticle_state(BlenderRNA *brna)
 {
 	StructRNA *srna;
-	PropertyRNA *prop;
+	FunctionRNA *func;
+	PropertyRNA *prop, *parm;
 
 	srna = RNA_def_struct(brna, "NParticleState", NULL);
 	RNA_def_struct_ui_text(srna, "Particle State", "Data in a particle system for a specific frame");
@@ -547,6 +563,27 @@ static void rna_def_nparticle_state(BlenderRNA *brna)
 	                                  "rna_NParticleState_particles_length", "rna_NParticleState_particles_lookup_int",
 	                                  NULL, NULL);
 #endif
+
+	func = RNA_def_function(srna, "find_particle", "rna_NParticleState_find_particle");
+	RNA_def_function_ui_description(func, "Get a particle's index");
+	parm = RNA_def_int(func, "id", 0, INT_MIN, INT_MAX, "Identifier", "Unique identifier of the particle", INT_MIN, INT_MAX);
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	/* return value */
+	parm = RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Index of the particle in attribute states", 0, INT_MAX);
+	RNA_def_function_return(func, parm);
+
+	func = RNA_def_function(srna, "add_particle", "rna_NParticleState_add_particle");
+	RNA_def_function_ui_description(func, "Add a particle");
+	parm = RNA_def_int(func, "id", 0, INT_MIN, INT_MAX, "Identifier", "Unique identifier of the particle", INT_MIN, INT_MAX);
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	/* return value */
+	parm = RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Index of the particle in attribute states", 0, INT_MAX);
+	RNA_def_function_return(func, parm);
+
+	func = RNA_def_function(srna, "remove_particle", "rna_NParticleState_remove_particle");
+	RNA_def_function_ui_description(func, "Remove a particle");
+	parm = RNA_def_int(func, "id", 0, INT_MIN, INT_MAX, "Identifier", "Unique identifier of the particle", INT_MIN, INT_MAX);
+	RNA_def_property_flag(parm, PROP_REQUIRED);
 }




More information about the Bf-blender-cvs mailing list