Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2019-06-21 12:49:43 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2019-06-21 13:09:45 +0300
commit7070e4c15e6c57da2bd46534e654ed5f9a1e6600 (patch)
tree221ceb5195fd6d98d4485db40e78d16a379107c5 /source/blender/blenkernel/intern
parent964e319a39abfe3808fded71dcacd296401ec04d (diff)
Revert "Particle system: Move runtime data to runtime field"
This reverts commit 36faf739a71624b6ca10cec7233779f9eeace0bd. Somewhat annoying but this change had some unforeseen consequences, which lead to an actual bug. Since this change was not sufficient to get original report fixed is easier to simply revert for now. Fixes T65842: Hair disappears when clicking on particle system name
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r--source/blender/blenkernel/intern/object.c13
-rw-r--r--source/blender/blenkernel/intern/particle.c108
-rw-r--r--source/blender/blenkernel/intern/particle_distribute.c14
-rw-r--r--source/blender/blenkernel/intern/particle_system.c17
4 files changed, 45 insertions, 107 deletions
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index e74b2b0f671..2a66edc8d42 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -497,13 +497,12 @@ void BKE_object_free_caches(Object *object)
for (md = object->modifiers.first; md != NULL; md = md->next) {
if (md->type == eModifierType_ParticleSystem) {
ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md;
- ParticleSystemModifierDataRuntime *psmd_runtime = BKE_particle_modifier_runtime_ensure(psmd);
- if (psmd_runtime->mesh_final) {
- BKE_id_free(NULL, psmd_runtime->mesh_final);
- psmd_runtime->mesh_final = NULL;
- if (psmd_runtime->mesh_original) {
- BKE_id_free(NULL, psmd_runtime->mesh_original);
- psmd_runtime->mesh_original = NULL;
+ if (psmd->mesh_final) {
+ BKE_id_free(NULL, psmd->mesh_final);
+ psmd->mesh_final = NULL;
+ if (psmd->mesh_original) {
+ BKE_id_free(NULL, psmd->mesh_original);
+ psmd->mesh_original = NULL;
}
psmd->flag |= eParticleSystemFlag_file_loaded;
update_flag |= ID_RECALC_GEOMETRY;
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 61ee5685451..13649eaf096 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -1889,8 +1889,7 @@ void psys_particle_on_emitter(ParticleSystemModifierData *psmd,
float vtan[3],
float orco[3])
{
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(psmd);
- if (psmd && mesh_final) {
+ if (psmd && psmd->mesh_final) {
if (psmd->psys->part->distr == PART_DISTR_GRID && psmd->psys->part->from != PART_FROM_VERT) {
if (vec) {
copy_v3_v3(vec, fuv);
@@ -1903,7 +1902,7 @@ void psys_particle_on_emitter(ParticleSystemModifierData *psmd,
}
/* we cant use the num_dmcache */
psys_particle_on_dm(
- mesh_final, from, index, index_dmcache, fuv, foffset, vec, nor, utan, vtan, orco);
+ psmd->mesh_final, from, index, index_dmcache, fuv, foffset, vec, nor, utan, vtan, orco);
}
else {
psys_particle_on_shape(from, index, fuv, vec, nor, utan, vtan, orco);
@@ -2254,15 +2253,13 @@ void psys_find_parents(ParticleSimulationData *sim, const bool use_render_params
tree = BLI_kdtree_3d_new(totparent);
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(sim->psmd);
-
for (p = 0, cpa = sim->psys->child; p < totparent; p++, cpa++) {
psys_particle_on_emitter(
sim->psmd, from, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co, 0, 0, 0, orco);
/* Check if particle doesn't exist because of texture influence.
* Insert only existing particles into kdtree. */
- get_cpa_texture(mesh_final,
+ get_cpa_texture(sim->psmd->mesh_final,
psys,
part,
psys->particles + cpa->pa[0],
@@ -2430,8 +2427,6 @@ static void psys_thread_create_path(ParticleTask *task,
return;
}
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(ctx->sim.psmd);
-
if (ctx->between) {
ParticleData *pa = psys->particles + cpa->pa[0];
int w, needupdate;
@@ -2536,7 +2531,7 @@ static void psys_thread_create_path(ParticleTask *task,
sub_v3_v3v3(off1[w], co, key[w]->co);
}
- psys_mat_hair_to_global(ob, mesh_final, psys->part->from, pa, hairmat);
+ psys_mat_hair_to_global(ob, ctx->sim.psmd->mesh_final, psys->part->from, pa, hairmat);
}
else {
ParticleData *pa = psys->particles + cpa->parent;
@@ -2567,7 +2562,7 @@ static void psys_thread_create_path(ParticleTask *task,
pa->num_dmcache;
/* XXX hack to avoid messed up particle num and subsequent crash (#40733) */
- if (cpa_num > mesh_final->totface) {
+ if (cpa_num > ctx->sim.psmd->mesh_final->totface) {
cpa_num = 0;
}
cpa_fuv = pa->fuv;
@@ -2584,7 +2579,7 @@ static void psys_thread_create_path(ParticleTask *task,
0,
orco);
- psys_mat_hair_to_global(ob, mesh_final, psys->part->from, pa, hairmat);
+ psys_mat_hair_to_global(ob, ctx->sim.psmd->mesh_final, psys->part->from, pa, hairmat);
}
child_keys->segments = ctx->segments;
@@ -2930,21 +2925,19 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
copy_v3_v3(col, &ma->r);
}
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(psmd);
-
if ((psys->flag & PSYS_GLOBAL_HAIR) == 0) {
if ((psys->part->flag & PART_CHILD_EFFECT) == 0) {
- vg_effector = psys_cache_vgroup(mesh_final, psys, PSYS_VG_EFFECTOR);
+ vg_effector = psys_cache_vgroup(psmd->mesh_final, psys, PSYS_VG_EFFECTOR);
}
if (!psys->totchild) {
- vg_length = psys_cache_vgroup(mesh_final, psys, PSYS_VG_LENGTH);
+ vg_length = psys_cache_vgroup(psmd->mesh_final, psys, PSYS_VG_LENGTH);
}
}
/* ensure we have tessfaces to be used for mapping */
if (part->from != PART_FROM_VERT) {
- BKE_mesh_tessface_ensure(mesh_final);
+ BKE_mesh_tessface_ensure(psmd->mesh_final);
}
/*---first main loop: create all actual particles' paths---*/
@@ -2954,7 +2947,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
psys_get_texture(sim, pa, &ptex, PAMAP_LENGTH, 0.f);
pa_length = ptex.length * (1.0f - part->randlength * psys_frand(psys, psys->seed + p));
if (vg_length) {
- pa_length *= psys_particle_value_from_verts(mesh_final, part->from, pa, vg_length);
+ pa_length *= psys_particle_value_from_verts(psmd->mesh_final, part->from, pa, vg_length);
}
}
@@ -2972,7 +2965,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
init_particle_interpolation(sim->ob, sim->psys, pa, &pind);
/* hairmat is needed for for non-hair particle too so we get proper rotations */
- psys_mat_hair_to_global(sim->ob, mesh_final, psys->part->from, pa, hairmat);
+ psys_mat_hair_to_global(sim->ob, psmd->mesh_final, psys->part->from, pa, hairmat);
copy_v3_v3(rotmat[0], hairmat[2]);
copy_v3_v3(rotmat[1], hairmat[1]);
copy_v3_v3(rotmat[2], hairmat[0]);
@@ -3030,7 +3023,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
float effector = 1.0f;
if (vg_effector) {
effector *= psys_particle_value_from_verts(
- mesh_final, psys->part->from, pa, vg_effector);
+ psmd->mesh_final, psys->part->from, pa, vg_effector);
}
sub_v3_v3v3(vec, (cache[p] + 1)->co, cache[p]->co);
@@ -3165,8 +3158,7 @@ static void psys_cache_edit_paths_iter(void *__restrict iter_data_v,
init_particle_interpolation(ob, psys, pa, &pind);
if (psys) {
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(psmd);
- psys_mat_hair_to_global(ob, mesh_final, psys->part->from, pa, hairmat);
+ psys_mat_hair_to_global(ob, psmd->mesh_final, psys->part->from, pa, hairmat);
copy_v3_v3(rotmat[0], hairmat[2]);
copy_v3_v3(rotmat[1], hairmat[1]);
copy_v3_v3(rotmat[2], hairmat[0]);
@@ -4046,9 +4038,8 @@ void psys_get_texture(
mul_m4_v3(mtex->object->imat, texvec);
}
break;
- case TEXCO_UV: {
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(sim->psmd);
- if (get_particle_uv(mesh_final,
+ case TEXCO_UV:
+ if (get_particle_uv(sim->psmd->mesh_final,
pa,
0,
pa->fuv,
@@ -4059,7 +4050,6 @@ void psys_get_texture(
}
/* no break, failed to get uv's, so let's try orco's */
ATTR_FALLTHROUGH;
- }
case TEXCO_ORCO:
psys_particle_on_emitter(sim->psmd,
sim->psys->part->from,
@@ -4333,8 +4323,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim,
}
else if (!keyed && !cached && !(psys->flag & PSYS_GLOBAL_HAIR)) {
if ((pa->flag & PARS_REKEY) == 0) {
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(sim->psmd);
- psys_mat_hair_to_global(sim->ob, mesh_final, part->from, pa, hairmat);
+ psys_mat_hair_to_global(sim->ob, sim->psmd->mesh_final, part->from, pa, hairmat);
mul_m4_v3(hairmat, state->co);
mul_mat3_m4_v3(hairmat, state->vel);
@@ -4416,8 +4405,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim,
0,
par_orco);
if (part->type == PART_HAIR) {
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(psmd);
- psys_mat_hair_to_global(sim->ob, mesh_final, psys->part->from, pa, hairmat);
+ psys_mat_hair_to_global(sim->ob, sim->psmd->mesh_final, psys->part->from, pa, hairmat);
}
else {
unit_m4(hairmat);
@@ -4449,10 +4437,9 @@ void psys_get_particle_on_path(ParticleSimulationData *sim,
0,
par_orco);
if (part->type == PART_HAIR) {
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(psmd);
psys_particle_on_emitter(
psmd, cpa_from, cpa_num, DMCACHE_ISCHILD, cpa_fuv, pa->foffset, co, 0, 0, 0, orco);
- psys_mat_hair_to_global(sim->ob, mesh_final, psys->part->from, pa, hairmat);
+ psys_mat_hair_to_global(sim->ob, sim->psmd->mesh_final, psys->part->from, pa, hairmat);
}
else {
copy_v3_v3(orco, cpa->fuv);
@@ -4463,7 +4450,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim,
/* get different child parameters from textures & vgroups */
memset(&ctx, 0, sizeof(ParticleThreadContext));
ctx.sim = *sim;
- ctx.mesh = BKE_particle_modifier_mesh_final_get(psmd);
+ ctx.mesh = psmd->mesh_final;
ctx.ma = ma;
/* TODO: assign vertex groups */
get_child_modifier_parameters(part, &ctx, cpa, cpa_from, cpa_num, cpa_fuv, orco, &ptex);
@@ -4728,16 +4715,14 @@ void psys_get_dupli_texture(ParticleSystem *psys,
/* Grid distribution doesn't support UV or emit from vertex mode */
bool is_grid = (part->distr == PART_DISTR_GRID && part->from != PART_FROM_VERT);
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(psmd);
-
if (cpa) {
- if ((part->childtype == PART_CHILD_FACES) && (mesh_final != NULL)) {
- CustomData *mtf_data = &mesh_final->fdata;
+ if ((part->childtype == PART_CHILD_FACES) && (psmd->mesh_final != NULL)) {
+ CustomData *mtf_data = &psmd->mesh_final->fdata;
const int uv_idx = CustomData_get_render_layer(mtf_data, CD_MTFACE);
mtface = CustomData_get_layer_n(mtf_data, CD_MTFACE, uv_idx);
if (mtface && !is_grid) {
- mface = CustomData_get(&mesh_final->fdata, cpa->num, CD_MFACE);
+ mface = CustomData_get(&psmd->mesh_final->fdata, cpa->num, CD_MFACE);
mtface += cpa->num;
psys_interpolate_uvs(mtface, mface->v4, cpa->fuv, uv);
}
@@ -4760,8 +4745,8 @@ void psys_get_dupli_texture(ParticleSystem *psys,
}
}
- if ((part->from == PART_FROM_FACE) && (mesh_final != NULL) && !is_grid) {
- CustomData *mtf_data = &mesh_final->fdata;
+ if ((part->from == PART_FROM_FACE) && (psmd->mesh_final != NULL) && !is_grid) {
+ CustomData *mtf_data = &psmd->mesh_final->fdata;
const int uv_idx = CustomData_get_render_layer(mtf_data, CD_MTFACE);
mtface = CustomData_get_layer_n(mtf_data, CD_MTFACE, uv_idx);
@@ -4771,14 +4756,14 @@ void psys_get_dupli_texture(ParticleSystem *psys,
num = pa->num;
}
- if (num >= mesh_final->totface) {
+ if (num >= psmd->mesh_final->totface) {
/* happens when simplify is enabled
* gives invalid coords but would crash otherwise */
num = DMCACHE_NOTFOUND;
}
if (mtface && !ELEM(num, DMCACHE_NOTFOUND, DMCACHE_ISCHILD)) {
- mface = CustomData_get(&mesh_final->fdata, num, CD_MFACE);
+ mface = CustomData_get(&psmd->mesh_final->fdata, num, CD_MFACE);
mtface += num;
psys_interpolate_uvs(mtface, mface->v4, pa->fuv, uv);
}
@@ -4899,10 +4884,8 @@ void psys_apply_hair_lattice(Depsgraph *depsgraph, Scene *scene, Object *ob, Par
int p, h;
float hairmat[4][4], imat[4][4];
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(sim.psmd);
-
for (p = 0; p < psys->totpart; p++, pa++) {
- psys_mat_hair_to_global(sim.ob, mesh_final, psys->part->from, pa, hairmat);
+ psys_mat_hair_to_global(sim.ob, sim.psmd->mesh_final, psys->part->from, pa, hairmat);
invert_m4_m4(imat, hairmat);
hkey = pa->hair;
@@ -4937,40 +4920,3 @@ void BKE_particle_batch_cache_free(ParticleSystem *psys)
BKE_particle_batch_cache_free_cb(psys);
}
}
-
-/* **** Particle system modifier helpers. **** */
-
-Mesh *BKE_particle_modifier_mesh_final_get(ParticleSystemModifierData *psmd)
-{
- if (psmd == NULL) {
- return NULL;
- }
- ParticleSystemModifierDataRuntime *runtime = psmd->modifier.runtime;
- if (runtime == NULL) {
- return NULL;
- }
- return runtime->mesh_final;
-}
-
-Mesh *BKE_particle_modifier_mesh_original_get(ParticleSystemModifierData *psmd)
-{
- if (psmd == NULL) {
- return NULL;
- }
- ParticleSystemModifierDataRuntime *runtime = psmd->modifier.runtime;
- if (runtime == NULL) {
- return NULL;
- }
- return runtime->mesh_original;
-}
-
-ParticleSystemModifierDataRuntime *BKE_particle_modifier_runtime_ensure(
- ParticleSystemModifierData *psmd)
-{
- BLI_assert(psmd != NULL);
- if (psmd->modifier.runtime == NULL) {
- psmd->modifier.runtime = MEM_callocN(sizeof(ParticleSystemModifierDataRuntime),
- "psmd runtime");
- }
- return psmd->modifier.runtime;
-}
diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c
index 7bb2daeab23..070c3c7a566 100644
--- a/source/blender/blenkernel/intern/particle_distribute.c
+++ b/source/blender/blenkernel/intern/particle_distribute.c
@@ -878,7 +878,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
int from)
{
Scene *scene = sim->scene;
- Mesh *final_mesh = BKE_particle_modifier_mesh_final_get(sim->psmd);
+ Mesh *final_mesh = sim->psmd->mesh_final;
Object *ob = sim->ob;
ParticleSystem *psys = sim->psys;
ParticleData *pa = 0, *tpars = 0;
@@ -926,8 +926,8 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
if (from == PART_FROM_CHILD) {
/* Simple children */
if (part->childtype != PART_CHILD_FACES) {
- Mesh *mesh_original = BKE_particle_modifier_mesh_original_get(sim->psmd);
- distribute_simple_children(scene, ob, final_mesh, mesh_original, psys, use_render_params);
+ distribute_simple_children(
+ scene, ob, final_mesh, sim->psmd->mesh_original, psys, use_render_params);
return 0;
}
}
@@ -1318,7 +1318,7 @@ static void distribute_particles_on_dm(ParticleSimulationData *sim, int from)
TaskPool *task_pool;
ParticleThreadContext ctx;
ParticleTask *tasks;
- Mesh *final_mesh = BKE_particle_modifier_mesh_final_get(sim->psmd);
+ Mesh *final_mesh = sim->psmd->mesh_final;
int i, totpart, numtasks;
/* create a task pool for distribution tasks */
@@ -1346,8 +1346,7 @@ static void distribute_particles_on_dm(ParticleSimulationData *sim, int from)
BLI_task_pool_free(task_pool);
- Mesh *mesh_original = BKE_particle_modifier_mesh_original_get(sim->psmd);
- psys_calc_dmcache(sim->ob, final_mesh, mesh_original, sim->psys);
+ psys_calc_dmcache(sim->ob, final_mesh, sim->psmd->mesh_original, sim->psys);
if (ctx.mesh != final_mesh) {
BKE_id_free(NULL, ctx.mesh);
@@ -1372,8 +1371,7 @@ void distribute_particles(ParticleSimulationData *sim, int from)
int distr_error = 0;
if (psmd) {
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(psmd);
- if (mesh_final) {
+ if (psmd->mesh_final) {
distribute_particles_on_dm(sim, from);
}
else {
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index 1b0655c6734..27722aab2d9 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -467,7 +467,7 @@ void psys_thread_context_init(ParticleThreadContext *ctx, ParticleSimulationData
{
memset(ctx, 0, sizeof(ParticleThreadContext));
ctx->sim = *sim;
- ctx->mesh = BKE_particle_modifier_mesh_final_get(ctx->sim.psmd);
+ ctx->mesh = ctx->sim.psmd->mesh_final;
ctx->ma = give_current_material(sim->ob, sim->psys->part->omat);
}
@@ -3348,7 +3348,6 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
/* make vgroup for pin roots etc.. */
hair_index = 1;
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(sim->psmd);
LOOP_PARTICLES
{
if (!(pa->flag & PARS_UNEXIST)) {
@@ -3359,7 +3358,7 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
pa->hair_index = hair_index;
use_hair = psys_hair_use_simulation(pa, max_length);
- psys_mat_hair_to_object(sim->ob, mesh_final, psys->part->from, pa, hairmat);
+ psys_mat_hair_to_object(sim->ob, sim->psmd->mesh_final, psys->part->from, pa, hairmat);
mul_m4_m4m4(root_mat, sim->ob->obmat, hairmat);
normalize_m4(root_mat);
@@ -3525,9 +3524,7 @@ static void hair_step(ParticleSimulationData *sim, float cfra, const bool use_re
if (psys->recalc & ID_RECALC_PSYS_RESET) {
/* need this for changing subsurf levels */
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(sim->psmd);
- Mesh *mesh_original = BKE_particle_modifier_mesh_original_get(sim->psmd);
- psys_calc_dmcache(sim->ob, mesh_final, mesh_original, psys);
+ psys_calc_dmcache(sim->ob, sim->psmd->mesh_final, sim->psmd->mesh_original, psys);
if (psys->clmd) {
cloth_free_modifier(psys->clmd);
@@ -3579,8 +3576,7 @@ static void save_hair(ParticleSimulationData *sim, float UNUSED(cfra))
if (pa->totkey) {
sub_v3_v3(key->co, root->co);
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(sim->psmd);
- psys_vec_rot_to_face(mesh_final, pa, key->co);
+ psys_vec_rot_to_face(sim->psmd->mesh_final, pa, key->co);
}
key->time = pa->state.time;
@@ -4614,13 +4610,12 @@ void particle_system_update(struct Depsgraph *depsgraph,
}
}
- Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(sim.psmd);
- if (!mesh_final) {
+ if (!sim.psmd->mesh_final) {
return;
}
if (part->from != PART_FROM_VERT) {
- BKE_mesh_tessface_ensure(mesh_final);
+ BKE_mesh_tessface_ensure(sim.psmd->mesh_final);
}
/* to verify if we need to restore object afterwards */