Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images #47

Merged
merged 6 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion flare_dart/lib/actor.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import "dart:typed_data";
import "dart:convert";
import "actor_image.dart";
Expand Down Expand Up @@ -96,10 +97,15 @@ abstract class Actor {

RadialGradientStroke makeRadialStroke();

void load(ByteData data) {
Future<bool> loadAtlases(List<Uint8List> rawAtlases);

Future<bool> load(ByteData data, dynamic context) async {
if (data.lengthInBytes < 5) {
throw UnsupportedError("Not a valid Flare file.");
}

bool success = true;

int F = data.getUint8(0);
int L = data.getUint8(1);
int A = data.getUint8(2);
Expand All @@ -126,8 +132,15 @@ abstract class Actor {
case BlockTypes.Artboards:
readArtboardsBlock(block);
break;

case BlockTypes.Atlases:
List<Uint8List> rawAtlases = await readAtlasesBlock(block, context);
success = await loadAtlases(rawAtlases);
break;
}
}

return success;
}

void readArtboardsBlock(StreamReader block) {
Expand All @@ -152,4 +165,45 @@ abstract class Actor {
}
}
}

Future<Uint8List> readOutOfBandAsset(String filename, dynamic context);

Future<List<Uint8List>> readAtlasesBlock(
StreamReader block, dynamic context) {
// Determine whether or not the atlas is in or out of band.
bool isOOB = block.readBool("isOOB");
block.openArray("data");
int numAtlases = block.readUint16Length();
if (isOOB) {
List<Future<Uint8List>> waitingFor = List<Future<Uint8List>>(numAtlases);
for (int i = 0; i < numAtlases; i++) {
waitingFor[i] = readOutOfBandAsset(block.readString("data"), context);
}
return Future.wait(waitingFor);
} else {
// This is sync.
List<Uint8List> inBandAssets = List<Uint8List>(numAtlases);
for (int i = 0; i < numAtlases; i++) {
inBandAssets[i] = block.readAsset();
}
Completer<List<Uint8List>> completer = Completer<List<Uint8List>>();
completer.complete(inBandAssets);
return completer.future;
}

// for(int i = 0; i < numAtlases; i++)
// {
// if(isOOB)
// {

// // Read from assets
// }
// else
// {
// // Read from data block.
// block.readUint32("length");
// }
// }
block.closeArray();
}
}
31 changes: 9 additions & 22 deletions flare_dart/lib/actor_artboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import "math/aabb.dart";
import "dart:math";

class ActorArtboard {
int _flags = ActorFlags.IsDrawOrderDirty | ActorFlags.IsVertexDeformDirty;
int _flags = ActorFlags.IsDrawOrderDirty;
int _drawableNodeCount = 0;
int _nodeCount = 0;
int _dirtDepth = 0;
Expand Down Expand Up @@ -175,10 +175,6 @@ class ActorArtboard {
_flags |= ActorFlags.IsDrawOrderDirty;
}

bool get isVertexDeformDirty {
return (_flags & ActorFlags.IsVertexDeformDirty) != 0x00;
}

ActorArtboard makeInstance() {
ActorArtboard artboardInstance = ActorArtboard(_actor);
artboardInstance.copyArtboard(this);
Expand Down Expand Up @@ -297,16 +293,6 @@ class ActorArtboard {
}
}
}
if ((_flags & ActorFlags.IsVertexDeformDirty) != 0) {
_flags &= ~ActorFlags.IsVertexDeformDirty;
for (int i = 0; i < _drawableNodeCount; i++) {
ActorDrawable drawable = _drawableNodes[i];
if (drawable is ActorImage && drawable.isVertexDeformDirty) {
drawable.isVertexDeformDirty = false;
//updateVertexDeform(drawable);
}
}
}
}

void read(StreamReader reader) {
Expand Down Expand Up @@ -359,13 +345,14 @@ class ActorArtboard {
component = ActorRootBone.read(this, nodeBlock, null);
break;

case BlockTypes.ActorImageSequence:
component =
ActorImage.readSequence(this, nodeBlock, actor.makeImageNode());
ActorImage ai = component as ActorImage;
actor.maxTextureIndex = ai
.sequenceFrames.last.atlasIndex; // Last atlasIndex is the biggest
break;
// Todo: fix sequences for flare.
// case BlockTypes.ActorImageSequence:
// component =
// ActorImage.readSequence(this, nodeBlock, actor.makeImageNode());
// ActorImage ai = component as ActorImage;
// actor.maxTextureIndex = ai
// .sequenceFrames.last.atlasIndex; // Last atlasIndex is the biggest
// break;

case BlockTypes.ActorImage:
component = ActorImage.read(this, nodeBlock, actor.makeImageNode());
Expand Down
70 changes: 65 additions & 5 deletions flare_dart/lib/actor_drawable.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,75 @@
import 'package:flare_dart/actor_artboard.dart';
import 'package:flare_dart/actor_shape.dart';
import 'package:flare_dart/stream_reader.dart';

import "math/aabb.dart";
import "actor_node.dart";

enum BlendModes { Normal, Multiply, Screen, Additive }

abstract class ActorDrawable {
abstract class ActorDrawable extends ActorNode {
List<List<ActorShape>> _clipShapes;
List<List<ActorShape>> get clipShapes => _clipShapes;

// Editor set draw index.
int get drawOrder;
set drawOrder(int value);
int _drawOrder;
int get drawOrder => _drawOrder;
set drawOrder(int value) {
if (_drawOrder == value) {
return;
}
_drawOrder = value;
artboard.markDrawOrderDirty();
}

// Computed draw index in the draw list.
int get drawIndex;
set drawIndex(int value);
int drawIndex;
bool isHidden;

bool get doesDraw {
return !isHidden && !renderCollapsed;
}

int get blendModeId;
set blendModeId(int value);

static ActorDrawable read(
ActorArtboard artboard, StreamReader reader, ActorDrawable component) {
ActorNode.read(artboard, reader, component);

component.isHidden = !reader.readBool("isVisible");
component.blendModeId = artboard.actor.version < 21 ? 3 : reader.readUint8("blendMode");
component.drawOrder = reader.readUint16("drawOrder");

return component;
}

void copyDrawable(ActorDrawable node, ActorArtboard resetArtboard) {
copyNode(node, resetArtboard);
// todo blendmode
drawOrder = node.drawOrder;
blendModeId = node.blendModeId;
isHidden = node.isHidden;
}

AABB computeAABB();
void initializeGraphics() {}

void completeResolve() {
_clipShapes = List<List<ActorShape>>();
List<List<ActorClip>> clippers = allClips;
for (List<ActorClip> clips in clippers) {
List<ActorShape> shapes = List<ActorShape>();
for (ActorClip clip in clips) {
clip.node.all((ActorNode node) {
if (node is ActorShape) {
shapes.add(node);
}
});
}
if (shapes.length > 0) {
_clipShapes.add(shapes);
}
}
}
}
3 changes: 1 addition & 2 deletions flare_dart/lib/actor_flags.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class ActorFlags {
static const int IsDrawOrderDirty = 1 << 0;
static const int IsVertexDeformDirty = 1 << 1;
static const int IsDirty = 1 << 2;
static const int IsDirty = 1 << 1;
}

class DirtyFlags {
Expand Down
Loading