diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-04-18 13:14:28 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-04-19 11:51:18 +0300 |
commit | 63225d7c8b3a45e8189476d537585b011993fb17 (patch) | |
tree | 905d1494b20ded621bf1f41d4f98e3ecbaa1f650 /source/blender/makesrna/intern/rna_modifier.c | |
parent | fcac9e841040812f227ecc3f10d4a970b9e174fd (diff) |
Port particle instance modifier changes from Gooseberry branch
The work is mainly from Lukas Toenne, with some modifications from myself.
Includes following obvious changes:
- Particle system selection is now name-based, with lookup menu.
- Lots of new options to control varieties.
Changes comparing to the Gooseberry branch:
- Default values and versioning code ensures same behavior as the
old modifier.
- Custom data layers are coming from vertex color, the modifier
does not create arbitrary layers now. The hope is to keep data
more manageable, and maybe make it easier to select in the shader
later on.
This means, values are quantized to 256 values, but it should be
enough to get varieties in practice.
Reviewers: brecht, campbellbarton
Reviewed By: brecht
Subscribers: eyecandy
Differential Revision: https://developer.blender.org/D3157
Diffstat (limited to 'source/blender/makesrna/intern/rna_modifier.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_modifier.c | 95 |
1 files changed, 93 insertions, 2 deletions
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 2f92c47eed9..0ebd29b200c 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -1155,6 +1155,43 @@ static void rna_MeshSequenceCache_object_path_update(Main *bmain, Scene *scene, rna_Modifier_update(bmain, scene, ptr); } +static int rna_ParticleInstanceModifier_particle_system_poll(PointerRNA *ptr, const PointerRNA value) +{ + ParticleInstanceModifierData *psmd = ptr->data; + ParticleSystem *psys = value.data; + + if (!psmd->ob) + return false; + + /* make sure psys is in the object */ + return BLI_findindex(&psmd->ob->particlesystem, psys) >= 0; +} + +static PointerRNA rna_ParticleInstanceModifier_particle_system_get(PointerRNA *ptr) +{ + ParticleInstanceModifierData *psmd = ptr->data; + ParticleSystem *psys; + PointerRNA rptr; + + if (!psmd->ob) + return PointerRNA_NULL; + + psys = BLI_findlink(&psmd->ob->particlesystem, psmd->psys - 1); + RNA_pointer_create((ID *)psmd->ob, &RNA_ParticleSystem, psys, &rptr); + return rptr; +} + +static void rna_ParticleInstanceModifier_particle_system_set(PointerRNA *ptr, const PointerRNA value) +{ + ParticleInstanceModifierData *psmd = ptr->data; + + if (!psmd->ob) + return; + + psmd->psys = BLI_findindex(&psmd->ob->particlesystem, value.data) + 1; + CLAMP_MIN(psmd->psys, 1); +} + #else static PropertyRNA *rna_def_property_subdivision_common(StructRNA *srna, const char type[]) @@ -2655,6 +2692,12 @@ static void rna_def_modifier_particleinstance(BlenderRNA *brna) StructRNA *srna; PropertyRNA *prop; + 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"); @@ -2669,16 +2712,30 @@ static void rna_def_modifier_particleinstance(BlenderRNA *brna) prop = RNA_def_property(srna, "particle_system_index", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "psys"); - RNA_def_property_range(prop, 1, 10); + RNA_def_property_range(prop, 1, SHRT_MAX); RNA_def_property_ui_text(prop, "Particle System Number", ""); RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "particle_system", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "ParticleSystem"); + RNA_def_property_pointer_funcs(prop, "rna_ParticleInstanceModifier_particle_system_get", "rna_ParticleInstanceModifier_particle_system_set", + NULL, "rna_ParticleInstanceModifier_particle_system_poll"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Particle System", ""); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "axis"); RNA_def_property_enum_items(prop, rna_enum_axis_xyz_items); 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"); @@ -2730,6 +2787,40 @@ 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, "rotation", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_float_sdna(prop, NULL, "rotation"); + RNA_def_property_range(prop, 0.0, 1.0); + RNA_def_property_ui_text(prop, "Rotation", "Rotation around path"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "random_rotation", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_float_sdna(prop, NULL, "random_rotation"); + RNA_def_property_range(prop, 0.0, 1.0); + RNA_def_property_ui_text(prop, "Random Rotation", "Randomize rotation around 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"); + + prop = RNA_def_property(srna, "index_layer_name", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "index_layer_name"); + RNA_def_property_ui_text(prop, "Index Layer Name", "Custom data layer name for the index"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "value_layer_name", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "value_layer_name"); + RNA_def_property_ui_text(prop, "Value Layer Name", "Custom data layer name for the randomized value"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); } static void rna_def_modifier_explode(BlenderRNA *brna) |