4 using System.Threading.Tasks;
6 using SiliconStudio.Assets.Compiler;
7 using SiliconStudio.BuildEngine;
8 using SiliconStudio.Core;
9 using SiliconStudio.Core.Collections;
10 using SiliconStudio.Core.IO;
11 using SiliconStudio.Core.Mathematics;
12 using SiliconStudio.Core.Serialization.Assets;
13 using SiliconStudio.Paradox.DataModel;
14 using SiliconStudio.Paradox.Engine;
16 namespace SiliconStudio.
Paradox.Assets.Model
23 var assetDirectory = assetAbsolutePath.GetParent();
24 var assetSource = UPath.Combine(assetDirectory, asset.Source);
25 var extension = assetSource.GetFileExtension();
29 if (additiveAnimationAsset != null)
31 var baseUrlInStorage = urlInStorage +
"_animation_base";
32 var sourceUrlInStorage = urlInStorage +
"_animation_source";
34 var baseAssetSource = UPath.Combine(assetDirectory, additiveAnimationAsset.BaseSource);
51 buildStep.Add(
new AdditiveAnimationCommand(urlInStorage,
new AdditiveAnimationParameters(baseUrlInStorage, sourceUrlInStorage, additiveAnimationAsset.Mode)));
57 buildStep.Add(
new ImportFbxCommand { SourcePath = assetSource, Location = urlInStorage, ExportType =
"animation", AnimationRepeatMode = asset.RepeatMode });
59 buildStep.Add(
new ImportAssimpCommand { SourcePath = assetSource, Location = urlInStorage, ExportType =
"animation", AnimationRepeatMode = asset.RepeatMode });
62 result.BuildSteps = buildStep;
65 internal class AdditiveAnimationCommand :
AssetCommand<AdditiveAnimationParameters>
67 public AdditiveAnimationCommand(
string url, AdditiveAnimationParameters asset) : base(url, asset)
76 var baseAnimation = assetManager.Load<
AnimationClip>(asset.BaseUrl);
77 var sourceAnimation = assetManager.Load<
AnimationClip>(asset.SourceUrl);
80 var animation = SubtractAnimations(baseAnimation, sourceAnimation);
83 assetManager.Save(Url, animation);
85 return Task.FromResult(ResultStatus.Successful);
90 if (baseAnimation == null)
throw new ArgumentNullException(
"baseAnimation");
91 if (sourceAnimation == null)
throw new ArgumentNullException(
"sourceAnimation");
95 var baseEvaluator = animationBlender.CreateEvaluator(baseAnimation);
96 var sourceEvaluator = animationBlender.CreateEvaluator(sourceAnimation);
100 foreach (var channel
in sourceAnimation.
Channels)
106 if (newCurve.ElementType != typeof(
Quaternion))
107 newCurve.InterpolationType = AnimationCurveInterpolationType.Cubic;
109 resultAnimation.AddCurve(channel.Key, newCurve);
112 var resultEvaluator = animationBlender.CreateEvaluator(resultAnimation);
114 var animationOperations =
new FastList<AnimationOperation>();
119 var frameTime = TimeSpan.FromSeconds(1.0f / 30.0f);
120 for (var time = TimeSpan.Zero; time < sourceAnimation.
Duration + frameTime; time += frameTime)
123 if (time > sourceAnimation.
Duration)
124 time = sourceAnimation.Duration;
129 case AdditiveAnimationBaseMode.FirstFrame:
130 baseTime = TimeSpan.Zero;
132 case AdditiveAnimationBaseMode.Animation:
133 baseTime = TimeSpan.FromTicks(time.Ticks % baseAnimation.Duration.Ticks);
136 throw new ArgumentOutOfRangeException();
140 animationOperations.Clear();
141 animationOperations.Add(AnimationOperation.NewPush(sourceEvaluator, time));
142 animationOperations.Add(AnimationOperation.NewPush(baseEvaluator, baseTime));
143 animationOperations.Add(AnimationOperation.NewBlend(AnimationBlendOperation.Subtract, 1.0f));
144 animationOperations.Add(AnimationOperation.NewPop(resultEvaluator, time));
148 animationBlender.Compute(animationOperations, ref animationClipResult);
151 resultAnimation.Duration = sourceAnimation.Duration;
152 resultAnimation.RepeatMode = sourceAnimation.RepeatMode;
154 return resultAnimation;
173 SourceUrl = sourceUrl;
TimeSpan Duration
Gets or sets the duration of this clip.
Dictionary< string, Channel > Channels
Gets the channels of this clip.
Result of a compilation of assets when using IAssetCompiler.Compile
A command processing an Asset.
AdditiveAnimationParameters(string baseUrl, string sourceUrl, AdditiveAnimationBaseMode mode)
The context used when compiling an asset in a Package.
When embedded in a EnumerableBuildStep, this build step will force all previous computations to be fi...
AdditiveAnimationBaseMode Mode
An aggregation of AnimationCurve with their channel names.
AnimationRepeatMode
Enumeration describing how an animation should be repeated.
AdditiveAnimationBaseMode
override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, AnimationAsset asset, AssetCompilerResult result)
AdditiveAnimationParameters()
Represents a four dimensional mathematical quaternion.
Untyped base class for animation curves.
Performs animation blending. For now, all AnimationClip must target the same skeleton.
static bool IsSupportingExtensions(string ext)
static bool IsSupportingExtensions(string ext)
Defines a normalized file path. See UPath for details. This class cannot be inherited.