improve Sprite export
This commit is contained in:
@@ -6,6 +6,40 @@ using System.Text;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public enum SpritePackingRotation
|
||||
{
|
||||
kSPRNone = 0,
|
||||
kSPRFlipHorizontal = 1,
|
||||
kSPRFlipVertical = 2,
|
||||
kSPRRotate180 = 3,
|
||||
kSPRRotate90 = 4
|
||||
};
|
||||
|
||||
public enum SpritePackingMode
|
||||
{
|
||||
kSPMTight = 0,
|
||||
kSPMRectangle
|
||||
};
|
||||
|
||||
public class SpriteSettings
|
||||
{
|
||||
public uint settingsRaw;
|
||||
|
||||
public uint packed => settingsRaw & 1; //1
|
||||
public SpritePackingMode packingMode => (SpritePackingMode)((settingsRaw >> 1) & 1); //1
|
||||
public SpritePackingRotation packingRotation => (SpritePackingRotation)((settingsRaw >> 2) & 0xf); //4
|
||||
public uint reserved => settingsRaw >> 6; //26
|
||||
/*
|
||||
*public uint meshType => (settingsRaw >> 6) & 1; //1
|
||||
*public uint reserved => settingsRaw >> 7; //25
|
||||
*/
|
||||
|
||||
public SpriteSettings(ObjectReader reader)
|
||||
{
|
||||
settingsRaw = reader.ReadUInt32();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Sprite : NamedObject
|
||||
{
|
||||
public RectangleF m_Rect;
|
||||
@@ -15,6 +49,7 @@ namespace AssetStudio
|
||||
public PPtr texture;
|
||||
public PPtr m_SpriteAtlas;
|
||||
public RectangleF textureRect;
|
||||
public SpriteSettings settingsRaw;
|
||||
public PointF[][] m_PhysicsShape;
|
||||
|
||||
public Sprite(ObjectReader reader) : base(reader)
|
||||
@@ -145,7 +180,7 @@ namespace AssetStudio
|
||||
reader.Position += 8;
|
||||
}
|
||||
// unsigned int settingsRaw
|
||||
reader.Position += 4;
|
||||
settingsRaw = new SpriteSettings(reader);
|
||||
// Vector4f uvTransform - 4.5 and up
|
||||
if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SharpDX;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
@@ -6,53 +7,60 @@ using System.Text;
|
||||
|
||||
namespace AssetStudio
|
||||
{
|
||||
public class SpriteAtlasData
|
||||
{
|
||||
public PPtr texture;
|
||||
public PPtr alphaTexture;
|
||||
public System.Drawing.RectangleF textureRect;
|
||||
public Vector2 textureRectOffset;
|
||||
public Vector2 atlasRectOffset;
|
||||
public Vector4 uvTransform;
|
||||
public float downscaleMultiplier;
|
||||
public SpriteSettings settingsRaw;
|
||||
|
||||
public SpriteAtlasData(ObjectReader reader)
|
||||
{
|
||||
var version = reader.version;
|
||||
texture = reader.ReadPPtr();
|
||||
alphaTexture = reader.ReadPPtr();
|
||||
textureRect = reader.ReadRectangleF();
|
||||
textureRectOffset = reader.ReadVector2();
|
||||
if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 2)) //2017.2 and up
|
||||
{
|
||||
atlasRectOffset = reader.ReadVector2();
|
||||
}
|
||||
uvTransform = reader.ReadVector4();
|
||||
downscaleMultiplier = reader.ReadSingle();
|
||||
settingsRaw = new SpriteSettings(reader);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SpriteAtlas : NamedObject
|
||||
{
|
||||
public List<PPtr> textures = new List<PPtr>();
|
||||
public List<RectangleF> textureRects = new List<RectangleF>();
|
||||
public List<Guid> guids = new List<Guid>();
|
||||
|
||||
public Dictionary<Tuple<Guid, long>, SpriteAtlasData> m_RenderDataMap;
|
||||
|
||||
public SpriteAtlas(ObjectReader reader) : base(reader)
|
||||
{
|
||||
//vector m_PackedSprites
|
||||
var size = reader.ReadInt32();
|
||||
for (int i = 0; i < size; i++)
|
||||
var m_PackedSpritesSize = reader.ReadInt32();
|
||||
for (int i = 0; i < m_PackedSpritesSize; i++)
|
||||
{
|
||||
//PPtr<Sprite> data
|
||||
reader.ReadPPtr();
|
||||
reader.ReadPPtr(); //PPtr<Sprite> data
|
||||
}
|
||||
//vector m_PackedSpriteNamesToIndex
|
||||
size = reader.ReadInt32();
|
||||
for (int i = 0; i < size; i++)
|
||||
|
||||
var m_PackedSpriteNamesToIndexSize = reader.ReadInt32();
|
||||
for (int i = 0; i < m_PackedSpriteNamesToIndexSize; i++)
|
||||
{
|
||||
var data = reader.ReadAlignedString();
|
||||
reader.ReadAlignedString();
|
||||
}
|
||||
//map m_RenderDataMap
|
||||
size = reader.ReadInt32();
|
||||
for (int i = 0; i < size; i++)
|
||||
|
||||
var m_RenderDataMapSize = reader.ReadInt32();
|
||||
m_RenderDataMap = new Dictionary<Tuple<Guid, long>, SpriteAtlasData>(m_RenderDataMapSize);
|
||||
for (int i = 0; i < m_RenderDataMapSize; i++)
|
||||
{
|
||||
//pair first
|
||||
guids.Add(new Guid(reader.ReadBytes(16)));
|
||||
var first = new Guid(reader.ReadBytes(16));
|
||||
var second = reader.ReadInt64();
|
||||
//SpriteAtlasData second
|
||||
// PPtr<Texture2D> texture
|
||||
textures.Add(reader.ReadPPtr());
|
||||
// PPtr<Texture2D> alphaTexture
|
||||
var alphaTexture = reader.ReadPPtr();
|
||||
// Rectf textureRect
|
||||
textureRects.Add(new RectangleF(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
|
||||
// Vector2f textureRectOffset
|
||||
reader.Position += 8;
|
||||
if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 2))//2017.2 and up
|
||||
{
|
||||
// Vector2f atlasRectOffset
|
||||
reader.Position += 8;
|
||||
}
|
||||
// Vector4f uvTransform
|
||||
// float downscaleMultiplier
|
||||
// unsigned int settingsRaw
|
||||
reader.Position += 24;
|
||||
var value = new SpriteAtlasData(reader);
|
||||
m_RenderDataMap.Add(new Tuple<Guid, long>(first, second), value);
|
||||
}
|
||||
//string m_Tag
|
||||
//bool m_IsVariant
|
||||
|
||||
Reference in New Issue
Block a user