Esempio n. 1
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();
            this.updateCacheReset.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.ikConstraints;
            var transformConstraints = this.transformConstraints;
            var pathConstraints = this.pathConstraints;
            int ikCount = IkConstraints.Count, transformCount = transformConstraints.Count, pathCount = pathConstraints.Count;
            int constraintCount = ikCount + transformCount + pathCount;

            //outer:
            for (int i = 0; i < constraintCount; i++)
            {
                for (int ii = 0; ii < ikCount; ii++)
                {
                    IkConstraint constraint = ikConstraints.Items[ii];
                    if (constraint.data.order == i)
                    {
                        SortIkConstraint(constraint);
                        goto outer;                         //continue outer;
                    }
                }
                for (int ii = 0; ii < transformCount; ii++)
                {
                    TransformConstraint constraint = transformConstraints.Items[ii];
                    if (constraint.data.order == i)
                    {
                        SortTransformConstraint(constraint);
                        goto outer;                         //continue outer;
                    }
                }
                for (int ii = 0; ii < pathCount; ii++)
                {
                    PathConstraint constraint = pathConstraints.Items[ii];
                    if (constraint.data.order == i)
                    {
                        SortPathConstraint(constraint);
                        goto outer;                         //continue outer;
                    }
                }
                outer : {}
            }

            for (int i = 0, n = bones.Count; i < n; i++)
            {
                SortBone(bones.Items[i]);
            }
        }
Esempio n. 2
0
        private void SortPathConstraint(PathConstraint constraint)
        {
            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);
            }

            Attachment attachment = slot.attachment;

            if (attachment is PathAttachment)
            {
                SortPathConstraintAttachment(attachment, slotBone);
            }

            var 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;
            }
        }
Esempio n. 3
0
        /// <returns>May be null.</returns>
        public PathConstraint FindPathConstraint(String constraintName)
        {
            if (constraintName == null)
            {
                throw new ArgumentNullException("constraintName", "constraintName cannot be null.");
            }
            ExposedList <PathConstraint> pathConstraints = this.pathConstraints;

            for (int i = 0, n = pathConstraints.Count; i < n; i++)
            {
                PathConstraint constraint = pathConstraints.Items[i];
                if (constraint.data.name.Equals(constraintName))
                {
                    return(constraint);
                }
            }
            return(null);
        }
Esempio n. 4
0
        /// <summary>Sets the bones and constraints to their setup pose values.</summary>
        public void SetBonesToSetupPose()
        {
            var bonesItems = this.bones.Items;

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

            var ikConstraintsItems = this.ikConstraints.Items;

            for (int i = 0, n = ikConstraints.Count; i < n; i++)
            {
                IkConstraint constraint = ikConstraintsItems[i];
                constraint.bendDirection = constraint.data.bendDirection;
                constraint.mix           = constraint.data.mix;
            }

            var transformConstraintsItems = this.transformConstraints.Items;

            for (int i = 0, n = transformConstraints.Count; i < n; i++)
            {
                TransformConstraint     constraint = transformConstraintsItems[i];
                TransformConstraintData data       = constraint.data;
                constraint.rotateMix    = data.rotateMix;
                constraint.translateMix = data.translateMix;
                constraint.scaleMix     = data.scaleMix;
                constraint.shearMix     = data.shearMix;
            }

            var pathConstraintItems = this.pathConstraints.Items;

            for (int i = 0, n = pathConstraints.Count; i < n; i++)
            {
                PathConstraint     constraint = pathConstraintItems[i];
                PathConstraintData data       = constraint.data;
                constraint.position     = data.position;
                constraint.spacing      = data.spacing;
                constraint.rotateMix    = data.rotateMix;
                constraint.translateMix = data.translateMix;
            }
        }