Compare commits
48 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53b8d352da | ||
|
|
2553d854e9 | ||
|
|
7f9c5a0f2d | ||
|
|
7718885781 | ||
|
|
5bf21ceaf9 | ||
|
|
d3f84f156a | ||
|
|
4fe79e3b92 | ||
|
|
2a5c863506 | ||
|
|
837a2cebc7 | ||
|
|
6ab814114e | ||
|
|
818d75b493 | ||
|
|
390b3d063b | ||
|
|
a0cdbde89f | ||
|
|
4088853705 | ||
|
|
b46cf85c83 | ||
|
|
e71f89e54f | ||
|
|
91d3894c83 | ||
|
|
6cf8e58bed | ||
|
|
025bdf662e | ||
|
|
4ebd5a6645 | ||
|
|
df4f647333 | ||
|
|
b089ddd501 | ||
|
|
57cff7fa47 | ||
|
|
450aacf0cc | ||
|
|
1a71e199aa | ||
|
|
91e50cf0ef | ||
|
|
0276c29d10 | ||
|
|
64309eeb54 | ||
|
|
504cc8ca30 | ||
|
|
28e26a722f | ||
|
|
18274ab14d | ||
|
|
1fe130d77f | ||
|
|
eada8d23bd | ||
|
|
7f107708b5 | ||
|
|
72ec72660d | ||
|
|
6bddc94b3d | ||
|
|
4eebe02f29 | ||
|
|
6327c8063b | ||
|
|
05bc5b122e | ||
|
|
d655672587 | ||
|
|
8358c0b236 | ||
|
|
80388c059d | ||
|
|
3b2d87536a | ||
|
|
1be2367b4f | ||
|
|
08ba9400d3 | ||
|
|
4d827badc4 | ||
|
|
e3408625bc | ||
|
|
78af8e12a0 |
@@ -1,3 +1,4 @@
|
|||||||
## 0.0.1
|
## 0.5.0
|
||||||
|
|
||||||
* TODO: Describe initial release.
|
* Replaced `isReadyForScene` Future in `FilamentController` with the `Stream<bool>` `hasViewer`.
|
||||||
|
* Rendering is set to false when the app is hidden, inactive or paused; on resume, this will be set to the value it held prior to being hidden/inactive/paused.
|
||||||
|
|||||||
269
README.md
269
README.md
@@ -1,46 +1,40 @@
|
|||||||
# Flutter Filament
|
# Flutter Filament
|
||||||
|
|
||||||
Cross-platform, Physically-based rendering inside Flutter applications.
|
Cross-platform, 3D PBR rendering and animation for [Flutter](https://github.com/google/filament).
|
||||||
|
|
||||||
Flutter plugin wrapping the Filament renderer https://github.com/google/filament.
|
Wraps the [the Filament rendering library](https://github.com/google/filament).
|
||||||
|
|
||||||
Powers the Polyvox and odd-io engines.
|
Powers the [Polyvox](https://polyvox.app) and [odd-io](https://github.com/odd-io/) engines.
|
||||||
|
|
||||||
# Sponsors
|
This is still in beta: bugs/missing features are to be expected.
|
||||||
|
|
||||||
Thank you to odd-io for sponsoring work on supporting Windows, raycasting, testing and documentation.
|
https://github.com/nmfisher/polyvox_filament/assets/7238578/abaed1c8-c97b-4999-97b2-39e85e0fa7dd
|
||||||
|
|
||||||
# Overview
|
|
||||||
|
|
||||||
## Versioning
|
|Feature|Supported|
|
||||||
|
|---|---|
|
||||||
|
|Platforms|✅ iOS (arm64)<br/>✅ MacOS (arm64)<br/>✅ Android (arm64) <br/>✅ Windows (x64)<br/>⚠️ Linux (x64 - broken)<br/>⚠️ Web (planned)|
|
||||||
|
|Formats|✅ glb <br/>⚠️ glTF (partial - see Known Issues)|
|
||||||
|
|Texture support|✅ PNG <br/>✅ JPEG <br/>✅ KTX <br/>⚠️ KTX2 (planned)|
|
||||||
|
|Camera movement|✅ Desktop (mouse)<br/>✅ Mobile (swipe/pinch)|
|
||||||
|
|Animation|✅ Embedded glTF skinning animations<br/>✅ Embedded glTF morph animations<br/> ✅ Runtime/dynamic morph animations<br/> ⚠️ Runtime/dynamic skinning animations <br/>
|
||||||
|
|Entity manipulation|✅ Viewport selection<br/>⚠️ Entity/transform parenting (planned)<br/> ⚠️ Transform manipulation (mouse/gesture to rotate/translate/scale object) (partial)<br/>⚠️ Runtime material changes (planned)|
|
||||||
|
|
||||||
|
Special thanks to [odd-io](https://github.com/odd-io/) for sponsoring work on supporting Windows, raycasting, testing and documentation.
|
||||||
|
|
||||||
|
PRs are welcome but please create a placeholder PR to discuss before writing any code. This will help with feature planning, avoid clashes with existing work and keep the project structure consistent.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
This package requires Flutter >= `3.16.0-0.2.pre`, so you will need to first switch to the `beta` channel:
|
||||||
|
|
||||||
Last tested on Flutter `3.15.0-15.2.pre`. This is on the Flutter beta channel, so run:
|
|
||||||
```
|
```
|
||||||
flutter channel beta
|
flutter channel beta
|
||||||
flutter upgrade
|
flutter upgrade
|
||||||
```
|
```
|
||||||
|
There are specific issues with earlier versions on Windows/MacOS (mobile should actually be fine, so if you want to experiment on your own you're free to remove the minimum version from `pubspec.yaml`).
|
||||||
|
|
||||||
||Android|iOS|MacOS|Windows|Linux|WebGL
|
Next, clone this repository and pull the latest binaries from Git LFS:
|
||||||
|---|---|---|---|---|---||
|
|
||||||
|Filament|v1.43.1 (arm64/armeabi-v7a/x86/x86_64)|v1.43.1* (arm64)|v1.43.1 (arm64)|v1.32.4 (x86_64)|TODO**|TODO***|
|
|
||||||
|Flutter||3.15.0-15.2.pre|3.15.0-15.2.pre|3.15.0-15.2.pre
|
|
||||||
|
|
||||||
* iOS release build has a skybox bug so the debug versions are currently shipped on iOS
|
|
||||||
** (Waiting for https://github.com/google/filament/issues/7078 to be resolved before upgrading, not sure exactly when the bug was introduced but it was somewhere between v1.32.4 and v1.40.0)
|
|
||||||
*** Texture widget not currently supported on web in Flutter.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
|Feature|Supported|
|
|
||||||
|---|---|
|
|
||||||
|glTF|Y|
|
|
||||||
|glb|Y|
|
|
||||||
|
|
||||||
# Basic Setup
|
|
||||||
|
|
||||||
## Clone flutter_filament
|
|
||||||
|
|
||||||
This plugin is not yet published to pub.dev. To use in your project, simply clone the repository and pull the latest binaries from Git LFS:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
cd $HOME
|
cd $HOME
|
||||||
@@ -48,17 +42,17 @@ git clone <repo> && cd flutter_filament
|
|||||||
git lfs pull
|
git lfs pull
|
||||||
```
|
```
|
||||||
|
|
||||||
You *do not need to build Filament yourself*. The repository is bundled with all necessary headers/static libraries (`windows/lib`, `ios/lib`, `macos/lib` and `linux/lib`) and the Flutter plugin has been configured to link at build time.
|
(this step won't be needed after the plugin is published to pub.dev).
|
||||||
|
|
||||||
If you want to run the example project to check:
|
> You *do not need to build Filament yourself*. The repository is bundled with all necessary headers/static libraries (`windows/lib`, `ios/lib`, `macos/lib` and `linux/lib`) and the Flutter plugin has been configured to link at build time.
|
||||||
|
|
||||||
|
Run the example project to check:
|
||||||
|
|
||||||
```
|
```
|
||||||
cd example && flutter run -d <macos/windows/Your iPhone/etc>
|
cd example && flutter run -d <macos/windows/Your iPhone/etc>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Add dependency
|
To use the plugin in your own project, add the plugin to your pubspec.yaml:
|
||||||
|
|
||||||
Add the plugin as a dependency in the pubspec.yaml for your application:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
name: your_project
|
name: your_project
|
||||||
@@ -71,15 +65,14 @@ dependencies:
|
|||||||
path: <path where you cloned the repository>
|
path: <path where you cloned the repository>
|
||||||
```
|
```
|
||||||
|
|
||||||
# Basic Usage
|
## Basic Usage
|
||||||
|
|
||||||
See the `example` project for a complete sample of the below steps.
|
See the `example` project for a complete sample that incorporates many of the below steps, and more.
|
||||||
|
|
||||||
## Creating the viewport widget and controller
|
### Creating the viewport widget and controller
|
||||||
|
|
||||||
To embed a viewport in your app, create an instance of `FilamentControllerFFI` somewhere in your app:
|
Create an instance of `FilamentControllerFFI` somewhere in your app where it will not be garbage collected until you no longer need a rendering canvas:
|
||||||
|
|
||||||
e.g.
|
|
||||||
```
|
```
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
|
|
||||||
@@ -88,9 +81,8 @@ class MyApp extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
Constructing this object only load symbols from the native FFI library.
|
|
||||||
|
|
||||||
(Note this is not (yet) a singleton, so ensure it is placed somewhere in the widget hierachy where it will not be garbage-collected until you no longer need a rendering canvas).
|
This is a relatively lightweight object, however its constructor will load/bind symbols from the native library. This may momentarily block the UI, so you may wish to structure your app so that this is hidden behind a static widget until it is available.
|
||||||
|
|
||||||
Next, create an instance of `FilamentWidget` in the widget hierarchy where you want the rendering canvas to appear. This can be sized as large or as small as you want. Flutter widgets can be positioned above or below the `FilamentWidget`.
|
Next, create an instance of `FilamentWidget` in the widget hierarchy where you want the rendering canvas to appear. This can be sized as large or as small as you want. Flutter widgets can be positioned above or below the `FilamentWidget`.
|
||||||
|
|
||||||
@@ -115,19 +107,52 @@ class MyApp extends StatelessWidget {
|
|||||||
When a `FilamentWidget` is added to the widget hierarchy:
|
When a `FilamentWidget` is added to the widget hierarchy:
|
||||||
1) on the first frame, by default a Container will be rendered with solid red. If you want to change this, pass a widget as the `initial` paramer to the `FilamentWidget` constructor.
|
1) on the first frame, by default a Container will be rendered with solid red. If you want to change this, pass a widget as the `initial` paramer to the `FilamentWidget` constructor.
|
||||||
2) on the second frame, `FilamentWidget` will retrieve its actual size and request the `FilamentController` to create:
|
2) on the second frame, `FilamentWidget` will retrieve its actual size and request the `FilamentController` to create:
|
||||||
a) the backing textures needed to insert a `Texture` widget into
|
* the backing textures needed to insert a `Texture` widget into
|
||||||
b) a rendering thread
|
* a rendering thread
|
||||||
c) a `FilamentViewer` and an `AssetManager`, which will allow you to load assets/cameras/lighting/etc via the `FilamentController`
|
* a `FilamentViewer` and an `AssetManager`, which will allow you to load assets/cameras/lighting/etc via the `FilamentController`
|
||||||
|
3) after an indeterminate number of frames, `FilamentController` will notify `FilamentWidget` when a texture is available the viewport
|
||||||
|
4) `FilamentWidget` will replace the default `initial` Widget with the viewport (which will initially be solid black or white, depending on your platform).
|
||||||
|
|
||||||
If this was successful, the viewport should turn from red to black.
|
It's important to note that there *will* be a delay between adding a `FilamentWidget` and the actual rendering viewport becoming available. This is why we fill `FilamentWidget` with red - to make it abundantly clear that you need to handle this asynchronous delay appropriately. You can call `await _filamentController.isReadyForScene` if you need to wait until the viewport is actually ready for rendering.
|
||||||
|
|
||||||
### Rendering
|
> Currently, the `initial` widget will also be displayed whenever the viewport is resized (including changing orientation on mobile and drag-to-resize on desktop). You probably want to change this from the default red.
|
||||||
|
|
||||||
|
|
||||||
|
Congratulations! You now have a scene. It's completely empty, so you probably want to add.
|
||||||
|
|
||||||
|
### Load a background
|
||||||
|
|
||||||
|
You probably want to set a background for your scene. You can load a skybox:
|
||||||
|
```
|
||||||
|
await _filamentController.loadSkybox("assets/default_env/default_env_skybox.ktx)
|
||||||
|
```
|
||||||
|
|
||||||
|
or a static background image:
|
||||||
|
|
||||||
|
```
|
||||||
|
await _filamentController.setBackgroundImage("assets/background.ktx)
|
||||||
|
```
|
||||||
|
|
||||||
|
or a solid background color:
|
||||||
|
|
||||||
|
```
|
||||||
|
await _filamentController.setBackgroundColor(0.0, 1.0, 0.0, 1.0); // solid green
|
||||||
|
```
|
||||||
|
|
||||||
|
At this point, you might not see any change in the viewport. This is because the FilamentController will only actually render into the viewport once `render` has been called.
|
||||||
|
|
||||||
By default, the FilamentController will only render into the viewport by manually calling `render()` on the FilamentController. This is to avoid needlessly running a render loop when there is nothing to display.
|
By default, the FilamentController will only render into the viewport by manually calling `render()` on the FilamentController. This is to avoid needlessly running a render loop when there is nothing to display.
|
||||||
|
|
||||||
To automatically render at 60fps, call `setRendering(true)` on `FilamentController`.
|
```
|
||||||
|
await _filamentController.render()
|
||||||
|
```
|
||||||
|
|
||||||
### Assets
|
You should now see your background displayed in the scene. To automatically render at 60fps, call `setRendering`:
|
||||||
|
```
|
||||||
|
await _filamentController.setRendering(true);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Load an asset
|
||||||
|
|
||||||
To add a glTF asset to the scene, call `loadGlb()` on `FilamentController` with the Flutter asset path to your .glb file.
|
To add a glTF asset to the scene, call `loadGlb()` on `FilamentController` with the Flutter asset path to your .glb file.
|
||||||
|
|
||||||
@@ -140,19 +165,44 @@ flutter:
|
|||||||
|
|
||||||
Then you would call the following
|
Then you would call the following
|
||||||
```
|
```
|
||||||
var entity = _filamentController.loadGlb("assets/models/bob.glb");
|
var entity = await _filamentController.loadGlb("assets/models/bob.glb");
|
||||||
```
|
```
|
||||||
You can also pass a URI to indicate that the glTF file should be loaded from the filesystem:
|
You can also pass a URI to indicate that the glTF file should be loaded from the filesystem:
|
||||||
```
|
```
|
||||||
var entity = _filamentController.loadGlb("file:///tmp/bob.glb");
|
var entity = await _filamentController.loadGlb("file:///tmp/bob.glb");
|
||||||
```
|
```
|
||||||
|
|
||||||
The returned value is an integer handle that be used to manipulate the asset (better referred to as the "entity") in the scene.
|
The return type `FilamentEntity` is simply an integer handle that be used to manipulate the entity in the scene. For example, to remove the asset:
|
||||||
|
|
||||||
E.g. to remove the asset:
|
|
||||||
```
|
```
|
||||||
_filamentController.removeAsset(entity);
|
await _filamentController.removeAsset(entity);
|
||||||
|
entity = null;
|
||||||
```
|
```
|
||||||
|
> Removing an entity from the scene will invalidate the corresponding `FilamentEntity` handle, so ensure you don't retain any references to it after calling `removeAsset` or `clearAssets`. Removing one `FilamentEntity` does not invalidate/change any other `FilamentEntity` handles; you can continue to safely manipulate these via the `FilamentController`.
|
||||||
|
|
||||||
|
### Lighting
|
||||||
|
|
||||||
|
You should now see your object in the viewport, but since we haven't added a light, this will be solid black.
|
||||||
|
|
||||||
|
Add an image-based light from a KTX file:
|
||||||
|
|
||||||
|
```
|
||||||
|
await _filamentController.loadIbl("assets/default_env/default_env_ibl.ktx");
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also add dynamic lights:
|
||||||
|
|
||||||
|
```
|
||||||
|
var sun = await _filamentController.addLight(
|
||||||
|
```
|
||||||
|
|
||||||
|
### Manipulating entity transforms
|
||||||
|
|
||||||
|
To set the world space position of the asset:
|
||||||
|
```
|
||||||
|
_filamentController.setPositon(entity, 1.0, 1.0, 1.0);
|
||||||
|
```
|
||||||
|
|
||||||
|
On desktop, you can also click any renderable object in the viewport to retrieve its associated FilamentEntity (see below).
|
||||||
|
|
||||||
### Camera movement
|
### Camera movement
|
||||||
|
|
||||||
@@ -168,8 +218,7 @@ class MyApp extends StatelessWidget {
|
|||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
home: Scaffold(backgroundColor: Colors.white, body: Stack(children:[
|
home: Scaffold(backgroundColor: Colors.white, body: Stack(children:[
|
||||||
Container(color:Colors.green, height:100, width:100),
|
Positioned.fill(child:FilamentGestureDetector(
|
||||||
Positioned.fill(top:100, left:100,child:FilamentGestureDetector(
|
|
||||||
controller: _filamentController,
|
controller: _filamentController,
|
||||||
child:FilamentWidget(
|
child:FilamentWidget(
|
||||||
controller:_filamentController
|
controller:_filamentController
|
||||||
@@ -180,6 +229,69 @@ class MyApp extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
On desktop:
|
||||||
|
1) hold the middle mouse button and move the mouse to rotate the camera
|
||||||
|
2) hold the left mouse button and move the mouse to pan the camera
|
||||||
|
3) scroll up/down with the scrollwheel to zoom in/out.
|
||||||
|
|
||||||
|
On mobile:
|
||||||
|
1) swipe with your finger to pan the camera
|
||||||
|
2) double tap the viewport, then swipe with your finger to rotate the camera (double-tap again to return to pan)
|
||||||
|
3) pinch with two fingers in/out to zoom in/out.
|
||||||
|
|
||||||
|
### Changing the active camera
|
||||||
|
|
||||||
|
Every scene has a default camera. Whenever you rotate/pan/zoom the viewport, you are moving the default camera.
|
||||||
|
|
||||||
|
If you have added an entity to the scene that contains one or more camera nodes, you can change the active scene camera to one of those camera nodes.
|
||||||
|
|
||||||
|
```
|
||||||
|
var asset = await _filamentController.loadGlb("assets/some_asset_with_camera.glb");
|
||||||
|
await _filamentController.setCamera(asset, "Camera.002"); // pass the node name to load a specific camera under that entity node
|
||||||
|
await _filamentController.setCamera(asset, null); // pass null to load the first camera found under that entity
|
||||||
|
```
|
||||||
|
|
||||||
|
### Picking entities
|
||||||
|
|
||||||
|
On desktop, left-clicking an object in the viewport will retrieve the FilamentEntity for the top-most renderable instance at that cursor position (if any).
|
||||||
|
|
||||||
|
Note this is an asynchronous operation, so you will need to subscribe to the [pickResult] stream on your [FilamentController] to do something with the result.
|
||||||
|
|
||||||
|
```
|
||||||
|
class MyApp extends StatefulWidget {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class _MyAppState extends State<MyApp> {
|
||||||
|
|
||||||
|
final _filamentController = FilamentControllerFFI();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_filamentController.pickResult.listen((FilamentEntity filamentEntity) async {
|
||||||
|
var entityName = _filamentController.getNameForEntity(filamentEntity);
|
||||||
|
await showDialog(builder:(ctx) {
|
||||||
|
return Container(child:Text("You clicked $entityName"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MaterialApp(
|
||||||
|
color: Colors.white,
|
||||||
|
home: Scaffold(backgroundColor: Colors.white, body: Stack(children:[
|
||||||
|
Positioned.fill(child:FilamentGestureDetector(
|
||||||
|
controller: _filamentController,
|
||||||
|
child:FilamentWidget(
|
||||||
|
controller:_filamentController
|
||||||
|
))),
|
||||||
|
])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Advanced Usage
|
## Advanced Usage
|
||||||
|
|
||||||
If you want to work with custom materials, you will need some (basic knowledge of the underlying Filament library)[https://google.github.io/filament/Materials.html#compilingmaterials].
|
If you want to work with custom materials, you will need some (basic knowledge of the underlying Filament library)[https://google.github.io/filament/Materials.html#compilingmaterials].
|
||||||
@@ -196,7 +308,43 @@ uberz -TSHADINGMODEL=lit -TBLENDING=opaque -o lit_opaque_43.uberz lit_opaque
|
|||||||
|
|
||||||
(note that the number in the filename corresponds to the Material version, not the Filament version. Not every Filament version requires a new Material version).
|
(note that the number in the filename corresponds to the Material version, not the Filament version. Not every Filament version requires a new Material version).
|
||||||
|
|
||||||
|
## Releasing your app
|
||||||
|
|
||||||
|
If you build your app in release mode, you will need to ensure that "Dead Strip" is set to false.
|
||||||
|
|
||||||
|
This is because we only invoke the library at runtime via FFI, so at link time these symbols are otherwise treated as redundant.
|
||||||
|
|
||||||
|
## Versioning
|
||||||
|
|
||||||
|
||Android|iOS|MacOS|Windows|Linux|WebGL|
|
||||||
|
|---|---|---|---|---|---||
|
||||||
|
|Filament|v1.43.1 (arm64/armeabi-v7a/x86/x86_64)|v1.43.1* (arm64)|v1.43.1 (arm64)|v1.32.4 (x86_64)|TODO**|TODO***|
|
||||||
|
|Flutter||3.15.0-15.2.pre|3.15.0-15.2.pre|3.15.0-15.2.pre
|
||||||
|
|
||||||
|
* iOS release build has a skybox bug so the debug versions are currently shipped on iOS
|
||||||
|
** (Waiting for https://github.com/google/filament/issues/7078 to be resolved before upgrading, not sure exactly when the bug was introduced but it was somewhere between v1.32.4 and v1.40.0)
|
||||||
|
*** Texture widget not currently supported on web in Flutter.
|
||||||
|
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
We automate testing by running the example project on actual iOS/Android/MacOS/Windows devices and executing various operations.
|
||||||
|
|
||||||
|
Eventually we want to compare screenshots after each operation to a set of goldens for every platform.
|
||||||
|
|
||||||
|
Currently this is only possible on iOS (see https://github.com/flutter/flutter/issues/123063 and https://github.com/flutter/flutter/issues/127306).
|
||||||
|
|
||||||
|
To re-generate the golden screenshots for a given device:
|
||||||
|
|
||||||
|
```
|
||||||
|
./regenerate_goldens.sh <your_device_id>
|
||||||
|
```
|
||||||
|
To run the tests and compare against those goldens:
|
||||||
|
```
|
||||||
|
./compare_goldens.sh <your_device_id>
|
||||||
|
```
|
||||||
|
|
||||||
|
The results will depend on the actual device used to generate the golden, therefore if you are using a different device (which is likely), your results may not be the same. This is expected.
|
||||||
|
|
||||||
# Building Filament from source
|
# Building Filament from source
|
||||||
|
|
||||||
@@ -213,9 +361,9 @@ Separately, we also force the Filament gltfio library to load assets via in-memo
|
|||||||
```
|
```
|
||||||
git checkout flutter-filament-windows
|
git checkout flutter-filament-windows
|
||||||
mkdir out && cd out
|
mkdir out && cd out
|
||||||
|
"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" --build . --target gltf_viewer --config Debug
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
Building notes:
|
Building notes:
|
||||||
On Android/iOS, we remove -fno-exceptions from CMakeLists.txt
|
On Android/iOS, we remove -fno-exceptions from CMakeLists.txt
|
||||||
|
|
||||||
@@ -249,19 +397,16 @@ EMCC_CFLAGS="-I/Users/nickfisher/Documents/filament/libs/utils/include -I/Users/
|
|||||||
|
|
||||||
## Materials
|
## Materials
|
||||||
|
|
||||||
glTF assets The default
|
We use a single material (no lighting and no transparency) for background images:
|
||||||
|
|
||||||
- there is a simple material (unlit/opaque) used for background images. This is created by:
|
|
||||||
```
|
```
|
||||||
filament/out/release/filament/bin/matc -a opengl -a metal -o materials/image.filamat materials/image.mat
|
filament/out/release/filament/bin/matc -a opengl -a metal -o materials/image.filamat materials/image.mat
|
||||||
filament/out/release/filament/bin/resgen -c -p image -x ios/include/material/ materials/image.filamat
|
filament/out/release/filament/bin/resgen -c -p image -x ios/include/material/ materials/image.filamat
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
# Known issues
|
# Known issues
|
||||||
|
|
||||||
On Windows, loading a glTF (but NOT a glb) may crash due to a race condition between uploading resource data to GPU memory and being freed on the host side.
|
On Windows, loading a glTF (but NOT a glb) may crash due to a race condition between uploading resource data to GPU memory and being freed on the host side.
|
||||||
|
|
||||||
This has been fixed in recent versions of Filament, but other bugs on Windows prevent upgrading.
|
This has been fixed in recent versions of Filament, but other bugs on Windows prevent upgrading.
|
||||||
|
|
||||||
Only workaround is to load a .glb file.
|
Only workaround is to load a .glb file.
|
||||||
|
|||||||
@@ -201,6 +201,7 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, Lo
|
|||||||
_surfaceTextureEntry!!.release();
|
_surfaceTextureEntry!!.release();
|
||||||
_surface = null
|
_surface = null
|
||||||
_surfaceTextureEntry = null
|
_surfaceTextureEntry = null
|
||||||
|
result.success(true)
|
||||||
}
|
}
|
||||||
"resize" -> {
|
"resize" -> {
|
||||||
val args = call.arguments as List<Any>
|
val args = call.arguments as List<Any>
|
||||||
|
|||||||
25
example/.gitattributes
vendored
25
example/.gitattributes
vendored
@@ -3,3 +3,28 @@ assets/BusterDrone filter=lfs diff=lfs merge=lfs -text
|
|||||||
assets/FlightHelmet filter=lfs diff=lfs merge=lfs -text
|
assets/FlightHelmet filter=lfs diff=lfs merge=lfs -text
|
||||||
assets/lit_opaque_32.uberz filter=lfs diff=lfs merge=lfs -text
|
assets/lit_opaque_32.uberz filter=lfs diff=lfs merge=lfs -text
|
||||||
windows/lib/**/*.* filter=lfs diff=lfs merge=lfs -text
|
windows/lib/**/*.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/12_Settonemappingtolinear.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/3_loadIBL.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/6_zoomin.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/13_Movecameratoasset.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/14_movecamerato.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/7_rotate.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/9_transformtounitcube.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/0_fresh.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/10_setshapespositionto.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/2_loadskybox.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/4_Renderingfalse.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/8_pan.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/11_Disablefrustumculling.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/15_setcameratofirstcamerainshapesGLB.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/1_createviewerdefaultubershader.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/5_loadshapesGLB.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/16_resize.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/3_loadskybox.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/4_loadIBL.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/19_resize.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/17_resize.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/2_Renderingfalse.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/18_resize.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
integration_test/goldens/ios/diffs filter=lfs diff=lfs merge=lfs -text
|
||||||
|
|||||||
9
example/compare_goldens.sh
Normal file
9
example/compare_goldens.sh
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
device=$1
|
||||||
|
if [ -z "$device" ]; then
|
||||||
|
echo "Usage: $0 <device_id>"
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f integration_test/goldens/{ios,macos,windows,android}/diffs/*.png
|
||||||
|
flutter drive --driver=test_driver/integration_test.dart -d $1 --target=integration_test/plugin_integration_test.dart
|
||||||
3
example/integration_test/goldens/ios/0_fresh.png
Normal file
3
example/integration_test/goldens/ios/0_fresh.png
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:ec2a9627f23ffe07750323c25afa78c6c7fcb7d26b5ed36d119363ced0b60f29
|
||||||
|
size 258304
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:53256c9443c6d36edfb8c1234711173c847126e888d714151ae026c57495fe6b
|
||||||
|
size 1875814
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:b0c715cadbf84c2161099e8373a404c7d6dbb093faf4157aa0e0aa3825c28217
|
||||||
|
size 1868778
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:56a431b561db7038ad7fe92d025fc2fe2806dfa2cf68c29a0380c3cbd2b66fb5
|
||||||
|
size 1742539
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:14193a392baf348f77895ca7bfb8cee160407c762d03c01bf1f7b5b771a9b1ab
|
||||||
|
size 2282401
|
||||||
3
example/integration_test/goldens/ios/14_movecamerato.png
Normal file
3
example/integration_test/goldens/ios/14_movecamerato.png
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:77badd0b2a59122949e497297052064c403006272daa4488db43e492d60093e2
|
||||||
|
size 1959141
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:bdf63e19e5a992f2c848cf71b55ceddf8930d6a9368c9b3adcc13e7c478c7146
|
||||||
|
size 1889777
|
||||||
3
example/integration_test/goldens/ios/16_resize.png
Normal file
3
example/integration_test/goldens/ios/16_resize.png
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:651c19434ae3753488eb840695955b98db9d66a20b79bee1e21b3384c2358025
|
||||||
|
size 1609541
|
||||||
3
example/integration_test/goldens/ios/17_resize.png
Normal file
3
example/integration_test/goldens/ios/17_resize.png
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:f11462c0fdf30d101b6ed6c430734adcf6451818f3c7824126c8423014836773
|
||||||
|
size 2060944
|
||||||
3
example/integration_test/goldens/ios/18_resize.png
Normal file
3
example/integration_test/goldens/ios/18_resize.png
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:beb941d33777ad2e1d6ef3704ba6a63b3a5608ca885a516a1c9e807a31b533fc
|
||||||
|
size 1608407
|
||||||
3
example/integration_test/goldens/ios/19_resize.png
Normal file
3
example/integration_test/goldens/ios/19_resize.png
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:2bcae11fd2eb593c419a62731e1799f7340408b28ad56575fab5f79db608ae17
|
||||||
|
size 2062339
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:dc3b3c5e0678a5b71728cea8961925e6c0fb44a59340aa2d77d4ea92a24cc7d6
|
||||||
|
size 316763
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:6dbbb518a86c546f188134c1d369762664f188dd6b9a38ec13963b6187cb4b25
|
||||||
|
size 1456648
|
||||||
3
example/integration_test/goldens/ios/3_loadskybox.png
Normal file
3
example/integration_test/goldens/ios/3_loadskybox.png
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:2d7951418e5875da7c7ed8dea482dbf1cbe81a42b47d255db7f1b6e11c16a193
|
||||||
|
size 1876507
|
||||||
3
example/integration_test/goldens/ios/4_loadIBL.png
Normal file
3
example/integration_test/goldens/ios/4_loadIBL.png
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:80cd11f5be75012cfdf953569e409a355826ca23af35feba41aac78f0e3d35d8
|
||||||
|
size 1874857
|
||||||
3
example/integration_test/goldens/ios/5_loadshapesGLB.png
Normal file
3
example/integration_test/goldens/ios/5_loadshapesGLB.png
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:e605bb18426ea657b9352ecca51f0b55daac904b15dba3afdcffc412a445548a
|
||||||
|
size 1941423
|
||||||
3
example/integration_test/goldens/ios/6_zoomin.png
Normal file
3
example/integration_test/goldens/ios/6_zoomin.png
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:c026e8723922a6c56ab8e28f99a29805c53627ff5a659971590c95d89d7ac6bd
|
||||||
|
size 1940845
|
||||||
3
example/integration_test/goldens/ios/7_rotate.png
Normal file
3
example/integration_test/goldens/ios/7_rotate.png
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:fffa285edd2c5474e16475cafc67d2519e000b74178ce1a0f8d88229827cfabf
|
||||||
|
size 1937116
|
||||||
3
example/integration_test/goldens/ios/8_pan.png
Normal file
3
example/integration_test/goldens/ios/8_pan.png
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:1db7a2f831d83e75e42dfe4f0547e9ed1f171152f45103e8f250d2b52ee3a8e1
|
||||||
|
size 1937776
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:00c70e7e77b98e4e72d0dde82482066096ebd502d25cccfada9cb87de332ecac
|
||||||
|
size 1941844
|
||||||
@@ -1,25 +1,158 @@
|
|||||||
// This is a basic Flutter integration test.
|
import 'dart:async';
|
||||||
//
|
import 'dart:io';
|
||||||
// Since integration tests run in a full Flutter application, they can interact
|
import 'dart:ui';
|
||||||
// with the host side of a plugin implementation, unlike Dart unit tests.
|
|
||||||
//
|
|
||||||
// For more information about Flutter integration tests, please see
|
|
||||||
// https://docs.flutter.dev/cookbook/testing/integration/introduction
|
|
||||||
|
|
||||||
|
|
||||||
|
import 'package:flutter/gestures.dart';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:integration_test/integration_test.dart';
|
import 'package:integration_test/integration_test.dart';
|
||||||
|
import 'package:polyvox_filament/widgets/filament_widget.dart';
|
||||||
import 'package:polyvox_filament/polyvox_filament.dart';
|
import '../lib/main.dart' as app;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized()
|
||||||
|
as IntegrationTestWidgetsFlutterBinding;
|
||||||
|
|
||||||
testWidgets('getPlatformVersion test', (WidgetTester tester) async {
|
late String platformIdentifier;
|
||||||
final PolyvoxFilament plugin = PolyvoxFilament();
|
if (Platform.isIOS) {
|
||||||
final String? version = await plugin.getPlatformVersion();
|
platformIdentifier = "ios";
|
||||||
// The version string depends on the host platform running the test, so
|
} else if (Platform.isAndroid) {
|
||||||
// just assert that some non-empty string is returned.
|
platformIdentifier = "android";
|
||||||
expect(version?.isNotEmpty, true);
|
} else if (Platform.isMacOS) {
|
||||||
|
platformIdentifier = "macos";
|
||||||
|
} else if (Platform.isWindows) {
|
||||||
|
platformIdentifier = "windows";
|
||||||
|
} else if (Platform.isLinux) {
|
||||||
|
platformIdentifier = "linux";
|
||||||
|
} else {
|
||||||
|
throw Exception("Unexpected platform");
|
||||||
|
}
|
||||||
|
|
||||||
|
int _counter = 0;
|
||||||
|
|
||||||
|
Future _snapshot(WidgetTester tester, String label,
|
||||||
|
[int seconds = 0]) async {
|
||||||
|
await tester.pumpAndSettle(Duration(milliseconds: 16));
|
||||||
|
for (int i = 0; i < seconds; i++) {
|
||||||
|
await Future.delayed(Duration(seconds: 1));
|
||||||
|
await tester.pumpAndSettle(Duration(milliseconds: 16));
|
||||||
|
}
|
||||||
|
await tester.pumpAndSettle(Duration(milliseconds: 16));
|
||||||
|
var screenshotPath = '$platformIdentifier/${_counter}_$label';
|
||||||
|
if (Platform.isIOS) {
|
||||||
|
// this is currently hanging on Android
|
||||||
|
// see https://github.com/flutter/flutter/issues/127306
|
||||||
|
// it is also not yet implemented on Windows or MacOS
|
||||||
|
await binding.convertFlutterSurfaceToImage();
|
||||||
|
final bytes = await binding.takeScreenshot(screenshotPath);
|
||||||
|
}
|
||||||
|
_counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future tap(WidgetTester tester, String label, [int seconds = 0]) async {
|
||||||
|
var target = find.text(label).first;
|
||||||
|
await tester.dragUntilVisible(
|
||||||
|
target,
|
||||||
|
find.byType(SingleChildScrollView),
|
||||||
|
// widget you want to scroll
|
||||||
|
const Offset(0, 500), // delta to move
|
||||||
|
duration: Duration(milliseconds: 10));
|
||||||
|
await tester.tap(target);
|
||||||
|
await _snapshot(
|
||||||
|
tester, label.replaceAll(RegExp("[ -:]"), ""), seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> pumpUntilFound(
|
||||||
|
WidgetTester tester,
|
||||||
|
Finder finder, {
|
||||||
|
Duration timeout = const Duration(seconds: 30),
|
||||||
|
}) async {
|
||||||
|
bool timerDone = false;
|
||||||
|
final timer = Timer(
|
||||||
|
timeout, () => throw TimeoutException("Pump until has timed out"));
|
||||||
|
while (timerDone != true) {
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
final found = tester.any(finder);
|
||||||
|
if (found) {
|
||||||
|
timerDone = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
timer.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets('test', (WidgetTester tester) async {
|
||||||
|
app.main();
|
||||||
|
await pumpUntilFound(tester, find.byType(app.ExampleWidget));
|
||||||
|
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await _snapshot(tester, "fresh");
|
||||||
|
|
||||||
|
await tap(tester, "create viewer (default ubershader)", 4);
|
||||||
|
|
||||||
|
await tap(tester, "Rendering: false", 2);
|
||||||
|
|
||||||
|
await tap(tester, "load skybox", 2);
|
||||||
|
await tap(tester, "load IBL", 2);
|
||||||
|
await tap(tester, "load shapes GLB", 2);
|
||||||
|
|
||||||
|
final Offset pointerLocation =
|
||||||
|
tester.getCenter(find.byType(FilamentWidget));
|
||||||
|
TestPointer testPointer = TestPointer(1, PointerDeviceKind.mouse);
|
||||||
|
|
||||||
|
// scroll/zoom
|
||||||
|
testPointer.hover(pointerLocation);
|
||||||
|
await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, 1.0)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, 1.0)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await _snapshot(tester, "zoomin");
|
||||||
|
|
||||||
|
// rotate
|
||||||
|
testPointer =
|
||||||
|
TestPointer(1, PointerDeviceKind.mouse, null, kTertiaryButton);
|
||||||
|
testPointer.hover(pointerLocation);
|
||||||
|
await tester.sendEventToBinding(testPointer.down(pointerLocation));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.sendEventToBinding(
|
||||||
|
testPointer.move(pointerLocation + Offset(10.0, 10.0)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.sendEventToBinding(
|
||||||
|
testPointer.move(pointerLocation + Offset(20.0, 20.0)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.sendEventToBinding(testPointer.up());
|
||||||
|
|
||||||
|
await _snapshot(tester, "rotate", 2);
|
||||||
|
|
||||||
|
// pan
|
||||||
|
testPointer = TestPointer(1, PointerDeviceKind.mouse, null, kPrimaryButton);
|
||||||
|
testPointer.hover(pointerLocation);
|
||||||
|
await tester.sendEventToBinding(testPointer.down(pointerLocation));
|
||||||
|
await tester
|
||||||
|
.sendEventToBinding(testPointer.move(pointerLocation + Offset(0, 1.0)));
|
||||||
|
|
||||||
|
for (int i = 0; i < 60; i++) {
|
||||||
|
await tester.sendEventToBinding(testPointer
|
||||||
|
.move(pointerLocation + Offset(i.toDouble() * 2, i.toDouble() * 2)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
await tester.sendEventToBinding(testPointer.up());
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await _snapshot(tester, "pan");
|
||||||
|
|
||||||
|
await tap(tester, "transform to unit cube");
|
||||||
|
await tap(tester, "set shapes position to 1, 1, -1");
|
||||||
|
await tap(tester, "Disable frustum culling");
|
||||||
|
await tap(tester, "Set tone mapping to linear");
|
||||||
|
await tap(tester, "Move camera to asset");
|
||||||
|
await tap(tester, "move camera to 1, 1, -1");
|
||||||
|
await tap(tester, 'set camera to first camera in shapes GLB');
|
||||||
|
|
||||||
|
await tap(tester, 'resize', 1);
|
||||||
|
await tap(tester, 'resize', 1);
|
||||||
|
await tap(tester, 'resize', 1);
|
||||||
|
await tap(tester, 'resize', 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,34 @@
|
|||||||
PODS:
|
PODS:
|
||||||
- Flutter (1.0.0)
|
- Flutter (1.0.0)
|
||||||
|
- integration_test (0.0.1):
|
||||||
|
- Flutter
|
||||||
|
- path_provider_foundation (0.0.1):
|
||||||
|
- Flutter
|
||||||
|
- FlutterMacOS
|
||||||
- polyvox_filament (0.0.1):
|
- polyvox_filament (0.0.1):
|
||||||
- Flutter
|
- Flutter
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
- Flutter (from `Flutter`)
|
- Flutter (from `Flutter`)
|
||||||
|
- integration_test (from `.symlinks/plugins/integration_test/ios`)
|
||||||
|
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
|
||||||
- polyvox_filament (from `.symlinks/plugins/polyvox_filament/ios`)
|
- polyvox_filament (from `.symlinks/plugins/polyvox_filament/ios`)
|
||||||
|
|
||||||
EXTERNAL SOURCES:
|
EXTERNAL SOURCES:
|
||||||
Flutter:
|
Flutter:
|
||||||
:path: Flutter
|
:path: Flutter
|
||||||
|
integration_test:
|
||||||
|
:path: ".symlinks/plugins/integration_test/ios"
|
||||||
|
path_provider_foundation:
|
||||||
|
:path: ".symlinks/plugins/path_provider_foundation/darwin"
|
||||||
polyvox_filament:
|
polyvox_filament:
|
||||||
:path: ".symlinks/plugins/polyvox_filament/ios"
|
:path: ".symlinks/plugins/polyvox_filament/ios"
|
||||||
|
|
||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
|
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
|
||||||
polyvox_filament: 99047b2e0d56e073f5db603dd6152a1598c2a345
|
integration_test: 13825b8a9334a850581300559b8839134b124670
|
||||||
|
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
|
||||||
|
polyvox_filament: 35fece7761e74c973afd80fe3aa0ca225eaace32
|
||||||
|
|
||||||
PODFILE CHECKSUM: 7adbc9d59f05e1b01f554ea99b6c79e97f2214a2
|
PODFILE CHECKSUM: 7adbc9d59f05e1b01f554ea99b6c79e97f2214a2
|
||||||
|
|
||||||
|
|||||||
@@ -138,6 +138,7 @@
|
|||||||
97C146EC1CF9000F007C117D /* Resources */,
|
97C146EC1CF9000F007C117D /* Resources */,
|
||||||
9705A1C41CF9048500538489 /* Embed Frameworks */,
|
9705A1C41CF9048500538489 /* Embed Frameworks */,
|
||||||
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
|
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
|
||||||
|
F9FAB8A67CF505858CCDA424 /* [CP] Embed Pods Frameworks */,
|
||||||
);
|
);
|
||||||
buildRules = (
|
buildRules = (
|
||||||
);
|
);
|
||||||
@@ -249,6 +250,23 @@
|
|||||||
shellPath = /bin/sh;
|
shellPath = /bin/sh;
|
||||||
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
|
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
|
||||||
};
|
};
|
||||||
|
F9FAB8A67CF505858CCDA424 /* [CP] Embed Pods Frameworks */ = {
|
||||||
|
isa = PBXShellScriptBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
inputFileListPaths = (
|
||||||
|
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
|
||||||
|
);
|
||||||
|
name = "[CP] Embed Pods Frameworks";
|
||||||
|
outputFileListPaths = (
|
||||||
|
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
shellPath = /bin/sh;
|
||||||
|
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
|
||||||
|
showEnvVarsInLog = 0;
|
||||||
|
};
|
||||||
/* End PBXShellScriptBuildPhase section */
|
/* End PBXShellScriptBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXSourcesBuildPhase section */
|
/* Begin PBXSourcesBuildPhase section */
|
||||||
@@ -343,6 +361,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
||||||
|
DEAD_CODE_STRIPPING = NO;
|
||||||
DEVELOPMENT_TEAM = TM2B4SJXNJ;
|
DEVELOPMENT_TEAM = TM2B4SJXNJ;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
@@ -354,6 +373,8 @@
|
|||||||
OTHER_CFLAGS = "-fvisibility=default";
|
OTHER_CFLAGS = "-fvisibility=default";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = app.polyvox.example;
|
PRODUCT_BUNDLE_IDENTIFIER = app.polyvox.example;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
STRIP_INSTALLED_PRODUCT = NO;
|
||||||
|
STRIP_STYLE = "non-global";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
VERSIONING_SYSTEM = "apple-generic";
|
VERSIONING_SYSTEM = "apple-generic";
|
||||||
@@ -479,6 +500,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
||||||
|
DEAD_CODE_STRIPPING = NO;
|
||||||
DEVELOPMENT_TEAM = TM2B4SJXNJ;
|
DEVELOPMENT_TEAM = TM2B4SJXNJ;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
@@ -490,6 +512,8 @@
|
|||||||
OTHER_CFLAGS = "-fvisibility=default";
|
OTHER_CFLAGS = "-fvisibility=default";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = app.polyvox.example;
|
PRODUCT_BUNDLE_IDENTIFIER = app.polyvox.example;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
STRIP_INSTALLED_PRODUCT = NO;
|
||||||
|
STRIP_STYLE = "non-global";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
@@ -505,6 +529,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
|
||||||
|
DEAD_CODE_STRIPPING = NO;
|
||||||
DEVELOPMENT_TEAM = TM2B4SJXNJ;
|
DEVELOPMENT_TEAM = TM2B4SJXNJ;
|
||||||
ENABLE_BITCODE = NO;
|
ENABLE_BITCODE = NO;
|
||||||
INFOPLIST_FILE = Runner/Info.plist;
|
INFOPLIST_FILE = Runner/Info.plist;
|
||||||
@@ -516,6 +541,8 @@
|
|||||||
OTHER_CFLAGS = "-fvisibility=default";
|
OTHER_CFLAGS = "-fvisibility=default";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = app.polyvox.example;
|
PRODUCT_BUNDLE_IDENTIFIER = app.polyvox.example;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
STRIP_INSTALLED_PRODUCT = NO;
|
||||||
|
STRIP_STYLE = "non-global";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
VERSIONING_SYSTEM = "apple-generic";
|
VERSIONING_SYSTEM = "apple-generic";
|
||||||
|
|||||||
@@ -41,41 +41,36 @@ class ExampleWidget extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ExampleWidgetState extends State<ExampleWidget> {
|
class _ExampleWidgetState extends State<ExampleWidget> {
|
||||||
FilamentControllerFFI? _filamentController;
|
FilamentController? _filamentController;
|
||||||
|
|
||||||
FilamentEntity? _shapes;
|
FilamentEntity? _shapes;
|
||||||
FilamentEntity? _flightHelmet;
|
FilamentEntity? _flightHelmet;
|
||||||
List<String>? _animations;
|
List<String>? _animations;
|
||||||
FilamentEntity? _light;
|
FilamentEntity? _light;
|
||||||
|
|
||||||
late StreamSubscription _pickResultListener;
|
StreamSubscription? _pickResultListener;
|
||||||
String? picked;
|
String? picked;
|
||||||
|
|
||||||
final weights = List.filled(255, 0.0);
|
final weights = List.filled(255, 0.0);
|
||||||
|
|
||||||
bool _loop = false;
|
bool _loop = false;
|
||||||
bool _vertical = false;
|
EdgeInsets _viewportMargin = EdgeInsets.zero;
|
||||||
|
|
||||||
|
bool _readyForScene = false;
|
||||||
|
|
||||||
bool _rendering = false;
|
bool _rendering = false;
|
||||||
int _framerate = 60;
|
int _framerate = 60;
|
||||||
bool _postProcessing = true;
|
bool _postProcessing = true;
|
||||||
bool _active = false;
|
|
||||||
|
|
||||||
bool _coneHidden = false;
|
bool _coneHidden = false;
|
||||||
bool _frustumCulling = true;
|
bool _frustumCulling = true;
|
||||||
|
|
||||||
@override
|
StreamSubscription? _hasViewerListener;
|
||||||
void initState() {
|
|
||||||
getApplicationSupportDirectory().then((dir) {
|
|
||||||
print(dir);
|
|
||||||
});
|
|
||||||
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
_pickResultListener.cancel();
|
_pickResultListener?.cancel();
|
||||||
|
_hasViewerListener?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _item(void Function() onTap, String text) {
|
Widget _item(void Function() onTap, String text) {
|
||||||
@@ -96,7 +91,13 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
|||||||
FilamentControllerFFI(uberArchivePath: uberArchivePath);
|
FilamentControllerFFI(uberArchivePath: uberArchivePath);
|
||||||
_filamentController!.pickResult.listen((entityId) {
|
_filamentController!.pickResult.listen((entityId) {
|
||||||
setState(() {
|
setState(() {
|
||||||
picked = _filamentController!.getNameForEntity(entityId);
|
picked = _filamentController!.getNameForEntity(entityId!);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
_hasViewerListener =
|
||||||
|
_filamentController!.hasViewer.listen((bool hasViewer) {
|
||||||
|
setState(() {
|
||||||
|
_readyForScene = hasViewer;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -117,17 +118,14 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
|||||||
: "assets/lit_opaque_43.uberz");
|
: "assets/lit_opaque_43.uberz");
|
||||||
}, "create viewer (custom ubershader - lit opaque only)"),
|
}, "create viewer (custom ubershader - lit opaque only)"),
|
||||||
]);
|
]);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (_readyForScene) {
|
||||||
children.addAll([
|
children.addAll([
|
||||||
_item(() {
|
_item(() {
|
||||||
_filamentController!.destroy();
|
_filamentController!.destroy();
|
||||||
_filamentController = null;
|
_filamentController = null;
|
||||||
}, "destroy viewer/texture")
|
}, "destroy viewer/texture"),
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_filamentController != null) {
|
|
||||||
children.addAll([
|
|
||||||
_item(() {
|
_item(() {
|
||||||
_filamentController!.render();
|
_filamentController!.render();
|
||||||
}, "render"),
|
}, "render"),
|
||||||
@@ -136,7 +134,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
|||||||
_rendering = !_rendering;
|
_rendering = !_rendering;
|
||||||
_filamentController!.setRendering(_rendering);
|
_filamentController!.setRendering(_rendering);
|
||||||
});
|
});
|
||||||
}, "Rendering: $_rendering "),
|
}, "Rendering: $_rendering"),
|
||||||
_item(() {
|
_item(() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_framerate = _framerate == 60 ? 30 : 60;
|
_framerate = _framerate == 60 ? 30 : 60;
|
||||||
@@ -161,6 +159,13 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
|||||||
_filamentController!
|
_filamentController!
|
||||||
.loadIbl('assets/default_env/default_env_ibl.ktx');
|
.loadIbl('assets/default_env/default_env_ibl.ktx');
|
||||||
}, 'load IBL'),
|
}, 'load IBL'),
|
||||||
|
_item(() async {
|
||||||
|
_light = await _filamentController!
|
||||||
|
.addLight(1, 6500, 150000, 0, 1, 0, 0, -1, 0, true);
|
||||||
|
}, "add directional light"),
|
||||||
|
_item(() async {
|
||||||
|
await _filamentController!.clearLights();
|
||||||
|
}, "clear lights"),
|
||||||
_item(() {
|
_item(() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_postProcessing = !_postProcessing;
|
_postProcessing = !_postProcessing;
|
||||||
@@ -207,8 +212,8 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
|||||||
_filamentController!.setPosition(_shapes!, 1.0, 1.0, -1.0);
|
_filamentController!.setPosition(_shapes!, 1.0, 1.0, -1.0);
|
||||||
}, 'set shapes position to 1, 1, -1'),
|
}, 'set shapes position to 1, 1, -1'),
|
||||||
_item(() async {
|
_item(() async {
|
||||||
_filamentController!.setPosition(_shapes!, 1.0, 1.0, -1.0);
|
_filamentController!.setCameraPosition(1.0, 1.0, -1.0);
|
||||||
}, 'move camera to shapes position'),
|
}, 'move camera to 1, 1, -1'),
|
||||||
_item(() async {
|
_item(() async {
|
||||||
var frameData = Float32List.fromList(
|
var frameData = Float32List.fromList(
|
||||||
List<double>.generate(120, (i) => i / 120).expand((x) {
|
List<double>.generate(120, (i) => i / 120).expand((x) {
|
||||||
@@ -299,7 +304,14 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
|||||||
_item(() {
|
_item(() {
|
||||||
_loop = !_loop;
|
_loop = !_loop;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}, "toggle animation looping ${_loop ? "OFF" : "ON"}")
|
}, "toggle animation looping ${_loop ? "OFF" : "ON"}"),
|
||||||
|
_item(() {
|
||||||
|
setState(() {
|
||||||
|
_viewportMargin = _viewportMargin == EdgeInsets.zero
|
||||||
|
? EdgeInsets.all(50)
|
||||||
|
: EdgeInsets.zero;
|
||||||
|
});
|
||||||
|
}, "resize")
|
||||||
]);
|
]);
|
||||||
if (_animations != null) {
|
if (_animations != null) {
|
||||||
children.addAll(_animations!.map((a) => _item(() {
|
children.addAll(_animations!.map((a) => _item(() {
|
||||||
@@ -332,28 +344,34 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
|||||||
return Stack(children: [
|
return Stack(children: [
|
||||||
_filamentController != null
|
_filamentController != null
|
||||||
? Positioned.fill(
|
? Positioned.fill(
|
||||||
child: FilamentGestureDetector(
|
child: Padding(
|
||||||
showControlOverlay: true,
|
padding: _viewportMargin,
|
||||||
controller: _filamentController!,
|
child: FilamentGestureDetector(
|
||||||
child: FilamentWidget(
|
showControlOverlay: true,
|
||||||
controller: _filamentController!,
|
controller: _filamentController!,
|
||||||
)))
|
child: FilamentWidget(
|
||||||
|
controller: _filamentController!,
|
||||||
|
))))
|
||||||
: Container(),
|
: Container(),
|
||||||
Positioned(
|
Positioned(
|
||||||
right: 50,
|
right: 50,
|
||||||
top: 50,
|
top: 50,
|
||||||
child: Text(picked ?? "",
|
child: Text(picked ?? "",
|
||||||
style: TextStyle(color: Colors.green, fontSize: 24))),
|
style: const TextStyle(color: Colors.green, fontSize: 24))),
|
||||||
Positioned(
|
Align(
|
||||||
bottom: 0,
|
alignment: Alignment.bottomCenter,
|
||||||
left: 0,
|
child: OrientationBuilder(builder: (ctx, orientation) {
|
||||||
right: 0,
|
return Container(
|
||||||
height: 200,
|
alignment: Alignment.bottomCenter,
|
||||||
child: Container(
|
height: orientation == Orientation.landscape ? 100 : 200,
|
||||||
color: Colors.white,
|
color: Colors.white.withOpacity(0.75),
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(child: Wrap(children: children)));
|
||||||
child: Wrap(children: children
|
}))
|
||||||
// _item(24 () async { 'rotate by pi around Y axis'),
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// _item(24 () async { 'rotate by pi around Y axis'),
|
||||||
// _item(5 () async { 'load flight helmet'),
|
// _item(5 () async { 'load flight helmet'),
|
||||||
|
|
||||||
// _item(7 () async { 'set all weights to 1'),
|
// _item(7 () async { 'set all weights to 1'),
|
||||||
@@ -384,10 +402,6 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
|||||||
// _item(30 () async { 'remove light'),
|
// _item(30 () async { 'remove light'),
|
||||||
// _item(31 () async { 'clear all lights'),
|
// _item(31 () async { 'clear all lights'),
|
||||||
// _item(32 () async { 'set camera model matrix'),
|
// _item(32 () async { 'set camera model matrix'),
|
||||||
))))
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// case -1:
|
// case -1:
|
||||||
|
|
||||||
@@ -464,11 +478,6 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
|||||||
// case 24:
|
// case 24:
|
||||||
// _filamentController!.setRotation(_shapes!, pi / 2, 0.0, 1.0, 0.0);
|
// _filamentController!.setRotation(_shapes!, pi / 2, 0.0, 1.0, 0.0);
|
||||||
// break;
|
// break;
|
||||||
// case 25:
|
|
||||||
// setState(() {
|
|
||||||
// _vertical = !_vertical;
|
|
||||||
// });
|
|
||||||
// break;
|
|
||||||
// case 26:
|
// case 26:
|
||||||
// _filamentController!.setCameraPosition(0, 0, 3);
|
// _filamentController!.setCameraPosition(0, 0, 3);
|
||||||
// _filamentController!.setCameraRotation(0, 0, 1, 0);
|
// _filamentController!.setCameraRotation(0, 0, 1, 0);
|
||||||
@@ -480,10 +489,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
|||||||
// case 28:
|
// case 28:
|
||||||
// _filamentController!.setBackgroundImagePosition(25, 25);
|
// _filamentController!.setBackgroundImagePosition(25, 25);
|
||||||
// break;
|
// break;
|
||||||
// case 29:
|
|
||||||
// _light = await _filamentController!.addLight(
|
|
||||||
// 1, 6500, 15000000, 0, 1, 0, 0, -1, 0, true);
|
|
||||||
// break;
|
|
||||||
// case 30:
|
// case 30:
|
||||||
// if (_light != null) {
|
// if (_light != null) {
|
||||||
// _filamentController!.removeLight(_light!);
|
// _filamentController!.removeLight(_light!);
|
||||||
@@ -491,7 +497,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
|||||||
// }
|
// }
|
||||||
// break;
|
// break;
|
||||||
// case 31:
|
// case 31:
|
||||||
// _filamentController!.clearLights();
|
|
||||||
// break;
|
// break;
|
||||||
// case 32:
|
// case 32:
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,28 @@
|
|||||||
PODS:
|
PODS:
|
||||||
- FlutterMacOS (1.0.0)
|
- FlutterMacOS (1.0.0)
|
||||||
|
- path_provider_foundation (0.0.1):
|
||||||
|
- Flutter
|
||||||
|
- FlutterMacOS
|
||||||
- polyvox_filament (0.0.1):
|
- polyvox_filament (0.0.1):
|
||||||
- FlutterMacOS
|
- FlutterMacOS
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
- FlutterMacOS (from `Flutter/ephemeral`)
|
- FlutterMacOS (from `Flutter/ephemeral`)
|
||||||
|
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
|
||||||
- polyvox_filament (from `Flutter/ephemeral/.symlinks/plugins/polyvox_filament/macos`)
|
- polyvox_filament (from `Flutter/ephemeral/.symlinks/plugins/polyvox_filament/macos`)
|
||||||
|
|
||||||
EXTERNAL SOURCES:
|
EXTERNAL SOURCES:
|
||||||
FlutterMacOS:
|
FlutterMacOS:
|
||||||
:path: Flutter/ephemeral
|
:path: Flutter/ephemeral
|
||||||
|
path_provider_foundation:
|
||||||
|
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
|
||||||
polyvox_filament:
|
polyvox_filament:
|
||||||
:path: Flutter/ephemeral/.symlinks/plugins/polyvox_filament/macos
|
:path: Flutter/ephemeral/.symlinks/plugins/polyvox_filament/macos
|
||||||
|
|
||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
|
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
|
||||||
polyvox_filament: 59a161de3df49c867bc2003d4ff73b8a304d2feb
|
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
|
||||||
|
polyvox_filament: 410c2b06ba59f1182e2fa4338b583903631fb95f
|
||||||
|
|
||||||
PODFILE CHECKSUM: 9cc8fc8fc62b1d9a89fd6f974ad4157b35254030
|
PODFILE CHECKSUM: 9cc8fc8fc62b1d9a89fd6f974ad4157b35254030
|
||||||
|
|
||||||
|
|||||||
@@ -575,6 +575,7 @@
|
|||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 13;
|
MACOSX_DEPLOYMENT_TARGET = 13;
|
||||||
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
};
|
};
|
||||||
@@ -723,6 +724,7 @@
|
|||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 13;
|
MACOSX_DEPLOYMENT_TARGET = 13;
|
||||||
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>com.apple.security.app-sandbox</key>
|
<key>com.apple.security.app-sandbox</key>
|
||||||
<true/>
|
<false/>
|
||||||
<key>com.apple.security.cs.allow-jit</key>
|
<key>com.apple.security.cs.allow-jit</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>com.apple.security.network.server</key>
|
<key>com.apple.security.network.server</key>
|
||||||
|
|||||||
@@ -28,5 +28,7 @@
|
|||||||
<string>MainMenu</string>
|
<string>MainMenu</string>
|
||||||
<key>NSPrincipalClass</key>
|
<key>NSPrincipalClass</key>
|
||||||
<string>NSApplication</string>
|
<string>NSApplication</string>
|
||||||
|
<key>com.apple.security.app-sandbox</key>
|
||||||
|
<false/>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ description: Demonstrates how to use the polyvox_filament plugin.
|
|||||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.12.0 <4.0.0"
|
sdk: ">=3.0.0 <4.0.0"
|
||||||
|
|
||||||
# Dependencies specify other packages that your package needs in order to work.
|
# Dependencies specify other packages that your package needs in order to work.
|
||||||
# To automatically upgrade your package dependencies to the latest versions
|
# To automatically upgrade your package dependencies to the latest versions
|
||||||
@@ -26,7 +26,11 @@ dependencies:
|
|||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
integration_test:
|
||||||
|
sdk: flutter
|
||||||
flutter_lints: ^1.0.0
|
flutter_lints: ^1.0.0
|
||||||
|
crypto:
|
||||||
|
image_compare: ^1.1.2
|
||||||
|
|
||||||
|
|
||||||
# For information on the generic Dart part of this file, see the
|
# For information on the generic Dart part of this file, see the
|
||||||
|
|||||||
8
example/regenerate_goldens.sh
Normal file
8
example/regenerate_goldens.sh
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
device=$1
|
||||||
|
if [ -z "$device" ]; then
|
||||||
|
echo "Usage: $0 <device_id>"
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
rm -f integration_test/goldens/{ios,macos,windows,android}/*.png
|
||||||
|
flutter drive --driver=test_driver/integration_test_update_goldens.dart -d $1 --target=integration_test/plugin_integration_test.dart
|
||||||
58
example/test_driver/integration_test.dart
Normal file
58
example/test_driver/integration_test.dart
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:integration_test/integration_test_driver_extended.dart';
|
||||||
|
import 'package:image_compare/image_compare.dart';
|
||||||
|
|
||||||
|
Future<void> main() async {
|
||||||
|
await integrationDriver(
|
||||||
|
onScreenshot: (
|
||||||
|
String screenshotName,
|
||||||
|
List<int> screenshotBytes, [
|
||||||
|
Map<String, Object?>? args,
|
||||||
|
]) async {
|
||||||
|
final dir = screenshotName.split("/")[0];
|
||||||
|
final name = screenshotName.split("/")[1];
|
||||||
|
final File golden = await File('integration_test/goldens/$dir/$name.png');
|
||||||
|
|
||||||
|
if (!golden.existsSync()) {
|
||||||
|
throw Exception(
|
||||||
|
"Golden image ${golden.path} doesn't exist yet. Make sure you have run integraton_test_update_goldens.dart first");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await compareImages(
|
||||||
|
src1: screenshotBytes,
|
||||||
|
src2: golden.readAsBytesSync(),
|
||||||
|
algorithm: ChiSquareDistanceHistogram());
|
||||||
|
|
||||||
|
print(result);
|
||||||
|
|
||||||
|
// TODO - it would be preferable to use Flutter's GoldenFileComparator here, e.g.
|
||||||
|
//
|
||||||
|
// ```var comparator = LocalFileComparator(testImage.uri);
|
||||||
|
// comparator.compare(imageBytes, golden)
|
||||||
|
// comparator.getFailureFile(failure, golden, basedir)
|
||||||
|
// var result = await comparator.compare(
|
||||||
|
// Uint8List.fromList(screenshotBytes), golden.uri);
|
||||||
|
// if (!result.passed) {
|
||||||
|
// for (var key in result.diffs!.keys) {
|
||||||
|
// var byteData = await result.diffs![key]!.toByteData();
|
||||||
|
// File('integration_test/goldens/$dir/diffs/$name.png')
|
||||||
|
// .writeAsBytesSync(
|
||||||
|
// byteData!.buffer.asUint8List(byteData!.offsetInBytes));
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
// }```
|
||||||
|
// but this is only available via a Flutter shell which is currently unavailable (this script is run as a plain Dart file I guess).
|
||||||
|
// let's revisit if/when this changes
|
||||||
|
// see https://github.com/flutter/flutter/issues/51890 and https://github.com/flutter/flutter/issues/103222
|
||||||
|
|
||||||
|
if (result > 0.005) {
|
||||||
|
File('integration_test/goldens/$dir/diffs/$name.png')
|
||||||
|
.writeAsBytesSync(screenshotBytes);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
22
example/test_driver/integration_test_update_goldens.dart
Normal file
22
example/test_driver/integration_test_update_goldens.dart
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'package:crypto/crypto.dart';
|
||||||
|
import 'package:integration_test/integration_test_driver_extended.dart';
|
||||||
|
|
||||||
|
Future<void> main() async {
|
||||||
|
await integrationDriver(
|
||||||
|
onScreenshot: (
|
||||||
|
String screenshotName,
|
||||||
|
List<int> screenshotBytes, [
|
||||||
|
Map<String, Object?>? args,
|
||||||
|
]) async {
|
||||||
|
final dir = screenshotName.split("/")[0];
|
||||||
|
final name = screenshotName.split("/")[1];
|
||||||
|
final File image = await File('integration_test/goldens/$dir/$name.png')
|
||||||
|
.create(recursive: true);
|
||||||
|
|
||||||
|
image.writeAsBytesSync(screenshotBytes);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -187,6 +187,7 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
}
|
}
|
||||||
self.flutterTextureId = nil
|
self.flutterTextureId = nil
|
||||||
self.pixelBuffer = nil
|
self.pixelBuffer = nil
|
||||||
|
result(true)
|
||||||
case "resize":
|
case "resize":
|
||||||
let args = call.arguments as! [Any]
|
let args = call.arguments as! [Any]
|
||||||
let width = UInt32(args[0] as! Int64)
|
let width = UInt32(args[0] as! Int64)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ typedef void (*FilamentRenderCallback)(void* const owner);
|
|||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void* const create_filament_viewer_ffi(void* const context, void* const platform, const char* uberArchivePath, const ResourceLoaderWrapper* const loader, void (*renderCallback)(void* const renderCallbackOwner), void* const renderCallbackOwner);
|
FLUTTER_PLUGIN_EXPORT void* const create_filament_viewer_ffi(void* const context, void* const platform, const char* uberArchivePath, const ResourceLoaderWrapper* const loader, void (*renderCallback)(void* const renderCallbackOwner), void* const renderCallbackOwner);
|
||||||
FLUTTER_PLUGIN_EXPORT void create_swap_chain_ffi(void* const viewer, void* const surface, uint32_t width, uint32_t height);
|
FLUTTER_PLUGIN_EXPORT void create_swap_chain_ffi(void* const viewer, void* const surface, uint32_t width, uint32_t height);
|
||||||
|
FLUTTER_PLUGIN_EXPORT void destroy_swap_chain_ffi(void* const viewer);
|
||||||
FLUTTER_PLUGIN_EXPORT void create_render_target_ffi(void* const viewer, intptr_t nativeTextureId, uint32_t width, uint32_t height);
|
FLUTTER_PLUGIN_EXPORT void create_render_target_ffi(void* const viewer, intptr_t nativeTextureId, uint32_t width, uint32_t height);
|
||||||
FLUTTER_PLUGIN_EXPORT void destroy_filament_viewer_ffi(void* const viewer);
|
FLUTTER_PLUGIN_EXPORT void destroy_filament_viewer_ffi(void* const viewer);
|
||||||
FLUTTER_PLUGIN_EXPORT void render_ffi(void* const viewer);
|
FLUTTER_PLUGIN_EXPORT void render_ffi(void* const viewer);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ extern "C" {
|
|||||||
#if defined(__cplusplus) && !defined(__ANDROID__) && !defined(__APPLE__)
|
#if defined(__cplusplus) && !defined(__ANDROID__) && !defined(__APPLE__)
|
||||||
ResourceBuffer(const void* const data, const int32_t size, const int32_t id) : data(data), size(size), id(id) {};
|
ResourceBuffer(const void* const data, const int32_t size, const int32_t id) : data(data), size(size), id(id) {};
|
||||||
ResourceBuffer(const ResourceBuffer& rb) : data(rb.data), size(rb.size), id(rb.id) { };
|
ResourceBuffer(const ResourceBuffer& rb) : data(rb.data), size(rb.size), id(rb.id) { };
|
||||||
ResourceBuffer(const ResourceBuffer&& rb) : data(rb.data), size(rb.size), id(rb.id) { };
|
ResourceBuffer(const ResourceBuffer&& rb) noexcept : data(rb.data), size(rb.size), id(rb.id) { };
|
||||||
ResourceBuffer& operator=(const ResourceBuffer& other) = delete;
|
ResourceBuffer& operator=(const ResourceBuffer& other) = delete;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,459 +2,446 @@
|
|||||||
#include "PolyvoxFilamentFFIApi.h"
|
#include "PolyvoxFilamentFFIApi.h"
|
||||||
|
|
||||||
#include "FilamentViewer.hpp"
|
#include "FilamentViewer.hpp"
|
||||||
#include "filament/LightManager.h"
|
|
||||||
#include "Log.hpp"
|
#include "Log.hpp"
|
||||||
#include "ThreadPool.hpp"
|
#include "ThreadPool.hpp"
|
||||||
|
#include "filament/LightManager.h"
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <mutex>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
using namespace polyvox;
|
using namespace polyvox;
|
||||||
|
|
||||||
class RenderLoop
|
class RenderLoop {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
explicit RenderLoop()
|
explicit RenderLoop() {
|
||||||
{
|
_t = new std::thread([this]() {
|
||||||
_t = new std::thread([this]()
|
while (!_stop) {
|
||||||
{
|
{
|
||||||
while(!_stop) {
|
if (_rendering) {
|
||||||
if(_rendering) {
|
doRender();
|
||||||
doRender();
|
}
|
||||||
}
|
}
|
||||||
std::function<void()> task;
|
std::function<void()> task;
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(_access);
|
std::unique_lock<std::mutex> lock(_access);
|
||||||
if(_tasks.empty()) {
|
if (_tasks.empty()) {
|
||||||
_cond.wait_for(lock, std::chrono::duration<float, std::milli>(_frameIntervalInMilliseconds));
|
_cond.wait_for(lock, std::chrono::duration<float, std::milli>(
|
||||||
continue;
|
_frameIntervalInMilliseconds));
|
||||||
}
|
continue;
|
||||||
task = std::move(_tasks.front());
|
}
|
||||||
_tasks.pop_front();
|
task = std::move(_tasks.front());
|
||||||
}
|
_tasks.pop_front();
|
||||||
task();
|
}
|
||||||
} });
|
task();
|
||||||
}
|
}
|
||||||
~RenderLoop()
|
});
|
||||||
{
|
}
|
||||||
_stop = true;
|
~RenderLoop() {
|
||||||
_t->join();
|
_stop = true;
|
||||||
}
|
_t->join();
|
||||||
|
}
|
||||||
|
|
||||||
void* const createViewer(
|
void *const createViewer(void *const context, void *const platform,
|
||||||
void* const context,
|
const char *uberArchivePath,
|
||||||
void* const platform,
|
const ResourceLoaderWrapper *const loader,
|
||||||
const char* uberArchivePath,
|
void (*renderCallback)(void *), void *const owner) {
|
||||||
const ResourceLoaderWrapper* const loader,
|
_renderCallback = renderCallback;
|
||||||
void (*renderCallback)(void*), void* const owner
|
_renderCallbackOwner = owner;
|
||||||
) {
|
std::packaged_task<FilamentViewer *()> lambda([&]() mutable {
|
||||||
_renderCallback = renderCallback;
|
std::thread::id this_id = std::this_thread::get_id();
|
||||||
_renderCallbackOwner = owner;
|
return new FilamentViewer(context, loader, platform, uberArchivePath);
|
||||||
std::packaged_task<FilamentViewer*()> lambda([&]() mutable
|
});
|
||||||
{
|
auto fut = add_task(lambda);
|
||||||
return new FilamentViewer(context, loader, platform, uberArchivePath);
|
fut.wait();
|
||||||
});
|
_viewer = fut.get();
|
||||||
auto fut = add_task(lambda);
|
return (void *const)_viewer;
|
||||||
fut.wait();
|
}
|
||||||
_viewer = fut.get();
|
|
||||||
return (void* const)_viewer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroyViewer() {
|
void destroyViewer() {
|
||||||
std::packaged_task<void()> lambda([&]() mutable {
|
std::packaged_task<void()> lambda([&]() mutable {
|
||||||
_rendering = false;
|
_rendering = false;
|
||||||
destroy_filament_viewer(_viewer);
|
destroy_filament_viewer(_viewer);
|
||||||
_viewer = nullptr;
|
_viewer = nullptr;
|
||||||
});
|
});
|
||||||
auto fut = add_task(lambda);
|
auto fut = add_task(lambda);
|
||||||
fut.wait();
|
fut.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRendering(bool rendering)
|
void setRendering(bool rendering) {
|
||||||
{
|
std::packaged_task<void()> lambda(
|
||||||
_rendering = rendering;
|
[&]() mutable { this->_rendering = rendering; });
|
||||||
}
|
auto fut = add_task(lambda);
|
||||||
|
fut.wait();
|
||||||
|
}
|
||||||
|
|
||||||
void doRender()
|
void doRender() {
|
||||||
{
|
render(_viewer, 0, nullptr, nullptr, nullptr);
|
||||||
render(_viewer, 0, nullptr, nullptr, nullptr);
|
_renderCallback(_renderCallbackOwner);
|
||||||
_renderCallback(_renderCallbackOwner);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void setFrameIntervalInMilliseconds(float frameIntervalInMilliseconds) {
|
void setFrameIntervalInMilliseconds(float frameIntervalInMilliseconds) {
|
||||||
_frameIntervalInMilliseconds = frameIntervalInMilliseconds;
|
_frameIntervalInMilliseconds = frameIntervalInMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Rt>
|
template <class Rt>
|
||||||
auto add_task(std::packaged_task<Rt()> &pt) -> std::future<Rt>
|
auto add_task(std::packaged_task<Rt()> &pt) -> std::future<Rt> {
|
||||||
{
|
std::unique_lock<std::mutex> lock(_access);
|
||||||
std::unique_lock<std::mutex> lock(_access);
|
auto ret = pt.get_future();
|
||||||
auto ret = pt.get_future();
|
_tasks.push_back([pt = std::make_shared<std::packaged_task<Rt()>>(
|
||||||
_tasks.push_back([pt = std::make_shared<std::packaged_task<Rt()>>(std::move(pt))]
|
std::move(pt))] { (*pt)(); });
|
||||||
{ (*pt)(); });
|
_cond.notify_one();
|
||||||
_cond.notify_one();
|
return ret;
|
||||||
return ret;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _stop = false;
|
bool _stop = false;
|
||||||
bool _rendering = false;
|
bool _rendering = false;
|
||||||
float _frameIntervalInMilliseconds = 1000.0 / 60.0;
|
float _frameIntervalInMilliseconds = 1000.0 / 60.0;
|
||||||
std::mutex _access;
|
std::mutex _access;
|
||||||
FilamentViewer *_viewer = nullptr;
|
FilamentViewer *_viewer = nullptr;
|
||||||
void (*_renderCallback)(void* const) = nullptr;
|
void (*_renderCallback)(void *const) = nullptr;
|
||||||
void *_renderCallbackOwner = nullptr;
|
void *_renderCallbackOwner = nullptr;
|
||||||
std::thread *_t = nullptr;
|
std::thread *_t = nullptr;
|
||||||
std::condition_variable _cond;
|
std::condition_variable _cond;
|
||||||
std::deque<std::function<void()>> _tasks;
|
std::deque<std::function<void()>> _tasks;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
|
||||||
|
|
||||||
static RenderLoop *_rl;
|
static RenderLoop *_rl;
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void* const create_filament_viewer_ffi(
|
FLUTTER_PLUGIN_EXPORT void *const create_filament_viewer_ffi(
|
||||||
void* const context,
|
void *const context, void *const platform, const char *uberArchivePath,
|
||||||
void* const platform,
|
const ResourceLoaderWrapper *const loader,
|
||||||
const char* uberArchivePath,
|
void (*renderCallback)(void *const renderCallbackOwner),
|
||||||
const ResourceLoaderWrapper* const loader,
|
void *const renderCallbackOwner) {
|
||||||
void (*renderCallback)(void* const renderCallbackOwner),
|
if (!_rl) {
|
||||||
void* const renderCallbackOwner) {
|
_rl = new RenderLoop();
|
||||||
if (!_rl)
|
}
|
||||||
{
|
return _rl->createViewer(context, platform, uberArchivePath, loader,
|
||||||
_rl = new RenderLoop();
|
renderCallback, renderCallbackOwner);
|
||||||
}
|
}
|
||||||
return _rl->createViewer(context, platform,uberArchivePath, loader, renderCallback, renderCallbackOwner);
|
|
||||||
}
|
FLUTTER_PLUGIN_EXPORT void destroy_filament_viewer_ffi(void *const viewer) {
|
||||||
|
_rl->destroyViewer();
|
||||||
FLUTTER_PLUGIN_EXPORT void destroy_filament_viewer_ffi(void* const viewer) {
|
}
|
||||||
_rl->destroyViewer();
|
|
||||||
}
|
FLUTTER_PLUGIN_EXPORT void create_swap_chain_ffi(void *const viewer,
|
||||||
|
void *const surface,
|
||||||
FLUTTER_PLUGIN_EXPORT void create_swap_chain_ffi(void* const viewer, void* const surface, uint32_t width, uint32_t height)
|
uint32_t width,
|
||||||
{
|
uint32_t height) {
|
||||||
Log("Creating swapchain %dx%d", width, height);
|
Log("Creating swapchain %dx%d", width, height);
|
||||||
std::packaged_task<void()> lambda([&]() mutable
|
std::packaged_task<void()> lambda(
|
||||||
{
|
[&]() mutable { create_swap_chain(viewer, surface, width, height); });
|
||||||
create_swap_chain(viewer, surface, width, height);
|
auto fut = _rl->add_task(lambda);
|
||||||
});
|
fut.wait();
|
||||||
auto fut = _rl->add_task(lambda);
|
}
|
||||||
fut.wait();
|
|
||||||
}
|
FLUTTER_PLUGIN_EXPORT void destroy_swap_chain_ffi(void *const viewer) {
|
||||||
|
Log("Destroying swapchain");
|
||||||
FLUTTER_PLUGIN_EXPORT void create_render_target_ffi(void* const viewer, intptr_t nativeTextureId, uint32_t width, uint32_t height)
|
std::packaged_task<void()> lambda(
|
||||||
{
|
[&]() mutable {
|
||||||
std::packaged_task<void()> lambda([&]() mutable
|
destroy_swap_chain(viewer);
|
||||||
{ create_render_target(viewer, nativeTextureId, width, height); });
|
});
|
||||||
auto fut = _rl->add_task(lambda);
|
auto fut = _rl->add_task(lambda);
|
||||||
fut.wait();
|
fut.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void update_viewport_and_camera_projection_ffi(void* const viewer, const uint32_t width, const uint32_t height, const float scaleFactor)
|
FLUTTER_PLUGIN_EXPORT void create_render_target_ffi(void *const viewer,
|
||||||
{
|
intptr_t nativeTextureId,
|
||||||
Log("Update viewport %dx%d", width, height);
|
uint32_t width,
|
||||||
std::packaged_task<void()> lambda([&]() mutable
|
uint32_t height) {
|
||||||
{
|
std::packaged_task<void()> lambda([&]() mutable {
|
||||||
update_viewport_and_camera_projection(viewer, width, height, scaleFactor);
|
create_render_target(viewer, nativeTextureId, width, height);
|
||||||
});
|
});
|
||||||
auto fut = _rl->add_task(lambda);
|
auto fut = _rl->add_task(lambda);
|
||||||
fut.wait();
|
fut.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void set_rendering_ffi(void* const viewer, bool rendering)
|
FLUTTER_PLUGIN_EXPORT void update_viewport_and_camera_projection_ffi(
|
||||||
{
|
void *const viewer, const uint32_t width, const uint32_t height,
|
||||||
if (!_rl)
|
const float scaleFactor) {
|
||||||
{
|
Log("Update viewport %dx%d", width, height);
|
||||||
Log("No render loop!"); // PANIC?
|
std::packaged_task<void()> lambda([&]() mutable {
|
||||||
}
|
update_viewport_and_camera_projection(viewer, width, height, scaleFactor);
|
||||||
else
|
});
|
||||||
{
|
auto fut = _rl->add_task(lambda);
|
||||||
if (rendering)
|
fut.wait();
|
||||||
{
|
}
|
||||||
Log("Set rendering to true");
|
|
||||||
}
|
FLUTTER_PLUGIN_EXPORT void set_rendering_ffi(void *const viewer,
|
||||||
else
|
bool rendering) {
|
||||||
{
|
if (!_rl) {
|
||||||
Log("Set rendering to false");
|
Log("No render loop!"); // PANIC?
|
||||||
}
|
} else {
|
||||||
_rl->setRendering(rendering);
|
if (rendering) {
|
||||||
}
|
Log("Set rendering to true");
|
||||||
}
|
} else {
|
||||||
|
Log("Set rendering to false");
|
||||||
FLUTTER_PLUGIN_EXPORT void set_frame_interval_ffi(float frameIntervalInMilliseconds) {
|
}
|
||||||
_rl->setFrameIntervalInMilliseconds(frameIntervalInMilliseconds);
|
_rl->setRendering(rendering);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
FLUTTER_PLUGIN_EXPORT void render_ffi(void* const viewer)
|
|
||||||
{
|
FLUTTER_PLUGIN_EXPORT void
|
||||||
std::packaged_task<void()> lambda([&]() mutable
|
set_frame_interval_ffi(float frameIntervalInMilliseconds) {
|
||||||
{
|
_rl->setFrameIntervalInMilliseconds(frameIntervalInMilliseconds);
|
||||||
_rl->doRender();
|
}
|
||||||
});
|
|
||||||
auto fut = _rl->add_task(lambda);
|
FLUTTER_PLUGIN_EXPORT void render_ffi(void *const viewer) {
|
||||||
fut.wait();
|
std::packaged_task<void()> lambda([&]() mutable { _rl->doRender(); });
|
||||||
}
|
auto fut = _rl->add_task(lambda);
|
||||||
|
fut.wait();
|
||||||
FLUTTER_PLUGIN_EXPORT void set_background_color_ffi(void* const viewer, const float r, const float g, const float b, const float a)
|
}
|
||||||
{
|
|
||||||
std::packaged_task<void()> lambda([&]() mutable
|
FLUTTER_PLUGIN_EXPORT void
|
||||||
{ set_background_color(viewer, r, g, b, a); });
|
set_background_color_ffi(void *const viewer, const float r, const float g,
|
||||||
auto fut = _rl->add_task(lambda);
|
const float b, const float a) {
|
||||||
fut.wait();
|
std::packaged_task<void()> lambda(
|
||||||
}
|
[&]() mutable { set_background_color(viewer, r, g, b, a); });
|
||||||
|
auto fut = _rl->add_task(lambda);
|
||||||
FLUTTER_PLUGIN_EXPORT EntityId load_gltf_ffi(void* const assetManager, const char *path, const char *relativeResourcePath)
|
fut.wait();
|
||||||
{
|
}
|
||||||
std::packaged_task<EntityId()> lambda([&]() mutable
|
|
||||||
{ return load_gltf(assetManager, path, relativeResourcePath); });
|
FLUTTER_PLUGIN_EXPORT EntityId load_gltf_ffi(void *const assetManager,
|
||||||
auto fut = _rl->add_task(lambda);
|
const char *path,
|
||||||
fut.wait();
|
const char *relativeResourcePath) {
|
||||||
return fut.get();
|
std::packaged_task<EntityId()> lambda([&]() mutable {
|
||||||
}
|
return load_gltf(assetManager, path, relativeResourcePath);
|
||||||
|
});
|
||||||
FLUTTER_PLUGIN_EXPORT EntityId load_glb_ffi(void* const assetManager, const char *path, bool unlit)
|
auto fut = _rl->add_task(lambda);
|
||||||
{
|
fut.wait();
|
||||||
std::packaged_task<EntityId()> lambda([&]() mutable
|
return fut.get();
|
||||||
{ return load_glb(assetManager, path, unlit); });
|
}
|
||||||
auto fut = _rl->add_task(lambda);
|
|
||||||
fut.wait();
|
FLUTTER_PLUGIN_EXPORT EntityId load_glb_ffi(void *const assetManager,
|
||||||
return fut.get();
|
const char *path, bool unlit) {
|
||||||
}
|
std::packaged_task<EntityId()> lambda(
|
||||||
|
[&]() mutable { return load_glb(assetManager, path, unlit); });
|
||||||
FLUTTER_PLUGIN_EXPORT void clear_background_image_ffi(void* const viewer)
|
auto fut = _rl->add_task(lambda);
|
||||||
{
|
fut.wait();
|
||||||
std::packaged_task<void()> lambda([&]
|
return fut.get();
|
||||||
{
|
}
|
||||||
clear_background_image(viewer);
|
|
||||||
});
|
FLUTTER_PLUGIN_EXPORT void clear_background_image_ffi(void *const viewer) {
|
||||||
auto fut = _rl->add_task(lambda);
|
std::packaged_task<void()> lambda([&] { clear_background_image(viewer); });
|
||||||
fut.wait();
|
auto fut = _rl->add_task(lambda);
|
||||||
}
|
fut.wait();
|
||||||
|
}
|
||||||
FLUTTER_PLUGIN_EXPORT void set_background_image_ffi(void* const viewer, const char *path, bool fillHeight)
|
|
||||||
{
|
FLUTTER_PLUGIN_EXPORT void set_background_image_ffi(void *const viewer,
|
||||||
std::packaged_task<void()> lambda([&]
|
const char *path,
|
||||||
{
|
bool fillHeight) {
|
||||||
set_background_image(viewer, path, fillHeight);
|
std::packaged_task<void()> lambda(
|
||||||
});
|
[&] { set_background_image(viewer, path, fillHeight); });
|
||||||
auto fut = _rl->add_task(lambda);
|
auto fut = _rl->add_task(lambda);
|
||||||
fut.wait();
|
fut.wait();
|
||||||
}
|
}
|
||||||
FLUTTER_PLUGIN_EXPORT void set_background_image_position_ffi(void* const viewer, float x, float y, bool clamp)
|
FLUTTER_PLUGIN_EXPORT void set_background_image_position_ffi(void *const viewer,
|
||||||
{
|
float x, float y,
|
||||||
std::packaged_task<void()> lambda([&]
|
bool clamp) {
|
||||||
{ set_background_image_position(viewer, x, y, clamp); });
|
std::packaged_task<void()> lambda(
|
||||||
auto fut = _rl->add_task(lambda);
|
[&] { set_background_image_position(viewer, x, y, clamp); });
|
||||||
fut.wait();
|
auto fut = _rl->add_task(lambda);
|
||||||
}
|
fut.wait();
|
||||||
FLUTTER_PLUGIN_EXPORT void set_tone_mapping_ffi(void* const viewer, int toneMapping)
|
}
|
||||||
{
|
FLUTTER_PLUGIN_EXPORT void set_tone_mapping_ffi(void *const viewer,
|
||||||
std::packaged_task<void()> lambda([&]
|
int toneMapping) {
|
||||||
{ set_tone_mapping(viewer, toneMapping); });
|
std::packaged_task<void()> lambda(
|
||||||
auto fut = _rl->add_task(lambda);
|
[&] { set_tone_mapping(viewer, toneMapping); });
|
||||||
fut.wait();
|
auto fut = _rl->add_task(lambda);
|
||||||
}
|
fut.wait();
|
||||||
FLUTTER_PLUGIN_EXPORT void set_bloom_ffi(void* const viewer, float strength)
|
}
|
||||||
{
|
FLUTTER_PLUGIN_EXPORT void set_bloom_ffi(void *const viewer, float strength) {
|
||||||
std::packaged_task<void()> lambda([&]
|
std::packaged_task<void()> lambda([&] { set_bloom(viewer, strength); });
|
||||||
{ set_bloom(viewer, strength); });
|
auto fut = _rl->add_task(lambda);
|
||||||
auto fut = _rl->add_task(lambda);
|
fut.wait();
|
||||||
fut.wait();
|
}
|
||||||
}
|
FLUTTER_PLUGIN_EXPORT void load_skybox_ffi(void *const viewer,
|
||||||
FLUTTER_PLUGIN_EXPORT void load_skybox_ffi(void* const viewer, const char *skyboxPath)
|
const char *skyboxPath) {
|
||||||
{
|
std::packaged_task<void()> lambda([&] { load_skybox(viewer, skyboxPath); });
|
||||||
std::packaged_task<void()> lambda([&]
|
auto fut = _rl->add_task(lambda);
|
||||||
{ load_skybox(viewer, skyboxPath); });
|
fut.wait();
|
||||||
auto fut = _rl->add_task(lambda);
|
}
|
||||||
fut.wait();
|
FLUTTER_PLUGIN_EXPORT void load_ibl_ffi(void *const viewer, const char *iblPath,
|
||||||
}
|
float intensity) {
|
||||||
FLUTTER_PLUGIN_EXPORT void load_ibl_ffi(void* const viewer, const char *iblPath, float intensity)
|
std::packaged_task<void()> lambda(
|
||||||
{
|
[&] { load_ibl(viewer, iblPath, intensity); });
|
||||||
std::packaged_task<void()> lambda([&]
|
auto fut = _rl->add_task(lambda);
|
||||||
{ load_ibl(viewer, iblPath, intensity); });
|
fut.wait();
|
||||||
auto fut = _rl->add_task(lambda);
|
}
|
||||||
fut.wait();
|
FLUTTER_PLUGIN_EXPORT void remove_skybox_ffi(void *const viewer) {
|
||||||
}
|
std::packaged_task<void()> lambda([&] { remove_skybox(viewer); });
|
||||||
FLUTTER_PLUGIN_EXPORT void remove_skybox_ffi(void* const viewer)
|
auto fut = _rl->add_task(lambda);
|
||||||
{
|
fut.wait();
|
||||||
std::packaged_task<void()> lambda([&]
|
}
|
||||||
{ remove_skybox(viewer); });
|
|
||||||
auto fut = _rl->add_task(lambda);
|
FLUTTER_PLUGIN_EXPORT void remove_ibl_ffi(void *const viewer) {
|
||||||
fut.wait();
|
std::packaged_task<void()> lambda([&] { remove_ibl(viewer); });
|
||||||
}
|
auto fut = _rl->add_task(lambda);
|
||||||
|
fut.wait();
|
||||||
FLUTTER_PLUGIN_EXPORT void remove_ibl_ffi(void* const viewer)
|
}
|
||||||
{
|
|
||||||
std::packaged_task<void()> lambda([&]
|
EntityId add_light_ffi(void *const viewer, uint8_t type, float colour,
|
||||||
{ remove_ibl(viewer); });
|
float intensity, float posX, float posY, float posZ,
|
||||||
auto fut = _rl->add_task(lambda);
|
float dirX, float dirY, float dirZ, bool shadows) {
|
||||||
fut.wait();
|
std::packaged_task<EntityId()> lambda([&] {
|
||||||
}
|
return add_light(viewer, type, colour, intensity, posX, posY, posZ, dirX,
|
||||||
|
dirY, dirZ, shadows);
|
||||||
EntityId add_light_ffi(void* const viewer, uint8_t type, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows)
|
});
|
||||||
{
|
auto fut = _rl->add_task(lambda);
|
||||||
std::packaged_task<EntityId()> lambda([&]
|
fut.wait();
|
||||||
{ return add_light(viewer, type, colour, intensity, posX, posY, posZ, dirX, dirY, dirZ, shadows); });
|
return fut.get();
|
||||||
auto fut = _rl->add_task(lambda);
|
}
|
||||||
fut.wait();
|
|
||||||
return fut.get();
|
FLUTTER_PLUGIN_EXPORT void remove_light_ffi(void *const viewer,
|
||||||
}
|
EntityId entityId) {
|
||||||
|
std::packaged_task<void()> lambda([&] { remove_light(viewer, entityId); });
|
||||||
FLUTTER_PLUGIN_EXPORT void remove_light_ffi(void* const viewer, EntityId entityId)
|
auto fut = _rl->add_task(lambda);
|
||||||
{
|
fut.wait();
|
||||||
std::packaged_task<void()> lambda([&]
|
}
|
||||||
{ remove_light(viewer, entityId); });
|
|
||||||
auto fut = _rl->add_task(lambda);
|
FLUTTER_PLUGIN_EXPORT void clear_lights_ffi(void *const viewer) {
|
||||||
fut.wait();
|
std::packaged_task<void()> lambda([&] { clear_lights(viewer); });
|
||||||
}
|
auto fut = _rl->add_task(lambda);
|
||||||
|
fut.wait();
|
||||||
FLUTTER_PLUGIN_EXPORT void clear_lights_ffi(void* const viewer)
|
}
|
||||||
{
|
|
||||||
std::packaged_task<void()> lambda([&]
|
FLUTTER_PLUGIN_EXPORT void remove_asset_ffi(void *const viewer,
|
||||||
{ clear_lights(viewer); });
|
EntityId asset) {
|
||||||
auto fut = _rl->add_task(lambda);
|
std::packaged_task<void()> lambda([&] { remove_asset(viewer, asset); });
|
||||||
fut.wait();
|
auto fut = _rl->add_task(lambda);
|
||||||
}
|
fut.wait();
|
||||||
|
}
|
||||||
FLUTTER_PLUGIN_EXPORT void remove_asset_ffi(void* const viewer, EntityId asset)
|
FLUTTER_PLUGIN_EXPORT void clear_assets_ffi(void *const viewer) {
|
||||||
{
|
std::packaged_task<void()> lambda([&] { clear_assets(viewer); });
|
||||||
std::packaged_task<void()> lambda([&]
|
auto fut = _rl->add_task(lambda);
|
||||||
{ remove_asset(viewer, asset); });
|
fut.wait();
|
||||||
auto fut = _rl->add_task(lambda);
|
}
|
||||||
fut.wait();
|
|
||||||
}
|
FLUTTER_PLUGIN_EXPORT bool set_camera_ffi(void *const viewer, EntityId asset,
|
||||||
FLUTTER_PLUGIN_EXPORT void clear_assets_ffi(void* const viewer)
|
const char *nodeName) {
|
||||||
{
|
std::packaged_task<bool()> lambda(
|
||||||
std::packaged_task<void()> lambda([&]
|
[&] { return set_camera(viewer, asset, nodeName); });
|
||||||
{ clear_assets(viewer); });
|
auto fut = _rl->add_task(lambda);
|
||||||
auto fut = _rl->add_task(lambda);
|
fut.wait();
|
||||||
fut.wait();
|
return fut.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT bool set_camera_ffi(void* const viewer, EntityId asset, const char *nodeName)
|
FLUTTER_PLUGIN_EXPORT void set_bone_animation_ffi(
|
||||||
{
|
void *assetManager, EntityId asset, const float *const frameData,
|
||||||
std::packaged_task<bool()> lambda([&]
|
int numFrames, int numBones, const char **const boneNames,
|
||||||
{ return set_camera(viewer, asset, nodeName); });
|
const char **const meshName, int numMeshTargets, float frameLengthInMs) {
|
||||||
auto fut = _rl->add_task(lambda);
|
std::packaged_task<void()> lambda([&] {
|
||||||
fut.wait();
|
set_bone_animation(assetManager, asset, frameData, numFrames, numBones,
|
||||||
return fut.get();
|
boneNames, meshName, numMeshTargets, frameLengthInMs);
|
||||||
}
|
});
|
||||||
|
auto fut = _rl->add_task(lambda);
|
||||||
FLUTTER_PLUGIN_EXPORT void set_bone_animation_ffi(
|
fut.wait();
|
||||||
void *assetManager,
|
}
|
||||||
EntityId asset,
|
|
||||||
const float *const frameData,
|
FLUTTER_PLUGIN_EXPORT void
|
||||||
int numFrames,
|
get_morph_target_name_ffi(void *assetManager, EntityId asset,
|
||||||
int numBones,
|
const char *meshName, char *const outPtr, int index) {
|
||||||
const char **const boneNames,
|
std::packaged_task<void()> lambda([&] {
|
||||||
const char **const meshName,
|
get_morph_target_name(assetManager, asset, meshName, outPtr, index);
|
||||||
int numMeshTargets,
|
});
|
||||||
float frameLengthInMs)
|
auto fut = _rl->add_task(lambda);
|
||||||
{
|
fut.wait();
|
||||||
std::packaged_task<void()> lambda([&]
|
}
|
||||||
{ set_bone_animation(
|
|
||||||
assetManager, asset, frameData, numFrames, numBones,
|
FLUTTER_PLUGIN_EXPORT int
|
||||||
boneNames, meshName, numMeshTargets, frameLengthInMs); });
|
get_morph_target_name_count_ffi(void *assetManager, EntityId asset,
|
||||||
auto fut = _rl->add_task(lambda);
|
const char *meshName) {
|
||||||
fut.wait();
|
std::packaged_task<int()> lambda([&] {
|
||||||
}
|
return get_morph_target_name_count(assetManager, asset, meshName);
|
||||||
|
});
|
||||||
FLUTTER_PLUGIN_EXPORT void get_morph_target_name_ffi(void *assetManager, EntityId asset, const char *meshName, char *const outPtr, int index)
|
auto fut = _rl->add_task(lambda);
|
||||||
{
|
fut.wait();
|
||||||
std::packaged_task<void()> lambda([&]
|
return fut.get();
|
||||||
{ get_morph_target_name(assetManager, asset, meshName, outPtr, index); });
|
}
|
||||||
auto fut = _rl->add_task(lambda);
|
|
||||||
fut.wait();
|
void set_morph_target_weights_ffi(void *const assetManager, EntityId asset,
|
||||||
}
|
const char *const entityName,
|
||||||
|
const float *const morphData,
|
||||||
FLUTTER_PLUGIN_EXPORT int get_morph_target_name_count_ffi(void *assetManager, EntityId asset, const char *meshName)
|
int numWeights) {
|
||||||
{
|
// TODO
|
||||||
std::packaged_task<int()> lambda([&]
|
}
|
||||||
{ return get_morph_target_name_count(assetManager, asset, meshName); });
|
|
||||||
auto fut = _rl->add_task(lambda);
|
FLUTTER_PLUGIN_EXPORT void play_animation_ffi(void *const assetManager,
|
||||||
fut.wait();
|
EntityId asset, int index,
|
||||||
return fut.get();
|
bool loop, bool reverse,
|
||||||
}
|
bool replaceActive,
|
||||||
|
float crossfade) {
|
||||||
void set_morph_target_weights_ffi(
|
std::packaged_task<void()> lambda([&] {
|
||||||
void* const assetManager,
|
play_animation(assetManager, asset, index, loop, reverse, replaceActive,
|
||||||
EntityId asset,
|
crossfade);
|
||||||
const char *const entityName,
|
});
|
||||||
const float *const morphData,
|
auto fut = _rl->add_task(lambda);
|
||||||
int numWeights)
|
fut.wait();
|
||||||
{
|
}
|
||||||
// TODO
|
|
||||||
}
|
FLUTTER_PLUGIN_EXPORT void set_animation_frame_ffi(void *const assetManager,
|
||||||
|
EntityId asset,
|
||||||
FLUTTER_PLUGIN_EXPORT void play_animation_ffi(void* const assetManager, EntityId asset, int index, bool loop, bool reverse, bool replaceActive, float crossfade)
|
int animationIndex,
|
||||||
{
|
int animationFrame) {
|
||||||
std::packaged_task<void()> lambda([&]
|
std::packaged_task<void()> lambda([&] {
|
||||||
{ play_animation(assetManager, asset, index, loop, reverse, replaceActive, crossfade); });
|
set_animation_frame(assetManager, asset, animationIndex, animationFrame);
|
||||||
auto fut = _rl->add_task(lambda);
|
});
|
||||||
fut.wait();
|
auto fut = _rl->add_task(lambda);
|
||||||
}
|
fut.wait();
|
||||||
|
}
|
||||||
FLUTTER_PLUGIN_EXPORT void set_animation_frame_ffi(void* const assetManager, EntityId asset, int animationIndex, int animationFrame)
|
|
||||||
{
|
FLUTTER_PLUGIN_EXPORT void stop_animation_ffi(void *const assetManager,
|
||||||
std::packaged_task<void()> lambda([&]
|
EntityId asset, int index) {
|
||||||
{ set_animation_frame(assetManager, asset, animationIndex, animationFrame); });
|
std::packaged_task<void()> lambda(
|
||||||
auto fut = _rl->add_task(lambda);
|
[&] { stop_animation(assetManager, asset, index); });
|
||||||
fut.wait();
|
auto fut = _rl->add_task(lambda);
|
||||||
}
|
fut.wait();
|
||||||
|
}
|
||||||
FLUTTER_PLUGIN_EXPORT void stop_animation_ffi(void* const assetManager, EntityId asset, int index)
|
|
||||||
{
|
FLUTTER_PLUGIN_EXPORT int get_animation_count_ffi(void *const assetManager,
|
||||||
std::packaged_task<void()> lambda([&]
|
EntityId asset) {
|
||||||
{ stop_animation(assetManager, asset, index); });
|
std::packaged_task<int()> lambda(
|
||||||
auto fut = _rl->add_task(lambda);
|
[&] { return get_animation_count(assetManager, asset); });
|
||||||
fut.wait();
|
auto fut = _rl->add_task(lambda);
|
||||||
}
|
fut.wait();
|
||||||
|
return fut.get();
|
||||||
FLUTTER_PLUGIN_EXPORT int get_animation_count_ffi(void* const assetManager, EntityId asset)
|
}
|
||||||
{
|
FLUTTER_PLUGIN_EXPORT void get_animation_name_ffi(void *const assetManager,
|
||||||
std::packaged_task<int()> lambda([&]
|
EntityId asset,
|
||||||
{ return get_animation_count(assetManager, asset); });
|
char *const outPtr,
|
||||||
auto fut = _rl->add_task(lambda);
|
int index) {
|
||||||
fut.wait();
|
std::packaged_task<void()> lambda(
|
||||||
return fut.get();
|
[&] { get_animation_name(assetManager, asset, outPtr, index); });
|
||||||
}
|
auto fut = _rl->add_task(lambda);
|
||||||
FLUTTER_PLUGIN_EXPORT void get_animation_name_ffi(void* const assetManager, EntityId asset, char *const outPtr, int index)
|
fut.wait();
|
||||||
{
|
}
|
||||||
std::packaged_task<void()> lambda([&] {
|
|
||||||
get_animation_name(assetManager, asset, outPtr, index);
|
FLUTTER_PLUGIN_EXPORT void set_post_processing_ffi(void *const viewer,
|
||||||
});
|
bool enabled) {
|
||||||
auto fut = _rl->add_task(lambda);
|
std::packaged_task<void()> lambda(
|
||||||
fut.wait();
|
[&] { set_post_processing(viewer, enabled); });
|
||||||
}
|
auto fut = _rl->add_task(lambda);
|
||||||
|
fut.wait();
|
||||||
FLUTTER_PLUGIN_EXPORT void set_post_processing_ffi(void* const viewer, bool enabled) {
|
}
|
||||||
std::packaged_task<void()> lambda([&] {
|
|
||||||
set_post_processing(viewer, enabled);
|
FLUTTER_PLUGIN_EXPORT void pick_ffi(void *const viewer, int x, int y,
|
||||||
});
|
EntityId *entityId) {
|
||||||
auto fut = _rl->add_task(lambda);
|
std::packaged_task<void()> lambda([&] { pick(viewer, x, y, entityId); });
|
||||||
fut.wait();
|
auto fut = _rl->add_task(lambda);
|
||||||
}
|
fut.wait();
|
||||||
|
}
|
||||||
FLUTTER_PLUGIN_EXPORT void pick_ffi(void* const viewer, int x, int y, EntityId* entityId) {
|
|
||||||
std::packaged_task<void()> lambda([&] {
|
FLUTTER_PLUGIN_EXPORT const char *
|
||||||
pick(viewer, x, y, entityId);
|
get_name_for_entity_ffi(void *const assetManager, const EntityId entityId) {
|
||||||
});
|
std::packaged_task<const char *()> lambda(
|
||||||
auto fut = _rl->add_task(lambda);
|
[&] { return get_name_for_entity(assetManager, entityId); });
|
||||||
fut.wait();
|
auto fut = _rl->add_task(lambda);
|
||||||
}
|
fut.wait();
|
||||||
|
return fut.get();
|
||||||
FLUTTER_PLUGIN_EXPORT const char* get_name_for_entity_ffi(void* const assetManager, const EntityId entityId) {
|
}
|
||||||
std::packaged_task<const char*()> lambda([&] {
|
|
||||||
return get_name_for_entity(assetManager, entityId);
|
FLUTTER_PLUGIN_EXPORT void ios_dummy_ffi() { Log("Dummy called"); }
|
||||||
});
|
|
||||||
auto fut = _rl->add_task(lambda);
|
|
||||||
fut.wait();
|
|
||||||
return fut.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void ios_dummy_ffi() {
|
|
||||||
Log("Dummy called");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,34 @@ import 'package:polyvox_filament/animations/bone_animation_data.dart';
|
|||||||
import 'package:polyvox_filament/animations/morph_animation_data.dart';
|
import 'package:polyvox_filament/animations/morph_animation_data.dart';
|
||||||
|
|
||||||
typedef FilamentEntity = int;
|
typedef FilamentEntity = int;
|
||||||
const FilamentEntity FILAMENT_ASSET_ERROR = 0;
|
|
||||||
|
|
||||||
enum ToneMapper { ACES, FILMIC, LINEAR }
|
enum ToneMapper { ACES, FILMIC, LINEAR }
|
||||||
|
|
||||||
abstract class FilamentController {
|
class TextureDetails {
|
||||||
// the current target size of the viewport, in logical pixels
|
final int textureId;
|
||||||
ui.Size size = ui.Size.zero;
|
final int width;
|
||||||
|
final int height;
|
||||||
|
|
||||||
Stream<int?> get textureId;
|
TextureDetails(
|
||||||
Future get isReadyForScene;
|
{required this.textureId, required this.width, required this.height});
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class FilamentController {
|
||||||
|
///
|
||||||
|
/// The Flutter texture ID and dimensions for current texture in use.
|
||||||
|
/// This is only used by [FilamentWidget]; you shouldn't need to access directly yourself.
|
||||||
|
///
|
||||||
|
TextureDetails? get textureDetails;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// A stream to indicate whether a FilamentViewer is available.
|
||||||
|
/// [FilamentWidget] will (asynchronously) create a [FilamentViewer] after being inserted into the widget hierarchy;
|
||||||
|
/// listen to this stream beforehand to perform any work necessary once the viewer is available.
|
||||||
|
/// [FilamentWidget] may also destroy/recreate the viewer on certain lifecycle events (e.g. backgrounding a mobile app);
|
||||||
|
/// listen for any corresponding [false]/[true] events to perform related work.
|
||||||
|
/// Note this is not a broadcast stream; only one listener can be registered and events will be buffered.
|
||||||
|
///
|
||||||
|
Stream<bool> get hasViewer;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// The result(s) of calling [pick] (see below).
|
/// The result(s) of calling [pick] (see below).
|
||||||
@@ -23,6 +41,11 @@ abstract class FilamentController {
|
|||||||
///
|
///
|
||||||
Stream<FilamentEntity?> get pickResult;
|
Stream<FilamentEntity?> get pickResult;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Whether the controller is currently rendering at [framerate].
|
||||||
|
///
|
||||||
|
bool get rendering;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Set to true to continuously render the scene at the framerate specified by [setFrameRate] (60 fps by default).
|
/// Set to true to continuously render the scene at the framerate specified by [setFrameRate] (60 fps by default).
|
||||||
///
|
///
|
||||||
@@ -46,7 +69,8 @@ abstract class FilamentController {
|
|||||||
void setPixelRatio(double ratio);
|
void setPixelRatio(double ratio);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Destroys the viewer and all backing textures. You can leave the FilamentWidget in the hierarchy after this is called, but
|
/// Destroys the viewer and all backing textures. You can leave the FilamentWidget in the hierarchy after this is called, but you will need to manually call [createViewer] to
|
||||||
|
///
|
||||||
Future destroy();
|
Future destroy();
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -55,42 +79,85 @@ abstract class FilamentController {
|
|||||||
Future destroyViewer();
|
Future destroyViewer();
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Destroys the backing texture. You probably want to call [destroy] instead of this; this is exposed mostly for lifecycle changes which are handled by FilamentWidget.
|
/// Destroys the specified backing texture. You probably want to call [destroy] instead of this; this is exposed mostly for lifecycle changes which are handled by FilamentWidget.
|
||||||
///
|
///
|
||||||
Future destroyTexture();
|
Future destroyTexture();
|
||||||
|
|
||||||
///
|
///
|
||||||
/// You can insert a Filament viewport into the Flutter rendering hierarchy as follows:
|
/// Called by [FilamentWidget]; you generally will not need to call this yourself.
|
||||||
|
/// To recap, you can create a viewport is created in the Flutter rendering hierarchy by:
|
||||||
/// 1) Create a FilamentController
|
/// 1) Create a FilamentController
|
||||||
/// 2) Insert a FilamentWidget into the rendering tree, passing this instance of FilamentController
|
/// 2) Insert a FilamentWidget into the rendering tree, passing your FilamentController
|
||||||
/// 3) Initially, the FilamentWidget will only contain an empty Container (by default, with a solid red background).
|
/// 3) Initially, the FilamentWidget will only contain an empty Container (by default, with a solid red background).
|
||||||
/// This widget will render a single frame to get its actual size, then will itself call [createViewer]. You do not need to call [createViewer] yourself.
|
/// This widget will render a single frame to get its actual size, then will itself call [createViewer]. You do not need to call [createViewer] yourself.
|
||||||
/// This will dispatch a request to the native platform to create a hardware texture (Metal on iOS, OpenGL on Linux, GLES on Android and Windows) and a FilamentViewer (the main interface for manipulating the 3D scene) .
|
/// This will dispatch a request to the native platform to create a hardware texture (Metal on iOS, OpenGL on Linux, GLES on Android and Windows) and a FilamentViewer (the main interface for manipulating the 3D scene) .
|
||||||
/// 4) The FilamentController will notify FilamentWidget that a texture is available
|
/// 4) The FilamentController will notify FilamentWidget that a texture is available
|
||||||
/// 5) The FilamentWidget will replace the empty Container with a Texture widget
|
/// 5) The FilamentWidget will replace the empty Container with a Texture widget
|
||||||
/// If you need to wait until a FilamentViewer has been created, [await] the [isReadyForScene] Future.
|
/// If you need to wait until a FilamentViewer has been created, listen to the [viewer] stream.
|
||||||
|
///
|
||||||
|
void createViewer(int width, int height);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Resize the viewport & backing texture.
|
||||||
|
/// This is called by FilamentWidget; you shouldn't need to invoke this manually.
|
||||||
///
|
///
|
||||||
Future createViewer(int width, int height);
|
|
||||||
Future resize(int width, int height, {double scaleFactor = 1.0});
|
Future resize(int width, int height, {double scaleFactor = 1.0});
|
||||||
|
|
||||||
Future clearBackgroundImage();
|
///
|
||||||
|
/// Set the background image to [path] (which should have a file extension .png, .jpg, or .ktx).
|
||||||
|
/// This will be rendered at the maximum depth (i.e. behind all other objects including the skybox).
|
||||||
|
/// If [fillHeight] is false, the image will be rendered at its original size. Note this may cause issues with pixel density so be sure to specify the correct resolution
|
||||||
|
/// If [fillHeight] is true, the image will be stretched/compressed to fit the height of the viewport.
|
||||||
|
///
|
||||||
Future setBackgroundImage(String path, {bool fillHeight = false});
|
Future setBackgroundImage(String path, {bool fillHeight = false});
|
||||||
|
|
||||||
Future setBackgroundColor(Color color);
|
///
|
||||||
|
/// Moves the background image to the relative offset from the origin (bottom-left) specified by [x] and [y].
|
||||||
|
/// If [clamp] is true, the image cannot be positioned outside the bounds of the viewport.
|
||||||
|
///
|
||||||
Future setBackgroundImagePosition(double x, double y, {bool clamp = false});
|
Future setBackgroundImagePosition(double x, double y, {bool clamp = false});
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Removes the background image.
|
||||||
|
///
|
||||||
|
Future clearBackgroundImage();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Sets the color for the background plane (positioned at the maximum depth, i.e. behind all other objects including the skybox).
|
||||||
|
///
|
||||||
|
Future setBackgroundColor(Color color);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Load a skybox from [skyboxPath] (which must be a .ktx file)
|
||||||
|
///
|
||||||
Future loadSkybox(String skyboxPath);
|
Future loadSkybox(String skyboxPath);
|
||||||
Future loadIbl(String lightingPath, {double intensity = 30000});
|
|
||||||
|
///
|
||||||
|
/// Removes the skybox from the scene.
|
||||||
|
///
|
||||||
Future removeSkybox();
|
Future removeSkybox();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Loads an image-based light from the specified path at the given intensity.
|
||||||
|
/// Only one IBL can be active at any given time; if an IBL has already been loaded, it will be replaced.
|
||||||
|
///
|
||||||
|
Future loadIbl(String lightingPath, {double intensity = 30000});
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Removes the image-based light from the scene.
|
||||||
|
///
|
||||||
Future removeIbl();
|
Future removeIbl();
|
||||||
|
|
||||||
// copied from LightManager.h
|
///
|
||||||
// enum class Type : uint8_t {
|
/// Adds a dynamic light to the scene.
|
||||||
// SUN, //!< Directional light that also draws a sun's disk in the sky.
|
/// copied from filament LightManager.h
|
||||||
// DIRECTIONAL, //!< Directional light, emits light in a given direction.
|
/// enum class Type : uint8_t {
|
||||||
// POINT, //!< Point light, emits light from a position, in all directions.
|
/// SUN, //!< Directional light that also draws a sun's disk in the sky.
|
||||||
// FOCUSED_SPOT, //!< Physically correct spot light.
|
/// DIRECTIONAL, //!< Directional light, emits light in a given direction.
|
||||||
// SPOT, //!< Spot light with coupling of outer cone and illumination disabled.
|
/// POINT, //!< Point light, emits light from a position, in all directions.
|
||||||
// };
|
/// FOCUSED_SPOT, //!< Physically correct spot light.
|
||||||
|
/// SPOT, //!< Spot light with coupling of outer cone and illumination disabled.
|
||||||
|
/// };
|
||||||
Future<FilamentEntity> addLight(
|
Future<FilamentEntity> addLight(
|
||||||
int type,
|
int type,
|
||||||
double colour,
|
double colour,
|
||||||
@@ -148,17 +215,18 @@ abstract class FilamentController {
|
|||||||
/// Set the weights for all morph targets under node [meshName] in [asset] to [weights].
|
/// Set the weights for all morph targets under node [meshName] in [asset] to [weights].
|
||||||
///
|
///
|
||||||
Future setMorphTargetWeights(
|
Future setMorphTargetWeights(
|
||||||
FilamentEntity asset, String meshName, List<double> weights);
|
FilamentEntity entity, String meshName, List<double> weights);
|
||||||
|
|
||||||
Future<List<String>> getMorphTargetNames(
|
Future<List<String>> getMorphTargetNames(
|
||||||
FilamentEntity asset, String meshName);
|
FilamentEntity entity, String meshName);
|
||||||
|
|
||||||
Future<List<String>> getAnimationNames(FilamentEntity asset);
|
Future<List<String>> getAnimationNames(FilamentEntity entity);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Returns the length (in seconds) of the animation at the given index.
|
/// Returns the length (in seconds) of the animation at the given index.
|
||||||
///
|
///
|
||||||
Future<double> getAnimationDuration(FilamentEntity asset, int animationIndex);
|
Future<double> getAnimationDuration(
|
||||||
|
FilamentEntity entity, int animationIndex);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Create/start a dynamic morph target animation for [asset].
|
/// Create/start a dynamic morph target animation for [asset].
|
||||||
@@ -167,7 +235,7 @@ abstract class FilamentController {
|
|||||||
/// Each frame is [numWeights] in length, and each entry is the weight to be applied to the morph target located at that index in the mesh primitive at that frame.
|
/// Each frame is [numWeights] in length, and each entry is the weight to be applied to the morph target located at that index in the mesh primitive at that frame.
|
||||||
///
|
///
|
||||||
Future setMorphAnimationData(
|
Future setMorphAnimationData(
|
||||||
FilamentEntity asset, MorphAnimationData animation);
|
FilamentEntity entity, MorphAnimationData animation);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Animates morph target weights/bone transforms (where each frame requires a duration of [frameLengthInMs].
|
/// Animates morph target weights/bone transforms (where each frame requires a duration of [frameLengthInMs].
|
||||||
@@ -175,13 +243,13 @@ abstract class FilamentController {
|
|||||||
/// Each frame is [numWeights] in length, and each entry is the weight to be applied to the morph target located at that index in the mesh primitive at that frame.
|
/// Each frame is [numWeights] in length, and each entry is the weight to be applied to the morph target located at that index in the mesh primitive at that frame.
|
||||||
/// for now we only allow animating a single bone (though multiple skinned targets are supported)
|
/// for now we only allow animating a single bone (though multiple skinned targets are supported)
|
||||||
///
|
///
|
||||||
Future setBoneAnimation(FilamentEntity asset, BoneAnimationData animation);
|
Future setBoneAnimation(FilamentEntity entity, BoneAnimationData animation);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Removes/destroys the specified entity from the scene.
|
/// Removes/destroys the specified entity from the scene.
|
||||||
/// [asset] will no longer be a valid handle after this method is called; ensure you immediately discard all references once this method is complete.
|
/// [asset] will no longer be a valid handle after this method is called; ensure you immediately discard all references once this method is complete.
|
||||||
///
|
///
|
||||||
Future removeAsset(FilamentEntity asset);
|
Future removeAsset(FilamentEntity entity);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Removes/destroys all renderable entities from the scene (including cameras).
|
/// Removes/destroys all renderable entities from the scene (including cameras).
|
||||||
@@ -207,18 +275,19 @@ abstract class FilamentController {
|
|||||||
///
|
///
|
||||||
/// Schedules the glTF animation at [index] in [asset] to start playing on the next frame.
|
/// Schedules the glTF animation at [index] in [asset] to start playing on the next frame.
|
||||||
///
|
///
|
||||||
Future playAnimation(FilamentEntity asset, int index,
|
Future playAnimation(FilamentEntity entity, int index,
|
||||||
{bool loop = false,
|
{bool loop = false,
|
||||||
bool reverse = false,
|
bool reverse = false,
|
||||||
bool replaceActive = true,
|
bool replaceActive = true,
|
||||||
double crossfade = 0.0});
|
double crossfade = 0.0});
|
||||||
Future setAnimationFrame(FilamentEntity asset, int index, int animationFrame);
|
Future setAnimationFrame(
|
||||||
Future stopAnimation(FilamentEntity asset, int animationIndex);
|
FilamentEntity entity, int index, int animationFrame);
|
||||||
|
Future stopAnimation(FilamentEntity entity, int animationIndex);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Sets the current scene camera to the glTF camera under [name] in [asset].
|
/// Sets the current scene camera to the glTF camera under [name] in [asset].
|
||||||
///
|
///
|
||||||
Future setCamera(FilamentEntity asset, String? name);
|
Future setCamera(FilamentEntity entity, String? name);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Sets the tone mapping (requires postprocessing).
|
/// Sets the tone mapping (requires postprocessing).
|
||||||
@@ -236,7 +305,7 @@ abstract class FilamentController {
|
|||||||
///
|
///
|
||||||
/// Repositions the camera to the last vertex of the bounding box of [asset], looking at the penultimate vertex.
|
/// Repositions the camera to the last vertex of the bounding box of [asset], looking at the penultimate vertex.
|
||||||
///
|
///
|
||||||
Future moveCameraToAsset(FilamentEntity asset);
|
Future moveCameraToAsset(FilamentEntity entity);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Enables/disables frustum culling. Currently we don't expose a method for manipulating the camera projection/culling matrices so this is your only option to deal with unwanted near/far clipping.
|
/// Enables/disables frustum culling. Currently we don't expose a method for manipulating the camera projection/culling matrices so this is your only option to deal with unwanted near/far clipping.
|
||||||
@@ -248,27 +317,39 @@ abstract class FilamentController {
|
|||||||
Future setCameraModelMatrix(List<double> matrix);
|
Future setCameraModelMatrix(List<double> matrix);
|
||||||
|
|
||||||
Future setMaterialColor(
|
Future setMaterialColor(
|
||||||
FilamentEntity asset, String meshName, int materialIndex, Color color);
|
FilamentEntity entity, String meshName, int materialIndex, Color color);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Scales [asset] up/down so it fits within a unit cube.
|
/// Scales [asset] up/down so it fits within a unit cube.
|
||||||
///
|
///
|
||||||
Future transformToUnitCube(FilamentEntity asset);
|
Future transformToUnitCube(FilamentEntity entity);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Sets the world space position for [asset] to the given coordinates.
|
/// Sets the world space position for [asset] to the given coordinates.
|
||||||
///
|
///
|
||||||
Future setPosition(FilamentEntity asset, double x, double y, double z);
|
Future setPosition(FilamentEntity entity, double x, double y, double z);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Enable/disable postprocessing.
|
/// Enable/disable postprocessing.
|
||||||
///
|
///
|
||||||
Future setPostProcessing(bool enabled);
|
Future setPostProcessing(bool enabled);
|
||||||
Future setScale(FilamentEntity asset, double scale);
|
|
||||||
|
///
|
||||||
|
/// Sets the scale for the given entity.
|
||||||
|
///
|
||||||
|
Future setScale(FilamentEntity entity, double scale);
|
||||||
Future setRotation(
|
Future setRotation(
|
||||||
FilamentEntity asset, double rads, double x, double y, double z);
|
FilamentEntity entity, double rads, double x, double y, double z);
|
||||||
Future hide(FilamentEntity asset, String meshName);
|
|
||||||
Future reveal(FilamentEntity asset, String meshName);
|
///
|
||||||
|
/// Reveal the node [meshName] under [entity]. Only applicable if [hide] had previously been called; this is a no-op otherwise.
|
||||||
|
///
|
||||||
|
Future reveal(FilamentEntity entity, String meshName);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Hide the node [meshName] under [entity]. The node is still loaded, but is no longer being rendered into the scene. Call [reveal] to re-commence rendering.
|
||||||
|
///
|
||||||
|
Future hide(FilamentEntity entity, String meshName);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Used to select the entity in the scene at the given viewport coordinates.
|
/// Used to select the entity in the scene at the given viewport coordinates.
|
||||||
@@ -277,4 +358,9 @@ abstract class FilamentController {
|
|||||||
/// [x] and [y] must be in local logical coordinates (i.e. where 0,0 is at top-left of the FilamentWidget).
|
/// [x] and [y] must be in local logical coordinates (i.e. where 0,0 is at top-left of the FilamentWidget).
|
||||||
///
|
///
|
||||||
void pick(int x, int y);
|
void pick(int x, int y);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Retrieves the name assigned to the given FilamentEntity (usually corresponds to the glTF mesh name).
|
||||||
|
///
|
||||||
|
String? getNameForEntity(FilamentEntity entity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:typed_data';
|
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
@@ -10,31 +9,30 @@ import 'package:polyvox_filament/animations/bone_animation_data.dart';
|
|||||||
import 'package:polyvox_filament/animations/morph_animation_data.dart';
|
import 'package:polyvox_filament/animations/morph_animation_data.dart';
|
||||||
import 'package:polyvox_filament/generated_bindings.dart';
|
import 'package:polyvox_filament/generated_bindings.dart';
|
||||||
|
|
||||||
|
const FilamentEntity _FILAMENT_ASSET_ERROR = 0;
|
||||||
|
|
||||||
class FilamentControllerFFI extends FilamentController {
|
class FilamentControllerFFI extends FilamentController {
|
||||||
late MethodChannel _channel = MethodChannel("app.polyvox.filament/event");
|
late MethodChannel _channel = MethodChannel("app.polyvox.filament/event");
|
||||||
|
|
||||||
double _pixelRatio = 1.0;
|
double _pixelRatio = 1.0;
|
||||||
|
|
||||||
int? _textureId;
|
|
||||||
final _textureIdController = StreamController<int?>.broadcast();
|
|
||||||
Stream<int?> get textureId => _textureIdController.stream;
|
|
||||||
|
|
||||||
Completer _isReadyForScene = Completer();
|
|
||||||
Future get isReadyForScene => _isReadyForScene.future;
|
|
||||||
|
|
||||||
late Pointer<Void>? _assetManager;
|
late Pointer<Void>? _assetManager;
|
||||||
|
|
||||||
late NativeLibrary _lib;
|
late NativeLibrary _lib;
|
||||||
|
|
||||||
Pointer<Void>? _viewer;
|
Pointer<Void>? _viewer;
|
||||||
|
|
||||||
bool _resizing = false;
|
|
||||||
|
|
||||||
final String? uberArchivePath;
|
final String? uberArchivePath;
|
||||||
|
|
||||||
|
Stream<bool> get hasViewer => _hasViewerController.stream;
|
||||||
|
final _hasViewerController = StreamController<bool>();
|
||||||
|
|
||||||
Stream<FilamentEntity> get pickResult => _pickResultController.stream;
|
Stream<FilamentEntity> get pickResult => _pickResultController.stream;
|
||||||
final _pickResultController = StreamController<FilamentEntity>.broadcast();
|
final _pickResultController = StreamController<FilamentEntity>.broadcast();
|
||||||
|
|
||||||
|
@override
|
||||||
|
TextureDetails? textureDetails;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// This controller uses platform channels to bridge Dart with the C/C++ code for the Filament API.
|
/// This controller uses platform channels to bridge Dart with the C/C++ code for the Filament API.
|
||||||
/// Setting up the context/texture (since this is platform-specific) and the render ticker are platform-specific; all other methods are passed through by the platform channel to the methods specified in PolyvoxFilamentApi.h.
|
/// Setting up the context/texture (since this is platform-specific) and the render ticker are platform-specific; all other methods are passed through by the platform channel to the methods specified in PolyvoxFilamentApi.h.
|
||||||
@@ -52,17 +50,21 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
_lib = NativeLibrary(dl);
|
_lib = NativeLibrary(dl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _rendering = false;
|
||||||
|
bool get rendering => _rendering;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future setRendering(bool render) async {
|
Future setRendering(bool render) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
|
_rendering = render;
|
||||||
_lib.set_rendering_ffi(_viewer!, render);
|
_lib.set_rendering_ffi(_viewer!, render);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future render() async {
|
Future render() async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.render_ffi(_viewer!);
|
_lib.render_ffi(_viewer!);
|
||||||
@@ -87,7 +89,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future destroyViewer() async {
|
Future destroyViewer() async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
var viewer = _viewer;
|
var viewer = _viewer;
|
||||||
@@ -96,44 +98,43 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
_assetManager = null;
|
_assetManager = null;
|
||||||
_lib.destroy_filament_viewer_ffi(viewer!);
|
_lib.destroy_filament_viewer_ffi(viewer!);
|
||||||
_isReadyForScene = Completer();
|
_hasViewerController.add(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future destroyTexture() async {
|
Future destroyTexture() async {
|
||||||
await _channel.invokeMethod("destroyTexture");
|
if (textureDetails != null) {
|
||||||
_textureId = null;
|
await _channel.invokeMethod("destroyTexture", textureDetails!.textureId);
|
||||||
_textureIdController.add(null);
|
}
|
||||||
|
print("Texture destroyed");
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Called by `FilamentWidget`. You do not need to call this yourself.
|
/// Called by `FilamentWidget`. You do not need to call this yourself.
|
||||||
///
|
///
|
||||||
Future createViewer(int width, int height) async {
|
void createViewer(int width, int height) async {
|
||||||
if (_viewer != null) {
|
if (_viewer != null) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"Viewer already exists, make sure you call destroyViewer first");
|
"Viewer already exists, make sure you call destroyViewer first");
|
||||||
}
|
}
|
||||||
if (_isReadyForScene.isCompleted) {
|
if (textureDetails != null) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"Do not call createViewer when a viewer has already been created without calling destroyViewer");
|
"Texture already exists, make sure you call destroyTexture first");
|
||||||
}
|
}
|
||||||
|
|
||||||
var loader = Pointer<ResourceLoaderWrapper>.fromAddress(
|
var loader = Pointer<ResourceLoaderWrapper>.fromAddress(
|
||||||
await _channel.invokeMethod("getResourceLoaderWrapper"));
|
await _channel.invokeMethod("getResourceLoaderWrapper"));
|
||||||
if (loader == nullptr) {
|
if (loader == nullptr) {
|
||||||
throw Exception("Failed to get resource loader");
|
throw Exception("Failed to get resource loader");
|
||||||
}
|
}
|
||||||
|
|
||||||
print("Using loader ${loader.address}");
|
var size = ui.Size(width * _pixelRatio, height * _pixelRatio);
|
||||||
|
|
||||||
size = ui.Size(width * _pixelRatio, height * _pixelRatio);
|
|
||||||
|
|
||||||
print("Creating viewer with size $size");
|
print("Creating viewer with size $size");
|
||||||
|
|
||||||
var textures =
|
var textures =
|
||||||
await _channel.invokeMethod("createTexture", [size.width, size.height]);
|
await _channel.invokeMethod("createTexture", [size.width, size.height]);
|
||||||
var flutterTextureId = textures[0];
|
var flutterTextureId = textures[0];
|
||||||
_textureId = flutterTextureId;
|
|
||||||
|
|
||||||
// void* on iOS (pointer to pixel buffer), void* on Android (pointer to native window), null on Windows/macOS
|
// void* on iOS (pointer to pixel buffer), void* on Android (pointer to native window), null on Windows/macOS
|
||||||
var surfaceAddress = textures[1] as int? ?? 0;
|
var surfaceAddress = textures[1] as int? ?? 0;
|
||||||
@@ -186,27 +187,104 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
_assetManager = _lib.get_asset_manager(_viewer!);
|
_assetManager = _lib.get_asset_manager(_viewer!);
|
||||||
|
|
||||||
_textureIdController.add(_textureId);
|
textureDetails = TextureDetails(
|
||||||
|
textureId: flutterTextureId!, width: width, height: height);
|
||||||
_isReadyForScene.complete(true);
|
_hasViewerController.add(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// I'm not exactly sure how to resize the backing textures on all platforms.
|
/// When a FilamentWidget is resized, it will call [resize]. This method will tear down/recreate the swapchain and propagate a new texture ID back to the FilamentWidget.
|
||||||
/// So for now, I'm sticking with the safe option when the widget is resized: destroying the swapchain, recreating the textures, and creating a new swapchain.
|
/// For "once-off" resizes, this is fine.
|
||||||
|
/// However, this can be problematic for consecutive resizes (e.g. dragging to expand/contract the parent window on desktop, or animating the size of the FilamentWidget itself).
|
||||||
|
/// It is too expensive to recreate the swapchain multiple times per second.
|
||||||
|
/// We therefore add a timer to FilamentWidget so that the call to [resize] is delayed (e.g. 50ms).
|
||||||
|
/// Any subsequent resizes before the delay window elapses will cancel the earlier call.
|
||||||
///
|
///
|
||||||
|
/// The overall process looks like this:
|
||||||
|
/// 1) the window is resized
|
||||||
|
/// 2) (Windows only) PixelBufferTexture is requested to provide a new pixel buffer with a new size, and we return an empty texture
|
||||||
|
/// 3) After Xms, [resize] is invoked
|
||||||
|
/// 4) the viewer is instructed to stop rendering (synchronous)
|
||||||
|
/// 5) the existing Filament swapchain is destroyed (synchronous)
|
||||||
|
/// 6) the Flutter texture is unregistered
|
||||||
|
/// a) this is asynchronous, but
|
||||||
|
/// b) *** SEE NOTE BELOW ON WINDOWS *** by passing the method channel result through to the callback, we make this synchronous from the Flutter side,
|
||||||
|
// c) in this async callback, the glTexture is destroyed
|
||||||
|
/// 7) a new Flutter/OpenGL texture is created (synchronous)
|
||||||
|
/// 8) a new swapchain is created (synchronous)
|
||||||
|
/// 9) if the viewer was rendering prior to the resize, the viewer is instructed to recommence rendering
|
||||||
|
/// 10) the new texture ID is pushed to the FilamentWidget
|
||||||
|
/// 11) the FilamentWidget updates the Texture widget with the new texture.
|
||||||
|
///
|
||||||
|
/// #### (Windows-only) ############################################################
|
||||||
|
/// # As soon as the widget/window is resized, the PixelBufferTexture will be
|
||||||
|
/// # requested to provide a new pixel buffer for the new size.
|
||||||
|
/// # Even with zero delay to the call to [resize], this will be triggered *before*
|
||||||
|
/// # we have had a chance to anything else (like tear down the swapchain).
|
||||||
|
/// # On the backend, we deal with this by simply returning an empty texture as soon
|
||||||
|
/// # as the size changes, and will rely on the followup call to [resize] to actually
|
||||||
|
/// # destroy/recreate the pixel buffer and Flutter texture.
|
||||||
|
///
|
||||||
|
/// NOTE RE ASYNC CALLBACK
|
||||||
|
/// # The bigger problem is a race condition when resize is called multiple times in quick succession (e.g dragging to resize on Windows).
|
||||||
|
/// # It looks like occasionally, the backend OpenGL texture is being destroyed while its corresponding swapchain is still active, causing a crash.
|
||||||
|
/// # I'm not exactly sure how/where this is occurring, but something clearly isn't synchronized between destroy_swap_chain_ffi and
|
||||||
|
/// # the asynchronous callback passed to FlutterTextureRegistrar::UnregisterTexture.
|
||||||
|
/// # Theoretically this could occur if resize_2 starts before resize_1 completes, i.e.
|
||||||
|
/// # 1) resize_1 destroys swapchain/texture and creates new texture
|
||||||
|
/// # 2) resize_2 destroys swapchain/texture
|
||||||
|
/// # 3) resize_1 creates new swapchain but texture isn't available, ergo crash
|
||||||
|
/// #
|
||||||
|
/// # I don't think this should happen if:
|
||||||
|
/// # 1) we add a flag on the Flutter side to ensure only one call to destroy/recreate the swapchain/texture is active at any given time, and
|
||||||
|
/// # 2) on the Flutter side, we are sure that calling destroyTexture only returns once the async callback on the native side has completed.
|
||||||
|
/// # For (1), checking if textureId is null at the entrypoint should be sufficient.
|
||||||
|
/// # For (2), we invoke flutter::MethodResult<flutter::EncodableValue>->Success in the UnregisterTexture callback.
|
||||||
|
/// #
|
||||||
|
/// # Maybe (2) doesn't actually make Flutter wait?
|
||||||
|
/// #
|
||||||
|
/// # The other possibility is that both (1) and (2) are fine and the issue is elsewhere.
|
||||||
|
/// #
|
||||||
|
/// # Either way, the current solution is to basically setup a double-buffer on resize.
|
||||||
|
/// # When destroyTexture is called, the active texture isn't destroyed yet, it's only marked as inactive.
|
||||||
|
/// # On subsequent calls to destroyTexture, the inactive texture is destroyed.
|
||||||
|
/// # This seems to work fine.
|
||||||
|
///
|
||||||
|
/// # Another option is to only use a single large (e.g. 4k) texture and simply crop whenever a resize is requested.
|
||||||
|
/// # This might be preferable for other reasons (e.g. don't need to destroy/recreate the pixel buffer or swapchain).
|
||||||
|
/// # Given we don't do this on other platforms, I'm OK to stick with the existing solution for the time being.
|
||||||
|
/// ############################################################################
|
||||||
|
///
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future resize(int width, int height, {double scaleFactor = 1.0}) async {
|
Future resize(int width, int height, {double scaleFactor = 1.0}) async {
|
||||||
_resizing = true;
|
// we defer to the FilamentWidget to ensure that every call to [resize] is synchronized
|
||||||
setRendering(false);
|
// so this exception should never be thrown (right?)
|
||||||
_lib.destroy_swap_chain(_viewer!);
|
if (textureDetails == null) {
|
||||||
await destroyTexture();
|
throw Exception("Resize currently underway, ignoring");
|
||||||
size = ui.Size(width * _pixelRatio, height * _pixelRatio);
|
}
|
||||||
|
|
||||||
var textures =
|
var _textureDetails = textureDetails;
|
||||||
await _channel.invokeMethod("createTexture", [size.width, size.height]);
|
|
||||||
var flutterTextureId = textures[0];
|
textureDetails = null;
|
||||||
_textureId = flutterTextureId;
|
|
||||||
|
_lib.set_rendering_ffi(_viewer!, false);
|
||||||
|
|
||||||
|
if (_textureDetails != null) {
|
||||||
|
if (_viewer != null) {
|
||||||
|
_lib.destroy_swap_chain_ffi(_viewer!);
|
||||||
|
}
|
||||||
|
|
||||||
|
await _channel.invokeMethod("destroyTexture", _textureDetails!.textureId);
|
||||||
|
print("Destroyed texture ${_textureDetails!.textureId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
var newSize = ui.Size(width * _pixelRatio, height * _pixelRatio);
|
||||||
|
|
||||||
|
print("Size after pixel ratio : $width x $height ");
|
||||||
|
|
||||||
|
var textures = await _channel
|
||||||
|
.invokeMethod("createTexture", [newSize.width, newSize.height]);
|
||||||
|
|
||||||
// void* on iOS (pointer to pixel buffer), void* on Android (pointer to native window), null on Windows/macOS
|
// void* on iOS (pointer to pixel buffer), void* on Android (pointer to native window), null on Windows/macOS
|
||||||
var surfaceAddress = textures[1] as int? ?? 0;
|
var surfaceAddress = textures[1] as int? ?? 0;
|
||||||
@@ -217,26 +295,26 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
_lib.create_swap_chain_ffi(
|
_lib.create_swap_chain_ffi(
|
||||||
_viewer!,
|
_viewer!,
|
||||||
Pointer<Void>.fromAddress(surfaceAddress),
|
Pointer<Void>.fromAddress(surfaceAddress),
|
||||||
size.width.toInt(),
|
newSize.width.toInt(),
|
||||||
size.height.toInt());
|
newSize.height.toInt());
|
||||||
if (nativeTexture != 0) {
|
if (nativeTexture != 0) {
|
||||||
assert(surfaceAddress == 0);
|
assert(surfaceAddress == 0);
|
||||||
print("Creating render target from native texture $nativeTexture");
|
print("Creating render target from native texture $nativeTexture");
|
||||||
_lib.create_render_target_ffi(
|
_lib.create_render_target_ffi(_viewer!, nativeTexture,
|
||||||
_viewer!, nativeTexture, size.width.toInt(), size.height.toInt());
|
newSize.width.toInt(), newSize.height.toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
_lib.update_viewport_and_camera_projection_ffi(
|
_lib.update_viewport_and_camera_projection_ffi(
|
||||||
_viewer!, size.width.toInt(), size.height.toInt(), 1.0);
|
_viewer!, newSize.width.toInt(), newSize.height.toInt(), 1.0);
|
||||||
|
|
||||||
_textureIdController.add(_textureId);
|
await setRendering(_rendering);
|
||||||
_resizing = false;
|
textureDetails =
|
||||||
setRendering(true);
|
TextureDetails(textureId: textures[0]!, width: width, height: height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future clearBackgroundImage() async {
|
Future clearBackgroundImage() async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.clear_background_image_ffi(_viewer!);
|
_lib.clear_background_image_ffi(_viewer!);
|
||||||
@@ -244,7 +322,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future setBackgroundImage(String path, {bool fillHeight = false}) async {
|
Future setBackgroundImage(String path, {bool fillHeight = false}) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_background_image_ffi(
|
_lib.set_background_image_ffi(
|
||||||
@@ -253,7 +331,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future setBackgroundColor(Color color) async {
|
Future setBackgroundColor(Color color) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_background_color_ffi(
|
_lib.set_background_color_ffi(
|
||||||
@@ -267,7 +345,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
@override
|
@override
|
||||||
Future setBackgroundImagePosition(double x, double y,
|
Future setBackgroundImagePosition(double x, double y,
|
||||||
{bool clamp = false}) async {
|
{bool clamp = false}) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_background_image_position_ffi(_viewer!, x, y, clamp);
|
_lib.set_background_image_position_ffi(_viewer!, x, y, clamp);
|
||||||
@@ -275,7 +353,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future loadSkybox(String skyboxPath) async {
|
Future loadSkybox(String skyboxPath) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.load_skybox_ffi(_viewer!, skyboxPath.toNativeUtf8().cast<Char>());
|
_lib.load_skybox_ffi(_viewer!, skyboxPath.toNativeUtf8().cast<Char>());
|
||||||
@@ -283,7 +361,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future loadIbl(String lightingPath, {double intensity = 30000}) async {
|
Future loadIbl(String lightingPath, {double intensity = 30000}) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.load_ibl_ffi(
|
_lib.load_ibl_ffi(
|
||||||
@@ -292,7 +370,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future removeSkybox() async {
|
Future removeSkybox() async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.remove_skybox_ffi(_viewer!);
|
_lib.remove_skybox_ffi(_viewer!);
|
||||||
@@ -300,7 +378,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future removeIbl() async {
|
Future removeIbl() async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.remove_ibl_ffi(_viewer!);
|
_lib.remove_ibl_ffi(_viewer!);
|
||||||
@@ -318,7 +396,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
double dirY,
|
double dirY,
|
||||||
double dirZ,
|
double dirZ,
|
||||||
bool castShadows) async {
|
bool castShadows) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
var entity = _lib.add_light_ffi(_viewer!, type, colour, intensity, posX,
|
var entity = _lib.add_light_ffi(_viewer!, type, colour, intensity, posX,
|
||||||
@@ -328,7 +406,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future removeLight(FilamentEntity light) async {
|
Future removeLight(FilamentEntity light) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.remove_light_ffi(_viewer!, light);
|
_lib.remove_light_ffi(_viewer!, light);
|
||||||
@@ -336,7 +414,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future clearLights() async {
|
Future clearLights() async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.clear_lights_ffi(_viewer!);
|
_lib.clear_lights_ffi(_viewer!);
|
||||||
@@ -344,7 +422,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<FilamentEntity> loadGlb(String path, {bool unlit = false}) async {
|
Future<FilamentEntity> loadGlb(String path, {bool unlit = false}) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
if (unlit) {
|
if (unlit) {
|
||||||
@@ -352,7 +430,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
}
|
}
|
||||||
var asset = _lib.load_glb_ffi(
|
var asset = _lib.load_glb_ffi(
|
||||||
_assetManager!, path.toNativeUtf8().cast<Char>(), unlit);
|
_assetManager!, path.toNativeUtf8().cast<Char>(), unlit);
|
||||||
if (asset == FILAMENT_ASSET_ERROR) {
|
if (asset == _FILAMENT_ASSET_ERROR) {
|
||||||
throw Exception("An error occurred loading the asset at $path");
|
throw Exception("An error occurred loading the asset at $path");
|
||||||
}
|
}
|
||||||
return asset;
|
return asset;
|
||||||
@@ -365,14 +443,14 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
throw Exception(
|
throw Exception(
|
||||||
"loadGltf has a race condition on Windows which is likely to crash your program. If you really want to try, pass force=true to loadGltf");
|
"loadGltf has a race condition on Windows which is likely to crash your program. If you really want to try, pass force=true to loadGltf");
|
||||||
}
|
}
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
var asset = _lib.load_gltf_ffi(
|
var asset = _lib.load_gltf_ffi(
|
||||||
_assetManager!,
|
_assetManager!,
|
||||||
path.toNativeUtf8().cast<Char>(),
|
path.toNativeUtf8().cast<Char>(),
|
||||||
relativeResourcePath.toNativeUtf8().cast<Char>());
|
relativeResourcePath.toNativeUtf8().cast<Char>());
|
||||||
if (asset == FILAMENT_ASSET_ERROR) {
|
if (asset == _FILAMENT_ASSET_ERROR) {
|
||||||
throw Exception("An error occurred loading the asset at $path");
|
throw Exception("An error occurred loading the asset at $path");
|
||||||
}
|
}
|
||||||
return asset;
|
return asset;
|
||||||
@@ -380,7 +458,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future panStart(double x, double y) async {
|
Future panStart(double x, double y) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.grab_begin(_viewer!, x * _pixelRatio, y * _pixelRatio, true);
|
_lib.grab_begin(_viewer!, x * _pixelRatio, y * _pixelRatio, true);
|
||||||
@@ -388,7 +466,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future panUpdate(double x, double y) async {
|
Future panUpdate(double x, double y) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.grab_update(_viewer!, x * _pixelRatio, y * _pixelRatio);
|
_lib.grab_update(_viewer!, x * _pixelRatio, y * _pixelRatio);
|
||||||
@@ -396,7 +474,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future panEnd() async {
|
Future panEnd() async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.grab_end(_viewer!);
|
_lib.grab_end(_viewer!);
|
||||||
@@ -404,7 +482,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future rotateStart(double x, double y) async {
|
Future rotateStart(double x, double y) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.grab_begin(_viewer!, x * _pixelRatio, y * _pixelRatio, false);
|
_lib.grab_begin(_viewer!, x * _pixelRatio, y * _pixelRatio, false);
|
||||||
@@ -412,7 +490,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future rotateUpdate(double x, double y) async {
|
Future rotateUpdate(double x, double y) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.grab_update(_viewer!, x * _pixelRatio, y * _pixelRatio);
|
_lib.grab_update(_viewer!, x * _pixelRatio, y * _pixelRatio);
|
||||||
@@ -420,7 +498,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future rotateEnd() async {
|
Future rotateEnd() async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.grab_end(_viewer!);
|
_lib.grab_end(_viewer!);
|
||||||
@@ -429,7 +507,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
@override
|
@override
|
||||||
Future setMorphTargetWeights(
|
Future setMorphTargetWeights(
|
||||||
FilamentEntity asset, String meshName, List<double> weights) async {
|
FilamentEntity asset, String meshName, List<double> weights) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
var weightsPtr = calloc<Float>(weights.length);
|
var weightsPtr = calloc<Float>(weights.length);
|
||||||
@@ -445,7 +523,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
@override
|
@override
|
||||||
Future<List<String>> getMorphTargetNames(
|
Future<List<String>> getMorphTargetNames(
|
||||||
FilamentEntity asset, String meshName) async {
|
FilamentEntity asset, String meshName) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
var names = <String>[];
|
var names = <String>[];
|
||||||
@@ -463,7 +541,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<String>> getAnimationNames(FilamentEntity asset) async {
|
Future<List<String>> getAnimationNames(FilamentEntity asset) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
var animationCount = _lib.get_animation_count(_assetManager!, asset);
|
var animationCount = _lib.get_animation_count(_assetManager!, asset);
|
||||||
@@ -480,7 +558,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
@override
|
@override
|
||||||
Future<double> getAnimationDuration(
|
Future<double> getAnimationDuration(
|
||||||
FilamentEntity asset, int animationIndex) async {
|
FilamentEntity asset, int animationIndex) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
var duration =
|
var duration =
|
||||||
@@ -492,7 +570,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
@override
|
@override
|
||||||
Future setMorphAnimationData(
|
Future setMorphAnimationData(
|
||||||
FilamentEntity asset, MorphAnimationData animation) async {
|
FilamentEntity asset, MorphAnimationData animation) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,7 +600,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
@override
|
@override
|
||||||
Future setBoneAnimation(
|
Future setBoneAnimation(
|
||||||
FilamentEntity asset, BoneAnimationData animation) async {
|
FilamentEntity asset, BoneAnimationData animation) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
// var data = calloc<Float>(animation.frameData.length);
|
// var data = calloc<Float>(animation.frameData.length);
|
||||||
@@ -559,7 +637,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future removeAsset(FilamentEntity asset) async {
|
Future removeAsset(FilamentEntity asset) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.remove_asset_ffi(_viewer!, asset);
|
_lib.remove_asset_ffi(_viewer!, asset);
|
||||||
@@ -567,7 +645,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future clearAssets() async {
|
Future clearAssets() async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.clear_assets_ffi(_viewer!);
|
_lib.clear_assets_ffi(_viewer!);
|
||||||
@@ -575,7 +653,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future zoomBegin() async {
|
Future zoomBegin() async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.scroll_begin(_viewer!);
|
_lib.scroll_begin(_viewer!);
|
||||||
@@ -583,7 +661,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future zoomUpdate(double x, double y, double z) async {
|
Future zoomUpdate(double x, double y, double z) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.scroll_update(_viewer!, x, y, z);
|
_lib.scroll_update(_viewer!, x, y, z);
|
||||||
@@ -591,7 +669,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future zoomEnd() async {
|
Future zoomEnd() async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.scroll_end(_viewer!);
|
_lib.scroll_end(_viewer!);
|
||||||
@@ -603,7 +681,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
bool reverse = false,
|
bool reverse = false,
|
||||||
bool replaceActive = true,
|
bool replaceActive = true,
|
||||||
double crossfade = 0.0}) async {
|
double crossfade = 0.0}) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.play_animation_ffi(
|
_lib.play_animation_ffi(
|
||||||
@@ -612,14 +690,14 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
Future setAnimationFrame(
|
Future setAnimationFrame(
|
||||||
FilamentEntity asset, int index, int animationFrame) async {
|
FilamentEntity asset, int index, int animationFrame) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_animation_frame(_assetManager!, asset, index, animationFrame);
|
_lib.set_animation_frame(_assetManager!, asset, index, animationFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future stopAnimation(FilamentEntity asset, int animationIndex) async {
|
Future stopAnimation(FilamentEntity asset, int animationIndex) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.stop_animation(_assetManager!, asset, animationIndex);
|
_lib.stop_animation(_assetManager!, asset, animationIndex);
|
||||||
@@ -627,7 +705,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future setCamera(FilamentEntity asset, String? name) async {
|
Future setCamera(FilamentEntity asset, String? name) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
var result = _lib.set_camera(
|
var result = _lib.set_camera(
|
||||||
@@ -639,7 +717,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future setToneMapping(ToneMapper mapper) async {
|
Future setToneMapping(ToneMapper mapper) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -648,7 +726,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future setPostProcessing(bool enabled) async {
|
Future setPostProcessing(bool enabled) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -657,35 +735,35 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future setBloom(double bloom) async {
|
Future setBloom(double bloom) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_bloom_ffi(_viewer!, bloom);
|
_lib.set_bloom_ffi(_viewer!, bloom);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future setCameraFocalLength(double focalLength) async {
|
Future setCameraFocalLength(double focalLength) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_camera_focal_length(_viewer!, focalLength);
|
_lib.set_camera_focal_length(_viewer!, focalLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future setCameraFocusDistance(double focusDistance) async {
|
Future setCameraFocusDistance(double focusDistance) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_camera_focus_distance(_viewer!, focusDistance);
|
_lib.set_camera_focus_distance(_viewer!, focusDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future setCameraPosition(double x, double y, double z) async {
|
Future setCameraPosition(double x, double y, double z) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_camera_position(_viewer!, x, y, z);
|
_lib.set_camera_position(_viewer!, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future moveCameraToAsset(FilamentEntity asset) async {
|
Future moveCameraToAsset(FilamentEntity asset) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.move_camera_to_asset(_viewer!, asset);
|
_lib.move_camera_to_asset(_viewer!, asset);
|
||||||
@@ -693,7 +771,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future setViewFrustumCulling(bool enabled) async {
|
Future setViewFrustumCulling(bool enabled) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_view_frustum_culling(_viewer!, enabled);
|
_lib.set_view_frustum_culling(_viewer!, enabled);
|
||||||
@@ -701,21 +779,21 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
Future setCameraExposure(
|
Future setCameraExposure(
|
||||||
double aperture, double shutterSpeed, double sensitivity) async {
|
double aperture, double shutterSpeed, double sensitivity) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_camera_exposure(_viewer!, aperture, shutterSpeed, sensitivity);
|
_lib.set_camera_exposure(_viewer!, aperture, shutterSpeed, sensitivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future setCameraRotation(double rads, double x, double y, double z) async {
|
Future setCameraRotation(double rads, double x, double y, double z) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_camera_rotation(_viewer!, rads, x, y, z);
|
_lib.set_camera_rotation(_viewer!, rads, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future setCameraModelMatrix(List<double> matrix) async {
|
Future setCameraModelMatrix(List<double> matrix) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
assert(matrix.length == 16);
|
assert(matrix.length == 16);
|
||||||
@@ -729,7 +807,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
Future setMaterialColor(FilamentEntity asset, String meshName,
|
Future setMaterialColor(FilamentEntity asset, String meshName,
|
||||||
int materialIndex, Color color) async {
|
int materialIndex, Color color) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
var result = _lib.set_material_color(
|
var result = _lib.set_material_color(
|
||||||
@@ -747,21 +825,21 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future transformToUnitCube(FilamentEntity asset) async {
|
Future transformToUnitCube(FilamentEntity asset) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.transform_to_unit_cube(_assetManager!, asset);
|
_lib.transform_to_unit_cube(_assetManager!, asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future setPosition(FilamentEntity asset, double x, double y, double z) async {
|
Future setPosition(FilamentEntity asset, double x, double y, double z) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_position(_assetManager!, asset, x, y, z);
|
_lib.set_position(_assetManager!, asset, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future setScale(FilamentEntity asset, double scale) async {
|
Future setScale(FilamentEntity asset, double scale) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_scale(_assetManager!, asset, scale);
|
_lib.set_scale(_assetManager!, asset, scale);
|
||||||
@@ -769,14 +847,14 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
|
|
||||||
Future setRotation(
|
Future setRotation(
|
||||||
FilamentEntity asset, double rads, double x, double y, double z) async {
|
FilamentEntity asset, double rads, double x, double y, double z) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
_lib.set_rotation(_assetManager!, asset, rads, x, y, z);
|
_lib.set_rotation(_assetManager!, asset, rads, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future hide(FilamentEntity asset, String meshName) async {
|
Future hide(FilamentEntity asset, String meshName) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
if (_lib.hide_mesh(
|
if (_lib.hide_mesh(
|
||||||
@@ -785,7 +863,7 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future reveal(FilamentEntity asset, String meshName) async {
|
Future reveal(FilamentEntity asset, String meshName) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
if (_lib.reveal_mesh(
|
if (_lib.reveal_mesh(
|
||||||
@@ -804,19 +882,22 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pick(int x, int y) async {
|
void pick(int x, int y) async {
|
||||||
if (_viewer == null || _resizing) {
|
if (_viewer == null) {
|
||||||
throw Exception("No viewer available, ignoring");
|
throw Exception("No viewer available, ignoring");
|
||||||
}
|
}
|
||||||
final outPtr = calloc<EntityId>(1);
|
final outPtr = calloc<EntityId>(1);
|
||||||
outPtr.value = 0;
|
outPtr.value = 0;
|
||||||
print("height ${size.height.toInt()} y $y");
|
|
||||||
|
|
||||||
_lib.pick_ffi(_viewer!, x, size.height.toInt() - y, outPtr);
|
_lib.pick_ffi(_viewer!, x, textureDetails!.height - y, outPtr);
|
||||||
|
int wait = 0;
|
||||||
while (outPtr.value == 0) {
|
while (outPtr.value == 0) {
|
||||||
await Future.delayed(Duration(milliseconds: 100));
|
await Future.delayed(Duration(milliseconds: 50));
|
||||||
print("Waiting");
|
wait++;
|
||||||
|
if (wait > 10) {
|
||||||
|
calloc.free(outPtr);
|
||||||
|
throw Exception("Failed to get picking result");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var entityId = outPtr.value;
|
var entityId = outPtr.value;
|
||||||
_pickResultController.add(entityId);
|
_pickResultController.add(entityId);
|
||||||
calloc.free(outPtr);
|
calloc.free(outPtr);
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import 'filament_controller.dart';
|
|||||||
|
|
||||||
typedef AssetManager = int;
|
typedef AssetManager = int;
|
||||||
|
|
||||||
|
const FilamentEntity _FILAMENT_ASSET_ERROR = 0;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// This is a previous iteration of FilamentController that used platform channels for every distinct platform.
|
/// This is a previous iteration of FilamentController that used platform channels for every distinct platform.
|
||||||
/// This is no longer used; currently kept only for reference/posterity.
|
/// This is no longer used; currently kept only for reference/posterity.
|
||||||
@@ -89,7 +91,8 @@ class FilamentControllerMethodChannel extends FilamentController {
|
|||||||
/// 3) Initially, this widget will only contain an empty Container. After the first frame is rendered, the widget itself will automatically call [createViewer] with the width/height from its constraints
|
/// 3) Initially, this widget will only contain an empty Container. After the first frame is rendered, the widget itself will automatically call [createViewer] with the width/height from its constraints
|
||||||
/// 4) The FilamentWidget will replace the empty Container with the Texture widget.
|
/// 4) The FilamentWidget will replace the empty Container with the Texture widget.
|
||||||
///
|
///
|
||||||
Future createViewer(int width, int height) async {
|
Future<TextureDetails> createViewer(int width, int height) async {
|
||||||
|
throw Exception();
|
||||||
if (_viewer != null) {
|
if (_viewer != null) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"Viewer already exists, make sure you call destroyViewer first");
|
"Viewer already exists, make sure you call destroyViewer first");
|
||||||
@@ -117,7 +120,9 @@ class FilamentControllerMethodChannel extends FilamentController {
|
|||||||
|
|
||||||
bool _resizing = false;
|
bool _resizing = false;
|
||||||
|
|
||||||
Future resize(int width, int height, {double scaleFactor = 1.0}) async {
|
Future<TextureDetails> resize(int width, int height,
|
||||||
|
{double scaleFactor = 1.0}) async {
|
||||||
|
throw Exception();
|
||||||
_resizing = true;
|
_resizing = true;
|
||||||
_textureId = await _channel.invokeMethod(
|
_textureId = await _channel.invokeMethod(
|
||||||
"resize", [width * _pixelRatio, height * _pixelRatio, scaleFactor]);
|
"resize", [width * _pixelRatio, height * _pixelRatio, scaleFactor]);
|
||||||
@@ -245,7 +250,7 @@ class FilamentControllerMethodChannel extends FilamentController {
|
|||||||
}
|
}
|
||||||
var asset =
|
var asset =
|
||||||
await _channel.invokeMethod("loadGlb", [_assetManager, path, unlit]);
|
await _channel.invokeMethod("loadGlb", [_assetManager, path, unlit]);
|
||||||
if (asset == FILAMENT_ASSET_ERROR) {
|
if (asset == _FILAMENT_ASSET_ERROR) {
|
||||||
throw Exception("An error occurred loading the asset at $path");
|
throw Exception("An error occurred loading the asset at $path");
|
||||||
}
|
}
|
||||||
return asset;
|
return asset;
|
||||||
@@ -659,4 +664,22 @@ class FilamentControllerMethodChannel extends FilamentController {
|
|||||||
@override
|
@override
|
||||||
// TODO: implement pickResult
|
// TODO: implement pickResult
|
||||||
Stream<FilamentEntity?> get pickResult => throw UnimplementedError();
|
Stream<FilamentEntity?> get pickResult => throw UnimplementedError();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? getNameForEntity(FilamentEntity entity) {
|
||||||
|
// TODO: implement getNameForEntity
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
// TODO: implement textureDetails
|
||||||
|
TextureDetails? get textureDetails => throw UnimplementedError();
|
||||||
|
|
||||||
|
@override
|
||||||
|
// TODO: implement rendering
|
||||||
|
bool get rendering => throw UnimplementedError();
|
||||||
|
|
||||||
|
@override
|
||||||
|
// TODO: implement hasViewer
|
||||||
|
Stream<bool> get hasViewer => throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1434,6 +1434,20 @@ class NativeLibrary {
|
|||||||
late final _create_swap_chain_ffi = _create_swap_chain_ffiPtr.asFunction<
|
late final _create_swap_chain_ffi = _create_swap_chain_ffiPtr.asFunction<
|
||||||
void Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Void>, int, int)>();
|
void Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Void>, int, int)>();
|
||||||
|
|
||||||
|
void destroy_swap_chain_ffi(
|
||||||
|
ffi.Pointer<ffi.Void> viewer,
|
||||||
|
) {
|
||||||
|
return _destroy_swap_chain_ffi(
|
||||||
|
viewer,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
late final _destroy_swap_chain_ffiPtr =
|
||||||
|
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>(
|
||||||
|
'destroy_swap_chain_ffi');
|
||||||
|
late final _destroy_swap_chain_ffi = _destroy_swap_chain_ffiPtr
|
||||||
|
.asFunction<void Function(ffi.Pointer<ffi.Void>)>();
|
||||||
|
|
||||||
void create_render_target_ffi(
|
void create_render_target_ffi(
|
||||||
ffi.Pointer<ffi.Void> viewer,
|
ffi.Pointer<ffi.Void> viewer,
|
||||||
int nativeTextureId,
|
int nativeTextureId,
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ class _FilamentGestureDetectorMobileState
|
|||||||
}
|
}
|
||||||
|
|
||||||
Timer? _scrollTimer;
|
Timer? _scrollTimer;
|
||||||
|
double _lastScale = 0;
|
||||||
|
|
||||||
// pinch zoom on mobile
|
// pinch zoom on mobile
|
||||||
// couldn't find any equivalent for pointerCount in Listener so we use two widgets:
|
// couldn't find any equivalent for pointerCount in Listener so we use two widgets:
|
||||||
@@ -133,33 +134,26 @@ class _FilamentGestureDetectorMobileState
|
|||||||
onScaleStart: (d) async {
|
onScaleStart: (d) async {
|
||||||
if (d.pointerCount == 2) {
|
if (d.pointerCount == 2) {
|
||||||
_scaling = true;
|
_scaling = true;
|
||||||
widget.controller.zoomBegin();
|
await widget.controller.zoomBegin();
|
||||||
} else if (!_scaling) {
|
} else if (!_scaling) {
|
||||||
if (_rotateOnPointerMove) {
|
if (_rotateOnPointerMove) {
|
||||||
widget.controller
|
widget.controller.rotateStart(
|
||||||
.rotateStart(d.focalPoint.dx, d.focalPoint.dy);
|
d.localFocalPoint.dx, d.localFocalPoint.dy);
|
||||||
} else {
|
} else {
|
||||||
widget.controller
|
widget.controller
|
||||||
.panStart(d.focalPoint.dx, d.focalPoint.dy);
|
.panStart(d.localFocalPoint.dx, d.localFocalPoint.dy);
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onScaleEnd: (d) async {
|
|
||||||
if (d.pointerCount == 2) {
|
|
||||||
widget.controller.zoomEnd();
|
|
||||||
_scaling = false;
|
|
||||||
} else if (!_scaling) {
|
|
||||||
if (_rotateOnPointerMove) {
|
|
||||||
widget.controller.rotateEnd();
|
|
||||||
} else {
|
|
||||||
widget.controller.panEnd();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onScaleUpdate: (ScaleUpdateDetails d) async {
|
onScaleUpdate: (ScaleUpdateDetails d) async {
|
||||||
if (d.pointerCount == 2) {
|
if (d.pointerCount == 2) {
|
||||||
widget.controller.zoomUpdate(d.localFocalPoint.dx,
|
if (d.horizontalScale != _lastScale) {
|
||||||
d.localFocalPoint.dy, d.horizontalScale > 1 ? 0.1 : -0.1);
|
widget.controller.zoomUpdate(
|
||||||
|
d.localFocalPoint.dx,
|
||||||
|
d.localFocalPoint.dy,
|
||||||
|
d.horizontalScale > _lastScale ? 0.1 : -0.1);
|
||||||
|
_lastScale = d.horizontalScale;
|
||||||
|
}
|
||||||
} else if (!_scaling) {
|
} else if (!_scaling) {
|
||||||
if (_rotateOnPointerMove) {
|
if (_rotateOnPointerMove) {
|
||||||
widget.controller
|
widget.controller
|
||||||
@@ -170,6 +164,18 @@ class _FilamentGestureDetectorMobileState
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onScaleEnd: (d) async {
|
||||||
|
if (d.pointerCount == 2) {
|
||||||
|
widget.controller.zoomEnd();
|
||||||
|
} else if (!_scaling) {
|
||||||
|
if (_rotateOnPointerMove) {
|
||||||
|
widget.controller.rotateEnd();
|
||||||
|
} else {
|
||||||
|
widget.controller.panEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_scaling = false;
|
||||||
|
},
|
||||||
child: widget.child)),
|
child: widget.child)),
|
||||||
widget.showControlOverlay
|
widget.showControlOverlay
|
||||||
? Align(
|
? Align(
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import 'package:polyvox_filament/filament_controller.dart';
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
typedef ResizeCallback = void Function(Size oldSize, Size newSize);
|
typedef ResizeCallback = void Function(Size newSize);
|
||||||
|
|
||||||
class ResizeObserver extends SingleChildRenderObjectWidget {
|
class ResizeObserver extends SingleChildRenderObjectWidget {
|
||||||
final ResizeCallback onResized;
|
final ResizeCallback onResized;
|
||||||
@@ -36,14 +36,14 @@ class _RenderResizeObserver extends RenderProxyBox {
|
|||||||
required this.onLayoutChangedCallback,
|
required this.onLayoutChangedCallback,
|
||||||
}) : super(child);
|
}) : super(child);
|
||||||
|
|
||||||
late var _oldSize = size;
|
Size _oldSize = Size.zero;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void performLayout() {
|
void performLayout() async {
|
||||||
super.performLayout();
|
super.performLayout();
|
||||||
if (size != _oldSize) {
|
if (size.width != _oldSize.width || size.height != _oldSize.height) {
|
||||||
onLayoutChangedCallback(_oldSize, size);
|
onLayoutChangedCallback(size);
|
||||||
_oldSize = size;
|
_oldSize = Size(size.width, size.height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,73 +55,86 @@ class FilamentWidget extends StatefulWidget {
|
|||||||
/// The content to render before the texture widget is available.
|
/// The content to render before the texture widget is available.
|
||||||
/// The default is a solid red Container, intentionally chosen to make it clear that there will be at least one frame where the Texture widget is not being rendered.
|
/// The default is a solid red Container, intentionally chosen to make it clear that there will be at least one frame where the Texture widget is not being rendered.
|
||||||
///
|
///
|
||||||
late final Widget initial;
|
final Widget? initial;
|
||||||
final void Function()? onResize;
|
|
||||||
|
|
||||||
FilamentWidget(
|
const FilamentWidget({Key? key, required this.controller, this.initial})
|
||||||
{Key? key, required this.controller, this.onResize, Widget? initial})
|
: super(key: key);
|
||||||
: super(key: key) {
|
|
||||||
if (initial != null) {
|
|
||||||
this.initial = initial;
|
|
||||||
} else {
|
|
||||||
this.initial = Container(color: Colors.red);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_FilamentWidgetState createState() => _FilamentWidgetState();
|
_FilamentWidgetState createState() => _FilamentWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FilamentWidgetState extends State<FilamentWidget> {
|
class _FilamentWidgetState extends State<FilamentWidget> {
|
||||||
StreamSubscription? _textureIdListener;
|
int? _width;
|
||||||
int? _textureId;
|
int? _height;
|
||||||
bool _resizing = false;
|
|
||||||
|
|
||||||
late final AppLifecycleListener _listener;
|
|
||||||
AppLifecycleState? _lastState;
|
|
||||||
|
|
||||||
Timer? _resizeTimer;
|
|
||||||
|
|
||||||
void _handleStateChange(AppLifecycleState state) async {
|
|
||||||
switch (state) {
|
|
||||||
case AppLifecycleState.detached:
|
|
||||||
print("Detached");
|
|
||||||
_textureId = null;
|
|
||||||
|
|
||||||
await widget.controller.destroyViewer();
|
|
||||||
await widget.controller.destroyTexture();
|
|
||||||
break;
|
|
||||||
case AppLifecycleState.hidden:
|
|
||||||
print("Hidden");
|
|
||||||
if (Platform.isIOS) {
|
|
||||||
_textureId = null;
|
|
||||||
await widget.controller.destroyViewer();
|
|
||||||
await widget.controller.destroyTexture();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case AppLifecycleState.inactive:
|
|
||||||
print("Inactive");
|
|
||||||
break;
|
|
||||||
case AppLifecycleState.paused:
|
|
||||||
print("Paused");
|
|
||||||
break;
|
|
||||||
case AppLifecycleState.resumed:
|
|
||||||
print("Resumed");
|
|
||||||
if (_textureId == null) {
|
|
||||||
var size = ((context.findRenderObject()) as RenderBox).size;
|
|
||||||
print("Size after resuming : $size");
|
|
||||||
await widget.controller
|
|
||||||
.createViewer(size.width.toInt(), size.height.toInt());
|
|
||||||
print("Created viewer Size after resuming");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_lastState = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
_listener = AppLifecycleListener(
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
||||||
|
// when attaching a debugger via Android Studio on startup, this can delay presentation of the widget
|
||||||
|
// (meaning the widget may attempt to create a viewer with size 0x0).
|
||||||
|
// we just add a small delay here which should avoid this
|
||||||
|
if (!kReleaseMode) {
|
||||||
|
await Future.delayed(Duration(seconds: 2));
|
||||||
|
}
|
||||||
|
var size = ((context.findRenderObject()) as RenderBox).size;
|
||||||
|
_width = size.width.ceil();
|
||||||
|
_height = size.height.ceil();
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (_width == null || _height == null) {
|
||||||
|
return widget.initial ?? Container(color: Colors.red);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResizeObserver(
|
||||||
|
onResized: (newSize) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||||
|
setState(() {
|
||||||
|
_width = newSize.width.ceil();
|
||||||
|
_height = newSize.height.ceil();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: _SizedFilamentWidget(
|
||||||
|
initial: widget.initial,
|
||||||
|
width: _width!,
|
||||||
|
height: _height!,
|
||||||
|
controller: widget.controller,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SizedFilamentWidget extends StatefulWidget {
|
||||||
|
final int width;
|
||||||
|
final int height;
|
||||||
|
final Widget? initial;
|
||||||
|
final FilamentController controller;
|
||||||
|
|
||||||
|
const _SizedFilamentWidget(
|
||||||
|
{super.key,
|
||||||
|
required this.width,
|
||||||
|
required this.height,
|
||||||
|
this.initial,
|
||||||
|
required this.controller});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<StatefulWidget> createState() => _SizedFilamentWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SizedFilamentWidgetState extends State<_SizedFilamentWidget> {
|
||||||
|
String? _error;
|
||||||
|
|
||||||
|
late final AppLifecycleListener _appLifecycleListener;
|
||||||
|
AppLifecycleState? _lastState;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_appLifecycleListener = AppLifecycleListener(
|
||||||
onStateChange: _handleStateChange,
|
onStateChange: _handleStateChange,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -132,77 +145,144 @@ class _FilamentWidgetState extends State<FilamentWidget> {
|
|||||||
if (!kReleaseMode) {
|
if (!kReleaseMode) {
|
||||||
await Future.delayed(Duration(seconds: 2));
|
await Future.delayed(Duration(seconds: 2));
|
||||||
}
|
}
|
||||||
var size = ((context.findRenderObject()) as RenderBox).size;
|
try {
|
||||||
|
widget.controller.createViewer(widget.width, widget.height);
|
||||||
widget.controller.createViewer(size.width.toInt(), size.height.toInt());
|
} catch (err) {
|
||||||
});
|
_error = err.toString();
|
||||||
|
}
|
||||||
_textureIdListener = widget.controller.textureId.listen((int? textureId) {
|
setState(() {});
|
||||||
var size = ((context.findRenderObject()) as RenderBox).size;
|
|
||||||
print(
|
|
||||||
"Received new texture ID $textureId at size $size (current textureID $_textureId)");
|
|
||||||
setState(() {
|
|
||||||
_textureId = textureId;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timer? _resizeTimer;
|
||||||
|
bool _resizing = false;
|
||||||
|
|
||||||
|
Future _resize() {
|
||||||
|
final completer = Completer();
|
||||||
|
// resizing the window can be sluggish (particular in debug mode), exacerbated when simultaneously recreating the swapchain and resize the window.
|
||||||
|
// to address this, whenever the widget is resized, we set a timer for Xms in the future.
|
||||||
|
// this timer will call [resize] with the widget size at that point in time.
|
||||||
|
// any subsequent widget resizes will cancel the timer and replace with a new one.
|
||||||
|
// debug mode does need a longer timeout.
|
||||||
|
_resizeTimer?.cancel();
|
||||||
|
|
||||||
|
_resizeTimer =
|
||||||
|
Timer(const Duration(milliseconds: kReleaseMode ? 20 : 100), () async {
|
||||||
|
if (!mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var size = ((context.findRenderObject()) as RenderBox).size;
|
||||||
|
var width = size.width.ceil();
|
||||||
|
var height = size.height.ceil();
|
||||||
|
while (_resizing) {
|
||||||
|
await Future.delayed(Duration(milliseconds: 20));
|
||||||
|
}
|
||||||
|
_resizing = true;
|
||||||
|
await widget.controller.resize(width, height);
|
||||||
|
_resizeTimer = null;
|
||||||
|
setState(() {});
|
||||||
|
_resizing = false;
|
||||||
|
completer.complete();
|
||||||
|
});
|
||||||
|
return completer.future;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(_SizedFilamentWidget oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
|
||||||
|
if (oldWidget.height != widget.height || oldWidget.width != widget.width) {
|
||||||
|
_resize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_textureIdListener?.cancel();
|
_appLifecycleListener.dispose();
|
||||||
_listener.dispose();
|
|
||||||
_resizeTimer?.cancel();
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _wasRenderingOnInactive = false;
|
||||||
|
|
||||||
|
void _handleStateChange(AppLifecycleState state) async {
|
||||||
|
switch (state) {
|
||||||
|
case AppLifecycleState.detached:
|
||||||
|
print("Detached");
|
||||||
|
if (!_wasRenderingOnInactive) {
|
||||||
|
_wasRenderingOnInactive = widget.controller.rendering;
|
||||||
|
}
|
||||||
|
await widget.controller.setRendering(false);
|
||||||
|
break;
|
||||||
|
case AppLifecycleState.hidden:
|
||||||
|
print("Hidden");
|
||||||
|
if (!_wasRenderingOnInactive) {
|
||||||
|
_wasRenderingOnInactive = widget.controller.rendering;
|
||||||
|
}
|
||||||
|
await widget.controller.setRendering(false);
|
||||||
|
break;
|
||||||
|
case AppLifecycleState.inactive:
|
||||||
|
print("Inactive");
|
||||||
|
if (!_wasRenderingOnInactive) {
|
||||||
|
_wasRenderingOnInactive = widget.controller.rendering;
|
||||||
|
}
|
||||||
|
// on Windows in particular, restoring a window after minimizing stalls the renderer (and the whole application) for a considerable length of time.
|
||||||
|
// disabling rendering on minimize seems to fix the issue (so I wonder if there's some kind of command buffer that's filling up while the window is minimized).
|
||||||
|
await widget.controller.setRendering(false);
|
||||||
|
break;
|
||||||
|
case AppLifecycleState.paused:
|
||||||
|
print("Paused");
|
||||||
|
if (!_wasRenderingOnInactive) {
|
||||||
|
_wasRenderingOnInactive = widget.controller.rendering;
|
||||||
|
}
|
||||||
|
await widget.controller.setRendering(false);
|
||||||
|
break;
|
||||||
|
case AppLifecycleState.resumed:
|
||||||
|
print("Resumed");
|
||||||
|
await widget.controller.setRendering(_wasRenderingOnInactive);
|
||||||
|
await _resize();
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_lastState = state;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return LayoutBuilder(builder: ((context, constraints) {
|
// if an error was encountered in creating a viewer, display the error message and don't even try to display a Texture widget.
|
||||||
if (_textureId == null) {
|
if (_error != null) {
|
||||||
return widget.initial;
|
return Container(
|
||||||
}
|
color: Colors.white,
|
||||||
var texture = Texture(
|
child: Column(children: [
|
||||||
key: ObjectKey("texture_$_textureId"),
|
const Text("A fatal error was encountered"),
|
||||||
textureId: _textureId!,
|
Text(_error!)
|
||||||
filterQuality: FilterQuality.none,
|
]));
|
||||||
);
|
}
|
||||||
return SizedBox(
|
|
||||||
height: constraints.maxHeight,
|
|
||||||
width: constraints.maxWidth,
|
|
||||||
child: ResizeObserver(
|
|
||||||
onResized: (Size oldSize, Size newSize) async {
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
||||||
if (!_resizing) {
|
|
||||||
setState(() {
|
|
||||||
_resizing = true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
_resizeTimer?.cancel();
|
if (widget.controller.textureDetails == null || _resizeTimer != null) {
|
||||||
|
return widget.initial ?? Container(color: Colors.red);
|
||||||
|
}
|
||||||
|
// see [FilamentControllerFFI.resize] for an explanation of how we deal with resizing
|
||||||
|
var texture = Texture(
|
||||||
|
key: ObjectKey("texture_${widget.controller.textureDetails!.textureId}"),
|
||||||
|
textureId: widget.controller.textureDetails!.textureId,
|
||||||
|
filterQuality: FilterQuality.none,
|
||||||
|
freeze: false,
|
||||||
|
);
|
||||||
|
|
||||||
_resizeTimer = Timer(Duration(milliseconds: 500), () async {
|
return Stack(children: [
|
||||||
await widget.controller
|
Positioned.fill(
|
||||||
.resize(newSize.width.toInt(), newSize.height.toInt());
|
child: Platform.isLinux || Platform.isWindows
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
? Transform(
|
||||||
setState(() {
|
alignment: Alignment.center,
|
||||||
_resizing = false;
|
transform: Matrix4.rotationX(
|
||||||
widget.onResize?.call();
|
pi), // TODO - this rotation is due to OpenGL texture coordinate working in a different space from Flutter, can we move this to the C++ side somewhere?
|
||||||
});
|
child: texture)
|
||||||
});
|
: texture)
|
||||||
});
|
]);
|
||||||
});
|
|
||||||
},
|
|
||||||
child: _resizing
|
|
||||||
? Container()
|
|
||||||
: Platform.isLinux || Platform.isWindows
|
|
||||||
? Transform(
|
|
||||||
alignment: Alignment.center,
|
|
||||||
transform: Matrix4.rotationX(
|
|
||||||
pi), // TODO - this rotation is due to OpenGL texture coordinate working in a different space from Flutter, can we move this to the C++ side somewhere?
|
|
||||||
child: texture)
|
|
||||||
: texture));
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
self.flutterTextureId = nil
|
self.flutterTextureId = nil
|
||||||
self.pixelBuffer = nil
|
self.pixelBuffer = nil
|
||||||
self.metalTexture = nil
|
self.metalTexture = nil
|
||||||
|
result(true)
|
||||||
case "resize":
|
case "resize":
|
||||||
let args = call.arguments as! [Any]
|
let args = call.arguments as! [Any]
|
||||||
let width = UInt32(args[0] as! Int64)
|
let width = UInt32(args[0] as! Int64)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ typedef void (*FilamentRenderCallback)(void* const owner);
|
|||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void* const create_filament_viewer_ffi(void* const context, void* const platform, const char* uberArchivePath, const ResourceLoaderWrapper* const loader, void (*renderCallback)(void* const renderCallbackOwner), void* const renderCallbackOwner);
|
FLUTTER_PLUGIN_EXPORT void* const create_filament_viewer_ffi(void* const context, void* const platform, const char* uberArchivePath, const ResourceLoaderWrapper* const loader, void (*renderCallback)(void* const renderCallbackOwner), void* const renderCallbackOwner);
|
||||||
FLUTTER_PLUGIN_EXPORT void create_swap_chain_ffi(void* const viewer, void* const surface, uint32_t width, uint32_t height);
|
FLUTTER_PLUGIN_EXPORT void create_swap_chain_ffi(void* const viewer, void* const surface, uint32_t width, uint32_t height);
|
||||||
|
FLUTTER_PLUGIN_EXPORT void destroy_swap_chain_ffi(void* const viewer);
|
||||||
FLUTTER_PLUGIN_EXPORT void create_render_target_ffi(void* const viewer, intptr_t nativeTextureId, uint32_t width, uint32_t height);
|
FLUTTER_PLUGIN_EXPORT void create_render_target_ffi(void* const viewer, intptr_t nativeTextureId, uint32_t width, uint32_t height);
|
||||||
FLUTTER_PLUGIN_EXPORT void destroy_filament_viewer_ffi(void* const viewer);
|
FLUTTER_PLUGIN_EXPORT void destroy_filament_viewer_ffi(void* const viewer);
|
||||||
FLUTTER_PLUGIN_EXPORT void render_ffi(void* const viewer);
|
FLUTTER_PLUGIN_EXPORT void render_ffi(void* const viewer);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ A new Flutter plugin project.
|
|||||||
|
|
||||||
s.pod_target_xcconfig = {
|
s.pod_target_xcconfig = {
|
||||||
'DEFINES_MODULE' => 'YES',
|
'DEFINES_MODULE' => 'YES',
|
||||||
'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386',
|
'EXCLUDED_ARCHS' => 'x86_64',
|
||||||
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
|
||||||
'OTHER_CXXFLAGS' => '"--std=c++17" "-fmodules" "-fcxx-modules" "-fvisibility=default" "$(inherited)"',
|
'OTHER_CXXFLAGS' => '"--std=c++17" "-fmodules" "-fcxx-modules" "-fvisibility=default" "$(inherited)"',
|
||||||
'OTHER_CFLAGS' => '"-fvisibility=default" "$(inherited)"',
|
'OTHER_CFLAGS' => '"-fvisibility=default" "$(inherited)"',
|
||||||
|
|||||||
@@ -1155,10 +1155,6 @@ namespace polyvox
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Log("Updating grab at %f %f", x, y);
|
|
||||||
|
|
||||||
|
|
||||||
if (_manipulator)
|
if (_manipulator)
|
||||||
{
|
{
|
||||||
_manipulator->grabUpdate(x, y);
|
_manipulator->grabUpdate(x, y);
|
||||||
|
|||||||
@@ -72,7 +72,12 @@ public:
|
|||||||
|
|
||||||
void setRendering(bool rendering)
|
void setRendering(bool rendering)
|
||||||
{
|
{
|
||||||
_rendering = rendering;
|
std::packaged_task<void()> lambda([&]() mutable
|
||||||
|
{
|
||||||
|
this->_rendering = rendering;
|
||||||
|
});
|
||||||
|
auto fut = add_task(lambda);
|
||||||
|
fut.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
void doRender()
|
void doRender()
|
||||||
@@ -143,6 +148,17 @@ extern "C"
|
|||||||
fut.wait();
|
fut.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FLUTTER_PLUGIN_EXPORT void destroy_swap_chain_ffi(void* const viewer)
|
||||||
|
{
|
||||||
|
Log("Destroying swapchain");
|
||||||
|
std::packaged_task<void()> lambda([&]() mutable
|
||||||
|
{
|
||||||
|
destroy_swap_chain(viewer);
|
||||||
|
});
|
||||||
|
auto fut = _rl->add_task(lambda);
|
||||||
|
fut.wait();
|
||||||
|
}
|
||||||
|
|
||||||
FLUTTER_PLUGIN_EXPORT void create_render_target_ffi(void* const viewer, intptr_t nativeTextureId, uint32_t width, uint32_t height)
|
FLUTTER_PLUGIN_EXPORT void create_render_target_ffi(void* const viewer, intptr_t nativeTextureId, uint32_t width, uint32_t height)
|
||||||
{
|
{
|
||||||
std::packaged_task<void()> lambda([&]() mutable
|
std::packaged_task<void()> lambda([&]() mutable
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
name: polyvox_filament
|
name: polyvox_filament
|
||||||
description: A Flutter plugin to wrap the Filament rendering engine.
|
description: A Flutter plugin to wrap the Filament rendering engine.
|
||||||
version: 0.0.1
|
version: 0.5.0
|
||||||
homepage:
|
homepage:
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=3.0.0 <3.11.0"
|
sdk: ">=3.0.0 <4.0.0"
|
||||||
flutter: ">=1.20.0"
|
flutter: ">=3.16.0-0.2.pre"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ set(PLUGIN_NAME "polyvox_filament_plugin")
|
|||||||
list(APPEND PLUGIN_SOURCES
|
list(APPEND PLUGIN_SOURCES
|
||||||
"polyvox_filament_plugin.cpp"
|
"polyvox_filament_plugin.cpp"
|
||||||
"polyvox_filament_plugin.h"
|
"polyvox_filament_plugin.h"
|
||||||
|
"opengl_texture_buffer.cpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../ios/src/AssetManager.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../ios/src/AssetManager.cpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../ios/src/FilamentViewer.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../ios/src/FilamentViewer.cpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../ios/src/PolyvoxFilamentApi.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../ios/src/PolyvoxFilamentApi.cpp"
|
||||||
@@ -69,8 +70,8 @@ if(USE_ANGLE)
|
|||||||
else()
|
else()
|
||||||
list(APPEND GL_LIBS
|
list(APPEND GL_LIBS
|
||||||
bluegl
|
bluegl
|
||||||
bluevk
|
# bluevk
|
||||||
vkshaders
|
# vkshaders
|
||||||
opengl32
|
opengl32
|
||||||
)
|
)
|
||||||
set(ANGLE_OR_OPENGL_DIR opengl)
|
set(ANGLE_OR_OPENGL_DIR opengl)
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:1a92c10991b982967746b267ba90e0e4e766dc41f2648232fece244c35981981
|
oid sha256:3827c9ad4d7849dd1266e317976fbea04a9c754594ece7d604e48b76d07e120b
|
||||||
size 54897670
|
size 20577924
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:5afb9555f719e7b7c60313b158b43c0464f122d09ed81e072b2a13db5d67e049
|
oid sha256:f032b3bda4d738d935e56dd89b10001480ce0146e0ffd94add2e79d7f76087d5
|
||||||
size 2066946
|
size 1706380
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:13b87d4eefacd3e4136d368697279c0e9c60da4ed2fb8dd5ce3490be1874ca8d
|
oid sha256:ce9d22143ce3d4cf6a680fde8a7f6ddfd8edeb18c0a8c38c3843915cdc8060a8
|
||||||
size 155917302
|
size 152979336
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:8aec12bdd40d4ac62d0d1ee3d7bd84b5719cf117e68acc0b75cbc85cb335970e
|
oid sha256:fb6214dcbfc505987921d21289934fa44d4e42e1e5e24aa243a61688d8f644b5
|
||||||
size 8271488
|
size 3615830
|
||||||
|
|||||||
3
windows/lib/Release/opengl/backend.lib
Normal file
3
windows/lib/Release/opengl/backend.lib
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:db7c2105955776ca6a946dc28b02114e1b670a2272cded6d9ae575f9390cb3d0
|
||||||
|
size 4430582
|
||||||
3
windows/lib/Release/opengl/backend.pdb
Normal file
3
windows/lib/Release/opengl/backend.pdb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:bf0190be5237c7cda21fb5b23462a4eca37149eb7d3ec27158a9692a7f4f7fe0
|
||||||
|
size 2797568
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:d8594c1993f55db256e67202d987e8940765312f5e90ae827182670b0deb0970
|
oid sha256:af44e04c48df8675168d9d4976faa569868f25fc0995a7854947bd64db00f294
|
||||||
size 2237062
|
size 1876560
|
||||||
|
|||||||
3
windows/lib/Release/opengl/bluegl.pdb
Normal file
3
windows/lib/Release/opengl/bluegl.pdb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:a0549e15af4181cfba098f6f2efc168f77373fb3d51c5a0068953ed41280c3e3
|
||||||
|
size 708608
|
||||||
3
windows/lib/Release/opengl/filament.lib
Normal file
3
windows/lib/Release/opengl/filament.lib
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:45ede612fb0dfe8a94c21818ab71947e1d3f5ebdfde086b4d5f6bd2520266c3d
|
||||||
|
size 27931534
|
||||||
3
windows/lib/Release/opengl/filament.pdb
Normal file
3
windows/lib/Release/opengl/filament.pdb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:26767b8aaac06dddbef4094cd55bcf4dc0477945a90a56ce1df21fcc6ca4f760
|
||||||
|
size 8581120
|
||||||
3
windows/lib/Release/opengl/uberarchive.lib
Normal file
3
windows/lib/Release/opengl/uberarchive.lib
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:3c40dbb6b83ba05cfb04426c1f20af992e5a446a9637325bca7b6237d70807af
|
||||||
|
size 61906
|
||||||
3
windows/lib/Release/opengl/uberarchive.pdb
Normal file
3
windows/lib/Release/opengl/uberarchive.pdb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:2cecdf0be05ee31b1768a21415d09910127d84a33e7f3379de8f3ff044153846
|
||||||
|
size 69632
|
||||||
131
windows/opengl_texture_buffer.cpp
Normal file
131
windows/opengl_texture_buffer.cpp
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
#include "opengl_texture_buffer.h"
|
||||||
|
|
||||||
|
#include <flutter/method_channel.h>
|
||||||
|
#include <flutter/plugin_registrar_windows.h>
|
||||||
|
#include <flutter/standard_method_codec.h>
|
||||||
|
#include <flutter/texture_registrar.h>
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
namespace polyvox_filament {
|
||||||
|
|
||||||
|
void _release_callback(void *releaseContext) {
|
||||||
|
// ((OpenGLTextureBuffer*)releaseContext)->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenGLTextureBuffer::OpenGLTextureBuffer(
|
||||||
|
flutter::PluginRegistrarWindows *pluginRegistrar,
|
||||||
|
flutter::TextureRegistrar *textureRegistrar,
|
||||||
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result,
|
||||||
|
uint32_t width, uint32_t height, HGLRC context,
|
||||||
|
std::shared_ptr<std::mutex> renderMutex)
|
||||||
|
: _pluginRegistrar(pluginRegistrar), _textureRegistrar(textureRegistrar),
|
||||||
|
_width(width), _height(height), _context(context),
|
||||||
|
_renderMutex(renderMutex) {
|
||||||
|
|
||||||
|
HWND hwnd = _pluginRegistrar->GetView()->GetNativeWindow();
|
||||||
|
|
||||||
|
HDC whdc = GetDC(hwnd);
|
||||||
|
|
||||||
|
if (!_context || !wglMakeCurrent(whdc, _context)) {
|
||||||
|
result->Error("ERROR", "Failed to switch OpenGL context in constructor.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenTextures(1, &glTextureId);
|
||||||
|
|
||||||
|
if (glTextureId == 0) {
|
||||||
|
result->Error("ERROR", "Failed to generate texture, OpenGL err was %d",
|
||||||
|
glGetError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, glTextureId);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, _width, _height, 0, GL_RGBA,
|
||||||
|
GL_UNSIGNED_BYTE, 0);
|
||||||
|
|
||||||
|
GLenum err = glGetError();
|
||||||
|
|
||||||
|
if (err != GL_NO_ERROR) {
|
||||||
|
result->Error("ERROR", "Failed to generate texture, GL error was %d", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wglMakeCurrent(NULL, NULL);
|
||||||
|
|
||||||
|
pixelBuffer = std::make_unique<FlutterDesktopPixelBuffer>();
|
||||||
|
pixelData.reset(new uint8_t[_width * _height * 4]);
|
||||||
|
|
||||||
|
pixelBuffer->buffer = pixelData.get();
|
||||||
|
pixelBuffer->width = size_t(_width);
|
||||||
|
pixelBuffer->height = size_t(_height);
|
||||||
|
pixelBuffer->release_callback = _release_callback;
|
||||||
|
pixelBuffer->release_context = this;
|
||||||
|
|
||||||
|
std::cout << "Created initial pixel data/buffer of size " << _width << "x"
|
||||||
|
<< _height << std::endl;
|
||||||
|
|
||||||
|
texture =
|
||||||
|
std::make_unique<flutter::TextureVariant>(flutter::PixelBufferTexture(
|
||||||
|
[=](size_t width,
|
||||||
|
size_t height) -> const FlutterDesktopPixelBuffer * {
|
||||||
|
|
||||||
|
if (width != this->_width || height != this->_height) {
|
||||||
|
if(!this->logged) {
|
||||||
|
std::cout << "Front-end widget expects " << width << "x" << height << " but this is " << this->_width << "x" << this->_height
|
||||||
|
<< std::endl;
|
||||||
|
this->logged = true;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
uint8_t *data = (uint8_t *)pixelData.get();
|
||||||
|
|
||||||
|
if (!_context || !wglMakeCurrent(whdc, _context)) {
|
||||||
|
std::cout << "Failed to switch OpenGL context in callback."
|
||||||
|
<< std::endl;
|
||||||
|
} else {
|
||||||
|
// It seems there's at least 1 frame delay between resizing a
|
||||||
|
// front-end widget and the layout operation being performed on
|
||||||
|
// Windows. I haven't found a way to guarantee that we can resize
|
||||||
|
// the OpenGL texture before the pixel buffer callback here. (If
|
||||||
|
// you can find/suggest a way, please let me know). This means we
|
||||||
|
// need to manually check that the requested size matches the
|
||||||
|
// current size of our GL texture, and return an empty pixel
|
||||||
|
// buffer if not.
|
||||||
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||||
|
|
||||||
|
GLenum err = glGetError();
|
||||||
|
|
||||||
|
if (err != GL_NO_ERROR) {
|
||||||
|
if (err == GL_INVALID_OPERATION) {
|
||||||
|
std::cout << "Invalid op" << std::endl;
|
||||||
|
} else if (err == GL_INVALID_VALUE) {
|
||||||
|
std::cout << "Invalid value" << std::endl;
|
||||||
|
} else if (err == GL_OUT_OF_MEMORY) {
|
||||||
|
std::cout << "Out of mem" << std::endl;
|
||||||
|
} else if (err == GL_INVALID_ENUM) {
|
||||||
|
std::cout << "Invalid enum" << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "Unknown error" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wglMakeCurrent(NULL, NULL);
|
||||||
|
}
|
||||||
|
pixelBuffer->buffer = pixelData.get();
|
||||||
|
return pixelBuffer.get();
|
||||||
|
}));
|
||||||
|
|
||||||
|
flutterTextureId = textureRegistrar->RegisterTexture(texture.get());
|
||||||
|
std::cout << "Registered Flutter texture ID " << flutterTextureId
|
||||||
|
<< std::endl;
|
||||||
|
std::vector<flutter::EncodableValue> resultList;
|
||||||
|
resultList.push_back(flutter::EncodableValue(flutterTextureId));
|
||||||
|
resultList.push_back(flutter::EncodableValue((int64_t) nullptr));
|
||||||
|
resultList.push_back(flutter::EncodableValue(glTextureId));
|
||||||
|
result->Success(resultList);
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenGLTextureBuffer::~OpenGLTextureBuffer() {}
|
||||||
|
|
||||||
|
} // namespace polyvox_filament
|
||||||
53
windows/opengl_texture_buffer.h
Normal file
53
windows/opengl_texture_buffer.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef _OPENGL_TEXTURE_BUFFER_H
|
||||||
|
#define _OPENGL_TEXTURE_BUFFER_H
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#include <flutter/texture_registrar.h>
|
||||||
|
#include <flutter/method_channel.h>
|
||||||
|
#include <flutter/plugin_registrar_windows.h>
|
||||||
|
|
||||||
|
#include "GL/GL.h"
|
||||||
|
#include "GL/GLu.h"
|
||||||
|
#include "GL/wglext.h"
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <wrl.h>
|
||||||
|
|
||||||
|
typedef uint32_t GLuint;
|
||||||
|
|
||||||
|
namespace polyvox_filament {
|
||||||
|
|
||||||
|
class OpenGLTextureBuffer {
|
||||||
|
public:
|
||||||
|
|
||||||
|
OpenGLTextureBuffer(
|
||||||
|
flutter::PluginRegistrarWindows* pluginRegistrar,
|
||||||
|
flutter::TextureRegistrar* textureRegistrar,
|
||||||
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result,
|
||||||
|
uint32_t width,
|
||||||
|
uint32_t height,
|
||||||
|
HGLRC context,
|
||||||
|
std::shared_ptr<std::mutex> renderMutex);
|
||||||
|
|
||||||
|
~OpenGLTextureBuffer();
|
||||||
|
GLuint glTextureId = 0;
|
||||||
|
int64_t flutterTextureId = 0;
|
||||||
|
std::unique_ptr<FlutterDesktopPixelBuffer> pixelBuffer;
|
||||||
|
std::unique_ptr<uint8_t> pixelData;
|
||||||
|
std::unique_ptr<flutter::TextureVariant> texture;
|
||||||
|
|
||||||
|
private:
|
||||||
|
flutter::PluginRegistrarWindows* _pluginRegistrar;
|
||||||
|
flutter::TextureRegistrar* _textureRegistrar;
|
||||||
|
uint32_t _width = 0;
|
||||||
|
uint32_t _height = 0;
|
||||||
|
HGLRC _context = NULL;
|
||||||
|
bool logged = false;
|
||||||
|
std::shared_ptr<std::mutex> _renderMutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // _OPENGL_TEXTURE_BUFFER_H
|
||||||
@@ -33,10 +33,6 @@
|
|||||||
#include "PlatformANGLE.h"
|
#include "PlatformANGLE.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "GL/GL.h"
|
|
||||||
#include "GL/GLu.h"
|
|
||||||
#include "GL/wglext.h"
|
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <wrl.h>
|
#include <wrl.h>
|
||||||
|
|
||||||
@@ -83,7 +79,7 @@ ResourceBuffer PolyvoxFilamentPlugin::loadResource(const char *name) {
|
|||||||
name_str = name_str.substr(8);
|
name_str = name_str.substr(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
TCHAR pBuf[256];
|
TCHAR pBuf[512];
|
||||||
size_t len = sizeof(pBuf);
|
size_t len = sizeof(pBuf);
|
||||||
int bytes = GetModuleFileName(NULL, pBuf, len);
|
int bytes = GetModuleFileName(NULL, pBuf, len);
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||||
@@ -145,7 +141,10 @@ void PolyvoxFilamentPlugin::RenderCallback() {
|
|||||||
_internalD3DTexture2D.Get());
|
_internalD3DTexture2D.Get());
|
||||||
_D3D11DeviceContext->Flush();
|
_D3D11DeviceContext->Flush();
|
||||||
#endif
|
#endif
|
||||||
_textureRegistrar->MarkTextureFrameAvailable(_flutterTextureId);
|
std::lock_guard<std::mutex> guard(*(_renderMutex.get()));
|
||||||
|
if (_active) {
|
||||||
|
_textureRegistrar->MarkTextureFrameAvailable(_active->flutterTextureId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_ANGLE
|
#ifdef USE_ANGLE
|
||||||
@@ -293,8 +292,9 @@ bool PolyvoxFilamentPlugin::MakeD3DTexture(uint32_t width, uint32_t height,std::
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
bool PolyvoxFilamentPlugin::MakeOpenGLTexture(uint32_t width, uint32_t height,std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
bool PolyvoxFilamentPlugin::MakeOpenGLTexture(uint32_t width, uint32_t height,std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
||||||
|
|
||||||
HWND hwnd = _pluginRegistrar->GetView()
|
HWND hwnd = _pluginRegistrar->GetView()
|
||||||
->GetNativeWindow();;
|
->GetNativeWindow();
|
||||||
|
|
||||||
HDC whdc = GetDC(hwnd);
|
HDC whdc = GetDC(hwnd);
|
||||||
if (whdc == NULL) {
|
if (whdc == NULL) {
|
||||||
@@ -302,145 +302,99 @@ bool PolyvoxFilamentPlugin::MakeOpenGLTexture(uint32_t width, uint32_t height,st
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PIXELFORMATDESCRIPTOR pfd = {
|
if(!_renderMutex.get()) {
|
||||||
sizeof(PIXELFORMATDESCRIPTOR),
|
_renderMutex = std::make_shared<std::mutex>();
|
||||||
1,
|
}
|
||||||
PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, // Flags
|
|
||||||
PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette.
|
|
||||||
32, // Colordepth of the framebuffer.
|
|
||||||
0, 0, 0, 0, 0, 0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0, 0, 0, 0,
|
|
||||||
32, // Number of bits for the depthbuffer
|
|
||||||
0, // Number of bits for the stencilbuffer
|
|
||||||
0, // Number of Aux buffers in the framebuffer.
|
|
||||||
PFD_MAIN_PLANE,
|
|
||||||
0,
|
|
||||||
0, 0, 0
|
|
||||||
};
|
|
||||||
|
|
||||||
int pixelFormat = ChoosePixelFormat(whdc, &pfd);
|
|
||||||
SetPixelFormat(whdc, pixelFormat, &pfd);
|
|
||||||
|
|
||||||
// We need a tmp context to retrieve and call wglCreateContextAttribsARB.
|
// we need a single context (since this will be passed to the renderer)
|
||||||
HGLRC tempContext = wglCreateContext(whdc);
|
// if this is the first time we are attempting to create a texture, let's create the context
|
||||||
if (!wglMakeCurrent(whdc, tempContext)) {
|
if(_context == NULL) {
|
||||||
result->Error("ERROR", "Failed to acquire temporary context", nullptr);
|
|
||||||
|
std::cout << "No GL context exists, creating" << std::endl;
|
||||||
|
|
||||||
|
PIXELFORMATDESCRIPTOR pfd = {
|
||||||
|
sizeof(PIXELFORMATDESCRIPTOR),
|
||||||
|
1,
|
||||||
|
PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, // Flags
|
||||||
|
PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette.
|
||||||
|
32, // Colordepth of the framebuffer.
|
||||||
|
0, 0, 0, 0, 0, 0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0, 0, 0, 0,
|
||||||
|
32, // Number of bits for the depthbuffer
|
||||||
|
0, // Number of bits for the stencilbuffer
|
||||||
|
0, // Number of Aux buffers in the framebuffer.
|
||||||
|
PFD_MAIN_PLANE,
|
||||||
|
0,
|
||||||
|
0, 0, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
int pixelFormat = ChoosePixelFormat(whdc, &pfd);
|
||||||
|
SetPixelFormat(whdc, pixelFormat, &pfd);
|
||||||
|
|
||||||
|
// We need a tmp context to retrieve and call wglCreateContextAttribsARB.
|
||||||
|
HGLRC tempContext = wglCreateContext(whdc);
|
||||||
|
if (!wglMakeCurrent(whdc, tempContext)) {
|
||||||
|
result->Error("ERROR", "Failed to acquire temporary context", nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
GLenum err = glGetError();
|
||||||
|
|
||||||
|
if(err != GL_NO_ERROR) {
|
||||||
|
result->Error("ERROR", "GL Error @ 455 %d", err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr;
|
||||||
|
|
||||||
|
wglCreateContextAttribs =
|
||||||
|
(PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress(
|
||||||
|
"wglCreateContextAttribsARB");
|
||||||
|
|
||||||
|
if (!wglCreateContextAttribs) {
|
||||||
|
result->Error("ERROR", "Failed to resolve wglCreateContextAttribsARB",
|
||||||
|
nullptr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int minor = 5; minor >= 1; minor--) {
|
||||||
|
std::vector<int> mAttribs = {WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
|
||||||
|
WGL_CONTEXT_MINOR_VERSION_ARB, minor, 0};
|
||||||
|
_context = wglCreateContextAttribs(whdc, nullptr, mAttribs.data());
|
||||||
|
if (_context) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wglMakeCurrent(NULL, NULL);
|
||||||
|
wglDeleteContext(tempContext);
|
||||||
|
|
||||||
|
if (!_context || !wglMakeCurrent(whdc, _context)) {
|
||||||
|
result->Error("ERROR", "Failed to create OpenGL context.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_active.get()) {
|
||||||
|
result->Error("ERROR", "Texture already exists. You must call destroyTexture before attempting to create a new one.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLenum err = glGetError();
|
_active = std::make_unique<OpenGLTextureBuffer>(
|
||||||
|
_pluginRegistrar,
|
||||||
if(err != GL_NO_ERROR) {
|
_textureRegistrar,
|
||||||
result->Error("ERROR", "GL Error @ 455 %d", err);
|
std::move(result),
|
||||||
return false;
|
width,
|
||||||
}
|
height,
|
||||||
|
_context,
|
||||||
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr;
|
_renderMutex
|
||||||
|
);
|
||||||
wglCreateContextAttribs =
|
|
||||||
(PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress(
|
return _active->flutterTextureId != -1;
|
||||||
"wglCreateContextAttribsARB");
|
|
||||||
|
|
||||||
if (!wglCreateContextAttribs) {
|
|
||||||
result->Error("ERROR", "Failed to resolve wglCreateContextAttribsARB",
|
|
||||||
nullptr);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int minor = 5; minor >= 1; minor--) {
|
|
||||||
std::vector<int> mAttribs = {WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
|
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB, minor, 0};
|
|
||||||
_context = wglCreateContextAttribs(whdc, nullptr, mAttribs.data());
|
|
||||||
if (_context) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wglMakeCurrent(NULL, NULL);
|
|
||||||
wglDeleteContext(tempContext);
|
|
||||||
|
|
||||||
|
|
||||||
if (!_context || !wglMakeCurrent(whdc, _context)) {
|
|
||||||
result->Error("ERROR", "Failed to create OpenGL context.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
glGenTextures(1, &_glTextureId);
|
|
||||||
|
|
||||||
if(_glTextureId == 0) {
|
|
||||||
result->Error("ERROR", "Failed to generate texture, OpenGL err was %d", glGetError());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, _glTextureId);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA,
|
|
||||||
GL_UNSIGNED_BYTE, 0);
|
|
||||||
|
|
||||||
err = glGetError();
|
|
||||||
|
|
||||||
if (err != GL_NO_ERROR) {
|
|
||||||
result->Error("ERROR", "Failed to generate texture, GL error was %d", err);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
wglMakeCurrent(NULL, NULL);
|
|
||||||
|
|
||||||
_pixelData.reset(new uint8_t[width * height * 4]);
|
|
||||||
_pixelBuffer = std::make_unique<FlutterDesktopPixelBuffer>();
|
|
||||||
_pixelBuffer->buffer = _pixelData.get();
|
|
||||||
|
|
||||||
_pixelBuffer->width = size_t(width);
|
|
||||||
_pixelBuffer->height = size_t(height);
|
|
||||||
|
|
||||||
_texture = std::make_unique<flutter::TextureVariant>(flutter::PixelBufferTexture(
|
|
||||||
[=](size_t width,
|
|
||||||
size_t height) -> const FlutterDesktopPixelBuffer * {
|
|
||||||
std::lock_guard<std::mutex> guard(_renderMutex);
|
|
||||||
|
|
||||||
if(!_context || !wglMakeCurrent(whdc, _context)) {
|
|
||||||
std::cout << "Failed to switch OpenGL context." << std::endl;
|
|
||||||
} else {
|
|
||||||
uint8_t* data = new uint8_t[width*height*4];
|
|
||||||
glBindTexture(GL_TEXTURE_2D, _glTextureId);
|
|
||||||
glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_UNSIGNED_BYTE,data);
|
|
||||||
|
|
||||||
GLenum err = glGetError();
|
|
||||||
|
|
||||||
if(err != GL_NO_ERROR) {
|
|
||||||
if(err == GL_INVALID_OPERATION) {
|
|
||||||
std::cout << "Invalid op" << std::endl;
|
|
||||||
} else if(err == GL_INVALID_VALUE) {
|
|
||||||
std::cout << "Invalid value" << std::endl;
|
|
||||||
} else if(err == GL_OUT_OF_MEMORY) {
|
|
||||||
std::cout << "Out of mem" << std::endl;
|
|
||||||
} else if(err == GL_INVALID_ENUM ) {
|
|
||||||
std::cout << "Invalid enum" << std::endl;
|
|
||||||
} else {
|
|
||||||
std::cout << "Unknown error" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glFinish();
|
|
||||||
_pixelData.reset(data);
|
|
||||||
wglMakeCurrent(NULL, NULL);
|
|
||||||
}
|
|
||||||
_pixelBuffer->buffer = _pixelData.get();
|
|
||||||
|
|
||||||
return _pixelBuffer.get();
|
|
||||||
}));
|
|
||||||
|
|
||||||
_flutterTextureId = _textureRegistrar->RegisterTexture(_texture.get());
|
|
||||||
std::cout << "Registered Flutter texture ID " << _flutterTextureId << std::endl;
|
|
||||||
|
|
||||||
std::vector<flutter::EncodableValue> resultList;
|
|
||||||
resultList.push_back(flutter::EncodableValue(_flutterTextureId));
|
|
||||||
resultList.push_back(flutter::EncodableValue((int64_t)nullptr));
|
|
||||||
resultList.push_back(flutter::EncodableValue(_glTextureId));
|
|
||||||
result->Success(resultList);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -449,7 +403,7 @@ void PolyvoxFilamentPlugin::CreateTexture(
|
|||||||
const flutter::MethodCall<flutter::EncodableValue> &methodCall,
|
const flutter::MethodCall<flutter::EncodableValue> &methodCall,
|
||||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
||||||
|
|
||||||
const auto *args =
|
const auto *args =
|
||||||
std::get_if<flutter::EncodableList>(methodCall.arguments());
|
std::get_if<flutter::EncodableList>(methodCall.arguments());
|
||||||
|
|
||||||
const auto width = (uint32_t)round(*(std::get_if<double>(&(args->at(0)))));
|
const auto width = (uint32_t)round(*(std::get_if<double>(&(args->at(0)))));
|
||||||
@@ -462,6 +416,60 @@ void PolyvoxFilamentPlugin::CreateTexture(
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PolyvoxFilamentPlugin::DestroyTexture(
|
||||||
|
const flutter::MethodCall<flutter::EncodableValue> &methodCall,
|
||||||
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
||||||
|
|
||||||
|
const auto *flutterTextureId =
|
||||||
|
std::get_if<int64_t>(methodCall.arguments());
|
||||||
|
|
||||||
|
if(!flutterTextureId) {
|
||||||
|
result->Error("NOT_IMPLEMENTED", "Flutter texture ID must be provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef USE_ANGLE
|
||||||
|
// TODO
|
||||||
|
result->Error("NOT_IMPLEMENTED", "Method is not implemented %s", methodCall.method_name());
|
||||||
|
#else
|
||||||
|
auto sh = std::make_shared<std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>>>(std::move(result));
|
||||||
|
|
||||||
|
if(!_active) {
|
||||||
|
result->Success("Texture has already been detroyed, ignoring");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_active->flutterTextureId != *flutterTextureId) {
|
||||||
|
result->Error("TEXTURE_MISMATCH", "Specified texture ID is not active");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_textureRegistrar->UnregisterTexture(_active->flutterTextureId, [=,
|
||||||
|
sharedResult=std::move(sh)
|
||||||
|
]() {
|
||||||
|
|
||||||
|
if(this->_inactive) {
|
||||||
|
|
||||||
|
HWND hwnd = _pluginRegistrar->GetView()->GetNativeWindow();
|
||||||
|
|
||||||
|
HDC whdc = GetDC(hwnd);
|
||||||
|
|
||||||
|
if (!wglMakeCurrent(whdc, _context)) {
|
||||||
|
std::cout << "Failed to switch OpenGL context in destructor." << std::endl;
|
||||||
|
// result->Error("CONTEXT", "Failed to switch OpenGL context.", nullptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
glDeleteTextures(1, &this->_inactive->glTextureId);
|
||||||
|
wglMakeCurrent(NULL, NULL);
|
||||||
|
}
|
||||||
|
this->_inactive = std::move(this->_active);
|
||||||
|
auto unique = std::move(*(sharedResult.get()));
|
||||||
|
unique->Success(flutter::EncodableValue(true));
|
||||||
|
std::cout << "Destroyed OpenGLTextureBuffer." << std::endl;
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void PolyvoxFilamentPlugin::HandleMethodCall(
|
void PolyvoxFilamentPlugin::HandleMethodCall(
|
||||||
const flutter::MethodCall<flutter::EncodableValue> &methodCall,
|
const flutter::MethodCall<flutter::EncodableValue> &methodCall,
|
||||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
||||||
@@ -479,6 +487,8 @@ void PolyvoxFilamentPlugin::HandleMethodCall(
|
|||||||
result->Success(flutter::EncodableValue((int64_t)resourceLoader));
|
result->Success(flutter::EncodableValue((int64_t)resourceLoader));
|
||||||
} else if (methodCall.method_name() == "createTexture") {
|
} else if (methodCall.method_name() == "createTexture") {
|
||||||
CreateTexture(methodCall, std::move(result));
|
CreateTexture(methodCall, std::move(result));
|
||||||
|
} else if (methodCall.method_name() == "destroyTexture") {
|
||||||
|
DestroyTexture(methodCall, std::move(result));
|
||||||
} else if(methodCall.method_name() == "getRenderCallback") {
|
} else if(methodCall.method_name() == "getRenderCallback") {
|
||||||
flutter::EncodableList resultList;
|
flutter::EncodableList resultList;
|
||||||
resultList.push_back(flutter::EncodableValue((int64_t)&render_callback));
|
resultList.push_back(flutter::EncodableValue((int64_t)&render_callback));
|
||||||
@@ -490,8 +500,7 @@ void PolyvoxFilamentPlugin::HandleMethodCall(
|
|||||||
#else
|
#else
|
||||||
result->Success(flutter::EncodableValue((int64_t)nullptr));
|
result->Success(flutter::EncodableValue((int64_t)nullptr));
|
||||||
#endif
|
#endif
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
result->Error("NOT_IMPLEMENTED", "Method is not implemented %s", methodCall.method_name());
|
result->Error("NOT_IMPLEMENTED", "Method is not implemented %s", methodCall.method_name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
#include "GLES2/gl2.h"
|
#include "GLES2/gl2.h"
|
||||||
#include "GLES2/gl2ext.h"
|
#include "GLES2/gl2ext.h"
|
||||||
#include "PlatformAngle.h"
|
#include "PlatformAngle.h"
|
||||||
|
#else
|
||||||
|
#include "opengl_texture_buffer.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "PolyvoxFilamentApi.h"
|
#include "PolyvoxFilamentApi.h"
|
||||||
@@ -54,15 +56,8 @@ public:
|
|||||||
|
|
||||||
std::map<uint32_t, ResourceBuffer> _resources;
|
std::map<uint32_t, ResourceBuffer> _resources;
|
||||||
|
|
||||||
std::unique_ptr<flutter::TextureVariant> _texture = nullptr;
|
|
||||||
|
|
||||||
std::unique_ptr<FlutterDesktopPixelBuffer> _pixelBuffer = nullptr;
|
|
||||||
std::unique_ptr<uint8_t> _pixelData = nullptr;
|
|
||||||
|
|
||||||
std::unique_ptr<FlutterDesktopGpuSurfaceDescriptor> _textureDescriptor = nullptr;
|
std::unique_ptr<FlutterDesktopGpuSurfaceDescriptor> _textureDescriptor = nullptr;
|
||||||
|
|
||||||
int64_t _flutterTextureId;
|
|
||||||
|
|
||||||
#ifdef USE_ANGLE
|
#ifdef USE_ANGLE
|
||||||
// Device
|
// Device
|
||||||
ID3D11Device* _D3D11Device = nullptr;
|
ID3D11Device* _D3D11Device = nullptr;
|
||||||
@@ -75,19 +70,22 @@ public:
|
|||||||
filament::backend::PlatformANGLE* _platform = nullptr;
|
filament::backend::PlatformANGLE* _platform = nullptr;
|
||||||
|
|
||||||
bool MakeD3DTexture(uint32_t width, uint32_t height, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
bool MakeD3DTexture(uint32_t width, uint32_t height, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||||
#else
|
#else
|
||||||
// OpenGL
|
std::shared_ptr<std::mutex> _renderMutex;
|
||||||
HGLRC _context = NULL;
|
std::unique_ptr<OpenGLTextureBuffer> _active = nullptr;
|
||||||
GLuint _glTextureId = 0;
|
std::unique_ptr<OpenGLTextureBuffer> _inactive = nullptr;
|
||||||
std::mutex _renderMutex;
|
|
||||||
|
|
||||||
|
// shared OpenGLContext
|
||||||
|
HGLRC _context = NULL;
|
||||||
bool MakeOpenGLTexture(uint32_t width, uint32_t height, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
bool MakeOpenGLTexture(uint32_t width, uint32_t height, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void CreateTexture(
|
void CreateTexture(
|
||||||
const flutter::MethodCall<flutter::EncodableValue> &methodCall,
|
const flutter::MethodCall<flutter::EncodableValue> &methodCall,
|
||||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||||
|
void DestroyTexture(
|
||||||
|
const flutter::MethodCall<flutter::EncodableValue> &methodCall,
|
||||||
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||||
void RenderCallback();
|
void RenderCallback();
|
||||||
|
|
||||||
ResourceBuffer loadResource(const char *path);
|
ResourceBuffer loadResource(const char *path);
|
||||||
|
|||||||
Reference in New Issue
Block a user