[Bf-blender-cvs] [36faf739a71] master: Particle system: Move runtime data to runtime field
Sergey Sharybin
noreply at git.blender.org
Thu Jun 13 11:41:23 CEST 2019
Commit: 36faf739a71624b6ca10cec7233779f9eeace0bd
Author: Sergey Sharybin
Date: Wed Jun 5 12:39:40 2019 +0200
Branches: master
https://developer.blender.org/rB36faf739a71624b6ca10cec7233779f9eeace0bd
Particle system: Move runtime data to runtime field
Allows it to be preserved during copy-on-write update when on-geometry
related update is needed.
This is a required part for T63537, where we need to preserve the entire
evaluation data when object is tagged for only RECALC_COPY_ON_WRITE.
Reviewers: brecht
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D5023
===================================================================
M source/blender/blenkernel/BKE_particle.h
M source/blender/blenkernel/intern/object.c
M source/blender/blenkernel/intern/particle.c
M source/blender/blenkernel/intern/particle_distribute.c
M source/blender/blenkernel/intern/particle_system.c
M source/blender/blenloader/intern/readfile.c
M source/blender/draw/intern/draw_cache_impl_particles.c
M source/blender/editors/physics/particle_edit.c
M source/blender/editors/physics/particle_object.c
M source/blender/editors/transform/transform_conversions.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_particle.c
M source/blender/modifiers/intern/MOD_explode.c
M source/blender/modifiers/intern/MOD_particleinstance.c
M source/blender/modifiers/intern/MOD_particlesystem.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 164dbbbf482..ca3a560286f 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -38,6 +38,7 @@ struct ParticleKey;
struct ParticleSettings;
struct ParticleSystem;
struct ParticleSystemModifierData;
+struct ParticleSystemModifierDataRuntime;
struct BVHTreeRay;
struct BVHTreeRayHit;
@@ -608,6 +609,13 @@ float psys_get_current_display_percentage(struct ParticleSystem *psys,
#define DMCACHE_NOTFOUND -1
#define DMCACHE_ISCHILD -2
+/* **** Particle system modifier helpers. **** */
+
+struct Mesh *BKE_particle_modifier_mesh_final_get(struct ParticleSystemModifierData *psmd);
+struct Mesh *BKE_particle_modifier_mesh_original_get(struct ParticleSystemModifierData *psmd);
+struct ParticleSystemModifierDataRuntime *BKE_particle_modifier_runtime_ensure(
+ struct ParticleSystemModifierData *psmd);
+
/* **** Depsgraph evaluation **** */
struct Depsgraph;
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 2a66edc8d42..e74b2b0f671 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -497,12 +497,13 @@ 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;
- 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;
+ 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;
}
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 13649eaf096..61ee5685451 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -1889,7 +1889,8 @@ void psys_particle_on_emitter(ParticleSystemModifierData *psmd,
float vtan[3],
float orco[3])
{
- if (psmd && psmd->mesh_final) {
+ Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(psmd);
+ if (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);
@@ -1902,7 +1903,7 @@ void psys_particle_on_emitter(ParticleSystemModifierData *psmd,
}
/* we cant use the num_dmcache */
psys_particle_on_dm(
- psmd->mesh_final, from, index, index_dmcache, fuv, foffset, vec, nor, utan, vtan, orco);
+ 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);
@@ -2253,13 +2254,15 @@ 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(sim->psmd->mesh_final,
+ get_cpa_texture(mesh_final,
psys,
part,
psys->particles + cpa->pa[0],
@@ -2427,6 +2430,8 @@ 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;
@@ -2531,7 +2536,7 @@ static void psys_thread_create_path(ParticleTask *task,
sub_v3_v3v3(off1[w], co, key[w]->co);
}
- psys_mat_hair_to_global(ob, ctx->sim.psmd->mesh_final, psys->part->from, pa, hairmat);
+ psys_mat_hair_to_global(ob, mesh_final, psys->part->from, pa, hairmat);
}
else {
ParticleData *pa = psys->particles + cpa->parent;
@@ -2562,7 +2567,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 > ctx->sim.psmd->mesh_final->totface) {
+ if (cpa_num > mesh_final->totface) {
cpa_num = 0;
}
cpa_fuv = pa->fuv;
@@ -2579,7 +2584,7 @@ static void psys_thread_create_path(ParticleTask *task,
0,
orco);
- psys_mat_hair_to_global(ob, ctx->sim.psmd->mesh_final, psys->part->from, pa, hairmat);
+ psys_mat_hair_to_global(ob, mesh_final, psys->part->from, pa, hairmat);
}
child_keys->segments = ctx->segments;
@@ -2925,19 +2930,21 @@ 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(psmd->mesh_final, psys, PSYS_VG_EFFECTOR);
+ vg_effector = psys_cache_vgroup(mesh_final, psys, PSYS_VG_EFFECTOR);
}
if (!psys->totchild) {
- vg_length = psys_cache_vgroup(psmd->mesh_final, psys, PSYS_VG_LENGTH);
+ vg_length = psys_cache_vgroup(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(psmd->mesh_final);
+ BKE_mesh_tessface_ensure(mesh_final);
}
/*---first main loop: create all actual particles' paths---*/
@@ -2947,7 +2954,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(psmd->mesh_final, part->from, pa, vg_length);
+ pa_length *= psys_particle_value_from_verts(mesh_final, part->from, pa, vg_length);
}
}
@@ -2965,7 +2972,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, psmd->mesh_final, psys->part->from, pa, hairmat);
+ psys_mat_hair_to_global(sim->ob, 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]);
@@ -3023,7 +3030,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(
- psmd->mesh_final, psys->part->from, pa, vg_effector);
+ mesh_final, psys->part->from, pa, vg_effector);
}
sub_v3_v3v3(vec, (cache[p] + 1)->co, cache[p]->co);
@@ -3158,7 +3165,8 @@ static void psys_cache_edit_paths_iter(void *__restrict iter_data_v,
init_particle_interpolation(ob, psys, pa, &pind);
if (psys) {
- psys_mat_hair_to_global(ob, psmd->mesh_final, psys->part->from, pa, hairmat);
+ Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(psmd);
+ psys_mat_hair_to_global(ob, 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]);
@@ -4038,8 +4046,9 @@ void psys_get_texture(
mul_m4_v3(mtex->object->imat, texvec);
}
break;
- case TEXCO_UV:
- if (get_particle_uv(sim->psmd->mesh_final,
+ case TEXCO_UV: {
+ Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(sim->psmd);
+ if (get_particle_uv(mesh_final,
pa,
0,
pa->fuv,
@@ -4050,6 +4059,7 @@ 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,
@@ -4323,7 +4333,8 @@ void psys_get_particle_on_path(ParticleSimulationData *sim,
}
else if (!keyed && !cached && !(psys->flag & PSYS_GLOBAL_HAIR)) {
if ((pa->flag & PARS_REKEY) == 0) {
- psys_mat_hair_to_global(sim->ob, sim->psmd->mesh_final, part->from, pa, hairmat);
+ Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(sim->psmd);
+ psys_mat_hair_to_global(sim->ob, mesh_final, part->from, pa, hairmat);
mul_m4_v3(hairmat, state->co);
mul_mat3_m4_v3(hairmat, state->vel);
@@ -4405,7 +4416,8 @@ void psys_get_particle_on_path(ParticleSimulationData *sim,
0,
par_orco);
if (part->type == PART_HAIR) {
- psys_mat_hair_to_global(sim->ob, sim->psmd->mesh_final, psys->part->from, pa, hairmat);
+ Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(psmd);
+ psys_mat_hair_to_global(sim->ob, mesh_final, psys->part->from, pa, hairmat);
}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list