diff options
author | Janne Karhu <jhkarh@gmail.com> | 2009-07-21 03:52:53 +0400 |
---|---|---|
committer | Janne Karhu <jhkarh@gmail.com> | 2009-07-21 03:52:53 +0400 |
commit | b4353a84439085ac7d4bb7da2daed983637a75cc (patch) | |
tree | 01e560f80b4c190cddae071c7ca41cd5840fe1ec /source/blender/editors | |
parent | 01b787636b468a1d37a27bb7601de5b0dea9c4b0 (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/editors')
-rw-r--r-- | source/blender/editors/include/ED_physics.h | 1 | ||||
-rw-r--r-- | source/blender/editors/physics/physics_boids.c | 433 | ||||
-rw-r--r-- | source/blender/editors/space_api/spacetypes.c | 1 | ||||
-rw-r--r-- | source/blender/editors/space_buttons/buttons_intern.h | 8 | ||||
-rw-r--r-- | source/blender/editors/space_buttons/buttons_ops.c | 112 | ||||
-rw-r--r-- | source/blender/editors/space_buttons/space_buttons.c | 8 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 23 |
7 files changed, 521 insertions, 65 deletions
diff --git a/source/blender/editors/include/ED_physics.h b/source/blender/editors/include/ED_physics.h index b04bfb992dc..6ab804230d0 100644 --- a/source/blender/editors/include/ED_physics.h +++ b/source/blender/editors/include/ED_physics.h @@ -32,6 +32,7 @@ /* operators */ +void ED_operatortypes_boids(void); void ED_operatortypes_pointcache(void); void ED_operatortypes_fluid(void); //void ED_keymap_pointcache(struct wmWindowManager *wm); diff --git a/source/blender/editors/physics/physics_boids.c b/source/blender/editors/physics/physics_boids.c new file mode 100644 index 00000000000..2d3b11080e7 --- /dev/null +++ b/source/blender/editors/physics/physics_boids.c @@ -0,0 +1,433 @@ +/** + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Janne Karhu. + * All rights reserved. + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +//#include <stdlib.h> +//#include <string.h> +// +#include "MEM_guardedalloc.h" + +#include "DNA_boid_types.h" +#include "DNA_particle_types.h" +//#include "DNA_curve_types.h" +#include "DNA_object_types.h" +//#include "DNA_material_types.h" +//#include "DNA_texture_types.h" +#include "DNA_scene_types.h" +//#include "DNA_world_types.h" + +#include "BKE_boids.h" +#include "BKE_context.h" +#include "BKE_depsgraph.h" +//#include "BKE_font.h" +//#include "BKE_library.h" +//#include "BKE_main.h" +//#include "BKE_material.h" +#include "BKE_particle.h" +//#include "BKE_texture.h" +//#include "BKE_utildefines.h" +//#include "BKE_world.h" + +//#include "BLI_editVert.h" +#include "BLI_listbase.h" +// +#include "RNA_access.h" +#include "RNA_enum_types.h" +#include "RNA_define.h" + +#include "WM_api.h" +#include "WM_types.h" + +//#include "ED_curve.h" +//#include "ED_mesh.h" +// +//#include "buttons_intern.h" // own include + +/************************ add/del boid rule operators *********************/ +static int boidrule_add_exec(bContext *C, wmOperator *op) +{ + Scene *scene = CTX_data_scene(C); + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= ptr.data; + Object *ob= ptr.id.data; + ParticleSettings *part; + int type= RNA_enum_get(op->ptr, "type"); + + BoidRule *rule; + BoidState *state; + + if(!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + return OPERATOR_CANCELLED; + + part = psys->part; + + state = boid_get_current_state(part->boids); + + + for(rule=state->rules.first; rule; rule=rule->next) + rule->flag &= ~BOIDRULE_CURRENT; + + rule = boid_new_rule(type); + rule->flag |= BOIDRULE_CURRENT; + + BLI_addtail(&state->rules, rule); + + psys_flush_particle_settings(scene, part, PSYS_RECALC_RESET); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +void BOID_OT_boidrule_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Add Boid Rule"; + ot->description = "Add a boid rule to the current boid state."; + ot->idname= "BOID_OT_boidrule_add"; + + /* api callbacks */ + ot->invoke= WM_menu_invoke; + ot->exec= boidrule_add_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + RNA_def_enum(ot->srna, "type", boidrule_type_items, 0, "Type", ""); +} +static int boidrule_del_exec(bContext *C, wmOperator *op) +{ + Scene *scene = CTX_data_scene(C); + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= ptr.data; + Object *ob = ptr.id.data; + BoidRule *rule; + BoidState *state; + + if(!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + return OPERATOR_CANCELLED; + + state = boid_get_current_state(psys->part->boids); + + + for(rule=state->rules.first; rule; rule=rule->next) { + if(rule->flag & BOIDRULE_CURRENT) { + BLI_remlink(&state->rules, rule); + MEM_freeN(rule); + break; + } + + } + rule = state->rules.first; + + if(rule) + rule->flag |= BOIDRULE_CURRENT; + + DAG_scene_sort(scene); + psys_flush_particle_settings(scene, psys->part, PSYS_RECALC_RESET); + + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +void BOID_OT_boidrule_del(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Remove Boid Rule"; + ot->idname= "BOID_OT_boidrule_del"; + + /* api callbacks */ + ot->exec= boidrule_del_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/************************ move up/down boid rule operators *********************/ +static int boidrule_move_up_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= ptr.data; + Object *ob = ptr.id.data; + BoidRule *rule; + BoidState *state; + + if(!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + return OPERATOR_CANCELLED; + + state = boid_get_current_state(psys->part->boids); + for(rule = state->rules.first; rule; rule=rule->next) { + if(rule->flag & BOIDRULE_CURRENT && rule->prev) { + BLI_remlink(&state->rules, rule); + BLI_insertlink(&state->rules, rule->prev->prev, rule); + + psys_flush_particle_settings(scene, psys->part, PSYS_RECALC_RESET); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + break; + } + } + + return OPERATOR_FINISHED; +} + +void BOID_OT_boidrule_move_up(wmOperatorType *ot) +{ + ot->name= "Move Up Boid Rule"; + ot->description= "Move boid rule up in the list."; + ot->idname= "BOID_OT_boidrule_move_up"; + + ot->exec= boidrule_move_up_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int boidrule_move_down_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= ptr.data; + Object *ob = ptr.id.data; + BoidRule *rule; + BoidState *state; + + if(!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + return OPERATOR_CANCELLED; + + state = boid_get_current_state(psys->part->boids); + for(rule = state->rules.first; rule; rule=rule->next) { + if(rule->flag & BOIDRULE_CURRENT && rule->next) { + BLI_remlink(&state->rules, rule); + BLI_insertlink(&state->rules, rule->next, rule); + + psys_flush_particle_settings(scene, psys->part, PSYS_RECALC_RESET); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + break; + } + } + + return OPERATOR_FINISHED; +} + +void BOID_OT_boidrule_move_down(wmOperatorType *ot) +{ + ot->name= "Move Down Boid Rule"; + ot->description= "Move boid rule down in the list."; + ot->idname= "BOID_OT_boidrule_move_down"; + + ot->exec= boidrule_move_down_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + + +/************************ add/del boid state operators *********************/ +static int boidstate_add_exec(bContext *C, wmOperator *op) +{ + Scene *scene = CTX_data_scene(C); + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= ptr.data; + Object *ob= ptr.id.data; + ParticleSettings *part; + BoidState *state; + + if(!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + return OPERATOR_CANCELLED; + + part = psys->part; + + for(state=part->boids->states.first; state; state=state->next) + state->flag &= ~BOIDSTATE_CURRENT; + + state = boid_new_state(part->boids); + state->flag |= BOIDSTATE_CURRENT; + + BLI_addtail(&part->boids->states, state); + + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +void BOID_OT_boidstate_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Add Boid State"; + ot->description = "Add a boid state to the particle system."; + ot->idname= "BOID_OT_boidstate_add"; + + /* api callbacks */ + ot->exec= boidstate_add_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} +static int boidstate_del_exec(bContext *C, wmOperator *op) +{ + Scene *scene = CTX_data_scene(C); + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= ptr.data; + Object *ob = ptr.id.data; + ParticleSettings *part; + BoidState *state; + + if(!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + return OPERATOR_CANCELLED; + + part = psys->part; + + for(state=part->boids->states.first; state; state=state->next) { + if(state->flag & BOIDSTATE_CURRENT) { + BLI_remlink(&part->boids->states, state); + MEM_freeN(state); + break; + } + + } + + /* there must be at least one state */ + if(!part->boids->states.first) { + state = boid_new_state(part->boids); + BLI_addtail(&part->boids->states, state); + } + else + state = part->boids->states.first; + + state->flag |= BOIDSTATE_CURRENT; + + DAG_scene_sort(scene); + psys_flush_particle_settings(scene, psys->part, PSYS_RECALC_RESET); + + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +void BOID_OT_boidstate_del(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Remove Boid State"; + ot->idname= "BOID_OT_boidstate_del"; + + /* api callbacks */ + ot->exec= boidstate_del_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/************************ move up/down boid state operators *********************/ +static int boidstate_move_up_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= ptr.data; + Object *ob = ptr.id.data; + BoidSettings *boids; + BoidState *state; + + if(!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + return OPERATOR_CANCELLED; + + boids = psys->part->boids; + + for(state = boids->states.first; state; state=state->next) { + if(state->flag & BOIDSTATE_CURRENT && state->prev) { + BLI_remlink(&boids->states, state); + BLI_insertlink(&boids->states, state->prev->prev, state); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + break; + } + } + + return OPERATOR_FINISHED; +} + +void BOID_OT_boidstate_move_up(wmOperatorType *ot) +{ + ot->name= "Move Up Boid State"; + ot->description= "Move boid state up in the list."; + ot->idname= "BOID_OT_boidstate_move_up"; + + ot->exec= boidstate_move_up_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int boidstate_move_down_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= ptr.data; + Object *ob = ptr.id.data; + BoidSettings *boids; + BoidState *state; + + if(!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + return OPERATOR_CANCELLED; + + boids = psys->part->boids; + + for(state = boids->states.first; state; state=state->next) { + if(state->flag & BOIDSTATE_CURRENT && state->next) { + BLI_remlink(&boids->states, state); + BLI_insertlink(&boids->states, state->next, state); + psys_flush_particle_settings(scene, psys->part, PSYS_RECALC_RESET); + break; + } + } + + return OPERATOR_FINISHED; +} + +void BOID_OT_boidstate_move_down(wmOperatorType *ot) +{ + ot->name= "Move Down Boid State"; + ot->description= "Move boid state down in the list."; + ot->idname= "BOID_OT_boidstate_move_down"; + + ot->exec= boidstate_move_down_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/*******************************************************************************/ +void ED_operatortypes_boids(void) +{ + WM_operatortype_append(BOID_OT_boidrule_add); + WM_operatortype_append(BOID_OT_boidrule_del); + WM_operatortype_append(BOID_OT_boidrule_move_up); + WM_operatortype_append(BOID_OT_boidrule_move_down); + + WM_operatortype_append(BOID_OT_boidstate_add); + WM_operatortype_append(BOID_OT_boidstate_del); + WM_operatortype_append(BOID_OT_boidstate_move_up); + WM_operatortype_append(BOID_OT_boidstate_move_down); +}
\ No newline at end of file diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c index 5a55c5fb717..b427742077a 100644 --- a/source/blender/editors/space_api/spacetypes.c +++ b/source/blender/editors/space_api/spacetypes.c @@ -93,6 +93,7 @@ void ED_spacetypes_init(void) ED_operatortypes_marker(); ED_operatortypes_pointcache(); ED_operatortypes_fluid(); + ED_operatortypes_boids(); ui_view2d_operatortypes(); diff --git a/source/blender/editors/space_buttons/buttons_intern.h b/source/blender/editors/space_buttons/buttons_intern.h index 20db9fce8f2..adae52c1ce7 100644 --- a/source/blender/editors/space_buttons/buttons_intern.h +++ b/source/blender/editors/space_buttons/buttons_intern.h @@ -78,10 +78,10 @@ void OBJECT_OT_particle_system_add(struct wmOperatorType *ot); void OBJECT_OT_particle_system_remove(struct wmOperatorType *ot); void PARTICLE_OT_new(struct wmOperatorType *ot); -void PARTICLE_OT_new_keyed_target(struct wmOperatorType *ot); -void PARTICLE_OT_remove_keyed_target(struct wmOperatorType *ot); -void PARTICLE_OT_keyed_target_move_up(struct wmOperatorType *ot); -void PARTICLE_OT_keyed_target_move_down(struct wmOperatorType *ot); +void PARTICLE_OT_new_target(struct wmOperatorType *ot); +void PARTICLE_OT_remove_target(struct wmOperatorType *ot); +void PARTICLE_OT_target_move_up(struct wmOperatorType *ot); +void PARTICLE_OT_target_move_down(struct wmOperatorType *ot); void SCENE_OT_render_layer_add(struct wmOperatorType *ot); void SCENE_OT_render_layer_remove(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index 7dececd2679..8a9d2e9149b 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -30,6 +30,7 @@ #include "MEM_guardedalloc.h" +#include "DNA_boid_types.h" #include "DNA_curve_types.h" #include "DNA_group_types.h" #include "DNA_object_types.h" @@ -57,6 +58,7 @@ #include "BLI_listbase.h" #include "RNA_access.h" +#include "RNA_enum_types.h" #include "WM_api.h" #include "WM_types.h" @@ -623,7 +625,7 @@ static int new_particle_settings_exec(bContext *C, wmOperator *op) if(psys->part) part= psys_copy_settings(psys->part); else - part= psys_new_settings("PSys", bmain); + part= psys_new_settings("ParticleSettings", bmain); ob= ptr.id.data; @@ -632,6 +634,8 @@ static int new_particle_settings_exec(bContext *C, wmOperator *op) psys->part = part; + psys_check_boid_data(psys); + DAG_scene_sort(scene); DAG_object_flush_update(scene, ob, OB_RECALC_DATA); @@ -655,28 +659,28 @@ void PARTICLE_OT_new(wmOperatorType *ot) /********************** keyed particle target operators *********************/ -static int new_keyed_particle_target_exec(bContext *C, wmOperator *op) +static int new_particle_target_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); ParticleSystem *psys= ptr.data; Object *ob = ptr.id.data; - KeyedParticleTarget *kpt; + ParticleTarget *pt; if(!psys) return OPERATOR_CANCELLED; - kpt = psys->keyed_targets.first; - for(; kpt; kpt=kpt->next) - kpt->flag &= ~KEYED_TARGET_CURRENT; + pt = psys->targets.first; + for(; pt; pt=pt->next) + pt->flag &= ~PTARGET_CURRENT; - kpt = MEM_callocN(sizeof(KeyedParticleTarget), "keyed particle target"); + pt = MEM_callocN(sizeof(ParticleTarget), "keyed particle target"); - kpt->flag |= KEYED_TARGET_CURRENT; - kpt->psys = 1; + pt->flag |= PTARGET_CURRENT; + pt->psys = 1; - BLI_addtail(&psys->keyed_targets, kpt); + BLI_addtail(&psys->targets, pt); DAG_scene_sort(scene); DAG_object_flush_update(scene, ob, OB_RECALC_DATA); @@ -686,44 +690,44 @@ static int new_keyed_particle_target_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void PARTICLE_OT_new_keyed_target(wmOperatorType *ot) +void PARTICLE_OT_new_target(wmOperatorType *ot) { /* identifiers */ - ot->name= "New Keyed Particle Target"; - ot->idname= "PARTICLE_OT_new_keyed_target"; + ot->name= "New Particle Target"; + ot->idname= "PARTICLE_OT_new_target"; /* api callbacks */ - ot->exec= new_keyed_particle_target_exec; + ot->exec= new_particle_target_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -static int remove_keyed_particle_target_exec(bContext *C, wmOperator *op) +static int remove_particle_target_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); ParticleSystem *psys= ptr.data; Object *ob = ptr.id.data; - KeyedParticleTarget *kpt; + ParticleTarget *pt; if(!psys) return OPERATOR_CANCELLED; - kpt = psys->keyed_targets.first; - for(; kpt; kpt=kpt->next) { - if(kpt->flag & KEYED_TARGET_CURRENT) { - BLI_remlink(&psys->keyed_targets, kpt); - MEM_freeN(kpt); + pt = psys->targets.first; + for(; pt; pt=pt->next) { + if(pt->flag & PTARGET_CURRENT) { + BLI_remlink(&psys->targets, pt); + MEM_freeN(pt); break; } } - kpt = psys->keyed_targets.last; + pt = psys->targets.last; - if(kpt) - kpt->flag |= KEYED_TARGET_CURRENT; + if(pt) + pt->flag |= PTARGET_CURRENT; DAG_scene_sort(scene); DAG_object_flush_update(scene, ob, OB_RECALC_DATA); @@ -733,37 +737,37 @@ static int remove_keyed_particle_target_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void PARTICLE_OT_remove_keyed_target(wmOperatorType *ot) +void PARTICLE_OT_remove_target(wmOperatorType *ot) { /* identifiers */ - ot->name= "Remove Keyed Particle Target"; - ot->idname= "PARTICLE_OT_remove_keyed_target"; + ot->name= "Remove Particle Target"; + ot->idname= "PARTICLE_OT_remove_target"; /* api callbacks */ - ot->exec= remove_keyed_particle_target_exec; + ot->exec= remove_particle_target_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -/************************ move up modifier operator *********************/ +/************************ move up particle target operator *********************/ -static int keyed_target_move_up_exec(bContext *C, wmOperator *op) +static int target_move_up_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); ParticleSystem *psys= ptr.data; Object *ob = ptr.id.data; - KeyedParticleTarget *kpt; + ParticleTarget *pt; if(!psys) return OPERATOR_CANCELLED; - kpt = psys->keyed_targets.first; - for(; kpt; kpt=kpt->next) { - if(kpt->flag & KEYED_TARGET_CURRENT && kpt->prev) { - BLI_remlink(&psys->keyed_targets, kpt); - BLI_insertlink(&psys->keyed_targets, kpt->prev->prev, kpt); + pt = psys->targets.first; + for(; pt; pt=pt->next) { + if(pt->flag & PTARGET_CURRENT && pt->prev) { + BLI_remlink(&psys->targets, pt); + BLI_insertlink(&psys->targets, pt->prev->prev, pt); DAG_object_flush_update(scene, ob, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); @@ -774,35 +778,35 @@ static int keyed_target_move_up_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void PARTICLE_OT_keyed_target_move_up(wmOperatorType *ot) +void PARTICLE_OT_target_move_up(wmOperatorType *ot) { - ot->name= "Move Up Keyed Target"; - ot->description= "Move keyed particle target up in the list."; - ot->idname= "PARTICLE_OT_keyed_target_move_up"; + ot->name= "Move Up Target"; + ot->description= "Move particle target up in the list."; + ot->idname= "PARTICLE_OT_target_move_up"; - ot->exec= keyed_target_move_up_exec; + ot->exec= target_move_up_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -/************************ move down modifier operator *********************/ +/************************ move down particle target operator *********************/ -static int keyed_target_move_down_exec(bContext *C, wmOperator *op) +static int target_move_down_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); ParticleSystem *psys= ptr.data; Object *ob = ptr.id.data; - KeyedParticleTarget *kpt; + ParticleTarget *pt; if(!psys) return OPERATOR_CANCELLED; - kpt = psys->keyed_targets.first; - for(; kpt; kpt=kpt->next) { - if(kpt->flag & KEYED_TARGET_CURRENT && kpt->next) { - BLI_remlink(&psys->keyed_targets, kpt); - BLI_insertlink(&psys->keyed_targets, kpt->next, kpt); + pt = psys->targets.first; + for(; pt; pt=pt->next) { + if(pt->flag & PTARGET_CURRENT && pt->next) { + BLI_remlink(&psys->targets, pt); + BLI_insertlink(&psys->targets, pt->next, pt); DAG_object_flush_update(scene, ob, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); @@ -813,13 +817,13 @@ static int keyed_target_move_down_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void PARTICLE_OT_keyed_target_move_down(wmOperatorType *ot) +void PARTICLE_OT_target_move_down(wmOperatorType *ot) { - ot->name= "Move Down Keyed Target"; - ot->description= "Move keyed particle target down in the list."; - ot->idname= "PARTICLE_OT_keyed_target_move_down"; + ot->name= "Move Down Target"; + ot->description= "Move particle target down in the list."; + ot->idname= "PARTICLE_OT_target_move_down"; - ot->exec= keyed_target_move_down_exec; + ot->exec= target_move_down_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c index 0c1f735451a..72c479b2877 100644 --- a/source/blender/editors/space_buttons/space_buttons.c +++ b/source/blender/editors/space_buttons/space_buttons.c @@ -198,10 +198,10 @@ void buttons_operatortypes(void) WM_operatortype_append(OBJECT_OT_particle_system_remove); WM_operatortype_append(PARTICLE_OT_new); - WM_operatortype_append(PARTICLE_OT_new_keyed_target); - WM_operatortype_append(PARTICLE_OT_remove_keyed_target); - WM_operatortype_append(PARTICLE_OT_keyed_target_move_up); - WM_operatortype_append(PARTICLE_OT_keyed_target_move_down); + WM_operatortype_append(PARTICLE_OT_new_target); + WM_operatortype_append(PARTICLE_OT_remove_target); + WM_operatortype_append(PARTICLE_OT_target_move_up); + WM_operatortype_append(PARTICLE_OT_target_move_down); WM_operatortype_append(SCENE_OT_render_layer_add); WM_operatortype_append(SCENE_OT_render_layer_remove); diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 41da2c5a85b..0f498810fb5 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -40,6 +40,7 @@ #include "MTC_matrixops.h" #include "DNA_armature_types.h" +#include "DNA_boid_types.h" #include "DNA_camera_types.h" #include "DNA_curve_types.h" #include "DNA_constraint_types.h" // for drawing constraint @@ -3136,7 +3137,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv Material *ma; float vel[3], imat[4][4]; float timestep, pixsize=1.0, pa_size, r_tilt, r_length; - float pa_time, pa_birthtime, pa_dietime; + float pa_time, pa_birthtime, pa_dietime, pa_health; float cfra= bsystem_time(scene, ob,(float)CFRA,0.0); float ma_r=0.0f, ma_g=0.0f, ma_b=0.0f; int a, totpart, totpoint=0, totve=0, drawn, draw_as, totchild=0; @@ -3362,6 +3363,10 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv pa_birthtime=pa->time; pa_dietime = pa->dietime; pa_size=pa->size; + if(part->phystype==PART_PHYS_BOIDS) + pa_health = pa->boid->health; + else + pa_health = -1.0; #if 0 // XXX old animation system if((part->flag&PART_ABS_TIME)==0){ @@ -3424,6 +3429,8 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv pa_size=psys_get_child_size(psys,cpa,cfra,0); + pa_health = -1.0; + r_tilt = 2.0f * cpa->rand[2]; r_length = cpa->rand[1]; } @@ -3506,9 +3513,19 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv setlinestyle(0); } - if(part->draw&PART_DRAW_NUM && !(G.f & G_RENDER_SHADOW)){ + if((part->draw&PART_DRAW_NUM || part->draw&PART_DRAW_HEALTH) && !(G.f & G_RENDER_SHADOW)){ + strcpy(val, ""); + + if(part->draw&PART_DRAW_NUM) + sprintf(val, " %i", a); + + if(part->draw&PART_DRAW_NUM && part->draw&PART_DRAW_HEALTH) + sprintf(val, "%s:", val); + + if(part->draw&PART_DRAW_HEALTH && a < totpart && part->phystype==PART_PHYS_BOIDS) + sprintf(val, "%s %.2f", val, pa_health); + /* in path drawing state.co is the end point */ - sprintf(val," %i",a); view3d_particle_text_draw_add(state.co[0], state.co[1], state.co[2], val, 0); } } |