Weekend news: 1. Spine ( http://esotericsoftware.com/ ) support in Castle Game Engine is now official, 2. introducing named animations support, 3. scene manager fine-tuned for 2D games :)
Read more for details:
1. Spine ( http://esotericsoftware.com/ ) is a great program to design 2D skeletal animations for games. It has several advantages over alternatives (like Flash): offers many features for animators (not just skeletons, also skins, also animations by mesh deformation...), and is friendly for engines (the format of Spine is designed for interoperability, it is small and nice, and it is documented --- at least the JSON version). This makes reading a Spine animation in our engine a natural thing.
You can use view3dscene to open Spine animations already! Grab view3dscene from snapshots http://michalis.ii.uni.wroc.pl/castle-engine-snapshots/ , and use "File->Open" to open any Spine xxx.json file. Be sure to check "View->Sort Transparent Shapes (2D...)" for best results.
Our implementation of Spine converts the Spine animation under the hood into an X3D node graph. This means that under the hood, Spine animation is actually 3D (although you can use SceneManager with RenderStyle := ds2D to render it under/above other 2D controls, as you wish), and the animation uses existing X3D features for animations (interpolators and such) and you can use all existing X3D rendering/processing tools to extend the Spine animation (for example, you can use sensors, texture settings, screen effects, you can cast shadows!, you can use shaders etc.).
To support correct slots order when rendering (this is not determined by bone hierarchy, Spine has separate slot order) we actually move quads by epsilon to back/front in 3D. To make it work with blending (depends on texture, all Spine examples uses texture atlas with smooth alpha channel on edges), we add new BlendingSort value: bs2D.
To use Spine animations for your games:
A.1) Easiest: Load them using T2DScene, and add to T2DSceneManager.Items.
A.2) Alternative: Load them using TCastleScene, add to TCastleSceneManager.Items --- just like 3D entities. Remember to possibly adjust TCastleScene.Attributes.BlendingSort to bs2D (to guarantee good drawing order for textures with smooth alpha channel), and possibly adjust TCastleSceneManager.RenderStyle to rs2D (then scene manager is rendered above/below other 2D controls, depending on their relative order on Window.Controls list).
B) To start a concrete Spine animation, use TCastleScene.PlayAnimation. Use TCastleScene.Animations to list named animations. This simply uses X3D named TimeSensor nodes underneath.
Underneath, we also support multiple Spine skins, although there is no easy API to change them at runtime yet (you can only choose skin at loading).
2. Named animations: many 3D and 2D models define multiple animations that can be started by an external code (for example, by a programmer using Castle Game Engine). Our engine detects now such animations by looking at X3D TimeSensor node names. Name starting with "Animation_xxx" indicates an animation, with name "xxx". Some converters (right now, our Spine to X3D conversion) follow this convention, so our engine immediately "knows" the Spine animation names and can play them.
The benefits of such "named" animations:
- view3dscene displays a user-friendly menu in "Animation->Named Animations->" to run animation by name. You can force the animation looping state when running it, if needed. (For example, useful for "walk" and such animations designed in Spine, as you cannot mark them "looping" in Spine.)
- TCastleScene offers a simple API for programmers to browse and run animation by name, see TCastleScene.Animations and TCastleScene.PlayAnimation. PlayAnimation automatically stops the previous animation too.
3. Scene manager for 2D: We have a new T2DSceneManager, best suited for 2D worlds (for example, using Spine animations). The rendering, with TUIControl.RenderStyle, was reworked to be more flexible for 2D stuff: RenderStyle 2D vs 3D now only determines the drawing order. This means that 2D and 3D rendering using our scene manager is almost identical, and yet they are both comfortable for programmer.
Read more for details:
1. Spine ( http://esotericsoftware.com/ ) is a great program to design 2D skeletal animations for games. It has several advantages over alternatives (like Flash): offers many features for animators (not just skeletons, also skins, also animations by mesh deformation...), and is friendly for engines (the format of Spine is designed for interoperability, it is small and nice, and it is documented --- at least the JSON version). This makes reading a Spine animation in our engine a natural thing.
You can use view3dscene to open Spine animations already! Grab view3dscene from snapshots http://michalis.ii.uni.wroc.pl/castle-engine-snapshots/ , and use "File->Open" to open any Spine xxx.json file. Be sure to check "View->Sort Transparent Shapes (2D...)" for best results.
Our implementation of Spine converts the Spine animation under the hood into an X3D node graph. This means that under the hood, Spine animation is actually 3D (although you can use SceneManager with RenderStyle := ds2D to render it under/above other 2D controls, as you wish), and the animation uses existing X3D features for animations (interpolators and such) and you can use all existing X3D rendering/processing tools to extend the Spine animation (for example, you can use sensors, texture settings, screen effects, you can cast shadows!, you can use shaders etc.).
To support correct slots order when rendering (this is not determined by bone hierarchy, Spine has separate slot order) we actually move quads by epsilon to back/front in 3D. To make it work with blending (depends on texture, all Spine examples uses texture atlas with smooth alpha channel on edges), we add new BlendingSort value: bs2D.
To use Spine animations for your games:
A.1) Easiest: Load them using T2DScene, and add to T2DSceneManager.Items.
A.2) Alternative: Load them using TCastleScene, add to TCastleSceneManager.Items --- just like 3D entities. Remember to possibly adjust TCastleScene.Attributes.BlendingSort to bs2D (to guarantee good drawing order for textures with smooth alpha channel), and possibly adjust TCastleSceneManager.RenderStyle to rs2D (then scene manager is rendered above/below other 2D controls, depending on their relative order on Window.Controls list).
B) To start a concrete Spine animation, use TCastleScene.PlayAnimation. Use TCastleScene.Animations to list named animations. This simply uses X3D named TimeSensor nodes underneath.
Underneath, we also support multiple Spine skins, although there is no easy API to change them at runtime yet (you can only choose skin at loading).
2. Named animations: many 3D and 2D models define multiple animations that can be started by an external code (for example, by a programmer using Castle Game Engine). Our engine detects now such animations by looking at X3D TimeSensor node names. Name starting with "Animation_xxx" indicates an animation, with name "xxx". Some converters (right now, our Spine to X3D conversion) follow this convention, so our engine immediately "knows" the Spine animation names and can play them.
The benefits of such "named" animations:
- view3dscene displays a user-friendly menu in "Animation->Named Animations->" to run animation by name. You can force the animation looping state when running it, if needed. (For example, useful for "walk" and such animations designed in Spine, as you cannot mark them "looping" in Spine.)
- TCastleScene offers a simple API for programmers to browse and run animation by name, see TCastleScene.Animations and TCastleScene.PlayAnimation. PlayAnimation automatically stops the previous animation too.
3. Scene manager for 2D: We have a new T2DSceneManager, best suited for 2D worlds (for example, using Spine animations). The rendering, with TUIControl.RenderStyle, was reworked to be more flexible for 2D stuff: RenderStyle 2D vs 3D now only determines the drawing order. This means that 2D and 3D rendering using our scene manager is almost identical, and yet they are both comfortable for programmer.