add getTargetNames method

This commit is contained in:
Nick Fisher
2021-09-21 10:55:46 +08:00
parent 952794fdf3
commit a167d38984
15 changed files with 200 additions and 215 deletions

View File

@@ -1,12 +1,13 @@
import 'dart:async';
import 'package:flutter/services.dart';
abstract class FilamentController {
void onFilamentViewCreated(int id);
Future initialize({String? materialPath});
Future loadSkybox(String skyboxPath, String lightingPath);
Future loadGlb(String path);
Future loadGltf(
String path, String relativeResourcePath, String materialInstanceName);
Future loadGltf(String path, String relativeResourcePath);
Future panStart(double x, double y);
Future panUpdate(double x, double y);
Future panEnd();
@@ -14,6 +15,10 @@ abstract class FilamentController {
Future rotateUpdate(double x, double y);
Future rotateEnd();
Future applyWeights(List<double> weights, int primitiveIndex);
Future<List<String>> getTargetNames(String meshName);
void animate(
List<List<double>> weights, int primitiveIndex, double frameRate);
Future createMorpher(String meshName, String entityName,
{String? materialName});
Future zoom(double z);
@@ -22,15 +27,27 @@ abstract class FilamentController {
class MimeticFilamentController extends FilamentController {
late int _id;
late MethodChannel _channel;
final String materialPath;
MimeticFilamentController(
{this.materialPath = "packages/mimetic_filament/assets/compiled.mat"});
@override
void onFilamentViewCreated(int id) async {
_id = id;
_channel = MethodChannel("mimetic.app/filament_view_$id");
_channel.setMethodCallHandler((call) async {
await Future.delayed(Duration(
seconds:
1)); // todo - need a better way to know when the GL context is actaully ready
await _initialize();
return Future.value(true);
});
}
@override
Future initialize({String? materialPath}) async {
Future _initialize() async {
print("Initializing");
await _channel.invokeMethod("initialize", materialPath);
}
@@ -43,10 +60,10 @@ class MimeticFilamentController extends FilamentController {
throw Exception();
}
Future loadGltf(String path, String relativeResourcePath,
String materialInstanceName) async {
await _channel.invokeMethod(
"loadGltf", [path, relativeResourcePath, materialInstanceName]);
Future loadGltf(String path, String relativeResourcePath) async {
print(
"Loading GLTF at $path with relative resource path $relativeResourcePath");
await _channel.invokeMethod("loadGltf", [path, relativeResourcePath]);
}
Future panStart(double x, double y) async {
@@ -77,6 +94,26 @@ class MimeticFilamentController extends FilamentController {
await _channel.invokeMethod("applyWeights", [weights, primitiveIndex]);
}
Future<List<String>> getTargetNames(String meshName) async {
var result = (await _channel.invokeMethod("getTargetNames", meshName))
.cast<String>();
return result;
}
void animate(
List<List<double>> weights, int primitiveIndex, double frameRate) async {
final msPerFrame = 1000 ~/ frameRate;
int i = 0;
Timer.periodic(Duration(milliseconds: msPerFrame), (t) async {
_channel.invokeMethod("applyWeights", [weights[i], primitiveIndex]);
i++;
if (i >= weights.length) {
t.cancel();
}
});
}
Future zoom(double z) async {
await _channel.invokeMethod("zoom", z);
}

View File

@@ -1,13 +0,0 @@
import 'dart:async';
import 'package:flutter/services.dart';
class MimeticFilament {
static const MethodChannel _channel = MethodChannel('mimetic_filament');
static Future<String?> get platformVersion async {
final String? version = await _channel.invokeMethod('getPlatformVersion');
return version;
}
}

View File

@@ -1,19 +0,0 @@
// You have generated a new plugin project without
// specifying the `--platforms` flag. A plugin project supports no platforms is generated.
// To add platforms, run `flutter create -t plugin --platforms <platforms> .` under the same
// directory. You can also find a detailed instruction on how to add platforms in the `pubspec.yaml` at https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms.
import 'dart:async';
import 'package:flutter/services.dart';
class MimeticFilamentPlugin {
static const MethodChannel _channel = MethodChannel('mimetic_filament');
static Future<String?> get platformVersion async {
final String? version = await _channel.invokeMethod('getPlatformVersion');
return version;
}
static void initialize() {}
}