/
AnimationAsset.cs
152 lines (133 loc) · 5.92 KB
/
AnimationAsset.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Xenko.Core.Assets;
using Xenko.Core.Assets.Compiler;
using Xenko.Core;
using Xenko.Core.Annotations;
using Xenko.Core.IO;
using Xenko.Core.Mathematics;
using Xenko.Core.Serialization;
using Xenko.Core.Serialization.Contents;
using Xenko.Animations;
using Xenko.Rendering;
namespace Xenko.Assets.Models
{
[DataContract("Animation")]
[AssetDescription(FileExtension)]
[AssetContentType(typeof(AnimationClip))]
[Display((int)AssetDisplayPriority.Models + 20, "Animation")]
[AssetFormatVersion(XenkoConfig.PackageName, CurrentVersion, "2.0.0.0")]
public class AnimationAsset : Asset, IAssetWithSource
{
private const string CurrentVersion = "2.0.0.0";
/// <summary>
/// The default file extension used by the <see cref="AnimationAsset"/>.
/// </summary>
public const string FileExtension = ".xkanim";
public static readonly TimeSpan LongestTimeSpan = TimeSpan.FromMinutes(30); // Avoid TimeSpan.MaxValue because it results in overflow exception when used in some calculations
public AnimationAsset()
{
ClipDuration = new AnimationAssetDuration()
{
Enabled = false,
StartAnimationTime = TimeSpan.Zero,
EndAnimationTime = LongestTimeSpan,
};
}
/// <summary>
/// Gets or sets the source file of this asset.
/// </summary>
/// <value>The source.</value>
/// <userdoc>
/// The source file of this asset.
/// </userdoc>
[DataMember(-50)]
[DefaultValue(null)]
[SourceFileMember(true)]
public UFile Source { get; set; } = new UFile("");
[DataMemberIgnore]
public override UFile MainSource => Source;
/// <summary>
/// Enable clipping of the animation duration
/// </summary>
/// <userdoc>
/// Enable clipping of the animation duration, constraining start and end frames.
/// </userdoc>
[DataMember(0)]
[Display("Clip duration", Expand = ExpandRule.Always)]
public AnimationAssetDuration ClipDuration { get; set; }
// This property is marked as hidden by the AnimationViewModel
public TimeSpan AnimationTimeMinimum { get; set; }
// This property is marked as hidden by the AnimationViewModel
public TimeSpan AnimationTimeMaximum { get; set; }
/// <summary>
/// Gets or sets the pivot position, that will be used as center of object. If a Skeleton is set, its value will be used instead.
/// </summary>
/// <userdoc>
/// The root (pivot) of the animation will be offset by this distance. If a Skeleton is set, its value will be used instead.
/// </userdoc>
[DataMember(10)]
public Vector3 PivotPosition { get; set; }
/// <summary>
/// Gets or sets the scale import. If a Skeleton is set, its value will be used instead.
/// </summary>
/// <userdoc>The scale applied to the imported animation. If a Skeleton is set, its value will be used instead.</userdoc>
[DataMember(15)]
[DefaultValue(1.0f)]
public float ScaleImport { get; set; } = 1.0f;
/// <summary>
/// Gets or sets the animation repeat mode.
/// </summary>
/// <value>The repeat mode</value>
/// <userdoc>
/// Hint for the animation engine. Can be overridden at runtime when playing the animation. If no mode is specified at runtime, the hint will be used.
/// </userdoc>
[DataMember(20)]
[Display("Repeat mode hint")]
public AnimationRepeatMode RepeatMode { get; set; } = AnimationRepeatMode.LoopInfinite;
/// <summary>
/// Determine the animation type of the asset, which will dictate in what blend mode we can use it
/// </summary>
/// <userdoc>
/// The animation type of the asset decides how we blend it - linear blending will be used for Animation Clip, additive blending for Difference Clip
/// </userdoc>
[NotNull]
[DataMember(30)]
public AnimationAssetType Type { get; set; } = new StandardAnimationAssetType();
/// <summary>
/// Gets or sets the Skeleton.
/// </summary>
/// <userdoc>
/// Describes the node hierarchy that will be active at runtime.
/// </userdoc>
[DataMember(50)]
public Skeleton Skeleton { get; set; }
/// <summary>
/// Gets or sets a boolean describing if root movement should be applied inside Skeleton (if false and a skeleton exists) or on TransformComponent (if true)
/// </summary>
/// <userdoc>
/// When root motion is enabled, main motion will be applied to TransformComponent. If false, it will be applied inside the skeleton nodes.
/// Note that if there is no skeleton, it will always apply motion to TransformComponent.
/// </userdoc>
[DataMember(60)]
public bool RootMotion { get; set; }
/// <summary>
/// Gets or sets a boolean describing if custom attributes present in the source asset should be imported or not.
/// </summary>
/// <userdoc>If checked, import all the custom animation cuves present in the source file.</userdoc>
[DataMember(70)]
[DefaultValue(false)]
public bool ImportCustomAttributes { get; set; } = false;
/// <summary>
/// Gets or sets the preview model
/// </summary>
/// <userdoc>
/// Choose a model to preview with.
/// </userdoc>
[DataMember(100)]
public Model PreviewModel { get; set; }
}
}