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

Public Member Functions

 KeyframeArray (int limit, float defaultValue=0)
 
int Clean ()
 
KeyframeEntry GetKeyframe (int index)
 
float GetFrameValue (float index, bool returnOutValue=false)
 
KeyframeEntry SetFrameValue (int index, float value, bool parsing=false)
 
KeyframeEntry Remove (int index)
 
void Insert (int index)
 
void Delete (int index)
 
bool Equals (KeyframeArray obj)
 

Properties

bool Loop [get, set]
 
int FrameLimit [get, set]
 
float this[int index] [get, set]
 

Constructor & Destructor Documentation

◆ KeyframeArray()

BrawlLib.Wii.Animations.KeyframeArray.KeyframeArray ( int  limit,
float  defaultValue = 0 
)
inline
415 {
416 _frameLimit = limit;
417 _keyRoot = new KeyframeEntry(-1, defaultValue);
418 }

Member Function Documentation

◆ Clean()

int BrawlLib.Wii.Animations.KeyframeArray.Clean ( )
inline
423 {
424 int flag, res, removed = 0;
425 KeyframeEntry entry;
426
427 //Eliminate redundant values
428 for (entry = _keyRoot._next._next; entry != _keyRoot; entry = entry._next)
429 {
430 flag = res = 0;
431
432 if (entry._prev == _keyRoot)
433 {
434 if (entry._next != _keyRoot)
435 {
436 flag = 1;
437 }
438 }
439 else if (entry._next == _keyRoot)
440 {
441 flag = 2;
442 }
443 else
444 {
445 flag = 3;
446 }
447
448 if ((flag & 1) != 0)
449 {
450 res |= Math.Abs(entry._next._value - entry._value) <= _cleanDistance ? 1 : 0;
451 }
452
453 if ((flag & 2) != 0)
454 {
455 res |= Math.Abs(entry._prev._value - entry._value) <= _cleanDistance ? 2 : 0;
456 }
457
458 if (flag == res && res != 0)
459 {
460 entry = entry._prev;
461 entry._next.Remove();
462
463 entry.GenerateTangent();
464 entry._next.GenerateTangent();
465 entry._prev.GenerateTangent();
466
467 _keyCount--;
468 removed++;
469 }
470 }
471
472 return removed;
473 }
KeyframeEntry _next
Definition: KeyframeCollection.cs:195

◆ Delete()

void BrawlLib.Wii.Animations.KeyframeArray.Delete ( int  index)
inline
633 {
634 KeyframeEntry entry = null;
635 for (entry = _keyRoot._prev; entry != _keyRoot && entry._index >= index; entry = entry._prev)
636 {
637 if (entry._index == index || --entry._index < 0)
638 {
639 entry = entry._next;
640 entry._prev.Remove();
641 _keyCount--;
642 }
643 }
644 }
KeyframeEntry _prev
Definition: KeyframeCollection.cs:195
int _index
Definition: KeyframeCollection.cs:194

◆ Equals()

bool BrawlLib.Wii.Animations.KeyframeArray.Equals ( KeyframeArray  obj)
inline
647 {
648 if(obj._keyCount != _keyCount)
649 return false;
650
651 KeyframeEntry comp1 = _keyRoot;
652 KeyframeEntry comp2 = obj._keyRoot;
653
654 for (int i = 0; i < _keyCount; i++)
655 {
656 if(!comp1.Equals(comp2))
657 return false;
658
659 comp1 = comp1._next;
660 comp2 = comp2._next;
661 }
662
663 return true;
664 }

◆ GetFrameValue()

float BrawlLib.Wii.Animations.KeyframeArray.GetFrameValue ( float  index,
bool  returnOutValue = false 
)
inline
492 {
493 KeyframeEntry entry;
494
495 if (index > _keyRoot._prev._index)
496 {
497 //If the frame is greater than the last keyframe's frame index
498 if (_looped)
499 {
500 float span = FrameLimit - _keyRoot._prev._index.Clamp(0, FrameLimit) +
501 _keyRoot._next._index.Clamp(0, FrameLimit);
502 float offset =
503 index > _keyRoot._prev._index && index < FrameLimit
504 ? index - _keyRoot._prev._index
505 : FrameLimit - _keyRoot._prev._index + index;
506
507 return _keyRoot._prev.Interpolate(offset, span, _keyRoot._next);
508 }
509
510 return _keyRoot._prev._value;
511 }
512
513 if (index < _keyRoot._next._index)
514 {
515 //If the frame is less than the first keyframe's frame index
516 if (_looped)
517 {
518 float span = FrameLimit - _keyRoot._prev._index.Clamp(0, FrameLimit) +
519 _keyRoot._next._index.Clamp(0, FrameLimit);
520 float offset =
521 index > _keyRoot._prev._index.Clamp(0, FrameLimit) && index < FrameLimit
522 ? index - _keyRoot._prev._index.Clamp(0, FrameLimit)
523 : FrameLimit - _keyRoot._prev._index.Clamp(0, FrameLimit) + index;
524
525 return _keyRoot._prev.Interpolate(offset, span, _keyRoot._next);
526 }
527
528 return _keyRoot._next._value;
529 }
530
531 //Find the entry just before the specified index
532 for (entry = _keyRoot._next; //Get the first entry
533 entry != _keyRoot && //Make sure it's not the root
534 entry._index <= index; //Its index must be less than or equal to the current index
535 entry = entry._next) //Get the next entry
536 {
537 if (entry._index == index)
538 {
539 //The index is a keyframe
540 if (returnOutValue)
541 {
542 while (entry._next != null && entry._next._index == entry._index)
543 {
544 entry = entry._next;
545 }
546 }
547
548 return entry._value; //Return the value of the keyframe.
549 }
550 }
551
552 //Frame lies between two keyframes. Interpolate between them
553 return entry._prev.Interpolate(index - entry._prev._index);
554 }
int FrameLimit
Definition: KeyframeCollection.cs:395
float _value
Definition: KeyframeCollection.cs:197
float Interpolate(float offset, float span, KeyframeEntry next, bool forceLinear=false)
Definition: KeyframeCollection.cs:259

◆ GetKeyframe()

KeyframeEntry BrawlLib.Wii.Animations.KeyframeArray.GetKeyframe ( int  index)
inline
476 {
477 KeyframeEntry entry;
478 for (entry = _keyRoot._next; entry != _keyRoot && entry._index < index; entry = entry._next)
479 {
480 ;
481 }
482
483 if (entry._index == index)
484 {
485 return entry;
486 }
487
488 return null;
489 }

◆ Insert()

void BrawlLib.Wii.Animations.KeyframeArray.Insert ( int  index)
inline
619 {
620 KeyframeEntry entry = null;
621 for (entry = _keyRoot._prev; entry != _keyRoot && entry._index >= index; entry = entry._prev)
622 {
623 if (++entry._index >= _frameLimit)
624 {
625 entry = entry._next;
626 entry._prev.Remove();
627 _keyCount--;
628 }
629 }
630 }

◆ Remove()

KeyframeEntry BrawlLib.Wii.Animations.KeyframeArray.Remove ( int  index)
inline
598 {
599 KeyframeEntry entry = null;
600 for (entry = _keyRoot._next; entry != _keyRoot && entry._index < index; entry = entry._next)
601 {
602 ;
603 }
604
605 if (entry._index == index)
606 {
607 entry.Remove();
608 _keyCount--;
609 }
610 else
611 {
612 entry = null;
613 }
614
615 return entry;
616 }

◆ SetFrameValue()

KeyframeEntry BrawlLib.Wii.Animations.KeyframeArray.SetFrameValue ( int  index,
float  value,
bool  parsing = false 
)
inline
557 {
558 KeyframeEntry entry = null;
559 if (_keyRoot._prev == _keyRoot || _keyRoot._prev._index < index)
560 {
561 entry = _keyRoot;
562 }
563 else
564 {
565 for (entry = _keyRoot._next; entry != _keyRoot && entry._index <= index; entry = entry._next)
566 {
567 ;
568 }
569 }
570
571 entry = entry._prev;
572 if (entry._index != index)
573 {
574 _keyCount++;
575 entry.InsertAfter(entry = new KeyframeEntry(index, value));
576 }
577 else
578 {
579 //There can be up to two keyframes with the same index.
580 if (!parsing)
581 {
582 entry._value = value; //Do this when editing
583 }
584 else
585 {
586 //And this when parsing
587 _keyCount++;
588 KeyframeEntry temp = new KeyframeEntry(index, value);
589 entry.InsertAfter(temp);
590 entry = temp;
591 }
592 }
593
594 return entry;
595 }

Property Documentation

◆ FrameLimit

int BrawlLib.Wii.Animations.KeyframeArray.FrameLimit
getset
395 {
396 get => _frameLimit;
397 set
398 {
399 _frameLimit = value;
400 while (_keyRoot._prev._index >= value)
401 {
402 _keyRoot._prev.Remove();
403 _keyCount--;
404 }
405 }
406 }
void Remove()
Definition: KeyframeCollection.cs:253

◆ Loop

bool BrawlLib.Wii.Animations.KeyframeArray.Loop
getset
387 {
388 get => _looped;
389 set => _looped = value;
390 }

◆ this[int index]

float BrawlLib.Wii.Animations.KeyframeArray.this[int index]
getset
409 {
410 get => GetFrameValue(index);
411 set => SetFrameValue(index, value);
412 }
KeyframeEntry SetFrameValue(int index, float value, bool parsing=false)
Definition: KeyframeCollection.cs:556
float GetFrameValue(float index, bool returnOutValue=false)
Definition: KeyframeCollection.cs:491

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