Example #1
0
        private static List <BMFVertex> ConvertGeometryVertices(VertexCompressor vertexCompressor, VertexBufferDefinition vertexBuffer, CacheVersion version, int vertexCount, int rigidNodeIndex)
        {
            var vertices = new List <BMFVertex>();

            using (var vertexDataStream = new MemoryStream(vertexBuffer.Data.Data))
            {
                var vertexStream = VertexStreamFactory.Create(version, vertexDataStream);

                for (int j = 0; j < vertexCount; j++)
                {
                    var          vertex = new BMFVertex();
                    RealVector2d texcoordTemp;

                    switch (vertexBuffer.Format)
                    {
                    case VertexBufferFormat.Rigid:
                        var rigid = vertexStream.ReadRigidVertex();

                        vertex.Position = vertexCompressor.DecompressPosition(rigid.Position).IJK;
                        texcoordTemp    = vertexCompressor.DecompressUv(rigid.Texcoord);
                        vertex.Texcoord = new RealVector3d(texcoordTemp.I, texcoordTemp.J, 0.0f);
                        vertex.Normal   = rigid.Normal;
                        vertex.Tangent  = rigid.Tangent.IJK;
                        vertex.Binormal = rigid.Binormal;

                        vertex.Weights[0] = new BMFVertexWeight {
                            NodeIndex = rigidNodeIndex, Weight = 1.0f
                        };

                        for (int i = 1; i < 4; i++)
                        {
                            vertex.Weights[i] = new BMFVertexWeight();
                        }

                        break;

                    case VertexBufferFormat.Skinned:
                        var skinned = vertexStream.ReadSkinnedVertex();

                        vertex.Position = vertexCompressor.DecompressPosition(skinned.Position).IJK;
                        texcoordTemp    = vertexCompressor.DecompressUv(skinned.Texcoord);
                        vertex.Texcoord = new RealVector3d(texcoordTemp.I, texcoordTemp.J, 0.0f);
                        vertex.Normal   = skinned.Normal;
                        vertex.Tangent  = skinned.Tangent.IJK;
                        vertex.Binormal = skinned.Binormal;

                        for (int i = 0; i < 4; i++)
                        {
                            vertex.Weights[i] = new BMFVertexWeight {
                                NodeIndex = skinned.BlendIndices[i], Weight = skinned.BlendWeights[i]
                            };
                        }
                        break;

                    default:
                        throw new InvalidOperationException("Unsupported vertex buffer type: " + vertexBuffer.Format);
                    }
                    vertices.Add(vertex);
                }
            }
            return(vertices);
        }