Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 5ca8d49
Author: Luigi Rosso <[email protected]>
Date:   Mon Oct 7 11:22:38 2019 -0700

    Bumping versions and changelog.

commit 874ce8e
Author: Luigi Rosso <[email protected]>
Date:   Mon Oct 7 11:20:28 2019 -0700

    Adding support for nodes inside of shapes.

commit 4d06431
Author: Luigi Rosso <[email protected]>
Date:   Fri Oct 4 18:06:09 2019 -0700

    Introducing FlareTesting.setup();

commit 2c5f420
Author: Luigi Rosso <[email protected]>
Date:   Fri Oct 4 13:44:25 2019 -0700

    Clamping trim start/end.

commit daba34d
Author: Luigi Rosso <[email protected]>
Date:   Mon Sep 30 21:21:55 2019 +0200

    Cherry picking critical lints from #1 63 and updating for pub.
  • Loading branch information
luigi-rosso committed Oct 7, 2019
1 parent e3d2414 commit e59d88d
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 64 deletions.
2 changes: 1 addition & 1 deletion example/simple/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 27
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
Expand Down
2 changes: 1 addition & 1 deletion example/simple/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ subprojects {

task clean(type: Delete) {
delete rootProject.buildDir
}
}
1 change: 1 addition & 0 deletions example/simple/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
4 changes: 4 additions & 0 deletions flare_dart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.4.9] - 2019-10-07 11:20:58

- Supporting Nodes inside of Shapes, effectively adding multiple transform spaces inside of a shape.

## [1.4.8] - 2019-09-30 21:19:37

- Fixing linting problems in ActorDrawable and ActorSkin.
Expand Down
11 changes: 8 additions & 3 deletions flare_dart/lib/actor_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -342,25 +342,30 @@ class ActorNode extends ActorComponent {
}
}

@override
void resolveComponentIndices(List<ActorComponent> components) {
super.resolveComponentIndices(components);

if (_clips == null) {
return;
}

for (ActorClip clip in _clips) {
clip.node = components[clip.clipIdx];
for (final ActorClip clip in _clips) {
final ActorComponent component = components[clip.clipIdx];
if (component is ActorNode) {
clip.node = component;
}
}
}

@override
void completeResolve() {
// Nothing to complete for actornode.
}

bool eachChildRecursive(NodeWalkCallback cb) {
if (_children != null) {
for (ActorNode child in _children) {
for (final ActorNode child in _children) {
if (cb(child) == false) {
return false;
}
Expand Down
83 changes: 56 additions & 27 deletions flare_dart/lib/actor_path.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import "dart:typed_data";
import "actor_shape.dart";
import "actor_artboard.dart";
import "actor_component.dart";
import "actor_node.dart";
import "actor_shape.dart";
import "actor_skinnable.dart";
import "actor_artboard.dart";
import "stream_reader.dart";
import "path_point.dart";
import "math/vec2d.dart";
import "math/mat2d.dart";
import "math/aabb.dart";
import "math/mat2d.dart";
import "math/vec2d.dart";
import "path_point.dart";
import "stream_reader.dart";

abstract class ActorBasePath {
//bool get isClosed;
ActorShape _shape;
ActorShape get shape => _shape;
bool _isRootPath = false;
bool get isRootPath => _isRootPath;
List<PathPoint> get points;
ActorNode get parent;
void invalidatePath();
bool get isPathInWorldSpace => false;
Mat2D get pathTransform;
Mat2D get transform;
Mat2D get worldTransform;
List<List<ActorClip>> get allClips;
List<PathPoint> get deformedPoints => points;

Expand All @@ -41,11 +45,16 @@ abstract class ActorBasePath {
// convert the path coordinates into local parent space.
localTransform = Mat2D();
Mat2D.invert(localTransform, parent.worldTransform);
} else if (!_isRootPath) {
// Path isn't root, so get transform in shape space.
if (Mat2D.invert(localTransform, shape.worldTransform)) {
Mat2D.multiply(localTransform, localTransform, worldTransform);
}
} else {
localTransform = transform;
}

for (Vec2D p in pts) {
for (final Vec2D p in pts) {
Vec2D wp = Vec2D.transformMat2D(p, p, localTransform);
if (wp[0] < minX) {
minX = wp[0];
Expand All @@ -64,10 +73,10 @@ abstract class ActorBasePath {
return AABB.fromValues(minX, minY, maxX, maxY);
}

invalidateDrawable() {
void invalidateDrawable() {
invalidatePath();
if (parent is ActorShape) {
parent.invalidateShape();
if (shape != null) {
shape.invalidateShape();
}
}

Expand All @@ -78,7 +87,7 @@ abstract class ActorBasePath {
double maxY = -double.maxFinite;

List<PathPoint> renderPoints = points;
for (PathPoint point in renderPoints) {
for (final PathPoint point in renderPoints) {
Vec2D t = point.translation;
double x = t[0];
double y = t[1];
Expand Down Expand Up @@ -132,6 +141,27 @@ abstract class ActorBasePath {

return AABB.fromValues(minX, minY, maxX, maxY);
}

void updateShape() {
if (_shape != null) {
_shape.removePath(this);
}
ActorNode possibleShape = parent;
while (possibleShape != null && possibleShape is! ActorShape) {
possibleShape = possibleShape.parent;
}
if (possibleShape != null) {
_shape = possibleShape as ActorShape;
_shape.addPath(this);
} else {
_shape = null;
}
_isRootPath = _shape == parent;
}

void completeResolve() {
updateShape();
}
}

abstract class ActorProceduralPath extends ActorNode with ActorBasePath {
Expand Down Expand Up @@ -168,8 +198,8 @@ abstract class ActorProceduralPath extends ActorNode with ActorBasePath {
void onDirty(int dirt) {
super.onDirty(dirt);
// We transformed, make sure parent is invalidated.
if (parent is ActorShape) {
parent.invalidateShape();
if (shape != null) {
shape.invalidateShape();
}
}
}
Expand Down Expand Up @@ -204,7 +234,7 @@ class ActorPath extends ActorNode with ActorSkinnable, ActorBasePath {

Float32List boneMatrices = skin.boneMatrices;
List<PathPoint> deformed = <PathPoint>[];
for (PathPoint point in _points) {
for (final PathPoint point in _points) {
deformed.add(point.skin(worldTransform, boneMatrices));
}
return deformed;
Expand All @@ -218,8 +248,8 @@ class ActorPath extends ActorNode with ActorSkinnable, ActorBasePath {
void onDirty(int dirt) {
super.onDirty(dirt);
// We transformed, make sure parent is invalidated.
if (parent is ActorShape) {
parent.invalidateShape();
if (shape != null) {
shape.invalidateShape();
}
}

Expand All @@ -232,7 +262,7 @@ class ActorPath extends ActorNode with ActorSkinnable, ActorBasePath {
});
Float32List vertices = Float32List(length);
int readIdx = 0;
for (PathPoint point in points) {
for (final PathPoint point in points) {
vertices[readIdx++] = point.translation[0];
vertices[readIdx++] = point.translation[1];
if (point.pointType == PointType.Straight) {
Expand All @@ -257,11 +287,12 @@ class ActorPath extends ActorNode with ActorSkinnable, ActorBasePath {
artboard.addDirt(this, VertexDeformDirty, false);
}

@override
void update(int dirt) {
if (vertexDeform != null &&
(dirt & VertexDeformDirty) == VertexDeformDirty) {
int readIdx = 0;
for (PathPoint point in _points) {
for (final PathPoint point in _points) {
point.translation[0] = vertexDeform[readIdx++];
point.translation[1] = vertexDeform[readIdx++];
switch (point.pointType) {
Expand All @@ -286,10 +317,8 @@ class ActorPath extends ActorNode with ActorSkinnable, ActorBasePath {

static ActorPath read(
ActorArtboard artboard, StreamReader reader, ActorPath component) {
if (component == null) {
component = ActorPath();
}
ActorNode.read(artboard, reader, component);
component ??= ActorPath();
ActorNode.read(artboard, reader, component);
ActorSkinnable.read(artboard, reader, component);

component._isHidden = !reader.readBool("isVisible");
Expand Down Expand Up @@ -333,14 +362,14 @@ class ActorPath extends ActorNode with ActorSkinnable, ActorBasePath {
return instanceEvent;
}

@override
@override
void resolveComponentIndices(List<ActorComponent> components) {
super.resolveComponentIndices(components);
resolveSkinnable(components);
super.resolveComponentIndices(components);
resolveSkinnable(components);
}

void copyPath(ActorPath node, ActorArtboard resetArtboard) {
copyNode(node, resetArtboard);
copyNode(node, resetArtboard);
copySkinnable(node, resetArtboard);
_isHidden = node._isHidden;
_isClosed = node._isClosed;
Expand Down
16 changes: 15 additions & 1 deletion flare_dart/lib/actor_shape.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "math/vec2d.dart";
import "stream_reader.dart";

class ActorShape extends ActorDrawable {
final List<ActorBasePath> _paths = <ActorBasePath>[];
final List<ActorStroke> _strokes = <ActorStroke>[];
final List<ActorFill> _fills = <ActorFill>[];
bool _transformAffectsStroke = false;
Expand All @@ -20,6 +21,7 @@ class ActorShape extends ActorDrawable {
ActorStroke get stroke => _strokes.isNotEmpty ? _strokes.first : null;
List<ActorFill> get fills => _fills;
List<ActorStroke> get strokes => _strokes;
List<ActorBasePath> get paths => _paths;

@override
void update(int dirt) {
Expand Down Expand Up @@ -47,7 +49,7 @@ class ActorShape extends ActorDrawable {

void copyShape(ActorShape node, ActorArtboard resetArtboard) {
copyDrawable(node, resetArtboard);
node._transformAffectsStroke = _transformAffectsStroke;
node._transformAffectsStroke = _transformAffectsStroke;
}

@override
Expand Down Expand Up @@ -177,4 +179,16 @@ class ActorShape extends ActorDrawable {

@override
set blendModeId(int value) {}

bool addPath(ActorBasePath path) {
if (_paths.contains(path)) {
return false;
}
_paths.add(path);
return true;
}

bool removePath(ActorBasePath path) {
return _paths.remove(path);
}
}
2 changes: 1 addition & 1 deletion flare_dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flare_dart
description: Vector design and runtime animation.
version: 1.4.8
version: 1.4.9
author: "2Dimensions Team <[email protected]>"
homepage: https://github.com/2d-inc/Flare-Flutter
environment:
Expand Down
4 changes: 4 additions & 0 deletions flare_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.5.13] - 2019-10-07 11:21:29

- Using latest flare_dart with support for Nodes inside of Shapes (Paths with multiple transform spaces).

## [1.5.12] - 2019-10-04 17:56:54

- Introduce FlareTesting.setup(); call this prior to running any tests using Flare content.
Expand Down
43 changes: 14 additions & 29 deletions flare_flutter/lib/flare.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,8 @@ class FlutterActorShape extends ActorShape with FlutterActorDrawable {
void initializeGraphics() {
super.initializeGraphics();
_path = ui.Path();
if (children != null) {
for (final ActorNode node in children) {
FlutterPath flutterPath = node as FlutterPath;
if (flutterPath != null) {
flutterPath.initializeGraphics();
}
}
for (final ActorBasePath path in paths) {
(path as FlutterPath).initializeGraphics();
}
}

Expand Down Expand Up @@ -211,15 +206,10 @@ class FlutterActorShape extends ActorShape with FlutterActorDrawable {
_isValid = true;
_path.reset();

if (children != null) {
for (final ActorNode node in children) {
FlutterPath flutterPath = node as FlutterPath;
if (flutterPath != null) {
Mat2D transform = (node as ActorBasePath).pathTransform;
_path.addPath(flutterPath.path, ui.Offset.zero,
matrix4: transform?.mat4);
}
}
for (final ActorBasePath path in paths) {
Mat2D transform = path.pathTransform;
_path.addPath((path as FlutterPath).path, ui.Offset.zero,
matrix4: transform?.mat4);
}
return _path;
}
Expand Down Expand Up @@ -308,21 +298,16 @@ class FlutterActorShapeWithTransformedStroke extends FlutterActorShape {
Mat2D.identity(inverseWorld);
}

if (children != null) {
for (final ActorNode node in children) {
FlutterPath flutterPath = node as FlutterPath;
if (flutterPath != null) {
Mat2D transform = (node as ActorBasePath).pathTransform;
for (final ActorBasePath path in paths) {
Mat2D transform = path.pathTransform;

Mat2D localTransform;
if (transform != null) {
localTransform = Mat2D();
Mat2D.multiply(localTransform, inverseWorld, transform);
}
_localPath.addPath(flutterPath.path, ui.Offset.zero,
matrix4: localTransform?.mat4);
}
Mat2D localTransform;
if (transform != null) {
localTransform = Mat2D();
Mat2D.multiply(localTransform, inverseWorld, transform);
}
_localPath.addPath((path as FlutterPath).path, ui.Offset.zero,
matrix4: localTransform?.mat4);
}
return _localPath;
}
Expand Down
2 changes: 1 addition & 1 deletion flare_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flare_flutter
description: Vector design and runtime animation for Flutter.
version: 1.5.12
version: 1.5.13
author: "2Dimensions Team <[email protected]>"
homepage: https://github.com/2d-inc/Flare-Flutter
environment:
Expand Down

0 comments on commit e59d88d

Please sign in to comment.