From 01db47b82c77610780159d543227e5e082a55071 Mon Sep 17 00:00:00 2001 From: Falk David Date: Mon, 11 Nov 2024 10:39:23 +0100 Subject: [PATCH] Fix #129766: GPv3: Fallback to "frames" mode in build modifier for natural drawing speed The issue was that if the `delta_time` attribute didn't exist, the drawing would appear immediatley. In case we don't have any drawing speed information, the fix makes it so that we fallback to use the number of frames to build the strokes. Pull Request: https://projects.blender.org/blender/blender/pulls/130035 --- .../modifiers/intern/MOD_grease_pencil_build.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_build.cc b/source/blender/modifiers/intern/MOD_grease_pencil_build.cc index ce8bf853ac6..3a47049a499 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_build.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_build.cc @@ -529,12 +529,20 @@ static float get_build_factor(const GreasePencilBuildTimeMode time_mode, const float max_gap, const float fade) { + const float build_factor_frames = math::clamp( + float(current_frame - start_frame) / length, 0.0f, 1.0f) * + (1.0f + fade); switch (time_mode) { case MOD_GREASE_PENCIL_BUILD_TIMEMODE_FRAMES: - return math::clamp(float(current_frame - start_frame) / length, 0.0f, 1.0f) * (1.0f + fade); + return build_factor_frames; case MOD_GREASE_PENCIL_BUILD_TIMEMODE_PERCENTAGE: return percentage * (1.0f + fade); case MOD_GREASE_PENCIL_BUILD_TIMEMODE_DRAWSPEED: + /* The "drawing speed" is written as an attribute called 'delta_time' (for each point). If + * this attribute doesn't exist, we fallback to the "frames" mode. */ + if (!curves.attributes().contains("delta_time")) { + return build_factor_frames; + } return get_factor_from_draw_speed( curves, float(current_frame) / scene_fps, speed_fac, max_gap) * (1.0f + fade);