From e59d88d1c1e73006319735233e70a49be4ba0bdc Mon Sep 17 00:00:00 2001 From: Luigi Rosso Date: Mon, 7 Oct 2019 11:23:24 -0700 Subject: [PATCH] Squashed commit of the following: commit 5ca8d49c09406d1ac62ffffd4d0c5082744be7a3 Author: Luigi Rosso Date: Mon Oct 7 11:22:38 2019 -0700 Bumping versions and changelog. commit 874ce8e0b77a8ffc3eea9027cb31e2b75437da01 Author: Luigi Rosso Date: Mon Oct 7 11:20:28 2019 -0700 Adding support for nodes inside of shapes. commit 4d06431f341b426dd5cc41529a49c115e6354c51 Author: Luigi Rosso Date: Fri Oct 4 18:06:09 2019 -0700 Introducing FlareTesting.setup(); commit 2c5f4200535d679fd3092d1b6aa15ff71d85b869 Author: Luigi Rosso Date: Fri Oct 4 13:44:25 2019 -0700 Clamping trim start/end. commit daba34d11233391e7277b157bc117b8bbb626982 Author: Luigi Rosso Date: Mon Sep 30 21:21:55 2019 +0200 Cherry picking critical lints from #1 63 and updating for pub. --- example/simple/android/app/build.gradle | 2 +- example/simple/android/build.gradle | 2 +- example/simple/android/gradle.properties | 1 + flare_dart/CHANGELOG.md | 4 ++ flare_dart/lib/actor_node.dart | 11 +++- flare_dart/lib/actor_path.dart | 83 ++++++++++++++++-------- flare_dart/lib/actor_shape.dart | 16 ++++- flare_dart/pubspec.yaml | 2 +- flare_flutter/CHANGELOG.md | 4 ++ flare_flutter/lib/flare.dart | 43 ++++-------- flare_flutter/pubspec.yaml | 2 +- 11 files changed, 106 insertions(+), 64 deletions(-) diff --git a/example/simple/android/app/build.gradle b/example/simple/android/app/build.gradle index bea1eaf..f62880b 100644 --- a/example/simple/android/app/build.gradle +++ b/example/simple/android/app/build.gradle @@ -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' diff --git a/example/simple/android/build.gradle b/example/simple/android/build.gradle index 4476887..136bad2 100644 --- a/example/simple/android/build.gradle +++ b/example/simple/android/build.gradle @@ -26,4 +26,4 @@ subprojects { task clean(type: Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/example/simple/android/gradle.properties b/example/simple/android/gradle.properties index 8bd86f6..7be3d8b 100644 --- a/example/simple/android/gradle.properties +++ b/example/simple/android/gradle.properties @@ -1 +1,2 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true diff --git a/flare_dart/CHANGELOG.md b/flare_dart/CHANGELOG.md index bb7cc98..10ea2d8 100644 --- a/flare_dart/CHANGELOG.md +++ b/flare_dart/CHANGELOG.md @@ -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. diff --git a/flare_dart/lib/actor_node.dart b/flare_dart/lib/actor_node.dart index 9b51a72..7e81097 100644 --- a/flare_dart/lib/actor_node.dart +++ b/flare_dart/lib/actor_node.dart @@ -342,6 +342,7 @@ class ActorNode extends ActorComponent { } } + @override void resolveComponentIndices(List components) { super.resolveComponentIndices(components); @@ -349,18 +350,22 @@ class ActorNode extends ActorComponent { 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; } diff --git a/flare_dart/lib/actor_path.dart b/flare_dart/lib/actor_path.dart index d5fa4bd..44ed3ae 100644 --- a/flare_dart/lib/actor_path.dart +++ b/flare_dart/lib/actor_path.dart @@ -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 get points; ActorNode get parent; void invalidatePath(); bool get isPathInWorldSpace => false; Mat2D get pathTransform; Mat2D get transform; + Mat2D get worldTransform; List> get allClips; List get deformedPoints => points; @@ -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]; @@ -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(); } } @@ -78,7 +87,7 @@ abstract class ActorBasePath { double maxY = -double.maxFinite; List 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]; @@ -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 { @@ -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(); } } } @@ -204,7 +234,7 @@ class ActorPath extends ActorNode with ActorSkinnable, ActorBasePath { Float32List boneMatrices = skin.boneMatrices; List deformed = []; - for (PathPoint point in _points) { + for (final PathPoint point in _points) { deformed.add(point.skin(worldTransform, boneMatrices)); } return deformed; @@ -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(); } } @@ -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) { @@ -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) { @@ -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"); @@ -333,14 +362,14 @@ class ActorPath extends ActorNode with ActorSkinnable, ActorBasePath { return instanceEvent; } - @override + @override void resolveComponentIndices(List 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; diff --git a/flare_dart/lib/actor_shape.dart b/flare_dart/lib/actor_shape.dart index 45eef36..24e7f91 100644 --- a/flare_dart/lib/actor_shape.dart +++ b/flare_dart/lib/actor_shape.dart @@ -11,6 +11,7 @@ import "math/vec2d.dart"; import "stream_reader.dart"; class ActorShape extends ActorDrawable { + final List _paths = []; final List _strokes = []; final List _fills = []; bool _transformAffectsStroke = false; @@ -20,6 +21,7 @@ class ActorShape extends ActorDrawable { ActorStroke get stroke => _strokes.isNotEmpty ? _strokes.first : null; List get fills => _fills; List get strokes => _strokes; + List get paths => _paths; @override void update(int dirt) { @@ -47,7 +49,7 @@ class ActorShape extends ActorDrawable { void copyShape(ActorShape node, ActorArtboard resetArtboard) { copyDrawable(node, resetArtboard); - node._transformAffectsStroke = _transformAffectsStroke; + node._transformAffectsStroke = _transformAffectsStroke; } @override @@ -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); + } } diff --git a/flare_dart/pubspec.yaml b/flare_dart/pubspec.yaml index 6562483..45334e9 100644 --- a/flare_dart/pubspec.yaml +++ b/flare_dart/pubspec.yaml @@ -1,6 +1,6 @@ name: flare_dart description: Vector design and runtime animation. -version: 1.4.8 +version: 1.4.9 author: "2Dimensions Team " homepage: https://github.com/2d-inc/Flare-Flutter environment: diff --git a/flare_flutter/CHANGELOG.md b/flare_flutter/CHANGELOG.md index 7f9a34d..031fc0a 100644 --- a/flare_flutter/CHANGELOG.md +++ b/flare_flutter/CHANGELOG.md @@ -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. diff --git a/flare_flutter/lib/flare.dart b/flare_flutter/lib/flare.dart index 9683b18..2609d03 100644 --- a/flare_flutter/lib/flare.dart +++ b/flare_flutter/lib/flare.dart @@ -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(); } } @@ -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; } @@ -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; } diff --git a/flare_flutter/pubspec.yaml b/flare_flutter/pubspec.yaml index 2a78eb3..9985d82 100644 --- a/flare_flutter/pubspec.yaml +++ b/flare_flutter/pubspec.yaml @@ -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 " homepage: https://github.com/2d-inc/Flare-Flutter environment: