refactoring
This commit is contained in:
@@ -111,6 +111,8 @@ abstract class MaterialInstance {
|
||||
Future setParameterFloat3Array(String name, List<Vector3> data);
|
||||
Future setParameterFloat4(
|
||||
String name, double x, double y, double z, double w);
|
||||
Future setParameterMat4(
|
||||
String name, Matrix4 matrix);
|
||||
|
||||
Future setParameterInt(String name, int value);
|
||||
Future setParameterBool(String name, bool value);
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import 'dart:math';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import '../../../thermion_dart.dart';
|
||||
|
||||
class GeometryHelper {
|
||||
static Geometry fullscreenQuad() {
|
||||
final vertices = Float32List.fromList(
|
||||
[-1.0, -1.0, 1.0, 1.0, 3.0, -1.0, 1.0, 1.0, -1.0, 3.0, 1.0, 1.0]);
|
||||
[-1.0, -1.0, 1.0, 3.0, -1.0, 1.0, -1.0, 3.0, 1.0]);
|
||||
final indices = [0, 1, 2];
|
||||
return Geometry(vertices, indices);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class BackgroundImage extends ThermionAsset {
|
||||
|
||||
Future destroy() async {
|
||||
Scene_removeEntity(scene.scene, entity);
|
||||
|
||||
|
||||
await texture!.dispose();
|
||||
await sampler!.dispose();
|
||||
await mi.destroy();
|
||||
@@ -40,6 +40,9 @@ class BackgroundImage extends ThermionAsset {
|
||||
|
||||
var backgroundImage =
|
||||
await viewer.createGeometry(GeometryHelper.fullscreenQuad());
|
||||
await imageMaterialInstance.setParameterInt("showImage", 0);
|
||||
await imageMaterialInstance.setParameterMat4("transform", Matrix4.identity());
|
||||
|
||||
backgroundImage.setMaterialInstanceAt(imageMaterialInstance);
|
||||
await scene.add(backgroundImage as FFIAsset);
|
||||
return BackgroundImage._(
|
||||
@@ -61,7 +64,6 @@ class BackgroundImage extends ThermionAsset {
|
||||
|
||||
await mi.setParameterTexture(
|
||||
"image", texture as FFITexture, sampler as FFITextureSampler);
|
||||
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
@@ -13,6 +13,17 @@ void using(Pointer ptr, Future Function(Pointer ptr) function) async {
|
||||
allocator.free(ptr);
|
||||
}
|
||||
|
||||
Future<void> withVoidCallback2(Function() func) async {
|
||||
final completer = Completer();
|
||||
void Function() callback = () {
|
||||
func.call();
|
||||
completer.complete();
|
||||
};
|
||||
final nativeCallable = NativeCallable<Void Function()>.listener(callback);
|
||||
await completer.future;
|
||||
nativeCallable.close();
|
||||
}
|
||||
|
||||
Future<void> withVoidCallback(
|
||||
Function(Pointer<NativeFunction<Void Function()>>) func) async {
|
||||
final completer = Completer();
|
||||
@@ -27,8 +38,7 @@ Future<void> withVoidCallback(
|
||||
}
|
||||
|
||||
Future<Pointer<T>> withPointerCallback<T extends NativeType>(
|
||||
Function(Pointer<NativeFunction<Void Function(Pointer<T>)>>)
|
||||
func) async {
|
||||
Function(Pointer<NativeFunction<Void Function(Pointer<T>)>>) func) async {
|
||||
final completer = Completer<Pointer<T>>();
|
||||
// ignore: prefer_function_declarations_over_variables
|
||||
void Function(Pointer<NativeType>) callback = (Pointer<NativeType> ptr) {
|
||||
@@ -101,4 +111,3 @@ Future<String> withCharPtrCallback(
|
||||
nativeCallable.close();
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
|
||||
@@ -563,6 +563,13 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
await withBoolCallback((cb) {
|
||||
Renderer_beginFrameRenderThread(renderer, swapChain!.swapChain, 0, cb);
|
||||
});
|
||||
await withVoidCallback((cb) {
|
||||
Renderer_renderRenderThread(
|
||||
renderer,
|
||||
view.view,
|
||||
cb,
|
||||
);
|
||||
});
|
||||
await withVoidCallback((cb) {
|
||||
Renderer_readPixelsRenderThread(
|
||||
renderer,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/callbacks.dart';
|
||||
@@ -192,4 +193,16 @@ class FFIMaterialInstance extends MaterialInstance {
|
||||
MaterialInstance_setParameterBool(
|
||||
pointer, name.toNativeUtf8().cast<Char>(), value);
|
||||
}
|
||||
|
||||
@override
|
||||
Future setParameterMat4(String name, Matrix4 matrix) async {
|
||||
final completer = Completer();
|
||||
final func = () {
|
||||
MaterialInstance_setParameterMat4(pointer, name.toNativeUtf8().cast<Char>(), matrix.storage.address);
|
||||
completer.complete();
|
||||
};
|
||||
final nativeCallable = NativeCallable<Void Function()>.listener(func);
|
||||
RenderLoop_addTask(nativeCallable.nativeFunction);
|
||||
await completer.future;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,15 @@ external void MaterialInstance_setParameterFloat4(
|
||||
double z,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<TMaterialInstance>, ffi.Pointer<ffi.Char>,
|
||||
ffi.Pointer<ffi.Double>)>(isLeaf: true)
|
||||
external void MaterialInstance_setParameterMat4(
|
||||
ffi.Pointer<TMaterialInstance> materialInstance,
|
||||
ffi.Pointer<ffi.Char> propertyName,
|
||||
ffi.Pointer<ffi.Double> matrix,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<TMaterialInstance>, ffi.Pointer<ffi.Char>,
|
||||
ffi.Int)>(isLeaf: true)
|
||||
@@ -1511,6 +1520,13 @@ external void RenderTicker_renderRenderThread(
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
external void RenderLoop_addTask(
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> task,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<TEngine>,
|
||||
|
||||
Reference in New Issue
Block a user