diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-05-15 14:08:06 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-05-15 18:20:02 +0300 |
commit | f43d33d3a404f9b3abdf1a3d44aeb646812506a4 (patch) | |
tree | 8147aa647d4f18d758950051343822174407b29d /source | |
parent | 4f5bcc30d3447a7a498b124bf6e35fe177a8a320 (diff) |
Depsgraph: Keep track of original particle system
Allows to have quicker lookup in particle edit mode.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_particle.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle.c | 22 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 1 | ||||
-rw-r--r-- | source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc | 17 | ||||
-rw-r--r-- | source/blender/draw/modes/particle_mode.c | 3 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_particle_types.h | 9 |
6 files changed, 40 insertions, 13 deletions
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h index 0c8d00e16a3..c2217969c98 100644 --- a/source/blender/blenkernel/BKE_particle.h +++ b/source/blender/blenkernel/BKE_particle.h @@ -302,6 +302,7 @@ void psys_set_current_num(Object *ob, int index); struct LatticeDeformData *psys_create_lattice_deform_data(struct ParticleSimulationData *sim); +struct ParticleSystem *psys_original_get(struct ParticleSystem *psys); bool psys_in_edit_mode(struct Depsgraph *depsgraph, struct ParticleSystem *psys); bool psys_check_enabled(struct Object *ob, struct ParticleSystem *psys, const bool use_render_params); bool psys_check_edited(struct ParticleSystem *psys); diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index d740963cde8..0f23fc1deea 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -289,6 +289,14 @@ void psys_enable_all(Object *ob) psys->flag &= ~PSYS_DISABLED; } +ParticleSystem *psys_original_get(ParticleSystem *psys) +{ + if (psys->orig_psys == NULL) { + return psys; + } + return psys->orig_psys; +} + bool psys_in_edit_mode(Depsgraph *depsgraph, ParticleSystem *psys) { const ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); @@ -301,19 +309,7 @@ bool psys_in_edit_mode(Depsgraph *depsgraph, ParticleSystem *psys) if (object->mode != OB_MODE_PARTICLE_EDIT) { return false; } - /* TODO(sergey): Find a faster way to switch to an original psys. */ - /*const*/ Object *object_orig = DEG_get_original_object(view_layer->basact->object); - ParticleSystem *psys_orig = object_orig->particlesystem.first; - while (psys_orig != NULL) { - if (STREQ(psys_orig->name, psys->name)) { - break; - } - psys = psys->next; - psys_orig = psys_orig->next; - } - if (psys_orig != psys_get_current(object_orig)) { - return false; - } + ParticleSystem *psys_orig = psys_original_get(psys); return (psys_orig->edit || psys->pointcache->edit) && (use_render_params == false); } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index f1aa4bd4ff1..6c617b52734 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4476,6 +4476,7 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles) psys->tree = NULL; psys->bvhtree = NULL; + psys->orig_psys = NULL; psys->batch_cache = NULL; } return; diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc index 7fd59f6408c..40f9402abc8 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc @@ -67,6 +67,7 @@ extern "C" { #include "DNA_mesh_types.h" #include "DNA_scene_types.h" #include "DNA_object_types.h" +#include "DNA_particle_types.h" #ifdef NESTED_ID_NASTY_WORKAROUND # include "DNA_curve_types.h" @@ -443,11 +444,26 @@ void updata_edit_mode_pointers(const Depsgraph *depsgraph, break; case ID_ME: updata_mesh_edit_mode_pointers(depsgraph, id_orig, id_cow); + break; default: break; } } +void update_particle_system_orig_pointers(const Object *object_orig, + Object *object_cow) +{ + ParticleSystem *psys_cow = + (ParticleSystem *) object_cow->particlesystem.first; + ParticleSystem *psys_orig = + (ParticleSystem *) object_orig->particlesystem.first; + while (psys_orig != NULL) { + psys_cow->orig_psys = psys_orig; + psys_cow = psys_cow->next; + psys_orig = psys_orig->next; + } +} + /* Do some special treatment of data transfer from original ID to it's * CoW complementary part. * @@ -473,6 +489,7 @@ void update_special_pointers(const Depsgraph *depsgraph, BKE_pose_remap_bone_pointers((bArmature *)object_cow->data, object_cow->pose); } + update_particle_system_orig_pointers(object_orig, object_cow); break; } default: diff --git a/source/blender/draw/modes/particle_mode.c b/source/blender/draw/modes/particle_mode.c index 39af98d7165..fe82e894495 100644 --- a/source/blender/draw/modes/particle_mode.c +++ b/source/blender/draw/modes/particle_mode.c @@ -183,6 +183,9 @@ static void particle_cache_populate(void *vedata, Object *object) Object *object_orig = DEG_get_original_object(object); PTCacheEdit *edit = PE_create_current( draw_ctx->depsgraph, scene_orig, object_orig); + /* NOTE: We need to pass evaluated particle system, which we need + * to find first. + */ ParticleSystem *psys = object->particlesystem.first; ParticleSystem *psys_orig = object_orig->particlesystem.first; while (psys_orig != NULL) { diff --git a/source/blender/makesdna/DNA_particle_types.h b/source/blender/makesdna/DNA_particle_types.h index 2c330501820..123fa8e171e 100644 --- a/source/blender/makesdna/DNA_particle_types.h +++ b/source/blender/makesdna/DNA_particle_types.h @@ -326,6 +326,15 @@ typedef struct ParticleSystem { float lattice_strength; /* influence of the lattice modifier */ void *batch_cache; + + /* Set by dependency graph's copy-on-write, allows to quickly go + * from evaluated particle system to original one. + * + * Original system will have this set to NULL. + * + * Use psys_original_get() function to access, + */ + struct ParticleSystem *orig_psys; } ParticleSystem; typedef enum eParticleDrawFlag { |