Skip to content

Commit

Permalink
Add public API in View for transparent picking (#8206)
Browse files Browse the repository at this point in the history
  • Loading branch information
show50726 authored Oct 22, 2024
1 parent 13310e4 commit 17e4d2b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
14 changes: 14 additions & 0 deletions android/filament-android/src/main/cpp/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,20 @@ Java_com_google_android_filament_View_nIsFrontFaceWindingInverted(JNIEnv*,
return static_cast<jboolean>(view->isFrontFaceWindingInverted());
}

extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetTransparentPickingEnabled(JNIEnv*,
jclass, jlong nativeView, jboolean enabled) {
View* view = (View*) nativeView;
view->setTransparentPickingEnabled(enabled);
}

extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_View_nIsTransparentPickingEnabled(JNIEnv*,
jclass, jlong nativeView) {
View* view = (View*) nativeView;
return static_cast<jboolean>(view->isTransparentPickingEnabled());
}

extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetAmbientOcclusion(JNIEnv*, jclass, jlong nativeView, jint ordinal) {
View* view = (View*) nativeView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,33 @@ public void setFrontFaceWindingInverted(boolean inverted) {
nSetFrontFaceWindingInverted(getNativeObject(), inverted);
}

/**
* Returns true if transparent picking is enabled.
*
* @see #setTransparentPickingEnabled
*/
public boolean isTransparentPickingEnabled() {
return nIsTransparentPickingEnabled(getNativeObject());
}

/**
* Enables or disables transparent picking. Disabled by default.
*
* When transparent picking is enabled, View::pick() will pick from both
* transparent and opaque renderables. When disabled, View::pick() will only
* pick from opaque renderables.
*
* <p>
* Transparent picking will create an extra pass for rendering depth
* from both transparent and opaque renderables.
* </p>
*
* @param enabled true enables transparent picking, false disables it.
*/
public void setTransparentPickingEnabled(boolean enabled) {
nSetTransparentPickingEnabled(getNativeObject(), enabled);
}

/**
* Sets options relative to dynamic lighting for this view.
*
Expand Down Expand Up @@ -1281,6 +1308,8 @@ void clearNativeObject() {
private static native boolean nIsPostProcessingEnabled(long nativeView);
private static native void nSetFrontFaceWindingInverted(long nativeView, boolean inverted);
private static native boolean nIsFrontFaceWindingInverted(long nativeView);
private static native void nSetTransparentPickingEnabled(long nativeView, boolean enabled);
private static native boolean nIsTransparentPickingEnabled(long nativeView);
private static native void nSetAmbientOcclusion(long nativeView, int ordinal);
private static native int nGetAmbientOcclusion(long nativeView);
private static native void nSetAmbientOcclusionOptions(long nativeView, float radius, float bias, float power, float resolution, float intensity, float bilateralThreshold, int quality, int lowPassFilter, int upsampling, boolean enabled, boolean bentNormals, float minHorizonAngleRad);
Expand Down
20 changes: 20 additions & 0 deletions filament/include/filament/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,26 @@ class UTILS_PUBLIC View : public FilamentAPI {
*/
bool isFrontFaceWindingInverted() const noexcept;

/**
* Enables or disables transparent picking. Disabled by default.
*
* When transparent picking is enabled, View::pick() will pick from both
* transparent and opaque renderables. When disabled, View::pick() will only
* pick from opaque renderables.
*
* @param enabled true enables transparent picking, false disables it.
*
* @note Transparent picking will create an extra pass for rendering depth
* from both transparent and opaque renderables.
*/
void setTransparentPickingEnabled(bool enabled) noexcept;

/**
* Returns true if transparent picking is enabled.
* See setTransparentPickingEnabled() for more information.
*/
bool isTransparentPickingEnabled() const noexcept;

/**
* Enables use of the stencil buffer.
*
Expand Down
8 changes: 8 additions & 0 deletions filament/src/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ bool View::isFrontFaceWindingInverted() const noexcept {
return downcast(this)->isFrontFaceWindingInverted();
}

void View::setTransparentPickingEnabled(bool enabled) noexcept {
downcast(this)->setTransparentPickingEnabled(enabled);
}

bool View::isTransparentPickingEnabled() const noexcept {
return downcast(this)->isTransparentPickingEnabled();
}

void View::setDynamicLightingOptions(float zLightNear, float zLightFar) noexcept {
downcast(this)->setDynamicLightingOptions(zLightNear, zLightFar);
}
Expand Down
2 changes: 2 additions & 0 deletions web/filament-js/filament.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ export class View {
public setAntiAliasing(antialiasing: View$AntiAliasing): void;
public setStencilBufferEnabled(enabled: boolean): void;
public isStencilBufferEnabled(): boolean;
public setTransparentPickingEnabled(enabled: boolean): void;
public isTransparentPickingEnabled(): boolean;
}

export class TransformManager {
Expand Down
2 changes: 2 additions & 0 deletions web/filament-js/jsbindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,8 @@ class_<View>("View")
.function("setRenderTarget", EMBIND_LAMBDA(void, (View* self, RenderTarget* renderTarget), {
self->setRenderTarget(renderTarget);
}), allow_raw_pointers())
.function("setTransparentPickingEnabled", &View::setTransparentPickingEnabled)
.function("isTransparentPickingEnabled", &View::isTransparentPickingEnabled)
.function("setStencilBufferEnabled", &View::setStencilBufferEnabled)
.function("isStencilBufferEnabled", &View::isStencilBufferEnabled)
.function("setMaterialGlobal", &View::setMaterialGlobal)
Expand Down

0 comments on commit 17e4d2b

Please sign in to comment.