Ejemplo n.º 1
0
        private void GetSkin()
        {
            Int32 countOfVertices = 0;

            foreach (Mesh mesh in m_scene.Meshes)
            {
                countOfVertices += mesh.VertexCount;
            }

            List <UInt32> countOfIndicesPerMesh = new List <UInt32>();

            float[,] local_vert  = new float[countOfVertices, 3],
            local_t_vert         = bHasTextureCoordinates ? new float[countOfVertices, 2] : null,
            local_n_vert         = bHasNormals ? new float[countOfVertices, 3] : null,
            local_tangent_vert   = bHasTangentVertices ? new float[countOfVertices, 3] : null,
            local_bitangent_vert = bHasTangentVertices ? new float[countOfVertices, 3] : null;

            for (Int32 i = 0; i < m_meshes.Length; i++)
            {
                Mesh mesh = m_meshes[i];
                countOfIndicesPerMesh.Add((UInt32)Indices.Count);
                CollectIndices(Indices, mesh, (UInt32)Indices.Count);
                TryToCollectSkinInfo((Int32)countOfIndicesPerMesh[i], ref local_vert, ref local_n_vert, ref local_t_vert, ref local_tangent_vert, ref local_bitangent_vert, mesh);
            }

            Verts          = local_vert;
            N_Verts        = local_n_vert;
            T_Verts        = local_t_vert;
            Tangent_Verts  = local_tangent_vert;
            Bitanget_Verts = local_bitangent_vert;

            // collect blend weights and blend ids
            if (bHasAnimation)
            {
                List <Vertex> blendData = new List <Vertex>();
                for (Int32 j = 0; j < countOfVertices; j++)
                {
                    for (Int32 i = 0; i < m_meshes.Length; i++)
                    {
                        Mesh mesh = m_meshes[i];
                        CollectBlendables(j, blendData, mesh, countOfIndicesPerMesh);
                    }
                }

                BlendWeights = new float[blendData.Count, m_strategy.GetBonesInfluenceCount()];
                BlendIndices = new int[blendData.Count, m_strategy.GetBonesInfluenceCount()];

                for (Int32 i = 0; i < blendData.Count; i++)
                {
                    Vertex blendVertex = blendData[i];
                    m_strategy.CollectWeightsAndIndices(blendVertex, i, BlendWeights, BlendIndices);
                }
            }
        }