Cleanup: Separate BKE_object_link_modifiers into functions
No functional changes. Split the grease pencil and object copy logic into separate functions. This makes the code cleaner and prepares utility functions for outliner modiifier drag and drop. Differential Revision: https://developer.blender.org/D8642
This commit is contained in:
@@ -77,6 +77,10 @@ bool BKE_object_shaderfx_use_time(struct Object *ob, struct ShaderFxData *md);
|
||||
|
||||
bool BKE_object_support_modifier_type_check(const struct Object *ob, int modifier_type);
|
||||
|
||||
bool BKE_object_copy_modifier(struct Object *ob_dst,
|
||||
const struct Object *ob_src,
|
||||
struct ModifierData *md);
|
||||
bool BKE_object_copy_gpencil_modifier(struct Object *ob_dst, struct GpencilModifierData *md);
|
||||
void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_src);
|
||||
void BKE_object_free_modifiers(struct Object *ob, const int flag);
|
||||
void BKE_object_free_shaderfx(struct Object *ob, const int flag);
|
||||
|
||||
@@ -686,27 +686,16 @@ bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
|
||||
return false;
|
||||
}
|
||||
|
||||
void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_src)
|
||||
bool BKE_object_copy_modifier(struct Object *ob_dst, const struct Object *ob_src, ModifierData *md)
|
||||
{
|
||||
BKE_object_free_modifiers(ob_dst, 0);
|
||||
|
||||
if (!ELEM(ob_dst->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE, OB_GPENCIL)) {
|
||||
/* only objects listed above can have modifiers and linking them to objects
|
||||
* which doesn't have modifiers stack is quite silly */
|
||||
return;
|
||||
}
|
||||
|
||||
/* No grease pencil modifiers. */
|
||||
if ((ob_src->type != OB_GPENCIL) && (ob_dst->type != OB_GPENCIL)) {
|
||||
LISTBASE_FOREACH (ModifierData *, md, &ob_src->modifiers) {
|
||||
ModifierData *nmd = NULL;
|
||||
|
||||
if (ELEM(md->type, eModifierType_Hook, eModifierType_Collision)) {
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!BKE_object_support_modifier_type_check(ob_dst, md->type)) {
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (md->type) {
|
||||
@@ -731,12 +720,12 @@ void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_sr
|
||||
BKE_modifier_copydata(md, nmd);
|
||||
BLI_addtail(&ob_dst->modifiers, nmd);
|
||||
BKE_modifier_unique_name(&ob_dst->modifiers, nmd);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Copy grease pencil modifiers. */
|
||||
if ((ob_src->type == OB_GPENCIL) && (ob_dst->type == OB_GPENCIL)) {
|
||||
LISTBASE_FOREACH (GpencilModifierData *, md, &ob_src->greasepencil_modifiers) {
|
||||
bool BKE_object_copy_gpencil_modifier(struct Object *ob_dst, GpencilModifierData *md)
|
||||
{
|
||||
GpencilModifierData *nmd = NULL;
|
||||
|
||||
nmd = BKE_gpencil_modifier_new(md->type);
|
||||
@@ -747,6 +736,31 @@ void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_sr
|
||||
|
||||
BLI_addtail(&ob_dst->greasepencil_modifiers, nmd);
|
||||
BKE_gpencil_modifier_unique_name(&ob_dst->greasepencil_modifiers, nmd);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_src)
|
||||
{
|
||||
BKE_object_free_modifiers(ob_dst, 0);
|
||||
|
||||
if (!ELEM(ob_dst->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE, OB_GPENCIL)) {
|
||||
/* only objects listed above can have modifiers and linking them to objects
|
||||
* which doesn't have modifiers stack is quite silly */
|
||||
return;
|
||||
}
|
||||
|
||||
/* No grease pencil modifiers. */
|
||||
if ((ob_src->type != OB_GPENCIL) && (ob_dst->type != OB_GPENCIL)) {
|
||||
LISTBASE_FOREACH (ModifierData *, md, &ob_src->modifiers) {
|
||||
BKE_object_copy_modifier(ob_dst, ob_src, md);
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy grease pencil modifiers. */
|
||||
if ((ob_src->type == OB_GPENCIL) && (ob_dst->type == OB_GPENCIL)) {
|
||||
LISTBASE_FOREACH (GpencilModifierData *, md, &ob_src->greasepencil_modifiers) {
|
||||
BKE_object_copy_gpencil_modifier(ob_dst, md);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user