如何在Android XR应用的Scene Viewer中设置3D模型初始位姿?
如何在Android XR应用的Scene Viewer中设置3D模型初始位置与姿态
Scene Viewer支持通过URL查询参数直接指定3D模型的初始姿态和初始位置,无需修改模型文件,直接在启动Intent的Uri中添加对应参数即可实现需求:
核心参数说明
initialRotation:设置模型初始旋转姿态,格式为y,<角度值>,单位是度,<角度值>即为绕Y轴的旋转角度(例如顺时针转90度填y,90)。若需多轴旋转,可扩展为x,<x角度>,y,<y角度>,z,<z角度>。initialPosition:设置模型初始位置偏移,格式为<X偏移>,<Y偏移>,<Z偏移>,单位是米。其中Z轴正方向朝向用户,沿Z轴移动就调整第三个值(例如向前移0.5米填0,0,0.5)。
修改后的代码示例
class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { AppTheme { val intent = sceneViewerWithIntent() startActivity(intent) } } } } fun sceneViewerWithIntent(): Intent { val intent = Intent(Intent.ACTION_VIEW) val domain = "https://raw.githubusercontent.com/" val path = "KhronosGroup/glTF-Sample-Models/refs/heads/main/2.0/AntiqueCamera/glTF-Binary/AntiqueCamera.glb" val type = "model/gltf-binary" val data = Uri .parse("https://arvr.google.com/scene-viewer/1.2") .buildUpon() .appendQueryParameter("file", domain + path) // 添加初始绕Y轴旋转90度 .appendQueryParameter("initialRotation", "y,90") // 添加沿Z轴向前移动0.5米 .appendQueryParameter("initialPosition", "0,0,0.5") .build() intent.setDataAndType(data, type) return intent }
内容的提问来源于stack exchange,提问作者dàhóngpáo
相关产品推荐
相关产品推荐

