<commit_before>import * as THREE from 'three/src/Three';

import { CelestialBody, OrbitalElements, AU, AxisAngleQuaternion, AddPlanetParams, addPlanet } from './CelestialBody';
import { Settings } from './SettingsControl';
import { RotationButtons } from './RotationControl';
import { ModulatedIcosahedronGeometry } from './ModulatedIcosahedronGeometry';
import { GraphicsParams } from './GameState';

import moonUrl from './images/moon.png';
import mercuryUrl from './images/mercury.jpg';
import marsUrl from './images/mars.jpg';
import venusUrl from './images/venus.jpg';
import jupiterUrl from './images/jupiter.jpg';
import earthUrl from './images/land_ocean_ice_cloud_2048.jpg';
import rocketModelUrl from './rocket.obj';
import rocketMtlUrl from './rocket.mtl';
import perlinUrl from './images/perlin.jpg';

const GMsun = 1.327124400e11 / AU / AU/ AU; // Product of gravitational constant (G) and Sun's mass (Msun)
const rad_per_deg = Math.PI / 180; // Radians per degrees

export const COLOR_PALETTE = [
    '1 1 1',
    '1 0.75 0.75',
    '0.75 1 0.75',
    '0.75 0.75 1',
    '1 1 0.75',
    '0.75 1 1',
    '1 0.75 1',
    '1 0.25 0.25',
    '0.25 1 0.25',
    '1 0.25 1',
    '0.25 1 1',
    '0.25 0.5 1',
    '0.25 1 0.5',
    '1 0.25 0.25',
    '0.5 1 0.25',
    '1 0.25 0.5',
    '0.5 0.25 1',
];

type AddPlanetArgType = (orbitalElements: OrbitalElements,
    params: AddPlanetParams, orbitGeometry: THREE.BufferGeometry) => CelestialBody;


export default class Universe{
    sun: CelestialBody;
    rocket: CelestialBody;
    light: THREE.PointLight;
    orbitGeometry: THREE.BufferGeometry;

    constructor(graphicsParams: GraphicsParams, settings: Settings){
        const { scene, viewScale, camera, windowHalfX, windowHalfY } = graphicsParams;
        this.light = new THREE.PointLight( 0xffffff, 1, 0, 1e-6 );
        scene.add( this.light );
        scene.add( new THREE.AmbientLight( 0x202020 ) );

        const curve = new THREE.EllipseCurve(0, 0, 1, 1,
            0, Math.PI * 2, false, 90);
        const orbitGeometry = new THREE.BufferGeometry().setFromPoints( curve.getPoints(256) );
        this.orbitGeometry = orbitGeometry;

        const group = new THREE.Object3D();
        const material = new THREE.MeshBasicMaterial( { color: "#ffffff" } );

        const Rsun = 695800.;
        const sunGeometry = new THREE.SphereGeometry( 1, 20, 20 );

        const sunMesh = new THREE.Mesh( sunGeometry, material );
        sunMesh.scale.setScalar(viewScale * Rsun / AU);
        group.add( sunMesh );

        scene.add(group);

        const addPlanetLocal = (orbitalElements: OrbitalElements, params: AddPlanetParams) =>
            addPlanet(orbitalElements, params, graphicsParams, orbitGeometry, settings);

        this.sun = new CelestialBody(null, new THREE.Vector3(), null, "#ffffff", GMsun, "sun");
        this.sun.radius = Rsun;
        this.sun.model = group;

        const mercury = addPlanetLocal({
            semimajor_axis: 0.387098,
            eccentricity: 0.205630,
            inclination: 7.005 * rad_per_deg,
            ascending_node: 48.331 * rad_per_deg,
            argument_of_perihelion: 29.124 * rad_per_deg
        },
        {
            name: "mercury",
            parent: this.sun,
            color: "#3f7f7f",
            texture: mercuryUrl,
            GM: 22032 / AU / AU / AU,
            radius: 2439.7,
            sphereOfInfluence: 2e5,
        });

        const venus = addPlanetLocal({
            semimajor_axis: 0.723332,
            eccentricity: 0.00677323,
            inclination: 3.39458 * rad_per_deg,
            ascending_node: 76.678 * rad_per_deg,
            argument_of_perihelion: 55.186 * rad_per_deg
        },
        {
            name: "venus",
            parent: this.sun,
            color: "#7f7f3f",
            texture: venusUrl,
            GM: 324859 / AU / AU / AU,
            radius: 6051.8,
            sphereOfInfluence: 5e5,
        });

        // Earth is at 1 AU (which is the AU's definition) and orbits around the ecliptic.
        const earth = addPlanetLocal({
            semimajor_axis: 1,
            eccentricity: 0.0167086,
            inclination: 0,
            ascending_node: -11.26064 * rad_per_deg,
            argument_of_perihelion: 114.20783 * rad_per_deg
        },
        {
            name: "earth",
            parent: this.sun,
            color: "#3f7f3f",
            texture: earthUrl,
            GM: 398600 / AU / AU / AU,
            radius: 6534,
            axialTilt: 23.4392811 * rad_per_deg,
            rotationPeriod: ((23 * 60 + 56) * 60 + 4.10),
            sphereOfInfluence: 5e5
        });

        this.rocket = this.addRocket("rocket",
        {
            semimajor_axis: 10000 / AU,
            eccentricity: 0.,
            inclination: 0,
            ascending_node: 0,
            argument_of_perihelion: 0
        },
        earth, 
        graphicsParams,
        settings);

        const moon = addPlanetLocal({
            semimajor_axis: 384399 / AU,
            eccentricity: 0.0167086,
            inclination: 0,
            ascending_node: -11.26064 * rad_per_deg,
            argument_of_perihelion: 114.20783 * rad_per_deg
        },
        {
            name: "moon",
            parent: earth,
            color: "#5f5f5f",
            texture: moonUrl,
            GM: 4904.8695 / AU / AU / AU,
            radius: 1737.1,
            sphereOfInfluence: 1e5,
        });

        const mars = addPlanetLocal({
            semimajor_axis: 1.523679,
            eccentricity: 0.0935,
            inclination: 1.850 * rad_per_deg,
            ascending_node: 49.562 * rad_per_deg,
            argument_of_perihelion: 286.537 * rad_per_deg
        },
        {
            name: "mars",
            parent: this.sun,
            color: "#7f3f3f",
            texture: marsUrl,
            GM: 42828 / AU / AU / AU,
            radius: 3389.5,
            sphereOfInfluence: 3e5
        });

        const jupiter = addPlanetLocal({
            semimajor_axis: 5.204267,
            eccentricity: 0.048775,
            inclination: 1.305 * rad_per_deg,
            ascending_node: 100.492 * rad_per_deg,
            argument_of_perihelion: 275.066 * rad_per_deg
        },
        {
            name: "jupiter",
            parent: this.sun,
            color: "#7f7f3f",
            texture: jupiterUrl,
            GM: 126686534 / AU / AU / AU,
            radius: 69911,
            sphereOfInfluence: 10e6,
        });

        // Use icosahedron instead of sphere to make it look like uniform
        // TODO: use simplex noise to make more smooth asteroid
        const asteroidGeometry = new ModulatedIcosahedronGeometry( 1, 2, (vec) => vec.multiplyScalar(0.3 * (Math.random() - 0.5) + 1) );
        asteroidGeometry.computeVertexNormals();

        // Perlin noise is applied as detail texture.
        // It's asynchrnonous because it's shared by multiple asteroids.
        const asteroidTexture = new THREE.TextureLoader().load(perlinUrl);
        asteroidTexture.wrapS = THREE.RepeatWrapping;
        asteroidTexture.wrapT = THREE.RepeatWrapping;
        asteroidTexture.repeat.set(4, 4);
        const asteroidMaterial = new THREE.MeshLambertMaterial( {
            map: asteroidTexture,
            color: 0xffaf7f, flatShading: false
        } );

        // Randomly generate asteroids
        for (let i = 0; i < 3; i ++ ) {
<commit_msg>Add rotation to all major planets<commit_after>import * as THREE from 'three/src/Three';

import { CelestialBody, OrbitalElements, AU, AxisAngleQuaternion, AddPlanetParams, addPlanet } from './CelestialBody';
import { Settings } from './SettingsControl';
import { RotationButtons } from './RotationControl';
import { ModulatedIcosahedronGeometry } from './ModulatedIcosahedronGeometry';
import { GraphicsParams } from './GameState';

import moonUrl from './images/moon.png';
import mercuryUrl from './images/mercury.jpg';
import marsUrl from './images/mars.jpg';
import venusUrl from './images/venus.jpg';
import jupiterUrl from './images/jupiter.jpg';
import earthUrl from './images/land_ocean_ice_cloud_2048.jpg';
import rocketModelUrl from './rocket.obj';
import rocketMtlUrl from './rocket.mtl';
import perlinUrl from './images/perlin.jpg';

const GMsun = 1.327124400e11 / AU / AU/ AU; // Product of gravitational constant (G) and Sun's mass (Msun)
const rad_per_deg = Math.PI / 180; // Radians per degrees

export const COLOR_PALETTE = [
    '1 1 1',
    '1 0.75 0.75',
    '0.75 1 0.75',
    '0.75 0.75 1',
    '1 1 0.75',
    '0.75 1 1',
    '1 0.75 1',
    '1 0.25 0.25',
    '0.25 1 0.25',
    '1 0.25 1',
    '0.25 1 1',
    '0.25 0.5 1',
    '0.25 1 0.5',
    '1 0.25 0.25',
    '0.5 1 0.25',
    '1 0.25 0.5',
    '0.5 0.25 1',
];

type AddPlanetArgType = (orbitalElements: OrbitalElements,
    params: AddPlanetParams, orbitGeometry: THREE.BufferGeometry) => CelestialBody;


export default class Universe{
    sun: CelestialBody;
    rocket: CelestialBody;
    light: THREE.PointLight;
    orbitGeometry: THREE.BufferGeometry;

    constructor(graphicsParams: GraphicsParams, settings: Settings){
        const { scene, viewScale, camera, windowHalfX, windowHalfY } = graphicsParams;
        this.light = new THREE.PointLight( 0xffffff, 1, 0, 1e-6 );
        scene.add( this.light );
        scene.add( new THREE.AmbientLight( 0x202020 ) );

        const curve = new THREE.EllipseCurve(0, 0, 1, 1,
            0, Math.PI * 2, false, 90);
        const orbitGeometry = new THREE.BufferGeometry().setFromPoints( curve.getPoints(256) );
        this.orbitGeometry = orbitGeometry;

        const group = new THREE.Object3D();
        const material = new THREE.MeshBasicMaterial( { color: "#ffffff" } );

        const Rsun = 695800.;
        const sunGeometry = new THREE.SphereGeometry( 1, 20, 20 );

        const sunMesh = new THREE.Mesh( sunGeometry, material );
        sunMesh.scale.setScalar(viewScale * Rsun / AU);
        group.add( sunMesh );

        scene.add(group);

        const addPlanetLocal = (orbitalElements: OrbitalElements, params: AddPlanetParams) =>
            addPlanet(orbitalElements, params, graphicsParams, orbitGeometry, settings);

        this.sun = new CelestialBody(null, new THREE.Vector3(), null, "#ffffff", GMsun, "sun");
        this.sun.radius = Rsun;
        this.sun.model = group;

        const mercury = addPlanetLocal({
            semimajor_axis: 0.387098,
            eccentricity: 0.205630,
            inclination: 7.005 * rad_per_deg,
            ascending_node: 48.331 * rad_per_deg,
            argument_of_perihelion: 29.124 * rad_per_deg
        },
        {
            name: "mercury",
            parent: this.sun,
            color: "#3f7f7f",
            texture: mercuryUrl,
            GM: 22032 / AU / AU / AU,
            radius: 2439.7,
            axialTilt: 2.04 * rad_per_deg,
            rotationPeriod: 58.646 * 24. * 60. * 60.,
            sphereOfInfluence: 2e5,
        });

        const venus = addPlanetLocal({
            semimajor_axis: 0.723332,
            eccentricity: 0.00677323,
            inclination: 3.39458 * rad_per_deg,
            ascending_node: 76.678 * rad_per_deg,
            argument_of_perihelion: 55.186 * rad_per_deg
        },
        {
            name: "venus",
            parent: this.sun,
            color: "#7f7f3f",
            texture: venusUrl,
            GM: 324859 / AU / AU / AU,
            radius: 6051.8,
            axialTilt: 	2.64 * rad_per_deg,
            rotationPeriod: -243. * 24. * 60. * 60.,
            sphereOfInfluence: 5e5,
        });

        // Earth is at 1 AU (which is the AU's definition) and orbits around the ecliptic.
        const earth = addPlanetLocal({
            semimajor_axis: 1,
            eccentricity: 0.0167086,
            inclination: 0,
            ascending_node: -11.26064 * rad_per_deg,
            argument_of_perihelion: 114.20783 * rad_per_deg
        },
        {
            name: "earth",
            parent: this.sun,
            color: "#3f7f3f",
            texture: earthUrl,
            GM: 398600 / AU / AU / AU,
            radius: 6534,
            axialTilt: 23.4392811 * rad_per_deg,
            rotationPeriod: ((23 * 60 + 56) * 60 + 4.10),
            sphereOfInfluence: 5e5
        });

        this.rocket = this.addRocket("rocket",
        {
            semimajor_axis: 10000 / AU,
            eccentricity: 0.,
            inclination: 0,
            ascending_node: 0,
            argument_of_perihelion: 0
        },
        earth, 
        graphicsParams,
        settings);

        const moon = addPlanetLocal({
            semimajor_axis: 384399 / AU,
            eccentricity: 0.0167086,
            inclination: 0,
            ascending_node: -11.26064 * rad_per_deg,
            argument_of_perihelion: 114.20783 * rad_per_deg
        },
        {
            name: "moon",
            parent: earth,
            color: "#5f5f5f",
            texture: moonUrl,
            GM: 4904.8695 / AU / AU / AU,
            radius: 1737.1,
            axialTilt: 	1.5424 * rad_per_deg,
            rotationPeriod: 27.321661 * 24. * 60. * 60.,
            sphereOfInfluence: 1e5,
        });

        const mars = addPlanetLocal({
            semimajor_axis: 1.523679,
            eccentricity: 0.0935,
            inclination: 1.850 * rad_per_deg,
            ascending_node: 49.562 * rad_per_deg,
            argument_of_perihelion: 286.537 * rad_per_deg
        },
        {
            name: "mars",
            parent: this.sun,
            color: "#7f3f3f",
            texture: marsUrl,
            GM: 42828 / AU / AU / AU,
            radius: 3389.5,
            axialTilt: 	25.19 * rad_per_deg,
            rotationPeriod: 24.6229 * 60. * 60.,
            sphereOfInfluence: 3e5
        });

        const jupiter = addPlanetLocal({
            semimajor_axis: 5.204267,
            eccentricity: 0.048775,
            inclination: 1.305 * rad_per_deg,
            ascending_node: 100.492 * rad_per_deg,
            argument_of_perihelion: 275.066 * rad_per_deg
        },
        {
            name: "jupiter",
            parent: this.sun,
            color: "#7f7f3f",
            texture: jupiterUrl,
            GM: 126686534 / AU / AU / AU,
            radius: 69911,
            axialTilt: 3.13 * rad_per_deg,
            rotationPeriod: 9.925 * 60. * 60.,
            sphereOfInfluence: 10e6,
        });

        // Use icosahedron instead of sphere to make it look like uniform
        // TODO: use simplex noise to make more smooth asteroid
        const asteroidGeometry = new ModulatedIcosahedronGeometry( 1, 2, (vec) => vec.multiplyScalar(0.3 * (Math.random() - 0.5) + 1) );
        asteroidGeometry.computeVertexNormals();

        // Perlin noise is applied as detail texture.
        // It's asynchrnonous because it's shared by multiple asteroids.
        const asteroidTexture = new THREE.TextureLoader().load(perlinUrl);
        asteroidTexture.wrapS = THREE.RepeatWrapping;
        asteroidTexture.wrapT = THREE.RepeatWrapping;
        asteroidTexture.repeat.set(4, 4);
        const asteroidMaterial = new THREE.MeshLambertMaterial( {
            map: asteroidTexture,
            color: 0xffaf7f, flatShading: false
        } );

        // Randomly generate asteroids
        for (let i = 0; i < 3; i ++ ) {

{'fraction_non_alphanumeric': 0.10938414515185016, 'fraction_numerical': 0.06555244846198868, 'mean_word_length': 1.8900582597256155, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4353412', 'n_tokens_mistral': 5619, 'n_tokens_neox': 4826, 'n_words': 1195}