f3d icon indicating copy to clipboard operation
f3d copied to clipboard

Cycle through animations in glTF files

Open pfirsich opened this issue 2 years ago • 8 comments

I searched the user documentation and looked at the help screen and searched for open issues, but could not find it, so I apologize if this feature exists.

Since glTF can have multiple animations per file, it would be good if the name of the current animation would be displayed somewhere and if there was a way (a single hotkey would be enough) to cycle through them.

pfirsich avatar Jul 08 '23 15:07 pfirsich

You are correct, you can either select an animation or select all animations but using the command line only. You need to restart F3D to select another animation.

That being said, adding this feature should be trivial!

mwestphal avatar Jul 08 '23 15:07 mwestphal

I think it would also be good if there was a way to list the names of all the animations in the file with a command line switch. E.g. passing --list-animations would show something like this:

0: Idle
1: Walk
2: Die

pfirsich avatar Jul 09 '23 21:07 pfirsich

--verbose already provide that

mwestphal avatar Jul 10 '23 03:07 mwestphal

Hi, I have been in recent communication with the F3D team on Discord, in which I mentioned my interest working on this Github issue.

I have set up my local development environment, as well as taken a look at the VTK Users Guide and accompanying examples. I am new to learning graphics software, so I am familiarizing myself with the core concepts such as actors, mappers, renderers, pipeline, etc.

Right now, I am trying to understand which part of the F3D codebase my modifications for this issue should reside in. I'm assuming it has something to do with: library/VTKExtensions/Rendering? I have also found some related content for text such as vtkTextSource(), vtkTextMapper(), vtkTextProperty(), TextActor, etc. I'm also looking into how to extract animation data from gltf files.

Since I am new to open source contributions, I will appreciate any additional tips!

kathleenhang avatar Jan 09 '24 04:01 kathleenhang

Here's 2 tracks to investigate if you fancy venturing blindly into the weeds (I don't know how animations actually work myself):

  1. animations can be selected with --animation-index from the command line. This option is declared here https://github.com/f3d-app/f3d/blob/2f95ee30cc1d36f5f522558656926d13ed952dd9/application/F3DOptionsParser.cxx#L333 and is stored internally as "scene.animation.index" in the options. It's then read here: https://github.com/f3d-app/f3d/blob/2f95ee30cc1d36f5f522558656926d13ed952dd9/library/src/animationManager.cxx#L80
  2. animation can be started/stopped pressing space within the app, which is handled here: https://github.com/f3d-app/f3d/blob/2f95ee30cc1d36f5f522558656926d13ed952dd9/library/src/interactor_impl.cxx#L340-L344

If you'd rather have a more directed plan I'm sure @mwestphal can provide an overview of how multiple animation are implemented and how UI would need to tie into it.

snoyer avatar Jan 09 '24 06:01 snoyer

@snoyer pointers are indeed on point.

What you need to do is add a new interaction bindings (in f3d/library/src/interactor_impl.cxx) that will cycle through available animations, which are recovered in the "vtkImporters" level.

It is a litle bit complicated because options like "scene.animation.index" are not great for cycling since you do not know the highest value possible.

It can be done though, you can look how cycling scalars is implemented.

@kathleenhang Ill let you investigate but feel free to ask any follow up questions.

mwestphal avatar Jan 09 '24 06:01 mwestphal

Thanks for the tips @snoyer, @mwestphal ! Very helpful.

I'll appreciate feedback on my recent commits: https://github.com/kathleenhang/f3d/tree/kathleenhang-902

The code isn't functional. However, it will be helpful to know if I'm on the right track. I'm simply experimenting with the codebase to better understand how it all interconnects. Therefore, some aspects might not make sense.

  • I have done a keybind to "W" for cycling through the animations.
  • CycleAnimationsFor{FILE_TYPE}() increments through the circular rotated array indices of {FILE_TYPE}
  • GetAnimationDescription() displays information for current animation keyframe
  • Animation options are set after "W" key is pressed

My question is: When a user imports their GLTF file into F3D, where does the data flow? I would assume it goes through vtkF3DGenericImporter which would contain a vtkGLTFReader. That would then allow me to access the data structure array containing each individual animation keyframe within the imported GLTF file. Finally, I could retrieve the file name property from each keyframe to display onto the frontend.

kathleenhang avatar Jan 11 '24 00:01 kathleenhang

I'll answer in detail but please open a pr directly, that will make it simpler to discuss the code :)

mwestphal avatar Jan 11 '24 05:01 mwestphal

@pfirsich F3D nightly binary release now contains the feature!

https://github.com/f3d-app/f3d/releases/tag/nightly

mwestphal avatar Mar 31 '24 09:03 mwestphal