Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ androidx-test-junit = "1.3.0"
androidx-window = "1.5.0"
androidx-window-core = "1.5.0"
androidx-window-java = "1.5.0"
androidx-xr-arcore = "1.0.0-alpha07"
androidx-xr-compose = "1.0.0-alpha08"
androidx-xr-scenecore = "1.0.0-alpha08"
androidx-xr-arcore = "1.0.0-alpha09"
androidx-xr-compose = "1.0.0-alpha09"
androidx-xr-scenecore = "1.0.0-alpha10"
androidxHiltNavigationCompose = "1.3.0"
appcompat = "1.7.1"
arcorePlayServices = "1.0.0-alpha08"
arcorePlayServices = "1.0.0-alpha09"
coil = "2.7.0"
# @keep
compileSdk = "36"
Expand Down
62 changes: 62 additions & 0 deletions xr/src/main/java/com/example/xr/compose/SceneCoreEntity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.compose

import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
import androidx.xr.compose.platform.LocalSession
import androidx.xr.compose.spatial.Subspace
import androidx.xr.compose.subspace.SceneCoreEntity
import androidx.xr.compose.subspace.SceneCoreEntitySizeAdapter
import androidx.xr.compose.subspace.layout.SubspaceModifier
import androidx.xr.compose.subspace.layout.offset
import androidx.xr.runtime.math.IntSize2d
import androidx.xr.runtime.math.Pose
import androidx.xr.scenecore.SurfaceEntity

@Composable
fun SceneCoreEntityExample() {
val session = LocalSession.current
if (session !== null) {
// [START androidxr_compose_SceneCoreEntity]
Subspace {
SceneCoreEntity(
modifier = SubspaceModifier.offset(x = 50.dp),
factory = {
SurfaceEntity.create(
session = session,
pose = Pose.Identity,
stereoMode = SurfaceEntity.StereoMode.MONO
)
},
update = { entity ->
// compose state changes may be applied to the
// SceneCore entity here.
entity.stereoMode = SurfaceEntity.StereoMode.SIDE_BY_SIDE
},
sizeAdapter =
SceneCoreEntitySizeAdapter({
IntSize2d(it.width, it.height)
}),
) {
// Content here will be children of the SceneCoreEntity
// in the scene graph.
}
}
// [END androidxr_compose_SceneCoreEntity]
}
}
5 changes: 2 additions & 3 deletions xr/src/main/java/com/example/xr/compose/Subspace.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.Composable
import androidx.xr.compose.platform.LocalSession
import androidx.xr.compose.spatial.ApplicationSubspace
import androidx.xr.compose.spatial.Subspace
import androidx.xr.compose.subspace.SpatialPanel
import androidx.xr.scenecore.scene
Expand All @@ -35,7 +34,7 @@ private class SubspaceActivity : ComponentActivity() {
// [START androidxr_compose_SubspaceSetContent]
setContent {
// This is a top-level subspace
ApplicationSubspace {
Subspace {
SpatialPanel {
MyComposable()
}
Expand All @@ -59,7 +58,7 @@ private fun PrimaryPane() {
// This is a nested subspace, because PrimaryPane is in a SpatialPanel
// and that SpatialPanel is in a top-level Subspace
Subspace {
ObjectInAVolume(true)
SpatialPanel {}
}
}
// [END androidxr_compose_SubspaceComponents]
Expand Down
91 changes: 0 additions & 91 deletions xr/src/main/java/com/example/xr/compose/Volume.kt

This file was deleted.

6 changes: 2 additions & 4 deletions xr/src/main/java/com/example/xr/scenecore/GltfEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import androidx.activity.ComponentActivity
import androidx.xr.runtime.Session
import androidx.xr.scenecore.GltfModel
import androidx.xr.scenecore.GltfModelEntity
import androidx.xr.scenecore.SpatialCapabilities
import androidx.xr.scenecore.SpatialCapability
import androidx.xr.scenecore.scene
import java.nio.file.Paths

Expand All @@ -35,9 +35,7 @@ private suspend fun loadGltfFile(session: Session) {

private fun createModelEntity(session: Session, gltfModel: GltfModel) {
// [START androidxr_scenecore_gltfmodelentity_create]
if (session.scene.spatialCapabilities
.hasCapability(SpatialCapabilities.SPATIAL_CAPABILITY_3D_CONTENT)
) {
if (session.scene.spatialCapabilities.contains(SpatialCapability.SPATIAL_3D_CONTENT)) {
val gltfEntity = GltfModelEntity.create(session, gltfModel)
}
// [END androidxr_scenecore_gltfmodelentity_create]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ private fun interactableComponentExample(session: Session, entity: Entity) {
val executor = Executors.newSingleThreadExecutor()
val interactableComponent = InteractableComponent.create(session, executor) {
// when the user disengages with the entity with their hands
if (it.source == InputEvent.Source.SOURCE_HANDS && it.action == InputEvent.Action.ACTION_UP) {
if (it.source == InputEvent.Source.HANDS && it.action == InputEvent.Action.UP) {
// increase size with right hand and decrease with left
if (it.pointerType == InputEvent.Pointer.POINTER_TYPE_RIGHT) {
if (it.pointerType == InputEvent.Pointer.RIGHT) {
entity.setScale(1.5f)
} else if (it.pointerType == InputEvent.Pointer.POINTER_TYPE_LEFT) {
} else if (it.pointerType == InputEvent.Pointer.LEFT) {
entity.setScale(0.5f)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private fun resizableComponentExample(
) {
// [START androidxr_scenecore_resizableComponentExample]
val resizableComponent = ResizableComponent.create(session) { event ->
if (event.resizeState == ResizeEvent.ResizeState.RESIZE_STATE_END) {
if (event.resizeState == ResizeEvent.ResizeState.END) {
// update the Entity to reflect the new size
surfaceEntity.shape = SurfaceEntity.Shape.Quad(FloatSize2d(event.newSize.width, event.newSize.height))
}
Expand Down
11 changes: 5 additions & 6 deletions xr/src/main/java/com/example/xr/scenecore/SpatialAudio.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import androidx.xr.runtime.Session
import androidx.xr.scenecore.Entity
import androidx.xr.scenecore.PointSourceParams
import androidx.xr.scenecore.SoundFieldAttributes
import androidx.xr.scenecore.SpatialCapabilities
import androidx.xr.scenecore.SpatialCapability
import androidx.xr.scenecore.SpatialMediaPlayer
import androidx.xr.scenecore.SpatialSoundPool
import androidx.xr.scenecore.SpatializerConstants
Expand All @@ -39,8 +39,7 @@ import androidx.xr.scenecore.scene
private fun playSpatialAudioAtEntity(session: Session, appContext: Context, entity: Entity) {
// [START androidxr_scenecore_playSpatialAudio]
// Check spatial capabilities before using spatial audio
if (session.scene.spatialCapabilities
.hasCapability(SpatialCapabilities.SPATIAL_CAPABILITY_SPATIAL_AUDIO)
if (session.scene.spatialCapabilities.contains(SpatialCapability.SPATIAL_AUDIO)
) { // The session has spatial audio capabilities
val maxVolume = 1F
val lowPriority = 0
Expand Down Expand Up @@ -85,7 +84,7 @@ private fun playSpatialAudioAtEntity(session: Session, appContext: Context, enti
private fun playSpatialAudioAtEntitySurround(session: Session, appContext: Context) {
// [START androidxr_scenecore_playSpatialAudioSurround]
// Check spatial capabilities before using spatial audio
if (session.scene.spatialCapabilities.hasCapability(SpatialCapabilities.SPATIAL_CAPABILITY_SPATIAL_AUDIO)) {
if (session.scene.spatialCapabilities.contains(SpatialCapability.SPATIAL_AUDIO)) {
// The session has spatial audio capabilities

val pointSourceAttributes = PointSourceParams(session.scene.mainPanelEntity)
Expand Down Expand Up @@ -120,11 +119,11 @@ private fun playSpatialAudioAtEntitySurround(session: Session, appContext: Conte
private fun playSpatialAudioAtEntityAmbionics(session: Session, appContext: Context) {
// [START androidxr_scenecore_playSpatialAudioAmbionics]
// Check spatial capabilities before using spatial audio
if (session.scene.spatialCapabilities.hasCapability(SpatialCapabilities.SPATIAL_CAPABILITY_SPATIAL_AUDIO)) {
if (session.scene.spatialCapabilities.contains(SpatialCapability.SPATIAL_AUDIO)) {
// The session has spatial audio capabilities

val soundFieldAttributes =
SoundFieldAttributes(SpatializerConstants.AMBISONICS_ORDER_FIRST_ORDER)
SoundFieldAttributes(SpatializerConstants.AmbisonicsOrder.FIRST_ORDER)

val mediaPlayer = MediaPlayer()

Expand Down
13 changes: 6 additions & 7 deletions xr/src/main/java/com/example/xr/scenecore/SpatialCapabilities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@
package com.example.xr.scenecore

import androidx.xr.runtime.Session
import androidx.xr.scenecore.SpatialCapabilities
import androidx.xr.scenecore.SpatialCapability
import androidx.xr.scenecore.SpatialCapability.Companion.SPATIAL_3D_CONTENT
import androidx.xr.scenecore.scene

fun checkMultipleCapabilities(xrSession: Session) {
// [START androidxr_compose_checkMultipleCapabilities]
// Example 1: check if enabling passthrough mode is allowed
if (xrSession.scene.spatialCapabilities.hasCapability(
SpatialCapabilities.SPATIAL_CAPABILITY_PASSTHROUGH_CONTROL
if (xrSession.scene.spatialCapabilities.contains(
SpatialCapability.PASSTHROUGH_CONTROL
)
) {
xrSession.scene.spatialEnvironment.preferredPassthroughOpacity = 1f
}
// Example 2: multiple capability flags can be checked simultaneously:
if (xrSession.scene.spatialCapabilities.hasCapability(
SpatialCapabilities.SPATIAL_CAPABILITY_PASSTHROUGH_CONTROL and
SpatialCapabilities.SPATIAL_CAPABILITY_3D_CONTENT
)
if (xrSession.scene.spatialCapabilities.contains(SpatialCapability.PASSTHROUGH_CONTROL) &&
xrSession.scene.spatialCapabilities.contains(SpatialCapability.SPATIAL_3D_CONTENT)
) {
// ...
}
Expand Down
20 changes: 10 additions & 10 deletions xr/src/main/java/com/example/xr/scenecore/SpatialVideo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private fun ComponentActivity.surfaceEntityCreate(xrSession: Session) {
// [START androidxr_scenecore_surfaceEntityCreate]
val stereoSurfaceEntity = SurfaceEntity.create(
session = xrSession,
stereoMode = SurfaceEntity.StereoMode.STEREO_MODE_SIDE_BY_SIDE,
stereoMode = SurfaceEntity.StereoMode.SIDE_BY_SIDE,
pose = Pose(Vector3(0.0f, 0.0f, -1.5f)),
shape = SurfaceEntity.Shape.Quad(FloatSize2d(1.0f, 1.0f))
)
Expand All @@ -61,7 +61,7 @@ private fun ComponentActivity.surfaceEntityCreateSbs(xrSession: Session) {
val hemisphereStereoSurfaceEntity =
SurfaceEntity.create(
session = xrSession,
stereoMode = SurfaceEntity.StereoMode.STEREO_MODE_SIDE_BY_SIDE,
stereoMode = SurfaceEntity.StereoMode.SIDE_BY_SIDE,
pose = xrSession.scene.spatialUser.head?.transformPoseTo(
Pose.Identity,
xrSession.scene.activitySpace
Expand All @@ -78,7 +78,7 @@ private fun ComponentActivity.surfaceEntityCreateTb(xrSession: Session) {
val sphereStereoSurfaceEntity =
SurfaceEntity.create(
session = xrSession,
stereoMode = SurfaceEntity.StereoMode.STEREO_MODE_TOP_BOTTOM,
stereoMode = SurfaceEntity.StereoMode.TOP_BOTTOM,
pose = xrSession.scene.spatialUser.head?.transformPoseTo(
Pose.Identity,
xrSession.scene.activitySpace
Expand All @@ -94,7 +94,7 @@ private fun ComponentActivity.surfaceEntityCreateMVHEVC(xrSession: Session) {
// Create the SurfaceEntity with the StereoMode corresponding to the MV-HEVC content
val stereoSurfaceEntity = SurfaceEntity.create(
session = xrSession,
stereoMode = SurfaceEntity.StereoMode.STEREO_MODE_MULTIVIEW_LEFT_PRIMARY,
stereoMode = SurfaceEntity.StereoMode.MULTIVIEW_LEFT_PRIMARY,
pose = Pose(Vector3(0.0f, 0.0f, -1.5f)),
shape = SurfaceEntity.Shape.Quad(FloatSize2d(1.0f, 1.0f))
)
Expand Down Expand Up @@ -123,10 +123,10 @@ private fun ComponentActivity.surfaceEntityCreateDRM(xrSession: Session) {
// Create the SurfaceEntity with the PROTECTED content security level.
val protectedSurfaceEntity = SurfaceEntity.create(
session = xrSession,
stereoMode = SurfaceEntity.StereoMode.STEREO_MODE_SIDE_BY_SIDE,
stereoMode = SurfaceEntity.StereoMode.SIDE_BY_SIDE,
pose = Pose(Vector3(0.0f, 0.0f, -1.5f)),
shape = SurfaceEntity.Shape.Quad(FloatSize2d(1.0f, 1.0f)),
surfaceProtection = SurfaceEntity.SurfaceProtection.SURFACE_PROTECTION_PROTECTED
surfaceProtection = SurfaceEntity.SurfaceProtection.PROTECTED
)

// Build a MediaItem with the necessary DRM configuration.
Expand Down Expand Up @@ -156,16 +156,16 @@ private fun ComponentActivity.surfaceEntityHDR(xrSession: Session) {
// Define the color properties for your HDR video. These values should be specific
// to your content.
val hdrMetadata = SurfaceEntity.ContentColorMetadata(
colorSpace = SurfaceEntity.ContentColorMetadata.ColorSpace.COLOR_SPACE_BT2020,
colorTransfer = SurfaceEntity.ContentColorMetadata.ColorTransfer.COLOR_TRANSFER_ST2084, // PQ
colorRange = SurfaceEntity.ContentColorMetadata.ColorRange.COLOR_RANGE_LIMITED,
colorSpace = SurfaceEntity.ContentColorMetadata.ColorSpace.BT2020,
colorTransfer = SurfaceEntity.ContentColorMetadata.ColorTransfer.ST2084, // PQ
colorRange = SurfaceEntity.ContentColorMetadata.ColorRange.LIMITED,
maxContentLightLevel = 1000 // Example: 1000 nits
)

// Create a SurfaceEntity, passing the HDR metadata at creation time.
val hdrSurfaceEntity = SurfaceEntity.create(
session = xrSession,
stereoMode = SurfaceEntity.StereoMode.STEREO_MODE_MONO,
stereoMode = SurfaceEntity.StereoMode.MONO,
pose = Pose(Vector3(0.0f, 0.0f, -1.5f)),
shape = SurfaceEntity.Shape.Quad(FloatSize2d(1.0f, 1.0f)),
)
Expand Down