예제 #1
0
 public void verifyAnimation(SSSkeletalAnimation animation)
 {
     if (this.numJoints != animation.numJoints)
     {
         string str = string.Format(
             "Joint number mismatch: {0} in md5mesh, {1} in md5anim",
             this.numJoints, animation.numJoints);
         Console.WriteLine(str);
         throw new Exception(str);
     }
     for (int j = 0; j < numJoints; ++j)
     {
         SSSkeletalJoint thisJointInfo = this._joints [j].baseInfo;
         SSSkeletalJoint animJointInfo = animation.jointHierarchy [j];
         if (thisJointInfo.name != animJointInfo.name)
         {
             string str = string.Format(
                 "Joint name mismatch: {0} in md5mesh, {1} in md5anim",
                 thisJointInfo.name, animJointInfo.name);
             Console.WriteLine(str);
             throw new Exception(str);
         }
         if (thisJointInfo.parentIndex != animJointInfo.parentIndex)
         {
             string str = string.Format(
                 "Hierarchy parent mismatch for joint \"{0}\": {1} in md5mesh, {2} in md5anim",
                 thisJointInfo.name, thisJointInfo.parentIndex, animJointInfo.parentIndex);
             Console.WriteLine(str);
             throw new Exception(str);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// This can be used to loop an animation without having to set up a state machine explicitly
        /// For a more sophisticated control use AddController()
        /// </summary>
        public void playAnimationLoop(SSSkeletalAnimation anim, float transitionTime = 0f,
                                      int[] topLevelJoints = null)
        {
            _hierarchy.verifyAnimation(anim);
            var loopSM = new SSAnimationStateMachine();

            loopSM.addState("default", anim, true);
            loopSM.addAnimationEndsTransition("default", "default", transitionTime);
            if (topLevelJoints == null)
            {
                topLevelJoints = _hierarchy.topLevelJoints;
            }
            var loopController = new SSAnimationStateMachineSkeletalController(loopSM, topLevelJoints);

            addController(loopController);
        }
            /// <summary>
            /// Update the animation channel based on time elapsed.
            /// </summary>
            /// <param name="timeElapsed">Time elapsed in seconds</param>
            public void update(float timeElapsed)
            {
                                #if PREV_PREV_FADE
                if (_prevPrevAnimation != null)
                {
                    _prevPrevT += timeElapsed;
                    if (_prevPrevT >= _prevTransitionTime)
                    {
                        _prevPrevAnimation = null;
                        _prevPrevT         = 0f;
                    }
                }
                                #endif

                if (_prevAnimation != null)
                {
                    _prevT += timeElapsed;
                    if (_prevT >= _prevTimeout)
                    {
                        _prevAnimation = null;
                        _prevT         = 0f;
                    }
                }

                if (_currAnimation != null)
                {
                    _currT += timeElapsed;
                    if (_currT >= _transitionTime)
                    {
                        _transitionTime = 0;
                    }
                    if (_currT >= _currAnimation.totalDuration)
                    {
                        _currAnimation = null;
                        _currT         = 0;
                    }
                }
                else if (_currT < _transitionTime)
                {
                    // maintain FadeIn ratio for use with interchannel interpolation
                    _currT += timeElapsed;
                }
            }
            public void playAnimation(SSSkeletalAnimation animation, float transitionTime)
            {
                //System.Console.WriteLine ("play: {0}, repeat: {1}, transitionTime {2}, ichf: {3}",
                //	animation != null ? animation.Name : "null", repeat, transitionTime, interChannelFade);


                // update "previous" variables
                if (transitionTime == 0f)
                {
                    _prevAnimation = null;
                    _prevT         = 0f;
                                        #if PREV_PREV_FADE
                    _prevPrevAnimation = null;
                    _prevPrevT         = 0f;
                                        #endif
                }
                else                     // transitionTime != 0f
                {
                    if (_currAnimation != null)
                    {
                                                #if PREV_PREV_FADE
                        if (_prevAnimation != null && _prevT < _transitionTime)
                        {
                            // update "previous" previous variables
                            _prevPrevT          = _prevT;
                            _prevPrevAnimation  = _prevAnimation;
                            _prevTransitionTime = _transitionTime;
                        }
                                                #endif
                        _prevAnimation = _currAnimation;
                        _prevT         = _currT;
                    }
                    if (_prevAnimation != null)
                    {
                        _prevTimeout = _prevT + transitionTime;
                    }
                }

                _currAnimation = animation;
                _currT         = 0;

                _transitionTime = transitionTime;
            }
        //-----------------
        /// <summary>
        /// Adds an animation state
        /// </summary>
        /// <param name="stateName">State name.</param>
        /// <param name="makeDefault">If set to <c>true</c> forces the state machine into this state.</param>
        public void addState(string stateName, 
							 SSSkeletalAnimation animation,
							 bool makeDefault = false)
        {
            if (makeDefault) {
                foreach (var state in _animationStates.Values) {
                    if (state.isDefault) {
                        var errMsg = "Default state already defined.";
                        System.Console.WriteLine (errMsg);
                        throw new Exception (errMsg);
                    }
                }
            }

            var newState = new AnimationState ();
            newState.isDefault = makeDefault;
            newState.animation = animation;
            _animationStates.Add (stateName, newState);
        }
예제 #6
0
        //-----------------

        /// <summary>
        /// Adds an animation state
        /// </summary>
        /// <param name="stateName">State name.</param>
        /// <param name="makeDefault">If set to <c>true</c> forces the state machine into this state.</param>
        public void addState(string stateName,
                             SSSkeletalAnimation animation,
                             bool makeDefault = false)
        {
            if (makeDefault)
            {
                foreach (var state in _animationStates.Values)
                {
                    if (state.isDefault)
                    {
                        var errMsg = "Default state already defined.";
                        System.Console.WriteLine(errMsg);
                        throw new Exception(errMsg);
                    }
                }
            }

            var newState = new AnimationState();

            newState.isDefault = makeDefault;
            newState.animation = animation;
            _animationStates.Add(stateName, newState);
        }
 public void verifyAnimation(SSSkeletalAnimation animation)
 {
     if (this.numJoints != animation.numJoints) {
         string str = string.Format (
             "Joint number mismatch: {0} in md5mesh, {1} in md5anim",
             this.numJoints, animation.numJoints);
         Console.WriteLine (str);
         throw new Exception (str);
     }
     for (int j = 0; j < numJoints; ++j) {
         SSSkeletalJoint thisJointInfo = this._joints [j].baseInfo;
         SSSkeletalJoint animJointInfo = animation.jointHierarchy [j];
         if (thisJointInfo.name != animJointInfo.name) {
             string str = string.Format (
                 "Joint name mismatch: {0} in md5mesh, {1} in md5anim",
                 thisJointInfo.name, animJointInfo.name);
             Console.WriteLine (str);
             throw new Exception (str);
         }
         if (thisJointInfo.parentIndex != animJointInfo.parentIndex) {
             string str = string.Format (
                 "Hierarchy parent mismatch for joint \"{0}\": {1} in md5mesh, {2} in md5anim",
                 thisJointInfo.name, thisJointInfo.parentIndex, animJointInfo.parentIndex);
             Console.WriteLine (str);
             throw new Exception (str);
         }
     }
 }
            /// <summary>
            /// Update the animation channel based on time elapsed.
            /// </summary>
            /// <param name="timeElapsed">Time elapsed in seconds</param>
            public void update(float timeElapsed)
            {
                #if PREV_PREV_FADE
                if (_prevPrevAnimation != null) {
                _prevPrevT += timeElapsed;
                if (_prevPrevT >= _prevTransitionTime) {
                _prevPrevAnimation = null;
                _prevPrevT = 0f;
                }
                }
                #endif

                if (_prevAnimation != null) {
                    _prevT += timeElapsed;
                    if (_prevT >= _prevTimeout) {
                        _prevAnimation = null;
                        _prevT = 0f;
                    }
                }

                if (_currAnimation != null) {
                    _currT += timeElapsed;
                    if (_currT >= _transitionTime) {
                        _transitionTime = 0;
                    }
                    if (_currT >= _currAnimation.totalDuration) {
                        _currAnimation = null;
                        _currT = 0;
                    }
                }
                else if (_currT < _transitionTime) {
                    // maintain FadeIn ratio for use with interchannel interpolation
                    _currT += timeElapsed;
                }
            }
            public void playAnimation(SSSkeletalAnimation animation, float transitionTime)
            {
                //System.Console.WriteLine ("play: {0}, repeat: {1}, transitionTime {2}, ichf: {3}",
                //	animation != null ? animation.Name : "null", repeat, transitionTime, interChannelFade);

                // update "previous" variables
                if (transitionTime == 0f) {
                    _prevAnimation = null;
                    _prevT = 0f;
                    #if PREV_PREV_FADE
                    _prevPrevAnimation = null;
                    _prevPrevT = 0f;
                    #endif
                } else { // transitionTime != 0f
                    if (_currAnimation != null) {
                        #if PREV_PREV_FADE
                        if (_prevAnimation != null && _prevT < _transitionTime) {
                        // update "previous" previous variables
                        _prevPrevT = _prevT;
                        _prevPrevAnimation = _prevAnimation;
                        _prevTransitionTime = _transitionTime;
                        }
                        #endif
                        _prevAnimation = _currAnimation;
                        _prevT = _currT;
                    }
                    if (_prevAnimation != null) {
                        _prevTimeout = _prevT + transitionTime;
                    }
                }

                _currAnimation = animation;
                _currT = 0;

                _transitionTime = transitionTime;
            }
예제 #10
0
 public void playAnimationLoop(SSSkeletalAnimation anim, float transitionTime = 0f,
                               params string[] topLevelJointNames)
 {
     playAnimationLoop(anim, transitionTime, _hierarchy.jointIndices(topLevelJointNames));
 }