CesiumGS / CesiumGS/cesium

Per position color for polyline entities

Open
#4,393 4 comments 0 reactions 0 assignees View on GitHub
category - polyline type - enhancement
Dominant language
JavaScript
Stars
15.7k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

I would like to make a gradient, but in an entity form (PolylineGraphics?). I currently destroy and recreate the primitive each time the positions update (code below).

Will I basically have to copy PolylineGraphics? Or would it be better to extend it instead?

I have async off because this line connects two objects that are moving, so it is constantly updating. Having async on makes the line disappear during animation.

Any pointers will help! 😄

```
function createGradientPrimitive(positions, color1, color2) {
var gradientColors = [];
for (var i = 0; i < positions.length; i++) {
var percent = i/(positions.length - 1);
var red = color1.red + percent * (color2.red - color1.red);
var green = color1.green + percent * (color2.green - color1.green);
var blue = color1.blue + percent * (color2.blue - color1.blue);
var alpha = color1.alpha + percent * (color2.alpha - color1.alpha);
gradientColors.push(new Cesium.Color(red, green, blue, alpha));
}

return new Cesium.Primitive({
asynchronous: false,
geometryInstances: new Cesium.GeometryInstance({
geometry: new Cesium.PolylineGeometry({
positions: positions,
width: 20,
vertexFormat: Cesium.PolylineColorAppearance.VERTEX_FORMAT,
colors: gradientColors,
colorsPerVertex: true
})
}),
appearance: new Cesium.PolylineColorAppearance({
translucent: true
})
});
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the reported createGradientPrimitive example and compare its PolylineGeometry and PolylineGraphics usage. Clarify the intended entity-level API and how it should behave when positions update continuously; done means per-position colors or gradients work without destroying and recreating the primitive during animation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.