update example project

This commit is contained in:
Nick Fisher
2023-11-03 17:28:25 +08:00
parent 58a9542121
commit f5cc7a8174
11 changed files with 732 additions and 372 deletions

View File

@@ -1,3 +1,5 @@
// ignore_for_file: constant_identifier_names
import 'dart:async';
import 'dart:ui' as ui;
import 'package:flutter/widgets.dart';
@@ -5,10 +7,14 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_filament/animations/animation_data.dart';
import 'package:vector_math/vector_math_64.dart';
// a handle that can be safely passed back to the rendering layer to manipulate an Entity
typedef FilamentEntity = int;
enum ToneMapper { ACES, FILMIC, LINEAR }
// see filament Manipulator.h for more details
enum ManipulatorMode { ORBIT, MAP, FREE_FLIGHT }
class TextureDetails {
final int textureId;
@@ -27,6 +33,13 @@ abstract class FilamentController {
///
ValueNotifier<Rect?> get rect;
///
/// A [ValueNotifier] to indicate whether a FilamentViewer is currently available.
/// (FilamentViewer is a C++ type, hence why it is not referenced) here.
/// Call [createViewer]/[destroyViewer] to create/destroy a FilamentViewer.
///
ValueNotifier<bool> get hasViewer;
///
/// Whether a Flutter Texture widget should be inserted into the widget hierarchy.
/// This will be false on certain platforms where we use a transparent window underlay.
@@ -424,4 +437,13 @@ abstract class FilamentController {
/// Retrieves the name assigned to the given FilamentEntity (usually corresponds to the glTF mesh name).
///
String? getNameForEntity(FilamentEntity entity);
///
/// Sets the options for manipulating the camera via the viewport.
///
Future setCameraManipulatorOptions(
{ManipulatorMode mode = ManipulatorMode.FREE_FLIGHT,
double orbitSpeedX = 0.01,
double orbitSpeedY = 0.01,
double zoomSpeed = 0.01});
}

View File

@@ -39,6 +39,9 @@ class FilamentControllerFFI extends FilamentController {
@override
final rect = ValueNotifier<Rect?>(null);
@override
final hasViewer = ValueNotifier<bool>(false);
@override
Stream<FilamentEntity> get pickResult => _pickResultController.stream;
final _pickResultController = StreamController<FilamentEntity>.broadcast();
@@ -135,6 +138,7 @@ class FilamentControllerFFI extends FilamentController {
_assetManager = null;
_lib.destroy_filament_viewer_ffi(viewer!);
hasViewer.value = false;
}
@override
@@ -217,6 +221,7 @@ class FilamentControllerFFI extends FilamentController {
print("texture details ${textureDetails.value}");
_lib.update_viewport_and_camera_projection_ffi(
_viewer!, rect.value!.width.toInt(), rect.value!.height.toInt(), 1.0);
hasViewer.value = true;
}
Future<RenderingSurface> _createRenderingSurface() async {
@@ -1024,4 +1029,17 @@ class FilamentControllerFFI extends FilamentController {
calloc.free(arrayPtr);
return rotationMatrix;
}
@override
Future setCameraManipulatorOptions(
{ManipulatorMode mode = ManipulatorMode.FREE_FLIGHT,
double orbitSpeedX = 0.01,
double orbitSpeedY = 0.01,
double zoomSpeed = 0.01}) async {
if (_viewer == null) {
throw Exception("No viewer available");
}
_lib.set_camera_manipulator_options(
_viewer!, mode.index, orbitSpeedX, orbitSpeedX, zoomSpeed);
}
}

View File

@@ -1322,22 +1322,29 @@ class NativeLibrary {
late final _set_camera_focus_distance = _set_camera_focus_distancePtr
.asFunction<void Function(ffi.Pointer<ffi.Void>, double)>();
void set_camera_manipulator_mode(
void set_camera_manipulator_options(
ffi.Pointer<ffi.Void> viewer,
int mode,
double orbitSpeedX,
double orbitSpeedY,
double zoomSpeed,
) {
return _set_camera_manipulator_mode(
return _set_camera_manipulator_options(
viewer,
mode,
orbitSpeedX,
orbitSpeedY,
zoomSpeed,
);
}
late final _set_camera_manipulator_modePtr = _lookup<
late final _set_camera_manipulator_optionsPtr = _lookup<
ffi.NativeFunction<
ffi.Void Function(ffi.Pointer<ffi.Void>,
ManipulatorMode)>>('set_camera_manipulator_mode');
late final _set_camera_manipulator_mode = _set_camera_manipulator_modePtr
.asFunction<void Function(ffi.Pointer<ffi.Void>, int)>();
ffi.Void Function(ffi.Pointer<ffi.Void>, _ManipulatorMode, ffi.Double,
ffi.Double, ffi.Double)>>('set_camera_manipulator_options');
late final _set_camera_manipulator_options =
_set_camera_manipulator_optionsPtr.asFunction<
void Function(ffi.Pointer<ffi.Void>, int, double, double, double)>();
int hide_mesh(
ffi.Pointer<ffi.Void> assetManager,
@@ -2456,7 +2463,7 @@ typedef FreeFilamentResourceFromOwner = ffi.Pointer<
/// This header replicates most of the methods in FlutterFilamentApi.h, and is only intended to be used to generate client FFI bindings.
/// The intention is that calling one of these methods will call its respective method in FlutterFilamentApi.h, but wrapped in some kind of thread runner to ensure thread safety.
typedef EntityId = ffi.Int32;
typedef ManipulatorMode = ffi.Int32;
typedef _ManipulatorMode = ffi.Int32;
typedef FilamentRenderCallback = ffi.Pointer<
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void> owner)>>;