globe = {
let orbit_selected = document.getElementById("orbit_selected_id").value
let orbit_array_leo = orbit("LEO");
let orbit_array_meo = orbit("MEO");
let orbit_array_geo = orbit("GEO");
let orbit_array_elliptical = orbit("Elliptical");
let canvas = this;
if (!canvas) {
canvas = DOM.context2d(width, width/2).canvas;
}
const context = canvas.getContext("2d");
const path = d3.geoPath()
.context(context);
context.drawImage(naturalEarth, 0, 0, width, width/2);
let earth = this;
if (!earth) {
earth = new THREE.Mesh();
earth.geometry = new THREE.SphereBufferGeometry(1, 40, 40);
earth.rotation.y = Math.PI;
}
let texture = this;
if (!texture) {
const texture = new THREE.CanvasTexture(canvas);
earth.material = new THREE.MeshLambertMaterial({ map: texture });
} else {
texture.needsUpdate = true;
}
const camera = new THREE.PerspectiveCamera(30, 2, 0.1, 60);
camera.position.set(15, 2, 2);
let scene = this;
console.log(scene)
if (!scene) {
scene = new THREE.Scene();
scene.background = new THREE.Color('#000000');
scene.add(earth, light());
}
for (let obt of orbit_array_geo) {
scene.add(obt);
}
for (let obt of orbit_array_leo) {
scene.add(obt);
}
for (let obt of orbit_array_meo) {
scene.add(obt);
}
for (let obt of orbit_array_elliptical) {
scene.add(obt);
}
// -- start of renderer
const renderer = new THREE.WebGLRenderer({antialias: true})
renderer.setSize(width, width / 2);
renderer.setPixelRatio(devicePixelRatio);
invalidation.then(() => renderer.dispose());
// -- end of renderer
// controls
const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.minDistance = 3;
controls.maxDistance = 40;
const redraw = () => renderer.render(scene(), camera);
controls.addEventListener("change", redraw);
invalidation.then(() => {
controls.removeEventListener("change", redraw);
controls.dispose();
});
// end of controls
// function to change the orbits
d3.select("#orbit_selected_id").on("change", function(d) {
while(scene.children.length > 0){
scene.remove(scene.children[0])
}
const context = canvas.getContext("2d");
const path = d3.geoPath()
.context(context);
context.drawImage(naturalEarth, 0, 0, width, width/2);
scene.add(earth, light());
orbit_selected = document.getElementById("orbit_selected_id").value
if (orbit_selected == "GEO") {
for (let obt of orbit_array_geo) {
scene.add(obt);
}
}
else if (orbit_selected == "LEO") {
for (let obt of orbit_array_leo) {
scene.add(obt);
}
}
else if (orbit_selected == "MEO") {
for (let obt of orbit_array_meo) {
scene.add(obt);
}
}
else if (orbit_selected == "Elliptical") {
for (let obt of orbit_array_elliptical) {
scene.add(obt);
}
}
else {
for (let obt of orbit_array_geo) {
scene.add(obt);
}
for (let obt of orbit_array_leo) {
scene.add(obt);
}
for (let obt of orbit_array_meo) {
scene.add(obt);
}
for (let obt of orbit_array_elliptical) {
scene.add(obt);
}
}
})
let lastUpdated = performance.now();
let count = 3;
while (true) {
let timeScale = 250; // set the speed of Earth rotation
if (count > 0){
console.log("in globe start - 6 time scale 999..")
timeScale = 99999999;
count = count - 1;
}
await Promises.tick(1000 / 60);
const currentTime = performance.now();
const simulatedTimeDelta = (currentTime - lastUpdated) * timeScale / 1000;
// simulate rotation of the Earth
earth.rotation.y += earthAngularVelocity * simulatedTimeDelta;
// rotate satellite
for (let obt of orbit_array_leo) {
obt.rotation.y += obt.satelliteAngularVelocity * simulatedTimeDelta;
}
for (let obt of orbit_array_meo) {
obt.rotation.y += obt.satelliteAngularVelocity * simulatedTimeDelta;
}
for (let obt of orbit_array_geo) {
obt.rotation.y += obt.satelliteAngularVelocity * simulatedTimeDelta;
}
for (let obt of orbit_array_elliptical) {
obt.rotation.y += obt.satelliteAngularVelocity * simulatedTimeDelta;
}
lastUpdated = currentTime;
renderer.render(scene, camera);
yield renderer.domElement;
}
}