/// <summary> /// Apply weighted transforms to the vertext data /// </summary> /// <param name="vertex">Vertex data</param> /// <param name="boneTransforms">Bone transforms list</param> /// <returns>Returns the weighted position</returns> public static Vector3 ApplyWeight(IVertexData vertex, IEnumerable <Matrix> boneTransforms) { Vector3 position = vertex.HasChannel(VertexDataChannels.Position) ? vertex.GetChannelValue <Vector3>(VertexDataChannels.Position) : Vector3.Zero; if (!IsSkinned(vertex.VertexType)) { return(position); } byte[] boneIndices = vertex.HasChannel(VertexDataChannels.BoneIndices) ? vertex.GetChannelValue <byte[]>(VertexDataChannels.BoneIndices) : null; float[] boneWeights = vertex.HasChannel(VertexDataChannels.Weights) ? vertex.GetChannelValue <float[]>(VertexDataChannels.Weights) : null; Matrix[] transforms = boneTransforms.ToArray(); Vector3 t = Vector3.Zero; for (int w = 0; w < boneIndices.Length; w++) { float weight = boneWeights[w]; if (weight > 0) { byte index = boneIndices[w]; var boneTransform = transforms != null ? transforms[index] : Matrix.Identity; Vector3.TransformCoordinate(ref position, ref boneTransform, out Vector3 p); t += (p * weight); } } return(t); }