1+ package com.example.xr.scenecore
2+
3+ import android.content.Intent
4+ import android.net.Uri
5+ import androidx.activity.ComponentActivity
6+ import androidx.xr.scenecore.GltfModel
7+ import androidx.xr.scenecore.GltfModelEntity
8+ import androidx.xr.scenecore.Session
9+ import androidx.xr.scenecore.SpatialCapabilities
10+ import androidx.xr.scenecore.getSpatialCapabilities
11+ import kotlinx.coroutines.guava.await
12+
13+ private suspend fun loadGltfFile (session : Session ) {
14+ // [START androidxr_scenecore_gltfmodel_create]
15+ val gltfModel = GltfModel .create(session, " models/saturn_rings.glb" ).await()
16+ // [END androidxr_scenecore_gltfmodel_create]
17+ }
18+
19+ private fun createModelEntity (session : Session , gltfModel : GltfModel ) {
20+ // [START androidxr_scenecore_gltfmodelentity_create]
21+ if (session.getSpatialCapabilities()
22+ .hasCapability(SpatialCapabilities .SPATIAL_CAPABILITY_3D_CONTENT )
23+ ) {
24+ val gltfEntity = GltfModelEntity .create(session, gltfModel)
25+ }
26+ // [END androidxr_scenecore_gltfmodelentity_create]
27+ }
28+
29+ private fun animateEntity (gltfEntity : GltfModelEntity ) {
30+ // [START androidxr_scenecore_gltfmodelentity_animation]
31+ gltfEntity.startAnimation(loop = true , animationName = " Walk" )
32+ // [END androidxr_scenecore_gltfmodelentity_animation]
33+ }
34+
35+ private fun ComponentActivity.startSceneViewer () {
36+ // [START androidxr_scenecore_sceneviewer]
37+ val url =
38+ " https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/FlightHelmet/glTF/FlightHelmet.gltf"
39+ val sceneViewerIntent = Intent (Intent .ACTION_VIEW )
40+ val intentUri =
41+ Uri .parse(" https://arvr.google.com/scene-viewer/1.2" )
42+ .buildUpon()
43+ .appendQueryParameter(" file" , url)
44+ .build()
45+ sceneViewerIntent.setDataAndType(intentUri, " model/gltf-binary" )
46+ startActivity(sceneViewerIntent)
47+ // [END androidxr_scenecore_sceneviewer]
48+ }
0 commit comments