valurl="https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Avocado/glTF/Avocado.gltf"valsceneViewerIntent=Intent(Intent.ACTION_VIEW)valintentUri=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.}
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-23 (世界標準時間)。"],[],[],null,["# Add 3D models to your app\n\nWhen working with 3D models, the Jetpack XR SDK supports the [glTF\n2.0](https://www.khronos.org/glTF/) open standard. When Android XR renders apps built with the\nJetpack XR SDK, 3D models will be rendered with [physically based\nrendering(PBR)](https://en.wikipedia.org/wiki/Physically_based_rendering) techniques specified in the glTF 2.0 standard\n(along with supported [extensions](#gltf-extensions)). Most digital content creation (dcc)\ntools, such as [Autodesk Maya](https://www.autodesk.com/products/maya/overview), [Maxon ZBrush](https://www.maxon.net/en/zbrush),\n[Blender](https://www.blender.org/) and [Spline](https://spline.design/) can export 3D models into\nthe glTF format (`.gltf` or `.glb` files).\n\nIf a [`SpatialEnvironment`](/reference/kotlin/androidx/xr/scenecore/SpatialEnvironment) skybox has been specified by the user or by your\napp, 3D models will be lit with lighting information provided by the environment\nskybox. Reflective materials and specular highlights will also reflect the\nenvironment skybox. If passthrough has been enabled, then the lighting,\nreflections and specular highlights will be based on a simple, bright room with\na single directional light.\n\nFor a quick overview of the supported materials, refer to the [glTF PBR\nProperties](https://www.khronos.org/gltf/pbr/) on the Khronos site.\n\nThere are two primary ways for apps built with the Jetpack XR SDK to load 3D\nmodels.\n\n- Load it into the `ActivitySpace` as described in [Place a 3D model into the\n `ActivitySpace`](#place-3d)\n- Use the built-in [Scene Viewer](#load-3d) through an intent\n\nPlace a 3D model into the ActivitySpace\n---------------------------------------\n\nOnce you have your glTF file, the next step is to add it to the assets directory\nin Android Studio. We recommend creating a `models` directory to better organize\nyour asset types.\n\nTo load the glTF model, call [`GltfModel.create()`](/reference/kotlin/androidx/xr/scenecore/GltfModel#create(androidx.xr.runtime.Session,java.nio.file.Path)).\n\n\n```kotlin\nval gltfModel = GltfModel.create(session, Paths.get(\"models\", \"saturn_rings.glb\"))https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/xr/src/main/java/com/example/xr/scenecore/GltfEntity.kt#L32-L32\n```\n\n\u003cbr /\u003e\n\nAt this point, the model is loaded into memory, but it's not being rendered yet.\nIf you have many 3D models to load or your model is large, it's a good idea to\nload them asynchronously ahead of time. This way, users don't have to wait for\nyour models to be loaded into memory.\n| **Tip:** If your app is going over [Google Play's maximum size\n| limits](https://support.google.com/googleplay/android-developer/answer/9859372#size_limits) due to 3D assets and high resolution textures, you should consider using [Play Asset Delivery](/guide/playcore/asset-delivery) to optimize the delivery of your assets. For more information, see how to [package and distribute apps for\n| Android XR](/develop/xr/package-and-distribute).\n\nWe need to add the glTF into the [`ActivitySpace`](/reference/kotlin/androidx/xr/scenecore/ActivitySpace). Call\n[`GltfModelEntity.create`](/reference/kotlin/androidx/xr/scenecore/GltfModelEntity#create) to create an entity and place it into the\n`ActivitySpace`. As best practice, you should [check that the app is in a state\nwhich allows for spatial capabilities](/develop/xr/jetpack-xr-sdk/check-spatial-capabilities).\n\n\n```kotlin\nif (session.scene.spatialCapabilities\n .hasCapability(SpatialCapabilities.SPATIAL_CAPABILITY_3D_CONTENT)\n) {\n val gltfEntity = GltfModelEntity.create(session, gltfModel)\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/xr/src/main/java/com/example/xr/scenecore/GltfEntity.kt#L38-L42\n```\n\n\u003cbr /\u003e\n\nYou should now see the loaded 3D model when you run your app.\n\n| **Important:** Some 3D content, such as 3D models, will only be visible when the app is in Full Space.\n\nPlace a 3D model into a Compose Volume\n--------------------------------------\n\nWhile you will still need to load the glTF into memory using\n[`GltfModel.create()`](/reference/kotlin/androidx/xr/scenecore/GltfModel#create(androidx.xr.runtime.Session,java.nio.file.Path)), you can place 3D models into a [`Volume`](/reference/kotlin/androidx/xr/compose/subspace/package-summary#Volume(androidx.xr.compose.subspace.layout.SubspaceModifier,kotlin.Function1)) if you\nare creating your UI with Jetpack Compose for XR. Refer to [Use a Volume to\nplace a 3D object in your layout](/develop/xr/jetpack-xr-sdk/develop-ui#use-volume).\n\nAnimate 3D models\n-----------------\n\nAs part of the glTF specification, 3D models can have animations embedded.\nSkeletal (rigged), rigid, morph target (blend shapes) animations are all\nsupported in the Jetpack XR SDK. Material animations created with the\n[`KHR_animation_pointer` glTF extension](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_animation_pointer/README.md) are also supported.\n\nTo play an animation, call [`startAnimation()`](/reference/kotlin/androidx/xr/scenecore/GltfModelEntity#startAnimation(kotlin.Boolean,kotlin.String)) and specify the name of the\nanimation. You can optionally specify whether or not the animation should loop\nindefinitely.\n\n\n```kotlin\ngltfEntity.startAnimation(loop = true, animationName = \"Walk\")https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/xr/src/main/java/com/example/xr/scenecore/GltfEntity.kt#L48-L48\n```\n\n\u003cbr /\u003e\n\nCalling `startAnimation` a second time, the current animation will stop and the\nnew animation will start.\n\nYou can query the current state of the animation through\n[`getAnimationState()`](/reference/kotlin/androidx/xr/scenecore/GltfModelEntity#getAnimationState()).\n\nIf the animation name specified when calling `startAnimation()` doesn't exist,\nthe call silently fails, any running animations stop, and `getAnimationState()`\nreturns `STOPPED`.\n\nLoad a 3D model using Scene Viewer\n----------------------------------\n\nIf you're looking for the simplest way to load a 3D model with basic interaction\ncapabilities, you may opt to [use Scene Viewer as you would on\nmobile](https://developers.google.com/ar/develop/scene-viewer). A key difference between the Scene Viewer on Android XR\nand on mobile is that Scene Viewer only supports the file URI parameter pointing\nto the glTF file and all other parameters are ignored.\n\nScene Viewer is a separate app that is invoked using an intent and runs in Full\nSpace Mode. As a result, when you invoke it, your app will no longer be visible\nand Scene Viewer will have focus. Any [environments](/develop/xr/jetpack-xr-sdk/add-environments) you may have changed\nwill be reset to the user's system preferences.\n\nHere's an example of using an [`Intent`](/reference/android/content/Intent) to view a glTF file in Scene Viewer\non Android XR:\n\n\n```kotlin\nval url =\n \"https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Avocado/glTF/Avocado.gltf\"\nval sceneViewerIntent = Intent(Intent.ACTION_VIEW)\nval intentUri =\n Uri.parse(\"https://arvr.google.com/scene-viewer/1.2\")\n .buildUpon()\n .appendQueryParameter(\"file\", url)\n .build()\nsceneViewerIntent.setData(intentUri)\ntry {\n startActivity(sceneViewerIntent)\n} catch (e: ActivityNotFoundException) {\n // There is no activity that could handle the intent.\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/xr/src/main/java/com/example/xr/scenecore/GltfEntity.kt#L54-L67\n```\n\n\u003cbr /\u003e\n\nFor more information on the interactivity options for Scene Viewer, refer to our\n[3D model design documentation](/design/ui/xr/guides/3d-content).\n\nglTF extensions\n---------------\n\nJetpack XR SDK supports several gfTF extensions that expand the capabilities of\n3D models. These capabilities are available through both the [`GltfEntity`](/reference/kotlin/androidx/xr/scenecore/JxrPlatformAdapter.GltfEntity)\nand Scene Viewer.\n\n- [`KHR_animation_pointer`](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_animation_pointer/README.md)\n- [`KHR_draco_mesh_compression`](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md)\n- [`KHR_lights_punctual`](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_lights_punctual)\n- [`KHR_materials_clearcoat`](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_clearcoat)\n- [`KHR_materials_sheen`](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen)\n- [`KHR_materials_unlit`](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_unlit)\n- [`KHR_materials_variants`](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_variants)\n- [`KHR_mesh_quantization`](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_mesh_quantization)\n- [`KHR_texture_basisu`](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu)\n- [`KHR_texture_transform`](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform)\n- [`EXT_texture_webp`](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_texture_webp/README.md)"]]