| 1 | # Split long animation into a number of smaller logical animations (subanimations) |
| 2 | |
| 3 | Some 3D models contain one long animation (like `Take 001` which seems to be created by default in _3ds Max_), and the 3D artist relies that you split the long animation into smaller animations (more logical to use) on the game engine side. |
| 4 | |
| 5 | This example shows how to do it. |
| 6 | |
| 7 | We call the smaller animations "subanimations" in this demo, since they are a subrange of some larger animation. |
| 8 | |
| 9 | This example defines `TSubAnimations` behavior class, descendant of `TCastleBehavior`. This behavior can be added to parent `TCastleScene` and play subanimations there: |
| 10 | |
| 11 | - Define subanimations using `TSubAnimations.Add`. |
| 12 | |
| 13 | - Read information about subanimations by `TSubAnimations.List`. |
| 14 | |
| 15 | - Play the subanimation using `TSubAnimations.Play`. |
| 16 | |
| 17 | Internally: the playback uses `TCastleSceneCore.ForceAnimationPose` to update each frame. It is done by `TSubAnimations.Update`. |
| 18 | |
| 19 | Note: _Castle Game Engine_ API of `TCastleScene` allows you to access the long animation, using `TCastleSceneCore.PlayAnimation`, `TCastleSceneCore.ForceAnimationPose`, `TCastleSceneCore.AnimationsList`. You should not use it directly if you want to use subanimations. |
| 20 | |
| 21 |  |
| 22 | |
| 23 | Using [Castle Game Engine](https://castle-engine.io/). |
| 24 | |
| 25 | ## Building |
| 26 | |
| 27 | Compile by: |
| 28 | |
| 29 | - [CGE editor](https://castle-engine.io/editor). Just use menu items _"Compile"_ or _"Compile And Run"_. |
| 30 | |
| 31 | - Or use [CGE command-line build tool](https://castle-engine.io/build_tool). Run `castle-engine compile` in this directory. |
| 32 | |
| 33 | - Or use [Lazarus](https://www.lazarus-ide.org/). Open in Lazarus `split_long_animation_standalone.lpi` file and compile / run from Lazarus. Make sure to first register [CGE Lazarus packages](https://castle-engine.io/lazarus). |
| 34 | |
| 35 | - Or use [Delphi](https://www.embarcadero.com/products/Delphi). Open in Delphi `split_long_animation_standalone.dproj` file and compile / run from Delphi. See [CGE and Delphi](https://castle-engine.io/delphi) documentation for details. |