mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2026-03-22 12:55:32 +07:00
clear mask frame detection
This commit is contained in:
@@ -23,11 +23,12 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
|
||||
void CreateAnimationPrefab() {
|
||||
//TODO: IMPLME
|
||||
}
|
||||
|
||||
void CreateAnimationOnScene() {
|
||||
if ( _asset ) {
|
||||
var anim_go = new GameObject("SwfAnimation");
|
||||
var anim_go = new GameObject(_asset.name);
|
||||
var mesh_renderer = anim_go.AddComponent<MeshRenderer>();
|
||||
mesh_renderer.sharedMaterial = null;
|
||||
mesh_renderer.useLightProbes = false;
|
||||
|
||||
@@ -90,31 +90,13 @@ namespace FlashTools.Internal {
|
||||
SwfAnimationColorTransform parent_color_transform,
|
||||
SwfAnimationFrameData frame)
|
||||
{
|
||||
var masks = new List<SwfAnimationInstanceData>();
|
||||
|
||||
var instances = dl.Instances.Values
|
||||
.Where(p => p.Visible);
|
||||
foreach ( var inst in instances ) {
|
||||
|
||||
foreach ( var mask in masks ) {
|
||||
if ( mask.ClipDepth < inst.Depth ) {
|
||||
frame.Instances.Add(new SwfAnimationInstanceData{
|
||||
Type = SwfAnimationInstanceType.MaskReset,
|
||||
ClipDepth = 0,
|
||||
Bitmap = mask.Bitmap,
|
||||
Matrix = mask.Matrix,
|
||||
ColorTransform = mask.ColorTransform
|
||||
});
|
||||
}
|
||||
}
|
||||
masks.RemoveAll(p => p.ClipDepth < inst.Depth);
|
||||
|
||||
var self_masks = new List<SwfAnimationInstanceData>();
|
||||
foreach ( var inst in dl.Instances.Values.Where(p => p.Visible) ) {
|
||||
CheckSelfMasks(self_masks, inst.Depth, frame);
|
||||
var child_matrix = parent_matrix * inst.Matrix.ToUnityMatrix();
|
||||
var child_color_transform = parent_color_transform * inst.ColorTransform.ToAnimationColorTransform();
|
||||
switch ( inst.Type ) {
|
||||
case SwfDisplayInstanceType.Shape:
|
||||
Debug.LogFormat(
|
||||
"--- Bitmap --- Depth: {0}, ClipDepth: {1}, Mask: {2}",
|
||||
inst.Depth, inst.ClipDepth, inst.ClipDepth > 0);
|
||||
|
||||
var shape_def = ctx.Library.FindDefine<SwfLibraryShapeDefine>(inst.Id);
|
||||
if ( shape_def != null ) {
|
||||
for ( var i = 0; i < shape_def.Bitmaps.Length; ++i ) {
|
||||
@@ -122,38 +104,45 @@ namespace FlashTools.Internal {
|
||||
var bitmap_matrix = i < shape_def.Matrices.Length ? shape_def.Matrices[i] : SwfMatrix.identity;
|
||||
var bitmap_def = ctx.Library.FindDefine<SwfLibraryBitmapDefine>(bitmap_id);
|
||||
if ( bitmap_def != null ) {
|
||||
var frame_inst_type =
|
||||
(parent_mask > 0 || inst.ClipDepth > 0)
|
||||
? SwfAnimationInstanceType.Mask
|
||||
: (parent_masked > 0 || self_masks.Count > 0)
|
||||
? SwfAnimationInstanceType.Masked
|
||||
: SwfAnimationInstanceType.Group;
|
||||
var frame_inst_clip_depth =
|
||||
(parent_mask > 0)
|
||||
? parent_mask
|
||||
: (inst.ClipDepth > 0)
|
||||
? inst.ClipDepth
|
||||
: parent_masked + self_masks.Count;
|
||||
frame.Instances.Add(new SwfAnimationInstanceData{
|
||||
Type = (parent_mask > 0 || inst.ClipDepth > 0) ? SwfAnimationInstanceType.Mask : (parent_masked > 0 || masks.Count > 0 ? SwfAnimationInstanceType.Masked : SwfAnimationInstanceType.Group),
|
||||
ClipDepth = (ushort)(parent_mask > 0 ? parent_mask : (inst.ClipDepth > 0 ? inst.ClipDepth : (parent_masked + masks.Count))),
|
||||
Type = frame_inst_type,
|
||||
ClipDepth = (ushort)frame_inst_clip_depth,
|
||||
Bitmap = bitmap_id,
|
||||
Matrix = parent_matrix * inst.Matrix.ToUnityMatrix() * bitmap_matrix.ToUnityMatrix(),
|
||||
ColorTransform = parent_color_transform * inst.ColorTransform.ToAnimationColorTransform()});
|
||||
|
||||
Matrix = child_matrix * bitmap_matrix.ToUnityMatrix(),
|
||||
ColorTransform = child_color_transform});
|
||||
if ( parent_mask > 0 ) {
|
||||
parent_masks.Add(frame.Instances[frame.Instances.Count - 1]);
|
||||
} else if ( inst.ClipDepth > 0 ) {
|
||||
masks.Add(frame.Instances[frame.Instances.Count - 1]);
|
||||
self_masks.Add(frame.Instances[frame.Instances.Count - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SwfDisplayInstanceType.Sprite:
|
||||
Debug.LogFormat(
|
||||
"--- Sprite --- Depth: {0}, ClipDepth: {1}, Mask: {2}",
|
||||
inst.Depth, inst.ClipDepth, inst.ClipDepth > 0);
|
||||
|
||||
var sprite_def = ctx.Library.FindDefine<SwfLibrarySpriteDefine>(inst.Id);
|
||||
if ( sprite_def != null ) {
|
||||
var sprite_inst = inst as SwfDisplaySpriteInstance;
|
||||
AddDisplayListToFrame(
|
||||
ctx,
|
||||
sprite_inst.DisplayList,
|
||||
(ushort)(parent_masked + masks.Count),
|
||||
(ushort)(parent_masked + self_masks.Count),
|
||||
(ushort)(parent_mask > 0 ? parent_mask : (inst.ClipDepth > 0 ? inst.ClipDepth : (ushort)0)),
|
||||
parent_mask > 0 ? parent_masks : (inst.ClipDepth > 0 ? masks : null),
|
||||
parent_matrix * sprite_inst.Matrix.ToUnityMatrix(),
|
||||
parent_color_transform * sprite_inst.ColorTransform.ToAnimationColorTransform(),
|
||||
parent_mask > 0 ? parent_masks : (inst.ClipDepth > 0 ? self_masks : null),
|
||||
child_matrix,
|
||||
child_color_transform,
|
||||
frame);
|
||||
}
|
||||
break;
|
||||
@@ -162,19 +151,27 @@ namespace FlashTools.Internal {
|
||||
"Unsupported SwfDisplayInstanceType: {0}", inst.Type));
|
||||
}
|
||||
}
|
||||
foreach ( var mask in masks ) {
|
||||
frame.Instances.Add(new SwfAnimationInstanceData{
|
||||
Type = SwfAnimationInstanceType.MaskReset,
|
||||
ClipDepth = 0,
|
||||
Bitmap = mask.Bitmap,
|
||||
Matrix = mask.Matrix,
|
||||
ColorTransform = mask.ColorTransform
|
||||
});
|
||||
}
|
||||
masks.Clear();
|
||||
CheckSelfMasks(self_masks, ushort.MaxValue, frame);
|
||||
return frame;
|
||||
}
|
||||
|
||||
static void CheckSelfMasks(
|
||||
List<SwfAnimationInstanceData> masks, ushort depth, SwfAnimationFrameData frame)
|
||||
{
|
||||
foreach ( var mask in masks ) {
|
||||
if ( mask.ClipDepth < depth ) {
|
||||
frame.Instances.Add(new SwfAnimationInstanceData{
|
||||
Type = SwfAnimationInstanceType.MaskReset,
|
||||
ClipDepth = 0,
|
||||
Bitmap = mask.Bitmap,
|
||||
Matrix = mask.Matrix,
|
||||
ColorTransform = mask.ColorTransform
|
||||
});
|
||||
}
|
||||
}
|
||||
masks.RemoveAll(p => p.ClipDepth < depth);
|
||||
}
|
||||
|
||||
static List<SwfAnimationBitmapData> LoadBitmapsFromContext(
|
||||
string swf_asset, SwfAnimationAsset asset, SwfContext context)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<Properties StartupItem="Assembly-CSharp.csproj">
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="Unity.Instance.Unity Editor" />
|
||||
<MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs">
|
||||
<Files>
|
||||
<File FileName="Assets/FlashTools/Scripts/Internal/Editor/SwfTools/SwfContextExecuter.cs" Line="1" Column="1" />
|
||||
<File FileName="Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs" Line="21" Column="37" />
|
||||
<File FileName="Assets/FlashTools/Scripts/SwfAnimationAsset.cs" Line="40" Column="3" NotebookId="1" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
|
||||
Reference in New Issue
Block a user