> 文章列表 > 了解Cesium场景的primitives属性

了解Cesium场景的primitives属性

了解Cesium场景的primitives属性

之前显示3d tiles的代码都是,scene.primitives.add(xxx);都是加到场景下的primitives里面;
看一下什么是场景的primitives属性;

看一下手册,

primitives : PrimitiveCollectione
Gets the collection of primitives.
primitives是PrimitiveCollectione,集合类型;

new Cesium.PrimitiveCollection(options)
A collection of primitives. This is most often used with Scene#primitives, but PrimitiveCollection is also a primitive itself so collections can be added to collections forming a hierarchy.
一个primitives的集合。多数情况使用的是Scene.primitives,。。。。。。;

new Cesium.Primitive(options)
A primitive represents geometry in the Scene. The geometry can be from a single GeometryInstance as shown in example 1 below, or from an array of instances, even if the geometry is from different geometry types, e.g., an RectangleGeometry and an EllipsoidGeometry as shown in Code Example 2.
一个primitive表示场景中的几何图形几何图形可以是一个单独的如例1显示的几何实例,或者是几何实例的数组,也可以是不同的几何图形类型,如例2的RectangleGeometry和EllipsoidGeometry。

A primitive combines geometry instances with an Appearance that describes the full shading, including Material and RenderState. Roughly, the geometry instance defines the structure and placement, and the appearance defines the visual characteristics. Decoupling geometry and appearance allows us to mix and match most of them and add a new geometry or appearance independently of each other.
一个primitive组合多个几何图形实例,包括材质,一次性渲染显示。

geometry
n:几何,几何学

Primitive由两个部分组成:
    几何形状(Geometry):定义了Primitive的结构,例如三角形、线条、点等
    外观(Appearance ):定义Primitive的着色(Sharding),包括GLSL(OpenGL着色语言,OpenGL Shading Language)顶点着色器和片段着色器( vertex and fragment shaders),以及渲染状态(render state)

可以用如下代码枚举primitives中的单个primitive,
const primitives = scene.primitives;
const length = primitives.length;
for (let i = 0; i < length; ++i) {
  const p = primitives.get(i);
......
}