2016-12-28 17:30:58 +01:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2016-12-28 17:30:58 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup edphys
|
2016-12-28 17:30:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
|
|
|
#include "BLI_listbase.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_math.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BLI_string.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-27 11:34:45 +02:00
|
|
|
#include "BKE_bvhutils.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_global.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_main.h"
|
2018-05-15 13:26:40 +02:00
|
|
|
#include "BKE_mesh.h"
|
2018-06-05 16:58:08 +02:00
|
|
|
#include "BKE_mesh_runtime.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_modifier.h"
|
|
|
|
#include "BKE_object.h"
|
|
|
|
#include "BKE_particle.h"
|
|
|
|
#include "BKE_pointcache.h"
|
|
|
|
#include "BKE_report.h"
|
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
#include "DEG_depsgraph_build.h"
|
2019-03-18 17:49:53 +01:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2017-06-08 10:14:53 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "ED_object.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "ED_particle.h"
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
2018-03-19 18:16:27 +01:00
|
|
|
#include "particle_edit_utildefines.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-03-19 18:16:27 +01:00
|
|
|
#include "physics_intern.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2019-04-18 17:17:32 +02:00
|
|
|
static float I[4][4] = {
|
|
|
|
{1.0f, 0.0f, 0.0f, 0.0f},
|
|
|
|
{0.0f, 1.0f, 0.0f, 0.0f},
|
|
|
|
{0.0f, 0.0f, 1.0f, 0.0f},
|
|
|
|
{0.0f, 0.0f, 0.0f, 1.0f},
|
|
|
|
};
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/********************** particle system slot operators *********************/
|
|
|
|
|
|
|
|
static int particle_system_add_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2018-06-13 10:57:10 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2018-08-14 10:00:15 +10:00
|
|
|
Object *ob = ED_object_context(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!scene || !ob) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-13 10:57:10 +02:00
|
|
|
object_add_particle_system(bmain, scene, ob, NULL);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, ob);
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, ob);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBJECT_OT_particle_system_add(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Add Particle System Slot";
|
|
|
|
ot->idname = "OBJECT_OT_particle_system_add";
|
|
|
|
ot->description = "Add a particle system";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
2020-07-13 14:29:04 +02:00
|
|
|
ot->poll = ED_operator_object_active_local_editable;
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->exec = particle_system_add_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2018-06-13 10:57:10 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
Object *ob = ED_object_context(C);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2017-11-23 13:51:49 -02:00
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
2018-04-05 18:20:27 +02:00
|
|
|
int mode_orig;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!scene || !ob) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-05 18:20:27 +02:00
|
|
|
mode_orig = ob->mode;
|
2021-08-24 18:38:28 +02:00
|
|
|
ParticleSystem *psys = psys_get_current(ob);
|
|
|
|
object_remove_particle_system(bmain, scene, ob, psys);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* possible this isn't the active object
|
|
|
|
* object_remove_particle_system() clears the mode on the last psys
|
|
|
|
*/
|
|
|
|
if (mode_orig & OB_MODE_PARTICLE_EDIT) {
|
2018-04-05 18:20:27 +02:00
|
|
|
if ((ob->mode & OB_MODE_PARTICLE_EDIT) == 0) {
|
2017-11-23 13:51:49 -02:00
|
|
|
if (view_layer->basact && view_layer->basact->object == ob) {
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, ob);
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBJECT_OT_particle_system_remove(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Remove Particle System Slot";
|
|
|
|
ot->idname = "OBJECT_OT_particle_system_remove";
|
|
|
|
ot->description = "Remove the selected particle system";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
2020-07-13 14:29:04 +02:00
|
|
|
ot->poll = ED_operator_object_active_local_editable;
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->exec = particle_system_remove_exec;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************** new particle settings operator *********************/
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool psys_poll(bContext *C)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem);
|
|
|
|
return (ptr.data != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int new_particle_settings_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSystem *psys;
|
|
|
|
ParticleSettings *part = NULL;
|
|
|
|
Object *ob;
|
|
|
|
PointerRNA ptr;
|
|
|
|
|
|
|
|
ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem);
|
|
|
|
|
|
|
|
psys = ptr.data;
|
|
|
|
|
|
|
|
/* add or copy particle setting */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (psys->part) {
|
2020-10-07 18:01:25 +02:00
|
|
|
part = (ParticleSettings *)BKE_id_copy(bmain, &psys->part->id);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2018-08-14 10:00:15 +10:00
|
|
|
part = BKE_particlesettings_add(bmain, "ParticleSettings");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2019-08-23 09:52:12 +02:00
|
|
|
ob = (Object *)ptr.owner_id;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (psys->part) {
|
2016-12-28 17:30:58 +01:00
|
|
|
id_us_min(&psys->part->id);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
psys->part = part;
|
|
|
|
|
|
|
|
psys_check_boid_data(psys);
|
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, ob);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_new(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "New Particle Settings";
|
|
|
|
ot->idname = "PARTICLE_OT_new";
|
|
|
|
ot->description = "Add new particle settings";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = new_particle_settings_exec;
|
|
|
|
ot->poll = psys_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************** keyed particle target operators *********************/
|
|
|
|
|
|
|
|
static int new_particle_target_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem);
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleSystem *psys = ptr.data;
|
2019-08-23 09:52:12 +02:00
|
|
|
Object *ob = (Object *)ptr.owner_id;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
ParticleTarget *pt;
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!psys) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
pt = psys->targets.first;
|
2019-04-22 09:19:45 +10:00
|
|
|
for (; pt; pt = pt->next) {
|
2016-12-28 17:30:58 +01:00
|
|
|
pt->flag &= ~PTARGET_CURRENT;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
pt = MEM_callocN(sizeof(ParticleTarget), "keyed particle target");
|
|
|
|
|
|
|
|
pt->flag |= PTARGET_CURRENT;
|
|
|
|
pt->psys = 1;
|
|
|
|
|
|
|
|
BLI_addtail(&psys->targets, pt);
|
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, ob);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_new_target(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "New Particle Target";
|
|
|
|
ot->idname = "PARTICLE_OT_new_target";
|
|
|
|
ot->description = "Add a new particle target";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = new_particle_target_exec;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int remove_particle_target_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem);
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleSystem *psys = ptr.data;
|
2019-08-23 09:52:12 +02:00
|
|
|
Object *ob = (Object *)ptr.owner_id;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
ParticleTarget *pt;
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!psys) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
pt = psys->targets.first;
|
2018-08-14 10:00:15 +10:00
|
|
|
for (; pt; pt = pt->next) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (pt->flag & PTARGET_CURRENT) {
|
|
|
|
BLI_remlink(&psys->targets, pt);
|
|
|
|
MEM_freeN(pt);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
pt = psys->targets.last;
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (pt) {
|
2016-12-28 17:30:58 +01:00
|
|
|
pt->flag |= PTARGET_CURRENT;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, ob);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_target_remove(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Remove Particle Target";
|
|
|
|
ot->idname = "PARTICLE_OT_target_remove";
|
|
|
|
ot->description = "Remove the selected particle target";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = remove_particle_target_exec;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ move up particle target operator *********************/
|
|
|
|
|
|
|
|
static int target_move_up_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem);
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleSystem *psys = ptr.data;
|
2019-08-23 09:52:12 +02:00
|
|
|
Object *ob = (Object *)ptr.owner_id;
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleTarget *pt;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!psys) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
pt = psys->targets.first;
|
2018-08-14 10:00:15 +10:00
|
|
|
for (; pt; pt = pt->next) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (pt->flag & PTARGET_CURRENT && pt->prev) {
|
|
|
|
BLI_remlink(&psys->targets, pt);
|
|
|
|
BLI_insertlinkbefore(&psys->targets, pt->prev, pt);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_target_move_up(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
ot->name = "Move Up Target";
|
|
|
|
ot->idname = "PARTICLE_OT_target_move_up";
|
|
|
|
ot->description = "Move particle target up in the list";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->exec = target_move_up_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ move down particle target operator *********************/
|
|
|
|
|
|
|
|
static int target_move_down_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem);
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleSystem *psys = ptr.data;
|
2019-08-23 09:52:12 +02:00
|
|
|
Object *ob = (Object *)ptr.owner_id;
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleTarget *pt;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!psys) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
pt = psys->targets.first;
|
2018-08-14 10:00:15 +10:00
|
|
|
for (; pt; pt = pt->next) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (pt->flag & PTARGET_CURRENT && pt->next) {
|
|
|
|
BLI_remlink(&psys->targets, pt);
|
|
|
|
BLI_insertlinkafter(&psys->targets, pt->next, pt);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_target_move_down(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
ot->name = "Move Down Target";
|
|
|
|
ot->idname = "PARTICLE_OT_target_move_down";
|
|
|
|
ot->description = "Move particle target down in the list";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->exec = target_move_down_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
2018-06-28 14:29:54 +02:00
|
|
|
/************************ refresh dupli objects *********************/
|
|
|
|
|
|
|
|
static int dupliob_refresh_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem);
|
2018-08-14 10:02:43 +10:00
|
|
|
ParticleSystem *psys = ptr.data;
|
2018-06-28 14:29:54 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!psys) {
|
2018-06-28 14:29:54 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-28 14:29:54 +02:00
|
|
|
|
|
|
|
psys_check_group_weights(psys->part);
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&psys->part->id, ID_RECALC_GEOMETRY | ID_RECALC_PSYS_REDO);
|
2018-08-14 10:02:43 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, NULL);
|
2018-06-28 14:29:54 +02:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_dupliob_refresh(wmOperatorType *ot)
|
|
|
|
{
|
2021-02-24 13:49:14 -06:00
|
|
|
ot->name = "Refresh Instance Objects";
|
2018-06-28 14:29:54 +02:00
|
|
|
ot->idname = "PARTICLE_OT_dupliob_refresh";
|
2021-02-24 13:49:14 -06:00
|
|
|
ot->description = "Refresh list of instance objects and their weights";
|
2018-06-28 14:29:54 +02:00
|
|
|
|
|
|
|
ot->exec = dupliob_refresh_exec;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:02:43 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-28 14:29:54 +02:00
|
|
|
}
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/************************ move up particle dupliweight operator *********************/
|
|
|
|
|
|
|
|
static int dupliob_move_up_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem);
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleSystem *psys = ptr.data;
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSettings *part;
|
|
|
|
ParticleDupliWeight *dw;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!psys) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
part = psys->part;
|
2019-02-17 19:00:54 +11:00
|
|
|
for (dw = part->instance_weights.first; dw; dw = dw->next) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (dw->flag & PART_DUPLIW_CURRENT && dw->prev) {
|
2019-02-17 19:00:54 +11:00
|
|
|
BLI_remlink(&part->instance_weights, dw);
|
|
|
|
BLI_insertlinkbefore(&part->instance_weights, dw->prev, dw);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&part->id, ID_RECALC_GEOMETRY | ID_RECALC_PSYS_REDO);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_dupliob_move_up(wmOperatorType *ot)
|
|
|
|
{
|
2021-02-24 13:49:14 -06:00
|
|
|
ot->name = "Move Up Instance Object";
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->idname = "PARTICLE_OT_dupliob_move_up";
|
2021-02-24 13:49:14 -06:00
|
|
|
ot->description = "Move instance object up in the list";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->exec = dupliob_move_up_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************** particle dupliweight operators *********************/
|
|
|
|
|
|
|
|
static int copy_particle_dupliob_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem);
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleSystem *psys = ptr.data;
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSettings *part;
|
|
|
|
ParticleDupliWeight *dw;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!psys) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
part = psys->part;
|
2019-02-17 19:00:54 +11:00
|
|
|
for (dw = part->instance_weights.first; dw; dw = dw->next) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (dw->flag & PART_DUPLIW_CURRENT) {
|
|
|
|
dw->flag &= ~PART_DUPLIW_CURRENT;
|
|
|
|
dw = MEM_dupallocN(dw);
|
|
|
|
dw->flag |= PART_DUPLIW_CURRENT;
|
2019-02-17 19:00:54 +11:00
|
|
|
BLI_addhead(&part->instance_weights, dw);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&part->id, ID_RECALC_GEOMETRY | ID_RECALC_PSYS_REDO);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_dupliob_copy(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2021-02-24 13:49:14 -06:00
|
|
|
ot->name = "Copy Particle Instance Object";
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->idname = "PARTICLE_OT_dupliob_copy";
|
2021-02-24 13:49:14 -06:00
|
|
|
ot->description = "Duplicate the current instance object";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = copy_particle_dupliob_exec;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int remove_particle_dupliob_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem);
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleSystem *psys = ptr.data;
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSettings *part;
|
|
|
|
ParticleDupliWeight *dw;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!psys) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
part = psys->part;
|
2019-02-17 19:00:54 +11:00
|
|
|
for (dw = part->instance_weights.first; dw; dw = dw->next) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (dw->flag & PART_DUPLIW_CURRENT) {
|
2019-02-17 19:00:54 +11:00
|
|
|
BLI_remlink(&part->instance_weights, dw);
|
2016-12-28 17:30:58 +01:00
|
|
|
MEM_freeN(dw);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-02-17 19:00:54 +11:00
|
|
|
dw = part->instance_weights.last;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (dw) {
|
2016-12-28 17:30:58 +01:00
|
|
|
dw->flag |= PART_DUPLIW_CURRENT;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&part->id, ID_RECALC_GEOMETRY | ID_RECALC_PSYS_REDO);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_dupliob_remove(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2021-02-24 13:49:14 -06:00
|
|
|
ot->name = "Remove Particle Instance Object";
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->idname = "PARTICLE_OT_dupliob_remove";
|
2021-02-24 13:49:14 -06:00
|
|
|
ot->description = "Remove the selected instance object";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = remove_particle_dupliob_exec;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ move down particle dupliweight operator *********************/
|
|
|
|
|
|
|
|
static int dupliob_move_down_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem);
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleSystem *psys = ptr.data;
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSettings *part;
|
|
|
|
ParticleDupliWeight *dw;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!psys) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
part = psys->part;
|
2019-02-17 19:00:54 +11:00
|
|
|
for (dw = part->instance_weights.first; dw; dw = dw->next) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (dw->flag & PART_DUPLIW_CURRENT && dw->next) {
|
2019-02-17 19:00:54 +11:00
|
|
|
BLI_remlink(&part->instance_weights, dw);
|
|
|
|
BLI_insertlinkafter(&part->instance_weights, dw->next, dw);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&part->id, ID_RECALC_GEOMETRY | ID_RECALC_PSYS_REDO);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_dupliob_move_down(wmOperatorType *ot)
|
|
|
|
{
|
2021-02-24 13:49:14 -06:00
|
|
|
ot->name = "Move Down Instance Object";
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->idname = "PARTICLE_OT_dupliob_move_down";
|
2021-02-24 13:49:14 -06:00
|
|
|
ot->description = "Move instance object down in the list";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->exec = dupliob_move_down_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ connect/disconnect hair operators *********************/
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
static void disconnect_hair(Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2019-03-18 17:49:53 +01:00
|
|
|
Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
|
|
|
|
ParticleSystem *psys_eval = psys_eval_get(depsgraph, ob, psys);
|
|
|
|
ParticleSystemModifierData *psmd_eval = psys_get_modifier(object_eval, psys_eval);
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleData *pa;
|
|
|
|
PTCacheEdit *edit;
|
|
|
|
PTCacheEditPoint *point;
|
|
|
|
PTCacheEditKey *ekey = NULL;
|
|
|
|
HairKey *key;
|
|
|
|
int i, k;
|
|
|
|
float hairmat[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!ob || !psys || psys->flag & PSYS_GLOBAL_HAIR) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!psys->part || psys->part->type != PART_HAIR) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
edit = psys->edit;
|
2018-08-14 10:00:15 +10:00
|
|
|
point = edit ? edit->points : NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (i = 0, pa = psys->particles; i < psys->totpart; i++, pa++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (point) {
|
|
|
|
ekey = point->keys;
|
|
|
|
point++;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-06-21 11:49:43 +02:00
|
|
|
psys_mat_hair_to_global(ob, psmd_eval->mesh_final, psys->part->from, pa, hairmat);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 0, key = pa->hair; k < pa->totkey; k++, key++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_m4_v3(hairmat, key->co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (ekey) {
|
|
|
|
ekey->flag &= ~PEK_USE_WCO;
|
|
|
|
ekey++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
psys_free_path_cache(psys, psys->edit);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
psys->flag |= PSYS_GLOBAL_HAIR;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-07 00:07:23 +11:00
|
|
|
if (ELEM(pset->brushtype, PE_BRUSH_ADD, PE_BRUSH_PUFF)) {
|
|
|
|
pset->brushtype = PE_BRUSH_COMB;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_object(depsgraph, scene, ob, 0);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int disconnect_hair_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-07-25 16:36:22 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = ED_object_context(C);
|
|
|
|
ParticleSystem *psys = NULL;
|
2016-12-28 17:30:58 +01:00
|
|
|
const bool all = RNA_boolean_get(op->ptr, "all");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!ob) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (all) {
|
2018-08-14 10:00:15 +10:00
|
|
|
for (psys = ob->particlesystem.first; psys; psys = psys->next) {
|
2018-04-06 12:07:27 +02:00
|
|
|
disconnect_hair(depsgraph, scene, ob, psys);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
psys = psys_get_current(ob);
|
2018-04-06 12:07:27 +02:00
|
|
|
disconnect_hair(depsgraph, scene, ob, psys);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_disconnect_hair(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
ot->name = "Disconnect Hair";
|
|
|
|
ot->description = "Disconnect hair from the emitter mesh";
|
|
|
|
ot->idname = "PARTICLE_OT_disconnect_hair";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->exec = disconnect_hair_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* flags */
|
2019-01-15 23:24:20 +11:00
|
|
|
/* No REGISTER, redo does not work due to missing update, see T47750. */
|
|
|
|
ot->flag = OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
RNA_def_boolean(
|
2020-10-24 11:42:17 -07:00
|
|
|
ot->srna, "all", 0, "All Hair", "Disconnect all hair systems from the emitter mesh");
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
*/
|
2017-08-16 12:45:11 +10:00
|
|
|
static bool remap_hair_emitter(Depsgraph *depsgraph,
|
2018-04-06 12:07:27 +02:00
|
|
|
Scene *scene,
|
|
|
|
Object *ob,
|
|
|
|
ParticleSystem *psys,
|
2017-08-16 12:45:11 +10:00
|
|
|
Object *target_ob,
|
|
|
|
ParticleSystem *target_psys,
|
|
|
|
PTCacheEdit *target_edit,
|
2019-09-14 08:10:50 +10:00
|
|
|
const float from_mat[4][4],
|
|
|
|
const float to_mat[4][4],
|
2017-08-16 12:45:11 +10:00
|
|
|
bool from_global,
|
|
|
|
bool to_global)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2019-03-18 17:49:53 +01:00
|
|
|
Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
|
|
|
|
ParticleSystem *psys_eval = psys_eval_get(depsgraph, ob, psys);
|
|
|
|
ParticleSystemModifierData *target_psmd = psys_get_modifier(object_eval, psys_eval);
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleData *pa, *tpa;
|
|
|
|
PTCacheEditPoint *edit_point;
|
|
|
|
PTCacheEditKey *ekey;
|
2018-08-14 10:00:15 +10:00
|
|
|
BVHTreeFromMesh bvhtree = {NULL};
|
2016-12-28 17:30:58 +01:00
|
|
|
MFace *mface = NULL, *mf;
|
|
|
|
MEdge *medge = NULL, *me;
|
|
|
|
MVert *mvert;
|
2018-05-15 13:26:40 +02:00
|
|
|
Mesh *mesh, *target_mesh;
|
2016-12-28 17:30:58 +01:00
|
|
|
int numverts;
|
2020-09-09 18:41:07 +02:00
|
|
|
int k;
|
2016-12-28 17:30:58 +01:00
|
|
|
float from_ob_imat[4][4], to_ob_imat[4][4];
|
|
|
|
float from_imat[4][4], to_imat[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-06-21 11:49:43 +02:00
|
|
|
if (!target_psmd->mesh_final) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (!psys->part || psys->part->type != PART_HAIR) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (!target_psys->part || target_psys->part->type != PART_HAIR) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
edit_point = target_edit ? target_edit->points : NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
invert_m4_m4(from_ob_imat, ob->obmat);
|
|
|
|
invert_m4_m4(to_ob_imat, target_ob->obmat);
|
|
|
|
invert_m4_m4(from_imat, from_mat);
|
|
|
|
invert_m4_m4(to_imat, to_mat);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-05 16:36:34 +01:00
|
|
|
const bool use_dm_final_indices = (target_psys->part->use_modifier_stack &&
|
|
|
|
!target_psmd->mesh_final->runtime.deformed_only);
|
|
|
|
|
|
|
|
if (use_dm_final_indices) {
|
2019-06-21 11:49:43 +02:00
|
|
|
mesh = target_psmd->mesh_final;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-06-21 11:49:43 +02:00
|
|
|
mesh = target_psmd->mesh_original;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-06-21 11:49:43 +02:00
|
|
|
target_mesh = target_psmd->mesh_final;
|
2018-05-15 13:26:40 +02:00
|
|
|
if (mesh == NULL) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/* don't modify the original vertices */
|
2022-01-05 16:36:34 +01:00
|
|
|
/* we don't want to mess up target_psmd->dm when converting to global coordinates below */
|
2020-10-07 14:27:33 +02:00
|
|
|
mesh = (Mesh *)BKE_id_copy_ex(NULL, &mesh->id, NULL, LIB_ID_COPY_LOCALIZE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* BMESH_ONLY, deform dm may not have tessface */
|
2018-05-15 13:26:40 +02:00
|
|
|
BKE_mesh_tessface_ensure(mesh);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
numverts = mesh->totvert;
|
|
|
|
mvert = mesh->mvert;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* convert to global coordinates */
|
2020-09-09 18:41:07 +02:00
|
|
|
for (int i = 0; i < numverts; i++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_m4_v3(to_mat, mvert[i].co);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
if (mesh->totface != 0) {
|
|
|
|
mface = mesh->mface;
|
|
|
|
BKE_bvhtree_from_mesh_get(&bvhtree, mesh, BVHTREE_FROM_FACES, 2);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2018-05-15 13:26:40 +02:00
|
|
|
else if (mesh->totedge != 0) {
|
|
|
|
medge = mesh->medge;
|
|
|
|
BKE_bvhtree_from_mesh_get(&bvhtree, mesh, BVHTREE_FROM_EDGES, 2);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-05-15 13:26:40 +02:00
|
|
|
BKE_id_free(NULL, mesh);
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-09 18:41:07 +02:00
|
|
|
int i;
|
2016-12-28 17:30:58 +01:00
|
|
|
for (i = 0, tpa = target_psys->particles, pa = psys->particles; i < target_psys->totpart;
|
2018-04-16 18:13:48 +02:00
|
|
|
i++, tpa++, pa++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
float from_co[3];
|
|
|
|
BVHTreeNearest nearest;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (from_global) {
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_v3_m4v3(from_co, from_ob_imat, pa->hair[0].co);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_v3_m4v3(from_co, from_ob_imat, pa->hair[0].world_co);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_m4_v3(from_mat, from_co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
nearest.index = -1;
|
|
|
|
nearest.dist_sq = FLT_MAX;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
BLI_bvhtree_find_nearest(bvhtree.tree, from_co, &nearest, bvhtree.nearest_callback, &bvhtree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (nearest.index == -1) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (G.debug & G_DEBUG) {
|
2016-12-28 17:30:58 +01:00
|
|
|
printf("No nearest point found for hair root!");
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
continue;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (mface) {
|
|
|
|
float v[4][3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
mf = &mface[nearest.index];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v3_v3(v[0], mvert[mf->v1].co);
|
|
|
|
copy_v3_v3(v[1], mvert[mf->v2].co);
|
|
|
|
copy_v3_v3(v[2], mvert[mf->v3].co);
|
|
|
|
if (mf->v4) {
|
|
|
|
copy_v3_v3(v[3], mvert[mf->v4].co);
|
|
|
|
interp_weights_poly_v3(tpa->fuv, v, 4, nearest.co);
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
else {
|
2016-12-28 17:30:58 +01:00
|
|
|
interp_weights_poly_v3(tpa->fuv, v, 3, nearest.co);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
tpa->foffset = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
tpa->num = nearest.index;
|
2022-01-05 16:36:34 +01:00
|
|
|
if (use_dm_final_indices) {
|
|
|
|
tpa->num_dmcache = DMCACHE_ISCHILD;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tpa->num_dmcache = psys_particle_dm_face_lookup(
|
|
|
|
target_psmd->mesh_final, target_psmd->mesh_original, tpa->num, tpa->fuv, NULL);
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
me = &medge[nearest.index];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
tpa->fuv[1] = line_point_factor_v3(nearest.co, mvert[me->v1].co, mvert[me->v2].co);
|
|
|
|
tpa->fuv[0] = 1.0f - tpa->fuv[1];
|
|
|
|
tpa->fuv[2] = tpa->fuv[3] = 0.0f;
|
|
|
|
tpa->foffset = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
tpa->num = nearest.index;
|
|
|
|
tpa->num_dmcache = -1;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* translate hair keys */
|
|
|
|
{
|
|
|
|
HairKey *key, *tkey;
|
|
|
|
float hairmat[4][4], imat[4][4];
|
|
|
|
float offset[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (to_global) {
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_m4_m4(imat, target_ob->obmat);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
else {
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE: using target_dm here, which is in target_ob object space and has full modifiers.
|
|
|
|
*/
|
2018-05-15 13:26:40 +02:00
|
|
|
psys_mat_hair_to_object(target_ob, target_mesh, target_psys->part->from, tpa, hairmat);
|
2016-12-28 17:30:58 +01:00
|
|
|
invert_m4_m4(imat, hairmat);
|
|
|
|
}
|
|
|
|
mul_m4_m4m4(imat, imat, to_imat);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* offset in world space */
|
|
|
|
sub_v3_v3v3(offset, nearest.co, from_co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (edit_point) {
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 0, key = pa->hair, tkey = tpa->hair, ekey = edit_point->keys; k < tpa->totkey;
|
|
|
|
k++, key++, tkey++, ekey++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
float co_orig[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (from_global) {
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_v3_m4v3(co_orig, from_ob_imat, key->co);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_v3_m4v3(co_orig, from_ob_imat, key->world_co);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_m4_v3(from_mat, co_orig);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
add_v3_v3v3(tkey->co, co_orig, offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_m4_v3(imat, tkey->co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
ekey->flag |= PEK_USE_WCO;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
edit_point++;
|
|
|
|
}
|
|
|
|
else {
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 0, key = pa->hair, tkey = tpa->hair; k < tpa->totkey; k++, key++, tkey++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
float co_orig[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (from_global) {
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_v3_m4v3(co_orig, from_ob_imat, key->co);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_v3_m4v3(co_orig, from_ob_imat, key->world_co);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_m4_v3(from_mat, co_orig);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
add_v3_v3v3(tkey->co, co_orig, offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_m4_v3(imat, tkey->co);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
free_bvhtree_from_mesh(&bvhtree);
|
2018-05-15 13:26:40 +02:00
|
|
|
BKE_id_free(NULL, mesh);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
psys_free_path_cache(target_psys, target_edit);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_object(depsgraph, scene, target_ob, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
static bool connect_hair(Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
bool ok;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!psys) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-16 12:45:11 +10:00
|
|
|
ok = remap_hair_emitter(depsgraph,
|
2018-04-06 12:07:27 +02:00
|
|
|
scene,
|
|
|
|
ob,
|
|
|
|
psys,
|
|
|
|
ob,
|
|
|
|
psys,
|
|
|
|
psys->edit,
|
2017-08-16 12:45:11 +10:00
|
|
|
ob->obmat,
|
|
|
|
ob->obmat,
|
|
|
|
psys->flag & PSYS_GLOBAL_HAIR,
|
|
|
|
false);
|
2016-12-28 17:30:58 +01:00
|
|
|
psys->flag &= ~PSYS_GLOBAL_HAIR;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int connect_hair_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-07-25 16:36:22 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = ED_object_context(C);
|
|
|
|
ParticleSystem *psys = NULL;
|
2016-12-28 17:30:58 +01:00
|
|
|
const bool all = RNA_boolean_get(op->ptr, "all");
|
|
|
|
bool any_connected = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!ob) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (all) {
|
2018-08-14 10:00:15 +10:00
|
|
|
for (psys = ob->particlesystem.first; psys; psys = psys->next) {
|
2018-04-06 12:07:27 +02:00
|
|
|
any_connected |= connect_hair(depsgraph, scene, ob, psys);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
psys = psys_get_current(ob);
|
2018-04-06 12:07:27 +02:00
|
|
|
any_connected |= connect_hair(depsgraph, scene, ob, psys);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (!any_connected) {
|
|
|
|
BKE_report(op->reports,
|
|
|
|
RPT_WARNING,
|
|
|
|
"No hair connected (can't connect hair if particle system modifier is disabled)");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE, ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_connect_hair(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
ot->name = "Connect Hair";
|
|
|
|
ot->description = "Connect hair to the emitter mesh";
|
|
|
|
ot->idname = "PARTICLE_OT_connect_hair";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->exec = connect_hair_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* flags */
|
2019-01-15 23:24:20 +11:00
|
|
|
/* No REGISTER, redo does not work due to missing update, see T47750. */
|
|
|
|
ot->flag = OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2020-10-24 11:42:17 -07:00
|
|
|
RNA_def_boolean(ot->srna, "all", 0, "All Hair", "Connect all hair systems to the emitter mesh");
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ particle system copy operator *********************/
|
|
|
|
|
|
|
|
typedef enum eCopyParticlesSpace {
|
|
|
|
PAR_COPY_SPACE_OBJECT = 0,
|
|
|
|
PAR_COPY_SPACE_WORLD = 1,
|
|
|
|
} eCopyParticlesSpace;
|
|
|
|
|
2017-08-16 12:45:11 +10:00
|
|
|
static void copy_particle_edit(Depsgraph *depsgraph,
|
2018-04-06 12:07:27 +02:00
|
|
|
Scene *scene,
|
2017-08-16 12:45:11 +10:00
|
|
|
Object *ob,
|
|
|
|
ParticleSystem *psys,
|
|
|
|
ParticleSystem *psys_from)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
PTCacheEdit *edit_from = psys_from->edit, *edit;
|
|
|
|
ParticleData *pa;
|
|
|
|
KEY_K;
|
|
|
|
POINT_P;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!edit_from) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
edit = MEM_dupallocN(edit_from);
|
|
|
|
edit->psys = psys;
|
|
|
|
psys->edit = edit;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
edit->pathcache = NULL;
|
|
|
|
BLI_listbase_clear(&edit->pathcachebufs);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
edit->emitter_field = NULL;
|
|
|
|
edit->emitter_cosnos = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
edit->points = MEM_dupallocN(edit_from->points);
|
|
|
|
pa = psys->particles;
|
2019-09-26 16:31:42 +02:00
|
|
|
LOOP_POINTS {
|
2016-12-28 17:30:58 +01:00
|
|
|
HairKey *hkey = pa->hair;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
point->keys = MEM_dupallocN(point->keys);
|
2019-09-26 16:31:42 +02:00
|
|
|
LOOP_KEYS {
|
2016-12-28 17:30:58 +01:00
|
|
|
key->co = hkey->co;
|
|
|
|
key->time = &hkey->time;
|
|
|
|
key->flag = hkey->editflag;
|
|
|
|
if (!(psys->flag & PSYS_GLOBAL_HAIR)) {
|
|
|
|
key->flag |= PEK_USE_WCO;
|
|
|
|
hkey->editflag |= PEK_USE_WCO;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
hkey++;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
pa++;
|
|
|
|
}
|
2019-07-31 11:50:42 +02:00
|
|
|
update_world_cos(ob, edit);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
recalc_lengths(edit);
|
2018-05-15 16:15:13 +02:00
|
|
|
recalc_emitter_field(depsgraph, ob, psys);
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_object(depsgraph, scene, ob, true);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_particle_systems_from_object(Object *ob_to)
|
|
|
|
{
|
|
|
|
ModifierData *md, *md_next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ob_to->type != OB_MESH) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (!ob_to->data || ID_IS_LINKED(ob_to->data)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
for (md = ob_to->modifiers.first; md; md = md_next) {
|
|
|
|
md_next = md->next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* remove all particle system modifiers as well,
|
|
|
|
* these need to sync to the particle system list
|
|
|
|
*/
|
|
|
|
if (ELEM(md->type,
|
|
|
|
eModifierType_ParticleSystem,
|
|
|
|
eModifierType_DynamicPaint,
|
2019-12-16 15:50:14 +01:00
|
|
|
eModifierType_Fluid)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
BLI_remlink(&ob_to->modifiers, md);
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_free(md);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
BKE_object_free_particlesystems(ob_to);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* single_psys_from is optional, if NULL all psys of ob_from are copied */
|
2017-07-21 11:53:13 +02:00
|
|
|
static bool copy_particle_systems_to_object(const bContext *C,
|
2016-12-28 17:30:58 +01:00
|
|
|
Scene *scene,
|
|
|
|
Object *ob_from,
|
|
|
|
ParticleSystem *single_psys_from,
|
|
|
|
Object *ob_to,
|
|
|
|
int space,
|
|
|
|
bool duplicate_settings)
|
|
|
|
{
|
2017-07-21 11:53:13 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2019-07-25 16:36:22 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
ModifierData *md;
|
|
|
|
ParticleSystem *psys_start = NULL, *psys, *psys_from;
|
|
|
|
ParticleSystem **tmp_psys;
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
CustomData_MeshMasks cdmask = {0};
|
2016-12-28 17:30:58 +01:00
|
|
|
int i, totpsys;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ob_to->type != OB_MESH) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (!ob_to->data || ID_IS_LINKED(ob_to->data)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* For remapping we need a valid DM.
|
2019-04-18 07:21:26 +02:00
|
|
|
* Because the modifiers are appended at the end it's safe to use
|
|
|
|
* the final DM of the object without particles.
|
|
|
|
* However, when evaluating the DM all the particle modifiers must be valid,
|
|
|
|
* i.e. have the psys assigned already.
|
2019-04-22 00:18:34 +10:00
|
|
|
*
|
|
|
|
* To break this hen/egg problem we create all psys separately first
|
|
|
|
* (to collect required customdata masks),
|
|
|
|
* then create the DM, then add them to the object and make the psys modifiers.
|
2019-04-18 07:21:26 +02:00
|
|
|
*/
|
2016-12-28 17:30:58 +01:00
|
|
|
#define PSYS_FROM_FIRST (single_psys_from ? single_psys_from : ob_from->particlesystem.first)
|
|
|
|
#define PSYS_FROM_NEXT(cur) (single_psys_from ? NULL : (cur)->next)
|
|
|
|
totpsys = single_psys_from ? 1 : BLI_listbase_count(&ob_from->particlesystem);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
tmp_psys = MEM_mallocN(sizeof(ParticleSystem *) * totpsys, "temporary particle system array");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-09-08 00:12:26 +10:00
|
|
|
for (psys_from = PSYS_FROM_FIRST, i = 0; psys_from; psys_from = PSYS_FROM_NEXT(psys_from), i++) {
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
psys = BKE_object_copy_particlesystem(psys_from, 0);
|
2016-12-28 17:30:58 +01:00
|
|
|
tmp_psys[i] = psys;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (psys_start == NULL) {
|
2016-12-28 17:30:58 +01:00
|
|
|
psys_start = psys;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
psys_emitter_customdata_mask(psys, &cdmask);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
/* to iterate source and target psys in sync,
|
|
|
|
* we need to know where the newly added psys start
|
|
|
|
*/
|
|
|
|
psys_start = totpsys > 0 ? tmp_psys[0] : NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* now append psys to the object and make modifiers */
|
|
|
|
for (i = 0, psys_from = PSYS_FROM_FIRST; i < totpsys;
|
2018-04-16 18:13:48 +02:00
|
|
|
++i, psys_from = PSYS_FROM_NEXT(psys_from)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSystemModifierData *psmd;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
psys = tmp_psys[i];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* append to the object */
|
|
|
|
BLI_addtail(&ob_to->particlesystem, psys);
|
2019-08-30 12:35:09 +02:00
|
|
|
psys_unique_name(ob_to, psys, psys->name);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* add a particle system modifier for each system */
|
2020-05-08 10:14:02 +02:00
|
|
|
md = BKE_modifier_new(eModifierType_ParticleSystem);
|
2016-12-28 17:30:58 +01:00
|
|
|
psmd = (ParticleSystemModifierData *)md;
|
|
|
|
/* push on top of the stack, no use trying to reproduce old stack order */
|
|
|
|
BLI_addtail(&ob_to->modifiers, md);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
BLI_snprintf(md->name, sizeof(md->name), "ParticleSystem %i", i);
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_unique_name(&ob_to->modifiers, (ModifierData *)psmd);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
psmd->psys = psys;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-08-16 12:45:11 +10:00
|
|
|
if (psys_from->edit) {
|
2018-04-06 12:07:27 +02:00
|
|
|
copy_particle_edit(depsgraph, scene, ob_to, psys, psys_from);
|
2017-08-16 12:45:11 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (duplicate_settings) {
|
|
|
|
id_us_min(&psys->part->id);
|
2020-10-07 18:01:25 +02:00
|
|
|
psys->part = (ParticleSettings *)BKE_id_copy(bmain, &psys->part->id);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
MEM_freeN(tmp_psys);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE: do this after creating DM copies for all the particle system modifiers,
|
2016-12-28 17:30:58 +01:00
|
|
|
* the remapping otherwise makes final_dm invalid!
|
|
|
|
*/
|
|
|
|
for (psys = psys_start, psys_from = PSYS_FROM_FIRST, i = 0; psys;
|
2019-09-08 00:12:26 +10:00
|
|
|
psys = psys->next, psys_from = PSYS_FROM_NEXT(psys_from), i++) {
|
2018-08-14 10:00:15 +10:00
|
|
|
float(*from_mat)[4], (*to_mat)[4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
switch (space) {
|
|
|
|
case PAR_COPY_SPACE_OBJECT:
|
|
|
|
from_mat = I;
|
|
|
|
to_mat = I;
|
|
|
|
break;
|
|
|
|
case PAR_COPY_SPACE_WORLD:
|
|
|
|
from_mat = ob_from->obmat;
|
|
|
|
to_mat = ob_to->obmat;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* should not happen */
|
|
|
|
from_mat = to_mat = NULL;
|
|
|
|
BLI_assert(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ob_from != ob_to) {
|
2017-08-16 12:45:11 +10:00
|
|
|
remap_hair_emitter(depsgraph,
|
2018-04-06 12:07:27 +02:00
|
|
|
scene,
|
|
|
|
ob_from,
|
|
|
|
psys_from,
|
|
|
|
ob_to,
|
|
|
|
psys,
|
|
|
|
psys->edit,
|
2017-08-16 12:45:11 +10:00
|
|
|
from_mat,
|
|
|
|
to_mat,
|
|
|
|
psys_from->flag & PSYS_GLOBAL_HAIR,
|
|
|
|
psys->flag & PSYS_GLOBAL_HAIR);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* tag for recalc */
|
2018-12-06 17:52:37 +01:00
|
|
|
// psys->recalc |= ID_RECALC_PSYS_RESET;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
#undef PSYS_FROM_FIRST
|
|
|
|
#undef PSYS_FROM_NEXT
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-10 22:39:28 +01:00
|
|
|
if (duplicate_settings) {
|
|
|
|
DEG_relations_tag_update(bmain);
|
|
|
|
}
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob_to->id, ID_RECALC_GEOMETRY);
|
2016-12-28 17:30:58 +01:00
|
|
|
WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, ob_to);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool copy_particle_systems_poll(bContext *C)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
Object *ob;
|
2020-07-13 14:29:04 +02:00
|
|
|
if (!ED_operator_object_active_local_editable(C)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
ob = ED_object_active_context(C);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (BLI_listbase_is_empty(&ob->particlesystem)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int copy_particle_systems_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
const int space = RNA_enum_get(op->ptr, "space");
|
|
|
|
const bool remove_target_particles = RNA_boolean_get(op->ptr, "remove_target_particles");
|
|
|
|
const bool use_active = RNA_boolean_get(op->ptr, "use_active");
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob_from = ED_object_active_context(C);
|
2021-10-26 09:55:50 +02:00
|
|
|
|
|
|
|
ParticleSystem *psys_from = NULL;
|
|
|
|
if (use_active) {
|
|
|
|
psys_from = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem).data;
|
|
|
|
if (psys_from == NULL) {
|
|
|
|
/* Particle System context pointer is only valid in the Properties Editor. */
|
|
|
|
psys_from = psys_get_current(ob_from);
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
int changed_tot = 0;
|
|
|
|
int fail = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
CTX_DATA_BEGIN (C, Object *, ob_to, selected_editable_objects) {
|
|
|
|
if (ob_from != ob_to) {
|
|
|
|
bool changed = false;
|
|
|
|
if (remove_target_particles) {
|
|
|
|
remove_particle_systems_from_object(ob_to);
|
|
|
|
changed = true;
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
if (copy_particle_systems_to_object(C, scene, ob_from, psys_from, ob_to, space, false)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
changed = true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2016-12-28 17:30:58 +01:00
|
|
|
fail++;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (changed) {
|
2016-12-28 17:30:58 +01:00
|
|
|
changed_tot++;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-01-21 15:30:07 +01:00
|
|
|
if (changed_tot > 0) {
|
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
|
|
|
|
DEG_graph_tag_relations_update(depsgraph);
|
|
|
|
}
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if ((changed_tot == 0 && fail == 0) || fail) {
|
|
|
|
BKE_reportf(op->reports,
|
|
|
|
RPT_ERROR,
|
|
|
|
"Copy particle systems to selected: %d done, %d failed",
|
|
|
|
changed_tot,
|
|
|
|
fail);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_copy_particle_systems(wmOperatorType *ot)
|
|
|
|
{
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem space_items[] = {
|
2016-12-28 17:30:58 +01:00
|
|
|
{PAR_COPY_SPACE_OBJECT, "OBJECT", 0, "Object", "Copy inside each object's local space"},
|
|
|
|
{PAR_COPY_SPACE_WORLD, "WORLD", 0, "World", "Copy in world space"},
|
2019-02-03 14:01:45 +11:00
|
|
|
{0, NULL, 0, NULL, NULL},
|
2016-12-28 17:30:58 +01:00
|
|
|
};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->name = "Copy Particle Systems";
|
|
|
|
ot->description = "Copy particle systems from the active object to selected objects";
|
|
|
|
ot->idname = "PARTICLE_OT_copy_particle_systems";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->poll = copy_particle_systems_poll;
|
|
|
|
ot->exec = copy_particle_systems_exec;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
RNA_def_enum(ot->srna,
|
|
|
|
"space",
|
|
|
|
space_items,
|
|
|
|
PAR_COPY_SPACE_OBJECT,
|
|
|
|
"Space",
|
|
|
|
"Space transform for copying from one object to another");
|
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
"remove_target_particles",
|
|
|
|
true,
|
|
|
|
"Remove Target Particles",
|
|
|
|
"Remove particle systems on the target objects");
|
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
"use_active",
|
|
|
|
false,
|
|
|
|
"Use Active",
|
|
|
|
"Use the active particle system from the context");
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool duplicate_particle_systems_poll(bContext *C)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2020-07-13 14:29:04 +02:00
|
|
|
if (!ED_operator_object_active_local_editable(C)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Object *ob = ED_object_active_context(C);
|
|
|
|
if (BLI_listbase_is_empty(&ob->particlesystem)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int duplicate_particle_systems_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
const bool duplicate_settings = RNA_boolean_get(op->ptr, "use_duplicate_settings");
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = ED_object_active_context(C);
|
2021-07-26 21:38:37 +02:00
|
|
|
/* Context pointer is only valid in the Properties Editor. */
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSystem *psys = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem).data;
|
2021-07-26 21:38:37 +02:00
|
|
|
if (psys == NULL) {
|
|
|
|
psys = psys_get_current(ob);
|
|
|
|
}
|
|
|
|
|
2018-04-02 15:11:53 +02:00
|
|
|
copy_particle_systems_to_object(
|
2016-12-28 17:30:58 +01:00
|
|
|
C, scene, ob, psys, ob, PAR_COPY_SPACE_OBJECT, duplicate_settings);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_duplicate_particle_system(wmOperatorType *ot)
|
|
|
|
{
|
2018-10-31 18:38:53 +01:00
|
|
|
ot->name = "Duplicate Particle System";
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->description = "Duplicate particle system within the active object";
|
|
|
|
ot->idname = "PARTICLE_OT_duplicate_particle_system";
|
|
|
|
|
|
|
|
ot->poll = duplicate_particle_systems_poll;
|
|
|
|
ot->exec = duplicate_particle_systems_exec;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
"use_duplicate_settings",
|
|
|
|
false,
|
|
|
|
"Duplicate Settings",
|
2018-10-31 18:38:53 +01:00
|
|
|
"Duplicate settings as well, so the new particle system uses its own settings");
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|