Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/physics/particle_object.c
| Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
| #include "ED_particle.h" | #include "ED_particle.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_object.h" | #include "ED_object.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "physics_intern.h" | #include "physics_intern.h" | ||||
| extern void PE_create_particle_edit(const bContext *C, Scene *scene, SceneLayer *sl, Object *ob, PointCache *cache, ParticleSystem *psys); | extern void PE_create_particle_edit(const bContext *C, Scene *scene, ViewLayer *sl, Object *ob, PointCache *cache, ParticleSystem *psys); | ||||
| extern void PTCacheUndo_clear(PTCacheEdit *edit); | extern void PTCacheUndo_clear(PTCacheEdit *edit); | ||||
| extern void recalc_lengths(PTCacheEdit *edit); | extern void recalc_lengths(PTCacheEdit *edit); | ||||
| extern void recalc_emitter_field(Object *ob, ParticleSystem *psys); | extern void recalc_emitter_field(Object *ob, ParticleSystem *psys); | ||||
| extern void update_world_cos(Object *ob, PTCacheEdit *edit); | extern void update_world_cos(Object *ob, PTCacheEdit *edit); | ||||
| #define KEY_K PTCacheEditKey *key; int k | #define KEY_K PTCacheEditKey *key; int k | ||||
| #define POINT_P PTCacheEditPoint *point; int p | #define POINT_P PTCacheEditPoint *point; int p | ||||
| #define LOOP_POINTS for (p=0, point=edit->points; p<edit->totpoint; p++, point++) | #define LOOP_POINTS for (p=0, point=edit->points; p<edit->totpoint; p++, point++) | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | void OBJECT_OT_particle_system_add(wmOperatorType *ot) | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | ||||
| } | } | ||||
| static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op)) | static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Object *ob = ED_object_context(C); | Object *ob = ED_object_context(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| int mode_orig; | int mode_orig; | ||||
| if (!scene || !ob) | if (!scene || !ob) | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| mode_orig = ob->mode; | mode_orig = ob->mode; | ||||
| object_remove_particle_system(scene, ob); | object_remove_particle_system(scene, ob); | ||||
| ▲ Show 20 Lines • Show All 417 Lines • ▼ Show 20 Lines | void PARTICLE_OT_dupliob_move_down(wmOperatorType *ot) | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | ||||
| } | } | ||||
| /************************ connect/disconnect hair operators *********************/ | /************************ connect/disconnect hair operators *********************/ | ||||
| static void disconnect_hair( | static void disconnect_hair( | ||||
| const EvaluationContext *eval_ctx, Scene *scene, SceneLayer *sl, | const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *sl, | ||||
| Object *ob, ParticleSystem *psys) | Object *ob, ParticleSystem *psys) | ||||
| { | { | ||||
| ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); | ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); | ||||
| ParticleEditSettings *pset= PE_settings(scene); | ParticleEditSettings *pset= PE_settings(scene); | ||||
| ParticleData *pa; | ParticleData *pa; | ||||
| PTCacheEdit *edit; | PTCacheEdit *edit; | ||||
| PTCacheEditPoint *point; | PTCacheEditPoint *point; | ||||
| PTCacheEditKey *ekey = NULL; | PTCacheEditKey *ekey = NULL; | ||||
| Show All 36 Lines | if (ELEM(pset->brushtype, PE_BRUSH_ADD, PE_BRUSH_PUFF)) | ||||
| pset->brushtype = PE_BRUSH_NONE; | pset->brushtype = PE_BRUSH_NONE; | ||||
| PE_update_object(eval_ctx, scene, sl, ob, 0); | PE_update_object(eval_ctx, scene, sl, ob, 0); | ||||
| } | } | ||||
| static int disconnect_hair_exec(bContext *C, wmOperator *op) | static int disconnect_hair_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Scene *scene= CTX_data_scene(C); | Scene *scene= CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| Object *ob= ED_object_context(C); | Object *ob= ED_object_context(C); | ||||
| ParticleSystem *psys= NULL; | ParticleSystem *psys= NULL; | ||||
| const bool all = RNA_boolean_get(op->ptr, "all"); | const bool all = RNA_boolean_get(op->ptr, "all"); | ||||
| EvaluationContext eval_ctx; | EvaluationContext eval_ctx; | ||||
| CTX_data_eval_ctx(C, &eval_ctx); | CTX_data_eval_ctx(C, &eval_ctx); | ||||
| if (!ob) | if (!ob) | ||||
| Show All 28 Lines | void PARTICLE_OT_disconnect_hair(wmOperatorType *ot) | ||||
| RNA_def_boolean(ot->srna, "all", 0, "All hair", "Disconnect all hair systems from the emitter mesh"); | RNA_def_boolean(ot->srna, "all", 0, "All hair", "Disconnect all hair systems from the emitter mesh"); | ||||
| } | } | ||||
| /* from/to_world_space : whether from/to particles are in world or hair space | /* from/to_world_space : whether from/to particles are in world or hair space | ||||
| * from/to_mat : additional transform for from/to particles (e.g. for using object space copying) | * from/to_mat : additional transform for from/to particles (e.g. for using object space copying) | ||||
| */ | */ | ||||
| static bool remap_hair_emitter( | static bool remap_hair_emitter( | ||||
| const EvaluationContext *eval_ctx, Scene *scene, SceneLayer *sl, Object *ob, ParticleSystem *psys, | const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *sl, Object *ob, ParticleSystem *psys, | ||||
| Object *target_ob, ParticleSystem *target_psys, PTCacheEdit *target_edit, | Object *target_ob, ParticleSystem *target_psys, PTCacheEdit *target_edit, | ||||
| float from_mat[4][4], float to_mat[4][4], bool from_global, bool to_global) | float from_mat[4][4], float to_mat[4][4], bool from_global, bool to_global) | ||||
| { | { | ||||
| ParticleSystemModifierData *target_psmd = psys_get_modifier(target_ob, target_psys); | ParticleSystemModifierData *target_psmd = psys_get_modifier(target_ob, target_psys); | ||||
| ParticleData *pa, *tpa; | ParticleData *pa, *tpa; | ||||
| PTCacheEditPoint *edit_point; | PTCacheEditPoint *edit_point; | ||||
| PTCacheEditKey *ekey; | PTCacheEditKey *ekey; | ||||
| BVHTreeFromMesh bvhtree= {NULL}; | BVHTreeFromMesh bvhtree= {NULL}; | ||||
| ▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | static bool remap_hair_emitter( | ||||
| psys_free_path_cache(target_psys, target_edit); | psys_free_path_cache(target_psys, target_edit); | ||||
| PE_update_object(eval_ctx, scene, sl, target_ob, 0); | PE_update_object(eval_ctx, scene, sl, target_ob, 0); | ||||
| return true; | return true; | ||||
| } | } | ||||
| static bool connect_hair( | static bool connect_hair( | ||||
| const EvaluationContext *eval_ctx, Scene *scene, SceneLayer *sl, | const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *sl, | ||||
| Object *ob, ParticleSystem *psys) | Object *ob, ParticleSystem *psys) | ||||
| { | { | ||||
| bool ok; | bool ok; | ||||
| if (!psys) | if (!psys) | ||||
| return false; | return false; | ||||
| ok = remap_hair_emitter( | ok = remap_hair_emitter( | ||||
| eval_ctx, scene, sl, ob, psys, ob, psys, psys->edit, | eval_ctx, scene, sl, ob, psys, ob, psys, psys->edit, | ||||
| ob->obmat, ob->obmat, psys->flag & PSYS_GLOBAL_HAIR, false); | ob->obmat, ob->obmat, psys->flag & PSYS_GLOBAL_HAIR, false); | ||||
| psys->flag &= ~PSYS_GLOBAL_HAIR; | psys->flag &= ~PSYS_GLOBAL_HAIR; | ||||
| return ok; | return ok; | ||||
| } | } | ||||
| static int connect_hair_exec(bContext *C, wmOperator *op) | static int connect_hair_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| EvaluationContext eval_ctx; | EvaluationContext eval_ctx; | ||||
| Scene *scene= CTX_data_scene(C); | Scene *scene= CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| Object *ob= ED_object_context(C); | Object *ob= ED_object_context(C); | ||||
| ParticleSystem *psys= NULL; | ParticleSystem *psys= NULL; | ||||
| const bool all = RNA_boolean_get(op->ptr, "all"); | const bool all = RNA_boolean_get(op->ptr, "all"); | ||||
| bool any_connected = false; | bool any_connected = false; | ||||
| if (!ob) | if (!ob) | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| Show All 38 Lines | |||||
| /************************ particle system copy operator *********************/ | /************************ particle system copy operator *********************/ | ||||
| typedef enum eCopyParticlesSpace { | typedef enum eCopyParticlesSpace { | ||||
| PAR_COPY_SPACE_OBJECT = 0, | PAR_COPY_SPACE_OBJECT = 0, | ||||
| PAR_COPY_SPACE_WORLD = 1, | PAR_COPY_SPACE_WORLD = 1, | ||||
| } eCopyParticlesSpace; | } eCopyParticlesSpace; | ||||
| static void copy_particle_edit( | static void copy_particle_edit( | ||||
| const EvaluationContext *eval_ctx, Scene *scene, SceneLayer *sl, | const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *sl, | ||||
| Object *ob, ParticleSystem *psys, ParticleSystem *psys_from) | Object *ob, ParticleSystem *psys, ParticleSystem *psys_from) | ||||
| { | { | ||||
| PTCacheEdit *edit_from = psys_from->edit, *edit; | PTCacheEdit *edit_from = psys_from->edit, *edit; | ||||
| ParticleData *pa; | ParticleData *pa; | ||||
| KEY_K; | KEY_K; | ||||
| POINT_P; | POINT_P; | ||||
| if (!edit_from) | if (!edit_from) | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | static void remove_particle_systems_from_object(Object *ob_to) | ||||
| } | } | ||||
| BKE_object_free_particlesystems(ob_to); | BKE_object_free_particlesystems(ob_to); | ||||
| } | } | ||||
| /* single_psys_from is optional, if NULL all psys of ob_from are copied */ | /* single_psys_from is optional, if NULL all psys of ob_from are copied */ | ||||
| static bool copy_particle_systems_to_object(const bContext *C, | static bool copy_particle_systems_to_object(const bContext *C, | ||||
| Scene *scene, | Scene *scene, | ||||
| SceneLayer *sl, | ViewLayer *sl, | ||||
| Object *ob_from, | Object *ob_from, | ||||
| ParticleSystem *single_psys_from, | ParticleSystem *single_psys_from, | ||||
| Object *ob_to, | Object *ob_to, | ||||
| int space, | int space, | ||||
| bool duplicate_settings) | bool duplicate_settings) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| EvaluationContext eval_ctx; | EvaluationContext eval_ctx; | ||||
| ▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static int copy_particle_systems_exec(bContext *C, wmOperator *op) | static int copy_particle_systems_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| const int space = RNA_enum_get(op->ptr, "space"); | const int space = RNA_enum_get(op->ptr, "space"); | ||||
| const bool remove_target_particles = RNA_boolean_get(op->ptr, "remove_target_particles"); | const bool remove_target_particles = RNA_boolean_get(op->ptr, "remove_target_particles"); | ||||
| const bool use_active = RNA_boolean_get(op->ptr, "use_active"); | const bool use_active = RNA_boolean_get(op->ptr, "use_active"); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| Object *ob_from = ED_object_active_context(C); | Object *ob_from = ED_object_active_context(C); | ||||
| ParticleSystem *psys_from = use_active ? CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem).data : NULL; | ParticleSystem *psys_from = use_active ? CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem).data : NULL; | ||||
| int changed_tot = 0; | int changed_tot = 0; | ||||
| int fail = 0; | int fail = 0; | ||||
| CTX_DATA_BEGIN (C, Object *, ob_to, selected_editable_objects) | CTX_DATA_BEGIN (C, Object *, ob_to, selected_editable_objects) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static int duplicate_particle_systems_exec(bContext *C, wmOperator *op) | static int duplicate_particle_systems_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| const bool duplicate_settings = RNA_boolean_get(op->ptr, "use_duplicate_settings"); | const bool duplicate_settings = RNA_boolean_get(op->ptr, "use_duplicate_settings"); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| ParticleSystem *psys = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem).data; | ParticleSystem *psys = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem).data; | ||||
| copy_particle_systems_to_object(C, scene, CTX_data_scene_layer(C), ob, psys, ob, | copy_particle_systems_to_object(C, scene, CTX_data_view_layer(C), ob, psys, ob, | ||||
| PAR_COPY_SPACE_OBJECT, duplicate_settings); | PAR_COPY_SPACE_OBJECT, duplicate_settings); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void PARTICLE_OT_duplicate_particle_system(wmOperatorType *ot) | void PARTICLE_OT_duplicate_particle_system(wmOperatorType *ot) | ||||
| { | { | ||||
| ot->name = "Duplicate Particle Systems"; | ot->name = "Duplicate Particle Systems"; | ||||
| ot->description = "Duplicate particle system within the active object"; | ot->description = "Duplicate particle system within the active object"; | ||||
| Show All 11 Lines | |||||