diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-02-20 23:39:27 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-02-20 23:39:27 +0300 |
commit | ebd2b1212de7bfc1fabb3af114e954beefd0798c (patch) | |
tree | c5aa448df9f03375566fbc019cb83477f992d9a7 /source/blender | |
parent | 39c2b438a9490468625bd047fdf7b4c02c5348ef (diff) |
2.5: Particle Edit, work in progress commit.
* Still incomplete and some operators don't work, refresh issues, etc.
* Made Hide/Reveal operators consistent for various modes.
Diffstat (limited to 'source/blender')
24 files changed, 1913 insertions, 1480 deletions
diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c index 51d46bb70bf..12554c8492f 100644 --- a/source/blender/editors/armature/armature_ops.c +++ b/source/blender/editors/armature/armature_ops.c @@ -192,7 +192,7 @@ void ED_keymap_armature(wmWindowManager *wm) WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, 0, 0); kmi= WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0); - RNA_boolean_set(kmi->ptr, "invert", 1); + RNA_boolean_set(kmi->ptr, "unselected", 1); WM_keymap_add_item(keymap, "POSE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0); /*clear pose*/ WM_keymap_add_item(keymap, "POSE_OT_rot_clear", RKEY, KM_PRESS, KM_ALT, 0); diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 403e5750030..3d8753d3ade 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -4703,7 +4703,7 @@ static int pose_hide_exec(bContext *C, wmOperator *op) Object *ob= CTX_data_active_object(C); bArmature *arm= ob->data; - if(RNA_boolean_get(op->ptr, "invert")) + if(RNA_boolean_get(op->ptr, "unselected")) bone_looper(ob, arm->bonebase.first, NULL, hide_unselected_pose_bone); else @@ -4719,7 +4719,7 @@ static int pose_hide_exec(bContext *C, wmOperator *op) void POSE_OT_hide(wmOperatorType *ot) { /* identifiers */ - ot->name= "Hide Selection"; + ot->name= "Hide Selected"; ot->idname= "POSE_OT_hide"; /* api callbacks */ @@ -4730,7 +4730,7 @@ void POSE_OT_hide(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ - RNA_def_boolean(ot->srna, "invert", 0, "Invert", ""); + RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", ""); } static int show_pose_bone(Object *ob, Bone *bone, void *ptr) @@ -4764,7 +4764,7 @@ static int pose_reveal_exec(bContext *C, wmOperator *op) void POSE_OT_reveal(wmOperatorType *ot) { /* identifiers */ - ot->name= "Reveil Selection"; + ot->name= "Reveal Selected"; ot->idname= "POSE_OT_reveal"; /* api callbacks */ @@ -4773,9 +4773,6 @@ void POSE_OT_reveal(wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - - /* props */ - RNA_def_boolean(ot->srna, "invert", 0, "Invert", ""); } /* ************* RENAMING DISASTERS ************ */ diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c index 8f0d408ca3a..b951829d9d1 100644 --- a/source/blender/editors/armature/poseobject.c +++ b/source/blender/editors/armature/poseobject.c @@ -128,7 +128,7 @@ void ED_armature_enter_posemode(bContext *C, Base *base) ob->flag |= OB_POSEMODE; base->flag= ob->flag; - WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_POSEMODE, NULL); + WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_POSE, NULL); break; default: diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c index 8958dc9b6d7..8989d8720eb 100644 --- a/source/blender/editors/curve/curve_ops.c +++ b/source/blender/editors/curve/curve_ops.c @@ -237,7 +237,7 @@ void ED_keymap_curve(wmWindowManager *wm) WM_keymap_add_item(keymap, "CURVE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_ALT|KM_CTRL, 0); - RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "deselected", 1); + RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "unselected", 1); WM_keymap_add_item(keymap, "CURVE_OT_specials_menu", WKEY, KM_PRESS, 0, 0); } diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 5140cdf3855..830d36dcfd8 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -1618,7 +1618,7 @@ static int hide_exec(bContext *C, wmOperator *op) Nurb *nu; BPoint *bp; BezTriple *bezt; - int a, sel, invert= RNA_boolean_get(op->ptr, "deselected"); + int a, sel, invert= RNA_boolean_get(op->ptr, "unselected"); for(nu= editnurb->first; nu; nu= nu->next) { if((nu->type & 7)==CU_BEZIER) { @@ -1668,7 +1668,7 @@ static int hide_exec(bContext *C, wmOperator *op) void CURVE_OT_hide(wmOperatorType *ot) { /* identifiers */ - ot->name= "Hide Selection"; + ot->name= "Hide Selected"; ot->idname= "CURVE_OT_hide"; /* api callbacks */ @@ -1679,7 +1679,7 @@ void CURVE_OT_hide(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ - RNA_def_boolean(ot->srna, "deselected", 0, "Deselected", "Hide deselected rather than selected."); + RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected."); } /********************** reveal operator *********************/ diff --git a/source/blender/editors/include/ED_editparticle.h b/source/blender/editors/include/ED_particle.h index e719562d5d6..b20db0cb7e8 100644 --- a/source/blender/editors/include/ED_editparticle.h +++ b/source/blender/editors/include/ED_particle.h @@ -27,8 +27,8 @@ * ***** END GPL LICENSE BLOCK ***** */ -#ifndef ED_EDITPARTICLE_H -#define ED_EDITPARTICLE_H +#ifndef ED_PARTICLE_H +#define ED_PARTICLE_H struct Object; struct ParticleSystem; @@ -36,18 +36,19 @@ struct ParticleEditSettings; struct RadialControl; struct ViewContext; struct rcti; +struct wmWindowManager; /* particle edit mode */ void PE_set_particle_edit(struct Scene *scene); -void PE_create_particle_edit(struct Object *ob, struct ParticleSystem *psys); +void PE_create_particle_edit(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys); void PE_free_particle_edit(struct ParticleSystem *psys); void PE_change_act(void *ob_v, void *act_v); -void PE_change_act_psys(struct Object *ob, struct ParticleSystem *psys); +void PE_change_act_psys(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys); int PE_can_edit(struct ParticleSystem *psys); /* access */ -struct ParticleSystem *PE_get_current(struct Object *ob); +struct ParticleSystem *PE_get_current(struct Scene *scene, struct Object *ob); short PE_get_current_num(struct Object *ob); int PE_minmax(struct Scene *scene, float *min, float *max); void PE_get_colors(char sel[4], char nosel[4]); @@ -69,18 +70,16 @@ void PE_select_less(void); void PE_select_more(void); void PE_mouse_particles(void); -void PE_borderselect(struct ViewContext *vc, struct rcti *rect, int select); -void PE_selectionCB(short selecting, struct Object *editobj, short *mval, float rad); -void PE_do_lasso_select(struct ViewContext *, short mcords[][2], short moves, short select); +void PE_border_select(struct ViewContext *vc, struct rcti *rect, int select); +void PE_circle_select(struct ViewContext *vc, int selecting, short *mval, float rad); +void PE_lasso_select(struct ViewContext *vc, short mcords[][2], short moves, short select); /* tools */ void PE_hide(int mode); void PE_rekey(void); void PE_subdivide(Object *ob); int PE_brush_particles(void); -void PE_delete_particle(void); void PE_remove_doubles(void); -void PE_mirror_x(Scene *scene, int tagged); void PE_selectbrush_menu(Scene *scene); void PE_remove_doubles(void); void PE_radialcontrol_start(const int mode); @@ -90,7 +89,11 @@ void PE_undo_push(Scene *scene, char *str); void PE_undo_step(Scene *scene, int step); void PE_undo(Scene *scene); void PE_redo(Scene *scene); -void PE_undo_menu(Scene *scene); +void PE_undo_menu(Scene *scene, Object *ob); -#endif /* ED_EDITPARTICLE_H */ +/* operators */ +void ED_operatortypes_particle(void); +void ED_keymap_particle(struct wmWindowManager *wm); + +#endif /* ED_PARTICLE_H */ diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 37e9c657d27..1ab61da83bb 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -33,6 +33,7 @@ struct ARegion; struct View3D; struct RegionView3D; struct ViewContext; +struct bglMats; struct BPoint; struct Nurb; struct BezTriple; @@ -122,6 +123,7 @@ void view3d_set_viewcontext(struct bContext *C, struct ViewContext *vc); void view3d_operator_needs_opengl(const struct bContext *C); void view3d_get_view_aligned_coordinate(struct ViewContext *vc, float *fp, short mval[2]); void view3d_get_object_project_mat(struct RegionView3D *v3d, struct Object *ob, float pmat[4][4], float vmat[4][4]);; +void view3d_get_transformation(struct ViewContext *vc, struct Object *ob, struct bglMats *mats); /* XXX should move to arithb.c */ int edge_inside_circle(short centx, short centy, short rad, short x1, short y1, short x2, short y2); diff --git a/source/blender/editors/mesh/editmesh_mods.c b/source/blender/editors/mesh/editmesh_mods.c index f6215f5120b..8d2925ee1b6 100644 --- a/source/blender/editors/mesh/editmesh_mods.c +++ b/source/blender/editors/mesh/editmesh_mods.c @@ -2631,7 +2631,7 @@ static int hide_mesh_exec(bContext *C, wmOperator *op) Object *obedit= CTX_data_edit_object(C); EditMesh *em= ((Mesh *)obedit->data)->edit_mesh; - EM_hide_mesh(em, RNA_boolean_get(op->ptr, "invert")); + EM_hide_mesh(em, RNA_boolean_get(op->ptr, "unselected")); WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit); return OPERATOR_FINISHED; @@ -2651,7 +2651,7 @@ void MESH_OT_hide(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ - RNA_def_boolean(ot->srna, "invert", 0, "Invert", "Hide unselected rather than selected."); + RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected."); } void EM_reveal_mesh(EditMesh *em) diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index bf69369b460..d0d7e834fcf 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -234,7 +234,7 @@ void ED_keymap_mesh(wmWindowManager *wm) /* hide */ WM_keymap_add_item(keymap, "MESH_OT_hide", HKEY, KM_PRESS, 0, 0); - RNA_boolean_set(WM_keymap_add_item(keymap, "MESH_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "invert", 1); + RNA_boolean_set(WM_keymap_add_item(keymap, "MESH_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1); WM_keymap_add_item(keymap, "MESH_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0); /* tools */ diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index a8e499c2547..6e2b38acd8d 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -112,7 +112,7 @@ #include "ED_anim_api.h" #include "ED_armature.h" #include "ED_curve.h" -#include "ED_editparticle.h" +#include "ED_particle.h" #include "ED_mesh.h" #include "ED_object.h" #include "ED_screen.h" @@ -6366,15 +6366,8 @@ void texspace_edit(Scene *scene, View3D *v3d) void mirrormenu(void) { - Scene *scene= NULL; // XXX - - if(G.f & G_PARTICLEEDIT) { - PE_mirror_x(scene, 0); - } - else { // XXX initTransform(TFM_MIRROR, CTX_NO_PET); // XXX Transform(); - } } void hookmenu(Scene *scene, View3D *v3d) diff --git a/source/blender/editors/physics/editparticle.c b/source/blender/editors/physics/editparticle.c index 89d4466d849..4751bd7bb33 100644 --- a/source/blender/editors/physics/editparticle.c +++ b/source/blender/editors/physics/editparticle.c @@ -1,6 +1,4 @@ -/* editparticle.c - * - * +/* * $Id: editparticle.c $ * * ***** BEGIN GPL LICENSE BLOCK ***** @@ -46,6 +44,7 @@ #include "DNA_view3d_types.h" #include "DNA_screen_types.h" #include "DNA_space_types.h" +#include "DNA_windowmanager_types.h" #include "BKE_DerivedMesh.h" #include "BKE_depsgraph.h" @@ -56,6 +55,7 @@ #include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_particle.h" +#include "BKE_report.h" #include "BKE_scene.h" #include "BKE_utildefines.h" @@ -70,11 +70,18 @@ #include "BIF_gl.h" #include "BIF_glutil.h" -#include "ED_editparticle.h" +#include "ED_particle.h" #include "ED_view3d.h" +#include "UI_interface.h" #include "UI_resources.h" +#include "WM_api.h" +#include "WM_types.h" + +#include "RNA_access.h" +#include "RNA_define.h" + #include "physics_intern.h" static void ParticleUndo_clear(ParticleSystem *psys); @@ -83,17 +90,46 @@ static void ParticleUndo_clear(ParticleSystem *psys); #define LOOP_KEYS(k,key) if(psys->edit)for(k=0, key=psys->edit->keys[i]; k<pa->totkey; k++, key++) /* XXX */ -static void BIF_undo_push() {} static void error() {} -static int pupmenu() {return 0;} static int lasso_inside() {return 0;} static void *mesh_get_x_mirror_faces() {return NULL;} -#define LEFTMOUSE 0 + #define RADIALCONTROL_SIZE 0 #define RADIALCONTROL_STRENGTH 0 #define RADIALCONTROL_NONE 0 /* XXX */ + +/**************************** utilities *******************************/ + +static int PE_poll(bContext *C) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + ParticleSystem *psys; + + if(!scene || !ob) + return 0; + + psys= PE_get_current(scene, ob); + + return (psys && psys->edit && (G.f & G_PARTICLEEDIT)); +} + +static int PE_poll_3dview(bContext *C) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + ParticleSystem *psys; + + if(!scene || !ob || !CTX_wm_region_view3d(C)) + return 0; + + psys= PE_get_current(scene, ob); + + return (psys && psys->edit && (G.f & G_PARTICLEEDIT)); +} + void PE_free_particle_edit(ParticleSystem *psys) { ParticleEdit *edit=psys->edit; @@ -103,34 +139,37 @@ void PE_free_particle_edit(ParticleSystem *psys) ParticleUndo_clear(psys); - if(edit->keys){ - for(i=0; i<totpart; i++){ + if(edit->keys) { + for(i=0; i<totpart; i++) { if(edit->keys[i]) MEM_freeN(edit->keys[i]); } + MEM_freeN(edit->keys); } if(edit->mirror_cache) MEM_freeN(edit->mirror_cache); - if(edit->emitter_cosnos){ + if(edit->emitter_cosnos) { MEM_freeN(edit->emitter_cosnos); - edit->emitter_cosnos=0; + edit->emitter_cosnos= 0; } - if(edit->emitter_field){ + if(edit->emitter_field) { BLI_kdtree_free(edit->emitter_field); - edit->emitter_field=0; + edit->emitter_field= 0; } MEM_freeN(edit); - psys->edit=NULL; + psys->edit= NULL; } + /************************************************/ /* Edit Mode Helpers */ /************************************************/ + int PE_can_edit(ParticleSystem *psys) { return (psys && psys->edit && (G.f & G_PARTICLEEDIT)); @@ -143,27 +182,28 @@ ParticleEditSettings *PE_settings(Scene *scene) void PE_change_act(void *ob_v, void *act_v) { - Object *ob = ob_v; + Scene *scene= NULL; // XXX + Object *ob= ob_v; ParticleSystem *psys; - short act = *((short*)act_v) - 1; + short act= *((short*)act_v) - 1; if((psys=psys_get_current(ob))) psys->flag &= ~PSYS_CURRENT; - if(act>=0){ + if(act>=0) { if((psys=BLI_findlink(&ob->particlesystem,act))) { psys->flag |= PSYS_CURRENT; if(psys_check_enabled(ob, psys)) { if(G.f & G_PARTICLEEDIT && !psys->edit) - PE_create_particle_edit(ob, psys); + PE_create_particle_edit(scene, ob, psys); PE_recalc_world_cos(ob, psys); } } } } -void PE_change_act_psys(Object *ob, ParticleSystem *psys) +void PE_change_act_psys(Scene *scene, Object *ob, ParticleSystem *psys) { ParticleSystem *p; @@ -174,13 +214,13 @@ void PE_change_act_psys(Object *ob, ParticleSystem *psys) if(psys_check_enabled(ob, psys)) { if(G.f & G_PARTICLEEDIT && !psys->edit) - PE_create_particle_edit(ob, psys); + PE_create_particle_edit(scene, ob, psys); PE_recalc_world_cos(ob, psys); } } /* always gets atleast the first particlesystem even if PSYS_CURRENT flag is not set */ -ParticleSystem *PE_get_current(Object *ob) +ParticleSystem *PE_get_current(Scene *scene, Object *ob) { ParticleSystem *psys; @@ -188,7 +228,7 @@ ParticleSystem *PE_get_current(Object *ob) return NULL; psys= ob->particlesystem.first; - while(psys){ + while(psys) { if(psys->flag & PSYS_CURRENT) break; psys=psys->next; @@ -199,10 +239,10 @@ ParticleSystem *PE_get_current(Object *ob) psys->flag |= PSYS_CURRENT; } - if(psys && psys_check_enabled(ob, psys)) // XXX && ob == OBACT && (G.f & G_PARTICLEEDIT)) + if(psys && psys_check_enabled(ob, psys)) // XXX && (ob == scene->obact) && (G.f & G_PARTICLEEDIT)) if(psys->part->type == PART_HAIR && psys->flag & PSYS_EDITED) if(psys->edit == NULL) - PE_create_particle_edit(ob, psys); + PE_create_particle_edit(scene, ob, psys); return psys; } @@ -211,9 +251,9 @@ ParticleSystem *PE_get_current(Object *ob) short PE_get_current_num(Object *ob) { short num=0; - ParticleSystem *psys = ob->particlesystem.first; + ParticleSystem *psys= ob->particlesystem.first; - while(psys){ + while(psys) { if(psys->flag & PSYS_CURRENT) return num; num++; @@ -228,100 +268,114 @@ void PE_hide_keys_time(Scene *scene, ParticleSystem *psys, float cfra) ParticleData *pa; ParticleEditKey *key; ParticleEditSettings *pset=PE_settings(scene); - int i,k,totpart=psys->totpart; + int i, k, totpart=psys->totpart; - if(pset->draw_timed && scene->selectmode==SCE_SELECT_POINT){ - LOOP_PARTICLES(i,pa){ - LOOP_KEYS(k,key){ + if(pset->draw_timed && scene->selectmode==SCE_SELECT_POINT) { + LOOP_PARTICLES(i,pa) { + LOOP_KEYS(k,key) { if(fabs(cfra-*key->time) < pset->draw_timed) key->flag &= ~PEK_HIDE; - else{ + else { key->flag |= PEK_HIDE; key->flag &= ~PEK_SELECT; } } } } - else{ - LOOP_PARTICLES(i,pa){ - LOOP_KEYS(k,key){ + else { + LOOP_PARTICLES(i,pa) { + LOOP_KEYS(k,key) { key->flag &= ~PEK_HIDE; } } } } -static int key_inside_circle(short mco[2], float rad, float co[3], float *distance) -{ - ARegion *ar= NULL; // XXX - float dx,dy,dist; - short vertco[2]; +/****************** common struct passed to callbacks ******************/ - project_short(ar, co, vertco); - - if (vertco[0]==IS_CLIPPED) - return 0; +typedef struct PEData { + ViewContext vc; + bglMats mats; - dx=(float)(mco[0]-vertco[0]); - dy=(float)(mco[1]-vertco[1]); - dist=(float)sqrt((double)(dx*dx + dy*dy)); + Scene *scene; + Object *ob; + DerivedMesh *dm; + ParticleSystem *psys; - if(dist<=rad){ - if(distance) *distance=dist; - return 1; - } - else - return 0; -} -static int key_inside_rect(rcti *rect, float co[3]) + short *mval; + rcti *rect; + float rad; + float dist; + float dval; + int select; + + float *dvec; + float combfac; + float pufffac; + float cutfac; + float smoothfac; + float weightfac; + float growfac; + + int invert; + int tot; + float vec[3]; +} PEData; + +static void PE_set_data(bContext *C, PEData *data) { - ARegion *ar= NULL; // XXX - short vertco[2]; + memset(data, 0, sizeof(*data)); - project_short(ar, co,vertco); + data->scene= CTX_data_scene(C); + data->ob= CTX_data_active_object(C); + data->psys= PE_get_current(data->scene, data->ob); +} - if (vertco[0]==IS_CLIPPED) - return 0; - - if(vertco[0] > rect->xmin && vertco[0] < rect->xmax && - vertco[1] > rect->ymin && vertco[1] < rect->ymax) - return 1; - else - return 0; +static void PE_set_view3d_data(bContext *C, PEData *data) +{ + PE_set_data(C, data); + + view3d_set_viewcontext(C, &data->vc); + view3d_get_transformation(&data->vc, data->ob, &data->mats); } -static int test_key_depth(float *co, bglMats *mats) +/*************************** selection utilities *******************************/ + +static int key_test_depth(PEData *data, float co[3]) { - ARegion *ar= NULL; // XXX - View3D *v3d= NULL; - RegionView3D *rv3d= ar->regiondata; + View3D *v3d= data->vc.v3d; + RegionView3D *rv3d= data->vc.rv3d; double ux, uy, uz; float depth; short wco[3], x,y; - if((v3d->drawtype<=OB_WIRE) || (v3d->flag & V3D_ZBUF_SELECT)==0) return 1; - - gluProject(co[0],co[1],co[2], mats->modelview, mats->projection, - (GLint *)mats->viewport, &ux, &uy, &uz ); + /* nothing to do */ + if((v3d->drawtype<=OB_WIRE) || (v3d->flag & V3D_ZBUF_SELECT)==0) + return 1; - project_short(ar, co, wco); + project_short(data->vc.ar, co, wco); - if (wco[0]==IS_CLIPPED) + if(wco[0] == IS_CLIPPED) return 0; - + + gluProject(co[0],co[1],co[2], data->mats.modelview, data->mats.projection, + (GLint *)data->mats.viewport, &ux, &uy, &uz); + x=wco[0]; y=wco[1]; - if(rv3d->depths && x<rv3d->depths->w && y<rv3d->depths->h){ + // XXX verify .. + + if(rv3d->depths && x<rv3d->depths->w && y<rv3d->depths->h) { /* the 0.0001 is an experimental threshold to make selecting keys right next to a surface work better */ if((float)uz - 0.0001 > rv3d->depths->depths[y*rv3d->depths->w+x]) return 0; else return 1; } - else{ - x+= (short)ar->winrct.xmin; - y+= (short)ar->winrct.ymin; + else { + x+= (short)data->vc.ar->winrct.xmin; + y+= (short)data->vc.ar->winrct.ymin; glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth); @@ -332,241 +386,294 @@ static int test_key_depth(float *co, bglMats *mats) } } +static int key_inside_circle(PEData *data, float co[3], float *distance) +{ + float dx, dy, dist; + short sco[2]; + + project_short(data->vc.ar, co, sco); + + if(sco[0] == IS_CLIPPED) + return 0; + + dx= data->mval[0] - sco[0]; + dy= data->mval[1] - sco[1]; + dist= sqrt(dx*dx + dy*dy); + + if(dist > data->rad) + return 0; + + if(key_test_depth(data, co)) { + if(distance) + *distance=dist; + + return 1; + } + + return 0; +} + +static int key_inside_rect(PEData *data, float co[3]) +{ + short sco[2]; + + project_short(data->vc.ar, co,sco); + + if(sco[0] == IS_CLIPPED) + return 0; + + if(sco[0] > data->rect->xmin && sco[0] < data->rect->xmax && + sco[1] > data->rect->ymin && sco[1] < data->rect->ymax) + return key_test_depth(data, co); + + return 0; +} + +static int key_inside_test(PEData *data, float co[3]) +{ + if(data->mval) + return key_inside_circle(data, co, NULL); + else + return key_inside_rect(data, co); +} + static int particle_is_selected(ParticleSystem *psys, ParticleData *pa) { ParticleEditKey *key; int sel, i, k; - if(pa->flag&PARS_HIDE) return 0; + if(pa->flag & PARS_HIDE) + return 0; - sel=0; + sel= 0; i= pa - psys->particles; + LOOP_KEYS(k,key) - if(key->flag&PEK_SELECT) + if(key->flag & PEK_SELECT) return 1; return 0; } -/*-----iterators over editable particles-----*/ -static void for_mouse_hit_keys(int nearest, ParticleSystem *psys, void (*func)(ParticleSystem *psys, - int pa_index, int key_index, void *userData), void *userData) +/*************************** iterators *******************************/ + +typedef void (*ForParticleFunc)(PEData *data, int pa_index); +typedef void (*ForKeyFunc)(PEData *data, int pa_index, int key_index); +typedef void (*ForKeyMatFunc)(PEData *data, float mat[][4], float imat[][4], int pa_index, int key_index); + +static void for_mouse_hit_keys(PEData *data, ForKeyFunc func, int nearest) { - /* these are allways the first in this userData */ - struct {Scene *scene; short *mval; float rad; rcti *rect;} *data = userData; + ParticleSystem *psys= data->psys; + ParticleEdit *edit= psys->edit; ParticleData *pa; ParticleEditKey *key; - bglMats mats; - int i,k, totpart, nearest_pa=-1, nearest_key=-1; - float dist=data->rad; + int i, k, totpart, nearest_pa, nearest_key; + float dist= data->rad; - if(psys==0 || data->scene->selectmode==SCE_SELECT_PATH) return; - - totpart=psys->totpart; + /* in path select mode we have no keys */ + if(data->scene->selectmode==SCE_SELECT_PATH) + return; - bgl_get_mats(&mats); + totpart= psys->totpart; + nearest_pa= -1; + nearest_key= -1; - LOOP_PARTICLES(i,pa){ + LOOP_PARTICLES(i, pa) { if(pa->flag & PARS_HIDE) continue; - if(data->scene->selectmode==SCE_SELECT_END){ - key=psys->edit->keys[i]+pa->totkey-1; + if(data->scene->selectmode == SCE_SELECT_END) { + /* only do end keys */ + key= edit->keys[i] + pa->totkey-1; - if(nearest){ - if(key_inside_circle(data->mval,dist,key->world_co,&dist) && test_key_depth(key->world_co,&mats)){ - nearest_pa=i; - nearest_key=pa->totkey-1; + if(nearest) { + if(key_inside_circle(data, key->world_co, &dist)) { + nearest_pa= i; + nearest_key= pa->totkey-1; } } - else if(((data->mval)? - key_inside_circle(data->mval,data->rad,key->world_co,0): - key_inside_rect(data->rect,key->world_co)) && test_key_depth(key->world_co,&mats)) - func(psys,i,pa->totkey-1,userData); + else if(key_inside_test(data, key->world_co)) + func(data, i, pa->totkey-1); } - else{ - key=psys->edit->keys[i]; + else { + /* do all keys */ + key= edit->keys[i]; - LOOP_KEYS(k,key){ - if(key->flag&PEK_HIDE) continue; + LOOP_KEYS(k, key) { + if(key->flag & PEK_HIDE) continue; - if(nearest){ - if(key_inside_circle(data->mval,dist,key->world_co,&dist) && test_key_depth(key->world_co,&mats)){ - nearest_pa=i; - nearest_key=k; + if(nearest) { + if(key_inside_circle(data, key->world_co, &dist)) { + nearest_pa= i; + nearest_key= k; } } - else if(((data->mval)? - key_inside_circle(data->mval,data->rad,key->world_co,0): - key_inside_rect(data->rect,key->world_co)) && test_key_depth(key->world_co,&mats)) - func(psys,i,k,userData); + else if(key_inside_test(data, key->world_co)) + func(data, i, k); } } } - if(nearest && nearest_pa>-1){ - func(psys,nearest_pa,nearest_key,userData); - } + + /* do nearest only */ + if(nearest && nearest_pa > -1) + func(data, nearest_pa, nearest_key); } -static void foreach_mouse_hit_element(int selected, ParticleSystem *psys,void (*func)(ParticleSystem *psys, int index, void *userData), void *userData) +static void foreach_mouse_hit_particle(PEData *data, ForParticleFunc func, int selected) { - /* these are allways the first in this userData */ - struct {Scene *scene; short *mval; float rad; rcti* rect; float dist;} *data = userData; + ParticleSystem *psys= data->psys; ParticleData *pa; ParticleEditKey *key; - bglMats mats; - int i,k, totpart; - - if(psys==0) return; - - totpart=psys->totpart; + int i, k, totpart; - bgl_get_mats(&mats); + totpart= psys->totpart; + /* all is selected in path mode */ if(data->scene->selectmode==SCE_SELECT_PATH) selected=0; - LOOP_PARTICLES(i,pa){ + LOOP_PARTICLES(i, pa) { if(pa->flag & PARS_HIDE) continue; - if(data->scene->selectmode==SCE_SELECT_END){ - key=psys->edit->keys[i]+pa->totkey-1; - if(key_inside_circle(data->mval,data->rad,key->world_co,&data->dist) && (selected==0 || key->flag&PEK_SELECT) && test_key_depth(key->world_co,&mats)) - func(psys,i,userData); + if(data->scene->selectmode==SCE_SELECT_END) { + /* only do end keys */ + key= psys->edit->keys[i] + pa->totkey-1; + + if(selected==0 || key->flag & PEK_SELECT) + if(key_inside_circle(data, key->world_co, &data->dist)) + func(data, i); } - else{ - LOOP_KEYS(k,key){ - if(key->flag&PEK_HIDE) continue; + else { + /* do all keys */ + LOOP_KEYS(k,key) { + if(key->flag & PEK_HIDE) continue; - if(key_inside_circle(data->mval,data->rad,key->world_co,&data->dist) && (selected==0 || key->flag&PEK_SELECT) && test_key_depth(key->world_co,&mats)){ - func(psys,i,userData); - break; + if(selected==0 || key->flag & PEK_SELECT) { + if(key_inside_circle(data, key->world_co, &data->dist)) { + func(data, i); + break; + } } } } } } -static void foreach_mouse_hit_key(int selected, ParticleSystem *psys,void (*func)(ParticleSystem *psys, float mat[][4], float imat[][4], int bel_index, int key_index, void *userData), void *userData) +static void foreach_mouse_hit_key(PEData *data, ForKeyMatFunc func, int selected) { - /* these are allways the first in this userData */ - struct {Scene *scene; Object *ob; short *mval; float rad; rcti* rect; float dist;} *data = userData; + ParticleSystem *psys= data->psys; ParticleData *pa; ParticleEditKey *key; ParticleSystemModifierData *psmd=0; - bglMats mats; - int i,k, totpart; + int i, k, totpart; float mat[4][4], imat[4][4]; - if(psys==0) return; - - psmd=psys_get_modifier(data->ob,psys); - - totpart=psys->totpart; - - bgl_get_mats(&mats); + psmd= psys_get_modifier(data->ob,psys); + totpart= psys->totpart; + /* all is selected in path mode */ if(data->scene->selectmode==SCE_SELECT_PATH) - selected=0; + selected= 0; Mat4One(imat); Mat4One(mat); - LOOP_PARTICLES(i,pa){ + LOOP_PARTICLES(i,pa) { if(pa->flag & PARS_HIDE) continue; psys_mat_hair_to_global(data->ob, psmd->dm, psys->part->from, pa, mat); - //psys_geometry_mat(psmd->dm,pa,tmat); - //Mat4MulMat4(mat,tmat,data->ob->obmat); Mat4Invert(imat,mat); - if(data->scene->selectmode==SCE_SELECT_END){ - key=psys->edit->keys[i]+pa->totkey-1; - if(key_inside_circle(data->mval,data->rad,key->world_co,&data->dist) && (selected==0 || key->flag&PEK_SELECT) && test_key_depth(key->world_co,&mats)) - func(psys,mat,imat,i,pa->totkey-1,userData); + if(data->scene->selectmode==SCE_SELECT_END) { + /* only do end keys */ + key= psys->edit->keys[i] + pa->totkey-1; + + if(selected==0 || key->flag & PEK_SELECT) + if(key_inside_circle(data, key->world_co, &data->dist)) + func(data, mat, imat, i, pa->totkey-1); } - else{ - LOOP_KEYS(k,key){ + else { + /* do all keys */ + LOOP_KEYS(k,key) { if(key->flag&PEK_HIDE) continue; - if(key_inside_circle(data->mval,data->rad,key->world_co,&data->dist) && (selected==0 || key->flag&PEK_SELECT) && test_key_depth(key->world_co,&mats)){ - func(psys,mat,imat,i,k,userData); - } + if(selected==0 || key->flag & PEK_SELECT) + if(key_inside_circle(data, key->world_co, &data->dist)) + func(data, mat, imat, i, k); } } } } -static void foreach_selected_element(ParticleSystem *psys, void (*func)(ParticleSystem *psys, int index, void *userData), void *userData) +static void foreach_selected_particle(PEData *data, ForParticleFunc func) { + ParticleSystem *psys= data->psys; ParticleData *pa; - int i,totpart; - - if(psys==0) return; + int i, totpart; - totpart=psys->totpart; + totpart= psys->totpart; LOOP_PARTICLES(i,pa) if(particle_is_selected(psys, pa)) - func(psys,i,userData); + func(data, i); } -static void foreach_selected_key(ParticleSystem *psys, void (*func)(ParticleSystem *psys, int pa_index, int key_index, void *userData), void *userData) +static void foreach_selected_key(PEData *data, ForKeyFunc func) { + ParticleSystem *psys= data->psys; ParticleData *pa; ParticleEditKey *key; - int i,k,totpart; + int i, k, totpart; - if(psys==0) return; + totpart= psys->totpart; - totpart=psys->totpart; + LOOP_PARTICLES(i,pa) { + if(pa->flag & PARS_HIDE) continue; - LOOP_PARTICLES(i,pa){ - if(pa->flag&PARS_HIDE) continue; + key= psys->edit->keys[i]; - key=psys->edit->keys[i]; - LOOP_KEYS(k,key){ - if(key->flag&PEK_SELECT) - func(psys,i,k,userData); - } + LOOP_KEYS(k,key) + if(key->flag & PEK_SELECT) + func(data, i, k); } } -void PE_foreach_element(ParticleSystem *psys, void (*func)(ParticleSystem *psys, int index, void *userData), void *userData) -{ - int i,totpart; - if(psys==0) return; +void PE_foreach_particle(PEData *data, ForParticleFunc func) +{ + ParticleSystem *psys= data->psys; + int i, totpart; - totpart=psys->totpart; + totpart= psys->totpart; for(i=0; i<totpart; i++) - func(psys,i,userData); + func(data, i); } + static int count_selected_keys(Scene *scene, ParticleSystem *psys) { ParticleData *pa; ParticleEditKey *key; - int i,k,totpart,sel=0; + int i, k, totpart, sel= 0; - if(psys==0) return 0; + totpart= psys->totpart; - totpart=psys->totpart; + LOOP_PARTICLES(i,pa) { + if(pa->flag & PARS_HIDE) continue; - LOOP_PARTICLES(i,pa){ - if(pa->flag&PARS_HIDE) continue; + key= psys->edit->keys[i]; - key=psys->edit->keys[i]; - if(scene->selectmode==SCE_SELECT_POINT){ - for(k=0; k<pa->totkey; k++,key++){ - if(key->flag&PEK_SELECT) + if(scene->selectmode==SCE_SELECT_POINT) { + for(k=0; k<pa->totkey; k++,key++) + if(key->flag & PEK_SELECT) sel++; - } } - else if(scene->selectmode==SCE_SELECT_END){ - key+=pa->totkey-1; - if(key->flag&PEK_SELECT) + else if(scene->selectmode==SCE_SELECT_END) { + key += pa->totkey-1; + + if(key->flag & PEK_SELECT) sel++; } } + return sel; } @@ -737,9 +844,9 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, ParticleSystem *psys) ParticleEdit *edit; ParticleData *pa; ParticleEditKey *key; - ParticleEditSettings *pset = PE_settings(scene); - ParticleSystemModifierData *psmd = psys_get_modifier(ob,psys); - int i,k,totpart,index; + ParticleEditSettings *pset= PE_settings(scene); + ParticleSystemModifierData *psmd= psys_get_modifier(ob,psys); + int i, k, totpart,index; float *vec, *nor, dvec[3], dot, dist_1st; float hairimat[4][4], hairmat[4][4]; @@ -752,24 +859,24 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, ParticleSystem *psys) edit=psys->edit; totpart=psys->totpart; - LOOP_PARTICLES(i,pa){ + LOOP_PARTICLES(i,pa) { if(!(pa->flag & PARS_EDIT_RECALC)) continue; psys_mat_hair_to_object(ob, psmd->dm, psys->part->from, pa, hairmat); - LOOP_KEYS(k,key){ + LOOP_KEYS(k,key) { Mat4MulVecfl(hairmat, key->co); } //} - //LOOP_PARTICLES(i,pa){ + //LOOP_PARTICLES(i,pa) { key=psys->edit->keys[i]+1; dist_1st=VecLenf((key-1)->co,key->co); dist_1st*=0.75f*pset->emitterdist; - for(k=1; k<pa->totkey; k++, key++){ + for(k=1; k<pa->totkey; k++, key++) { index= BLI_kdtree_find_nearest(edit->emitter_field,key->co,NULL,NULL); vec=edit->emitter_cosnos +index*6; @@ -780,14 +887,14 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, ParticleSystem *psys) dot=Inpf(dvec,nor); VECCOPY(dvec,nor); - if(dot>0.0f){ - if(dot<dist_1st){ + if(dot>0.0f) { + if(dot<dist_1st) { Normalize(dvec); VecMulf(dvec,dist_1st-dot); VecAddf(key->co,key->co,dvec); } } - else{ + else { Normalize(dvec); VecMulf(dvec,dist_1st-dot); VecAddf(key->co,key->co,dvec); @@ -797,11 +904,11 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, ParticleSystem *psys) } //} - //LOOP_PARTICLES(i,pa){ + //LOOP_PARTICLES(i,pa) { Mat4Invert(hairimat,hairmat); - LOOP_KEYS(k,key){ + LOOP_KEYS(k,key) { Mat4MulVecfl(hairimat, key->co); } } @@ -813,7 +920,7 @@ void PE_apply_lengths(Scene *scene, ParticleSystem *psys) ParticleData *pa; ParticleEditKey *key; ParticleEditSettings *pset=PE_settings(scene); - int i,k,totpart; + int i, k, totpart; float dv1[3]; if(psys==0) @@ -825,11 +932,11 @@ void PE_apply_lengths(Scene *scene, ParticleSystem *psys) edit=psys->edit; totpart=psys->totpart; - LOOP_PARTICLES(i,pa){ + LOOP_PARTICLES(i,pa) { if(!(pa->flag & PARS_EDIT_RECALC)) continue; - for(k=1, key=edit->keys[i] + 1; k<pa->totkey; k++, key++){ + for(k=1, key=edit->keys[i] + 1; k<pa->totkey; k++, key++) { VecSubf(dv1, key->co, (key - 1)->co); Normalize(dv1); VecMulf(dv1, (key - 1)->length); @@ -844,11 +951,11 @@ static void pe_iterate_lengths(Scene *scene, ParticleSystem *psys) ParticleData *pa; ParticleEditKey *key; ParticleEditSettings *pset=PE_settings(scene); - int i, j, k,totpart; + int i, j, k, totpart; float tlen; - float dv0[3] = {0.0f, 0.0f, 0.0f}; - float dv1[3] = {0.0f, 0.0f, 0.0f}; - float dv2[3] = {0.0f, 0.0f, 0.0f}; + float dv0[3]= {0.0f, 0.0f, 0.0f}; + float dv1[3]= {0.0f, 0.0f, 0.0f}; + float dv2[3]= {0.0f, 0.0f, 0.0f}; if(psys==0) return; @@ -859,38 +966,38 @@ static void pe_iterate_lengths(Scene *scene, ParticleSystem *psys) edit=psys->edit; totpart=psys->totpart; - LOOP_PARTICLES(i,pa){ + LOOP_PARTICLES(i,pa) { if(!(pa->flag & PARS_EDIT_RECALC)) continue; - for(j=1; j<pa->totkey; j++){ - float mul = 1.0f / (float)pa->totkey; + for(j=1; j<pa->totkey; j++) { + float mul= 1.0f / (float)pa->totkey; - if(pset->flag & PE_LOCK_FIRST){ - key = edit->keys[i] + 1; - k = 1; - dv1[0] = dv1[1] = dv1[2] = 0.0; + if(pset->flag & PE_LOCK_FIRST) { + key= edit->keys[i] + 1; + k= 1; + dv1[0]= dv1[1]= dv1[2]= 0.0; } - else{ - key = edit->keys[i]; - k = 0; - dv0[0] = dv0[1] = dv0[2] = 0.0; + else { + key= edit->keys[i]; + k= 0; + dv0[0]= dv0[1]= dv0[2]= 0.0; } - for(; k<pa->totkey; k++, key++){ - if(k){ + for(; k<pa->totkey; k++, key++) { + if(k) { VecSubf(dv0, (key - 1)->co, key->co); - tlen = Normalize(dv0); + tlen= Normalize(dv0); VecMulf(dv0, (mul * (tlen - (key - 1)->length))); } - if(k < pa->totkey - 1){ + if(k < pa->totkey - 1) { VecSubf(dv2, (key + 1)->co, key->co); - tlen = Normalize(dv2); + tlen= Normalize(dv2); VecMulf(dv2, mul * (tlen - key->length)); } - if(k){ + if(k) { VecAddf((key-1)->co,(key-1)->co,dv1); } @@ -909,19 +1016,19 @@ static void recalc_lengths(ParticleSystem *psys) if(psys==0) return; - totpart = psys->totpart; + totpart= psys->totpart; - LOOP_PARTICLES(i,pa){ - key = psys->edit->keys[i]; - for(k=0; k<pa->totkey-1; k++, key++){ - key->length = VecLenf(key->co, (key + 1)->co); + LOOP_PARTICLES(i,pa) { + key= psys->edit->keys[i]; + for(k=0; k<pa->totkey-1; k++, key++) { + key->length= VecLenf(key->co, (key + 1)->co); } } } /* calculate and store key locations in world coordinates */ void PE_recalc_world_cos(Object *ob, ParticleSystem *psys) { - ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); + ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys); ParticleData *pa; ParticleEditKey *key; int i, k, totpart; @@ -930,12 +1037,12 @@ void PE_recalc_world_cos(Object *ob, ParticleSystem *psys) if(psys==0) return; - totpart = psys->totpart; + totpart= psys->totpart; - LOOP_PARTICLES(i,pa){ + LOOP_PARTICLES(i,pa) { psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat); - LOOP_KEYS(k,key){ + LOOP_KEYS(k,key) { VECCOPY(key->world_co,key->co); Mat4MulVecfl(hairmat, key->world_co); } @@ -945,7 +1052,7 @@ void PE_recalc_world_cos(Object *ob, ParticleSystem *psys) static void recalc_emitter_field(Object *ob, ParticleSystem *psys) { DerivedMesh *dm=psys_get_modifier(ob,psys)->dm; - ParticleEdit *edit = psys->edit; + ParticleEdit *edit= psys->edit; MFace *mface; MVert *mvert; float *vec, *nor; @@ -967,7 +1074,7 @@ static void recalc_emitter_field(Object *ob, ParticleSystem *psys) nor=vec+3; mvert=dm->getVertDataArray(dm,CD_MVERT); - for(i=0; i<totface; i++, vec+=6, nor+=6){ + for(i=0; i<totface; i++, vec+=6, nor+=6) { mface=dm->getFaceData(dm,i,CD_MFACE); mvert=dm->getVertData(dm,mface->v1,CD_MVERT); @@ -982,7 +1089,7 @@ static void recalc_emitter_field(Object *ob, ParticleSystem *psys) VECADD(vec,vec,mvert->co); VECADD(nor,nor,mvert->no); - if (mface->v4){ + if(mface->v4) { mvert=dm->getVertData(dm,mface->v4,CD_MVERT); VECADD(vec,vec,mvert->co); VECADD(nor,nor,mvert->no); @@ -1002,7 +1109,7 @@ static void recalc_emitter_field(Object *ob, ParticleSystem *psys) void PE_update_selection(Scene *scene, Object *ob, int useflag) { - ParticleSystem *psys= PE_get_current(ob); + ParticleSystem *psys= PE_get_current(scene, ob); ParticleEdit *edit= psys->edit; ParticleEditSettings *pset= PE_settings(scene); ParticleSettings *part= psys->part; @@ -1022,7 +1129,7 @@ void PE_update_selection(Scene *scene, Object *ob, int useflag) /* flush edit key flag to hair key flag to preserve selection * on save */ LOOP_PARTICLES(i,pa) { - key = edit->keys[i]; + key= edit->keys[i]; for(k=0, hkey=pa->hair; k<pa->totkey; k++, hkey++, key++) hkey->editflag= key->flag; @@ -1040,7 +1147,7 @@ void PE_update_selection(Scene *scene, Object *ob, int useflag) void PE_update_object(Scene *scene, Object *ob, int useflag) { - ParticleSystem *psys= PE_get_current(ob); + ParticleSystem *psys= PE_get_current(scene, ob); ParticleEditSettings *pset= PE_settings(scene); ParticleSettings *part= psys->part; ParticleData *pa; @@ -1072,27 +1179,28 @@ void PE_update_object(Scene *scene, Object *ob, int useflag) pa->flag &= ~PARS_EDIT_RECALC; } +/************************ particle edit toggle operator ************************/ + /* initialize needed data for bake edit */ -void PE_create_particle_edit(Object *ob, ParticleSystem *psys) +void PE_create_particle_edit(Scene *scene, Object *ob, ParticleSystem *psys) { - Scene *scene= NULL; // XXX ParticleEdit *edit=psys->edit; ParticleData *pa; ParticleEditKey *key; HairKey *hkey; - int i,k, totpart=psys->totpart, alloc=1; + int i, k, totpart=psys->totpart, alloc=1; if((psys->flag & PSYS_EDITED)==0) return; - if(edit){ - int newtotkeys = psys_count_keys(psys); + if(edit) { + int newtotkeys= psys_count_keys(psys); if(newtotkeys == edit->totkeys) alloc=0; } - if(alloc){ - if(edit){ + if(alloc) { + if(edit) { error("ParticleEdit exists allready! Poke jahka!"); PE_free_particle_edit(psys); } @@ -1101,16 +1209,16 @@ void PE_create_particle_edit(Object *ob, ParticleSystem *psys) edit->keys=MEM_callocN(totpart*sizeof(ParticleEditKey*),"ParticleEditKey array"); - LOOP_PARTICLES(i,pa){ - key = edit->keys[i] = MEM_callocN(pa->totkey*sizeof(ParticleEditKey),"ParticleEditKeys"); - for(k=0, hkey=pa->hair; k<pa->totkey; k++, hkey++, key++){ - key->co = hkey->co; - key->time = &hkey->time; + LOOP_PARTICLES(i,pa) { + key= edit->keys[i]= MEM_callocN(pa->totkey*sizeof(ParticleEditKey),"ParticleEditKeys"); + for(k=0, hkey=pa->hair; k<pa->totkey; k++, hkey++, key++) { + key->co= hkey->co; + key->time= &hkey->time; key->flag= hkey->editflag; } } - edit->totkeys = psys_count_keys(psys); + edit->totkeys= psys_count_keys(psys); } recalc_lengths(psys); @@ -1123,197 +1231,145 @@ void PE_create_particle_edit(Object *ob, ParticleSystem *psys) } } -/* toggle particle mode on & off */ -void PE_set_particle_edit(Scene *scene) +static int particle_edit_toggle_poll(bContext *C) { - Object *ob= OBACT; - ParticleSystem *psys = PE_get_current(ob); + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + if(!scene || !ob || ob->id.lib) + return 0; - //if(!ob || ob->id.lib) return; /* is the id.lib test needed? -jahka*/ - if(ob==0 || psys==0) return; + return (ob->particlesystem.first != NULL); +} + +static int particle_edit_toggle_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + ParticleSystem *psys= PE_get_current(scene, ob); - if(psys==0){ - if(ob->particlesystem.first){ - psys=ob->particlesystem.first; - psys->flag |= PSYS_CURRENT; - } - else - return; + if(psys==NULL) { + psys= ob->particlesystem.first; + psys->flag |= PSYS_CURRENT; } - if((G.f & G_PARTICLEEDIT)==0){ + if(!(G.f & G_PARTICLEEDIT)) { if(psys && psys->part->type == PART_HAIR && psys->flag & PSYS_EDITED) { if(psys_check_enabled(ob, psys)) { - if(psys->edit==0) - PE_create_particle_edit(ob, psys); + if(psys->edit==NULL) + PE_create_particle_edit(scene, ob, psys); + PE_recalc_world_cos(ob, psys); } } G.f |= G_PARTICLEEDIT; + WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_PARTICLE, NULL); } - else{ + else { G.f &= ~G_PARTICLEEDIT; + WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, NULL); } - DAG_object_flush_update(scene, OBACT, OB_RECALC_DATA); + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_particle_edit_toggle(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Particle Edit Toggle"; + ot->idname= "PARTICLE_OT_particle_edit_toggle"; + + /* api callbacks */ + ot->exec= particle_edit_toggle_exec; + ot->poll= particle_edit_toggle_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } /************************************************/ /* Edit Selections */ /************************************************/ + /*-----selection callbacks-----*/ -static void select_key(ParticleSystem *psys, int pa_index, int key_index, void *userData) + +static void select_key(PEData *data, int pa_index, int key_index) { - struct {Scene *scene; short *mval; float rad; rcti* rect; int select; } *data = userData; - ParticleData *pa = psys->particles + pa_index; - ParticleEditKey *key = psys->edit->keys[pa_index] + key_index; + ParticleSystem *psys= data->psys; + ParticleData *pa= psys->particles + pa_index; + ParticleEditKey *key= psys->edit->keys[pa_index] + key_index; if(data->select) - key->flag|=PEK_SELECT; + key->flag |= PEK_SELECT; else - key->flag&=~PEK_SELECT; + key->flag &= ~PEK_SELECT; pa->flag |= PARS_EDIT_RECALC; } -static void select_keys(ParticleSystem *psys, int pa_index, int key_index, void *userData) +static void select_keys(PEData *data, int pa_index, int key_index) { - struct {Scene *scene; short *mval; float rad; rcti* rect; int select; } *data = userData; - ParticleData *pa = psys->particles + pa_index; - ParticleEditKey *key = psys->edit->keys[pa_index]; + ParticleSystem *psys= data->psys; + ParticleData *pa= psys->particles + pa_index; + ParticleEditKey *key= psys->edit->keys[pa_index]; int k; - for(k=0; k<pa->totkey; k++,key++){ + for(k=0; k<pa->totkey; k++,key++) { if(data->select) - key->flag|=PEK_SELECT; + key->flag |= PEK_SELECT; else - key->flag&=~PEK_SELECT; + key->flag &= ~PEK_SELECT; } pa->flag |= PARS_EDIT_RECALC; } -static void toggle_key_select(ParticleSystem *psys, int pa_index, int key_index, void *userData) +static void toggle_key_select(PEData *data, int pa_index, int key_index) { - ParticleData *pa = psys->particles + pa_index; + ParticleSystem *psys= data->psys; + ParticleData *pa= psys->particles + pa_index; if(psys->edit->keys[pa_index][key_index].flag&PEK_SELECT) - psys->edit->keys[pa_index][key_index].flag&=~PEK_SELECT; + psys->edit->keys[pa_index][key_index].flag &= ~PEK_SELECT; else - psys->edit->keys[pa_index][key_index].flag|=PEK_SELECT; + psys->edit->keys[pa_index][key_index].flag |= PEK_SELECT; pa->flag |= PARS_EDIT_RECALC; } -static void select_root(ParticleSystem *psys, int index, void *userData) -{ - psys->edit->keys[index]->flag |= PEK_SELECT; -} +/************************ de select all operator ************************/ -static void select_tip(ParticleSystem *psys, int index, void *userData) +static int de_select_all_exec(bContext *C, wmOperator *op) { - ParticleData *pa = psys->particles + index; - ParticleEditKey *key = psys->edit->keys[index] + pa->totkey-1; - - key->flag |= PEK_SELECT; -} -static void select_more_keys(ParticleSystem *psys, int index, void *userData) -{ - ParticleEdit *edit = psys->edit; - ParticleData *pa = psys->particles+index; - ParticleEditKey *key; - int k; - - for(k=0,key=edit->keys[index]; k<pa->totkey; k++,key++){ - if(key->flag&PEK_SELECT) continue; - - if(k==0){ - if((key+1)->flag&PEK_SELECT) - key->flag |= PEK_TO_SELECT; - } - else if(k==pa->totkey-1){ - if((key-1)->flag&PEK_SELECT) - key->flag |= PEK_TO_SELECT; - } - else{ - if(((key-1)->flag | (key+1)->flag) & PEK_SELECT) - key->flag |= PEK_TO_SELECT; - } - } - - for(k=0,key=edit->keys[index]; k<pa->totkey; k++,key++){ - if(key->flag&PEK_TO_SELECT){ - key->flag &= ~PEK_TO_SELECT; - key->flag |= PEK_SELECT; - } - } -} - -static void select_less_keys(ParticleSystem *psys, int index, void *userData) -{ - ParticleEdit *edit = psys->edit; - ParticleData *pa = psys->particles+index; - ParticleEditKey *key; - int k; - - for(k=0,key=edit->keys[index]; k<pa->totkey; k++,key++){ - if((key->flag&PEK_SELECT)==0) continue; - - if(k==0){ - if(((key+1)->flag&PEK_SELECT)==0) - key->flag |= PEK_TO_SELECT; - } - else if(k==pa->totkey-1){ - if(((key-1)->flag&PEK_SELECT)==0) - key->flag |= PEK_TO_SELECT; - } - else{ - if((((key-1)->flag & (key+1)->flag) & PEK_SELECT)==0) - key->flag |= PEK_TO_SELECT; - } - } - - for(k=0,key=edit->keys[index]; k<pa->totkey; k++,key++){ - if(key->flag&PEK_TO_SELECT) - key->flag &= ~(PEK_TO_SELECT|PEK_SELECT); - } -} - -/*-----using above callbacks-----*/ -void PE_deselectall(void) -{ - Scene *scene= NULL; - Object *ob = OBACT; - ParticleSystem *psys = PE_get_current(ob); - ParticleEdit *edit = 0; + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + ParticleSystem *psys= PE_get_current(scene, ob); + ParticleEdit *edit= 0; ParticleData *pa; ParticleEditKey *key; - int i,k,totpart, sel = 0; - - if(!PE_can_edit(psys)) return; + int i, k, totpart, sel= 0; - edit = psys->edit; - - totpart = psys->totpart; + edit= psys->edit; + totpart= psys->totpart; - LOOP_PARTICLES(i,pa){ + LOOP_PARTICLES(i,pa) { if(pa->flag & PARS_HIDE) continue; - LOOP_KEYS(k,key){ - if(key->flag&PEK_SELECT){ - sel = 1; + LOOP_KEYS(k,key) { + if(key->flag & PEK_SELECT) { + sel= 1; key->flag &= ~PEK_SELECT; pa->flag |= PARS_EDIT_RECALC; } } } - if(sel==0){ - LOOP_PARTICLES(i,pa){ + if(sel==0) { + LOOP_PARTICLES(i,pa) { if(pa->flag & PARS_HIDE) continue; - LOOP_KEYS(k,key){ + LOOP_KEYS(k,key) { if(!(key->flag & PEK_SELECT)) { key->flag |= PEK_SELECT; pa->flag |= PARS_EDIT_RECALC; @@ -1323,28 +1379,46 @@ void PE_deselectall(void) } PE_update_selection(scene, ob, 1); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_de_select_all(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Select or Deselect All"; + ot->idname= "PARTICLE_OT_de_select_all"; + + /* api callbacks */ + ot->exec= de_select_all_exec; + ot->poll= PE_poll; - BIF_undo_push("(De)select all keys"); + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +/************************ pick select operator ************************/ + void PE_mouse_particles(void) { - struct {Scene *scene; short *mval; float rad; rcti* rect; int select; } data; - Scene *scene= NULL; - Object *ob = OBACT; - ParticleSystem *psys = PE_get_current(ob); - ParticleEdit *edit = 0; + bContext *C= NULL; // XXX + PEData data; + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + ParticleSystem *psys= PE_get_current(scene, ob); + ParticleEdit *edit= 0; ParticleData *pa; ParticleEditKey *key; short mval[2]; - int i,k,totpart; + int i, k, totpart; int shift= 0; // XXX if(!PE_can_edit(psys)) return; - edit = psys->edit; + edit= psys->edit; - totpart = psys->totpart; + totpart= psys->totpart; bglFlush(); glReadBuffer(GL_BACK); @@ -1352,128 +1426,214 @@ void PE_mouse_particles(void) // persp(PERSP_VIEW); if(shift) - LOOP_PARTICLES(i,pa){ + LOOP_PARTICLES(i,pa) { if(pa->flag & PARS_HIDE) continue; - LOOP_KEYS(k,key){ + LOOP_KEYS(k,key) { if(key->flag & PEK_SELECT) { key->flag &= ~PEK_SELECT; pa->flag |= PARS_EDIT_RECALC; } } } + + // XXX mval -// getmouseco_areawin(mval); - - data.scene= scene; + PE_set_view3d_data(C, &data); data.mval= mval; data.rad= 75.0f; - data.rect= 0; - data.select= 0; - for_mouse_hit_keys(1,psys,toggle_key_select,&data); + for_mouse_hit_keys(&data, toggle_key_select, 1); /* nearest only */ PE_update_selection(scene, ob, 1); } -void PE_select_root(void) +/************************ select first operator ************************/ + +static void select_root(PEData *data, int pa_index) { - Object *ob=NULL; // XXX - ParticleSystem *psys = PE_get_current(ob); + ParticleSystem *psys= data->psys; - if(!PE_can_edit(psys)) return; + psys->edit->keys[pa_index]->flag |= PEK_SELECT; +} - PE_foreach_element(psys,select_root,NULL); - BIF_undo_push("Select first"); +static int select_first_exec(bContext *C, wmOperator *op) +{ + PEData data; + + PE_set_data(C, &data); + PE_foreach_particle(&data, select_root); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, data.ob); + + return OPERATOR_FINISHED; } -void PE_select_tip() +void PARTICLE_OT_select_first(wmOperatorType *ot) { - Object *ob=NULL; // XXX - ParticleSystem *psys = PE_get_current(ob); + /* identifiers */ + ot->name= "Select First"; + ot->idname= "PARTICLE_OT_select_first"; + + /* api callbacks */ + ot->exec= select_first_exec; + ot->poll= PE_poll; - if(!PE_can_edit(psys)) return; + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/************************ select last operator ************************/ - PE_foreach_element(psys,select_tip,NULL); - BIF_undo_push("Select last"); +static void select_tip(PEData *data, int pa_index) +{ + ParticleSystem *psys= data->psys; + ParticleData *pa= psys->particles + pa_index; + ParticleEditKey *key= psys->edit->keys[pa_index] + pa->totkey-1; + + key->flag |= PEK_SELECT; } -void PE_select_linked(void) +static int select_last_exec(bContext *C, wmOperator *op) { - struct {Scene *scene; short *mval; float rad; rcti* rect; int select; } data; - Object *ob=NULL; // XXX - Scene *scene= NULL; - ParticleSystem *psys = PE_get_current(ob); - short mval[2]; - int shift= 0; // XXX + PEData data; + + PE_set_data(C, &data); + PE_foreach_particle(&data, select_tip); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, data.ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_select_last(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Select Last"; + ot->idname= "PARTICLE_OT_select_last"; - if(!PE_can_edit(psys)) return; + /* api callbacks */ + ot->exec= select_last_exec; + ot->poll= PE_poll; -// getmouseco_areawin(mval); + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} - data.scene= NULL; // XXX - data.mval=mval; +/************************ select linked operator ************************/ + +static int select_linked_exec(bContext *C, wmOperator *op) +{ + PEData data; + short mval[2]; + int location[2]; + + RNA_int_get_array(op->ptr, "location", location); + mval[0]= location[0]; + mval[1]= location[1]; + + PE_set_view3d_data(C, &data); + data.mval= mval; data.rad=75.0f; - data.rect=0; - data.select=(shift); + data.select= !RNA_boolean_get(op->ptr, "deselect"); - for_mouse_hit_keys(1,psys,select_keys,&data); + for_mouse_hit_keys(&data, select_keys, 1); /* nearest only */ + PE_update_selection(data.scene, data.ob, 1); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, data.ob); - PE_update_selection(scene, ob, 1); + return OPERATOR_FINISHED; +} - BIF_undo_push("Select linked keys"); +static int select_linked_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + ARegion *ar= CTX_wm_region(C); + int location[2]; - return; + location[0]= event->x - ar->winrct.xmin; + location[1]= event->y - ar->winrct.ymin; + RNA_int_set_array(op->ptr, "location", location); + + return select_linked_exec(C, op); } -void PE_borderselect(ViewContext *vc, rcti *rect, int select) +void PARTICLE_OT_select_linked(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Select Linked"; + ot->idname= "PARTICLE_OT_select_linked"; + + /* api callbacks */ + ot->exec= select_linked_exec; + ot->invoke= select_linked_invoke; + ot->poll= PE_poll_3dview; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Deselect linked keys rather than selecting them."); + RNA_def_int_vector(ot->srna, "location", 2, NULL, 0, INT_MAX, "Location", "", 0, 16384); +} + +/************************ border select operator ************************/ + +void PE_border_select(ViewContext *vc, rcti *rect, int select) { - struct {Scene *scene; short *mval; float rad; rcti* rect; int select; } data; Scene *scene= vc->scene; Object *ob= vc->obact; - ParticleSystem *psys = PE_get_current(ob); + ParticleSystem *psys= PE_get_current(scene, ob); + PEData data; if(!PE_can_edit(psys)) return; + memset(&data, 0, sizeof(data)); + data.vc= *vc; data.scene= scene; - data.mval=0; + data.ob= ob; + data.psys= psys; data.rect= rect; data.select= select; - for_mouse_hit_keys(0, psys, select_key, &data); + for_mouse_hit_keys(&data, select_key, 0); PE_update_selection(scene, ob, 1); - BIF_undo_push("Select keys"); - - return; + /* XXX undo, notifier */ + PE_undo_push(scene, "Border Select"); } -void PE_selectionCB(short selecting, Object *editobj, short *mval, float rad) +/************************ circle select operator ************************/ + +void PE_circle_select(ViewContext *vc, int selecting, short *mval, float rad) { - struct {Scene *scene; short *mval; float rad; rcti* rect; int select; } data; - Scene *scene= NULL; - ParticleSystem *psys = PE_get_current(OBACT); + Scene *scene= vc->scene; + Object *ob= vc->obact; + ParticleSystem *psys= PE_get_current(scene, ob); + PEData data; if(!PE_can_edit(psys)) return; + memset(&data, 0, sizeof(data)); + data.vc= *vc; data.scene= scene; + data.ob= ob; + data.psys= psys; data.mval=mval; data.rad=rad; - data.rect=0; - data.select=(selecting==LEFTMOUSE); + data.select= selecting; - for_mouse_hit_keys(0,psys,select_key,&data); + for_mouse_hit_keys(&data, select_key, 0); -// draw_sel_circle(0, 0, 0, 0, 0); /* signal */ + /* XXX undo, notifier */ + PE_undo_push(scene, "Circle Select"); } -void PE_do_lasso_select(ViewContext *vc, short mcords[][2], short moves, short select) +/************************ lasso select operator ************************/ + +void PE_lasso_select(ViewContext *vc, short mcords[][2], short moves, short select) { Scene *scene= vc->scene; ARegion *ar= vc->ar; - Object *ob = OBACT; - ParticleSystem *psys = PE_get_current(ob); + Object *ob= OBACT; + ParticleSystem *psys= PE_get_current(scene, ob); ParticleSystemModifierData *psmd; ParticleEdit *edit; ParticleData *pa; @@ -1488,41 +1648,41 @@ void PE_do_lasso_select(ViewContext *vc, short mcords[][2], short moves, short s edit=psys->edit; totpart=psys->totpart; - LOOP_PARTICLES(i,pa){ + LOOP_PARTICLES(i,pa) { if(pa->flag & PARS_HIDE) continue; psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, mat); - if(scene->selectmode==SCE_SELECT_POINT){ - LOOP_KEYS(k,key){ + if(scene->selectmode==SCE_SELECT_POINT) { + LOOP_KEYS(k,key) { VECCOPY(co, key->co); Mat4MulVecfl(mat, co); project_short(ar, co, vertco); - if((vertco[0] != IS_CLIPPED) && lasso_inside(mcords,moves,vertco[0],vertco[1])){ + if((vertco[0] != IS_CLIPPED) && lasso_inside(mcords,moves,vertco[0],vertco[1])) { if(select && !(key->flag & PEK_SELECT)) { - key->flag|=PEK_SELECT; + key->flag |= PEK_SELECT; pa->flag |= PARS_EDIT_RECALC; } else if(key->flag & PEK_SELECT) { - key->flag&=~PEK_SELECT; + key->flag &= ~PEK_SELECT; pa->flag |= PARS_EDIT_RECALC; } } } } - else if(scene->selectmode==SCE_SELECT_END){ - key = edit->keys[i] + pa->totkey - 1; + else if(scene->selectmode==SCE_SELECT_END) { + key= edit->keys[i] + pa->totkey - 1; VECCOPY(co, key->co); Mat4MulVecfl(mat, co); project_short(ar, co,vertco); - if((vertco[0] != IS_CLIPPED) && lasso_inside(mcords,moves,vertco[0],vertco[1])){ + if((vertco[0] != IS_CLIPPED) && lasso_inside(mcords,moves,vertco[0],vertco[1])) { if(select && !(key->flag & PEK_SELECT)) { - key->flag|=PEK_SELECT; + key->flag |= PEK_SELECT; pa->flag |= PARS_EDIT_RECALC; } else if(key->flag & PEK_SELECT) { - key->flag&=~PEK_SELECT; + key->flag &= ~PEK_SELECT; pa->flag |= PARS_EDIT_RECALC; } } @@ -1531,37 +1691,26 @@ void PE_do_lasso_select(ViewContext *vc, short mcords[][2], short moves, short s PE_update_selection(scene, ob, 1); - BIF_undo_push("Lasso select particles"); - + /* XXX undo, notifier */ + PE_undo_push(scene, "Lasso select particles"); } -void PE_hide(int mode) +/*************************** hide operator **************************/ + +static int hide_exec(bContext *C, wmOperator *op) { - Scene *scene= NULL; - Object *ob = OBACT; - ParticleSystem *psys = PE_get_current(ob); + Object *ob= CTX_data_active_object(C); + Scene *scene= CTX_data_scene(C); + ParticleSystem *psys= PE_get_current(scene, ob); ParticleEdit *edit; ParticleEditKey *key; ParticleData *pa; int i, k, totpart; - if(!PE_can_edit(psys)) return; - - edit = psys->edit; - totpart = psys->totpart; + edit= psys->edit; + totpart= psys->totpart; - if(mode == 0){ /* reveal all particles */ - LOOP_PARTICLES(i, pa){ - if(pa->flag & PARS_HIDE) { - pa->flag &= ~PARS_HIDE; - pa->flag |= PARS_EDIT_RECALC; - - LOOP_KEYS(k, key) - key->flag |= PEK_SELECT; - } - } - } - else if(mode == 1){ /* hide unselected particles */ + if(RNA_enum_get(op->ptr, "unselected")) { LOOP_PARTICLES(i, pa) { if(!particle_is_selected(psys, pa)) { pa->flag |= PARS_HIDE; @@ -1572,7 +1721,7 @@ void PE_hide(int mode) } } } - else{ /* hide selected particles */ + else { LOOP_PARTICLES(i, pa) { if(particle_is_selected(psys, pa)) { pa->flag |= PARS_HIDE; @@ -1585,43 +1734,199 @@ void PE_hide(int mode) } PE_update_selection(scene, ob, 1); - BIF_undo_push("(Un)hide elements"); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_hide(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Hide Selected"; + ot->idname= "PARTICLE_OT_hide"; + /* api callbacks */ + ot->exec= hide_exec; + ot->poll= PE_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* props */ + RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected."); } -void PE_select_less(void) +/*************************** reveal operator **************************/ + +static int reveal_exec(bContext *C, wmOperator *op) { - Scene *scene= NULL; - ParticleSystem *psys = PE_get_current(OBACT); + Object *ob= CTX_data_active_object(C); + Scene *scene= CTX_data_scene(C); + ParticleSystem *psys= PE_get_current(scene, ob); + ParticleEdit *edit; + ParticleEditKey *key; + ParticleData *pa; + int i, k, totpart; - if(!PE_can_edit(psys)) return; + edit= psys->edit; + totpart= psys->totpart; + + LOOP_PARTICLES(i, pa) { + if(pa->flag & PARS_HIDE) { + pa->flag &= ~PARS_HIDE; + pa->flag |= PARS_EDIT_RECALC; - PE_foreach_element(psys,select_less_keys,NULL); + LOOP_KEYS(k, key) + key->flag |= PEK_SELECT; + } + } + + PE_update_selection(scene, ob, 1); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_reveal(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Reveal"; + ot->idname= "PARTICLE_OT_reveal"; - BIF_undo_push("Select less"); + /* api callbacks */ + ot->exec= reveal_exec; + ot->poll= PE_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -void PE_select_more(void) +/************************ select less operator ************************/ + +static void select_less_keys(PEData *data, int pa_index) { - Scene *scene= NULL; - ParticleSystem *psys = PE_get_current(OBACT); + ParticleSystem *psys= data->psys; + ParticleEdit *edit= psys->edit; + ParticleData *pa= &psys->particles[pa_index]; + ParticleEditKey *key; + int k; - if(!PE_can_edit(psys)) return; + for(k=0,key=edit->keys[pa_index]; k<pa->totkey; k++,key++) { + if((key->flag & PEK_SELECT)==0) continue; + + if(k==0) { + if(((key+1)->flag&PEK_SELECT)==0) + key->flag |= PEK_TO_SELECT; + } + else if(k==pa->totkey-1) { + if(((key-1)->flag&PEK_SELECT)==0) + key->flag |= PEK_TO_SELECT; + } + else { + if((((key-1)->flag & (key+1)->flag) & PEK_SELECT)==0) + key->flag |= PEK_TO_SELECT; + } + } + + for(k=0,key=edit->keys[pa_index]; k<pa->totkey; k++,key++) { + if(key->flag&PEK_TO_SELECT) + key->flag &= ~(PEK_TO_SELECT|PEK_SELECT); + } +} + +static int select_less_exec(bContext *C, wmOperator *op) +{ + PEData data; + + PE_set_data(C, &data); + PE_foreach_particle(&data, select_less_keys); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, data.ob); + + return OPERATOR_FINISHED; +} - PE_foreach_element(psys,select_more_keys,NULL); +void PARTICLE_OT_select_less(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Select Less"; + ot->idname= "PARTICLE_OT_select_less"; - BIF_undo_push("Select more"); + /* api callbacks */ + ot->exec= select_less_exec; + ot->poll= PE_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -/************************************************/ -/* Edit Rekey */ -/************************************************/ -static void rekey_element(ParticleSystem *psys, int index, void *userData) +/************************ select more operator ************************/ + +static void select_more_keys(PEData *data, int pa_index) { - struct {Scene *scene; Object *ob; float dval; } *data = userData; - ParticleData *pa = psys->particles + index; - ParticleEdit *edit = psys->edit; - ParticleEditSettings *pset = PE_settings(data->scene); + ParticleSystem *psys= data->psys; + ParticleEdit *edit= psys->edit; + ParticleData *pa= &psys->particles[pa_index]; + ParticleEditKey *key; + int k; + + for(k=0,key=edit->keys[pa_index]; k<pa->totkey; k++,key++) { + if(key->flag & PEK_SELECT) continue; + + if(k==0) { + if((key+1)->flag&PEK_SELECT) + key->flag |= PEK_TO_SELECT; + } + else if(k==pa->totkey-1) { + if((key-1)->flag&PEK_SELECT) + key->flag |= PEK_TO_SELECT; + } + else { + if(((key-1)->flag | (key+1)->flag) & PEK_SELECT) + key->flag |= PEK_TO_SELECT; + } + } + + for(k=0,key=edit->keys[pa_index]; k<pa->totkey; k++,key++) { + if(key->flag&PEK_TO_SELECT) { + key->flag &= ~PEK_TO_SELECT; + key->flag |= PEK_SELECT; + } + } +} + +static int select_more_exec(bContext *C, wmOperator *op) +{ + PEData data; + + PE_set_data(C, &data); + PE_foreach_particle(&data, select_more_keys); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, data.ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_select_more(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Select More"; + ot->idname= "PARTICLE_OT_select_more"; + + /* api callbacks */ + ot->exec= select_more_exec; + ot->poll= PE_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/************************ rekey operator ************************/ + +static void rekey_particle(PEData *data, int pa_index) +{ + ParticleSystem *psys= data->psys; + ParticleData *pa= &psys->particles[pa_index]; + ParticleEdit *edit= psys->edit; + ParticleEditSettings *pset= PE_settings(data->scene); ParticleKey state; HairKey *key, *new_keys; ParticleEditKey *ekey; @@ -1630,73 +1935,88 @@ static void rekey_element(ParticleSystem *psys, int index, void *userData) pa->flag |= PARS_REKEY; - key = new_keys = MEM_callocN(pset->totrekey * sizeof(HairKey),"Hair re-key keys"); + key= new_keys= MEM_callocN(pset->totrekey * sizeof(HairKey),"Hair re-key keys"); /* root and tip stay the same */ VECCOPY(key->co, pa->hair->co); VECCOPY((key + pset->totrekey - 1)->co, (pa->hair + pa->totkey - 1)->co); - sta = key->time = pa->hair->time; - end = (key + pset->totrekey - 1)->time = (pa->hair + pa->totkey - 1)->time; - dval = (end - sta) / (float)(pset->totrekey - 1); + sta= key->time= pa->hair->time; + end= (key + pset->totrekey - 1)->time= (pa->hair + pa->totkey - 1)->time; + dval= (end - sta) / (float)(pset->totrekey - 1); /* interpolate new keys from old ones */ for(k=1,key++; k<pset->totrekey-1; k++,key++) { - state.time = (float)k / (float)(pset->totrekey-1); - psys_get_particle_on_path(data->scene, data->ob, psys, index, &state, 0); + state.time= (float)k / (float)(pset->totrekey-1); + psys_get_particle_on_path(data->scene, data->ob, psys, pa_index, &state, 0); VECCOPY(key->co, state.co); - key->time = sta + k * dval; + key->time= sta + k * dval; } /* replace keys */ if(pa->hair) MEM_freeN(pa->hair); - pa->hair = new_keys; + pa->hair= new_keys; pa->totkey=pset->totrekey; - if(edit->keys[index]) - MEM_freeN(edit->keys[index]); - ekey = edit->keys[index] = MEM_callocN(pa->totkey * sizeof(ParticleEditKey),"Hair re-key edit keys"); + if(edit->keys[pa_index]) + MEM_freeN(edit->keys[pa_index]); + ekey= edit->keys[pa_index]= MEM_callocN(pa->totkey * sizeof(ParticleEditKey),"Hair re-key edit keys"); for(k=0, key=pa->hair; k<pa->totkey; k++, key++, ekey++) { - ekey->co = key->co; - ekey->time = &key->time; + ekey->co= key->co; + ekey->time= &key->time; } pa->flag &= ~PARS_REKEY; pa->flag |= PARS_EDIT_RECALC; } -void PE_rekey(void) +static int rekey_exec(bContext *C, wmOperator *op) { - Scene *scene= NULL; // XXX - Object *ob=OBACT; - ParticleSystem *psys = PE_get_current(ob); - ParticleEditSettings *pset = PE_settings(scene); - struct {Scene *scene; Object *ob; float dval; } data; + PEData data; + ParticleEditSettings *pset; - if(!PE_can_edit(psys)) return; + PE_set_data(C, &data); + + pset= PE_settings(data.scene); + pset->totrekey= RNA_int_get(op->ptr, "keys"); - data.scene = scene; - data.ob = ob; - data.dval = 1.0f / (float)(pset->totrekey-1); + data.dval= 1.0f / (float)(pset->totrekey-1); - foreach_selected_element(psys, rekey_element, &data); + foreach_selected_particle(&data, rekey_particle); - psys->edit->totkeys = psys_count_keys(psys); + data.psys->edit->totkeys= psys_count_keys(data.psys); + recalc_lengths(data.psys); + + PE_update_object(data.scene, data.ob, 1); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, data.ob); - recalc_lengths(psys); + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_rekey(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Rekey"; + ot->idname= "PARTICLE_OT_rekey"; - PE_update_object(scene, ob, 1); + /* api callbacks */ + ot->exec= rekey_exec; + // XXX show buttons ot->invoke= rekey_invoke; + ot->poll= PE_poll; - BIF_undo_push("Re-key particles"); + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + RNA_def_int(ot->srna, "keys", 2, 2, INT_MAX, "Number of Keys", "", 2, 100); } -static void rekey_element_to_time(Object *ob, int index, float path_time) +static void rekey_particle_to_time(Scene *scene, Object *ob, int pa_index, float path_time) { - Scene *scene= NULL; // XXX - ParticleSystem *psys = PE_get_current(ob); + ParticleSystem *psys= PE_get_current(scene, ob); ParticleEdit *edit=0; ParticleData *pa; ParticleKey state; @@ -1706,48 +2026,50 @@ static void rekey_element_to_time(Object *ob, int index, float path_time) if(psys==0) return; - edit = psys->edit; + edit= psys->edit; - pa = psys->particles + index; + pa= &psys->particles[pa_index]; pa->flag |= PARS_REKEY; - key = new_keys = MEM_dupallocN(pa->hair); + key= new_keys= MEM_dupallocN(pa->hair); /* interpolate new keys from old ones (roots stay the same) */ for(k=1, key++; k < pa->totkey; k++, key++) { - state.time = path_time * (float)k / (float)(pa->totkey-1); - psys_get_particle_on_path(scene, ob, psys, index, &state, 0); + state.time= path_time * (float)k / (float)(pa->totkey-1); + psys_get_particle_on_path(scene, ob, psys, pa_index, &state, 0); VECCOPY(key->co, state.co); } /* replace hair keys */ if(pa->hair) MEM_freeN(pa->hair); - pa->hair = new_keys; + pa->hair= new_keys; /* update edit pointers */ - for(k=0, key=pa->hair, ekey=edit->keys[index]; k<pa->totkey; k++, key++, ekey++) { - ekey->co = key->co; - ekey->time = &key->time; + for(k=0, key=pa->hair, ekey=edit->keys[pa_index]; k<pa->totkey; k++, key++, ekey++) { + ekey->co= key->co; + ekey->time= &key->time; } pa->flag &= ~PARS_REKEY; } -static int remove_tagged_elements(Scene *scene, Object *ob, ParticleSystem *psys) +/************************* utilities **************************/ + +static int remove_tagged_particles(Scene *scene, Object *ob, ParticleSystem *psys) { - ParticleEdit *edit = psys->edit; - ParticleEditSettings *pset = PE_settings(scene); + ParticleEdit *edit= psys->edit; + ParticleEditSettings *pset= PE_settings(scene); ParticleData *pa, *npa=0, *new_pars=0; ParticleEditKey **key, **nkey=0, **new_keys=0; ParticleSystemModifierData *psmd; - int i, totpart, new_totpart = psys->totpart, removed = 0; + int i, totpart, new_totpart= psys->totpart, removed= 0; if(pset->flag & PE_X_MIRROR) { /* mirror tags */ - psmd = psys_get_modifier(ob, psys); - totpart = psys->totpart; + psmd= psys_get_modifier(ob, psys); + totpart= psys->totpart; LOOP_PARTICLES(i,pa) if(pa->flag & PARS_TAG) @@ -1763,12 +2085,12 @@ static int remove_tagged_elements(Scene *scene, Object *ob, ParticleSystem *psys if(new_totpart != psys->totpart) { if(new_totpart) { - npa = new_pars = MEM_callocN(new_totpart * sizeof(ParticleData), "ParticleData array"); - nkey = new_keys = MEM_callocN(new_totpart * sizeof(ParticleEditKey *), "ParticleEditKey array"); + npa= new_pars= MEM_callocN(new_totpart * sizeof(ParticleData), "ParticleData array"); + nkey= new_keys= MEM_callocN(new_totpart * sizeof(ParticleEditKey *), "ParticleEditKey array"); } - pa = psys->particles; - key = edit->keys; + pa= psys->particles; + key= edit->keys; for(i=0; i<psys->totpart; i++, pa++, key++) { if(pa->flag & PARS_TAG) { if(*key) @@ -1785,19 +2107,19 @@ static int remove_tagged_elements(Scene *scene, Object *ob, ParticleSystem *psys } if(psys->particles) MEM_freeN(psys->particles); - psys->particles = new_pars; + psys->particles= new_pars; if(edit->keys) MEM_freeN(edit->keys); - edit->keys = new_keys; + edit->keys= new_keys; if(edit->mirror_cache) { MEM_freeN(edit->mirror_cache); - edit->mirror_cache = NULL; + edit->mirror_cache= NULL; } - psys->totpart = new_totpart; + psys->totpart= new_totpart; - edit->totkeys = psys_count_keys(psys); + edit->totkeys= psys_count_keys(psys); } return removed; @@ -1805,18 +2127,18 @@ static int remove_tagged_elements(Scene *scene, Object *ob, ParticleSystem *psys static void remove_tagged_keys(Scene *scene, Object *ob, ParticleSystem *psys) { - ParticleEdit *edit = psys->edit; - ParticleEditSettings *pset = PE_settings(scene); + ParticleEdit *edit= psys->edit; + ParticleEditSettings *pset= PE_settings(scene); ParticleData *pa; HairKey *key, *nkey, *new_keys=0; ParticleEditKey *ekey; ParticleSystemModifierData *psmd; - int i, k, totpart = psys->totpart; + int i, k, totpart= psys->totpart; short new_totkey; if(pset->flag & PE_X_MIRROR) { /* mirror key tags */ - psmd = psys_get_modifier(ob, psys); + psmd= psys_get_modifier(ob, psys); LOOP_PARTICLES(i,pa) { LOOP_KEYS(k,ekey) { @@ -1829,7 +2151,7 @@ static void remove_tagged_keys(Scene *scene, Object *ob, ParticleSystem *psys) } LOOP_PARTICLES(i,pa) { - new_totkey = pa->totkey; + new_totkey= pa->totkey; LOOP_KEYS(k,ekey) { if(ekey->flag & PEK_TAG) new_totkey--; @@ -1838,19 +2160,19 @@ static void remove_tagged_keys(Scene *scene, Object *ob, ParticleSystem *psys) if(new_totkey < 2) pa->flag |= PARS_TAG; } - remove_tagged_elements(scene, ob, psys); + remove_tagged_particles(scene, ob, psys); - totpart = psys->totpart; + totpart= psys->totpart; LOOP_PARTICLES(i,pa) { - new_totkey = pa->totkey; + new_totkey= pa->totkey; LOOP_KEYS(k,ekey) { if(ekey->flag & PEK_TAG) new_totkey--; } if(new_totkey != pa->totkey) { - key = pa->hair; - nkey = new_keys = MEM_callocN(new_totkey*sizeof(HairKey), "HairKeys"); + key= pa->hair; + nkey= new_keys= MEM_callocN(new_totkey*sizeof(HairKey), "HairKeys"); for(k=0, ekey=edit->keys[i]; k<new_totkey; k++, key++, nkey++, ekey++) { while(ekey->flag & PEK_TAG && key < pa->hair + pa->totkey) { @@ -1860,36 +2182,39 @@ static void remove_tagged_keys(Scene *scene, Object *ob, ParticleSystem *psys) if(key < pa->hair + pa->totkey) { VECCOPY(nkey->co, key->co); - nkey->time = key->time; - nkey->weight = key->weight; + nkey->time= key->time; + nkey->weight= key->weight; } } if(pa->hair) MEM_freeN(pa->hair); - pa->hair = new_keys; + pa->hair= new_keys; pa->totkey=new_totkey; if(edit->keys[i]) MEM_freeN(edit->keys[i]); - ekey = edit->keys[i] = MEM_callocN(new_totkey*sizeof(ParticleEditKey), "particle edit keys"); + ekey= edit->keys[i]= MEM_callocN(new_totkey*sizeof(ParticleEditKey), "particle edit keys"); for(k=0, key=pa->hair; k<pa->totkey; k++, key++, ekey++) { - ekey->co = key->co; - ekey->time = &key->time; + ekey->co= key->co; + ekey->time= &key->time; } } } - edit->totkeys = psys_count_keys(psys); + edit->totkeys= psys_count_keys(psys); } + +/************************ subdivide opertor *********************/ + /* works like normal edit mode subdivide, inserts keys between neighbouring selected keys */ -static void subdivide_element(ParticleSystem *psys, int index, void *userData) +static void subdivide_particle(PEData *data, int pa_index) { - struct {Scene *scene; Object *ob; } *data = userData; - ParticleEdit *edit = psys->edit; - ParticleData *pa = psys->particles + index; + ParticleSystem *psys= data->psys; + ParticleEdit *edit= psys->edit; + ParticleData *pa= &psys->particles[pa_index]; ParticleKey state; HairKey *key, *nkey, *new_keys; @@ -1899,7 +2224,7 @@ static void subdivide_element(ParticleSystem *psys, int index, void *userData) short totnewkey=0; float endtime; - for(k=0, ekey=edit->keys[index]; k<pa->totkey-1; k++,ekey++){ + for(k=0, ekey=edit->keys[pa_index]; k<pa->totkey-1; k++,ekey++) { if(ekey->flag&PEK_SELECT && (ekey+1)->flag&PEK_SELECT) totnewkey++; } @@ -1908,25 +2233,25 @@ static void subdivide_element(ParticleSystem *psys, int index, void *userData) pa->flag |= PARS_REKEY; - nkey = new_keys = MEM_callocN((pa->totkey+totnewkey)*(sizeof(HairKey)),"Hair subdivide keys"); - nekey = new_ekeys = MEM_callocN((pa->totkey+totnewkey)*(sizeof(ParticleEditKey)),"Hair subdivide edit keys"); - endtime = pa->hair[pa->totkey-1].time; + nkey= new_keys= MEM_callocN((pa->totkey+totnewkey)*(sizeof(HairKey)),"Hair subdivide keys"); + nekey= new_ekeys= MEM_callocN((pa->totkey+totnewkey)*(sizeof(ParticleEditKey)),"Hair subdivide edit keys"); + endtime= pa->hair[pa->totkey-1].time; - for(k=0, key=pa->hair, ekey=edit->keys[index]; k<pa->totkey-1; k++, key++, ekey++){ + for(k=0, key=pa->hair, ekey=edit->keys[pa_index]; k<pa->totkey-1; k++, key++, ekey++) { memcpy(nkey,key,sizeof(HairKey)); memcpy(nekey,ekey,sizeof(ParticleEditKey)); - nekey->co = nkey->co; - nekey->time = &nkey->time; + nekey->co= nkey->co; + nekey->time= &nkey->time; nkey++; nekey++; - if(ekey->flag & PEK_SELECT && (ekey+1)->flag & PEK_SELECT){ + if(ekey->flag & PEK_SELECT && (ekey+1)->flag & PEK_SELECT) { nkey->time= (key->time + (key+1)->time)*0.5f; - state.time = (endtime != 0.0f)? nkey->time/endtime: 0.0f; - psys_get_particle_on_path(data->scene, data->ob, psys, index, &state, 0); + state.time= (endtime != 0.0f)? nkey->time/endtime: 0.0f; + psys_get_particle_on_path(data->scene, data->ob, psys, pa_index, &state, 0); VECCOPY(nkey->co, state.co); nekey->co= nkey->co; @@ -1941,61 +2266,71 @@ static void subdivide_element(ParticleSystem *psys, int index, void *userData) memcpy(nkey,key,sizeof(HairKey)); memcpy(nekey,ekey,sizeof(ParticleEditKey)); - nekey->co = nkey->co; - nekey->time = &nkey->time; + nekey->co= nkey->co; + nekey->time= &nkey->time; if(pa->hair) MEM_freeN(pa->hair); - pa->hair = new_keys; + pa->hair= new_keys; - if(edit->keys[index]) - MEM_freeN(edit->keys[index]); + if(edit->keys[pa_index]) + MEM_freeN(edit->keys[pa_index]); - edit->keys[index] = new_ekeys; + edit->keys[pa_index]= new_ekeys; pa->totkey += totnewkey; pa->flag |= PARS_EDIT_RECALC; pa->flag &= ~PARS_REKEY; } -void PE_subdivide(Object *ob) +static int subdivide_exec(bContext *C, wmOperator *op) { - ParticleSystem *psys = PE_get_current(ob); - Scene *scene= NULL; - struct {Scene *scene; Object *ob; } data; - - if(!PE_can_edit(psys)) return; + PEData data; - data.scene= scene; - data.ob= ob; - PE_foreach_element(psys,subdivide_element,&data); + PE_set_data(C, &data); + PE_foreach_particle(&data, subdivide_particle); - psys->edit->totkeys = psys_count_keys(psys); + data.psys->edit->totkeys= psys_count_keys(data.psys); - recalc_lengths(psys); - PE_recalc_world_cos(ob, psys); + recalc_lengths(data.psys); + PE_recalc_world_cos(data.ob, data.psys); - PE_update_object(scene, ob, 1); + PE_update_object(data.scene, data.ob, 1); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, data.ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_subdivide(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Subdivide"; + ot->idname= "PARTICLE_OT_subdivide"; - BIF_undo_push("Subdivide hair(s)"); + /* api callbacks */ + ot->exec= subdivide_exec; + ot->poll= PE_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -void PE_remove_doubles() +/************************ remove doubles opertor *********************/ + +static int remove_doubles_exec(bContext *C, wmOperator *op) { - Scene *scene= NULL; // XXX - Object *ob=OBACT; - ParticleSystem *psys=PE_get_current(ob); + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + ParticleSystem *psys= PE_get_current(scene, ob); ParticleEditSettings *pset=PE_settings(scene); ParticleData *pa; ParticleEdit *edit; ParticleSystemModifierData *psmd; KDTree *tree; KDTreeNearest nearest[10]; - float mat[4][4], co[3]; + float mat[4][4], co[3], threshold= RNA_float_get(op->ptr, "threshold"); int i, n, totn, removed, totpart, flag, totremoved; - if(!PE_can_edit(psys)) return; - edit= psys->edit; psmd= psys_get_modifier(ob, psys); totremoved= 0; @@ -2029,7 +2364,7 @@ void PE_remove_doubles() for(n=0; n<totn; n++) { /* this needs a custom threshold still */ - if(nearest[n].index > i && nearest[n].dist < 0.0002f) { + if(nearest[n].index > i && nearest[n].dist < threshold) { if(!(pa->flag & PARS_TAG)) { pa->flag |= PARS_TAG; removed++; @@ -2044,74 +2379,350 @@ void PE_remove_doubles() /* remove tagged particles - don't do mirror here! */ flag= pset->flag; pset->flag &= ~PE_X_MIRROR; - remove_tagged_elements(scene, ob, psys); + remove_tagged_particles(scene, ob, psys); pset->flag= flag; totremoved += removed; } while(removed); -// if(totremoved) -// XXX notice("Removed: %d", totremoved); + if(totremoved == 0) + return OPERATOR_CANCELLED; + + BKE_reportf(op->reports, RPT_INFO, "Remove %d double particles.", totremoved); PE_recalc_world_cos(ob, psys); DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - BIF_undo_push("Remove double particles"); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob); + + return OPERATOR_FINISHED; } +void PARTICLE_OT_remove_doubles(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Remove Doubles"; + ot->idname= "PARTICLE_OT_remove_doubles"; + + /* api callbacks */ + ot->exec= remove_doubles_exec; + ot->poll= PE_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + RNA_def_float(ot->srna, "threshold", 0.0002f, 0.0f, FLT_MAX, "Threshold", "Threshold distance withing which particles are removed", 0.00001f, 0.1f); +} + +/********************* radial control operator *********************/ + /* XXX static */ void PE_radialcontrol_callback(const int mode, const int val) { - ParticleEditSettings *pset = NULL; // XXX PE_settings(scene); + ParticleEditSettings *pset= NULL; // XXX PE_settings(scene); if(pset->brushtype>=0) { ParticleBrushData *brush= &pset->brush[pset->brushtype]; if(mode == RADIALCONTROL_SIZE) - brush->size = val; + brush->size= val; else if(mode == RADIALCONTROL_STRENGTH) - brush->strength = val; + brush->strength= val; } - (*PE_radialcontrol()) = NULL; + (*PE_radialcontrol())= NULL; } struct RadialControl **PE_radialcontrol(void) { - static struct RadialControl *rc = NULL; + static struct RadialControl *rc= NULL; return &rc; } void PE_radialcontrol_start(const int mode) { - ParticleEditSettings *pset = NULL; // XXX PE_settings(scene); + ParticleEditSettings *pset= NULL; // XXX PE_settings(scene); int orig= 1; if(pset->brushtype>=0) { ParticleBrushData *brush= &pset->brush[pset->brushtype]; if(mode == RADIALCONTROL_SIZE) - orig = brush->size; + orig= brush->size; else if(mode == RADIALCONTROL_STRENGTH) - orig = brush->strength; + orig= brush->strength; // if(mode != RADIALCONTROL_NONE) // (*PE_radialcontrol())= radialcontrol_start(mode, PE_radialcontrol_callback, orig, 100, 0); } } -/************************************************/ -/* Edit Brushes */ -/************************************************/ -static void brush_comb(ParticleSystem *psys, float mat[][4], float imat[][4], int pa_index, int key_index, void *userData) +/*************************** delete operator **************************/ + +enum { DEL_PARTICLE, DEL_KEY }; + +static EnumPropertyItem delete_type_items[]= { + {DEL_PARTICLE, "PARTICLE", "Particle", ""}, + {DEL_KEY, "KEY", "Key", ""}, + {0, NULL, NULL}}; + +static void set_delete_particle(PEData *data, int pa_index) +{ + ParticleSystem *psys= data->psys; + + psys->particles[pa_index].flag |= PARS_TAG; +} + +static void set_delete_particle_key(PEData *data, int pa_index, int key_index) +{ + ParticleSystem *psys= data->psys; + + psys->edit->keys[pa_index][key_index].flag |= PEK_TAG; +} + +static int delete_exec(bContext *C, wmOperator *op) { - struct {Scene *scene; Object *ob; short *mval; float rad; rcti* rect; float dist; float *dvec; float combfac;} *data = userData; + PEData data; + int type= RNA_enum_get(op->ptr, "type"); + + PE_set_data(C, &data); + + if(type == DEL_KEY) { + foreach_selected_key(&data, set_delete_particle_key); + remove_tagged_keys(data.scene, data.ob, data.psys); + recalc_lengths(data.psys); + } + else if(type == DEL_PARTICLE) { + foreach_selected_particle(&data, set_delete_particle); + remove_tagged_particles(data.scene, data.ob, data.psys); + recalc_lengths(data.psys); + } + + DAG_object_flush_update(data.scene, data.ob, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, data.ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_delete(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Delete"; + ot->idname= "PARTICLE_OT_delete"; + + /* api callbacks */ + ot->exec= delete_exec; + ot->invoke= WM_menu_invoke; + ot->poll= PE_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + RNA_def_enum(ot->srna, "type", delete_type_items, DEL_PARTICLE, "Type", "Delete a full particle or only keys."); +} + +/*************************** mirror operator **************************/ + +static void PE_mirror_x(Scene *scene, Object *ob, int tagged) +{ + Mesh *me= (Mesh*)(ob->data); + ParticleSystemModifierData *psmd; + ParticleSystem *psys= PE_get_current(scene, ob); + ParticleEdit *edit; + ParticleData *pa, *newpa, *new_pars; + ParticleEditKey *ekey, **newkey, **key, **new_keys; + HairKey *hkey; + int *mirrorfaces; + int i, k, rotation, totpart, newtotpart; + + edit= psys->edit; + psmd= psys_get_modifier(ob, psys); + + mirrorfaces= mesh_get_x_mirror_faces(ob); + + if(!edit->mirror_cache) + PE_update_mirror_cache(ob, psys); + + totpart= psys->totpart; + newtotpart= psys->totpart; + LOOP_PARTICLES(i,pa) { + if(pa->flag & PARS_HIDE) continue; + + if(!tagged) { + if(particle_is_selected(psys, pa)) { + if(edit->mirror_cache[i] != -1) { + /* already has a mirror, don't need to duplicate */ + PE_mirror_particle(ob, psmd->dm, psys, pa, NULL); + continue; + } + else + pa->flag |= PARS_TAG; + } + } + + if((pa->flag & PARS_TAG) && mirrorfaces[pa->num*2] != -1) + newtotpart++; + } + + if(newtotpart != psys->totpart) { + /* allocate new arrays and copy existing */ + new_pars= MEM_callocN(newtotpart*sizeof(ParticleData), "ParticleData new"); + new_keys= MEM_callocN(newtotpart*sizeof(ParticleEditKey*), "ParticleEditKey new"); + + memcpy(new_pars, psys->particles, totpart*sizeof(ParticleData)); + memcpy(new_keys, edit->keys, totpart*sizeof(ParticleEditKey*)); + + if(psys->particles) MEM_freeN(psys->particles); + psys->particles= new_pars; + + if(edit->keys) MEM_freeN(edit->keys); + edit->keys= new_keys; + + if(edit->mirror_cache) { + MEM_freeN(edit->mirror_cache); + edit->mirror_cache= NULL; + } + + psys->totpart= newtotpart; + + /* create new elements */ + pa= psys->particles; + newpa= psys->particles + totpart; + key= edit->keys; + newkey= edit->keys + totpart; + + for(i=0; i<totpart; i++, pa++, key++) { + if(pa->flag & PARS_HIDE) continue; + + if(!(pa->flag & PARS_TAG) || mirrorfaces[pa->num*2] == -1) + continue; + + /* duplicate */ + *newpa= *pa; + if(pa->hair) newpa->hair= MEM_dupallocN(pa->hair); + if(pa->keys) newpa->keys= MEM_dupallocN(pa->keys); + if(*key) *newkey= MEM_dupallocN(*key); + + /* rotate weights according to vertex index rotation */ + rotation= mirrorfaces[pa->num*2+1]; + newpa->fuv[0]= pa->fuv[2]; + newpa->fuv[1]= pa->fuv[1]; + newpa->fuv[2]= pa->fuv[0]; + newpa->fuv[3]= pa->fuv[3]; + while(rotation-- > 0) + if(me->mface[pa->num].v4) + SHIFT4(float, newpa->fuv[0], newpa->fuv[1], newpa->fuv[2], newpa->fuv[3]) + else + SHIFT3(float, newpa->fuv[0], newpa->fuv[1], newpa->fuv[2]) + + /* assign face inddex */ + newpa->num= mirrorfaces[pa->num*2]; + newpa->num_dmcache= psys_particle_dm_face_lookup(ob,psmd->dm,newpa->num,newpa->fuv, NULL); + + /* update edit key pointers */ + ekey= *newkey; + for(k=0, hkey=newpa->hair; k<newpa->totkey; k++, hkey++, ekey++) { + ekey->co= hkey->co; + ekey->time= &hkey->time; + } + + /* map key positions as mirror over x axis */ + PE_mirror_particle(ob, psmd->dm, psys, pa, newpa); + + newpa++; + newkey++; + } + + edit->totkeys= psys_count_keys(psys); + } + + for(pa=psys->particles, i=0; i<psys->totpart; i++, pa++) + pa->flag &= ~PARS_TAG; + + MEM_freeN(mirrorfaces); +} + +static int mirror_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + ParticleSystem *psys= PE_get_current(scene, ob); + + PE_mirror_x(scene, ob, 0); + + PE_recalc_world_cos(ob, psys); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob); + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_mirror(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Mirror"; + ot->idname= "PARTICLE_OT_mirror"; + + /* api callbacks */ + ot->exec= mirror_exec; + ot->poll= PE_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/*********************** set brush operator **********************/ + +static EnumPropertyItem brush_type_items[]= { + {PE_BRUSH_NONE, "NONE", "None", ""}, + {PE_BRUSH_COMB, "COMB", "Comb", ""}, + {PE_BRUSH_SMOOTH, "SMOOTH", "Smooth", ""}, + {PE_BRUSH_WEIGHT, "WEIGHT", "Weight", ""}, + {PE_BRUSH_ADD, "ADD", "Add", ""}, + {PE_BRUSH_LENGTH, "LENGTH", "Length", ""}, + {PE_BRUSH_PUFF, "PUFF", "Puff", ""}, + {PE_BRUSH_CUT, "CUT", "Cut", ""}, + {0, NULL, NULL, NULL} +}; + +static int set_brush_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + ParticleEditSettings *pset= PE_settings(scene); + + pset->brushtype= RNA_enum_get(op->ptr, "type"); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_set_brush(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Set Brush"; + ot->idname= "PARTICLE_OT_set_brush"; + + /* api callbacks */ + ot->exec= set_brush_exec; + ot->invoke= WM_menu_invoke; + ot->poll= PE_poll; + + /* properties */ + RNA_def_enum(ot->srna, "type", brush_type_items, PE_BRUSH_NONE, "Type", "Brush type to select for editing."); +} + +/************************* brush edit callbacks ********************/ + +static void brush_comb(PEData *data, float mat[][4], float imat[][4], int pa_index, int key_index) +{ + ParticleSystem *psys= data->psys; ParticleData *pa= &psys->particles[pa_index]; ParticleEditSettings *pset= PE_settings(data->scene); - HairKey *key = pa->hair + key_index; + HairKey *key= pa->hair + key_index; float cvec[3], fac; if(pset->flag & PE_LOCK_FIRST && key_index == 0) return; - fac = (float)pow((double)(1.0f - data->dist / data->rad), (double)data->combfac); + fac= (float)pow((double)(1.0f - data->dist / data->rad), (double)data->combfac); VECCOPY(cvec,data->dvec); Mat4Mul3Vecfl(imat,cvec); @@ -2121,67 +2732,67 @@ static void brush_comb(ParticleSystem *psys, float mat[][4], float imat[][4], in pa->flag |= PARS_EDIT_RECALC; } -static void brush_cut(ParticleSystem *psys, int index, void *userData) +static void brush_cut(PEData *data, int pa_index) { - struct {Scene *scene; short *mval; float rad; rcti* rect; int selected; float cutfac; bglMats mats;} *data = userData; - ARegion *ar= NULL; // XXX - Object *ob= NULL; // XXX - ParticleData *pa= &psys->particles[index]; - ParticleCacheKey *key = psys->pathcache[index]; - float rad2, cut_time = 1.0; + ParticleSystem *psys= data->psys; + ARegion *ar= data->vc.ar; + Object *ob= data->ob; + ParticleData *pa= &psys->particles[pa_index]; + ParticleCacheKey *key= psys->pathcache[pa_index]; + float rad2, cut_time= 1.0; float x0, x1, v0, v1, o0, o1, xo0, xo1, d, dv; - int k, cut, keys = (int)pow(2.0, (double)psys->part->draw_step); + int k, cut, keys= (int)pow(2.0, (double)psys->part->draw_step); short vertco[2]; /* blunt scissors */ if(BLI_frand() > data->cutfac) return; - rad2 = data->rad * data->rad; + rad2= data->rad * data->rad; cut=0; project_short_noclip(ar, key->co, vertco); - x0 = (float)vertco[0]; - x1 = (float)vertco[1]; + x0= (float)vertco[0]; + x1= (float)vertco[1]; - o0 = (float)data->mval[0]; - o1 = (float)data->mval[1]; + o0= (float)data->mval[0]; + o1= (float)data->mval[1]; - xo0 = x0 - o0; - xo1 = x1 - o1; + xo0= x0 - o0; + xo1= x1 - o1; /* check if root is inside circle */ - if(xo0*xo0 + xo1*xo1 < rad2 && test_key_depth(key->co,&(data->mats))) { - cut_time = -1.0f; - cut = 1; + if(xo0*xo0 + xo1*xo1 < rad2 && key_test_depth(data, key->co)) { + cut_time= -1.0f; + cut= 1; } else { /* calculate path time closest to root that was inside the circle */ - for(k=1, key++; k<=keys; k++, key++){ + for(k=1, key++; k<=keys; k++, key++) { project_short_noclip(ar, key->co, vertco); - if(test_key_depth(key->co,&(data->mats)) == 0) { - x0 = (float)vertco[0]; - x1 = (float)vertco[1]; + if(key_test_depth(data, key->co) == 0) { + x0= (float)vertco[0]; + x1= (float)vertco[1]; - xo0 = x0 - o0; - xo1 = x1 - o1; + xo0= x0 - o0; + xo1= x1 - o1; continue; } - v0 = (float)vertco[0] - x0; - v1 = (float)vertco[1] - x1; + v0= (float)vertco[0] - x0; + v1= (float)vertco[1] - x1; - dv = v0*v0 + v1*v1; + dv= v0*v0 + v1*v1; - d = (v0*xo1 - v1*xo0); + d= (v0*xo1 - v1*xo0); - d = dv * rad2 - d*d; + d= dv * rad2 - d*d; if(d > 0.0f) { - d = sqrt(d); + d= sqrt(d); - cut_time = -(v0*xo0 + v1*xo1 + d); + cut_time= -(v0*xo0 + v1*xo1 + d); if(cut_time > 0.0f) { cut_time /= dv; @@ -2189,17 +2800,17 @@ static void brush_cut(ParticleSystem *psys, int index, void *userData) if(cut_time < 1.0f) { cut_time += (float)(k-1); cut_time /= (float)keys; - cut = 1; + cut= 1; break; } } } - x0 = (float)vertco[0]; - x1 = (float)vertco[1]; + x0= (float)vertco[0]; + x1= (float)vertco[1]; - xo0 = x0 - o0; - xo1 = x1 - o1; + xo0= x0 - o0; + xo1= x1 - o1; } } @@ -2208,24 +2819,24 @@ static void brush_cut(ParticleSystem *psys, int index, void *userData) pa->flag |= PARS_TAG; } else { - rekey_element_to_time(ob, index, cut_time); + rekey_particle_to_time(data->scene, ob, pa_index, cut_time); pa->flag |= PARS_EDIT_RECALC; } } } -static void brush_length(ParticleSystem *psys, int index, void *userData) +static void brush_length(PEData *data, int pa_index) { - struct {Scene *scene; short *mval; float rad; rcti* rect; float dist; float growfac; } *data = userData; - ParticleData *pa = &psys->particles[index]; + ParticleSystem *psys= data->psys; + ParticleData *pa= &psys->particles[pa_index]; HairKey *key; float dvec[3],pvec[3]; int k; - key = pa->hair; + key= pa->hair; VECCOPY(pvec,key->co); - for(k=1, key++; k<pa->totkey; k++,key++){ + for(k=1, key++; k<pa->totkey; k++,key++) { VECSUB(dvec,key->co,pvec); VECCOPY(pvec,key->co); VecMulf(dvec,data->growfac); @@ -2235,12 +2846,11 @@ static void brush_length(ParticleSystem *psys, int index, void *userData) pa->flag |= PARS_EDIT_RECALC; } -static void brush_puff(ParticleSystem *psys, int index, void *userData) +static void brush_puff(PEData *data, int pa_index) { - struct {Scene *scene; short *mval; float rad; rcti* rect; float dist; - Object *ob; DerivedMesh *dm; float pufffac; int invert; } *data = userData; - ParticleData *pa = &psys->particles[index]; - ParticleEdit *edit = psys->edit; + ParticleSystem *psys= data->psys; + ParticleData *pa= &psys->particles[pa_index]; + ParticleEdit *edit= psys->edit; HairKey *key; float mat[4][4], imat[4][4]; float lastco[3], rootco[3], co[3], nor[3], kco[3], dco[3], fac, length; @@ -2250,15 +2860,15 @@ static void brush_puff(ParticleSystem *psys, int index, void *userData) Mat4Invert(imat,mat); /* find root coordinate and normal on emitter */ - key = pa->hair; + key= pa->hair; VECCOPY(co, key->co); Mat4MulVecfl(mat, co); - index= BLI_kdtree_find_nearest(edit->emitter_field, co, NULL, NULL); - if(index == -1) return; + pa_index= BLI_kdtree_find_nearest(edit->emitter_field, co, NULL, NULL); + if(pa_index == -1) return; VECCOPY(rootco, co); - VecCopyf(nor, &psys->edit->emitter_cosnos[index*6+3]); + VecCopyf(nor, &psys->edit->emitter_cosnos[pa_index*6+3]); Normalize(nor); length= 0.0f; @@ -2267,7 +2877,7 @@ static void brush_puff(ParticleSystem *psys, int index, void *userData) if(data->invert) fac= -fac; - for(k=1, key++; k<pa->totkey; k++, key++){ + for(k=1, key++; k<pa->totkey; k++, key++) { /* compute position as if hair was standing up straight */ VECCOPY(lastco, co); VECCOPY(co, key->co); @@ -2287,13 +2897,13 @@ static void brush_puff(ParticleSystem *psys, int index, void *userData) pa->flag |= PARS_EDIT_RECALC; } -static void brush_smooth_get(ParticleSystem *psys, float mat[][4], float imat[][4], int pa_index, int key_index, void *userData) +static void brush_smooth_get(PEData *data, float mat[][4], float imat[][4], int pa_index, int key_index) { - struct {Scene *scene; Object *ob; short *mval; float rad; rcti* rect; float dist; float vec[3]; int tot; float smoothfac;} *data = userData; + ParticleSystem *psys= data->psys; ParticleData *pa= &psys->particles[pa_index]; - HairKey *key = pa->hair + key_index; + HairKey *key= pa->hair + key_index; - if(key_index){ + if(key_index) { float dvec[3]; VecSubf(dvec,key->co,(key-1)->co); @@ -2303,14 +2913,14 @@ static void brush_smooth_get(ParticleSystem *psys, float mat[][4], float imat[][ } } -static void brush_smooth_do(ParticleSystem *psys, float mat[][4], float imat[][4], int pa_index, int key_index, void *userData) +static void brush_smooth_do(PEData *data, float mat[][4], float imat[][4], int pa_index, int key_index) { - struct {Scene *scene; Object *ob; short *mval; float rad; rcti* rect; float dist; float vec[3]; int tot; float smoothfac;} *data = userData; + ParticleSystem *psys= data->psys; ParticleData *pa= &psys->particles[pa_index]; - HairKey *key = pa->hair + key_index; + HairKey *key= pa->hair + key_index; float vec[3], dvec[3]; - if(key_index){ + if(key_index) { VECCOPY(vec,data->vec); Mat4Mul3Vecfl(imat,vec); @@ -2325,128 +2935,62 @@ static void brush_smooth_do(ParticleSystem *psys, float mat[][4], float imat[][4 pa->flag |= PARS_EDIT_RECALC; } -#define EXPERIMENTAL_DEFORM_ONLY_PAINTING 1 -static void brush_add(Scene *scene, Object *ob, ParticleSystem *psys, short *mval, short number) +static void brush_add(PEData *data, short number) { - ParticleData *add_pars = MEM_callocN(number*sizeof(ParticleData),"ParticleData add"); - ParticleSystemModifierData *psmd = psys_get_modifier(ob,psys); + Scene *scene= data->scene; + Object *ob= data->ob; + ParticleSystem *psys= data->psys; + ParticleData *add_pars= MEM_callocN(number*sizeof(ParticleData),"ParticleData add"); + ParticleSystemModifierData *psmd= psys_get_modifier(ob,psys); ParticleEditSettings *pset= PE_settings(scene); - ARegion *ar= NULL; // XXX - View3D *v3d= NULL; // XXX - ParticleEdit *edit = psys->edit; - int i, k, n = 0, totpart = psys->totpart; + ParticleEdit *edit= psys->edit; + int i, k, n= 0, totpart= psys->totpart; short mco[2]; - short dmx = 0, dmy = 0; + short dmx= 0, dmy= 0; float co1[3], co2[3], min_d, imat[4][4]; - float framestep, timestep = psys_get_timestep(psys->part); - short size = pset->brush[PE_BRUSH_ADD].size; - short size2 = size*size; -#if EXPERIMENTAL_DEFORM_ONLY_PAINTING + float framestep, timestep= psys_get_timestep(psys->part); + short size= pset->brush[PE_BRUSH_ADD].size; + short size2= size*size; DerivedMesh *dm=0; -#endif Mat4Invert(imat,ob->obmat); - BLI_srandom(psys->seed+mval[0]+mval[1]); + BLI_srandom(psys->seed+data->mval[0]+data->mval[1]); /* painting onto the deformed mesh, could be an option? */ -#if EXPERIMENTAL_DEFORM_ONLY_PAINTING - if (psmd->dm->deformedOnly) - dm = psmd->dm; + if(psmd->dm->deformedOnly) + dm= psmd->dm; else - dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); -#endif - for(i=0; i<number; i++){ - if(number>1){ + dm= mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); + + for(i=0; i<number; i++) { + if(number>1) { dmx=dmy=size; - while(dmx*dmx+dmy*dmy>size2){ + while(dmx*dmx+dmy*dmy>size2) { dmx=(short)((2.0f*BLI_frand()-1.0f)*size); dmy=(short)((2.0f*BLI_frand()-1.0f)*size); } } - mco[0] = mval[0] + dmx; - mco[1] = mval[1] + dmy; - viewline(ar, v3d, mco, co1, co2); + mco[0]= data->mval[0] + dmx; + mco[1]= data->mval[1] + dmy; + viewline(data->vc.ar, data->vc.v3d, mco, co1, co2); Mat4MulVecfl(imat,co1); Mat4MulVecfl(imat,co2); min_d=2.0; /* warning, returns the derived mesh face */ -#if EXPERIMENTAL_DEFORM_ONLY_PAINTING if(psys_intersect_dm(scene, ob,dm,0,co1,co2,&min_d,&add_pars[n].num,add_pars[n].fuv,0,0,0,0)) { add_pars[n].num_dmcache= psys_particle_dm_face_lookup(ob,psmd->dm,add_pars[n].num,add_pars[n].fuv,NULL); n++; } -#else -#if 0 - if (psmd->dm->deformedOnly) { - if(psys_intersect_dm(scene, ob,psmd->dm,0,co1,co2,&min_d,&add_pars[n].num,add_pars[n].fuv,0,0,0,0)){ - n++; - } - } else { - /* we need to test against the cage mesh, because 1) its faster and 2) then we can avoid converting the fuv back which is not simple */ - if(psys_intersect_dm(scene, ob,psmd->dm,0,co1,co2,&min_d,&add_pars[n].num,add_pars[n].fuv,0,0,0,0)){ - MFace *mface; - float fuv_mod[3] = {0.0, 0.0, 0.0}; - OrigSpaceFace *osface; - - mface= psmd->dm->getFaceData(psmd->dm,add_pars[n].num,CD_MFACE); - osface= psmd->dm->getFaceData(psmd->dm, add_pars[n].num, CD_ORIGSPACE); - - add_pars[n].fuv[2]=0.0; - - /* use the original index for num and the derived index for num_dmcache */ - add_pars[n].num_dmcache = add_pars[n].num; - add_pars[n].num = *(int *)psmd->dm->getFaceData(psmd->dm, add_pars[n].num, CD_ORIGINDEX); - - /* This is totally unaceptable code (fakeing mesh dara) but changing the target function isnt really nice either, do this temporarily */ - if (1) { /* Evilness*/ - MFace mface_fake; - MVert mvert_fake[4]; - //int test1,test2; - //test1 = add_pars[n].num_dmcache; - //test2 = add_pars[n].num; - - mvert_fake[0].co[2] = mvert_fake[1].co[2] = mvert_fake[2].co[2] = mvert_fake[3].co[2] = 0.0; - - mface_fake.v1 = 0; - mface_fake.v2 = 1; - mface_fake.v3 = 2; - - if (mface->v4) { - mface_fake.v4 = 3; - } else { - mface_fake.v4 = 0; - } - - Vec2Copyf(mvert_fake[0].co, osface->uv[0]); - Vec2Copyf(mvert_fake[1].co, osface->uv[1]); - Vec2Copyf(mvert_fake[2].co, osface->uv[2]); - Vec2Copyf(mvert_fake[3].co, osface->uv[3]); - //printf("before %f %f %i %i\n", add_pars[n].fuv[0], add_pars[n].fuv[1], test1, test2); - psys_interpolate_face(&mvert_fake, &mface_fake, NULL, &add_pars[n].fuv, &fuv_mod, NULL, NULL, NULL); - - /* Apply as the UV */ - Vec2Copyf(add_pars[n].fuv, fuv_mod); - //printf("after %f %f\n", add_pars[n].fuv[0], add_pars[n].fuv[1]); - } - /* Make a fake face, for calculating the derived face's fuv on the original face */ - //PointInFace2DUV(mface->v4, osface->uv[0], osface->uv[1], osface->uv[2], osface->uv[3], add_pars[n].fuv, fuv_mod); - //Vec2Copyf(add_pars[n].fuv, fuv_mod); - - n++; - } - } -#endif -#endif } - if(n){ + if(n) { int newtotpart=totpart+n; float hairmat[4][4], cur_co[3]; KDTree *tree=0; - ParticleData *pa, *new_pars = MEM_callocN(newtotpart*sizeof(ParticleData),"ParticleData new"); - ParticleEditKey *ekey, **key, **new_keys = MEM_callocN(newtotpart*sizeof(ParticleEditKey *),"ParticleEditKey array new"); + ParticleData *pa, *new_pars= MEM_callocN(newtotpart*sizeof(ParticleData),"ParticleData new"); + ParticleEditKey *ekey, **key, **new_keys= MEM_callocN(newtotpart*sizeof(ParticleEditKey *),"ParticleEditKey array new"); HairKey *hkey; /* save existing elements */ @@ -2455,18 +2999,18 @@ static void brush_add(Scene *scene, Object *ob, ParticleSystem *psys, short *mva /* change old arrays to new ones */ if(psys->particles) MEM_freeN(psys->particles); - psys->particles = new_pars; + psys->particles= new_pars; if(edit->keys) MEM_freeN(edit->keys); - edit->keys = new_keys; + edit->keys= new_keys; if(edit->mirror_cache) { MEM_freeN(edit->mirror_cache); - edit->mirror_cache = NULL; + edit->mirror_cache= NULL; } /* create tree for interpolation */ - if(pset->flag & PE_INTERPOLATE_ADDED && psys->totpart){ + if(pset->flag & PE_INTERPOLATE_ADDED && psys->totpart) { tree=BLI_kdtree_new(psys->totpart); for(i=0, pa=psys->particles; i<totpart; i++, pa++) { @@ -2477,21 +3021,21 @@ static void brush_add(Scene *scene, Object *ob, ParticleSystem *psys, short *mva BLI_kdtree_balance(tree); } - psys->totpart = newtotpart; + psys->totpart= newtotpart; /* create new elements */ - pa = psys->particles + totpart; - key = edit->keys + totpart; + pa= psys->particles + totpart; + key= edit->keys + totpart; - for(i=totpart; i<newtotpart; i++, pa++, key++){ + for(i=totpart; i<newtotpart; i++, pa++, key++) { memcpy(pa, add_pars + i - totpart, sizeof(ParticleData)); - pa->hair = MEM_callocN(pset->totaddkey * sizeof(HairKey), "BakeKey key add"); - ekey = *key = MEM_callocN(pset->totaddkey * sizeof(ParticleEditKey), "ParticleEditKey add"); - pa->totkey = pset->totaddkey; + pa->hair= MEM_callocN(pset->totaddkey * sizeof(HairKey), "BakeKey key add"); + ekey= *key= MEM_callocN(pset->totaddkey * sizeof(ParticleEditKey), "ParticleEditKey add"); + pa->totkey= pset->totaddkey; for(k=0, hkey=pa->hair; k<pa->totkey; k++, hkey++, ekey++) { - ekey->co = hkey->co; - ekey->time = &hkey->time; + ekey->co= hkey->co; + ekey->time= &hkey->time; } pa->size= 1.0f; @@ -2501,9 +3045,9 @@ static void brush_add(Scene *scene, Object *ob, ParticleSystem *psys, short *mva if(pset->flag & PE_X_MIRROR) pa->flag |= PARS_TAG; /* signal for duplicate */ - framestep = pa->lifetime/(float)(pset->totaddkey-1); + framestep= pa->lifetime/(float)(pset->totaddkey-1); - if(tree){ + if(tree) { HairKey *hkey; ParticleKey key[3]; KDTreeNearest ptn[3]; @@ -2511,39 +3055,39 @@ static void brush_add(Scene *scene, Object *ob, ParticleSystem *psys, short *mva float maxd, mind, dd, totw=0.0, weight[3]; psys_particle_on_dm(psmd->dm,psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co1,0,0,0,0,0); - maxw = BLI_kdtree_find_n_nearest(tree,3,co1,NULL,ptn); + maxw= BLI_kdtree_find_n_nearest(tree,3,co1,NULL,ptn); - maxd = ptn[maxw-1].dist; - mind = ptn[0].dist; - dd = maxd - mind; + maxd= ptn[maxw-1].dist; + mind= ptn[0].dist; + dd= maxd - mind; - for(w=0; w<maxw; w++){ - weight[w] = (float)pow(2.0, (double)(-6.0f * ptn[w].dist / maxd)); + for(w=0; w<maxw; w++) { + weight[w]= (float)pow(2.0, (double)(-6.0f * ptn[w].dist / maxd)); totw += weight[w]; } - for(;w<3; w++){ - weight[w] = 0.0f; + for(;w<3; w++) { + weight[w]= 0.0f; } for(w=0; w<maxw; w++) weight[w] /= totw; for(k=0; k<pset->totaddkey; k++) { - hkey = pa->hair + k; - hkey->time = pa->time + k * framestep; + hkey= pa->hair + k; + hkey->time= pa->time + k * framestep; - key[0].time = hkey->time/ 100.0f; + key[0].time= hkey->time/ 100.0f; psys_get_particle_on_path(scene, ob, psys, ptn[0].index, key, 0); VecMulf(key[0].co, weight[0]); if(maxw>1) { - key[1].time = key[0].time; + key[1].time= key[0].time; psys_get_particle_on_path(scene, ob, psys, ptn[1].index, key + 1, 0); VecMulf(key[1].co, weight[1]); VECADD(key[0].co, key[0].co, key[1].co); if(maxw>2) { - key[2].time = key[0].time; + key[2].time= key[0].time; psys_get_particle_on_path(scene, ob, psys, ptn[2].index, key + 2, 0); VecMulf(key[2].co, weight[2]); VECADD(key[0].co, key[0].co, key[2].co); @@ -2555,10 +3099,10 @@ static void brush_add(Scene *scene, Object *ob, ParticleSystem *psys, short *mva VECADD(pa->hair[k].co, key[0].co, co1); - pa->hair[k].time = key[0].time; + pa->hair[k].time= key[0].time; } } - else{ + else { for(k=0, hkey=pa->hair; k<pset->totaddkey; k++, hkey++) { VECADDFAC(hkey->co, pa->state.co, pa->state.vel, k * framestep * timestep); pa->hair[k].time += k * framestep; @@ -2570,7 +3114,7 @@ static void brush_add(Scene *scene, Object *ob, ParticleSystem *psys, short *mva Mat4MulVecfl(imat, hkey->co); } } - edit->totkeys = psys_count_keys(psys); + edit->totkeys= psys_count_keys(psys); if(tree) BLI_kdtree_free(tree); @@ -2578,422 +3122,356 @@ static void brush_add(Scene *scene, Object *ob, ParticleSystem *psys, short *mva if(add_pars) MEM_freeN(add_pars); -/* painting onto the deformed mesh, could be an option? */ -#if EXPERIMENTAL_DEFORM_ONLY_PAINTING - if (!psmd->dm->deformedOnly) + if(!psmd->dm->deformedOnly) dm->release(dm); -#endif } -static void brush_weight(ParticleSystem *psys, float mat[][4], float imat[][4], int pa_index, int key_index, void *userData) + +static void brush_weight(PEData *data, float mat[][4], float imat[][4], int pa_index, int key_index) { - struct {Scene *scene; Object *ob; short *mval; float rad; rcti* rect; float dist; float weightfac;} *data = userData; + ParticleSystem *psys= data->psys; ParticleData *pa; /* roots have full weight allways */ if(key_index) { pa= &psys->particles[pa_index]; - pa->hair[key_index].weight = data->weightfac; + pa->hair[key_index].weight= data->weightfac; pa->flag |= PARS_EDIT_RECALC; } } -/* returns 0 if no brush was used */ -int PE_brush_particles(void) -{ - Scene *scene= NULL; // XXX - ARegion *ar= NULL; // XXX - Object *ob = OBACT; - ParticleSystem *psys = PE_get_current(ob); - ParticleEdit *edit; - ParticleEditSettings *pset = PE_settings(scene); - ParticleSystemModifierData *psmd; - ParticleBrushData *brush; - float vec1[3], vec2[3]; - short mval[2], mvalo[2], firsttime = 1, dx, dy; - int selected = 0, flip, removed = 0; +/************************* brush edit operator ********************/ - if(!PE_can_edit(psys)) return 0; +typedef struct BrushEdit { + Scene *scene; + Object *ob; + ParticleSystem *psys; - edit = psys->edit; - psmd= psys_get_modifier(ob, psys); + int first; + int lastmouse[2]; +} BrushEdit; -// XXX flip= (get_qual() == LR_SHIFTKEY); +static int brush_edit_init(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + ParticleSystem *psys= PE_get_current(scene, ob); + ParticleEditSettings *pset= PE_settings(scene); + ARegion *ar= CTX_wm_region(C); + BrushEdit *bedit; - if(pset->brushtype<0) return 0; - brush= &pset->brush[pset->brushtype]; + if(pset->brushtype < 0) + return 0; + // XXX initgrabz(ar->regiondata, ob->obmat[3][0], ob->obmat[3][1], ob->obmat[3][2]); -// getmouseco_areawin(mvalo); + bedit= MEM_callocN(sizeof(BrushEdit), "BrushEdit"); + bedit->first= 1; + op->customdata= bedit; - mval[0] = mvalo[0]; mval[1] = mvalo[1]; - - while(0){ // XXX get_mbut - bglFlush(); - glReadBuffer(GL_BACK); - glDrawBuffer(GL_BACK); -// persp(PERSP_VIEW); + bedit->scene= scene; + bedit->ob= ob; + bedit->psys= psys; - dx=mval[0]-mvalo[0]; - dy=mval[1]-mvalo[1]; - if(((pset->brushtype == PE_BRUSH_ADD) ? - (sqrt(dx * dx + dy * dy) > pset->brush[PE_BRUSH_ADD].step) : (dx != 0 || dy != 0)) - || firsttime){ - firsttime = 0; + return 1; +} - selected = (short)count_selected_keys(scene, psys); +static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) +{ + BrushEdit *bedit= op->customdata; + Scene *scene= bedit->scene; + Object *ob= bedit->ob; + ParticleSystem *psys= bedit->psys; + ParticleEditSettings *pset= PE_settings(scene); + ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys); + ParticleBrushData *brush= &pset->brush[pset->brushtype]; + ARegion *ar= CTX_wm_region(C); + float vec1[3], vec2[3]; + short mval[2], mvalo[2]; + int flip, mouse[2], dx, dy, removed= 0, selected= 0; - switch(pset->brushtype){ - case PE_BRUSH_COMB: - { - struct {Scene *scene; Object *ob; short *mval; float rad; rcti* rect; float dist; float *dvec; float combfac;} data; + RNA_int_get_array(itemptr, "mouse", mouse); + flip= RNA_boolean_get(itemptr, "flip"); - data.scene = scene; - data.ob = ob; - data.mval = mval; - data.rad = (float)brush->size; + bglFlush(); + glReadBuffer(GL_BACK); + glDrawBuffer(GL_BACK); +// persp(PERSP_VIEW); - data.combfac = (float)(brush->strength - 50) / 50.0f; - if(data.combfac < 0.0f) - data.combfac = 1.0f - 9.0f * data.combfac; - else - data.combfac = 1.0f - data.combfac; + dx= mouse[0] - bedit->lastmouse[0]; + dy= mouse[1] - bedit->lastmouse[1]; - Mat4Invert(ob->imat, ob->obmat); + mval[0]= mouse[0]; + mval[1]= mouse[1]; - window_to_3d(ar, vec1, mvalo[0], mvalo[1]); - window_to_3d(ar, vec2, mval[0], mval[1]); - VECSUB(vec1, vec2, vec1); - data.dvec = vec1; + mvalo[0]= bedit->lastmouse[0]; + mvalo[1]= bedit->lastmouse[1]; - foreach_mouse_hit_key(selected, psys,brush_comb, &data); - break; - } - case PE_BRUSH_CUT: - { - struct {Scene *scene; short *mval; float rad; rcti* rect; int selected; float cutfac; bglMats mats;} data; + if(((pset->brushtype == PE_BRUSH_ADD) ? + (sqrt(dx * dx + dy * dy) > pset->brush[PE_BRUSH_ADD].step) : (dx != 0 || dy != 0)) + || bedit->first) { - data.scene = scene; - data.mval = mval; - data.rad = (float)brush->size; + selected= (short)count_selected_keys(scene, psys); - data.selected = selected; + switch(pset->brushtype) { + case PE_BRUSH_COMB: + { + PEData data; - data.cutfac = (float)(brush->strength / 100.0f); + PE_set_view3d_data(C, &data); + data.mval= mval; + data.rad= (float)brush->size; - bgl_get_mats(&(data.mats)); - - if(selected) - foreach_selected_element(psys, brush_cut, &data); - else - PE_foreach_element(psys, brush_cut, &data); + data.combfac= (float)(brush->strength - 50) / 50.0f; + if(data.combfac < 0.0f) + data.combfac= 1.0f - 9.0f * data.combfac; + else + data.combfac= 1.0f - data.combfac; - removed= remove_tagged_elements(scene, ob, psys); - if(pset->flag & PE_KEEP_LENGTHS) - recalc_lengths(psys); - break; - } - case PE_BRUSH_LENGTH: - { - struct {Scene *scene; short *mval; float rad; rcti* rect; float dist; float growfac; } data; - - data.scene= scene; - data.mval = mval; - - data.rad = (float)brush->size; - data.growfac = (float)brush->strength / 5000.0f; + Mat4Invert(ob->imat, ob->obmat); - if(brush->invert ^ flip) - data.growfac = 1.0f - data.growfac; - else - data.growfac = 1.0f + data.growfac; + window_to_3d(ar, vec1, mvalo[0], mvalo[1]); + window_to_3d(ar, vec2, mval[0], mval[1]); + VECSUB(vec1, vec2, vec1); + data.dvec= vec1; - foreach_mouse_hit_element(selected, psys, brush_length, &data); + foreach_mouse_hit_key(&data, brush_comb, selected); + break; + } + case PE_BRUSH_CUT: + { + PEData data; - if(pset->flag & PE_KEEP_LENGTHS) - recalc_lengths(psys); - break; - } - case PE_BRUSH_PUFF: - { - struct {Scene *scene; short *mval; float rad; rcti* rect; float dist; - Object *ob; DerivedMesh *dm; float pufffac; int invert; } data; - - data.scene= scene; - data.ob = ob; - data.dm = psmd->dm; - data.mval = mval; - data.rad = (float)brush->size; - - data.pufffac = (float)(brush->strength - 50) / 50.0f; - if(data.pufffac < 0.0f) - data.pufffac = 1.0f - 9.0f * data.pufffac; - else - data.pufffac = 1.0f - data.pufffac; - - data.invert= (brush->invert ^ flip); - Mat4Invert(ob->imat, ob->obmat); - - foreach_mouse_hit_element(selected, psys, brush_puff, &data); - break; - } - case PE_BRUSH_ADD: - if(psys->part->from==PART_FROM_FACE){ - brush_add(scene, ob, psys, mval, brush->strength); - if(pset->flag & PE_KEEP_LENGTHS) - recalc_lengths(psys); - } - break; - case PE_BRUSH_WEIGHT: - { - struct {Scene *scene; Object *ob; short *mval; float rad; rcti* rect; float dist; float weightfac;} data; + PE_set_view3d_data(C, &data); + data.mval= mval; + data.rad= (float)brush->size; + data.cutfac= (float)(brush->strength / 100.0f); - data.scene = scene; - data.ob = ob; - data.mval = mval; - data.rad = (float)brush->size; + if(selected) + foreach_selected_particle(&data, brush_cut); + else + PE_foreach_particle(&data, brush_cut); - data.weightfac = (float)(brush->strength / 100.0f); + removed= remove_tagged_particles(scene, ob, psys); + if(pset->flag & PE_KEEP_LENGTHS) + recalc_lengths(psys); + break; + } + case PE_BRUSH_LENGTH: + { + PEData data; + + PE_set_view3d_data(C, &data); + data.mval= mval; + + data.rad= (float)brush->size; + data.growfac= (float)brush->strength / 5000.0f; - foreach_mouse_hit_key(selected, psys, brush_weight, &data); - break; - } - case PE_BRUSH_SMOOTH: - { - struct {Scene *scene; Object *ob; short *mval; float rad; rcti* rect; float dist; float vec[3]; int tot; float smoothfac;} data; + if(brush->invert ^ flip) + data.growfac= 1.0f - data.growfac; + else + data.growfac= 1.0f + data.growfac; - data.scene = scene; - data.ob = ob; - data.mval = mval; - data.rad = (float)brush->size; + foreach_mouse_hit_particle(&data, brush_length, selected); - data.vec[0] = data.vec[1] = data.vec[2] = 0.0f; - data.tot = 0; + if(pset->flag & PE_KEEP_LENGTHS) + recalc_lengths(psys); + break; + } + case PE_BRUSH_PUFF: + { + PEData data; + + PE_set_view3d_data(C, &data); + data.dm= psmd->dm; + data.mval= mval; + data.rad= (float)brush->size; + + data.pufffac= (float)(brush->strength - 50) / 50.0f; + if(data.pufffac < 0.0f) + data.pufffac= 1.0f - 9.0f * data.pufffac; + else + data.pufffac= 1.0f - data.pufffac; - data.smoothfac = (float)(brush->strength / 100.0f); + data.invert= (brush->invert ^ flip); + Mat4Invert(ob->imat, ob->obmat); - Mat4Invert(ob->imat, ob->obmat); + foreach_mouse_hit_particle(&data, brush_puff, selected); + break; + } + case PE_BRUSH_ADD: + { + PEData data; - foreach_mouse_hit_key(selected, psys, brush_smooth_get, &data); + if(psys->part->from==PART_FROM_FACE) { + PE_set_view3d_data(C, &data); + data.mval= mval; - if(data.tot){ - VecMulf(data.vec, 1.0f / (float)data.tot); - foreach_mouse_hit_key(selected, psys, brush_smooth_do, &data); - } + brush_add(&data, brush->strength); - break; + if(pset->flag & PE_KEEP_LENGTHS) + recalc_lengths(psys); } + break; } - if((pset->flag & PE_KEEP_LENGTHS)==0) - recalc_lengths(psys); - - if(pset->brushtype == PE_BRUSH_ADD || removed) { - if(pset->brushtype == PE_BRUSH_ADD && (pset->flag & PE_X_MIRROR)) - PE_mirror_x(scene, 1); - PE_recalc_world_cos(ob,psys); - psys_free_path_cache(psys); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - } - else - PE_update_object(scene, ob, 1); - - mvalo[0] = mval[0]; - mvalo[1] = mval[1]; - } - - PIL_sleep_ms(10); - -// getmouseco_areawin(mval); - } + case PE_BRUSH_WEIGHT: + { + PEData data; - BIF_undo_push("Brush edit particles"); + PE_set_view3d_data(C, &data); + data.mval= mval; + data.rad= (float)brush->size; - return 1; -} + data.weightfac= (float)(brush->strength / 100.0f); -static void set_delete_particle(ParticleSystem *psys, int index, void *userData) -{ - psys->particles[index].flag |= PARS_TAG; -} - -static void set_delete_particle_key(ParticleSystem *psys, int pa_index, int key_index, void *userData) -{ - psys->edit->keys[pa_index][key_index].flag |= PEK_TAG; -} + foreach_mouse_hit_key(&data, brush_weight, selected); + break; + } + case PE_BRUSH_SMOOTH: + { + PEData data; -void PE_delete_particle(void) -{ - Scene *scene= NULL; // XXX - Object *ob=OBACT; - ParticleSystem *psys = PE_get_current(ob); - short event=0; + PE_set_view3d_data(C, &data); + data.mval= mval; + data.rad= (float)brush->size; - if(!PE_can_edit(psys)) return; + data.vec[0]= data.vec[1]= data.vec[2]= 0.0f; + data.tot= 0; - event= pupmenu("Erase %t|Particle%x2|Key%x1"); + data.smoothfac= (float)(brush->strength / 100.0f); - if(event<1) return; + Mat4Invert(ob->imat, ob->obmat); - if(event==1){ - foreach_selected_key(psys, set_delete_particle_key, 0); - remove_tagged_keys(scene, ob, psys); - recalc_lengths(psys); - } - else if(event==2){ - foreach_selected_element(psys, set_delete_particle, 0); - remove_tagged_elements(scene, ob, psys); - recalc_lengths(psys); - } + foreach_mouse_hit_key(&data, brush_smooth_get, selected); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - BIF_undo_push("Delete particles/keys"); -} - -void PE_mirror_x(Scene *scene, int tagged) -{ - Object *ob=OBACT; - Mesh *me= (Mesh*)(ob->data); - ParticleSystemModifierData *psmd; - ParticleSystem *psys = PE_get_current(ob); - ParticleEdit *edit; - ParticleData *pa, *newpa, *new_pars; - ParticleEditKey *ekey, **newkey, **key, **new_keys; - HairKey *hkey; - int *mirrorfaces; - int i, k, rotation, totpart, newtotpart; - - if(!PE_can_edit(psys)) return; - - edit= psys->edit; - psmd= psys_get_modifier(ob, psys); - - mirrorfaces= mesh_get_x_mirror_faces(ob); + if(data.tot) { + VecMulf(data.vec, 1.0f / (float)data.tot); + foreach_mouse_hit_key(&data, brush_smooth_do, selected); + } - if(!edit->mirror_cache) - PE_update_mirror_cache(ob, psys); + break; + } + } + if((pset->flag & PE_KEEP_LENGTHS)==0) + recalc_lengths(psys); - totpart= psys->totpart; - newtotpart= psys->totpart; - LOOP_PARTICLES(i,pa) { - if(pa->flag&PARS_HIDE) continue; + if(pset->brushtype == PE_BRUSH_ADD || removed) { + if(pset->brushtype == PE_BRUSH_ADD && (pset->flag & PE_X_MIRROR)) + PE_mirror_x(scene, ob, 1); - if(!tagged) { - if(particle_is_selected(psys, pa)) { - if(edit->mirror_cache[i] != -1) { - /* already has a mirror, don't need to duplicate */ - PE_mirror_particle(ob, psmd->dm, psys, pa, NULL); - continue; - } - else - pa->flag |= PARS_TAG; - } + PE_recalc_world_cos(ob,psys); + psys_free_path_cache(psys); + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); } + else + PE_update_object(scene, ob, 1); - if((pa->flag & PARS_TAG) && mirrorfaces[pa->num*2] != -1) - newtotpart++; + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, ob); + + bedit->lastmouse[0]= mouse[0]; + bedit->lastmouse[1]= mouse[1]; + bedit->first= 0; } +} - if(newtotpart != psys->totpart) { - /* allocate new arrays and copy existing */ - new_pars= MEM_callocN(newtotpart*sizeof(ParticleData), "ParticleData new"); - new_keys= MEM_callocN(newtotpart*sizeof(ParticleEditKey*), "ParticleEditKey new"); +static void brush_edit_exit(bContext *C, wmOperator *op) +{ + BrushEdit *bedit= op->customdata; - memcpy(new_pars, psys->particles, totpart*sizeof(ParticleData)); - memcpy(new_keys, edit->keys, totpart*sizeof(ParticleEditKey*)); + MEM_freeN(bedit); +} - if(psys->particles) MEM_freeN(psys->particles); - psys->particles= new_pars; +static int brush_edit_exec(bContext *C, wmOperator *op) +{ + if(!brush_edit_init(C, op)) + return OPERATOR_CANCELLED; - if(edit->keys) MEM_freeN(edit->keys); - edit->keys= new_keys; + RNA_BEGIN(op->ptr, itemptr, "stroke") { + brush_edit_apply(C, op, &itemptr); + } + RNA_END; - if(edit->mirror_cache) { - MEM_freeN(edit->mirror_cache); - edit->mirror_cache= NULL; - } + brush_edit_exit(C, op); - psys->totpart= newtotpart; - - /* create new elements */ - pa= psys->particles; - newpa= psys->particles + totpart; - key= edit->keys; - newkey= edit->keys + totpart; + return OPERATOR_FINISHED; +} - for(i=0; i<totpart; i++, pa++, key++) { - if(pa->flag&PARS_HIDE) continue; +static void brush_edit_apply_event(bContext *C, wmOperator *op, wmEvent *event) +{ + ARegion *ar= CTX_wm_region(C); + PointerRNA itemptr; + int mouse[2]; - if(!(pa->flag & PARS_TAG) || mirrorfaces[pa->num*2] == -1) - continue; + mouse[0]= event->x - ar->winrct.xmin; + mouse[1]= event->y - ar->winrct.ymin; - /* duplicate */ - *newpa= *pa; - if(pa->hair) newpa->hair= MEM_dupallocN(pa->hair); - if(pa->keys) newpa->keys= MEM_dupallocN(pa->keys); - if(*key) *newkey= MEM_dupallocN(*key); + /* fill in stroke */ + RNA_collection_add(op->ptr, "stroke", &itemptr); - /* rotate weights according to vertex index rotation */ - rotation= mirrorfaces[pa->num*2+1]; - newpa->fuv[0]= pa->fuv[2]; - newpa->fuv[1]= pa->fuv[1]; - newpa->fuv[2]= pa->fuv[0]; - newpa->fuv[3]= pa->fuv[3]; - while(rotation-- > 0) - if(me->mface[pa->num].v4) - SHIFT4(float, newpa->fuv[0], newpa->fuv[1], newpa->fuv[2], newpa->fuv[3]) - else - SHIFT3(float, newpa->fuv[0], newpa->fuv[1], newpa->fuv[2]) + RNA_int_set_array(&itemptr, "mouse", mouse); + RNA_boolean_set(&itemptr, "flip", event->shift != 0); // XXX hardcoded - /* assign face inddex */ - newpa->num= mirrorfaces[pa->num*2]; - newpa->num_dmcache= psys_particle_dm_face_lookup(ob,psmd->dm,newpa->num,newpa->fuv, NULL); + /* apply */ + brush_edit_apply(C, op, &itemptr); +} - /* update edit key pointers */ - ekey= *newkey; - for(k=0, hkey=newpa->hair; k<newpa->totkey; k++, hkey++, ekey++) { - ekey->co= hkey->co; - ekey->time= &hkey->time; - } +static int brush_edit_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + if(!brush_edit_init(C, op)) + return OPERATOR_CANCELLED; + + brush_edit_apply_event(C, op, event); - /* map key positions as mirror over x axis */ - PE_mirror_particle(ob, psmd->dm, psys, pa, newpa); + WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op); - newpa++; - newkey++; - } + return OPERATOR_RUNNING_MODAL; +} - edit->totkeys = psys_count_keys(psys); +static int brush_edit_modal(bContext *C, wmOperator *op, wmEvent *event) +{ + switch(event->type) { + case LEFTMOUSE: + case MIDDLEMOUSE: + case RIGHTMOUSE: // XXX hardcoded + brush_edit_exit(C, op); + return OPERATOR_FINISHED; + case MOUSEMOVE: + brush_edit_apply_event(C, op, event); + break; } - for(pa=psys->particles, i=0; i<psys->totpart; i++, pa++) - pa->flag &= ~PARS_TAG; + return OPERATOR_RUNNING_MODAL; +} - MEM_freeN(mirrorfaces); +static int brush_edit_cancel(bContext *C, wmOperator *op) +{ + brush_edit_exit(C, op); - if(!tagged) { - PE_recalc_world_cos(ob,psys); - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - BIF_undo_push("Mirror particles"); - } + return OPERATOR_CANCELLED; } -void PE_selectbrush_menu(Scene *scene) +void PARTICLE_OT_brush_edit(wmOperatorType *ot) { - ParticleEditSettings *pset= PE_settings(scene); - int val; + /* identifiers */ + ot->name= "Brush Edit"; + ot->idname= "PARTICLE_OT_brush_edit"; - // XXX pupmenu_set_active(pset->brushtype); - - val= pupmenu("Select Brush%t|None %x0|Comb %x1|Smooth %x7|Weight %x6|Add %x5|Length %x3|Puff %x4|Cut %x2"); + /* api callbacks */ + ot->exec= brush_edit_exec; + ot->invoke= brush_edit_invoke; + ot->modal= brush_edit_modal; + ot->cancel= brush_edit_cancel; + ot->poll= PE_poll_3dview; - if(val>=0) { - pset->brushtype= val-1; - } + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", ""); } -/************************************************/ -/* Particle Edit Undo */ -/************************************************/ +/*********************** undo ***************************/ + static void free_ParticleUndo(ParticleUndo *undo) { ParticleData *pa; @@ -3014,29 +3492,31 @@ static void free_ParticleUndo(ParticleUndo *undo) //if(undo->emitter_cosnos) // MEM_freeN(undo->emitter_cosnos); } + static void make_ParticleUndo(ParticleSystem *psys, ParticleUndo *undo) { ParticleData *pa,*upa; int i; - undo->totpart = psys->totpart; - undo->totkeys = psys->edit->totkeys; + undo->totpart= psys->totpart; + undo->totkeys= psys->edit->totkeys; - upa = undo->particles = MEM_dupallocN(psys->particles); - undo->keys = MEM_dupallocN(psys->edit->keys); + upa= undo->particles= MEM_dupallocN(psys->particles); + undo->keys= MEM_dupallocN(psys->edit->keys); for(i=0, pa=psys->particles; i<undo->totpart; i++, pa++, upa++) { - upa->hair = MEM_dupallocN(pa->hair); - undo->keys[i] = MEM_dupallocN(psys->edit->keys[i]); + upa->hair= MEM_dupallocN(pa->hair); + undo->keys[i]= MEM_dupallocN(psys->edit->keys[i]); /* no need to update edit key->co & key->time pointers here */ } } + static void get_ParticleUndo(ParticleSystem *psys, ParticleUndo *undo) { ParticleData *pa, *upa; ParticleEditKey *key; HairKey *hkey; - int i, k, totpart = psys->totpart; + int i, k, totpart= psys->totpart; LOOP_PARTICLES(i,pa) { if(pa->hair) @@ -3054,31 +3534,31 @@ static void get_ParticleUndo(ParticleSystem *psys, ParticleUndo *undo) psys->edit->mirror_cache= NULL; } - pa = psys->particles = MEM_dupallocN(undo->particles); - psys->edit->keys = MEM_dupallocN(undo->keys); + pa= psys->particles= MEM_dupallocN(undo->particles); + psys->edit->keys= MEM_dupallocN(undo->keys); - for(i=0,upa=undo->particles; i<undo->totpart; i++, upa++, pa++){ - hkey = pa->hair = MEM_dupallocN(upa->hair); - key = psys->edit->keys[i] = MEM_dupallocN(undo->keys[i]); + for(i=0,upa=undo->particles; i<undo->totpart; i++, upa++, pa++) { + hkey= pa->hair= MEM_dupallocN(upa->hair); + key= psys->edit->keys[i]= MEM_dupallocN(undo->keys[i]); for(k=0; k<pa->totkey; k++, hkey++, key++) { - key->co = hkey->co; - key->time = &hkey->time; + key->co= hkey->co; + key->time= &hkey->time; } } - psys->totpart = undo->totpart; - psys->edit->totkeys = undo->totkeys; + psys->totpart= undo->totpart; + psys->edit->totkeys= undo->totkeys; } void PE_undo_push(Scene *scene, char *str) { - ParticleSystem *psys = PE_get_current(OBACT); - ParticleEdit *edit = 0; + ParticleSystem *psys= PE_get_current(scene, OBACT); + ParticleEdit *edit= 0; ParticleUndo *undo; int nr; if(!PE_can_edit(psys)) return; - edit = psys->edit; + edit= psys->edit; /* remove all undos after (also when curundo==NULL) */ while(edit->undo.last != edit->curundo) { @@ -3113,10 +3593,11 @@ void PE_undo_push(Scene *scene, char *str) /* copy */ make_ParticleUndo(psys,edit->curundo); } + void PE_undo_step(Scene *scene, int step) { - ParticleSystem *psys = PE_get_current(OBACT); - ParticleEdit *edit = 0; + ParticleSystem *psys= PE_get_current(scene, OBACT); + ParticleEdit *edit= 0; if(!PE_can_edit(psys)) return; edit=psys->edit; @@ -3166,7 +3647,7 @@ static void ParticleUndo_clear(ParticleSystem *psys) if(psys==0) return; - edit = psys->edit; + edit= psys->edit; if(edit==0) return; @@ -3178,25 +3659,28 @@ static void ParticleUndo_clear(ParticleSystem *psys) BLI_freelistN(&edit->undo); edit->curundo= NULL; } + void PE_undo(Scene *scene) { PE_undo_step(scene, 1); } + void PE_redo(Scene *scene) { PE_undo_step(scene, -1); } -void PE_undo_menu(Scene *scene) + +void PE_undo_menu(Scene *scene, Object *ob) { - ParticleSystem *psys = PE_get_current(OBACT); - ParticleEdit *edit = 0; + ParticleSystem *psys= PE_get_current(scene, ob); + ParticleEdit *edit= 0; ParticleUndo *undo; DynStr *ds; short event; char *menu; if(!PE_can_edit(psys)) return; - edit = psys->edit; + edit= psys->edit; ds= BLI_dynstr_new(); @@ -3216,6 +3700,8 @@ void PE_undo_menu(Scene *scene) if(event>0) ParticleUndo_number(scene, edit,event); } +/************************ utilities ******************************/ + void PE_get_colors(char sel[4], char nosel[4]) { UI_GetThemeColor3ubv(TH_EDGE_SELECT, sel); @@ -3224,26 +3710,26 @@ void PE_get_colors(char sel[4], char nosel[4]) int PE_minmax(Scene *scene, float *min, float *max) { - Object *ob = OBACT; - ParticleSystem *psys = PE_get_current(ob); + Object *ob= OBACT; + ParticleSystem *psys= PE_get_current(scene, ob); ParticleSystemModifierData *psmd; ParticleData *pa; ParticleEditKey *key; float co[3], mat[4][4]; - int i, k, totpart, ok = 0; + int i, k, totpart, ok= 0; if(!PE_can_edit(psys)) return ok; psmd= psys_get_modifier(ob, psys); totpart= psys->totpart; - LOOP_PARTICLES(i,pa){ - if(pa->flag&PARS_HIDE) continue; + LOOP_PARTICLES(i,pa) { + if(pa->flag & PARS_HIDE) continue; psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, mat); - LOOP_KEYS(k,key){ - if(key->flag&PEK_SELECT) { + LOOP_KEYS(k,key) { + if(key->flag & PEK_SELECT) { VECCOPY(co, key->co); Mat4MulVecfl(mat, co); DO_MINMAX(co, min, max); @@ -3260,3 +3746,87 @@ int PE_minmax(Scene *scene, float *min, float *max) return ok; } +/*********************** specials menu **************************/ + +static int specials_menu_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + Scene *scene= CTX_data_scene(C); + uiMenuItem *head; + + head= uiPupMenuBegin("Specials", 0); + + uiMenuItemO(head, 0, "PARTICLE_OT_rekey"); + if(scene->selectmode & SCE_SELECT_POINT) { + uiMenuItemO(head, 0, "PARTICLE_OT_subdivide"); + uiMenuItemO(head, 0, "PARTICLE_OT_select_first"); + uiMenuItemO(head, 0, "PARTICLE_OT_select_last"); + } + uiMenuItemO(head, 0, "PARTICLE_OT_remove_doubles"); + + uiPupMenuEnd(C, head); + + return OPERATOR_CANCELLED; +} + +void PARTICLE_OT_specials_menu(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Specials Menu"; + ot->idname= "PARTICLE_OT_specials_menu"; + + /* api callbacks */ + ot->invoke= specials_menu_invoke; + ot->poll= PE_poll; +} + +/**************************** registration **********************************/ + +void ED_operatortypes_particle(void) +{ + WM_operatortype_append(PARTICLE_OT_de_select_all); + WM_operatortype_append(PARTICLE_OT_select_first); + WM_operatortype_append(PARTICLE_OT_select_last); + WM_operatortype_append(PARTICLE_OT_select_linked); + WM_operatortype_append(PARTICLE_OT_select_less); + WM_operatortype_append(PARTICLE_OT_select_more); + + WM_operatortype_append(PARTICLE_OT_hide); + WM_operatortype_append(PARTICLE_OT_reveal); + + WM_operatortype_append(PARTICLE_OT_rekey); + WM_operatortype_append(PARTICLE_OT_subdivide); + WM_operatortype_append(PARTICLE_OT_remove_doubles); + WM_operatortype_append(PARTICLE_OT_delete); + WM_operatortype_append(PARTICLE_OT_mirror); + + WM_operatortype_append(PARTICLE_OT_set_brush); + WM_operatortype_append(PARTICLE_OT_brush_edit); + + WM_operatortype_append(PARTICLE_OT_specials_menu); + + WM_operatortype_append(PARTICLE_OT_particle_edit_toggle); +} + +void ED_keymap_particle(wmWindowManager *wm) +{ + ListBase *keymap= WM_keymap_listbase(wm, "Particle", 0, 0); + + WM_keymap_add_item(keymap, "PARTICLE_OT_de_select_all", AKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "PARTICLE_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "PARTICLE_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, 0, 0); + RNA_boolean_set(WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1); + + WM_keymap_add_item(keymap, "PARTICLE_OT_delete", XKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "PARTICLE_OT_delete", DELKEY, KM_PRESS, 0, 0); + + WM_keymap_add_item(keymap, "PARTICLE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0); + WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, 0, 0); + RNA_enum_set(WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1); + + WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", ACTIONMOUSE, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0); + + WM_keymap_add_item(keymap, "PARTICLE_OT_specials_menu", WKEY, KM_PRESS, 0, 0); +} + diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index f3d29989bb8..8987479bbfc 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -1300,26 +1300,6 @@ static void SCULPT_OT_radial_control(wmOperatorType *ot) /**** Operator for applying a stroke (various attributes including mouse path) using the current brush. ****/ -static void sculpt_load_mats(bglMats *mats, ViewContext *vc) -{ - float cpy[4][4]; - int i, j; - - Mat4MulMat4(cpy, vc->rv3d->viewmat, vc->obact->obmat); - - for(i = 0; i < 4; ++i) { - for(j = 0; j < 4; ++j) { - mats->projection[i*4+j] = vc->rv3d->winmat[i][j]; - mats->modelview[i*4+j] = cpy[i][j]; - } - } - - mats->viewport[0] = vc->ar->winrct.xmin; - mats->viewport[1] = vc->ar->winrct.ymin; - mats->viewport[2] = vc->ar->winx; - mats->viewport[3] = vc->ar->winy; -} - static float unproject_brush_radius(SculptSession *ss, float offset) { float brush_edge[3]; @@ -1363,7 +1343,7 @@ static void sculpt_update_cache_invariants(Sculpt *sd, bContext *C, wmOperator * view3d_set_viewcontext(C, &cache->vc); cache->mats = MEM_callocN(sizeof(bglMats), "sculpt bglMats"); - sculpt_load_mats(cache->mats, &cache->vc); + view3d_get_transformation(&cache->vc, cache->vc.obact, cache->mats); sculpt_update_mesh_elements(C); diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c index cae8afb2c44..9a4d1f329e8 100644 --- a/source/blender/editors/space_api/spacetypes.c +++ b/source/blender/editors/space_api/spacetypes.c @@ -45,6 +45,7 @@ #include "ED_mesh.h" #include "ED_markers.h" #include "ED_object.h" +#include "ED_particle.h" #include "ED_sculpt.h" #include "ED_screen.h" #include "ED_space_api.h" @@ -83,6 +84,7 @@ void ED_spacetypes_init(void) ED_operatortypes_sculpt(); ED_operatortypes_uvedit(); ED_operatortypes_paint(); + ED_operatortypes_particle(); ED_operatortypes_curve(); ED_operatortypes_armature(); ED_marker_operatortypes(); @@ -111,6 +113,7 @@ void ED_spacetypes_keymap(wmWindowManager *wm) ED_keymap_uvedit(wm); ED_keymap_curve(wm); ED_keymap_armature(wm); + ED_keymap_particle(wm); ED_marker_keymap(wm); UI_view2d_keymap(wm); diff --git a/source/blender/editors/space_image/image_header.c b/source/blender/editors/space_image/image_header.c index 6025b81f7fd..8f981b6982b 100644 --- a/source/blender/editors/space_image/image_header.c +++ b/source/blender/editors/space_image/image_header.c @@ -261,9 +261,9 @@ static void image_imagemenu(bContext *C, uiMenuItem *head, void *arg_unused) static void image_uvs_showhidemenu(bContext *C, uiMenuItem *head, void *arg_unused) { - uiMenuItemO(head, 0, "UV_OT_show_hidden"); - uiMenuItemO(head, 0, "UV_OT_hide_selected"); - uiMenuItemO(head, 0, "UV_OT_hide_deselected"); + uiMenuItemO(head, 0, "UV_OT_reveal"); + uiMenuItemO(head, 0, "UV_OT_hide"); + uiMenuItemBooleanO(head, "Hide Unselected", 0, "UV_OT_hide", "unselected", 1); } static void image_uvs_transformmenu(bContext *C, uiMenuItem *head, void *arg_unused) diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 7df8f3a75db..f9a5195860d 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -98,7 +98,7 @@ #include "GPU_material.h" #include "GPU_extensions.h" -#include "ED_editparticle.h" +#include "ED_particle.h" #include "ED_mesh.h" #include "ED_types.h" #include "ED_util.h" @@ -5086,7 +5086,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) draw_new_particle_system(scene, v3d, rv3d, base, psys, dt); if(G.f & G_PARTICLEEDIT && ob==OBACT) { - psys= PE_get_current(ob); + psys= PE_get_current(scene, ob); if(psys && !scene->obedit && psys_in_edit_mode(scene, psys)) draw_particle_edit(scene, v3d, rv3d, ob, psys, dt); } diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index d3935b49658..4e2a0090244 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -240,7 +240,13 @@ static void view3d_modal_keymaps(wmWindowManager *wm, ARegion *ar, int stype) WM_event_add_keymap_handler(&ar->handlers, keymap); else WM_event_remove_keymap_handler(&ar->handlers, keymap); - + + keymap= WM_keymap_listbase(wm, "Particle", 0, 0); + if(stype==NS_MODE_PARTICLE) + WM_event_add_keymap_handler(&ar->handlers, keymap); + else + WM_event_remove_keymap_handler(&ar->handlers, keymap); + /* editfont keymap swallows all... */ keymap= WM_keymap_listbase(wm, "Font", 0, 0); if(stype==NS_EDITMODE_TEXT) diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c index 15c5df8f6cb..d449b0cc774 100644 --- a/source/blender/editors/space_view3d/view3d_buttons.c +++ b/source/blender/editors/space_view3d/view3d_buttons.c @@ -77,7 +77,7 @@ #include "ED_armature.h" #include "ED_curve.h" -#include "ED_editparticle.h" +#include "ED_particle.h" #include "ED_keyframing.h" #include "ED_mesh.h" #include "ED_object.h" diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 4c2cd184b84..78309a40f94 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -70,7 +70,7 @@ #include "RNA_access.h" #include "RNA_define.h" -#include "ED_editparticle.h" +#include "ED_particle.h" #include "ED_space_api.h" #include "ED_screen.h" #include "ED_types.h" diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 5fc93304e5d..a7dd419f672 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -66,7 +66,7 @@ #include "BKE_utildefines.h" /* for VECCOPY */ #include "ED_armature.h" -#include "ED_editparticle.h" +#include "ED_particle.h" #include "ED_object.h" #include "ED_mesh.h" #include "ED_util.h" @@ -149,9 +149,8 @@ void ED_view3d_exit_paint_modes(bContext *C) if(G.f & G_SCULPTMODE) WM_operator_name_call(C, "SCULPT_OT_sculptmode_toggle", WM_OP_EXEC_REGION_WIN, NULL); - -// if(G.f & G_TEXTUREPAINT) set_texturepaint(); - if(G.f & G_PARTICLEEDIT) PE_set_particle_edit(CTX_data_scene(C)); + if(G.f & G_PARTICLEEDIT) + WM_operator_name_call(C, "PARTICLE_OT_particle_edit_toggle", WM_OP_EXEC_REGION_WIN, NULL); G.f &= ~(G_VERTEXPAINT+G_TEXTUREPAINT+G_WEIGHTPAINT+G_SCULPTMODE+G_PARTICLEEDIT); } @@ -2487,7 +2486,7 @@ static uiBlock *view3d_edit_object_showhidemenu(bContext *C, ARegion *ar, void * uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Hidden|Alt H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Selected|H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Deselected|Shift H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Unselected|Shift H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); uiBlockSetDirection(block, UI_RIGHT); uiTextBoundsBlock(block, 60); @@ -3104,7 +3103,7 @@ static uiBlock *view3d_edit_mesh_showhidemenu(bContext *C, ARegion *ar, void *ar uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Hidden|Alt H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Selected|H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Deselected|Shift H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Unselected|Shift H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); uiBlockSetDirection(block, UI_RIGHT); uiTextBoundsBlock(block, 60); @@ -3322,7 +3321,7 @@ static void view3d_edit_curve_showhidemenu(bContext *C, uiMenuItem *head, void * { uiMenuItemO(head, 0, "CURVE_OT_reveal"); uiMenuItemO(head, 0, "CURVE_OT_hide"); - uiMenuItemBooleanO(head, "Hide Deselected", 0, "CURVE_OT_hide", "deselected", 1); + uiMenuItemBooleanO(head, "Hide Unselected", 0, "CURVE_OT_hide", "unselected", 1); } static void view3d_edit_curvemenu(bContext *C, uiMenuItem *head, void *arg_unused) @@ -3379,7 +3378,7 @@ static void do_view3d_edit_mball_showhidemenu(bContext *C, void *arg, int event) case 11: /* hide selected control points */ hide_mball(0); break; - case 12: /* hide deselected control points */ + case 12: /* hide selected control points */ hide_mball(1); break; } @@ -3396,7 +3395,7 @@ static uiBlock *view3d_edit_mball_showhidemenu(bContext *C, ARegion *ar, void *a uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Hidden|Alt H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Selected|H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Deselected|Shift H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Unselected|Shift H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, ""); uiBlockSetDirection(block, UI_RIGHT); uiTextBoundsBlock(block, 60); @@ -3934,7 +3933,7 @@ static uiBlock *view3d_pose_armature_showhidemenu(bContext *C, ARegion *ar, void uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Hidden|Alt H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Selected|H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Deselected|Shift H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Unselected|Shift H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); uiBlockSetDirection(block, UI_RIGHT); uiTextBoundsBlock(block, 60); @@ -4638,7 +4637,7 @@ static uiBlock *view3d_facesel_showhidemenu(bContext *C, ARegion *ar, void *arg_ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Hidden Faces|Alt H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Selected Faces|H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Deselected Faces|Shift H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Unselected Faces|Shift H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, ""); uiBlockSetDirection(block, UI_RIGHT); uiTextBoundsBlock(block, 60); @@ -4693,195 +4692,61 @@ static uiBlock *view3d_faceselmenu(bContext *C, ARegion *ar, void *arg_unused) return block; } -void do_view3d_select_particlemenu(bContext *C, void *arg, int event) +static void view3d_select_particlemenu(bContext *C, uiMenuItem *head, void *arg_unused) { + Scene *scene= CTX_data_scene(C); - /* events >= 6 are registered bpython scripts */ -#ifndef DISABLE_PYTHON -// XXX if (event >= 6) BPY_menu_do_python(PYMENU_FACESELECT, event - 6); -#endif - switch(event) { - case 0: - // XXX PE_borderselect(); - break; - case 1: - PE_deselectall(); - break; - case 2: - PE_select_root(); - break; - case 3: - PE_select_tip(); - break; - case 4: - PE_select_more(); - break; - case 5: - PE_select_less(); - break; - case 7: - PE_select_linked(); - break; - } -} - -static uiBlock *view3d_select_particlemenu(bContext *C, ARegion *ar, void *arg_unused) -{ - uiBlock *block; - short yco= 0, menuwidth=120; - - block= uiBeginBlock(C, ar, "view3d_select_particlemenu", UI_EMBOSSP, UI_HELV); - uiBlockSetButmFunc(block, do_view3d_select_particlemenu, NULL); - - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Border Select|B", - 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, ""); - - uiDefBut(block, SEPR, 0, "", - 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); - - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All|A", - 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Linked|L", - 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Last|W, 4", - 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select First|W, 3", - 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); - - uiDefBut(block, SEPR, 0, "", - 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + uiMenuItemO(head, 0, "VIEW3D_OT_borderselect"); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "More|Ctrl NumPad +", - 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Less|Ctrl NumPad -", - 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, ""); + uiMenuSeparator(head); + uiMenuItemO(head, 0, "PARTICLE_OT_de_select_all"); + uiMenuItemO(head, 0, "PARTICLE_OT_select_linked"); - if(ar->alignment==RGN_ALIGN_TOP) { - uiBlockSetDirection(block, UI_DOWN); - } - else { - uiBlockSetDirection(block, UI_TOP); - uiBlockFlipOrder(block); + if(scene->selectmode & SCE_SELECT_POINT) { + uiMenuItemO(head, 0, "PARTICLE_OT_select_last"); // |W, 4 + uiMenuItemO(head, 0, "PARTICLE_OT_select_first"); // |W, 3 } - uiTextBoundsBlock(block, 50); - return block; -} - -void do_view3d_particle_showhidemenu(bContext *C, void *arg, int event) -{ + uiMenuSeparator(head); - switch(event) { - case 1: /* show hidden */ - PE_hide(0); - break; - case 2: /* hide selected */ - PE_hide(2); - break; - case 3: /* hide deselected */ - PE_hide(1); - break; - } + uiMenuItemO(head, 0, "PARTICLE_OT_select_more"); + uiMenuItemO(head, 0, "PARTICLE_OT_select_less"); } -static uiBlock *view3d_particle_showhidemenu(bContext *C, ARegion *ar, void *arg_unused) +static void view3d_particle_showhidemenu(bContext *C, uiMenuItem *head, void *arg_unused) { - uiBlock *block; - short yco = 20, menuwidth = 120; - - block= uiBeginBlock(C, ar, "view3d_particle_showhidemenu", UI_EMBOSSP, UI_HELV); - uiBlockSetButmFunc(block, do_view3d_particle_showhidemenu, NULL); - - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Hidden|Alt H", - 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Selected|H", - 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide Deselected|Shift H", - 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, ""); - - uiBlockSetDirection(block, UI_RIGHT); - uiTextBoundsBlock(block, 60); - return block; + uiMenuItemO(head, 0, "PARTICLE_OT_reveal"); + uiMenuItemO(head, 0, "PARTICLE_OT_hide"); + uiMenuItemBooleanO(head, "Hide Unselected", 0, "PARTICLE_OT_hide", "unselected", 1); } -void do_view3d_particlemenu(bContext *C, void *arg, int event) +static void view3d_particlemenu(bContext *C, uiMenuItem *head, void *arg_unused) { -#if 0 Scene *scene= CTX_data_scene(C); - ScrArea *sa= CTX_wm_area(C); - View3D *v3d= sa->spacedata.first; - ParticleEditSettings *pset= PE_settings(); - switch(event) { - case 1: - add_blockhandler(sa, VIEW3D_HANDLER_OBJECT, UI_PNL_UNSTOW); - break; - case 2: - if(button(&pset->totrekey, 2, 100, "Number of Keys:")==0) return; - PE_rekey(); - break; - case 3: - PE_subdivide(); - break; - case 4: - PE_delete_particle(); - break; - case 5: - PE_mirror_x(0); - break; - case 6: - pset->flag ^= PE_X_MIRROR; - break; - case 7: - PE_remove_doubles(); - break; - } + // XXX uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Particle Edit Properties|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, ""); + // add_blockhandler(sa, VIEW3D_HANDLER_OBJECT, UI_PNL_UNSTOW); + // XXX uiMenuSeparator(head); + // + // XXX uiDefIconTextBut(block, BUTM, 1, (pset->flag & PE_X_MIRROR)? ICON_CHECKBOX_HLT: ICON_CHECKBOX_DEHLT, "X-Axis Mirror Editing", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, ""); + // pset->flag ^= PE_X_MIRROR; -#endif -} + uiMenuItemO(head, 0, "PARTICLE_OT_mirror"); // |Ctrl M -uiBlock *view3d_particlemenu(bContext *C, ARegion *ar, void *arg_unused) -{ - Scene *scene= CTX_data_scene(C); - uiBlock *block; - ParticleEditSettings *pset= PE_settings(scene); - short yco= 0, menuwidth= 120; - - block= uiBeginBlock(C, ar, "view3d_particlemenu", UI_EMBOSSP, UI_HELV); - uiBlockSetButmFunc(block, do_view3d_particlemenu, NULL); - - uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Particle Edit Properties|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, ""); - uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); - - uiDefIconTextBut(block, BUTM, 1, (pset->flag & PE_X_MIRROR)? ICON_CHECKBOX_HLT: ICON_CHECKBOX_DEHLT, "X-Axis Mirror Editing", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, ""); - - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Mirror|Ctrl M", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, ""); - uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + uiMenuSeparator(head); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Remove Doubles|W, 5", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Delete...|X", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, ""); + uiMenuItemO(head, 0, "PARTICLE_OT_remove_doubles"); // |W, 5 + uiMenuItemO(head, 0, "PARTICLE_OT_delete"); if(scene->selectmode & SCE_SELECT_POINT) - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Subdivide|W, 2", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Rekey|W, 1", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); - uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + uiMenuItemO(head, 0, "PARTICLE_OT_subdivide"); // |W, 2 + uiMenuItemO(head, 0, "PARTICLE_OT_rekey"); // |W, 1 - uiDefIconTextBlockBut(block, view3d_particle_showhidemenu, NULL, ICON_RIGHTARROW_THIN, "Show/Hide Particles", 0, yco-=20, menuwidth, 19, ""); - - if(ar->alignment==RGN_ALIGN_TOP) { - uiBlockSetDirection(block, UI_DOWN); - } - else { - uiBlockSetDirection(block, UI_TOP); - uiBlockFlipOrder(block); - } - - uiTextBoundsBlock(block, 50); + uiMenuSeparator(head); - return block; + uiMenuLevel(head, "Show/Hide Particles", view3d_particle_showhidemenu); } - static char *view3d_modeselect_pup(Scene *scene) { Object *ob= OBACT; @@ -5127,7 +4992,7 @@ static void do_view3d_header_buttons(bContext *C, void *arg, int event) ED_view3d_exit_paint_modes(C); if(obedit) ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* exit editmode and undo */ - PE_set_particle_edit(scene); + WM_operator_name_call(C, "PARTICLE_OT_particle_edit_toggle", WM_OP_EXEC_REGION_WIN, NULL); } } break; @@ -5295,7 +5160,7 @@ static void view3d_header_pulldowns(const bContext *C, uiBlock *block, Object *o } else if ((G.f & G_VERTEXPAINT) || (G.f & G_TEXTUREPAINT) || (G.f & G_WEIGHTPAINT)) { uiDefBut(block, LABEL,0,"", xco, 0, xmax, 20, 0, 0, 0, 0, 0, ""); } else if (G.f & G_PARTICLEEDIT) { - uiDefPulldownBut(block, view3d_select_particlemenu, NULL, "Select", xco,yco-2, xmax-3, 24, ""); + uiDefMenuBut(block, view3d_select_particlemenu, NULL, "Select", xco,yco-2, xmax-3, 24, ""); } else { if (ob && (ob->flag & OB_POSEMODE)) @@ -5366,7 +5231,7 @@ static void view3d_header_pulldowns(const bContext *C, uiBlock *block, Object *o } else if(G.f & G_PARTICLEEDIT) { xmax= GetButStringLength("Particle"); - uiDefPulldownBut(block, view3d_particlemenu, NULL, "Particle", xco,yco-2, xmax-3, 24, ""); + uiDefMenuBut(block, view3d_particlemenu, NULL, "Particle", xco,yco-2, xmax-3, 24, ""); xco+= xmax; } else { diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 0348907820d..f4525b97128 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -76,7 +76,7 @@ #include "ED_armature.h" #include "ED_curve.h" -#include "ED_editparticle.h" +#include "ED_particle.h" #include "ED_mesh.h" #include "ED_object.h" #include "ED_screen.h" @@ -121,6 +121,26 @@ void view3d_get_view_aligned_coordinate(ViewContext *vc, float *fp, short mval[2 } } +void view3d_get_transformation(ViewContext *vc, Object *ob, bglMats *mats) +{ + float cpy[4][4]; + int i, j; + + Mat4MulMat4(cpy, vc->rv3d->viewmat, ob->obmat); + + for(i = 0; i < 4; ++i) { + for(j = 0; j < 4; ++j) { + mats->projection[i*4+j] = vc->rv3d->winmat[i][j]; + mats->modelview[i*4+j] = cpy[i][j]; + } + } + + mats->viewport[0] = vc->ar->winrct.xmin; + mats->viewport[1] = vc->ar->winrct.ymin; + mats->viewport[2] = vc->ar->winx; + mats->viewport[3] = vc->ar->winy; +} + /* ********************** view3d_select: selection manipulations ********************* */ /* XXX to solve *************** */ @@ -677,7 +697,7 @@ void view3d_lasso_select(ViewContext *vc, short mcords[][2], short moves, short else if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT|G_WEIGHTPAINT)) ; else if(G.f & G_PARTICLEEDIT) - PE_do_lasso_select(vc, mcords, moves, select); + PE_lasso_select(vc, mcords, moves, select); else do_lasso_select_objects(vc, mcords, moves, select); } @@ -1329,7 +1349,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } else if(obedit==NULL && (G.f & G_PARTICLEEDIT)) { - PE_borderselect(&vc, &rect, (val==LEFTMOUSE)); + PE_border_select(&vc, &rect, (val==LEFTMOUSE)); return OPERATOR_FINISHED; } @@ -1765,7 +1785,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) int y= RNA_int_get(op->ptr, "y"); int radius= RNA_int_get(op->ptr, "radius"); - if(CTX_data_edit_object(C)) { + if(CTX_data_edit_object(C) || (G.f & G_PARTICLEEDIT)) { ViewContext vc; short mval[2], selecting; @@ -1775,7 +1795,11 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) mval[0]= x; mval[1]= y; selecting= LEFTMOUSE==RNA_int_get(op->ptr, "event_type"); // XXX solve - obedit_circle_select(&vc, selecting, mval, (float)radius); + + if(CTX_data_edit_object(C)) + obedit_circle_select(&vc, selecting, mval, (float)radius); + else + PE_circle_select(&vc, selecting, mval, (float)radius); } else { Base *base; diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index bf059f7b9be..641b538a3ed 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -121,7 +121,7 @@ #include "ED_anim_api.h" #include "ED_armature.h" -#include "ED_editparticle.h" +#include "ED_particle.h" #include "ED_image.h" #include "ED_keyframing.h" #include "ED_keyframes_edit.h" diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c index 0584644c027..a54d590c2af 100644 --- a/source/blender/editors/util/undo.c +++ b/source/blender/editors/util/undo.c @@ -55,7 +55,7 @@ #include "BKE_utildefines.h" #include "ED_armature.h" -#include "ED_editparticle.h" +#include "ED_particle.h" #include "ED_curve.h" #include "ED_mesh.h" #include "ED_object.h" @@ -191,7 +191,7 @@ void ED_undo_menu(bContext *C) } else { if(G.f & G_PARTICLEEDIT) - PE_undo_menu(CTX_data_scene(C)); + PE_undo_menu(CTX_data_scene(C), CTX_data_active_object(C)); else if(U.uiflag & USER_GLOBALUNDO) { char *menu= BKE_undo_menu_string(); if(menu) { diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index ec7c5450cd0..60cfbfd0f39 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -2513,7 +2513,7 @@ void UV_OT_snap_selection(wmOperatorType *ot) static EnumPropertyItem target_items[] = { {0, "PIXELS", "Pixels", ""}, {1, "CURSOR", "Cursor", ""}, - {2, "ADJACENT_DESELECTED", "Adjacent Deselected", ""}, + {2, "ADJACENT_UNSELECTED", "Adjacent Unselected", ""}, {0, NULL, NULL, NULL}}; /* identifiers */ @@ -2633,7 +2633,7 @@ static int hide_exec(bContext *C, wmOperator *op) EditMesh *em= ((Mesh*)obedit->data)->edit_mesh; EditFace *efa; MTFace *tf; - int swap= (strcmp(op->idname, "UV_OT_hide_deselected") == 0); + int swap= RNA_boolean_get(op->ptr, "unselected"); if(scene->toolsettings->uv_flag & UV_SYNC_SELECTION) { EM_hide_mesh(em, swap); @@ -2748,33 +2748,24 @@ static int hide_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void UV_OT_hide_selected(wmOperatorType *ot) +void UV_OT_hide(wmOperatorType *ot) { /* identifiers */ ot->name= "Hide Selected"; - ot->idname= "UV_OT_hide_selected"; + ot->idname= "UV_OT_hide"; ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* api callbacks */ ot->exec= hide_exec; ot->poll= ED_operator_uvedit; -} -void UV_OT_hide_deselected(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Hide Deselected"; - ot->idname= "UV_OT_hide_deselected"; - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - - /* api callbacks */ - ot->exec= hide_exec; - ot->poll= ED_operator_uvedit; + /* props */ + RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected."); } -/****************** show hidden operator ******************/ +/****************** reveal operator ******************/ -static int show_hidden_exec(bContext *C, wmOperator *op) +static int reveal_exec(bContext *C, wmOperator *op) { SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C); Scene *scene= CTX_data_scene(C); @@ -2885,22 +2876,21 @@ static int show_hidden_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void UV_OT_show_hidden(wmOperatorType *ot) +void UV_OT_reveal(wmOperatorType *ot) { /* identifiers */ - ot->name= "Show Hidden"; - ot->idname= "UV_OT_show_hidden"; + ot->name= "Reveal Hidden"; + ot->idname= "UV_OT_reveal"; ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* api callbacks */ - ot->exec= show_hidden_exec; + ot->exec= reveal_exec; ot->poll= ED_operator_uvedit; } - /******************** set 3d cursor operator ********************/ -static int set_3d_cursor_exec(bContext *C, wmOperator *op) +static int set_2d_cursor_exec(bContext *C, wmOperator *op) { ARegion *ar= CTX_wm_region(C); float location[2]; @@ -2914,7 +2904,7 @@ static int set_3d_cursor_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static int set_3d_cursor_invoke(bContext *C, wmOperator *op, wmEvent *event) +static int set_2d_cursor_invoke(bContext *C, wmOperator *op, wmEvent *event) { ARegion *ar= CTX_wm_region(C); int x, y; @@ -2925,18 +2915,18 @@ static int set_3d_cursor_invoke(bContext *C, wmOperator *op, wmEvent *event) UI_view2d_region_to_view(&ar->v2d, x, y, &location[0], &location[1]); RNA_float_set_array(op->ptr, "location", location); - return set_3d_cursor_exec(C, op); + return set_2d_cursor_exec(C, op); } -void UV_OT_set_3d_cursor(wmOperatorType *ot) +void UV_OT_set_2d_cursor(wmOperatorType *ot) { /* identifiers */ ot->name= "Set 3D Cursor"; - ot->idname= "UV_OT_set_3d_cursor"; + ot->idname= "UV_OT_set_2d_cursor"; /* api callbacks */ - ot->exec= set_3d_cursor_exec; - ot->invoke= set_3d_cursor_invoke; + ot->exec= set_2d_cursor_exec; + ot->invoke= set_2d_cursor_invoke; ot->poll= ED_operator_uvedit; /* flags */ @@ -3045,11 +3035,10 @@ void ED_operatortypes_uvedit(void) WM_operatortype_append(UV_OT_sphere_project); WM_operatortype_append(UV_OT_unwrap); - WM_operatortype_append(UV_OT_show_hidden); - WM_operatortype_append(UV_OT_hide_selected); - WM_operatortype_append(UV_OT_hide_deselected); + WM_operatortype_append(UV_OT_reveal); + WM_operatortype_append(UV_OT_hide); - WM_operatortype_append(UV_OT_set_3d_cursor); + WM_operatortype_append(UV_OT_set_2d_cursor); WM_operatortype_append(UV_OT_set_tile); } @@ -3087,12 +3076,12 @@ void ED_keymap_uvedit(wmWindowManager *wm) WM_keymap_add_item(keymap, "UV_OT_average_islands_scale", AKEY, KM_PRESS, KM_CTRL, 0); /* hide */ - WM_keymap_add_item(keymap, "UV_OT_hide_selected", HKEY, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "UV_OT_hide_deselected", HKEY, KM_PRESS, KM_SHIFT, 0); - WM_keymap_add_item(keymap, "UV_OT_show_hidden", HKEY, KM_PRESS, KM_ALT, 0); + WM_keymap_add_item(keymap, "UV_OT_hide", HKEY, KM_PRESS, 0, 0); + RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1); + WM_keymap_add_item(keymap, "UV_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0); /* cursor */ - WM_keymap_add_item(keymap, "UV_OT_set_3d_cursor", ACTIONMOUSE, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "UV_OT_set_2d_cursor", ACTIONMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "UV_OT_set_tile", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0); transform_keymap_for_space(wm, keymap, SPACE_IMAGE); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 2f24e180ae6..9dc2d5cf0b2 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -218,7 +218,8 @@ typedef struct wmNotifier { #define NS_EDITMODE_MBALL (6<<8) #define NS_EDITMODE_LATTICE (7<<8) #define NS_EDITMODE_ARMATURE (8<<8) -#define NS_POSEMODE (9<<8) +#define NS_MODE_POSE (9<<8) +#define NS_MODE_PARTICLE (10<<8) /* action classification */ |