Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Mon, 4 Jun 2018 15:58:07 +0000 (17:58 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 4 Jun 2018 15:58:07 +0000 (17:58 +0200)
source/blender/blenkernel/BKE_particle.h
source/blender/blenkernel/intern/particle_system.c
source/blender/makesrna/intern/rna_particle.c

index 4820f0173bfd40cc2d267e5caa339473e835938e..d9a5cbab16e78c7b44ef2e4795fee9643597aa99 100644 (file)
@@ -312,6 +312,7 @@ bool psys_check_edited(struct ParticleSystem *psys);
 
 void psys_check_group_weights(struct ParticleSettings *part);
 int psys_uses_gravity(struct ParticleSimulationData *sim);
+void BKE_particlesettings_fluid_default_settings(struct ParticleSettings *part);
 
 /* free */
 void BKE_particlesettings_free(struct ParticleSettings *part);
index 88fc8c6a4401966ddf2270fa123f430eac29aced..a2d9891ec2d51aed55e0794360bdf4476e6bba0f 100644 (file)
@@ -4150,7 +4150,7 @@ void psys_check_boid_data(ParticleSystem *psys)
                }
 }
 
-static void fluid_default_settings(ParticleSettings *part)
+void BKE_particlesettings_fluid_default_settings(ParticleSettings *part)
 {
        SPHFluidSettings *fluid = part->fluid;
 
@@ -4182,24 +4182,12 @@ static void psys_prepare_physics(ParticleSimulationData *sim)
                sim->psys->flag &= ~PSYS_KEYED;
        }
 
-       if (part->phystype == PART_PHYS_BOIDS && part->boids == NULL) {
-               BoidState *state;
-
-               part->boids = MEM_callocN(sizeof(BoidSettings), "Boid Settings");
-               boid_default_settings(part->boids);
-
-               state = boid_new_state(part->boids);
-               BLI_addtail(&state->rules, boid_new_rule(eBoidRuleType_Separate));
-               BLI_addtail(&state->rules, boid_new_rule(eBoidRuleType_Flock));
-
-               ((BoidRule*)state->rules.first)->flag |= BOIDRULE_CURRENT;
-
-               state->flag |= BOIDSTATE_CURRENT;
-               BLI_addtail(&part->boids->states, state);
+       /* RNA Update must ensure this is true. */
+       if (part->phystype == PART_PHYS_BOIDS) {
+               BLI_assert(part->boids != NULL);
        }
-       else if (part->phystype == PART_PHYS_FLUID && part->fluid == NULL) {
-               part->fluid = MEM_callocN(sizeof(SPHFluidSettings), "SPH Fluid Settings");
-               fluid_default_settings(part);
+       else if (part->phystype == PART_PHYS_FLUID) {
+               BLI_assert(part->fluid != NULL);
        }
 
        psys_check_boid_data(sim->psys);
index 3af0ac63d9610eb095d37239451173a091e7a340..4f9ac94dec1c390d95ffb97c44e48088f335230d 100644 (file)
@@ -134,6 +134,7 @@ static const EnumPropertyItem part_hair_ren_as_items[] = {
 
 #include "BLI_math.h"
 
+#include "BKE_boids.h"
 #include "BKE_context.h"
 #include "BKE_cloth.h"
 #include "BKE_colortools.h"
@@ -638,9 +639,31 @@ static void rna_Particle_change_type(Main *bmain, Scene *UNUSED(scene), PointerR
        DEG_relations_tag_update(bmain);
 }
 
-static void rna_Particle_change_physics(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_Particle_change_physics_type(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
        particle_recalc(bmain, scene, ptr, PSYS_RECALC_RESET | PSYS_RECALC_PHYS);
+       
+       ParticleSettings *part = (ParticleSettings *)ptr->data;
+
+       if (part->phystype == PART_PHYS_BOIDS && part->boids == NULL) {
+               BoidState *state;
+
+               part->boids = MEM_callocN(sizeof(BoidSettings), "Boid Settings");
+               boid_default_settings(part->boids);
+
+               state = boid_new_state(part->boids);
+               BLI_addtail(&state->rules, boid_new_rule(eBoidRuleType_Separate));
+               BLI_addtail(&state->rules, boid_new_rule(eBoidRuleType_Flock));
+
+               ((BoidRule*)state->rules.first)->flag |= BOIDRULE_CURRENT;
+
+               state->flag |= BOIDSTATE_CURRENT;
+               BLI_addtail(&part->boids->states, state);
+       }
+       else if (part->phystype == PART_PHYS_FLUID && part->fluid == NULL) {
+               part->fluid = MEM_callocN(sizeof(SPHFluidSettings), "SPH Fluid Settings");
+               BKE_particlesettings_fluid_default_settings(part);
+       }
 }
 
 static void rna_Particle_redo_child(Main *bmain, Scene *scene, PointerRNA *ptr)
@@ -2227,7 +2250,7 @@ static void rna_def_particle_settings(BlenderRNA *brna)
        RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
        RNA_def_property_enum_items(prop, phys_type_items);
        RNA_def_property_ui_text(prop, "Physics Type", "Particle physics type");
-       RNA_def_property_update(prop, 0, "rna_Particle_change_physics");
+       RNA_def_property_update(prop, 0, "rna_Particle_change_physics_type");
 
        prop = RNA_def_property(srna, "rotation_mode", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "rotmode");