Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/physics/particle_object.c
| Show First 20 Lines • Show All 1,022 Lines • ▼ Show 20 Lines | static bool copy_particle_systems_to_object(const bContext *C, | ||||
| bool duplicate_settings) | bool duplicate_settings) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_depsgraph(C); | ||||
| ModifierData *md; | ModifierData *md; | ||||
| ParticleSystem *psys_start = NULL, *psys, *psys_from; | ParticleSystem *psys_start = NULL, *psys, *psys_from; | ||||
| ParticleSystem **tmp_psys; | ParticleSystem **tmp_psys; | ||||
| Mesh *final_mesh; | Mesh *final_mesh; | ||||
| CustomDataMask cdmask; | CustomData_Masks cdmask = {0}; | ||||
| int i, totpsys; | int i, totpsys; | ||||
| if (ob_to->type != OB_MESH) | if (ob_to->type != OB_MESH) | ||||
| return false; | return false; | ||||
| if (!ob_to->data || ID_IS_LINKED(ob_to->data)) | if (!ob_to->data || ID_IS_LINKED(ob_to->data)) | ||||
| return false; | return false; | ||||
| /* For remapping we need a valid DM. | /* For remapping we need a valid DM. | ||||
| * Because the modifiers are appended at the end it's safe to use | * Because the modifiers are appended at the end it's safe to use | ||||
| * the final DM of the object without particles. | * the final DM of the object without particles. | ||||
| * However, when evaluating the DM all the particle modifiers must be valid, | * However, when evaluating the DM all the particle modifiers must be valid, | ||||
| * i.e. have the psys assigned already. | * i.e. have the psys assigned already. | ||||
| * To break this hen/egg problem we create all psys separately first (to collect required customdata masks), | * To break this hen/egg problem we create all psys separately first (to collect required customdata masks), | ||||
| * then create the DM, then add them to the object and make the psys modifiers ... | * then create the DM, then add them to the object and make the psys modifiers ... | ||||
| */ | */ | ||||
| #define PSYS_FROM_FIRST (single_psys_from ? single_psys_from : ob_from->particlesystem.first) | #define PSYS_FROM_FIRST (single_psys_from ? single_psys_from : ob_from->particlesystem.first) | ||||
| #define PSYS_FROM_NEXT(cur) (single_psys_from ? NULL : (cur)->next) | #define PSYS_FROM_NEXT(cur) (single_psys_from ? NULL : (cur)->next) | ||||
| totpsys = single_psys_from ? 1 : BLI_listbase_count(&ob_from->particlesystem); | totpsys = single_psys_from ? 1 : BLI_listbase_count(&ob_from->particlesystem); | ||||
| tmp_psys = MEM_mallocN(sizeof(ParticleSystem *) * totpsys, "temporary particle system array"); | tmp_psys = MEM_mallocN(sizeof(ParticleSystem *) * totpsys, "temporary particle system array"); | ||||
| cdmask = 0; | |||||
| for (psys_from = PSYS_FROM_FIRST, i = 0; | for (psys_from = PSYS_FROM_FIRST, i = 0; | ||||
| psys_from; | psys_from; | ||||
| psys_from = PSYS_FROM_NEXT(psys_from), ++i) | psys_from = PSYS_FROM_NEXT(psys_from), ++i) | ||||
| { | { | ||||
| psys = BKE_object_copy_particlesystem(psys_from, 0); | psys = BKE_object_copy_particlesystem(psys_from, 0); | ||||
| tmp_psys[i] = psys; | tmp_psys[i] = psys; | ||||
| if (psys_start == NULL) | if (psys_start == NULL) | ||||
| psys_start = psys; | psys_start = psys; | ||||
| cdmask |= psys_emitter_customdata_mask(psys); | psys_emitter_customdata_mask(psys, &cdmask); | ||||
| } | } | ||||
| /* to iterate source and target psys in sync, | /* to iterate source and target psys in sync, | ||||
| * we need to know where the newly added psys start | * we need to know where the newly added psys start | ||||
| */ | */ | ||||
| psys_start = totpsys > 0 ? tmp_psys[0] : NULL; | psys_start = totpsys > 0 ? tmp_psys[0] : NULL; | ||||
| /* Get the evaluated mesh (psys and their modifiers have not been appended yet) */ | /* Get the evaluated mesh (psys and their modifiers have not been appended yet) */ | ||||
| final_mesh = mesh_get_eval_final(depsgraph, scene, ob_to, cdmask); | final_mesh = mesh_get_eval_final(depsgraph, scene, ob_to, &cdmask); | ||||
| /* now append psys to the object and make modifiers */ | /* now append psys to the object and make modifiers */ | ||||
| for (i = 0, psys_from = PSYS_FROM_FIRST; | for (i = 0, psys_from = PSYS_FROM_FIRST; | ||||
| i < totpsys; | i < totpsys; | ||||
| ++i, psys_from = PSYS_FROM_NEXT(psys_from)) | ++i, psys_from = PSYS_FROM_NEXT(psys_from)) | ||||
| { | { | ||||
| ParticleSystemModifierData *psmd; | ParticleSystemModifierData *psmd; | ||||
| ▲ Show 20 Lines • Show All 187 Lines • Show Last 20 Lines | |||||