Skip to content

Commit

Permalink
Ondine: Follow Curve modifier for GPv3, initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SietseB committed Jun 12, 2024
1 parent 1109c1d commit 6a31656
Show file tree
Hide file tree
Showing 10 changed files with 1,224 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/startup/bl_ui/properties_data_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def draw(self, context):
if ob_type == 'GREASEPENCIL':
self.operator_modifier_add(layout, 'GREASE_PENCIL_ARMATURE')
self.operator_modifier_add(layout, 'GREASE_PENCIL_HOOK')
self.operator_modifier_add(layout, 'GREASE_PENCIL_FOLLOW_CURVE')
self.operator_modifier_add(layout, 'GREASE_PENCIL_LATTICE')
self.operator_modifier_add(layout, 'GREASE_PENCIL_NOISE')
self.operator_modifier_add(layout, 'GREASE_PENCIL_OFFSET')
Expand Down
30 changes: 30 additions & 0 deletions source/blender/blenkernel/intern/modifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,28 @@ bool BKE_modifiers_persistent_uids_are_valid(const Object &object)
return true;
}

static void modifier_renumber_by_type_name(ModifierData *md)
{
if (BLI_strcaseeq(md->type_name, "FollowCurve")) {
md->type = eModifierType_GreasePencilFollowCurve;
return;
}
}

static void modifier_set_type_name(ModifierData *md)
{
if (md->type_name[0] != '\0') {
return;
}

switch (md->type) {
case eModifierType_GreasePencilFollowCurve: {
BLI_strncpy(md->type_name, "FollowCurve", sizeof(md->type_name));
break;
}
}
}

void BKE_modifier_blend_write(BlendWriter *writer, const ID *id_owner, ListBase *modbase)
{
if (modbase == nullptr) {
Expand All @@ -1038,6 +1060,9 @@ void BKE_modifier_blend_write(BlendWriter *writer, const ID *id_owner, ListBase
continue;
}

/* Set modifier type name, because it's more robust than just a type number. */
modifier_set_type_name(md);

BLO_write_struct_by_name(writer, mti->struct_name, md);

if (md->type == eModifierType_Cloth) {
Expand Down Expand Up @@ -1248,6 +1273,11 @@ void BKE_modifier_blend_read_data(BlendDataReader *reader, ListBase *lb, Object
md->error = nullptr;
md->runtime = nullptr;

/* Renumber modifiers based on their type name. */
if (md->type_name[0] != '\0') {
modifier_renumber_by_type_name(md);
}

/* If linking from a library, clear 'local' library override flag. */
if (ID_IS_LINKED(ob)) {
md->flag &= ~eModifierFlag_OverrideLibrary_Local;
Expand Down
16 changes: 16 additions & 0 deletions source/blender/makesdna/DNA_modifier_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -1085,4 +1085,20 @@
.mode = 0, \
}

#define _DNA_DEFAULT_GreasePencilFollowCurveModifierData \
{ \
.object = NULL, \
.flag = MOD_GREASE_PENCIL_FOLLOWCURVE_DISSOLVE | MOD_GREASE_PENCIL_FOLLOWCURVE_REPEAT | MOD_GREASE_PENCIL_FOLLOWCURVE_STROKE_TAIL_FIRST, \
.seed = 0, \
.speed = 0.0f, \
.speed_variation = 0.0f, \
.angle = 0.0f, \
.angle_axis = MOD_GREASE_PENCIL_FOLLOWCURVE_AXIS_Y, \
.spirals = 0.0f, \
.curve_resolution = 1024, \
.object_axis = MOD_GREASE_PENCIL_FOLLOWCURVE_AXIS_Z, \
.object_center = 0.5f, \
.completion = 1.0f, \
}

/* clang-format off */
89 changes: 89 additions & 0 deletions source/blender/makesdna/DNA_modifier_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ typedef enum ModifierType {
eModifierType_GreasePencilBuild = 84,
eModifierType_GreasePencilSimplify = 85,
eModifierType_GreasePencilTexture = 86,
eModifierType_GreasePencilFollowCurve = 87,
NUM_MODIFIER_TYPES,
} ModifierType;

Expand Down Expand Up @@ -169,6 +170,8 @@ typedef struct ModifierData {
int persistent_uid;
/** MAX_NAME. */
char name[64];
/* Type name. */
char type_name[32];

char *error;

Expand Down Expand Up @@ -3472,3 +3475,89 @@ typedef enum GreasePencilTextureModifierMode {
MOD_GREASE_PENCIL_TEXTURE_FILL = 1,
MOD_GREASE_PENCIL_TEXTURE_STROKE_AND_FILL = 2,
} GreasePencilTextureModifierMode;

typedef struct GreasePencilFollowCurvePoint {
float co[3];
float vec_to_next[3];
float vec_len;
float vec_len_accumulative;
} GreasePencilFollowCurvePoint;

typedef struct GreasePencilFollowCurve {
/** Bezier curve. */
struct Curve *curve;
/** Curve point data. */
struct GreasePencilFollowCurvePoint *points;
int points_len;
/* Curve length. */
float length;
} GreasePencilFollowCurve;

typedef struct GreasePencilFollowCurveModifierData {
ModifierData modifier;
GreasePencilModifierInfluenceData influence;

/** Object with curves to follow. */
struct Object *object;

/** Flags. */
int flag;
/** Seed. */
int seed;
/** Spped. */
float speed;
/** Speed variation. */
float speed_variation;
/* Projection angle. */
float angle;
/* Projection axis. */
int angle_axis;
/** Number of spirals around a curve. */
float spirals;
/** Curve resolution */
int curve_resolution;
/** Object profile axis. */
int object_axis;
/** Object profile center. */
float object_center;
/** Projection completion. */
float completion;

/** Stroke or object profile vector. */
float profile_vec[3];
/** Stroke or object profile starting point. */
float profile_start[3];
/** Scale of profile for mapping it fully to the curve. */
float profile_scale;
char _pad0[4];
/** Current frame. */
int cfra;
/** Speed data per frame. */
float *speed_per_frame;
int speed_per_frame_len;
/** Bezier curves to follow. */
int curves_len;
struct GreasePencilFollowCurve *curves;
} GreasePencilFollowCurveModifierData;

typedef enum GreasePencilFollowCurveFlag {
MOD_GREASE_PENCIL_FOLLOWCURVE_INVERT_LAYER = (1 << 0),
MOD_GREASE_PENCIL_FOLLOWCURVE_INVERT_PASS = (1 << 1),
MOD_GREASE_PENCIL_FOLLOWCURVE_INVERT_VGROUP = (1 << 2),
MOD_GREASE_PENCIL_FOLLOWCURVE_UNIFORM_SPACE = (1 << 3),
MOD_GREASE_PENCIL_FOLLOWCURVE_INVERT_LAYERPASS = (1 << 4),
MOD_GREASE_PENCIL_FOLLOWCURVE_INVERT_MATERIAL = (1 << 5),
MOD_GREASE_PENCIL_FOLLOWCURVE_SCATTER = (1 << 6),
MOD_GREASE_PENCIL_FOLLOWCURVE_DISSOLVE = (1 << 7),
MOD_GREASE_PENCIL_FOLLOWCURVE_REPEAT = (1 << 8),
MOD_GREASE_PENCIL_FOLLOWCURVE_STROKE_TAIL_FIRST = (1 << 9),
MOD_GREASE_PENCIL_FOLLOWCURVE_VARY_DIR = (1 << 10),
MOD_GREASE_PENCIL_FOLLOWCURVE_ENTIRE_OBJECT = (1 << 11),
MOD_GREASE_PENCIL_FOLLOWCURVE_CURVE_TAIL_FIRST = (1 << 12),
} GreasePencilFollowCurveFlag;

typedef enum GreasePencilFollowCurveAxis {
MOD_GREASE_PENCIL_FOLLOWCURVE_AXIS_X = 0,
MOD_GREASE_PENCIL_FOLLOWCURVE_AXIS_Y = 1,
MOD_GREASE_PENCIL_FOLLOWCURVE_AXIS_Z = 2,
} GreasePencilFollowCurveAxis;
2 changes: 2 additions & 0 deletions source/blender/makesdna/intern/dna_defaults.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ SDNA_DEFAULT_DECL_STRUCT(GreasePencilEnvelopeModifierData);
SDNA_DEFAULT_DECL_STRUCT(GreasePencilOutlineModifierData);
SDNA_DEFAULT_DECL_STRUCT(GreasePencilShrinkwrapModifierData);
SDNA_DEFAULT_DECL_STRUCT(GreasePencilTextureModifierData);
SDNA_DEFAULT_DECL_STRUCT(GreasePencilFollowCurveModifierData);
SDNA_DEFAULT_DECL_STRUCT(MorphTargetsGpencilModifierData);
SDNA_DEFAULT_DECL_STRUCT(FollowCurveGpencilModifierData);

Expand Down Expand Up @@ -652,6 +653,7 @@ const void *DNA_default_table[SDNA_TYPE_MAX] = {
SDNA_DEFAULT_DECL(GreasePencilOutlineModifierData),
SDNA_DEFAULT_DECL(GreasePencilShrinkwrapModifierData),
SDNA_DEFAULT_DECL(GreasePencilTextureModifierData),
SDNA_DEFAULT_DECL(GreasePencilFollowCurveModifierData),
SDNA_DEFAULT_DECL(MorphTargetsGpencilModifierData),
SDNA_DEFAULT_DECL(FollowCurveGpencilModifierData),
};
Expand Down
Loading

0 comments on commit 6a31656

Please sign in to comment.