Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2009 by Janne Karhu. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include <float.h> 00034 #include <limits.h> 00035 #include <stdlib.h> 00036 00037 #include "RNA_define.h" 00038 00039 #include "rna_internal.h" 00040 00041 #include "DNA_scene_types.h" 00042 #include "DNA_boid_types.h" 00043 #include "DNA_object_types.h" 00044 #include "DNA_particle_types.h" 00045 00046 #include "WM_api.h" 00047 #include "WM_types.h" 00048 00049 EnumPropertyItem boidrule_type_items[] ={ 00050 {eBoidRuleType_Goal, "GOAL", 0, "Goal", "Go to assigned object or loudest assigned signal source"}, 00051 {eBoidRuleType_Avoid, "AVOID", 0, "Avoid", "Get away from assigned object or loudest assigned signal source"}, 00052 {eBoidRuleType_AvoidCollision, "AVOID_COLLISION", 0, "Avoid Collision", "Manoeuvre to avoid collisions with other boids and deflector objects in near future"}, 00053 {eBoidRuleType_Separate, "SEPARATE", 0, "Separate", "Keep from going through other boids"}, 00054 {eBoidRuleType_Flock, "FLOCK", 0, "Flock", "Move to center of neighbors and match their velocity"}, 00055 {eBoidRuleType_FollowLeader, "FOLLOW_LEADER", 0, "Follow Leader", "Follow a boid or assigned object"}, 00056 {eBoidRuleType_AverageSpeed, "AVERAGE_SPEED", 0, "Average Speed", "Maintain speed, flight level or wander"}, 00057 {eBoidRuleType_Fight, "FIGHT", 0, "Fight", "Go to closest enemy and attack when in range"}, 00058 //{eBoidRuleType_Protect, "PROTECT", 0, "Protect", "Go to enemy closest to target and attack when in range"}, 00059 //{eBoidRuleType_Hide, "HIDE", 0, "Hide", "Find a deflector move to it's other side from closest enemy"}, 00060 //{eBoidRuleType_FollowPath, "FOLLOW_PATH", 0, "Follow Path", "Move along a assigned curve or closest curve in a group"}, 00061 //{eBoidRuleType_FollowWall, "FOLLOW_WALL", 0, "Follow Wall", "Move next to a deflector object's in direction of it's tangent"}, 00062 {0, NULL, 0, NULL, NULL}}; 00063 00064 EnumPropertyItem boidruleset_type_items[] ={ 00065 {eBoidRulesetType_Fuzzy, "FUZZY", 0, "Fuzzy", "Rules are gone through top to bottom. Only the first rule that effect above fuzziness threshold is evaluated"}, 00066 {eBoidRulesetType_Random, "RANDOM", 0, "Random", "A random rule is selected for each boid"}, 00067 {eBoidRulesetType_Average, "AVERAGE", 0, "Average", "All rules are averaged"}, 00068 {0, NULL, 0, NULL, NULL}}; 00069 00070 00071 #ifdef RNA_RUNTIME 00072 00073 #include "BKE_context.h" 00074 #include "BKE_depsgraph.h" 00075 #include "BKE_particle.h" 00076 00077 static void rna_Boids_reset(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) 00078 { 00079 if(ptr->type==&RNA_ParticleSystem) { 00080 ParticleSystem *psys = (ParticleSystem*)ptr->data; 00081 00082 psys->recalc = PSYS_RECALC_RESET; 00083 00084 DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA); 00085 } 00086 else 00087 DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA|PSYS_RECALC_RESET); 00088 00089 WM_main_add_notifier(NC_OBJECT|ND_PARTICLE|NA_EDITED, NULL); 00090 } 00091 static void rna_Boids_reset_deps(Main *bmain, Scene *scene, PointerRNA *ptr) 00092 { 00093 if(ptr->type==&RNA_ParticleSystem) { 00094 ParticleSystem *psys = (ParticleSystem*)ptr->data; 00095 00096 psys->recalc = PSYS_RECALC_RESET; 00097 00098 DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA); 00099 } 00100 else 00101 DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA|PSYS_RECALC_RESET); 00102 00103 DAG_scene_sort(bmain, scene); 00104 00105 WM_main_add_notifier(NC_OBJECT|ND_PARTICLE|NA_EDITED, NULL); 00106 } 00107 00108 static StructRNA* rna_BoidRule_refine(struct PointerRNA *ptr) 00109 { 00110 BoidRule *rule= (BoidRule*)ptr->data; 00111 00112 switch(rule->type) { 00113 case eBoidRuleType_Goal: 00114 return &RNA_BoidRuleGoal; 00115 case eBoidRuleType_Avoid: 00116 return &RNA_BoidRuleAvoid; 00117 case eBoidRuleType_AvoidCollision: 00118 return &RNA_BoidRuleAvoidCollision; 00119 case eBoidRuleType_FollowLeader: 00120 return &RNA_BoidRuleFollowLeader; 00121 case eBoidRuleType_AverageSpeed: 00122 return &RNA_BoidRuleAverageSpeed; 00123 case eBoidRuleType_Fight: 00124 return &RNA_BoidRuleFight; 00125 default: 00126 return &RNA_BoidRule; 00127 } 00128 } 00129 00130 static char *rna_BoidRule_path(PointerRNA *ptr) 00131 { 00132 return BLI_sprintfN("rules[\"%s\"]", ((BoidRule*)ptr->data)->name); // XXX not unique 00133 } 00134 00135 static PointerRNA rna_BoidState_active_boid_rule_get(PointerRNA *ptr) 00136 { 00137 BoidState *state= (BoidState*)ptr->data; 00138 BoidRule *rule = (BoidRule*)state->rules.first; 00139 00140 for(; rule; rule=rule->next) { 00141 if(rule->flag & BOIDRULE_CURRENT) 00142 return rna_pointer_inherit_refine(ptr, &RNA_BoidRule, rule); 00143 } 00144 return rna_pointer_inherit_refine(ptr, &RNA_BoidRule, NULL); 00145 } 00146 static void rna_BoidState_active_boid_rule_index_range(PointerRNA *ptr, int *min, int *max) 00147 { 00148 BoidState *state= (BoidState*)ptr->data; 00149 *min= 0; 00150 *max= BLI_countlist(&state->rules)-1; 00151 *max= MAX2(0, *max); 00152 } 00153 00154 static int rna_BoidState_active_boid_rule_index_get(PointerRNA *ptr) 00155 { 00156 BoidState *state= (BoidState*)ptr->data; 00157 BoidRule *rule = (BoidRule*)state->rules.first; 00158 int i=0; 00159 00160 for(; rule; rule=rule->next, i++) { 00161 if(rule->flag & BOIDRULE_CURRENT) 00162 return i; 00163 } 00164 return 0; 00165 } 00166 00167 static void rna_BoidState_active_boid_rule_index_set(struct PointerRNA *ptr, int value) 00168 { 00169 BoidState *state= (BoidState*)ptr->data; 00170 BoidRule *rule = (BoidRule*)state->rules.first; 00171 int i=0; 00172 00173 for(; rule; rule=rule->next, i++) { 00174 if(i==value) 00175 rule->flag |= BOIDRULE_CURRENT; 00176 else 00177 rule->flag &= ~BOIDRULE_CURRENT; 00178 } 00179 } 00180 00181 static int particle_id_check(PointerRNA *ptr) 00182 { 00183 ID *id= ptr->id.data; 00184 00185 return (GS(id->name) == ID_PA); 00186 } 00187 00188 static char *rna_BoidSettings_path(PointerRNA *ptr) 00189 { 00190 BoidSettings *boids = (BoidSettings *)ptr->data; 00191 00192 if(particle_id_check(ptr)) { 00193 ParticleSettings *part = (ParticleSettings*)ptr->id.data; 00194 00195 if (part->boids == boids) 00196 return BLI_sprintfN("boids"); 00197 } 00198 return NULL; 00199 } 00200 00201 static PointerRNA rna_BoidSettings_active_boid_state_get(PointerRNA *ptr) 00202 { 00203 BoidSettings *boids= (BoidSettings*)ptr->data; 00204 BoidState *state = (BoidState*)boids->states.first; 00205 00206 for(; state; state=state->next) { 00207 if(state->flag & BOIDSTATE_CURRENT) 00208 return rna_pointer_inherit_refine(ptr, &RNA_BoidState, state); 00209 } 00210 return rna_pointer_inherit_refine(ptr, &RNA_BoidState, NULL); 00211 } 00212 static void rna_BoidSettings_active_boid_state_index_range(PointerRNA *ptr, int *min, int *max) 00213 { 00214 BoidSettings *boids= (BoidSettings*)ptr->data; 00215 *min= 0; 00216 *max= BLI_countlist(&boids->states)-1; 00217 *max= MAX2(0, *max); 00218 } 00219 00220 static int rna_BoidSettings_active_boid_state_index_get(PointerRNA *ptr) 00221 { 00222 BoidSettings *boids= (BoidSettings*)ptr->data; 00223 BoidState *state = (BoidState*)boids->states.first; 00224 int i=0; 00225 00226 for(; state; state=state->next, i++) { 00227 if(state->flag & BOIDSTATE_CURRENT) 00228 return i; 00229 } 00230 return 0; 00231 } 00232 00233 static void rna_BoidSettings_active_boid_state_index_set(struct PointerRNA *ptr, int value) 00234 { 00235 BoidSettings *boids= (BoidSettings*)ptr->data; 00236 BoidState *state = (BoidState*)boids->states.first; 00237 int i=0; 00238 00239 for(; state; state=state->next, i++) { 00240 if(i==value) 00241 state->flag |= BOIDSTATE_CURRENT; 00242 else 00243 state->flag &= ~BOIDSTATE_CURRENT; 00244 } 00245 } 00246 00247 #else 00248 00249 static void rna_def_boidrule_goal(BlenderRNA *brna) 00250 { 00251 StructRNA *srna; 00252 PropertyRNA *prop; 00253 00254 srna= RNA_def_struct(brna, "BoidRuleGoal", "BoidRule"); 00255 RNA_def_struct_ui_text(srna, "Goal", ""); 00256 RNA_def_struct_sdna(srna, "BoidRuleGoalAvoid"); 00257 00258 prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE); 00259 RNA_def_property_pointer_sdna(prop, NULL, "ob"); 00260 RNA_def_property_flag(prop, PROP_EDITABLE); 00261 RNA_def_property_ui_text(prop, "Object", "Goal object"); 00262 RNA_def_property_update(prop, 0, "rna_Boids_reset_deps"); 00263 00264 prop= RNA_def_property(srna, "use_predict", PROP_BOOLEAN, PROP_NONE); 00265 RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_GOAL_AVOID_PREDICT); 00266 RNA_def_property_ui_text(prop, "Predict", "Predict target movement"); 00267 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00268 } 00269 00270 static void rna_def_boidrule_avoid(BlenderRNA *brna) 00271 { 00272 StructRNA *srna; 00273 PropertyRNA *prop; 00274 00275 srna= RNA_def_struct(brna, "BoidRuleAvoid", "BoidRule"); 00276 RNA_def_struct_ui_text(srna, "Avoid", ""); 00277 RNA_def_struct_sdna(srna, "BoidRuleGoalAvoid"); 00278 00279 prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE); 00280 RNA_def_property_pointer_sdna(prop, NULL, "ob"); 00281 RNA_def_property_flag(prop, PROP_EDITABLE); 00282 RNA_def_property_ui_text(prop, "Object", "Object to avoid"); 00283 RNA_def_property_update(prop, 0, "rna_Boids_reset_deps"); 00284 00285 prop= RNA_def_property(srna, "use_predict", PROP_BOOLEAN, PROP_NONE); 00286 RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_GOAL_AVOID_PREDICT); 00287 RNA_def_property_ui_text(prop, "Predict", "Predict target movement"); 00288 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00289 00290 prop= RNA_def_property(srna, "fear_factor", PROP_FLOAT, PROP_NONE); 00291 RNA_def_property_range(prop, 0.0f, 100.0f); 00292 RNA_def_property_ui_text(prop, "Fear factor", "Avoid object if danger from it is above this threshold"); 00293 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00294 } 00295 00296 static void rna_def_boidrule_avoid_collision(BlenderRNA *brna) 00297 { 00298 StructRNA *srna; 00299 PropertyRNA *prop; 00300 00301 srna= RNA_def_struct(brna, "BoidRuleAvoidCollision", "BoidRule"); 00302 RNA_def_struct_ui_text(srna, "Avoid Collision", ""); 00303 00304 prop= RNA_def_property(srna, "use_avoid", PROP_BOOLEAN, PROP_NONE); 00305 RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_ACOLL_WITH_BOIDS); 00306 RNA_def_property_ui_text(prop, "Boids", "Avoid collision with other boids"); 00307 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00308 00309 prop= RNA_def_property(srna, "use_avoid_collision", PROP_BOOLEAN, PROP_NONE); 00310 RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_ACOLL_WITH_DEFLECTORS); 00311 RNA_def_property_ui_text(prop, "Deflectors", "Avoid collision with deflector objects"); 00312 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00313 00314 prop= RNA_def_property(srna, "look_ahead", PROP_FLOAT, PROP_NONE); 00315 RNA_def_property_range(prop, 0.0f, 100.0f); 00316 RNA_def_property_ui_text(prop, "Look ahead", "Time to look ahead in seconds"); 00317 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00318 } 00319 00320 static void rna_def_boidrule_follow_leader(BlenderRNA *brna) 00321 { 00322 StructRNA *srna; 00323 PropertyRNA *prop; 00324 00325 srna= RNA_def_struct(brna, "BoidRuleFollowLeader", "BoidRule"); 00326 RNA_def_struct_ui_text(srna, "Follow Leader", ""); 00327 00328 prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE); 00329 RNA_def_property_pointer_sdna(prop, NULL, "ob"); 00330 RNA_def_property_flag(prop, PROP_EDITABLE); 00331 RNA_def_property_ui_text(prop, "Object", "Follow this object instead of a boid"); 00332 RNA_def_property_update(prop, 0, "rna_Boids_reset_deps"); 00333 00334 prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE); 00335 RNA_def_property_range(prop, 0.0f, 100.0f); 00336 RNA_def_property_ui_text(prop, "Distance", "Distance behind leader to follow"); 00337 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00338 00339 prop= RNA_def_property(srna, "queue_count", PROP_INT, PROP_NONE); 00340 RNA_def_property_int_sdna(prop, NULL, "queue_size"); 00341 RNA_def_property_range(prop, 0.0f, 100.0f); 00342 RNA_def_property_ui_text(prop, "Queue Size", "How many boids in a line"); 00343 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00344 00345 prop= RNA_def_property(srna, "use_line", PROP_BOOLEAN, PROP_NONE); 00346 RNA_def_property_boolean_sdna(prop, NULL, "options", BRULE_LEADER_IN_LINE); 00347 RNA_def_property_ui_text(prop, "Line", "Follow leader in a line"); 00348 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00349 } 00350 00351 static void rna_def_boidrule_average_speed(BlenderRNA *brna) 00352 { 00353 StructRNA *srna; 00354 PropertyRNA *prop; 00355 00356 srna= RNA_def_struct(brna, "BoidRuleAverageSpeed", "BoidRule"); 00357 RNA_def_struct_ui_text(srna, "Average Speed", ""); 00358 00359 prop= RNA_def_property(srna, "wander", PROP_FLOAT, PROP_NONE); 00360 RNA_def_property_range(prop, 0.0f, 1.0f); 00361 RNA_def_property_ui_text(prop, "Wander", "How fast velocity's direction is randomized"); 00362 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00363 00364 prop= RNA_def_property(srna, "level", PROP_FLOAT, PROP_NONE); 00365 RNA_def_property_range(prop, 0.0f, 1.0f); 00366 RNA_def_property_ui_text(prop, "Level", "How much velocity's z-component is kept constant"); 00367 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00368 00369 prop= RNA_def_property(srna, "speed", PROP_FLOAT, PROP_NONE); 00370 RNA_def_property_range(prop, 0.0f, 1.0f); 00371 RNA_def_property_ui_text(prop, "Speed", "Percentage of maximum speed"); 00372 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00373 } 00374 00375 static void rna_def_boidrule_fight(BlenderRNA *brna) 00376 { 00377 StructRNA *srna; 00378 PropertyRNA *prop; 00379 00380 srna= RNA_def_struct(brna, "BoidRuleFight", "BoidRule"); 00381 RNA_def_struct_ui_text(srna, "Fight", ""); 00382 00383 prop= RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE); 00384 RNA_def_property_range(prop, 0.0f, 100.0f); 00385 RNA_def_property_ui_text(prop, "Fight Distance", "Attack boids at max this distance"); 00386 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00387 00388 prop= RNA_def_property(srna, "flee_distance", PROP_FLOAT, PROP_NONE); 00389 RNA_def_property_range(prop, 0.0f, 100.0f); 00390 RNA_def_property_ui_text(prop, "Flee Distance", "Flee to this distance"); 00391 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00392 } 00393 00394 static void rna_def_boidrule(BlenderRNA *brna) 00395 { 00396 StructRNA *srna; 00397 PropertyRNA *prop; 00398 00399 /* data */ 00400 srna= RNA_def_struct(brna, "BoidRule", NULL); 00401 RNA_def_struct_ui_text(srna , "Boid Rule", ""); 00402 RNA_def_struct_refine_func(srna, "rna_BoidRule_refine"); 00403 RNA_def_struct_path_func(srna, "rna_BoidRule_path"); 00404 00405 /* strings */ 00406 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); 00407 RNA_def_property_ui_text(prop, "Name", "Boid rule name"); 00408 RNA_def_struct_name_property(srna, prop); 00409 00410 /* enums */ 00411 prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); 00412 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00413 RNA_def_property_enum_sdna(prop, NULL, "type"); 00414 RNA_def_property_enum_items(prop, boidrule_type_items); 00415 RNA_def_property_ui_text(prop, "Type", ""); 00416 00417 /* flags */ 00418 prop= RNA_def_property(srna, "use_in_air", PROP_BOOLEAN, PROP_NONE); 00419 RNA_def_property_boolean_sdna(prop, NULL, "flag", BOIDRULE_IN_AIR); 00420 RNA_def_property_ui_text(prop, "In Air", "Use rule when boid is flying"); 00421 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00422 00423 prop= RNA_def_property(srna, "use_on_land", PROP_BOOLEAN, PROP_NONE); 00424 RNA_def_property_boolean_sdna(prop, NULL, "flag", BOIDRULE_ON_LAND); 00425 RNA_def_property_ui_text(prop, "On Land", "Use rule when boid is on land"); 00426 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00427 00428 //prop= RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE); 00429 //RNA_def_property_boolean_sdna(prop, NULL, "mode", eModifierMode_Expanded); 00430 //RNA_def_property_ui_text(prop, "Expanded", "Set modifier expanded in the user interface"); 00431 00432 /* types */ 00433 rna_def_boidrule_goal(brna); 00434 rna_def_boidrule_avoid(brna); 00435 rna_def_boidrule_avoid_collision(brna); 00436 rna_def_boidrule_follow_leader(brna); 00437 rna_def_boidrule_average_speed(brna); 00438 rna_def_boidrule_fight(brna); 00439 } 00440 00441 static void rna_def_boidstate(BlenderRNA *brna) 00442 { 00443 StructRNA *srna; 00444 PropertyRNA *prop; 00445 00446 srna = RNA_def_struct(brna, "BoidState", NULL); 00447 RNA_def_struct_ui_text(srna, "Boid State", "Boid state for boid physics"); 00448 00449 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); 00450 RNA_def_property_ui_text(prop, "Name", "Boid state name"); 00451 RNA_def_struct_name_property(srna, prop); 00452 00453 prop= RNA_def_property(srna, "ruleset_type", PROP_ENUM, PROP_NONE); 00454 RNA_def_property_enum_items(prop, boidruleset_type_items); 00455 RNA_def_property_ui_text(prop, "Rule Evaluation", "How the rules in the list are evaluated"); 00456 00457 prop= RNA_def_property(srna, "rules", PROP_COLLECTION, PROP_NONE); 00458 RNA_def_property_struct_type(prop, "BoidRule"); 00459 RNA_def_property_ui_text(prop, "Boid Rules", ""); 00460 00461 prop= RNA_def_property(srna, "active_boid_rule", PROP_POINTER, PROP_NONE); 00462 RNA_def_property_struct_type(prop, "BoidRule"); 00463 RNA_def_property_pointer_funcs(prop, "rna_BoidState_active_boid_rule_get", NULL, NULL, NULL); 00464 RNA_def_property_ui_text(prop, "Active Boid Rule", ""); 00465 00466 prop= RNA_def_property(srna, "active_boid_rule_index", PROP_INT, PROP_UNSIGNED); 00467 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"); 00468 RNA_def_property_ui_text(prop, "Active Boid Rule Index", ""); 00469 00470 prop= RNA_def_property(srna, "rule_fuzzy", PROP_FLOAT, PROP_NONE); 00471 RNA_def_property_float_sdna(prop, NULL, "rule_fuzziness"); 00472 RNA_def_property_range(prop, 0.0, 1.0); 00473 RNA_def_property_ui_text(prop, "Rule Fuzziness", ""); 00474 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00475 00476 prop= RNA_def_property(srna, "volume", PROP_FLOAT, PROP_NONE); 00477 RNA_def_property_range(prop, 0.0, 100.0); 00478 RNA_def_property_ui_text(prop, "Volume", ""); 00479 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00480 00481 prop= RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_NONE); 00482 RNA_def_property_range(prop, 0.0, 10.0); 00483 RNA_def_property_ui_text(prop, "Falloff", ""); 00484 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00485 } 00486 static void rna_def_boid_settings(BlenderRNA *brna) 00487 { 00488 StructRNA *srna; 00489 PropertyRNA *prop; 00490 00491 srna = RNA_def_struct(brna, "BoidSettings", NULL); 00492 RNA_def_struct_path_func(srna, "rna_BoidSettings_path"); 00493 RNA_def_struct_ui_text(srna, "Boid Settings", "Settings for boid physics"); 00494 00495 prop= RNA_def_property(srna, "land_smooth", PROP_FLOAT, PROP_NONE); 00496 RNA_def_property_float_sdna(prop, NULL, "landing_smoothness"); 00497 RNA_def_property_range(prop, 0.0, 10.0); 00498 RNA_def_property_ui_text(prop, "Landing Smoothness", "How smoothly the boids land"); 00499 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00500 00501 prop= RNA_def_property(srna, "bank", PROP_FLOAT, PROP_NONE); 00502 RNA_def_property_float_sdna(prop, NULL, "banking"); 00503 RNA_def_property_range(prop, 0.0, 2.0); 00504 RNA_def_property_ui_text(prop, "Banking", "Amount of rotation around velocity vector on turns"); 00505 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00506 00507 prop= RNA_def_property(srna, "pitch", PROP_FLOAT, PROP_NONE); 00508 RNA_def_property_float_sdna(prop, NULL, "pitch"); 00509 RNA_def_property_range(prop, 0.0, 2.0); 00510 RNA_def_property_ui_text(prop, "Pitch", "Amount of rotation around side vector"); 00511 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00512 00513 prop= RNA_def_property(srna, "height", PROP_FLOAT, PROP_NONE); 00514 RNA_def_property_range(prop, 0.0, 2.0); 00515 RNA_def_property_ui_text(prop, "Height", "Boid height relative to particle size"); 00516 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00517 00518 /* states */ 00519 prop= RNA_def_property(srna, "states", PROP_COLLECTION, PROP_NONE); 00520 RNA_def_property_struct_type(prop, "BoidState"); 00521 RNA_def_property_ui_text(prop, "Boid States", ""); 00522 00523 prop= RNA_def_property(srna, "active_boid_state", PROP_POINTER, PROP_NONE); 00524 RNA_def_property_struct_type(prop, "BoidRule"); 00525 RNA_def_property_pointer_funcs(prop, "rna_BoidSettings_active_boid_state_get", NULL, NULL, NULL); 00526 RNA_def_property_ui_text(prop, "Active Boid Rule", ""); 00527 00528 prop= RNA_def_property(srna, "active_boid_state_index", PROP_INT, PROP_UNSIGNED); 00529 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"); 00530 RNA_def_property_ui_text(prop, "Active Boid State Index", ""); 00531 00532 /* character properties */ 00533 prop= RNA_def_property(srna, "health", PROP_FLOAT, PROP_NONE); 00534 RNA_def_property_range(prop, 0.0, 100.0); 00535 RNA_def_property_ui_text(prop, "Health", "Initial boid health when born"); 00536 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00537 00538 prop= RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE); 00539 RNA_def_property_range(prop, 0.0, 100.0); 00540 RNA_def_property_ui_text(prop, "Strength", "Maximum caused damage on attack per second"); 00541 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00542 00543 prop= RNA_def_property(srna, "aggression", PROP_FLOAT, PROP_NONE); 00544 RNA_def_property_range(prop, 0.0, 100.0); 00545 RNA_def_property_ui_text(prop, "Aggression", "Boid will fight this times stronger enemy"); 00546 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00547 00548 prop= RNA_def_property(srna, "accuracy", PROP_FLOAT, PROP_NONE); 00549 RNA_def_property_range(prop, 0.0, 1.0); 00550 RNA_def_property_ui_text(prop, "Accuracy", "Accuracy of attack"); 00551 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00552 00553 prop= RNA_def_property(srna, "range", PROP_FLOAT, PROP_NONE); 00554 RNA_def_property_range(prop, 0.0, 100.0); 00555 RNA_def_property_ui_text(prop, "Range", "Maximum distance from which a boid can attack"); 00556 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00557 00558 /* physical properties */ 00559 prop= RNA_def_property(srna, "air_speed_min", PROP_FLOAT, PROP_NONE); 00560 RNA_def_property_float_sdna(prop, NULL, "air_min_speed"); 00561 RNA_def_property_range(prop, 0.0, 1.0); 00562 RNA_def_property_ui_text(prop, "Min Air Speed", "Minimum speed in air (relative to maximum speed)"); 00563 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00564 00565 prop= RNA_def_property(srna, "air_speed_max", PROP_FLOAT, PROP_NONE); 00566 RNA_def_property_float_sdna(prop, NULL, "air_max_speed"); 00567 RNA_def_property_range(prop, 0.0, 100.0); 00568 RNA_def_property_ui_text(prop, "Max Air Speed", "Maximum speed in air"); 00569 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00570 00571 prop= RNA_def_property(srna, "air_acc_max", PROP_FLOAT, PROP_NONE); 00572 RNA_def_property_float_sdna(prop, NULL, "air_max_acc"); 00573 RNA_def_property_range(prop, 0.0, 1.0); 00574 RNA_def_property_ui_text(prop, "Max Air Acceleration", "Maximum acceleration in air (relative to maximum speed)"); 00575 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00576 00577 prop= RNA_def_property(srna, "air_ave_max", PROP_FLOAT, PROP_NONE); 00578 RNA_def_property_float_sdna(prop, NULL, "air_max_ave"); 00579 RNA_def_property_range(prop, 0.0, 1.0); 00580 RNA_def_property_ui_text(prop, "Max Air Angular Velocity", "Maximum angular velocity in air (relative to 180 degrees)"); 00581 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00582 00583 prop= RNA_def_property(srna, "air_personal_space", PROP_FLOAT, PROP_NONE); 00584 RNA_def_property_range(prop, 0.0, 10.0); 00585 RNA_def_property_ui_text(prop, "Air Personal Space", "Radius of boids personal space in air (% of particle size)"); 00586 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00587 00588 prop= RNA_def_property(srna, "land_jump_speed", PROP_FLOAT, PROP_NONE); 00589 RNA_def_property_range(prop, 0.0, 100.0); 00590 RNA_def_property_ui_text(prop, "Jump Speed", "Maximum speed for jumping"); 00591 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00592 00593 prop= RNA_def_property(srna, "land_speed_max", PROP_FLOAT, PROP_NONE); 00594 RNA_def_property_float_sdna(prop, NULL, "land_max_speed"); 00595 RNA_def_property_range(prop, 0.0, 100.0); 00596 RNA_def_property_ui_text(prop, "Max Land Speed", "Maximum speed on land"); 00597 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00598 00599 prop= RNA_def_property(srna, "land_acc_max", PROP_FLOAT, PROP_NONE); 00600 RNA_def_property_float_sdna(prop, NULL, "land_max_acc"); 00601 RNA_def_property_range(prop, 0.0, 1.0); 00602 RNA_def_property_ui_text(prop, "Max Land Acceleration", "Maximum acceleration on land (relative to maximum speed)"); 00603 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00604 00605 prop= RNA_def_property(srna, "land_ave_max", PROP_FLOAT, PROP_NONE); 00606 RNA_def_property_float_sdna(prop, NULL, "land_max_ave"); 00607 RNA_def_property_range(prop, 0.0, 1.0); 00608 RNA_def_property_ui_text(prop, "Max Land Angular Velocity", "Maximum angular velocity on land (relative to 180 degrees)"); 00609 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00610 00611 prop= RNA_def_property(srna, "land_personal_space", PROP_FLOAT, PROP_NONE); 00612 RNA_def_property_range(prop, 0.0, 10.0); 00613 RNA_def_property_ui_text(prop, "Land Personal Space", "Radius of boids personal space on land (% of particle size)"); 00614 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00615 00616 prop= RNA_def_property(srna, "land_stick_force", PROP_FLOAT, PROP_NONE); 00617 RNA_def_property_range(prop, 0.0, 1000.0); 00618 RNA_def_property_ui_text(prop, "Land Stick Force", "How strong a force must be to start effecting a boid on land"); 00619 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00620 00621 /* options */ 00622 prop= RNA_def_property(srna, "use_flight", PROP_BOOLEAN, PROP_NONE); 00623 RNA_def_property_boolean_sdna(prop, NULL, "options", BOID_ALLOW_FLIGHT); 00624 RNA_def_property_ui_text(prop, "Allow Flight", "Allow boids to move in air"); 00625 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00626 00627 prop= RNA_def_property(srna, "use_land", PROP_BOOLEAN, PROP_NONE); 00628 RNA_def_property_boolean_sdna(prop, NULL, "options", BOID_ALLOW_LAND); 00629 RNA_def_property_ui_text(prop, "Allow Land", "Allow boids to move on land"); 00630 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00631 00632 prop= RNA_def_property(srna, "use_climb", PROP_BOOLEAN, PROP_NONE); 00633 RNA_def_property_boolean_sdna(prop, NULL, "options", BOID_ALLOW_CLIMB); 00634 RNA_def_property_ui_text(prop, "Allow Climbing", "Allow boids to climb goal objects"); 00635 RNA_def_property_update(prop, 0, "rna_Boids_reset"); 00636 } 00637 00638 void RNA_def_boid(BlenderRNA *brna) 00639 { 00640 rna_def_boidrule(brna); 00641 rna_def_boidstate(brna); 00642 rna_def_boid_settings(brna); 00643 } 00644 00645 #endif