Exemplo n.º 1
0
 public Mesh(MeshChunk meshChunk, BitmapChunk bmpChunk)
 {
     _polys = meshChunk.Polygons;
     Identifier = meshChunk.Identifier;
     Resolve(bmpChunk);
     BoundingBox = GetBoundingBox();
 }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        private void ReadChunk(BinaryReader reader, bool readHeaderOnly)
        {
            string identifier = new string(reader.ReadChars(4));

            if (identifier == "ORIP")
            {
                MeshChunk meshChunk = new MeshChunk();
                if (readHeaderOnly)
                {
                    meshChunk.Offset = reader.BaseStream.Position;
                }
                else
                {
                    meshChunk.Read(reader);
                }
                _meshChunks.Add(meshChunk);
            }
            else if (identifier == "SHPI")
            {
                BitmapChunk bitmapChunk = new BitmapChunk();
                bitmapChunk.Index = _index++;
                if (readHeaderOnly)
                {
                    bitmapChunk.Offset = reader.BaseStream.Position;
                }
                else
                {
                    bitmapChunk.Read(reader);
                }
                _bitmapChunks.Add(bitmapChunk);
            }
            else if (identifier == "wwww")
            {
                HeaderChunk header = new HeaderChunk();
                if (readHeaderOnly)
                {
                    header.Offset = reader.BaseStream.Position;
                }
                else
                {
                    header.Read(reader, false, false);
                }
                _headerChunks.Add(header);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Exemplo n.º 4
0
        private void ReadChunk(BinaryReader reader, bool readHeaderOnly)
        {
            string identifier = new string(reader.ReadChars(4));

            if (identifier == "ORIP")
            {
                MeshChunk meshChunk = new MeshChunk();
                if (readHeaderOnly)
                    meshChunk.Offset = reader.BaseStream.Position;
                else
                {
                    meshChunk.Read(reader);
                }
                _meshChunks.Add(meshChunk);
            }
            else if (identifier == "SHPI")
            {
                BitmapChunk bitmapChunk = new BitmapChunk();
                bitmapChunk.Index = _index++;
                if (readHeaderOnly)
                    bitmapChunk.Offset = reader.BaseStream.Position;
                else
                    bitmapChunk.Read(reader);
                _bitmapChunks.Add(bitmapChunk);
            }
            else if (identifier == "wwww")
            {
                HeaderChunk header = new HeaderChunk();
                if (readHeaderOnly)
                    header.Offset = reader.BaseStream.Position;
                else
                    header.Read(reader, false, false);
                _headerChunks.Add(header);
            }
            else
            {
                throw new NotImplementedException();
            }
        }