用途:本技能面向 CesiumJS v1.144+(ES module 导入),介绍 Primitive API 这一位于 Entity API 之下的低层渲染层,用性能换取便利。核心公式为 Primitive = GeometryInstance[] + Appearance:GeometryInstance 在世界坐标中定位几何体并携带逐实例属性(color、show),Geometry 描述顶点数据,Appearance 提供 GLSL 着色器、渲染状态与可选 Material。Primitive 首次渲染后不可变,几何体不能更改,但可通过 primitive.getGeometryInstanceAttributes(id) 更新逐实例属性。
主要能力:支持单个或多个 GeometryInstance 批量合并为一次绘制调用;通过 modelMatrix 定位体积几何体(Box、Cylinder、Ellipsoid 等),可用 Matrix4.multiply 组合 ENU 锚点与局部偏移;提供 7 种 Appearance(PerInstanceColorAppearance、MaterialAppearance、EllipsoidSurfaceAppearance、PolylineColorAppearance、PolylineMaterialAppearance、DebugAppearance、Appearance 基类),几何体 vertexFormat 必须与 Appearance 匹配;GroundPrimitive 可将几何体贴附到地形或 3D Tiles;PrimitiveCollection 可嵌套分组并统一控制 show。
使用方式:从 "cesium" 导入所需类,创建 Viewer 后向 scene.primitives.add 添加 Primitive;异步几何体编译需监听 scene.postRender 并检查 primitive.ready 后再更新属性;批量体积几何体建议用约 -45° 俯仰角与约 3 倍网格足迹的距离取景,也可用 viewer.camera.flyToBoundingSphere 或 viewer.flyTo 确保可见。
适用场景与限制:适合大规模静态或批量更新的矢量数据、需要手动控制点/线/面缓冲的高吞吐场景。BufferPointCollection、BufferPolylineCollection、BufferPolygonCollection 与 GeoJsonPrimitive 为实验性 API(1.140+/1.142+),使用 flyweight 对象复用;1.141 起 modelMatrix、boundingVolume 等属性只读,1.142 起 boundingVolume 为世界空间,1.143 修复 outlineColor 泄漏。需要 Entity 生命周期、聚类、时间动态属性时仍应使用 GeoJsonDataSource。资料未提供收费、价格与平台信息。