mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-16 14:11:19 +07:00
visible and rasterization fix
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -82,7 +82,7 @@ namespace FlashTools.Internal {
|
||||
Matrix4x4 parent_matrix, SwfAnimationColorTransform parent_color_transform,
|
||||
SwfAnimationFrameData frame)
|
||||
{
|
||||
foreach ( var inst in dl.Instances.Values ) {
|
||||
foreach ( var inst in dl.Instances.Values.Where(p => p.Visible) ) {
|
||||
switch ( inst.Type ) {
|
||||
case SwfDisplayInstanceType.Shape:
|
||||
var shape_def = ctx.Library.FindDefine<SwfLibraryShapeDefine>(inst.Id);
|
||||
|
||||
@@ -77,6 +77,7 @@ namespace FlashTools.Internal.SwfTools {
|
||||
|
||||
public ushort Id;
|
||||
public ushort Depth;
|
||||
public bool Visible;
|
||||
public SwfMatrix Matrix;
|
||||
public SwfColorTransform ColorTransform;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace FlashTools.Internal.SwfTools {
|
||||
if ( new_inst != null ) {
|
||||
new_inst.Id = tag.CharacterId;
|
||||
new_inst.Depth = tag.Depth;
|
||||
new_inst.Visible = true;
|
||||
new_inst.Matrix = tag.Matrix;
|
||||
new_inst.ColorTransform = tag.ColorTransform;
|
||||
dl.Instances.Add(new_inst.Depth, new_inst);
|
||||
@@ -70,6 +71,7 @@ namespace FlashTools.Internal.SwfTools {
|
||||
if ( new_inst != null ) {
|
||||
new_inst.Id = tag.CharacterId;
|
||||
new_inst.Depth = tag.Depth;
|
||||
new_inst.Visible = true;
|
||||
new_inst.Matrix = tag.HasMatrix ? tag.Matrix : SwfMatrix.identity;
|
||||
new_inst.ColorTransform = tag.HasColorTransform ? tag.ColorTransform : SwfColorTransform.identity;
|
||||
dl.Instances.Add(new_inst.Depth, new_inst);
|
||||
@@ -90,6 +92,45 @@ namespace FlashTools.Internal.SwfTools {
|
||||
|
||||
public SwfDisplayList Visit(PlaceObject3Tag tag, SwfDisplayList dl) {
|
||||
Debug.Log(tag);
|
||||
var is_shape = tag.HasCharacter
|
||||
? MainContex.Library.HasDefine<SwfLibraryShapeDefine >(tag.CharacterId)
|
||||
: false;
|
||||
var is_sprite = tag.HasCharacter
|
||||
? MainContex.Library.HasDefine<SwfLibrarySpriteDefine>(tag.CharacterId)
|
||||
: false;
|
||||
if ( tag.HasCharacter ) {
|
||||
if ( tag.Move ) { // replace character
|
||||
dl.Instances.Remove(tag.Depth);
|
||||
}
|
||||
// new character
|
||||
SwfDisplayInstance new_inst = null;
|
||||
if ( is_shape ) {
|
||||
new_inst = new SwfDisplayShapeInstance();
|
||||
} else if ( is_sprite ) {
|
||||
new_inst = new SwfDisplaySpriteInstance();
|
||||
}
|
||||
if ( new_inst != null ) {
|
||||
new_inst.Id = tag.CharacterId;
|
||||
new_inst.Depth = tag.Depth;
|
||||
new_inst.Visible = tag.HasVisible ? tag.Visible : true;
|
||||
new_inst.Matrix = tag.HasMatrix ? tag.Matrix : SwfMatrix.identity;
|
||||
new_inst.ColorTransform = tag.HasColorTransform ? tag.ColorTransform : SwfColorTransform.identity;
|
||||
dl.Instances.Add(new_inst.Depth, new_inst);
|
||||
}
|
||||
} else if ( tag.Move ) { // move character
|
||||
SwfDisplayInstance inst;
|
||||
if ( dl.Instances.TryGetValue(tag.Depth, out inst) ) {
|
||||
if ( tag.HasVisible ) {
|
||||
inst.Visible = tag.Visible;
|
||||
}
|
||||
if ( tag.HasMatrix ) {
|
||||
inst.Matrix = tag.Matrix;
|
||||
}
|
||||
if ( tag.HasColorTransform ) {
|
||||
inst.ColorTransform = tag.ColorTransform;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dl;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
public ushort ClipDepth;
|
||||
public SwfSurfaceFilters SurfaceFilters;
|
||||
public SwfBlendMode BlendMode;
|
||||
public byte BitmapCache;
|
||||
public byte Visible;
|
||||
public bool BitmapCache;
|
||||
public bool Visible;
|
||||
public SwfColor BackgroundColor;
|
||||
public SwfClipActions ClipActions;
|
||||
|
||||
@@ -126,12 +126,12 @@ namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
: SwfBlendMode.identity;
|
||||
|
||||
tag.BitmapCache = tag.HasCacheAsBitmap
|
||||
? reader.ReadByte()
|
||||
: (byte)0;
|
||||
? (0 != reader.ReadByte())
|
||||
: false;
|
||||
|
||||
tag.Visible = tag.HasVisible
|
||||
? reader.ReadByte()
|
||||
: (byte)1;
|
||||
? (0 != reader.ReadByte())
|
||||
: true;
|
||||
|
||||
tag.BackgroundColor = tag.HasVisible && !reader.IsEOF
|
||||
? SwfColor.Read(reader, true)
|
||||
|
||||
@@ -174,11 +174,18 @@ if (!Function.prototype.bind) {
|
||||
// Document
|
||||
// ------------------------------------
|
||||
|
||||
var ftd = {};
|
||||
var ftdoc = {};
|
||||
|
||||
ftd.prepare_folders = function (document) {
|
||||
ftdoc.full_exit_edit_mode = function (document) {
|
||||
ft.type_assert(document, Document);
|
||||
var export_folder = ftd.get_export_folder(document);
|
||||
for (var i = 0; i < 100; ++i) {
|
||||
document.exitEditMode();
|
||||
}
|
||||
};
|
||||
|
||||
ftdoc.prepare_folders = function (document) {
|
||||
ft.type_assert(document, Document);
|
||||
var export_folder = ftdoc.get_export_folder(document);
|
||||
if (FLfile.exists(export_folder)) {
|
||||
if (!FLfile.remove(export_folder)) {
|
||||
throw "Can't remove document export folder ({0})!"
|
||||
@@ -191,171 +198,55 @@ if (!Function.prototype.bind) {
|
||||
}
|
||||
};
|
||||
|
||||
ftd.full_exit_edit_mode = function (document) {
|
||||
for (var i = 0; i < 100; ++i) {
|
||||
document.exitEditMode();
|
||||
}
|
||||
};
|
||||
|
||||
ftd.delete_unused_items = function(document) {
|
||||
var unused_items = document.library.unusedItems;
|
||||
ft.array_foreach(unused_items, function (item) {
|
||||
ft.trace_fmt("Remove unused item: {0}", item.name);
|
||||
document.library.deleteItem(item.name);
|
||||
});
|
||||
};
|
||||
|
||||
ftd.convert_shapes = function(document) {
|
||||
ftt.convert(document.getTimeline());
|
||||
ftlib.convert(document.library, document);
|
||||
|
||||
ftt.prepare(document.getTimeline(), document);
|
||||
ftlib.prepare(document.library, document);
|
||||
};
|
||||
|
||||
ftd.prepare_bitmaps = function (document) {
|
||||
ftdoc.delete_unused_items = function(document) {
|
||||
ft.type_assert(document, Document);
|
||||
ft.array_foreach(document.library.items, function(item) {
|
||||
//ft.trace_fmt("-Item: {0}", item.name);
|
||||
if ( item.itemType == "bitmap" ) {
|
||||
item.compressionType = "lossless";
|
||||
}
|
||||
});
|
||||
ftlib.delete_unused_items(document.library);
|
||||
};
|
||||
|
||||
ftdoc.prepare_keyframes = function(document) {
|
||||
ftlib.prepare_keyframes(document.library, document);
|
||||
fttim.prepare_keyframes(document.getTimeline());
|
||||
};
|
||||
|
||||
ftd.export_swf = function (document) {
|
||||
ftdoc.convert_shapes = function(document) {
|
||||
ftlib.convert_shapes(document.library, document);
|
||||
fttim.convert_shapes(document.getTimeline(), document);
|
||||
};
|
||||
|
||||
ftdoc.prepare_bitmaps = function (document) {
|
||||
ft.type_assert(document, Document);
|
||||
document.exportSWF(ftd.get_swf_export_path(document));
|
||||
ftlib.prepare_bitmaps(document.library);
|
||||
};
|
||||
|
||||
ftd.get_document_name = function (document) {
|
||||
ftdoc.export_swf = function (document) {
|
||||
ft.type_assert(document, Document);
|
||||
document.exportSWF(ftdoc.get_swf_export_path(document));
|
||||
};
|
||||
|
||||
ftdoc.get_document_name = function (document) {
|
||||
ft.type_assert(document, Document);
|
||||
return document.name;
|
||||
};
|
||||
|
||||
ftd.get_document_path = function (document) {
|
||||
ftdoc.get_document_path = function (document) {
|
||||
ft.type_assert(document, Document);
|
||||
return ft.escape_path(document.pathURI);
|
||||
};
|
||||
|
||||
ftd.get_export_folder = function (document) {
|
||||
ftdoc.get_export_folder = function (document) {
|
||||
ft.type_assert(document, Document);
|
||||
return ft.combine_path(
|
||||
ftd.get_document_path(document),
|
||||
ftdoc.get_document_path(document),
|
||||
"_export/");
|
||||
};
|
||||
|
||||
ftd.get_swf_export_path = function (document) {
|
||||
ftdoc.get_swf_export_path = function (document) {
|
||||
ft.type_assert(document, Document);
|
||||
return ft.combine_path(
|
||||
ftd.get_export_folder(document),
|
||||
ftd.get_document_name(document) + ".swf");
|
||||
ftdoc.get_export_folder(document),
|
||||
ftdoc.get_document_name(document) + ".swf");
|
||||
};
|
||||
|
||||
// ------------------------------------
|
||||
// Timeline
|
||||
// ------------------------------------
|
||||
|
||||
var ftt = {};
|
||||
|
||||
ftt.remove_empty_layers = function(timeline) {
|
||||
var layers = timeline.layers;
|
||||
for ( var i = layers.length - 1; i >= 0; --i ) {
|
||||
if (ftl.is_empty(layers[i])) {
|
||||
timeline.deleteLayer(i);
|
||||
layers = timeline.layers;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ftt.convert = function(timeline) {
|
||||
ftt.remove_empty_layers(timeline);
|
||||
if ( timeline.layers.length > 0 && timeline.frameCount > 1 ) {
|
||||
timeline.selectAllFrames();
|
||||
timeline.convertToKeyframes();
|
||||
}
|
||||
ft.array_reverse_foreach(timeline.layers, function(layer, index) {
|
||||
timeline.setSelectedLayers(index);
|
||||
ftl.convert(layer);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
ftt.prepare = function(timeline, document) {
|
||||
ft.array_reverse_foreach(timeline.layers, function(layer, index) {
|
||||
timeline.setSelectedLayers(index);
|
||||
ftl.prepare(layer, timeline, document);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
// ------------------------------------
|
||||
// Layer
|
||||
// ------------------------------------
|
||||
|
||||
var ftl = {};
|
||||
|
||||
ftl.do_in_unlocked = function(layer, func) {
|
||||
ft.type_assert(func, Function);
|
||||
var prev_locked = layer.locked;
|
||||
var prev_visible = layer.visible;
|
||||
layer.locked = false;
|
||||
layer.visible = true;
|
||||
func();
|
||||
layer.locked = prev_locked;
|
||||
layer.visible = prev_visible;
|
||||
};
|
||||
|
||||
ftl.convert = function(layer) {
|
||||
ftl.do_in_unlocked(layer, function() {
|
||||
ft.array_foreach(layer.frames, function(frame, index) {
|
||||
frame.convertToFrameByFrameAnimation();
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
ftl.is_element_shape = function(element) {
|
||||
return element.elementType == "shape"
|
||||
};
|
||||
|
||||
ftl.is_frame_empty = function(frame) {
|
||||
return frame.elements.length == 0;
|
||||
};
|
||||
|
||||
ftl.is_empty = function(layer) {
|
||||
if ( !layer.visible ) {
|
||||
return true;
|
||||
}
|
||||
if ( layer.layerType == "guide" || layer.layerType == "mask" || layer.layerType == "folder" ) {
|
||||
return false;
|
||||
}
|
||||
var frames = layer.frames;
|
||||
for ( var i = 0; i < frames.length; ++i ) {
|
||||
if (!ftl.is_frame_empty(frames[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
ftl.prepare = function(layer, timeline, document) {
|
||||
ftl.do_in_unlocked(layer, function() {
|
||||
ft.array_foreach(layer.frames, function(frame, index) {
|
||||
if (frame.startFrame == index) {
|
||||
timeline.setSelectedFrames(index, index + 1);
|
||||
|
||||
timeline.currentFrame = frame.startFrame;
|
||||
document.selectNone();
|
||||
document.selection = ft.array_filter(
|
||||
frame.elements,
|
||||
ftl.is_element_shape.bind(this));
|
||||
if ( document.selection.length > 0 ) {
|
||||
document.convertSelectionToBitmap();
|
||||
document.arrange("back");
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Library
|
||||
// ------------------------------------
|
||||
@@ -382,28 +273,146 @@ if (!Function.prototype.bind) {
|
||||
ft.type_assert_if_defined(filter, Function);
|
||||
ft.array_foreach(library.items, func, filter);
|
||||
};
|
||||
|
||||
ftlib.convert = function(library, document) {
|
||||
|
||||
ftlib.delete_unused_items = function(library) {
|
||||
ft.type_assert(library, Library);
|
||||
var unused_items = library.unusedItems;
|
||||
ft.array_foreach(unused_items, function (item) {
|
||||
ft.trace_fmt("Remove unused item: {0}", item.name);
|
||||
library.deleteItem(item.name);
|
||||
});
|
||||
};
|
||||
|
||||
ftlib.prepare_keyframes = function(library, document) {
|
||||
ft.type_assert(library, Library);
|
||||
ft.type_assert(document, Document);
|
||||
ftlib.for_each_by_items(library, function (item) {
|
||||
if ( library.editItem(item.name) ) {
|
||||
ft.trace_fmt("Convert: {0}", item.name);
|
||||
ftsym.convert(item, document);
|
||||
ftsym.prepare_keyframes(item);
|
||||
document.exitEditMode();
|
||||
}
|
||||
}.bind(this), this.is_symbol_item.bind(this));
|
||||
};
|
||||
|
||||
ftlib.prepare = function(library, document) {
|
||||
|
||||
ftlib.convert_shapes = function(library, document) {
|
||||
ft.type_assert(library, Library);
|
||||
ft.type_assert(document, Document);
|
||||
ftlib.for_each_by_items(library, function (item) {
|
||||
if ( library.editItem(item.name) ) {
|
||||
ft.trace_fmt("Prepare: {0}", item.name);
|
||||
ftsym.prepare(item, document);
|
||||
ftsym.convert_shapes(item, document);
|
||||
document.exitEditMode();
|
||||
}
|
||||
}.bind(this), this.is_symbol_item.bind(this));
|
||||
};
|
||||
|
||||
ftlib.prepare_bitmaps = function(library) {
|
||||
ft.type_assert(library, Library);
|
||||
ftlib.for_each_by_items(library, function (item) {
|
||||
ft.trace_fmt("Prepare bitmap: {0}", item.name);
|
||||
item.compressionType = "lossless";
|
||||
}.bind(this), this.is_bitmap_item.bind(this));
|
||||
};
|
||||
|
||||
// ------------------------------------
|
||||
// Timeline
|
||||
// ------------------------------------
|
||||
|
||||
var fttim = {};
|
||||
|
||||
fttim.remove_empty_layers = function(timeline) {
|
||||
ft.type_assert(timeline, Timeline);
|
||||
var layers = timeline.layers;
|
||||
for ( var i = layers.length - 1; i >= 0; --i ) {
|
||||
if (ftlay.is_empty(layers[i])) {
|
||||
timeline.deleteLayer(i);
|
||||
layers = timeline.layers;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fttim.prepare_keyframes = function(timeline) {
|
||||
ft.type_assert(timeline, Timeline);
|
||||
fttim.remove_empty_layers(timeline);
|
||||
if ( timeline.layers.length > 0 && timeline.frameCount > 1 ) {
|
||||
timeline.selectAllFrames();
|
||||
timeline.convertToKeyframes();
|
||||
}
|
||||
ft.array_reverse_foreach(timeline.layers, function(layer, index) {
|
||||
timeline.setSelectedLayers(index);
|
||||
ftlay.prepare_keyframes(layer);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
fttim.convert_shapes = function(timeline, document) {
|
||||
ft.type_assert(timeline, Timeline);
|
||||
ft.array_reverse_foreach(timeline.layers, function(layer, index) {
|
||||
timeline.setSelectedLayers(index);
|
||||
ftlay.convert_shapes(layer, timeline, document);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
// ------------------------------------
|
||||
// Layer
|
||||
// ------------------------------------
|
||||
|
||||
var ftlay = {};
|
||||
|
||||
ftlay.do_in_unlocked = function(layer, func) {
|
||||
ft.type_assert(layer, Layer);
|
||||
ft.type_assert(func, Function);
|
||||
var prev_locked = layer.locked;
|
||||
var prev_visible = layer.visible;
|
||||
layer.locked = false;
|
||||
layer.visible = true;
|
||||
func();
|
||||
layer.locked = prev_locked;
|
||||
layer.visible = prev_visible;
|
||||
};
|
||||
|
||||
ftlay.prepare_keyframes = function(layer) {
|
||||
ft.type_assert(layer, Layer);
|
||||
ftlay.do_in_unlocked(layer, function() {
|
||||
ft.array_foreach(layer.frames, function(frame, index) {
|
||||
frame.convertToFrameByFrameAnimation();
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
ftlay.is_empty = function(layer) {
|
||||
if ( !layer.visible ) {
|
||||
return true;
|
||||
}
|
||||
if ( layer.layerType == "guide" || layer.layerType == "mask" || layer.layerType == "folder" ) {
|
||||
return false;
|
||||
}
|
||||
var frames = layer.frames;
|
||||
for ( var i = 0; i < frames.length; ++i ) {
|
||||
var frame = frames[i];
|
||||
if ( frame.elements.length != 0 ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
ftlay.convert_shapes = function(layer, timeline, document) {
|
||||
ftlay.do_in_unlocked(layer, function() {
|
||||
ft.array_foreach(layer.frames, function(frame, index) {
|
||||
if (frame.startFrame == index) {
|
||||
timeline.setSelectedFrames(index, index + 1);
|
||||
timeline.currentFrame = frame.startFrame;
|
||||
document.selectNone();
|
||||
document.selection = ft.array_filter(
|
||||
frame.elements,
|
||||
function(element) { return element.elementType == "shape"; });
|
||||
if ( document.selection.length > 0 ) {
|
||||
document.convertSelectionToBitmap();
|
||||
document.arrange("back");
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Symbol
|
||||
@@ -411,12 +420,12 @@ if (!Function.prototype.bind) {
|
||||
|
||||
var ftsym = {};
|
||||
|
||||
ftsym.convert = function(item, document) {
|
||||
ftt.convert(item.timeline);
|
||||
ftsym.prepare_keyframes = function(item) {
|
||||
fttim.prepare_keyframes(item.timeline);
|
||||
};
|
||||
|
||||
ftsym.prepare = function(item, document) {
|
||||
ftt.prepare(item.timeline, document);
|
||||
ftsym.convert_shapes = function(item, document) {
|
||||
fttim.convert_shapes(item.timeline, document);
|
||||
};
|
||||
|
||||
// ------------------------------------
|
||||
@@ -425,15 +434,24 @@ if (!Function.prototype.bind) {
|
||||
|
||||
(function () {
|
||||
ft.clear_output();
|
||||
fl.showIdleMessage(false);
|
||||
ft.trace("- Start -");
|
||||
ft.array_foreach(fl.documents, function (document) {
|
||||
ft.trace_fmt("Doc: {0}", document.name);
|
||||
ftd.prepare_folders(document);
|
||||
ftd.full_exit_edit_mode(document);
|
||||
ftd.delete_unused_items(document);
|
||||
ftd.convert_shapes(document);
|
||||
ftd.prepare_bitmaps(document);
|
||||
ftd.export_swf(document);
|
||||
//fl.revertDocument(document);
|
||||
try {
|
||||
ft.trace_fmt("Document: {0}", document.name);
|
||||
ftdoc.full_exit_edit_mode(document);
|
||||
ftdoc.prepare_folders(document);
|
||||
ftdoc.delete_unused_items(document);
|
||||
ftdoc.prepare_keyframes(document);
|
||||
ftdoc.convert_shapes(document);
|
||||
ftdoc.prepare_bitmaps(document);
|
||||
ftdoc.export_swf(document);
|
||||
} catch (e) {
|
||||
ft.trace_fmt("- Document conversion error: {0}", e);
|
||||
}
|
||||
fl.revertDocument(document);
|
||||
});
|
||||
ft.trace("- Finish -");
|
||||
fl.showIdleMessage(true);
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user