From 0b759dfca5498b90b79c8be6209d3feaae882e31 Mon Sep 17 00:00:00 2001 From: Luigi Rosso Date: Thu, 7 Nov 2019 12:34:28 -0800 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit e9712a4244eefe96e8b4644be1a6e8eb0d3feae1 Author: Luigi Rosso Date: Thu Nov 7 12:32:17 2019 -0800 Bumping versions. commit 366cdc03cef7110f9247b4de332a12f40d987f32 Author: Luigi Rosso Date: Thu Nov 7 12:27:53 2019 -0800 Adding support for runtime image swapping, requires marking image nodes as isDynamic in Flare. Issue #183. commit 53a7c659b772f5b9442f569be0a389512a77ff29 Author: Luigi Rosso Date: Wed Nov 6 17:30:42 2019 -0800 Updating flare_flutter version. commit b391dd4343b710fa575b45c47d11aca8b3cb4b52 Merge: 1e9b22e 9ec074b Author: Luigi Rosso Date: Wed Nov 6 17:28:34 2019 -0800 Merge branch 'warmth_fix' commit 9ec074be6328914ebcd82e5285c9aef9e408e1d5 Author: Luigi Rosso Date: Wed Nov 6 15:43:31 2019 -0800 Call setState if mounted. commit c66ac647efac650ef38b425fa7488343e36a075f Author: Luigi Rosso Date: Wed Nov 6 15:38:06 2019 -0800 Addressing an issue found in #177 with FlareCacheBuilder setting state when widget is no longer mounted. commit 1e9b22e0aa12e27c362fcaf28d914aa482198db9 Author: Umberto Sonnino Date: Wed Nov 6 19:02:25 2019 +0100 Init mat before inverting commit bc07b8752c05bd1a05cfcded0c2193e23602a1e0 Author: Umberto Sonnino Date: Wed Nov 6 19:00:13 2019 +0100 Remove local flare_dart from examples pubspec #184 commit e1cca7cdc97bdfb1fd19d2ee365ce901c1e8339a Author: Luigi Rosso Date: Tue Oct 29 12:50:30 2019 -0700 Bumping versions, merging optimal_load branch, and persisting settings in checkbox example. commit 55cae393bb92dcd7157a5b12c55074e3bafa6d6d Author: Luigi Rosso Date: Tue Oct 29 12:41:43 2019 -0700 Copy transform affects stroke properly when instancing shapes. commit 43716dd3449266fe9f6f42c5bf05701d0bb06b88 Author: Luigi Rosso Date: Mon Oct 28 12:52:09 2019 -0700 Prevent coldLoad (async) from happening when widget isn’t ready to load. commit 506837e0bafff3060318bc65d03296ebb599f284 Author: Luigi Rosso Date: Fri Oct 25 13:00:56 2019 -0700 Improving loading. commit 9ee95b964dde6ee3fb17b9e969ab00b3d0992c9f Author: Luigi Rosso Date: Fri Oct 25 10:42:42 2019 -0700 Make sure overrideColor is set even when drawableNodes is null. commit 7d59de1e77c040acc271bc3981a70517856a31b1 Author: Umberto Sonnino Date: Fri Oct 25 13:15:34 2019 +0100 Move null check commit 528af53a2bc9ac68d00fc30aadb2f78509fff922 Author: Umberto Sonnino Date: Fri Oct 25 13:10:17 2019 +0100 Insert null checks for artboards with no drawables #178 commit 33f23a7d29b5adf04f5b6536ddaf74f1aa590165 Author: Umberto Sonnino Date: Fri Oct 25 12:16:16 2019 +0100 Remove GradientColor override of ActorPaint opacity getter #179 commit 59ba2f08174b43c7a7f8a7ff97cd04d533da1eea Author: Umberto Sonnino Date: Thu Oct 24 09:31:41 2019 +0100 Document the `actor_animatino.apply()` function commit d77438f87f7aae2d850a8295ae4d9a5b33505694 Author: Umberto Sonnino Date: Thu Oct 24 09:31:10 2019 +0100 Fix division by 0 on transform constraint commit f0cf988bc3ef928b8b96ae217133ecadca02b418 Author: Luigi Rosso Date: Fri Oct 11 12:59:13 2019 -0700 Fix reading of JSON clip values. Issue #172 commit a7796e0d6e9b5ea6957eafc9f784ba4c36320967 Author: Luigi Rosso Date: Fri Oct 11 12:39:48 2019 -0700 Mitigating issue #172. commit 373c14a4f3b2360c4252a8ac834c23bb28068f6e Author: Luigi Rosso Date: Wed Oct 9 14:21:47 2019 -0700 Fixing issue with image clipping. commit ae1c901441306953f09549b4c3bdd4612cc86af4 Author: Luigi Rosso Date: Wed Oct 9 11:19:16 2019 -0700 Fix merge bugs. commit d8cb780a543fe9fd35d60bcfcb198b70622c524f Author: Luigi Rosso Date: Wed Oct 9 11:09:42 2019 -0700 Adding support for difference clipping. commit bf99a765746f321937315e7ecd96aaa190a3d20b Author: Luigi Rosso Date: Tue Oct 8 19:07:26 2019 -0700 Matching stable version commit 9becc744d0d50f10533e3ad1f7c0b4daee6604c2 Author: Luigi Rosso Date: Tue Oct 8 13:58:11 2019 -0700 Bumping flare_dart to 2.0 due to breaking changes. commit 0a292cc67ea8d261057b9f9e5c32028e3436436c Author: Luigi Rosso Date: Tue Oct 8 13:39:57 2019 -0700 Bumping versions and changelogs. commit 431a98e4804efe6d073a9b55a9ce1a5f23c7ca4d Author: Luigi Rosso Date: Tue Oct 8 13:35:26 2019 -0700 Fixing up analysis issues for #169 commit 72fb6fc743ed3a241c7c51e5a8ebc90836f734ba Merge: 4d00202 dc68dea Author: Luigi Rosso Date: Tue Oct 8 13:02:17 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter commit 4d00202a4f24b2c3d581b28cb15b953ec91c9f3c Author: Luigi Rosso Date: Tue Oct 8 13:02:11 2019 -0700 Cleaning up analysis issues. commit dc68dea6d57cb504d1a867c7e4c5b6768ec5dfe2 Merge: 5ca8d49 f1d9749 Author: Luigi Rosso Date: Tue Oct 8 11:06:53 2019 -0700 Merge pull request #168 from mehmetf/master Escalate the severity of unused imports in analyzer commit f1d97496a2679f470202f17298cd76a0411d7a8c Author: Mehmet Fidanboylu Date: Tue Oct 8 10:20:58 2019 -0700 Do the same changes to flare_dart commit 64f395edf7c6f8419a7a461e46664ff3723cfa78 Author: Mehmet Fidanboylu Date: Tue Oct 8 10:17:51 2019 -0700 Escalate the severity of unused imports in analyzer 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. --- flare_dart/CHANGELOG.md | 4 +++ flare_dart/lib/actor_image.dart | 12 +++++++ flare_dart/pubspec.yaml | 2 +- flare_flutter/CHANGELOG.md | 4 +++ flare_flutter/lib/flare.dart | 62 ++++++++++++++++++++++++++++++++- flare_flutter/pubspec.yaml | 2 +- 6 files changed, 83 insertions(+), 3 deletions(-) diff --git a/flare_dart/CHANGELOG.md b/flare_dart/CHANGELOG.md index 267d3b6..1dcbe83 100644 --- a/flare_dart/CHANGELOG.md +++ b/flare_dart/CHANGELOG.md @@ -1,3 +1,7 @@ +## [2.2.4] - 2019-11-07 12:14:49 + +- Adding support for ActorImage.isDynamic which allows Flare to pacakge source UV coordinates for the image such that it can be swapped at runtime. This requires re-exporting files from Flare after marking the image as dynamic in the Flare UI. + ## [2.2.3] - 2019-10-29 12:44:02 - Copy transformAffectsStroke from the source shape when instancing. diff --git a/flare_dart/lib/actor_image.dart b/flare_dart/lib/actor_image.dart index 9a96446..611337f 100644 --- a/flare_dart/lib/actor_image.dart +++ b/flare_dart/lib/actor_image.dart @@ -28,6 +28,8 @@ class ActorImage extends ActorDrawable with ActorSkinnable { int _textureIndex = -1; Float32List _vertices; + Float32List _dynamicUV; + Float32List get dynamicUV => _dynamicUV; Uint16List _triangles; int _vertexCount = 0; int _triangleCount = 0; @@ -141,6 +143,15 @@ class ActorImage extends ActorDrawable with ActorSkinnable { node._vertices = reader.readFloat32Array(numVertices * node.vertexStride, "vertices"); + // In version 24 we started packing the original UV coordinates if the + // image was marked for dynamic runtime swapping. + if (artboard.actor.version >= 24) { + bool isDynamic = reader.readBool("isDynamic"); + if (isDynamic) { + node._dynamicUV = reader.readFloat32Array(numVertices * 2, "uv"); + } + } + int numTris = reader.readUint32("numTriangles"); node._triangles = Uint16List(numTris * 3); node._triangleCount = numTris; @@ -217,6 +228,7 @@ class ActorImage extends ActorDrawable with ActorSkinnable { _triangleCount = node._triangleCount; _vertices = node._vertices; _triangles = node._triangles; + _dynamicUV = node._dynamicUV; if (node._animationDeformedVertices != null) { _animationDeformedVertices = Float32List.fromList(node._animationDeformedVertices); diff --git a/flare_dart/pubspec.yaml b/flare_dart/pubspec.yaml index 905179d..77e590b 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: 2.2.3 +version: 2.2.4 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 f518ac0..08f6de5 100644 --- a/flare_flutter/CHANGELOG.md +++ b/flare_flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## [1.7.0] - 2019-11-07 12:16:35 + +- Adding support for runtime image swapping. + ## [1.6.5] - 2019-11-06 17:29:43 - Fixed an issue with FlareCacheBuilder calling setState when the widget is no longer mounted. diff --git a/flare_flutter/lib/flare.dart b/flare_flutter/lib/flare.dart index b27ca43..a629c0b 100644 --- a/flare_flutter/lib/flare.dart +++ b/flare_flutter/lib/flare.dart @@ -1067,6 +1067,67 @@ class FlutterActorImage extends ActorImage with FlutterActorDrawable { } } + /// Swap the image used to draw the mesh for this image node. + /// Returns true when successful. + bool changeImage(ui.Image image) { + if (triangles == null || dynamicUV == null) { + return false; + } + _uvBuffer = makeVertexUVBuffer(); + int count = vertexCount; + + // SKIA requires texture coordinates in full image space, not traditional + // normalized uv coordinates. + int idx = 0; + for (int i = 0; i < count; i++) { + _uvBuffer[idx] = dynamicUV[idx] * image.width; + _uvBuffer[idx + 1] = dynamicUV[idx + 1] * image.height; + idx += 2; + } + + _paint.shader = image != null + ? ui.ImageShader( + image, ui.TileMode.clamp, ui.TileMode.clamp, _identityMatrix) + : null; + + _canvasVertices = ui.Vertices.raw(ui.VertexMode.triangles, _vertexBuffer, + indices: _indices, textureCoordinates: _uvBuffer); + + onPaintUpdated(_paint); + + return true; + } + + /// Change the image for this node via a network url. + /// Returns true when successful. + Future changeImageFromNetwork(String url) async { + var networkImage = NetworkImage(url); + var val = await networkImage.obtainKey(const ImageConfiguration()); + var load = networkImage.load(val, (Uint8List bytes, + {int cacheWidth, int cacheHeight}) { + return PaintingBinding.instance.instantiateImageCodec(bytes, + cacheWidth: cacheWidth, cacheHeight: cacheHeight); + }); + + final completer = Completer(); + load.addListener(ImageStreamListener((ImageInfo info, bool syncCall) { + changeImage(info.image); + completer.complete(true); + })); + return completer.future; + } + + /// Change the image for this node with one in an asset bundle. + /// Returns true when successful. + Future changeImageFromBundle( + AssetBundle bundle, String filename) async { + ByteData data = await bundle.load(filename); + ui.Codec codec = + await ui.instantiateImageCodec(Uint8List.view(data.buffer)); + ui.FrameInfo frame = await codec.getNextFrame(); + return changeImage(frame.image); + } + @override void initializeGraphics() { super.initializeGraphics(); @@ -1139,7 +1200,6 @@ class FlutterActorImage extends ActorImage with FlutterActorDrawable { canvas.save(); clip(canvas); - _paint.color = _paint.color.withOpacity(renderOpacity.clamp(0.0, 1.0).toDouble()); diff --git a/flare_flutter/pubspec.yaml b/flare_flutter/pubspec.yaml index cd3b0b9..4e50caf 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.6.5 +version: 1.7.0 author: "2Dimensions Team " homepage: https://github.com/2d-inc/Flare-Flutter environment: