diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-08-19 14:11:48 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-08-19 14:11:48 +0400 |
commit | c46cbc602e1007a15c6d9824ec34c41f124faeaa (patch) | |
tree | 3cc89f89a2601d7a8de18ef39b7207803b5f75fd /source/blender/blenkernel/intern | |
parent | b9ae749480aeeb7e77f16ebe667ddfcf8b63650e (diff) |
Make lattice deform safe for threading
Lattice deformation used to store some runtime data
inside of lattice datablock itself. It's something
which is REALLY bad. Ideally DNA shouldn't contain
and runtime data.
For now solved it in a way that initialization of
lattice deform will create a structure which contains
lattice object for which deformation is calculating
and that runtime data which used to be stored in
lattice datablock itself.
It works really fine for mesh deform modifier, but
there's still runtime data stored in particle system
DNA, It didn't look something easy to be solved, so
leaving this as-is for now.
--
svn merge -r58277:58278 -r58795:58796 ^/branches/soc-2013-depsgraph_mt
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/anim.c | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lattice.c | 59 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle.c | 48 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle_system.c | 22 |
4 files changed, 76 insertions, 61 deletions
diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index b5a56024976..1b1bcffb493 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -1330,7 +1330,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p psys_check_group_weights(part); - psys->lattice = psys_get_lattice(&sim); + psys->lattice_deform_data = psys_create_lattice_deform_data(&sim); /* gather list of objects or single object */ if (part->ren_as == PART_DRAW_GR) { @@ -1567,9 +1567,9 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p if (obcopylist) MEM_freeN(obcopylist); - if (psys->lattice) { - end_latt_deform(psys->lattice); - psys->lattice = NULL; + if (psys->lattice_deform_data) { + end_latt_deform(psys->lattice_deform_data); + psys->lattice_deform_data = NULL; } } diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index b6baeea51b1..60b4db6aa9b 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -307,7 +307,13 @@ void BKE_lattice_make_local(Lattice *lt) } } -void init_latt_deform(Object *oblatt, Object *ob) +typedef struct LatticeDeformData { + Object *object; + float *latticedata; + float latmat[4][4]; +} LatticeDeformData; + +LatticeDeformData *init_latt_deform(Object *oblatt, Object *ob) { /* we make an array with all differences */ Lattice *lt = oblatt->data; @@ -317,27 +323,30 @@ void init_latt_deform(Object *oblatt, Object *ob) float *fp, imat[4][4]; float fu, fv, fw; int u, v, w; + float *latticedata; + float latmat[4][4]; + LatticeDeformData *lattice_deform_data; if (lt->editlatt) lt = lt->editlatt->latt; bp = lt->def; - fp = lt->latticedata = MEM_mallocN(sizeof(float) * 3 * lt->pntsu * lt->pntsv * lt->pntsw, "latticedata"); + fp = latticedata = MEM_mallocN(sizeof(float) * 3 * lt->pntsu * lt->pntsv * lt->pntsw, "latticedata"); /* for example with a particle system: (ob == NULL) */ if (ob == NULL) { /* in deformspace, calc matrix */ - invert_m4_m4(lt->latmat, oblatt->obmat); + invert_m4_m4(latmat, oblatt->obmat); /* back: put in deform array */ - invert_m4_m4(imat, lt->latmat); + invert_m4_m4(imat, latmat); } else { /* in deformspace, calc matrix */ invert_m4_m4(imat, oblatt->obmat); - mul_m4_m4m4(lt->latmat, imat, ob->obmat); + mul_m4_m4m4(latmat, imat, ob->obmat); /* back: put in deform array */ - invert_m4_m4(imat, lt->latmat); + invert_m4_m4(imat, latmat); } for (w = 0, fw = lt->fw; w < lt->pntsw; w++, fw += lt->dw) { @@ -358,10 +367,18 @@ void init_latt_deform(Object *oblatt, Object *ob) } } } + + lattice_deform_data = MEM_mallocN(sizeof(LatticeDeformData), "Lattice Deform Data"); + lattice_deform_data->latticedata = latticedata; + lattice_deform_data->object = oblatt; + copy_m4_m4(lattice_deform_data->latmat, latmat); + + return lattice_deform_data; } -void calc_latt_deform(Object *ob, float co[3], float weight) +void calc_latt_deform(LatticeDeformData *lattice_deform_data, float co[3], float weight) { + Object *ob = lattice_deform_data->object; Lattice *lt = ob->data; float u, v, w, tu[4], tv[4], tw[4]; float vec[3]; @@ -375,7 +392,7 @@ void calc_latt_deform(Object *ob, float co[3], float weight) if (lt->editlatt) lt = lt->editlatt->latt; - if (lt->latticedata == NULL) return; + if (lattice_deform_data->latticedata == NULL) return; if (lt->vgroup[0] && dvert) { defgrp_index = defgroup_name_index(ob, lt->vgroup); @@ -383,7 +400,7 @@ void calc_latt_deform(Object *ob, float co[3], float weight) } /* co is in local coords, treat with latmat */ - mul_v3_m4v3(vec, lt->latmat, co); + mul_v3_m4v3(vec, lattice_deform_data->latmat, co); /* u v w coords */ @@ -456,7 +473,7 @@ void calc_latt_deform(Object *ob, float co[3], float weight) idx_u = idx_v; } - madd_v3_v3fl(co, <->latticedata[idx_u * 3], u); + madd_v3_v3fl(co, &lattice_deform_data->latticedata[idx_u * 3], u); if (defgrp_index != -1) weight_blend += (u * defvert_find_weight(dvert + idx_u, defgrp_index)); @@ -472,15 +489,12 @@ void calc_latt_deform(Object *ob, float co[3], float weight) } -void end_latt_deform(Object *ob) +void end_latt_deform(LatticeDeformData *lattice_deform_data) { - Lattice *lt = ob->data; - - if (lt->editlatt) lt = lt->editlatt->latt; - - if (lt->latticedata) - MEM_freeN(lt->latticedata); - lt->latticedata = NULL; + if (lattice_deform_data->latticedata) + MEM_freeN(lattice_deform_data->latticedata); + + MEM_freeN(lattice_deform_data); } /* calculations is in local space of deformed object @@ -815,13 +829,14 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target, void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm, float (*vertexCos)[3], int numVerts, const char *vgroup, float fac) { + LatticeDeformData *lattice_deform_data; int a; int use_vgroups; if (laOb->type != OB_LATTICE) return; - init_latt_deform(laOb, target); + lattice_deform_data = init_latt_deform(laOb, target); /* check whether to use vertex groups (only possible if target is a Mesh) * we want either a Mesh with no derived data, or derived data with @@ -855,16 +870,16 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm, weight = defvert_find_weight(dvert, defgrp_index); if (weight > 0.0f) - calc_latt_deform(laOb, vertexCos[a], weight * fac); + calc_latt_deform(lattice_deform_data, vertexCos[a], weight * fac); } } } else { for (a = 0; a < numVerts; a++) { - calc_latt_deform(laOb, vertexCos[a], fac); + calc_latt_deform(lattice_deform_data, vertexCos[a], fac); } } - end_latt_deform(laOb); + end_latt_deform(lattice_deform_data); } int object_deform_mball(Object *ob, ListBase *dispbase) diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 6b754743c11..216bc94a058 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -221,12 +221,12 @@ Object *psys_find_object(Scene *scene, ParticleSystem *psys) } #endif -Object *psys_get_lattice(ParticleSimulationData *sim) +struct LatticeDeformData *psys_create_lattice_deform_data(ParticleSimulationData *sim) { - Object *lattice = NULL; - - if (psys_in_edit_mode(sim->scene, sim->psys) == 0) { + struct LatticeDeformData *lattice_deform_data = NULL; + if (psys_in_edit_mode(sim->scene, sim->psys) == 0) { + Object *lattice = NULL; ModifierData *md = (ModifierData *)psys_get_modifier(sim->ob, sim->psys); for (; md; md = md->next) { @@ -237,10 +237,10 @@ Object *psys_get_lattice(ParticleSimulationData *sim) } } if (lattice) - init_latt_deform(lattice, NULL); + lattice_deform_data = init_latt_deform(lattice, NULL); } - return lattice; + return lattice_deform_data; } void psys_disable_all(Object *ob) { @@ -2513,7 +2513,7 @@ static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float c ctx->cfra = cfra; ctx->editupdate = editupdate; - psys->lattice = psys_get_lattice(&ctx->sim); + psys->lattice_deform_data = psys_create_lattice_deform_data(&ctx->sim); /* cache all relevant vertex groups if they exist */ ctx->vg_length = psys_cache_vgroup(ctx->dm, psys, PSYS_VG_LENGTH); @@ -2974,7 +2974,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) psys_free_path_cache(psys, psys->edit); cache = psys->pathcache = psys_alloc_path_cache_buffers(&psys->pathcachebufs, totpart, steps + 1); - psys->lattice = psys_get_lattice(sim); + psys->lattice_deform_data = psys_create_lattice_deform_data(sim); ma = give_current_material(sim->ob, psys->part->omat); if (ma && (psys->part->draw_col == PART_DRAW_COL_MAT)) copy_v3_v3(col, &ma->r); @@ -3079,9 +3079,9 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) } /* lattices have to be calculated separately to avoid mixups between effector calculations */ - if (psys->lattice) { + if (psys->lattice_deform_data) { for (k = 0, ca = cache[p]; k <= steps; k++, ca++) - calc_latt_deform(psys->lattice, ca->co, 1.0f); + calc_latt_deform(psys->lattice_deform_data, ca->co, 1.0f); } } @@ -3112,9 +3112,9 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) psys->totcached = totpart; - if (psys->lattice) { - end_latt_deform(psys->lattice); - psys->lattice = NULL; + if (psys->lattice_deform_data) { + end_latt_deform(psys->lattice_deform_data); + psys->lattice_deform_data = NULL; } if (vg_effector) @@ -4166,8 +4166,8 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * /* TODO: proper velocity handling */ } - if (psys->lattice && edit == 0) - calc_latt_deform(psys->lattice, state->co, 1.0f); + if (psys->lattice_deform_data && edit == 0) + calc_latt_deform(psys->lattice_deform_data, state->co, 1.0f); } } } @@ -4402,8 +4402,8 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta unit_m4(mat); do_child_modifiers(sim, NULL, key1, key1->rot, cpa, cpa->fuv, mat, state, t); - if (psys->lattice) - calc_latt_deform(sim->psys->lattice, state->co, 1.0f); + if (psys->lattice_deform_data) + calc_latt_deform(psys->lattice_deform_data, state->co, 1.0f); } else { if (pa->state.time == cfra || ELEM(part->phystype, PART_PHYS_NO, PART_PHYS_KEYED)) @@ -4461,8 +4461,8 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta } } - if (sim->psys->lattice) - calc_latt_deform(sim->psys->lattice, state->co, 1.0f); + if (sim->psys->lattice_deform_data) + calc_latt_deform(sim->psys->lattice_deform_data, state->co, 1.0f); } return 1; @@ -4678,9 +4678,9 @@ void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys) sim.psys = psys; sim.psmd = psys_get_modifier(ob, psys); - psys->lattice = psys_get_lattice(&sim); + psys->lattice_deform_data = psys_create_lattice_deform_data(&sim); - if (psys->lattice) { + if (psys->lattice_deform_data) { ParticleData *pa = psys->particles; HairKey *hkey; int p, h; @@ -4693,13 +4693,13 @@ void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys) hkey = pa->hair; for (h = 0; h < pa->totkey; h++, hkey++) { mul_m4_v3(hairmat, hkey->co); - calc_latt_deform(psys->lattice, hkey->co, 1.0f); + calc_latt_deform(psys->lattice_deform_data, hkey->co, 1.0f); mul_m4_v3(imat, hkey->co); } } - end_latt_deform(psys->lattice); - psys->lattice = NULL; + end_latt_deform(psys->lattice_deform_data); + psys->lattice_deform_data = NULL; /* protect the applied shape */ psys->flag |= PSYS_EDITED; diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 16ea71204cc..ee3f3332ec3 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -1514,9 +1514,9 @@ void psys_threads_free(ParticleThread *threads) if (ctx->vg_roughe) MEM_freeN(ctx->vg_roughe); - if (ctx->sim.psys->lattice) { - end_latt_deform(ctx->sim.psys->lattice); - ctx->sim.psys->lattice= NULL; + if (ctx->sim.psys->lattice_deform_data) { + end_latt_deform(ctx->sim.psys->lattice_deform_data); + ctx->sim.psys->lattice_deform_data = NULL; } /* distribution */ @@ -4108,7 +4108,7 @@ static void save_hair(ParticleSimulationData *sim, float UNUSED(cfra)) invert_m4_m4(ob->imat, ob->obmat); - psys->lattice= psys_get_lattice(sim); + psys->lattice_deform_data= psys_create_lattice_deform_data(sim); if (psys->totpart==0) return; @@ -4479,7 +4479,7 @@ static void cached_step(ParticleSimulationData *sim, float cfra) if (part->randsize > 0.0f) pa->size *= 1.0f - part->randsize * PSYS_FRAND(p + 1); - psys->lattice= psys_get_lattice(sim); + psys->lattice_deform_data = psys_create_lattice_deform_data(sim); dietime = pa->dietime; @@ -4494,9 +4494,9 @@ static void cached_step(ParticleSimulationData *sim, float cfra) else pa->alive = PARS_ALIVE; - if (psys->lattice) { - end_latt_deform(psys->lattice); - psys->lattice= NULL; + if (psys->lattice_deform_data) { + end_latt_deform(psys->lattice_deform_data); + psys->lattice_deform_data = NULL; } if (PSYS_FRAND(p) > disp) @@ -4777,9 +4777,9 @@ static void system_step(ParticleSimulationData *sim, float cfra) update_children(sim); /* cleanup */ - if (psys->lattice) { - end_latt_deform(psys->lattice); - psys->lattice= NULL; + if (psys->lattice_deform_data) { + end_latt_deform(psys->lattice_deform_data); + psys->lattice_deform_data = NULL; } } |