Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJanne Karhu <jhkarh@gmail.com>2009-07-21 03:52:53 +0400
committerJanne Karhu <jhkarh@gmail.com>2009-07-21 03:52:53 +0400
commitb4353a84439085ac7d4bb7da2daed983637a75cc (patch)
tree01e560f80b4c190cddae071c7ca41cd5840fe1ec /source/blender/blenkernel/intern/particle.c
parent01b787636b468a1d37a27bb7601de5b0dea9c4b0 (diff)
Initial code for boids v2
Too many new features to list! But here are the biggies: - Boids can move on air and/or land, or climb a goal object. - Proper interaction with collision objects. * Closest collision object in negative z direction is considered as ground. * Other collision objects are obstacles and boids collide with them. - Boid behavior rules are now added to a dynamic list. * Many new rules and many still not implemented. * Different rule evaluation modes (fuzzy, random, average). - Only particle systems defined by per system "boid relations" are considered for simulation of that system. * This is in addition to the boids own system of course. * Relations define other systems as "neutral", "friend" or "enemy". - All effectors now effect boid physics, not boid brains. * This allows forcing boids somewhere. * Exception to this is new "boid" effector, which defines boid predators (positive strength) and goals (negative strength). Known issue: - Boid health isn't yet stored in pointcache so simulations with "fight" rule are not be read from cache properly. - Object/Group visualization object's animation is not played in "particle time". This is definately the wanted behavior, but isn't possible with the current state of dupliobject code. Other new features: - Particle systems can now be named separately from particle settings. * Default name for particle settings is now "ParticleSettings" instead of "PSys" - Per particle system list of particle effector weights. * Enables different effection strengths for particles from different particle systems with without messing around with effector group setting. Other code changes: - KDTree now supports range search as it's needed for new boids. - "Keyed particle targets" renamed as general "particle targets", as they're needed for boids too. (this might break some files saved with new keyed particles) Bug fixes: - Object & group visualizations didn't work. - Interpolating pointcache didn't do rotation.
Diffstat (limited to 'source/blender/blenkernel/intern/particle.c')
-rw-r--r--source/blender/blenkernel/intern/particle.c55
1 files changed, 31 insertions, 24 deletions
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index da14ac46550..6e8f9ee213c 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -36,6 +36,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_scene_types.h"
+#include "DNA_boid_types.h"
#include "DNA_particle_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
@@ -58,6 +59,7 @@
#include "BKE_anim.h"
+#include "BKE_boids.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_lattice.h"
@@ -355,10 +357,13 @@ void psys_free_settings(ParticleSettings *part)
MEM_freeN(part->pd);
part->pd = NULL;
}
+
if(part->pd2) {
MEM_freeN(part->pd2);
part->pd2 = NULL;
}
+
+ boid_free_settings(part->boids);
}
void free_hair(ParticleSystem *psys, int softbody)
@@ -439,6 +444,9 @@ void psys_free(Object *ob, ParticleSystem * psys)
psys->free_edit(psys);
if(psys->particles){
+ if(psys->particles->boid)
+ MEM_freeN(psys->particles->boid);
+
MEM_freeN(psys->particles);
psys->particles = 0;
psys->totpart = 0;
@@ -479,8 +487,10 @@ void psys_free(Object *ob, ParticleSystem * psys)
if(psys->pointcache)
BKE_ptcache_free(psys->pointcache);
- if(psys->keyed_targets.first)
- BLI_freelistN(&psys->keyed_targets);
+ if(psys->targets.first)
+ BLI_freelistN(&psys->targets);
+
+ BLI_kdtree_free(psys->tree);
MEM_freeN(psys);
}
@@ -1043,21 +1053,21 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData
real_t = pind->kkey[0]->time + t * (pind->kkey[0][pa->totkey-1].time - pind->kkey[0]->time);
if(psys->part->phystype==PART_PHYS_KEYED && psys->flag & PSYS_KEYED_TIMING) {
- KeyedParticleTarget *kpt = psys->keyed_targets.first;
+ ParticleTarget *pt = psys->targets.first;
- kpt=kpt->next;
+ pt=pt->next;
- while(kpt && pa->time + kpt->time < real_t)
- kpt= kpt->next;
+ while(pt && pa->time + pt->time < real_t)
+ pt= pt->next;
- if(kpt) {
- kpt=kpt->prev;
+ if(pt) {
+ pt=pt->prev;
- if(pa->time + kpt->time + kpt->duration > real_t)
- real_t = pa->time + kpt->time;
+ if(pa->time + pt->time + pt->duration > real_t)
+ real_t = pa->time + pt->time;
}
else
- real_t = pa->time + ((KeyedParticleTarget*)psys->keyed_targets.last)->time;
+ real_t = pa->time + ((ParticleTarget*)psys->targets.last)->time;
}
CLAMP(real_t, pa->time, pa->dietime);
@@ -3028,7 +3038,12 @@ void object_add_particle_system(Scene *scene, Object *ob)
psys->pointcache = BKE_ptcache_add();
BLI_addtail(&ob->particlesystem, psys);
- psys->part = psys_new_settings("PSys", NULL);
+ psys->part = psys_new_settings("ParticleSettings", NULL);
+
+ if(BLI_countlist(&ob->particlesystem)>1)
+ sprintf(psys->name, "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
+ else
+ strcpy(psys->name, "ParticleSystem");
md= modifier_new(eModifierType_ParticleSystem);
sprintf(md->name, "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
@@ -3099,14 +3114,8 @@ static void default_particle_settings(ParticleSettings *part)
part->reactevent= PART_EVENT_DEATH;
part->disp=100;
part->from= PART_FROM_FACE;
- part->nbetween= 4;
- part->boidneighbours= 5;
part->normfac= 1.0f;
- part->max_vel = 10.0f;
- part->average_vel = 0.3f;
- part->max_tan_acc = 0.2f;
- part->max_lat_acc = 1.0f;
part->reactshape=1.0f;
@@ -3136,13 +3145,9 @@ static void default_particle_settings(ParticleSettings *part)
part->keyed_loops = 1;
- part->banking=1.0;
- part->max_bank=1.0;
+ for(i=0; i<10; i++)
+ part->effector_weight[i]=1.0f;
- for(i=0; i<BOID_TOT_RULES; i++){
- part->boidrule[i]=(char)i;
- part->boidfac[i]=0.5;
- }
#if 0 // XXX old animation system
part->ipo = NULL;
@@ -3176,6 +3181,8 @@ ParticleSettings *psys_copy_settings(ParticleSettings *part)
partn= copy_libblock(part);
if(partn->pd) partn->pd= MEM_dupallocN(part->pd);
if(partn->pd2) partn->pd2= MEM_dupallocN(part->pd2);
+
+ partn->boids = boid_copy_settings(part->boids);
return partn;
}