Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/particle_system.c
| Show First 20 Lines • Show All 461 Lines • ▼ Show 20 Lines | void psys_calc_dmcache(Object *ob, Mesh *mesh_final, Mesh *mesh_original, ParticleSystem *psys) | ||||
| } | } | ||||
| } | } | ||||
| /* threaded child particle distribution and path caching */ | /* threaded child particle distribution and path caching */ | ||||
| void psys_thread_context_init(ParticleThreadContext *ctx, ParticleSimulationData *sim) | void psys_thread_context_init(ParticleThreadContext *ctx, ParticleSimulationData *sim) | ||||
| { | { | ||||
| memset(ctx, 0, sizeof(ParticleThreadContext)); | memset(ctx, 0, sizeof(ParticleThreadContext)); | ||||
| ctx->sim = *sim; | ctx->sim = *sim; | ||||
| ctx->mesh = ctx->sim.psmd->mesh_final; | ctx->mesh = BKE_particle_modifier_mesh_final_get(ctx->sim.psmd); | ||||
| ctx->ma = give_current_material(sim->ob, sim->psys->part->omat); | ctx->ma = give_current_material(sim->ob, sim->psys->part->omat); | ||||
| } | } | ||||
| void psys_tasks_create(ParticleThreadContext *ctx, | void psys_tasks_create(ParticleThreadContext *ctx, | ||||
| int startpart, | int startpart, | ||||
| int endpart, | int endpart, | ||||
| ParticleTask **r_tasks, | ParticleTask **r_tasks, | ||||
| int *r_numtasks) | int *r_numtasks) | ||||
| ▲ Show 20 Lines • Show All 2,864 Lines • ▼ Show 20 Lines | static void hair_create_input_mesh(ParticleSimulationData *sim, | ||||
| psys->clmd->sim_parms->vgroup_mass = 1; | psys->clmd->sim_parms->vgroup_mass = 1; | ||||
| /* XXX placeholder for more flexible future hair settings */ | /* XXX placeholder for more flexible future hair settings */ | ||||
| hair_radius = part->size; | hair_radius = part->size; | ||||
| /* make vgroup for pin roots etc.. */ | /* make vgroup for pin roots etc.. */ | ||||
| hair_index = 1; | hair_index = 1; | ||||
| Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(sim->psmd); | |||||
| LOOP_PARTICLES | LOOP_PARTICLES | ||||
| { | { | ||||
| if (!(pa->flag & PARS_UNEXIST)) { | if (!(pa->flag & PARS_UNEXIST)) { | ||||
| float root_mat[4][4]; | float root_mat[4][4]; | ||||
| float bending_stiffness; | float bending_stiffness; | ||||
| bool use_hair; | bool use_hair; | ||||
| pa->hair_index = hair_index; | pa->hair_index = hair_index; | ||||
| use_hair = psys_hair_use_simulation(pa, max_length); | use_hair = psys_hair_use_simulation(pa, max_length); | ||||
| psys_mat_hair_to_object(sim->ob, sim->psmd->mesh_final, psys->part->from, pa, hairmat); | psys_mat_hair_to_object(sim->ob, mesh_final, psys->part->from, pa, hairmat); | ||||
| mul_m4_m4m4(root_mat, sim->ob->obmat, hairmat); | mul_m4_m4m4(root_mat, sim->ob->obmat, hairmat); | ||||
| normalize_m4(root_mat); | normalize_m4(root_mat); | ||||
| bending_stiffness = CLAMPIS( | bending_stiffness = CLAMPIS( | ||||
| 1.0f - part->bending_random * psys_frand(psys, p + 666), 0.0f, 1.0f); | 1.0f - part->bending_random * psys_frand(psys, p + 666), 0.0f, 1.0f); | ||||
| for (k = 0, key = pa->hair; k < pa->totkey; k++, key++) { | for (k = 0, key = pa->hair; k < pa->totkey; k++, key++) { | ||||
| ClothHairData *hair; | ClothHairData *hair; | ||||
| ▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | LOOP_PARTICLES | ||||
| } | } | ||||
| else { | else { | ||||
| pa->flag &= ~PARS_NO_DISP; | pa->flag &= ~PARS_NO_DISP; | ||||
| } | } | ||||
| } | } | ||||
| if (psys->recalc & ID_RECALC_PSYS_RESET) { | if (psys->recalc & ID_RECALC_PSYS_RESET) { | ||||
| /* need this for changing subsurf levels */ | /* need this for changing subsurf levels */ | ||||
| psys_calc_dmcache(sim->ob, sim->psmd->mesh_final, sim->psmd->mesh_original, psys); | 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); | |||||
| if (psys->clmd) { | if (psys->clmd) { | ||||
| cloth_free_modifier(psys->clmd); | cloth_free_modifier(psys->clmd); | ||||
| } | } | ||||
| } | } | ||||
| /* dynamics with cloth simulation, psys->particles can be NULL with 0 particles [#25519] */ | /* dynamics with cloth simulation, psys->particles can be NULL with 0 particles [#25519] */ | ||||
| if (psys->part->type == PART_HAIR && psys->flag & PSYS_HAIR_DYNAMICS && psys->particles) { | if (psys->part->type == PART_HAIR && psys->flag & PSYS_HAIR_DYNAMICS && psys->particles) { | ||||
| Show All 35 Lines | LOOP_PARTICLES | ||||
| key += pa->totkey; | key += pa->totkey; | ||||
| /* convert from global to geometry space */ | /* convert from global to geometry space */ | ||||
| copy_v3_v3(key->co, pa->state.co); | copy_v3_v3(key->co, pa->state.co); | ||||
| mul_m4_v3(ob->imat, key->co); | mul_m4_v3(ob->imat, key->co); | ||||
| if (pa->totkey) { | if (pa->totkey) { | ||||
| sub_v3_v3(key->co, root->co); | sub_v3_v3(key->co, root->co); | ||||
| psys_vec_rot_to_face(sim->psmd->mesh_final, pa, key->co); | Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(sim->psmd); | ||||
| psys_vec_rot_to_face(mesh_final, pa, key->co); | |||||
| } | } | ||||
| key->time = pa->state.time; | key->time = pa->state.time; | ||||
| key->weight = 1.0f - key->time / 100.0f; | key->weight = 1.0f - key->time / 100.0f; | ||||
| pa->totkey++; | pa->totkey++; | ||||
| ▲ Show 20 Lines • Show All 1,017 Lines • ▼ Show 20 Lines | void particle_system_update(struct Depsgraph *depsgraph, | ||||
| if (sim.psmd->flag & eParticleSystemFlag_psys_updated) { | if (sim.psmd->flag & eParticleSystemFlag_psys_updated) { | ||||
| sim.psmd->flag &= ~eParticleSystemFlag_psys_updated; | sim.psmd->flag &= ~eParticleSystemFlag_psys_updated; | ||||
| /* make sure it really was updated to cfra */ | /* make sure it really was updated to cfra */ | ||||
| if (psys->cfra == cfra) { | if (psys->cfra == cfra) { | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| if (!sim.psmd->mesh_final) { | Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(sim.psmd); | ||||
| if (!mesh_final) { | |||||
| return; | return; | ||||
| } | } | ||||
| if (part->from != PART_FROM_VERT) { | if (part->from != PART_FROM_VERT) { | ||||
| BKE_mesh_tessface_ensure(sim.psmd->mesh_final); | BKE_mesh_tessface_ensure(mesh_final); | ||||
| } | } | ||||
| /* to verify if we need to restore object afterwards */ | /* to verify if we need to restore object afterwards */ | ||||
| psys->flag &= ~PSYS_OB_ANIM_RESTORE; | psys->flag &= ~PSYS_OB_ANIM_RESTORE; | ||||
| if (psys->recalc & ID_RECALC_PSYS_RESET) { | if (psys->recalc & ID_RECALC_PSYS_RESET) { | ||||
| psys->totunexist = 0; | psys->totunexist = 0; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 215 Lines • Show Last 20 Lines | |||||