本系列文章:
一、利用Primitive图元类加载点位
一、对昨日的补充
对Cesium的轻度使用者来说,只是简单加载几个模型,Entity类已经可以满足基本需求。但是对于大范围、大数据量、交互复杂的场景,Primitive类是更好的选择。这里翻译几段摘自Cesium官网的介绍:
CesiumJS has a rich API for spatial data that can be split into two categories: a low-level
Primitive APIgeared towards graphics developers, and a high-levelEntity APIfor data-driven visualization.
译文:Cesium有丰富的API用于空间数据展示。针对图形学开发者提供了一个底层的Primitive API,对于数据驱动的可视化需求提供了一个高层级的Entity API。
上篇文章提到,Primitive类由一个或多个几何实体(geomnetryInstance)及渲染这些实体的材质(Appearance)构成。几何实体包含几何对象(geometry)、模型矩阵(modalMatrix)、几何id(id)、几何属性(attributes)。我们常见几何图形,包括线、面、椭圆、椭球等等,都可以被Geometry类来定义。而appearance与geometryInstance的关系就像css和html的关系,前者定义了外观,后者定义了结构。贴一张官网的图捋一捋这几个类:
The benefits of using geometries and appearances are:
- Performance - When drawing a large number of static primitives (such as polygon for each zip code in the United States), using geometries directly allows us to combine them into a single geometry to reduce CPU overhead and better utilize the GPU. Combining primitives is done on a web worker to keep the UI responsive.
- Flexibility - Primitives combine geometry and appearance. By decoupling them, we can modify each independently. We can add new geometries that are compatible with many different appearances and vice-versa.
- Low-level access - Appearances provide close-to-the-metal access to rendering without having to worry about all the details of using the Renderer directly.
Appearances make it easy to:
- Write full GLSL vertex and fragment shaders.
- Use custom render state.
译文:
使用几何和材质的优点如下:
提升性能表现——当需要画大量的静态图元时(例如polygon对应美国的每个邮政编码),直接用几何方式可以让我们把众多几何图元组合成一个(来绘制),从而减少CPU的开销从而更好利用GPU。组合图元实在WEB Worker上面完成的,从而保证UI的响应速度。
灵活性——图元是几何和材质的结合体,通过把他们两个解耦出来,我们可以独立地修改他们其中任何一项。我们可以添加同一个geometry,不同材质的多种几何体,反过来也一样。
更接近底层——材质提供接近底层的渲染方式,不用担心Renderer类的渲染细节。
本系列文章均从Primitive类入手,尝试针对不同的Geometry,不同数据量的三维数据,做出较为理想的性能实践。
二、线条类简单介绍
GeometryInstance:包括geometry、modalMatrix、id、attributes四个属性,本篇暂不展开,只介绍geometry属性。
Appearance:定义了渲染instance所用的材质。
2.1 Geometry
A geometry representation with attributes forming vertices and optional index data defining primitives. Geometries and an
Appearance, which describes the shading, can be assigned to aPrimitivefor visualization. APrimitivecan be created from many heterogeneous - in many cases - geometries for performance.
译文:
(geometry是)一种通过属性形成顶点,并通过可选的数据次序来定义图元的几何表现形式。geometries和定义纹理的材质共同组合起来,赋给Primitive类来进行可视化。一个图元可以由多种异构的,在不同情况下的集合体来创建,以提升性能。
这段可以简单理解为,Geometry类定义了图元的基本结构,Geometry和Appearance结合起来构成图元,Geometry类可以派生出多种异构的几何类,来解决不同情况下的需求。