Using with 3D object’s
TexturePacker standalone is available for download here:
The TexturePacker Unity extension is available here:
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.
- Data Format: Unity3D
- Data File: YourProject/Assets/Resources/TutorialAtlas_data.txt Texture File: YourProject/Assets/Resources/TutorialAtlas.png
- Texture Format: png
- Check the “Force Squared” toggle
- 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 have 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:
Atlas is ready, so we need material for it.
In The 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:
It already has a texture and a material assigned. Replace this with a texture from the atlas:
Select the sword_01 game object (the one with the MeshRenderer component attached).
Attach TPMeshTextureEx component (TPHelper component will be added automatically)
Choose Atlas and Texture in TPHelper menu
The sword is now using the texture from the atlas.
Note: Do not attach TPMeshTexture component, it will cause component loops if you replace TexturePacker.dll. Use it only for extending.
The usage is similar to a simple model.
Select the sword_01 game object (the one with the SkinnedMeshRenderer component attached).
Attach TPSkinnedMeshTextureEx component (TPHelper component will be added automatically)
Choose Atlas and Texture in TPHelper menu
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:
Create a cube in the scene by selecting GameObhect->Create Other->Cube
Change the material on the cube to TutorialAtlasMaterial
Attach a TPMeshAnimation component
Configure the TPMeshAnimation component options as follows:
Frames: add 6 frames fireball_0001, fireball_0002, fireball_0003, fireball_0004, fireball_0005, fireball_0006
The component should look like this:
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 at Assets/Extensions/TexturePacker/Tutorial/Scenes/AtlasesAnim
For this scene was used only one atlas, that’s why whole this scene with almost 100 objects and 50 animations has only 1 Draw Call. 1 Texture and 1MB of memory
Let's look at the optimization of weight in this example.
We have only one texture for the whole stage, which is already good benefit, but we can squeeze even more.
size of our texture is 754*754, if we choose RGBA 32 compression it will weight 2.2 MB
But if we will set PVRTC compression and stretch texture to the 1024 * 1024 (compression work only with POV2 textures) It will weight only 1MB. And if you do not mind some quality lost, Unity3d can scale it to 512 *512 so it weight becomes only 256KB. Try it.
By the way, you can use POV2 texture packer options to always see how much texture you can add to your atlas.
Lear more about Draw Call Batching.