| 663 | //------------------------------------------------------------------------------------- |
| 664 | |
| 665 | void TSShapeInstance::animateVisibility(S32 ss) |
| 666 | { |
| 667 | PROFILE_SCOPE( TSShapeInstance_animateVisibility ); |
| 668 | |
| 669 | S32 i; |
| 670 | if (!mMeshObjects.size()) |
| 671 | return; |
| 672 | |
| 673 | // find out who needs default values set |
| 674 | TSIntegerSet beenSet; |
| 675 | beenSet.setAll(mMeshObjects.size()); |
| 676 | for (i=0; i<mThreadList.size(); i++) |
| 677 | beenSet.takeAway(mThreadList[i]->getSequence()->visMatters); |
| 678 | |
| 679 | // set defaults |
| 680 | S32 a = mShape->subShapeFirstObject[ss]; |
| 681 | S32 b = a + mShape->subShapeNumObjects[ss]; |
| 682 | for (i=a; i<b; i++) |
| 683 | { |
| 684 | if (beenSet.test(i)) |
| 685 | mMeshObjects[i].visible = mShape->objectStates[i].vis; |
| 686 | } |
| 687 | |
| 688 | // go through each thread and set visibility on those objects that |
| 689 | // are not set yet and are controlled by that thread |
| 690 | for (i=0; i<mThreadList.size(); i++) |
| 691 | { |
| 692 | TSThread * th = mThreadList[i]; |
| 693 | |
| 694 | const TSShape::Sequence* threadSequence = th->getSequence(); |
| 695 | |
| 696 | // For better or worse, object states are stored together (frame, |
| 697 | // matFrame, visibility all in one structure). Thus, indexing into |
| 698 | // object state array for animation for any of these attributes needs to |
| 699 | // take into account whether or not the other attributes are also animated. |
| 700 | // The object states should eventually be separated (like the node states were) |
| 701 | // in order to save memory and save the following step. |
| 702 | TSIntegerSet objectMatters = threadSequence->frameMatters; |
| 703 | objectMatters.overlap(threadSequence->matFrameMatters); |
| 704 | objectMatters.overlap(threadSequence->visMatters); |
| 705 | |
| 706 | // skip to beginning of this sub-shape |
| 707 | S32 j=0; |
| 708 | S32 start = objectMatters.start(); |
| 709 | S32 end = b; |
| 710 | for (S32 objectIndex = start; objectIndex<end; objectMatters.next(objectIndex), j++) |
| 711 | { |
| 712 | if (!beenSet.test(objectIndex) && threadSequence->visMatters.test(objectIndex)) |
| 713 | { |
| 714 | F32 state1 = mShape->getObjectState(*threadSequence,th->keyNum1,j).vis; |
| 715 | F32 state2 = mShape->getObjectState(*threadSequence,th->keyNum2,j).vis; |
| 716 | if ((state1-state2) * (state1-state2) > 0.99f) |
| 717 | // goes from 0 to 1 -- discreet jump |
| 718 | mMeshObjects[objectIndex].visible = th->keyPos<0.5f ? state1 : state2; |
| 719 | else |
| 720 | // interpolate between keyframes when visibility change is gradual |
| 721 | mMeshObjects[objectIndex].visible = (1.0f-th->keyPos) * state1 + th->keyPos * state2; |
| 722 | |