Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview the color animation in the animation editor #47230

Merged
merged 1 commit into from
Mar 31, 2021

Conversation

trollodel
Copy link
Contributor

Fixes godotengine/godot-proposals#289 for color tracks (not sure if it is enough to close the proposal)

image

It is done by splitting the link between the 2 keys in chunks.

@Calinou Calinou added cherrypick:3.x Considered for cherry-picking into a future 3.x release enhancement topic:editor labels Mar 21, 2021
@Calinou Calinou added this to the 4.0 milestone Mar 21, 2021
@timothyqiu
Copy link
Member

When I set update mode to discrete, the color still interpolates in the second section.
Snapshot

@trollodel
Copy link
Contributor Author

@timothyqiu should be fixed now.

@akien-mga akien-mga requested review from a team March 23, 2021 10:50
@trollodel trollodel force-pushed the anim_track_color branch 2 times, most recently from 5e3bdeb to 2c31dae Compare March 26, 2021 14:46
Comment on lines 157 to 158
points.write[points.size() - i] = Vector2(x_pos, y_from + fh);
colors.write[points.size() - i] = color_samples[i];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
points.write[points.size() - i] = Vector2(x_pos, y_from + fh);
colors.write[points.size() - i] = color_samples[i];
points.write[points.size() - i - 1] = Vector2(x_pos, y_from + fh);
colors.write[points.size() - i - 1] = color_samples[i];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually something is wrong when setting easing to high value:
image
Not sure why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a bigger version for reference.
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After debugging a bit, it seems a bug in the renderer as it appears only when there are 8 or more points.
I fix it by splitting the polygon in chunks of 6 points.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, the code looks too complicated now .-.
But that maybe it should be fine if you add a comment saying that this is a workaround for a bug. Or alternatively you could return to the first approach...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same issue happens in 3.x, so I think it is better to return to the draw_primitive approach.

chunked draw_polygon approach
  const int polygon_points = 3;

  Vector<Vector2> points;
  Vector<Color> colors;
  points.resize(polygon_points * 2);
  colors.resize(polygon_points * 2);

  int j = 0;
  for (int i = 0; i < color_samples.size() || j == polygon_points; i++) {
  	if (j == polygon_points) {
  		j = 0;
  		i -= 2;
  		draw_polygon(points.duplicate(), colors.duplicate());
  	} else {
  		int x_pos = Math::lerp(x_from, x_to, float(i) / (color_samples.size() - 1));
  		points.write[j] = Vector2(x_pos, y_from);
  		colors.write[j] = color_samples[i];
  		points.write[points.size() - j - 1] = Vector2(x_pos, y_from + fh);
  		colors.write[points.size() - j - 1] = color_samples[i];
  		j++;
  	}
  }

  if (j > 1) {
  	Vector<Vector2> points_aux = points.subarray(points.size() - j, points.size() - 1);
  	Vector<Color> colors_aux = colors.subarray(points.size() - j, points.size() - 1);
  	points.resize(j);
  	colors.resize(j);
  	points.append_array(points_aux);
  	colors.append_array(colors_aux);
  	draw_polygon(points, colors);
  }

@trollodel trollodel force-pushed the anim_track_color branch 2 times, most recently from 6474aa8 to ae8f732 Compare March 26, 2021 22:12
@akien-mga akien-mga merged commit 1508fe1 into godotengine:master Mar 31, 2021
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Cherry-picked for 3.4.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Jun 3, 2021
@trollodel trollodel deleted the anim_track_color branch November 2, 2022 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AnimationPlayer track: track visualisation should also visualize Update Mode, Interpolation Mode or Easing
5 participants