public void ClearTracks()
 {
     for (int i = 0, n = tracks.Count; i < n; i++)
     {
         ClearTrack(i);
     }
     tracks.Clear();
 }
示例#2
0
        public void Update(Skeleton skeleton, bool updateAabb)
        {
            ExposedList <BoundingBoxAttachment> boundingBoxes = BoundingBoxes;
            ExposedList <Polygon> polygons = Polygons;
            ExposedList <Slot>    slots    = skeleton.slots;
            int slotCount = slots.Count;

            boundingBoxes.Clear();
            for (int i = 0, n = polygons.Count; i < n; i++)
            {
                polygonPool.Add(polygons.Items[i]);
            }
            polygons.Clear();

            for (int i = 0; i < slotCount; i++)
            {
                Slot slot = slots.Items[i];
                BoundingBoxAttachment boundingBox = slot.attachment as BoundingBoxAttachment;
                if (boundingBox == null)
                {
                    continue;
                }
                boundingBoxes.Add(boundingBox);

                Polygon polygon   = null;
                int     poolCount = polygonPool.Count;
                if (poolCount > 0)
                {
                    polygon = polygonPool.Items[poolCount - 1];
                    polygonPool.RemoveAt(poolCount - 1);
                }
                else
                {
                    polygon = new Polygon();
                }
                polygons.Add(polygon);

                int count = boundingBox.Vertices.Length;
                polygon.Count = count;
                if (polygon.Vertices.Length < count)
                {
                    polygon.Vertices = new float[count];
                }
                boundingBox.ComputeWorldVertices(slot.bone, polygon.Vertices);
            }

            if (updateAabb)
            {
                aabbCompute();
            }
        }
示例#3
0
        public void SetSlotsToSetupPose()
        {
            ExposedList <Slot> slots = this.slots;

            drawOrder.Clear();
            for (int i = 0, n = slots.Count; i < n; i++)
            {
                drawOrder.Add(slots.Items[i]);
            }

            for (int i = 0, n = slots.Count; i < n; i++)
            {
                slots.Items[i].SetToSetupPose(i);
            }
        }
示例#4
0
        /// <summary>Caches information about bones and constraints. Must be called if bones or constraints are added
        /// or removed.</summary>
        public void UpdateCache()
        {
            ExposedList <Bone>                bones                = this.bones;
            ExposedList <IUpdatable>          updateCache          = this.updateCache;
            ExposedList <IkConstraint>        ikConstraints        = this.ikConstraints;
            ExposedList <TransformConstraint> transformConstraints = this.transformConstraints;
            int ikConstraintsCount        = ikConstraints.Count;
            int transformConstraintsCount = transformConstraints.Count;

            updateCache.Clear();
            for (int i = 0, n = bones.Count; i < n; i++)
            {
                Bone bone = bones.Items[i];
                updateCache.Add(bone);
                for (int ii = 0; ii < ikConstraintsCount; ii++)
                {
                    IkConstraint ikConstraint = ikConstraints.Items[ii];
                    if (bone == ikConstraint.bones.Items[ikConstraint.bones.Count - 1])
                    {
                        updateCache.Add(ikConstraint);
                        break;
                    }
                }
            }

            for (int i = 0; i < transformConstraintsCount; i++)
            {
                TransformConstraint transformConstraint = transformConstraints.Items[i];
                for (int ii = updateCache.Count - 1; i >= 0; ii--)
                {
                    if (updateCache.Items[ii] == transformConstraint.bone)
                    {
                        updateCache.Insert(ii + 1, transformConstraint);
                        break;
                    }
                }
            }
        }
示例#5
0
        public void Apply(Skeleton skeleton, float lastTime, float time, ExposedList <Event> firedEvents, float alpha)
        {
            float[] frames = this.frames;
            if (time < frames[0])
            {
                return;                               // Time is before first frame.
            }
            int frame;

            if (time >= frames[frames.Length - 1])             // Time is after last frame.
            {
                frame = frames.Length - 1;
            }
            else
            {
                frame = Animation.binarySearch(frames, time) - 1;
            }

            ExposedList <Slot> drawOrder = skeleton.drawOrder;
            ExposedList <Slot> slots     = skeleton.slots;

            int[] drawOrderToSetupIndex = drawOrders[frame];
            if (drawOrderToSetupIndex == null)
            {
                drawOrder.Clear();
                for (int i = 0, n = slots.Count; i < n; i++)
                {
                    drawOrder.Add(slots.Items[i]);
                }
            }
            else
            {
                for (int i = 0, n = drawOrderToSetupIndex.Length; i < n; i++)
                {
                    drawOrder.Items[i] = slots.Items[drawOrderToSetupIndex[i]];
                }
            }
        }
        public void Apply(Skeleton skeleton)
        {
            ExposedList <Event> events = this.events;

            for (int i = 0; i < tracks.Count; i++)
            {
                TrackEntry current = tracks.Items[i];
                if (current == null)
                {
                    continue;
                }

                events.Clear();

                float time = current.time;
                bool  loop = current.loop;
                if (!loop && time > current.endTime)
                {
                    time = current.endTime;
                }

                TrackEntry previous = current.previous;
                if (previous == null)
                {
                    if (current.mix == 1)
                    {
                        current.animation.Apply(skeleton, current.lastTime, time, loop, events);
                    }
                    else
                    {
                        current.animation.Mix(skeleton, current.lastTime, time, loop, events, current.mix);
                    }
                }
                else
                {
                    float previousTime = previous.time;
                    if (!previous.loop && previousTime > previous.endTime)
                    {
                        previousTime = previous.endTime;
                    }
                    previous.animation.Apply(skeleton, previous.lastTime, previousTime, previous.loop, null);
                    // Remove the line above, and uncomment the line below, to allow previous animations to fire events during mixing.
                    //previous.animation.Apply(skeleton, previous.lastTime, previousTime, previous.loop, events);
                    previous.lastTime = previousTime;

                    float alpha = current.mixTime / current.mixDuration * current.mix;
                    if (alpha >= 1)
                    {
                        alpha            = 1;
                        current.previous = null;
                    }
                    current.animation.Mix(skeleton, current.lastTime, time, loop, events, alpha);
                }

                for (int ii = 0, nn = events.Count; ii < nn; ii++)
                {
                    Event e = events.Items[ii];
                    current.OnEvent(this, i, e);
                    if (Event != null)
                    {
                        Event(this, i, e);
                    }
                }

                current.lastTime = current.time;
            }
        }