WebXR 要求
如需设置能够使用 WebXR 进行 AR 开发的环境,您需要:
使用安全的上下文
安全上下文是一种安全机制,可确保网络资源在传输时提供特定级别的安全性。
您需要一个安全上下文才能通过新功能提供可信 XR 体验。
为了有资格在安全上下文中提供,您的资源必须至少满足以下条件之一:
- 资源必须通过 TLS (
https://
) 递送
- 必须通过
localhost
或 *.localhost
请求资源。
设置端口转发
如果您没有可通过 TLS 访问的开发服务器,仍然可以使用 Chrome 开发者工具的端口转发在安全的上下文中进行开发。通过端口转发,Android 设备可以访问开发机器网络服务器上托管的内容。它会在 Android 设备上创建一个映射到开发机器上的 TCP 端口的监听 TCP 端口。然后,流量便可通过这两个端口之间的 USB 连接传输。
请按照以下步骤设置端口转发:
- 按照 Chrome 开发者工具说明中的设置端口转发中的步骤操作。
- 确保开发工作站上的 Web 服务器正在运行。
- 验证您的连接是否正常运行。在 Android 设备上打开 Google Chrome,然后通过端口转发设置中指定的端口号找到
localhost
,例如 localhost:8000
。
现在,Web 服务器上的资源应该可以在 Android 设备上可见。这些资源是在安全上下文中提供,可以使用 WebXR 功能。
设置受支持的设备
Android 上的 AR 体验只能在支持 ARCore 的设备上运行。确保设备已安装并启用了面向 AR 的 Google Play 服务。
如需验证设备是否已正确配置为运行 WebXR,请在兼容的浏览器中浏览到示例 WebXR 页面。
后续步骤
现在,您已经设置了开发环境以使用 WebXR 打造 AR 体验,接下来您可以:
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2023-12-08。
[null,null,["最后更新时间 (UTC):2023-12-08。"],[[["WebXR AR development requires a secure context (HTTPS, localhost, or *.localhost), a compatible browser, and an ARCore supported device."],["Port forwarding through Chrome DevTools can be used to establish a secure context if a TLS-enabled server is unavailable."],["AR experiences on Android are limited to ARCore supported devices with Google Play Services for AR installed and enabled."],["To verify device and browser compatibility, visit a sample WebXR page like the one linked in the document."],["After setup, you can proceed to create immersive AR sessions and explore further using provided resources."]]],["To enable WebXR AR development, use a web server in a secure context, either via TLS (`https://`) or `localhost`. If TLS is unavailable, use Chrome DevTools' port forwarding to map a port on your development machine to your Android device, ensuring the server is running. Confirm your Android device is ARCore-supported with Google Play Services for AR. Verify the setup by browsing to a sample WebXR page using a compatible browser.\n"]]