Example #1
0
            /// <summary>
            /// Vztvoreni skinned meshe
            /// </summary>
            /// <param name="mesh">Container s meshem</param>
            /// <param name="adjacency">adjacency</param>
            static void GenerateSkinnedMesh(AnimationMeshContainer mesh, GraphicsStream adjacency)
            {
                if (mesh.SkinInformation == null)
                {
                    throw new ArgumentException();  // There is nothing to generate
                }
                MeshFlags flags = MeshFlags.OptimizeVertexCache;

                flags |= MeshFlags.Managed;


                int numMaxFaceInfl;

                using (IndexBuffer ib = mesh.MeshData.Mesh.IndexBuffer)
                {
                    numMaxFaceInfl = mesh.SkinInformation.GetMaxFaceInfluences(ib,
                                                                               mesh.MeshData.Mesh.NumberFaces);
                }
                // 12 entry palette guarantees that any triangle (4 independent
                // influences per vertex of a tri) can be handled
                numMaxFaceInfl = (int)Math.Min(numMaxFaceInfl, 12);


                mesh.NumberPaletteEntries = 4;

                int influences = 0;

                BoneCombination[] bones = null;

                // Use ConvertToBlendedMesh to generate a drawable mesh
                MeshData data = mesh.MeshData;

                data.Mesh = mesh.SkinInformation.ConvertToIndexedBlendedMesh(data.Mesh, flags, mesh.GetAdjacencyStream(), mesh.NumberPaletteEntries, out influences, out bones);



                int use32Bit = (int)(data.Mesh.Options.Value & MeshFlags.Use32Bit);


                mesh.NumberInfluences = influences;
                mesh.SetBones(bones);

                // Get the number of attributes
                mesh.NumberAttributes = bones.Length;

                mesh.MeshData = data;
            }