mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-16 22:19:31 +07:00
style fixes
This commit is contained in:
@@ -103,6 +103,7 @@
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfTools\SwfTypes\SwfShapesWithStyle.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfTools\SwfTypes\SwfShortHeader.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfTools\SwfTypes\SwfSurfaceFilters.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\Tests\SwfUtilsTests.cs" />
|
||||
<None Include="Assets\FlashTools\Resources\Shaders\SwfDecrMask.shader" />
|
||||
<None Include="Assets\FlashTools\Resources\Shaders\SwfSimple.shader" />
|
||||
<None Include="Assets\FlashTools\CHANGELOG.txt" />
|
||||
|
||||
@@ -219,7 +219,7 @@ namespace FlashTools.Internal {
|
||||
|
||||
var matrix =
|
||||
Matrix4x4.Scale(new Vector3(1.0f, -1.0f, 1.0f)) *
|
||||
inst.Matrix.ToUnityMatrix();
|
||||
inst.Matrix.ToUMatrix();
|
||||
|
||||
var p0 = matrix.MultiplyPoint3x4(v0);
|
||||
var p1 = matrix.MultiplyPoint3x4(v1);
|
||||
@@ -308,7 +308,7 @@ namespace FlashTools.Internal {
|
||||
SubMeshes = baked_groups
|
||||
.Select(p => new SwfClipAsset.SubMeshData{
|
||||
StartVertex = p.StartVertex,
|
||||
TriangleCount = p.TriangleCount})
|
||||
IndexCount = p.TriangleCount})
|
||||
.ToList(),
|
||||
MeshMin = baked_mesh_min,
|
||||
MeshScale = asset.Settings.PixelsPerUnit,
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace FlashTools.Internal {
|
||||
var self_masks = new List<SwfInstanceData>();
|
||||
foreach ( var inst in display_list.Instances.Values.Where(p => p.Visible) ) {
|
||||
CheckSelfMasks(self_masks, inst.Depth, frame);
|
||||
var child_matrix = parent_matrix * inst.Matrix.ToUnityMatrix();
|
||||
var child_matrix = parent_matrix * inst.Matrix.ToUMatrix();
|
||||
var child_color_transform = parent_color_transform * inst.ColorTransform.ToColorTransData();
|
||||
switch ( inst.Type ) {
|
||||
case SwfDisplayInstanceType.Shape:
|
||||
@@ -148,7 +148,7 @@ namespace FlashTools.Internal {
|
||||
Type = frame_inst_type,
|
||||
ClipDepth = (ushort)frame_inst_clip_depth,
|
||||
Bitmap = bitmap_id,
|
||||
Matrix = SwfMatrixData.FromUnityMatrix(child_matrix * bitmap_matrix.ToUnityMatrix()),
|
||||
Matrix = SwfMatrixData.FromUMatrix(child_matrix * bitmap_matrix.ToUMatrix()),
|
||||
ColorTrans = child_color_transform});
|
||||
if ( parent_mask > 0 ) {
|
||||
parent_masks.Add(frame.Instances[frame.Instances.Count - 1]);
|
||||
|
||||
@@ -71,126 +71,5 @@ namespace FlashTools.Internal {
|
||||
var asset_path = AssetDatabase.GetAssetPath(asset);
|
||||
return Path.ChangeExtension(asset_path, "._Atlas_.png");
|
||||
}
|
||||
|
||||
//
|
||||
// SwfUtils tests
|
||||
//
|
||||
|
||||
[Test]
|
||||
public static void PackUVTests() {
|
||||
float v0 = 0.99f, v1 = 0.11f;
|
||||
Assert.AreEqual(
|
||||
v0,
|
||||
SwfUtils.UnpackUV(SwfUtils.PackUV(v0, v1)).x,
|
||||
0.0001f);
|
||||
Assert.AreEqual(
|
||||
v1,
|
||||
SwfUtils.UnpackUV(SwfUtils.PackUV(v0, v1)).y,
|
||||
0.0001f);
|
||||
|
||||
float v2 = 0.09f, v3 = 0.01f;
|
||||
Assert.AreEqual(
|
||||
v2,
|
||||
SwfUtils.UnpackUV(SwfUtils.PackUV(v2, v3)).x,
|
||||
0.0001f);
|
||||
Assert.AreEqual(
|
||||
v3,
|
||||
SwfUtils.UnpackUV(SwfUtils.PackUV(v2, v3)).y,
|
||||
0.0001f);
|
||||
|
||||
float v4 = 1.0f, v5 = 0.0f;
|
||||
Assert.AreEqual(
|
||||
v4,
|
||||
SwfUtils.UnpackUV(SwfUtils.PackUV(v4, v5)).x,
|
||||
0.0001f);
|
||||
Assert.AreEqual(
|
||||
v5,
|
||||
SwfUtils.UnpackUV(SwfUtils.PackUV(v4, v5)).y,
|
||||
0.0001f);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void PackFloatColorToUShortTests() {
|
||||
float v0 = -5.678f;
|
||||
Assert.AreEqual(
|
||||
v0,
|
||||
SwfUtils.UnpackFloatColorFromUShort(SwfUtils.PackFloatColorToUShort(v0)),
|
||||
0.002f);
|
||||
|
||||
float v1 = 60.678f;
|
||||
Assert.AreEqual(
|
||||
v1,
|
||||
SwfUtils.UnpackFloatColorFromUShort(SwfUtils.PackFloatColorToUShort(v1)),
|
||||
0.002f);
|
||||
|
||||
float v2 = 0.678f;
|
||||
Assert.AreEqual(
|
||||
v2,
|
||||
SwfUtils.UnpackFloatColorFromUShort(SwfUtils.PackFloatColorToUShort(v2)),
|
||||
0.002f);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void PackColorToUIntsTests() {
|
||||
var v0 = new Color(0.01f, 0.02f, 0.33f, 1.0f);
|
||||
uint u0, u1;
|
||||
SwfUtils.PackColorToUInts(v0, out u0, out u1);
|
||||
Color c0;
|
||||
SwfUtils.UnpackColorFromUInts(u0, u1, out c0);
|
||||
Assert.AreEqual(v0.r, c0.r, SwfUtils.ColorPrecision);
|
||||
Assert.AreEqual(v0.g, c0.g, SwfUtils.ColorPrecision);
|
||||
Assert.AreEqual(v0.b, c0.b, SwfUtils.ColorPrecision);
|
||||
Assert.AreEqual(v0.a, c0.a, SwfUtils.ColorPrecision);
|
||||
|
||||
var v1 = new Vector4(0.01f, 0.02f, 0.33f, 1.0f);
|
||||
uint u2, u3;
|
||||
SwfUtils.PackColorToUInts(v1, out u2, out u3);
|
||||
Vector4 c1;
|
||||
SwfUtils.UnpackColorFromUInts(u2, u3, out c1);
|
||||
Assert.AreEqual(v1.x, c1.x, SwfUtils.ColorPrecision);
|
||||
Assert.AreEqual(v1.y, c1.y, SwfUtils.ColorPrecision);
|
||||
Assert.AreEqual(v1.z, c1.z, SwfUtils.ColorPrecision);
|
||||
Assert.AreEqual(v1.w, c1.w, SwfUtils.ColorPrecision);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void PackUShortsToUIntTests() {
|
||||
ushort v0 = 11, v1 = 99;
|
||||
ushort o0, o1;
|
||||
SwfUtils.UnpackUShortsFromUInt(
|
||||
SwfUtils.PackUShortsToUInt(v0, v1), out o0, out o1);
|
||||
Assert.AreEqual(v0, o0);
|
||||
Assert.AreEqual(v1, o1);
|
||||
|
||||
ushort v2 = 16789, v3 = 31234;
|
||||
ushort o2, o3;
|
||||
SwfUtils.UnpackUShortsFromUInt(
|
||||
SwfUtils.PackUShortsToUInt(v2, v3), out o2, out o3);
|
||||
Assert.AreEqual(v2, o2);
|
||||
Assert.AreEqual(v3, o3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void PackCoordsToUIntTests() {
|
||||
var v0 = new Vector2(1.14f, 2.23f);
|
||||
Assert.AreEqual(
|
||||
v0.x,
|
||||
SwfUtils.UnpackCoordsFromUInt(SwfUtils.PackCoordsToUInt(v0)).x,
|
||||
SwfUtils.CoordPrecision);
|
||||
Assert.AreEqual(
|
||||
v0.y,
|
||||
SwfUtils.UnpackCoordsFromUInt(SwfUtils.PackCoordsToUInt(v0)).y,
|
||||
SwfUtils.CoordPrecision);
|
||||
|
||||
var v1 = new Vector2(1234.14f, 3200.23f);
|
||||
Assert.AreEqual(
|
||||
v1.x,
|
||||
SwfUtils.UnpackCoordsFromUInt(SwfUtils.PackCoordsToUInt(v1)).x,
|
||||
SwfUtils.CoordPrecision);
|
||||
Assert.AreEqual(
|
||||
v1.y,
|
||||
SwfUtils.UnpackCoordsFromUInt(SwfUtils.PackCoordsToUInt(v1)).y,
|
||||
SwfUtils.CoordPrecision);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,21 +34,5 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
"SwfColor. R: {0}, G: {1}, B: {2}, A: {3}",
|
||||
R, G, B, A);
|
||||
}
|
||||
|
||||
public Color ToUnityColor() {
|
||||
return new Color(
|
||||
R / 255.0f,
|
||||
G / 255.0f,
|
||||
B / 255.0f,
|
||||
A / 255.0f);
|
||||
}
|
||||
|
||||
public Color32 ToUnityColor32() {
|
||||
return new Color32(
|
||||
R,
|
||||
G,
|
||||
B,
|
||||
A);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
TranslateX, TranslateY);
|
||||
}
|
||||
|
||||
public Matrix4x4 ToUnityMatrix() {
|
||||
public Matrix4x4 ToUMatrix() {
|
||||
var mat = Matrix4x4.identity;
|
||||
mat.m00 = ScaleX;
|
||||
mat.m10 = RotateSkew0;
|
||||
|
||||
@@ -37,11 +37,5 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
"XMin: {0}, XMax: {1}, YMin: {2}, YMax: {3}",
|
||||
XMin, XMax, YMin, YMax);
|
||||
}
|
||||
|
||||
public Rect ToUnityRect() {
|
||||
return Rect.MinMaxRect(
|
||||
XMin, YMin,
|
||||
XMax, YMax);
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Assets/FlashTools/Scripts/Internal/Editor/Tests.meta
Normal file
9
Assets/FlashTools/Scripts/Internal/Editor/Tests.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e21e87290a7a4488ac2343d6defe08f
|
||||
folderAsset: yes
|
||||
timeCreated: 1473785847
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
122
Assets/FlashTools/Scripts/Internal/Editor/Tests/SwfUtilsTests.cs
Normal file
122
Assets/FlashTools/Scripts/Internal/Editor/Tests/SwfUtilsTests.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using UnityEngine;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FlashTools.Internal.Tests {
|
||||
public static class SwfUtilsTests {
|
||||
|
||||
static void AssertAreEqualVectors(Vector2 v0, Vector2 v1, float delta) {
|
||||
Assert.AreEqual(v0.x, v1.x, delta);
|
||||
Assert.AreEqual(v0.y, v1.y, delta);
|
||||
}
|
||||
|
||||
static void AssertAreEqualVectors(Vector3 v0, Vector3 v1, float delta) {
|
||||
Assert.AreEqual(v0.x, v1.x, delta);
|
||||
Assert.AreEqual(v0.y, v1.y, delta);
|
||||
Assert.AreEqual(v0.z, v1.z, delta);
|
||||
}
|
||||
|
||||
static void AssertAreEqualVectors(Vector4 v0, Vector4 v1, float delta) {
|
||||
Assert.AreEqual(v0.x, v1.x, delta);
|
||||
Assert.AreEqual(v0.y, v1.y, delta);
|
||||
Assert.AreEqual(v0.z, v1.z, delta);
|
||||
Assert.AreEqual(v0.w, v1.w, delta);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
[Test]
|
||||
public static void PackUShortsToUIntTests() {
|
||||
ushort v0 = 11, v1 = 99;
|
||||
ushort o0, o1;
|
||||
SwfUtils.UnpackUShortsFromUInt(
|
||||
SwfUtils.PackUShortsToUInt(v0, v1), out o0, out o1);
|
||||
Assert.AreEqual(v0, o0);
|
||||
Assert.AreEqual(v1, o1);
|
||||
|
||||
ushort v2 = 16789, v3 = 31234;
|
||||
ushort o2, o3;
|
||||
SwfUtils.UnpackUShortsFromUInt(
|
||||
SwfUtils.PackUShortsToUInt(v2, v3), out o2, out o3);
|
||||
Assert.AreEqual(v2, o2);
|
||||
Assert.AreEqual(v3, o3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void PackUVTests() {
|
||||
var v0 = new Vector2(0.99f, 0.11f);
|
||||
AssertAreEqualVectors(
|
||||
v0,
|
||||
SwfUtils.UnpackUV(SwfUtils.PackUV(v0)),
|
||||
SwfUtils.UVPrecision);
|
||||
|
||||
var v1 = new Vector2(0.09f, 0.01f);
|
||||
AssertAreEqualVectors(
|
||||
v1,
|
||||
SwfUtils.UnpackUV(SwfUtils.PackUV(v1)),
|
||||
SwfUtils.UVPrecision);
|
||||
|
||||
var v2 = new Vector2(1.0f, 0.0f);
|
||||
AssertAreEqualVectors(
|
||||
v2,
|
||||
SwfUtils.UnpackUV(SwfUtils.PackUV(v2)),
|
||||
SwfUtils.UVPrecision);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void PackFloatColorToUShortTests() {
|
||||
float v0 = -5.678f;
|
||||
Assert.AreEqual(
|
||||
v0,
|
||||
SwfUtils.UnpackFloatColorFromUShort(SwfUtils.PackFloatColorToUShort(v0)),
|
||||
SwfUtils.ColorPrecision);
|
||||
|
||||
float v1 = 60.678f;
|
||||
Assert.AreEqual(
|
||||
v1,
|
||||
SwfUtils.UnpackFloatColorFromUShort(SwfUtils.PackFloatColorToUShort(v1)),
|
||||
SwfUtils.ColorPrecision);
|
||||
|
||||
float v2 = 0.678f;
|
||||
Assert.AreEqual(
|
||||
v2,
|
||||
SwfUtils.UnpackFloatColorFromUShort(SwfUtils.PackFloatColorToUShort(v2)),
|
||||
SwfUtils.ColorPrecision);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void PackColorToUIntsTests() {
|
||||
var v0 = new Color(0.01f, 0.02f, 0.33f, 1.0f);
|
||||
uint u0, u1;
|
||||
SwfUtils.PackColorToUInts(v0, out u0, out u1);
|
||||
Color c0;
|
||||
SwfUtils.UnpackColorFromUInts(u0, u1, out c0);
|
||||
AssertAreEqualVectors(
|
||||
v0, c0, SwfUtils.ColorPrecision);
|
||||
|
||||
var v1 = new Vector4(0.01f, 0.02f, 0.33f, 1.0f);
|
||||
uint u2, u3;
|
||||
SwfUtils.PackColorToUInts(v1, out u2, out u3);
|
||||
Vector4 c1;
|
||||
SwfUtils.UnpackColorFromUInts(u2, u3, out c1);
|
||||
AssertAreEqualVectors(
|
||||
v1, c1, SwfUtils.ColorPrecision);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void PackCoordsToUIntTests() {
|
||||
var v0 = new Vector2(1.14f, 2.23f);
|
||||
AssertAreEqualVectors(
|
||||
v0,
|
||||
SwfUtils.UnpackCoordsFromUInt(SwfUtils.PackCoordsToUInt(v0)),
|
||||
SwfUtils.CoordPrecision);
|
||||
|
||||
var v1 = new Vector2(1234.14f, 3200.23f);
|
||||
AssertAreEqualVectors(
|
||||
v1,
|
||||
SwfUtils.UnpackCoordsFromUInt(SwfUtils.PackCoordsToUInt(v1)),
|
||||
SwfUtils.CoordPrecision);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56c243ac3822b44ffa1520cfc5471e75
|
||||
timeCreated: 1473785856
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,21 +3,52 @@
|
||||
namespace FlashTools.Internal {
|
||||
public static class SwfUtils {
|
||||
|
||||
public const float UVPrecision = 0.0001f;
|
||||
public const float CoordPrecision = 0.05f;
|
||||
public const float ColorPrecision = 0.002f;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
public static uint PackUShortsToUInt(ushort x, ushort y) {
|
||||
var xx = (uint)x;
|
||||
var yy = (uint)y;
|
||||
return (xx << 16) + yy;
|
||||
}
|
||||
|
||||
public static void UnpackUShortsFromUInt(uint pack, out ushort x, out ushort y) {
|
||||
var xx = ((pack >> 16) & 0xFFFF);
|
||||
var yy = (pack & 0xFFFF);
|
||||
x = (ushort)xx;
|
||||
y = (ushort)yy;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
public static uint PackUV(float u, float v) {
|
||||
var uu = (uint)(Mathf.Clamp01(u) * ushort.MaxValue);
|
||||
var vv = (uint)(Mathf.Clamp01(v) * ushort.MaxValue);
|
||||
return (uu << 16) + vv;
|
||||
}
|
||||
|
||||
public static Vector2 UnpackUV(uint v) {
|
||||
var uu = ((v >> 16) & 0xFFFF);
|
||||
var vv = (v & 0xFFFF);
|
||||
return new Vector2(
|
||||
(float)uu / ushort.MaxValue,
|
||||
(float)vv / ushort.MaxValue);
|
||||
public static void UnpackUV(uint pack, out float u, out float v) {
|
||||
var uu = ((pack >> 16) & 0xFFFF);
|
||||
var vv = (pack & 0xFFFF);
|
||||
u = (float)uu / ushort.MaxValue;
|
||||
v = (float)vv / ushort.MaxValue;
|
||||
}
|
||||
|
||||
public static uint PackUV(Vector2 uv) {
|
||||
return PackUV(uv.x, uv.y);
|
||||
}
|
||||
|
||||
public static Vector2 UnpackUV(uint pack) {
|
||||
float u, v;
|
||||
UnpackUV(pack, out u, out v);
|
||||
return new Vector2(u, v);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -31,50 +62,62 @@ namespace FlashTools.Internal {
|
||||
short.MaxValue);
|
||||
}
|
||||
|
||||
public static float UnpackFloatColorFromUShort(ushort v) {
|
||||
return (short)v / (1.0f / ColorPrecision);
|
||||
public static float UnpackFloatColorFromUShort(ushort pack) {
|
||||
return (short)pack / (1.0f / ColorPrecision);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
public static void PackColorToUInts(Color v, out uint u0, out uint u1) {
|
||||
PackColorToUInts(v.r, v.g, v.b, v.a, out u0, out u1);
|
||||
public static void PackColorToUInts(
|
||||
Color v,
|
||||
out uint pack0, out uint pack1)
|
||||
{
|
||||
PackColorToUInts(v.r, v.g, v.b, v.a, out pack0, out pack1);
|
||||
}
|
||||
|
||||
public static void PackColorToUInts(Vector4 v, out uint u0, out uint u1) {
|
||||
PackColorToUInts(v.x, v.y, v.z, v.w, out u0, out u1);
|
||||
public static void PackColorToUInts(
|
||||
Vector4 v,
|
||||
out uint pack0, out uint pack1)
|
||||
{
|
||||
PackColorToUInts(v.x, v.y, v.z, v.w, out pack0, out pack1);
|
||||
}
|
||||
|
||||
public static void PackColorToUInts(
|
||||
float v0, float v1, float v2, float v3,
|
||||
out uint u0, out uint u1)
|
||||
out uint pack0, out uint pack1)
|
||||
{
|
||||
var s0 = PackFloatColorToUShort(v0);
|
||||
var s1 = PackFloatColorToUShort(v1);
|
||||
var s2 = PackFloatColorToUShort(v2);
|
||||
var s3 = PackFloatColorToUShort(v3);
|
||||
u0 = PackUShortsToUInt(s0, s1);
|
||||
u1 = PackUShortsToUInt(s2, s3);
|
||||
pack0 = PackUShortsToUInt(
|
||||
PackFloatColorToUShort(v0),
|
||||
PackFloatColorToUShort(v1));
|
||||
pack1 = PackUShortsToUInt(
|
||||
PackFloatColorToUShort(v2),
|
||||
PackFloatColorToUShort(v3));
|
||||
}
|
||||
|
||||
public static void UnpackColorFromUInts(uint u0, uint u1, out Color v) {
|
||||
public static void UnpackColorFromUInts(
|
||||
uint pack0, uint pack1,
|
||||
out Color color)
|
||||
{
|
||||
ushort s0, s1, s2, s3;
|
||||
UnpackUShortsFromUInt(u0, out s0, out s1);
|
||||
UnpackUShortsFromUInt(u1, out s2, out s3);
|
||||
v = new Color(
|
||||
UnpackUShortsFromUInt(pack0, out s0, out s1);
|
||||
UnpackUShortsFromUInt(pack1, out s2, out s3);
|
||||
color = new Color(
|
||||
UnpackFloatColorFromUShort(s0),
|
||||
UnpackFloatColorFromUShort(s1),
|
||||
UnpackFloatColorFromUShort(s2),
|
||||
UnpackFloatColorFromUShort(s3));
|
||||
}
|
||||
|
||||
public static void UnpackColorFromUInts(uint u0, uint u1, out Vector4 v) {
|
||||
public static void UnpackColorFromUInts(
|
||||
uint pack0, uint pack1,
|
||||
out Vector4 color)
|
||||
{
|
||||
ushort s0, s1, s2, s3;
|
||||
UnpackUShortsFromUInt(u0, out s0, out s1);
|
||||
UnpackUShortsFromUInt(u1, out s2, out s3);
|
||||
v = new Vector4(
|
||||
UnpackUShortsFromUInt(pack0, out s0, out s1);
|
||||
UnpackUShortsFromUInt(pack1, out s2, out s3);
|
||||
color = new Vector4(
|
||||
UnpackFloatColorFromUShort(s0),
|
||||
UnpackFloatColorFromUShort(s1),
|
||||
UnpackFloatColorFromUShort(s2),
|
||||
@@ -85,23 +128,6 @@ namespace FlashTools.Internal {
|
||||
//
|
||||
//
|
||||
|
||||
public static uint PackUShortsToUInt(ushort x, ushort y) {
|
||||
var xx = (uint)x;
|
||||
var yy = (uint)y;
|
||||
return (xx << 16) + yy;
|
||||
}
|
||||
|
||||
public static void UnpackUShortsFromUInt(uint v, out ushort x, out ushort y) {
|
||||
var xx = ((v >> 16) & 0xFFFF);
|
||||
var yy = (v & 0xFFFF);
|
||||
x = (ushort)xx;
|
||||
y = (ushort)yy;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
public static ushort PackFloatCoordToUShort(float v) {
|
||||
return (ushort)Mathf.Clamp(
|
||||
v * (1.0f / CoordPrecision),
|
||||
@@ -109,26 +135,38 @@ namespace FlashTools.Internal {
|
||||
ushort.MaxValue);
|
||||
}
|
||||
|
||||
public static float UnpackFloatCoordFromUShort(ushort v) {
|
||||
return v / (1.0f / CoordPrecision);
|
||||
public static float UnpackFloatCoordFromUShort(ushort pack) {
|
||||
return pack / (1.0f / CoordPrecision);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
public static uint PackCoordsToUInt(float x, float y) {
|
||||
return PackUShortsToUInt(
|
||||
PackFloatCoordToUShort(x),
|
||||
PackFloatCoordToUShort(y));
|
||||
}
|
||||
|
||||
public static void UnpackCoordsFromUInt(
|
||||
uint pack,
|
||||
out float x, out float y)
|
||||
{
|
||||
ushort sx, sy;
|
||||
UnpackUShortsFromUInt(pack, out sx, out sy);
|
||||
x = SwfUtils.UnpackFloatCoordFromUShort(sx);
|
||||
y = SwfUtils.UnpackFloatCoordFromUShort(sy);
|
||||
}
|
||||
|
||||
public static uint PackCoordsToUInt(Vector2 v) {
|
||||
return PackUShortsToUInt(
|
||||
PackFloatCoordToUShort(v.x),
|
||||
PackFloatCoordToUShort(v.y));
|
||||
return PackCoordsToUInt(v.x, v.y);
|
||||
}
|
||||
|
||||
public static Vector2 UnpackCoordsFromUInt(uint v) {
|
||||
ushort sx, sy;
|
||||
UnpackUShortsFromUInt(v, out sx, out sy);
|
||||
return new Vector2(
|
||||
SwfUtils.UnpackFloatCoordFromUShort(sx),
|
||||
SwfUtils.UnpackFloatCoordFromUShort(sy));
|
||||
public static Vector2 UnpackCoordsFromUInt(uint pack) {
|
||||
float x, y;
|
||||
UnpackCoordsFromUInt(pack, out x, out y);
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,45 +5,36 @@ using System.Collections.Generic;
|
||||
namespace FlashTools {
|
||||
[System.Serializable]
|
||||
public struct SwfMatrixData {
|
||||
public float ScX;
|
||||
public float ScY;
|
||||
public float SkX;
|
||||
public float SkY;
|
||||
public float TrX;
|
||||
public float TrY;
|
||||
public Vector2 Sc;
|
||||
public Vector2 Sk;
|
||||
public Vector2 Tr;
|
||||
|
||||
public static SwfMatrixData identity {
|
||||
get {
|
||||
return new SwfMatrixData{
|
||||
ScX = 1.0f,
|
||||
ScY = 1.0f,
|
||||
SkX = 0.0f,
|
||||
SkY = 0.0f,
|
||||
TrX = 0.0f,
|
||||
TrY = 0.0f};
|
||||
Sc = Vector2.one,
|
||||
Sk = Vector2.zero,
|
||||
Tr = Vector2.zero};
|
||||
}
|
||||
}
|
||||
|
||||
public static SwfMatrixData FromUnityMatrix(Matrix4x4 mat) {
|
||||
return new SwfMatrixData{
|
||||
ScX = mat.m00,
|
||||
ScY = mat.m11,
|
||||
SkX = mat.m10,
|
||||
SkY = mat.m01,
|
||||
TrX = mat.m03,
|
||||
TrY = mat.m13};
|
||||
}
|
||||
|
||||
public Matrix4x4 ToUnityMatrix() {
|
||||
public Matrix4x4 ToUMatrix() {
|
||||
var mat = Matrix4x4.identity;
|
||||
mat.m00 = ScX;
|
||||
mat.m11 = ScY;
|
||||
mat.m10 = SkX;
|
||||
mat.m01 = SkY;
|
||||
mat.m03 = TrX;
|
||||
mat.m13 = TrY;
|
||||
mat.m00 = Sc.x;
|
||||
mat.m11 = Sc.y;
|
||||
mat.m10 = Sk.x;
|
||||
mat.m01 = Sk.y;
|
||||
mat.m03 = Tr.x;
|
||||
mat.m13 = Tr.y;
|
||||
return mat;
|
||||
}
|
||||
|
||||
public static SwfMatrixData FromUMatrix(Matrix4x4 mat) {
|
||||
return new SwfMatrixData{
|
||||
Sc = new Vector2(mat.m00, mat.m11),
|
||||
Sk = new Vector2(mat.m10, mat.m01),
|
||||
Tr = new Vector2(mat.m03, mat.m13)};
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
||||
@@ -3,93 +3,11 @@ using FlashTools.Internal;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FlashTools {
|
||||
public static class SwfClipAssetCache {
|
||||
public static List<int> Triangles = new List<int>();
|
||||
public static void FillTriangles(int start_vertex, int triangle_count) {
|
||||
Triangles.Clear();
|
||||
if ( Triangles.Capacity < triangle_count ) {
|
||||
Triangles.Capacity = triangle_count * 2;
|
||||
}
|
||||
for ( var i = 0; i < triangle_count; i += 6 ) {
|
||||
Triangles.Add(start_vertex + 2);
|
||||
Triangles.Add(start_vertex + 1);
|
||||
Triangles.Add(start_vertex + 0);
|
||||
Triangles.Add(start_vertex + 0);
|
||||
Triangles.Add(start_vertex + 3);
|
||||
Triangles.Add(start_vertex + 2);
|
||||
start_vertex += 4;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Vector3> Vertices = new List<Vector3>();
|
||||
public static void FillVertices(
|
||||
Vector2 mesh_min, float mesh_scale, List<uint> vertices)
|
||||
{
|
||||
Vertices.Clear();
|
||||
if ( Vertices.Capacity < vertices.Count ) {
|
||||
Vertices.Capacity = vertices.Count * 2;
|
||||
}
|
||||
for ( int i = 0, e = vertices.Count; i < e; ++i ) {
|
||||
Vertices.Add(
|
||||
(mesh_min +
|
||||
SwfUtils.UnpackCoordsFromUInt(vertices[i])) / mesh_scale);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Vector2> UVs = new List<Vector2>();
|
||||
public static void FillUVs(List<uint> uvs) {
|
||||
UVs.Clear();
|
||||
if ( UVs.Capacity < uvs.Count * 2 ) {
|
||||
UVs.Capacity = uvs.Count * 2 * 2;
|
||||
}
|
||||
for ( int i = 0, e = uvs.Count; i < e; i += 2 ) {
|
||||
var min = SwfUtils.UnpackUV(uvs[i+0]);
|
||||
var max = SwfUtils.UnpackUV(uvs[i+1]);
|
||||
UVs.Add(new Vector2(min.x, min.y));
|
||||
UVs.Add(new Vector2(max.x, min.y));
|
||||
UVs.Add(new Vector2(max.x, max.y));
|
||||
UVs.Add(new Vector2(min.x, max.y));
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Vector4> AddColors = new List<Vector4>();
|
||||
public static void FillAddColors(List<uint> colors) {
|
||||
AddColors.Clear();
|
||||
if ( AddColors.Capacity < colors.Count * 2 ) {
|
||||
AddColors.Capacity = colors.Count * 2 * 2;
|
||||
}
|
||||
for ( int i = 0, e = colors.Count; i < e; i += 2 ) {
|
||||
Vector4 color;
|
||||
SwfUtils.UnpackColorFromUInts(colors[i+0], colors[i+1], out color);
|
||||
AddColors.Add(color);
|
||||
AddColors.Add(color);
|
||||
AddColors.Add(color);
|
||||
AddColors.Add(color);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Color> MulColors = new List<Color>();
|
||||
public static void FillMulColors(List<uint> colors) {
|
||||
MulColors.Clear();
|
||||
if ( MulColors.Capacity < colors.Count * 2 ) {
|
||||
MulColors.Capacity = colors.Count * 2 * 2;
|
||||
}
|
||||
for ( int i = 0, e = colors.Count; i < e; i += 2 ) {
|
||||
Color color;
|
||||
SwfUtils.UnpackColorFromUInts(colors[i+0], colors[i+1], out color);
|
||||
MulColors.Add(color);
|
||||
MulColors.Add(color);
|
||||
MulColors.Add(color);
|
||||
MulColors.Add(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SwfClipAsset : ScriptableObject {
|
||||
[System.Serializable]
|
||||
public class SubMeshData {
|
||||
public int StartVertex;
|
||||
public int TriangleCount;
|
||||
public int IndexCount;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
@@ -109,10 +27,10 @@ namespace FlashTools {
|
||||
SwfClipAssetCache.FillVertices(MeshMin, MeshScale, Vertices);
|
||||
mesh.SetVertices(SwfClipAssetCache.Vertices);
|
||||
|
||||
for ( var i = 0; i < SubMeshes.Count; ++i ) {
|
||||
for ( int i = 0, e = SubMeshes.Count; i < e; ++i ) {
|
||||
SwfClipAssetCache.FillTriangles(
|
||||
SubMeshes[i].StartVertex, SubMeshes[i].TriangleCount);
|
||||
mesh.SetTriangles(SwfClipAssetCache.Triangles, i);
|
||||
SubMeshes[i].StartVertex, SubMeshes[i].IndexCount);
|
||||
mesh.SetTriangles(SwfClipAssetCache.Indices, i);
|
||||
}
|
||||
|
||||
SwfClipAssetCache.FillUVs(UVs);
|
||||
@@ -177,4 +95,94 @@ namespace FlashTools {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// SwfClipAssetCache
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
static class SwfClipAssetCache {
|
||||
public static List<int> Indices = new List<int>();
|
||||
public static void FillTriangles(int start_vertex, int index_count) {
|
||||
Indices.Clear();
|
||||
if ( Indices.Capacity < index_count ) {
|
||||
Indices.Capacity = index_count * 2;
|
||||
}
|
||||
for ( var i = 0; i < index_count; i += 6 ) {
|
||||
Indices.Add(start_vertex + 2);
|
||||
Indices.Add(start_vertex + 1);
|
||||
Indices.Add(start_vertex + 0);
|
||||
Indices.Add(start_vertex + 0);
|
||||
Indices.Add(start_vertex + 3);
|
||||
Indices.Add(start_vertex + 2);
|
||||
start_vertex += 4;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Vector3> Vertices = new List<Vector3>();
|
||||
public static void FillVertices(
|
||||
Vector2 mesh_min, float mesh_scale, List<uint> vertices)
|
||||
{
|
||||
Vertices.Clear();
|
||||
if ( Vertices.Capacity < vertices.Count ) {
|
||||
Vertices.Capacity = vertices.Count * 2;
|
||||
}
|
||||
for ( int i = 0, e = vertices.Count; i < e; ++i ) {
|
||||
Vertices.Add(
|
||||
(mesh_min + SwfUtils.UnpackCoordsFromUInt(vertices[i])) /
|
||||
mesh_scale);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Vector2> UVs = new List<Vector2>();
|
||||
public static void FillUVs(List<uint> uvs) {
|
||||
UVs.Clear();
|
||||
if ( UVs.Capacity < uvs.Count * 2 ) {
|
||||
UVs.Capacity = uvs.Count * 2 * 2;
|
||||
}
|
||||
for ( int i = 0, e = uvs.Count; i < e; i += 2 ) {
|
||||
var min = SwfUtils.UnpackUV(uvs[i+0]);
|
||||
var max = SwfUtils.UnpackUV(uvs[i+1]);
|
||||
UVs.Add(new Vector2(min.x, min.y));
|
||||
UVs.Add(new Vector2(max.x, min.y));
|
||||
UVs.Add(new Vector2(max.x, max.y));
|
||||
UVs.Add(new Vector2(min.x, max.y));
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Vector4> AddColors = new List<Vector4>();
|
||||
public static void FillAddColors(List<uint> colors) {
|
||||
AddColors.Clear();
|
||||
if ( AddColors.Capacity < colors.Count * 2 ) {
|
||||
AddColors.Capacity = colors.Count * 2 * 2;
|
||||
}
|
||||
for ( int i = 0, e = colors.Count; i < e; i += 2 ) {
|
||||
Vector4 color;
|
||||
SwfUtils.UnpackColorFromUInts(
|
||||
colors[i+0], colors[i+1], out color);
|
||||
AddColors.Add(color);
|
||||
AddColors.Add(color);
|
||||
AddColors.Add(color);
|
||||
AddColors.Add(color);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Color> MulColors = new List<Color>();
|
||||
public static void FillMulColors(List<uint> colors) {
|
||||
MulColors.Clear();
|
||||
if ( MulColors.Capacity < colors.Count * 2 ) {
|
||||
MulColors.Capacity = colors.Count * 2 * 2;
|
||||
}
|
||||
for ( int i = 0, e = colors.Count; i < e; i += 2 ) {
|
||||
Color color;
|
||||
SwfUtils.UnpackColorFromUInts(
|
||||
colors[i+0], colors[i+1], out color);
|
||||
MulColors.Add(color);
|
||||
MulColors.Add(color);
|
||||
MulColors.Add(color);
|
||||
MulColors.Add(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
<Properties StartupItem="Assembly-CSharp.csproj">
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="Unity.Instance.Unity Editor" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/FlashTools/Scripts/Internal/SwfUtils.cs">
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/FlashTools/Scripts/SwfClipAsset.cs">
|
||||
<Files>
|
||||
<File FileName="Assets/FlashTools/Scripts/Internal/Editor/Postprocessors/SwfAssetPostprocessor.cs" Line="232" Column="32" />
|
||||
<File FileName="Assets/FlashTools/Scripts/SwfClipAsset.cs" Line="42" Column="40" />
|
||||
<File FileName="Assets/FlashTools/Scripts/Internal/SwfUtils.cs" Line="13" Column="2" NotebookId="1" />
|
||||
<File FileName="Assets/FlashTools/Scripts/SwfClipAsset.cs" Line="37" Column="18" />
|
||||
<File FileName="Assets/FlashTools/Scripts/Internal/Editor/Postprocessors/SwfAssetPostprocessor.cs" Line="239" Column="20" />
|
||||
<File FileName="Assets/FlashTools/Scripts/Internal/SwfUtils.cs" Line="131" Column="7" NotebookId="1" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
|
||||
Reference in New Issue
Block a user