48#include "RNA_prototypes.hh"
63static float I[4][4] = {
64 {1.0f, 0.0f, 0.0f, 0.0f},
65 {0.0f, 1.0f, 0.0f, 0.0f},
66 {0.0f, 0.0f, 1.0f, 0.0f},
67 {0.0f, 0.0f, 0.0f, 1.0f},
93 ot->
name =
"Add Particle System Slot";
94 ot->
idname =
"OBJECT_OT_particle_system_add";
117 mode_orig = ob->
mode;
142 ot->
name =
"Remove Particle System Slot";
143 ot->
idname =
"OBJECT_OT_particle_system_remove";
144 ot->
description =
"Remove the selected particle system";
183 ob = id_cast<Object *>(ptr.
owner_id);
204 ot->
name =
"New Particle Settings";
205 ot->
idname =
"PARTICLE_OT_new";
232 for (; pt; pt = pt->
next) {
236 pt = MEM_new<ParticleTarget>(
"keyed particle target");
254 ot->
name =
"New Particle Target";
255 ot->
idname =
"PARTICLE_OT_new_target";
279 for (; pt; pt = pt->
next) {
303 ot->
name =
"Remove Particle Target";
304 ot->
idname =
"PARTICLE_OT_target_remove";
305 ot->
description =
"Remove the selected particle target";
328 for (; pt; pt = pt->
next) {
344 ot->
name =
"Move Up Target";
345 ot->
idname =
"PARTICLE_OT_target_move_up";
346 ot->
description =
"Move particle target up in the list";
367 for (; pt; pt = pt->
next) {
383 ot->
name =
"Move Down Target";
384 ot->
idname =
"PARTICLE_OT_target_move_down";
385 ot->
description =
"Move particle target down in the list";
413 ot->
name =
"Refresh Instance Objects";
414 ot->
idname =
"PARTICLE_OT_dupliob_refresh";
415 ot->
description =
"Refresh list of instance objects and their weights";
452 ot->
name =
"Move Up Instance Object";
453 ot->
idname =
"PARTICLE_OT_dupliob_move_up";
454 ot->
description =
"Move instance object up in the list";
494 ot->
name =
"Copy Particle Instance Object";
495 ot->
idname =
"PARTICLE_OT_dupliob_copy";
496 ot->
description =
"Duplicate the current instance object";
538 ot->
name =
"Remove Particle Instance Object";
539 ot->
idname =
"PARTICLE_OT_dupliob_remove";
540 ot->
description =
"Remove the selected instance object";
578 ot->
name =
"Move Down Instance Object";
579 ot->
idname =
"PARTICLE_OT_dupliob_move_down";
580 ot->
description =
"Move instance object down in the list";
613 point = edit ? edit->
points :
nullptr;
615 for (i = 0, pa = psys->
particles; i < psys->totpart; i++, pa++) {
623 for (k = 0, key = pa->
hair; k < pa->totkey; k++, key++) {
674 ot->
name =
"Disconnect Hair";
675 ot->
description =
"Disconnect hair from the emitter mesh";
676 ot->
idname =
"PARTICLE_OT_disconnect_hair";
685 ot->
srna,
"all",
false,
"All Hair",
"Disconnect all hair systems from the emitter mesh");
698 const float from_mat[4][4],
699 const float to_mat[4][4],
711 const MFace *mface =
nullptr, *mf;
712 const int2 *edges =
nullptr, *edge;
716 float from_ob_imat[4][4], to_ob_imat[4][4];
717 float from_imat[4][4], to_imat[4][4];
729 edit_point = target_edit ? target_edit->
points :
nullptr;
731 invert_m4_m4(from_ob_imat, ob->object_to_world().ptr());
732 invert_m4_m4(to_ob_imat, target_ob->object_to_world().ptr());
746 if (
mesh ==
nullptr) {
756 numverts =
mesh->verts_num;
760 for (
int i = 0; i < numverts; i++) {
764 if (
mesh->totface_legacy != 0) {
766 legacy_faces_bvhtree =
mesh->bvh_legacy_faces();
768 else if (
mesh->edges_num != 0) {
769 edges =
mesh->edges().data();
770 edges_tree = &
mesh->bvh_edges();
778 for (i = 0, tpa = target_psys->
particles, pa = psys->
particles; i < target_psys->totpart;
791 int nearest_index = -1;
801 &legacy_faces_bvhtree);
802 nearest_index = nearest.
index;
805 else if (
const std::optional<bke::bvh::ClosestPointResult> nearest = edges_tree->
closest_point(
808 nearest_index = int(nearest->index);
809 nearest_co = nearest->position;
812 if (nearest_index == -1) {
814 printf(
"No nearest point found for hair root!");
822 mf = &mface[nearest_index];
836 tpa->
num = nearest_index;
837 if (use_dm_final_indices) {
846 edge = &edges[nearest_index];
849 tpa->
fuv[0] = 1.0f - tpa->
fuv[1];
850 tpa->
fuv[2] = tpa->
fuv[3] = 0.0f;
853 tpa->
num = nearest_index;
860 float hairmat[4][4], imat[4][4];
864 copy_m4_m4(imat, target_ob->object_to_world().ptr());
878 for (k = 0, key = pa->
hair, tkey = tpa->
hair, ekey = edit_point->
keys; k < tpa->totkey;
879 k++, key++, tkey++, ekey++)
901 for (k = 0, key = pa->
hair, tkey = tpa->
hair; k < tpa->totkey; k++, key++, tkey++) {
944 ob->object_to_world().ptr(),
945 ob->object_to_world().ptr(),
962 bool any_connected =
false;
970 any_connected |=
connect_hair(depsgraph, scene, ob, &psys);
975 any_connected |=
connect_hair(depsgraph, scene, ob, psys);
978 if (!any_connected) {
981 "No hair connected (cannot connect hair if particle system modifier is disabled)");
993 ot->
name =
"Connect Hair";
994 ot->
description =
"Connect hair to the emitter mesh";
995 ot->
idname =
"PARTICLE_OT_connect_hair";
1004 ot->
srna,
"all",
false,
"All Hair",
"Connect all hair systems to the emitter mesh");
1029 edit = MEM_dupalloc(edit_from);
1034 edit->mirror_cache =
nullptr;
1035 edit->pathcachebufs.clear_no_delete();
1037 edit->emitter_field =
nullptr;
1038 edit->emitter_cosnos =
nullptr;
1040 edit->points = MEM_dupalloc(edit_from->
points);
1045 point->keys = MEM_dupalloc(point->keys);
1048 key->time = &hkey->
time;
1078 for (md = ob_to->
modifiers.first(); md; md = md_next) {
1104 bool duplicate_settings)
1131#define PSYS_FROM_FIRST \
1132 static_cast<ParticleSystem *>( \
1133 (single_psys_from ? single_psys_from : ob_from->particlesystem.first()))
1134#define PSYS_FROM_NEXT(cur) (single_psys_from ? nullptr : (cur)->next)
1135 totpsys = single_psys_from ? 1 : ob_from->
particlesystem.count();
1138 "temporary particle system array");
1144 if (psys_start ==
nullptr) {
1153 psys_start = totpsys > 0 ? tmp_psys[0] :
nullptr;
1178 if (psys_from->edit) {
1182 if (duplicate_settings) {
1184 psys->part = id_cast<ParticleSettings *>(
BKE_id_copy(bmain, &psys->part->id));
1187 MEM_delete(tmp_psys);
1195 const float (*from_mat)[4], (*to_mat)[4];
1203 from_mat = ob_from->object_to_world().ptr();
1204 to_mat = ob_to->object_to_world().ptr();
1208 from_mat = to_mat =
nullptr;
1212 if (ob_from != ob_to) {
1230#undef PSYS_FROM_FIRST
1231#undef PSYS_FROM_NEXT
1257 const bool remove_target_particles =
RNA_boolean_get(op->
ptr,
"remove_target_particles");
1266 if (psys_from ==
nullptr) {
1272 int changed_tot = 0;
1276 if (ob_from != ob_to) {
1277 bool changed =
false;
1278 if (remove_target_particles) {
1296 if (changed_tot > 0) {
1300 if ((changed_tot == 0 && fail == 0) || fail) {
1303 "Copy particle systems to selected: %d done, %d failed",
1316 {0,
nullptr, 0,
nullptr,
nullptr},
1319 ot->
name =
"Copy Particle Systems";
1320 ot->
description =
"Copy particle systems from the active object to selected objects";
1321 ot->
idname =
"PARTICLE_OT_copy_particle_systems";
1334 "Space transform for copying from one object to another");
1336 "remove_target_particles",
1338 "Remove Target Particles",
1339 "Remove particle systems on the target objects");
1344 "Use the active particle system from the context");
1371 if (psys ==
nullptr) {
1382 ot->
name =
"Duplicate Particle System";
1383 ot->
description =
"Duplicate particle system within the active object";
1384 ot->
idname =
"PARTICLE_OT_duplicate_particle_system";
1393 "use_duplicate_settings",
1395 "Duplicate Settings",
1396 "Duplicate settings as well, so the new particle system uses its own settings");
1421 if (!scene || !ob) {
1450 ot->
name =
"Remove All Particle Systems";
1451 ot->
description =
"Remove all particle system within the active object";
1452 ot->
idname =
"PARTICLE_OT_particle_system_remove_all";
#define CTX_DATA_BEGIN(C, Type, instance, member)
CustomData interface, see also DNA_customdata_types.h.
General operations, lookup, etc. for blender objects.
#define SNPRINTF_UTF8(dst, format,...)
#define ID_IS_EDITABLE(_id)
#define ID_IS_OVERRIDE_LIBRARY(_id)
Read Blender memory allocation and freeing.
std::optional< ClosestPointResult > closest_point(const float3 &point, float radius=std::numeric_limits< float >::max()) const
bool all(VecOp< bool, D >) RET
Object * context_object(const bContext *C)
Object * context_active_object(const bContext *C)
void psys_free_path_cache(struct ParticleSystem *psys, struct PTCacheEdit *edit)
void WM_main_add_notifier(uint type, void *reference)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
float line_point_factor_v3(const float p[3], const float l1[3], const float l2[3])
struct ModifierData * object_add_particle_system(struct Main *bmain, const struct Scene *scene, struct Object *ob, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void object_remove_particle_system(struct Main *bmain, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys)
static void remove_particle_systems_from_object(Object *ob_to)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
static wmOperatorStatus particle_system_remove_all_exec(bContext *C, wmOperator *)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
int BLI_bvhtree_find_nearest(const BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata)
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
struct ParticleSystem * psys_get_current(struct Object *ob)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
static bool copy_particle_systems_poll(bContext *C)
void OBJECT_OT_particle_system_add(wmOperatorType *ot)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void BKE_object_free_particlesystems(Object *ob)
static wmOperatorStatus target_move_up_exec(bContext *C, wmOperator *)
static void copy_particle_edit(Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys, ParticleSystem *psys_from)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
@ eModifierType_ParticleSystem
@ eModifierType_DynamicPaint
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static wmOperatorStatus dupliob_move_down_exec(bContext *C, wmOperator *)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void PARTICLE_OT_connect_hair(wmOperatorType *ot)
ATTR_WARN_UNUSED_RESULT const BMVert * v
struct ParticleSystemModifierData * psys_get_modifier(struct Object *ob, struct ParticleSystem *psys)
bool ED_operator_object_active_local_editable(bContext *C)
static bool psys_poll(bContext *C)
void PARTICLE_OT_dupliob_remove(wmOperatorType *ot)
struct ParticleSettings * BKE_particlesettings_add(struct Main *bmain, const char *name)
static void disconnect_hair(Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys)
void BKE_modifiers_persistent_uid_init(const Object &object, ModifierData &md)
ViewLayer * CTX_data_view_layer(const bContext *C)
void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int useflag)
static bool duplicate_particle_systems_poll(bContext *C)
static bool remove_all_particle_systems_poll(bContext *C)
void BKE_modifier_unique_name(ListBaseT< ModifierData > *modifiers, ModifierData *md)
void mul_m4_v3(const float M[4][4], float r[3])
void PARTICLE_OT_particle_system_remove_all(wmOperatorType *ot)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
void recalc_lengths(PTCacheEdit *edit)
VecBase< int32_t, 2 > int2
void PARTICLE_OT_new(wmOperatorType *ot)
void recalc_emitter_field(Depsgraph *, Object *, ParticleSystem *psys)
static wmOperatorStatus connect_hair_exec(bContext *C, wmOperator *op)
static wmOperatorStatus new_particle_settings_exec(bContext *C, wmOperator *)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void DEG_id_tag_update(ID *id, unsigned int flags)
static wmOperatorStatus copy_particle_systems_exec(bContext *C, wmOperator *op)
void BKE_report(ReportList *reports, eReportType type, const char *message)
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
void psys_emitter_customdata_mask(struct ParticleSystem *psys, struct CustomData_MeshMasks *r_cddata_masks)
void BKE_modifiers_add_at_end_if_possible(Object *ob, ModifierData *new_md)
static wmOperatorStatus dupliob_move_up_exec(bContext *C, wmOperator *)
ModifierData * BKE_modifier_new(int type)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
static wmOperatorStatus copy_particle_dupliob_exec(bContext *C, wmOperator *)
static wmOperatorStatus remove_particle_target_exec(bContext *C, wmOperator *)
static wmOperatorStatus particle_system_remove_exec(bContext *C, wmOperator *)
void BKE_modifier_free(ModifierData *md)
void PARTICLE_OT_dupliob_move_up(wmOperatorType *ot)
void PARTICLE_OT_target_move_down(wmOperatorType *ot)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void psys_mat_hair_to_object(struct Object *ob, struct Mesh *mesh, short from, struct ParticleData *pa, float hairmat[4][4])
void PARTICLE_OT_dupliob_refresh(wmOperatorType *ot)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
void interp_weights_poly_v3(float w[], float v[][3], int n, const float co[3])
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void PARTICLE_OT_disconnect_hair(wmOperatorType *ot)
static wmOperatorStatus duplicate_particle_systems_exec(bContext *C, wmOperator *op)
void BKE_id_free(Main *bmain, void *idv)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
void PARTICLE_OT_target_remove(wmOperatorType *ot)
void PARTICLE_OT_target_move_up(wmOperatorType *ot)
static wmOperatorStatus dupliob_refresh_exec(bContext *C, wmOperator *)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
static wmOperatorStatus particle_system_add_exec(bContext *C, wmOperator *)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void PARTICLE_OT_duplicate_particle_system(wmOperatorType *ot)
void psys_mat_hair_to_global(struct Object *ob, struct Mesh *mesh, short from, struct ParticleData *pa, float hairmat[4][4])
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
static bool copy_particle_systems_to_object(const bContext *C, Scene *scene, Object *ob_from, ParticleSystem *single_psys_from, Object *ob_to, int space, bool duplicate_settings)
Main * CTX_data_main(const bContext *C)
int psys_particle_dm_face_lookup(struct Mesh *mesh_final, struct Mesh *mesh_original, int findex_orig, const float fw[4], struct LinkNode **poly_nodes)
static wmOperatorStatus new_particle_target_exec(bContext *C, wmOperator *)
void update_world_cos(Object *ob, PTCacheEdit *edit)
static wmOperatorStatus remove_particle_dupliob_exec(bContext *C, wmOperator *)
void OBJECT_OT_particle_system_remove(wmOperatorType *ot)
void BKE_mesh_tessface_ensure(Mesh *mesh)
static wmOperatorStatus target_move_down_exec(bContext *C, wmOperator *)
void DEG_relations_tag_update(Main *bmain)
Scene * CTX_data_scene(const bContext *C)
static bool connect_hair(Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys)
ParticleSystem * BKE_object_copy_particlesystem(ParticleSystem *psys, int flag)
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
VecBase< float, 3 > float3
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
void psys_check_group_weights(struct ParticleSettings *part)
void PARTICLE_OT_copy_particle_systems(wmOperatorType *ot)
ID * BKE_id_copy(Main *bmain, const ID *id)
struct ParticleSystem * psys_eval_get(struct Depsgraph *depsgraph, struct Object *object, struct ParticleSystem *psys)
void PARTICLE_OT_dupliob_copy(wmOperatorType *ot)
static bool remap_hair_emitter(Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys, Object *target_ob, ParticleSystem *target_psys, PTCacheEdit *target_edit, const float from_mat[4][4], const float to_mat[4][4], bool from_global, bool to_global)
void PARTICLE_OT_new_target(wmOperatorType *ot)
void psys_check_boid_data(struct ParticleSystem *psys)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
void PARTICLE_OT_dupliob_move_down(wmOperatorType *ot)
ParticleEditSettings * PE_settings(Scene *scene)
static wmOperatorStatus disconnect_hair_exec(bContext *C, wmOperator *op)
void psys_unique_name(struct Object *object, struct ParticleSystem *psys, const char *defname) ATTR_NONNULL(1
#define PSYS_FROM_NEXT(cur)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::MeshRuntime * runtime
struct ModifierData * next
ListBaseT< ModifierData > modifiers
ListBaseT< struct ParticleSystem > particlesystem
struct PTCacheEditKey * keys
PTCacheEditPoint * points
struct ParticleCacheKey ** pathcache
struct ParticleDupliWeight * prev
struct ParticleDupliWeight * next
eParticleDupliWeight_Flag flag
ListBaseT< ParticleDupliWeight > instance_weights
struct ParticleSystem * psys
struct Mesh * mesh_original
struct PTCacheEdit * edit
ListBaseT< ParticleTarget > targets
eParticleSystem_Flag flag
struct ParticleTarget * prev
eParticleTarget_Flag flag
struct ParticleTarget * next
BVHTree_NearestPointCallback nearest_callback
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports