public void GCAtlas() { //IL_0081: Unknown result type (might be due to invalid IL or missing references) int count = atlases.Count; for (int i = 0; i < count; i++) { AtlasEntry atlasEntry = atlases[i]; atlasEntry.orgSpriteList.RemoveAll(delegate(UISprite o) { if (null == o) { return(true); } return(false); }); if (0 >= atlasEntry.orgSpriteList.Count) { if (null != atlasEntry.copyAtlas) { Object.Destroy(atlasEntry.copyAtlas.spriteMaterial); Object.Destroy(atlasEntry.copyAtlas.get_gameObject()); } atlasEntry.copyAtlas = null; } } atlases.RemoveAll(delegate(AtlasEntry o) { if (null == o.copyAtlas) { return(true); } return(false); }); }
private bool SubmitImage(Image image, out AtlasEntry entry) { if (_packer.TryAdd(image, image.Size)) { // Successfully added image to packing var rect = _packer.GetRectangle(image); // Construct atlas entry entry = new AtlasEntry { Texture = _texture, UVRect = new Rectangle { X = rect.X / (float)_texture.Width, Y = rect.Y / (float)_texture.Height, Width = rect.Width / (float)_texture.Width, Height = rect.Height / (float)_texture.Height }, Rect = rect }; // Record image entry _entries.Add(image, entry); return(true); } else { // Unable to insert into atlas entry = null; return(false); } }
public void ReleaseAtlas(UISprite sprite) { //IL_009d: Unknown result type (might be due to invalid IL or missing references) if (!(null == sprite) && !(null == sprite.atlas)) { AtlasEntry atlasEntry = atlases.Find(delegate(AtlasEntry o) { if (sprite.atlas.Equals((object)o.orgAtlas)) { return(true); } return(false); }); if (atlasEntry != null) { atlasEntry.orgSpriteList.Remove(sprite); if (0 >= atlasEntry.orgSpriteList.Count) { if (null != atlasEntry.copyAtlas) { Object.Destroy(atlasEntry.copyAtlas.spriteMaterial); Object.Destroy(atlasEntry.copyAtlas.get_gameObject()); } atlases.Remove(atlasEntry); } } } }
private static void UpdateLinkDicts(PackageReference pr, IList <Entry> contents) { for (int i = 0; i < contents.Count; i++) { TextureEntry te = contents[i] as TextureEntry; if (te != null) { if (TexturesByName.ContainsKey(te.Name)) { Console.WriteLine("Duplicate Texture entry: " + te.Name + " in " + pr.DisplayName + " and " + TexturesByName[te.Name].ContainingPackage.DisplayName); } else { TexturesByName.Add(te.Name, new EntryReference(i, pr)); } continue; } AtlasEntry ae = contents[i] as AtlasEntry; if (ae != null) { if (ae.IsReference) { AddTo(AtlasesByTextureName, ae.ReferencedTextureName, new EntryReference(i, pr)); } continue; } } }
public static Entry ReadManifestEntry(MemoryStream chunk, out ReadStatus readStatus) { int entryType = chunk.ReadByte(); readStatus = ReadStatus.OK; switch (entryType) { case ATLAS_CODE: return(AtlasEntry.Read(chunk, true)); case BINK_ATLAS_CODE: return(BinkAtlasEntry.Read(chunk)); case INCLUDE_PACKAGE_CODE: return(IncludePackageEntry.Read(chunk)); case END_CHUNK_CODE: readStatus = ReadStatus.EndOfChunk; return(null); case (int)byte.MaxValue: case -1: readStatus = ReadStatus.EndOfFile; return(null); default: throw new PackageReadException(string.Format(ERR_UNKNOWN_MANIFEST_entryType, entryType)); } }
public void AddSprite(Sprite sprite) { AtlasEntry entry = new AtlasEntry(); entry.spriteName = sprite.name; entry.sprite = sprite; atlasEntries.Add(entry); }
void Awake() { int count = atlasEntries.Count; for (int i = 0; i < count; i++) { AtlasEntry entry = atlasEntries[i]; spriteMap.Add(entry.spriteName, entry.sprite); } }
private AtlasEntry newEntry(uint texID, int x, int y, int width, int height) { AtlasEntry a = new AtlasEntry(); a.texID = texID; a.x = x; a.y = y; a.width = width; a.height = height; return(a); }
void ScreenFillQuad(Box2 box, Vector4 color, AtlasEntry entry, bool useScale = true) { var zoom = useScale ? pixelZoom : 1; var br = box.BottomRight + Vector2.One; vaoGui.Vertices.Add(new(box.TopLeft * zoom, color, entry.TextureCoordinate0)); vaoGui.Vertices.Add(new(br * zoom, color, entry.TextureCoordinate1)); vaoGui.Vertices.Add(new(new((box.Right + 1) * zoom, box.Top * zoom), color, new(entry.TextureCoordinate1.X, entry.TextureCoordinate0.Y, entry.TextureCoordinate0.Z))); vaoGui.Vertices.Add(new(new(box.Left * zoom, (box.Bottom + 1) * zoom), color, new(entry.TextureCoordinate0.X, entry.TextureCoordinate1.Y, entry.TextureCoordinate0.Z))); vaoGui.Vertices.Add(new(br * zoom, color, entry.TextureCoordinate1)); vaoGui.Vertices.Add(new(box.TopLeft * zoom, color, entry.TextureCoordinate0)); }
private AtlasEntry GenerateAtlasEntry(int a_iAtlasEntryIndex, Texture2D a_rAtlasTexture, Dictionary <int, PackedRect> a_rTextureIndexUVRectsDict, string a_oGeneratedDataPathLocal) { Texture2D rCurrentAtlasTexture; Material rCurrentAtlasMaterial; float fWidth = (float)a_rAtlasTexture.width; float fHeight = (float)a_rAtlasTexture.height; if (m_oAtlasEntries != null && m_oAtlasEntries.Length > a_iAtlasEntryIndex && m_oAtlasEntries[a_iAtlasEntryIndex] != null) { AtlasEntry rAtlasEntry = m_oAtlasEntries[a_iAtlasEntryIndex]; rCurrentAtlasTexture = rAtlasEntry.atlasTexture; rCurrentAtlasMaterial = rAtlasEntry.material; } else { rCurrentAtlasTexture = null; rCurrentAtlasMaterial = null; } // rSavedAtlasTexture = instance of the saved/exported/serialized atlas texture at a_oGeneratedDataPathLocal Texture2D rSavedAtlasTexture = this.ExportAndSaveAtlasTexture(a_iAtlasEntryIndex, rCurrentAtlasTexture, a_rAtlasTexture, a_oGeneratedDataPathLocal); Material rSavedAtlasMaterial = this.GenerateAtlasMaterial(a_iAtlasEntryIndex, rCurrentAtlasMaterial, rSavedAtlasTexture, a_oGeneratedDataPathLocal); int iTextureCount = a_rTextureIndexUVRectsDict.Count; string[] oTextureGUIDs = new string[iTextureCount]; PackedRect[] oPackedUVRects = new PackedRect[iTextureCount]; int iTextureIndex = 0; foreach (KeyValuePair <int, PackedRect> rTextureIndexPackedUVRectPair in a_rTextureIndexUVRectsDict) { oTextureGUIDs[iTextureIndex] = m_rTextureContainers[rTextureIndexPackedUVRectPair.Key].GUID; PackedRect oNormalizedPackedRect = rTextureIndexPackedUVRectPair.Value; // Normalize UVs Rect rUVRect = oNormalizedPackedRect.rect; oNormalizedPackedRect.rect = new Rect(rUVRect.x / fWidth, rUVRect.y / fHeight, (rUVRect.width - m_iPadding) / fWidth, (rUVRect.height - m_iPadding) / fHeight); oPackedUVRects[iTextureIndex] = oNormalizedPackedRect; ++iTextureIndex; } return(new AtlasEntry(rSavedAtlasTexture, rSavedAtlasMaterial, oTextureGUIDs, oPackedUVRects)); }
private void AddAtlasEntries(TreeNode root, IList <PsigaPkgLib.Entries.Entry> contents) { foreach (var e in contents) { AtlasEntry ae = e as AtlasEntry; if (ae != null) { foreach (var sa in ae.Entries) { root.EnsurePath(sa); } } } }
public AtlasEntry ReplaceAtlas(UISprite sprite, string shader) { //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown if (null == sprite || null == sprite.atlas) { return(null); } AtlasEntry atlasEntry = atlases.Find(delegate(AtlasEntry o) { if (sprite.atlas.Equals((object)o.orgAtlas)) { return(true); } return(false); }); if (atlasEntry != null && (null == atlasEntry.copyAtlas || null == atlasEntry.orgAtlas)) { atlases.Remove(atlasEntry); atlasEntry = null; } UIAtlas uIAtlas; if (atlasEntry == null) { uIAtlas = ((!(sprite.atlas.replacement != null)) ? ResourceUtility.Instantiate <UIAtlas>(sprite.atlas) : ResourceUtility.Instantiate <UIAtlas>(sprite.atlas.replacement)); if (!(uIAtlas == null) && !(uIAtlas.spriteMaterial == null)) { goto IL_00f4; } goto IL_00f4; } goto IL_0154; IL_0154: atlasEntry.orgSpriteList.Add(sprite); sprite.atlas = atlasEntry.copyAtlas; return(atlasEntry); IL_00f4: uIAtlas.spriteMaterial = new Material(uIAtlas.spriteMaterial); uIAtlas.spriteMaterial.set_shader(ResourceUtility.FindShader(shader)); atlasEntry = new AtlasEntry(sprite.atlas, uIAtlas); atlases.Add(atlasEntry); uIAtlas.set_name("_" + sprite.atlas.get_name()); goto IL_0154; }
void ChangeEnemy(int index) { // Replaces the visible enemy Destroy(enemy); displayedEnemyEntry = unlockedEnemyEntries[index]; enemy = Instantiate(displayedEnemyEntry.enemy); DisableBehavior(); enemy.transform.position = displayPosition.position; if (tallEnemy) { enemy.transform.position = new Vector3(enemy.transform.position.x, enemy.transform.position.y + 3, enemy.transform.position.z); } // Replaces the text enemyName.text = displayedEnemyEntry.enemyName; enemyDescription.text = displayedEnemyEntry.description; designer.text = "Designed By: " + displayedEnemyEntry.designer; }
private void RebuildDict( ) { m_oTextureGUIDAtlasEntriesDict = new Dictionary <string, AtlasEntry>( ); if (m_rTextureContainers != null && m_oAtlasEntries != null) { // Build texture <-> atlas entry dict. int iAtlasEntriesCount = m_oAtlasEntries.Length; for (int iAtlasEntryIndex = 0; iAtlasEntryIndex < iAtlasEntriesCount; ++iAtlasEntryIndex) { AtlasEntry rAtlasEntry = m_oAtlasEntries[iAtlasEntryIndex]; string[] rContainedTextureGUIDs = rAtlasEntry.atlasedTextureGUIDs; int iContainedTextureGUIDsCount = rContainedTextureGUIDs.Length; for (int iContainedTextureGUIDIndex = 0; iContainedTextureGUIDIndex < iContainedTextureGUIDsCount; ++iContainedTextureGUIDIndex) { m_oTextureGUIDAtlasEntriesDict.Add(rContainedTextureGUIDs[iContainedTextureGUIDIndex], rAtlasEntry); } } } }
public void Replace(string shaderName) { //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Expected O, but got Unknown //IL_010e: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit(sprite)) { Awake(); if (!Object.op_Implicit(sprite)) { return; } } if (entry != null) { entry.refCount--; entry = null; } if (atlases.TryGetValue(sprite.atlas, out entry) && !Object.op_Implicit(entry.atlas)) { atlases.Remove(sprite.atlas); entry = null; } if (entry == null) { UIAtlas uIAtlas = ResourceUtility.Instantiate <UIAtlas>(sprite.atlas); uIAtlas.spriteMaterial = new Material(uIAtlas.spriteMaterial); uIAtlas.spriteMaterial.set_shader(ResourceUtility.FindShader(shaderName)); entry = new AtlasEntry(uIAtlas); atlases.Add(sprite.atlas, entry); if (MonoBehaviourSingleton <AppMain> .IsValid()) { uIAtlas.get_transform().set_parent(MonoBehaviourSingleton <AppMain> .I._transform); } } entry.refCount++; sprite.atlas = entry.atlas; }
private void FindAllEntries(BuildTarget buildTarget, List <SpriteEntry> spriteEntries, List <AtlasEntry> atlasEntries) { var platformString = GetPlatformString(buildTarget); foreach (var guid in AssetDatabase.FindAssets("t:Texture")) { var path = AssetDatabase.GUIDToAssetPath(guid); var importer = AssetImporter.GetAtPath(path) as TextureImporter; if (importer == null) { continue; } // 获取sprite列表 var sprites = AssetDatabase.LoadAllAssetRepresentationsAtPath(path) .Distinct() .OfType <Sprite>() .Where(x => x.packed) .ToArray(); for (var i = 0; i < sprites.Length; ++i) { var sprite = sprites[i]; Texture2D atlasTexture; string atlasName; Packer.GetAtlasDataForSprite(sprite, out atlasName, out atlasTexture); if (atlasTexture != null) { var entry = new SpriteEntry { Path = path, Sprite = sprite, Importer = importer, Texture = SpriteUtility.GetSpriteTexture(sprite, false), AtlasName = atlasName, Uvs = SpriteUtility.GetSpriteUVs(sprite, false), AtlasUvs = SpriteUtility.GetSpriteUVs(sprite, true), AtlasTexture = atlasTexture, }; spriteEntries.Add(entry); } } } // 获取atlas列表 var atlasGroups = from e in spriteEntries group e by e.AtlasTexture; foreach (var atlasGroup in atlasGroups) { var tex = atlasGroup.Key; var texName = tex.name; // 检查是否需要分离alpha通道 var atlasName = string.Empty; var needSeparateAlpha = false; foreach (var spriteEntry in atlasGroup) { var importer = spriteEntry.Importer; atlasName = importer.spritePackingTag; if (!string.IsNullOrEmpty(atlasName)) { var settings = importer.GetPlatformTextureSettings(platformString); var format = settings.format; if (format == TextureImporterFormat.Automatic) { format = importer.GetAutomaticFormat(platformString); } needSeparateAlpha = TextureUtility.IsTransparent(format); } } if (CustomAtlasConfig.ShouldKeepAlpha(atlasName)) { needSeparateAlpha = false; } var entry = new AtlasEntry { Name = texName, Texture = tex, SpriteEntries = atlasGroup.ToList(), NeedSeparateAlpha = needSeparateAlpha, }; atlasEntries.Add(entry); } }
public void GetMesh(VoxelSet <Vec4b> voxels, out int[] indices, out Vec3f[] points, out Vec3f[] normals, out Vec2f[] uvs, out VoxelSet <Vec4b> textureAtlas) { List <int> indicesList = new List <int>(); List <Vec3f> pointsList = new List <Vec3f>(); List <Vec3f> normalsList = new List <Vec3f>(); List <Vec2f> uvsList = new List <Vec2f>(); Dictionary <int, int> vertIdxRemap = new Dictionary <int, int>(); List <Bin> bins = new List <Bin>(); foreach (var poly in AllPolygons()) { // For each connected polygon vertIdxRemap.Clear(); Vec3f normal = Normal(poly.First()); Vec3f maxP = new Vec3f(-1); Vec3f minP = new Vec3f(1024 * 1024); AtlasEntry atlasEntry = new AtlasEntry(); atlasEntry.startVertIdx = pointsList.Count; atlasEntry.normal = new Vec3i( (int)Math.Round(normal.x), (int)Math.Round(normal.y), (int)Math.Round(normal.z) ); foreach (var baseEdge in poly) { // Each triangle that makes up the polygon foreach (var e in new int[] { baseEdge, Next(baseEdge), Prev(baseEdge) }) { // Each vertex of each triangle int vertIdx = Edges[e].vertexIdx; if (!vertIdxRemap.ContainsKey(vertIdx)) { vertIdxRemap.Add(vertIdx, pointsList.Count); pointsList.Add(Points[vertIdx]); normalsList.Add(normal); maxP = Max3f(maxP, Points[vertIdx]); minP = Min3f(minP, Points[vertIdx]); // TODO: Add UV here } indicesList.Add(vertIdxRemap[vertIdx]); } } atlasEntry.vertCount = pointsList.Count - atlasEntry.startVertIdx; // TODO: Add to texture atlas here Vec3f deltaP = maxP - minP; // Determine which dimension is flat int flatIdx = -1; for (int i = 0; i < 3; ++i) { if (deltaP[i] == 0) { if (flatIdx >= 0) { throw new Exception("Two or more flat dimensions found"); } flatIdx = i; } } Vec2i size; if (flatIdx == 0) { size = new Vec2i((int)Math.Round(deltaP.y), (int)Math.Round(deltaP.z)); } else if (flatIdx == 1) { size = new Vec2i((int)Math.Round(deltaP.x), (int)Math.Round(deltaP.z)); } else { size = new Vec2i((int)Math.Round(deltaP.x), (int)Math.Round(deltaP.y)); } atlasEntry.flatDimension = flatIdx; atlasEntry.max = new Vec3i(maxP + new Vec3f(0.5f)); atlasEntry.min = new Vec3i(minP + new Vec3f(0.5f)); Bin b = new Bin(); b.Size = size; b.UserData = atlasEntry; bins.Add(b); } indices = indicesList.ToArray(); points = pointsList.ToArray(); normals = normalsList.ToArray(); //BinPacker bp = new BinPacker(512); BinPacker bp = new BinPacker(512); bp.BinPadding = new Vec2i(2); bp.Pack(bins); bp.MakePow2(); textureAtlas = new VoxelSet <Vec4b>(bp.Width, bp.Height, 1); for (int y = 0; y < textureAtlas.Size.y; ++y) { for (int x = 0; x < textureAtlas.Size.x; ++x) { textureAtlas[x, y, 0] = new Vec4b(0, 255, 0, 255); } } uvs = new Vec2f[points.Length]; foreach (var bin in bp.Bins) { var atlasEntry = (AtlasEntry)bin.UserData; // Copy to atlas var toSlice = textureAtlas.Slice(new Vec3i(bin.Position, 0), new Vec3i(bin.Position + bin.Size - 1, 0)); Vec3i voxelOffset = new Vec3i(0); if (atlasEntry.normal.Dot(new Vec3i(1)) > 0) { voxelOffset = atlasEntry.normal * -1; } else { //voxelOffset = atlasEntry.normal * -1; voxelOffset = new Vec3i(0); } var fromSlice = voxels.Slice( atlasEntry.min + voxelOffset, atlasEntry.max - atlasEntry.min + atlasEntry.Basis() * new Vec3i(0, 0, 1), atlasEntry.Basis() ); if (toSlice.Size.x != fromSlice.Size.x || toSlice.Size.y != fromSlice.Size.y || toSlice.Size.z != fromSlice.Size.z) { throw new Exception(); } /*for (int y = 0; y < toSlice.Size.y; ++y) { * for (int x = 0; x < toSlice.Size.x; ++x) { * toSlice[x, y, 0] = fromSlice[x, y, 0]; * } * }*/ for (int y = 0; y < toSlice.Size.y; ++y) { for (int x = 0; x < toSlice.Size.x; ++x) { if (Vec4b.Dot(toSlice[x, y, 0], new Vec4b(1)) != 0) { ////throw new Exception(); } toSlice[x, y, 0] = voxels[atlasEntry.To3d(new Vec2i(x, y)) + voxelOffset]; //toSlice[x, y, 0] = c; } } // Compute UVs for (int i = atlasEntry.startVertIdx; i < atlasEntry.startVertIdx + atlasEntry.vertCount; ++i) { Vec2f uv = new Vec2f(atlasEntry.To2d(new Vec3i(points[i]))); //uv *= new Vec2f(bin.Size - 1) / new Vec2f(bin.Size); //uv += 0.5f; uv *= (new Vec2f(bin.Size) - 0.01f) / new Vec2f(bin.Size); uv += 0.005f; ///////// //uv *= 0.998f; //uv += 0.01f; uv += new Vec2f(bin.Position); /////// //uv += 0.25f; uv.x /= bp.Width; uv.y /= bp.Height; uvs[i] = uv; } } Console.WriteLine("Total size: {0} x {1}", bp.Width, bp.Height); }