refactoring
This commit is contained in:
@@ -5,7 +5,7 @@ import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_filament_app.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/thermion_dart.g.dart';
|
||||
import 'package:thermion_dart/src/filament/src/layers.dart';
|
||||
import 'package:thermion_dart/thermion_dart.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import '../../../../utils/src/matrix.dart';
|
||||
|
||||
class FFICamera extends Camera {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:thermion_dart/src/filament/src/engine.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/callbacks.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_material.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_render_target.dart';
|
||||
@@ -14,12 +15,12 @@ typedef RenderCallback = Pointer<NativeFunction<Void Function(Pointer<Void>)>>;
|
||||
|
||||
class FFIFilamentConfig extends FilamentConfig<RenderCallback, Pointer<Void>> {
|
||||
FFIFilamentConfig(
|
||||
{required super.backend,
|
||||
required super.resourceLoader,
|
||||
required super.driver,
|
||||
required super.platform,
|
||||
required super.sharedContext,
|
||||
required super.uberArchivePath});
|
||||
{required super.resourceLoader,
|
||||
super.backend = Backend.DEFAULT,
|
||||
super.driver = null,
|
||||
super.platform = null,
|
||||
super.sharedContext = null,
|
||||
super.uberArchivePath = null});
|
||||
}
|
||||
|
||||
class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
@@ -55,7 +56,8 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
renderableManager: renderableManager,
|
||||
ubershaderMaterialProvider: ubershaderMaterialProvider) {}
|
||||
|
||||
static Future create(FFIFilamentConfig config) async {
|
||||
static Future create({FFIFilamentConfig? config}) async {
|
||||
config ??= FFIFilamentConfig(resourceLoader: nullptr);
|
||||
if (FilamentApp.instance != null) {
|
||||
await FilamentApp.instance!.destroy();
|
||||
}
|
||||
@@ -65,7 +67,7 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
|
||||
final engine = await withPointerCallback<TEngine>((cb) =>
|
||||
Engine_createRenderThread(
|
||||
TBackend.values[config.backend.index].index,
|
||||
TBackend.values[config!.backend.index].index,
|
||||
config.platform ?? nullptr,
|
||||
config.sharedContext ?? nullptr,
|
||||
config.stereoscopicEyeCount,
|
||||
@@ -79,15 +81,13 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
final renderer = await withPointerCallback<TRenderer>(
|
||||
(cb) => Engine_createRendererRenderThread(engine, cb));
|
||||
final ubershaderMaterialProvider =
|
||||
await withPointerCallback<TMaterialProvider>(
|
||||
(cb) => GltfAssetLoader_getMaterialProvider(gltfAssetLoader));
|
||||
GltfAssetLoader_getMaterialProvider(gltfAssetLoader);
|
||||
|
||||
final transformManager = Engine_getTransformManager(engine);
|
||||
final lightManager = Engine_getLightManager(engine);
|
||||
final renderableManager = Engine_getRenderableManager(engine);
|
||||
|
||||
final renderTicker = await withPointerCallback<TRenderTicker>(
|
||||
(cb) => RenderTicker_create(renderer));
|
||||
final renderTicker = RenderTicker_create(renderer);
|
||||
|
||||
final nameComponentManager = NameComponentManager_create();
|
||||
|
||||
@@ -210,7 +210,8 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
TextureSamplerType textureSamplerType = TextureSamplerType.SAMPLER_2D,
|
||||
TextureFormat textureFormat = TextureFormat.RGBA16F,
|
||||
int? importedTextureHandle}) async {
|
||||
var bitmask = flags.fold(0, (a, b) => a | b.index);
|
||||
var bitmask = flags.fold(0, (a, b) => a | b.value);
|
||||
print("bitmask $bitmask");
|
||||
final texturePtr = await withPointerCallback<TTexture>((cb) {
|
||||
Texture_buildRenderThread(
|
||||
engine,
|
||||
@@ -218,8 +219,8 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
height,
|
||||
depth,
|
||||
levels,
|
||||
importedTextureHandle ?? 0,
|
||||
bitmask,
|
||||
importedTextureHandle ?? 0,
|
||||
TTextureSamplerType.values[textureSamplerType.index],
|
||||
TTextureFormat.values[textureFormat.index],
|
||||
cb);
|
||||
@@ -404,7 +405,7 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
|
||||
FFIMaterial? _gridMaterial;
|
||||
Future<FFIMaterial> get gridMaterial async {
|
||||
_gridMaterial ??= FFIMaterial(Material_createGridMaterial(), this);
|
||||
_gridMaterial ??= FFIMaterial(Material_createGridMaterial(engine), this);
|
||||
return _gridMaterial!;
|
||||
}
|
||||
|
||||
@@ -425,8 +426,8 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
///
|
||||
@override
|
||||
Future render() async {
|
||||
await withVoidCallback((cb) =>
|
||||
RenderTicker_renderRenderThread(renderTicker, 0, cb));
|
||||
await withVoidCallback(
|
||||
(cb) => RenderTicker_renderRenderThread(renderTicker, 0, cb));
|
||||
}
|
||||
|
||||
///
|
||||
@@ -436,6 +437,10 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
Future register(
|
||||
covariant FFISwapChain swapChain, covariant FFIView view) async {
|
||||
_viewMappings[view] = swapChain;
|
||||
if (!_views.containsKey(swapChain)) {
|
||||
_views[swapChain] = [];
|
||||
}
|
||||
_views[swapChain]!.add(view);
|
||||
}
|
||||
|
||||
final _hooks = <Future Function()>[];
|
||||
@@ -531,9 +536,12 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
|
||||
Material? _imageMaterial;
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
@override
|
||||
Future<MaterialInstance> createImageMaterialInstance() async {
|
||||
_imageMaterial ??= FFIMaterial(Material_createImageMaterial(),
|
||||
_imageMaterial ??= FFIMaterial(Material_createImageMaterial(engine),
|
||||
FilamentApp.instance! as FFIFilamentApp);
|
||||
var instance =
|
||||
await _imageMaterial!.createInstance() as FFIMaterialInstance;
|
||||
|
||||
@@ -4,7 +4,6 @@ import 'package:thermion_dart/src/viewer/src/ffi/src/callbacks.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_filament_app.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_texture.dart';
|
||||
import 'package:thermion_dart/thermion_dart.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
class FFIMaterial extends Material {
|
||||
final FFIFilamentApp app;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/callbacks.dart';
|
||||
import 'package:thermion_dart/thermion_dart.dart';
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ class FFIView extends View {
|
||||
}
|
||||
|
||||
Future setScene(covariant FFIScene scene) async {
|
||||
await withVoidCallback((cb) => View_setScene(view, scene.scene));
|
||||
View_setScene(view, scene.scene);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -25,11 +25,15 @@ external ffi.Pointer<TMaterialInstance> Material_createInstance(
|
||||
ffi.Pointer<TMaterial> tMaterial,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Pointer<TMaterial> Function()>(isLeaf: true)
|
||||
external ffi.Pointer<TMaterial> Material_createImageMaterial();
|
||||
@ffi.Native<ffi.Pointer<TMaterial> Function(ffi.Pointer<TEngine>)>(isLeaf: true)
|
||||
external ffi.Pointer<TMaterial> Material_createImageMaterial(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Pointer<TMaterial> Function()>(isLeaf: true)
|
||||
external ffi.Pointer<TMaterial> Material_createGridMaterial();
|
||||
@ffi.Native<ffi.Pointer<TMaterial> Function(ffi.Pointer<TEngine>)>(isLeaf: true)
|
||||
external ffi.Pointer<TMaterial> Material_createGridMaterial(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Bool Function(ffi.Pointer<TMaterial>, ffi.Pointer<ffi.Char>)>(
|
||||
isLeaf: true)
|
||||
@@ -1491,9 +1495,11 @@ external void RenderLoop_create();
|
||||
@ffi.Native<ffi.Void Function()>(isLeaf: true)
|
||||
external void RenderLoop_destroy();
|
||||
|
||||
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(isLeaf: true)
|
||||
@ffi.Native<
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
external void RenderLoop_requestAnimationFrame(
|
||||
ffi.Pointer<ffi.Void> onComplete,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
@@ -3847,7 +3853,7 @@ enum TGizmoType {
|
||||
};
|
||||
}
|
||||
|
||||
sealed class TPrimitiveType {
|
||||
abstract class TPrimitiveType {
|
||||
/// !< points
|
||||
static const PRIMITIVETYPE_POINTS = 0;
|
||||
|
||||
@@ -4265,7 +4271,7 @@ enum TTextureFormat {
|
||||
}
|
||||
|
||||
/// ! Pixel Data Format
|
||||
sealed class TPixelDataFormat {
|
||||
abstract class TPixelDataFormat {
|
||||
/// !< One Red channel, float
|
||||
static const PIXELDATAFORMAT_R = 0;
|
||||
|
||||
@@ -4299,7 +4305,7 @@ sealed class TPixelDataFormat {
|
||||
static const PIXELDATAFORMAT_ALPHA = 11;
|
||||
}
|
||||
|
||||
sealed class TPixelDataType {
|
||||
abstract class TPixelDataType {
|
||||
/// !< unsigned byte
|
||||
static const PIXELDATATYPE_UBYTE = 0;
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
_cameras.add(camera);
|
||||
|
||||
await view.setCamera(camera);
|
||||
|
||||
if (renderTarget != null) {
|
||||
await view.setRenderTarget(renderTarget);
|
||||
}
|
||||
@@ -149,14 +150,12 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
}
|
||||
|
||||
final _onDispose = <Future Function()>[];
|
||||
bool _disposing = false;
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
@override
|
||||
Future dispose() async {
|
||||
_disposing = true;
|
||||
await setRendering(false);
|
||||
await destroyAssets();
|
||||
await destroyLights();
|
||||
@@ -166,7 +165,6 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
}
|
||||
|
||||
_onDispose.clear();
|
||||
_disposing = false;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user