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/makesrna | |
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/makesrna')
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_enum_types.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/makesrna.c | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_boid.c | 615 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_fluidsim.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_internal.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_object_force.c | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_particle.c | 368 |
8 files changed, 830 insertions, 163 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 90270483adb..f3c2e95451d 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -221,7 +221,7 @@ extern StructRNA RNA_Key; extern StructRNA RNA_KeyboardSensor; extern StructRNA RNA_KeyingSet; extern StructRNA RNA_KeyingSetPath; -extern StructRNA RNA_KeyedParticleTarget; +extern StructRNA RNA_ParticleTarget; extern StructRNA RNA_KinematicConstraint; extern StructRNA RNA_Lamp; extern StructRNA RNA_LampSkySettings; diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index 276f421c586..2592a1340ec 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -34,6 +34,7 @@ extern EnumPropertyItem space_type_items[]; extern EnumPropertyItem region_type_items[]; extern EnumPropertyItem modifier_type_items[]; extern EnumPropertyItem constraint_type_items[]; +extern EnumPropertyItem boidrule_type_items[]; extern EnumPropertyItem beztriple_handle_type_items[]; extern EnumPropertyItem beztriple_interpolation_mode_items[]; diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 85c266e3f27..c8698ef57ac 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -1901,6 +1901,7 @@ RNAProcessItem PROCESS_ITEMS[]= { {"rna_animation.c", NULL, RNA_def_animation}, {"rna_actuator.c", NULL, RNA_def_actuator}, {"rna_armature.c", NULL, RNA_def_armature}, + {"rna_boid.c", NULL, RNA_def_boid}, {"rna_brush.c", NULL, RNA_def_brush}, {"rna_camera.c", NULL, RNA_def_camera}, {"rna_cloth.c", NULL, RNA_def_cloth}, diff --git a/source/blender/makesrna/intern/rna_boid.c b/source/blender/makesrna/intern/rna_boid.c new file mode 100644 index 00000000000..af274d813b5 --- /dev/null +++ b/source/blender/makesrna/intern/rna_boid.c @@ -0,0 +1,615 @@ +/** + * $Id: rna_modifier.c 21514 2009-07-11 05:41:21Z aligorith $ + * + * ***** 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 by Janne Karhu. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <float.h> +#include <limits.h> +#include <stdlib.h> + +#include "RNA_define.h" +#include "RNA_types.h" + +#include "rna_internal.h" + +#include "DNA_scene_types.h" +#include "DNA_boid_types.h" +#include "DNA_object_types.h" +#include "DNA_particle_types.h" + +#include "WM_types.h" + +EnumPropertyItem boidrule_type_items[] ={ + {eBoidRuleType_Goal, "GOAL", 0, "Goal", "Go to assigned object or loudest assigned signal source."}, + {eBoidRuleType_Avoid, "AVOID", 0, "Avoid", "Get away from assigned object or loudest assigned signal source."}, + {eBoidRuleType_AvoidCollision, "AVOID_COLLISION", 0, "Avoid Collision", "Monoeuver to avoid collisions with other boids and deflector objects in near future."}, + {eBoidRuleType_Separate, "SEPARATE", 0, "Separate", "Keep from going through other boids."}, + {eBoidRuleType_Flock, "FLOCK", 0, "Flock", "Move to center of neighbors and match their velocity."}, + {eBoidRuleType_FollowLeader, "FOLLOW_LEADER", 0, "Follow Leader", "Follow a boid or assigned object."}, + {eBoidRuleType_AverageSpeed, "AVERAGE_SPEED", 0, "Average Speed", "Maintain speed, flight level or wander."}, + {eBoidRuleType_Fight, "FIGHT", 0, "Fight", "Go to closest enemy and attack when in range."}, + //{eBoidRuleType_Protect, "PROTECT", 0, "Protect", "Go to enemy closest to target and attack when in range."}, + //{eBoidRuleType_Hide, "HIDE", 0, "Hide", "Find a deflector move to it's other side from closest enemy."}, + //{eBoidRuleType_FollowPath, "FOLLOW_PATH", 0, "Follow Path", "Move along a assigned curve or closest curve in a group."}, + //{eBoidRuleType_FollowWall, "FOLLOW_WALL", 0, "Follow Wall", "Move next to a deflector object's in direction of it's tangent."}, + {0, NULL, 0, NULL, NULL}}; + +EnumPropertyItem boidruleset_type_items[] ={ + {eBoidRulesetType_Fuzzy, "FUZZY", 0, "Fuzzy", "Rules are gone through top to bottom. Only the first rule that effect above fuzziness threshold is evaluated."}, + {eBoidRulesetType_Random, "RANDOM", 0, "Random", "A random rule is selected for each boid."}, + {eBoidRulesetType_Average, "AVERAGE", 0, "Average", "All rules are averaged."}, + {0, NULL, 0, NULL, NULL}}; + + +#ifdef RNA_RUNTIME + +#include "BKE_context.h" +#include "BKE_depsgraph.h" +#include "BKE_particle.h" + +static void rna_Boids_reset(bContext *C, PointerRNA *ptr) +{ + Scene *scene = CTX_data_scene(C); + ParticleSettings *part; + + if(ptr->type==&RNA_ParticleSystem) { + ParticleSystem *psys = (ParticleSystem*)ptr->data; + Object *ob = psys_find_object(scene, psys); + + psys->recalc = PSYS_RECALC_RESET; + + if(ob) { + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + } + } + else { + part = ptr->id.data; + psys_flush_particle_settings(scene, part, PSYS_RECALC_RESET); + } +} +static void rna_Boids_reset_deps(bContext *C, PointerRNA *ptr) +{ + Scene *scene = CTX_data_scene(C); + ParticleSettings *part; + + if(ptr->type==&RNA_ParticleSystem) { + ParticleSystem *psys = (ParticleSystem*)ptr->data; + Object *ob = psys_find_object(scene, psys); + + psys->recalc = PSYS_RECALC_RESET; + + if(ob) { + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + } + } + else { + part = ptr->id.data; + psys_flush_particle_settings(scene, part, PSYS_RECALC_RESET); + DAG_scene_sort(scene); + } +} + +static StructRNA* rna_BoidRule_refine(struct PointerRNA *ptr) +{ + BoidRule *rule= (BoidRule*)ptr->data; + + switch(rule->type) { + case eBoidRuleType_Goal: + return &RNA_BoidRuleGoal; + case eBoidRuleType_Avoid: + return &RNA_BoidRuleAvoid; + case eBoidRuleType_AvoidCollision: + return &RNA_BoidRuleAvoidCollision; + case eBoidRuleType_FollowLeader: + return &RNA_BoidRuleFollowLeader; + case eBoidRuleType_AverageSpeed: + return &RNA_BoidRuleAverageSpeed; + case eBoidRuleType_Fight: + return &RNA_BoidRuleFight; + default: + return &RNA_BoidRule; + } +} + +static char *rna_BoidRule_path(PointerRNA *ptr) +{ + return BLI_sprintfN("rules[%s]", ((BoidRule*)ptr->data)->name); // XXX not unique +} + +static PointerRNA rna_BoidState_active_boid_rule_get(PointerRNA *ptr) +{ + BoidState *state= (BoidState*)ptr->data; + BoidRule *rule = (BoidRule*)state->rules.first; + + for(; rule; rule=rule->next) { + if(rule->flag & BOIDRULE_CURRENT) + return rna_pointer_inherit_refine(ptr, &RNA_BoidRule, rule); + } + return rna_pointer_inherit_refine(ptr, &RNA_BoidRule, NULL); +} +static void rna_BoidState_active_boid_rule_index_range(PointerRNA *ptr, int *min, int *max) +{ + BoidState *state= (BoidState*)ptr->data; + *min= 0; + *max= BLI_countlist(&state->rules)-1; + *max= MAX2(0, *max); +} + +static int rna_BoidState_active_boid_rule_index_get(PointerRNA *ptr) +{ + BoidState *state= (BoidState*)ptr->data; + BoidRule *rule = (BoidRule*)state->rules.first; + int i=0; + + for(; rule; rule=rule->next, i++) { + if(rule->flag & BOIDRULE_CURRENT) + return i; + } + return 0; +} + +static void rna_BoidState_active_boid_rule_index_set(struct PointerRNA *ptr, int value) +{ + BoidState *state= (BoidState*)ptr->data; + BoidRule *rule = (BoidRule*)state->rules.first; + int i=0; + + for(; rule; rule=rule->next, i++) { + if(i==value) + rule->flag |= BOIDRULE_CURRENT; + else + rule->flag &= ~BOIDRULE_CURRENT; + } +} + +static PointerRNA rna_BoidSettings_active_boid_state_get(PointerRNA *ptr) +{ + BoidSettings *boids= (BoidSettings*)ptr->data; + BoidState *state = (BoidState*)boids->states.first; + + for(; state; state=state->next) { + if(state->flag & BOIDSTATE_CURRENT) + return rna_pointer_inherit_refine(ptr, &RNA_BoidState, state); + } + return rna_pointer_inherit_refine(ptr, &RNA_BoidState, NULL); +} +static void rna_BoidSettings_active_boid_state_index_range(PointerRNA *ptr, int *min, int *max) +{ + BoidSettings *boids= (BoidSettings*)ptr->data; + *min= 0; + *max= BLI_countlist(&boids->states)-1; + *max= MAX2(0, *max); +} + +static int rna_BoidSettings_active_boid_state_index_get(PointerRNA *ptr) +{ + BoidSettings *boids= (BoidSettings*)ptr->data; + BoidState *state = (BoidState*)boids->states.first; + int i=0; + + for(; state; state=state->next, i++) { + if(state->flag & BOIDSTATE_CURRENT) + return i; + } + return 0; +} + +static void rna_BoidSettings_active_boid_state_index_set(struct PointerRNA *ptr, int value) +{ + BoidSettings *boids= (BoidSettings*)ptr->data; + BoidState *state = (BoidState*)boids->states.first; + int i=0; + + for(; state; state=state->next, i++) { + if(i==value) + state->flag |= BOIDSTATE_CURRENT; + else + state->flag &= ~BOIDSTATE_CURRENT; + } +} + +#else + +static void rna_def_boidrule_goal(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "BoidRuleGoal", "BoidRule"); + RNA_def_struct_ui_text(srna, "Goal", ""); + RNA_def_struct_sdna(srna, "BoidRuleGoalAvoid"); + + prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "ob"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Object", "Goal object."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset_deps"); + + prop= RNA_def_property(srna, "predict", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_GOAL_AVOID_PREDICT); + RNA_def_property_ui_text(prop, "Predict", "Predict target movement."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); +} + +static void rna_def_boidrule_avoid(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "BoidRuleAvoid", "BoidRule"); + RNA_def_struct_ui_text(srna, "Avoid", ""); + RNA_def_struct_sdna(srna, "BoidRuleGoalAvoid"); + + prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "ob"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Object", "Object to avoid."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset_deps"); + + prop= RNA_def_property(srna, "predict", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_GOAL_AVOID_PREDICT); + RNA_def_property_ui_text(prop, "Predict", "Predict target movement."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "fear_factor", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0f, 100.0f); + RNA_def_property_ui_text(prop, "Fear factor", "Avoid object if danger from it is above this threshol."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); +} + +static void rna_def_boidrule_avoid_collision(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "BoidRuleAvoidCollision", "BoidRule"); + RNA_def_struct_ui_text(srna, "Avoid Collision", ""); + + prop= RNA_def_property(srna, "boids", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_ACOLL_WITH_BOIDS); + RNA_def_property_ui_text(prop, "Boids", "Avoid collision with other boids."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "deflectors", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_ACOLL_WITH_DEFLECTORS); + RNA_def_property_ui_text(prop, "Deflectors", "Avoid collision with deflector objects."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "look_ahead", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0f, 100.0f); + RNA_def_property_ui_text(prop, "Look ahead", "Time to look ahead in seconds."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); +} + +static void rna_def_boidrule_follow_leader(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "BoidRuleFollowLeader", "BoidRule"); + RNA_def_struct_ui_text(srna, "Follow Leader", ""); + + prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "ob"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Object", "Follow this object instead of a boid."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset_deps"); + + prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0f, 100.0f); + RNA_def_property_ui_text(prop, "Distance", "Distance behind leader to follow."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "queue_size", PROP_INT, PROP_NONE); + RNA_def_property_range(prop, 0.0f, 100.0f); + RNA_def_property_ui_text(prop, "Queue Size", "How many boids in a line."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "line", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_LEADER_IN_LINE); + RNA_def_property_ui_text(prop, "Line", "Follow leader in a line."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); +} + +static void rna_def_boidrule_average_speed(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "BoidRuleAverageSpeed", "BoidRule"); + RNA_def_struct_ui_text(srna, "Average Speed", ""); + + prop= RNA_def_property(srna, "wander", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Wander", "How fast velocity's direction is randomized."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "level", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Level", "How much velocity's z-component is kept constant."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "speed", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Speed", "Percentage of maximum speed."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); +} + +static void rna_def_boidrule_fight(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "BoidRuleFight", "BoidRule"); + RNA_def_struct_ui_text(srna, "Fight", ""); + + prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0f, 100.0f); + RNA_def_property_ui_text(prop, "Fight Distance", "Attack boids at max this distance."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "flee_distance", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0f, 100.0f); + RNA_def_property_ui_text(prop, "Flee Distance", "Flee to this distance."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); +} + +static void rna_def_boidrule(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + /* data */ + srna= RNA_def_struct(brna, "BoidRule", NULL); + RNA_def_struct_ui_text(srna , "Boid Rule", ""); + RNA_def_struct_refine_func(srna, "rna_BoidRule_refine"); + RNA_def_struct_path_func(srna, "rna_BoidRule_path"); + + /* strings */ + prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_ui_text(prop, "Name", "Boid rule name."); + RNA_def_struct_name_property(srna, prop); + + /* enums */ + prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_enum_sdna(prop, NULL, "type"); + RNA_def_property_enum_items(prop, boidrule_type_items); + RNA_def_property_ui_text(prop, "Type", ""); + + /* flags */ + prop= RNA_def_property(srna, "in_air", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", BOIDRULE_IN_AIR); + RNA_def_property_ui_text(prop, "In Air", "Use rule when boid is flying."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "on_land", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", BOIDRULE_ON_LAND); + RNA_def_property_ui_text(prop, "On Land", "Use rule when boid is on land."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + //prop= RNA_def_property(srna, "expanded", PROP_BOOLEAN, PROP_NONE); + //RNA_def_property_boolean_sdna(prop, NULL, "mode", eModifierMode_Expanded); + //RNA_def_property_ui_text(prop, "Expanded", "Set modifier expanded in the user interface."); + + /* types */ + rna_def_boidrule_goal(brna); + rna_def_boidrule_avoid(brna); + rna_def_boidrule_avoid_collision(brna); + rna_def_boidrule_follow_leader(brna); + rna_def_boidrule_average_speed(brna); + rna_def_boidrule_fight(brna); +} + +static void rna_def_boidstate(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "BoidState", NULL); + RNA_def_struct_ui_text(srna, "Boid State", "Boid state for boid physics."); + + prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_ui_text(prop, "Name", "Boid state name."); + RNA_def_struct_name_property(srna, prop); + + prop= RNA_def_property(srna, "ruleset_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, boidruleset_type_items); + RNA_def_property_ui_text(prop, "Rule Evaluation", "How the rules in the list are evaluated."); + + prop= RNA_def_property(srna, "rules", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_type(prop, "BoidRule"); + RNA_def_property_ui_text(prop, "Boid Rules", ""); + + prop= RNA_def_property(srna, "active_boid_rule", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "BoidRule"); + RNA_def_property_pointer_funcs(prop, "rna_BoidState_active_boid_rule_get", NULL, NULL); + RNA_def_property_ui_text(prop, "Active Boid Rule", ""); + + prop= RNA_def_property(srna, "active_boid_rule_index", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_funcs(prop, "rna_BoidState_active_boid_rule_index_get", "rna_BoidState_active_boid_rule_index_set", "rna_BoidState_active_boid_rule_index_range"); + RNA_def_property_ui_text(prop, "Active Boid Rule Index", ""); + + prop= RNA_def_property(srna, "rule_fuzziness", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 1.0); + RNA_def_property_ui_text(prop, "Rule Fuzzines", ""); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "volume", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 100.0); + RNA_def_property_ui_text(prop, "Volume", ""); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 10.0); + RNA_def_property_ui_text(prop, "Falloff", ""); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); +} +static void rna_def_boid_settings(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "BoidSettings", NULL); + RNA_def_struct_ui_text(srna, "Boid Settings", "Settings for boid physics."); + + prop= RNA_def_property(srna, "landing_smoothness", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 10.0); + RNA_def_property_ui_text(prop, "Landing Smoothness", "How smoothly the boids land."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "banking", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 2.0); + RNA_def_property_ui_text(prop, "Banking", "Amount of rotation around velocity vector on turns."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "height", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 2.0); + RNA_def_property_ui_text(prop, "Height", "Boid height relative to particle size."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + /* states */ + prop= RNA_def_property(srna, "states", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_type(prop, "BoidState"); + RNA_def_property_ui_text(prop, "Boid States", ""); + + prop= RNA_def_property(srna, "active_boid_state", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "BoidRule"); + RNA_def_property_pointer_funcs(prop, "rna_BoidSettings_active_boid_state_get", NULL, NULL); + RNA_def_property_ui_text(prop, "Active Boid Rule", ""); + + prop= RNA_def_property(srna, "active_boid_state_index", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_funcs(prop, "rna_BoidSettings_active_boid_state_index_get", "rna_BoidSettings_active_boid_state_index_set", "rna_BoidSettings_active_boid_state_index_range"); + RNA_def_property_ui_text(prop, "Active Boid State Index", ""); + + /* character properties */ + prop= RNA_def_property(srna, "health", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 100.0); + RNA_def_property_ui_text(prop, "Health", "Initial boid health when born."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 100.0); + RNA_def_property_ui_text(prop, "Strength", "Maximum caused damage on attack per second."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "aggression", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 100.0); + RNA_def_property_ui_text(prop, "Aggression", "Boid will fight this times stronger enemy."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "accuracy", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 1.0); + RNA_def_property_ui_text(prop, "Accuracy", "Accuracy of attack."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "range", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 100.0); + RNA_def_property_ui_text(prop, "Range", "The maximum distance from which a boid can attack."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + /* physical properties */ + prop= RNA_def_property(srna, "air_min_speed", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 1.0); + RNA_def_property_ui_text(prop, "Min Air Speed", "Minimum speed in air (relative to maximum speed)."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "air_max_speed", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 100.0); + RNA_def_property_ui_text(prop, "Max Air Speed", "Maximum speed in air."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "air_max_acc", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 1.0); + RNA_def_property_ui_text(prop, "Max Air Acceleration", "Maximum acceleration in air (relative to maximum speed)."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "air_max_ave", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 1.0); + RNA_def_property_ui_text(prop, "Max Air Angular Velocity", "Maximum angular velocity in air (relative to 180 degrees)."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "air_personal_space", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 10.0); + RNA_def_property_ui_text(prop, "Air Personal Space", "Radius of boids personal space in air (% of particle size)."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "land_jump_speed", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 100.0); + RNA_def_property_ui_text(prop, "Jump Speed", "Maximum speed for jumping."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "land_max_speed", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 100.0); + RNA_def_property_ui_text(prop, "Max Land Speed", "Maximum speed on land."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "land_max_acc", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 1.0); + RNA_def_property_ui_text(prop, "Max Land Acceleration", "Maximum acceleration on land (relative to maximum speed)."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "land_max_ave", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 1.0); + RNA_def_property_ui_text(prop, "Max Land Angular Velocity", "Maximum angular velocity on land (relative to 180 degrees)."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "land_personal_space", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 10.0); + RNA_def_property_ui_text(prop, "Land Personal Space", "Radius of boids personal space on land (% of particle size)."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "land_stick_force", PROP_FLOAT, PROP_NONE); + RNA_def_property_range(prop, 0.0, 1000.0); + RNA_def_property_ui_text(prop, "Land Stick Force", "How strong a force must be to start effecting a boid on land."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + /* options */ + prop= RNA_def_property(srna, "allow_flight", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "options", BOID_ALLOW_FLIGHT); + RNA_def_property_ui_text(prop, "Allow Flight", "Allow boids to move in air."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "allow_land", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "options", BOID_ALLOW_LAND); + RNA_def_property_ui_text(prop, "Allow Land", "Allow boids to move on land."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); + + prop= RNA_def_property(srna, "allow_climb", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "options", BOID_ALLOW_CLIMB); + RNA_def_property_ui_text(prop, "Allow Climbing", "Allow boids to climb goal objects."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Boids_reset"); +} + +void RNA_def_boid(BlenderRNA *brna) +{ + rna_def_boidrule(brna); + rna_def_boidstate(brna); + rna_def_boid_settings(brna); +} + +#endif diff --git a/source/blender/makesrna/intern/rna_fluidsim.c b/source/blender/makesrna/intern/rna_fluidsim.c index 9afe36fb142..ea4deae08e7 100644 --- a/source/blender/makesrna/intern/rna_fluidsim.c +++ b/source/blender/makesrna/intern/rna_fluidsim.c @@ -93,7 +93,7 @@ static void rna_FluidSettings_update_type(bContext *C, PointerRNA *ptr) if(ob->type == OB_MESH && !psys) { /* add particle system */ - part= psys_new_settings("PSys", bmain); + part= psys_new_settings("ParticleSettings", bmain); psys= MEM_callocN(sizeof(ParticleSystem), "particle_system"); part->type= PART_FLUID; diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 3e92c606e53..5afc08439e2 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -117,6 +117,7 @@ void RNA_def_action(struct BlenderRNA *brna); void RNA_def_animation(struct BlenderRNA *brna); void RNA_def_armature(struct BlenderRNA *brna); void RNA_def_actuator(struct BlenderRNA *brna); +void RNA_def_boid(struct BlenderRNA *brna); void RNA_def_brush(struct BlenderRNA *brna); void RNA_def_brushclone(struct BlenderRNA *brna); void RNA_def_camera(struct BlenderRNA *brna); diff --git a/source/blender/makesrna/intern/rna_object_force.c b/source/blender/makesrna/intern/rna_object_force.c index 269437a8fae..2ec8d9ea41e 100644 --- a/source/blender/makesrna/intern/rna_object_force.c +++ b/source/blender/makesrna/intern/rna_object_force.c @@ -284,7 +284,7 @@ static void rna_FieldSettings_surface_update(bContext *C, PointerRNA *ptr) /* add/remove modifier as needed */ if(!md) { if(pd && (pd->flag & PFIELD_SURFACE)) - if(ELEM5(pd->forcefield,PFIELD_HARMONIC,PFIELD_FORCE,PFIELD_HARMONIC,PFIELD_CHARGE,PFIELD_LENNARDJ)) + if(ELEM6(pd->forcefield,PFIELD_HARMONIC,PFIELD_FORCE,PFIELD_HARMONIC,PFIELD_CHARGE,PFIELD_LENNARDJ,PFIELD_BOID)) if(ELEM4(ob->type, OB_MESH, OB_SURF, OB_FONT, OB_CURVE)) ED_object_modifier_add(NULL, scene, ob, eModifierType_Surface); } @@ -504,6 +504,7 @@ static void rna_def_field(BlenderRNA *brna) {PFIELD_HARMONIC, "HARMONIC", 0, "Harmonic", ""}, {PFIELD_CHARGE, "CHARGE", 0, "Charge", ""}, {PFIELD_LENNARDJ, "LENNARDJ", 0, "Lennard-Jones", ""}, + {PFIELD_BOID, "BOID", 0, "Boid", ""}, {0, NULL, 0, NULL, NULL}}; static EnumPropertyItem falloff_items[] = { diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c index 3c25bd76630..f07351f0a30 100644 --- a/source/blender/makesrna/intern/rna_particle.c +++ b/source/blender/makesrna/intern/rna_particle.c @@ -29,6 +29,7 @@ #include "RNA_define.h" #include "RNA_types.h" +#include "RNA_access.h" #include "rna_internal.h" @@ -36,6 +37,7 @@ #include "DNA_object_force.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "DNA_boid_types.h" #include "WM_types.h" #include "WM_api.h" @@ -140,13 +142,33 @@ static void rna_Particle_reset(bContext *C, PointerRNA *ptr) } } -static void rna_Particle_keyed_reset(bContext *C, PointerRNA *ptr) +static void rna_Particle_target_reset(bContext *C, PointerRNA *ptr) { Scene *scene = CTX_data_scene(C); - if(ptr->type==&RNA_KeyedParticleTarget) { + if(ptr->type==&RNA_ParticleTarget) { + ParticleTarget *pt = (ParticleTarget*)ptr->data; Object *ob = (Object*)ptr->id.data; - ParticleSystem *psys = psys_get_current(ob); + ParticleSystem *kpsys=NULL, *psys=psys_get_current(ob); + int psys_num = BLI_findindex(&ob->particlesystem, psys); + + if(pt->ob==ob || pt->ob==NULL) { + kpsys = BLI_findlink(&ob->particlesystem, pt->psys-1); + + if(kpsys) + pt->flag |= PTARGET_VALID; + else + pt->flag &= ~PTARGET_VALID; + } + else { + if(pt->ob) + kpsys = BLI_findlink(&pt->ob->particlesystem, pt->psys-1); + + if(kpsys) + pt->flag |= PTARGET_VALID; + else + pt->flag &= ~PTARGET_VALID; + } psys->recalc = PSYS_RECALC_RESET; @@ -155,11 +177,11 @@ static void rna_Particle_keyed_reset(bContext *C, PointerRNA *ptr) } } -static void rna_Particle_keyed_redo(bContext *C, PointerRNA *ptr) +static void rna_Particle_target_redo(bContext *C, PointerRNA *ptr) { Scene *scene = CTX_data_scene(C); - if(ptr->type==&RNA_KeyedParticleTarget) { + if(ptr->type==&RNA_ParticleTarget) { Object *ob = (Object*)ptr->id.data; ParticleSystem *psys = psys_get_current(ob); @@ -235,8 +257,10 @@ static void rna_particle_settings_set(PointerRNA *ptr, PointerRNA value) psys->part = (ParticleSettings *)value.data; - if(psys->part) + if(psys->part) { psys->part->id.us++; + psys_check_boid_data(psys); + } } static void rna_Particle_abspathtime_update(bContext *C, PointerRNA *ptr) { @@ -315,97 +339,100 @@ static float rna_PartSetting_linelenhead_get(struct PointerRNA *ptr) return settings->draw_line[1]; } -static int rna_ParticleSystem_name_length(PointerRNA *ptr) -{ - ParticleSystem *psys= ptr->data; - - if(psys->part) - return strlen(psys->part->id.name+2); - - return 0; -} - -static void rna_ParticleSystem_name_get(PointerRNA *ptr, char *str) -{ - ParticleSystem *psys= ptr->data; - - if(psys->part) - strcpy(str, psys->part->id.name+2); - else - strcpy(str, ""); -} - -static PointerRNA rna_ParticleSystem_active_keyed_target_get(PointerRNA *ptr) +static PointerRNA rna_ParticleSystem_active_particle_target_get(PointerRNA *ptr) { ParticleSystem *psys= (ParticleSystem*)ptr->data; - KeyedParticleTarget *kpt = psys->keyed_targets.first; + ParticleTarget *pt = psys->targets.first; - for(; kpt; kpt=kpt->next) { - if(kpt->flag & KEYED_TARGET_CURRENT) - return rna_pointer_inherit_refine(ptr, &RNA_KeyedParticleTarget, kpt); + for(; pt; pt=pt->next) { + if(pt->flag & PTARGET_CURRENT) + return rna_pointer_inherit_refine(ptr, &RNA_ParticleTarget, pt); } - return rna_pointer_inherit_refine(ptr, &RNA_KeyedParticleTarget, NULL); + return rna_pointer_inherit_refine(ptr, &RNA_ParticleTarget, NULL); } -static void rna_ParticleSystem_active_keyed_target_index_range(PointerRNA *ptr, int *min, int *max) +static void rna_ParticleSystem_active_particle_target_index_range(PointerRNA *ptr, int *min, int *max) { ParticleSystem *psys= (ParticleSystem*)ptr->data; *min= 0; - *max= BLI_countlist(&psys->keyed_targets)-1; + *max= BLI_countlist(&psys->targets)-1; *max= MAX2(0, *max); } -static int rna_ParticleSystem_active_keyed_target_index_get(PointerRNA *ptr) +static int rna_ParticleSystem_active_particle_target_index_get(PointerRNA *ptr) { ParticleSystem *psys= (ParticleSystem*)ptr->data; - KeyedParticleTarget *kpt = psys->keyed_targets.first; + ParticleTarget *pt = psys->targets.first; int i=0; - for(; kpt; kpt=kpt->next, i++) - if(kpt->flag & KEYED_TARGET_CURRENT) + for(; pt; pt=pt->next, i++) + if(pt->flag & PTARGET_CURRENT) return i; return 0; } -static void rna_ParticleSystem_active_keyed_target_index_set(struct PointerRNA *ptr, int value) +static void rna_ParticleSystem_active_particle_target_index_set(struct PointerRNA *ptr, int value) { ParticleSystem *psys= (ParticleSystem*)ptr->data; - KeyedParticleTarget *kpt = psys->keyed_targets.first; + ParticleTarget *pt = psys->targets.first; int i=0; - for(; kpt; kpt=kpt->next, i++) { + for(; pt; pt=pt->next, i++) { if(i==value) - kpt->flag |= KEYED_TARGET_CURRENT; + pt->flag |= PTARGET_CURRENT; else - kpt->flag &= ~KEYED_TARGET_CURRENT; + pt->flag &= ~PTARGET_CURRENT; } } -static int rna_KeyedParticleTarget_name_length(PointerRNA *ptr) +static int rna_ParticleTarget_name_length(PointerRNA *ptr) { - KeyedParticleTarget *kpt= ptr->data; + ParticleTarget *pt= ptr->data; + + if(pt->flag & PTARGET_VALID) { + ParticleSystem *psys = NULL; - if(kpt->flag & KEYED_TARGET_VALID) { - if(kpt->ob) - return strlen(kpt->ob->id.name+2) + 4; + if(pt->ob) + psys = BLI_findlink(&pt->ob->particlesystem, pt->psys-1); + else { + Object *ob = (Object*) ptr->id.data; + psys = BLI_findlink(&ob->particlesystem, pt->psys-1); + } + + if(psys) { + if(pt->ob) + return strlen(pt->ob->id.name+2) + 2 + strlen(psys->name); + else + return strlen(psys->name); + } else - return 20; + return 15; } else return 15; - - return 0; } -static void rna_KeyedParticleTarget_name_get(PointerRNA *ptr, char *str) +static void rna_ParticleTarget_name_get(PointerRNA *ptr, char *str) { - KeyedParticleTarget *kpt= ptr->data; + ParticleTarget *pt= ptr->data; - if(kpt->flag & KEYED_TARGET_VALID) { - if(kpt->ob) - sprintf(str, "%s: %i", kpt->ob->id.name+2, kpt->psys); - else - sprintf(str, "Particle System: %i", kpt->psys); + if(pt->flag & PTARGET_VALID) { + ParticleSystem *psys = NULL; + if(pt->ob) + psys = BLI_findlink(&pt->ob->particlesystem, pt->psys-1); + else { + Object *ob = (Object*) ptr->id.data; + psys = BLI_findlink(&ob->particlesystem, pt->psys-1); + } + + if(psys) { + if(pt->ob) + sprintf(str, "%s: %s", pt->ob->id.name+2, psys->name); + else + strcpy(str, psys->name); + } + else + strcpy(str, "Invalid target!"); } else strcpy(str, "Invalid target!"); @@ -636,10 +663,10 @@ static void rna_def_particle(BlenderRNA *brna) // RNA_def_property_range(prop, lowerLimitf, upperLimitf); RNA_def_property_ui_text(prop, "Die Time", ""); - prop= RNA_def_property(srna, "banking_angle", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "bank"); -// RNA_def_property_range(prop, lowerLimitf, upperLimitf); - RNA_def_property_ui_text(prop, "Banking Angle", ""); +// prop= RNA_def_property(srna, "banking_angle", PROP_FLOAT, PROP_NONE); +// RNA_def_property_float_sdna(prop, NULL, "bank"); +//// RNA_def_property_range(prop, lowerLimitf, upperLimitf); +// RNA_def_property_ui_text(prop, "Banking Angle", ""); prop= RNA_def_property(srna, "size", PROP_FLOAT, PROP_NONE); // RNA_def_property_range(prop, lowerLimitf, upperLimitf); @@ -1024,10 +1051,10 @@ static void rna_def_particle_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Emitter", "Render emitter Object also."); RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_redo"); - //prop= RNA_def_property(srna, "draw_health", PROP_BOOLEAN, PROP_NONE); - //RNA_def_property_boolean_sdna(prop, NULL, "draw", PART_DRAW_HEALTH); - //RNA_def_property_ui_text(prop, "Health", "Draw boid health"); - //RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_redo"); + prop= RNA_def_property(srna, "draw_health", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "draw", PART_DRAW_HEALTH); + RNA_def_property_ui_text(prop, "Health", "Draw boid health"); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_redo"); prop= RNA_def_property(srna, "abs_path_time", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "draw", PART_ABS_PATH_TIME); @@ -1149,9 +1176,6 @@ static void rna_def_particle_settings(BlenderRNA *brna) RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_redo"); - //interpolation - //TODO: can't find where interpolation is used - //TODO: is this read only/internal? prop= RNA_def_property(srna, "rotate_from", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "rotfrom"); @@ -1173,19 +1197,6 @@ static void rna_def_particle_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Axis", "Which axis to use for offset"); RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_redo_child"); - /* used? - prop= RNA_def_property(srna, "inbetween", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, NULL, "nbetween"); - RNA_def_property_range(prop, 0, INT_MAX); - RNA_def_property_ui_text(prop, "Inbetween", ""); - */ - - prop= RNA_def_property(srna, "boid_neighbours", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, NULL, "boidneighbours"); - RNA_def_property_range(prop, 1, 10); - RNA_def_property_ui_text(prop, "Neighbours", "How many neighbours to consider for each boid"); - RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); - /* billboards */ prop= RNA_def_property(srna, "billboard_align", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "bb_align"); @@ -1421,6 +1432,12 @@ static void rna_def_particle_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Acceleration", "Constant acceleration"); RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + prop= RNA_def_property(srna, "gravity", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "acc[2]"); + RNA_def_property_range(prop, -200.0f, 200.0f); + RNA_def_property_ui_text(prop, "Gravity", "Constant acceleration in global Z axis direction"); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + prop= RNA_def_property(srna, "drag_factor", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "dragfac"); RNA_def_property_range(prop, 0.0f, 1.0f); @@ -1619,46 +1636,12 @@ static void rna_def_particle_settings(BlenderRNA *brna) RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_redo"); /* boids */ - prop= RNA_def_property(srna, "max_velocity", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "max_vel"); - RNA_def_property_range(prop, 0.0f, 200.0f); - RNA_def_property_ui_text(prop, "Maximum Velocity", ""); - RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); - - prop= RNA_def_property(srna, "lateral_acceleration_max", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "max_lat_acc"); - RNA_def_property_range(prop, 0.0f, 1.0f); - RNA_def_property_ui_text(prop, "Lateral Acceleration", "Lateral acceleration % of max velocity"); - RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); - - prop= RNA_def_property(srna, "tangential_acceleration_max", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "max_tan_acc"); - RNA_def_property_range(prop, 0.0f, 1.0f); - RNA_def_property_ui_text(prop, "Tangential acceleration", "Tangential acceleration % of max velocity"); - RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); - - prop= RNA_def_property(srna, "average_velocity", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "average_vel"); - RNA_def_property_range(prop, 0.0f, 1.0f); - RNA_def_property_ui_text(prop, "Average Velocity", "The usual speed % of max velocity"); - RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); - - prop= RNA_def_property(srna, "banking", PROP_FLOAT, PROP_NONE); - RNA_def_property_range(prop, -10.0f, 10.0f); - RNA_def_property_ui_text(prop, "Banking", "Banking of boids on turns (1.0==natural banking)"); - RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); - - prop= RNA_def_property(srna, "banking_max", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "max_bank"); - RNA_def_property_range(prop, 0.0f, 1.0f); - RNA_def_property_ui_text(prop, "Maximum Banking", "How much a boid can bank at a single step"); - RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + prop= RNA_def_property(srna, "boids", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "BoidSettings"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Boid Settings", ""); - prop= RNA_def_property(srna, "ground_z", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "groundz"); - RNA_def_property_range(prop, -100.0f, 100.0f); - RNA_def_property_ui_text(prop, "Ground Z", "Default Z value"); - RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + /* draw objects & groups */ prop= RNA_def_property(srna, "dupli_group", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "dup_group"); @@ -1667,13 +1650,6 @@ static void rna_def_particle_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Dupli Group", "Show Objects in this Group in place of particles"); RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_redo"); - prop= RNA_def_property(srna, "effector_group", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, NULL, "eff_group"); - RNA_def_property_struct_type(prop, "Group"); - RNA_def_property_flag(prop, PROP_EDITABLE); - RNA_def_property_ui_text(prop, "Effector Group", "Limit effectors to this Group."); - RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); - prop= RNA_def_property(srna, "dupli_object", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "dup_ob"); RNA_def_property_struct_type(prop, "Object"); @@ -1687,6 +1663,74 @@ static void rna_def_particle_settings(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Billboard Object", "Billboards face this object (default is active camera)"); RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_redo"); + + /* effectors */ + prop= RNA_def_property(srna, "effector_group", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "eff_group"); + RNA_def_property_struct_type(prop, "Group"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Effector Group", "Limit effectors to this Group."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + + prop= RNA_def_property(srna, "eweight_all", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "effector_weight[0]"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "All", "All effector's weight."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + + prop= RNA_def_property(srna, "eweight_spherical", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "effector_weight[1]"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Spherical", "Spherical effector weight."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + + prop= RNA_def_property(srna, "eweight_vortex", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "effector_weight[2]"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Vortex", "Vortex effector weight."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + + prop= RNA_def_property(srna, "eweight_magnetic", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "effector_weight[3]"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Magnetic", "Magnetic effector weight."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + + prop= RNA_def_property(srna, "eweight_wind", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "effector_weight[4]"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Wind", "Wind effector weight."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + + prop= RNA_def_property(srna, "eweight_curveguide", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "effector_weight[5]"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Curve Guide", "Curve guide effector weight."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + + prop= RNA_def_property(srna, "eweight_texture", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "effector_weight[6]"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Magnetic", "Texture effector weight."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + + prop= RNA_def_property(srna, "eweight_harmonic", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "effector_weight[7]"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Harmonic", "Harmonic effector weight."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + + prop= RNA_def_property(srna, "eweight_charge", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "effector_weight[8]"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Charge", "Charge effector weight."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); + + prop= RNA_def_property(srna, "eweight_lennardjones", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "effector_weight[9]"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Lennard-Jones", "Lennard-Jones effector weight."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); /* animation here? */ rna_def_animdata_common(srna); @@ -1695,17 +1739,25 @@ static void rna_def_particle_settings(BlenderRNA *brna) // struct PartDeflect *pd2; } -static void rna_def_keyed_particle_target(BlenderRNA *brna) +static void rna_def_particle_target(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; - srna = RNA_def_struct(brna, "KeyedParticleTarget", NULL); - RNA_def_struct_ui_text(srna, "Keyed Particle Target", "Target particle system for keyed particles."); + static EnumPropertyItem mode_items[] = { + {PTARGET_MODE_FRIEND, "FRIEND", 0, "Friend", ""}, + {PTARGET_MODE_NEUTRAL, "NEUTRAL", 0, "Neutral", ""}, + {PTARGET_MODE_ENEMY, "ENEMY", 0, "Enemy", ""}, + {0, NULL, 0, NULL, NULL} + }; + + + srna = RNA_def_struct(brna, "ParticleTarget", NULL); + RNA_def_struct_ui_text(srna, "Particle Target", "Target particle system."); prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); - RNA_def_property_string_funcs(prop, "rna_KeyedParticleTarget_name_get", "rna_KeyedParticleTarget_name_length", NULL); - RNA_def_property_ui_text(prop, "Name", "Keyed particle target name."); + RNA_def_property_string_funcs(prop, "rna_ParticleTarget_name_get", "rna_ParticleTarget_name_length", NULL); + RNA_def_property_ui_text(prop, "Name", "Particle target name."); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_struct_name_property(srna, prop); @@ -1713,32 +1765,36 @@ static void rna_def_keyed_particle_target(BlenderRNA *brna) RNA_def_property_pointer_sdna(prop, NULL, "ob"); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Target Object", "The object that has the target particle system (empty if same object)."); - RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_keyed_reset"); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_target_reset"); prop= RNA_def_property(srna, "system", PROP_INT, PROP_UNSIGNED); RNA_def_property_int_sdna(prop, NULL, "psys"); RNA_def_property_range(prop, 1, INT_MAX); RNA_def_property_ui_text(prop, "Target Particle System", "The index of particle system on the target object."); - RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_keyed_reset"); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_target_reset"); prop= RNA_def_property(srna, "time", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "time"); RNA_def_property_range(prop, 0.0, 30000.0f); //TODO: replace 30000 with MAXFRAMEF when available in 2.5 RNA_def_property_ui_text(prop, "Time", ""); - RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_keyed_redo"); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_target_redo"); prop= RNA_def_property(srna, "duration", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "duration"); RNA_def_property_range(prop, 0.0, 30000.0f); //TODO: replace 30000 with MAXFRAMEF when available in 2.5 RNA_def_property_ui_text(prop, "Duration", ""); - RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_keyed_redo"); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_target_redo"); prop= RNA_def_property(srna, "valid", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYED_TARGET_VALID); + RNA_def_property_boolean_sdna(prop, NULL, "flag", PTARGET_VALID); RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE); RNA_def_property_ui_text(prop, "Valid", "Keyed particles target is valid."); - + prop= RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, mode_items); + RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE); + RNA_def_property_ui_text(prop, "Mode", ""); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_target_reset"); } static void rna_def_particle_system(BlenderRNA *brna) @@ -1751,9 +1807,7 @@ static void rna_def_particle_system(BlenderRNA *brna) RNA_def_struct_ui_icon(srna, ICON_PARTICLE_DATA); prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); - RNA_def_property_string_funcs(prop, "rna_ParticleSystem_name_get", "rna_ParticleSystem_name_length", NULL); RNA_def_property_ui_text(prop, "Name", "Particle system name."); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_struct_name_property(srna, prop); /* access to particle settings is redirected through functions */ @@ -1807,13 +1861,6 @@ static void rna_def_particle_system(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Reactor Target Particle System", "For reactor systems, index of particle system on the target object."); RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); - /* boids */ - //prop= RNA_def_property(srna, "boids_surface_object", PROP_POINTER, PROP_NONE); - //RNA_def_property_pointer_sdna(prop, NULL, "keyed_ob"); - //RNA_def_property_flag(prop, PROP_EDITABLE); - //RNA_def_property_ui_text(prop, "Boids Surface Object", "For boids physics systems, constrain boids to this object's surface."); - //RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); - /* keyed */ prop= RNA_def_property(srna, "keyed_timing", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", PSYS_KEYED_TIMING); @@ -1821,19 +1868,18 @@ static void rna_def_particle_system(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Keyed timing", "Use key times"); RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_redo"); - prop= RNA_def_property(srna, "keyed_targets", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "keyed_targets", NULL); - RNA_def_property_struct_type(prop, "KeyedParticleTarget"); - RNA_def_property_ui_text(prop, "Keyed Targets", "Target particle systems for keyed particles"); + prop= RNA_def_property(srna, "targets", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_type(prop, "ParticleTarget"); + RNA_def_property_ui_text(prop, "Targets", "Target particle systems."); - prop= RNA_def_property(srna, "active_keyed_target", PROP_POINTER, PROP_NONE); - RNA_def_property_struct_type(prop, "KeyedParticleTarget"); - RNA_def_property_pointer_funcs(prop, "rna_ParticleSystem_active_keyed_target_get", NULL, NULL); - RNA_def_property_ui_text(prop, "Active Particle System", "Active particle system being displayed"); + prop= RNA_def_property(srna, "active_particle_target", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "ParticleTarget"); + RNA_def_property_pointer_funcs(prop, "rna_ParticleSystem_active_particle_target_get", NULL, NULL); + RNA_def_property_ui_text(prop, "Active Particle Target", ""); - prop= RNA_def_property(srna, "active_keyed_target_index", PROP_INT, PROP_UNSIGNED); - RNA_def_property_int_funcs(prop, "rna_ParticleSystem_active_keyed_target_index_get", "rna_ParticleSystem_active_keyed_target_index_set", "rna_ParticleSystem_active_keyed_target_index_range"); - RNA_def_property_ui_text(prop, "Active Particle System Index", "Index of active particle system slot."); + prop= RNA_def_property(srna, "active_particle_target_index", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_funcs(prop, "rna_ParticleSystem_active_particle_target_index_get", "rna_ParticleSystem_active_particle_target_index_set", "rna_ParticleSystem_active_particle_target_index_range"); + RNA_def_property_ui_text(prop, "Active Particle Target Index", ""); /* billboard */ @@ -1989,11 +2035,13 @@ static void rna_def_particle_system(BlenderRNA *brna) void RNA_def_particle(BlenderRNA *brna) { + rna_def_particle_target(brna); + rna_def_particle_hair_key(brna); rna_def_particle_key(brna); + rna_def_child_particle(brna); rna_def_particle(brna); - rna_def_keyed_particle_target(brna); rna_def_particle_system(brna); rna_def_particle_settings(brna); } |