Пример #1
0
        public static GeometryData Read(ContentReader input)
        {
            var device = input.GetGraphicsDevice();

            var name     = input.ReadString();
            var vertices = ReadVertexBuffer(input, device);
            var indices  = ReadIndexBuffer(input, device);
            var bounds   = ReadBoundingSphere(input);

            return(new GeometryData(name, vertices, indices, bounds));
        }
Пример #2
0
        protected override Effect Read(ContentReader input, Effect _)
        {
            var sourceFile = input.ReadString();
            var length     = input.ReadInt32();
            var effectCode = input.ReadBytes(length);

            var effect = new Effect(input.GetGraphicsDevice(), effectCode);

            effect.Tag = sourceFile;

            return(effect);
        }
Пример #3
0
        internal TiledMapLayerModel(ContentReader reader, bool isDynamicData = false)
        {
            var graphicsDevice = reader.GetGraphicsDevice();

            LayerName = reader.ReadString();
            var textureAssetName = reader.GetRelativeAssetName(reader.ReadString());

            Texture = reader.ContentManager.Load <Texture2D>(textureAssetName);

            var vertexCount = reader.ReadInt32();
            var vertices    = new VertexPositionTexture[vertexCount];

            for (var i = 0; i < vertexCount; i++)
            {
                var x = reader.ReadSingle();
                var y = reader.ReadSingle();
                var textureCoordinateX = reader.ReadSingle();
                var textureCoordinateY = reader.ReadSingle();
                vertices[i] = new VertexPositionTexture(new Vector3(x, y, 0), new Vector2(textureCoordinateX, textureCoordinateY));
            }

            if (isDynamicData)
            {
                Vertices = vertices;
            }

            VertexBuffer = isDynamicData
                ? new DynamicVertexBuffer(graphicsDevice, VertexPositionTexture.VertexDeclaration, vertexCount, BufferUsage.WriteOnly)
                : new VertexBuffer(graphicsDevice, VertexPositionTexture.VertexDeclaration, vertexCount, BufferUsage.WriteOnly);
            VertexBuffer.SetData(vertices, 0, vertexCount);

            var indexCount = reader.ReadInt32();
            var indices    = new ushort[indexCount];

            for (var i = 0; i < indexCount; i++)
            {
                indices[i] = reader.ReadUInt16();
            }

            IndexBuffer = isDynamicData
                ? new DynamicIndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indexCount, BufferUsage.WriteOnly)
                : new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indexCount, BufferUsage.WriteOnly);
            IndexBuffer.SetData(indices, 0, indexCount);

            TrianglesCount = indexCount / 3;
        }