public void GetBaseTextureStandalone(PAL Palette) { var beginX = -Bounds.X; var beginY = -Bounds.Y; for (var y = 0; y < TileHeight; ++y) { for (var x = 0; x < TileWidth; ++x) { var ixPix = IndexOfPixel(x, y); if (ixPix != -1) { var ixClr = Graphics[ixPix]; if (ixClr != 0) { var clr = Palette.Colors[ixClr]; var z = (HasZData) ? ZData[ixPix] : 0 ; _Texture.PutPixel(clr, beginX + x, beginY + y, z); } } } } }
public void GetExtrasTextureStandalone(PAL Palette) { var beginX = ExtraX - X - Bounds.X; var beginY = ExtraY - Y - Bounds.Y; for (var y = 0; y < ExtraHeight; ++y) { for (var x = 0; x < ExtraWidth; ++x) { var ixPix = y * ExtraWidth + x; var ixClr = Extras[ixPix]; if (ixClr != 0) { var clr = Palette.Colors[ixClr]; var z = (HasZData) ? ExtraZData[ixPix] : 0 ; _Texture.PutPixel(clr, beginX + x, beginY + y, z); } } } }
internal void GetVertices(HVA.Section MotLib, int FrameIdx, PAL Palette, List <VertexPositionColorNormal> Vertices, List <int> Indices) { if (ComputedFrames[FrameIdx] == null) { ComputeVerticesIndices(Palette); var computedF = new SectionFrame(); var rot = MotLib.GetRotation(FrameIdx); var pos = MotLib.GetPosition(FrameIdx); pos *= Tail.HVAMultiplier; computedF.ComputedVertices = ComputedVertices.Select(v => { v.Position = Vector3.Transform(v.Position, rot); v.Position += pos; return(v); }).ToList(); computedF.ComputedIndices = ComputedIndices; ComputedFrames[FrameIdx] = computedF; } var cached = ComputedFrames[FrameIdx]; Vertices.AddRange(cached.ComputedVertices); Indices.AddRange(cached.ComputedIndices); }
public Helpers.ZBufferedTexture GetTextureStandalone(PAL Palette) { if (_Texture == null) { PrepareTexture(Palette); } return(_Texture); }
public Helpers.ZBufferedTexture PrepareTexture(PAL Palette) { _Texture = new Helpers.ZBufferedTexture(Bounds.Width, Bounds.Height); GetBaseTextureStandalone(Palette); if (HasExtraData) { GetExtrasTextureStandalone(Palette); } return(_Texture); }
public void GetVertices(PAL Palette, int FrameIdx, List <VertexPositionColorNormal> Vertices, List <int> Indices) { for (var i = 0; i < Sections.Count; ++i) { var s = Sections[i]; var hvaSection = MotLib != null ? MotLib.Sections[i] : null; s.GetVertices(hvaSection, FrameIdx, Palette, Vertices, Indices); } }
public void DrawIntoTexture(Helpers.ZBufferedTexture Texture, CellStruct CenterPoint, uint FrameIndex, PAL tmpPalette, int zIndex = 0) { if (FrameIndex > FrameHeaders.Count) { throw new InvalidOperationException(String.Format("Frame {0} is not present in this file.", FrameIndex)); } var frame = FrameHeaders[(int)FrameIndex]; var fw = (int)frame.Width; var fh = (int)frame.Height; var startX = (int)(CenterPoint.X - fw / 2); var startY = (int)(CenterPoint.Y - fh / 2); frame.DrawIntoTexture(Texture, new CellStruct(startX, startY), tmpPalette, zIndex); }
public void GetVertices(PAL Palette, int FrameIdx, List<VertexPositionColorNormal> Vertices, List<int> Indices) { for (var i = 0; i < Sections.Count; ++i) { var s = Sections[i]; var hvaSection = MotLib != null ? MotLib.Sections[i] : null; s.GetVertices(hvaSection, FrameIdx, Palette, Vertices, Indices); } }
public void DrawIntoTextureBL(Helpers.ZBufferedTexture Texture, CellStruct BottomLeft, uint FrameIndex, PAL tmpPalette, int zIndex = 0) { if (FrameIndex > FrameHeaders.Count) { throw new InvalidOperationException(String.Format("Frame {0} is not present in this file.", FrameIndex)); } var frame = FrameHeaders[(int)FrameIndex]; var fh = (int)frame.Height; var startX = (int)(BottomLeft.X); var startY = (int)(BottomLeft.Y - fh); frame.DrawIntoTexture(Texture, new CellStruct(startX, startY), tmpPalette, zIndex); }
public void DrawIntoTextureTL(Helpers.ZBufferedTexture Texture, CellStruct topLeft, uint FrameIndex, PAL tmpPalette, int zIndex = 0) { if (FrameIndex > FrameHeaders.Count) { throw new InvalidOperationException(String.Format("Frame {0} is not present in this file.", FrameIndex)); } var frame = FrameHeaders[(int)FrameIndex]; frame.DrawIntoTexture(Texture, topLeft, tmpPalette, zIndex); }
public void ApplyPalette(PAL NewPalette) { Palette = NewPalette; }
public void DrawIntoTexture(Helpers.ZBufferedTexture Texture, CellStruct StartXY, PAL tmpPalette, int zIndex = 0) { var fw = (int)Width; var fh = (int)Height; if (fw * fh != ProcessedBytes.Length) { throw new InvalidDataException("Frame does not decompress to the right amount of bytes"); } for (var y = 0; y < fh; ++y) { for (var x = 0; x < fw; ++x) { var ixPix = y * fw + x; var ixClr = ProcessedBytes[ixPix]; var clr = PAL.TranslucentColor; if (ixClr != 0) { clr = tmpPalette.Colors[ixClr]; } Texture.PutPixel(clr, StartXY.X + x, StartXY.Y + y, zIndex); } } }
private void LoadGameFiles() { FileSystem.LoadMIX("LANGMD.MIX"); FileSystem.LoadMIX("LANGUAGE.MIX"); for (var ix = 99; ix > 0; --ix) { var pattern = String.Format("EXPANDMD{0:d2}.MIX", ix); FileSystem.LoadMIX(pattern); } FileSystem.LoadMIX("RA2MD.MIX"); FileSystem.LoadMIX("RA2.MIX"); FileSystem.LoadMIX("CACHEMD.MIX"); FileSystem.LoadMIX("CACHE.MIX"); FileSystem.LoadMIX("LOCALMD.MIX"); FileSystem.LoadMIX("LOCAL.MIX"); FileSystem.LoadMIX("AUDIOMD.MIX"); foreach (var ecache in Directory.GetFiles(GameDir, "ECACHE*.MIX", SearchOption.TopDirectoryOnly)) { FileSystem.LoadMIX(ecache); } foreach (var elocal in Directory.GetFiles(GameDir, "ELOCAL*.MIX", SearchOption.TopDirectoryOnly)) { FileSystem.LoadMIX(elocal); } FileSystem.LoadMIX("CONQMD.MIX"); FileSystem.LoadMIX("GENERMD.MIX"); FileSystem.LoadMIX("GENERIC.MIX"); FileSystem.LoadMIX("ISOGENMD.MIX"); FileSystem.LoadMIX("ISOGEN.MIX"); FileSystem.LoadMIX("CONQUER.MIX"); FileSystem.LoadMIX("CAMEOMD.MIX"); FileSystem.LoadMIX("CAMEO.MIX"); FileSystem.LoadMIX("MAPSMD03.MIX"); FileSystem.LoadMIX("MULTIMD.MIX"); FileSystem.LoadMIX("THEMEMD.MIX"); FileSystem.LoadMIX("MOVMD03.MIX"); var str = FileSystem.LoadFile("RA2MD.CSF"); if (str != null) { new CSF(str); } var m = FileSystem.LoadFile("MOUSE.SHA"); if (m != null) { MouseTextures = new SHP(m); MouseFrame = 0; MouseFrameChanged = true; } else { throw new InvalidDataException(); } var mp = FileSystem.LoadFile("MOUSEPAL.PAL"); if (mp != null) { MousePalette = new PAL(mp); MouseTextures.Palette = MousePalette; } else { throw new InvalidDataException(); } var p = FileSystem.LoadFile("ANIM.PAL"); if (p != null) { AnimPalette = new PAL(p); } else { throw new InvalidDataException(); } var rules = FileSystem.LoadFile("RULESMD.INI"); if (rules != null) { INI.Rules_INI = new INI(rules); } else { throw new InvalidDataException(); } var art = FileSystem.LoadFile("ARTMD.INI"); if (art != null) { INI.Art_INI = new INI(art); } else { throw new InvalidDataException(); } }
internal void ComputeVerticesIndices(PAL Palette) { if (ComputedVertices == null) { ComputedVertices = new List<VertexPositionColorNormal>(); ComputedIndices = new List<int>(); var Normals = GetNormals(); var shifts = new Vector3[] { new Vector3(-1, -1, -1), new Vector3(-1, +1, -1), new Vector3(-1, -1, +1), new Vector3(-1, +1, +1), new Vector3(+1, -1, -1), new Vector3(+1, +1, -1), new Vector3(+1, -1, +1), new Vector3(+1, +1, +1), }; foreach (var sp in Body.Spans) { foreach (var v in sp.Voxels) { var Clr = Palette.Colors[v.ColorIndex]; var N = Normals[v.NormalIndex]; var obs = Body.ObscuredFrom(v.X, v.Y, v.Z); if (obs == Edges.All) { continue; } var realPos = Tail.Displacement(v.X, v.Y, v.Z); var start = ComputedVertices.Count; foreach (var sh in shifts) { var vpcn = new VertexPositionColorNormal(); var scaledShift = sh * Tail.Scale; var pos = realPos + scaledShift; vpcn.Position = pos; vpcn.Color = Clr; vpcn.Normal = N; ComputedVertices.Add(vpcn); } if (!obs.HasFlag(Edges.XLess)) { // 0123 ComputedIndices.Add(start + 0); ComputedIndices.Add(start + 1); ComputedIndices.Add(start + 2); ComputedIndices.Add(start + 1); ComputedIndices.Add(start + 2); ComputedIndices.Add(start + 3); } if (!obs.HasFlag(Edges.YLess)) { // 0246 ComputedIndices.Add(start + 0); ComputedIndices.Add(start + 2); ComputedIndices.Add(start + 4); ComputedIndices.Add(start + 2); ComputedIndices.Add(start + 4); ComputedIndices.Add(start + 6); } if (!obs.HasFlag(Edges.ZLess)) { // 0145 ComputedIndices.Add(start + 0); ComputedIndices.Add(start + 1); ComputedIndices.Add(start + 4); ComputedIndices.Add(start + 1); ComputedIndices.Add(start + 4); ComputedIndices.Add(start + 5); } if (!obs.HasFlag(Edges.ZMore)) { // 2367 ComputedIndices.Add(start + 2); ComputedIndices.Add(start + 3); ComputedIndices.Add(start + 6); ComputedIndices.Add(start + 3); ComputedIndices.Add(start + 6); ComputedIndices.Add(start + 7); } if (!obs.HasFlag(Edges.YMore)) { // 1357 ComputedIndices.Add(start + 1); ComputedIndices.Add(start + 3); ComputedIndices.Add(start + 5); ComputedIndices.Add(start + 3); ComputedIndices.Add(start + 5); ComputedIndices.Add(start + 7); } if (!obs.HasFlag(Edges.XMore)) { // 4567 ComputedIndices.Add(start + 4); ComputedIndices.Add(start + 5); ComputedIndices.Add(start + 6); ComputedIndices.Add(start + 5); ComputedIndices.Add(start + 6); ComputedIndices.Add(start + 7); } } } } }
internal void GetVertices(HVA.Section MotLib, int FrameIdx, PAL Palette, List<VertexPositionColorNormal> Vertices, List<int> Indices) { if (ComputedFrames[FrameIdx] == null) { ComputeVerticesIndices(Palette); var computedF = new SectionFrame(); var rot = MotLib.GetRotation(FrameIdx); var pos = MotLib.GetPosition(FrameIdx); pos *= Tail.HVAMultiplier; computedF.ComputedVertices = ComputedVertices.Select(v => { v.Position = Vector3.Transform(v.Position, rot); v.Position += pos; return v; }).ToList(); computedF.ComputedIndices = ComputedIndices; ComputedFrames[FrameIdx] = computedF; } var cached = ComputedFrames[FrameIdx]; Vertices.AddRange(cached.ComputedVertices); Indices.AddRange(cached.ComputedIndices); }
public Helpers.ZBufferedTexture GetTextureStandalone(PAL Palette) { if (_Texture == null) { PrepareTexture(Palette); } return _Texture; }
internal void ComputeVerticesIndices(PAL Palette) { if (ComputedVertices == null) { ComputedVertices = new List <VertexPositionColorNormal>(); ComputedIndices = new List <int>(); var Normals = GetNormals(); var shifts = new Vector3[] { new Vector3(-1, -1, -1), new Vector3(-1, +1, -1), new Vector3(-1, -1, +1), new Vector3(-1, +1, +1), new Vector3(+1, -1, -1), new Vector3(+1, +1, -1), new Vector3(+1, -1, +1), new Vector3(+1, +1, +1), }; foreach (var sp in Body.Spans) { foreach (var v in sp.Voxels) { var Clr = Palette.Colors[v.ColorIndex]; var N = Normals[v.NormalIndex]; var obs = Body.ObscuredFrom(v.X, v.Y, v.Z); if (obs == Edges.All) { continue; } var realPos = Tail.Displacement(v.X, v.Y, v.Z); var start = ComputedVertices.Count; foreach (var sh in shifts) { var vpcn = new VertexPositionColorNormal(); var scaledShift = sh * Tail.Scale; var pos = realPos + scaledShift; vpcn.Position = pos; vpcn.Color = Clr; vpcn.Normal = N; ComputedVertices.Add(vpcn); } if (!obs.HasFlag(Edges.XLess)) { // 0123 ComputedIndices.Add(start + 0); ComputedIndices.Add(start + 1); ComputedIndices.Add(start + 2); ComputedIndices.Add(start + 1); ComputedIndices.Add(start + 2); ComputedIndices.Add(start + 3); } if (!obs.HasFlag(Edges.YLess)) { // 0246 ComputedIndices.Add(start + 0); ComputedIndices.Add(start + 2); ComputedIndices.Add(start + 4); ComputedIndices.Add(start + 2); ComputedIndices.Add(start + 4); ComputedIndices.Add(start + 6); } if (!obs.HasFlag(Edges.ZLess)) { // 0145 ComputedIndices.Add(start + 0); ComputedIndices.Add(start + 1); ComputedIndices.Add(start + 4); ComputedIndices.Add(start + 1); ComputedIndices.Add(start + 4); ComputedIndices.Add(start + 5); } if (!obs.HasFlag(Edges.ZMore)) { // 2367 ComputedIndices.Add(start + 2); ComputedIndices.Add(start + 3); ComputedIndices.Add(start + 6); ComputedIndices.Add(start + 3); ComputedIndices.Add(start + 6); ComputedIndices.Add(start + 7); } if (!obs.HasFlag(Edges.YMore)) { // 1357 ComputedIndices.Add(start + 1); ComputedIndices.Add(start + 3); ComputedIndices.Add(start + 5); ComputedIndices.Add(start + 3); ComputedIndices.Add(start + 5); ComputedIndices.Add(start + 7); } if (!obs.HasFlag(Edges.XMore)) { // 4567 ComputedIndices.Add(start + 4); ComputedIndices.Add(start + 5); ComputedIndices.Add(start + 6); ComputedIndices.Add(start + 5); ComputedIndices.Add(start + 6); ComputedIndices.Add(start + 7); } } } } }
public Helpers.ZBufferedTexture PrepareTexture(PAL Palette) { _Texture = new Helpers.ZBufferedTexture(Bounds.Width, Bounds.Height); GetBaseTextureStandalone(Palette); if (HasExtraData) { GetExtrasTextureStandalone(Palette); } return _Texture; }
public static void Init(MapTheater tData) { var mixFiles = new List<String>() { String.Format("{0:s}.MIX", tData.mixName), String.Format("{0:s}MD.MIX", tData.mixName), String.Format("{0:s}.MIX", tData.isoName1), String.Format("{0:s}MD.MIX", tData.isoName2), String.Format("{0:s}.MIX", tData.Extension), }; if (CurrentTheater != tData) { if (CurrentTheater != null) { CurrentTheater.Mixes.ForEach(M => FileSystem.UnloadMIX(M)); CurrentTheater.Mixes.Clear(); } CurrentTheater = tData; IsoTileTypeClass.TheaterChanged(); foreach (var mixName in mixFiles) { var M = FileSystem.LoadMIX(mixName); if (M != null) { CurrentTheater.Mixes.Add(M); } } String PalName = String.Format("ISO{0}.PAL", CurrentTheater.Extension); var PalStream = FileSystem.LoadFile(PalName); if (PalStream != null) { isoPAL = new PAL(PalStream); } else { isoPAL = null; } PalName = String.Format("UNIT{0}.PAL", CurrentTheater.Extension); PalStream = FileSystem.LoadFile(PalName); if (PalStream != null) { unitPAL = new PAL(PalStream); } else { unitPAL = null; } PalName = "TEMPERAT.PAL"; PalStream = FileSystem.LoadFile(PalName); if (PalStream != null) { TemperatePAL = new PAL(PalStream); } else { TemperatePAL = null; } } }