xb-world 用于在 XR Blocks 应用中理解真实世界,相关示例见 templates/8_objects、samples/depthmesh 与 src/world/。
主要能力包括平面检测、场景网格重建与物体识别。三种能力相互独立,可按需启用。
平面检测:通过 options.enablePlaneDetection() 启用,检测到的平面会成为世界的一部分;可用 xb.world.placeOnHorizontalSurface(model, {seconds: 30}) 将模型自动放置到检测到的水平面(如地板或桌面)上。
物体检测:需 AI、环境摄像头与深度三者配合(把 2D 检测提升到 3D)。配置包括 options.enableAI()(检测后端,需要密钥,见 xb-ai)、options.enableCamera('environment')、options.enableDepth()、options.world.enableObjectDetection();可用 options.world.objects.showDebugVisualizations = true 显示调试可视化。按需运行检测(如捏合/点击时)使用 xb.world.objects.runDetection(),其解析为放置在检测世界位置的 THREE.Object3D 数组,每项含检测到的世界位姿与元数据。
场景网格:通过 options.world.enableMeshDetection() 启用,options.world.meshes.showDebugVisualizations = true 可视化重建几何。
后端位于 src/world/objects/backends/(GeminiDetectorBackend、MediaPipeDetectorBackend),通过 options.world.objects 选择。使用 Gemini 后端进行物体检测时,会将摄像头帧发送给 Gemini(见 xb-ai 及 AGENTS.md 中的 API 密钥指引)。具体收费、价格与平台支持情况资料未提供。