new Primitive(optionsopt)
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.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Object with the following properties:
Properties
|
- Source:
- See:
Examples
// 1. Draw a translucent ellipse on the surface with a checkerboard pattern
var instance = new Cesium.GeometryInstance({
geometry : new Cesium.EllipseGeometry({
center : Cesium.Cartesian3.fromDegrees(-100.0, 20.0),
semiMinorAxis : 500000.0,
semiMajorAxis : 1000000.0,
rotation : Cesium.Math.PI_OVER_FOUR,
vertexFormat : Cesium.VertexFormat.POSITION_AND_ST
}),
id : 'object returned when this instance is picked and to get/set per-instance attributes'
});
scene.primitives.add(new Cesium.Primitive({
geometryInstances : instance,
appearance : new Cesium.EllipsoidSurfaceAppearance({
material : Cesium.Material.fromType('Checkerboard')
})
}));
// 2. Draw different instances each with a unique color
var rectangleInstance = new Cesium.GeometryInstance({
geometry : new Cesium.RectangleGeometry({
rectangle : Cesium.Rectangle.fromDegrees(-140.0, 30.0, -100.0, 40.0),
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
}),
id : 'rectangle',
attributes : {
color : new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5)
}
});
var ellipsoidInstance = new Cesium.GeometryInstance({
geometry : new Cesium.EllipsoidGeometry({
radii : new Cesium.Cartesian3(500000.0, 500000.0, 1000000.0),
vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL
}),
modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
Cesium.Cartesian3.fromDegrees(-95.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 500000.0), new Cesium.Matrix4()),
id : 'ellipsoid',
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)
}
});
scene.primitives.add(new Cesium.Primitive({
geometryInstances : [rectangleInstance, ellipsoidInstance],
appearance : new Cesium.PerInstanceColorAppearance()
}));
// 3. Create the geometry on the main thread.
scene.primitives.add(new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : Cesium.EllipsoidGeometry.createGeometry(new Cesium.EllipsoidGeometry({
radii : new Cesium.Cartesian3(500000.0, 500000.0, 1000000.0),
vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL
})),
modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
Cesium.Cartesian3.fromDegrees(-95.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 500000.0), new Cesium.Matrix4()),
id : 'ellipsoid',
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA)
}
}),
appearance : new Cesium.PerInstanceColorAppearance()
}));
Members
(readonly) allowPicking :Boolean
true
, each geometry instance will only be pickable with Scene#pick
. When false
, GPU memory is saved. *
Type:
- Boolean
- Default Value:
- true
- Source:
appearance :Appearance
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.
Type:
- Default Value:
- undefined
- Source:
(readonly) asynchronous :Boolean
Type:
- Boolean
- Default Value:
- true
- Source:
(readonly) compressVertices :Boolean
true
, geometry vertices are compressed, which will save memory.
Type:
- Boolean
- Default Value:
- true
- Source:
cull :Boolean
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.
Type:
- Boolean
- Default Value:
- true
- Source:
debugShowBoundingVolume :Boolean
Draws the bounding sphere for each draw command in the primitive.
Type:
- Boolean
- Default Value:
- false
- Source:
geometryInstances :Array.<GeometryInstance>|GeometryInstance
undefined
if options.releaseGeometryInstances
is true
when the primitive is constructed.
Changing this property after the primitive is rendered has no effect.
Type:
- Array.<GeometryInstance> | GeometryInstance
- Default Value:
- undefined
- Source:
(readonly) interleave :Boolean
Type:
- Boolean
- Default Value:
- false
- Source:
modelMatrix :Matrix4
Transforms.eastNorthUpToFixedFrame
.
This property is only supported in 3D mode.
Type:
- Default Value:
- Matrix4.IDENTITY
- Source:
Example
var origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);
p.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
(readonly) ready :Boolean
Primitive#update
is called.
Type:
- Boolean
- Source:
(readonly) readyPromise :Promise.<Primitive>
Type:
- Promise.<Primitive>
- Source:
(readonly) releaseGeometryInstances :Boolean
true
, the primitive does not keep a reference to the input geometryInstances
to save memory.
Type:
- Boolean
- Default Value:
- true
- Source:
shadows :ShadowMode
Type:
- ShadowMode
- Default Value:
- ShadowMode.DISABLED
- Source:
show :Boolean
Type:
- Boolean
- Default Value:
- true
- Source:
(readonly) vertexCacheOptimize :Boolean
true
, geometry vertices are optimized for the pre and post-vertex-shader caches.
Type:
- Boolean
- Default Value:
- true
- Source:
Methods
destroy() → {undefined}
Once an object is destroyed, it should not be used; calling any function other than
isDestroyed
will result in a DeveloperError
exception. Therefore,
assign the return value (undefined
) to the object as done in the example.
- Source:
- See:
Throws:
-
This object was destroyed, i.e., destroy() was called.
- Type
- DeveloperError
Returns:
- Type
- undefined
Example
e = e && e.destroy();
getGeometryInstanceAttributes(id) → {Object}
GeometryInstance
.
Parameters:
Name | Type | Description |
---|---|---|
id |
Object | The id of the GeometryInstance . |
- Source:
Throws:
-
must call update before calling getGeometryInstanceAttributes.
- Type
- DeveloperError
Returns:
- Type
- Object
Example
var attributes = primitive.getGeometryInstanceAttributes('an id');
attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);
attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true);
attributes.distanceDisplayCondition = Cesium.DistanceDisplayConditionGeometryInstanceAttribute.toValue(100.0, 10000.0);
isDestroyed() → {Boolean}
If this object was destroyed, it should not be used; calling any function other than
isDestroyed
will result in a DeveloperError
exception.
- Source:
- See:
Returns:
true
if this object was destroyed; otherwise, false
.
- Type
- Boolean
update()
Viewer
or CesiumWidget
render the scene to
get the draw commands needed to render this primitive.
Do not call this function directly. This is documented just to list the exceptions that may be propagated when the scene is rendered:
- Source:
Throws:
-
-
All instance geometries must have the same primitiveType.
- Type
- DeveloperError
-
-
-
Appearance and material have a uniform with the same name.
- Type
- DeveloperError
-
-
-
Primitive.modelMatrix is only supported in 3D mode.
- Type
- DeveloperError
-
-
-
Vertex texture fetch support is required to render primitives with per-instance attributes. The maximum number of vertex texture image units must be greater than zero.
- Type
- RuntimeError
-