[Bf-blender-cvs] [c8d5206] gooseberry: New space enum option for the particle instance modifier, to chose which space the particle data should be interpreted in.

Lukas Tönne noreply at git.blender.org
Wed Feb 4 17:41:23 CET 2015


Commit: c8d520608210c4febe867cd5fb11c911269c685a
Author: Lukas Tönne
Date:   Wed Feb 4 17:37:38 2015 +0100
Branches: gooseberry
https://developer.blender.org/rBc8d520608210c4febe867cd5fb11c911269c685a

New space enum option for the particle instance modifier, to chose which
space the particle data should be interpreted in.

By default the space will now be `Local`, meaning that copies of the
mesh are made with the offset of the respective particle in the particle
object's local space, rather than using the world space offset of the
particle //inside the modified object space//. This behavior is much
more intuitive and consistent with true duplicators, such as face duplis.
Old files will still have `World` setting, so existing blend files are
not changed.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
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 66ecfe7..cb24f4e 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -649,6 +649,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         split = layout.split()
         col = split.column()
         col.label(text="Create From:")
+        layout.prop(md, "space", text="")
         col.prop(md, "use_normal")
         col.prop(md, "use_children")
         col.prop(md, "use_size")
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 47273d3..6867f2a 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -721,11 +721,16 @@ typedef enum {
 	eParticleInstanceFlag_UseSize   = (1 << 7),
 } ParticleInstanceModifierFlag;
 
+typedef enum {
+	eParticleInstanceSpace_World    = 0,
+	eParticleInstanceSpace_Local    = 1,
+} ParticleInstanceModifierSpace;
+
 typedef struct ParticleInstanceModifierData {
 	ModifierData modifier;
 
 	struct Object *ob;
-	short psys, flag, axis, pad;
+	short psys, flag, axis, space;
 	float position, random_position;
 } ParticleInstanceModifierData;
 
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 3cbd117..352f628 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -2345,6 +2345,12 @@ static void rna_def_modifier_particleinstance(BlenderRNA *brna)
 		{0, NULL, 0, NULL, NULL}
 	};
 
+	static EnumPropertyItem particleinstance_space[] = {
+		{eParticleInstanceSpace_Local, "LOCAL", 0, "Local", "Use offset from the particle object in the instance object"},
+		{eParticleInstanceSpace_World, "WORLD", 0, "World", "Use world space offset in the instance object"},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	srna = RNA_def_struct(brna, "ParticleInstanceModifier", "Modifier");
 	RNA_def_struct_ui_text(srna, "ParticleInstance Modifier", "Particle system instancing modifier");
 	RNA_def_struct_sdna(srna, "ParticleInstanceModifierData");
@@ -2367,7 +2373,13 @@ static void rna_def_modifier_particleinstance(BlenderRNA *brna)
 	RNA_def_property_enum_items(prop, particleinstance_axis);
 	RNA_def_property_ui_text(prop, "Axis", "Pole axis for rotation");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
-	
+
+	prop = RNA_def_property(srna, "space", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "space");
+	RNA_def_property_enum_items(prop, particleinstance_space);
+	RNA_def_property_ui_text(prop, "Space", "Space to use for copying mesh data");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
 	prop = RNA_def_property(srna, "use_normal", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", eParticleInstanceFlag_Parents);
 	RNA_def_property_ui_text(prop, "Normal", "Create instances from normal particles");
diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c
index 50c6282..4b6f403 100644
--- a/source/blender/modifiers/intern/MOD_particleinstance.c
+++ b/source/blender/modifiers/intern/MOD_particleinstance.c
@@ -62,7 +62,7 @@ static void initData(ModifierData *md)
 	pimd->psys = 1;
 	pimd->position = 1.0f;
 	pimd->axis = 2;
-
+	pimd->space = eParticleInstanceSpace_Local;
 }
 static void copyData(ModifierData *md, ModifierData *target)
 {
@@ -187,6 +187,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 	short track = ob->trackflag % 3, trackneg, axis = pimd->axis;
 	float max_co = 0.0, min_co = 0.0, temp_co[3];
 	float *size = NULL;
+	float spacemat[4][4];
 
 	trackneg = ((ob->trackflag > 2) ? 1 : 0);
 
@@ -238,6 +239,21 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 		}
 	}
 
+	switch (pimd->space) {
+		case eParticleInstanceSpace_World:
+			/* particle states are in world space already */
+			unit_m4(spacemat);
+			break;
+		case eParticleInstanceSpace_Local:
+			/* get particle states in the particle object's local space */
+			invert_m4_m4(spacemat, pimd->ob->obmat);
+			break;
+		default:
+			/* should not happen */
+			BLI_assert(false);
+			break;
+	}
+
 	totvert = dm->getNumVerts(dm);
 	totpoly = dm->getNumPolys(dm);
 	totloop = dm->getNumLoops(dm);
@@ -385,6 +401,8 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 			if (pimd->flag & eParticleInstanceFlag_UseSize)
 				mul_v3_fl(mv->co, size[p]);
 			add_v3_v3(mv->co, state.co);
+			
+			mul_m4_v3(spacemat, mv->co);
 		}
 
 		/* create polys and loops */




More information about the Bf-blender-cvs mailing list