From 6e64177c7aeb8441966829c4f91641456db71cc2 Mon Sep 17 00:00:00 2001 From: Dereck Bridie Date: Wed, 16 Apr 2025 16:08:58 +0200 Subject: [PATCH 1/2] Port environment snippets from DAC --- .../com/example/xr/scenecore/Environments.kt | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 xr/src/main/java/com/example/xr/scenecore/Environments.kt diff --git a/xr/src/main/java/com/example/xr/scenecore/Environments.kt b/xr/src/main/java/com/example/xr/scenecore/Environments.kt new file mode 100644 index 00000000..eac080db --- /dev/null +++ b/xr/src/main/java/com/example/xr/scenecore/Environments.kt @@ -0,0 +1,62 @@ +package com.example.xr.scenecore + +import androidx.xr.scenecore.ExrImage +import androidx.xr.scenecore.GltfModel +import androidx.xr.scenecore.Session +import androidx.xr.scenecore.SpatialEnvironment +import kotlinx.coroutines.guava.await + +private class Environments(val session: Session) { + suspend fun loadEnvironmentGeometry() { + // [START androidxr_scenecore_environment_loadEnvironmentGeometry] + val environmentGeometryFuture = GltfModel.create(session, "DayGeometry.glb") + val environmentGeometry = environmentGeometryFuture.await() + // [END androidxr_scenecore_environment_loadEnvironmentGeometry] + } + + fun loadEnvironmentSkybox() { + // [START androidxr_scenecore_environment_loadEnvironmentSkybox] + val skybox = ExrImage.create(session, "BlueSkybox.exr") + // [END androidxr_scenecore_environment_loadEnvironmentSkybox] + } + + fun setEnvironmentPreference(environmentGeometry: GltfModel, skybox: ExrImage) { + // [START androidxr_scenecore_environment_setEnvironmentPreference] + val spatialEnvironmentPreference = + SpatialEnvironment.SpatialEnvironmentPreference(skybox, environmentGeometry) + val preferenceResult = + session.spatialEnvironment.setSpatialEnvironmentPreference(spatialEnvironmentPreference) + if (preferenceResult == SpatialEnvironment.SetSpatialEnvironmentPreferenceChangeApplied()) { + // The environment was successfully updated and is now visible, and any listeners + // specified using addOnSpatialEnvironmentChangedListener will be notified. + } else if (preferenceResult == SpatialEnvironment.SetSpatialEnvironmentPreferenceChangePending()) { + // The environment is in the process of being updated. Once visible, any listeners + // specified using addOnSpatialEnvironmentChangedListener will be notified. + } + // [END androidxr_scenecore_environment_setEnvironmentPreference] + } + + fun setPassthroughOpacityPreference() { + // [START androidxr_scenecore_environment_setPassthroughOpacityPreference] + val preferenceResult = session.spatialEnvironment.setPassthroughOpacityPreference(1.0f) + if (preferenceResult == SpatialEnvironment.SetPassthroughOpacityPreferenceChangeApplied()) { + // The passthrough opacity request succeeded and should be visible now, and any listeners + // specified using addOnPassthroughOpacityChangedListener will be notified + } else if (preferenceResult == SpatialEnvironment.SetPassthroughOpacityPreferenceChangePending()) { + // The passthrough opacity preference was successfully set, but not + // immediately visible. The passthrough opacity change will be applied + // when the activity has the + // SpatialCapabilities.SPATIAL_CAPABILITY_PASSTHROUGH_CONTROL capability. + // Then, any listeners specified using addOnPassthroughOpacityChangedListener + // will be notified + } + // [END androidxr_scenecore_environment_setPassthroughOpacityPreference] + } + + fun getCurrentPassthroughOpacity() { + // [START androidxr_scenecore_environment_getCurrentPassthroughOpacity] + val currentPassthroughOpacity = session.spatialEnvironment.getCurrentPassthroughOpacity() + // [END androidxr_scenecore_environment_getCurrentPassthroughOpacity] + } +} + From 0295b87c2ea1442ea5f7be79628311bd0cf8396d Mon Sep 17 00:00:00 2001 From: devbridie <442644+devbridie@users.noreply.github.com> Date: Wed, 16 Apr 2025 14:12:48 +0000 Subject: [PATCH 2/2] Apply Spotless --- .../com/example/xr/scenecore/Environments.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/xr/src/main/java/com/example/xr/scenecore/Environments.kt b/xr/src/main/java/com/example/xr/scenecore/Environments.kt index eac080db..a366f9d1 100644 --- a/xr/src/main/java/com/example/xr/scenecore/Environments.kt +++ b/xr/src/main/java/com/example/xr/scenecore/Environments.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.example.xr.scenecore import androidx.xr.scenecore.ExrImage @@ -59,4 +75,3 @@ private class Environments(val session: Session) { // [END androidxr_scenecore_environment_getCurrentPassthroughOpacity] } } -