User:Lexevo/Findings/AnimJ

From Neos Wiki
< User:Lexevo‎ | Findings
Revision as of 04:09, 19 January 2023 by Lexevo (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

AnimJ is just a JSON representation of a CodeX.Animation object.

Valid Animation Types

The supported types for AnimJ imported Animations are:

  • bool
  • bool2
  • bool3
  • bool4
  • byte
  • ushort
  • ulong
  • sbyte
  • short
  • int
  • int2
  • int3
  • int4
  • uint
  • uint2
  • uint3
  • uint4
  • long
  • long2
  • long3
  • long4
  • float
  • float2
  • float3
  • float4
  • floatQ
  • float2x2
  • float3x3
  • float4x4
  • double
  • double2
  • double3
  • double4
  • doubleQ
  • double2x2
  • double3x3
  • double4x4
  • color
  • color32 (Not sure about this)
  • string


NOT Supported:

  • char
  • DateTime
  • TimeSpan
  • decimal
  • enums

These are not supported due to them not being contained in the BaseX.AnimX.elementTypes list.

Value Examples

Data Type Example
bool True
bool2 {"x": True, "y": False}
bool3 {"x": True, "y": False, "z": True}
bool4 {"x": True, "y": False, "z": True, "w": False}
byte 23
ushort 1200
ulong 2349587120938
sbyte -3
short -56
int 69
int2 {"x": 12, "y": -4}
int3 {"x": 12, "y": -4, "z": 203}
int4 {"x": 12, "y": -4, "z": 203, "w": 0}
uint 9
uint2 {"x": 9, "y": 4}
uint3 {"x": 9, "y": 4, "z": 2147483699}
uint4 {"x": 9, "y": 4, "z": 2147483699, "w": 1}
long 9876543210
long2 {"x": 12, "y": -4}
long3 {"x": 12, "y": -4, "z": 203}
long4 {"x": 12, "y": -4, "z": 203, "w": 0}
float 4.3
float2 {"x": 4.3, "y": 1.34}
float3 {"x": 4.3, "y": 1.34, "z": 2.333E+9}
float4 {"x": 4.3, "y": 1.34, "z": 2.333E+9, "w": -5.000000001}
floatQ {"x": 1.889846E-07, "y": -0.5664063, "z": -1.762067E-07, "w": 0.8241262}
float2x2
float3x3
float4x4
double 4.3
double2 {"x": 4.3, "y": 1.34}
double3 {"x": 4.3, "y": 1.34, "z": 2.333E+9}
double4 {"x": 4.3, "y": 1.34, "z": 2.333E+9, "w": -5.000000001}
doubleQ {"x": 1.889846E-07, "y": -0.5664063, "z": -1.762067E-07, "w": 0.8241262}
double2x2
double3x3
double4x4
color {"r": 0.2, "g": 0, "b": 1, "a": 0.85}
color32 {"r": 0.2, "g": 0, "b": 1, "a": 0.85}
string "Hello World!"

Schema of AnimJ

Animation

The base Animation object.

Property Type Description Required
name String The internal name of the whole Animation No
globalDuration Number The amount of time in seconds the whole animation will play for (even if your keyframes end earlier) No
tracks array of AnimationTrack objects The list of tracks that are included in the animation No, but useless without

AnimationTrack

The track(s) inside an Animation.

Property Type Description Required
trackType "Raw", "Discrete" or "Curve" Used to determine how each keyframe is interpolated between frames. Yes
valueType One of the valid types as a String Determines what value type is used throughout the track. Yes
data The rest of the AnimationTrack object (See below) Holds the keyframe data, as well as the Node and Property properties. Yes

Note: The AnimationTrack object imported from the JSON isn't what actually gets stored in Neos. Instead, a custom JsonConverter is used to read the trackType and valuetype properties, and then creates the corresponding object related to those with the data property. (RawAnimationTrack<T>, DiscreteAnimationTrack<T>, CurveAnimationTrack<T>)

Therefore, there is different keyframe data depending on what type you specify in trackType.

The data that applies to all track types:

Property Type Description Required
node String Designed to be used to specify the object being controlled by the animation. Can be used with the Find Animation Track Index Logix node. No
property String Designed to be used to specify the field of the object that is being controlled by the animation. Can be used with the Find Animation Track Index Logix node. No
keyframes See Below A list of values at specific time intervals to determine what the whole track's value should be at specific times. No

Data that applies to the Raw Animation Track Type only:

Property Type Description Required
interval Number The time it takes in seconds to linearly interpolate between each keyframe (Using this will ignore globalDuration) No

Keyframes

The data that contains what the animation track's value should be at specific times.

This is structured differently for each Animation Track Type.

Raw

This track type will set the value at equal intervals only. The Keyframes property is just an array of values for the Raw type. The time between each frame is determined by the interval. The Animation Track will not work as intended, however, unless the interval property is included.

Discrete

This track type will set the value at specified times. These keyframes are objects

Property Type Description Required
time Number The elapsed amount of time in seconds since the start of the animation in which the accompanying value property should be applied. Yes
value The type set in the valueType property. See the examples for representations of each type. The value that will be set Yes

Curve

This track type will set the values at the specified time, and interpolate between the frames to get to those values. These keyframes are objects

Property Type Description Required
time Number The elapsed amount of time in seconds since the start of the animation in which the accompanying value property should be reached through interpolation. Yes
value The type set in the valueType property. See the examples for representations of each type. The value that will be set Yes
interpolation "Linear", "Tangent" or "Hold" See #Interpolation types Yes
leftTangent The type set in the valueType property. See the examples for representations of each type. See #Interpolation types Only when interpolation is set to "Tangent"
rightTangent The type set in the valueType property. See the examples for representations of each type. See #Interpolation types Only when interpolation is set to "Tangent"
Interpolation types

Each keyframe in the Curve animation track can have a different interpolation type. These types are as follows:

Linear

The linear interpolation type will transform the value linearly from the current keyframe's value to the next keyframe's value, between the start of the current keyframe's time and the start of the next keyframe's time.

Hold

The Hold interpolation type makes the current keyframe act like the Discrete Animation Track type, where it will stay at that position and when the next keyframe's time is reached, will immediately transform to the next keyframe's value.

Tangent

TODO

Other Notes

  • I seem to be having trouble getting any of the matrix types to work properly. Neos is expecting the values of these to be named the same way as the internal property names, so for example, a float2x2 would look like:

{"m00": 1.0, "m01": 2.0, "m10": 3.0, "m11": 4.0}. This imports and creates a StaticAnimation in Neos, however, when the animation is played, it is stuck at all zeroes.

  • I'm very confused on the specifics of the Tangent interpolation type. Froox says here that they define a Bezier curve, however, through my testing, I can't seem to get the values of my Bezier curve that I made inside Neos to match exactly the same as how the animation interpolates it. I've tried both a quadratic and cubic Bezier curve with the float3 type to visually represent an object, but these both don't match up. Not certain if it is my implementation of Bezier curves that is incorrect, or I just don't have enough info on how this interpolation works.
    • So it turns out that the data Neos uses to interpolate tangent is: The value of the current keyframe, the rightTangent of the current keyframe, the leftTangent of the next keyframe, and the value of the next keyframe.
    • I'm still having trouble with the equations it uses.
  • I think there's some functionality difference between the Sample Animation Track logix node and the Animator component. Especially in how they read the Raw animaiton track type.
  • There's a few small bits of functionality I need to figure out like:
    • How the Sample Animation Track logix node and the Animator component handle Animations without a set globalDuration.
    • What happens when you have multiple animation tracks with the same Node or Property value set. And what happens when you use the "Find Animation Track Index" logix node in this situation.
    • What happens to a RawAnimationTrack with no globalDuration or interval.
    • What happens when a keyframe has a lower time value than the previous keyframe (probably just plays it first, but not sure).
    • How Neos interprets time values greater than the globalDuration when using the Sample Animation Track logix node.