在 Android NDK (C) 中使用周围的建筑物和地形
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Streetscape Geometry API 提供场景中地形、建筑物或其他结构的几何图形。该几何图形可用于通过碰撞检测 API 进行遮挡、渲染或放置 AR 内容。街景几何图形数据是通过 Google 街景图像获取的。
设置 Geospatial API
如需使用街景几何图形,您需要在项目中设置 Geospatial API。
按照启用 Geospatial API 中的说明设置 Geospatial API。
启用街景几何图形
当 ArGeospatialMode
设置为 ArGeospatialModeEnabled
且 ArStreetscapeGeometryMode
设置为 ArStreetscapeGeometryModeEnabled
时,Geospatial API 会获取街景几何图形数据。
// Create a session config.
ArConfig* ar_config = NULL;
ArConfig_create(ar_session, &ar_config);
// Enable the Geospatial API.
ArConfig_setGeospatialMode(ar_session, ar_config, AR_GEOSPATIAL_MODE_ENABLED);
CHECK(ArSession_configure(ar_session, ar_config) == AR_SUCCESS);
// Enable Streetscape Geometry.
ArConfig_setStreetscapeGeometryMode(ar_session, ar_config, AR_STREETSCAPE_GEOMETRY_MODE_ENABLED);
CHECK(ArSession_configure(ar_session, ar_config) == AR_SUCCESS);
// Release config resources.
ArConfig_destroy(ar_config);
在 ARCore 会话中获取街景几何图形
使用
ArSession_getAllTrackables()
和
AR_TRACKABLE_STREETSCAPE_GEOMETRY
过滤结果。
ArTrackableList* trackable_list = NULL;
ArTrackableList_create(ar_session, &trackable_list);
ArSession_getAllTrackables(ar_session, AR_TRACKABLE_STREETSCAPE_GEOMETRY, trackable_list);
ArStreetscapeGeometry
包含建筑物相关信息:
建筑物 LOD 1
AR_STREETSCAPE_GEOMETRY_QUALITY_BUILDING_LOD_1
由向上延伸到平顶的建筑物平面图组成。建筑物高度可能不准确。

构建 LOD 2
AR_STREETSCAPE_GEOMETRY_QUALITY_BUILDING_LOD_2
将具有更高的几何保真度。网格墙和屋顶将更贴近建筑物的形状。烟囱或屋顶通风口等较小的建筑物特征可能仍会超出网格范围。

ArMesh
是一个多边形网格,表示街景几何图形的表面重建。
每个 ArMesh
都包含一个顶点缓冲区和一个索引缓冲区:
您可以通过以下两种方式将 AR 内容附加到街景几何图形:
ArFrame_hitTest
可用于对街景几何图形执行点击测试。如果找到了交叉点,ArHitResult
将包含与命中位置相关的姿势信息,以及对命中的 ArStreetscapeGeometry
的引用。此 Streetscape Geometry 可以传递给 ArTrackable_acquireNewAnchor()
,以创建与其关联的锚点。
ArHitResultList *hit_result_list = NULL;
ArHitResult *hit_result = NULL;
ArHitResultList_create(ar_session, &hit_result_list);
ArHitResult_create(ar_session, &hit_result);
ArFrame_hitTestRay(ar_session, ar_frame, origin, direction, hit_result_list);
ArHitResultList_getItem(ar_session, hit_result_list, 0, hit_result);
ArAnchor *out_anchor = NULL;
ArStatus status = ArHitResult_acquireNewAnchor(ar_session, hit_result, &out_anchor);
CHECK(status == AR_SUCCESS);
启用地理深度
Geospatial Depth 将 Streetscape Geometry 与本地传感器输入相结合,以增强深度数据。启用 Geospatial Depth 后,输出深度和原始深度图片会被修改,以包含光栅化街景几何图形以及本地观察到的深度。这可能会提高使用深度数据估算姿势的准确性。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eThe Streetscape Geometry APIs offer terrain and building geometry from Google Street View for occlusion, rendering, and AR content placement.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize this feature, enable the Geospatial and Streetscape Geometry modes in your ARCore session configuration.\u003c/p\u003e\n"],["\u003cp\u003eYou can access Streetscape Geometry data using \u003ccode\u003eArSession_getAllTrackables()\u003c/code\u003e and filter the results by \u003ccode\u003eAR_TRACKABLE_STREETSCAPE_GEOMETRY\u003c/code\u003e to obtain \u003ccode\u003eArStreetscapeGeometry\u003c/code\u003e objects, which include mesh and quality details.\u003c/p\u003e\n"],["\u003cp\u003eTwo methods exist for attaching AR content: using Geospatial Depth and Depth hit-test (recommended), or creating anchors directly on \u003ccode\u003eArStreetscapeGeometry\u003c/code\u003e using \u003ccode\u003eArTrackable_acquireNewAnchor()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eHit-testing against Streetscape Geometry allows interaction and anchor placement, enabling you to align and integrate virtual objects with the real-world environment.\u003c/p\u003e\n"]]],["Streetscape Geometry APIs provide data on terrain and building structures, sourced from Google Street View, for occlusion, rendering, or AR content placement. To utilize this, enable the Geospatial API and set `ArGeospatialMode` and `ArStreetscapeGeometryMode` to enabled. Retrieve geometry using `ArSession_getAllTrackables()`. Each geometry includes type, mesh, origin, and quality data. `ArMesh` details vertex and index buffers. Content can be attached through Geospatial Depth or anchors. Hit-testing against geometry is possible via `ArFrame_hitTest`, and Geospatial Depth enhances depth data.\n"],null,["# Use buildings and terrain around you on Android NDK (C)\n\nThe Streetscape Geometry APIs provide the geometry of terrain, buildings, or other structures in a scene. The geometry can be used for occlusion, rendering, or placing AR content via hit-test APIs. Streetscape Geometry data is obtained through Google Street View imagery.\n\nSet up the Geospatial API\n-------------------------\n\nTo use Streetscape Geometry, you'll need to set up the Geospatial API in your project.\nFollow instructions on [Enabling the Geospatial API](/ar/develop/c/geospatial/enable) to set up the Geospatial API.\n\nEnable Streetscape Geometry\n---------------------------\n\nThe Geospatial API obtains Streetscape Geometry data when the [`ArGeospatialMode`](/ar/reference/c/group/ar-config#argeospatialmode) is set to [`ArGeospatialModeEnabled`](/ar/reference/c/group/ar-config#ar_geospatial_mode_enabled) and [`ArStreetscapeGeometryMode`](/ar/reference/c/group/ar-config#arstreetscapegeometrymode) is set to [`ArStreetscapeGeometryModeEnabled`](/ar/reference/c/group/ar-config#ar_streetscape_geometry_mode_enabled). \n\n```c\n// Create a session config.\nArConfig* ar_config = NULL;\nArConfig_create(ar_session, &ar_config);\n\n// Enable the Geospatial API.\nArConfig_setGeospatialMode(ar_session, ar_config, AR_GEOSPATIAL_MODE_ENABLED);\nCHECK(ArSession_configure(ar_session, ar_config) == AR_SUCCESS);\n\n// Enable Streetscape Geometry.\nArConfig_setStreetscapeGeometryMode(ar_session, ar_config, AR_STREETSCAPE_GEOMETRY_MODE_ENABLED);\nCHECK(ArSession_configure(ar_session, ar_config) == AR_SUCCESS);\n\n// Release config resources.\nArConfig_destroy(ar_config);\n```\n\nObtain Streetscape Geometry in an ARCore session\n------------------------------------------------\n\nUse [`ArSession_getAllTrackables()`](/ar/reference/c/group/ar-session#arsession_getalltrackables) and use [`AR_TRACKABLE_STREETSCAPE_GEOMETRY`](/ar/reference/c/group/ar-trackable#ar_trackable_streetscape_geometry) to filter results.\n\n\u003cbr /\u003e\n\n```c\nArTrackableList* trackable_list = NULL;\nArTrackableList_create(ar_session, &trackable_list);\nArSession_getAllTrackables(ar_session, AR_TRACKABLE_STREETSCAPE_GEOMETRY, trackable_list);\n```\n\nUnderstand [`ArStreetscapeGeometry`](/ar/reference/c/group/ar-streetscape-geometry)\n-----------------------------------------------------------------------------------\n\n[`ArStreetscapeGeometry`](/ar/reference/c/group/ar-streetscape-geometry) contains information about a building:\n\n- [`ArStreetscapeGeometry_getType()`](/ar/reference/c/group/ar-streetscape-geometry#arstreetscapegeometry_gettype) \n Identifies the StreetscapeGeometry as either terrain or a building.\n- [`ArStreetscapeGeometry_acquireMesh()`](/ar/reference/c/group/ar-streetscape-geometry#arstreetscapegeometry_acquiremesh) \n Obtain a polygon [`ArMesh`](/ar/reference/c/group/ar-mesh) that corresponds to this terrain or building.\n- [`ArStreetscapeGeometry_getMeshPose()`](/ar/reference/c/group/ar-streetscape-geometry#arstreetscapegeometry_getmeshpose) \n Describes the origin of the geometry. All points in the [`ArMesh`](/ar/reference/c/group/ar-mesh) should be transformed by [`ArStreetscapeGeometry_getMeshPose()`](/ar/reference/c/group/ar-streetscape-geometry#arstreetscapegeometry_getmeshpose).\n- [`ArStreetscapeGeometry_getQuality()`](/ar/reference/c/group/ar-streetscape-geometry#arstreetscapegeometry_getquality) \n Provides the quality of the mesh data. Levels of detail are described in the [CityGML 2.0 standard](https://portal.ogc.org/files/?artifact_id=16675).\n\n### Building LOD 1\n\n[`AR_STREETSCAPE_GEOMETRY_QUALITY_BUILDING_LOD_1`](/ar/reference/c/group/ar-streetscape-geometry#ar_streetscape_geometry_quality_building_lod_1) consists of building footprints extruded upwards to a flat top. Building heights may be inaccurate.\n\n### Building LOD 2\n\n[`AR_STREETSCAPE_GEOMETRY_QUALITY_BUILDING_LOD_2`](/ar/reference/c/group/ar-streetscape-geometry#ar_streetscape_geometry_quality_building_lod_2) will have higher fidelity geometry. Mesh walls and roofs will more closely match the building's shape. Smaller features like chimneys or roof vents may still poke outside of the mesh.\n\nUnderstand [`ArMesh`](/ar/reference/c/group/ar-mesh)\n----------------------------------------------------\n\n[`ArMesh`](/ar/reference/c/group/ar-mesh) is a polygon mesh representing a surface reconstruction of the Streetscape Geometry.\n\nEach [`ArMesh`](/ar/reference/c/group/ar-mesh) includes a vertex buffer and index buffer:\n\n- [`ArMesh_getVertexListSize()`](/ar/reference/c/group/ar-mesh#armesh_getvertexlistsize) \n Retrieves the number of vertices in this mesh.\n- [`ArMesh_getVertexList()`](/ar/reference/c/group/ar-mesh#armesh_getvertexlist) \n Obtain the concatenated positions of mesh vertices, in coordinates relative to [`ArStreetscapeGeometry_getMeshPose()`](/ar/reference/c/group/ar-streetscape-geometry#arstreetscapegeometry_getmeshpose).\n- [`ArMesh_getIndexListSize()`](/ar/reference/c/group/ar-mesh#armesh_getindexlistsize) \n Retrieves the number of indices in this mesh.\n- [`ArMesh_getIndexList()`](/ar/reference/c/group/ar-mesh#armesh_getindexlist) \n Obtain the indexes of vertices that make up a face.\n\nAttach AR content to a [`ArStreetscapeGeometry`](/ar/reference/c/group/ar-streetscape-geometry)\n-----------------------------------------------------------------------------------------------\n\nThere are two ways to attach AR content to Streetscape Geometry:\n\n\u003cbr /\u003e\n\n- Enable [Geospatial Depth](/ar/develop/c/depth/geospatial-depth) and use a [Depth hit-test](/ar/develop/c/depth/developer-guide#depth_hit-test). This is the recommended and easier method.\n- Use [`ArTrackable_acquireNewAnchor()`](/ar/reference/c/group/ar-trackable#artrackable_acquirenewanchor) to create an anchor at a given pose attached to a [`ArStreetscapeGeometry`](/ar/reference/c/group/ar-streetscape-geometry). This anchor will inherit its tracking state from the parent [`ArStreetscapeGeometry`](/ar/reference/c/group/ar-streetscape-geometry).\n\n### Perform a hit-test against [`ArStreetscapeGeometry`](/ar/reference/c/group/ar-streetscape-geometry)\n\n[`ArFrame_hitTest`](/ar/reference/c/group/ar-frame#arframe_hittest) can be used to hit-test against Streetscape Geometry. If intersections are found, [`ArHitResult`](/ar/reference/c/group/ar-hit-result) contains pose information about the hit location as well as a reference to the [`ArStreetscapeGeometry`](/ar/reference/c/group/ar-streetscape-geometry) which was hit. This Streetscape Geometry can be passed to [`ArTrackable_acquireNewAnchor()`](/ar/reference/c/group/ar-trackable#artrackable_acquirenewanchor) to create an anchor attached to it. \n\n```c\nArHitResultList *hit_result_list = NULL;\nArHitResult *hit_result = NULL;\nArHitResultList_create(ar_session, &hit_result_list);\nArHitResult_create(ar_session, &hit_result);\n\nArFrame_hitTestRay(ar_session, ar_frame, origin, direction, hit_result_list);\nArHitResultList_getItem(ar_session, hit_result_list, 0, hit_result);\n\nArAnchor *out_anchor = NULL;\nArStatus status = ArHitResult_acquireNewAnchor(ar_session, hit_result, &out_anchor);\nCHECK(status == AR_SUCCESS);\n```\n\nEnable Geospatial Depth\n-----------------------\n\n[Geospatial Depth](/ar/develop/c/depth/geospatial-depth) combines Streetscape Geometry\nwith local sensor input to enhance depth data. When Geospatial Depth is enabled,\nthe output depth and raw depth images are modified to include rasterized Streetscape Geometry in addition to locally observed depth.\nThis may improve the accuracy of poses using Depth."]]