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

[WIP] Adding shader support for doing the animations #702

Draft
wants to merge 68 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
6d03eb1
Merge branch 'Timeline-Transformation-matrices-integration' into New-…
m-agour Sep 5, 2022
5b63f7f
Updated tutorials
m-agour Sep 5, 2022
68e01dc
Updated titles
m-agour Sep 5, 2022
c4d7ca5
Time as float representation
m-agour Sep 11, 2022
88d9187
Added slerp docs
m-agour Sep 12, 2022
2b40bf3
Added add_timeline method
m-agour Sep 19, 2022
ddb3bdb
added unit test for `add_timeline`
m-agour Sep 19, 2022
671a441
Fixed pep issue
m-agour Sep 19, 2022
143b9d2
@filipinascimento's review
m-agour Sep 20, 2022
5bef71b
pep8
m-agour Sep 20, 2022
7d3adea
_get_actors to return list of actors not UI element
m-agour Sep 20, 2022
de4b952
Modified how PlaybackPanel objects are added to scene
m-agour Sep 20, 2022
4b6a75f
Implemented remove_timeline from ShowManagger
m-agour Sep 20, 2022
ffa85d8
removed additional prints
m-agour Sep 20, 2022
70a78d0
Renamed `ren` to `scene`
m-agour Sep 20, 2022
93a2a2c
Set timer_callback to None again and added tests
m-agour Sep 20, 2022
50b31a7
@skoudoro review (pep)
m-agour Sep 23, 2022
c722947
@skoudoro review (issue) and updated tests
m-agour Sep 23, 2022
c219c40
Seperating Timeline into Timeline and Animation
m-agour Sep 25, 2022
a97754a
Modifing tests
m-agour Sep 25, 2022
49d0d73
Fixed some docs
m-agour Sep 26, 2022
03c14d2
Added more docs
m-agour Sep 26, 2022
e158720
Duration should be initialized
m-agour Sep 26, 2022
2105548
Animation playable on its own
m-agour Sep 26, 2022
fb9df0d
parent animation impl and doc
m-agour Sep 26, 2022
af350a1
updated robot arm tutorial
m-agour Sep 26, 2022
c4a0c6d
pep fixing
m-agour Sep 26, 2022
83e716c
Tutorials adapt to new method
m-agour Sep 26, 2022
f255501
Update duration in case of hard setting the length
m-agour Sep 26, 2022
7d5615b
Set back playback_panel to False untill tutorials are edited
m-agour Sep 26, 2022
0d602f4
@skoudoro review - pep and doc issues
m-agour Sep 27, 2022
373268e
Impl `get_camera_data` method
m-agour Sep 27, 2022
965daa1
get_keyframes doc typo
m-agour Sep 27, 2022
bf1ab65
Too long dash fixed
m-agour Sep 27, 2022
fc67551
Fixed one letter param
m-agour Sep 27, 2022
5a8c805
Merge remote-tracking branch 'upstream/master' into Seperating-`Timel…
m-agour Sep 27, 2022
097cb3f
fixed glTF animation test
m-agour Sep 27, 2022
cc806e4
Optimized motion path and some docs
m-agour Sep 28, 2022
8b35e9a
assert actor is not already added to animation
m-agour Sep 28, 2022
2682f5b
updated tests
m-agour Sep 28, 2022
426936b
sleep time is not accurate and fails the tests on some OSs
m-agour Sep 28, 2022
5c23ece
Added loop property
m-agour Sep 30, 2022
117c270
making Timeline independent
m-agour Oct 1, 2022
9751457
updated tests
m-agour Oct 1, 2022
ac94ae4
Merge branch 'Seperating-`Timeline`-into-`Timeline`-and-`Animation`' …
m-agour Oct 2, 2022
a9f97f4
Implemented `remove_from_scene` for Timeline and Animation
m-agour Oct 2, 2022
79f30d1
add_animation to showManager
m-agour Oct 2, 2022
2cf48cb
updated tests
m-agour Oct 2, 2022
09ad047
PlaybackPanel might not exist
m-agour Oct 3, 2022
a2f8030
Adding animations after adding creating the PlaybackPanel
m-agour Oct 3, 2022
c45dc5b
some renaming and loop issue fixed
m-agour Oct 4, 2022
37ab99c
Abandoned the `Container` as a superclass
m-agour Oct 4, 2022
87d2169
Separated camera animation from normal animation
m-agour Oct 5, 2022
0a73f7e
Updated docs
m-agour Oct 5, 2022
1d0c673
Added 'camera' property and some docs
m-agour Oct 5, 2022
1c32b2d
Added tests for CameraAnimation
m-agour Oct 5, 2022
0617d87
renaming `update_timeline` to just `update`
m-agour Oct 5, 2022
926ef96
Merge branch 'Seperating-`Timeline`-into-`Timeline`-and-`Animation`' …
m-agour Oct 7, 2022
8197396
`update_timeline` renamed
m-agour Oct 7, 2022
cee5723
Animation loop adjustment
m-agour Oct 7, 2022
0fb1880
Added the ability to get current timestamp of Animation
m-agour Oct 7, 2022
331e755
Added support for general callbacks
m-agour Oct 7, 2022
8c735d9
Merge branch 'Seperating-`Timeline`-into-`Timeline`-and-`Animation`' …
m-agour Oct 7, 2022
1c1d117
Merge branch 'Add-timeline-to-showmanager' into New-tutorials
m-agour Oct 7, 2022
d65059e
updated animation tutorials
m-agour Oct 7, 2022
5b04d88
Added hierarchical animation tutorial
m-agour Oct 7, 2022
8906480
@filipinascimento's addition
m-agour Oct 8, 2022
ae80376
Added initial shader support for animation
m-agour Oct 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
=====================
Keyframe animation
=====================
===================
Bezier Interpolator
===================

Keyframe animation using cubic Bezier interpolator.

"""
import numpy as np
from fury import actor, window
from fury.animation.timeline import Timeline
from fury.animation import Animation, Timeline
from fury.animation.interpolator import cubic_bezier_interpolator

###############################################################################
Expand Down Expand Up @@ -64,10 +64,10 @@
colors=np.array([0, 1, 0]))

###############################################################################
# Initializing a ``Timeline`` and adding sphere actor to it.
timeline = Timeline(playback_panel=True)
# Initializing an ``Animation`` and adding sphere actor to it.
animation = Animation()
sphere = actor.sphere(np.array([[0, 0, 0]]), (1, 0, 1))
timeline.add_actor(sphere)
animation.add_actor(sphere)

###############################################################################
# Setting Cubic Bezier keyframes
Expand All @@ -82,31 +82,22 @@
# Note: If a control point is not provided or set `None`, this control point
# will be the same as the position itself.

timeline.set_position(0, np.array(keyframe_1.get('value')),
out_cp=np.array(keyframe_1.get('out_cp')))
timeline.set_position(5, np.array(keyframe_2.get('value')),
in_cp=np.array(keyframe_2.get('in_cp')))
animation.set_position(0.0, np.array(keyframe_1.get('value')),
out_cp=np.array(keyframe_1.get('out_cp')))
animation.set_position(5.0, np.array(keyframe_2.get('value')),
in_cp=np.array(keyframe_2.get('in_cp')))

###############################################################################
# changing position interpolation into cubic bezier interpolation
timeline.set_position_interpolator(cubic_bezier_interpolator)
# Changing position interpolation into cubic bezier interpolation
animation.set_position_interpolator(cubic_bezier_interpolator)

###############################################################################
# adding the timeline and the static actors to the scene.
# Adding the visualization actors to the scene.
scene.add(pts_actor, cps_actor, cline_actor)
scene.add(timeline)


###############################################################################
# making a function to update the animation
def timer_callback(_obj, _event):
timeline.update_animation()
showm.render()


###############################################################################
# Adding the callback function that updates the animation
showm.add_timer_callback(True, 10, timer_callback)
# Adding the animation to the ``ShowManager``
showm.add_animation(animation)

interactive = False

Expand Down Expand Up @@ -138,18 +129,20 @@ def timer_callback(_obj, _event):
}

###############################################################################
# Initializing the timeline
timeline = Timeline(playback_panel=True)
# Creat the sphere actor.
sphere = actor.sphere(np.array([[0, 0, 0]]), (1, 0, 1))
timeline.add_actor(sphere)

###############################################################################
# Creat an ``Animation`` and adding the sphere actor to it.
animation = Animation(sphere)

###############################################################################
# Setting Cubic Bezier keyframes
timeline.set_position_keyframes(keyframes)
animation.set_position_keyframes(keyframes)

###############################################################################
# changing position interpolation into cubic bezier interpolation
timeline.set_position_interpolator(cubic_bezier_interpolator)
animation.set_position_interpolator(cubic_bezier_interpolator)

###########################################################################
# visualizing the points and control points (only for demonstration)
Expand All @@ -174,21 +167,16 @@ def timer_callback(_obj, _event):
scene.add(vis_cps, cline_actor)

###############################################################################
# adding actors to the scene
scene.add(timeline)

# Initializing the timeline to be able to control the playback of the
# animation.
timeline = Timeline(animation, playback_panel=True)

###############################################################################
# making a function to update the animation
def timer_callback(_obj, _event):
timeline.update_animation()
show_manager.render()

# We only need to add the ``Timeline`` to the ``ShowManager``
show_manager.add_animation(timeline)

###############################################################################
# Adding the callback function that updates the animation
show_manager.add_timer_callback(True, 10, timer_callback)

# Start the animation
if interactive:
show_manager.start()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import numpy as np
from fury import actor, window
from fury.animation.timeline import Timeline
from fury.animation import Timeline, Animation, CameraAnimation
from fury.animation.interpolator import cubic_spline_interpolator

###############################################################################
Expand All @@ -29,20 +29,21 @@
# Creating the main ``Timeline`` and adding static actors to it
# =============================================================
#
# Here we create a ``Timeline``. which we will call ``main_timeline`` so that
# we can use it as a controller for the other 50 Timelines.
# So, Instead of updating and adding 50 timelines to the ``scene``, we only
# need to update the main ``Timeline``. Also, a playback panel can be assigned
# to this main Timeline.
# But, why we need 50 ``Timelines``, you may ask.
# -> A single ``Timeline`` can handle each property once at a time. So we need
# 50 ``Timelines`` to translate and scale our 50 spheres.
# Here we create a ``Timeline``. so that we can use it as a controller for the
# 50 animations we will create.
# So, Instead of updating and adding 50 Animations to the ``ShowManager``,
# we only need to update the main ``Timeline``. Also, a playback panel can be
# assigned to this main Timeline.
#
# But, why we need 50 ``Animations``, you may ask.
# -> A single ``Animation`` can handle each property once at a time. So we need
# 50 ``Animations`` to translate and scale our 50 spheres.

###############################################################################
# ``playback_panel=True`` assigns a playback panel that can control the
# playback of this ``main_timeline`` and all of its children ``Timelines``
# playback of its ``Animations``

main_timeline = Timeline(playback_panel=True)
timeline = Timeline(playback_panel=True)

###############################################################################
# Creating two actors for visualization, and to detect camera's animations.
Expand All @@ -51,13 +52,6 @@
plan = actor.box(np.array([[0, 0, 0]]), colors=np.array([[1, 1, 1]]),
scales=np.array([[20, 0.2, 20]]))

###############################################################################
# adding static actors to the timeline.
# Note: adding actors as static actors just ensures that they get added to the
# scene along with the Timeline and will not be controlled nor animated by the
# timeline.
main_timeline.add_static_actor([arrow, plan])

###############################################################################
# Creating "FURY" text
# ====================
Expand All @@ -66,18 +60,18 @@
scale=(2, 2, 2))

###############################################################################
# Creating a ``Timeline`` to animate the opacity of ``fury_text``
text_timeline = Timeline(fury_text)
# Creating an ``Animation`` to animate the opacity of ``fury_text``
text_anim = Animation(fury_text, loop=False)

###############################################################################
# opacity is set to 0 at time 28 and set to one at time 31.
# Linear interpolator is always used by default.
text_timeline.set_opacity(29, 0)
text_timeline.set_opacity(35, 1)
text_anim.set_opacity(29, 0)
text_anim.set_opacity(35, 1)

###############################################################################
# ``text_timeline`` contains the text actor is added to the main Timeline.
main_timeline.add_child_timeline(text_timeline)
# ``text_anim`` contains the text actor is added to the Timeline.
timeline.add_animation(text_anim)

###############################################################################
# Creating and animating 50 Spheres
Expand All @@ -95,37 +89,41 @@
###########################################################################
# create a timeline to animate this actor (single actor or list of actors)
# Actors can be added later using `Timeline.add_actor(actor)`
timeline = Timeline(actors)
animation = Animation(actors)

# We generate random position and scale values from time=0 to time=49 each
# two seconds.
for t in range(0, 50, 2):
#######################################################################
# Position and scale are set to a random value at the timestamps
# mentioned above.
timeline.set_position(t,
np.random.random(3) * 30 - np.array([15, 0, 15]))
timeline.set_scale(t, np.repeat(np.random.random(1), 3))
animation.set_position(t,
np.random.random(3) * 30 - np.array(
[15, 0, 15]))
animation.set_scale(t, np.repeat(np.random.random(1), 3))

###########################################################################
# change the position interpolator to cubic spline interpolator.
timeline.set_position_interpolator(cubic_spline_interpolator)
animation.set_position_interpolator(cubic_spline_interpolator)

###########################################################################
# Finally, the ``Timeline`` is added to the ``main_timeline``.
main_timeline.add_child_timeline(timeline)
# Finally, the ``Animation`` is added to the ``Timeline``.
timeline.add_animation(animation)

###############################################################################
# Animating the camera
# ====================
#
# Since, only one camera is needed, camera animations are preferably done using
# the main `Timeline`. Three properties can control the camera's animation:
# a seperate ``Animation``.
# Three properties can control the camera's animation:
# Position, focal position (referred to by `focal`), and up-view.

camera_anim = CameraAnimation(loop=False)
timeline.add_animation(camera_anim)

###############################################################################
# Multiple keyframes can be set at once as follows.

# camera focal positions
camera_positions = {
# time: camera position
Expand All @@ -151,35 +149,24 @@
###############################################################################
# ``set_camera_focal`` can only set one keyframeB , but
# ``set_camera_focal_keyframes`` can set a dictionary of keyframes.
main_timeline.set_camera_focal_keyframes(camera_focal_positions)
main_timeline.set_camera_position_keyframes(camera_positions)
camera_anim.set_focal_keyframes(camera_focal_positions)
camera_anim.set_position_keyframes(camera_positions)

###############################################################################
# Change camera position and focal interpolators
main_timeline.set_camera_position_interpolator(cubic_spline_interpolator)
main_timeline.set_camera_focal_interpolator(cubic_spline_interpolator)
camera_anim.set_position_interpolator(cubic_spline_interpolator)
camera_anim.set_focal_interpolator(cubic_spline_interpolator)

###############################################################################
# Only the main Timeline is added to the scene.
scene.add(main_timeline)

# Adding non-animatable actors to the scene.
scene.add(arrow, plan)

###############################################################################
# making a function to update the animation
def timer_callback(_obj, _event):
###########################################################################
# Only the main timeline is needed to be updated, and it would update all
# children ``Timelines``.
main_timeline.update_animation()

###########################################################################
# The scene is rendered after the animations are updated.
showm.render()

# Adding the timeline to the ShowManager.
showm.add_animation(timeline)

###############################################################################
# Adding the callback function that updates the animation
showm.add_timer_callback(True, 10, timer_callback)
# The ShowManager must go on!

interactive = False

Expand Down
Loading