Эх сурвалжийг харах

[flutter] Fix up vertex & texture color modulation, go back to passing native views directly to avoid copy.

Mario Zechner 3 жил өмнө
parent
commit
689f748f5d

+ 1 - 4
spine-flutter/example/lib/main.dart

@@ -65,12 +65,9 @@ class _SpinePainter extends CustomPainter {
     canvas.save();
     canvas.translate(size.width / 2, size.height);
     for (final cmd in commands) {
-      canvas.drawVertices(cmd.vertices, BlendMode.srcOut, drawable.atlas.atlasPagePaints[cmd.atlasPageIndex]);
+      canvas.drawVertices(cmd.vertices, BlendMode.modulate, drawable.atlas.atlasPagePaints[cmd.atlasPageIndex]);
     }
     canvas.restore();
-    canvas.drawLine(Offset(0, 0), Offset(size.width, size.height), Paint()
-      ..color = Colors.blue
-      ..strokeWidth = 4);
   }
 
   @override

+ 11 - 11
spine-flutter/lib/spine_flutter.dart

@@ -14,10 +14,10 @@ int minorVersion() => _bindings.spine_minor_version();
 
 class SpineAtlas {
   Pointer<spine_atlas> _atlas;
-  List<Image> _atlasPages;
+  List<Image> atlasPages;
   List<Paint> atlasPagePaints;
 
-  SpineAtlas(this._atlas, this._atlasPages, this.atlasPagePaints);
+  SpineAtlas(this._atlas, this.atlasPages, this.atlasPagePaints);
 
   static Future<SpineAtlas> fromAsset(AssetBundle assetBundle, String atlasFileName) async {
     final atlasData = await assetBundle.loadString(atlasFileName);
@@ -42,7 +42,10 @@ class SpineAtlas {
       final FrameInfo frameInfo = await codec.getNextFrame();
       final Image image = frameInfo.image;
       atlasPages.add(image);
-      atlasPagePaints.add(Paint()..shader = ImageShader(image, TileMode.clamp, TileMode.clamp, Matrix4.identity().storage));
+      atlasPagePaints.add(Paint()
+        ..shader = ImageShader(image, TileMode.clamp, TileMode.clamp, Matrix4.identity().storage, filterQuality: FilterQuality.high)
+        ..isAntiAlias = true
+      );
     }
 
     return SpineAtlas(atlas, atlasPages, atlasPagePaints);
@@ -98,7 +101,7 @@ class SpineSkeletonDrawable {
     Pointer<spine_render_command> nativeCmd = _bindings.spine_skeleton_drawable_render(_drawable);
     List<SpineRenderCommand> commands = [];
     while(nativeCmd.address != nullptr.address) {
-      final atlasPage = atlas._atlasPages[nativeCmd.ref.atlasPage];
+      final atlasPage = atlas.atlasPages[nativeCmd.ref.atlasPage];
       commands.add(SpineRenderCommand(nativeCmd, atlasPage.width.toDouble(), atlasPage.height.toDouble()));
       nativeCmd = nativeCmd.ref.next;
     }
@@ -114,10 +117,7 @@ class SpineRenderCommand {
     atlasPageIndex = nativeCmd.ref.atlasPage;
     int numVertices = nativeCmd.ref.numVertices;
     int numIndices = nativeCmd.ref.numIndices;
-    final positions = Float32List.fromList(nativeCmd.ref.positions.asTypedList(numVertices * 2));
-    final uvs = Float32List.fromList(nativeCmd.ref.uvs.asTypedList(numVertices * 2));
-    final colors = Int32List.fromList(nativeCmd.ref.colors.asTypedList(numVertices));
-    final indices = Uint16List.fromList(nativeCmd.ref.indices.asTypedList(numIndices));
+    final uvs = nativeCmd.ref.uvs.asTypedList(numVertices * 2);
     for (int i = 0; i < numVertices * 2; i += 2) {
       uvs[i] *= pageWidth;
       uvs[i+1] *= pageHeight;
@@ -127,10 +127,10 @@ class SpineRenderCommand {
     // render call. See the implementation of Vertices.raw() here:
     // https://github.com/flutter/engine/blob/5c60785b802ad2c8b8899608d949342d5c624952/lib/ui/painting/vertices.cc#L21
     vertices = Vertices.raw(VertexMode.triangles,
-        positions,
+        nativeCmd.ref.positions.asTypedList(numVertices * 2),
         textureCoordinates: uvs,
-        colors: colors,
-        indices: indices
+        colors: nativeCmd.ref.colors.asTypedList(numVertices),
+        indices: nativeCmd.ref.indices.asTypedList(numIndices)
     );
   }
 }