Skip to content

Commit 6e64177

Browse files
committed
Port environment snippets from DAC
1 parent 4493417 commit 6e64177

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.example.xr.scenecore
2+
3+
import androidx.xr.scenecore.ExrImage
4+
import androidx.xr.scenecore.GltfModel
5+
import androidx.xr.scenecore.Session
6+
import androidx.xr.scenecore.SpatialEnvironment
7+
import kotlinx.coroutines.guava.await
8+
9+
private class Environments(val session: Session) {
10+
suspend fun loadEnvironmentGeometry() {
11+
// [START androidxr_scenecore_environment_loadEnvironmentGeometry]
12+
val environmentGeometryFuture = GltfModel.create(session, "DayGeometry.glb")
13+
val environmentGeometry = environmentGeometryFuture.await()
14+
// [END androidxr_scenecore_environment_loadEnvironmentGeometry]
15+
}
16+
17+
fun loadEnvironmentSkybox() {
18+
// [START androidxr_scenecore_environment_loadEnvironmentSkybox]
19+
val skybox = ExrImage.create(session, "BlueSkybox.exr")
20+
// [END androidxr_scenecore_environment_loadEnvironmentSkybox]
21+
}
22+
23+
fun setEnvironmentPreference(environmentGeometry: GltfModel, skybox: ExrImage) {
24+
// [START androidxr_scenecore_environment_setEnvironmentPreference]
25+
val spatialEnvironmentPreference =
26+
SpatialEnvironment.SpatialEnvironmentPreference(skybox, environmentGeometry)
27+
val preferenceResult =
28+
session.spatialEnvironment.setSpatialEnvironmentPreference(spatialEnvironmentPreference)
29+
if (preferenceResult == SpatialEnvironment.SetSpatialEnvironmentPreferenceChangeApplied()) {
30+
// The environment was successfully updated and is now visible, and any listeners
31+
// specified using addOnSpatialEnvironmentChangedListener will be notified.
32+
} else if (preferenceResult == SpatialEnvironment.SetSpatialEnvironmentPreferenceChangePending()) {
33+
// The environment is in the process of being updated. Once visible, any listeners
34+
// specified using addOnSpatialEnvironmentChangedListener will be notified.
35+
}
36+
// [END androidxr_scenecore_environment_setEnvironmentPreference]
37+
}
38+
39+
fun setPassthroughOpacityPreference() {
40+
// [START androidxr_scenecore_environment_setPassthroughOpacityPreference]
41+
val preferenceResult = session.spatialEnvironment.setPassthroughOpacityPreference(1.0f)
42+
if (preferenceResult == SpatialEnvironment.SetPassthroughOpacityPreferenceChangeApplied()) {
43+
// The passthrough opacity request succeeded and should be visible now, and any listeners
44+
// specified using addOnPassthroughOpacityChangedListener will be notified
45+
} else if (preferenceResult == SpatialEnvironment.SetPassthroughOpacityPreferenceChangePending()) {
46+
// The passthrough opacity preference was successfully set, but not
47+
// immediately visible. The passthrough opacity change will be applied
48+
// when the activity has the
49+
// SpatialCapabilities.SPATIAL_CAPABILITY_PASSTHROUGH_CONTROL capability.
50+
// Then, any listeners specified using addOnPassthroughOpacityChangedListener
51+
// will be notified
52+
}
53+
// [END androidxr_scenecore_environment_setPassthroughOpacityPreference]
54+
}
55+
56+
fun getCurrentPassthroughOpacity() {
57+
// [START androidxr_scenecore_environment_getCurrentPassthroughOpacity]
58+
val currentPassthroughOpacity = session.spatialEnvironment.getCurrentPassthroughOpacity()
59+
// [END androidxr_scenecore_environment_getCurrentPassthroughOpacity]
60+
}
61+
}
62+

0 commit comments

Comments
 (0)