mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2026-03-22 12:55:32 +07:00
little style refactor
This commit is contained in:
@@ -56,7 +56,6 @@ namespace FlashTools.Internal {
|
||||
//
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
static void ConfigureAtlas(string asset_path, SwfAnimationAsset asset) {
|
||||
var atlas_importer = GetBitmapsAtlasImporter(asset_path);
|
||||
var atlas_importer_size = GetSizeFromTextureImporter(atlas_importer);
|
||||
@@ -141,7 +140,7 @@ namespace FlashTools.Internal {
|
||||
//
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
class BakeGroup {
|
||||
class BakedGroup {
|
||||
public SwfAnimationInstanceType Type;
|
||||
public int ClipDepth;
|
||||
public List<int> Triangles;
|
||||
@@ -160,20 +159,24 @@ namespace FlashTools.Internal {
|
||||
asset.Frames = baked_frames;
|
||||
}
|
||||
|
||||
static SwfAnimationAsset.Frame BakeFrameFromAnimationFrame(SwfAnimationAsset asset, SwfAnimationFrameData frame) {
|
||||
List<Vector2> _uvs = new List<Vector2>();
|
||||
List<Color> _mulcolors = new List<Color>();
|
||||
List<Vector4> _addcolors = new List<Vector4>();
|
||||
List<Vector3> _vertices = new List<Vector3>();
|
||||
List<BakeGroup> _groups = new List<BakeGroup>();
|
||||
List<Material> _materials = new List<Material>();
|
||||
static SwfAnimationAsset.Frame BakeFrameFromAnimationFrame(
|
||||
SwfAnimationAsset asset, SwfAnimationFrameData frame)
|
||||
{
|
||||
List<Vector2> baked_uvs = new List<Vector2>();
|
||||
List<Color> baked_mulcolors = new List<Color>();
|
||||
List<Vector4> baked_addcolors = new List<Vector4>();
|
||||
List<Vector3> baked_vertices = new List<Vector3>();
|
||||
List<BakedGroup> baked_groups = new List<BakedGroup>();
|
||||
List<Material> baked_materials = new List<Material>();
|
||||
|
||||
for ( var i = 0; i < frame.Instances.Count; ++i ) {
|
||||
var inst = frame.Instances[i];
|
||||
var bitmap = inst != null ? FindBitmapFromAnimationData(asset.Data, inst.Bitmap) : null;
|
||||
var bitmap = inst != null
|
||||
? FindBitmapFromAnimationData(asset.Data, inst.Bitmap)
|
||||
: null;
|
||||
if ( bitmap != null ) {
|
||||
var width = bitmap.RealSize.x / 20.0f;
|
||||
var height = bitmap.RealSize.y / 20.0f;
|
||||
var width = bitmap.RealSize.x / 20.0f; //TODO: twips?
|
||||
var height = bitmap.RealSize.y / 20.0f; //TODO: twips?
|
||||
|
||||
var v0 = new Vector3( 0, 0, 0);
|
||||
var v1 = new Vector3(width, 0, 0);
|
||||
@@ -186,32 +189,32 @@ namespace FlashTools.Internal {
|
||||
-1.0f / asset.Settings.PixelsPerUnit,
|
||||
+1.0f / asset.Settings.PixelsPerUnit)) * inst.Matrix;
|
||||
|
||||
_vertices.Add(matrix.MultiplyPoint3x4(v0));
|
||||
_vertices.Add(matrix.MultiplyPoint3x4(v1));
|
||||
_vertices.Add(matrix.MultiplyPoint3x4(v2));
|
||||
_vertices.Add(matrix.MultiplyPoint3x4(v3));
|
||||
baked_vertices.Add(matrix.MultiplyPoint3x4(v0));
|
||||
baked_vertices.Add(matrix.MultiplyPoint3x4(v1));
|
||||
baked_vertices.Add(matrix.MultiplyPoint3x4(v2));
|
||||
baked_vertices.Add(matrix.MultiplyPoint3x4(v3));
|
||||
|
||||
var source_rect = bitmap.SourceRect;
|
||||
_uvs.Add(new Vector2(source_rect.xMin, source_rect.yMin));
|
||||
_uvs.Add(new Vector2(source_rect.xMax, source_rect.yMin));
|
||||
_uvs.Add(new Vector2(source_rect.xMax, source_rect.yMax));
|
||||
_uvs.Add(new Vector2(source_rect.xMin, source_rect.yMax));
|
||||
baked_uvs.Add(new Vector2(source_rect.xMin, source_rect.yMin));
|
||||
baked_uvs.Add(new Vector2(source_rect.xMax, source_rect.yMin));
|
||||
baked_uvs.Add(new Vector2(source_rect.xMax, source_rect.yMax));
|
||||
baked_uvs.Add(new Vector2(source_rect.xMin, source_rect.yMax));
|
||||
|
||||
_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
baked_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
baked_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
baked_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
baked_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
|
||||
_addcolors.Add(inst.ColorTransform.Add);
|
||||
_addcolors.Add(inst.ColorTransform.Add);
|
||||
_addcolors.Add(inst.ColorTransform.Add);
|
||||
_addcolors.Add(inst.ColorTransform.Add);
|
||||
baked_addcolors.Add(inst.ColorTransform.Add);
|
||||
baked_addcolors.Add(inst.ColorTransform.Add);
|
||||
baked_addcolors.Add(inst.ColorTransform.Add);
|
||||
baked_addcolors.Add(inst.ColorTransform.Add);
|
||||
|
||||
if ( _groups.Count == 0 ||
|
||||
_groups[_groups.Count - 1].Type != inst.Type ||
|
||||
_groups[_groups.Count - 1].ClipDepth != inst.ClipDepth )
|
||||
if ( baked_groups.Count == 0 ||
|
||||
baked_groups[baked_groups.Count - 1].Type != inst.Type ||
|
||||
baked_groups[baked_groups.Count - 1].ClipDepth != inst.ClipDepth )
|
||||
{
|
||||
_groups.Add(new BakeGroup{
|
||||
baked_groups.Add(new BakedGroup{
|
||||
Type = inst.Type,
|
||||
ClipDepth = inst.ClipDepth,
|
||||
Triangles = new List<int>(),
|
||||
@@ -219,18 +222,18 @@ namespace FlashTools.Internal {
|
||||
});
|
||||
}
|
||||
|
||||
_groups[_groups.Count - 1].Triangles.Add(_vertices.Count - 4 + 2);
|
||||
_groups[_groups.Count - 1].Triangles.Add(_vertices.Count - 4 + 1);
|
||||
_groups[_groups.Count - 1].Triangles.Add(_vertices.Count - 4 + 0);
|
||||
_groups[_groups.Count - 1].Triangles.Add(_vertices.Count - 4 + 0);
|
||||
_groups[_groups.Count - 1].Triangles.Add(_vertices.Count - 4 + 3);
|
||||
_groups[_groups.Count - 1].Triangles.Add(_vertices.Count - 4 + 2);
|
||||
baked_groups.Last().Triangles.Add(baked_vertices.Count - 4 + 2);
|
||||
baked_groups.Last().Triangles.Add(baked_vertices.Count - 4 + 1);
|
||||
baked_groups.Last().Triangles.Add(baked_vertices.Count - 4 + 0);
|
||||
baked_groups.Last().Triangles.Add(baked_vertices.Count - 4 + 0);
|
||||
baked_groups.Last().Triangles.Add(baked_vertices.Count - 4 + 3);
|
||||
baked_groups.Last().Triangles.Add(baked_vertices.Count - 4 + 2);
|
||||
}
|
||||
}
|
||||
|
||||
var default_converter = SwfConverterSettings.GetDefaultConverter();
|
||||
for ( var i = 0; i < _groups.Count; ++i ) {
|
||||
var group = _groups[i];
|
||||
for ( var i = 0; i < baked_groups.Count; ++i ) {
|
||||
var group = baked_groups[i];
|
||||
switch ( group.Type ) {
|
||||
case SwfAnimationInstanceType.Mask:
|
||||
group.Material = default_converter.GetIncrMaskMaterial();
|
||||
@@ -244,30 +247,37 @@ namespace FlashTools.Internal {
|
||||
case SwfAnimationInstanceType.MaskReset:
|
||||
group.Material = default_converter.GetDecrMaskMaterial();
|
||||
break;
|
||||
default:
|
||||
throw new UnityException(string.Format(
|
||||
"SwfAnimationAssetPostprocessor. Incorrect instance type: {0}",
|
||||
group.Type));
|
||||
}
|
||||
if ( group.Material ) {
|
||||
baked_materials.Add(group.Material);
|
||||
} else {
|
||||
throw new UnityException(string.Format(
|
||||
"SwfAnimationAssetPostprocessor. Material for baked group ({0}) not found",
|
||||
group.Type));
|
||||
}
|
||||
}
|
||||
|
||||
for ( var i = 0; i < _groups.Count; ++i ) {
|
||||
var group = _groups[i];
|
||||
_materials.Add(group.Material);
|
||||
}
|
||||
|
||||
var mesh = new Mesh();
|
||||
mesh.subMeshCount = _groups.Count;
|
||||
mesh.SetVertices(_vertices);
|
||||
for ( var i = 0; i < _groups.Count; ++i ) {
|
||||
mesh.SetTriangles(_groups[i].Triangles, i);
|
||||
mesh.subMeshCount = baked_groups.Count;
|
||||
mesh.SetVertices(baked_vertices);
|
||||
for ( var i = 0; i < baked_groups.Count; ++i ) {
|
||||
mesh.SetTriangles(baked_groups[i].Triangles, i);
|
||||
}
|
||||
mesh.SetUVs(0, _uvs);
|
||||
mesh.SetUVs(1, _addcolors);
|
||||
mesh.SetColors(_mulcolors);
|
||||
mesh.SetUVs(0, baked_uvs);
|
||||
mesh.SetUVs(1, baked_addcolors);
|
||||
mesh.SetColors(baked_mulcolors);
|
||||
mesh.RecalculateNormals();
|
||||
|
||||
//TODO: add remove all old meshes
|
||||
AssetDatabase.AddObjectToAsset(mesh, asset);
|
||||
|
||||
return new SwfAnimationAsset.Frame{
|
||||
Mesh = mesh,
|
||||
Materials = _materials.ToArray()};
|
||||
Materials = baked_materials.ToArray()};
|
||||
}
|
||||
|
||||
static SwfAnimationBitmapData FindBitmapFromAnimationData(SwfAnimationData data, int bitmap_id) {
|
||||
|
||||
Reference in New Issue
Block a user