This commit is contained in:
Nick Fisher
2023-04-18 14:17:05 +08:00
parent 67ac8990b8
commit 8298e473c2
13 changed files with 431 additions and 175 deletions

View File

@@ -1,12 +1,12 @@
import 'dart:async';
import 'dart:typed_data';
import 'dart:ui';
import 'package:flutter/services.dart';
import 'animations/animation_builder.dart';
import 'animations/animations.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
// this is confusing - "FilamentAsset" actually defines a pointer to a SceneAsset, whereas FilamentLight is an Entity ID.
// should make this consistent
typedef FilamentAsset = int;
@@ -26,11 +26,12 @@ abstract class FilamentController {
void setPixelRatio(double ratio);
Future resize(int width, int height, {double contentScaleFactor = 1});
Future setBackgroundColor(Color color);
Future clearBackgroundImage();
Future setBackgroundImage(String path);
Future setBackgroundImagePosition(double x, double y, {bool clamp = false});
Future loadSkybox(String skyboxPath);
Future removeSkybox();
Future loadIbl(String path);
Future loadIbl(String path, {double intensity = 30000});
Future removeIbl();
// copied from LightManager.h
@@ -54,7 +55,7 @@ abstract class FilamentController {
bool castShadows);
Future removeLight(FilamentLight light);
Future clearLights();
Future<FilamentAsset> loadGlb(String path);
Future<FilamentAsset> loadGlb(String path, {bool unlit = false});
Future<FilamentAsset> loadGltf(String path, String relativeResourcePath);
Future zoomBegin();
Future zoomUpdate(double z);
@@ -172,6 +173,11 @@ class PolyvoxFilamentController extends FilamentController {
_textureIdController.add(_textureId);
}
@override
Future clearBackgroundImage() async {
await _channel.invokeMethod("clearBackgroundImage");
}
@override
Future setBackgroundImage(String path) async {
await _channel.invokeMethod("setBackgroundImage", path);
@@ -179,15 +185,12 @@ class PolyvoxFilamentController extends FilamentController {
@override
Future setBackgroundColor(Color color) async {
print(
"setting to ${color.red.toDouble() / 255.0} ${color.blue.toDouble() / 255.0} ${color.red.toDouble() / 255.0}");
await _channel.invokeMethod(
"setBackgroundColor",
Float32List.fromList([
color.red.toDouble() / 255.0,
color.green.toDouble() / 255.0,
color.blue.toDouble() / 255.0
]));
await _channel.invokeMethod("setBackgroundColor", [
color.red.toDouble() / 255.0,
color.green.toDouble() / 255.0,
color.blue.toDouble() / 255.0,
color.alpha.toDouble() / 255.0
]);
}
@override
@@ -253,9 +256,9 @@ class PolyvoxFilamentController extends FilamentController {
return _channel.invokeMethod("clearLights");
}
Future<FilamentAsset> loadGlb(String path) async {
Future<FilamentAsset> loadGlb(String path, {bool unlit = false}) async {
print("Loading GLB at $path ");
var asset = await _channel.invokeMethod("loadGlb", path);
var asset = await _channel.invokeMethod("loadGlb", [path, unlit]);
if (asset == FILAMENT_ASSET_ERROR) {
throw Exception("An error occurred loading the asset at $path");
}

View File

@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
@@ -35,6 +36,7 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
};
bool _rotating = false;
bool _scaling = false;
// to avoid duplicating code for pan/rotate (panStart, panUpdate, panEnd, rotateStart, rotateUpdate etc)
// we have only a single function for start/update/end.
@@ -100,6 +102,8 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
onScaleStart: !widget.enableControls
? null
: (d) async {
_scaling = true;
print("SCALE START");
if (d.pointerCount == 2) {
await widget.controller.zoomEnd();
await widget.controller.zoomBegin();
@@ -108,6 +112,7 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
onScaleEnd: !widget.enableControls
? null
: (d) async {
_scaling = false;
if (d.pointerCount == 2) {
_lastScale = 0;
await widget.controller.zoomEnd();
@@ -118,8 +123,9 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
: (d) async {
if (d.pointerCount == 2) {
if (_lastScale != 0) {
await widget.controller
.zoomUpdate(100 * (_lastScale - d.scale));
await widget.controller.zoomUpdate(Platform.isIOS
? 1000 * (_lastScale - d.scale)
: 100 * (_lastScale - d.scale));
}
}
_lastScale = d.scale;
@@ -128,6 +134,8 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
onPointerSignal: !widget.enableControls
? null
: (pointerSignal) async {
print("ponter signal");
// scroll-wheel zoom on desktop
if (pointerSignal is PointerScrollEvent) {
_scrollTimer?.cancel();
@@ -146,6 +154,7 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
onPointerDown: !widget.enableControls
? null
: (d) async {
print("piinterodoiwn");
if (d.buttons == kTertiaryButton || _rotating) {
await widget.controller.rotateStart(
d.localPosition.dx, d.localPosition.dy);
@@ -157,6 +166,7 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
onPointerMove: !widget.enableControls
? null
: (d) async {
print("pointermove");
if (d.buttons == kTertiaryButton || _rotating) {
await widget.controller.rotateUpdate(
d.localPosition.dx, d.localPosition.dy);
@@ -168,6 +178,7 @@ class _FilamentGestureDetectorState extends State<FilamentGestureDetector> {
onPointerUp: !widget.enableControls
? null
: (d) async {
print("pointerup");
if (d.buttons == kTertiaryButton || _rotating) {
await widget.controller.rotateEnd();
} else {