Ejemplo n.º 1
0
        public Matrix32 CalcWeightedRelativeTransform(SkinningWeights weights)
        {
            Matrix32 skinningMatrix = new Matrix32();

            skinningMatrix.T = ApplySkinningToVector(Vector2.Zero, weights);
            skinningMatrix.U = ApplySkinningToVector(Vector2.Right, weights) - skinningMatrix.T;
            skinningMatrix.V = ApplySkinningToVector(Vector2.Down, weights) - skinningMatrix.T;

            return(skinningMatrix);
        }
Ejemplo n.º 2
0
        public static SkinningWeights CalcSkinningWeight(SkinningWeights oldSkinningWeights, Vector2 position, List <Bone> bones)
        {
            var skinningWeights = new SkinningWeights();
            var i             = 0;
            var overallWeight = 0f;

            while (oldSkinningWeights[i].Index != 0)
            {
                skinningWeights[i] = oldSkinningWeights[i];
                overallWeight     += skinningWeights[i].Weight;
                i++;
            }
            var j = 0;

            while (j < bones.Count && i < 4)
            {
                var weight = bones[j].CalcWeightForPoint(position);
                if (Mathf.Abs(weight) > Mathf.ZeroTolerance)
                {
                    skinningWeights[i] = new BoneWeight {
                        Weight = weight,
                        Index  = bones[j].Index
                    };
                    overallWeight += skinningWeights[i].Weight;
                    i++;
                }
                j++;
            }
            if (overallWeight != 0)
            {
                for (i = 0; i < 4; i++)
                {
                    var bw = skinningWeights[i];
                    bw.Weight         /= overallWeight;
                    skinningWeights[i] = bw;
                }
            }
            return(skinningWeights);
        }
Ejemplo n.º 3
0
        public Vector2 ApplySkinningToVector(Vector2 vector, SkinningWeights weights)
        {
            Vector2 result        = Vector2.Zero;
            float   overallWeight = 0;

            ApplyBone(weights.Bone0, vector, ref result, ref overallWeight);
            ApplyBone(weights.Bone1, vector, ref result, ref overallWeight);
            ApplyBone(weights.Bone2, vector, ref result, ref overallWeight);
            ApplyBone(weights.Bone3, vector, ref result, ref overallWeight);
            if (overallWeight < 0)
            {
                result = vector;
            }
            else if (overallWeight >= 0 && overallWeight < 1)
            {
                result += (1 - overallWeight) * vector;
            }
            else
            {
                result.X /= overallWeight;
                result.Y /= overallWeight;
            }
            return(result);
        }