Example #1
0
        public void Resolve(BitmapChunk bitmapChunk)
        {
            if (_vertexBuffer != null)
            {
                return;                 //already resolved
            }
            int vertCount = 0;

            List <VertexPositionTexture> allVerts = new List <VertexPositionTexture>();

            foreach (Polygon poly in _polys)
            {
                if (poly.TextureName != null)
                {
                    poly.ResolveTexture(bitmapChunk.FindByName(poly.TextureName));
                }

                poly.VertexBufferIndex = vertCount;
                vertCount += poly.VertexCount;
                allVerts.AddRange(poly.GetVertices());
            }

            _vertexBuffer = new VertexBuffer(Engine.Instance.Device, typeof(VertexPositionTexture), vertCount, BufferUsage.WriteOnly);
            _vertexBuffer.SetData <VertexPositionTexture>(allVerts.ToArray());
        }
Example #2
0
        static Color BrakeOnColor  = new Color(158, 110, 6);       //color of brake-off light color...

        public CarMesh(MeshChunk meshChunk, BitmapChunk bmpChunk, Color brakeColor)
            : base(meshChunk, bmpChunk)
        {
            foreach (var poly in _polys)
            {
                switch (poly.Label)
                {
                case "rt_rear":
                    _rightRearWheel = poly;
                    break;

                case "lt_rear":
                    _leftRearWheel = poly;
                    break;

                case "rt_frnt":
                    _rightFrontWheel = poly;
                    break;

                case "lt_frnt":
                    _leftFrontWheel = poly;
                    break;

                case "bkll":
                    _leftBrakeLight = poly;
                    break;

                case "bklr":
                    _rightBrakeLight = poly;
                    break;
                }
            }
            var tyreEntry = bmpChunk.FindByName("tyr1");

            if (tyreEntry != null)
            {
                _wheelTexture = tyreEntry.Texture;
            }

            // This seems like it should be done in a shader but I couldn't get it to work well enough
            // (dealing with original paletted colors doesn't work so well in a texture stretched over a polygon)

            var rsidPoly = _polys.FirstOrDefault(a => a.TextureName == "rsid");

            if (rsidPoly != null)
            {
                // Generate a new texture for brake lights on.
                Color[] pixels = new Color[rsidPoly.Texture.Width * rsidPoly.Texture.Height];
                rsidPoly.Texture.GetData <Color>(pixels);
                for (int i = 0; i < pixels.Length; i++)
                {
                    if (pixels[i] == brakeColor)
                    {
                        pixels[i] = BrakeOnColor;
                    }
                }

                _brakeOnTexture = new Texture2D(Engine.Instance.Device, rsidPoly.Texture.Width, rsidPoly.Texture.Height);
                _brakeOnTexture.SetData <Color>(pixels);

                // Generate a new texture for brake lights off.
                for (int i = 0; i < pixels.Length; i++)
                {
                    if (pixels[i] == BrakeOnColor)
                    {
                        pixels[i] = BrakeOffColor;
                    }
                }

                _brakeOffTexture = new Texture2D(Engine.Instance.Device, _leftBrakeLight.Texture.Width, _leftBrakeLight.Texture.Height);
                _brakeOffTexture.SetData <Color>(pixels);
            }
        }