import * as THREE from "../cosmetics/three.module.js";
import { TrackballControls } from "../cosmetics/TrackballControls.js";
import {
getJ2000Offset,
getElements,
getOrbitTrail
} from "./orrery_calculations.js";
import planets from "./orrery_planets.js";
const orbitColours = {
mercury: 0x887766,
venus: 0xcc7700,
earth: 0x229955,
mars: 0xcc3322,
jupiter: 0xcc7788,
saturn: 0xddaa44,
uranus: 0x22bbbb,
neptune: 0x2266bb,
pluto: 0x7722aa,
eris: 0xbb1188,
ceres: 0xccddbb,
haumea: 0xbbddcc,
makemake: 0xbbccdd,
sedna: 0xccbbdd
};
const orbitMeshes = {};
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xffffff);
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1e15
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const controls = new TrackballControls(camera, renderer.domElement);
const orbitTrail = getOrbitTrail(planets.mercury, new Date());
console.log(orbitTrail);
for (const planetKey in planets) {
const orbit = getOrbitTrail(planets[planetKey], new Date());
const orbitGeometry = new THREE.BufferGeometry().setFromPoints(
orbit.map(o => new THREE.Vector3(...o.xyz))
);
const orbitMesh = new THREE.Line(
orbitGeometry,
new THREE.LineBasicMaterial({ color: orbitColours[planetKey] })
);
orbitMeshes[planetKey] = orbitMesh;
scene.add(orbitMesh);
const map = new THREE.TextureLoader().load(
`/sandbox/${
[
"venus",
"uranus",
"mars",
"earth",
"jupiter",
"saturn",
"neptune",
"pluto",
"eris"
].includes(planetKey)
? planetKey
: "mercury"
}.png`
);
map.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.PointsMaterial({
map: map,
size: 20,
sizeAttenuation: false,
alphaTest: 0.5,
depthTest: true,
depthWrite: true
});
const sprite = new THREE.Points(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(...orbit[0].xyz)
]),
material
);
scene.add(sprite);
}
camera.position.z = 1e12;
controls.update();
const animate = time => {
controls.update();
renderer.render(scene, camera);
};
renderer.setAnimationLoop(animate);