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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJanne Karhu <jhkarh@gmail.com>2009-10-01 02:10:14 +0400
committerJanne Karhu <jhkarh@gmail.com>2009-10-01 02:10:14 +0400
commitbff893a42047cfc92671f878109c1ff17ce5f8a2 (patch)
treef18bfc386773e1878fc4805a57618af481bc876e /source/blender/editors
parent7d9bfdc31ab179b4dd4a626bc8f9a873c59402b4 (diff)
Unified effector functionality for particles, cloth and softbody
* Unified scene wide gravity (currently in scene buttons) instead of each simulation having it's own gravity. * Weight parameters for all effectors and an effector group setting. * Every effector can use noise. * Most effectors have "shapes" point, plane, surface, every point. - "Point" is most like the old effectors and uses the effector location as the effector point. - "Plane" uses the closest point on effectors local xy-plane as the effector point. - "Surface" uses the closest point on an effector object's surface as the effector point. - "Every Point" uses every point in a mesh effector object as an effector point. - The falloff is calculated from this point, so for example with "surface" shape and "use only negative z axis" it's possible to apply force only "inside" the effector object. * Spherical effector is now renamed as "force" as it's no longer just spherical. * New effector parameter "flow", which makes the effector act as surrounding air velocity, so the resulting force is proportional to the velocity difference of the point and "air velocity". For example a wind field with flow=1.0 results in proper non-accelerating wind. * New effector fields "turbulence", which creates nice random flow paths, and "drag", which slows the points down. * Much improved vortex field. * Effectors can now effect particle rotation as well as location. * Use full, or only positive/negative z-axis to apply force (note. the z-axis is the surface normal in the case of effector shape "surface") * New "force field" submenu in add menu, which adds an empty with the chosen effector (curve object for corve guides). * Other dynamics should be quite easy to add to the effector system too if wanted. * "Unified" doesn't mean that force fields give the exact same results for particles, softbody & cloth, since their final effect depends on many external factors, like for example the surface area of the effected faces. Code changes * Subversion bump for correct handling of global gravity. * Separate ui py file for common dynamics stuff. * Particle settings updating is flushed with it's id through DAG_id_flush_update(..). Known issues * Curve guides don't yet have all ui buttons in place, but they should work none the less. * Hair dynamics don't yet respect force fields. Other changes * Particle emission defaults now to frames 1-200 with life of 50 frames to fill the whole default timeline. * Many particles drawing related crashes fixed. * Sometimes particles didn't update on first frame properly. * Hair with object/group visualization didn't work properly. * Memory leaks with PointCacheID lists (Genscher, remember to free pidlists after use :).
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/object/object_add.c88
-rw-r--r--source/blender/editors/object/object_edit.c1
-rw-r--r--source/blender/editors/object/object_intern.h1
-rw-r--r--source/blender/editors/object/object_modifier.c6
-rw-r--r--source/blender/editors/object/object_ops.c1
-rw-r--r--source/blender/editors/physics/particle_boids.c12
-rw-r--r--source/blender/editors/space_view3d/drawobject.c8
-rw-r--r--source/blender/editors/transform/transform_conversions.c1
8 files changed, 106 insertions, 12 deletions
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index 05905cd42a4..7188368a95f 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -38,6 +38,7 @@
#include "DNA_meta_types.h"
#include "DNA_object_fluidsim.h"
#include "DNA_object_types.h"
+#include "DNA_object_force.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_userdef_types.h"
@@ -56,6 +57,7 @@
#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_displist.h"
+#include "BKE_effect.h"
#include "BKE_global.h"
#include "BKE_group.h"
#include "BKE_lattice.h"
@@ -190,6 +192,90 @@ void OBJECT_OT_add(wmOperatorType *ot)
RNA_def_enum(ot->srna, "type", object_type_items, 0, "Type", "");
}
+/********************* Add Effector Operator ********************/
+/* copy from rna_object_force.c*/
+static EnumPropertyItem field_type_items[] = {
+ {0, "NONE", 0, "None", ""},
+ {PFIELD_FORCE, "FORCE", 0, "Force", ""},
+ {PFIELD_WIND, "WIND", 0, "Wind", ""},
+ {PFIELD_VORTEX, "VORTEX", 0, "Vortex", ""},
+ {PFIELD_MAGNET, "MAGNET", 0, "Magnetic", ""},
+ {PFIELD_HARMONIC, "HARMONIC", 0, "Harmonic", ""},
+ {PFIELD_CHARGE, "CHARGE", 0, "Charge", ""},
+ {PFIELD_LENNARDJ, "LENNARDJ", 0, "Lennard-Jones", ""},
+ {PFIELD_TEXTURE, "TEXTURE", 0, "Texture", ""},
+ {PFIELD_GUIDE, "GUIDE", 0, "Curve Guide", ""},
+ {PFIELD_BOID, "BOID", 0, "Boid", ""},
+ {PFIELD_TURBULENCE, "TURBULENCE", 0, "Turbulence", ""},
+ {PFIELD_DRAG, "DRAG", 0, "Drag", ""},
+ {0, NULL, 0, NULL, NULL}};
+
+void add_effector_draw(Scene *scene, View3D *v3d, int type) /* for toolbox or menus, only non-editmode stuff */
+{
+ /* keep here to get things compile, remove later */
+}
+
+/* for effector add primitive operators */
+static Object *effector_add_type(bContext *C, int type)
+{
+ Scene *scene= CTX_data_scene(C);
+ Object *ob;
+
+ /* for as long scene has editmode... */
+ if (CTX_data_edit_object(C))
+ ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
+
+ /* deselects all, sets scene->basact */
+ if(type==PFIELD_GUIDE) {
+ ob = add_object(scene, OB_CURVE);
+ ((Curve*)ob->data)->flag |= CU_PATH|CU_3D;
+ ED_object_enter_editmode(C, 0);
+ BLI_addtail(curve_get_editcurve(ob), add_nurbs_primitive(C, CU_NURBS|CU_PRIM_PATH, 1));
+ ED_object_exit_editmode(C, EM_FREEDATA);
+ }
+ else
+ ob= add_object(scene, OB_EMPTY);
+
+ ob->pd= object_add_collision_fields(type);
+
+ /* editor level activate, notifiers */
+ ED_base_object_activate(C, BASACT);
+
+ /* more editor stuff */
+ ED_object_base_init_from_view(C, BASACT);
+
+ DAG_scene_sort(scene);
+
+ return ob;
+}
+
+/* for object add operator */
+static int effector_add_exec(bContext *C, wmOperator *op)
+{
+ effector_add_type(C, RNA_int_get(op->ptr, "type"));
+
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_effector_add(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Add Effector";
+ ot->description = "Add an empty object with a physics effector to the scene.";
+ ot->idname= "OBJECT_OT_effector_add";
+
+ /* api callbacks */
+ ot->invoke= WM_menu_invoke;
+ ot->exec= effector_add_exec;
+
+ ot->poll= ED_operator_scene_editable;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ RNA_def_enum(ot->srna, "type", field_type_items, 0, "Type", "");
+}
+
/* ***************** add primitives *************** */
/* ****** work both in and outside editmode ****** */
@@ -616,6 +702,8 @@ static int object_primitive_add_invoke(bContext *C, wmOperator *op, wmEvent *eve
uiItemS(layout);
uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_CAMERA, "OBJECT_OT_add", "type", OB_CAMERA);
uiItemMenuEnumO(layout, "Lamp", ICON_OUTLINER_OB_LAMP, "OBJECT_OT_lamp_add", "type");
+ uiItemS(layout);
+ uiItemMenuEnumO(layout, "Force Field", ICON_OUTLINER_OB_EMPTY, "OBJECT_OT_effector_add", "type");
uiPupMenuEnd(C, pup);
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index ee0b043a9a1..54df3ae92da 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -346,6 +346,7 @@ void ED_object_exit_editmode(bContext *C, int flag)
if(pid->type != PTCACHE_TYPE_PARTICLES) /* particles don't need reset on geometry change */
pid->cache->flag |= PTCACHE_OUTDATED;
}
+ BLI_freelistN(&pidlist);
BKE_ptcache_object_reset(scene, obedit, PTCACHE_RESET_OUTDATED);
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index c5499ef8f5d..474715c593b 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -91,6 +91,7 @@ void OBJECT_OT_text_add(struct wmOperatorType *ot);
void OBJECT_OT_armature_add(struct wmOperatorType *ot);
void OBJECT_OT_lamp_add(struct wmOperatorType *ot);
void OBJECT_OT_primitive_add(struct wmOperatorType *ot); /* only used as menu */
+void OBJECT_OT_effector_add(struct wmOperatorType *ot);
void OBJECT_OT_duplicates_make_real(struct wmOperatorType *ot);
void OBJECT_OT_duplicate(struct wmOperatorType *ot);
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index cc8cc420bf7..7f0f1876417 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -110,7 +110,7 @@ int ED_object_modifier_add(ReportList *reports, Scene *scene, Object *ob, int ty
}
else if(type == eModifierType_Collision) {
if(!ob->pd)
- ob->pd= object_add_collision_fields();
+ ob->pd= object_add_collision_fields(0);
ob->pd->deflect= 1;
DAG_scene_sort(scene);
@@ -159,8 +159,8 @@ int ED_object_modifier_remove(ReportList *reports, Scene *scene, Object *ob, Mod
DAG_scene_sort(scene);
}
else if(md->type == eModifierType_Surface) {
- if(ob->pd)
- ob->pd->flag &= ~PFIELD_SURFACE;
+ if(ob->pd && ob->pd->shape == PFIELD_SHAPE_SURFACE)
+ ob->pd->shape = PFIELD_SHAPE_PLANE;
DAG_scene_sort(scene);
}
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index 3f975d1e807..9bfd6a4201c 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -117,6 +117,7 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_armature_add);
WM_operatortype_append(OBJECT_OT_lamp_add);
WM_operatortype_append(OBJECT_OT_add);
+ WM_operatortype_append(OBJECT_OT_effector_add);
WM_operatortype_append(OBJECT_OT_primitive_add);
WM_operatortype_append(OBJECT_OT_mesh_add);
WM_operatortype_append(OBJECT_OT_metaball_add);
diff --git a/source/blender/editors/physics/particle_boids.c b/source/blender/editors/physics/particle_boids.c
index 47d073e2dbb..0b63f1a98ff 100644
--- a/source/blender/editors/physics/particle_boids.c
+++ b/source/blender/editors/physics/particle_boids.c
@@ -78,7 +78,7 @@ static int rule_add_exec(bContext *C, wmOperator *op)
BLI_addtail(&state->rules, rule);
- psys_flush_particle_settings(scene, part, PSYS_RECALC_RESET);
+ DAG_id_flush_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
return OPERATOR_FINISHED;
@@ -129,7 +129,7 @@ static int rule_del_exec(bContext *C, wmOperator *op)
rule->flag |= BOIDRULE_CURRENT;
DAG_scene_sort(scene);
- psys_flush_particle_settings(scene, psys->part, PSYS_RECALC_RESET);
+ DAG_id_flush_update(&psys->part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
@@ -168,7 +168,7 @@ static int rule_move_up_exec(bContext *C, wmOperator *op)
BLI_remlink(&state->rules, rule);
BLI_insertlink(&state->rules, rule->prev->prev, rule);
- psys_flush_particle_settings(scene, psys->part, PSYS_RECALC_RESET);
+ DAG_id_flush_update(&psys->part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
break;
}
@@ -207,7 +207,7 @@ static int rule_move_down_exec(bContext *C, wmOperator *op)
BLI_remlink(&state->rules, rule);
BLI_insertlink(&state->rules, rule->next, rule);
- psys_flush_particle_settings(scene, psys->part, PSYS_RECALC_RESET);
+ DAG_id_flush_update(&psys->part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
break;
}
@@ -303,7 +303,7 @@ static int state_del_exec(bContext *C, wmOperator *op)
state->flag |= BOIDSTATE_CURRENT;
DAG_scene_sort(scene);
- psys_flush_particle_settings(scene, psys->part, PSYS_RECALC_RESET);
+ DAG_id_flush_update(&psys->part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
@@ -378,7 +378,7 @@ static int state_move_down_exec(bContext *C, wmOperator *op)
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);
+ DAG_id_flush_update(&psys->part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
break;
}
}
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 60ae91e7a89..db3b7130ab3 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -3159,9 +3159,11 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
ma_g = ma->g;
ma_b = ma->b;
- pdd->ma_r = &ma_r;
- pdd->ma_g = &ma_g;
- pdd->ma_b = &ma_b;
+ if(pdd) {
+ pdd->ma_r = &ma_r;
+ pdd->ma_g = &ma_g;
+ pdd->ma_b = &ma_b;
+ }
create_cdata = 1;
}
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index 8d709d1b38a..f6d30a7bec9 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -4848,6 +4848,7 @@ void special_aftertrans_update(TransInfo *t)
if(pid->type != PTCACHE_TYPE_PARTICLES) /* particles don't need reset on geometry change */
pid->cache->flag |= PTCACHE_OUTDATED;
}
+ BLI_freelistN(&pidlist);
/* pointcache refresh */
if (BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_OUTDATED))