[Bf-blender-cvs] [80ce351] gooseberry: Partial instancing feature for the ParticleInstance modifier.

Lukas Tönne noreply at git.blender.org
Thu Feb 12 20:23:25 CET 2015


Commit: 80ce3516cc8d9ce8f83e04542b20f70f96091570
Author: Lukas Tönne
Date:   Thu Feb 12 20:20:55 2015 +0100
Branches: gooseberry
https://developer.blender.org/rB80ce3516cc8d9ce8f83e04542b20f70f96091570

Partial instancing feature for the ParticleInstance modifier.

This allows using the same particle system for multiple objects without
creating too much repetitiveness. Each instance object can select a
range of the particles to actually use for instancing (default 1.0 means
all particles are used). To further avoid overlap with multiple
instancing objects, the offset value can be used to make each system
use a specific range of particles.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_particleinstance.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 7374655..2a27610 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -664,6 +664,10 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col.prop(md, "show_unborn")
         col.prop(md, "show_dead")
 
+        row = layout.row(align=True)
+        row.prop(md, "particle_amount", text="Amount")
+        row.prop(md, "particle_offset", text="Offset")
+
         layout.separator()
 
         layout.prop(md, "use_path", text="Create Along Paths")
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 83aa187..c59e92a 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -698,4 +698,20 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 			}
 		}
 	}
+
+	if (!DNA_struct_elem_find(fd->filesdna, "ParticleInstanceModifierData", "float", "particle_amount")) {
+		Object *ob;
+		ModifierData *md;
+		
+		for (ob = main->object.first; ob; ob = ob->id.next) {
+			for (md = ob->modifiers.first; md; md = md->next) {
+				if (md->type == eModifierType_ParticleInstance) {
+					ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md;
+					
+					pimd->particle_amount = 1.0f;
+					pimd->particle_offset = 0.0f;
+				}
+			}
+		}
+	}
 }
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index cd6cda3..e603f3e 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -733,6 +733,7 @@ typedef struct ParticleInstanceModifierData {
 	struct Object *ob;
 	short psys, flag, axis, space;
 	float position, random_position;
+	float particle_amount, particle_offset;
 } ParticleInstanceModifierData;
 
 typedef enum {
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index c6fe00c..3a72119 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -2436,6 +2436,18 @@ static void rna_def_modifier_particleinstance(BlenderRNA *brna)
 	RNA_def_property_range(prop, 0.0, 1.0);
 	RNA_def_property_ui_text(prop, "Random Position", "Randomize position along path");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "particle_amount", PROP_FLOAT, PROP_FACTOR);
+	RNA_def_property_range(prop, 0.0, 1.0);
+	RNA_def_property_ui_text(prop, "Particle Amount", "Amount of particles to use for instancing");
+	RNA_def_property_float_default(prop, 1.0f);
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+	prop = RNA_def_property(srna, "particle_offset", PROP_FLOAT, PROP_FACTOR);
+	RNA_def_property_range(prop, 0.0, 1.0);
+	RNA_def_property_ui_text(prop, "Particle Offset", "Relative offset of particles to use for instancing, to avoid overlap of multiple instances");
+	RNA_def_property_float_default(prop, 0.0f);
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
 static void rna_def_modifier_explode(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c
index 4b6f403..f7092c7 100644
--- a/source/blender/modifiers/intern/MOD_particleinstance.c
+++ b/source/blender/modifiers/intern/MOD_particleinstance.c
@@ -63,6 +63,8 @@ static void initData(ModifierData *md)
 	pimd->position = 1.0f;
 	pimd->axis = 2;
 	pimd->space = eParticleInstanceSpace_Local;
+	pimd->particle_amount = 1.0f;
+	pimd->particle_offset = 0.0f;
 }
 static void copyData(ModifierData *md, ModifierData *target)
 {
@@ -134,9 +136,10 @@ static void foreachObjectLink(ModifierData *md, Object *ob,
 	walk(userData, ob, &pimd->ob);
 }
 
-static int particle_skip(ParticleInstanceModifierData *pimd, ParticleSystem *psys, int p)
+static bool particle_skip(ParticleInstanceModifierData *pimd, ParticleSystem *psys, int p)
 {
 	ParticleData *pa;
+	int totpart, randp, minp, maxp;
 
 	if (pimd->flag & eParticleInstanceFlag_Parents) {
 		if (p >= psys->totpart) {
@@ -161,12 +164,29 @@ static int particle_skip(ParticleInstanceModifierData *pimd, ParticleSystem *psy
 	}
 
 	if (pa) {
-		if (pa->alive == PARS_UNBORN && (pimd->flag & eParticleInstanceFlag_Unborn) == 0) return 1;
-		if (pa->alive == PARS_ALIVE && (pimd->flag & eParticleInstanceFlag_Alive) == 0) return 1;
-		if (pa->alive == PARS_DEAD && (pimd->flag & eParticleInstanceFlag_Dead) == 0) return 1;
+		if (pa->alive == PARS_UNBORN && (pimd->flag & eParticleInstanceFlag_Unborn) == 0) return true;
+		if (pa->alive == PARS_ALIVE && (pimd->flag & eParticleInstanceFlag_Alive) == 0) return true;
+		if (pa->alive == PARS_DEAD && (pimd->flag & eParticleInstanceFlag_Dead) == 0) return true;
 	}
 	
-	return 0;
+	totpart = psys->totpart + psys->totchild;
+	
+	/* TODO make randomization optional? */
+	randp = (int)(psys_frand(psys, 3578 + p) * totpart) % totpart;
+	
+	minp = (int)(totpart * pimd->particle_offset) % (totpart+1);
+	maxp = (int)(totpart * (pimd->particle_offset + pimd->particle_amount)) % (totpart+1);
+	
+	if (maxp > minp) {
+		return randp < minp || randp >= maxp;
+	}
+	else if (maxp < minp) {
+		return randp < minp && randp >= maxp;
+	}
+	else
+		return true;
+	
+	return false;
 }
 
 static DerivedMesh *applyModifier(ModifierData *md, Object *ob,




More information about the Bf-blender-cvs mailing list