From 0585c4ef8f68a167a6018e7f9a8af46708da92e1 Mon Sep 17 00:00:00 2001 From: Miguel Angel Besalduch Garcia Date: Mon, 24 Jul 2023 16:43:44 +0200 Subject: [PATCH] fix loadTexture loads from directory --- example/bunny/.metadata | 26 ++++++- example/bunny/pubspec.lock | 121 ++++++++++++++++++--------------- example/bunny/pubspec.yaml | 3 - example/cube_app/.metadata | 24 ++++++- example/cube_app/lib/main.dart | 11 ++- example/cube_app/pubspec.lock | 117 ++++++++++++++++++------------- example/ruby/.metadata | 24 ++++++- example/ruby/lib/main.dart | 10 ++- example/ruby/pubspec.lock | 121 ++++++++++++++++++--------------- example/ruby/pubspec.yaml | 3 - lib/src/mesh.dart | 107 ++++++++++++++++++++--------- 11 files changed, 358 insertions(+), 209 deletions(-) diff --git a/example/bunny/.metadata b/example/bunny/.metadata index 366c3fa..c9e5f2c 100644 --- a/example/bunny/.metadata +++ b/example/bunny/.metadata @@ -1,10 +1,30 @@ # This file tracks properties of this Flutter project. # Used by Flutter tool to assess capabilities and perform upgrades etc. # -# This file should be version controlled and should not be manually edited. +# This file should be version controlled. version: - revision: 2294d75bfa8d067ba90230c0fc2268f3636d7584 - channel: beta + revision: 796c8ef79279f9c774545b3771238c3098dbefab + channel: stable project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 796c8ef79279f9c774545b3771238c3098dbefab + base_revision: 796c8ef79279f9c774545b3771238c3098dbefab + - platform: linux + create_revision: 796c8ef79279f9c774545b3771238c3098dbefab + base_revision: 796c8ef79279f9c774545b3771238c3098dbefab + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/example/bunny/pubspec.lock b/example/bunny/pubspec.lock index 361f5cd..8eb0e73 100644 --- a/example/bunny/pubspec.lock +++ b/example/bunny/pubspec.lock @@ -5,58 +5,50 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.5.0" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.1.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + url: "https://pub.dev" source: hosted - version: "1.15.0" - cupertino_icons: - dependency: "direct main" - description: - name: cupertino_icons - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.3" + version: "1.17.1" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -68,33 +60,52 @@ packages: path: "../.." relative: true source: path - version: "0.0.6" + version: "0.1.0" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + url: "https://pub.dev" + source: hosted + version: "0.12.15" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" source: hosted - version: "0.12.10" + version: "0.2.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.9.1" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.8.3" sky_engine: dependency: transitive description: flutter @@ -104,57 +115,57 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.9.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + url: "https://pub.dev" source: hosted - version: "0.2.19" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" + version: "0.5.1" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.4" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=3.0.0-0 <4.0.0" diff --git a/example/bunny/pubspec.yaml b/example/bunny/pubspec.yaml index 701efec..7223cad 100644 --- a/example/bunny/pubspec.yaml +++ b/example/bunny/pubspec.yaml @@ -21,9 +21,6 @@ dependencies: sdk: flutter - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.3 flutter_cube: path: ../../ diff --git a/example/cube_app/.metadata b/example/cube_app/.metadata index fea404f..c9e5f2c 100755 --- a/example/cube_app/.metadata +++ b/example/cube_app/.metadata @@ -1,10 +1,30 @@ # This file tracks properties of this Flutter project. # Used by Flutter tool to assess capabilities and perform upgrades etc. # -# This file should be version controlled and should not be manually edited. +# This file should be version controlled. version: - revision: 68587a0916366e9512a78df22c44163d041dd5f3 + revision: 796c8ef79279f9c774545b3771238c3098dbefab channel: stable project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 796c8ef79279f9c774545b3771238c3098dbefab + base_revision: 796c8ef79279f9c774545b3771238c3098dbefab + - platform: linux + create_revision: 796c8ef79279f9c774545b3771238c3098dbefab + base_revision: 796c8ef79279f9c774545b3771238c3098dbefab + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/example/cube_app/lib/main.dart b/example/cube_app/lib/main.dart index c29c502..a9ac92a 100755 --- a/example/cube_app/lib/main.dart +++ b/example/cube_app/lib/main.dart @@ -25,7 +25,8 @@ class MyHomePage extends StatefulWidget { _MyHomePageState createState() => _MyHomePageState(); } -class _MyHomePageState extends State with SingleTickerProviderStateMixin { +class _MyHomePageState extends State + with SingleTickerProviderStateMixin { late Scene _scene; Object? _cube; late AnimationController _controller; @@ -33,7 +34,10 @@ class _MyHomePageState extends State with SingleTickerProviderStateM void _onSceneCreated(Scene scene) { _scene = scene; scene.camera.position.z = 50; - _cube = Object(scale: Vector3(2.0, 2.0, 2.0), backfaceCulling: false, fileName: 'assets/cube/cube.obj'); + _cube = Object( + scale: Vector3(2.0, 2.0, 2.0), + backfaceCulling: false, + fileName: 'assets/cube/cube.obj'); final int samples = 100; final double radius = 8; final double offset = 2 / samples; @@ -56,7 +60,8 @@ class _MyHomePageState extends State with SingleTickerProviderStateM @override void initState() { super.initState(); - _controller = AnimationController(duration: Duration(milliseconds: 30000), vsync: this) + _controller = AnimationController( + duration: Duration(milliseconds: 30000), vsync: this) ..addListener(() { if (_cube != null) { _cube!.rotation.y = _controller.value * 360; diff --git a/example/cube_app/pubspec.lock b/example/cube_app/pubspec.lock index 43829de..320ed9f 100755 --- a/example/cube_app/pubspec.lock +++ b/example/cube_app/pubspec.lock @@ -5,58 +5,58 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.5.0" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.1.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.17.1" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.dartlang.org" + sha256: caac504f942f41dfadcf45229ce8c47065b93919a12739f20d6173a883c5ec73 + url: "https://pub.dev" source: hosted version: "1.0.2" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -68,33 +68,52 @@ packages: path: "../.." relative: true source: path - version: "0.0.6" + version: "0.1.0" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + url: "https://pub.dev" source: hosted - version: "0.12.10" + version: "0.12.15" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" + source: hosted + version: "0.2.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.9.1" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.8.3" sky_engine: dependency: transitive description: flutter @@ -104,57 +123,57 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.9.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + url: "https://pub.dev" source: hosted - version: "0.2.19" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" + version: "0.5.1" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.4" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=3.0.0-0 <4.0.0" diff --git a/example/ruby/.metadata b/example/ruby/.metadata index 1b5cec0..c9e5f2c 100644 --- a/example/ruby/.metadata +++ b/example/ruby/.metadata @@ -1,10 +1,30 @@ # This file tracks properties of this Flutter project. # Used by Flutter tool to assess capabilities and perform upgrades etc. # -# This file should be version controlled and should not be manually edited. +# This file should be version controlled. version: - revision: 27321ebbad34b0a3fafe99fac037102196d655ff + revision: 796c8ef79279f9c774545b3771238c3098dbefab channel: stable project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 796c8ef79279f9c774545b3771238c3098dbefab + base_revision: 796c8ef79279f9c774545b3771238c3098dbefab + - platform: linux + create_revision: 796c8ef79279f9c774545b3771238c3098dbefab + base_revision: 796c8ef79279f9c774545b3771238c3098dbefab + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/example/ruby/lib/main.dart b/example/ruby/lib/main.dart index b64ca6c..88a7643 100644 --- a/example/ruby/lib/main.dart +++ b/example/ruby/lib/main.dart @@ -24,12 +24,15 @@ class MyHomePage extends StatefulWidget { _MyHomePageState createState() => _MyHomePageState(); } -class _MyHomePageState extends State with SingleTickerProviderStateMixin { +class _MyHomePageState extends State + with SingleTickerProviderStateMixin { void _onSceneCreated(Scene scene) { scene.camera.position.z = 10; - scene.camera.target.y = 2; + scene.camera.target.y = 0; // from https://sketchfab.com/3d-models/ruby-rose-2270ee59d38e409491a76451f6c6ef80 - scene.world.add(Object(scale: Vector3(10.0, 10.0, 10.0), fileName: 'assets/ruby_rose/ruby_rose.obj')); + scene.world.add(Object( + scale: Vector3(10.0, 10.0, 10.0), + fileName: 'assets/ruby_rose/ruby_rose.obj')); } @override @@ -40,6 +43,7 @@ class _MyHomePageState extends State with SingleTickerProviderStateM ), body: Center( child: Cube( + interactive: false, onSceneCreated: _onSceneCreated, ), ), diff --git a/example/ruby/pubspec.lock b/example/ruby/pubspec.lock index 361f5cd..8eb0e73 100644 --- a/example/ruby/pubspec.lock +++ b/example/ruby/pubspec.lock @@ -5,58 +5,50 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.5.0" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.1.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + url: "https://pub.dev" source: hosted - version: "1.15.0" - cupertino_icons: - dependency: "direct main" - description: - name: cupertino_icons - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.3" + version: "1.17.1" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -68,33 +60,52 @@ packages: path: "../.." relative: true source: path - version: "0.0.6" + version: "0.1.0" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + url: "https://pub.dev" + source: hosted + version: "0.12.15" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" source: hosted - version: "0.12.10" + version: "0.2.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.9.1" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.8.3" sky_engine: dependency: transitive description: flutter @@ -104,57 +115,57 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.9.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + url: "https://pub.dev" source: hosted - version: "0.2.19" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" + version: "0.5.1" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.4" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=3.0.0-0 <4.0.0" diff --git a/example/ruby/pubspec.yaml b/example/ruby/pubspec.yaml index ee78df1..8782a3e 100644 --- a/example/ruby/pubspec.yaml +++ b/example/ruby/pubspec.yaml @@ -20,9 +20,6 @@ dependencies: flutter: sdk: flutter - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 flutter_cube: path: ../../ diff --git a/lib/src/mesh.dart b/lib/src/mesh.dart index 46c67b8..dd60d3b 100755 --- a/lib/src/mesh.dart +++ b/lib/src/mesh.dart @@ -33,13 +33,24 @@ int _getVertexIndex(String vIndex) { } class Mesh { - Mesh({List? vertices, List? texcoords, List? indices, List? colors, this.texture, Rect? textureRect, this.texturePath, Material? material, this.name}) { + Mesh( + {List? vertices, + List? texcoords, + List? indices, + List? colors, + this.texture, + Rect? textureRect, + this.texturePath, + Material? material, + this.name}) { this.vertices = vertices ?? []; this.texcoords = texcoords ?? []; this.colors = colors ?? []; this.indices = indices ?? []; this.material = material ?? Material(); - this.textureRect = textureRect ?? Rect.fromLTWH(0, 0, texture?.width.toDouble() ?? 1.0, texture?.height.toDouble() ?? 1.0); + this.textureRect = textureRect ?? + Rect.fromLTWH(0, 0, texture?.width.toDouble() ?? 1.0, + texture?.height.toDouble() ?? 1.0); } late List vertices; late List texcoords; @@ -55,7 +66,8 @@ class Mesh { /// Loading mesh from Wavefront's object file (.obj). /// Reference:http://paulbourke.net/dataformats/obj/ /// -Future> loadObj(String fileName, bool normalized, {bool isAsset = true}) async { +Future> loadObj(String fileName, bool normalized, + {bool isAsset = true}) async { Map? materials; List vertices = []; List texcoords = []; @@ -91,7 +103,8 @@ Future> loadObj(String fileName, bool normalized, {bool isAsset = tru // material name from material library. eg: usemtl red if (parts.length >= 2) materialName = parts[1]; // create a new mesh element - final String elementName = objectlName ?? groupName ?? materialName ?? ''; + final String elementName = + objectlName ?? groupName ?? materialName ?? ''; elementNames.add(elementName); elementMaterials.add(materialName ?? ''); elementOffsets.add(vertexIndices.length); @@ -107,7 +120,8 @@ Future> loadObj(String fileName, bool normalized, {bool isAsset = tru case 'v': // a geometric vertex and its x y z coordinates. eg: v 0.000000 2.000000 0.000000 if (parts.length >= 4) { - final v = Vector3(double.parse(parts[1]), double.parse(parts[2]), double.parse(parts[3])); + final v = Vector3(double.parse(parts[1]), double.parse(parts[2]), + double.parse(parts[3])); vertices.add(v); } break; @@ -128,11 +142,15 @@ Future> loadObj(String fileName, bool normalized, {bool isAsset = tru final List p1 = parts[1].split('/'); final List p2 = parts[2].split('/'); final List p3 = parts[3].split('/'); - Polygon vi = Polygon(_getVertexIndex(p1[0]), _getVertexIndex(p2[0]), _getVertexIndex(p3[0])); + Polygon vi = Polygon(_getVertexIndex(p1[0]), _getVertexIndex(p2[0]), + _getVertexIndex(p3[0])); vertexIndices.add(vi); Polygon ti = Polygon(0, 0, 0); - if ((p1.length >= 2 && p1[1] != '') && (p2.length >= 2 && p2[1] != '') && (p3.length >= 2 && p3[1] != '')) { - ti = Polygon(_getVertexIndex(p1[1]), _getVertexIndex(p2[1]), _getVertexIndex(p3[1])); + if ((p1.length >= 2 && p1[1] != '') && + (p2.length >= 2 && p2[1] != '') && + (p3.length >= 2 && p3[1] != '')) { + ti = Polygon(_getVertexIndex(p1[1]), _getVertexIndex(p2[1]), + _getVertexIndex(p3[1])); textureIndices.add(ti); } // polygon to triangle. eg: f 1/1 2/2 3/3 4/4 ==> f 1/1 2/2 3/3 + f 1/1 3/3 4/4 @@ -187,7 +205,9 @@ Future> _buildMesh( final List meshes = []; for (int index = 0; index < elementOffsets.length; index++) { int faceStart = elementOffsets[index]; - int faceEnd = (index + 1 < elementOffsets.length) ? elementOffsets[index + 1] : vertexIndices.length; + int faceEnd = (index + 1 < elementOffsets.length) + ? elementOffsets[index + 1] + : vertexIndices.length; var newVertices = []; var newTexcoords = []; @@ -200,17 +220,25 @@ Future> _buildMesh( newIndices = vertexIndices; newTextureIndices = textureIndices; } else { - _copyRangeIndices(faceStart, faceEnd, vertices, vertexIndices, newVertices, newIndices); - _copyRangeIndices(faceStart, faceEnd, texcoords, textureIndices, newTexcoords, newTextureIndices); + _copyRangeIndices( + faceStart, faceEnd, vertices, vertexIndices, newVertices, newIndices); + _copyRangeIndices(faceStart, faceEnd, texcoords, textureIndices, + newTexcoords, newTextureIndices); } // load texture image from assets. - final Material? material = (materials != null) ? materials[elementMaterials[index]] : null; - final MapEntry? imageEntry = await loadTexture(material, basePath); + final Material? material = + (materials != null) ? materials[elementMaterials[index]] : null; + final MapEntry? imageEntry = + await loadTexture(material, basePath, isAsset: isAsset); // fix zero texture area if (imageEntry != null) { - _remapZeroAreaUVs(newTexcoords, newTextureIndices, imageEntry.value.width.toDouble(), imageEntry.value.height.toDouble()); + _remapZeroAreaUVs( + newTexcoords, + newTextureIndices, + imageEntry.value.width.toDouble(), + imageEntry.value.height.toDouble()); } // If a vertex has multiple different texture coordinates, @@ -233,7 +261,8 @@ Future> _buildMesh( } /// Copy a mesh from the obj -void _copyRangeIndices(int start, int end, List fromVertices, List fromIndices, List toVertices, List toIndices) { +void _copyRangeIndices(int start, int end, List fromVertices, + List fromIndices, List toVertices, List toIndices) { if (start < 0 || end > fromIndices.length) return; final faceMap = List.filled(fromVertices.length, null); final List face = List.filled(3, 0); @@ -256,10 +285,12 @@ void _copyRangeIndices(int start, int end, List fromVertices, List

texcoords, List textureIndices, double textureWidth, double textureHeight) { +void _remapZeroAreaUVs(List texcoords, List textureIndices, + double textureWidth, double textureHeight) { for (int index = 0; index < textureIndices.length; index++) { Polygon p = textureIndices[index]; - if (texcoords[p.vertex0] == texcoords[p.vertex1] && texcoords[p.vertex0] == texcoords[p.vertex2]) { + if (texcoords[p.vertex0] == texcoords[p.vertex1] && + texcoords[p.vertex0] == texcoords[p.vertex2]) { double u = (texcoords[p.vertex0].dx * textureWidth).floorToDouble(); double v = (texcoords[p.vertex0].dy * textureHeight).floorToDouble(); double u1 = (u + 1.0) / textureWidth; @@ -278,7 +309,8 @@ void _remapZeroAreaUVs(List texcoords, List textureIndices, dou } /// Rebuild vertices and texture coordinates to keep the same length. -void _rebuildVertices(List vertices, List texcoords, List vertexIndices, List textureIndices) { +void _rebuildVertices(List vertices, List texcoords, + List vertexIndices, List textureIndices) { int texcoordsCount = texcoords.length; if (texcoordsCount == 0) return; List newVertices = []; @@ -349,7 +381,8 @@ List normalizeMesh(List meshes) { Future packingTexture(List meshes) async { // generate a key for a mesh. String getMeshKey(Mesh mesh) { - if (mesh.texture != null) return mesh.texturePath ?? '' + mesh.textureRect.toString(); + if (mesh.texture != null) + return mesh.texturePath ?? '' + mesh.textureRect.toString(); return toColor(mesh.material.diffuse.bgr).toString(); } @@ -373,7 +406,8 @@ Future packingTexture(List meshes) async { area += mesh.textureRect.width * mesh.textureRect.height; maxWidth = math.max(maxWidth, mesh.textureRect.width); } - meshes.sort((Mesh a, Mesh b) => b.textureRect.height.compareTo(a.textureRect.height)); + meshes.sort( + (Mesh a, Mesh b) => b.textureRect.height.compareTo(a.textureRect.height)); final double startWidth = math.max(math.sqrt(area / 0.95), maxWidth); final List spaces = []; @@ -384,17 +418,22 @@ Future packingTexture(List meshes) async { final Rect block = mesh.textureRect; final Rect space = spaces[i]; if (block.width > space.width || block.height > space.height) continue; - mesh.textureRect = Rect.fromLTWH(space.left, space.top, block.width, block.height); + mesh.textureRect = + Rect.fromLTWH(space.left, space.top, block.width, block.height); if (block.width == space.width && block.height == space.height) { final Rect last = spaces.removeLast(); if (i < spaces.length) spaces[i] = last; } else if (block.height == space.height) { - spaces[i] = Rect.fromLTWH(space.left + block.width, space.top, space.width - block.width, space.height); + spaces[i] = Rect.fromLTWH(space.left + block.width, space.top, + space.width - block.width, space.height); } else if (block.width == space.width) { - spaces[i] = Rect.fromLTWH(space.left, space.top + block.height, space.width, space.height - block.height); + spaces[i] = Rect.fromLTWH(space.left, space.top + block.height, + space.width, space.height - block.height); } else { - spaces.add(Rect.fromLTWH(space.left + block.width, space.top, space.width - block.width, block.height)); - spaces[i] = Rect.fromLTWH(space.left, space.top + block.height, space.width, space.height - block.height); + spaces.add(Rect.fromLTWH(space.left + block.width, space.top, + space.width - block.width, block.height)); + spaces[i] = Rect.fromLTWH(space.left, space.top + block.height, + space.width, space.height - block.height); } break; } @@ -405,8 +444,10 @@ Future packingTexture(List meshes) async { int textureHeight = 0; for (Mesh mesh in meshes) { final Rect box = mesh.textureRect; - if (textureWidth < box.left + box.width) textureWidth = (box.left + box.width).ceil(); - if (textureHeight < box.top + box.height) textureHeight = (box.top + box.height).ceil(); + if (textureWidth < box.left + box.width) + textureWidth = (box.left + box.width).ceil(); + if (textureHeight < box.top + box.height) + textureHeight = (box.top + box.height).ceil(); } // get the pixels from mesh.texture @@ -422,18 +463,21 @@ Future packingTexture(List meshes) async { final int length = imageWidth * imageHeight; pixels = Uint32List(length); // color mode then set texture to transparent. - final int color = 0; //mesh.material == null ? 0 : toColor(mesh.material.kd.bgr, mesh.material.d).value; + final int color = + 0; //mesh.material == null ? 0 : toColor(mesh.material.kd.bgr, mesh.material.d).value; for (int i = 0; i < length; i++) { pixels[i] = color; } } // break if the mesh.texture has changed - if (mesh.textureRect.right > textureWidth || mesh.textureRect.bottom > textureHeight) break; + if (mesh.textureRect.right > textureWidth || + mesh.textureRect.bottom > textureHeight) break; // copy pixels from mesh.texture to texture int fromIndex = 0; - int toIndex = mesh.textureRect.top.toInt() * textureWidth + mesh.textureRect.left.toInt(); + int toIndex = mesh.textureRect.top.toInt() * textureWidth + + mesh.textureRect.left.toInt(); for (int y = 0; y < imageHeight; y++) { for (int x = 0; x < imageWidth; x++) { texture[toIndex + x] = pixels[fromIndex + x]; @@ -453,7 +497,8 @@ Future packingTexture(List meshes) async { } final c = Completer(); - decodeImageFromPixels(texture.buffer.asUint8List(), textureWidth, textureHeight, PixelFormat.rgba8888, (image) { + decodeImageFromPixels(texture.buffer.asUint8List(), textureWidth, + textureHeight, PixelFormat.rgba8888, (image) { c.complete(image); }); return c.future;