Manual: PSDReader

Documentation and discussion for Draconus Texture Utils available in the Unity Asset Store.
snlehton
Crew
Crew
Posts: 16
Joined: Tue Nov 04, 2014 1:59 pm

Manual: PSDReader

Postby snlehton » Tue Nov 25, 2014 4:04 pm

Manual: PSDReader
TextureUtils: Slicing | Pixel Operations |Normal Maps | Misc
AtlasGenerator | PSDReader |API Scripting Reference

The PSDReader included in DTU can be used to read layers and slices in Photoshop PSD files. The layers are read into Unity's Texture2D textures.

Note that all the coordinates and rectangles loaded are primarily in PSD coordinate space (top-down) and either have accessors or can be converted to Unity coordinate space (bottom-up).

Note: PSD file does only contain parameters for the layer effects and not the rasterized effects. Therefore layers with effects will be loaded as if the effects were disabled. To overcome this limitation, you can convert a layer that you want to have effects on into Photoshop Smart Object (right-click the layer, and choose Convert to Smart Object). The contents of the smart object will be stored as a rasterized layer.

Usage

You can load a PSD file simply by giving the path to the file:

Code: Select all

PSDFile psdfile = PSDReader.ReadPSDFile("Assets/MyAwesome.psd");


You can also find path for a PSD file using AssetDatabase if you're working in Unity editor script:

Code: Select all

Texture2D reallyPSD = ...; // reference to a PSD file which was interpreted as Texture2D by Unity
string path = AssetDatabase.GetAssetPath(reallyPSD);
PSDFile psdfile = PSDReader.ReadPSDFile(path);


The flattened PSD image can be accessed via flattenedImage accessor:

Code: Select all

Texture2D flattened = psdfile.flattenedImage;


To access the layers, you can either get them all or get a layer by name:

Code: Select all

foreach (PSDLayer layer in psdfile.layers)
{
   Debug.Log("Layer is " + layer.name + ", texture is " + layer.texture);
}
// OR
PSDLayer layer = psdfile.FindLayerByName("diffuse");


Slices can be used to slice the PSD file into smaller pieces:

Code: Select all

var slices = psdfile.slices;
var layerTexture = psdfile.FindLayerByName("sprites").texture;
List<Texture2D> sprites = new List<Texture2D>();
foreach (var slice in slices)
{
   sprites.Add(TextureUtils.SliceTexture(layerTexture, slice.rectUnity));
}


====================================================================================
TextureUtils: Slicing | Pixel Operations |Normal Maps | Misc
AtlasGenerator | PSDReader |API Scripting Reference

Return to “DTU - Draconus Texture Utils”

Who is online

Users browsing this forum: No registered users and 1 guest