feat: add Dart methods for getRenderableBoundingBox, setParameterInt and setParameterFloat4
This commit is contained in:
@@ -83,8 +83,15 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
this._sharedContext = sharedContext ?? nullptr;
|
||||
|
||||
_onPickResultCallable = NativeCallable<
|
||||
Void Function(EntityId entityId, Int x, Int y,
|
||||
Pointer<TView> view, Float depth, Float fragX, Float fragY, Float fragZ)>.listener(_onPickResult);
|
||||
Void Function(
|
||||
EntityId entityId,
|
||||
Int x,
|
||||
Int y,
|
||||
Pointer<TView> view,
|
||||
Float depth,
|
||||
Float fragX,
|
||||
Float fragY,
|
||||
Float fragZ)>.listener(_onPickResult);
|
||||
|
||||
_initialize();
|
||||
}
|
||||
@@ -300,7 +307,7 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
return;
|
||||
}
|
||||
_disposing = true;
|
||||
|
||||
|
||||
await setRendering(false);
|
||||
await clearEntities();
|
||||
await clearLights();
|
||||
@@ -1509,17 +1516,38 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
}
|
||||
|
||||
void _onPickResult(
|
||||
ThermionEntity entityId, int x, int y, Pointer<TView> viewPtr, double depth, double fragX, double fragY, double fragZ) async {
|
||||
ThermionEntity entityId,
|
||||
int x,
|
||||
int y,
|
||||
Pointer<TView> viewPtr,
|
||||
double depth,
|
||||
double fragX,
|
||||
double fragY,
|
||||
double fragZ) async {
|
||||
final view = FFIView(viewPtr, _viewer!);
|
||||
final viewport = await view.getViewport();
|
||||
|
||||
_pickResultController
|
||||
.add((entity: entityId, x: x, y: (viewport.height - y), depth: depth, fragX: fragX, fragY: viewport.height - fragY, fragZ: fragZ ));
|
||||
_pickResultController.add((
|
||||
entity: entityId,
|
||||
x: x,
|
||||
y: (viewport.height - y),
|
||||
depth: depth,
|
||||
fragX: fragX,
|
||||
fragY: viewport.height - fragY,
|
||||
fragZ: fragZ
|
||||
));
|
||||
}
|
||||
|
||||
late NativeCallable<
|
||||
Void Function(EntityId entityId, Int x, Int y, Pointer<TView> view, Float depth, Float fragX, Float fragY, Float fragZ)>
|
||||
_onPickResultCallable;
|
||||
Void Function(
|
||||
EntityId entityId,
|
||||
Int x,
|
||||
Int y,
|
||||
Pointer<TView> view,
|
||||
Float depth,
|
||||
Float fragX,
|
||||
Float fragY,
|
||||
Float fragZ)> _onPickResultCallable;
|
||||
|
||||
///
|
||||
///
|
||||
@@ -1750,6 +1778,7 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
throw Exception("Viewer must not be null");
|
||||
}
|
||||
|
||||
|
||||
var entity = await withIntCallback((callback) =>
|
||||
SceneManager_createGeometryRenderThread(
|
||||
_sceneManager!,
|
||||
@@ -1835,6 +1864,18 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
set_priority(_sceneManager!, entityId, priority);
|
||||
}
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
@override
|
||||
Future<v64.Aabb3> getRenderableBoundingBox(ThermionEntity entityId) async {
|
||||
final result =
|
||||
SceneManager_getRenderableBoundingBox(_sceneManager!, entityId);
|
||||
return v64.Aabb3.centerAndHalfExtents(
|
||||
Vector3(result.centerX, result.centerY, result.centerZ),
|
||||
Vector3(result.halfExtentX, result.halfExtentY, result.halfExtentZ));
|
||||
}
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
@@ -2051,9 +2092,11 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
///
|
||||
///
|
||||
///
|
||||
Future<ThermionFFIMaterialInstance> createUnlitFixedSizeMaterialInstance() async {
|
||||
Future<ThermionFFIMaterialInstance>
|
||||
createUnlitFixedSizeMaterialInstance() async {
|
||||
var instance = await withPointerCallback<TMaterialInstance>((cb) {
|
||||
SceneManager_createUnlitFixedSizeMaterialInstanceRenderThread(_sceneManager!, cb);
|
||||
SceneManager_createUnlitFixedSizeMaterialInstanceRenderThread(
|
||||
_sceneManager!, cb);
|
||||
});
|
||||
if (instance == nullptr) {
|
||||
throw Exception("Failed to create material instance");
|
||||
@@ -2205,6 +2248,12 @@ class ThermionFFIMaterialInstance extends MaterialInstance {
|
||||
MaterialInstance_setDepthWrite(this._pointer, enabled);
|
||||
}
|
||||
|
||||
@override
|
||||
Future setParameterFloat4(String name, double x, double y, double z, double w) async {
|
||||
MaterialInstance_setParameterFloat4(
|
||||
_pointer, name.toNativeUtf8().cast<Char>(), x, y, z, w);
|
||||
}
|
||||
|
||||
@override
|
||||
Future setParameterFloat2(String name, double x, double y) async {
|
||||
MaterialInstance_setParameterFloat2(
|
||||
@@ -2216,6 +2265,14 @@ class ThermionFFIMaterialInstance extends MaterialInstance {
|
||||
MaterialInstance_setParameterFloat(
|
||||
_pointer, name.toNativeUtf8().cast<Char>(), value);
|
||||
}
|
||||
|
||||
@override
|
||||
Future setParameterInt(String name, int value) async {
|
||||
MaterialInstance_setParameterInt(
|
||||
_pointer, name.toNativeUtf8().cast<Char>(), value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class FFIRenderTarget extends RenderTarget {
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
abstract class MaterialInstance {
|
||||
Future setDepthWriteEnabled(bool enabled);
|
||||
|
||||
Future setDepthCullingEnabled(bool enabled);
|
||||
Future setParameterFloat4(String name, double x, double y, double z, double w);
|
||||
Future setParameterFloat2(String name, double x, double y);
|
||||
Future setParameterFloat(String name, double x);
|
||||
Future setParameterInt(String name, int value);
|
||||
}
|
||||
|
||||
enum AlphaMode { OPAQUE, MASK, BLEND }
|
||||
|
||||
@@ -790,6 +790,11 @@ abstract class ThermionViewer {
|
||||
///
|
||||
void onDispose(Future Function() callback);
|
||||
|
||||
///
|
||||
/// Gets the 3D axis aligned bounding box for the given entity.
|
||||
///
|
||||
Future<Aabb3> getRenderableBoundingBox(ThermionEntity entity);
|
||||
|
||||
///
|
||||
/// Gets the 2D bounding box (in viewport coordinates) for the given entity.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user