{"id":523,"date":"2018-03-21T05:05:53","date_gmt":"2018-03-21T05:05:53","guid":{"rendered":"https:\/\/castle-engine.io\/wp\/?p=523"},"modified":"2018-03-21T05:05:53","modified_gmt":"2018-03-21T05:05:53","slug":"animation-blending","status":"publish","type":"post","link":"https:\/\/castle-engine.io\/wp\/2018\/03\/21\/animation-blending\/","title":{"rendered":"Animation Blending"},"content":{"rendered":"<table class=\"thumbnails thumbnails-align-right\"><tr><td>\n          <a href=\"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2018\/03\/Screenshot-at-2018-03-21-054737.png\"\n             class=\"screenshot\"\n             title=\"PlayAnimation demo with animation blending\"><img loading=\"lazy\" decoding=\"async\"\n            style=\"float: right\"\n            src=\"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2018\/03\/Screenshot-at-2018-03-21-054737-200x112.png\"\n             width=\"200\" height=\"112\" \n            alt=\"PlayAnimation demo with animation blending\"\n          ><\/a><\/td><\/tr><\/table>\n<p><i>Animation blending<\/i> means that the transition between animations is smooth. Without animation blending, the old animation instantly stops and the new animation plays. With animation blending, there is a short time during which the old animation &#8220;fades out&#8221; (it&#8217;s applied with decreasing strength) and the new animation &#8220;fades in&#8221; (analogously, it&#8217;s applied with increasing strength).<\/p>\n<p>The movie below shows this technique in action in new <em>Castle Game Engine<\/em>. Notice how animation changes are sharp when <code>TransitionDuration<\/code> is zero, but they are smooth when <code>TransitionDuration<\/code> is larger. This is especially visible when switching between &#8220;Idle&#8221; and &#8220;Attack&#8221; animations on the 3D knight model.<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/h-S1vRIpbTk\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen><\/iframe><\/p>\n<p>This feature was implemented thanks to <a href=\"https:\/\/www.patreon.com\/castleengine\">Castle Game Engine supporters on Patreon<\/a>, in particular thanks to <i>Robert Daniel Murphy<\/i> who wished for it. Thank you! Please <a href=\"https:\/\/www.patreon.com\/castleengine\">support me<\/a> to see more cool features \ud83d\ude42<\/p>\n<h2>How to use this<\/h2>\n<p>Use <a href=\"http:\/\/michalis.ii.uni.wroc.pl\/cge-www-preview\/apidoc\/html\/CastleSceneCore.TCastleSceneCore.html#PlayAnimation\">TCastleSceneCore.PlayAnimation<\/a> with <a href=\"http:\/\/michalis.ii.uni.wroc.pl\/cge-www-preview\/apidoc\/html\/CastleSceneCore.TPlayAnimationParameters.html\">TPlayAnimationParameters<\/a>, and set <a href=\"http:\/\/michalis.ii.uni.wroc.pl\/cge-www-preview\/apidoc\/html\/CastleSceneCore.TPlayAnimationParameters.html#TransitionDuration\">TPlayAnimationParameters.TransitionDuration<\/a>. TransitionDuration is the time (in seconds) when when previous animation fades-out and new animation fades-in, usually values around 0.1-0.5 make sensible smooth effect. TransitionDuration = 0 (default) means that no animation blending occurs.<\/p>\n<p>We have a new demo <a href=\"https:\/\/github.com\/castle-engine\/castle-engine\/tree\/master\/examples\/play_animation\">examples\/play_animation\/<\/a> to test the <code>PlayAnimation<\/code> method, including <code>Loop<\/code>, <code>Forward<\/code> and <code>TransitionDuration<\/code>.<\/p>\n<h2>Additional cool features of our animation blending<\/h2>\n<ol>\n<li>Note that animation blending happens even when you restart the same animation. We show this in the movie by restarting the &#8220;Walk&#8221; animation &#8212; note that &#8220;old Walk&#8221; blends smoothly into &#8220;new, restarted Walk&#8221; when Transition is non-zero.\n<li>Animation blending works for any field that can be linearly interpolated. So it works for animating translations, rotations, coordinate sets and everything else. It works for mesh deformations, or bone animations produced by Spine. It works for 3D or 2D.\n<\/ol>\n<h2>Caveats (aka &#8220;things that, sadly, do not work yet&#8221;)<\/h2>\n<ol>\n<li>For now, the animation blending doesn&#8217;t work for animations defined by <a href=\"https:\/\/castle-engine.io\/castle_animation_frames.php\">castle-anim-frames<\/a> (which you probably use to export <a href=\"https:\/\/castle-engine.io\/creating_data_blender.php\">animations from Blender<\/a>). Fixing this requires improving the castle-anim-frames loading a bit.\n<p><em>Background<\/em>: Animation blending only works when the same mesh is used by all animation frames, but in case of castle-anim-frames we cheat a little and we have many (precalculated) copies of the mesh. This was supposed to be fixed one day anyway, to decrease memory usage (<a href=\"https:\/\/castle-engine.io\/castle_animation_frames.php\">see the TODO here<\/a>). It turns out that this fix is also needed to enable animation blending.<\/p>\n<li>\n<p>For now, there is no way to define <code>TransitionDuration<\/code> for animations run by our TCreature system (using <code>resource.xml<\/code>) files. The resources animations (like TCreature) are done a little differently, without directly calling PlayAnimation, and they require a bit different code to make use of animation blending.\n<\/ol>\n<p>Both of these will be fixed one day (AD 1 is a work for ~2 days, AD 2 is a work for ~0.5 day). Let me know if any of this is critical for your project, and I&#8217;ll try to make it rather sooner than later! \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Animation blending means that the transition between animations is smooth. Without animation blending, the old animation instantly stops and the new animation plays. With animation blending, there is a short time during which the old animation &#8220;fades out&#8221; (it&#8217;s applied with decreasing strength) and the new animation &#8220;fades in&#8221; (analogously, it&#8217;s applied with increasing strength). &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/castle-engine.io\/wp\/2018\/03\/21\/animation-blending\/\" class=\"more-link\">Continue reading  \u27a4<span class=\"screen-reader-text\"> &#8220;Animation Blending&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":524,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"publish_to_discourse":"","publish_post_category":"","wpdc_auto_publish_overridden":"","wpdc_topic_tags":"","wpdc_pin_topic":"","wpdc_pin_until":"","discourse_post_id":"","discourse_permalink":"","wpdc_publishing_response":"","wpdc_publishing_error":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/castle-engine.io\/wp\/wp-content\/uploads\/2018\/03\/Screenshot-at-2018-03-21-054737.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9IgYW-8r","jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts\/523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/comments?post=523"}],"version-history":[{"count":8,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts\/523\/revisions"}],"predecessor-version":[{"id":532,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/posts\/523\/revisions\/532"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/media\/524"}],"wp:attachment":[{"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/media?parent=523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/categories?post=523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/castle-engine.io\/wp\/wp-json\/wp\/v2\/tags?post=523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}