BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Properties | List of all members
BrawlLib.Wii.Animations.KeyframeEntry Class Reference

Public Member Functions

bool Equals (KeyframeEntry obj)
 
 KeyframeEntry (int index, float value)
 
void InsertBefore (KeyframeEntry entry)
 Inserts the provided entry before this one and relinks the previous and next entries. More...
 
void InsertAfter (KeyframeEntry entry)
 Inserts the provided entry after this one and relinks the previous and next entries. More...
 
void Remove ()
 
float Interpolate (float offset, float span, KeyframeEntry next, bool forceLinear=false)
 
float Interpolate (float offset, bool forceLinear=false)
 Returns an interpolated value between this keyframe and the next. You can force linear calculation, but the Wii itself doesn't have anything like that. The Wii emulates linear interpolation using two keyframes across a range with the same tangent and then two keyframes on the same frame but with different tangents. More...
 
float GenerateTangent ()
 
override string ToString ()
 

Public Attributes

int _index
 
KeyframeEntry _prev
 
KeyframeEntry _next
 
float _value
 
float _tangent
 

Properties

KeyframeEntry Second [get, set]
 

Constructor & Destructor Documentation

◆ KeyframeEntry()

BrawlLib.Wii.Animations.KeyframeEntry.KeyframeEntry ( int  index,
float  value 
)
inline
225 {
226 _index = index;
227 _prev = _next = this;
228 _value = value;
229 }
KeyframeEntry _prev
Definition: KeyframeCollection.cs:195
int _index
Definition: KeyframeCollection.cs:194
float _value
Definition: KeyframeCollection.cs:197
KeyframeEntry _next
Definition: KeyframeCollection.cs:195

Member Function Documentation

◆ Equals()

bool BrawlLib.Wii.Animations.KeyframeEntry.Equals ( KeyframeEntry  obj)
inline
201 {
202 return obj is KeyframeEntry entry && _index == entry._index && _value == entry._value && _tangent == entry._tangent;
203 }
KeyframeEntry(int index, float value)
Definition: KeyframeCollection.cs:224
float _tangent
Definition: KeyframeCollection.cs:198

◆ GenerateTangent()

float BrawlLib.Wii.Animations.KeyframeEntry.GenerateTangent ( )
inline
323 {
324 _tangent = 0.0f;
325 if (Second != null)
326 {
327 if (_prev._index == _index)
328 {
329 if (_next._index != -1)
330 {
331 //Generate only with the next keyframe
333 }
334 }
335 else if (_next._index == _index)
336 {
337 if (_prev._index != -1)
338 {
339 //Generate only with the previous keyframe
341 }
342 }
343 }
344 else
345 {
346 float weightCount = 0;
347 if (_prev._index != -1)
348 {
350 weightCount++;
351 }
352
353 if (_next._index != -1)
354 {
355 _tangent += (_next._value - _value) / (_next._index - _index);
356 weightCount++;
357 }
358
359 if (weightCount > 0)
360 {
361 _tangent /= weightCount;
362 }
363 }
364
365 if (RoundTangent)
366 {
367 _tangent = (float) Math.Round(_tangent, TangetDecimalPlaces);
368 }
369
370 return _tangent;
371 }
KeyframeEntry Second
Definition: KeyframeCollection.cs:206

◆ InsertAfter()

void BrawlLib.Wii.Animations.KeyframeEntry.InsertAfter ( KeyframeEntry  entry)
inline

Inserts the provided entry after this one and relinks the previous and next entries.

246 {
247 _next._prev = entry;
248 entry._next = _next;
249 entry._prev = this;
250 _next = entry;
251 }

◆ InsertBefore()

void BrawlLib.Wii.Animations.KeyframeEntry.InsertBefore ( KeyframeEntry  entry)
inline

Inserts the provided entry before this one and relinks the previous and next entries.

235 {
236 _prev._next = entry;
237 entry._prev = _prev;
238 entry._next = this;
239 _prev = entry;
240 }

◆ Interpolate() [1/2]

float BrawlLib.Wii.Animations.KeyframeEntry.Interpolate ( float  offset,
bool  forceLinear = false 
)
inline

Returns an interpolated value between this keyframe and the next. You can force linear calculation, but the Wii itself doesn't have anything like that. The Wii emulates linear interpolation using two keyframes across a range with the same tangent and then two keyframes on the same frame but with different tangents.

315 {
316 return Interpolate(offset, _next._index - _index, _next, forceLinear);
317 }
float Interpolate(float offset, float span, KeyframeEntry next, bool forceLinear=false)
Definition: KeyframeCollection.cs:259

◆ Interpolate() [2/2]

float BrawlLib.Wii.Animations.KeyframeEntry.Interpolate ( float  offset,
float  span,
KeyframeEntry  next,
bool  forceLinear = false 
)
inline
260 {
261 //Return this value if no offset from this keyframe
262 if (offset == 0)
263 {
264 return _value;
265 }
266
267 //Return next value if offset is to the next keyframe
268 if (offset == span)
269 {
270 return next._value;
271 }
272
273 //Get the difference in values
274 float diff = next._value - _value;
275
276 //Calculate a percentage from this keyframe to the next
277 float time = offset / span; //Normalized, 0 to 1
278
279 bool prevDouble = _prev._index >= 0 && _prev._index == _index - 1;
280 bool nextDouble = next._next._index >= 0 && next._next._index == next._index + 1;
281 bool oneApart = _next._index == _index + 1;
282
283 if (forceLinear)
284 {
285 return _value + diff * time;
286 }
287
288 float tan = _tangent;
289 float nextTan = next._tangent;
290
291 if (prevDouble || oneApart)
292 {
293 // Do nothing, as this doesn't seem to work properly //tan = (next._value - _value) / (next._index - _index);
294 }
295
296 if (nextDouble || oneApart)
297 {
298 // Do nothing, as this doesn't seem to work properly //nextTan = (next._value - _value) / (next._index - _index);
299 }
300
301 //Interpolate using a hermite curve
302 float inv = time - 1.0f; //-1 to 0
303 return _value
304 + offset * inv * (inv * tan + time * nextTan)
305 + time * time * (3.0f - 2.0f * time) * diff;
306 }

◆ Remove()

void BrawlLib.Wii.Animations.KeyframeEntry.Remove ( )
inline
254 {
255 _next._prev = _prev;
256 _prev._next = _next;
257 }

◆ ToString()

override string BrawlLib.Wii.Animations.KeyframeEntry.ToString ( )
inline
374 {
375 return $"Value={_value}";
376 }

Member Data Documentation

◆ _index

int BrawlLib.Wii.Animations.KeyframeEntry._index

◆ _next

KeyframeEntry BrawlLib.Wii.Animations.KeyframeEntry._next

◆ _prev

KeyframeEntry BrawlLib.Wii.Animations.KeyframeEntry._prev

◆ _tangent

float BrawlLib.Wii.Animations.KeyframeEntry._tangent

◆ _value

float BrawlLib.Wii.Animations.KeyframeEntry._value

Property Documentation

◆ Second

KeyframeEntry BrawlLib.Wii.Animations.KeyframeEntry.Second
getset
206 {
207 get => _prev._index == _index ? _prev : _next._index == _index ? _next : null;
208 set
209 {
210 KeyframeEntry second = Second;
211 if (second == null)
212 {
213 value._index = _index;
214 InsertAfter(value);
215 }
216 else
217 {
218 second._value = value._value;
219 second._tangent = value._tangent;
220 }
221 }
222 }
void InsertAfter(KeyframeEntry entry)
Inserts the provided entry after this one and relinks the previous and next entries.
Definition: KeyframeCollection.cs:245

The documentation for this class was generated from the following file: