예제 #1
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.mix           = constraint.data.mix;
                constraint.softness      = constraint.data.softness;
                constraint.bendDirection = constraint.data.bendDirection;
                constraint.compress      = constraint.data.compress;
                constraint.stretch       = constraint.data.stretch;
            }

            var transformConstraintsItems = this.transformConstraints.Items;

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

            var pathConstraintItems = this.pathConstraints.Items;

            for (int i = 0, n = pathConstraints.Count; i < n; i++)
            {
                PathConstraint     constraint     = pathConstraintItems[i];
                PathConstraintData constraintData = constraint.data;
                constraint.position     = constraintData.position;
                constraint.spacing      = constraintData.spacing;
                constraint.rotateMix    = constraintData.rotateMix;
                constraint.translateMix = constraintData.translateMix;
            }
        }
예제 #2
0
        /// <returns>May be null.</returns>
        public IkConstraint FindIkConstraint(string constraintName)
        {
            if (constraintName == null)
            {
                throw new ArgumentNullException("constraintName", "constraintName cannot be null.");
            }
            ExposedList <IkConstraint> ikConstraints = this.ikConstraints;

            for (int i = 0, n = ikConstraints.Count; i < n; i++)
            {
                IkConstraint ikConstraint = ikConstraints.Items[i];
                if (ikConstraint.data.name == constraintName)
                {
                    return(ikConstraint);
                }
            }
            return(null);
        }
예제 #3
0
 /// <summary>Copy constructor.</summary>
 public IkConstraint(IkConstraint constraint, Skeleton skeleton)
 {
     if (constraint == null)
     {
         throw new ArgumentNullException("constraint cannot be null.");
     }
     if (skeleton == null)
     {
         throw new ArgumentNullException("skeleton cannot be null.");
     }
     data  = constraint.data;
     bones = new ExposedList <Bone>(constraint.Bones.Count);
     foreach (Bone bone in constraint.Bones)
     {
         bones.Add(skeleton.Bones.Items[bone.data.index]);
     }
     target        = skeleton.Bones.Items[constraint.target.data.index];
     mix           = constraint.mix;
     softness      = constraint.softness;
     bendDirection = constraint.bendDirection;
     compress      = constraint.compress;
     stretch       = constraint.stretch;
 }
예제 #4
0
        /// <summary>Caches information about bones and constraints. Must be called if the <see cref="Skin"/> is modified or if bones, constraints, or
        /// constraints, or weighted path attachments are added or removed.</summary>
        public void UpdateCache()
        {
            var updateCache = this.updateCache;

            updateCache.Clear();
            this.updateCacheReset.Clear();

            int boneCount = this.bones.Items.Length;
            var bones     = this.bones;

            for (int i = 0; i < boneCount; i++)
            {
                Bone bone = bones.Items[i];
                bone.sorted = bone.data.skinRequired;
                bone.active = !bone.sorted;
            }
            if (skin != null)
            {
                Object[] skinBones = skin.bones.Items;
                for (int i = 0, n = skin.bones.Count; i < n; i++)
                {
                    Bone bone = (Bone)bones.Items[((BoneData)skinBones[i]).index];
                    do
                    {
                        bone.sorted = false;
                        bone.active = true;
                        bone        = bone.parent;
                    } while (bone != null);
                }
            }

            int ikCount = this.ikConstraints.Count, transformCount = this.transformConstraints.Count, pathCount = this.pathConstraints.Count;
            var ikConstraints        = this.ikConstraints;
            var transformConstraints = this.transformConstraints;
            var pathConstraints      = this.pathConstraints;
            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 continue_outer;                         //continue outer;
                    }
                }
                for (int ii = 0; ii < transformCount; ii++)
                {
                    TransformConstraint constraint = transformConstraints.Items[ii];
                    if (constraint.data.order == i)
                    {
                        SortTransformConstraint(constraint);
                        goto continue_outer;                         //continue outer;
                    }
                }
                for (int ii = 0; ii < pathCount; ii++)
                {
                    PathConstraint constraint = pathConstraints.Items[ii];
                    if (constraint.data.order == i)
                    {
                        SortPathConstraint(constraint);
                        goto continue_outer;                         //continue outer;
                    }
                }
                continue_outer : {}
            }

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