Primitive

external class Primitive(options: Primitive.ConstructorOptions? = definedExternally)(source)

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.

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.

Combining multiple instances into one primitive is called batching, and significantly improves performance for static data. Instances can be individually picked; Scene.pick returns their GeometryInstance.id. Using per-instance appearances like PerInstanceColorAppearance, each instance can also have a unique color.

Geometry can either be created and batched on a web worker or the main thread. The first two examples show geometry that will be created on a web worker by using the descriptions of the geometry. The third example shows how to create the geometry on the main thread by explicitly calling the createGeometry method.

// 1. Draw a translucent ellipse on the surface with a checkerboard pattern
const instance = new GeometryInstance({
geometry : new EllipseGeometry({
center : Cartesian3.fromDegrees(-100.0, 20.0),
semiMinorAxis : 500000.0,
semiMajorAxis : 1000000.0,
rotation : Math.PI_OVER_FOUR,
vertexFormat : VertexFormat.POSITION_AND_ST
}),
id : 'object returned when this instance is picked and to get/set per-instance attributes'
});
scene.primitives.add(new Primitive({
geometryInstances : instance,
appearance : new EllipsoidSurfaceAppearance({
material : Material.fromType('Checkerboard')
})
}));
// 2. Draw different instances each with a unique color
const rectangleInstance = new GeometryInstance({
geometry : new RectangleGeometry({
rectangle : Rectangle.fromDegrees(-140.0, 30.0, -100.0, 40.0),
vertexFormat : PerInstanceColorAppearance.VERTEX_FORMAT
}),
id : 'rectangle',
attributes : {
color : new ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5)
}
});
const ellipsoidInstance = new GeometryInstance({
geometry : new EllipsoidGeometry({
radii : new Cartesian3(500000.0, 500000.0, 1000000.0),
vertexFormat : VertexFormat.POSITION_AND_NORMAL
}),
modelMatrix : Matrix4.multiplyByTranslation(Transforms.eastNorthUpToFixedFrame(
Cartesian3.fromDegrees(-95.59777, 40.03883)), new Cartesian3(0.0, 0.0, 500000.0), new Matrix4()),
id : 'ellipsoid',
attributes : {
color : ColorGeometryInstanceAttribute.fromColor(Color.AQUA)
}
});
scene.primitives.add(new Primitive({
geometryInstances : [rectangleInstance, ellipsoidInstance],
appearance : new PerInstanceColorAppearance()
}));
// 3. Create the geometry on the main thread.
scene.primitives.add(new Primitive({
geometryInstances : new GeometryInstance({
geometry : EllipsoidGeometry.createGeometry(new EllipsoidGeometry({
radii : new Cartesian3(500000.0, 500000.0, 1000000.0),
vertexFormat : VertexFormat.POSITION_AND_NORMAL
})),
modelMatrix : Matrix4.multiplyByTranslation(Transforms.eastNorthUpToFixedFrame(
Cartesian3.fromDegrees(-95.59777, 40.03883)), new Cartesian3(0.0, 0.0, 500000.0), new Matrix4()),
id : 'ellipsoid',
attributes : {
color : ColorGeometryInstanceAttribute.fromColor(Color.AQUA)
}
}),
appearance : new PerInstanceColorAppearance(),
asynchronous : false
}));

See also

Constructors

Link copied to clipboard
constructor(options: Primitive.ConstructorOptions? = definedExternally)

Types

Link copied to clipboard
sealed interface ConstructorOptions

Properties

Link copied to clipboard

When true, each geometry instance will only be pickable with Scene.pick. When false, GPU memory is saved. *

Link copied to clipboard

The Appearance used to shade this primitive. Each geometry instance is shaded with the same appearance. Some appearances, like PerInstanceColorAppearance allow giving each instance unique properties.

Link copied to clipboard

Determines if the geometry instances will be created and batched on a web worker.

Link copied to clipboard

When true, geometry vertices are compressed, which will save memory.

Link copied to clipboard

When true, the renderer frustum culls and horizon culls the primitive's commands based on their bounding volume. Set this to false for a small performance gain if you are manually culling the primitive.

Link copied to clipboard

This property is for debugging only; it is not for production use nor is it optimized.

Link copied to clipboard

The Appearance used to shade this primitive when it fails the depth test. Each geometry instance is shaded with the same appearance. Some appearances, like PerInstanceColorAppearance allow giving each instance unique properties.

Link copied to clipboard

The geometry instances rendered with this primitive. This may be undefined if options.releaseGeometryInstances is true when the primitive is constructed.

Link copied to clipboard

Determines if geometry vertex attributes are interleaved, which can slightly improve rendering performance.

Link copied to clipboard

The 4x4 transformation matrix that transforms the primitive (all geometry instances) from model to world coordinates. When this is the identity matrix, the primitive is drawn in world coordinates, i.e., Earth's WGS84 coordinates. Local reference frames can be used by providing a different transformation matrix, like that returned by Transforms.eastNorthUpToFixedFrame.

Link copied to clipboard

Determines if the primitive is complete and ready to render. If this property is true, the primitive will be rendered the next time that Primitive.update is called.

Link copied to clipboard

When true, the primitive does not keep a reference to the input geometryInstances to save memory.

Link copied to clipboard

Determines whether this primitive casts or receives shadows from light sources.

Link copied to clipboard

Determines if the primitive will be shown. This affects all geometry instances in the primitive.

Link copied to clipboard

When true, geometry vertices are optimized for the pre and post-vertex-shader caches.

Functions

Link copied to clipboard
fun destroy()

Destroys the WebGL resources held by this object. Destroying an object allows for deterministic release of WebGL resources, instead of relying on the garbage collector to destroy this object.

Link copied to clipboard

Returns the modifiable per-instance attributes for a GeometryInstance.

Link copied to clipboard

Returns true if this object was destroyed; otherwise, false.

Link copied to clipboard
fun update()

Called when Viewer or CesiumWidget render the scene to get the draw commands needed to render this primitive.