Exemplo n.º 1
0
 public void ClearTracks()
 {
     for (int i = 0, n = tracks.Count; i < n; i++)
     {
         ClearTrack(i);
     }
     tracks.Clear();
 }
Exemplo n.º 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, polygon.Vertices);
            }

            if (updateAabb)
            {
                aabbCompute();
            }
        }
Exemplo n.º 3
0
        public void SetSlotsToSetupPose()
        {
            var slots      = this.slots;
            var slotsItems = slots.Items;

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

            for (int i = 0, n = slots.Count; i < n; i++)
            {
                slotsItems[i].SetToSetupPose();
            }
        }
Exemplo n.º 4
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
            {
                var drawOrderItems = drawOrder.Items;
                var slotsItems     = slots.Items;
                for (int i = 0, n = drawOrderToSetupIndex.Length; i < n; i++)
                {
                    drawOrderItems[i] = slotsItems[drawOrderToSetupIndex[i]];
                }
            }
        }
Exemplo n.º 5
0
        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;
            }
        }
Exemplo n.º 6
0
        /// <summary>Caches information about bones and constraints. Must be called if bones, constraints or weighted path attachments are added
        /// or removed.</summary>
        public void UpdateCache()
        {
            ExposedList <IUpdatable> updateCache = this.updateCache;

            updateCache.Clear();

            ExposedList <Bone> bones = this.bones;

            for (int i = 0, n = bones.Count; i < n; i++)
            {
                bones.Items[i].sorted = false;
            }

            ExposedList <IkConstraint> ikConstraints = this.ikConstraintsSorted;

            ikConstraints.Clear();
            ikConstraints.AddRange(this.ikConstraints);
            int ikCount = ikConstraints.Count;

            for (int i = 0, level, n = ikCount; i < n; i++)
            {
                IkConstraint ik   = ikConstraints.Items[i];
                Bone         bone = ik.bones.Items[0].parent;
                for (level = 0; bone != null; level++)
                {
                    bone = bone.parent;
                }
                ik.level = level;
            }
            for (int i = 1, ii; i < ikCount; i++)
            {
                IkConstraint ik    = ikConstraints.Items[i];
                int          level = ik.level;
                for (ii = i - 1; ii >= 0; ii--)
                {
                    IkConstraint other = ikConstraints.Items[ii];
                    if (other.level < level)
                    {
                        break;
                    }
                    ikConstraints.Items[ii + 1] = other;
                }
                ikConstraints.Items[ii + 1] = ik;
            }
            for (int i = 0, n = ikConstraints.Count; i < n; i++)
            {
                IkConstraint constraint = ikConstraints.Items[i];
                Bone         target     = constraint.target;
                SortBone(target);

                ExposedList <Bone> constrained = constraint.bones;
                Bone parent = constrained.Items[0];
                SortBone(parent);

                updateCache.Add(constraint);

                SortReset(parent.children);
                constrained.Items[constrained.Count - 1].sorted = true;
            }

            ExposedList <PathConstraint> pathConstraints = this.pathConstraints;

            for (int i = 0, n = pathConstraints.Count; i < n; i++)
            {
                PathConstraint constraint = pathConstraints.Items[i];

                Slot slot      = constraint.target;
                int  slotIndex = slot.data.index;
                Bone slotBone  = slot.bone;
                if (skin != null)
                {
                    SortPathConstraintAttachment(skin, slotIndex, slotBone);
                }
                if (data.defaultSkin != null && data.defaultSkin != skin)
                {
                    SortPathConstraintAttachment(data.defaultSkin, slotIndex, slotBone);
                }
                for (int ii = 0, nn = data.skins.Count; ii < nn; ii++)
                {
                    SortPathConstraintAttachment(data.skins.Items[ii], slotIndex, slotBone);
                }

                PathAttachment attachment = slot.Attachment as PathAttachment;
                if (attachment != null)
                {
                    SortPathConstraintAttachment(attachment, slotBone);
                }

                ExposedList <Bone> constrained = constraint.bones;
                int boneCount = constrained.Count;
                for (int ii = 0; ii < boneCount; ii++)
                {
                    SortBone(constrained.Items[ii]);
                }

                updateCache.Add(constraint);

                for (int ii = 0; ii < boneCount; ii++)
                {
                    SortReset(constrained.Items[ii].children);
                }
                for (int ii = 0; ii < boneCount; ii++)
                {
                    constrained.Items[ii].sorted = true;
                }
            }

            ExposedList <TransformConstraint> transformConstraints = this.transformConstraints;

            for (int i = 0, n = transformConstraints.Count; i < n; i++)
            {
                TransformConstraint constraint = transformConstraints.Items[i];

                SortBone(constraint.target);

                ExposedList <Bone> constrained = constraint.bones;
                int boneCount = constrained.Count;
                for (int ii = 0; ii < boneCount; ii++)
                {
                    SortBone(constrained.Items[ii]);
                }

                updateCache.Add(constraint);

                for (int ii = 0; ii < boneCount; ii++)
                {
                    SortReset(constrained.Items[ii].children);
                }
                for (int ii = 0; ii < boneCount; ii++)
                {
                    constrained.Items[ii].sorted = true;
                }
            }

            for (int i = 0, n = bones.Count; i < n; i++)
            {
                SortBone(bones.Items[i]);
            }
        }