Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Texture Packer + Unity Tutorial

Discussion in 'Community Learning & Teaching' started by stanislav-osipov, Jun 2, 2013.

  1. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    This is a tutorial on how to use the TexturePacker extension for Unity. There are two different versions of TexturePacker – The stand alone TexturePacker, and the TexturePacker Unity Extension. Both have a limited function free version in addition to the full version.

    To get started as quick as possible, here is Video Tutorials Section (will be upgraded shortly)

    Basicly tutorial is splitted in 3 parts.

    • Introduction
    • Using with 3D object’s (animation, automatic UV)
    • Using with GUI (drawing GUI textures from Atlas, GUI Animation)


    Introduction.

    Why you should use texture atlases in your game:
    • Reduced build size
    • Reduced RAM consumption
    • Increased performance


    Why use TexturePacker?
    TexturePacker will allow you to easily and quickly create texture atlases for your game.
    • Rotation
    • Trimming / cropping
    • Scaling
    • Smoothing
    • Note: Some features are not available in the free version

    Learn More here:
    http://www.codeandweb.com/texturepacker

    Why use the TexturePacker Unity Extension?

    Unity GUI
    • Draw textures from the atlas
    • Supports TexturePacker features (rotation. crop, trim)
    • GUI animations

    3D object
    • Auto generation of UV coordinates for Meshes
    • Rotated images for optimal space
    • Play animations from atlas
    • Preview in editor mode
    • Note: Some features are not available in the free version


    Using with 3D objects

    TexturePacker is available for download here:
    http://www.codeandweb.com/texturepacker/download

    The TexturePacker Unity extension is available here:
    Free
    https://www.assetstore.unity3d.com/#/content/8905
    Paid
    https://www.assetstore.unity3d.com/#/content/8456


    Creating the Texture Atlas:

    For the first tutorial, we’ll pack textures for our scene (Assets are available in the TexturePacker Extension package under Assets/Extensions/TexturePacker/Tutorial/Art/AtlasSource).

    Open TexturePacker, and simply drag the textures inside. Now let’s configure our atlas.


    Output Options
    Data Format: Unity3D
    Data File: YourProject/Assets/Resources/TutorialAtlas_data.txt Texture File: YourProject/Assets/Resources/TutorialAtlas.png
    Texture Format: png

    Geometry Options
    Check the “Force Squared” toggle

    Layout Options
    Algorithm: MaxRect (Full version only) or Basic (available in the free version)
    Allow Rotation: checked (Full version only) unchecked (free version)
    Trim mode: none (Trim mode is only supported for GUI rendering)

    Note
    I has described most optimal options, but you can experiment with TexturePacker option to get the best result for your atlas.

    Next, press the Publish button. Your altas should look like this:

    Free version:
    $TutorialAtlasFree.png
    If you do not see the image, you can view the image by clicking directly on the URL


    Paid version:
    $TutorialAtlasPro.png
    If you do not see the image, you can view the image by clicking directly on the URL

    Atlas is ready, so we need material for it.

    In Resources Folder Create->Material. Set material name as TutorialAtlasMaterial, attach TutorialAtlas.png as main material texture and change shader to Transparent->Diffuse.

    *Note: The material will be created automatically by Asset Processor editor script. But you can create any number of other materials with different shader for atlas.


    Using the texture atlas with a model:

    Using the texture atlas with a model:
    (Assets/Extensions/TexturePacker/Tutorial/Art/Models/Sword/sword_01)

    It already has a texture and a material assigned. Replace this with a texture from the atlas:


    1. Select the sword_01 gameobject (the one with the MeshRenderer component attached).
    2. Attach TPMeshTextureEx component (TPHelper component will be added automaticly)
    3. Choose Atlas and Texture in TPHelper menu
      • Atlas: TutorialAtlas
      • Texture: sword_01_dif
    $13 3-07 AM.png

    If you do not see the image, you can view the image by clicking directly on the URL

    The sword is now using the texture from the atlas.

    *Note: Do not attach TPMeshTexture component, it will casue component lost if you replace TexturePacker.dll. Use it only for extending.

    Using the texture atlas with skinned model
    The usage is similar to a simple model.

    1. Select the sword_01 gameobject (the one with the SkinnedMeshRenderer component attached).
    2. Attach TPSkinnedMeshTextureEx component (TPHelper component will be added automaticly)
    3. Choose Atlas and Texture in TPHelper menu

    Play an animation from the atlas:
    This approach is only useful if you want play animation on YOUR mesh (not simple plane). Trim / Crop is not supported with this approach. If you just want to play animation on plane from atlas, please follow Creating Sprite Animation steps. It has additional features implemented as:
    • Trim / Crop support
    • Animation can contain frames from different atlases.

    For the next tutorial, we will play an animation from the texture atlas on a cube:
    1. Create a cube in the scene by selecting GameObhect->Create Other->Cube
    2. Change the material on the cube to TutorialAtlasMaterial
    3. Attach a TPMeshAnimation component
    4. Configure the TPMeshAnimation component options as follows:
      • Atlas: TutorialAtlas
      • Frames: add 6 frames fireball_0001, fireball_0002, fireball_0003, fireball_0004, fireball_0005, fireball_0006
    The component should look like this:
    $anim.png
    If you do not see the image, you can view the image by clicking directly on the URL


    Now press play and you will see fireball animation playing on the cube. You can try other meshes and experiment with different TPMeshAnimation options.

    You always can automate this process using extensions, there are a few examples of how do this inside the package. See the MyFireAnimation, MyTeslaAnimation and MyMeshTexture classes.


    The complete scene can be found here:Assets/Extensions/TexturePacker/Tutorial/Scenes/AtlasesAnim

    The demo scene uses only one atlas. The entire scene with almost 100 objects and 50 animations has only 1 Draw Call, 1 Texture, and uses only 1MB of memory.

    You can view a preview of the scene in the web player here:
    https://dl.dropboxusercontent.com/u/83133800/TexturePacker/3D/build.html

    Screenshot:
    $preview.png

    Optimization.

    There are further optimizations that can be done.
    The scene uses only one texture for the whole scene - already good benefit - but we can squeeze even more. The size of our texture is 754x754, if we had choose RGBA 32 compression it would have consumed 2.2 MB. But setting the compression to PVRTC and stretching the texture to 1024 * 1024 (compression works only with POV2 textures) changed the memory consumption to only 1MB. With just a little quality loss, it can be scaled down to 512x512, reducing memory consumption to only 256KB.
    The POV2 TexturePacker options allow you to always see how many textures you can add to your atlas.




    Using with GUI


    For the next tutorial, we will use the same atlas from our 3D scene, But you can always experiment and create new one, using the source GUI textures which are located under Assets/Extensions/TexturePacker/Tutorial/Art/AtlasSource.

    The difference between creating a texture for a 3D object and for use in the GUI is that for GUI atlases you can use the Trim / Crop TexturePacker methods to save even more space (this option is available in paid version of TexturePacker)


    First, we need to create our GUI drawing class. And assign it to a GameObject.
    Here is an overview of some useful snippets for working with the GUI part of the TexturePacker extension.


    Getting the Atlas:

    Code (csharp):
    1. TPackManager.getAtlas(MyAtlasName);
    Getting the Texture:
    Code (csharp):
    1.  
    2. TPAtlas atlas = TPackManager.getAtlas(MyAtlasName);
    3. TPAtlasTexture texture =  atlas.getTexture("myTextureName");
    4.  
    Or

    Code (csharp):
    1.  
    2. TPAtlasTexture texture = TPackManager.getAtlas(MyAtlasName).getPngTexture("myTextureName");
    3.  
    Drawing a texture:

    Code (csharp):
    1.  
    2. void OnGUI() {
    3.     TPackManager.draw(Rect rect, string atlas, string textureName);
    4. }
    5.  
    AtlasGUIExample – an Example GUI class to draw textures from the atlas:

    Code (csharp):
    1.  
    2. public class AtlasGUIExample : MonoBehaviour {
    3.  
    4.     private TPAtlasTexture play;
    5.    
    6.     private Texture2D unityTexture;
    7.    
    8.    
    9.     void Awake() {
    10.         play = TPackManager.getAtlas(Atlases.EXAMPLE).getPngTexture("play");
    11.        
    12.         //Warning to Get Texture2D from atlas, should remain the same size which was generated,
    13.         //that's why we using another atlas here
    14.  
    15.         unityTexture = TPackManager.getAtlas(Atlases.EXAMPLE2).getUnityTexture("play");
    16.     }
    17.    
    18.    
    19.    
    20.     void OnGUI() {
    21.         play.draw(new Rect(0, 0, play.width * 0.5f, play.height * 0.5f));
    22.        
    23.         play.draw(new Rect(0, 75, play.width, play.height));
    24.        
    25.         GUI.DrawTexture(new Rect(0, 225, unityTexture.width, unityTexture.height ), unityTexture);
    26.        
    27.        
    28.        
    29.         TPackManager.draw(new Rect(200, 0, 122, 42), Atlases.EXAMPLE, "f_share.png");
    30.         TPackManager.getAtlas(Atlases.EXAMPLE).draw(new Rect(200, 100, 122, 42), "t_share.png");
    31.        
    32.        
    33.     }
    34.  
    35.  
    36.  
    AtlasGUIAnimationExample – An example GUI Animation class - (GUI animation is not available in the free version). Using the same atlas as for our 3D scene above.


    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class AtlasGUIAnimationExample : MonoBehaviour {
    6.  
    7.    
    8.     private TPGUIAnimation anim;
    9.     private TPGUIAnimation Scaledanim;
    10.    
    11.    
    12.     void Awake() {
    13.         anim        =  TPGUIAnimation.Create();
    14.         Scaledanim  =  TPGUIAnimation.Create();
    15.        
    16.         for(int i = 1; i < 7; i++) {
    17.             TPAtlasTexture frame = TPackManager.getAtlas(Atlases.EXAMPLE).getPngTexture("fireball_000" + i.ToString());
    18.             anim.addFrame(frame);
    19.             Scaledanim.addFrame(frame);
    20.         }
    21.        
    22.         anim.pos = new Vector2(200, 200);
    23.         anim.loop = true;
    24.         anim.fps = 25;
    25.         anim.Play();
    26.        
    27.         Scaledanim.pos = new Vector2(300, 200);
    28.         Scaledanim.loop = true;
    29.         Scaledanim.fps = 25;
    30.         Scaledanim.scale = 0.5f;
    31.         Scaledanim.Play();
    32.        
    33.        
    34.        
    35.     }
    36.    
    37.     void OnGUI() {
    38.         anim.draw();
    39.        
    40.         Scaledanim.draw();
    41.     }
    42. }
    43.  
    44.  
    You can view this here in the web player:
    https://dl.dropboxusercontent.com/u/83133800/TexturePacker/previewGUI/previewGUI.html

    In conclusion, here are some of the advantages you will get from using TexturePacker:
    • Fast and easy atlas generation
    • Easy to remove and/or add texture from the atlas
    • Built in animation solution
    • Reduced build size
    • Reduced RAM consumption
    • Increased performance

    Special Thanks:

    NassacGames for free 6 Medieval Shields pack package, it was used
    for building graphic part.

    Jaimi, eskimojoe for help with this tutorial.

    If you have any comments, questions or suggestions, feel free contact support team via e-mail: stans.assets@gmail.com

    I hope you enjoyed the tutorial and good luck with your game :)
     
    Last edited: Oct 30, 2014
  2. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    - I do not see my atlas in TPHelper drop down menu.

    Your atlas wasn't registered by TPAssetProcessor.
    • Did you put atlas file inside Resources folder?
    • Is data file has "_data.txt" postfix?
    • Did you use Unity3D format when generating atlas in Texture Packer?
    • If you steel have the same issue, please contact me by e-mail.


    - I have big performance hit when instantiating character with TPSkinnedMeshTextureEx or MeshTextureEx attached, how to fix this?

    It happens because script creates new mesh with recalculated UV on Awake. That makes you available to use same mesh for different textures. But this kind of behavior can cause performance hit on object Instantiate. Problem is mostly actual for big meshes, characters for example.
    You can fix this by checking "Use Shared Mesh" on TextureMesh component. It will remove mesh recreation and UV calculation, but you would not able to use this mesh for different atlas texture.


    - I've create second material for my atlas with another shader, but I can not assigned it to the model.

    Uncheck "Replace Material" on TPHelper component. Now you able to assign any material to your model.


    After importing your tools, is it possible to move them to another location?

    You can move it anywhere you what to. It absolutely not place related.
    The only one exception is Asset/Plugins folder. Unity will not look for Editor folder there. If you want to place this tool inside Asset/Plugins folder, then you have to move Editor folder of TexturePacker in any other place.

    I try to replace a texture in TpMeshTextureEx on the Play mode , it just switches variables(tx/texture) but it does Not refreshes The visible texture/result .

    After you change texture name or path to the atlas you should call applayUV function of TPMeshTexture component. It will recalculate UV and you will get visible result.
     
    Last edited: Jul 31, 2013
  3. betaalpha

    betaalpha

    Joined:
    Apr 28, 2013
    Posts:
    6
    Hi - cheers for making such a useful extension. I thought I'd let you know about a bug I found and how I fixed it. My game's platform textures go into an atlas via Texture Packer. I use the same mesh for three platforms of different sizes - ranging from 10x10x10 meters to 30x10x30 meters. I use non-uniform scale on the 30x10x30 game object to enlarge it - scale values X3, Y1, Z3.

    I discovered that that messed with the UVs, causing the textures to get misaligned on each surface.

    This was happening because I applied the non-uniform scale on the game object that contained the mesh and your texture packer components. So I changed it to being X1, Y1, Z1 and made it a child of another game object that had the X3, Y1, Z3 scale values. The UV properties were now fine, the mesh was extended to the right dimensions and all was good.

    Let me know if that was unclear - I can upload pictures and further explain.
     
  4. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    I'm having trouble getting this to work at all. I'm pretty sure I'm following the steps, but all I end up with is flat shading on the models.

    Any ideas what I might be doing wrong?

     
    Last edited: Aug 20, 2013
  5. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Okay... exited Unity, relaunched, and everything is now fine. Very odd, but working :)
     
  6. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Hi SteveJ, Thanks for sharing your experience. I assume that atlas was changed from external source withour reimport.

    Let me explain little bit more.

    • After Atlas was imported, frames data was cashed.
    • Atlas was changed from external source, but frames data wasn't recalculated
    • After you exited Unity (or just triggered asset reimport by any other action, modifying script fro example ) frame data was recalculated.

    This is very rare but know issue and it already fixed in upcoming version. Texture Packer 2.0 already submitted.

    Few spoilers about version 2.0
    • It will have a Editor windows and custom inspectors
    • Solution for "on plane" animation with Trim/Crop and An
    • You will be able to preview animation in editor mode.


    I'll do full announce as soon as it will be available.
     
    Last edited: Aug 20, 2013
  7. Pardue

    Pardue

    Joined:
    Aug 20, 2013
    Posts:
    2
    Edit: This issue has been solved and was not due to TexturePacker.

    Hi lacost, thanks for the tutorial. I am hoping you can help me out with an issue I am having with achieving pixel perfect renders in a simple game. My problem seems to be that in play mode I lose the top line of pixels on my plane. I think it is best to just show you what is going on. This is a basic tile I created in Photoshop followed by the same tile taken from the atlas texture that TP created.

    $BaseTile.png $atlasTile.png

    Both are the same. My camera is set to orthographic, size 320, and my game aspect is set to 960x640. I have created a basic 2 tri mesh that is 64 units by 64 units and has no material. (The rightmost object in pics) I then duplicated that mesh and added the TPMeshTextureEx script and picked the Atlas texture and the corresponding png from the texture drop down list. (The middle object in pics) I also created a primitive cube and scaled it to (64,64,1). (The leftmost object in pics) The following is a screen capture from the game view in Unity.

    $PlayTile.png

    I spaced the two planes and cube so there is one unit in between them. You may have to zoom in your browser to get a better look but the middle tile is short one row of pixels at the top. The following is a screen capture of the exact same setup in the editor view.

    $EditorTile.png

    You can see the one pixel or one unit offset in between the tiles, but in the editor I am not having a problem with missing the top pixel row. In the texture settings for the atlas texture I have turned off Generate Mip Maps and have used both Clamp and Repeat for Wrap Mode, and I have the Filter Mode set to Point. I have played around with various Max Size and Format settings as well without being able to solve my problem. I am using the built-in Unlit/Transparent shader on the middle tile, the basic primitive shader on the leftmost tile and obviously no shader on the rightmost tile.

    I am at a loss as to how to fix this. My best guess is that it has to do with the UV's, and maybe precision due to float values, but I am not sure.

    Any assistance or insight or information you can provide me that may assist me with wrapping my brain around this would be much appreciated. Thanks... :)
     
    Last edited: Aug 21, 2013
  8. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Hi, Pardue.
    I need closer look to understand what you trying to achieve, and provide some help.
    Pm sent.
     
  9. Pardue

    Pardue

    Joined:
    Aug 20, 2013
    Posts:
    2
    So my issue has nothing to do with TexturePacker as I can create the same issue without TexturePacker. I also don't seem to have the issue on my other computer and I found the issue goes away if I move the tiles up and over .5 units. Thanks lacost for all your assistance, the support with TexturePacker has been outstanding!
     
  10. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Animation in Texture Packer 2.0

    2.0 version contains more advanced function for sprite render and sprite animation. Main features:
    • Trim / Crop, Rotation and Scale support
    • Full Editor integration
    • You can use frames for one animation from different atlases
    • Animation preview in editor
    • Draw calls batching

    Note: This is “on mesh” animation, it doesn't use Unity GUI system. To play animation using Unity GUI, please read about plugin GUI classes.

    Creating Sprite Animation

    You can use your or tutorial atlas to create 2D sprite animation.
    Go to the
    Game Object -> Create Other -> Texture Packer -> Sprite Animation
    This will create new TP Sprite Animation object.
    Now you can add some frame to the animation. Press Add button. Add button will call Texture Packer custom window or bring it up, if you already have it.

    Note: For opening Texture Packer custom window go to the Windows-> Texture Packer.
    $skitch.png
    If you do not see the image, you can view the image by clicking directly on the URL

    In Texture Packer window, just select frames for your animation. You can use Ctrl/Cmd and Shift button to easily select frames you want for this animation. After frames are selected press “Add to animation” button.
    Note: You can add more frames from different atlas (just switch) atlas in Texture Packer window and add another frames. And of course you can add the same frames multiple times to the animation if you want to.

    $skitch (1).png
    If you do not see the image, you can view the image by clicking directly on the URL

    $skitch (2).png
    If you do not see the image, you can view the image by clicking directly on the URL

    That is it. That is all you have to do to set up the sprite animation from atlas.

    Creating Simple Sprite

    That is useful if you want atlas texture to be rendered on simple plane Mesh, or if you want trim support. Go to
    Game Object -> Create Other -> Texture Packer -> Sprite Texture
    And follow the same steps as form Creating Sprite Animation.

    Texture Packer Window

    $skitch (3).png
    If you do not see the image, you can view the image by clicking directly on the URL

    • Atlas choose drop down. Use it to switch between atlases in your project.
    • Adds selected frames to the selected sprite animation.
    • Toggle between display or not display frames extension.
    • Search field. Start typing in this search field to filter frames result
    • Cancel search. Press this button to disable filter and clear search field.

    Sprite Animation Inspector

    $skitch (4).png
    If you do not see the image, you can view the image by clicking directly on the URL

    • Info Box. It will display useful information about the animation
    • Animation settings:
      1. Gizmos Color. Color of the box around animation.
      2. Current Frame. Current frame of animation which is displayed in editor. When you press play animation will start playing from this frame.
      3. Frame Rate. Frame rate of selected animation.
      4. Play On Start. If this option is active, animation will start playing when animation game object will receive Unity Start event.
      5. Loop. If the options is active, animation will play a round.
      6. Force Selection. When you selecting animation by clicking on it in the editor scene, Game object with TPSpriteAnimation component will be selected instead animation sprite. To disable this behaviour uncheck this select box.
    • Control buttons:
      1. Add. Button will open Texture Packer window, or bring it up if already opened.
      2. Clear. Clear all animation frames.
      3. Update. Update animation view. Can be useful if something goes wrong, and view wasn’t updated automatically.

    Optimization tips
    Last Optimization section was about RAM and Texture Atlases size saving. Let’s talk about CPU. One of the main features of this extension is Draw Calls saving. This is possible thanks Unity Dynamic batching.
    When you creating different animation they use the same material with make dynamic batching possible. To use it with the full power you should understand how the dynamic batching work, and render part of this extension work.

    When the sprite animation is running it applying new scale and local position to the sprite every frame. It means that TP Sprite is always non-uniform object. With means it can be batched with other non-uniform objects, but if you will use the same material on object with uniform scale it will cause 1 additional draw call.

    Using frames for different atlas is a great feature. But you should understand that animation sprite will switch materials while playing in this case. Every additional material on scene this is additional draw call.
    Learn more about batching.
     
  11. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    This looks very interesting. A basic YouTube style video tutorial would be a mighty nice thing.
     
  12. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Yea, you right. I am working on the video, it should be available during next few weeks. Thanks for the interest.
     
  13. layola

    layola

    Joined:
    Aug 6, 2013
    Posts:
    94
    where is the register point ?is topleft(0,0) or bottommid(width/2,height)?
    can I change the register point?
     
    Last edited: Aug 23, 2013
  14. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Sprite Registration point is topleft(0,0)

    It depends what you trying to achieve by changing the registration point.
    There is no current functionality with allow to change sprite pivot. But I can easily add such feature.
    Any way now you change change pivot point by parenting to another object. Like with any other game-object.
    Lem me know if you need more explanations.
    Cheers!
     
  15. Ging2020

    Ging2020

    Joined:
    Jan 15, 2013
    Posts:
    33
    thx,good work,I hope the developer can record a video tutorial, and then upload youtube, this is just suggestions, hoping not to waste too much time developers
     
  16. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Hello,

    First of all thank you for this asset. I have some questions about the tutorial though.

    The beginning part I can't get to work (or I don't understand). You say this: "For the first tutorial, we’ll pack textures for our scene (Assets are available in the TexturePacker Extension package under Assets/Extensions/TexturePacker/Tutorial/Art/AtlasSource).

    Open TexturePacker, and simply drag the textures inside. Now let’s configure our atlas."

    But I opened up the Texture Packer window, and tried dragging some textures onto the window, and nothing happened. I also tried placing some textures inside the Assets/Extensions/TexturePacker/Tutorial/Art/AtlasSource folder, and then opening up the Texture Packer window, and again my textures did not show up?

    I don't know what I'm doing wrong. Thanks for any help.
     
  17. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Hello Velo222.

    Here is little misunderstanding I guess. I ment Texture Packer program. This is aaset working with texture atlases created via TexturePacker program. You have to create atlas in TexturePacker program (not TexturePacker Unity Extension) and then start work with extension.
    Here is what I mean by this step.
    $13 10-53 PM.png

    If you have any other questions, please fell free to contact me via PM or e-mail.
     
  18. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Ohhh okay. Thank you :)

    Sorry, I was confused.
     
  19. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    Hi,
    Can we use this on meshes using tiled textures !.
     
  20. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Hello, sathya. Sorry for slow replay.
    Can you explain more what are you mean by this.
     
  21. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    Well say i create a texture atlas with many tilable textures and can i use the textures from the atlas as tilable texture. $Send1.PNG
     
  22. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Thanks for your interest sathya.

    You can not tile texture from atlas by material tile property.
    But if your game object already has tiled UV, you can assign atlas texture to it. and you will have tiled effect.

    Assigning texture from atlas the same as assigning simple texture to 3D object. Except, you can not use Tile and Offset, material properties.
     
  23. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    Thanks lacost. Yes i wont be doing tiling in unity unity shader. This is how i planned aproach:
    1. I will be using 3d application to do the UV mapping with tiled textures.
    2. Then using texture packer i ll be creating the atlas with all tile-able textures
    3. later I want to use your extension to apply appropriate textures.

    Hope its all possible.

    Something similar to this
    $send2.PNG

    from this atlas $2.jpg
     
    Last edited: Sep 11, 2013
  24. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    This should work.

    Do not forget that Texture Packer and my extension both have free version.
    So you can test your pipeline before buying. Thanks for your interest!
     
  25. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    Cool. You can have my money. Thanks
     
  26. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    Cool. You can have my money. Thanks
     
  27. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Thanks :) I glad it works for you!
     
  28. iKonrad

    iKonrad

    Joined:
    Jun 23, 2013
    Posts:
    179
    I've got TP, but the standalone version (I was using it for another project with Cocos2D) and it works brilliantly. I'm wondering however what are the differences in terms of the engine between those two versions.
     
  29. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Texture Packer application is the same. It just great atlasing engine.

    Texture Packer Extension for Unity works with generated atlas and generated atlas data. Basically it make possible use textures from the atlas in diffrent ways.

    OnGUI, Apply texture to the 3D objects(MeshRenders) or characters (SkinnedMesh renders), Play sprite animation, etc.
    If you only need to assign texture on plane, or play sprite animation, extension offers very handy workflow.
    http://forum.unity3d.com/threads/18...ity-Tutorial?p=1336362&viewfull=1#post1336362

    If you have any questions or suggestions feel free to post it here or send them directly to my e-mail: lacost.st@gmail.com.
     
  30. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    I found that it does not work with mesh containing multi materials. any work around for this!
     
  31. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    You mean shader with use few materials?
     
  32. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    I mean mesh having multi-sub-materials. with different material IDs
     
  33. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Okay.
    It not supported.
    Mesh uv changed to fit texture from atlas material. I can not detect with part of mesh is related to specific material.

    I think you are talking about your "roof" mesh.
    The only way around I see Use 2 meshes and one material.
    Polygon count wiil be the same, but you will save some draw call because you will use only one material. Hope it helps.
     
  34. ma.parizeau

    ma.parizeau

    Joined:
    Mar 21, 2010
    Posts:
    116
    Hi, I've followed your instruction mentioned in the PDF and/or in this post here, but I always get, in the TPHelper component, a No Texture message.

    Folder scheme:

    Assets
    - Resources (where my atlas and data files are lcated
    - Level Items
    -- Props (where my FBX is located)


    First I though it might be my original images since they where TGA, so I've redone them to JPG, but I still get the same message. I'v also tried changing the shader, but nothing..


    See image below.


    So what am I doing wrong?

    thanks,


    $error.jpg
     
  35. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,908
    Can you explain the important parts for this to work? I have it working, but I would like to know the important parts.

    The .txt file must be named "_data.txt". The material must have "Material" in the file name? And everything (data.txt, Atlas, Material) must be in the Assets/Resources folder?

    Also, I have to scale up my lightmap resolution a lot. Is that normal?

    Very good script!
     
    Last edited: Sep 15, 2013
  36. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Hi Stardog, Thanks for your interest.

    Yes, that is right. By default Texture Packer suggest same names for texture(png file) and data(txt file). But Unity does not allow 2 files with the same name in same location. If you have 2 files with the same name and same location and you will try to perform Resource.Load call, you will get error, despite that files have different extensions. That was the main reason.
    Besides, using "_data" postfix makes very easy for TPAssetProcessor to detect where you storing your atlases.

    As soon as TPAssetProcessor has detected atlas in your project folder, it will create material <YourAtlasName> Material with Unlit/Transparent shader (you can change material shader after it was created) this material will be used as default for this atlas.
    Here is more detail explanations of what it mean.

    When you selecting atlas from drop-down menu of TPHelper, default material will be assigned to Mesh renderer component of this gam-object.
    $13 10-40 PM.png

    Of-course some times you want different models to be rendered with different shaders BUT have texture from the same atlas. You not able to assign another material to the model because TPHelper keep changing it to default.
    In this case you should Uncheck "Replace Material" on TPHelper component, and you will be able to assign any material to this game-object.
    $skitch_iphoto.export.skitch.png

    So basically you can use any number of materials with different shader for one atlas, and there is no naming restrictions on that.

    Yes, atlas should be in Resources folder. To be more correct it should be inside Resources folder. It doesn't matter where exactly inside Resources folder your atlas is. Here is valid location examples.

    Assets/Resources/<MyAtlases>
    Assets/Locations/Main/Resources/<MyAtlases>
    Assets/Locations/Main/Resources/Textures/HiRes/<MyAtlases>

    etc...

    To adopt mesh UV for Atlas, script adds some offset and scale to mesh UV. The same action you do in the 3Dmax by your hands. So this behavior is perceptible. Try to bake light map after you applied atlases to all your objects, it should work fine.

    If you do any other question fell free to ask.
    Cheers!
     
  37. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    No luck with the Video tut?

    I crank out on average 3-5 Maya demos a week for my students, they don't require that much forethought. Grab some images, set `em up in TP (which I own...easy-peazy), fire up your extension in Unity..and run through the setup. 10 mins?
     
  38. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Main reason why I didn't create video tutorial yet - English isn't my native language and my pronunciation is far from good.

    Bu here is templates for future tutorials (I will add labels effects and arrows). But even now I guess it pretty understandable.
    And I happy to hear any questions or suggestions about it.



    TexturePacker To Unity Tutorial Part 1 (Creating atlas and import to the engine)





    TexturePacker To Unity Tutorial Part 2 (Use atlas texture with custom meshes)





    TexturePacker To Unity Tutorial Part 3 (Sprite animation from atlas)



    I hope you enjoy watching :)
     
    Last edited: Sep 18, 2013
  39. ma.parizeau

    ma.parizeau

    Joined:
    Mar 21, 2010
    Posts:
    116
    Problem fix thanks to Stanislav (lacost) I had to remove _data from my PNG file.
     
  40. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    New Features

    * Pivot adjustment in editor
    $88afe603-71cc-41aa-a94e-dd8d2f58fef1_scaled.jpg

    * Collision
    $d48f24ac-c5c3-4d99-8e60-35457a09d72b_scaled.jpg

    Fixes
    Fixed issue with gizmos render when you parenting objects
     
    Last edited: Sep 19, 2013
  41. Sidewinder

    Sidewinder

    Joined:
    Feb 15, 2013
    Posts:
    1
    Can we integrate NGUI?
     
  42. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    I am not use NGUI for my game's. So I'am not really familiar with it.

    I am pretty sure that it can be easily integrated, because wit this package you able to get Texture2D from atlas and then treat this texture like any other not atlased texture in your project.

    Also you able to put texture from atlas on any mesh you want.
    If integration with NGUI is important for you just download free version of package and try to do what you want, Fell free to ask any guastion on this forum or via e-mail.

    But I do not want to do integration with iGUI or NGUI as declared package feature.
     
  43. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    New Features
    • Full multi-editing support added
    • More Editor user friendly features
    • You can now easily change sprite shader.

    $Ladder.unity_-_TheIsland_-_iPhone__iPod_Touch_and_iPad_and_Asset_Store_-_Texture_Packer_Pro.png

    Fixes
    When you change atlas from outside without restarting Unity atlas will work incorrect. This annoying issue is fixed now. All you have to do know is press "Refresh" button in TexturePacker window.

    $fx.png
     
  44. Jerome-Maurey

    Jerome-Maurey

    Joined:
    May 6, 2013
    Posts:
    6
    Hi,

    We are using TP Pro and I would like to know if you have documentation on creating atlases at runtime. I would like to dynamically load bitmap assets and rect data and apply them to meshes thereafter.

    Cheers,

    J.
     
  45. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Hello. Thanks for your interest.
    Unfortunately atlas creation logic is under TexturePacker application. TexturePacker extension is only parce atlases data and generate appropriate mesh uv + bunch of other features.

    In other words creating atlases in runtime is not supported. And if you will explane why did you need this I will try to help. Atlas creation can take about 1 minute event on good computer. I dought that you want to do such huge performance hit for your game.

    But I'm looking forward to generating atlas inside Unity Editor.
    I'm thinking to start work on this feature.

    Cheers!
     
  46. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    131
    Hi lacost,

    Thank you for your efforts in making this extension - it's really great. Unfortunately I'm having a problem with using the extension on mobile, specifically iPhone. When I try to build a project (using the free version of your extension) I receive an error:

    There isn't a great deal more information to go on. Any ideas what might be going on here? I actually saw your note on the asset store comments section saying that the latest package was empty, so I downloaded the version from your dropbox. Does this version work with mobile? Any help you could provide would be much appreciated.

    Thanks again,

    Ben
     
  47. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    Last edited: Oct 14, 2013
  48. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    131
    Hi lacost,

    That's great news, thanks for your help. I've just downloaded the updated package, but the TPHelper.cs file isn't present. Has this been removed from newer versions?

    Thanks again,

    Ben
     
  49. Jerome-Maurey

    Jerome-Maurey

    Joined:
    May 6, 2013
    Posts:
    6
    Hi Lacost,

    We are fine generating atlases in the TexturePacker App. What I want to do is load these atlases (spritesheet + json data) at runtime and not embed them in the Unity IDE. Even if it's just swapping the image used to update the textures on our meshes.

    Cheers,

    J.
     
  50. stanislav-osipov

    stanislav-osipov

    Joined:
    May 30, 2012
    Posts:
    1,790
    No, it should be there. Let me check this.
    ---
    I just imported package in clean project all files are there, and TPHelper.cs also. Please check one more time.
    Never thought about implementing this. But it should be easy. I will add remote download support in next update. Cheers!
     
    Last edited: Oct 14, 2013