private void FillIndicesWeights(ref VertexBoneIndicesWeights indicesWeights, int index, List <VertexArealBoneIndexWeight> tmpStorage)
        {
            if (index >= tmpStorage.Count)
            {
                return;
            }

            indicesWeights.Indices[index] = tmpStorage[index].Index;
            indicesWeights.Weights[index] = tmpStorage[index].Weight;
        }
        private void NormalizeBoneWeights(ref VertexBoneIndicesWeights indicesWeights)
        {
            float sum = 0;

            for (int it = 0; it < 4; it++)
            {
                sum += indicesWeights.Weights[it];
            }

            for (int it = 0; it < 4; it++)
            {
                indicesWeights.Weights[it] /= sum;
            }
        }
        public VertexBoneIndicesWeights?GetAffectingBoneIndicesWeights(ref List <VertexArealBoneIndexWeight> tmpStorage)
        {
            if (!Triangle.BoneWeights.HasValue)
            {
                return(null);
            }

            if (tmpStorage == null)
            {
                tmpStorage = new List <VertexArealBoneIndexWeight>(4);
            }

            tmpStorage.Clear();

            MyTriangle_BoneIndicesWeigths boneWeights = Triangle.BoneWeights.Value;

            float u, v, w;

            Vector3.Barycentric(IntersectionPointInObjectSpace, Triangle.InputTriangle.Vertex0,
                                Triangle.InputTriangle.Vertex1, Triangle.InputTriangle.Vertex2, out u, out v, out w);

            FillIndicesWeightsStorage(tmpStorage, ref boneWeights.Vertex0, u);
            FillIndicesWeightsStorage(tmpStorage, ref boneWeights.Vertex1, v);
            FillIndicesWeightsStorage(tmpStorage, ref boneWeights.Vertex2, w);

            tmpStorage.Sort(Comparison);

            VertexBoneIndicesWeights indicesWeights = new VertexBoneIndicesWeights();

            FillIndicesWeights(ref indicesWeights, 0, tmpStorage);
            FillIndicesWeights(ref indicesWeights, 1, tmpStorage);
            FillIndicesWeights(ref indicesWeights, 2, tmpStorage);
            FillIndicesWeights(ref indicesWeights, 3, tmpStorage);

            NormalizeBoneWeights(ref indicesWeights);
            return(indicesWeights);
        }
        private void NormalizeBoneWeights(ref VertexBoneIndicesWeights indicesWeights)
        {
            float sum = 0;
            for (int it = 0; it < 4; it++)
                sum += indicesWeights.Weights[it];

            for (int it = 0; it < 4; it++)
                indicesWeights.Weights[it] /= sum;
        }
 private void FillIndicesWeights(ref VertexBoneIndicesWeights indicesWeights, int index, List<VertexArealBoneIndexWeight> tmpStorage)
 {
     if (index >= tmpStorage.Count)
         return;
     
     indicesWeights.Indices[index] = tmpStorage[index].Index;
     indicesWeights.Weights[index] = tmpStorage[index].Weight;
 }
        public VertexBoneIndicesWeights? GetAffectingBoneIndicesWeights(ref List<VertexArealBoneIndexWeight> tmpStorage)
        {
            if (!Triangle.BoneWeights.HasValue)
                return null;

            if (tmpStorage == null)
                tmpStorage = new List<VertexArealBoneIndexWeight>(4);

            tmpStorage.Clear();

            MyTriangle_BoneIndicesWeigths boneWeights = Triangle.BoneWeights.Value;

            float u, v, w;
            Vector3.Barycentric(IntersectionPointInObjectSpace, Triangle.InputTriangle.Vertex0,
                Triangle.InputTriangle.Vertex1, Triangle.InputTriangle.Vertex2, out u, out v, out w);

            FillIndicesWeightsStorage(tmpStorage, ref boneWeights.Vertex0, u);
            FillIndicesWeightsStorage(tmpStorage, ref boneWeights.Vertex1, v);
            FillIndicesWeightsStorage(tmpStorage, ref boneWeights.Vertex2, w);

            tmpStorage.Sort(Comparison);

            VertexBoneIndicesWeights indicesWeights = new VertexBoneIndicesWeights();
            FillIndicesWeights(ref indicesWeights, 0, tmpStorage);
            FillIndicesWeights(ref indicesWeights, 1, tmpStorage);
            FillIndicesWeights(ref indicesWeights, 2, tmpStorage);
            FillIndicesWeights(ref indicesWeights, 3, tmpStorage);

            NormalizeBoneWeights(ref indicesWeights);
            return indicesWeights;
        }