Here’s the section of the code responsible for connecting satellites with lines, which appears to be causing the performance issues:
function updateSatelliteConnection(connection, satellite1, satellite2) {
var position1 = satellite1.position.getValue(viewer.clock.currentTime);
var position2 = satellite2.position.getValue(viewer.clock.currentTime);
if (!position1 || !position2) {
connection.polyline.positions = [new Cesium.Cartesian3(), new Cesium.Cartesian3()];
} else {
connection.polyline.positions = [position1, position2];
if (isOccluded(position1, position2)) {
connection.polyline.material = new Cesium.PolylineDashMaterialProperty({
color: connection.polyline.material.color.getValue(),
dashLength: 16.0
});
} else {
connection.polyline.material = new Cesium.ColorMaterialProperty(connection.polyline.material.color.getValue());
}
}
}
// Example usage:
var connection1 = viewer.entities.add({
polyline: {
positions: [],
width: 2,
material: new Cesium.PolylineDashMaterialProperty({
color: Cesium.Color.RED,
dashLength: 16.0
})
}
});
setInterval(function() {
updateSatelliteConnection(connection1, earthSatellite, moonSatellite);
}, 300); // Update every 300 ms
Strangely, while the earlier parts of the code exhibit high CPU usage without causing freezes, adding even a single section of this connection line code causes significant slowdowns. This occurs despite the connection lines themselves not consuming a large amount of resources.