Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_modifier.c
| Show First 20 Lines • Show All 529 Lines • ▼ Show 20 Lines | void ED_object_modifier_link(bContext *C, Object *ob_dst, Object *ob_src) | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| } | } | ||||
| void ED_object_modifier_copy_to_object(bContext *C, | void ED_object_modifier_copy_to_object(bContext *C, | ||||
| Object *ob_dst, | Object *ob_dst, | ||||
| Object *ob_src, | Object *ob_src, | ||||
| ModifierData *md) | ModifierData *md) | ||||
| { | { | ||||
| BKE_object_copy_modifier(ob_dst, ob_src, md); | BKE_object_copy_modifier(CTX_data_main(C), CTX_data_scene(C), ob_dst, ob_src, md); | ||||
| WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob_dst); | WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob_dst); | ||||
| DEG_id_tag_update(&ob_dst->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION); | DEG_id_tag_update(&ob_dst->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION); | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| } | } | ||||
| bool ED_object_modifier_convert(ReportList *UNUSED(reports), | bool ED_object_modifier_convert(ReportList *UNUSED(reports), | ||||
| ▲ Show 20 Lines • Show All 1,132 Lines • ▼ Show 20 Lines | void OBJECT_OT_modifier_set_active(wmOperatorType *ot) | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ||||
| edit_modifier_properties(ot); | edit_modifier_properties(ot); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /** \name Copy Modifier To Selected Operator | /** \name Copy Modifier To Selected Operator | ||||
| * \{ */ | * \{ */ | ||||
| /* If the modifier uses particles, copy particle system to destination object | |||||
| * or reuse existing if it has the same ParticleSettings */ | |||||
| static void copy_or_reuse_particle_system(bContext *C, Object *ob, ModifierData *md) | |||||
| { | |||||
| ParticleSystem *psys_on_modifier = NULL; | |||||
| if (md->type == eModifierType_DynamicPaint) { | |||||
| DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md; | |||||
| if (pmd->brush && pmd->brush->psys) { | |||||
| psys_on_modifier = pmd->brush->psys; | |||||
| } | |||||
| } | |||||
| else if (md->type == eModifierType_Fluid) { | |||||
| FluidModifierData *fmd = (FluidModifierData *)md; | |||||
| if (fmd->type == MOD_FLUID_TYPE_FLOW) { | |||||
| if (fmd->flow && fmd->flow->psys) { | |||||
| psys_on_modifier = fmd->flow->psys; | |||||
| } | |||||
| } | |||||
| } | |||||
| if (!psys_on_modifier) { | |||||
| return; | |||||
| } | |||||
| ParticleSystem *psys_on_new_modifier = NULL; | |||||
| /* Check if a particle system with the same particle settings | |||||
| * already exists on the destination object. */ | |||||
| LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { | |||||
| if (psys_on_modifier->part == psys->part) { | |||||
| psys_on_new_modifier = psys; | |||||
| break; | |||||
| } | |||||
| } | |||||
| /* If it does not exist, copy the particle system to the destination object. */ | |||||
| if (!psys_on_new_modifier) { | |||||
| Main *bmain = CTX_data_main(C); | |||||
| Scene *scene = CTX_data_scene(C); | |||||
| object_copy_particle_system(bmain, scene, ob, psys_on_modifier); | |||||
| LISTBASE_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { | |||||
| if (psys_on_modifier->part == psys->part) { | |||||
| psys_on_new_modifier = psys; | |||||
| } | |||||
| } | |||||
| } | |||||
| /* Update the modifier to point to the new/existing particle system. */ | |||||
| LISTBASE_FOREACH (ModifierData *, new_md, &ob->modifiers) { | |||||
| if (new_md->type == eModifierType_DynamicPaint) { | |||||
| DynamicPaintModifierData *new_pmd = (DynamicPaintModifierData *)new_md; | |||||
| if (psys_on_modifier == new_pmd->brush->psys) { | |||||
| new_pmd->brush->psys = psys_on_new_modifier; | |||||
| } | |||||
| } | |||||
| else if (new_md->type == eModifierType_Fluid) { | |||||
| FluidModifierData *new_fmd = (FluidModifierData *)new_md; | |||||
| if (psys_on_modifier == new_fmd->flow->psys) { | |||||
| new_fmd->flow->psys = psys_on_new_modifier; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| static int modifier_copy_to_selected_exec(bContext *C, wmOperator *op) | static int modifier_copy_to_selected_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *obact = ED_object_active_context(C); | Object *obact = ED_object_active_context(C); | ||||
| ModifierData *md = edit_modifier_property_get(op, obact, 0); | ModifierData *md = edit_modifier_property_get(op, obact, 0); | ||||
| if (!md) { | if (!md) { | ||||
| Show All 23 Lines | if (mti->flags & eModifierTypeFlag_Single) { | ||||
| BKE_reportf(op->reports, | BKE_reportf(op->reports, | ||||
| RPT_WARNING, | RPT_WARNING, | ||||
| "Modifier can only be added once to object '%s'", | "Modifier can only be added once to object '%s'", | ||||
| ob->id.name + 2); | ob->id.name + 2); | ||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| if (md->type == eModifierType_ParticleSystem) { | if (!BKE_object_copy_modifier(bmain, scene, ob, obact, md)) { | ||||
| ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md; | |||||
| object_copy_particle_system(bmain, scene, ob, psmd->psys); | |||||
| } | |||||
| else { | |||||
| if (!BKE_object_copy_modifier(ob, obact, md)) { | |||||
| BKE_reportf(op->reports, | BKE_reportf(op->reports, | ||||
| RPT_ERROR, | RPT_ERROR, | ||||
| "Copying modifier '%s' to object '%s' failed", | "Copying modifier '%s' to object '%s' failed", | ||||
| md->name, | md->name, | ||||
| ob->id.name + 2); | ob->id.name + 2); | ||||
| } | } | ||||
| } | |||||
| if (ELEM(md->type, eModifierType_DynamicPaint, eModifierType_Fluid)) { | |||||
| copy_or_reuse_particle_system(C, ob, md); | |||||
| } | |||||
| num_copied++; | num_copied++; | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | ||||
| DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION); | DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION); | ||||
| } | } | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| if (num_copied > 0) { | if (num_copied > 0) { | ||||
| ▲ Show 20 Lines • Show All 1,498 Lines • Show Last 20 Lines | |||||