refactor!: refactor to support multiple Views/Render Targets

This commit is contained in:
Nick Fisher
2024-09-27 23:16:01 +08:00
parent a6d2f2ecf9
commit 7f11250b79
25 changed files with 1137 additions and 1304 deletions

View File

@@ -45,14 +45,6 @@ external void Viewer_destroyRenderTarget(
ffi.Pointer<TRenderTarget> tRenderTarget,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TViewer>, ffi.Pointer<TRenderTarget>)>(isLeaf: true)
external void Viewer_setRenderTarget(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TRenderTarget> tRenderTarget,
);
@ffi.Native<
ffi.Pointer<TSwapChain> Function(ffi.Pointer<TViewer>,
ffi.Pointer<ffi.Void>, ffi.Uint32, ffi.Uint32)>(isLeaf: true)
@@ -73,6 +65,7 @@ external void Viewer_destroySwapChain(
@ffi.Native<
ffi.Bool Function(
ffi.Pointer<TViewer>,
ffi.Pointer<TView>,
ffi.Pointer<TSwapChain>,
ffi.Uint64,
ffi.Pointer<ffi.Void>,
@@ -83,6 +76,7 @@ external void Viewer_destroySwapChain(
ffi.Pointer<ffi.Void>)>(isLeaf: true)
external bool Viewer_render(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TView> view,
ffi.Pointer<TSwapChain> swapChain,
int frameTimeInNanos,
ffi.Pointer<ffi.Void> pixelBuffer,
@@ -97,11 +91,13 @@ external bool Viewer_render(
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TViewer>,
ffi.Pointer<TView>,
ffi.Pointer<TSwapChain>,
ffi.Pointer<ffi.Uint8>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
external void Viewer_capture(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TView> view,
ffi.Pointer<TSwapChain> swapChain,
ffi.Pointer<ffi.Uint8> pixelBuffer,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
@@ -110,18 +106,39 @@ external void Viewer_capture(
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TViewer>,
ffi.Pointer<TView>,
ffi.Pointer<TSwapChain>,
ffi.Pointer<TRenderTarget>,
ffi.Pointer<ffi.Uint8>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
external void Viewer_captureRenderTarget(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TView> view,
ffi.Pointer<TSwapChain> swapChain,
ffi.Pointer<TRenderTarget> renderTarget,
ffi.Pointer<ffi.Uint8> pixelBuffer,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
);
@ffi.Native<ffi.Pointer<TView> Function(ffi.Pointer<TViewer>)>(isLeaf: true)
external ffi.Pointer<TView> Viewer_createView(
ffi.Pointer<TViewer> viewer,
);
@ffi.Native<ffi.Pointer<TView> Function(ffi.Pointer<TViewer>, ffi.Int)>(
isLeaf: true)
external ffi.Pointer<TView> Viewer_getViewAt(
ffi.Pointer<TViewer> viewer,
int index,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>, ffi.Pointer<TView>)>(
isLeaf: true)
external void Viewer_setMainCamera(
ffi.Pointer<TViewer> tViewer,
ffi.Pointer<TView> tView,
);
@ffi.Native<ffi.Pointer<TEngine> Function(ffi.Pointer<TViewer>)>(isLeaf: true)
external ffi.Pointer<TEngine> Viewer_getEngine(
ffi.Pointer<TViewer> viewer,
@@ -177,12 +194,6 @@ external void set_background_color(
double a,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>, ffi.Int)>(isLeaf: true)
external void set_tone_mapping(
ffi.Pointer<TViewer> viewer,
int toneMapping,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>, ffi.Float)>(isLeaf: true)
external void set_bloom(
ffi.Pointer<TViewer> viewer,
@@ -360,25 +371,11 @@ external void get_instances(
ffi.Pointer<EntityId> out,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>)>(isLeaf: true)
external void set_main_camera(
ffi.Pointer<TViewer> viewer,
);
@ffi.Native<EntityId Function(ffi.Pointer<TViewer>)>(isLeaf: true)
external int get_main_camera(
ffi.Pointer<TViewer> viewer,
);
@ffi.Native<
ffi.Bool Function(
ffi.Pointer<TViewer>, EntityId, ffi.Pointer<ffi.Char>)>(isLeaf: true)
external bool set_camera(
ffi.Pointer<TViewer> viewer,
int entity,
ffi.Pointer<ffi.Char> nodeName,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>, ffi.Bool)>(isLeaf: true)
external void set_view_frustum_culling(
ffi.Pointer<TViewer> viewer,
@@ -391,57 +388,6 @@ external void set_frame_interval(
double interval,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>, ffi.Uint32, ffi.Uint32)>(
isLeaf: true)
external void update_viewport(
ffi.Pointer<TViewer> viewer,
int width,
int height,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>)>(isLeaf: true)
external void scroll_begin(
ffi.Pointer<TViewer> viewer,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TViewer>, ffi.Float, ffi.Float, ffi.Float)>(isLeaf: true)
external void scroll_update(
ffi.Pointer<TViewer> viewer,
double x,
double y,
double z,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>)>(isLeaf: true)
external void scroll_end(
ffi.Pointer<TViewer> viewer,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TViewer>, ffi.Float, ffi.Float, ffi.Bool)>(isLeaf: true)
external void grab_begin(
ffi.Pointer<TViewer> viewer,
double x,
double y,
bool pan,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>, ffi.Float, ffi.Float)>(
isLeaf: true)
external void grab_update(
ffi.Pointer<TViewer> viewer,
double x,
double y,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>)>(isLeaf: true)
external void grab_end(
ffi.Pointer<TViewer> viewer,
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<TSceneManager>, EntityId,
ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Float>, ffi.Int)>(isLeaf: true)
@@ -699,6 +645,29 @@ external void SceneManager_queueTransformUpdates(
int numEntities,
);
@ffi.Native<
ffi.Pointer<TCamera> Function(ffi.Pointer<TSceneManager>, EntityId,
ffi.Pointer<ffi.Char>)>(isLeaf: true)
external ffi.Pointer<TCamera> SceneManager_findCameraByName(
ffi.Pointer<TSceneManager> tSceneManager,
int entity,
ffi.Pointer<ffi.Char> name,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TSceneManager>, EntityId, ffi.Int)>(
isLeaf: true)
external void SceneManager_setVisibilityLayer(
ffi.Pointer<TSceneManager> tSceneManager,
int entity,
int layer,
);
@ffi.Native<ffi.Pointer<TGizmo> Function(ffi.Pointer<TSceneManager>)>(
isLeaf: true)
external ffi.Pointer<TGizmo> SceneManager_getGizmo(
ffi.Pointer<TSceneManager> tSceneManager,
);
@ffi.Native<ffi.Bool Function(ffi.Pointer<TSceneManager>, EntityId)>(
isLeaf: true)
external bool update_bone_matrices(
@@ -778,10 +747,11 @@ external void queue_relative_position_update_world_axis(
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<TSceneManager>, EntityId, ffi.Float,
ffi.Float)>(isLeaf: true)
ffi.Void Function(ffi.Pointer<TSceneManager>, ffi.Pointer<TView>, EntityId,
ffi.Float, ffi.Float)>(isLeaf: true)
external void queue_position_update_from_viewport_coords(
ffi.Pointer<TSceneManager> sceneManager,
ffi.Pointer<TView> view,
int entity,
double viewportX,
double viewportY,
@@ -942,17 +912,6 @@ external void set_camera_focus_distance(
double focusDistance,
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<TViewer>, _ManipulatorMode, ffi.Double,
ffi.Double, ffi.Double)>(isLeaf: true)
external void set_camera_manipulator_options(
ffi.Pointer<TViewer> viewer,
int mode,
double orbitSpeedX,
double orbitSpeedY,
double zoomSpeed,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TCamera>, double4x4, ffi.Double, ffi.Double)>(isLeaf: true)
@@ -1005,14 +964,6 @@ external void SceneManager_destroyCamera(
ffi.Pointer<TCamera> camera,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TSceneManager>, ffi.Pointer<TCamera>)>(isLeaf: true)
external void SceneManager_setCamera(
ffi.Pointer<TSceneManager> sceneManager,
ffi.Pointer<TCamera> camera,
);
@ffi.Native<ffi.Size Function(ffi.Pointer<TSceneManager>)>(isLeaf: true)
external int SceneManager_getCameraCount(
ffi.Pointer<TSceneManager> sceneManager,
@@ -1026,12 +977,6 @@ external ffi.Pointer<TCamera> SceneManager_getCameraAt(
int index,
);
@ffi.Native<ffi.Pointer<TCamera> Function(ffi.Pointer<TSceneManager>)>(
isLeaf: true)
external ffi.Pointer<TCamera> SceneManager_getActiveCamera(
ffi.Pointer<TSceneManager> sceneManager,
);
@ffi.Native<
ffi.Int Function(ffi.Pointer<TSceneManager>, EntityId,
ffi.Pointer<ffi.Char>)>(isLeaf: true)
@@ -1050,45 +995,10 @@ external int reveal_mesh(
ffi.Pointer<ffi.Char> meshName,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>, ffi.Bool)>(isLeaf: true)
external void set_post_processing(
ffi.Pointer<TViewer> viewer,
bool enabled,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>, ffi.Bool)>(isLeaf: true)
external void set_shadows_enabled(
ffi.Pointer<TViewer> viewer,
bool enabled,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>, ffi.Int)>(isLeaf: true)
external void set_shadow_type(
ffi.Pointer<TViewer> viewer,
int shadowType,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>, ffi.Float, ffi.Float)>(
isLeaf: true)
external void set_soft_shadow_options(
ffi.Pointer<TViewer> viewer,
double penumbraScale,
double penumbraRatioScale,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TViewer>, ffi.Bool, ffi.Bool, ffi.Bool)>(isLeaf: true)
external void set_antialiasing(
ffi.Pointer<TViewer> viewer,
bool msaa,
bool fxaa,
bool taa,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TViewer>,
ffi.Pointer<TView>,
ffi.Int,
ffi.Int,
ffi.Pointer<
@@ -1097,6 +1007,7 @@ external void set_antialiasing(
EntityId entityId, ffi.Int x, ffi.Int y)>>)>(isLeaf: true)
external void filament_pick(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TView> tView,
int x,
int y,
ffi.Pointer<
@@ -1273,15 +1184,19 @@ external void get_gizmo(
ffi.Pointer<EntityId> out,
);
@ffi.Native<Aabb2 Function(ffi.Pointer<TSceneManager>, EntityId)>(isLeaf: true)
@ffi.Native<
Aabb2 Function(
ffi.Pointer<TSceneManager>, ffi.Pointer<TView>, EntityId)>(isLeaf: true)
external Aabb2 get_bounding_box(
ffi.Pointer<TSceneManager> sceneManager,
ffi.Pointer<TView> view,
int entity,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TSceneManager>,
ffi.Pointer<TView>,
EntityId,
ffi.Pointer<ffi.Float>,
ffi.Pointer<ffi.Float>,
@@ -1289,6 +1204,7 @@ external Aabb2 get_bounding_box(
ffi.Pointer<ffi.Float>)>(isLeaf: true)
external void get_bounding_box_to_out(
ffi.Pointer<TSceneManager> sceneManager,
ffi.Pointer<TView> view,
int entity,
ffi.Pointer<ffi.Float> minX,
ffi.Pointer<ffi.Float> minY,
@@ -1296,41 +1212,6 @@ external void get_bounding_box_to_out(
ffi.Pointer<ffi.Float> maxY,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TSceneManager>, ffi.Int, ffi.Bool)>(
isLeaf: true)
external void set_layer_visibility(
ffi.Pointer<TSceneManager> sceneManager,
int layer,
bool visible,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TSceneManager>, EntityId, ffi.Int)>(
isLeaf: true)
external void set_visibility_layer(
ffi.Pointer<TSceneManager> sceneManager,
int entity,
int layer,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TSceneManager>,
ffi.Int,
ffi.Int,
ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(
EntityId entityId, ffi.Int x, ffi.Int y)>>)>(isLeaf: true)
external void pick_gizmo(
ffi.Pointer<TSceneManager> sceneManager,
int x,
int y,
ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(EntityId entityId, ffi.Int x, ffi.Int y)>>
callback,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TSceneManager>, ffi.Bool)>(
isLeaf: true)
external void set_gizmo_visibility(
@@ -1537,21 +1418,25 @@ external void Viewer_destroySwapChainRenderThread(
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>, ffi.Pointer<TSwapChain>)>(
isLeaf: true)
@ffi.Native<
ffi.Void Function(ffi.Pointer<TViewer>, ffi.Pointer<TView>,
ffi.Pointer<TSwapChain>)>(isLeaf: true)
external void Viewer_renderRenderThread(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TView> view,
ffi.Pointer<TSwapChain> swapChain,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TViewer>,
ffi.Pointer<TView>,
ffi.Pointer<TSwapChain>,
ffi.Pointer<ffi.Uint8>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
external void Viewer_captureRenderThread(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TView> view,
ffi.Pointer<TSwapChain> swapChain,
ffi.Pointer<ffi.Uint8> out,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
@@ -1560,12 +1445,14 @@ external void Viewer_captureRenderThread(
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TViewer>,
ffi.Pointer<TView>,
ffi.Pointer<TSwapChain>,
ffi.Pointer<TRenderTarget>,
ffi.Pointer<ffi.Uint8>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
external void Viewer_captureRenderTargetRenderThread(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TView> view,
ffi.Pointer<TSwapChain> swapChain,
ffi.Pointer<TRenderTarget> renderTarget,
ffi.Pointer<ffi.Uint8> out,
@@ -1749,17 +1636,6 @@ external void clear_entities_render_thread(
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<TViewer>, EntityId, ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Bool)>>)>(
isLeaf: true)
external void set_camera_render_thread(
ffi.Pointer<TViewer> viewer,
int asset,
ffi.Pointer<ffi.Char> nodeName,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Bool)>> callback,
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<TSceneManager>, EntityId,
ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Float>, ffi.Int)>(isLeaf: true)
@@ -1956,6 +1832,119 @@ external void unproject_texture_render_thread(
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.Pointer<TRenderTarget>)>(
isLeaf: true)
external void View_setRenderTarget(
ffi.Pointer<TView> view,
ffi.Pointer<TRenderTarget> renderTarget,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.Bool)>(isLeaf: true)
external void View_setFrustumCullingEnabled(
ffi.Pointer<TView> view,
bool enabled,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.Uint32, ffi.Uint32)>(
isLeaf: true)
external void View_updateViewport(
ffi.Pointer<TView> tView,
int width,
int height,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.Bool)>(isLeaf: true)
external void View_setPostProcessing(
ffi.Pointer<TView> tView,
bool enabled,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.Bool)>(isLeaf: true)
external void View_setShadowsEnabled(
ffi.Pointer<TView> tView,
bool enabled,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.Int)>(isLeaf: true)
external void View_setShadowType(
ffi.Pointer<TView> tView,
int shadowType,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.Float, ffi.Float)>(
isLeaf: true)
external void View_setSoftShadowOptions(
ffi.Pointer<TView> tView,
double penumbraScale,
double penumbraRatioScale,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.Float)>(isLeaf: true)
external void View_setBloom(
ffi.Pointer<TView> tView,
double strength,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TView>, ffi.Pointer<TEngine>, ffi.Int)>(isLeaf: true)
external void View_setToneMapping(
ffi.Pointer<TView> tView,
ffi.Pointer<TEngine> tEngine,
int toneMapping,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TView>, ffi.Bool, ffi.Bool, ffi.Bool)>(isLeaf: true)
external void View_setAntiAliasing(
ffi.Pointer<TView> tView,
bool msaa,
bool fxaa,
bool taa,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.Int, ffi.Bool)>(
isLeaf: true)
external void View_setLayerEnabled(
ffi.Pointer<TView> tView,
int layer,
bool visible,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.Pointer<TCamera>)>(
isLeaf: true)
external void View_setCamera(
ffi.Pointer<TView> tView,
ffi.Pointer<TCamera> tCamera,
);
@ffi.Native<ffi.Pointer<TCamera> Function(ffi.Pointer<TView>)>(isLeaf: true)
external ffi.Pointer<TCamera> View_getCamera(
ffi.Pointer<TView> tView,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TGizmo>,
ffi.Pointer<TView>,
ffi.Int,
ffi.Int,
ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(
EntityId entityId, ffi.Int x, ffi.Int y)>>)>(isLeaf: true)
external void Gizmo_pick(
ffi.Pointer<TGizmo> tGizmo,
ffi.Pointer<TView> tView,
int x,
int y,
ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(EntityId entityId, ffi.Int x, ffi.Int y)>>
callback,
);
final class TCamera extends ffi.Opaque {}
final class TMaterialInstance extends ffi.Opaque {}
@@ -1972,6 +1961,10 @@ final class TRenderTarget extends ffi.Opaque {}
final class TSwapChain extends ffi.Opaque {}
final class TView extends ffi.Opaque {}
final class TGizmo extends ffi.Opaque {}
final class TMaterialKey extends ffi.Struct {
@ffi.Bool()
external bool doubleSided;
@@ -2197,8 +2190,6 @@ typedef DartLoadFilamentResourceIntoOutPointerFunction = void Function(
/// - setting up a render loop
typedef EntityId = ffi.Int32;
typedef DartEntityId = int;
typedef _ManipulatorMode = ffi.Int32;
typedef Dart_ManipulatorMode = int;
typedef FilamentRenderCallback
= ffi.Pointer<ffi.NativeFunction<FilamentRenderCallbackFunction>>;
typedef FilamentRenderCallbackFunction = ffi.Void Function(

View File

@@ -10,6 +10,7 @@ import '../../../../entities/gizmo.dart';
import '../../../../utils/matrix.dart';
import '../../events.dart';
import '../../shared_types/camera.dart';
import '../../shared_types/view.dart';
import '../../thermion_viewer_base.dart';
import 'package:logging/logging.dart';
@@ -111,12 +112,28 @@ class ThermionViewerFFI extends ThermionViewer {
///
///
Future setRenderTarget(FFIRenderTarget renderTarget) async {
Viewer_setRenderTarget(_viewer!, renderTarget.renderTarget);
final view = (await getViewAt(0)) as FFIView;
View_setRenderTarget(view.view, renderTarget.renderTarget);
}
///
///
///
Future<View> createView() async {
var view = Viewer_createView(_viewer!);
if (view == nullptr) {
throw Exception("Failed to create view");
}
return FFIView(view, _viewer!);
}
///
///
///
Future updateViewportAndCameraProjection(double width, double height) async {
viewportDimensions = (width * pixelRatio, height * pixelRatio);
update_viewport(_viewer!, width.toInt(), height.toInt());
var mainView = FFIView(Viewer_getViewAt(_viewer!, 0), _viewer!);
mainView.updateViewport(width.toInt(), height.toInt());
final cameraCount = await getCameraCount();
@@ -176,8 +193,6 @@ class ThermionViewerFFI extends ThermionViewer {
_sceneManager = Viewer_getSceneManager(_viewer!);
await setCameraManipulatorOptions(zoomSpeed: 1.0);
final gizmoEntities = allocator<Int32>(4);
get_gizmo(_sceneManager!, gizmoEntities);
_gizmo = Gizmo(gizmoEntities[0], gizmoEntities[1], gizmoEntities[2],
@@ -210,7 +225,8 @@ class ThermionViewerFFI extends ThermionViewer {
///
@override
Future render(FFISwapChain swapChain) async {
Viewer_renderRenderThread(_viewer!, swapChain.swapChain);
final view = (await getViewAt(0)) as FFIView;
Viewer_renderRenderThread(_viewer!, view.view, swapChain.swapChain);
}
///
@@ -223,13 +239,14 @@ class ThermionViewerFFI extends ThermionViewer {
this.viewportDimensions.$2.toInt() *
4;
final out = Uint8List(length);
final view = (await getViewAt(0)) as FFIView;
await withVoidCallback((cb) {
if (renderTarget != null) {
Viewer_captureRenderTargetRenderThread(
_viewer!, swapChain.swapChain, renderTarget.renderTarget, out.address, cb);
Viewer_captureRenderTargetRenderThread(_viewer!, view.view,
swapChain.swapChain, renderTarget.renderTarget, out.address, cb);
} else {
Viewer_captureRenderThread(
_viewer!, swapChain.swapChain, out.address, cb);
_viewer!, view.view, swapChain.swapChain, out.address, cb);
}
});
return out;
@@ -569,54 +586,6 @@ class ThermionViewerFFI extends ThermionViewer {
return entity;
}
///
///
///
@override
Future panStart(double x, double y) async {
grab_begin(_viewer!, x * pixelRatio, y * pixelRatio, true);
}
///
///
///
@override
Future panUpdate(double x, double y) async {
grab_update(_viewer!, x * pixelRatio, y * pixelRatio);
}
///
///
///
@override
Future panEnd() async {
grab_end(_viewer!);
}
///
///
///
@override
Future rotateStart(double x, double y) async {
grab_begin(_viewer!, x * pixelRatio, y * pixelRatio, false);
}
///
///
///
@override
Future rotateUpdate(double x, double y) async {
grab_update(_viewer!, x * pixelRatio, y * pixelRatio);
}
///
///
///
@override
Future rotateEnd() async {
grab_end(_viewer!);
}
///
///
///
@@ -1072,33 +1041,6 @@ class ThermionViewerFFI extends ThermionViewer {
});
}
///
///
///
///
///
///
@override
Future zoomBegin() async {
scroll_begin(_viewer!);
}
///
///
///
@override
Future zoomUpdate(double x, double y, double z) async {
scroll_update(_viewer!, x, y, z);
}
///
///
///
@override
Future zoomEnd() async {
scroll_end(_viewer!);
}
///
///
///
@@ -1167,7 +1109,8 @@ class ThermionViewerFFI extends ThermionViewer {
///
@override
Future setMainCamera() async {
set_main_camera(_viewer!);
final view = (await getViewAt(0)) as FFIView;
Viewer_setMainCamera(_viewer!, view.view);
}
///
@@ -1198,11 +1141,14 @@ class ThermionViewerFFI extends ThermionViewer {
Future setCamera(ThermionEntity entity, String? name) async {
var cameraNamePtr =
name?.toNativeUtf8(allocator: allocator).cast<Char>() ?? nullptr;
var result = set_camera(_viewer!, entity, cameraNamePtr);
allocator.free(cameraNamePtr);
if (!result) {
final camera =
SceneManager_findCameraByName(_sceneManager!, entity, cameraNamePtr);
if (camera == nullptr) {
throw Exception("Failed to set camera");
}
final view = (await getViewAt(0)) as FFIView;
View_setCamera(view.view, camera);
allocator.free(cameraNamePtr);
}
///
@@ -1218,7 +1164,8 @@ class ThermionViewerFFI extends ThermionViewer {
///
@override
Future setPostProcessing(bool enabled) async {
set_post_processing_render_thread(_viewer!, enabled);
final view = await getViewAt(0) as FFIView;
View_setPostProcessing(view.view, enabled);
}
///
@@ -1226,14 +1173,16 @@ class ThermionViewerFFI extends ThermionViewer {
///
@override
Future setShadowsEnabled(bool enabled) async {
set_shadows_enabled(_viewer!, enabled);
final view = await getViewAt(0) as FFIView;
View_setShadowsEnabled(view.view, enabled);
}
///
///
///
Future setShadowType(ShadowType shadowType) async {
set_shadow_type(_viewer!, shadowType.index);
final view = await getViewAt(0) as FFIView;
View_setShadowType(view.view, shadowType.index);
}
///
@@ -1241,7 +1190,8 @@ class ThermionViewerFFI extends ThermionViewer {
///
Future setSoftShadowOptions(
double penumbraScale, double penumbraRatioScale) async {
set_soft_shadow_options(_viewer!, penumbraScale, penumbraRatioScale);
final view = await getViewAt(0) as FFIView;
View_setSoftShadowOptions(view.view, penumbraScale, penumbraRatioScale);
}
///
@@ -1249,7 +1199,8 @@ class ThermionViewerFFI extends ThermionViewer {
///
@override
Future setAntiAliasing(bool msaa, bool fxaa, bool taa) async {
set_antialiasing(_viewer!, msaa, fxaa, taa);
final view = await getViewAt(0) as FFIView;
View_setAntiAliasing(view.view, msaa, fxaa, taa);
}
///
@@ -1257,7 +1208,8 @@ class ThermionViewerFFI extends ThermionViewer {
///
@override
Future setBloom(double bloom) async {
set_bloom_render_thread(_viewer!, bloom);
final view = await getViewAt(0) as FFIView;
View_setBloom(view.view, bloom);
}
///
@@ -1489,7 +1441,9 @@ class ThermionViewerFFI extends ThermionViewer {
///
Future queuePositionUpdateFromViewportCoords(
ThermionEntity entity, double x, double y) async {
queue_position_update_from_viewport_coords(_sceneManager!, entity, x, y);
final view = (await getViewAt(0)) as FFIView;
queue_position_update_from_viewport_coords(
_sceneManager!, view.view, entity, x, y);
}
///
@@ -1566,8 +1520,9 @@ class ThermionViewerFFI extends ThermionViewer {
void pick(int x, int y) async {
x = (x * pixelRatio).ceil();
y = (viewportDimensions.$2 - (y * pixelRatio)).ceil();
filament_pick(_viewer!, x, y, _onPickResultCallable.nativeFunction);
final view = (await getViewAt(0)) as FFIView;
filament_pick(
_viewer!, view.view, x, y, _onPickResultCallable.nativeFunction);
}
///
@@ -1577,7 +1532,10 @@ class ThermionViewerFFI extends ThermionViewer {
void pickGizmo(int x, int y) async {
x = (x * pixelRatio).ceil();
y = (viewportDimensions.$2 - (y * pixelRatio)).ceil();
pick_gizmo(_sceneManager!, x, y, _onGizmoPickResultCallable.nativeFunction);
final view = (await getViewAt(0)) as FFIView;
final gizmo = SceneManager_getGizmo(_sceneManager!);
Gizmo_pick(
gizmo, view.view, x, y, _onGizmoPickResultCallable.nativeFunction);
}
///
@@ -1658,27 +1616,6 @@ class ThermionViewerFFI extends ThermionViewer {
return rotationMatrix;
}
ManipulatorMode _cameraMode = ManipulatorMode.ORBIT;
///
///
///
@override
Future setCameraManipulatorOptions(
{ManipulatorMode? mode,
double orbitSpeedX = 0.01,
double orbitSpeedY = 0.01,
double zoomSpeed = 0.01}) async {
if (mode != null) {
_cameraMode = mode;
}
if (_cameraMode != ManipulatorMode.ORBIT) {
throw Exception("Manipulator mode $mode not yet implemented");
}
set_camera_manipulator_options(
_viewer!, _cameraMode.index, orbitSpeedX, orbitSpeedX, zoomSpeed);
}
///
///
///
@@ -1908,7 +1845,8 @@ class ThermionViewerFFI extends ThermionViewer {
///
@override
Future<v64.Aabb2> getViewportBoundingBox(ThermionEntity entityId) async {
final result = get_bounding_box(_sceneManager!, entityId);
final view = (await getViewAt(0)) as FFIView;
final result = get_bounding_box(_sceneManager!, view.view, entityId);
return v64.Aabb2.minMax(v64.Vector2(result.minX, result.minY),
v64.Vector2(result.maxX, result.maxY));
}
@@ -1916,17 +1854,16 @@ class ThermionViewerFFI extends ThermionViewer {
///
///
///
Future setLayerVisibility(int layer, bool visible) {
set_layer_visibility(_sceneManager!, layer, visible);
return Future.value();
Future setLayerVisibility(int layer, bool visible) async {
final view = (await getViewAt(0)) as FFIView;
View_setLayerEnabled(view.view, layer, visible);
}
///
///
///
Future setVisibilityLayer(ThermionEntity entity, int layer) {
set_visibility_layer(_sceneManager!, entity, layer);
return Future.value();
Future setVisibilityLayer(ThermionEntity entity, int layer) async {
SceneManager_setVisibilityLayer(_sceneManager!, entity, layer);
}
///
@@ -2171,14 +2108,16 @@ class ThermionViewerFFI extends ThermionViewer {
///
///
Future setActiveCamera(ThermionFFICamera camera) async {
SceneManager_setCamera(_sceneManager!, camera.camera);
final view = (await getViewAt(0)) as FFIView;
View_setCamera(view.view, camera.camera);
}
///
///
///
Future<Camera> getActiveCamera() async {
final ptr = SceneManager_getActiveCamera(_sceneManager!);
final view = (await getViewAt(0)) as FFIView;
final ptr = View_getCamera(view.view);
return ThermionFFICamera(ptr, Viewer_getEngine(_viewer!));
}
@@ -2216,6 +2155,15 @@ class ThermionViewerFFI extends ThermionViewer {
}
return ThermionFFICamera(camera, Viewer_getEngine(_viewer!));
}
@override
Future<View> getViewAt(int index) async {
var view = Viewer_getViewAt(_viewer!, index);
if (view == nullptr) {
throw Exception("Failed to get view");
}
return FFIView(view, _viewer!);
}
}
class ThermionFFITexture extends ThermionTexture {
@@ -2270,3 +2218,20 @@ class FFISwapChain extends SwapChain {
});
}
}
class FFIView extends View {
final Pointer<TView> view;
final Pointer<TViewer> viewer;
FFIView(this.view, this.viewer);
@override
Future updateViewport(int width, int height) async {
View_updateViewport(view, width, height);
}
@override
Future setRenderTarget(covariant FFIRenderTarget renderTarget) async {
View_setRenderTarget(view, renderTarget.renderTarget);
}
}

View File

@@ -0,0 +1,6 @@
import 'package:thermion_dart/thermion_dart.dart';
abstract class View {
Future updateViewport(int width, int height);
Future setRenderTarget(covariant RenderTarget renderTarget);
}

View File

@@ -11,6 +11,7 @@ import 'dart:async';
import 'package:animation_tools_dart/animation_tools_dart.dart';
import 'shared_types/swap_chain.dart';
import 'shared_types/view.dart';
const double kNear = 0.05;
const double kFar = 1000.0;
@@ -72,7 +73,8 @@ abstract class ThermionViewer {
///
/// Render a single frame and copy the pixel buffer to [out].
///
Future<Uint8List> capture(covariant SwapChain swapChain, { covariant RenderTarget? renderTarget });
Future<Uint8List> capture(covariant SwapChain swapChain,
{covariant RenderTarget? renderTarget});
///
///
@@ -82,13 +84,23 @@ abstract class ThermionViewer {
///
///
///
Future<RenderTarget> createRenderTarget(int width, int height, int textureHandle);
Future<RenderTarget> createRenderTarget(
int width, int height, int textureHandle);
///
///
///
Future setRenderTarget(covariant RenderTarget renderTarget);
///
///
///
Future<View> createView();
///
///
///
Future<View> getViewAt(int index);
///
/// Sets the framerate for continuous rendering when [setRendering] is enabled.
@@ -246,36 +258,6 @@ abstract class ThermionViewer {
Future<ThermionEntity> loadGltf(String path, String relativeResourcePath,
{bool keepData = false});
///
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
///
Future panStart(double x, double y);
///
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
///
Future panUpdate(double x, double y);
///
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
///
Future panEnd();
///
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
///
Future rotateStart(double x, double y);
///
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
///
Future rotateUpdate(double x, double y);
///
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
///
Future rotateEnd();
///
/// Set the weights for all morph targets in [entity] to [weights].
/// Note that [weights] must contain values for ALL morph targets, but no exception will be thrown if you don't do so (you'll just get incorrect results).
@@ -418,20 +400,6 @@ abstract class ThermionViewer {
///
Future clearEntities();
///
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
///
Future zoomBegin();
///
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
///
Future zoomUpdate(double x, double y, double z);
///
/// Called by `FilamentGestureDetector`. You probably don't want to call this yourself.
///
Future zoomEnd();
///
/// Schedules the glTF animation at [index] in [entity] to start playing on the next frame.
@@ -746,17 +714,6 @@ abstract class ThermionViewer {
///
String? getNameForEntity(ThermionEntity entity);
///
/// Sets the options for manipulating the camera via the viewport.
/// ManipulatorMode.FREE_FLIGHT and ManipulatorMode.MAP are currently unsupported and will throw an exception.
///
@Deprecated("Use InputHandler instead")
Future setCameraManipulatorOptions(
{ManipulatorMode mode = ManipulatorMode.ORBIT,
double orbitSpeedX = 0.01,
double orbitSpeedY = 0.01,
double zoomSpeed = 0.01});
///
/// Returns all child entities under [parent].
///

View File

@@ -2,6 +2,7 @@ import 'dart:math';
import 'dart:typed_data';
import 'package:thermion_dart/src/viewer/src/shared_types/swap_chain.dart';
import 'package:thermion_dart/src/viewer/src/shared_types/view.dart';
import 'package:thermion_dart/thermion_dart.dart';
import 'package:vector_math/vector_math_64.dart';
import 'dart:async';
@@ -385,12 +386,7 @@ class ThermionViewerStub extends ThermionViewer {
throw UnimplementedError();
}
@override
Future render() {
// TODO: implement render
throw UnimplementedError();
}
@override
// TODO: implement rendering
bool get rendering => throw UnimplementedError();
@@ -1032,6 +1028,30 @@ class ThermionViewerStub extends ThermionViewer {
// TODO: implement setRenderTarget
throw UnimplementedError();
}
@override
Future<Uint8List> capture(covariant SwapChain swapChain, {covariant RenderTarget? renderTarget}) {
// TODO: implement capture
throw UnimplementedError();
}
@override
Future<View> createView() {
// TODO: implement createView
throw UnimplementedError();
}
@override
Future<View> getViewAt(int index) {
// TODO: implement getViewAt
throw UnimplementedError();
}
@override
Future render(covariant SwapChain swapChain) {
// TODO: implement render
throw UnimplementedError();
}
}

View File

@@ -1803,26 +1803,6 @@ class ThermionViewerWasm implements ThermionViewer {
null);
}
@override
Future setCameraManipulatorOptions(
{ManipulatorMode mode = ManipulatorMode.ORBIT,
double orbitSpeedX = 0.01,
double orbitSpeedY = 0.01,
double zoomSpeed = 0.01}) async {
_module!.ccall(
"set_camera_manipulator_options",
"void",
["void*".toJS, "int".toJS, "double".toJS, "double".toJS, "double".toJS]
.toJS,
[
_viewer!,
mode.index.toJS,
orbitSpeedX.toJS,
orbitSpeedY.toJS,
zoomSpeed.toJS
].toJS,
null);
}
@override
Future setCameraModelMatrix(List<double> matrix) async {