public Mesh(MeshChunk meshChunk, BitmapChunk bmpChunk) { _polys = meshChunk.Polygons; Identifier = meshChunk.Identifier; Resolve(bmpChunk); BoundingBox = GetBoundingBox(); }
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); } }
private void Parse(Stream contents) { BinaryReader br = new BinaryReader(contents); Header = new BitmapChunk(); Header.EnableTextureAttachments = true; Header.SkipHeader(br); Header.Read(br); br.Close(); }
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(); } }
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()); }
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(); } }