Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/particle_distribute.c
| Show First 20 Lines • Show All 872 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* Creates a distribution of coordinates on a Mesh */ | /* Creates a distribution of coordinates on a Mesh */ | ||||
| static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, | static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, | ||||
| ParticleSimulationData *sim, | ParticleSimulationData *sim, | ||||
| int from) | int from) | ||||
| { | { | ||||
| Scene *scene = sim->scene; | Scene *scene = sim->scene; | ||||
| Mesh *final_mesh = sim->psmd->mesh_final; | Mesh *final_mesh = BKE_particle_modifier_mesh_final_get(sim->psmd); | ||||
| Object *ob = sim->ob; | Object *ob = sim->ob; | ||||
| ParticleSystem *psys = sim->psys; | ParticleSystem *psys = sim->psys; | ||||
| ParticleData *pa = 0, *tpars = 0; | ParticleData *pa = 0, *tpars = 0; | ||||
| ParticleSettings *part; | ParticleSettings *part; | ||||
| ParticleSeam *seams = 0; | ParticleSeam *seams = 0; | ||||
| KDTree_3d *tree = 0; | KDTree_3d *tree = 0; | ||||
| Mesh *mesh = NULL; | Mesh *mesh = NULL; | ||||
| float *jit = NULL; | float *jit = NULL; | ||||
| Show All 31 Lines | static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, | ||||
| psys_thread_context_init(ctx, sim); | psys_thread_context_init(ctx, sim); | ||||
| const bool use_render_params = (DEG_get_mode(sim->depsgraph) == DAG_EVAL_RENDER); | const bool use_render_params = (DEG_get_mode(sim->depsgraph) == DAG_EVAL_RENDER); | ||||
| /* First handle special cases */ | /* First handle special cases */ | ||||
| if (from == PART_FROM_CHILD) { | if (from == PART_FROM_CHILD) { | ||||
| /* Simple children */ | /* Simple children */ | ||||
| if (part->childtype != PART_CHILD_FACES) { | if (part->childtype != PART_CHILD_FACES) { | ||||
| distribute_simple_children( | Mesh *mesh_original = BKE_particle_modifier_mesh_original_get(sim->psmd); | ||||
| scene, ob, final_mesh, sim->psmd->mesh_original, psys, use_render_params); | distribute_simple_children(scene, ob, final_mesh, mesh_original, psys, use_render_params); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Grid distribution */ | /* Grid distribution */ | ||||
| if (part->distr == PART_DISTR_GRID && from != PART_FROM_VERT) { | if (part->distr == PART_DISTR_GRID && from != PART_FROM_VERT) { | ||||
| if (psys->part->use_modifier_stack) { | if (psys->part->use_modifier_stack) { | ||||
| mesh = final_mesh; | mesh = final_mesh; | ||||
| ▲ Show 20 Lines • Show All 374 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void distribute_particles_on_dm(ParticleSimulationData *sim, int from) | static void distribute_particles_on_dm(ParticleSimulationData *sim, int from) | ||||
| { | { | ||||
| TaskScheduler *task_scheduler; | TaskScheduler *task_scheduler; | ||||
| TaskPool *task_pool; | TaskPool *task_pool; | ||||
| ParticleThreadContext ctx; | ParticleThreadContext ctx; | ||||
| ParticleTask *tasks; | ParticleTask *tasks; | ||||
| Mesh *final_mesh = sim->psmd->mesh_final; | Mesh *final_mesh = BKE_particle_modifier_mesh_final_get(sim->psmd); | ||||
| int i, totpart, numtasks; | int i, totpart, numtasks; | ||||
| /* create a task pool for distribution tasks */ | /* create a task pool for distribution tasks */ | ||||
| if (!psys_thread_context_init_distribute(&ctx, sim, from)) { | if (!psys_thread_context_init_distribute(&ctx, sim, from)) { | ||||
| return; | return; | ||||
| } | } | ||||
| task_scheduler = BLI_task_scheduler_get(); | task_scheduler = BLI_task_scheduler_get(); | ||||
| Show All 11 Lines | for (i = 0; i < numtasks; ++i) { | ||||
| else { | else { | ||||
| BLI_task_pool_push(task_pool, exec_distribute_parent, task, false, TASK_PRIORITY_LOW); | BLI_task_pool_push(task_pool, exec_distribute_parent, task, false, TASK_PRIORITY_LOW); | ||||
| } | } | ||||
| } | } | ||||
| BLI_task_pool_work_and_wait(task_pool); | BLI_task_pool_work_and_wait(task_pool); | ||||
| BLI_task_pool_free(task_pool); | BLI_task_pool_free(task_pool); | ||||
| psys_calc_dmcache(sim->ob, final_mesh, sim->psmd->mesh_original, sim->psys); | Mesh *mesh_original = BKE_particle_modifier_mesh_original_get(sim->psmd); | ||||
| psys_calc_dmcache(sim->ob, final_mesh, mesh_original, sim->psys); | |||||
| if (ctx.mesh != final_mesh) { | if (ctx.mesh != final_mesh) { | ||||
| BKE_id_free(NULL, ctx.mesh); | BKE_id_free(NULL, ctx.mesh); | ||||
| } | } | ||||
| psys_tasks_free(tasks, numtasks); | psys_tasks_free(tasks, numtasks); | ||||
| psys_thread_context_free(&ctx); | psys_thread_context_free(&ctx); | ||||
| } | } | ||||
| /* ready for future use, to emit particles without geometry */ | /* ready for future use, to emit particles without geometry */ | ||||
| static void distribute_particles_on_shape(ParticleSimulationData *sim, int UNUSED(from)) | static void distribute_particles_on_shape(ParticleSimulationData *sim, int UNUSED(from)) | ||||
| { | { | ||||
| distribute_invalid(sim, 0); | distribute_invalid(sim, 0); | ||||
| fprintf(stderr, "Shape emission not yet possible!\n"); | fprintf(stderr, "Shape emission not yet possible!\n"); | ||||
| } | } | ||||
| void distribute_particles(ParticleSimulationData *sim, int from) | void distribute_particles(ParticleSimulationData *sim, int from) | ||||
| { | { | ||||
| PARTICLE_PSMD; | PARTICLE_PSMD; | ||||
| int distr_error = 0; | int distr_error = 0; | ||||
| if (psmd) { | if (psmd) { | ||||
| if (psmd->mesh_final) { | Mesh *mesh_final = BKE_particle_modifier_mesh_final_get(psmd); | ||||
| if (mesh_final) { | |||||
| distribute_particles_on_dm(sim, from); | distribute_particles_on_dm(sim, from); | ||||
| } | } | ||||
| else { | else { | ||||
| distr_error = 1; | distr_error = 1; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| distribute_particles_on_shape(sim, from); | distribute_particles_on_shape(sim, from); | ||||
| } | } | ||||
| if (distr_error) { | if (distr_error) { | ||||
| distribute_invalid(sim, from); | distribute_invalid(sim, from); | ||||
| fprintf(stderr, "Particle distribution error!\n"); | fprintf(stderr, "Particle distribution error!\n"); | ||||
| } | } | ||||
| } | } | ||||