expose View methods for transparent picking

This commit is contained in:
Nick Fisher
2025-07-01 14:20:02 +08:00
parent 83e4a5142a
commit f9a7ac49a1
6 changed files with 56 additions and 0 deletions

View File

@@ -571,6 +571,17 @@ external void View_setFogOptions(
TFogOptions tFogOptions,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.Bool)>(isLeaf: true)
external void View_setTransparentPickingEnabled(
ffi.Pointer<TView> tView,
bool enabled,
);
@ffi.Native<ffi.Bool Function(ffi.Pointer<TView>)>(isLeaf: true)
external bool View_isTransparentPickingEnabled(
ffi.Pointer<TView> tView,
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<TView>, ffi.Uint32, ffi.Uint32, ffi.Uint32,
PickCallback)>(isLeaf: true)

View File

@@ -720,6 +720,13 @@ extension type NativeLibrary(JSObject _) implements JSObject {
Pointer<TView> tView,
Pointer<TFogOptions> tFogOptionsPtr,
);
external void _View_setTransparentPickingEnabled(
Pointer<TView> tView,
bool enabled,
);
external int _View_isTransparentPickingEnabled(
Pointer<TView> tView,
);
external void _View_pick(
Pointer<TView> tView,
int requestId,
@@ -3008,6 +3015,21 @@ void View_setFogOptions(
return result;
}
void View_setTransparentPickingEnabled(
self.Pointer<TView> tView,
bool enabled,
) {
final result = _lib._View_setTransparentPickingEnabled(tView.cast(), enabled);
return result;
}
bool View_isTransparentPickingEnabled(
self.Pointer<TView> tView,
) {
final result = _lib._View_isTransparentPickingEnabled(tView.cast());
return result == 1;
}
void View_pick(
self.Pointer<TView> tView,
int requestId,

View File

@@ -335,4 +335,12 @@ class FFIView extends View<Pointer<TView>> {
void setName(String name) {
View_setName(getNativeHandle(), name.toNativeUtf8().cast());
}
Future setTransparentPickingEnabled(bool enabled) async {
View_setTransparentPickingEnabled(getNativeHandle(), enabled);
}
Future<bool> isTransparentPickingEnabled() async {
return View_isTransparentPickingEnabled(getNativeHandle());
}
}

View File

@@ -92,6 +92,9 @@ abstract class View<T> extends NativeHandle<T> {
Future setShadowsEnabled(bool enabled);
Future setLayerVisibility(VisibilityLayers layer, bool visible);
Future setTransparentPickingEnabled(bool enabled);
Future<bool> isTransparentPickingEnabled();
/// Renders an outline around [entity] with the given color.
Future setStencilHighlight(ThermionAsset asset,
{double r = 1.0,

View File

@@ -89,6 +89,8 @@ EMSCRIPTEN_KEEPALIVE bool View_isDitheringEnabled(TView *tView);
EMSCRIPTEN_KEEPALIVE void View_setScene(TView *tView, TScene *tScene);
EMSCRIPTEN_KEEPALIVE void View_setFrontFaceWindingInverted(TView *tView, bool inverted);
EMSCRIPTEN_KEEPALIVE void View_setFogOptions(TView *tView, TFogOptions tFogOptions);
EMSCRIPTEN_KEEPALIVE void View_setTransparentPickingEnabled(TView *tView, bool enabled);
EMSCRIPTEN_KEEPALIVE bool View_isTransparentPickingEnabled(TView *tView);
typedef void (*PickCallback)(uint32_t requestId, EntityId entityId, float depth, float fragX, float fragY, float fragZ);
EMSCRIPTEN_KEEPALIVE void View_pick(TView* tView, uint32_t requestId, uint32_t x, uint32_t y, PickCallback callback);

View File

@@ -284,6 +284,16 @@ namespace thermion
view->setName(name);
}
EMSCRIPTEN_KEEPALIVE void View_setTransparentPickingEnabled(TView* tView, bool enabled) {
auto view = reinterpret_cast<View *>(tView);
view->setTransparentPickingEnabled(enabled);
}
EMSCRIPTEN_KEEPALIVE bool View_isTransparentPickingEnabled(TView* tView) {
auto view = reinterpret_cast<View *>(tView);
return view->isTransparentPickingEnabled();
}
#ifdef __cplusplus
}
}