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)
1  2 
source/blender/blenkernel/BKE_particle.h
source/blender/blenkernel/intern/particle_system.c
source/blender/makesrna/intern/rna_particle.c

@@@ -619,28 -674,37 +620,50 @@@ static void rna_Particle_reset_dependen
        rna_Particle_reset(bmain, scene, ptr);
  }
  
 -static void rna_Particle_change_type(Main *bmain, Scene *scene, PointerRNA *ptr)
 +static void rna_Particle_change_type(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
  {
 -      particle_recalc(bmain, scene, ptr, PSYS_RECALC_RESET | PSYS_RECALC_TYPE);
 -      DAG_relations_tag_update(bmain);
 +      ParticleSettings *part = ptr->id.data;
 +
 +      /* Iterating over all object is slow, but no better solution exists at the moment. */
 +      for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
 +              for (ParticleSystem *psys = ob->particlesystem.first; psys; psys = psys->next) {
 +                      if (psys->part == part) {
 +                              psys_changed_type(ob, psys);
 +                              psys->recalc |= PSYS_RECALC_RESET;
 +                              DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
 +                      }
 +              }
 +      }
 +
 +      WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, NULL);
 +      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)