Skip to content

Commit 8e5b5db

Browse files
authored
Merge pull request #26 from android/dec_xr_updates
Updating Hello Android XR for latest Jetpack XR libraries
2 parents 5863b69 + 5e50527 commit 8e5b5db

File tree

7 files changed

+73
-47
lines changed

7 files changed

+73
-47
lines changed

app/src/main/assets/white.png

199 Bytes
Loading

app/src/main/java/com/example/helloandroidxr/ui/components/BugdroidModel.kt

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,20 @@ import androidx.compose.runtime.setValue
2929
import androidx.compose.ui.platform.LocalContext
3030
import androidx.compose.ui.platform.LocalDensity
3131
import androidx.xr.compose.platform.LocalSession
32-
import androidx.xr.compose.spatial.Subspace
32+
import androidx.xr.compose.spatial.PlanarEmbeddedSubspace
3333
import androidx.xr.compose.subspace.SceneCoreEntity
3434
import androidx.xr.compose.subspace.SceneCoreEntitySizeAdapter
3535
import androidx.xr.compose.subspace.layout.SubspaceModifier
3636
import androidx.xr.compose.subspace.layout.scale
3737
import androidx.xr.compose.unit.Meter
3838
import androidx.xr.runtime.math.Vector4
39+
import androidx.xr.scenecore.AlphaMode
3940
import androidx.xr.scenecore.GltfModelEntity
4041
import androidx.xr.scenecore.KhronosPbrMaterial
41-
import androidx.xr.scenecore.KhronosPbrMaterialSpec
42+
import androidx.xr.scenecore.Texture
4243
import com.example.helloandroidxr.bugdroid.BugdroidController
4344
import com.example.helloandroidxr.viewmodel.ModelTransform
45+
import kotlin.io.path.Path
4446

4547
// Bugdroid glb height in meters
4648
private const val bugdroidHeight = 2.08f
@@ -67,41 +69,52 @@ fun BugdroidModel(
6769
}
6870
val gltfModel = bugdroidController.gltfModel
6971
gltfModel?.let { model ->
70-
Subspace {
72+
PlanarEmbeddedSubspace {
7173
val density = LocalDensity.current
7274
var scaleFromLayout by remember { mutableFloatStateOf(1f) }
7375
var pbrMaterial by remember { mutableStateOf<KhronosPbrMaterial?>(null) }
7476
LaunchedEffect(xrSession) {
7577
try {
76-
val spec =
77-
KhronosPbrMaterialSpec.create(
78-
lightingModel = KhronosPbrMaterialSpec.LightingModel.LIT,
79-
blendMode = KhronosPbrMaterialSpec.BlendMode.OPAQUE,
80-
doubleSidedMode = KhronosPbrMaterialSpec.DoubleSidedMode.SINGLE_SIDED,
78+
pbrMaterial = KhronosPbrMaterial.create(
79+
session = xrSession,
80+
alphaMode = AlphaMode.OPAQUE
81+
)
82+
val texture = Texture.create(
83+
session = xrSession,
84+
path = Path("white.png") // Used as a base texture for material properties.
85+
)
86+
pbrMaterial?.setOcclusionTexture(
87+
texture = texture,
88+
strength = modelTransform.materialProperties.ambientOcclusion
89+
)
90+
pbrMaterial?.setBaseColorFactor(
91+
Vector4(
92+
x = modelTransform.materialColor.x,
93+
y = modelTransform.materialColor.y,
94+
z = modelTransform.materialColor.z,
95+
w = modelTransform.materialColor.w
8196
)
82-
pbrMaterial = KhronosPbrMaterial.create(xrSession, spec)
97+
)
8398
} catch (e: Exception) {
8499
Log.e(TAG, "Error creating material", e)
85100
}
86101
}
87102
LaunchedEffect(
88-
pbrMaterial,
89103
modelTransform.materialColor.x,
90104
modelTransform.materialColor.y,
91105
modelTransform.materialColor.z,
92106
modelTransform.materialColor.w,
93-
modelTransform.materialProperties.ambientOcclusion,
94107
modelTransform.materialProperties.metallic,
95108
modelTransform.materialProperties.roughness,
96109
) {
97-
pbrMaterial?.setBaseColorFactors(
110+
pbrMaterial?.setBaseColorFactor(
98111
Vector4(
99112
x = modelTransform.materialColor.x,
100113
y = modelTransform.materialColor.y,
101114
z = modelTransform.materialColor.z,
115+
w = modelTransform.materialColor.w
102116
)
103117
)
104-
pbrMaterial?.setAmbientOcclusionFactor(modelTransform.materialProperties.ambientOcclusion)
105118
pbrMaterial?.setMetallicFactor(modelTransform.materialProperties.metallic)
106119
pbrMaterial?.setRoughnessFactor(modelTransform.materialProperties.roughness)
107120
}

app/src/main/java/com/example/helloandroidxr/ui/components/BugdroidSliderControls.kt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,6 @@ fun MaterialPropertySliders(
313313
Text(text = stringResource(R.string.change_material_factors))
314314
Spacer(modifier = Modifier.padding(10.dp))
315315

316-
Text(text = stringResource(R.string.ambient))
317-
Slider(
318-
value = materialProperties.ambientOcclusion,
319-
onValueChange = { newAmbientOcclusion ->
320-
onMaterialPropertiesChange(
321-
materialProperties.copy(
322-
ambientOcclusion = newAmbientOcclusion
323-
)
324-
)
325-
},
326-
valueRange = MIN_MATERIAL_PROP_VALUE..MAX_MATERIAL_PROP_VALUE,
327-
modifier = Modifier.padding()
328-
)
329-
Text(text = "%.2f".format(materialProperties.ambientOcclusion))
330-
331316
Text(text = stringResource(R.string.metallic))
332317
Slider(
333318
value = materialProperties.metallic,

app/src/main/java/com/example/helloandroidxr/ui/components/SearchBar.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import androidx.compose.foundation.layout.width
2424
import androidx.compose.foundation.shape.CircleShape
2525
import androidx.compose.foundation.text.KeyboardActions
2626
import androidx.compose.foundation.text.KeyboardOptions
27-
import androidx.compose.material.icons.Icons
28-
import androidx.compose.material.icons.filled.Search
2927
import androidx.compose.material3.Icon
3028
import androidx.compose.material3.Surface
3129
import androidx.compose.material3.Text
@@ -42,6 +40,7 @@ import androidx.compose.ui.graphics.Color
4240
import androidx.compose.ui.platform.LocalContext
4341
import androidx.compose.ui.platform.LocalFocusManager
4442
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
43+
import androidx.compose.ui.res.painterResource
4544
import androidx.compose.ui.res.stringResource
4645
import androidx.compose.ui.text.input.ImeAction
4746
import androidx.compose.ui.tooling.preview.Preview
@@ -85,7 +84,14 @@ fun SearchTextBox(
8584
stringResource(R.string.search_product_name),
8685
)
8786
},
88-
leadingIcon = { Icon(Icons.Filled.Search, null) },
87+
leadingIcon = {
88+
// This icon is decorative. The TextField's placeholder text is sufficient for screen
89+
// readers.
90+
Icon(
91+
painter = painterResource(R.drawable.search_24px),
92+
contentDescription = null,
93+
)
94+
},
8995
colors = TextFieldDefaults.colors(
9096
focusedIndicatorColor = Color.Transparent,
9197
unfocusedIndicatorColor = Color.Transparent

app/src/main/java/com/example/helloandroidxr/viewmodel/BugdroidViewModel.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private const val DEFAULT_X_MATERIAL_COLOR = 0.0f
3434
private const val DEFAULT_Y_MATERIAL_COLOR = 1.0f
3535
private const val DEFAULT_Z_MATERIAL_COLOR = 0.0f
3636
private const val DEFAULT_W_MATERIAL_COLOR = 0.0f
37-
private const val DEFAULT_AMBIENT_OCCLUSION = 0.5f
37+
private const val DEFAULT_AMBIENT_OCCLUSION = 1.0f
3838
private const val DEFAULT_METALLIC = 0.0f
3939
private const val DEFAULT_ROUGHNESS = 0.0f
4040
const val MIN_SCALE_VALUE = 0.1f
@@ -176,10 +176,22 @@ class BugdroidViewModel : ViewModel() {
176176
currentState.copy(
177177
modelTransform = currentState.modelTransform.copy(
178178
materialColor = currentState.modelTransform.materialColor.copy(
179-
x = newMaterialColor.x.coerceIn(MIN_MATERIAL_COLOR_VALUE, MAX_MATERIAL_COLOR_VALUE),
180-
y = newMaterialColor.y.coerceIn(MIN_MATERIAL_COLOR_VALUE, MAX_MATERIAL_COLOR_VALUE),
181-
z = newMaterialColor.z.coerceIn(MIN_MATERIAL_COLOR_VALUE, MAX_MATERIAL_COLOR_VALUE),
182-
w = newMaterialColor.w.coerceIn(MIN_MATERIAL_COLOR_VALUE, MAX_MATERIAL_COLOR_VALUE),
179+
x = newMaterialColor.x.coerceIn(
180+
MIN_MATERIAL_COLOR_VALUE,
181+
MAX_MATERIAL_COLOR_VALUE
182+
),
183+
y = newMaterialColor.y.coerceIn(
184+
MIN_MATERIAL_COLOR_VALUE,
185+
MAX_MATERIAL_COLOR_VALUE
186+
),
187+
z = newMaterialColor.z.coerceIn(
188+
MIN_MATERIAL_COLOR_VALUE,
189+
MAX_MATERIAL_COLOR_VALUE
190+
),
191+
w = newMaterialColor.w.coerceIn(
192+
MIN_MATERIAL_COLOR_VALUE,
193+
MAX_MATERIAL_COLOR_VALUE
194+
),
183195
)
184196
)
185197
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:tint="?attr/colorControlNormal"
5+
android:viewportWidth="960"
6+
android:viewportHeight="960">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M784,840L532,588Q502,612 463,626Q424,640 380,640Q271,640 195.5,564.5Q120,489 120,380Q120,271 195.5,195.5Q271,120 380,120Q489,120 564.5,195.5Q640,271 640,380Q640,424 626,463Q612,502 588,532L840,784L784,840ZM380,560Q455,560 507.5,507.5Q560,455 560,380Q560,305 507.5,252.5Q455,200 380,200Q305,200 252.5,252.5Q200,305 200,380Q200,455 252.5,507.5Q305,560 380,560Z" />
10+
</vector>

gradle/libs.versions.toml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[versions]
2-
androidx-runtime = "1.9.2"
3-
agp = "8.13.0"
4-
arcore = "1.0.0-alpha06"
5-
compose = "1.0.0-alpha07"
2+
androidx-runtime = "1.10.0"
3+
agp = "8.13.1"
4+
arcore = "1.0.0-alpha09"
5+
compose = "1.0.0-alpha09"
66
extensionsXr = "1.1.0"
7-
scenecore = "1.0.0-alpha07"
7+
scenecore = "1.0.0-alpha10"
88
kotlinxCoroutinesGuava = "1.10.2"
9-
kotlin = "2.2.0"
9+
kotlin = "2.2.21"
1010
concurrentFuturesKtx = "1.3.0"
11-
activityCompose = "1.10.1"
12-
composeBom = "2025.08.00"
13-
material = "1.12.0"
14-
adaptiveAndroid = "1.1.0"
15-
kotlinAndroid = "2.2.0"
11+
activityCompose = "1.12.1"
12+
composeBom = "2025.12.00"
13+
material = "1.13.0"
14+
adaptiveAndroid = "1.2.0"
15+
kotlinAndroid = "2.2.21"
1616

1717
[libraries]
1818
androidx-arcore = { module = "androidx.xr.arcore:arcore", version.ref = "arcore" }

0 commit comments

Comments
 (0)