Particle edit: Support children particles display with copy on write
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 15 May 2018 12:38:02 +0000 (14:38 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 15 May 2018 15:20:02 +0000 (17:20 +0200)
source/blender/blenkernel/intern/particle.c
source/blender/draw/intern/draw_cache_impl_particles.c

index 0f23fc1deea346fdc1806d8ee74ec6241cae645e..75d4d5cf736854046dab1ce2c7dbd69e345407ab 100644 (file)
@@ -297,6 +297,14 @@ ParticleSystem *psys_original_get(ParticleSystem *psys)
        return psys->orig_psys;
 }
 
+static PTCacheEdit *psys_original_edit_get(ParticleSystem *psys)
+{
+       if (psys->orig_psys == NULL) {
+               return psys->edit;
+       }
+       return psys->orig_psys->edit;
+}
+
 bool psys_in_edit_mode(Depsgraph *depsgraph, ParticleSystem *psys)
 {
        const ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
@@ -1899,7 +1907,7 @@ static bool psys_thread_context_init_path(
        if (psys_in_edit_mode(sim->depsgraph, psys)) {
                ParticleEditSettings *pset = &scene->toolsettings->particle;
 
-               if ((use_render_params == 0) && (psys->edit == NULL || pset->flag & PE_DRAW_PART) == 0)
+               if ((use_render_params == 0) && (psys_original_edit_get(psys) == NULL || pset->flag & PE_DRAW_PART) == 0)
                        totchild = 0;
 
                segments = 1 << pset->draw_step;
@@ -1993,7 +2001,8 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp
        ParticleSystem *psys = ctx->sim.psys;
        ParticleSettings *part = psys->part;
        ParticleCacheKey **cache = psys->childcache;
-       ParticleCacheKey **pcache = psys_in_edit_mode(ctx->sim.depsgraph, psys) && psys->edit ? psys->edit->pathcache : psys->pathcache;
+       PTCacheEdit *edit = psys_original_edit_get(psys);
+       ParticleCacheKey **pcache = psys_in_edit_mode(ctx->sim.depsgraph, psys) && edit ? edit->pathcache : psys->pathcache;
        ParticleCacheKey *child, *key[4];
        ParticleTexture ptex;
        float *cpa_fuv = 0, *par_rot = 0, rot[4];
@@ -2019,7 +2028,7 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp
                        needupdate = 0;
                        w = 0;
                        while (w < 4 && cpa->pa[w] >= 0) {
-                               if (psys->edit->points[cpa->pa[w]].flag & PEP_EDIT_RECALC) {
+                               if (edit->points[cpa->pa[w]].flag & PEP_EDIT_RECALC) {
                                        needupdate = 1;
                                        break;
                                }
@@ -2106,7 +2115,7 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp
                ParticleData *pa = psys->particles + cpa->parent;
                float co[3];
                if (ctx->editupdate) {
-                       if (!(psys->edit->points[cpa->parent].flag & PEP_EDIT_RECALC))
+                       if (!(edit->points[cpa->parent].flag & PEP_EDIT_RECALC))
                                return;
 
                        memset(child_keys, 0, sizeof(*child_keys) * (ctx->segments + 1));
index f9b3735eb426961e9b1c7384bfee5aa2899a1fde..a1eb98a85e21657a0b7fbfbb481f2c5d1f12b611 100644 (file)
@@ -616,6 +616,7 @@ static void particle_batch_cache_ensure_pos(Object *object,
 }
 
 static void drw_particle_update_ptcache_edit(Object *object_eval,
+                                             ParticleSystem *psys,
                                              PTCacheEdit *edit)
 {
        if (edit->psys == NULL) {
@@ -627,8 +628,9 @@ static void drw_particle_update_ptcache_edit(Object *object_eval,
        const DRWContextState *draw_ctx = DRW_context_state_get();
        Scene *scene_orig = (Scene *)DEG_get_original_id(&draw_ctx->scene->id);
        Object *object_orig = DEG_get_original_object(object_eval);
-       if (edit->psys->flag & PSYS_HAIR_UPDATED) {
+       if (psys->flag & PSYS_HAIR_UPDATED) {
                PE_update_object(draw_ctx->depsgraph, scene_orig, object_orig, 0);
+               psys->flag &= ~PSYS_HAIR_UPDATED;
        }
        if (edit->pathcache == NULL) {
                Depsgraph *depsgraph = draw_ctx->depsgraph;
@@ -640,7 +642,8 @@ static void drw_particle_update_ptcache_edit(Object *object_eval,
        }
 }
 
-static void drw_particle_update_ptcache(Object *object_eval)
+static void drw_particle_update_ptcache(Object *object_eval,
+                                        ParticleSystem *psys)
 {
        if ((object_eval->mode & OB_MODE_PARTICLE_EDIT) == 0) {
                return;
@@ -651,7 +654,7 @@ static void drw_particle_update_ptcache(Object *object_eval)
        PTCacheEdit *edit = PE_create_current(
                draw_ctx->depsgraph, scene_orig, object_orig);
        if (edit != NULL) {
-               drw_particle_update_ptcache_edit(object_eval, edit);
+               drw_particle_update_ptcache_edit(object_eval, psys, edit);
        }
 }
 
@@ -663,7 +666,7 @@ Gwn_Batch *DRW_particles_batch_cache_get_hair(
        ParticleBatchCache *cache = particle_batch_cache_get(psys);
 
        if (cache->hair.hairs == NULL) {
-               drw_particle_update_ptcache(object);
+               drw_particle_update_ptcache(object, psys);
                ensure_seg_pt_count(NULL, psys, &cache->hair);
                particle_batch_cache_ensure_pos_and_seg(NULL, psys, md, &cache->hair);
                cache->hair.hairs = GWN_batch_create(GWN_PRIM_LINE_STRIP,
@@ -695,7 +698,7 @@ Gwn_Batch *DRW_particles_batch_cache_get_edit_strands(
        if (cache->edit_hair.hairs != NULL) {
                return cache->edit_hair.hairs;
        }
-       drw_particle_update_ptcache_edit(object, edit);
+       drw_particle_update_ptcache_edit(object, psys, edit);
        ensure_seg_pt_count(edit, psys, &cache->edit_hair);
        particle_batch_cache_ensure_pos_and_seg(edit, psys, NULL, &cache->edit_hair);
        cache->edit_hair.hairs = GWN_batch_create(GWN_PRIM_LINE_STRIP,
@@ -779,7 +782,7 @@ Gwn_Batch *DRW_particles_batch_cache_get_edit_inner_points(
        if (cache->edit_inner_points != NULL) {
                return cache->edit_inner_points;
        }
-       drw_particle_update_ptcache_edit(object, edit);
+       drw_particle_update_ptcache_edit(object, psys, edit);
        ensure_edit_inner_points_count(edit, cache);
        particle_batch_cache_ensure_edit_inner_pos(edit, cache);
        cache->edit_inner_points = GWN_batch_create(GWN_PRIM_POINTS,
@@ -844,7 +847,7 @@ Gwn_Batch *DRW_particles_batch_cache_get_edit_tip_points(
        if (cache->edit_tip_points != NULL) {
                return cache->edit_tip_points;
        }
-       drw_particle_update_ptcache_edit(object, edit);
+       drw_particle_update_ptcache_edit(object, psys, edit);
        ensure_edit_tip_points_count(edit, cache);
        particle_batch_cache_ensure_edit_tip_pos(edit, cache);
        cache->edit_tip_points = GWN_batch_create(GWN_PRIM_POINTS,