Detailed introduction and cases of Primitive in Cesium

Cesium from entry to project implementation general directory: click

Detailed introduction to Primitive in Cesium

In Cesium, Primitive is a basic primitive used to represent geometric shapes, materials and other properties in 3D scenes. Primitives are defined through a set of properties that describe how geometry and materials are rendered. Primitive types supported in Cesium include points, lines, surfaces, models, etc.

The following is a detailed introduction to some properties and methods of Primitive in Cesium:

  1. geometry: Used to define primitive geometric shapes, which can be Cesium's built-in geometric shapes (such as BoxGeometry, CircleGeometry, CylinderGeometry, etc.) or developer-defined geometric shapes.
  2. appearance: Used to define the appearance of Primitive, including properties such as material, color, and transparency. It can be Cesium's built-in material (such as ColorMaterial, ImageMaterial, CheckerboardMaterial, etc.), or it can be a developer-defined material.
  3. modelMatrix: used to define the transformation matrix of Primitive, which can be used to translate, rotate and scale Primitive.
  4. show: used to define whether Primitive is visible, the default value is true.
  5. allowPicking: used to define whether Primitive can be selected, the default value is true.
  6. release: used to release resources occupied by Primitive to avoid memory leaks.
  7. update: used to update Primitive properties, such as geometry, material, transformation matrix, etc.
  8. destroy: used to destroy Primitive and release occupied resources.

In addition to the above properties and methods, Primitive also has some events and callback functions that can be used to handle mouse events, keyboard events, collision detection, etc.

In short, Primitive is the most basic primitive in Cesium. By setting attributes such as geometric shapes and materials, 3D graphics of various shapes can be presented.

Primitive case in Cesium

The following is a simple case using Primitive in Cesium to create a red cube:

javascriptCopy code// 创建Cesium Viewer对象
var viewer = new Cesium.Viewer('cesiumContainer');

// 创建Geometry对象
var geometry = new Cesium.BoxGeometry({
    vertexFormat: Cesium.VertexFormat.POSITION_ONLY
});

// 创建Appearance对象
var appearance = new Cesium.MaterialAppearance({
    material: Cesium.Material.fromType('Color', {
        color: Cesium.Color.RED
    })
});

// 创建Primitive对象
var primitive = new Cesium.Primitive({
    geometryInstances: new Cesium.GeometryInstance({
        geometry: geometry
    }),
    appearance: appearance
});

// 添加Primitive对象到场景中
viewer.scene.primitives.add(primitive);

In the above case, we first created a Cesium Viewer object and then created a BoxGeometry object to define the geometry of the cube. Next, we created a MaterialAppearance object to define the appearance of the cube, including material, color, transparency and other properties. Finally, we create a Primitive object and pass it the BoxGeometry and MaterialAppearance for rendering the cube. Finally, we add the Primitive object to the scene and you can see a red cube in the Cesium Viewer.

This is just a simple case of Primitive in Cesium. In fact, Primitive also supports many other properties and methods that can be used to create more complex 3D scenes. Developers can refer to Cesium's official documentation to learn more about Primitive information and usage.
Welcome to follow my original public account [GISer World]. This sharing ends here.
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_44857463/article/details/129381862