-
Notifications
You must be signed in to change notification settings - Fork 361
Expand file tree
/
Copy pathGltfEntity.kt
More file actions
67 lines (61 loc) · 2.52 KB
/
GltfEntity.kt
File metadata and controls
67 lines (61 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* 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 android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import androidx.activity.ComponentActivity
import androidx.xr.runtime.Session
import androidx.xr.scenecore.GltfModel
import androidx.xr.scenecore.GltfModelEntity
import androidx.xr.scenecore.SpatialCapability
import androidx.xr.scenecore.scene
import java.nio.file.Paths
private suspend fun loadGltfFile(session: Session) {
// [START androidxr_scenecore_gltfmodel_create]
val gltfModel = GltfModel.create(session, Paths.get("models", "saturn_rings.glb"))
// [END androidxr_scenecore_gltfmodel_create]
}
private fun createModelEntity(session: Session, gltfModel: GltfModel) {
// [START androidxr_scenecore_gltfmodelentity_create]
if (session.scene.spatialCapabilities.contains(SpatialCapability.SPATIAL_3D_CONTENT)) {
val gltfEntity = GltfModelEntity.create(session, gltfModel)
}
// [END androidxr_scenecore_gltfmodelentity_create]
}
private fun animateEntity(gltfEntity: GltfModelEntity) {
// [START androidxr_scenecore_gltfmodelentity_animation]
gltfEntity.startAnimation(loop = true, animationName = "Walk")
// [END androidxr_scenecore_gltfmodelentity_animation]
}
private fun ComponentActivity.startSceneViewer() {
// [START androidxr_scenecore_sceneviewer]
val url =
"https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Avocado/glTF/Avocado.gltf"
val sceneViewerIntent = Intent(Intent.ACTION_VIEW)
val intentUri =
Uri.parse("https://arvr.google.com/scene-viewer/1.2")
.buildUpon()
.appendQueryParameter("file", url)
.build()
sceneViewerIntent.setData(intentUri)
try {
startActivity(sceneViewerIntent)
} catch (e: ActivityNotFoundException) {
// There is no activity that could handle the intent.
}
// [END androidxr_scenecore_sceneviewer]
}