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
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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) 2007 by Janne Karhu.
|
|
|
|
* 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 <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
#include "DNA_view3d_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
|
|
|
|
#include "BLI_math.h"
|
2018-02-18 21:27:33 +11:00
|
|
|
#include "BLI_lasso_2d.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BLI_listbase.h"
|
|
|
|
#include "BLI_kdtree.h"
|
|
|
|
#include "BLI_rand.h"
|
2018-06-15 10:22:44 +02:00
|
|
|
#include "BLI_task.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_bvhutils.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_global.h"
|
2018-06-13 14:26:26 +02:00
|
|
|
#include "BKE_main.h"
|
2016-12-28 17:30:58 +01: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"
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_object.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_particle.h"
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_pointcache.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_report.h"
|
2018-06-06 14:13:46 +02:00
|
|
|
#include "BKE_scene.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
#include "ED_object.h"
|
|
|
|
#include "ED_physics.h"
|
|
|
|
#include "ED_mesh.h"
|
|
|
|
#include "ED_particle.h"
|
2018-02-28 16:27:55 +11:00
|
|
|
#include "ED_screen.h"
|
2018-08-14 10:28:41 +10:00
|
|
|
#include "ED_select_utils.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "ED_view3d.h"
|
|
|
|
|
2017-02-14 14:27:31 +01:00
|
|
|
#include "GPU_immediate.h"
|
2017-04-05 18:30:14 +10:00
|
|
|
#include "GPU_immediate_util.h"
|
2018-06-27 19:07:23 -06:00
|
|
|
#include "GPU_state.h"
|
2017-02-14 14:27:31 +01:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
2018-05-08 07:22:52 +02:00
|
|
|
#include "WM_message.h"
|
2018-05-23 08:20:46 +02:00
|
|
|
#include "WM_toolsystem.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
2018-05-11 12:44:43 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
#include "PIL_time_utildefines.h"
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "physics_intern.h"
|
|
|
|
|
2018-03-19 17:46:49 +01:00
|
|
|
#include "particle_edit_utildefines.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/**************************** utilities *******************************/
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
bool PE_poll(bContext *C)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-04-05 18:20:27 +02:00
|
|
|
if (!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return 0;
|
2018-02-06 17:28:00 +11:00
|
|
|
}
|
2009-10-22 23:22:05 +00:00
|
|
|
return (PE_get_current(scene, ob) != NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
bool PE_hair_poll(bContext *C)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
PTCacheEdit *edit;
|
|
|
|
|
2018-04-05 18:20:27 +02:00
|
|
|
if (!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return 0;
|
2018-02-06 17:28:00 +11:00
|
|
|
}
|
2018-06-13 15:36:24 +02:00
|
|
|
edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return (edit && edit->psys);
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
bool PE_poll_view3d(bContext *C)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
|
|
|
|
return (PE_poll(C) &&
|
|
|
|
(sa && sa->spacetype == SPACE_VIEW3D) &&
|
|
|
|
(ar && ar->regiontype == RGN_TYPE_WINDOW));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PE_free_ptcache_edit(PTCacheEdit *edit)
|
|
|
|
{
|
|
|
|
POINT_P;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (edit == 0) return;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (edit->points) {
|
|
|
|
LOOP_POINTS {
|
|
|
|
if (point->keys)
|
|
|
|
MEM_freeN(point->keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(edit->points);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edit->mirror_cache)
|
|
|
|
MEM_freeN(edit->mirror_cache);
|
|
|
|
|
|
|
|
if (edit->emitter_cosnos) {
|
|
|
|
MEM_freeN(edit->emitter_cosnos);
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->emitter_cosnos = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (edit->emitter_field) {
|
|
|
|
BLI_kdtree_free(edit->emitter_field);
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->emitter_field = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
psys_free_path_cache(edit->psys, edit);
|
|
|
|
|
|
|
|
MEM_freeN(edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************/
|
|
|
|
/* Edit Mode Helpers */
|
|
|
|
/************************************************/
|
|
|
|
|
|
|
|
int PE_start_edit(PTCacheEdit *edit)
|
|
|
|
{
|
|
|
|
if (edit) {
|
|
|
|
edit->edited = 1;
|
|
|
|
if (edit->psys)
|
|
|
|
edit->psys->flag |= PSYS_EDITED;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParticleEditSettings *PE_settings(Scene *scene)
|
|
|
|
{
|
|
|
|
return scene->toolsettings ? &scene->toolsettings->particle : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float pe_brush_size_get(const Scene *UNUSED(scene), ParticleBrushData *brush)
|
|
|
|
{
|
|
|
|
// here we can enable unified brush size, needs more work...
|
|
|
|
// UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
// float size = (ups->flag & UNIFIED_PAINT_SIZE) ? ups->size : brush->size;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return brush->size * U.pixelsize;
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:54:50 +02:00
|
|
|
PTCacheEdit *PE_get_current_from_psys(ParticleSystem *psys)
|
|
|
|
{
|
|
|
|
if (psys->part && psys->part->type == PART_HAIR) {
|
|
|
|
if ((psys->flag & PSYS_HAIR_DYNAMICS) != 0 &&
|
|
|
|
(psys->pointcache->flag & PTCACHE_BAKED) != 0)
|
|
|
|
{
|
|
|
|
return psys->pointcache->edit;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return psys->edit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (psys->pointcache->flag & PTCACHE_BAKED) {
|
|
|
|
return psys->pointcache->edit;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-06-19 15:25:48 +02:00
|
|
|
/* NOTE: Similar to creation of edit, but only updates pointers in the
|
|
|
|
* existing struct.
|
|
|
|
*/
|
|
|
|
static void pe_update_hair_particle_edit_pointers(PTCacheEdit *edit)
|
|
|
|
{
|
|
|
|
ParticleSystem *psys = edit->psys;
|
|
|
|
ParticleData *pa = psys->particles;
|
|
|
|
for (int p = 0; p < edit->totpoint; p++) {
|
|
|
|
PTCacheEditPoint *point = &edit->points[p];
|
|
|
|
HairKey *hair_key = pa->hair;
|
|
|
|
for (int k = 0; k < point->totkey; k++) {
|
|
|
|
PTCacheEditKey *key = &point->keys[k];
|
|
|
|
key->co = hair_key->co;
|
|
|
|
key->time = &hair_key->time;
|
|
|
|
key->flag = hair_key->editflag;
|
|
|
|
if (!(psys->flag & PSYS_GLOBAL_HAIR)) {
|
|
|
|
key->flag |= PEK_USE_WCO;
|
|
|
|
hair_key->editflag |= PEK_USE_WCO;
|
|
|
|
}
|
|
|
|
hair_key++;
|
|
|
|
}
|
|
|
|
pa++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* always gets at least the first particlesystem even if PSYS_CURRENT flag is not set
|
|
|
|
*
|
|
|
|
* note: this function runs on poll, therefor it can runs many times a second
|
|
|
|
* keep it fast! */
|
2017-08-16 12:45:11 +10:00
|
|
|
static PTCacheEdit *pe_get_current(
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph, Scene *scene, Object *ob, int create)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
2016-12-28 17:30:58 +01:00
|
|
|
PTCacheEdit *edit = NULL;
|
|
|
|
ListBase pidlist;
|
|
|
|
PTCacheID *pid;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (pset == NULL || ob == NULL)
|
2016-12-28 17:30:58 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pset->scene = scene;
|
|
|
|
pset->object = ob;
|
|
|
|
|
|
|
|
BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0);
|
|
|
|
|
|
|
|
/* in the case of only one editable thing, set pset->edittype accordingly */
|
|
|
|
if (BLI_listbase_is_single(&pidlist)) {
|
|
|
|
pid = pidlist.first;
|
|
|
|
switch (pid->type) {
|
|
|
|
case PTCACHE_TYPE_PARTICLES:
|
|
|
|
pset->edittype = PE_TYPE_PARTICLES;
|
|
|
|
break;
|
|
|
|
case PTCACHE_TYPE_SOFTBODY:
|
|
|
|
pset->edittype = PE_TYPE_SOFTBODY;
|
|
|
|
break;
|
|
|
|
case PTCACHE_TYPE_CLOTH:
|
|
|
|
pset->edittype = PE_TYPE_CLOTH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (pid = pidlist.first; pid; pid = pid->next) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (pset->edittype == PE_TYPE_PARTICLES && pid->type == PTCACHE_TYPE_PARTICLES) {
|
|
|
|
ParticleSystem *psys = pid->calldata;
|
|
|
|
|
|
|
|
if (psys->flag & PSYS_CURRENT) {
|
|
|
|
if (psys->part && psys->part->type == PART_HAIR) {
|
|
|
|
if (psys->flag & PSYS_HAIR_DYNAMICS && psys->pointcache->flag & PTCACHE_BAKED) {
|
|
|
|
if (create && !psys->pointcache->edit)
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_create_particle_edit(depsgraph, scene, ob, pid->cache, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
edit = pid->cache->edit;
|
|
|
|
}
|
|
|
|
else {
|
2018-05-15 14:50:24 +02:00
|
|
|
if (create && !psys->edit) {
|
2018-06-06 15:48:30 +02:00
|
|
|
if (psys->flag & PSYS_HAIR_DONE) {
|
2018-05-15 14:50:24 +02:00
|
|
|
PE_create_particle_edit(depsgraph, scene, ob, NULL, psys);
|
|
|
|
}
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
edit = psys->edit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit)
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_create_particle_edit(depsgraph, scene, ob, pid->cache, psys);
|
2016-12-28 17:30:58 +01:00
|
|
|
edit = pid->cache->edit;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pset->edittype == PE_TYPE_SOFTBODY && pid->type == PTCACHE_TYPE_SOFTBODY) {
|
|
|
|
if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit) {
|
|
|
|
pset->flag |= PE_FADE_TIME;
|
|
|
|
// NICE TO HAVE but doesn't work: pset->brushtype = PE_BRUSH_COMB;
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_create_particle_edit(depsgraph, scene, ob, pid->cache, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
edit = pid->cache->edit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (pset->edittype == PE_TYPE_CLOTH && pid->type == PTCACHE_TYPE_CLOTH) {
|
|
|
|
if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit) {
|
|
|
|
pset->flag |= PE_FADE_TIME;
|
|
|
|
// NICE TO HAVE but doesn't work: pset->brushtype = PE_BRUSH_COMB;
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_create_particle_edit(depsgraph, scene, ob, pid->cache, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
edit = pid->cache->edit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-19 15:25:48 +02:00
|
|
|
if (edit) {
|
2016-12-28 17:30:58 +01:00
|
|
|
edit->pid = *pid;
|
2018-06-19 15:25:48 +02:00
|
|
|
if (edit->flags & PT_CACHE_EDIT_UPDATE_PARTICLE_FROM_EVAL) {
|
|
|
|
if (edit->psys != NULL) {
|
|
|
|
psys_copy_particles(edit->psys, edit->psys_eval);
|
|
|
|
pe_update_hair_particle_edit_pointers(edit);
|
|
|
|
}
|
|
|
|
edit->flags &= ~PT_CACHE_EDIT_UPDATE_PARTICLE_FROM_EVAL;
|
|
|
|
}
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
BLI_freelistN(&pidlist);
|
|
|
|
|
|
|
|
return edit;
|
|
|
|
}
|
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
PTCacheEdit *PE_get_current(Scene *scene, Object *ob)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-04-01 11:03:25 +02:00
|
|
|
return pe_get_current(NULL, scene, ob, 0);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PTCacheEdit *PE_create_current(Depsgraph *depsgraph, Scene *scene, Object *ob)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-04-06 12:07:27 +02:00
|
|
|
return pe_get_current(depsgraph, scene, ob, 1);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
void PE_current_changed(Depsgraph *depsgraph, Scene *scene, Object *ob)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-04-05 18:20:27 +02:00
|
|
|
if (ob->mode == OB_MODE_PARTICLE_EDIT) {
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_create_current(depsgraph, scene, ob);
|
2017-08-16 12:45:11 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PE_hide_keys_time(Scene *scene, PTCacheEdit *edit, float cfra)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P; KEY_K;
|
|
|
|
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (pset->flag & PE_FADE_TIME && pset->selectmode == SCE_SELECT_POINT) {
|
2016-12-28 17:30:58 +01:00
|
|
|
LOOP_POINTS {
|
|
|
|
LOOP_KEYS {
|
|
|
|
if (fabsf(cfra - *key->time) < pset->fade_frames)
|
|
|
|
key->flag &= ~PEK_HIDE;
|
|
|
|
else {
|
|
|
|
key->flag |= PEK_HIDE;
|
|
|
|
//key->flag &= ~PEK_SELECT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOOP_POINTS {
|
|
|
|
LOOP_KEYS {
|
|
|
|
key->flag &= ~PEK_HIDE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pe_x_mirror(Object *ob)
|
|
|
|
{
|
|
|
|
if (ob->type == OB_MESH)
|
|
|
|
return (((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_X);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************** common struct passed to callbacks ******************/
|
|
|
|
|
|
|
|
typedef struct PEData {
|
|
|
|
ViewContext vc;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2017-07-21 11:53:13 +02:00
|
|
|
const bContext *context;
|
2018-06-13 14:26:26 +02:00
|
|
|
Main *bmain;
|
2016-12-28 17:30:58 +01:00
|
|
|
Scene *scene;
|
2017-11-22 10:52:39 -02:00
|
|
|
ViewLayer *view_layer;
|
2016-12-28 17:30:58 +01:00
|
|
|
Object *ob;
|
2018-05-15 13:26:40 +02:00
|
|
|
Mesh *mesh;
|
2016-12-28 17:30:58 +01:00
|
|
|
PTCacheEdit *edit;
|
|
|
|
BVHTreeFromMesh shape_bvh;
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-20 11:27:19 +02:00
|
|
|
RNG *rng;
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
const int *mval;
|
2018-08-14 17:41:01 +10:00
|
|
|
const rcti *rect;
|
2016-12-28 17:30:58 +01:00
|
|
|
float rad;
|
|
|
|
float dist;
|
|
|
|
float dval;
|
|
|
|
int select;
|
2018-08-14 10:28:41 +10:00
|
|
|
eSelectOp sel_op;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
float *dvec;
|
|
|
|
float combfac;
|
|
|
|
float pufffac;
|
|
|
|
float cutfac;
|
|
|
|
float smoothfac;
|
|
|
|
float weightfac;
|
|
|
|
float growfac;
|
|
|
|
int totrekey;
|
|
|
|
|
|
|
|
int invert;
|
|
|
|
int tot;
|
|
|
|
float vec[3];
|
|
|
|
|
|
|
|
int select_action;
|
|
|
|
int select_toggle_action;
|
2019-03-01 23:09:22 +11:00
|
|
|
bool is_changed;
|
2016-12-28 17:30:58 +01:00
|
|
|
} PEData;
|
|
|
|
|
|
|
|
static void PE_set_data(bContext *C, PEData *data)
|
|
|
|
{
|
|
|
|
memset(data, 0, sizeof(*data));
|
|
|
|
|
2018-06-13 14:26:26 +02:00
|
|
|
data->bmain = CTX_data_main(C);
|
2017-07-21 11:53:13 +02:00
|
|
|
data->scene = CTX_data_scene(C);
|
2017-11-22 10:52:39 -02:00
|
|
|
data->view_layer = CTX_data_view_layer(C);
|
2017-07-21 11:53:13 +02:00
|
|
|
data->ob = CTX_data_active_object(C);
|
2018-04-06 12:07:27 +02:00
|
|
|
data->depsgraph = CTX_data_depsgraph(C);
|
2018-04-01 11:03:25 +02:00
|
|
|
data->edit = PE_get_current(data->scene, data->ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PE_set_view3d_data(bContext *C, PEData *data)
|
|
|
|
{
|
|
|
|
PE_set_data(C, data);
|
|
|
|
|
2018-03-08 17:30:24 +11:00
|
|
|
ED_view3d_viewcontext_init(C, &data->vc);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (V3D_IS_ZBUF(data->vc.v3d)) {
|
|
|
|
if (data->vc.v3d->flag & V3D_INVALID_BACKBUF) {
|
|
|
|
/* needed or else the draw matrix can be incorrect */
|
|
|
|
view3d_operator_needs_opengl(C);
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
ED_view3d_backbuf_validate(&data->vc);
|
2016-12-28 17:30:58 +01:00
|
|
|
/* we may need to force an update here by setting the rv3d as dirty
|
|
|
|
* for now it seems ok, but take care!:
|
|
|
|
* rv3d->depths->dirty = 1; */
|
|
|
|
ED_view3d_depth_update(data->vc.ar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool PE_create_shape_tree(PEData *data, Object *shapeob)
|
|
|
|
{
|
2018-05-30 11:34:08 +02:00
|
|
|
Mesh *mesh = BKE_object_get_evaluated_mesh(data->depsgraph, shapeob);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
memset(&data->shape_bvh, 0, sizeof(data->shape_bvh));
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
if (!mesh) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
return (BKE_bvhtree_from_mesh_get(&data->shape_bvh, mesh, BVHTREE_FROM_LOOPTRI, 4) != NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PE_free_shape_tree(PEData *data)
|
|
|
|
{
|
|
|
|
free_bvhtree_from_mesh(&data->shape_bvh);
|
|
|
|
}
|
|
|
|
|
2018-06-20 11:27:19 +02:00
|
|
|
static void PE_create_random_generator(PEData *data)
|
|
|
|
{
|
|
|
|
uint rng_seed = (uint)(PIL_check_seconds_timer_i() & UINT_MAX);
|
2018-09-19 12:14:36 +10:00
|
|
|
rng_seed ^= POINTER_AS_UINT(data->ob);
|
|
|
|
rng_seed ^= POINTER_AS_UINT(data->edit);
|
2018-06-20 11:27:19 +02:00
|
|
|
data->rng = BLI_rng_new(rng_seed);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PE_free_random_generator(PEData *data)
|
|
|
|
{
|
|
|
|
if (data->rng != NULL) {
|
|
|
|
BLI_rng_free(data->rng);
|
|
|
|
data->rng = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/*************************** selection utilities *******************************/
|
|
|
|
|
|
|
|
static bool key_test_depth(PEData *data, const float co[3], const int screen_co[2])
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
View3D *v3d = data->vc.v3d;
|
2016-12-28 17:30:58 +01:00
|
|
|
ViewDepths *vd = data->vc.rv3d->depths;
|
|
|
|
float depth;
|
|
|
|
|
|
|
|
/* nothing to do */
|
|
|
|
if (!V3D_IS_ZBUF(v3d))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* used to calculate here but all callers have the screen_co already, so pass as arg */
|
|
|
|
#if 0
|
|
|
|
if (ED_view3d_project_int_global(data->vc.ar, co, screen_co,
|
|
|
|
V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) != V3D_PROJ_RET_OK)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* check if screen_co is within bounds because brush_cut uses out of screen coords */
|
|
|
|
if (screen_co[0] >= 0 && screen_co[0] < vd->w && screen_co[1] >= 0 && screen_co[1] < vd->h) {
|
|
|
|
BLI_assert(vd && vd->depths);
|
|
|
|
/* we know its not clipped */
|
|
|
|
depth = vd->depths[screen_co[1] * vd->w + screen_co[0]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
2017-02-25 21:58:23 +01:00
|
|
|
float win[3];
|
|
|
|
ED_view3d_project(data->vc.ar, co, win);
|
|
|
|
|
|
|
|
if (win[2] - 0.00001f > depth)
|
2016-12-28 17:30:58 +01:00
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool key_inside_circle(PEData *data, float rad, const float co[3], float *distance)
|
|
|
|
{
|
|
|
|
float dx, dy, dist;
|
|
|
|
int screen_co[2];
|
|
|
|
|
|
|
|
/* TODO, should this check V3D_PROJ_TEST_CLIP_BB too? */
|
|
|
|
if (ED_view3d_project_int_global(data->vc.ar, co, screen_co, V3D_PROJ_TEST_CLIP_WIN) != V3D_PROJ_RET_OK) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
dx = data->mval[0] - screen_co[0];
|
|
|
|
dy = data->mval[1] - screen_co[1];
|
2016-12-28 17:30:58 +01:00
|
|
|
dist = sqrtf(dx * dx + dy * dy);
|
|
|
|
|
|
|
|
if (dist > rad)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (key_test_depth(data, co, screen_co)) {
|
|
|
|
if (distance)
|
2018-08-14 10:00:15 +10:00
|
|
|
*distance = dist;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool key_inside_rect(PEData *data, const float co[3])
|
|
|
|
{
|
|
|
|
int screen_co[2];
|
|
|
|
|
|
|
|
if (ED_view3d_project_int_global(data->vc.ar, co, screen_co, V3D_PROJ_TEST_CLIP_WIN) != V3D_PROJ_RET_OK) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (screen_co[0] > data->rect->xmin && screen_co[0] < data->rect->xmax &&
|
|
|
|
screen_co[1] > data->rect->ymin && screen_co[1] < data->rect->ymax)
|
|
|
|
{
|
|
|
|
return key_test_depth(data, co, screen_co);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool key_inside_test(PEData *data, const float co[3])
|
|
|
|
{
|
|
|
|
if (data->mval)
|
|
|
|
return key_inside_circle(data, data->rad, co, NULL);
|
|
|
|
else
|
|
|
|
return key_inside_rect(data, co);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool point_is_selected(PTCacheEditPoint *point)
|
|
|
|
{
|
|
|
|
KEY_K;
|
|
|
|
|
|
|
|
if (point->flag & PEP_HIDE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
LOOP_SELECTED_KEYS {
|
|
|
|
return 1;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************** iterators *******************************/
|
|
|
|
|
|
|
|
typedef void (*ForPointFunc)(PEData *data, int point_index);
|
2018-08-14 10:28:41 +10:00
|
|
|
typedef void (*ForKeyFunc)(PEData *data, int point_index, int key_index, bool is_inside);
|
2016-12-28 17:30:58 +01:00
|
|
|
typedef void (*ForKeyMatFunc)(PEData *data, float mat[4][4], float imat[4][4], int point_index, int key_index, PTCacheEditKey *key);
|
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
enum eParticleSelectFlag {
|
|
|
|
PSEL_NEAREST = (1 << 0),
|
|
|
|
PSEL_ALL_KEYS = (1 << 1),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void for_mouse_hit_keys(PEData *data, ForKeyFunc func, const enum eParticleSelectFlag flag)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleEditSettings *pset = PE_settings(data->scene);
|
|
|
|
PTCacheEdit *edit = data->edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P; KEY_K;
|
|
|
|
int nearest_point, nearest_key;
|
2018-08-14 10:00:15 +10:00
|
|
|
float dist = data->rad;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* in path select mode we have no keys */
|
2018-08-14 10:00:15 +10:00
|
|
|
if (pset->selectmode == SCE_SELECT_PATH)
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
nearest_point = -1;
|
|
|
|
nearest_key = -1;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
LOOP_VISIBLE_POINTS {
|
|
|
|
if (pset->selectmode == SCE_SELECT_END) {
|
|
|
|
if (point->totkey) {
|
|
|
|
/* only do end keys */
|
2018-08-14 10:00:15 +10:00
|
|
|
key = point->keys + point->totkey - 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
if (flag & PSEL_NEAREST) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (key_inside_circle(data, dist, KEY_WCO, &dist)) {
|
2018-08-14 10:00:15 +10:00
|
|
|
nearest_point = p;
|
|
|
|
nearest_key = point->totkey - 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
2018-08-14 10:28:41 +10:00
|
|
|
else {
|
|
|
|
const bool is_inside = key_inside_test(data, KEY_WCO);
|
|
|
|
if (is_inside || (flag & PSEL_ALL_KEYS)) {
|
|
|
|
func(data, p, point->totkey - 1, is_inside);
|
|
|
|
}
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* do all keys */
|
|
|
|
LOOP_VISIBLE_KEYS {
|
2018-08-14 10:28:41 +10:00
|
|
|
if (flag & PSEL_NEAREST) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (key_inside_circle(data, dist, KEY_WCO, &dist)) {
|
2018-08-14 10:00:15 +10:00
|
|
|
nearest_point = p;
|
|
|
|
nearest_key = k;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
2018-08-14 10:28:41 +10:00
|
|
|
else {
|
|
|
|
const bool is_inside = key_inside_test(data, KEY_WCO);
|
|
|
|
if (is_inside || (flag & PSEL_ALL_KEYS)) {
|
|
|
|
func(data, p, k, is_inside);
|
|
|
|
}
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do nearest only */
|
2018-08-14 10:28:41 +10:00
|
|
|
if (flag & PSEL_NEAREST) {
|
|
|
|
if (nearest_point != -1) {
|
|
|
|
func(data, nearest_point, nearest_key, true);
|
|
|
|
}
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void foreach_mouse_hit_point(PEData *data, ForPointFunc func, int selected)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleEditSettings *pset = PE_settings(data->scene);
|
|
|
|
PTCacheEdit *edit = data->edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P; KEY_K;
|
|
|
|
|
|
|
|
/* all is selected in path mode */
|
2018-08-14 10:00:15 +10:00
|
|
|
if (pset->selectmode == SCE_SELECT_PATH)
|
|
|
|
selected = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
LOOP_VISIBLE_POINTS {
|
2018-08-14 10:00:15 +10:00
|
|
|
if (pset->selectmode == SCE_SELECT_END) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (point->totkey) {
|
|
|
|
/* only do end keys */
|
2018-08-14 10:00:15 +10:00
|
|
|
key = point->keys + point->totkey - 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (selected == 0 || key->flag & PEK_SELECT)
|
2016-12-28 17:30:58 +01:00
|
|
|
if (key_inside_circle(data, data->rad, KEY_WCO, &data->dist))
|
|
|
|
func(data, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* do all keys */
|
|
|
|
LOOP_VISIBLE_KEYS {
|
2018-08-14 10:00:15 +10:00
|
|
|
if (selected == 0 || key->flag & PEK_SELECT) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (key_inside_circle(data, data->rad, KEY_WCO, &data->dist)) {
|
|
|
|
func(data, p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
typedef struct KeyIterData {
|
|
|
|
PEData *data;
|
|
|
|
PTCacheEdit *edit;
|
|
|
|
int selected;
|
|
|
|
ForKeyMatFunc func;
|
|
|
|
} KeyIterData;
|
|
|
|
|
|
|
|
static void foreach_mouse_hit_key_iter(
|
|
|
|
void *__restrict iter_data_v,
|
|
|
|
const int iter,
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-06-15 10:22:44 +02:00
|
|
|
KeyIterData *iter_data = (KeyIterData *)iter_data_v;
|
|
|
|
PEData *data = iter_data->data;
|
2016-12-28 17:30:58 +01:00
|
|
|
PTCacheEdit *edit = data->edit;
|
2018-06-15 10:22:44 +02:00
|
|
|
PTCacheEditPoint *point = &edit->points[iter];
|
|
|
|
if (point->flag & PEP_HIDE) {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSystem *psys = edit->psys;
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval = iter_data->edit->psmd_eval;
|
2018-06-15 10:22:44 +02:00
|
|
|
ParticleEditSettings *pset = PE_settings(data->scene);
|
|
|
|
const int selected = iter_data->selected;
|
2016-12-28 17:30:58 +01:00
|
|
|
float mat[4][4], imat[4][4];
|
|
|
|
unit_m4(mat);
|
|
|
|
unit_m4(imat);
|
2018-08-14 10:02:43 +10:00
|
|
|
if (pset->selectmode == SCE_SELECT_END) {
|
2018-06-15 10:22:44 +02:00
|
|
|
if (point->totkey) {
|
|
|
|
/* only do end keys */
|
2018-08-14 10:02:43 +10:00
|
|
|
PTCacheEditKey *key = point->keys + point->totkey - 1;
|
2018-06-15 10:22:44 +02:00
|
|
|
|
2018-08-14 10:02:43 +10:00
|
|
|
if (selected == 0 || key->flag & PEK_SELECT) {
|
2018-06-15 10:22:44 +02:00
|
|
|
if (key_inside_circle(data, data->rad, KEY_WCO, &data->dist)) {
|
|
|
|
if (edit->psys && !(edit->psys->flag & PSYS_GLOBAL_HAIR)) {
|
2018-06-19 15:25:48 +02:00
|
|
|
psys_mat_hair_to_global(data->ob, psmd_eval->mesh_final, psys->part->from, psys->particles + iter, mat);
|
2018-06-15 10:22:44 +02:00
|
|
|
invert_m4_m4(imat, mat);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2018-08-14 10:02:43 +10:00
|
|
|
iter_data->func(data, mat, imat, iter, point->totkey - 1, key);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-15 10:22:44 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* do all keys */
|
|
|
|
PTCacheEditKey *key;
|
|
|
|
int k;
|
|
|
|
LOOP_VISIBLE_KEYS {
|
2018-08-14 10:02:43 +10:00
|
|
|
if (selected == 0 || key->flag & PEK_SELECT) {
|
2018-06-15 10:22:44 +02:00
|
|
|
if (key_inside_circle(data, data->rad, KEY_WCO, &data->dist)) {
|
|
|
|
if (edit->psys && !(edit->psys->flag & PSYS_GLOBAL_HAIR)) {
|
2018-06-19 15:25:48 +02:00
|
|
|
psys_mat_hair_to_global(data->ob, psmd_eval->mesh_final, psys->part->from, psys->particles + iter, mat);
|
2018-06-15 10:22:44 +02:00
|
|
|
invert_m4_m4(imat, mat);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2018-06-15 10:22:44 +02:00
|
|
|
iter_data->func(data, mat, imat, iter, k, key);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
static void foreach_mouse_hit_key(PEData *data, ForKeyMatFunc func, int selected)
|
|
|
|
{
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
ParticleEditSettings *pset = PE_settings(data->scene);
|
|
|
|
/* all is selected in path mode */
|
|
|
|
if (pset->selectmode == SCE_SELECT_PATH) {
|
|
|
|
selected = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyIterData iter_data;
|
|
|
|
iter_data.data = data;
|
2018-06-18 16:01:13 +02:00
|
|
|
iter_data.edit = edit;
|
2018-06-15 10:22:44 +02:00
|
|
|
iter_data.selected = selected;
|
|
|
|
iter_data.func = func;
|
|
|
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC;
|
|
|
|
BLI_task_parallel_range(0, edit->totpoint, &iter_data, foreach_mouse_hit_key_iter, &settings);
|
|
|
|
}
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
static void foreach_selected_point(PEData *data, ForPointFunc func)
|
|
|
|
{
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
POINT_P;
|
|
|
|
|
|
|
|
LOOP_SELECTED_POINTS {
|
|
|
|
func(data, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void foreach_selected_key(PEData *data, ForKeyFunc func)
|
|
|
|
{
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
POINT_P; KEY_K;
|
|
|
|
|
|
|
|
LOOP_VISIBLE_POINTS {
|
|
|
|
LOOP_SELECTED_KEYS {
|
2018-08-14 10:28:41 +10:00
|
|
|
func(data, p, k, true);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void foreach_point(PEData *data, ForPointFunc func)
|
|
|
|
{
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
POINT_P;
|
|
|
|
|
|
|
|
LOOP_POINTS {
|
|
|
|
func(data, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int count_selected_keys(Scene *scene, PTCacheEdit *edit)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P; KEY_K;
|
2018-08-14 10:00:15 +10:00
|
|
|
int sel = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
LOOP_VISIBLE_POINTS {
|
2018-08-14 10:00:15 +10:00
|
|
|
if (pset->selectmode == SCE_SELECT_POINT) {
|
2016-12-28 17:30:58 +01:00
|
|
|
LOOP_SELECTED_KEYS {
|
|
|
|
sel++;
|
|
|
|
}
|
|
|
|
}
|
2018-08-14 10:00:15 +10:00
|
|
|
else if (pset->selectmode == SCE_SELECT_END) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (point->totkey) {
|
|
|
|
key = point->keys + point->totkey - 1;
|
|
|
|
if (key->flag & PEK_SELECT)
|
|
|
|
sel++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************/
|
|
|
|
/* Particle Edit Mirroring */
|
|
|
|
/************************************************/
|
|
|
|
|
|
|
|
static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys)
|
|
|
|
{
|
|
|
|
PTCacheEdit *edit;
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval;
|
2016-12-28 17:30:58 +01:00
|
|
|
KDTree *tree;
|
|
|
|
KDTreeNearest nearest;
|
|
|
|
HairKey *key;
|
|
|
|
PARTICLE_P;
|
|
|
|
float mat[4][4], co[3];
|
|
|
|
int index, totpart;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
edit = psys->edit;
|
2018-06-19 15:25:48 +02:00
|
|
|
psmd_eval = edit->psmd_eval;
|
2018-08-14 10:00:15 +10:00
|
|
|
totpart = psys->totpart;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-19 15:25:48 +02:00
|
|
|
if (!psmd_eval->mesh_final)
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
tree = BLI_kdtree_new(totpart);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* insert particles into kd tree */
|
|
|
|
LOOP_PARTICLES {
|
|
|
|
key = pa->hair;
|
2018-06-19 15:25:48 +02:00
|
|
|
psys_mat_hair_to_orco(ob, psmd_eval->mesh_final, psys->part->from, pa, mat);
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v3_v3(co, key->co);
|
|
|
|
mul_m4_v3(mat, co);
|
|
|
|
BLI_kdtree_insert(tree, p, co);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_kdtree_balance(tree);
|
|
|
|
|
|
|
|
/* lookup particles and set in mirror cache */
|
|
|
|
if (!edit->mirror_cache)
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->mirror_cache = MEM_callocN(sizeof(int) * totpart, "PE mirror cache");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
LOOP_PARTICLES {
|
|
|
|
key = pa->hair;
|
2018-06-19 15:25:48 +02:00
|
|
|
psys_mat_hair_to_orco(ob, psmd_eval->mesh_final, psys->part->from, pa, mat);
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v3_v3(co, key->co);
|
|
|
|
mul_m4_v3(mat, co);
|
|
|
|
co[0] = -co[0];
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
index = BLI_kdtree_find_nearest(tree, co, &nearest);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* this needs a custom threshold still, duplicated for editmode mirror */
|
|
|
|
if (index != -1 && index != p && (nearest.dist <= 0.0002f))
|
|
|
|
edit->mirror_cache[p] = index;
|
|
|
|
else
|
|
|
|
edit->mirror_cache[p] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure mirrors are in two directions */
|
|
|
|
LOOP_PARTICLES {
|
|
|
|
if (edit->mirror_cache[p]) {
|
2018-08-14 10:00:15 +10:00
|
|
|
index = edit->mirror_cache[p];
|
2016-12-28 17:30:58 +01:00
|
|
|
if (edit->mirror_cache[index] != p)
|
|
|
|
edit->mirror_cache[p] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_kdtree_free(tree);
|
|
|
|
}
|
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
static void PE_mirror_particle(Object *ob, Mesh *mesh, ParticleSystem *psys, ParticleData *pa, ParticleData *mpa)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
HairKey *hkey, *mhkey;
|
|
|
|
PTCacheEditPoint *point, *mpoint;
|
|
|
|
PTCacheEditKey *key, *mkey;
|
|
|
|
PTCacheEdit *edit;
|
|
|
|
float mat[4][4], mmat[4][4], immat[4][4];
|
|
|
|
int i, mi, k;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
edit = psys->edit;
|
|
|
|
i = pa - psys->particles;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* find mirrored particle if needed */
|
|
|
|
if (!mpa) {
|
|
|
|
if (!edit->mirror_cache)
|
|
|
|
PE_update_mirror_cache(ob, psys);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (!edit->mirror_cache)
|
|
|
|
return; /* something went wrong! */
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
mi = edit->mirror_cache[i];
|
2016-12-28 17:30:58 +01:00
|
|
|
if (mi == -1)
|
|
|
|
return;
|
2018-08-14 10:00:15 +10:00
|
|
|
mpa = psys->particles + mi;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
else
|
2018-08-14 10:00:15 +10:00
|
|
|
mi = mpa - psys->particles;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
point = edit->points + i;
|
|
|
|
mpoint = edit->points + mi;
|
|
|
|
|
|
|
|
/* make sure they have the same amount of keys */
|
|
|
|
if (pa->totkey != mpa->totkey) {
|
|
|
|
if (mpa->hair) MEM_freeN(mpa->hair);
|
|
|
|
if (mpoint->keys) MEM_freeN(mpoint->keys);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
mpa->hair = MEM_dupallocN(pa->hair);
|
|
|
|
mpa->totkey = pa->totkey;
|
|
|
|
mpoint->keys = MEM_dupallocN(point->keys);
|
|
|
|
mpoint->totkey = point->totkey;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
mhkey = mpa->hair;
|
|
|
|
mkey = mpoint->keys;
|
|
|
|
for (k = 0; k < mpa->totkey; k++, mkey++, mhkey++) {
|
|
|
|
mkey->co = mhkey->co;
|
|
|
|
mkey->time = &mhkey->time;
|
2016-12-28 17:30:58 +01:00
|
|
|
mkey->flag &= ~PEK_SELECT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mirror positions and tags */
|
2018-05-15 13:26:40 +02:00
|
|
|
psys_mat_hair_to_orco(ob, mesh, psys->part->from, pa, mat);
|
|
|
|
psys_mat_hair_to_orco(ob, mesh, psys->part->from, mpa, mmat);
|
2016-12-28 17:30:58 +01:00
|
|
|
invert_m4_m4(immat, mmat);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
hkey = pa->hair;
|
|
|
|
mhkey = mpa->hair;
|
|
|
|
key = point->keys;
|
|
|
|
mkey = mpoint->keys;
|
|
|
|
for (k = 0; k < pa->totkey; k++, hkey++, mhkey++, key++, mkey++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v3_v3(mhkey->co, hkey->co);
|
|
|
|
mul_m4_v3(mat, mhkey->co);
|
|
|
|
mhkey->co[0] = -mhkey->co[0];
|
|
|
|
mul_m4_v3(immat, mhkey->co);
|
|
|
|
|
|
|
|
if (key->flag & PEK_TAG)
|
|
|
|
mkey->flag |= PEK_TAG;
|
|
|
|
|
|
|
|
mkey->length = key->length;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (point->flag & PEP_TAG)
|
|
|
|
mpoint->flag |= PEP_TAG;
|
|
|
|
if (point->flag & PEP_EDIT_RECALC)
|
|
|
|
mpoint->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PE_apply_mirror(Object *ob, ParticleSystem *psys)
|
|
|
|
{
|
|
|
|
PTCacheEdit *edit;
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval;
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P;
|
|
|
|
|
|
|
|
if (!psys)
|
|
|
|
return;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
edit = psys->edit;
|
2018-08-14 10:02:43 +10:00
|
|
|
psmd_eval = edit->psmd_eval;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-19 15:25:48 +02:00
|
|
|
if (!psmd_eval->mesh_final)
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!edit->mirror_cache)
|
|
|
|
PE_update_mirror_cache(ob, psys);
|
|
|
|
|
|
|
|
if (!edit->mirror_cache)
|
|
|
|
return; /* something went wrong */
|
|
|
|
|
|
|
|
/* we delay settings the PARS_EDIT_RECALC for mirrored particles
|
|
|
|
* to avoid doing mirror twice */
|
|
|
|
LOOP_POINTS {
|
|
|
|
if (point->flag & PEP_EDIT_RECALC) {
|
2018-06-19 15:25:48 +02:00
|
|
|
PE_mirror_particle(ob, psmd_eval->mesh_final, psys, psys->particles + p, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (edit->mirror_cache[p] != -1)
|
|
|
|
edit->points[edit->mirror_cache[p]].flag &= ~PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LOOP_POINTS {
|
|
|
|
if (point->flag & PEP_EDIT_RECALC)
|
|
|
|
if (edit->mirror_cache[p] != -1)
|
|
|
|
edit->points[edit->mirror_cache[p]].flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************/
|
|
|
|
/* Edit Calculation */
|
|
|
|
/************************************************/
|
2018-06-15 10:22:44 +02:00
|
|
|
|
|
|
|
typedef struct DeflectEmitterIter {
|
|
|
|
Object *object;
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSystem *psys;
|
2018-06-15 10:22:44 +02:00
|
|
|
PTCacheEdit *edit;
|
|
|
|
float dist;
|
|
|
|
float emitterdist;
|
|
|
|
} DeflectEmitterIter;
|
|
|
|
|
|
|
|
static void deflect_emitter_iter(
|
|
|
|
void *__restrict iter_data_v,
|
|
|
|
const int iter,
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
2018-08-14 10:02:43 +10:00
|
|
|
{
|
2018-06-15 10:22:44 +02:00
|
|
|
DeflectEmitterIter *iter_data = (DeflectEmitterIter *)iter_data_v;
|
|
|
|
PTCacheEdit *edit = iter_data->edit;
|
|
|
|
PTCacheEditPoint *point = &edit->points[iter];
|
|
|
|
if ((point->flag & PEP_EDIT_RECALC) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Object *object = iter_data->object;
|
|
|
|
ParticleSystem *psys = iter_data->psys;
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval = iter_data->edit->psmd_eval;
|
2018-06-15 10:22:44 +02:00
|
|
|
PTCacheEditKey *key;
|
|
|
|
int k;
|
|
|
|
float hairimat[4][4], hairmat[4][4];
|
2016-12-28 17:30:58 +01:00
|
|
|
int index;
|
2018-08-14 10:00:15 +10:00
|
|
|
float *vec, *nor, dvec[3], dot, dist_1st = 0.0f;
|
2018-06-15 10:22:44 +02:00
|
|
|
const float dist = iter_data->dist;
|
|
|
|
const float emitterdist = iter_data->emitterdist;
|
|
|
|
psys_mat_hair_to_object(object,
|
2018-06-19 15:25:48 +02:00
|
|
|
psmd_eval->mesh_final,
|
2018-06-15 10:22:44 +02:00
|
|
|
psys->part->from,
|
|
|
|
psys->particles + iter,
|
|
|
|
hairmat);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
LOOP_KEYS {
|
|
|
|
mul_m4_v3(hairmat, key->co);
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
LOOP_KEYS {
|
|
|
|
if (k == 0) {
|
|
|
|
dist_1st = len_v3v3((key + 1)->co, key->co);
|
|
|
|
dist_1st *= dist * emitterdist;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2018-06-15 10:22:44 +02:00
|
|
|
else {
|
|
|
|
index = BLI_kdtree_find_nearest(edit->emitter_field, key->co, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
vec = edit->emitter_cosnos + index * 6;
|
|
|
|
nor = vec + 3;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
sub_v3_v3v3(dvec, key->co, vec);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
dot = dot_v3v3(dvec, nor);
|
|
|
|
copy_v3_v3(dvec, nor);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
if (dot > 0.0f) {
|
|
|
|
if (dot < dist_1st) {
|
2016-12-28 17:30:58 +01:00
|
|
|
normalize_v3(dvec);
|
2018-06-15 10:22:44 +02:00
|
|
|
mul_v3_fl(dvec, dist_1st - dot);
|
2016-12-28 17:30:58 +01:00
|
|
|
add_v3_v3(key->co, dvec);
|
|
|
|
}
|
2018-06-15 10:22:44 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
normalize_v3(dvec);
|
|
|
|
mul_v3_fl(dvec, dist_1st - dot);
|
|
|
|
add_v3_v3(key->co, dvec);
|
|
|
|
}
|
|
|
|
if (k == 1) {
|
|
|
|
dist_1st *= 1.3333f;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
2018-06-15 10:22:44 +02:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
invert_m4_m4(hairimat, hairmat);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
LOOP_KEYS {
|
|
|
|
mul_m4_v3(hairimat, key->co);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
/* tries to stop edited particles from going through the emitter's surface */
|
|
|
|
static void pe_deflect_emitter(Scene *scene, Object *ob, PTCacheEdit *edit)
|
|
|
|
{
|
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
|
|
|
ParticleSystem *psys;
|
|
|
|
const float dist = ED_view3d_select_dist_px() * 0.01f;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
if (edit == NULL || edit->psys == NULL ||
|
|
|
|
(pset->flag & PE_DEFLECT_EMITTER) == 0 ||
|
|
|
|
(edit->psys->flag & PSYS_GLOBAL_HAIR))
|
|
|
|
{
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
2018-06-15 10:22:44 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
psys = edit->psys;
|
|
|
|
|
2018-06-19 15:25:48 +02:00
|
|
|
if (!edit->psmd_eval->mesh_final) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
2018-06-15 10:22:44 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
DeflectEmitterIter iter_data;
|
|
|
|
iter_data.object = ob;
|
|
|
|
iter_data.psys = psys;
|
|
|
|
iter_data.edit = edit;
|
|
|
|
iter_data.dist = dist;
|
|
|
|
iter_data.emitterdist = pset->emitterdist;
|
|
|
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC;
|
|
|
|
BLI_task_parallel_range(0, edit->totpoint, &iter_data, deflect_emitter_iter, &settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct ApplyLengthsIterData {
|
|
|
|
PTCacheEdit *edit;
|
|
|
|
} ApplyLengthsIterData;
|
|
|
|
|
|
|
|
static void apply_lengths_iter(
|
|
|
|
void *__restrict iter_data_v,
|
|
|
|
const int iter,
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
2018-08-14 10:02:43 +10:00
|
|
|
{
|
2018-06-15 10:22:44 +02:00
|
|
|
ApplyLengthsIterData *iter_data = (ApplyLengthsIterData *)iter_data_v;
|
|
|
|
PTCacheEdit *edit = iter_data->edit;
|
|
|
|
PTCacheEditPoint *point = &edit->points[iter];
|
|
|
|
if ((point->flag & PEP_EDIT_RECALC) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PTCacheEditKey *key;
|
|
|
|
int k;
|
|
|
|
LOOP_KEYS {
|
|
|
|
if (k) {
|
|
|
|
float dv1[3];
|
|
|
|
sub_v3_v3v3(dv1, key->co, (key - 1)->co);
|
|
|
|
normalize_v3(dv1);
|
|
|
|
mul_v3_fl(dv1, (key - 1)->length);
|
|
|
|
add_v3_v3v3(key->co, (key - 1)->co, dv1);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-15 10:22:44 +02:00
|
|
|
|
|
|
|
/* force set distances between neighboring keys */
|
|
|
|
static void PE_apply_lengths(Scene *scene, PTCacheEdit *edit)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (edit == 0 || (pset->flag & PE_KEEP_LENGTHS) == 0)
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR)
|
|
|
|
return;
|
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
ApplyLengthsIterData iter_data;
|
|
|
|
iter_data.edit = edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC;
|
|
|
|
BLI_task_parallel_range(0, edit->totpoint, &iter_data, apply_lengths_iter, &settings);
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
typedef struct IterateLengthsIterData {
|
|
|
|
PTCacheEdit *edit;
|
|
|
|
ParticleEditSettings *pset;
|
|
|
|
} IterateLengthsIterData;
|
|
|
|
|
|
|
|
static void iterate_lengths_iter(
|
|
|
|
void *__restrict iter_data_v,
|
|
|
|
const int iter,
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
|
|
|
{
|
|
|
|
IterateLengthsIterData *iter_data = (IterateLengthsIterData *)iter_data_v;
|
|
|
|
PTCacheEdit *edit = iter_data->edit;
|
|
|
|
PTCacheEditPoint *point = &edit->points[iter];
|
|
|
|
if ((point->flag & PEP_EDIT_RECALC) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ParticleEditSettings *pset = iter_data->pset;
|
|
|
|
float tlen;
|
|
|
|
float dv0[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
float dv1[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
float dv2[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
for (int j = 1; j < point->totkey; j++) {
|
|
|
|
PTCacheEditKey *key;
|
|
|
|
int k;
|
|
|
|
float mul = 1.0f / (float)point->totkey;
|
|
|
|
if (pset->flag & PE_LOCK_FIRST) {
|
|
|
|
key = point->keys + 1;
|
|
|
|
k = 1;
|
|
|
|
dv1[0] = dv1[1] = dv1[2] = 0.0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
key = point->keys;
|
|
|
|
k = 0;
|
|
|
|
dv0[0] = dv0[1] = dv0[2] = 0.0;
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
for (; k < point->totkey; k++, key++) {
|
|
|
|
if (k) {
|
|
|
|
sub_v3_v3v3(dv0, (key - 1)->co, key->co);
|
|
|
|
tlen = normalize_v3(dv0);
|
|
|
|
mul_v3_fl(dv0, (mul * (tlen - (key - 1)->length)));
|
|
|
|
}
|
|
|
|
if (k < point->totkey - 1) {
|
|
|
|
sub_v3_v3v3(dv2, (key + 1)->co, key->co);
|
|
|
|
tlen = normalize_v3(dv2);
|
|
|
|
mul_v3_fl(dv2, mul * (tlen - key->length));
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2018-06-15 10:22:44 +02:00
|
|
|
if (k) {
|
2018-08-14 10:02:43 +10:00
|
|
|
add_v3_v3((key - 1)->co, dv1);
|
2018-06-15 10:22:44 +02:00
|
|
|
}
|
|
|
|
add_v3_v3v3(dv1, dv0, dv2);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-15 10:22:44 +02:00
|
|
|
|
|
|
|
/* try to find a nice solution to keep distances between neighboring keys */
|
|
|
|
static void pe_iterate_lengths(Scene *scene, PTCacheEdit *edit)
|
|
|
|
{
|
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
2018-08-14 10:02:43 +10:00
|
|
|
if (edit == 0 || (pset->flag & PE_KEEP_LENGTHS) == 0) {
|
2018-06-15 10:22:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IterateLengthsIterData iter_data;
|
|
|
|
iter_data.edit = edit;
|
|
|
|
iter_data.pset = pset;
|
|
|
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC;
|
|
|
|
BLI_task_parallel_range(0, edit->totpoint, &iter_data, iterate_lengths_iter, &settings);
|
|
|
|
}
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* set current distances to be kept between neighbouting keys */
|
|
|
|
void recalc_lengths(PTCacheEdit *edit)
|
|
|
|
{
|
|
|
|
POINT_P; KEY_K;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (edit == 0)
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
LOOP_EDITED_POINTS {
|
2018-08-14 10:00:15 +10:00
|
|
|
key = point->keys;
|
|
|
|
for (k = 0; k < point->totkey - 1; k++, key++) {
|
|
|
|
key->length = len_v3v3(key->co, (key + 1)->co);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate a tree for finding nearest emitter's vertice */
|
2018-06-19 15:25:48 +02:00
|
|
|
void recalc_emitter_field(Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), ParticleSystem *psys)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-05-15 16:15:13 +02:00
|
|
|
PTCacheEdit *edit = psys->edit;
|
2018-06-19 15:25:48 +02:00
|
|
|
Mesh *mesh = edit->psmd_eval->mesh_final;
|
2016-12-28 17:30:58 +01:00
|
|
|
float *vec, *nor;
|
|
|
|
int i, totface /*, totvert*/;
|
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
if (!mesh)
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (edit->emitter_cosnos)
|
|
|
|
MEM_freeN(edit->emitter_cosnos);
|
|
|
|
|
|
|
|
BLI_kdtree_free(edit->emitter_field);
|
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
totface = mesh->totface;
|
2018-09-27 15:49:59 +02:00
|
|
|
/*totvert=dm->getNumVerts(dm);*/ /*UNUSED*/
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->emitter_cosnos = MEM_callocN(totface * 6 * sizeof(float), "emitter cosnos");
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->emitter_field = BLI_kdtree_new(totface);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
vec = edit->emitter_cosnos;
|
|
|
|
nor = vec + 3;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (i = 0; i < totface; i++, vec += 6, nor += 6) {
|
2018-05-15 13:26:40 +02:00
|
|
|
MFace *mface = &mesh->mface[i];
|
2016-12-28 17:30:58 +01:00
|
|
|
MVert *mvert;
|
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
mvert = &mesh->mvert[mface->v1];
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v3_v3(vec, mvert->co);
|
2019-01-20 16:22:55 +01:00
|
|
|
copy_v3fl_v3s(nor, mvert->no);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
mvert = &mesh->mvert[mface->v2];
|
2016-12-28 17:30:58 +01:00
|
|
|
add_v3_v3v3(vec, vec, mvert->co);
|
2019-01-20 16:22:55 +01:00
|
|
|
add_v3fl_v3fl_v3s(nor, nor, mvert->no);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
mvert = &mesh->mvert[mface->v3];
|
2016-12-28 17:30:58 +01:00
|
|
|
add_v3_v3v3(vec, vec, mvert->co);
|
2019-01-20 16:22:55 +01:00
|
|
|
add_v3fl_v3fl_v3s(nor, nor, mvert->no);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (mface->v4) {
|
2018-05-15 13:26:40 +02:00
|
|
|
mvert = &mesh->mvert[mface->v4];
|
2016-12-28 17:30:58 +01:00
|
|
|
add_v3_v3v3(vec, vec, mvert->co);
|
2019-01-20 16:22:55 +01:00
|
|
|
add_v3fl_v3fl_v3s(nor, nor, mvert->no);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_v3_fl(vec, 0.25);
|
|
|
|
}
|
2019-01-20 16:22:55 +01:00
|
|
|
else {
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_v3_fl(vec, 1.0f / 3.0f);
|
2019-01-20 16:22:55 +01:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
normalize_v3(nor);
|
|
|
|
|
|
|
|
BLI_kdtree_insert(edit->emitter_field, i, vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_kdtree_balance(edit->emitter_field);
|
|
|
|
}
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
static void PE_update_selection(Depsgraph *depsgraph, Scene *scene, Object *ob, int useflag)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-04-01 11:03:25 +02:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
HairKey *hkey;
|
|
|
|
POINT_P; KEY_K;
|
|
|
|
|
|
|
|
/* flag all particles to be updated if not using flag */
|
|
|
|
if (!useflag)
|
2018-08-14 10:14:05 +10:00
|
|
|
LOOP_POINTS {
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-04 09:31:30 +02:00
|
|
|
/* flush edit key flag to hair key flag to preserve selection
|
2016-12-28 17:30:58 +01:00
|
|
|
* on save */
|
2018-08-14 10:14:05 +10:00
|
|
|
if (edit->psys) {
|
|
|
|
LOOP_POINTS {
|
2018-08-14 10:00:15 +10:00
|
|
|
hkey = edit->psys->particles[p].hair;
|
|
|
|
LOOP_KEYS {
|
|
|
|
hkey->editflag = key->flag;
|
|
|
|
hkey++;
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2018-08-14 10:14:05 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
psys_cache_edit_paths(depsgraph, scene, ob, edit, CFRA, G.is_rendering);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* disable update flag */
|
2018-08-14 10:14:05 +10:00
|
|
|
LOOP_POINTS {
|
2016-12-28 17:30:58 +01:00
|
|
|
point->flag &= ~PEP_EDIT_RECALC;
|
2018-08-14 10:14:05 +10:00
|
|
|
}
|
2018-05-09 14:08:44 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_SELECT);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
2018-06-06 15:48:30 +02:00
|
|
|
void update_world_cos(Depsgraph *UNUSED(depsgraph), Object *ob, PTCacheEdit *edit)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
ParticleSystem *psys = edit->psys;
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval = edit->psmd_eval;
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P; KEY_K;
|
|
|
|
float hairmat[4][4];
|
|
|
|
|
2018-06-19 15:25:48 +02:00
|
|
|
if (psys == 0 || psys->edit == 0 || psmd_eval->mesh_final == NULL)
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
LOOP_POINTS {
|
|
|
|
if (!(psys->flag & PSYS_GLOBAL_HAIR))
|
2018-08-14 10:02:43 +10:00
|
|
|
psys_mat_hair_to_global(ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, hairmat);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
LOOP_KEYS {
|
|
|
|
copy_v3_v3(key->world_co, key->co);
|
|
|
|
if (!(psys->flag & PSYS_GLOBAL_HAIR))
|
|
|
|
mul_m4_v3(hairmat, key->world_co);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void update_velocities(PTCacheEdit *edit)
|
|
|
|
{
|
|
|
|
/*TODO: get frs_sec properly */
|
|
|
|
float vec1[3], vec2[3], frs_sec, dfra;
|
|
|
|
POINT_P; KEY_K;
|
|
|
|
|
|
|
|
/* hair doesn't use velocities */
|
|
|
|
if (edit->psys || !edit->points || !edit->points->keys->vel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
frs_sec = edit->pid.flag & PTCACHE_VEL_PER_SEC ? 25.0f : 1.0f;
|
|
|
|
|
|
|
|
LOOP_EDITED_POINTS {
|
|
|
|
LOOP_KEYS {
|
2018-08-14 10:00:15 +10:00
|
|
|
if (k == 0) {
|
|
|
|
dfra = *(key + 1)->time - *key->time;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (dfra <= 0.0f)
|
|
|
|
continue;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
sub_v3_v3v3(key->vel, (key + 1)->co, key->co);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (point->totkey > 2) {
|
|
|
|
sub_v3_v3v3(vec1, (key + 1)->co, (key + 2)->co);
|
2016-12-28 17:30:58 +01:00
|
|
|
project_v3_v3v3(vec2, vec1, key->vel);
|
|
|
|
sub_v3_v3v3(vec2, vec1, vec2);
|
|
|
|
madd_v3_v3fl(key->vel, vec2, 0.5f);
|
|
|
|
}
|
|
|
|
}
|
2018-08-14 10:00:15 +10:00
|
|
|
else if (k == point->totkey - 1) {
|
|
|
|
dfra = *key->time - *(key - 1)->time;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (dfra <= 0.0f)
|
|
|
|
continue;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
sub_v3_v3v3(key->vel, key->co, (key - 1)->co);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (point->totkey > 2) {
|
|
|
|
sub_v3_v3v3(vec1, (key - 2)->co, (key - 1)->co);
|
2016-12-28 17:30:58 +01:00
|
|
|
project_v3_v3v3(vec2, vec1, key->vel);
|
|
|
|
sub_v3_v3v3(vec2, vec1, vec2);
|
|
|
|
madd_v3_v3fl(key->vel, vec2, 0.5f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2018-08-14 10:00:15 +10:00
|
|
|
dfra = *(key + 1)->time - *(key - 1)->time;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (dfra <= 0.0f)
|
|
|
|
continue;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
sub_v3_v3v3(key->vel, (key + 1)->co, (key - 1)->co);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2018-08-14 10:00:15 +10:00
|
|
|
mul_v3_fl(key->vel, frs_sec / dfra);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int useflag)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
/* use this to do partial particle updates, not usable when adding or
|
|
|
|
* removing, then a full redo is necessary and calling this may crash */
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
2009-09-16 17:43:09 +00:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P;
|
|
|
|
|
|
|
|
if (!edit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* flag all particles to be updated if not using flag */
|
|
|
|
if (!useflag)
|
|
|
|
LOOP_POINTS {
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
/* do post process on particle edit keys */
|
|
|
|
pe_iterate_lengths(scene, edit);
|
2016-12-28 17:30:58 +01:00
|
|
|
pe_deflect_emitter(scene, ob, edit);
|
|
|
|
PE_apply_lengths(scene, edit);
|
|
|
|
if (pe_x_mirror(ob))
|
|
|
|
PE_apply_mirror(ob, edit->psys);
|
|
|
|
if (edit->psys)
|
2018-05-11 12:44:43 +02:00
|
|
|
update_world_cos(depsgraph, ob, edit);
|
2016-12-28 17:30:58 +01:00
|
|
|
if (pset->flag & PE_AUTO_VELOCITY)
|
|
|
|
update_velocities(edit);
|
|
|
|
PE_hide_keys_time(scene, edit, CFRA);
|
|
|
|
|
|
|
|
/* regenerate path caches */
|
2018-04-06 12:07:27 +02:00
|
|
|
psys_cache_edit_paths(depsgraph, scene, ob, edit, CFRA, G.is_rendering);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* disable update flag */
|
|
|
|
LOOP_POINTS {
|
|
|
|
point->flag &= ~PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edit->psys)
|
|
|
|
edit->psys->flag &= ~PSYS_HAIR_UPDATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************/
|
|
|
|
/* Edit Selections */
|
|
|
|
/************************************************/
|
|
|
|
|
|
|
|
/*-----selection callbacks-----*/
|
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
static void select_key(PEData *data, int point_index, int key_index, bool UNUSED(is_inside))
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
PTCacheEditPoint *point = edit->points + point_index;
|
|
|
|
PTCacheEditKey *key = point->keys + key_index;
|
|
|
|
|
|
|
|
if (data->select)
|
|
|
|
key->flag |= PEK_SELECT;
|
|
|
|
else
|
|
|
|
key->flag &= ~PEK_SELECT;
|
|
|
|
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
2019-03-01 23:09:22 +11:00
|
|
|
data->is_changed = true;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
static void select_key_op(PEData *data, int point_index, int key_index, bool is_inside)
|
|
|
|
{
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
PTCacheEditPoint *point = edit->points + point_index;
|
|
|
|
PTCacheEditKey *key = point->keys + key_index;
|
|
|
|
const bool is_select = key->flag & PEK_SELECT;
|
|
|
|
const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
|
|
|
|
if (sel_op_result != -1) {
|
|
|
|
SET_FLAG_FROM_TEST(key->flag, sel_op_result, PEK_SELECT);
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void select_keys(PEData *data, int point_index, int UNUSED(key_index), bool UNUSED(is_inside))
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
PTCacheEditPoint *point = edit->points + point_index;
|
|
|
|
KEY_K;
|
|
|
|
|
|
|
|
LOOP_KEYS {
|
|
|
|
if (data->select)
|
|
|
|
key->flag |= PEK_SELECT;
|
|
|
|
else
|
|
|
|
key->flag &= ~PEK_SELECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
static void extend_key_select(PEData *data, int point_index, int key_index, bool UNUSED(is_inside))
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
PTCacheEditPoint *point = edit->points + point_index;
|
|
|
|
PTCacheEditKey *key = point->keys + key_index;
|
|
|
|
|
|
|
|
key->flag |= PEK_SELECT;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
static void deselect_key_select(PEData *data, int point_index, int key_index, bool UNUSED(is_inside))
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
PTCacheEditPoint *point = edit->points + point_index;
|
|
|
|
PTCacheEditKey *key = point->keys + key_index;
|
|
|
|
|
|
|
|
key->flag &= ~PEK_SELECT;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
static void toggle_key_select(PEData *data, int point_index, int key_index, bool UNUSED(is_inside))
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
PTCacheEditPoint *point = edit->points + point_index;
|
|
|
|
PTCacheEditKey *key = point->keys + key_index;
|
|
|
|
|
|
|
|
key->flag ^= PEK_SELECT;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************ de select all operator ************************/
|
|
|
|
|
|
|
|
static void select_action_apply(PTCacheEditPoint *point, PTCacheEditKey *key, int action)
|
|
|
|
{
|
|
|
|
switch (action) {
|
2018-04-16 17:08:27 +02:00
|
|
|
case SEL_SELECT:
|
|
|
|
if ((key->flag & PEK_SELECT) == 0) {
|
|
|
|
key->flag |= PEK_SELECT;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SEL_DESELECT:
|
|
|
|
if (key->flag & PEK_SELECT) {
|
|
|
|
key->flag &= ~PEK_SELECT;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SEL_INVERT:
|
|
|
|
if ((key->flag & PEK_SELECT) == 0) {
|
|
|
|
key->flag |= PEK_SELECT;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
key->flag &= ~PEK_SELECT;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
break;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pe_select_all_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2018-08-14 10:00:15 +10:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2018-08-14 10:02:43 +10:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P; KEY_K;
|
|
|
|
int action = RNA_enum_get(op->ptr, "action");
|
|
|
|
|
|
|
|
if (action == SEL_TOGGLE) {
|
|
|
|
action = SEL_SELECT;
|
|
|
|
LOOP_VISIBLE_POINTS {
|
|
|
|
LOOP_SELECTED_KEYS {
|
|
|
|
action = SEL_DESELECT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action == SEL_DESELECT)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LOOP_VISIBLE_POINTS {
|
|
|
|
LOOP_VISIBLE_KEYS {
|
|
|
|
select_action_apply(point, key, action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_selection(depsgraph, scene, ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_select_all(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "(De)select All";
|
|
|
|
ot->idname = "PARTICLE_OT_select_all";
|
|
|
|
ot->description = "(De)select all particles' keys";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = pe_select_all_exec;
|
|
|
|
ot->poll = PE_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
WM_operator_properties_select_all(ot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************ pick select operator ************************/
|
|
|
|
|
|
|
|
int PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle)
|
|
|
|
{
|
|
|
|
PEData data;
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
2018-08-14 10:02:43 +10:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P; KEY_K;
|
2017-07-21 11:53:13 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (!PE_start_edit(edit))
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
if (!extend && !deselect && !toggle) {
|
|
|
|
LOOP_VISIBLE_POINTS {
|
|
|
|
LOOP_SELECTED_KEYS {
|
|
|
|
key->flag &= ~PEK_SELECT;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PE_set_view3d_data(C, &data);
|
2018-08-14 10:00:15 +10:00
|
|
|
data.mval = mval;
|
2016-12-28 17:30:58 +01:00
|
|
|
data.rad = ED_view3d_select_dist_px();
|
|
|
|
|
|
|
|
/* 1 = nearest only */
|
2018-08-14 10:28:41 +10:00
|
|
|
if (extend) {
|
|
|
|
for_mouse_hit_keys(&data, extend_key_select, PSEL_NEAREST);
|
|
|
|
}
|
|
|
|
else if (deselect) {
|
|
|
|
for_mouse_hit_keys(&data, deselect_key_select, PSEL_NEAREST);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for_mouse_hit_keys(&data, toggle_key_select, PSEL_NEAREST);
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_selection(data.depsgraph, scene, ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, data.ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************ select root operator ************************/
|
|
|
|
|
|
|
|
static void select_root(PEData *data, int point_index)
|
|
|
|
{
|
|
|
|
PTCacheEditPoint *point = data->edit->points + point_index;
|
|
|
|
PTCacheEditKey *key = point->keys;
|
|
|
|
|
|
|
|
if (point->flag & PEP_HIDE)
|
|
|
|
return;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (data->select_action != SEL_TOGGLE)
|
|
|
|
select_action_apply(point, key, data->select_action);
|
|
|
|
else if (key->flag & PEK_SELECT)
|
|
|
|
data->select_toggle_action = SEL_DESELECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int select_roots_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
PEData data;
|
|
|
|
int action = RNA_enum_get(op->ptr, "action");
|
|
|
|
|
|
|
|
PE_set_data(C, &data);
|
|
|
|
|
|
|
|
if (action == SEL_TOGGLE) {
|
|
|
|
data.select_action = SEL_TOGGLE;
|
|
|
|
data.select_toggle_action = SEL_SELECT;
|
|
|
|
|
|
|
|
foreach_point(&data, select_root);
|
|
|
|
|
|
|
|
action = data.select_toggle_action;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.select_action = action;
|
|
|
|
foreach_point(&data, select_root);
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_selection(data.depsgraph, data.scene, data.ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, data.ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_select_roots(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Select Roots";
|
|
|
|
ot->idname = "PARTICLE_OT_select_roots";
|
|
|
|
ot->description = "Select roots of all visible particles";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = select_roots_exec;
|
|
|
|
ot->poll = PE_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* properties */
|
|
|
|
WM_operator_properties_select_action(ot, SEL_SELECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************ select tip operator ************************/
|
|
|
|
|
|
|
|
static void select_tip(PEData *data, int point_index)
|
|
|
|
{
|
|
|
|
PTCacheEditPoint *point = data->edit->points + point_index;
|
|
|
|
PTCacheEditKey *key;
|
|
|
|
|
|
|
|
if (point->totkey == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
key = &point->keys[point->totkey - 1];
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (point->flag & PEP_HIDE)
|
|
|
|
return;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (data->select_action != SEL_TOGGLE)
|
|
|
|
select_action_apply(point, key, data->select_action);
|
|
|
|
else if (key->flag & PEK_SELECT)
|
|
|
|
data->select_toggle_action = SEL_DESELECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int select_tips_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
PEData data;
|
|
|
|
int action = RNA_enum_get(op->ptr, "action");
|
|
|
|
|
|
|
|
PE_set_data(C, &data);
|
|
|
|
|
|
|
|
if (action == SEL_TOGGLE) {
|
|
|
|
data.select_action = SEL_TOGGLE;
|
|
|
|
data.select_toggle_action = SEL_SELECT;
|
|
|
|
|
|
|
|
foreach_point(&data, select_tip);
|
|
|
|
|
|
|
|
action = data.select_toggle_action;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.select_action = action;
|
|
|
|
foreach_point(&data, select_tip);
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_selection(data.depsgraph, data.scene, data.ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, data.ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_select_tips(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Select Tips";
|
|
|
|
ot->idname = "PARTICLE_OT_select_tips";
|
|
|
|
ot->description = "Select tips of all visible particles";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = select_tips_exec;
|
|
|
|
ot->poll = PE_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* properties */
|
|
|
|
WM_operator_properties_select_action(ot, SEL_SELECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************** select random operator ************************/
|
|
|
|
|
|
|
|
enum { RAN_HAIR, RAN_POINTS };
|
|
|
|
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem select_random_type_items[] = {
|
2016-12-28 17:30:58 +01:00
|
|
|
{RAN_HAIR, "HAIR", 0, "Hair", ""},
|
|
|
|
{RAN_POINTS, "POINTS", 0, "Points", ""},
|
2019-02-03 14:01:45 +11:00
|
|
|
{0, NULL, 0, NULL, NULL},
|
2016-12-28 17:30:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static int select_random_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
PEData data;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
/* used by LOOP_VISIBLE_POINTS, LOOP_VISIBLE_KEYS and LOOP_KEYS */
|
|
|
|
PTCacheEdit *edit;
|
|
|
|
PTCacheEditPoint *point;
|
|
|
|
PTCacheEditKey *key;
|
|
|
|
int p;
|
|
|
|
int k;
|
|
|
|
|
|
|
|
const float randfac = RNA_float_get(op->ptr, "percent") / 100.0f;
|
|
|
|
const int seed = WM_operator_properties_select_random_seed_increment_get(op);
|
|
|
|
const bool select = (RNA_enum_get(op->ptr, "action") == SEL_SELECT);
|
|
|
|
RNG *rng;
|
|
|
|
|
|
|
|
type = RNA_enum_get(op->ptr, "type");
|
|
|
|
|
|
|
|
PE_set_data(C, &data);
|
|
|
|
data.select_action = SEL_SELECT;
|
2018-06-13 15:36:24 +02:00
|
|
|
edit = PE_get_current(data.scene, data.ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
rng = BLI_rng_new_srandom(seed);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case RAN_HAIR:
|
|
|
|
LOOP_VISIBLE_POINTS {
|
|
|
|
int flag = ((BLI_rng_get_float(rng) < randfac) == select) ? SEL_SELECT : SEL_DESELECT;
|
|
|
|
LOOP_KEYS {
|
2018-08-14 10:00:15 +10:00
|
|
|
select_action_apply(point, key, flag);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RAN_POINTS:
|
|
|
|
LOOP_VISIBLE_POINTS {
|
|
|
|
LOOP_VISIBLE_KEYS {
|
|
|
|
int flag = ((BLI_rng_get_float(rng) < randfac) == select) ? SEL_SELECT : SEL_DESELECT;
|
2018-08-14 10:00:15 +10:00
|
|
|
select_action_apply(point, key, flag);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_rng_free(rng);
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_selection(data.depsgraph, data.scene, data.ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, data.ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_select_random(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Select Random";
|
|
|
|
ot->idname = "PARTICLE_OT_select_random";
|
|
|
|
ot->description = "Select a randomly distributed set of hair or points";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = select_random_exec;
|
|
|
|
ot->poll = PE_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* properties */
|
|
|
|
WM_operator_properties_select_random(ot);
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->prop = RNA_def_enum(ot->srna, "type", select_random_type_items, RAN_HAIR,
|
|
|
|
"Type", "Select either hair or points");
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ select linked operator ************************/
|
|
|
|
|
|
|
|
static int select_linked_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
PEData data;
|
|
|
|
int mval[2];
|
|
|
|
int location[2];
|
|
|
|
|
|
|
|
RNA_int_get_array(op->ptr, "location", location);
|
|
|
|
mval[0] = location[0];
|
|
|
|
mval[1] = location[1];
|
|
|
|
|
|
|
|
PE_set_view3d_data(C, &data);
|
2018-08-14 10:00:15 +10:00
|
|
|
data.mval = mval;
|
|
|
|
data.rad = 75.0f;
|
|
|
|
data.select = !RNA_boolean_get(op->ptr, "deselect");
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
for_mouse_hit_keys(&data, select_keys, PSEL_NEAREST);
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_selection(data.depsgraph, data.scene, data.ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, data.ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int select_linked_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
{
|
|
|
|
RNA_int_set_array(op->ptr, "location", event->mval);
|
|
|
|
return select_linked_exec(C, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_select_linked(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Select Linked";
|
|
|
|
ot->idname = "PARTICLE_OT_select_linked";
|
|
|
|
ot->description = "Select nearest particle from mouse pointer";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = select_linked_exec;
|
|
|
|
ot->invoke = select_linked_invoke;
|
|
|
|
ot->poll = PE_poll_view3d;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* properties */
|
|
|
|
RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Deselect linked keys rather than selecting them");
|
|
|
|
RNA_def_int_vector(ot->srna, "location", 2, NULL, 0, INT_MAX, "Location", "", 0, 16384);
|
|
|
|
}
|
|
|
|
|
2018-10-05 10:27:04 +10:00
|
|
|
/************************ box select operator ************************/
|
2016-12-28 17:30:58 +01:00
|
|
|
void PE_deselect_all_visible(PTCacheEdit *edit)
|
|
|
|
{
|
|
|
|
POINT_P; KEY_K;
|
|
|
|
|
|
|
|
LOOP_VISIBLE_POINTS {
|
|
|
|
LOOP_SELECTED_KEYS {
|
|
|
|
key->flag &= ~PEK_SELECT;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 10:27:04 +10:00
|
|
|
int PE_box_select(bContext *C, const rcti *rect, const int sel_op)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
2018-08-14 10:02:43 +10:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
PEData data;
|
|
|
|
|
|
|
|
if (!PE_start_edit(edit))
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
PE_deselect_all_visible(edit);
|
2018-08-14 10:28:41 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
PE_set_view3d_data(C, &data);
|
2018-08-14 10:00:15 +10:00
|
|
|
data.rect = rect;
|
2018-08-14 10:28:41 +10:00
|
|
|
data.sel_op = sel_op;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
for_mouse_hit_keys(&data, select_key_op, PSEL_ALL_KEYS);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_selection(data.depsgraph, scene, ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************ circle select operator ************************/
|
|
|
|
|
2019-03-01 23:09:22 +11:00
|
|
|
bool PE_circle_select(bContext *C, const int sel_op, const int mval[2], float rad)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2019-03-01 23:09:22 +11:00
|
|
|
BLI_assert(ELEM(sel_op, SEL_OP_SET, SEL_OP_ADD, SEL_OP_SUB));
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
2018-08-14 10:02:43 +10:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
PEData data;
|
|
|
|
|
2019-03-01 23:09:22 +11:00
|
|
|
if (!PE_start_edit(edit)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool changed = false;
|
|
|
|
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
|
|
|
PE_deselect_all_visible(edit);
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
const bool select = (sel_op != SEL_OP_SUB);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
PE_set_view3d_data(C, &data);
|
2018-08-14 10:00:15 +10:00
|
|
|
data.mval = mval;
|
|
|
|
data.rad = rad;
|
2019-03-01 23:09:22 +11:00
|
|
|
data.select = select;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
for_mouse_hit_keys(&data, select_key, 0);
|
2019-03-01 23:09:22 +11:00
|
|
|
changed |= data.is_changed;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2019-03-01 23:09:22 +11:00
|
|
|
if (changed) {
|
|
|
|
PE_update_selection(data.depsgraph, scene, ob, 1);
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, ob);
|
|
|
|
}
|
|
|
|
return changed;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ lasso select operator ************************/
|
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, const int sel_op)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
2009-09-16 17:43:09 +00:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSystem *psys = edit->psys;
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval = edit->psmd_eval;
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P; KEY_K;
|
|
|
|
float co[3], mat[4][4];
|
|
|
|
int screen_co[2];
|
|
|
|
|
|
|
|
PEData data;
|
|
|
|
|
|
|
|
unit_m4(mat);
|
|
|
|
|
|
|
|
if (!PE_start_edit(edit))
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
PE_deselect_all_visible(edit);
|
2018-08-14 10:28:41 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* only for depths */
|
|
|
|
PE_set_view3d_data(C, &data);
|
|
|
|
|
|
|
|
LOOP_VISIBLE_POINTS {
|
|
|
|
if (edit->psys && !(psys->flag & PSYS_GLOBAL_HAIR))
|
2018-06-19 15:25:48 +02:00
|
|
|
psys_mat_hair_to_global(ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, mat);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (pset->selectmode == SCE_SELECT_POINT) {
|
2016-12-28 17:30:58 +01:00
|
|
|
LOOP_KEYS {
|
|
|
|
copy_v3_v3(co, key->co);
|
|
|
|
mul_m4_v3(mat, co);
|
2018-08-14 10:28:41 +10:00
|
|
|
const bool is_select = key->flag & PEK_SELECT;
|
|
|
|
const bool is_inside = (
|
|
|
|
(ED_view3d_project_int_global(ar, co, screen_co, V3D_PROJ_TEST_CLIP_WIN) == V3D_PROJ_RET_OK) &&
|
|
|
|
BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], IS_CLIPPED) &&
|
|
|
|
key_test_depth(&data, co, screen_co));
|
|
|
|
const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
|
|
|
|
if (sel_op_result != -1) {
|
|
|
|
SET_FLAG_FROM_TEST(key->flag, sel_op_result, PEK_SELECT);
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-14 10:00:15 +10:00
|
|
|
else if (pset->selectmode == SCE_SELECT_END) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (point->totkey) {
|
2018-08-14 10:00:15 +10:00
|
|
|
key = point->keys + point->totkey - 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v3_v3(co, key->co);
|
|
|
|
mul_m4_v3(mat, co);
|
2018-08-14 10:28:41 +10:00
|
|
|
const bool is_select = key->flag & PEK_SELECT;
|
|
|
|
const bool is_inside = (
|
|
|
|
(ED_view3d_project_int_global(ar, co, screen_co, V3D_PROJ_TEST_CLIP_WIN) == V3D_PROJ_RET_OK) &&
|
|
|
|
BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], IS_CLIPPED) &&
|
|
|
|
key_test_depth(&data, co, screen_co));
|
|
|
|
const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
|
|
|
|
if (sel_op_result != -1) {
|
|
|
|
SET_FLAG_FROM_TEST(key->flag, sel_op_result, PEK_SELECT);
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_selection(data.depsgraph, scene, ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************** hide operator **************************/
|
|
|
|
|
|
|
|
static int hide_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2018-03-19 19:03:18 +01:00
|
|
|
|
2018-08-14 10:02:43 +10:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P; KEY_K;
|
2018-03-19 19:03:18 +01:00
|
|
|
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (RNA_enum_get(op->ptr, "unselected")) {
|
|
|
|
LOOP_UNSELECTED_POINTS {
|
|
|
|
point->flag |= PEP_HIDE;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
|
2018-08-14 10:14:05 +10:00
|
|
|
LOOP_KEYS {
|
|
|
|
key->flag &= ~PEK_SELECT;
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOOP_SELECTED_POINTS {
|
|
|
|
point->flag |= PEP_HIDE;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
|
2018-08-14 10:14:05 +10:00
|
|
|
LOOP_KEYS {
|
|
|
|
key->flag &= ~PEK_SELECT;
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_selection(depsgraph, scene, ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_hide(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Hide Selected";
|
|
|
|
ot->idname = "PARTICLE_OT_hide";
|
|
|
|
ot->description = "Hide selected particles";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = hide_exec;
|
|
|
|
ot->poll = PE_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* props */
|
|
|
|
RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************** reveal operator **************************/
|
|
|
|
|
2017-11-20 02:28:07 +11:00
|
|
|
static int reveal_exec(bContext *C, wmOperator *op)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2018-08-14 10:02:43 +10:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2017-11-20 02:28:07 +11:00
|
|
|
const bool select = RNA_boolean_get(op->ptr, "select");
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P; KEY_K;
|
|
|
|
|
|
|
|
LOOP_POINTS {
|
|
|
|
if (point->flag & PEP_HIDE) {
|
|
|
|
point->flag &= ~PEP_HIDE;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
|
2017-11-20 02:28:07 +11:00
|
|
|
LOOP_KEYS {
|
|
|
|
SET_FLAG_FROM_TEST(key->flag, select, PEK_SELECT);
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_selection(depsgraph, scene, ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_reveal(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Reveal";
|
|
|
|
ot->idname = "PARTICLE_OT_reveal";
|
|
|
|
ot->description = "Show hidden particles";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = reveal_exec;
|
|
|
|
ot->poll = PE_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2017-11-20 02:28:07 +11:00
|
|
|
|
|
|
|
/* props */
|
|
|
|
RNA_def_boolean(ot->srna, "select", true, "Select", "");
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ select less operator ************************/
|
|
|
|
|
|
|
|
static void select_less_keys(PEData *data, int point_index)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
PTCacheEdit *edit = data->edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
PTCacheEditPoint *point = edit->points + point_index;
|
|
|
|
KEY_K;
|
|
|
|
|
|
|
|
LOOP_SELECTED_KEYS {
|
2018-08-14 10:00:15 +10:00
|
|
|
if (k == 0) {
|
|
|
|
if (((key + 1)->flag & PEK_SELECT) == 0)
|
2016-12-28 17:30:58 +01:00
|
|
|
key->flag |= PEK_TAG;
|
|
|
|
}
|
2018-08-14 10:00:15 +10:00
|
|
|
else if (k == point->totkey - 1) {
|
|
|
|
if (((key - 1)->flag & PEK_SELECT) == 0)
|
2016-12-28 17:30:58 +01:00
|
|
|
key->flag |= PEK_TAG;
|
|
|
|
}
|
|
|
|
else {
|
2018-08-14 10:00:15 +10:00
|
|
|
if ((((key - 1)->flag & (key + 1)->flag) & PEK_SELECT) == 0)
|
2016-12-28 17:30:58 +01:00
|
|
|
key->flag |= PEK_TAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LOOP_KEYS {
|
2018-08-14 10:00:15 +10:00
|
|
|
if (key->flag & PEK_TAG) {
|
|
|
|
key->flag &= ~(PEK_TAG | PEK_SELECT);
|
2016-12-28 17:30:58 +01:00
|
|
|
point->flag |= PEP_EDIT_RECALC; /* redraw selection only */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int select_less_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PEData data;
|
|
|
|
|
|
|
|
PE_set_data(C, &data);
|
|
|
|
foreach_point(&data, select_less_keys);
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_selection(data.depsgraph, data.scene, data.ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, data.ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_select_less(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Select Less";
|
|
|
|
ot->idname = "PARTICLE_OT_select_less";
|
|
|
|
ot->description = "Deselect boundary selected keys of each particle";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = select_less_exec;
|
|
|
|
ot->poll = PE_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ select more operator ************************/
|
|
|
|
|
|
|
|
static void select_more_keys(PEData *data, int point_index)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
PTCacheEdit *edit = data->edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
PTCacheEditPoint *point = edit->points + point_index;
|
|
|
|
KEY_K;
|
|
|
|
|
|
|
|
LOOP_KEYS {
|
|
|
|
if (key->flag & PEK_SELECT) continue;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (k == 0) {
|
|
|
|
if ((key + 1)->flag & PEK_SELECT)
|
2016-12-28 17:30:58 +01:00
|
|
|
key->flag |= PEK_TAG;
|
|
|
|
}
|
2018-08-14 10:00:15 +10:00
|
|
|
else if (k == point->totkey - 1) {
|
|
|
|
if ((key - 1)->flag & PEK_SELECT)
|
2016-12-28 17:30:58 +01:00
|
|
|
key->flag |= PEK_TAG;
|
|
|
|
}
|
|
|
|
else {
|
2018-08-14 10:00:15 +10:00
|
|
|
if (((key - 1)->flag | (key + 1)->flag) & PEK_SELECT)
|
2016-12-28 17:30:58 +01:00
|
|
|
key->flag |= PEK_TAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LOOP_KEYS {
|
2018-08-14 10:00:15 +10:00
|
|
|
if (key->flag & PEK_TAG) {
|
2016-12-28 17:30:58 +01:00
|
|
|
key->flag &= ~PEK_TAG;
|
|
|
|
key->flag |= PEK_SELECT;
|
|
|
|
point->flag |= PEP_EDIT_RECALC; /* redraw selection only */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int select_more_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PEData data;
|
|
|
|
|
|
|
|
PE_set_data(C, &data);
|
|
|
|
foreach_point(&data, select_more_keys);
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_selection(data.depsgraph, data.scene, data.ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_SELECTED, data.ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_select_more(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Select More";
|
|
|
|
ot->idname = "PARTICLE_OT_select_more";
|
|
|
|
ot->description = "Select keys linked to boundary selected keys of each particle";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = select_more_exec;
|
|
|
|
ot->poll = PE_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ rekey operator ************************/
|
|
|
|
|
|
|
|
static void rekey_particle(PEData *data, int pa_index)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
ParticleSystem *psys = edit->psys;
|
|
|
|
ParticleSimulationData sim = {0};
|
|
|
|
ParticleData *pa = psys->particles + pa_index;
|
2016-12-28 17:30:58 +01:00
|
|
|
PTCacheEditPoint *point = edit->points + pa_index;
|
|
|
|
ParticleKey state;
|
|
|
|
HairKey *key, *new_keys, *okey;
|
|
|
|
PTCacheEditKey *ekey;
|
|
|
|
float dval, sta, end;
|
|
|
|
int k;
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
sim.depsgraph = data->depsgraph;
|
2017-07-21 11:53:13 +02:00
|
|
|
sim.scene = data->scene;
|
|
|
|
sim.ob = data->ob;
|
|
|
|
sim.psys = edit->psys;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
pa->flag |= PARS_REKEY;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
key = new_keys = MEM_callocN(data->totrekey * sizeof(HairKey), "Hair re-key keys");
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
okey = pa->hair;
|
|
|
|
/* root and tip stay the same */
|
|
|
|
copy_v3_v3(key->co, okey->co);
|
|
|
|
copy_v3_v3((key + data->totrekey - 1)->co, (okey + pa->totkey - 1)->co);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
sta = key->time = okey->time;
|
|
|
|
end = (key + data->totrekey - 1)->time = (okey + pa->totkey - 1)->time;
|
|
|
|
dval = (end - sta) / (float)(data->totrekey - 1);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* interpolate new keys from old ones */
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 1, key++; k < data->totrekey - 1; k++, key++) {
|
|
|
|
state.time = (float)k / (float)(data->totrekey - 1);
|
2016-12-28 17:30:58 +01:00
|
|
|
psys_get_particle_on_path(&sim, pa_index, &state, 0);
|
|
|
|
copy_v3_v3(key->co, state.co);
|
2018-08-14 10:00:15 +10:00
|
|
|
key->time = sta + k * dval;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* replace keys */
|
|
|
|
if (pa->hair)
|
|
|
|
MEM_freeN(pa->hair);
|
2018-08-14 10:00:15 +10:00
|
|
|
pa->hair = new_keys;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
point->totkey = pa->totkey = data->totrekey;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (point->keys)
|
|
|
|
MEM_freeN(point->keys);
|
2018-08-14 10:00:15 +10:00
|
|
|
ekey = point->keys = MEM_callocN(pa->totkey * sizeof(PTCacheEditKey), "Hair re-key edit keys");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 0, key = pa->hair; k < pa->totkey; k++, key++, ekey++) {
|
|
|
|
ekey->co = key->co;
|
|
|
|
ekey->time = &key->time;
|
2016-12-28 17:30:58 +01:00
|
|
|
ekey->flag |= PEK_SELECT;
|
|
|
|
if (!(psys->flag & PSYS_GLOBAL_HAIR))
|
|
|
|
ekey->flag |= PEK_USE_WCO;
|
|
|
|
}
|
|
|
|
|
|
|
|
pa->flag &= ~PARS_REKEY;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rekey_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
PEData data;
|
|
|
|
|
|
|
|
PE_set_data(C, &data);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
data.dval = 1.0f / (float)(data.totrekey - 1);
|
|
|
|
data.totrekey = RNA_int_get(op->ptr, "keys_number");
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
foreach_selected_point(&data, rekey_particle);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
recalc_lengths(data.edit);
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_object(data.depsgraph, data.scene, data.ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, data.ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_rekey(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Rekey";
|
|
|
|
ot->idname = "PARTICLE_OT_rekey";
|
|
|
|
ot->description = "Change the number of keys of selected particles (root and tip keys included)";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = rekey_exec;
|
|
|
|
ot->invoke = WM_operator_props_popup;
|
|
|
|
ot->poll = PE_hair_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* properties */
|
|
|
|
RNA_def_int(ot->srna, "keys_number", 2, 2, INT_MAX, "Number of Keys", "", 2, 100);
|
|
|
|
}
|
|
|
|
|
2018-04-01 11:03:25 +02:00
|
|
|
static void rekey_particle_to_time(const bContext *C, Scene *scene, Object *ob, int pa_index, float path_time)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-08-14 10:02:43 +10:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSystem *psys;
|
2017-07-21 11:53:13 +02:00
|
|
|
ParticleSimulationData sim = {0};
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleData *pa;
|
|
|
|
ParticleKey state;
|
|
|
|
HairKey *new_keys, *key;
|
|
|
|
PTCacheEditKey *ekey;
|
|
|
|
int k;
|
|
|
|
|
|
|
|
if (!edit || !edit->psys) return;
|
|
|
|
|
|
|
|
psys = edit->psys;
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
sim.depsgraph = CTX_data_depsgraph(C);
|
2017-07-21 11:53:13 +02:00
|
|
|
sim.scene = scene;
|
|
|
|
sim.ob = ob;
|
|
|
|
sim.psys = psys;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
pa = psys->particles + pa_index;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
pa->flag |= PARS_REKEY;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
key = new_keys = MEM_dupallocN(pa->hair);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* interpolate new keys from old ones (roots stay the same) */
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 1, key++; k < pa->totkey; k++, key++) {
|
|
|
|
state.time = path_time * (float)k / (float)(pa->totkey - 1);
|
2016-12-28 17:30:58 +01:00
|
|
|
psys_get_particle_on_path(&sim, pa_index, &state, 0);
|
|
|
|
copy_v3_v3(key->co, state.co);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* replace hair keys */
|
|
|
|
if (pa->hair)
|
|
|
|
MEM_freeN(pa->hair);
|
2018-08-14 10:00:15 +10:00
|
|
|
pa->hair = new_keys;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* update edit pointers */
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 0, key = pa->hair, ekey = edit->points[pa_index].keys; k < pa->totkey; k++, key++, ekey++) {
|
|
|
|
ekey->co = key->co;
|
|
|
|
ekey->time = &key->time;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pa->flag &= ~PARS_REKEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************* utilities **************************/
|
|
|
|
|
|
|
|
static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror)
|
|
|
|
{
|
|
|
|
PTCacheEdit *edit = psys->edit;
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleData *pa, *npa = 0, *new_pars = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P;
|
2018-08-14 10:00:15 +10:00
|
|
|
PTCacheEditPoint *npoint = 0, *new_points = 0;
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval;
|
2018-08-14 10:00:15 +10:00
|
|
|
int i, new_totpart = psys->totpart, removed = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (mirror) {
|
|
|
|
/* mirror tags */
|
2018-06-19 15:25:48 +02:00
|
|
|
psmd_eval = edit->psmd_eval;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
LOOP_TAGGED_POINTS {
|
2018-06-19 15:25:48 +02:00
|
|
|
PE_mirror_particle(ob, psmd_eval->mesh_final, psys, psys->particles + p, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LOOP_TAGGED_POINTS {
|
|
|
|
new_totpart--;
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_totpart != psys->totpart) {
|
|
|
|
if (new_totpart) {
|
2018-08-14 10:00:15 +10:00
|
|
|
npa = new_pars = MEM_callocN(new_totpart * sizeof(ParticleData), "ParticleData array");
|
|
|
|
npoint = new_points = MEM_callocN(new_totpart * sizeof(PTCacheEditPoint), "PTCacheEditKey array");
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (ELEM(NULL, new_pars, new_points)) {
|
|
|
|
/* allocation error! */
|
|
|
|
if (new_pars)
|
|
|
|
MEM_freeN(new_pars);
|
|
|
|
if (new_points)
|
|
|
|
MEM_freeN(new_points);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
pa = psys->particles;
|
|
|
|
point = edit->points;
|
|
|
|
for (i = 0; i < psys->totpart; i++, pa++, point++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (point->flag & PEP_TAG) {
|
|
|
|
if (point->keys)
|
|
|
|
MEM_freeN(point->keys);
|
|
|
|
if (pa->hair)
|
|
|
|
MEM_freeN(pa->hair);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
memcpy(npa, pa, sizeof(ParticleData));
|
|
|
|
memcpy(npoint, point, sizeof(PTCacheEditPoint));
|
|
|
|
npa++;
|
|
|
|
npoint++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (psys->particles) MEM_freeN(psys->particles);
|
2018-08-14 10:00:15 +10:00
|
|
|
psys->particles = new_pars;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (edit->points) MEM_freeN(edit->points);
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->points = new_points;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (edit->mirror_cache) {
|
|
|
|
MEM_freeN(edit->mirror_cache);
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->mirror_cache = NULL;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (psys->child) {
|
|
|
|
MEM_freeN(psys->child);
|
2018-08-14 10:00:15 +10:00
|
|
|
psys->child = NULL;
|
|
|
|
psys->totchild = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->totpoint = psys->totpart = new_totpart;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_tagged_keys(Object *ob, ParticleSystem *psys)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
PTCacheEdit *edit = psys->edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleData *pa;
|
2018-08-14 10:00:15 +10:00
|
|
|
HairKey *hkey, *nhkey, *new_hkeys = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P; KEY_K;
|
|
|
|
PTCacheEditKey *nkey, *new_keys;
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval;
|
2016-12-28 17:30:58 +01:00
|
|
|
short new_totkey;
|
|
|
|
|
|
|
|
if (pe_x_mirror(ob)) {
|
|
|
|
/* mirror key tags */
|
2018-06-19 15:25:48 +02:00
|
|
|
psmd_eval = psys_get_modifier(ob, psys);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
LOOP_POINTS {
|
|
|
|
LOOP_TAGGED_KEYS {
|
2018-06-19 15:25:48 +02:00
|
|
|
PE_mirror_particle(ob, psmd_eval->mesh_final, psys, psys->particles + p, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LOOP_POINTS {
|
2018-08-14 10:00:15 +10:00
|
|
|
new_totkey = point->totkey;
|
2016-12-28 17:30:58 +01:00
|
|
|
LOOP_TAGGED_KEYS {
|
|
|
|
new_totkey--;
|
|
|
|
}
|
|
|
|
/* we can't have elements with less than two keys*/
|
|
|
|
if (new_totkey < 2)
|
|
|
|
point->flag |= PEP_TAG;
|
|
|
|
}
|
|
|
|
remove_tagged_particles(ob, psys, pe_x_mirror(ob));
|
|
|
|
|
|
|
|
LOOP_POINTS {
|
|
|
|
pa = psys->particles + p;
|
2018-08-14 10:00:15 +10:00
|
|
|
new_totkey = pa->totkey;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
LOOP_TAGGED_KEYS {
|
|
|
|
new_totkey--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_totkey != pa->totkey) {
|
2018-08-14 10:00:15 +10:00
|
|
|
nhkey = new_hkeys = MEM_callocN(new_totkey * sizeof(HairKey), "HairKeys");
|
|
|
|
nkey = new_keys = MEM_callocN(new_totkey * sizeof(PTCacheEditKey), "particle edit keys");
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
hkey = pa->hair;
|
2016-12-28 17:30:58 +01:00
|
|
|
LOOP_KEYS {
|
|
|
|
while (key->flag & PEK_TAG && hkey < pa->hair + pa->totkey) {
|
|
|
|
key++;
|
|
|
|
hkey++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hkey < pa->hair + pa->totkey) {
|
|
|
|
copy_v3_v3(nhkey->co, hkey->co);
|
|
|
|
nhkey->editflag = hkey->editflag;
|
2018-08-14 10:00:15 +10:00
|
|
|
nhkey->time = hkey->time;
|
|
|
|
nhkey->weight = hkey->weight;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
nkey->co = nhkey->co;
|
|
|
|
nkey->time = &nhkey->time;
|
2016-12-28 17:30:58 +01:00
|
|
|
/* these can be copied from old edit keys */
|
|
|
|
nkey->flag = key->flag;
|
|
|
|
nkey->ftime = key->ftime;
|
|
|
|
nkey->length = key->length;
|
|
|
|
copy_v3_v3(nkey->world_co, key->world_co);
|
|
|
|
}
|
|
|
|
nkey++;
|
|
|
|
nhkey++;
|
|
|
|
hkey++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pa->hair)
|
|
|
|
MEM_freeN(pa->hair);
|
|
|
|
|
|
|
|
if (point->keys)
|
|
|
|
MEM_freeN(point->keys);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
pa->hair = new_hkeys;
|
|
|
|
point->keys = new_keys;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
point->totkey = pa->totkey = new_totkey;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* flag for recalculating length */
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************ subdivide opertor *********************/
|
|
|
|
|
|
|
|
/* works like normal edit mode subdivide, inserts keys between neighboring selected keys */
|
|
|
|
static void subdivide_particle(PEData *data, int pa_index)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
ParticleSystem *psys = edit->psys;
|
|
|
|
ParticleSimulationData sim = {0};
|
|
|
|
ParticleData *pa = psys->particles + pa_index;
|
2016-12-28 17:30:58 +01:00
|
|
|
PTCacheEditPoint *point = edit->points + pa_index;
|
|
|
|
ParticleKey state;
|
|
|
|
HairKey *key, *nkey, *new_keys;
|
|
|
|
PTCacheEditKey *ekey, *nekey, *new_ekeys;
|
|
|
|
|
|
|
|
int k;
|
2018-08-14 10:00:15 +10:00
|
|
|
short totnewkey = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
float endtime;
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
sim.depsgraph = data->depsgraph;
|
2017-07-21 11:53:13 +02:00
|
|
|
sim.scene = data->scene;
|
|
|
|
sim.ob = data->ob;
|
|
|
|
sim.psys = edit->psys;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 0, ekey = point->keys; k < pa->totkey - 1; k++, ekey++) {
|
|
|
|
if (ekey->flag & PEK_SELECT && (ekey + 1)->flag & PEK_SELECT)
|
2016-12-28 17:30:58 +01:00
|
|
|
totnewkey++;
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (totnewkey == 0) return;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
pa->flag |= PARS_REKEY;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
nkey = new_keys = MEM_callocN((pa->totkey + totnewkey) * (sizeof(HairKey)), "Hair subdivide keys");
|
|
|
|
nekey = new_ekeys = MEM_callocN((pa->totkey + totnewkey) * (sizeof(PTCacheEditKey)), "Hair subdivide edit keys");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
key = pa->hair;
|
2018-08-14 10:00:15 +10:00
|
|
|
endtime = key[pa->totkey - 1].time;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 0, ekey = point->keys; k < pa->totkey - 1; k++, key++, ekey++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
memcpy(nkey, key, sizeof(HairKey));
|
|
|
|
memcpy(nekey, ekey, sizeof(PTCacheEditKey));
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
nekey->co = nkey->co;
|
|
|
|
nekey->time = &nkey->time;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
nkey++;
|
|
|
|
nekey++;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (ekey->flag & PEK_SELECT && (ekey + 1)->flag & PEK_SELECT) {
|
2016-12-28 17:30:58 +01:00
|
|
|
nkey->time = (key->time + (key + 1)->time) * 0.5f;
|
2018-08-14 10:00:15 +10:00
|
|
|
state.time = (endtime != 0.0f) ? nkey->time / endtime : 0.0f;
|
2016-12-28 17:30:58 +01:00
|
|
|
psys_get_particle_on_path(&sim, pa_index, &state, 0);
|
|
|
|
copy_v3_v3(nkey->co, state.co);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
nekey->co = nkey->co;
|
2016-12-28 17:30:58 +01:00
|
|
|
nekey->time = &nkey->time;
|
|
|
|
nekey->flag |= PEK_SELECT;
|
|
|
|
if (!(psys->flag & PSYS_GLOBAL_HAIR))
|
|
|
|
nekey->flag |= PEK_USE_WCO;
|
|
|
|
|
|
|
|
nekey++;
|
|
|
|
nkey++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*tip still not copied*/
|
|
|
|
memcpy(nkey, key, sizeof(HairKey));
|
|
|
|
memcpy(nekey, ekey, sizeof(PTCacheEditKey));
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
nekey->co = nkey->co;
|
|
|
|
nekey->time = &nkey->time;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (pa->hair)
|
|
|
|
MEM_freeN(pa->hair);
|
2018-08-14 10:00:15 +10:00
|
|
|
pa->hair = new_keys;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (point->keys)
|
|
|
|
MEM_freeN(point->keys);
|
2018-08-14 10:00:15 +10:00
|
|
|
point->keys = new_ekeys;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
point->totkey = pa->totkey = pa->totkey + totnewkey;
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
pa->flag &= ~PARS_REKEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int subdivide_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PEData data;
|
|
|
|
|
|
|
|
PE_set_data(C, &data);
|
|
|
|
foreach_point(&data, subdivide_particle);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
recalc_lengths(data.edit);
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_object(data.depsgraph, data.scene, data.ob, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, data.ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_subdivide(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Subdivide";
|
|
|
|
ot->idname = "PARTICLE_OT_subdivide";
|
|
|
|
ot->description = "Subdivide selected particles segments (adds keys)";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = subdivide_exec;
|
|
|
|
ot->poll = PE_hair_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ remove doubles opertor *********************/
|
|
|
|
|
|
|
|
static int remove_doubles_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
2018-08-14 10:02:43 +10:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSystem *psys = edit->psys;
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval;
|
2016-12-28 17:30:58 +01:00
|
|
|
KDTree *tree;
|
|
|
|
KDTreeNearest nearest[10];
|
|
|
|
POINT_P;
|
2018-08-14 10:00:15 +10:00
|
|
|
float mat[4][4], co[3], threshold = RNA_float_get(op->ptr, "threshold");
|
2016-12-28 17:30:58 +01:00
|
|
|
int n, totn, removed, totremoved;
|
|
|
|
|
|
|
|
if (psys->flag & PSYS_GLOBAL_HAIR)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
edit = psys->edit;
|
2018-06-19 15:25:48 +02:00
|
|
|
psmd_eval = edit->psmd_eval;
|
2018-08-14 10:00:15 +10:00
|
|
|
totremoved = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
do {
|
2018-08-14 10:00:15 +10:00
|
|
|
removed = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
tree = BLI_kdtree_new(psys->totpart);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* insert particles into kd tree */
|
|
|
|
LOOP_SELECTED_POINTS {
|
2018-08-14 10:02:43 +10:00
|
|
|
psys_mat_hair_to_object(ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, mat);
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v3_v3(co, point->keys->co);
|
|
|
|
mul_m4_v3(mat, co);
|
|
|
|
BLI_kdtree_insert(tree, p, co);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_kdtree_balance(tree);
|
|
|
|
|
|
|
|
/* tag particles to be removed */
|
|
|
|
LOOP_SELECTED_POINTS {
|
2018-08-14 10:02:43 +10:00
|
|
|
psys_mat_hair_to_object(ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, mat);
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v3_v3(co, point->keys->co);
|
|
|
|
mul_m4_v3(mat, co);
|
|
|
|
|
|
|
|
totn = BLI_kdtree_find_nearest_n(tree, co, nearest, 10);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (n = 0; n < totn; n++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
/* this needs a custom threshold still */
|
|
|
|
if (nearest[n].index > p && nearest[n].dist < threshold) {
|
|
|
|
if (!(point->flag & PEP_TAG)) {
|
|
|
|
point->flag |= PEP_TAG;
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_kdtree_free(tree);
|
|
|
|
|
|
|
|
/* remove tagged particles - don't do mirror here! */
|
|
|
|
remove_tagged_particles(ob, psys, 0);
|
|
|
|
totremoved += removed;
|
|
|
|
} while (removed);
|
|
|
|
|
|
|
|
if (totremoved == 0)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
BKE_reportf(op->reports, RPT_INFO, "Removed %d double particles", totremoved);
|
|
|
|
|
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 | NA_EDITED, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_remove_doubles(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Remove Doubles";
|
|
|
|
ot->idname = "PARTICLE_OT_remove_doubles";
|
|
|
|
ot->description = "Remove selected particles close enough of others";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = remove_doubles_exec;
|
|
|
|
ot->poll = PE_hair_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* properties */
|
|
|
|
RNA_def_float(ot->srna, "threshold", 0.0002f, 0.0f, FLT_MAX,
|
2018-05-09 14:26:47 +02:00
|
|
|
"Merge Distance", "Threshold distance within which particles are removed", 0.00001f, 0.1f);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int weight_set_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
2018-08-14 10:02:43 +10:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSystem *psys = edit->psys;
|
|
|
|
POINT_P;
|
|
|
|
KEY_K;
|
|
|
|
HairKey *hkey;
|
|
|
|
float weight;
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleBrushData *brush = &pset->brush[pset->brushtype];
|
|
|
|
float factor = RNA_float_get(op->ptr, "factor");
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
weight = brush->strength;
|
|
|
|
edit = psys->edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
LOOP_SELECTED_POINTS {
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleData *pa = psys->particles + p;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
LOOP_SELECTED_KEYS {
|
2018-08-14 10:00:15 +10:00
|
|
|
hkey = pa->hair + k;
|
|
|
|
hkey->weight = interpf(weight, hkey->weight, factor);
|
2016-12-28 17:30:58 +01: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 | NA_EDITED, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_weight_set(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Weight Set";
|
|
|
|
ot->idname = "PARTICLE_OT_weight_set";
|
|
|
|
ot->description = "Set the weight of selected keys";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = weight_set_exec;
|
|
|
|
ot->poll = PE_hair_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
RNA_def_float(ot->srna, "factor", 1, 0, 1, "Factor",
|
|
|
|
"Interpolation factor between current brush weight, and keys' weights", 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************ cursor drawing *******************************/
|
|
|
|
|
|
|
|
static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata))
|
|
|
|
{
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleBrushData *brush;
|
|
|
|
|
2019-03-06 21:48:22 +11:00
|
|
|
if (!WM_toolsystem_active_tool_is_brush(C)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-14 14:27:31 +01:00
|
|
|
brush = &pset->brush[pset->brushtype];
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (brush) {
|
2018-07-18 00:12:21 +02:00
|
|
|
uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
2017-02-14 14:27:31 +01:00
|
|
|
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2017-02-14 14:27:31 +01:00
|
|
|
immUniformColor4ub(255, 255, 255, 128);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_line_smooth(true);
|
|
|
|
GPU_blend(true);
|
2017-02-14 14:27:31 +01:00
|
|
|
|
2017-09-14 00:39:28 +10:00
|
|
|
imm_draw_circle_wire_2d(pos, (float)x, (float)y, pe_brush_size_get(scene, brush), 40);
|
2017-02-14 14:27:31 +01:00
|
|
|
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_blend(false);
|
|
|
|
GPU_line_smooth(false);
|
2017-02-14 14:27:31 +01:00
|
|
|
|
|
|
|
immUnbindProgram();
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void toggle_particle_cursor(bContext *C, int enable)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleEditSettings *pset = PE_settings(CTX_data_scene(C));
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (pset->paintcursor && !enable) {
|
|
|
|
WM_paint_cursor_end(CTX_wm_manager(C), pset->paintcursor);
|
|
|
|
pset->paintcursor = NULL;
|
|
|
|
}
|
|
|
|
else if (enable)
|
2018-10-25 16:06:47 +11:00
|
|
|
pset->paintcursor = WM_paint_cursor_activate(
|
|
|
|
CTX_wm_manager(C),
|
|
|
|
SPACE_VIEW3D, RGN_TYPE_WINDOW,
|
|
|
|
PE_poll_view3d,
|
|
|
|
brush_drawcursor,
|
|
|
|
NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************** delete operator **************************/
|
|
|
|
|
|
|
|
enum { DEL_PARTICLE, DEL_KEY };
|
|
|
|
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem delete_type_items[] = {
|
2016-12-28 17:30:58 +01:00
|
|
|
{DEL_PARTICLE, "PARTICLE", 0, "Particle", ""},
|
|
|
|
{DEL_KEY, "KEY", 0, "Key", ""},
|
2019-02-03 14:01:45 +11:00
|
|
|
{0, NULL, 0, NULL, NULL},
|
2018-08-14 10:00:15 +10:00
|
|
|
};
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
static void set_delete_particle(PEData *data, int pa_index)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
PTCacheEdit *edit = data->edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
edit->points[pa_index].flag |= PEP_TAG;
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:28:41 +10:00
|
|
|
static void set_delete_particle_key(PEData *data, int pa_index, int key_index, bool UNUSED(is_inside))
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
PTCacheEdit *edit = data->edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
edit->points[pa_index].keys[key_index].flag |= PEK_TAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int delete_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
PEData data;
|
2018-08-14 10:00:15 +10:00
|
|
|
int type = RNA_enum_get(op->ptr, "type");
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
PE_set_data(C, &data);
|
|
|
|
|
|
|
|
if (type == DEL_KEY) {
|
|
|
|
foreach_selected_key(&data, set_delete_particle_key);
|
|
|
|
remove_tagged_keys(data.ob, data.edit->psys);
|
|
|
|
recalc_lengths(data.edit);
|
|
|
|
}
|
|
|
|
else if (type == DEL_PARTICLE) {
|
|
|
|
foreach_selected_point(&data, set_delete_particle);
|
|
|
|
remove_tagged_particles(data.ob, data.edit->psys, pe_x_mirror(data.ob));
|
|
|
|
recalc_lengths(data.edit);
|
|
|
|
}
|
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&data.ob->id, ID_RECALC_GEOMETRY);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, data.ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_delete(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Delete";
|
|
|
|
ot->idname = "PARTICLE_OT_delete";
|
|
|
|
ot->description = "Delete selected particles or keys";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = delete_exec;
|
|
|
|
ot->invoke = WM_menu_invoke;
|
|
|
|
ot->poll = PE_hair_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* properties */
|
|
|
|
ot->prop = RNA_def_enum(ot->srna, "type", delete_type_items, DEL_PARTICLE, "Type", "Delete a full particle or only keys");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************** mirror operator **************************/
|
|
|
|
|
2018-02-06 17:28:00 +11:00
|
|
|
static void PE_mirror_x(
|
2018-04-01 11:03:25 +02:00
|
|
|
Scene *scene, Object *ob, int tagged)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Mesh *me = (Mesh *)(ob->data);
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval;
|
2018-04-01 11:03:25 +02:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSystem *psys = edit->psys;
|
|
|
|
ParticleData *pa, *newpa, *new_pars;
|
|
|
|
PTCacheEditPoint *newpoint, *new_points;
|
|
|
|
POINT_P; KEY_K;
|
|
|
|
HairKey *hkey;
|
|
|
|
int *mirrorfaces = NULL;
|
|
|
|
int rotation, totpart, newtotpart;
|
|
|
|
|
|
|
|
if (psys->flag & PSYS_GLOBAL_HAIR)
|
|
|
|
return;
|
|
|
|
|
2018-06-19 15:25:48 +02:00
|
|
|
psmd_eval = edit->psmd_eval;
|
|
|
|
if (!psmd_eval->mesh_final)
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
|
|
|
|
2018-06-19 15:25:48 +02:00
|
|
|
const bool use_dm_final_indices = (psys->part->use_modifier_stack && !psmd_eval->mesh_final->runtime.deformed_only);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* NOTE: this is not nice to use tessfaces but hard to avoid since pa->num uses tessfaces */
|
|
|
|
BKE_mesh_tessface_ensure(me);
|
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
/* Note: In case psys uses Mesh tessface indices, we mirror final Mesh itself, not orig mesh. Avoids an (impossible)
|
|
|
|
* mesh -> orig -> mesh tessface indices conversion... */
|
2018-06-21 19:05:10 +02:00
|
|
|
mirrorfaces = mesh_get_x_mirror_faces(ob, NULL, use_dm_final_indices ? psmd_eval->mesh_final : NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (!edit->mirror_cache)
|
|
|
|
PE_update_mirror_cache(ob, psys);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
totpart = psys->totpart;
|
|
|
|
newtotpart = psys->totpart;
|
2016-12-28 17:30:58 +01:00
|
|
|
LOOP_VISIBLE_POINTS {
|
|
|
|
pa = psys->particles + p;
|
|
|
|
|
|
|
|
if (!tagged) {
|
|
|
|
if (point_is_selected(point)) {
|
|
|
|
if (edit->mirror_cache[p] != -1) {
|
|
|
|
/* already has a mirror, don't need to duplicate */
|
2018-06-19 15:25:48 +02:00
|
|
|
PE_mirror_particle(ob, psmd_eval->mesh_final, psys, pa, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
point->flag |= PEP_TAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if ((point->flag & PEP_TAG) && mirrorfaces[pa->num * 2] != -1)
|
2016-12-28 17:30:58 +01:00
|
|
|
newtotpart++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newtotpart != psys->totpart) {
|
2018-06-19 15:25:48 +02:00
|
|
|
MFace *mtessface = use_dm_final_indices ? psmd_eval->mesh_final->mface : me->mface;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* allocate new arrays and copy existing */
|
2018-08-14 10:00:15 +10:00
|
|
|
new_pars = MEM_callocN(newtotpart * sizeof(ParticleData), "ParticleData new");
|
|
|
|
new_points = MEM_callocN(newtotpart * sizeof(PTCacheEditPoint), "PTCacheEditPoint new");
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (psys->particles) {
|
2018-08-14 10:00:15 +10:00
|
|
|
memcpy(new_pars, psys->particles, totpart * sizeof(ParticleData));
|
2016-12-28 17:30:58 +01:00
|
|
|
MEM_freeN(psys->particles);
|
|
|
|
}
|
2018-08-14 10:00:15 +10:00
|
|
|
psys->particles = new_pars;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (edit->points) {
|
2018-08-14 10:00:15 +10:00
|
|
|
memcpy(new_points, edit->points, totpart * sizeof(PTCacheEditPoint));
|
2016-12-28 17:30:58 +01:00
|
|
|
MEM_freeN(edit->points);
|
|
|
|
}
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->points = new_points;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (edit->mirror_cache) {
|
|
|
|
MEM_freeN(edit->mirror_cache);
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->mirror_cache = NULL;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->totpoint = psys->totpart = newtotpart;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* create new elements */
|
2018-08-14 10:00:15 +10:00
|
|
|
newpa = psys->particles + totpart;
|
|
|
|
newpoint = edit->points + totpart;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (p = 0, point = edit->points; p < totpart; p++, point++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
pa = psys->particles + p;
|
|
|
|
const int pa_num = pa->num;
|
|
|
|
|
|
|
|
if (point->flag & PEP_HIDE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!(point->flag & PEP_TAG) || mirrorfaces[pa_num * 2] == -1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* duplicate */
|
2018-08-14 10:00:15 +10:00
|
|
|
*newpa = *pa;
|
|
|
|
*newpoint = *point;
|
|
|
|
if (pa->hair) newpa->hair = MEM_dupallocN(pa->hair);
|
|
|
|
if (point->keys) newpoint->keys = MEM_dupallocN(point->keys);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* rotate weights according to vertex index rotation */
|
2018-08-14 10:00:15 +10:00
|
|
|
rotation = mirrorfaces[pa_num * 2 + 1];
|
2016-12-28 17:30:58 +01:00
|
|
|
newpa->fuv[0] = pa->fuv[2];
|
|
|
|
newpa->fuv[1] = pa->fuv[1];
|
|
|
|
newpa->fuv[2] = pa->fuv[0];
|
|
|
|
newpa->fuv[3] = pa->fuv[3];
|
|
|
|
while (rotation--) {
|
|
|
|
if (mtessface[pa_num].v4) {
|
|
|
|
SHIFT4(float, newpa->fuv[0], newpa->fuv[1], newpa->fuv[2], newpa->fuv[3]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SHIFT3(float, newpa->fuv[0], newpa->fuv[1], newpa->fuv[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assign face index */
|
|
|
|
/* NOTE: mesh_get_x_mirror_faces generates -1 for non-found mirror, same as DMCACHE_NOTFOUND... */
|
|
|
|
newpa->num = mirrorfaces[pa_num * 2];
|
|
|
|
|
|
|
|
if (use_dm_final_indices) {
|
|
|
|
newpa->num_dmcache = DMCACHE_ISCHILD;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newpa->num_dmcache = psys_particle_dm_face_lookup(
|
2018-08-14 10:02:43 +10:00
|
|
|
psmd_eval->mesh_final, psmd_eval->mesh_original, newpa->num, newpa->fuv, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* update edit key pointers */
|
2018-08-14 10:00:15 +10:00
|
|
|
key = newpoint->keys;
|
|
|
|
for (k = 0, hkey = newpa->hair; k < newpa->totkey; k++, hkey++, key++) {
|
|
|
|
key->co = hkey->co;
|
|
|
|
key->time = &hkey->time;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* map key positions as mirror over x axis */
|
2018-06-19 15:25:48 +02:00
|
|
|
PE_mirror_particle(ob, psmd_eval->mesh_final, psys, pa, newpa);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
newpa++;
|
|
|
|
newpoint++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LOOP_POINTS {
|
|
|
|
point->flag &= ~PEP_TAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(mirrorfaces);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mirror_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
2018-08-14 10:02:43 +10:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-20 20:39:27 +00:00
|
|
|
PE_mirror_x(scene, ob, 0);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-05-11 12:44:43 +02:00
|
|
|
update_world_cos(CTX_data_depsgraph(C), ob, edit);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, ob);
|
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
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_mirror(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Mirror";
|
|
|
|
ot->idname = "PARTICLE_OT_mirror";
|
|
|
|
ot->description = "Duplicate and mirror the selected particles along the local X axis";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = mirror_exec;
|
|
|
|
ot->poll = PE_hair_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************* brush edit callbacks ********************/
|
|
|
|
|
|
|
|
static void brush_comb(PEData *data, float UNUSED(mat[4][4]), float imat[4][4], int point_index, int key_index, PTCacheEditKey *key)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleEditSettings *pset = PE_settings(data->scene);
|
2016-12-28 17:30:58 +01:00
|
|
|
float cvec[3], fac;
|
|
|
|
|
|
|
|
if (pset->flag & PE_LOCK_FIRST && key_index == 0) return;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
fac = (float)pow((double)(1.0f - data->dist / data->rad), (double)data->combfac);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
copy_v3_v3(cvec, data->dvec);
|
|
|
|
mul_mat3_m4_v3(imat, cvec);
|
|
|
|
mul_v3_fl(cvec, fac);
|
|
|
|
add_v3_v3(key->co, cvec);
|
|
|
|
|
|
|
|
(data->edit->points + point_index)->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void brush_cut(PEData *data, int pa_index)
|
|
|
|
{
|
|
|
|
PTCacheEdit *edit = data->edit;
|
2018-08-14 10:00:15 +10:00
|
|
|
ARegion *ar = data->vc.ar;
|
|
|
|
Object *ob = data->ob;
|
|
|
|
ParticleEditSettings *pset = PE_settings(data->scene);
|
|
|
|
ParticleCacheKey *key = edit->pathcache[pa_index];
|
|
|
|
float rad2, cut_time = 1.0;
|
2016-12-28 17:30:58 +01:00
|
|
|
float x0, x1, v0, v1, o0, o1, xo0, xo1, d, dv;
|
2018-08-14 10:00:15 +10:00
|
|
|
int k, cut, keys = (int)pow(2.0, (double)pset->draw_step);
|
2016-12-28 17:30:58 +01:00
|
|
|
int screen_co[2];
|
|
|
|
|
2018-06-20 11:27:19 +02:00
|
|
|
BLI_assert(data->rng != NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
/* blunt scissors */
|
2018-06-20 11:27:19 +02:00
|
|
|
if (BLI_rng_get_float(data->rng) > data->cutfac) {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* don't cut hidden */
|
|
|
|
if (edit->points[pa_index].flag & PEP_HIDE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ED_view3d_project_int_global(ar, key->co, screen_co, V3D_PROJ_TEST_CLIP_NEAR) != V3D_PROJ_RET_OK)
|
|
|
|
return;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
rad2 = data->rad * data->rad;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
cut = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
x0 = (float)screen_co[0];
|
|
|
|
x1 = (float)screen_co[1];
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
o0 = (float)data->mval[0];
|
|
|
|
o1 = (float)data->mval[1];
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
xo0 = x0 - o0;
|
|
|
|
xo1 = x1 - o1;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* check if root is inside circle */
|
2018-08-14 10:00:15 +10:00
|
|
|
if (xo0 * xo0 + xo1 * xo1 < rad2 && key_test_depth(data, key->co, screen_co)) {
|
|
|
|
cut_time = -1.0f;
|
|
|
|
cut = 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* calculate path time closest to root that was inside the circle */
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 1, key++; k <= keys; k++, key++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if ((ED_view3d_project_int_global(ar, key->co, screen_co, V3D_PROJ_TEST_CLIP_NEAR) != V3D_PROJ_RET_OK) ||
|
|
|
|
key_test_depth(data, key->co, screen_co) == 0)
|
|
|
|
{
|
|
|
|
x0 = (float)screen_co[0];
|
|
|
|
x1 = (float)screen_co[1];
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
xo0 = x0 - o0;
|
|
|
|
xo1 = x1 - o1;
|
2016-12-28 17:30:58 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
v0 = (float)screen_co[0] - x0;
|
|
|
|
v1 = (float)screen_co[1] - x1;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
dv = v0 * v0 + v1 * v1;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
d = (v0 * xo1 - v1 * xo0);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
d = dv * rad2 - d * d;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (d > 0.0f) {
|
2018-08-14 10:00:15 +10:00
|
|
|
d = sqrtf(d);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
cut_time = -(v0 * xo0 + v1 * xo1 + d);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (cut_time > 0.0f) {
|
|
|
|
cut_time /= dv;
|
|
|
|
|
|
|
|
if (cut_time < 1.0f) {
|
2018-08-14 10:00:15 +10:00
|
|
|
cut_time += (float)(k - 1);
|
2016-12-28 17:30:58 +01:00
|
|
|
cut_time /= (float)keys;
|
2018-08-14 10:00:15 +10:00
|
|
|
cut = 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x0 = (float)screen_co[0];
|
|
|
|
x1 = (float)screen_co[1];
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
xo0 = x0 - o0;
|
|
|
|
xo1 = x1 - o1;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cut) {
|
|
|
|
if (cut_time < 0.0f) {
|
|
|
|
edit->points[pa_index].flag |= PEP_TAG;
|
|
|
|
}
|
|
|
|
else {
|
2018-04-01 11:03:25 +02:00
|
|
|
rekey_particle_to_time(data->context, data->scene, ob, pa_index, cut_time);
|
2016-12-28 17:30:58 +01:00
|
|
|
edit->points[pa_index].flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void brush_length(PEData *data, int point_index)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
PTCacheEdit *edit = data->edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
PTCacheEditPoint *point = edit->points + point_index;
|
|
|
|
KEY_K;
|
|
|
|
float dvec[3], pvec[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
LOOP_KEYS {
|
2018-08-14 10:00:15 +10:00
|
|
|
if (k == 0) {
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v3_v3(pvec, key->co);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sub_v3_v3v3(dvec, key->co, pvec);
|
|
|
|
copy_v3_v3(pvec, key->co);
|
|
|
|
mul_v3_fl(dvec, data->growfac);
|
2018-08-14 10:00:15 +10:00
|
|
|
add_v3_v3v3(key->co, (key - 1)->co, dvec);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void brush_puff(PEData *data, int point_index)
|
|
|
|
{
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
ParticleSystem *psys = edit->psys;
|
|
|
|
PTCacheEditPoint *point = edit->points + point_index;
|
|
|
|
KEY_K;
|
|
|
|
float mat[4][4], imat[4][4];
|
|
|
|
|
|
|
|
float onor_prev[3]; /* previous normal (particle-space) */
|
|
|
|
float ofs_prev[3]; /* accumulate offset for puff_volume (particle-space) */
|
|
|
|
float co_root[3], no_root[3]; /* root location and normal (global-space) */
|
|
|
|
float co_prev[3], co[3]; /* track key coords as we loop (global-space) */
|
|
|
|
float fac = 0.0f, length_accum = 0.0f;
|
|
|
|
bool puff_volume = false;
|
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
zero_v3(ofs_prev);
|
|
|
|
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleEditSettings *pset = PE_settings(data->scene);
|
|
|
|
ParticleBrushData *brush = &pset->brush[pset->brushtype];
|
2016-12-28 17:30:58 +01:00
|
|
|
puff_volume = (brush->flag & PE_BRUSH_DATA_PUFF_VOLUME) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) {
|
2018-05-15 13:26:40 +02:00
|
|
|
psys_mat_hair_to_global(data->ob, data->mesh, psys->part->from, psys->particles + point_index, mat);
|
2016-12-28 17:30:58 +01:00
|
|
|
invert_m4_m4(imat, mat);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unit_m4(mat);
|
|
|
|
unit_m4(imat);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOOP_KEYS {
|
|
|
|
float kco[3];
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (k == 0) {
|
2016-12-28 17:30:58 +01:00
|
|
|
/* find root coordinate and normal on emitter */
|
|
|
|
copy_v3_v3(co, key->co);
|
|
|
|
mul_m4_v3(mat, co);
|
2019-01-15 23:24:20 +11:00
|
|
|
|
|
|
|
/* use 'kco' as the object space version of worldspace 'co',
|
|
|
|
* ob->imat is set before calling */
|
|
|
|
mul_v3_m4v3(kco, data->ob->imat, co);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
point_index = BLI_kdtree_find_nearest(edit->emitter_field, kco, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
if (point_index == -1) return;
|
|
|
|
|
|
|
|
copy_v3_v3(co_root, co);
|
|
|
|
copy_v3_v3(no_root, &edit->emitter_cosnos[point_index * 6 + 3]);
|
|
|
|
mul_mat3_m4_v3(data->ob->obmat, no_root); /* normal into global-space */
|
|
|
|
normalize_v3(no_root);
|
|
|
|
|
|
|
|
if (puff_volume) {
|
|
|
|
copy_v3_v3(onor_prev, no_root);
|
|
|
|
mul_mat3_m4_v3(imat, onor_prev); /* global-space into particle space */
|
|
|
|
normalize_v3(onor_prev);
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
fac = (float)pow((double)(1.0f - data->dist / data->rad), (double)data->pufffac);
|
2016-12-28 17:30:58 +01:00
|
|
|
fac *= 0.025f;
|
|
|
|
if (data->invert)
|
2018-08-14 10:00:15 +10:00
|
|
|
fac = -fac;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* compute position as if hair was standing up straight.
|
|
|
|
* */
|
|
|
|
float length;
|
|
|
|
copy_v3_v3(co_prev, co);
|
|
|
|
copy_v3_v3(co, key->co);
|
|
|
|
mul_m4_v3(mat, co);
|
|
|
|
length = len_v3v3(co_prev, co);
|
|
|
|
length_accum += length;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if ((data->select == 0 || (key->flag & PEK_SELECT)) && !(key->flag & PEK_HIDE)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
float dco[3]; /* delta temp var */
|
|
|
|
|
|
|
|
madd_v3_v3v3fl(kco, co_root, no_root, length_accum);
|
|
|
|
|
|
|
|
/* blend between the current and straight position */
|
|
|
|
sub_v3_v3v3(dco, kco, co);
|
|
|
|
madd_v3_v3fl(co, dco, fac);
|
|
|
|
/* keep the same distance from the root or we get glitches [#35406] */
|
|
|
|
dist_ensure_v3_v3fl(co, co_root, length_accum);
|
|
|
|
|
|
|
|
/* re-use dco to compare before and after translation and add to the offset */
|
|
|
|
copy_v3_v3(dco, key->co);
|
|
|
|
|
|
|
|
mul_v3_m4v3(key->co, imat, co);
|
|
|
|
|
|
|
|
if (puff_volume) {
|
|
|
|
/* accumulate the total distance moved to apply to unselected
|
|
|
|
* keys that come after */
|
|
|
|
sub_v3_v3v3(ofs_prev, key->co, dco);
|
|
|
|
}
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
if (puff_volume) {
|
|
|
|
#if 0
|
|
|
|
/* this is simple but looks bad, adds annoying kinks */
|
|
|
|
add_v3_v3(key->co, ofs);
|
|
|
|
#else
|
|
|
|
/* translate (not rotate) the rest of the hair if its not selected */
|
|
|
|
{
|
2018-09-27 15:35:22 +02:00
|
|
|
#if 0 /* kindof works but looks worse then what's below */
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* Move the unselected point on a vector based on the
|
|
|
|
* hair direction and the offset */
|
|
|
|
float c1[3], c2[3];
|
|
|
|
sub_v3_v3v3(dco, lastco, co);
|
|
|
|
mul_mat3_m4_v3(imat, dco); /* into particle space */
|
|
|
|
|
|
|
|
/* move the point along a vector perpendicular to the
|
|
|
|
* hairs direction, reduces odd kinks, */
|
|
|
|
cross_v3_v3v3(c1, ofs, dco);
|
|
|
|
cross_v3_v3v3(c2, c1, dco);
|
|
|
|
normalize_v3(c2);
|
|
|
|
mul_v3_fl(c2, len_v3(ofs));
|
|
|
|
add_v3_v3(key->co, c2);
|
|
|
|
#else
|
|
|
|
/* Move the unselected point on a vector based on the
|
|
|
|
* the normal of the closest geometry */
|
|
|
|
float oco[3], onor[3];
|
|
|
|
copy_v3_v3(oco, key->co);
|
|
|
|
mul_m4_v3(mat, oco);
|
2019-01-15 23:24:20 +11:00
|
|
|
|
|
|
|
/* use 'kco' as the object space version of worldspace 'co',
|
|
|
|
* ob->imat is set before calling */
|
|
|
|
mul_v3_m4v3(kco, data->ob->imat, oco);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
point_index = BLI_kdtree_find_nearest(edit->emitter_field, kco, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
if (point_index != -1) {
|
2018-08-14 10:00:15 +10:00
|
|
|
copy_v3_v3(onor, &edit->emitter_cosnos[point_index * 6 + 3]);
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_mat3_m4_v3(data->ob->obmat, onor); /* normal into worldspace */
|
|
|
|
mul_mat3_m4_v3(imat, onor); /* worldspace into particle space */
|
|
|
|
normalize_v3(onor);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_v3_v3(onor, onor_prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_zero_v3(ofs_prev)) {
|
|
|
|
mul_v3_fl(onor, len_v3(ofs_prev));
|
|
|
|
|
|
|
|
add_v3_v3(key->co, onor);
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_v3_v3(onor_prev, onor);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void BKE_brush_weight_get(PEData *data, float UNUSED(mat[4][4]), float UNUSED(imat[4][4]), int point_index, int key_index, PTCacheEditKey *UNUSED(key))
|
|
|
|
{
|
|
|
|
/* roots have full weight always */
|
|
|
|
if (key_index) {
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
ParticleSystem *psys = edit->psys;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleData *pa = psys->particles + point_index;
|
2016-12-28 17:30:58 +01:00
|
|
|
pa->hair[key_index].weight = data->weightfac;
|
|
|
|
|
|
|
|
(data->edit->points + point_index)->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void brush_smooth_get(PEData *data, float mat[4][4], float UNUSED(imat[4][4]), int UNUSED(point_index), int key_index, PTCacheEditKey *key)
|
2018-06-04 09:31:30 +02:00
|
|
|
{
|
2016-12-28 17:30:58 +01:00
|
|
|
if (key_index) {
|
|
|
|
float dvec[3];
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
sub_v3_v3v3(dvec, key->co, (key - 1)->co);
|
2016-12-28 17:30:58 +01:00
|
|
|
mul_mat3_m4_v3(mat, dvec);
|
|
|
|
add_v3_v3(data->vec, dvec);
|
|
|
|
data->tot++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void brush_smooth_do(PEData *data, float UNUSED(mat[4][4]), float imat[4][4], int point_index, int key_index, PTCacheEditKey *key)
|
|
|
|
{
|
|
|
|
float vec[3], dvec[3];
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (key_index) {
|
|
|
|
copy_v3_v3(vec, data->vec);
|
|
|
|
mul_mat3_m4_v3(imat, vec);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
sub_v3_v3v3(dvec, key->co, (key - 1)->co);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
sub_v3_v3v3(dvec, vec, dvec);
|
|
|
|
mul_v3_fl(dvec, data->smoothfac);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
add_v3_v3(key->co, dvec);
|
|
|
|
}
|
|
|
|
|
|
|
|
(data->edit->points + point_index)->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert from triangle barycentric weights to quad mean value weights */
|
|
|
|
static void intersect_dm_quad_weights(const float v1[3], const float v2[3], const float v3[3], const float v4[3], float w[4])
|
|
|
|
{
|
|
|
|
float co[3], vert[4][3];
|
|
|
|
|
|
|
|
copy_v3_v3(vert[0], v1);
|
|
|
|
copy_v3_v3(vert[1], v2);
|
|
|
|
copy_v3_v3(vert[2], v3);
|
|
|
|
copy_v3_v3(vert[3], v4);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
co[0] = v1[0] * w[0] + v2[0] * w[1] + v3[0] * w[2] + v4[0] * w[3];
|
|
|
|
co[1] = v1[1] * w[0] + v2[1] * w[1] + v3[1] * w[2] + v4[1] * w[3];
|
|
|
|
co[2] = v1[2] * w[0] + v2[2] * w[1] + v3[2] * w[2] + v4[2] * w[3];
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
interp_weights_poly_v3(w, vert, 4, co);
|
|
|
|
}
|
|
|
|
|
2018-06-27 11:34:45 +02:00
|
|
|
/** Check intersection with an evaluated mesh. */
|
2018-12-01 19:06:44 +03:00
|
|
|
static int particle_intersect_mesh(Depsgraph *depsgraph, Scene *UNUSED(scene), Object *ob, Mesh *mesh,
|
2018-06-15 10:22:44 +02:00
|
|
|
float *vert_cos,
|
|
|
|
const float co1[3], const float co2[3],
|
|
|
|
float *min_d, int *min_face, float *min_w,
|
|
|
|
float *face_minmax, float *pa_minmax,
|
|
|
|
float radius, float *ipoint)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
MFace *mface = NULL;
|
|
|
|
MVert *mvert = NULL;
|
|
|
|
int i, totface, intersect = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
float cur_d, cur_uv[2], v1[3], v2[3], v3[3], v4[3], min[3], max[3], p_min[3], p_max[3];
|
|
|
|
float cur_ipoint[3];
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
if (mesh == NULL) {
|
2016-12-28 17:30:58 +01:00
|
|
|
psys_disable_all(ob);
|
|
|
|
|
2018-12-01 19:06:44 +03:00
|
|
|
Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
|
|
|
|
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
|
|
|
|
|
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
|
|
|
mesh = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH);
|
2018-06-27 11:34:45 +02:00
|
|
|
if (mesh == NULL) {
|
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
|
|
|
mesh = mesh_get_eval_deform(depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH);
|
2018-06-27 11:34:45 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
psys_enable_all(ob);
|
|
|
|
|
2018-06-27 11:34:45 +02:00
|
|
|
if (mesh == NULL) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return 0;
|
2018-06-27 11:34:45 +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);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (pa_minmax == 0) {
|
2016-12-28 17:30:58 +01:00
|
|
|
INIT_MINMAX(p_min, p_max);
|
|
|
|
minmax_v3v3_v3(p_min, p_max, co1);
|
|
|
|
minmax_v3v3_v3(p_min, p_max, co2);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_v3_v3(p_min, pa_minmax);
|
2018-08-14 10:00:15 +10:00
|
|
|
copy_v3_v3(p_max, pa_minmax + 3);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
2018-05-15 13:26:40 +02:00
|
|
|
totface = mesh->totface;
|
|
|
|
mface = mesh->mface;
|
|
|
|
mvert = mesh->mvert;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* lets intersect the faces */
|
2018-08-14 10:00:15 +10:00
|
|
|
for (i = 0; i < totface; i++, mface++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (vert_cos) {
|
2018-08-14 10:00:15 +10:00
|
|
|
copy_v3_v3(v1, vert_cos + 3 * mface->v1);
|
|
|
|
copy_v3_v3(v2, vert_cos + 3 * mface->v2);
|
|
|
|
copy_v3_v3(v3, vert_cos + 3 * mface->v3);
|
2016-12-28 17:30:58 +01:00
|
|
|
if (mface->v4)
|
2018-08-14 10:00:15 +10:00
|
|
|
copy_v3_v3(v4, vert_cos + 3 * mface->v4);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_v3_v3(v1, mvert[mface->v1].co);
|
|
|
|
copy_v3_v3(v2, mvert[mface->v2].co);
|
|
|
|
copy_v3_v3(v3, mvert[mface->v3].co);
|
|
|
|
if (mface->v4)
|
|
|
|
copy_v3_v3(v4, mvert[mface->v4].co);
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (face_minmax == 0) {
|
2016-12-28 17:30:58 +01:00
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
DO_MINMAX(v1, min, max);
|
|
|
|
DO_MINMAX(v2, min, max);
|
|
|
|
DO_MINMAX(v3, min, max);
|
|
|
|
if (mface->v4)
|
|
|
|
DO_MINMAX(v4, min, max);
|
2018-08-14 10:00:15 +10:00
|
|
|
if (isect_aabb_aabb_v3(min, max, p_min, p_max) == 0)
|
2016-12-28 17:30:58 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
2018-08-14 10:00:15 +10:00
|
|
|
copy_v3_v3(min, face_minmax + 6 * i);
|
|
|
|
copy_v3_v3(max, face_minmax + 6 * i + 3);
|
|
|
|
if (isect_aabb_aabb_v3(min, max, p_min, p_max) == 0)
|
2016-12-28 17:30:58 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (radius > 0.0f) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (isect_sweeping_sphere_tri_v3(co1, co2, radius, v2, v3, v1, &cur_d, cur_ipoint)) {
|
2018-08-14 10:00:15 +10:00
|
|
|
if (cur_d < *min_d) {
|
|
|
|
*min_d = cur_d;
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v3_v3(ipoint, cur_ipoint);
|
2018-08-14 10:00:15 +10:00
|
|
|
*min_face = i;
|
|
|
|
intersect = 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mface->v4) {
|
|
|
|
if (isect_sweeping_sphere_tri_v3(co1, co2, radius, v4, v1, v3, &cur_d, cur_ipoint)) {
|
2018-08-14 10:00:15 +10:00
|
|
|
if (cur_d < *min_d) {
|
|
|
|
*min_d = cur_d;
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v3_v3(ipoint, cur_ipoint);
|
2018-08-14 10:00:15 +10:00
|
|
|
*min_face = i;
|
|
|
|
intersect = 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (isect_line_segment_tri_v3(co1, co2, v1, v2, v3, &cur_d, cur_uv)) {
|
2018-08-14 10:00:15 +10:00
|
|
|
if (cur_d < *min_d) {
|
|
|
|
*min_d = cur_d;
|
2016-12-28 17:30:58 +01:00
|
|
|
min_w[0] = 1.0f - cur_uv[0] - cur_uv[1];
|
|
|
|
min_w[1] = cur_uv[0];
|
|
|
|
min_w[2] = cur_uv[1];
|
|
|
|
min_w[3] = 0.0f;
|
|
|
|
if (mface->v4)
|
|
|
|
intersect_dm_quad_weights(v1, v2, v3, v4, min_w);
|
2018-08-14 10:00:15 +10:00
|
|
|
*min_face = i;
|
|
|
|
intersect = 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mface->v4) {
|
|
|
|
if (isect_line_segment_tri_v3(co1, co2, v1, v3, v4, &cur_d, cur_uv)) {
|
2018-08-14 10:00:15 +10:00
|
|
|
if (cur_d < *min_d) {
|
|
|
|
*min_d = cur_d;
|
2016-12-28 17:30:58 +01:00
|
|
|
min_w[0] = 1.0f - cur_uv[0] - cur_uv[1];
|
|
|
|
min_w[1] = 0.0f;
|
|
|
|
min_w[2] = cur_uv[0];
|
|
|
|
min_w[3] = cur_uv[1];
|
|
|
|
intersect_dm_quad_weights(v1, v2, v3, v4, min_w);
|
2018-08-14 10:00:15 +10:00
|
|
|
*min_face = i;
|
|
|
|
intersect = 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return intersect;
|
|
|
|
}
|
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
typedef struct BrushAddCountIterData {
|
|
|
|
Depsgraph *depsgraph;
|
|
|
|
Scene *scene;
|
|
|
|
Object *object;
|
|
|
|
Mesh *mesh;
|
|
|
|
PEData *data;
|
|
|
|
int number;
|
|
|
|
short size;
|
|
|
|
float imat[4][4];
|
|
|
|
ParticleData *add_pars;
|
|
|
|
int num_added;
|
|
|
|
} BrushAddCountIterData;
|
|
|
|
|
|
|
|
typedef struct BrushAddCountIterTLSData {
|
|
|
|
RNG *rng;
|
|
|
|
int num_added;
|
|
|
|
} BrushAddCountIterTLSData;
|
|
|
|
|
|
|
|
static void brush_add_count_iter(
|
|
|
|
void *__restrict iter_data_v,
|
|
|
|
const int iter,
|
|
|
|
const ParallelRangeTLS *__restrict tls_v)
|
|
|
|
{
|
|
|
|
BrushAddCountIterData *iter_data = (BrushAddCountIterData *)iter_data_v;
|
|
|
|
Depsgraph *depsgraph = iter_data->depsgraph;
|
|
|
|
PEData *data = iter_data->data;
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
ParticleSystem *psys = edit->psys;
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval = edit->psmd_eval;
|
2018-06-15 10:22:44 +02:00
|
|
|
ParticleData *add_pars = iter_data->add_pars;
|
|
|
|
BrushAddCountIterTLSData *tls = tls_v->userdata_chunk;
|
|
|
|
const int number = iter_data->number;
|
|
|
|
const short size = iter_data->size;
|
2018-08-14 10:02:43 +10:00
|
|
|
const short size2 = size * size;
|
2018-06-15 10:22:44 +02:00
|
|
|
float dmx, dmy;
|
|
|
|
if (number > 1) {
|
|
|
|
dmx = size;
|
|
|
|
dmy = size;
|
|
|
|
if (tls->rng == NULL) {
|
|
|
|
tls->rng = BLI_rng_new_srandom(
|
|
|
|
psys->seed + data->mval[0] + data->mval[1] + tls_v->thread_id);
|
|
|
|
}
|
|
|
|
/* rejection sampling to get points in circle */
|
2018-08-14 10:02:43 +10:00
|
|
|
while (dmx * dmx + dmy * dmy > size2) {
|
|
|
|
dmx = (2.0f * BLI_rng_get_float(tls->rng) - 1.0f) * size;
|
|
|
|
dmy = (2.0f * BLI_rng_get_float(tls->rng) - 1.0f) * size;
|
2018-06-15 10:22:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dmx = 0.0f;
|
|
|
|
dmy = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
float mco[2];
|
|
|
|
mco[0] = data->mval[0] + dmx;
|
|
|
|
mco[1] = data->mval[1] + dmy;
|
|
|
|
|
|
|
|
float co1[3], co2[3];
|
2018-09-20 12:04:18 +10:00
|
|
|
ED_view3d_win_to_segment_clipped(depsgraph, data->vc.ar, data->vc.v3d, mco, co1, co2, true);
|
2018-06-15 10:22:44 +02:00
|
|
|
|
|
|
|
mul_m4_v3(iter_data->imat, co1);
|
|
|
|
mul_m4_v3(iter_data->imat, co2);
|
|
|
|
float min_d = 2.0;
|
|
|
|
|
|
|
|
/* warning, returns the derived mesh face */
|
|
|
|
BLI_assert(iter_data->mesh != NULL);
|
|
|
|
if (particle_intersect_mesh(depsgraph, iter_data->scene, iter_data->object, iter_data->mesh,
|
|
|
|
0, co1, co2,
|
|
|
|
&min_d,
|
|
|
|
&add_pars[iter].num_dmcache,
|
|
|
|
add_pars[iter].fuv,
|
2018-08-30 01:36:52 +10:00
|
|
|
0, 0, 0, 0))
|
|
|
|
{
|
2018-06-19 15:25:48 +02:00
|
|
|
if (psys->part->use_modifier_stack && !psmd_eval->mesh_final->runtime.deformed_only) {
|
2018-06-15 10:22:44 +02:00
|
|
|
add_pars[iter].num = add_pars[iter].num_dmcache;
|
|
|
|
add_pars[iter].num_dmcache = DMCACHE_ISCHILD;
|
|
|
|
}
|
2018-06-19 15:25:48 +02:00
|
|
|
else if (iter_data->mesh == psmd_eval->mesh_original) {
|
2018-06-15 10:22:44 +02:00
|
|
|
/* Final DM is not same topology as orig mesh, we have to map num_dmcache to real final dm. */
|
|
|
|
add_pars[iter].num = add_pars[iter].num_dmcache;
|
|
|
|
add_pars[iter].num_dmcache = psys_particle_dm_face_lookup(
|
2018-08-14 10:02:43 +10:00
|
|
|
psmd_eval->mesh_final, psmd_eval->mesh_original,
|
|
|
|
add_pars[iter].num, add_pars[iter].fuv, NULL);
|
2018-06-15 10:22:44 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
add_pars[iter].num = add_pars[iter].num_dmcache;
|
|
|
|
}
|
|
|
|
if (add_pars[iter].num != DMCACHE_NOTFOUND) {
|
|
|
|
tls->num_added++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void brush_add_count_iter_finalize(void *__restrict userdata_v,
|
|
|
|
void *__restrict userdata_chunk_v)
|
|
|
|
{
|
|
|
|
BrushAddCountIterData *iter_data = (BrushAddCountIterData *)userdata_v;
|
|
|
|
BrushAddCountIterTLSData *tls = (BrushAddCountIterTLSData *)userdata_chunk_v;
|
|
|
|
iter_data->num_added += tls->num_added;
|
|
|
|
if (tls->rng != NULL) {
|
|
|
|
BLI_rng_free(tls->rng);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-21 11:53:13 +02:00
|
|
|
static int brush_add(const bContext *C, PEData *data, short number)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = data->scene;
|
|
|
|
Object *ob = data->ob;
|
2018-05-15 13:26:40 +02:00
|
|
|
Mesh *mesh;
|
2016-12-28 17:30:58 +01:00
|
|
|
PTCacheEdit *edit = data->edit;
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleSystem *psys = edit->psys;
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleData *add_pars;
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval = edit->psmd_eval;
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleSimulationData sim = {0};
|
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
|
|
|
int i, k, n = 0, totpart = psys->totpart;
|
2018-06-15 10:22:44 +02:00
|
|
|
float co1[3], imat[4][4];
|
2016-12-28 17:30:58 +01:00
|
|
|
float framestep, timestep;
|
2018-08-14 10:00:15 +10:00
|
|
|
short size = pset->brush[PE_BRUSH_ADD].size;
|
2016-12-28 17:30:58 +01:00
|
|
|
RNG *rng;
|
|
|
|
|
|
|
|
invert_m4_m4(imat, ob->obmat);
|
|
|
|
|
|
|
|
if (psys->flag & PSYS_GLOBAL_HAIR)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
add_pars = MEM_callocN(number * sizeof(ParticleData), "ParticleData add");
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
rng = BLI_rng_new_srandom(psys->seed + data->mval[0] + data->mval[1]);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
sim.depsgraph = depsgraph;
|
2018-06-15 10:22:44 +02:00
|
|
|
sim.scene = scene;
|
|
|
|
sim.ob = ob;
|
|
|
|
sim.psys = psys;
|
2018-06-19 15:25:48 +02:00
|
|
|
sim.psmd = psmd_eval;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
timestep = psys_get_timestep(&sim);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-19 15:25:48 +02:00
|
|
|
if (psys->part->use_modifier_stack || psmd_eval->mesh_final->runtime.deformed_only) {
|
|
|
|
mesh = psmd_eval->mesh_final;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-06-19 15:25:48 +02:00
|
|
|
mesh = psmd_eval->mesh_original;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2018-05-15 13:26:40 +02:00
|
|
|
BLI_assert(mesh);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-15 10:22:44 +02:00
|
|
|
/* Calculate positions of new particles to add, based on brush interseciton
|
2018-09-27 15:49:59 +02:00
|
|
|
* with object. New particle data is assigned to a corresponding to check
|
2018-06-15 10:22:44 +02:00
|
|
|
* index element of add_pars array. This means, that add_pars is a sparse
|
|
|
|
* array.
|
|
|
|
*/
|
|
|
|
BrushAddCountIterData iter_data;
|
|
|
|
iter_data.depsgraph = depsgraph;
|
|
|
|
iter_data.scene = scene;
|
|
|
|
iter_data.object = ob;
|
|
|
|
iter_data.mesh = mesh;
|
|
|
|
iter_data.data = data;
|
|
|
|
iter_data.number = number;
|
|
|
|
iter_data.size = size;
|
|
|
|
iter_data.add_pars = add_pars;
|
|
|
|
iter_data.num_added = 0;
|
|
|
|
copy_m4_m4(iter_data.imat, imat);
|
|
|
|
|
|
|
|
BrushAddCountIterTLSData tls = {NULL};
|
|
|
|
|
|
|
|
ParallelRangeSettings settings;
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC;
|
|
|
|
settings.userdata_chunk = &tls;
|
|
|
|
settings.userdata_chunk_size = sizeof(BrushAddCountIterTLSData);
|
|
|
|
settings.func_finalize = brush_add_count_iter_finalize;
|
|
|
|
BLI_task_parallel_range(0, number, &iter_data, brush_add_count_iter, &settings);
|
|
|
|
|
|
|
|
/* Convert add_parse to a dense array, where all new particles are in the
|
|
|
|
* beginnign of the array.
|
|
|
|
*/
|
|
|
|
n = iter_data.num_added;
|
|
|
|
for (int current_iter = 0, new_index = 0; current_iter < number; current_iter++) {
|
|
|
|
if (add_pars[current_iter].num == DMCACHE_NOTFOUND) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (new_index != current_iter) {
|
|
|
|
new_index++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
memcpy(add_pars + new_index, add_pars + current_iter, sizeof(ParticleData));
|
|
|
|
new_index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO(sergey): Consider multi-threading this part as well. */
|
2016-12-28 17:30:58 +01:00
|
|
|
if (n) {
|
2018-08-14 10:00:15 +10:00
|
|
|
int newtotpart = totpart + n;
|
2016-12-28 17:30:58 +01:00
|
|
|
float hairmat[4][4], cur_co[3];
|
2018-08-14 10:00:15 +10:00
|
|
|
KDTree *tree = 0;
|
|
|
|
ParticleData *pa, *new_pars = MEM_callocN(newtotpart * sizeof(ParticleData), "ParticleData new");
|
|
|
|
PTCacheEditPoint *point, *new_points = MEM_callocN(newtotpart * sizeof(PTCacheEditPoint), "PTCacheEditPoint array new");
|
2016-12-28 17:30:58 +01:00
|
|
|
PTCacheEditKey *key;
|
|
|
|
HairKey *hkey;
|
|
|
|
|
|
|
|
/* save existing elements */
|
|
|
|
memcpy(new_pars, psys->particles, totpart * sizeof(ParticleData));
|
|
|
|
memcpy(new_points, edit->points, totpart * sizeof(PTCacheEditPoint));
|
|
|
|
|
|
|
|
/* change old arrays to new ones */
|
|
|
|
if (psys->particles) MEM_freeN(psys->particles);
|
2018-08-14 10:00:15 +10:00
|
|
|
psys->particles = new_pars;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (edit->points) MEM_freeN(edit->points);
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->points = new_points;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (edit->mirror_cache) {
|
|
|
|
MEM_freeN(edit->mirror_cache);
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->mirror_cache = NULL;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create tree for interpolation */
|
|
|
|
if (pset->flag & PE_INTERPOLATE_ADDED && psys->totpart) {
|
2018-08-14 10:00:15 +10:00
|
|
|
tree = BLI_kdtree_new(psys->totpart);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (i = 0, pa = psys->particles; i < totpart; i++, pa++) {
|
2018-06-19 15:25:48 +02:00
|
|
|
psys_particle_on_dm(psmd_eval->mesh_final, psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, cur_co, 0, 0, 0, 0);
|
2016-12-28 17:30:58 +01:00
|
|
|
BLI_kdtree_insert(tree, i, cur_co);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_kdtree_balance(tree);
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
edit->totpoint = psys->totpart = newtotpart;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* create new elements */
|
|
|
|
pa = psys->particles + totpart;
|
|
|
|
point = edit->points + totpart;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (i = totpart; i < newtotpart; i++, pa++, point++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
memcpy(pa, add_pars + i - totpart, sizeof(ParticleData));
|
2018-08-14 10:00:15 +10:00
|
|
|
pa->hair = MEM_callocN(pset->totaddkey * sizeof(HairKey), "BakeKey key add");
|
|
|
|
key = point->keys = MEM_callocN(pset->totaddkey * sizeof(PTCacheEditKey), "PTCacheEditKey add");
|
|
|
|
point->totkey = pa->totkey = pset->totaddkey;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 0, hkey = pa->hair; k < pa->totkey; k++, hkey++, key++) {
|
|
|
|
key->co = hkey->co;
|
|
|
|
key->time = &hkey->time;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (!(psys->flag & PSYS_GLOBAL_HAIR))
|
|
|
|
key->flag |= PEK_USE_WCO;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
pa->size = 1.0f;
|
2016-12-28 17:30:58 +01:00
|
|
|
initialize_particle(&sim, pa);
|
|
|
|
reset_particle(&sim, pa, 0.0, 1.0);
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
if (pe_x_mirror(ob))
|
|
|
|
point->flag |= PEP_TAG; /* signal for duplicate */
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
framestep = pa->lifetime / (float)(pset->totaddkey - 1);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (tree) {
|
|
|
|
ParticleData *ppa;
|
|
|
|
HairKey *thkey;
|
|
|
|
ParticleKey key3[3];
|
|
|
|
KDTreeNearest ptn[3];
|
|
|
|
int w, maxw;
|
2018-08-14 10:00:15 +10:00
|
|
|
float maxd, totw = 0.0, weight[3];
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-19 15:25:48 +02:00
|
|
|
psys_particle_on_dm(psmd_eval->mesh_final, psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co1, 0, 0, 0, 0);
|
2016-12-28 17:30:58 +01:00
|
|
|
maxw = BLI_kdtree_find_nearest_n(tree, co1, ptn, 3);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
maxd = ptn[maxw - 1].dist;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (w = 0; w < maxw; w++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
weight[w] = (float)pow(2.0, (double)(-6.0f * ptn[w].dist / maxd));
|
|
|
|
totw += weight[w];
|
|
|
|
}
|
2018-08-14 10:00:15 +10:00
|
|
|
for (; w < 3; w++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
weight[w] = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (totw > 0.0f) {
|
2018-08-14 10:00:15 +10:00
|
|
|
for (w = 0; w < maxw; w++)
|
2016-12-28 17:30:58 +01:00
|
|
|
weight[w] /= totw;
|
|
|
|
}
|
|
|
|
else {
|
2018-08-14 10:00:15 +10:00
|
|
|
for (w = 0; w < maxw; w++)
|
|
|
|
weight[w] = 1.0f / maxw;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
ppa = psys->particles + ptn[0].index;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 0; k < pset->totaddkey; k++) {
|
|
|
|
thkey = (HairKey *)pa->hair + k;
|
|
|
|
thkey->time = pa->time + k * framestep;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
key3[0].time = thkey->time / 100.0f;
|
2016-12-28 17:30:58 +01:00
|
|
|
psys_get_particle_on_path(&sim, ptn[0].index, key3, 0);
|
|
|
|
mul_v3_fl(key3[0].co, weight[0]);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* TODO: interpolating the weight would be nicer */
|
2018-08-14 10:00:15 +10:00
|
|
|
thkey->weight = (ppa->hair + MIN2(k, ppa->totkey - 1))->weight;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (maxw > 1) {
|
|
|
|
key3[1].time = key3[0].time;
|
2016-12-28 17:30:58 +01:00
|
|
|
psys_get_particle_on_path(&sim, ptn[1].index, &key3[1], 0);
|
|
|
|
mul_v3_fl(key3[1].co, weight[1]);
|
|
|
|
add_v3_v3(key3[0].co, key3[1].co);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (maxw > 2) {
|
|
|
|
key3[2].time = key3[0].time;
|
2016-12-28 17:30:58 +01:00
|
|
|
psys_get_particle_on_path(&sim, ptn[2].index, &key3[2], 0);
|
|
|
|
mul_v3_fl(key3[2].co, weight[2]);
|
|
|
|
add_v3_v3(key3[0].co, key3[2].co);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
if (k == 0)
|
2016-12-28 17:30:58 +01:00
|
|
|
sub_v3_v3v3(co1, pa->state.co, key3[0].co);
|
|
|
|
|
|
|
|
add_v3_v3v3(thkey->co, key3[0].co, co1);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
thkey->time = key3[0].time;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 0, hkey = pa->hair; k < pset->totaddkey; k++, hkey++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
madd_v3_v3v3fl(hkey->co, pa->state.co, pa->state.vel, k * framestep * timestep);
|
|
|
|
hkey->time += k * framestep;
|
2018-08-14 10:00:15 +10:00
|
|
|
hkey->weight = 1.f - (float)k / (float)(pset->totaddkey - 1);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
2018-08-14 10:00:15 +10:00
|
|
|
for (k = 0, hkey = pa->hair; k < pset->totaddkey; k++, hkey++) {
|
2018-06-19 15:25:48 +02:00
|
|
|
psys_mat_hair_to_global(ob, psmd_eval->mesh_final, psys->part->from, pa, hairmat);
|
2016-12-28 17:30:58 +01:00
|
|
|
invert_m4_m4(imat, hairmat);
|
|
|
|
mul_m4_v3(imat, hkey->co);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tree)
|
|
|
|
BLI_kdtree_free(tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(add_pars);
|
|
|
|
|
|
|
|
BLI_rng_free(rng);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************* brush edit operator ********************/
|
|
|
|
|
|
|
|
typedef struct BrushEdit {
|
|
|
|
Scene *scene;
|
2017-11-23 13:51:49 -02:00
|
|
|
ViewLayer *view_layer;
|
2016-12-28 17:30:58 +01:00
|
|
|
Object *ob;
|
|
|
|
PTCacheEdit *edit;
|
|
|
|
|
|
|
|
int first;
|
|
|
|
int lastmouse[2];
|
|
|
|
float zfac;
|
|
|
|
|
|
|
|
/* optional cached view settings to avoid setting on every mousemove */
|
|
|
|
PEData data;
|
|
|
|
} BrushEdit;
|
|
|
|
|
|
|
|
static int brush_edit_init(bContext *C, wmOperator *op)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2017-11-23 13:51:49 -02:00
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
2018-08-14 10:00:15 +10:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2018-08-14 10:02:43 +10:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2018-08-14 10:00:15 +10:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
BrushEdit *bedit;
|
|
|
|
float min[3], max[3];
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-03-06 21:48:22 +11:00
|
|
|
if (!WM_toolsystem_active_tool_is_brush(C)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return 0;
|
2019-03-06 21:48:22 +11:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* set the 'distance factor' for grabbing (used in comb etc) */
|
|
|
|
INIT_MINMAX(min, max);
|
2017-11-23 13:51:49 -02:00
|
|
|
PE_minmax(scene, view_layer, min, max);
|
2016-12-28 17:30:58 +01:00
|
|
|
mid_v3_v3v3(min, min, max);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
bedit = MEM_callocN(sizeof(BrushEdit), "BrushEdit");
|
|
|
|
bedit->first = 1;
|
|
|
|
op->customdata = bedit;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
bedit->scene = scene;
|
2017-11-23 13:51:49 -02:00
|
|
|
bedit->view_layer = view_layer;
|
2018-08-14 10:00:15 +10:00
|
|
|
bedit->ob = ob;
|
|
|
|
bedit->edit = edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
bedit->zfac = ED_view3d_calc_zfac(ar->regiondata, min, NULL);
|
|
|
|
|
|
|
|
/* cache view depths and settings for re-use */
|
|
|
|
PE_set_view3d_data(C, &bedit->data);
|
2018-06-20 11:27:19 +02:00
|
|
|
PE_create_random_generator(&bedit->data);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
BrushEdit *bedit = op->customdata;
|
2018-05-11 12:44:43 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2018-08-14 10:00:15 +10:00
|
|
|
Scene *scene = bedit->scene;
|
|
|
|
Object *ob = bedit->ob;
|
|
|
|
PTCacheEdit *edit = bedit->edit;
|
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval = edit->psmd_eval;
|
2018-08-14 10:00:15 +10:00
|
|
|
ParticleBrushData *brush = &pset->brush[pset->brushtype];
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
float vec[3], mousef[2];
|
|
|
|
int mval[2];
|
2018-08-14 10:00:15 +10:00
|
|
|
int flip, mouse[2], removed = 0, added = 0, selected = 0, tot_steps = 1, step = 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
float dx, dy, dmax;
|
|
|
|
int lock_root = pset->flag & PE_LOCK_FIRST;
|
|
|
|
|
|
|
|
if (!PE_start_edit(edit))
|
|
|
|
return;
|
|
|
|
|
|
|
|
RNA_float_get_array(itemptr, "mouse", mousef);
|
|
|
|
mouse[0] = mousef[0];
|
|
|
|
mouse[1] = mousef[1];
|
2018-08-14 10:00:15 +10:00
|
|
|
flip = RNA_boolean_get(itemptr, "pen_flip");
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (bedit->first) {
|
|
|
|
bedit->lastmouse[0] = mouse[0];
|
|
|
|
bedit->lastmouse[1] = mouse[1];
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
dx = mouse[0] - bedit->lastmouse[0];
|
|
|
|
dy = mouse[1] - bedit->lastmouse[1];
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
mval[0] = mouse[0];
|
|
|
|
mval[1] = mouse[1];
|
|
|
|
|
|
|
|
|
|
|
|
/* disable locking temporatily for disconnected hair */
|
|
|
|
if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR)
|
|
|
|
pset->flag &= ~PE_LOCK_FIRST;
|
|
|
|
|
|
|
|
if (((pset->brushtype == PE_BRUSH_ADD) ?
|
|
|
|
(sqrtf(dx * dx + dy * dy) > pset->brush[PE_BRUSH_ADD].step) : (dx != 0 || dy != 0)) || bedit->first)
|
|
|
|
{
|
2018-06-20 11:27:19 +02:00
|
|
|
PEData data = bedit->data;
|
2018-02-08 00:15:09 -05:00
|
|
|
data.context = C; // TODO(mai): why isnt this set in bedit->data?
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
view3d_operator_needs_opengl(C);
|
2018-08-14 10:00:15 +10:00
|
|
|
selected = (short)count_selected_keys(scene, edit);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
dmax = max_ff(fabsf(dx), fabsf(dy));
|
2018-08-14 10:00:15 +10:00
|
|
|
tot_steps = dmax / (0.2f * pe_brush_size_get(scene, brush)) + 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
dx /= (float)tot_steps;
|
|
|
|
dy /= (float)tot_steps;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (step = 1; step <= tot_steps; step++) {
|
|
|
|
mval[0] = bedit->lastmouse[0] + step * dx;
|
|
|
|
mval[1] = bedit->lastmouse[1] + step * dy;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
switch (pset->brushtype) {
|
|
|
|
case PE_BRUSH_COMB:
|
|
|
|
{
|
|
|
|
const float mval_f[2] = {dx, dy};
|
2018-08-14 10:00:15 +10:00
|
|
|
data.mval = mval;
|
|
|
|
data.rad = pe_brush_size_get(scene, brush);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
data.combfac = (brush->strength - 0.5f) * 2.0f;
|
2016-12-28 17:30:58 +01:00
|
|
|
if (data.combfac < 0.0f)
|
2018-08-14 10:00:15 +10:00
|
|
|
data.combfac = 1.0f - 9.0f * data.combfac;
|
2016-12-28 17:30:58 +01:00
|
|
|
else
|
2018-08-14 10:00:15 +10:00
|
|
|
data.combfac = 1.0f - data.combfac;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
invert_m4_m4(ob->imat, ob->obmat);
|
|
|
|
|
|
|
|
ED_view3d_win_to_delta(ar, mval_f, vec, bedit->zfac);
|
2018-08-14 10:00:15 +10:00
|
|
|
data.dvec = vec;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
foreach_mouse_hit_key(&data, brush_comb, selected);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PE_BRUSH_CUT:
|
|
|
|
{
|
|
|
|
if (edit->psys && edit->pathcache) {
|
2018-08-14 10:00:15 +10:00
|
|
|
data.mval = mval;
|
|
|
|
data.rad = pe_brush_size_get(scene, brush);
|
|
|
|
data.cutfac = brush->strength;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (selected)
|
|
|
|
foreach_selected_point(&data, brush_cut);
|
|
|
|
else
|
|
|
|
foreach_point(&data, brush_cut);
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
removed = remove_tagged_particles(ob, edit->psys, pe_x_mirror(ob));
|
2016-12-28 17:30:58 +01:00
|
|
|
if (pset->flag & PE_KEEP_LENGTHS)
|
|
|
|
recalc_lengths(edit);
|
|
|
|
}
|
|
|
|
else
|
2018-08-14 10:00:15 +10:00
|
|
|
removed = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PE_BRUSH_LENGTH:
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
data.mval = mval;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
data.rad = pe_brush_size_get(scene, brush);
|
|
|
|
data.growfac = brush->strength / 50.0f;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (brush->invert ^ flip)
|
2018-08-14 10:00:15 +10:00
|
|
|
data.growfac = 1.0f - data.growfac;
|
2016-12-28 17:30:58 +01:00
|
|
|
else
|
2018-08-14 10:00:15 +10:00
|
|
|
data.growfac = 1.0f + data.growfac;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
foreach_mouse_hit_point(&data, brush_length, selected);
|
|
|
|
|
|
|
|
if (pset->flag & PE_KEEP_LENGTHS)
|
|
|
|
recalc_lengths(edit);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PE_BRUSH_PUFF:
|
|
|
|
{
|
|
|
|
if (edit->psys) {
|
2018-06-19 15:25:48 +02:00
|
|
|
data.mesh = psmd_eval->mesh_final;
|
2018-08-14 10:00:15 +10:00
|
|
|
data.mval = mval;
|
|
|
|
data.rad = pe_brush_size_get(scene, brush);
|
|
|
|
data.select = selected;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
data.pufffac = (brush->strength - 0.5f) * 2.0f;
|
2016-12-28 17:30:58 +01:00
|
|
|
if (data.pufffac < 0.0f)
|
2018-08-14 10:00:15 +10:00
|
|
|
data.pufffac = 1.0f - 9.0f * data.pufffac;
|
2016-12-28 17:30:58 +01:00
|
|
|
else
|
2018-08-14 10:00:15 +10:00
|
|
|
data.pufffac = 1.0f - data.pufffac;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
data.invert = (brush->invert ^ flip);
|
2016-12-28 17:30:58 +01:00
|
|
|
invert_m4_m4(ob->imat, ob->obmat);
|
|
|
|
|
|
|
|
foreach_mouse_hit_point(&data, brush_puff, selected);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PE_BRUSH_ADD:
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
if (edit->psys && edit->psys->part->from == PART_FROM_FACE) {
|
|
|
|
data.mval = mval;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:02:43 +10:00
|
|
|
added = brush_add(C, &data, brush->count);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (pset->flag & PE_KEEP_LENGTHS)
|
|
|
|
recalc_lengths(edit);
|
|
|
|
}
|
|
|
|
else
|
2018-08-14 10:00:15 +10:00
|
|
|
added = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PE_BRUSH_SMOOTH:
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
data.mval = mval;
|
|
|
|
data.rad = pe_brush_size_get(scene, brush);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
data.vec[0] = data.vec[1] = data.vec[2] = 0.0f;
|
2018-08-14 10:00:15 +10:00
|
|
|
data.tot = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
data.smoothfac = brush->strength;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
invert_m4_m4(ob->imat, ob->obmat);
|
|
|
|
|
|
|
|
foreach_mouse_hit_key(&data, brush_smooth_get, selected);
|
|
|
|
|
|
|
|
if (data.tot) {
|
|
|
|
mul_v3_fl(data.vec, 1.0f / (float)data.tot);
|
|
|
|
foreach_mouse_hit_key(&data, brush_smooth_do, selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PE_BRUSH_WEIGHT:
|
|
|
|
{
|
|
|
|
if (edit->psys) {
|
2018-06-19 15:25:48 +02:00
|
|
|
data.mesh = psmd_eval->mesh_final;
|
2018-08-14 10:00:15 +10:00
|
|
|
data.mval = mval;
|
|
|
|
data.rad = pe_brush_size_get(scene, brush);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
data.weightfac = brush->strength; /* note that this will never be zero */
|
|
|
|
|
|
|
|
foreach_mouse_hit_key(&data, BKE_brush_weight_get, selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-08-14 10:00:15 +10:00
|
|
|
if ((pset->flag & PE_KEEP_LENGTHS) == 0)
|
2016-12-28 17:30:58 +01:00
|
|
|
recalc_lengths(edit);
|
|
|
|
|
|
|
|
if (ELEM(pset->brushtype, PE_BRUSH_ADD, PE_BRUSH_CUT) && (added || removed)) {
|
|
|
|
if (pset->brushtype == PE_BRUSH_ADD && pe_x_mirror(ob))
|
2011-06-21 11:15:37 +00:00
|
|
|
PE_mirror_x(scene, ob, 1);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-05-11 12:44:43 +02:00
|
|
|
update_world_cos(depsgraph, ob, edit);
|
2016-12-28 17:30:58 +01:00
|
|
|
psys_free_path_cache(NULL, edit);
|
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
|
|
|
}
|
2017-08-16 12:45:11 +10:00
|
|
|
else {
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_object(depsgraph, scene, ob, 1);
|
2017-08-16 12:45:11 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (edit->psys) {
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, ob);
|
2018-08-23 10:14:29 -03:00
|
|
|
BKE_particle_batch_cache_dirty_tag(edit->psys, BKE_PARTICLE_BATCH_DIRTY_ALL);
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_SELECT);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
else {
|
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_MODIFIER, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bedit->lastmouse[0] = mouse[0];
|
|
|
|
bedit->lastmouse[1] = mouse[1];
|
2018-08-14 10:00:15 +10:00
|
|
|
bedit->first = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pset->flag |= lock_root;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void brush_edit_exit(wmOperator *op)
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
BrushEdit *bedit = op->customdata;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-06-20 11:27:19 +02:00
|
|
|
PE_free_random_generator(&bedit->data);
|
2016-12-28 17:30:58 +01:00
|
|
|
MEM_freeN(bedit);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int brush_edit_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
if (!brush_edit_init(C, op))
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
RNA_BEGIN(op->ptr, itemptr, "stroke")
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
brush_edit_apply(C, op, &itemptr);
|
|
|
|
}
|
|
|
|
RNA_END;
|
|
|
|
|
|
|
|
brush_edit_exit(op);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void brush_edit_apply_event(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
{
|
|
|
|
PointerRNA itemptr;
|
|
|
|
float mouse[2];
|
|
|
|
|
2019-01-20 16:22:55 +01:00
|
|
|
copy_v2fl_v2i(mouse, event->mval);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* fill in stroke */
|
|
|
|
RNA_collection_add(op->ptr, "stroke", &itemptr);
|
|
|
|
|
|
|
|
RNA_float_set_array(&itemptr, "mouse", mouse);
|
|
|
|
RNA_boolean_set(&itemptr, "pen_flip", event->shift != false); // XXX hardcoded
|
|
|
|
|
|
|
|
/* apply */
|
|
|
|
brush_edit_apply(C, op, &itemptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int brush_edit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
{
|
|
|
|
if (!brush_edit_init(C, op))
|
|
|
|
return OPERATOR_CANCELLED;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
brush_edit_apply_event(C, op, event);
|
|
|
|
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int brush_edit_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->type) {
|
|
|
|
case LEFTMOUSE:
|
|
|
|
case MIDDLEMOUSE:
|
|
|
|
case RIGHTMOUSE: // XXX hardcoded
|
2018-06-13 18:23:09 +02:00
|
|
|
if (event->val == KM_RELEASE) {
|
|
|
|
brush_edit_exit(op);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
break;
|
2016-12-28 17:30:58 +01:00
|
|
|
case MOUSEMOVE:
|
|
|
|
brush_edit_apply_event(C, op, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void brush_edit_cancel(bContext *UNUSED(C), wmOperator *op)
|
|
|
|
{
|
|
|
|
brush_edit_exit(op);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_brush_edit(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Brush Edit";
|
|
|
|
ot->idname = "PARTICLE_OT_brush_edit";
|
|
|
|
ot->description = "Apply a stroke of brush to the particles";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = brush_edit_exec;
|
|
|
|
ot->invoke = brush_edit_invoke;
|
|
|
|
ot->modal = brush_edit_modal;
|
|
|
|
ot->cancel = brush_edit_cancel;
|
|
|
|
ot->poll = PE_poll_view3d;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* properties */
|
2017-10-16 16:11:04 +11:00
|
|
|
PropertyRNA *prop;
|
|
|
|
prop = RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************** cut shape ***************************/
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool shape_cut_poll(bContext *C)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
if (PE_hair_poll(C)) {
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (pset->shape_object && (pset->shape_object->type == OB_MESH)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct PointInsideBVH {
|
|
|
|
BVHTreeFromMesh bvhdata;
|
|
|
|
int num_hits;
|
|
|
|
} PointInsideBVH;
|
|
|
|
|
|
|
|
static void point_inside_bvh_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
|
|
|
|
{
|
|
|
|
PointInsideBVH *data = userdata;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
data->bvhdata.raycast_callback(&data->bvhdata, index, ray, hit);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (hit->index != -1)
|
|
|
|
++data->num_hits;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* true if the point is inside the shape mesh */
|
|
|
|
static bool shape_cut_test_point(PEData *data, ParticleCacheKey *key)
|
|
|
|
{
|
|
|
|
BVHTreeFromMesh *shape_bvh = &data->shape_bvh;
|
|
|
|
const float dir[3] = {1.0f, 0.0f, 0.0f};
|
|
|
|
PointInsideBVH userdata;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
userdata.bvhdata = data->shape_bvh;
|
|
|
|
userdata.num_hits = 0;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
BLI_bvhtree_ray_cast_all(
|
2018-08-14 10:00:15 +10:00
|
|
|
shape_bvh->tree, key->co, dir, 0.0f, BVH_RAYCAST_DIST_MAX,
|
|
|
|
point_inside_bvh_cb, &userdata);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* for any point inside a watertight mesh the number of hits is uneven */
|
|
|
|
return (userdata.num_hits % 2) == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shape_cut(PEData *data, int pa_index)
|
|
|
|
{
|
|
|
|
PTCacheEdit *edit = data->edit;
|
|
|
|
Object *ob = data->ob;
|
|
|
|
ParticleEditSettings *pset = PE_settings(data->scene);
|
|
|
|
ParticleCacheKey *key;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
bool cut;
|
|
|
|
float cut_time = 1.0;
|
|
|
|
int k, totkeys = 1 << pset->draw_step;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* don't cut hidden */
|
|
|
|
if (edit->points[pa_index].flag & PEP_HIDE)
|
|
|
|
return;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
cut = false;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* check if root is inside the cut shape */
|
|
|
|
key = edit->pathcache[pa_index];
|
|
|
|
if (!shape_cut_test_point(data, key)) {
|
|
|
|
cut_time = -1.0f;
|
|
|
|
cut = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (k = 0; k < totkeys; k++, key++) {
|
|
|
|
BVHTreeRayHit hit;
|
|
|
|
float dir[3];
|
|
|
|
float len;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
sub_v3_v3v3(dir, (key + 1)->co, key->co);
|
2016-12-28 17:30:58 +01:00
|
|
|
len = normalize_v3(dir);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
memset(&hit, 0, sizeof(hit));
|
|
|
|
hit.index = -1;
|
|
|
|
hit.dist = len;
|
|
|
|
BLI_bvhtree_ray_cast(data->shape_bvh.tree, key->co, dir, 0.0f, &hit, data->shape_bvh.raycast_callback, &data->shape_bvh);
|
|
|
|
if (hit.index >= 0) {
|
|
|
|
if (hit.dist < len) {
|
|
|
|
cut_time = (hit.dist / len + (float)k) / (float)totkeys;
|
|
|
|
cut = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cut) {
|
|
|
|
if (cut_time < 0.0f) {
|
|
|
|
edit->points[pa_index].flag |= PEP_TAG;
|
|
|
|
}
|
|
|
|
else {
|
2018-04-01 11:03:25 +02:00
|
|
|
rekey_particle_to_time(data->context, data->scene, ob, pa_index, cut_time);
|
2016-12-28 17:30:58 +01:00
|
|
|
edit->points[pa_index].flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2018-05-11 12:44:43 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
ParticleEditSettings *pset = PE_settings(scene);
|
2014-10-22 16:36:23 +02:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
Object *shapeob = pset->shape_object;
|
|
|
|
int selected = count_selected_keys(scene, edit);
|
|
|
|
int lock_root = pset->flag & PE_LOCK_FIRST;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (!PE_start_edit(edit))
|
|
|
|
return OPERATOR_CANCELLED;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* disable locking temporatily for disconnected hair */
|
|
|
|
if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR)
|
|
|
|
pset->flag &= ~PE_LOCK_FIRST;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (edit->psys && edit->pathcache) {
|
|
|
|
PEData data;
|
|
|
|
int removed;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
PE_set_data(C, &data);
|
|
|
|
if (!PE_create_shape_tree(&data, shapeob)) {
|
|
|
|
/* shapeob may not have faces... */
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (selected)
|
|
|
|
foreach_selected_point(&data, shape_cut);
|
|
|
|
else
|
|
|
|
foreach_point(&data, shape_cut);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
removed = remove_tagged_particles(ob, edit->psys, pe_x_mirror(ob));
|
|
|
|
recalc_lengths(edit);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (removed) {
|
2018-05-11 12:44:43 +02:00
|
|
|
update_world_cos(depsgraph, ob, edit);
|
2016-12-28 17:30:58 +01:00
|
|
|
psys_free_path_cache(NULL, edit);
|
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
|
|
|
}
|
2017-08-16 12:45:11 +10:00
|
|
|
else {
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_object(data.depsgraph, scene, ob, 1);
|
2017-08-16 12:45:11 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (edit->psys) {
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, ob);
|
2018-08-23 10:14:29 -03:00
|
|
|
BKE_particle_batch_cache_dirty_tag(edit->psys, BKE_PARTICLE_BATCH_DIRTY_ALL);
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_SELECT);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
else {
|
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_MODIFIER, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
PE_free_shape_tree(&data);
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
pset->flag |= lock_root;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_shape_cut(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Shape Cut";
|
|
|
|
ot->idname = "PARTICLE_OT_shape_cut";
|
|
|
|
ot->description = "Cut hair to conform to the set shape object";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = shape_cut_exec;
|
|
|
|
ot->poll = shape_cut_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ utilities ******************************/
|
|
|
|
|
2017-11-23 13:51:49 -02:00
|
|
|
int PE_minmax(Scene *scene, ViewLayer *view_layer, float min[3], float max[3])
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-08-14 10:02:43 +10:00
|
|
|
Object *ob = OBACT(view_layer);
|
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSystem *psys;
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval = NULL;
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P; KEY_K;
|
|
|
|
float co[3], mat[4][4];
|
2018-08-14 10:00:15 +10:00
|
|
|
int ok = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (!edit) return ok;
|
|
|
|
|
|
|
|
if ((psys = edit->psys))
|
2018-06-19 15:25:48 +02:00
|
|
|
psmd_eval = edit->psmd_eval;
|
2016-12-28 17:30:58 +01:00
|
|
|
else
|
|
|
|
unit_m4(mat);
|
|
|
|
|
|
|
|
LOOP_VISIBLE_POINTS {
|
|
|
|
if (psys)
|
2018-08-14 10:02:43 +10:00
|
|
|
psys_mat_hair_to_global(ob, psmd_eval->mesh_final, psys->part->from, psys->particles + p, mat);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
LOOP_SELECTED_KEYS {
|
|
|
|
copy_v3_v3(co, key->co);
|
|
|
|
mul_m4_v3(mat, co);
|
|
|
|
DO_MINMAX(co, min, max);
|
2018-08-14 10:00:15 +10:00
|
|
|
ok = 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
BKE_object_minmax(ob, min, max, true);
|
2018-08-14 10:00:15 +10:00
|
|
|
ok = 1;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************ particle edit toggle operator ************************/
|
|
|
|
|
|
|
|
/* initialize needed data for bake edit */
|
2017-08-16 12:45:11 +10:00
|
|
|
void PE_create_particle_edit(
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph, Scene *scene, Object *ob, PointCache *cache, ParticleSystem *psys)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-06-19 15:25:48 +02:00
|
|
|
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
PTCacheEdit *edit;
|
|
|
|
ParticleSystemModifierData *psmd = (psys) ? psys_get_modifier(ob, psys) : NULL;
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystemModifierData *psmd_eval = NULL;
|
2016-12-28 17:30:58 +01:00
|
|
|
POINT_P; KEY_K;
|
|
|
|
ParticleData *pa = NULL;
|
|
|
|
HairKey *hkey;
|
|
|
|
int totpoint;
|
|
|
|
|
2018-06-19 15:25:48 +02:00
|
|
|
if (psmd != NULL) {
|
|
|
|
psmd_eval = (ParticleSystemModifierData *)modifiers_findByName(ob_eval, psmd->modifier.name);
|
|
|
|
}
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* no psmd->dm happens in case particle system modifier is not enabled */
|
2018-06-19 15:25:48 +02:00
|
|
|
if (!(psys && psmd && psmd_eval->mesh_final) && !cache)
|
2016-12-28 17:30:58 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (cache && cache->flag & PTCACHE_DISK_CACHE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (psys == NULL && (cache && BLI_listbase_is_empty(&cache->mem_cache)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
edit = (psys) ? psys->edit : cache->edit;
|
|
|
|
|
|
|
|
if (!edit) {
|
2018-06-19 15:25:48 +02:00
|
|
|
ParticleSystem *psys_eval = psys_eval_get(depsgraph, ob, psys);
|
|
|
|
psys_copy_particles(psys, psys_eval);
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
totpoint = psys ? psys->totpart : (int)((PTCacheMem *)cache->mem_cache.first)->totpoint;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
edit = MEM_callocN(sizeof(PTCacheEdit), "PE_create_particle_edit");
|
|
|
|
edit->points = MEM_callocN(totpoint * sizeof(PTCacheEditPoint), "PTCacheEditPoints");
|
2016-12-28 17:30:58 +01:00
|
|
|
edit->totpoint = totpoint;
|
|
|
|
|
|
|
|
if (psys && !cache) {
|
2018-06-19 15:25:48 +02:00
|
|
|
edit->psmd = psmd;
|
|
|
|
edit->psmd_eval = psmd_eval;
|
|
|
|
psys->edit = edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
edit->psys = psys;
|
2018-06-19 15:25:48 +02:00
|
|
|
edit->psys_eval = psys_eval;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
psys->free_edit = PE_free_ptcache_edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
edit->pathcache = NULL;
|
|
|
|
BLI_listbase_clear(&edit->pathcachebufs);
|
|
|
|
|
|
|
|
pa = psys->particles;
|
|
|
|
LOOP_POINTS {
|
|
|
|
point->totkey = pa->totkey;
|
2018-08-14 10:00:15 +10:00
|
|
|
point->keys = MEM_callocN(point->totkey * sizeof(PTCacheEditKey), "ParticleEditKeys");
|
2016-12-28 17:30:58 +01:00
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
|
|
|
|
hkey = pa->hair;
|
|
|
|
LOOP_KEYS {
|
2018-08-14 10:00:15 +10:00
|
|
|
key->co = hkey->co;
|
|
|
|
key->time = &hkey->time;
|
|
|
|
key->flag = hkey->editflag;
|
2016-12-28 17:30:58 +01:00
|
|
|
if (!(psys->flag & PSYS_GLOBAL_HAIR)) {
|
|
|
|
key->flag |= PEK_USE_WCO;
|
|
|
|
hkey->editflag |= PEK_USE_WCO;
|
|
|
|
}
|
|
|
|
|
|
|
|
hkey++;
|
|
|
|
}
|
|
|
|
pa++;
|
|
|
|
}
|
2018-05-11 12:44:43 +02:00
|
|
|
update_world_cos(depsgraph, ob, edit);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PTCacheMem *pm;
|
2018-08-14 10:00:15 +10:00
|
|
|
int totframe = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
cache->edit = edit;
|
|
|
|
cache->free_edit = PE_free_ptcache_edit;
|
2016-12-28 17:30:58 +01:00
|
|
|
edit->psys = NULL;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (pm = cache->mem_cache.first; pm; pm = pm->next)
|
2016-12-28 17:30:58 +01:00
|
|
|
totframe++;
|
|
|
|
|
2018-08-14 10:00:15 +10:00
|
|
|
for (pm = cache->mem_cache.first; pm; pm = pm->next) {
|
2016-12-28 17:30:58 +01:00
|
|
|
LOOP_POINTS {
|
|
|
|
if (BKE_ptcache_mem_pointers_seek(p, pm) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!point->totkey) {
|
2018-08-14 10:00:15 +10:00
|
|
|
key = point->keys = MEM_callocN(totframe * sizeof(PTCacheEditKey), "ParticleEditKeys");
|
2016-12-28 17:30:58 +01:00
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
key = point->keys + point->totkey;
|
|
|
|
|
|
|
|
key->co = pm->cur[BPHYS_DATA_LOCATION];
|
|
|
|
key->vel = pm->cur[BPHYS_DATA_VELOCITY];
|
|
|
|
key->rot = pm->cur[BPHYS_DATA_ROTATION];
|
|
|
|
key->ftime = (float)pm->frame;
|
|
|
|
key->time = &key->ftime;
|
|
|
|
BKE_ptcache_mem_pointers_incr(pm);
|
|
|
|
|
|
|
|
point->totkey++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
psys = NULL;
|
|
|
|
}
|
|
|
|
|
2018-06-18 17:39:35 +02:00
|
|
|
/* Causes assert on startup. */
|
|
|
|
#if 0
|
2016-12-28 17:30:58 +01:00
|
|
|
UI_GetThemeColor3ubv(TH_EDGE_SELECT, edit->sel_col);
|
|
|
|
UI_GetThemeColor3ubv(TH_WIRE, edit->nosel_col);
|
2018-06-18 17:39:35 +02:00
|
|
|
#else
|
|
|
|
memset(edit->sel_col, 0xff, sizeof(edit->sel_col));
|
|
|
|
memset(edit->nosel_col, 0x00, sizeof(edit->nosel_col));
|
|
|
|
#endif
|
2016-12-28 17:30:58 +01:00
|
|
|
recalc_lengths(edit);
|
|
|
|
if (psys && !cache)
|
2018-05-15 16:15:13 +02:00
|
|
|
recalc_emitter_field(depsgraph, ob, psys);
|
2018-04-03 14:19:51 +02:00
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_object(depsgraph, scene, ob, 1);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool particle_edit_toggle_poll(bContext *C)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
|
|
|
|
if (ob == NULL || ob->type != OB_MESH)
|
|
|
|
return 0;
|
2017-11-06 17:17:10 +01:00
|
|
|
if (!ob->data || ID_IS_LINKED(ob->data))
|
2016-12-28 17:30:58 +01:00
|
|
|
return 0;
|
|
|
|
if (CTX_data_edit_object(C))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return (ob->particlesystem.first ||
|
|
|
|
modifiers_findByType(ob, eModifierType_Cloth) ||
|
|
|
|
modifiers_findByType(ob, eModifierType_Softbody));
|
|
|
|
}
|
|
|
|
|
2018-12-21 14:24:16 +01:00
|
|
|
static void free_all_psys_edit(Object *object)
|
|
|
|
{
|
|
|
|
for (ParticleSystem *psys = object->particlesystem.first;
|
|
|
|
psys != NULL;
|
|
|
|
psys = psys->next)
|
|
|
|
{
|
|
|
|
if (psys->edit != NULL) {
|
|
|
|
BLI_assert(psys->free_edit != NULL);
|
|
|
|
psys->free_edit(psys->edit);
|
|
|
|
psys->free_edit = NULL;
|
|
|
|
psys->edit = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2018-05-08 07:22:52 +02:00
|
|
|
struct wmMsgBus *mbus = CTX_wm_message_bus(C);
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
const int mode_flag = OB_MODE_PARTICLE_EDIT;
|
2018-04-05 18:20:27 +02:00
|
|
|
const bool is_mode_set = (ob->mode & mode_flag) != 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
if (!is_mode_set) {
|
2018-04-05 18:20:27 +02:00
|
|
|
if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_mode_set) {
|
|
|
|
PTCacheEdit *edit;
|
2017-08-16 12:45:11 +10:00
|
|
|
|
2018-04-05 18:20:27 +02:00
|
|
|
ob->mode |= mode_flag;
|
2018-06-06 13:53:51 +02:00
|
|
|
|
2018-08-14 10:02:43 +10:00
|
|
|
edit = PE_create_current(depsgraph, scene, ob);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-11-16 14:21:57 +01:00
|
|
|
/* Mesh may have changed since last entering editmode.
|
|
|
|
* note, this may have run before if the edit data was just created,
|
|
|
|
* so could avoid this and speed up a little. */
|
|
|
|
if (edit && edit->psys) {
|
|
|
|
/* Make sure pointer to the evaluated modifier data is up to date,
|
|
|
|
* with possible changes applied when object was outside of the
|
|
|
|
* edit mode. */
|
|
|
|
Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
|
|
|
|
edit->psmd_eval = (ParticleSystemModifierData *)modifiers_findByName(
|
|
|
|
object_eval, edit->psmd->modifier.name);
|
2018-05-15 16:15:13 +02:00
|
|
|
recalc_emitter_field(depsgraph, ob, edit->psys);
|
2018-11-16 14:21:57 +01:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
toggle_particle_cursor(C, 1);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_PARTICLE, NULL);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-04-05 18:20:27 +02:00
|
|
|
ob->mode &= ~mode_flag;
|
2016-12-28 17:30:58 +01:00
|
|
|
toggle_particle_cursor(C, 0);
|
2018-12-21 14:24:16 +01:00
|
|
|
free_all_psys_edit(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
|
|
|
}
|
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2018-05-08 07:22:52 +02:00
|
|
|
WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
|
|
|
|
|
2018-05-16 18:41:11 +02:00
|
|
|
WM_toolsystem_update_from_context_view3d(C);
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_particle_edit_toggle(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Particle Edit Toggle";
|
|
|
|
ot->idname = "PARTICLE_OT_particle_edit_toggle";
|
|
|
|
ot->description = "Toggle particle edit mode";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = particle_edit_toggle_exec;
|
|
|
|
ot->poll = particle_edit_toggle_poll;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************ set editable operator ************************/
|
|
|
|
|
|
|
|
static int clear_edited_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2018-08-14 10:00:15 +10:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSystem *psys = psys_get_current(ob);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (psys->edit) {
|
|
|
|
if (psys->edit->edited || 1) {
|
|
|
|
PE_free_ptcache_edit(psys->edit);
|
|
|
|
|
|
|
|
psys->edit = NULL;
|
|
|
|
psys->free_edit = NULL;
|
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
psys->recalc |= ID_RECALC_PSYS_RESET;
|
2016-12-28 17:30:58 +01:00
|
|
|
psys->flag &= ~PSYS_GLOBAL_HAIR;
|
|
|
|
psys->flag &= ~PSYS_EDITED;
|
|
|
|
|
|
|
|
psys_reset(psys, PSYS_RESET_DEPSGRAPH);
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, ob);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* some operation might have protected hair from editing so let's clear the flag */
|
2018-12-06 17:52:37 +01:00
|
|
|
psys->recalc |= ID_RECALC_PSYS_RESET;
|
2016-12-28 17:30:58 +01:00
|
|
|
psys->flag &= ~PSYS_GLOBAL_HAIR;
|
|
|
|
psys->flag &= ~PSYS_EDITED;
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, ob);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clear_edited_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
|
|
|
{
|
|
|
|
return WM_operator_confirm_message(C, op, "Lose changes done in particle mode? (no undo)");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_edited_clear(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Clear Edited";
|
|
|
|
ot->idname = "PARTICLE_OT_edited_clear";
|
|
|
|
ot->description = "Undo all edition performed on the particle system";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = clear_edited_exec;
|
|
|
|
ot->poll = particle_edit_toggle_poll;
|
|
|
|
ot->invoke = clear_edited_invoke;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ Unify length operator ************************/
|
|
|
|
|
|
|
|
static float calculate_point_length(PTCacheEditPoint *point)
|
|
|
|
{
|
|
|
|
float length = 0.0f;
|
|
|
|
KEY_K;
|
|
|
|
LOOP_KEYS {
|
|
|
|
if (k > 0) {
|
|
|
|
length += len_v3v3((key - 1)->co, key->co);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float calculate_average_length(PTCacheEdit *edit)
|
|
|
|
{
|
|
|
|
int num_selected = 0;
|
|
|
|
float total_length = 0;
|
|
|
|
POINT_P;
|
|
|
|
LOOP_SELECTED_POINTS {
|
|
|
|
total_length += calculate_point_length(point);
|
|
|
|
++num_selected;
|
|
|
|
}
|
|
|
|
if (num_selected == 0) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
return total_length / num_selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void scale_point_factor(PTCacheEditPoint *point, float factor)
|
|
|
|
{
|
|
|
|
float orig_prev_co[3], prev_co[3];
|
|
|
|
KEY_K;
|
|
|
|
LOOP_KEYS {
|
|
|
|
if (k == 0) {
|
|
|
|
copy_v3_v3(orig_prev_co, key->co);
|
|
|
|
copy_v3_v3(prev_co, key->co);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float new_co[3];
|
|
|
|
float delta[3];
|
|
|
|
|
|
|
|
sub_v3_v3v3(delta, key->co, orig_prev_co);
|
|
|
|
mul_v3_fl(delta, factor);
|
|
|
|
add_v3_v3v3(new_co, prev_co, delta);
|
|
|
|
|
|
|
|
copy_v3_v3(orig_prev_co, key->co);
|
|
|
|
copy_v3_v3(key->co, new_co);
|
|
|
|
copy_v3_v3(prev_co, key->co);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
point->flag |= PEP_EDIT_RECALC;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void scale_point_to_length(PTCacheEditPoint *point, float length)
|
|
|
|
{
|
|
|
|
const float point_length = calculate_point_length(point);
|
|
|
|
if (point_length != 0.0f) {
|
|
|
|
const float factor = length / point_length;
|
|
|
|
scale_point_factor(point, factor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void scale_points_to_length(PTCacheEdit *edit, float length)
|
|
|
|
{
|
|
|
|
POINT_P;
|
|
|
|
LOOP_SELECTED_POINTS {
|
|
|
|
scale_point_to_length(point, length);
|
|
|
|
}
|
|
|
|
recalc_lengths(edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int unify_length_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2018-03-19 19:03:18 +01:00
|
|
|
|
2016-04-26 16:05:52 +02:00
|
|
|
PTCacheEdit *edit = PE_get_current(scene, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
float average_length = calculate_average_length(edit);
|
2017-08-16 12:45:11 +10:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (average_length == 0.0f) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
scale_points_to_length(edit, average_length);
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
PE_update_object(depsgraph, scene, ob, 1);
|
2016-12-28 17:30:58 +01:00
|
|
|
if (edit->psys) {
|
2018-08-14 10:00:15 +10:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
else {
|
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_MODIFIER, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PARTICLE_OT_unify_length(struct wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Unify Length";
|
|
|
|
ot->idname = "PARTICLE_OT_unify_length";
|
|
|
|
ot->description = "Make selected hair the same length";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = unify_length_exec;
|
|
|
|
ot->poll = PE_poll_view3d;
|
|
|
|
|
|
|
|
/* flags */
|
2018-08-14 10:00:15 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|