Quantcast
Channel: Questions in topic: "packtextures"
Viewing all 83 articles
Browse latest View live

Texture2D.PackTextures - attempt to determine if texture was scaled

$
0
0
Texture2D.PackTextures scales textures if they don't fit, and I want to avoid that by adding more atlases. The function output is an array of rectangles, so I tried to compare the sum of texture areas before packing, to the sum of those rect areas from output, but the results differ even if I add a single texture, which fits to atlas bounds. My problem is very similar to http://forum.unity3d.com/threads/texture2d-packtextures-currently-decreases-quality-without-alternative.98177/, though I couldn't find an optimal solution for that. Anyone had this problem?

Packing unity textures into atlases

$
0
0
Hello, I'm trying to create atlases, which will hold only textures that weren't scaled down, number of atlases doesn't matter. I'm using Texture2D.PackTextures() for that, but it scales textures down if they don't fit. To avoid that, I tried to sum areas of each texture and compare it to the sum of rectangle areas, but results always differ and I actually don't have any idea how this function computes that. Any clues?

Unity 5.2 Sprite packer too slow

$
0
0
I just switched from Unity 4.6 to Unity 5.2, and after all the trouble of updating various libraries and classes to resolve the compatibility issues, I realized that packing of the sprites into atlases has changed the way it works. Before I was able to repack all Sprites for less then a minute, and now it takes a good 6 hours to do it. Does anyone knows a way to improve the performance of that or if there is a fix coming soon? Thank you in advance.

Texture2D.PackTextures causing seams in atlas?

$
0
0
I generated a texture atlas for some small 32x32 tile textures using PackTextures, but the tiles have seams when rendered. Is there something that can be done to fix this? Note: With my own handmade atlas, seams are only an issue at high mip levels. ![alt text][1] [1]: /storage/temp/63286-screen-shot-2016-02-04-at-63942-pm.png

Saving Textures As Readable In AssetBundles

$
0
0
I am working with a large system using many assetbundles to build a scene dynamically. Currently I am attempting to build texture atlases after the assetbundles are loaded. Each asset bundle is one or more mesh with the required materials referencing textures. The issue I am running into is the textures loaded from the assetbundles are not readable therefore Texture2D PackTextures fails. I understand without the Readable flag the data of the texture is not accessible therefore GetPixels won't work. I am also aware having this flag on will cost more in memory, it is a cost I am willing to bear. One suggested solution is change the importer settings through UnityEditor.AssetPostProcessor. The problem is this works in the editor but not at runtime. When I build the assetbundles the textures are set to "Advanced" and Read/Write Enabled is checked. When I load the assetbundles the textures are not set to readable. I understand this setting is applied to the importer not the texture itself. - Is there a way to access the importer for the assetbundle or texture within at runtime? - UnityEditor.dll is not accessible outside the editor (at runtime) so how are you to handle importer logic or set specific Textures to be Readable outside the editor? I am in Unity 5.2 now but would be open to move to Unity 5.3 if there is a viable solution to this issue. Thank you, Matt

How do I make my textured models pull the source images for the textures in a package?

$
0
0
If you dont feel like reading all of this and you probably wont understand it because i dont. Watch this quick video I made, just watch my cursor and it should explain it to you. https://youtu.be/nb7_3brTUHY Sorry if the title is confusing, but I need help and have no other way of explaining this. So I have made models in blender and have and textured them. Once I put them in Unity and put the textures on and configure it to my liking. Then i package up the model and the textures and images that go with it and store it on my computer as a UnityPackage File. After i've done that to multiple models I try to test it out. Some of my models use the same image for textures and when they both enter Unity they go their places in the materials folder. But because there should be 2 with the same file name one is deleted and the model that the image was designated to comes up with no color. I can re-link it manually but its a pain and when i try to make a final project, it will be too overwhelming. Thanks in advance. (if you didnt get it watch the video)

One Texture2D from multiple others

$
0
0
Hi guys!, I've been struggling to find a proper way to create a new Texture2D based on multiple others. The Idea is that I dynamically load up a list of Textures2D form a certain folder (that's done). so I have this list of textures. What I want to do is to create a new Texture that has every texture on the list in such a way that it has 1 column and X rows where X is the count of the list. That way I'll end up having one texture with every texture of the list in 1 column and I can use this to create a particles system. So the problem is generating this master texture. Can anybody help me do this?. Thanks!

Have there been changes to PackTextures in 5.6 ? Seeing Artifacts in Scene which disappear in 5.5

$
0
0
I'm getting some artifacts in a scene when moving to 5.6, which is using Texture2D.PackTextures. Changing the Padding for PackTextures down to 0 or 1 fixes the problem, anything above that seems to introduce errors, especially in Rects that are near the border of the Atlas Image that is being packed into. Were there any changes to PackTextures in 5.6 ? Or any other changes under the hood that may affect floating point math ? Moving back to 5.5 fixes the problem immediately. ![alt text][1] [1]: /storage/temp/91163-unity56problem2c.jpeg

PackTextures works in editor but not on iPad/iPhone ...

$
0
0

Hiya all.

I've made a script which loads some objects, instantiates them and then uses PackTextures() to make a texture atlas so they all use one draw call. Simple enough I thought.

It works fine in the editor but when i load it to iPad/iPhone the textures are distorted. They look a bit like this image, but more pixelated:http://www.athlens.com/myspace-backgrounds/multicolor/color_multicolor_186.jpg.

Here's my code. It's a little messy as I've not had any time to tidy it up.

    public static bool showMainGUI = true;
    public int iconWidth = 30;
    public int padding = 15;
    public Material newMat; //Created and assigned in inspector
    private GameObject[] tools;
    private Texture2D packedTexture = new Texture2D(1024,1024);

    private void Start()
    {
        useGUILayout = false;
        Object[] temp = Resources.LoadAll("Icons", typeof(GameObject));
        tools = new GameObject[temp.Length];
        Texture2D[] oldMats = new Texture2D[tools.Length];
        int xPos = 50;
        for(int i = 0; i<temp.Length; i++)
        {
            Vector3 instPoint = Camera.main.ScreenToWorldPoint(new Vector3(xPos,18,1));
            tools[i] = Instantiate(temp[i],instPoint,Quaternion.identity) as GameObject;
            tools[i].transform.parent = Camera.main.transform;
            // Cache old materials so they can be packed into atlas
            oldMats[i] = tools[i].renderer.material.mainTexture as Texture2D;
            xPos+=iconWidth+padding;
        }
        // Pack textures and assign atlas to our new material
        Rect[] texUVs = packedTexture.PackTextures(oldMats,0);
        newMat.mainTexture = packedTexture;

        // Assign new material to objects and adjust UVs accordingly
        for(int i = 0; i<tools.Length; i++)
        {
            tools[i].renderer.material = newMat;
            Vector2[] originUV = (tools[i].GetComponent(typeof(MeshFilter))as MeshFilter).mesh.uv;
            Vector2[] newUV = new Vector2[originUV.Length];
            for(int k = 0; k<originUV.Length; k++)
            {
                // Recalculate UV
                newUV[k] = new Vector2((originUV[k].x*texUVs[i].width)+texUVs[i].x,
                                        (originUV[k].y*texUVs[i].height)+texUVs[i].y);
            }
            // Reassign UVs
            (tools[i].GetComponent(typeof(MeshFilter))as MeshFilter).mesh.uv = newUV;
        }
    }

Any help would be greatly appreciated as I'm starting to get a little tired of the inconstencies between the Unity editor and the actual build.

Is it possible to get the atlas for a font texture?

$
0
0

Using the PackTextures method returns an array of indexes of all the different textures in a given texture atlas, apparently. That's hugely useful, and I assume that with the font textures Unity is doing something similar so that it can effectively render text in a given font when given a string as input.

My question is: can I get access to that array (and also the characters that map to each array index)? It seems pretty definite that Unity has that information internally, and normally I wouldn't need it, but I want to be able to get at the font texture and then use GetPixels to extract a single character at a time out, and then composite those into another texture.

My goal is just to composite some drawn fonts onto custom textures of my choosing. RenderTextures can't have a transparent background, to my knowledge, and they seem awkward and troublesome in general. But I am using Unity Pro, so I have access to that if absolutely necessary.

PackTexture not packing correctly?

$
0
0

I have a script with this

public Texture2D[] World_Textures; public Texture2D WorldTextureAtlas; private Rect[] m_WorldTextureAtlasUvs;

Later, I do this for the atlas generatio:

WorldTextureAtlas = new Texture2D(2048, 2048); m_WorldTextureAtlasUvs = WorldTextureAtlas.PackTextures(World_Textures, 0); Debug.Log(WorldTextureAtlasUvs[0]);

Now, I currently only have two textures in Texture2D[] World_Textures , both are 256x256.

However, the atlas I get back stretches them to an atlas of 512x512...effectively doubling the height of my textures and their uvs. The debug statement shows this:

> (left:0.00, top:0.00, width:0.50, height:1.00) UnityEngine.Debug:Log(Object)> World:InitializeTextures() (at Assets/Scripts/World.cs:58)> World:Start() (at Assets/Scripts/World.cs:41)

Any idea why this is?

Texture2D.PackTextures() - maximumAtlasSize

$
0
0

The manual says PackTextures() will create an atlas that has a maximum size of maximumAtlasSize, if the textures don't fit in there they will be downscaled. I have some rather long animations, that would require an atlas that is at least 2048x2048 pixels big. However for some reason PackTextures() will always create a 1024x1024 texture and downscale everything to fit in there. The result is suboptimal at best. If I pass 2048 or 4096 as maximum size it will still generate a 1024 texure. If I set it to a smaller value (e.g. 512) it will create a smaller texture (512x512). So the question is how do I get PackTextures() to create textures of sizes > 1024x1024??

PackTextures() resultant texture completely black

$
0
0
Hey so I'm trying to create a spritesheet and it seems to work fine when I set the maximumAtlasSize arguement to a size where I know the final texture would not fit causing it to downsample. Other then setting that to something really large where I know that the final texture would fit, the sprite atlas shows up black but at the correct size. I don't know what's going on Here's some of the code: static void GenerateSpriteSheet() { Object[] textureObjects = (Object[])Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets); int textureCount = textureObjects.Length; if (textureCount <= 0) return; Texture2D[] textures = new Texture2D[textureCount]; for (int i = 0; i < textureCount; ++i) textures[i] = (Texture2D)textureObjects[i]; string newSpriteSheetPath = "Assets/Game Assets/Resources/Spritesheets/NewEntries/"; // Texture Texture2D packedTexture = new Texture2D(1024, 1024, TextureFormat.ARGB32, true); Material newMaterial = new Material(Shader.Find("Transparent/Cutout/Diffuse")); Rect[] uvs = packedTexture.PackTextures(textures, 1, 1024); newMaterial.mainTexture = packedTexture; //set the main texture of the newMaterial as the new packed textures... packedTexture.Apply(); EditorUtility.CompressTexture(packedTexture, TextureFormat.ARGB32); string fileName = newSpriteSheetPath + "NewSpriteSheet-Texture.png"; byte[] bytes = packedTexture.EncodeToPNG(); File.WriteAllBytes(fileName , bytes); AssetDatabase.ImportAsset(fileName ); packedTexture= (Texture2D)AssetDatabase.LoadMainAssetAtPath(fileName ); EditorUtility.SetDirty(packedTexture); AssetDatabase.ImportAsset(fileName ); AssetDatabase.CreateAsset(newMaterial, newSpriteSheetPath + "NewSpriteSheet-material.mat"); AssetDatabase.SaveAssets(); }

Procedural Mesh with visible seams

$
0
0
Hello, I've been working on proceduraly generated meshs with variable size. At the moment it's just a big square although I intend it to have holes in the future. Because I want those meshes to have multiple textures that I will get through WWW I am creating an atlas texture map (through PackTexture) but when I use the atlas, the squares' seams become noticeble. If I use a material with a single texture the seams are not visible. I've been searching the web but so far I have yet to figure out why this is happening. The way I generate the mesh is: For each cell I create four vertices, then two triangles and finaly UV's. The UV's are based on the Rect list obtained from Texture.PackTextures. The generating code: using UnityEngine; using UnityEditor; using System.Collections; public class MeshCreator : MonoBehaviour { public Texture2D tex1; public Texture2D tex2; public Texture2D tex3; public Texture2D atlas; void Start () { GetComponent().enabled = false; Texture2D[] texs = new Texture2D[3]; texs[0] = tex1; texs[1] = tex2; texs[2] = tex3; /*foreach (Texture2D texture in texs) { string path = AssetDatabase.GetAssetPath(texture); //Debug.Log("path: " + path); TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; textureImporter.isReadable = true; AssetDatabase.ImportAsset(path); }*/ atlas = new Texture2D(0, 0); Rect[] texUVS = atlas.PackTextures(texs, 0, 2048); Mesh myMesh = new Mesh(); int XX = 10, YY = 10;// 10x10 Mesh int CellSize = 2; int NumCells = XX * YY; int NumTriangles = NumCells * 2; // Each cell has 2 tris int NumVertices = NumCells * 4; // Each cell has 4 verts int p0, p1, p2, p3; Vector3[] verts = new Vector3[NumVertices]; int[] triangles = new int[NumTriangles * 3]; Vector2[] uvs = new Vector2[NumVertices]; for(float c = 0, x = 0, z = 0, v = 0, t = 0; c < NumCells; c++, x+= CellSize, v+=4, t+=6) { if( c % XX == 0 && c > 0) { x = 0; z+= CellSize; } p0 = (int)v; p1 = (int)v + 1; p2 = (int)v + 2; p3 = (int)v + 3; verts[p0] = new Vector3(x,0,z); verts[p1] = new Vector3(x + CellSize,0,z); verts[p2] = new Vector3(x,0,z + CellSize); verts[p3] = new Vector3(x + CellSize, 0, z + CellSize); // tri 1 triangles[(int)t] = p2; triangles[(int)t+1] = p1; triangles[(int)t+2] = p0; // tri 2 triangles[(int)t+3] = p2; triangles[(int)t+4] = p3; triangles[(int)t+5] = p1; //uvs int r = Random.Range(0,(texUVS.Length )); uvs[p0] = new Vector2(texUVS[r].xMin, texUVS[r].yMin); //(0,0) uvs[p1] = new Vector2(texUVS[r].xMax, texUVS[r].yMin); //(1,0) uvs[p2] = new Vector2(texUVS[r].xMin, texUVS[r].yMax); //(0,1) uvs[p3] = new Vector2(texUVS[r].xMax, texUVS[r].yMax); //(1,1) /* uvs[p0] = new Vector2(0.0f, 0.0f); uvs[p1] = new Vector2(1.0f, 0.0f); uvs[p2] = new Vector2(0.0f, 1.0f); uvs[p3] = new Vector2(1.0f, 1.0f);*/ } myMesh.vertices = verts; myMesh.triangles = triangles; myMesh.uv = uvs; myMesh.RecalculateNormals(); myMesh.RecalculateBounds(); myMesh.Optimize(); GetComponent().mesh = myMesh; GetComponent().sharedMesh = myMesh; GetComponent().material.mainTexture = atlas; GetComponent().enabled = true; } } And here's a picture using a black texture in the atlas: ![alt text][1] [1]: http://img710.imageshack.us/img710/3418/seams.jpg Thank you.

PackTexture doesn't work in flash platform?

$
0
0
I'm trying to port my project to flash. And I get an error "Texture atlas needs textures to have Readable flag set!" from this line of code. rectUV = texture.PackTextures(inputTexture, padding, 1024, true); This works perfectly fine in PC and iOS. I've already set read/write enable of every textures in inspector. Is this a bug or not?

PackTextures doesn't work when packed texture greater than 2048x2048

$
0
0
I packed a lot of textures into a large one(max size: 2048). In unity3.4, if the packed texture greater than max size, it scale down to fit. But in unity3.5, it doesn't scale down correctly, each little texture is cut off(about 1/3), except I reduce textures till packed texture less than max size. I don't know why it doesn't scale down correctly.

Is there a way to cap the max mipmap level of a generated texture?

$
0
0
Hi, Does anyone know how to solve this problem? ![alt text][1] I think it's related to this post: http://forum.unity3d.com/threads/889...-Mipmap-Levels Is there a way to cap the max mipmap level of a generated texture atlas (using Texture2D.PackTextures())? (from the picture above, mip level 5 would be the solution for this issue) If not, is there a shader workaround? TIA, R. [1]: http://forum.unity3d.com/attachment.php?attachmentid=32836&d=1333161607

Sprite Atlas Generation in android build

$
0
0
Alright, so this is my first post on the Unity forums. So excuse my ignorance of any unwritten rules. I have built an automatic sprite atlas generator, that searches my project for specific scripts and constructs an atlas from them. This all works fairly well, I have even been able to make use of this for my 3D game objects, by setting the UVs accordingly. However, I am running into a bit of an issue. Its not major but I am trying to clean up my tool for quicker use. Essentially, I use PackTextures to build the texture, convert it to ARGB32 and then into my desired format (be it DXT or PVRTC etc). This however, seems only to work correctly when my build settings are set to PC Standalone, not Android or iOS. Texture2D newTexture = new Texture2D(maxSize , maxSize , format , enableMipMapping); _TextureRects = newTexture.PackTextures(textures.ToArray() , padding , maxSize , makeNoLongerReadable); Texture2D correctedTexture = new Texture2D(newTexture.width , newTexture.height , TextureFormat.ARGB32 , enableMipMapping); correctedTexture.SetPixels(newTexture.GetPixels()); EditorUtility.CompressTexture(correctedTexture , format , TextureCompressionQuality.Normal); The UVs seem to be remapping correctly regardless of platform. It seems to be the generated texture that is causing the issue. As shown below: ![alt text][1] (As seen on PC) ![alt text][2] (As seen on Android) Any help, would be greatly appreciated. Thanks in advance! [1]: http://answers.unity3d.com/storage/temp/874-StdAlnCap.png [2]: http://answers.unity3d.com/storage/temp/875-AndroidCap.png

Need help packing menu textures

$
0
0
I have a menu that is essentially a background image and 4 buttons using GUITextures. What I'm trying to do is get the buttons into one draw call. My idea is to use the [PackTextures()][1] function to create an atlas, but I need help! I'm unfamiliar with non-runtime code and was wondering if someone could give me the basics of how I'd go about replacing my buttons into one atlas and getting them back into the scene? I'm thinking something along the lines of… 1. Create temporary GameObject 2. Attach the button textures as an array 3. Run PackTextures() function on array to create atlas 4. Delete/disable the temp GameObject 5. Find the resulting atlas [where?] and attach it to all 4 buttons 6. Get the rect coordinates [how?] 7. Specify the rect coordinates to each GUITexture component so it knows which area of atlas to use [also how?] [1]: http://unity3d.com/support/documentation/ScriptReference/Texture2D.PackTextures.html

Black lines after using PackTextures()

$
0
0
I have a tiled based game and to increase performance I'm attempting to use PackTextures() to pack a lot of ground tiles into one texture and use the same material. I got everything working but my result ended up in black lines showing around the tiles. There are 6 different types of grass tiles, that are randomly chosen herein the picture below. ![alt text][1] I tried adding padding to PackTextures with the same results. Does anyone know how to fix this? Thanks! [1]: /storage/temp/1765-screen+shot+2012-07-09+at+3.07.10+pm.png
Viewing all 83 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>