Skip to content

Commit ef42c55

Browse files
authored
update java and js bindings (#9676)
* implement some missing javascript bindings DOCS_FORCE * use exclusively javadoc comments in Options.h This is because this file is currently used to generate java and javascript bindings and doxygen can ingest javadoc. And regenerate javascript and java bindings * add missing java bindings
1 parent bd67c9c commit ef42c55

File tree

15 files changed

+1022
-910
lines changed

15 files changed

+1022
-910
lines changed

android/filament-android/src/main/cpp/Camera.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <filament/Camera.h>
2020

21+
2122
#include <utils/Entity.h>
2223

2324
#include <math/mat4.h>
@@ -40,6 +41,13 @@ Java_com_google_android_filament_Camera_nSetProjectionFov(JNIEnv*, jclass ,
4041
camera->setProjection(fovInDegrees, aspect, near, far, (Camera::Fov) fov);
4142
}
4243

44+
extern "C" JNIEXPORT jdouble JNICALL
45+
Java_com_google_android_filament_Camera_nGetFieldOfViewInDegrees(JNIEnv*, jclass,
46+
jlong nativeCamera, jint direction) {
47+
Camera *camera = (Camera *) nativeCamera;
48+
return camera->getFieldOfViewInDegrees((Camera::Fov) direction);
49+
}
50+
4351
extern "C" JNIEXPORT void JNICALL
4452
Java_com_google_android_filament_Camera_nSetLensProjection(JNIEnv*, jclass,
4553
jlong nativeCamera, jdouble focalLength, jdouble aspect, jdouble near, jdouble far) {
@@ -62,6 +70,21 @@ Java_com_google_android_filament_Camera_nSetCustomProjection(JNIEnv *env, jclass
6270
env->ReleaseDoubleArrayElements(inProjectionForCulling_, inProjectionForCulling, JNI_ABORT);
6371
}
6472

73+
extern "C" JNIEXPORT void JNICALL
74+
Java_com_google_android_filament_Camera_nSetCustomEyeProjection(JNIEnv *env, jclass,
75+
jlong nativeCamera, jdoubleArray inProjection_, jint count, jdoubleArray inProjectionForCulling_,
76+
jdouble near, jdouble far) {
77+
Camera *camera = (Camera *) nativeCamera;
78+
jdouble *inProjection = env->GetDoubleArrayElements(inProjection_, NULL);
79+
jdouble *inProjectionForCulling = env->GetDoubleArrayElements(inProjectionForCulling_, NULL);
80+
camera->setCustomEyeProjection(
81+
reinterpret_cast<const filament::math::mat4 *>(inProjection), (size_t) count,
82+
*reinterpret_cast<const filament::math::mat4 *>(inProjectionForCulling),
83+
near, far);
84+
env->ReleaseDoubleArrayElements(inProjection_, inProjection, JNI_ABORT);
85+
env->ReleaseDoubleArrayElements(inProjectionForCulling_, inProjectionForCulling, JNI_ABORT);
86+
}
87+
6588
extern "C" JNIEXPORT void JNICALL
6689
Java_com_google_android_filament_Camera_nSetScaling(JNIEnv* env, jclass,
6790
jlong nativeCamera, jdouble x, jdouble y) {
@@ -76,6 +99,17 @@ Java_com_google_android_filament_Camera_nSetShift(JNIEnv* env, jclass,
7699
camera->setShift({(double)x, (double)y});
77100
}
78101

102+
extern "C" JNIEXPORT void JNICALL
103+
Java_com_google_android_filament_Camera_nGetShift(JNIEnv* env, jclass,
104+
jlong nativeCamera, jdoubleArray out_) {
105+
Camera *camera = (Camera *) nativeCamera;
106+
jdouble *out = env->GetDoubleArrayElements(out_, NULL);
107+
filament::math::double2 s = camera->getShift();
108+
out[0] = s.x;
109+
out[1] = s.y;
110+
env->ReleaseDoubleArrayElements(out_, out, 0);
111+
}
112+
79113
extern "C" JNIEXPORT void JNICALL
80114
Java_com_google_android_filament_Camera_nLookAt(JNIEnv*, jclass, jlong nativeCamera,
81115
jdouble eye_x, jdouble eye_y, jdouble eye_z, jdouble center_x, jdouble center_y,
@@ -115,6 +149,15 @@ Java_com_google_android_filament_Camera_nSetModelMatrixFp64(JNIEnv *env, jclass,
115149
env->ReleaseDoubleArrayElements(in_, in, JNI_ABORT);
116150
}
117151

152+
extern "C" JNIEXPORT void JNICALL
153+
Java_com_google_android_filament_Camera_nSetEyeModelMatrix(JNIEnv *env, jclass,
154+
jlong nativeCamera, jint eyeId, jdoubleArray model_) {
155+
Camera* camera = (Camera *) nativeCamera;
156+
jdouble *model = env->GetDoubleArrayElements(model_, NULL);
157+
camera->setEyeModelMatrix((uint8_t)eyeId, *reinterpret_cast<const filament::math::mat4*>(model));
158+
env->ReleaseDoubleArrayElements(model_, model, JNI_ABORT);
159+
}
160+
118161
extern "C" JNIEXPORT void JNICALL
119162
Java_com_google_android_filament_Camera_nGetProjectionMatrix(JNIEnv *env, jclass,
120163
jlong nativeCamera, jdoubleArray out_) {
@@ -280,3 +323,5 @@ Java_com_google_android_filament_Camera_nComputeEffectiveFov(JNIEnv*, jclass,
280323
jdouble fovInDegrees, jdouble focusDistance) {
281324
return Camera::computeEffectiveFov(fovInDegrees, focusDistance);
282325
}
326+
327+

android/filament-android/src/main/cpp/Material.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ Java_com_google_android_filament_Material_nGetBlendingMode(JNIEnv*, jclass,
9696
return (jint) material->getBlendingMode();
9797
}
9898

99+
extern "C"
100+
JNIEXPORT jint JNICALL
101+
Java_com_google_android_filament_Material_nGetTransparencyMode(JNIEnv*, jclass,
102+
jlong nativeMaterial) {
103+
Material* material = (Material*) nativeMaterial;
104+
return (jint) material->getTransparencyMode();
105+
}
106+
99107

100108
extern "C"
101109
JNIEXPORT jint JNICALL

android/filament-android/src/main/cpp/MaterialInstance.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,3 +564,19 @@ Java_com_google_android_filament_MaterialInstance_nGetDepthFunc(JNIEnv* env, jcl
564564
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
565565
return (jint)instance->getDepthFunc();
566566
}
567+
568+
extern "C"
569+
JNIEXPORT void JNICALL
570+
Java_com_google_android_filament_MaterialInstance_nSetTransparencyMode(JNIEnv*, jclass,
571+
jlong nativeMaterialInstance, jint mode) {
572+
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
573+
instance->setTransparencyMode((MaterialInstance::TransparencyMode) mode);
574+
}
575+
576+
extern "C"
577+
JNIEXPORT jint JNICALL
578+
Java_com_google_android_filament_MaterialInstance_nGetTransparencyMode(JNIEnv*, jclass,
579+
jlong nativeMaterialInstance) {
580+
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
581+
return (jint) instance->getTransparencyMode();
582+
}

android/filament-android/src/main/cpp/Texture.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ Java_com_google_android_filament_Texture_nBuilderSwizzle(JNIEnv *, jclass ,
173173
(Texture::Swizzle)r, (Texture::Swizzle)g, (Texture::Swizzle)b, (Texture::Swizzle)a);
174174
}
175175

176+
extern "C" JNIEXPORT void JNICALL
177+
Java_com_google_android_filament_Texture_nBuilderSamples(JNIEnv*, jclass,
178+
jlong nativeBuilder, jint samples) {
179+
Texture::Builder *builder = (Texture::Builder *) nativeBuilder;
180+
builder->samples((uint8_t) samples);
181+
}
182+
176183
extern "C"
177184
JNIEXPORT void JNICALL
178185
Java_com_google_android_filament_Texture_nBuilderImportTexture(JNIEnv*, jclass, jlong nativeBuilder, jlong id) {

android/filament-android/src/main/cpp/View.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ Java_com_google_android_filament_View_nSetVisibleLayers(JNIEnv*, jclass, jlong n
7676
view->setVisibleLayers((uint8_t) select, (uint8_t) value);
7777
}
7878

79+
extern "C" JNIEXPORT jint JNICALL
80+
Java_com_google_android_filament_View_nGetVisibleLayers(JNIEnv*, jclass, jlong nativeView) {
81+
View* view = (View*) nativeView;
82+
return view->getVisibleLayers();
83+
}
84+
7985
extern "C" JNIEXPORT void JNICALL
8086
Java_com_google_android_filament_View_nSetShadowingEnabled(JNIEnv*, jclass, jlong nativeView, jboolean enabled) {
8187
View* view = (View*) nativeView;
@@ -440,6 +446,18 @@ Java_com_google_android_filament_View_nIsShadowingEnabled(JNIEnv *, jclass, jlon
440446
return (jboolean)view->isShadowingEnabled();
441447
}
442448

449+
extern "C" JNIEXPORT void JNICALL
450+
Java_com_google_android_filament_View_nSetFrustumCullingEnabled(JNIEnv*, jclass, jlong nativeView, jboolean enabled) {
451+
View* view = (View*) nativeView;
452+
view->setFrustumCullingEnabled(enabled);
453+
}
454+
455+
extern "C" JNIEXPORT jboolean JNICALL
456+
Java_com_google_android_filament_View_nIsFrustumCullingEnabled(JNIEnv*, jclass, jlong nativeView) {
457+
View* view = (View*) nativeView;
458+
return (jboolean)view->isFrustumCullingEnabled();
459+
}
460+
443461
extern "C"
444462
JNIEXPORT void JNICALL
445463
Java_com_google_android_filament_View_nSetScreenSpaceRefractionEnabled(JNIEnv *, jclass,

android/filament-android/src/main/java/com/google/android/filament/Asserts.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,13 @@ static void assertDouble4In(@NonNull double[] in) {
136136
throw new ArrayIndexOutOfBoundsException("Array length must be at least 4");
137137
}
138138
}
139+
140+
@NonNull @Size(min = 2)
141+
static double[] assertDouble2(@Nullable double[] out) {
142+
if (out == null) out = new double[2];
143+
else if (out.length < 2) {
144+
throw new ArrayIndexOutOfBoundsException("Array length must be at least 2");
145+
}
146+
return out;
147+
}
139148
}

android/filament-android/src/main/java/com/google/android/filament/Camera.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,27 @@ public void setScaling(double xscaling, double yscaling) {
343343
nSetScaling(getNativeObject(), xscaling, yscaling);
344344
}
345345

346+
/**
347+
* Sets a custom projection matrix for each eye.
348+
*
349+
* @param inProjection An array of projection matrices, one for each eye.
350+
* Must have at least 16 * count elements.
351+
* @param count Number of eyes to set.
352+
* @param inProjectionForCulling Custom projection matrix for culling, must encompass all eyes.
353+
* @param near Distance to the near plane.
354+
* @param far Distance to the far plane.
355+
*/
356+
public void setCustomEyeProjection(
357+
@NonNull double[] inProjection, int count,
358+
@NonNull @Size(min = 16) double[] inProjectionForCulling,
359+
double near, double far) {
360+
Asserts.assertMat4dIn(inProjectionForCulling);
361+
if (inProjection.length < 16 * count) {
362+
throw new IllegalArgumentException("inProjection array too small for the given count");
363+
}
364+
nSetCustomEyeProjection(getNativeObject(), inProjection, count, inProjectionForCulling, near, far);
365+
}
366+
346367
/**
347368
* Sets an additional matrix that scales the projection matrix.
348369
*
@@ -399,6 +420,31 @@ public void setShift(double xshift, double yshift) {
399420
nSetShift(getNativeObject(), xshift, yshift);
400421
}
401422

423+
/**
424+
* Returns the shift amount used to translate the projection matrix.
425+
*
426+
* @param out A 2-double array where the shift will be stored, or null.
427+
* @return A 2-double array containing the x and y shift.
428+
*/
429+
@NonNull @Size(min = 2)
430+
public double[] getShift(@Nullable @Size(min = 2) double[] out) {
431+
out = Asserts.assertDouble2(out);
432+
nGetShift(getNativeObject(), out);
433+
return out;
434+
}
435+
436+
/**
437+
* Returns the camera's field of view in degrees.
438+
*
439+
* @param direction The direction of the FOV (VERTICAL or HORIZONTAL).
440+
* @return The field of view in degrees.
441+
*/
442+
public double getFieldOfViewInDegrees(@NonNull Fov direction) {
443+
return nGetFieldOfViewInDegrees(getNativeObject(), direction.ordinal());
444+
}
445+
446+
447+
402448
/**
403449
* Sets the camera's model matrix.
404450
* <p>
@@ -745,6 +791,17 @@ public int getEntity() {
745791
return mEntity;
746792
}
747793

794+
/**
795+
* Sets the model matrix for a specific eye.
796+
*
797+
* @param eyeId The index of the eye.
798+
* @param model The model matrix for the eye.
799+
*/
800+
public void setEyeModelMatrix(int eyeId, @NonNull @Size(min = 16) double[] model) {
801+
Asserts.assertMat4dIn(model);
802+
nSetEyeModelMatrix(getNativeObject(), eyeId, model);
803+
}
804+
748805
/**
749806
* Helper to compute the effective focal length taking into account the focus distance
750807
*
@@ -784,8 +841,13 @@ void clearNativeObject() {
784841
private static native void nSetCustomProjection(long nativeCamera, double[] inProjection, double[] inProjectionForCulling, double near, double far);
785842
private static native void nSetScaling(long nativeCamera, double x, double y);
786843
private static native void nSetShift(long nativeCamera, double x, double y);
844+
private static native void nGetShift(long nativeCamera, double[] out);
787845
private static native void nSetModelMatrix(long nativeCamera, float[] in);
788846
private static native void nSetModelMatrixFp64(long nativeCamera, double[] in);
847+
private static native void nSetEyeModelMatrix(long nativeCamera, int eyeId, double[] model);
848+
private static native void nSetCustomEyeProjection(long nativeCamera, double[] inProjection, int count, double[] inProjectionForCulling, double near, double far);
849+
private static native double nGetFieldOfViewInDegrees(long nativeCamera, int direction);
850+
789851
private static native void nLookAt(long nativeCamera, double eyeX, double eyeY, double eyeZ, double centerX, double centerY, double centerZ, double upX, double upY, double upZ);
790852
private static native double nGetNear(long nativeCamera);
791853
private static native double nGetCullingFar(long nativeCamera);

android/filament-android/src/main/java/com/google/android/filament/Material.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ private EnumCache() { }
5454
static final CullingMode[] sCullingModeValues = CullingMode.values();
5555
static final VertexBuffer.VertexAttribute[] sVertexAttributeValues =
5656
VertexBuffer.VertexAttribute.values();
57+
static final TransparencyMode[] sTransparencyModeValues = TransparencyMode.values();
5758
}
5859

5960
private long mNativeObject;
@@ -160,6 +161,31 @@ public enum BlendingMode {
160161
SCREEN,
161162
}
162163

164+
/**
165+
* How transparent objects are handled
166+
*
167+
* @see
168+
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/blendingandtransparency:transparencymode">
169+
* Blending and transparency: transparencyMode</a>
170+
*/
171+
public enum TransparencyMode {
172+
/** The transparent object is drawn honoring the raster state. */
173+
DEFAULT,
174+
175+
/**
176+
* The transparent object is first drawn in the depth buffer,
177+
* then in the color buffer, honoring the culling mode, but ignoring the depth test function.
178+
*/
179+
TWO_PASSES_ONE_SIDE,
180+
181+
/**
182+
* The transparent object is drawn twice in the color buffer,
183+
* first with back faces only, then with front faces; the culling
184+
* mode is ignored. Can be combined with two-sided lighting.
185+
*/
186+
TWO_PASSES_TWO_SIDES
187+
}
188+
163189
/**
164190
* Supported refraction modes
165191
*
@@ -587,6 +613,18 @@ public BlendingMode getBlendingMode() {
587613
return EnumCache.sBlendingModeValues[nGetBlendingMode(getNativeObject())];
588614
}
589615

616+
/**
617+
* Returns the transparency mode of this material.
618+
* This value only makes sense when the blending mode is transparent or fade.
619+
*
620+
* @see
621+
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/blendingandtransparency:transparencymode">
622+
* Blending and transparency: transparencyMode</a>
623+
*/
624+
public TransparencyMode getTransparencyMode() {
625+
return EnumCache.sTransparencyModeValues[nGetTransparencyMode(getNativeObject())];
626+
}
627+
590628
/**
591629
* Returns the refraction mode of this material.
592630
*
@@ -1130,6 +1168,7 @@ void clearNativeObject() {
11301168
private static native int nGetShading(long nativeMaterial);
11311169
private static native int nGetInterpolation(long nativeMaterial);
11321170
private static native int nGetBlendingMode(long nativeMaterial);
1171+
private static native int nGetTransparencyMode(long nativeMaterial);
11331172
private static native int nGetVertexDomain(long nativeMaterial);
11341173
private static native int nGetCullingMode(long nativeMaterial);
11351174
private static native boolean nIsColorWriteEnabled(long nativeMaterial);

android/filament-android/src/main/java/com/google/android/filament/MaterialInstance.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,14 @@ public void setDoubleSided(boolean doubleSided) {
537537
nSetDoubleSided(getNativeObject(), doubleSided);
538538
}
539539

540+
/**
541+
* Sets the transparency mode for this material instance.
542+
* @see Material.TransparencyMode
543+
*/
544+
public void setTransparencyMode(@NonNull Material.TransparencyMode mode) {
545+
nSetTransparencyMode(getNativeObject(), mode.ordinal());
546+
}
547+
540548
/**
541549
* Returns whether double-sided lighting is enabled when the parent Material has double-sided
542550
* capability.
@@ -545,6 +553,14 @@ public boolean isDoubleSided() {
545553
return nIsDoubleSided(getNativeObject());
546554
}
547555

556+
/**
557+
* Returns the transparency mode.
558+
*/
559+
@NonNull
560+
public Material.TransparencyMode getTransparencyMode() {
561+
return Material.EnumCache.sTransparencyModeValues[nGetTransparencyMode(getNativeObject())];
562+
}
563+
548564
/**
549565
* Overrides the default triangle culling state that was set on the material.
550566
*
@@ -982,4 +998,6 @@ private static native void nSetStencilWriteMask(long nativeMaterialInstance, int
982998
private static native boolean nIsStencilWriteEnabled(long nativeMaterialInstance);
983999
private static native boolean nIsDepthCullingEnabled(long nativeMaterialInstance);
9841000
private static native int nGetDepthFunc(long nativeMaterialInstance);
1001+
private static native void nSetTransparencyMode(long nativeMaterialInstance, int mode);
1002+
private static native int nGetTransparencyMode(long nativeMaterialInstance);
9851003
}

0 commit comments

Comments
 (0)