private static void ShpTestWrite(string filepath) { //string wkt = "POLYGON ((125.96146242562871 42.286033095153826,125.96045391503911 42.288221777709978,125.961333679596 42.289101542266863,125.96285717431645 42.289337576660174,125.96596853677373 42.288951338562029,125.96738474313359 42.287942827972429,125.96753494683843 42.286698282989519,125.96611874047856 42.285453738006609,125.96395151559453 42.285861433776873,125.96285717431645 42.286590994628924,125.96225635949712 42.28618329885866,125.962234901825 42.28618329885866,125.96146242562871 42.286033095153826),(125.96146242562871 42.286033095153826,125.96045391503911 42.288221777709978,125.961333679596 42.289101542266863,125.96285717431645 42.289337576660174,125.96596853677373 42.288951338562029,125.96738474313359 42.287942827972429,125.96753494683843 42.286698282989519,125.96611874047856 42.285453738006609,125.96395151559453 42.285861433776873,125.96285717431645 42.286590994628924,125.96225635949712 42.28618329885866,125.962234901825 42.28618329885866,125.96146242562871 42.286033095153826))"; //string wkt = "LINESTRING ((125.96146242562871 42.286033095153826,125.96045391503911 42.288221777709978,125.961333679596 42.289101542266863,125.96285717431645 42.289337576660174,125.96596853677373 42.288951338562029,125.96738474313359 42.287942827972429,125.96753494683843 42.286698282989519,125.96611874047856 42.285453738006609,125.96395151559453 42.285861433776873,125.96285717431645 42.286590994628924,125.96225635949712 42.28618329885866,125.962234901825 42.28618329885866,125.96146242562871 42.286033095153826),(125.96146242562871 42.286033095153826,125.96045391503911 42.288221777709978,125.961333679596 42.289101542266863,125.96285717431645 42.289337576660174,125.96596853677373 42.288951338562029,125.96738474313359 42.287942827972429,125.96753494683843 42.286698282989519,125.96611874047856 42.285453738006609,125.96395151559453 42.285861433776873,125.96285717431645 42.286590994628924,125.96225635949712 42.28618329885866,125.962234901825 42.28618329885866,125.96146242562871 42.286033095153826))"; //string wkt = "POINT (125.96146242562871 42.286033095153826)"; //边界 //string border = "POLYGON ((124.797090749881 43.4559641037949,124.833482961795 43.4679804001816,124.848589162967 43.4528741990098,124.855455618045 43.4346780930527,124.85854552283 43.4171686326035,124.861978750369 43.3986292038926,124.851679067752 43.3872995530137,124.840349416873 43.3728799973496,124.82421324744 43.3701334153184,124.804987173221 43.3704767380723,124.784387807987 43.3708200608262,124.777178030155 43.378716484166,124.773744802615 43.3996591721543,124.771684866092 43.4236917649277,124.797090749881 43.4559641037949))"; //图斑 string p1 = "POLYGON ((124.799150686405 43.4515009079941,124.808077078006 43.4490976487168,124.807390432498 43.4415445481309,124.801210622928 43.4401712571152,124.795374136112 43.4449777756699,124.799150686405 43.4515009079941))"; string p2 = "POLYGON ((124.792970876834 43.4370813523301,124.797777395389 43.4288416062363,124.801553945682 43.4168253098496,124.795717458865 43.4151086960801,124.787821035526 43.422661796666,124.792284231326 43.4284982834824,124.792970876834 43.4370813523301))"; string p3 = "POLYGON ((124.82249663367 43.441201225377,124.830736379764 43.4532175217637,124.835199575565 43.4442911301621,124.83657286658 43.4339914475449,124.832452993533 43.4309015427598,124.826273183963 43.4315881882676,124.82249663367 43.441201225377))"; string p4 = "POLYGON ((124.807733755252 43.4130487595566,124.8163168241 43.4212885056504,124.821466665408 43.4096155320176,124.821466665408 43.4024057541855,124.815630178592 43.397255912877,124.80842040076 43.400689140416,124.807733755252 43.4130487595566))"; List <string> lwkt = new List <string>(); //lwkt.Add(border); lwkt.Add(p1); lwkt.Add(p2); lwkt.Add(p3); lwkt.Add(p4); var oshp = new ShpFile(); oshp.Creat(filepath, FileMode.Create); oshp.WriteShp(lwkt); oshp.WriteShx(); oshp.Close(); }
void ExtractArt() { var artpak = new PakFile(@"MCG_DATA\ART\ART.PAK"); MCBitmap atlas; Dictionary <string, Rect> dict; for (int i = 0; i < artpak.PakInnerFileCount; i++) { var aux = artpak.GetFileInner(i); if (aux != null) { if (aux[0] == 71 && aux[1] == 73 && aux[2] == 70) { System.IO.File.WriteAllBytes(@"a\" + i + ".gif", aux); } else { System.IO.File.WriteAllBytes(@"a\" + i + ".shp", aux); try { var shp = new ShpFile(aux); ImageProcessing.CreateAtlas(shp.GetBitMaps(), out atlas, out dict); var MainText = ImageProcessing.MakeTexture2D(atlas, MechCommanderUnity.Instance.ContentReader.ShapesPakFile.Palette); ImageProcessing.SaveTextureAsPng(MainText, @"a\" + i); } catch (Exception) {} } } } }
unsafe public static void DrawAlpha(GameObject obj, ShpFile shp, DrawProperties props, DrawingSurface ds) { shp.Initialize(); // Change originally implemented by Starkku: Ares supports multiframe AlphaImages, based on frame count // the direction the unit it facing. int frameIndex = props.FrameDecider(obj); var img = shp.GetImage(frameIndex); var imgData = img.GetImageData(); var c_px = (uint)(img.Width * img.Height); if (c_px <= 0 || img.Width < 0 || img.Height < 0 || frameIndex > shp.NumImages) { return; } Point offset = props.GetOffset(obj); offset.X += obj.Tile.Dx * Drawable.TileWidth / 2; offset.Y += (obj.Tile.Dy - obj.Tile.Z) * Drawable.TileHeight / 2; Logger.Trace("Drawing AlphaImage SHP file {0} (frame {1}) at ({2},{3})", shp.FileName, frameIndex, offset.X, offset.Y); int stride = ds.BitmapData.Stride; var w_low = (byte *)ds.BitmapData.Scan0; byte *w_high = (byte *)ds.BitmapData.Scan0 + stride * ds.BitmapData.Height; int dx = offset.X + Drawable.TileWidth / 2 - shp.Width / 2 + img.X, dy = offset.Y - shp.Height / 2 + img.Y; byte *w = (byte *)ds.BitmapData.Scan0 + dx * 3 + stride * dy; short zOffset = (short)((obj.Tile.Rx + obj.Tile.Ry) * Drawable.TileHeight / 2 - shp.Height / 2 + img.Y); int rIdx = 0; for (int y = 0; y < img.Height; y++) { for (int x = 0; x < img.Width; x++) { if (imgData[rIdx] != 0 && w_low <= w && w < w_high) { float mult = imgData[rIdx] / 127.0f; *(w + 0) = limit(mult, *(w + 0)); *(w + 1) = limit(mult, *(w + 1)); *(w + 2) = limit(mult, *(w + 2)); } // Up to the next pixel rIdx++; w += 3; } w += stride - 3 * img.Width; // ... and if we're no more on the same row, // adjust the writing pointer accordingy } }
private short GetBuildingZ(int x, int y, ShpFile shp, ShpFile.ShpImage img, GameObject obj) { if (_noBuildingZAvailable) { return(0); } else if (BuildingZ == null) { if (_config.Engine < EngineType.YurisRevenge) { BuildingZ = _vfs.Open <ShpFile>("buildngz.shp"); } else // Yuri's Revenge uses .sha as a file extension for this { BuildingZ = _vfs.Open <ShpFile>("buildngz.sha"); } if (BuildingZ != null) { BuildingZ.Initialize(); } else { _noBuildingZAvailable = true; } } var zImg = BuildingZ.GetImage(0); byte[] zData = zImg.GetImageData(); // center x x += zImg.Width / 2 - shp.Width / 2 + img.X; // correct for foundation x -= (obj.Drawable.Foundation.Width - obj.Drawable.Foundation.Height) * 30; // add zshapepointmove x += obj.Drawable.Props.ZShapePointMove.X; // align y on bottom y += zImg.Height - shp.Height; // add zshapepointmove y -= obj.Drawable.Props.ZShapePointMove.Y; x = Math.Min(zImg.Width - 1, Math.Max(0, x)); y = Math.Min(zImg.Height - 1, Math.Max(0, y)); return((short)(-64 + zData[y * zImg.Width + x])); }
public Rectangle GetBounds(GameObject obj, ShpFile shp, DrawProperties props) { shp.Initialize(); int frameIndex = DecideFrameIndex(props.FrameDecider(obj), shp.NumImages); var offset = new Point(-shp.Width / 2, -shp.Height / 2); Size size = new Size(0, 0); var img = shp.GetImage(frameIndex); if (img != null) { offset.Offset(img.X, img.Y); size = new Size(img.Width, img.Height); } return(new Rectangle(offset, size)); }
private static void ShpTestRead(string filepath) { var oshp = new ShpFile(); oshp.Open(filepath, FileMode.Open); oshp.ReadShxRecord(); oshp.ReadShpRecord(); //根据实际情况进行投影 //oshp.ShpFileProject = ShapeProject.WGS_1984_Albers; //oshp.CoordTransPro2Geo();//投影转换 foreach (var item in oshp.ShpRecord.RecordDic) { string wkt = item.Value.WKTStr;//获取wkt Console.WriteLine(wkt); } }
public object Load(AssetManager assets, VFS.VFSHandle handle, object parameters) { string filename = handle.FileName; using (var stream = handle.Open()) if (filename.EndsWith(".CPS")) { return(CpsFile.Read(stream)); } else if (filename.EndsWith(".PCX")) { return(PcxFile.Read(stream)); } else { return(ShpFile.Read(stream)); } }
public static Func <GameObject, int> AlphaImageFrameDecider(ShpFile shp) { return(delegate(GameObject obj) { int direction = 0; if (obj is OwnableObject) { direction = (obj as OwnableObject).Direction; } shp.Initialize(); // header needs to be loaded at least int imgCount = shp.NumImages; if (imgCount % 8 == 0) { return (imgCount / 8) * (direction / 32); } else { return 0; } }); }
public bool GetAllShapes(int ObjIndex, out List <MCBitmap> lstImgs) { lstImgs = new List <MCBitmap>(); if (!isReady) { return(false); } // Get block data var maxShp = shapesPakFile.PakInnerFileCount; bool result = false; var pakData = shapesPakFile.GetFileInner(ObjIndex); if (pakData == null) { pakData = shapes90PakFile.GetFileInner(ObjIndex); } if (pakData != null) { var pak = new PakFile(pakData); for (int i = 0; i < pak.PakInnerFileCount; i++) { var shpdata = pak.GetFileInner(i); if (shpdata != null) { result = true; var shp = new ShpFile(shpdata); lstImgs.AddRange(shp.GetBitMaps()); } } } return(result); }
private static byte GetBuildingZ(int x, int y, ShpFile shp, ShpFile.ShpImage img, GameObject obj, DrawProperties props) { if (BuildingZ == null) { BuildingZ = VFS.Open <ShpFile>("buildngz.shp"); BuildingZ.Initialize(); } var zImg = BuildingZ.GetImage(0); byte[] zData = zImg.GetImageData(); // center x x += zImg.Width / 2; x += obj.Drawable.Foundation.Width * Drawable.TileHeight / 2; // align y y += zImg.Height - shp.Height; // y += props.ZAdjust; return(zData[y * zImg.Width + x]); }
public ShpDrawable(IniFile.IniSection rules, IniFile.IniSection art, ShpFile shpFile) : base(rules, art) { Shp = shpFile; }
public ShpDrawable(ShpFile shpFile) { Shp = shpFile; }
public ShpDrawable(ShpRenderer renderer, ShpFile shpFile) { _renderer = renderer; Shp = shpFile; }
public ShpDrawable(ModConfig config, VirtualFileSystem vfs, IniFile.IniSection rules, IniFile.IniSection art, ShpFile shpFile = null) : base(config, vfs, rules, art) { _renderer = new ShpRenderer(config, vfs); Shp = shpFile; }
public AlphaDrawable(ShpFile alphaShpFile) : base(alphaShpFile) { Props.Offset = new Point(0, 15); Props.FrameDecider = FrameDeciders.AlphaImageFrameDecider(Shp); }
public bool GetShape(int ObjIndex, out List <MCBitmap> lstImgs, int innerShp = -1, int indexImg = -1) { lstImgs = new List <MCBitmap>(); if (!isReady) { return(false); } // Get block data var maxShp = shapesPakFile.PakInnerFileCount; bool result = false; PakFile pak = null; if (!shapePakFiles.ContainsKey(ObjIndex)) { var pakData = shapesPakFile.GetFileInner(ObjIndex); if (pakData == null) { pakData = shapes90PakFile.GetFileInner(ObjIndex); } if (pakData != null) { pak = new PakFile(pakData); shapePakFiles.Add(ObjIndex, pak); } } else { pak = shapePakFiles[ObjIndex]; } if (pak != null) { var shpdata = pak.GetFileInner(innerShp); Debug.Log("SHP: " + ObjIndex + " - " + innerShp); if (shpdata != null) { result = true; var shp = new ShpFile(shpdata); if (indexImg > -1) { lstImgs.Add(shp.GetBitMap(indexImg)); } else { lstImgs.AddRange(shp.GetBitMaps()); } } } if (!result) { MechCommanderUnity.LogMessage(string.Format("Unknown Shape '{0}' '{1}' '{2}'.", ObjIndex, innerShp, indexImg), true); return(false); } return(true); }
public ShpDrawable(IniFile.IniSection rules, IniFile.IniSection art, ShpFile shpFile) : base(rules, art) { Shp = shpFile; random = new Random(); }
public AlphaDrawable(ModConfig config, VirtualFileSystem vfs, IniFile.IniSection rules, IniFile.IniSection art, ShpFile alphaShpFile) : base(config, vfs, rules, art, alphaShpFile) { Props.Offset = new Point(0, 15); Props.FrameDecider = FrameDeciders.AlphaImageFrameDecider(Shp); }
static IEnumerator CreateMaterialLibrary() { Debug.Log("Coruotine: "); var pal = new MCPalette(@"HB.pal"); var pak = new PakFile(@"04-Cougar.PAK"); // AssetDatabase.StartAssetEditing(); float progressBar = 0.0f; EditorUtility.DisplayProgressBar("Creating Textures", "Working...", progressBar); for (int index = 65; index < 400; index++) { try { //var index = 65; var shpdata = pak.GetFileInner(index); if (shpdata == null) { continue; } var shp = new ShpFile(shpdata); var bitmaps = shp.GetBitMaps(); if (bitmaps.Length == 0) { continue; } List <Texture2D> lstTextures = new List <Texture2D>(); foreach (var bmp in bitmaps) { MCSize sz; Color32[] albedoColors = MCBitmap.GetColor32(bmp, pal, 0, 0, out sz); // Debug.Log(bitmaps.Length); Texture2D albedoMap = null; albedoMap = new Texture2D(sz.Width, sz.Height, TextureFormat.RGBA32, false); albedoMap.SetPixels32(albedoColors); albedoMap.alphaIsTransparency = true; albedoMap.Apply(true, false); lstTextures.Add(albedoMap); } Texture2D atlas = new Texture2D(1, 1, TextureFormat.ARGB32, false); var rects = atlas.PackTextures(lstTextures.ToArray(), 0); atlas.alphaIsTransparency = true; atlas.filterMode = FilterMode.Point; atlas.wrapMode = TextureWrapMode.Clamp; atlas.Apply(); byte[] bytes = (atlas as Texture2D).EncodeToPNG(); // For testing purposes, also write to a file in the project folder File.WriteAllBytes(Application.dataPath + "./Sprites/Tests/" + "04-Cougar.PAK-" + index + ".png", bytes); Shader shader = Shader.Find("Sprites/Default"); Material material = new Material(shader); //material.SetFloat("_Mode", (int)0); //material.SetFloat("_SmoothnessTextureChannel", (int)1); //material.SetFloat("_Metallic", 0); //material.SetFloat("_Glossiness", 1); //material.SetOverrideTag("RenderType", "TransparentCutout"); //material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); //material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); //material.SetInt("_ZWrite", 1); //material.EnableKeyword("_ALPHATEST_ON"); //material.DisableKeyword("_ALPHABLEND_ON"); //material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); //material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest; material.name = "testmaterial"; material.mainTexture = atlas; material.mainTexture.filterMode = FilterMode.Point; //material.mainTextureOffset = new Vector2(rects[0].x, rects[0].y); //material.mainTextureScale = new Vector2(rects[0].width, rects[0].height); var go = new GameObject(); var rend = go.AddComponent <MeshRenderer>(); var meshFilter = go.AddComponent <MeshFilter>(); rend.material = material; rend.sharedMaterial = material; rend.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; rend.receiveShadows = false; rend.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; rend.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; // Vertices for a 1x1 unit quad // This is scaled to correct size depending on facing and orientation float hx = 0.5f, hy = 0.5f; Vector3[] vertices = new Vector3[4]; vertices[0] = new Vector3(-hx, hy, 0); vertices[1] = new Vector3(hx, hy, 0); vertices[2] = new Vector3(-hx, -hy, 0); vertices[3] = new Vector3(hx, -hy, 0); // Indices int[] triangles = new int[6] { 0, 1, 2, 3, 2, 1, }; // Normals Vector3 normal = Vector3.Normalize(Vector3.up + Vector3.forward); Vector3[] normals = new Vector3[4]; normals[0] = normal; normals[1] = normal; normals[2] = normal; normals[3] = normal; // Create mesh Mesh mesh = new Mesh(); mesh.name = string.Format("MobileEnemyMesh"); mesh.vertices = vertices; mesh.triangles = triangles; mesh.normals = normals; Vector2[] uvs = new Vector2[4]; var rect = rects[0]; uvs[0] = new Vector2(rect.x, rect.yMax); uvs[1] = new Vector2(rect.xMax, rect.yMax); uvs[2] = new Vector2(rect.x, rect.y); uvs[3] = new Vector2(rect.xMax, rect.y); // Assign mesh meshFilter.sharedMesh = mesh; meshFilter.sharedMesh.uv = uvs; // AssetDatabase.CreateAsset(material, "Assets/Sprites/Tests/" + "04-Cougar.PAK-" + index + ".mat"); //AssetDatabase.SaveAssets(); //AssetDatabase.Refresh(); // DestroyImmediate(atlas); //foreach (var text in lstTextures) //{ // DestroyImmediate(text); //} } catch (System.Exception e) { Debug.Log(e.Message); EditorUtility.ClearProgressBar(); throw; } progressBar = (float)(index / 4f); Debug.Log(progressBar); if ((index % 12f) == 0) { Debug.Log("Update ->" + progressBar); EditorUtility.DisplayProgressBar("Creating Textures", "Working...", progressBar); } yield return(true); break; } // AssetDatabase.SaveAssets(); // AssetDatabase.Refresh(); EditorUtility.ClearProgressBar(); yield return(true); Debug.Log("Coruotine2: "); yield return(null); }
public unsafe void DrawShadow(GameObject obj, ShpFile shp, DrawProperties props, DrawingSurface ds) { shp.Initialize(); int frameIndex = props.FrameDecider(obj); if (obj.Drawable.IsActualWall) { frameIndex = ((StructureObject)obj).WallBuildingFrame; } frameIndex = DecideFrameIndex(frameIndex, shp.NumImages); frameIndex += shp.Images.Count / 2; // latter half are shadow Images if (frameIndex >= shp.Images.Count) { return; } var img = shp.GetImage(frameIndex); var imgData = img.GetImageData(); if (imgData == null || img.Width * img.Height != imgData.Length) { return; } Point offset = props.GetShadowOffset(obj); offset.X += obj.Tile.Dx * _config.TileWidth / 2 - shp.Width / 2 + img.X; offset.Y += (obj.Tile.Dy - obj.Tile.Z) * _config.TileHeight / 2 - shp.Height / 2 + img.Y; Logger.Trace("Drawing SHP shadow {0} (frame {1}) at ({2},{3})", shp.FileName, frameIndex, offset.X, offset.Y); int stride = ds.BitmapData.Stride; var shadows = ds.GetShadows(); var zBuffer = ds.GetZBuffer(); var heightBuffer = ds.GetHeightBuffer(); var w_low = (byte *)ds.BitmapData.Scan0; byte *w_high = (byte *)ds.BitmapData.Scan0 + stride * ds.BitmapData.Height; byte *w = (byte *)ds.BitmapData.Scan0 + offset.X * 3 + stride * offset.Y; int zIdx = offset.X + offset.Y * ds.Width; int rIdx = 0; short zOffset = (short)((obj.Tile.Rx + obj.Tile.Ry) * _config.TileHeight / 2 - shp.Height / 2 + img.Y); int castHeight = obj.Tile.Z * _config.TileHeight / 2; if (obj.Drawable != null && !obj.Drawable.Flat) { castHeight += shp.Height; castHeight += obj.Drawable.TileElevation * _config.TileHeight / 2; } for (int y = 0; y < img.Height; y++) { if (offset.Y + y < 0) { w += stride; rIdx += img.Width; zIdx += ds.Width; continue; // out of bounds } short zBufVal = zOffset; if (obj.Drawable.Flat) { zBufVal += (short)y; } else { zBufVal += img.Height; } for (int x = 0; x < img.Width; x++) { if (0 <= offset.X + x && offset.X + x < ds.Width && 0 <= y + offset.Y && y + offset.Y < ds.Height && imgData[rIdx] != 0 && !shadows[zIdx] && // zBufVal >= zBuffer[zIdx] && castHeight >= heightBuffer[zIdx]) { *(w + 0) /= 2; *(w + 1) /= 2; *(w + 2) /= 2; shadows[zIdx] = true; } // Up to the next pixel rIdx++; zIdx++; w += 3; } w += stride - 3 * img.Width; // ... and if we're no more on the same row, zIdx += ds.Width - img.Width; // adjust the writing pointer accordingy } }
public bool GetShapes(int ObjIndex, out List <MCBitmap> lstImgs, List <int> shpIds) { lstImgs = new List <MCBitmap>(); if (!isReady) { return(false); } // Get block data var maxShp = shapesPakFile.PakInnerFileCount; bool result = false; PakFile pak = null; try { if (!shapePakFiles.ContainsKey(ObjIndex)) { var pakData = shapesPakFile.GetFileInner(ObjIndex); if (pakData == null) { pakData = shapes90PakFile.GetFileInner(ObjIndex); } if (pakData != null) { pak = new PakFile(pakData); shapePakFiles.Add(ObjIndex, pak); } } else { pak = shapePakFiles[ObjIndex]; } if (pak != null) { foreach (var innerShp in shpIds) { var shpdata = pak.GetFileInner(innerShp); if (shpdata != null) { result = true; var shp = new ShpFile(shpdata); var lstBmps = shp.GetBitMaps(); for (int i = 0; i < lstBmps.Length; i++) { if (lstBmps[i] == null) { continue; Debug.Log("BMP Vacio exportando: " + ObjIndex + " - " + innerShp + " : " + i); lstBmps[i] = new MCBitmap(1, 1); } lstBmps[i].Name = innerShp + "-" + i; } lstImgs.AddRange(lstBmps.Where(x => x != null).ToArray()); } } } } catch (Exception e) { Console.WriteLine(e); return(false); } if (!result) { MechCommanderUnity.LogMessage(string.Format("Unknown Shape '{0}' '{1}' t:{2}.", ObjIndex, string.Join(",", shpIds.Select(x => x.ToString()).ToArray()), pak.PakInnerFileCount), true); return(false); } return(true); }
public AnimDrawable(IniFile.IniSection rules, IniFile.IniSection art, ShpFile shp) : base(rules, art, shp) { }
public ShpDrawable(ShpFile shpFile) { Shp = shpFile; random = new Random(); }
public AlphaDrawable(IniFile.IniSection rules, IniFile.IniSection art, ShpFile alphaShpFile) : base(rules, art, alphaShpFile) { Props.Offset = new Point(0, 15); Props.FrameDecider = FrameDeciders.AlphaImageFrameDecider(Shp); }
public AnimDrawable(ModConfig config, VirtualFileSystem vfs, IniFile.IniSection rules, IniFile.IniSection art, ShpFile shpFile = null) : base(config, vfs, rules, art, shpFile) { }
public unsafe void Draw(ShpFile shp, GameObject obj, Drawable dr, DrawProperties props, DrawingSurface ds, int transLucency = 0) { shp.Initialize(); Palette p = props.PaletteOverride ?? obj.Palette; int frameIndex = props.FrameDecider(obj); if (obj.Drawable.IsActualWall) { frameIndex = ((StructureObject)obj).WallBuildingFrame; } frameIndex = DecideFrameIndex(frameIndex, shp.NumImages); if (frameIndex >= shp.Images.Count) { return; } var img = shp.GetImage(frameIndex); var imgData = img.GetImageData(); if (imgData == null || img.Width * img.Height != imgData.Length) { return; } Point offset = props.GetOffset(obj); offset.X += obj.Tile.Dx * _config.TileWidth / 2 - shp.Width / 2 + img.X; offset.Y += (obj.Tile.Dy - obj.Tile.Z) * _config.TileHeight / 2 - shp.Height / 2 + img.Y; Logger.Trace("Drawing SHP file {0} (Frame {1}) at ({2},{3})", shp.FileName, frameIndex, offset.X, offset.Y); int stride = ds.BitmapData.Stride; var heightBuffer = ds.GetHeightBuffer(); var zBuffer = ds.GetZBuffer(); var w_low = (byte *)ds.BitmapData.Scan0; byte *w_high = (byte *)ds.BitmapData.Scan0 + stride * ds.BitmapData.Height; byte *w = (byte *)ds.BitmapData.Scan0 + offset.X * 3 + stride * offset.Y; // clip to 25-50-75-100 transLucency = (transLucency / 25) * 25; float a = transLucency / 100f; float b = 1 - a; int rIdx = 0; // image pixel index int zIdx = offset.X + offset.Y * ds.Width; // z-buffer pixel index short hBufVal = (short)(obj.Tile.Z * _config.TileHeight / 2); short zOffset = (short)((obj.BottomTile.Rx + obj.BottomTile.Ry) * _config.TileHeight / 2 + props.ZAdjust); if (!dr.Flat) { hBufVal += shp.Height; } for (int y = 0; y < img.Height; y++) { if (offset.Y + y < 0) { w += stride; rIdx += img.Width; zIdx += ds.Width; continue; // out of bounds } for (int x = 0; x < img.Width; x++) { byte paletteValue = imgData[rIdx]; short zshapeOffset = obj is StructureObject ? (GetBuildingZ(x, y, shp, img, obj)) : (short)0; if (paletteValue != 0) { short zBufVal = zOffset; if (dr.Flat) { zBufVal += (short)(y - img.Height); } else if (dr.IsBuildingPart) { // nonflat building zBufVal += zshapeOffset; } else { zBufVal += img.Height; } if (w_low <= w && w < w_high /*&& zBufVal >= zBuffer[zIdx]*/) { if (transLucency != 0) { *(w + 0) = (byte)(a * *(w + 0) + b * p.Colors[paletteValue].B); *(w + 1) = (byte)(a * *(w + 1) + b * p.Colors[paletteValue].G); *(w + 2) = (byte)(a * *(w + 2) + b * p.Colors[paletteValue].R); } else { *(w + 0) = p.Colors[paletteValue].B; *(w + 1) = p.Colors[paletteValue].G; *(w + 2) = p.Colors[paletteValue].R; //var pal = Theater.Active.GetPalettes().UnitPalette.Colors; //*(w + 0) = pal[zshapeOffset].R; //*(w + 1) = pal[zshapeOffset].G; //*(w + 2) = pal[zshapeOffset].B; } zBuffer[zIdx] = zBufVal; heightBuffer[zIdx] = hBufVal; } } //else { // *(w + 0) = 0; // *(w + 1) = 0; // *(w + 2) = 255; //} // Up to the next pixel rIdx++; zIdx++; w += 3; } w += stride - 3 * img.Width; zIdx += ds.Width - img.Width; } }