예제 #1
0
파일: Mesh.cs 프로젝트: STPKITT/OpenNFS1
 public Mesh(MeshChunk meshChunk, BitmapChunk bmpChunk)
 {
     _polys = meshChunk.Polygons;
     Identifier = meshChunk.Identifier;
     Resolve(bmpChunk);
     BoundingBox = GetBoundingBox();
 }
예제 #2
0
파일: CarMesh.cs 프로젝트: STPKITT/OpenNFS1
        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);
            }
        }
예제 #3
0
파일: FshFile.cs 프로젝트: STPKITT/OpenNFS1
 private void Parse(Stream contents)
 {
     BinaryReader br = new BinaryReader(contents);
     Header = new BitmapChunk();
     Header.EnableTextureAttachments = true;
     Header.SkipHeader(br);
     Header.Read(br);
     br.Close();
 }
예제 #4
0
        private void Parse(Stream contents)
        {
            BinaryReader br = new BinaryReader(contents);

            Header = new BitmapChunk();
            Header.EnableTextureAttachments = true;
            Header.SkipHeader(br);
            Header.Read(br);
            br.Close();
        }
예제 #5
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();
            }
        }
예제 #6
0
파일: Mesh.cs 프로젝트: STPKITT/OpenNFS1
        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());
        }
예제 #7
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();
            }
        }