Skip to content

Commit

Permalink
Merge pull request #157 from BarthPaleologue/ReworkModelArchi
Browse files Browse the repository at this point in the history
Extensive data model rework
  • Loading branch information
BarthPaleologue authored Oct 15, 2024
2 parents 51f2b7e + 1236e2f commit debb649
Show file tree
Hide file tree
Showing 166 changed files with 2,943 additions and 3,613 deletions.
3 changes: 0 additions & 3 deletions seeds.txt

This file was deleted.

3 changes: 0 additions & 3 deletions src/html/bodyEditor.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ <h1>General</h1>

<h1>Star</h1>

<p>Temperature (K) : </p>
<div id="temperature"></div>

<p>Exposure : </p>
<div id="starExposure"></div>

Expand Down
177 changes: 82 additions & 95 deletions src/ts/alphaTestis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,43 @@

import "../styles/index.scss";

import { StarSystemController } from "./starSystem/starSystemController";

import { Settings } from "./settings";
import { positionNearObjectBrightSide } from "./utils/positionNearObject";
import { CosmosJourneyer } from "./cosmosJourneyer";
import { Vector3 } from "@babylonjs/core/Maths/math.vector";
import { PostProcessType } from "./postProcesses/postProcessTypes";
import { TelluricPlanetModel } from "./planets/telluricPlanet/telluricPlanetModel";
import { GasPlanetModel } from "./planets/gasPlanet/gasPlanetModel";
import { StarSystemHelper } from "./starSystem/starSystemHelper";
import { getMoonSeed } from "./planets/common";
import { newSeededGasPlanetModel } from "./planets/gasPlanet/gasPlanetModel";
import { SpaceShipControlsInputs } from "./spaceship/spaceShipControlsInputs";
import { CustomStarSystemModel } from "./starSystem/customStarSystemModel";
import { BodyType } from "./architecture/bodyType";

import { newSeededStarModel } from "./stellarObjects/star/starModel";
import { newSeededSpaceStationModel } from "./spacestation/spacestationModel";
import { StarSystemModel } from "./starSystem/starSystemModel";
import { StarSystemCoordinates } from "./utils/coordinates/universeCoordinates";
import { CustomSystemRegistry } from "./starSystem/customSystemRegistry";
import { newSeededTelluricSatelliteModel } from "./planets/telluricPlanet/telluricSatelliteModel";
import { newSeededTelluricPlanetModel } from "./planets/telluricPlanet/telluricPlanetModel";

const engine = await CosmosJourneyer.CreateAsync();

const starSystemView = engine.starSystemView;

const spaceshipController = starSystemView.getSpaceshipControls();

const characterController = starSystemView.getCharacterControls();

// const physicsViewer = new PhysicsViewer();
// physicsViewer.showBody(spaceshipController.aggregate.body);

console.log(`Time is going ${Settings.TIME_MULTIPLIER} time${Settings.TIME_MULTIPLIER > 1 ? "s" : ""} faster than in reality`);

const starSystemModel = new CustomStarSystemModel(
"Alpha Testis",
{
starSectorX: 0,
starSectorY: 0,
starSectorZ: 0,
localX: 0,
localY: 0,
localZ: 0
},
[[BodyType.STAR, 4413.641464990006]],
[
[BodyType.TELLURIC_PLANET, 0.4233609183800225],
[BodyType.TELLURIC_PLANET, 0.3725],
[BodyType.GAS_PLANET, 0.28711440474126226]
],
[]
);

const starSystem = new StarSystemController(starSystemModel, starSystemView.scene);

await starSystemView.loadStarSystem(starSystem, false);

const sun = StarSystemHelper.MakeStar(starSystem);
sun.model.orbit.period = 60 * 60 * 24;
const systemName = "Alpha Testis";
const systemCoordinates: StarSystemCoordinates = {
starSectorX: 0,
starSectorY: 0,
starSectorZ: 0,
localX: 0,
localY: 0,
localZ: 0
};

const sunModel = newSeededStarModel(420, "Weierstrass", []);
sunModel.physics.blackBodyTemperature = 5778;
sunModel.orbit.period = 60 * 60 * 24;

/*const secundaModel = new StarModel(-672446, sunModel);
secundaModel.orbit.radius = 30 * sunModel.radius;
Expand All @@ -81,74 +65,91 @@ terminaModel.orbit.radius = 50 * sunModel.radius;
terminaModel.orbit.period = 60 * 60;
const termina = StarSystemHelper.makeStar(starSystem, terminaModel);*/

const planetModel = new TelluricPlanetModel(starSystemModel.getPlanetSeed(0), starSystemModel, sun.model);
planetModel.physicalProperties.minTemperature = -40;
planetModel.physicalProperties.maxTemperature = 30;

planetModel.orbit.period = 60 * 60 * 24 * 365.25;
planetModel.orbit.radius = 25000 * planetModel.radius;
planetModel.orbit.normalToPlane = Vector3.Up();
const hecateModel = newSeededTelluricPlanetModel(253, "Hécate", [sunModel]);
hecateModel.physics.minTemperature = -40;
hecateModel.physics.maxTemperature = 30;

const planet = StarSystemHelper.MakeTelluricPlanet(starSystem, planetModel);
hecateModel.orbit.period = 60 * 60 * 24 * 365.25;
hecateModel.orbit.radius = 25000 * hecateModel.radius;
hecateModel.orbit.normalToPlane = Vector3.Up();

const spaceStation = StarSystemHelper.MakeSpaceStation(starSystem, 0, planet);
const spaceStationModel = newSeededSpaceStationModel(0, [sunModel], systemCoordinates, [hecateModel]);

//physicsViewer.showBody(spaceStation.aggregate.body);
/*for(const landingpad of spaceStation.landingPads) {
physicsViewer.showBody(landingpad.aggregate.body);
}*/

const moonModel = new TelluricPlanetModel(getMoonSeed(planetModel, 0), starSystemModel, planetModel);
moonModel.physicalProperties.mass = 2;
moonModel.physicalProperties.rotationPeriod = 7 * 60 * 60;
moonModel.physicalProperties.minTemperature = -180;
moonModel.physicalProperties.maxTemperature = 200;
moonModel.physicalProperties.waterAmount = 0.9;
const moonModel = newSeededTelluricSatelliteModel(23, "Manaleth", [hecateModel]);
moonModel.physics.mass = 2;
moonModel.physics.rotationPeriod = 7 * 60 * 60;
moonModel.physics.minTemperature = -180;
moonModel.physics.maxTemperature = 200;
moonModel.physics.waterAmount = 0.9;

moonModel.orbit.period = moonModel.physicalProperties.rotationPeriod;
moonModel.orbit.radius = 8 * planet.getRadius();
moonModel.orbit.period = moonModel.physics.rotationPeriod;
moonModel.orbit.radius = 8 * hecateModel.radius;
moonModel.orbit.normalToPlane = Vector3.Up();

const moon = StarSystemHelper.MakeSatellite(starSystem, planet, moonModel);

const aresModel = new TelluricPlanetModel(0.3725, starSystemModel, sun.model);
aresModel.physicalProperties.mass = 7;
aresModel.physicalProperties.rotationPeriod = (24 * 60 * 60) / 30;
aresModel.physicalProperties.minTemperature = -30;
aresModel.physicalProperties.maxTemperature = 20;
aresModel.physicalProperties.pressure = 0.5;
aresModel.physicalProperties.waterAmount = 0.2;
aresModel.physicalProperties.oceanLevel = 0;
const aresModel = newSeededTelluricPlanetModel(0.3725, "Ares", [sunModel]);
if (aresModel.clouds !== null) aresModel.clouds.coverage = 1;
aresModel.physics.mass = 7;
aresModel.physics.rotationPeriod = (24 * 60 * 60) / 30;
aresModel.physics.minTemperature = -30;
aresModel.physics.maxTemperature = 20;
aresModel.physics.pressure = 0.5;
aresModel.physics.waterAmount = 0.2;
aresModel.physics.oceanLevel = 0;

aresModel.orbit.period = 60 * 60 * 24 * 365.24;
aresModel.orbit.radius = 25020 * planet.getRadius();
aresModel.orbit.radius = 25020 * hecateModel.radius;
aresModel.orbit.normalToPlane = Vector3.Up();

//aresModel.terrainSettings.continents_fragmentation = 0.0;
//aresModel.terrainSettings.continent_base_height = 10e3;
//aresModel.terrainSettings.max_mountain_height = 20e3;

const ares = StarSystemHelper.MakeTelluricPlanet(starSystem, aresModel);
ares.postProcesses.splice(ares.postProcesses.indexOf(PostProcessType.OCEAN), 1);
ares.postProcesses.splice(ares.postProcesses.indexOf(PostProcessType.CLOUDS), 1);

ares.material.updateConstants();

const andromaqueModel = new GasPlanetModel(0.28711440474126226, starSystemModel, sun.model);
const andromaqueModel = newSeededGasPlanetModel(0.28711440474126226, "Andromaque", [sunModel]);
andromaqueModel.orbit.period = 60 * 60 * 24 * 365.25;
andromaqueModel.orbit.radius = 25300 * ares.getRadius();
andromaqueModel.orbit.radius = 25300 * hecateModel.radius;
andromaqueModel.orbit.normalToPlane = Vector3.Up();

const andromaque = StarSystemHelper.MakeGasPlanet(starSystem, andromaqueModel);

/*const blackHoleModel = new BlackHoleModel(0.5, sunModel);
blackHoleModel.orbit.period = 60 * 60 * 24 * 365.25;
blackHoleModel.orbit.radius = 100 * ares.getRadius();
const blackHole = starSystem.makeBlackHole(blackHoleModel);*/
const starSystemModel: StarSystemModel = {
name: systemName,
coordinates: systemCoordinates,
subSystems: [
{
stellarObjects: [sunModel],
planetarySystems: [
{ planets: [hecateModel], satellites: [moonModel], spaceStations: [spaceStationModel] },
{ planets: [aresModel], satellites: [], spaceStations: [] },
{ planets: [andromaqueModel], satellites: [], spaceStations: [] }
],
anomalies: [],
spaceStations: []
}
]
};

CustomSystemRegistry.RegisterSystem(starSystemModel);

const starSystem = await starSystemView.loadStarSystem(starSystemModel);

engine.init(true);

positionNearObjectBrightSide(starSystemView.scene.getActiveControls(), planet, starSystem, 2);
const planets = starSystem.getPlanets();

const hecate = planets.find((planet) => planet.model === hecateModel);
if (hecate === undefined) {
throw new Error("Hécate not found");
}

positionNearObjectBrightSide(starSystemView.scene.getActiveControls(), hecate, starSystem, 2);

const ares = planets.find((planet) => planet.model === aresModel);
if (ares === undefined) {
throw new Error("Ares not found");
}

const aresAtmosphere = starSystemView.postProcessManager.getAtmosphere(ares);
if (aresAtmosphere) {
Expand All @@ -161,20 +162,6 @@ if (aresAtmosphere) {

document.addEventListener("keydown", (e) => {

Check warning on line 163 in src/ts/alphaTestis.ts

View workflow job for this annotation

GitHub Actions / eslint (18)

'e' is defined but never used

Check warning on line 163 in src/ts/alphaTestis.ts

View workflow job for this annotation

GitHub Actions / eslint (20)

'e' is defined but never used
if (engine.isPaused()) return;

if (e.key === "x") {
let nbVertices = 0;
let nbInstances = 0;
planet.sides.forEach((side) => {
side.executeOnEveryChunk((chunk) => {
nbVertices += Settings.VERTEX_RESOLUTION * Settings.VERTEX_RESOLUTION;
chunk.instancePatches.forEach((patch) => {
nbInstances += patch.getNbInstances();
});
});
});
console.log("Vertices", nbVertices, "Instances", nbInstances);
}
});

starSystemView.getSpaceshipControls().spaceship.enableWarpDrive();
Expand Down
8 changes: 4 additions & 4 deletions src/ts/anomalies/anomaly.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AnomalyType } from "./anomalyType";
import { CelestialBody } from "../architecture/celestialBody";
import { CelestialBodyModel } from "../architecture/celestialBody";
import { OrbitalObjectType } from "../architecture/orbitalObject";

export interface Anomaly extends CelestialBody {
readonly anomalyType: AnomalyType;
export interface AnomalyModel extends CelestialBodyModel {
readonly type: OrbitalObjectType.MANDELBULB | OrbitalObjectType.JULIA_SET;
}
4 changes: 0 additions & 4 deletions src/ts/anomalies/anomalyType.ts

This file was deleted.

51 changes: 10 additions & 41 deletions src/ts/anomalies/julia/juliaSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,36 @@ import { Camera } from "@babylonjs/core/Cameras/camera";
import { JuliaSetModel } from "./juliaSetModel";
import { PostProcessType } from "../../postProcesses/postProcessTypes";
import { Axis } from "@babylonjs/core/Maths/math.axis";
import { CelestialBody } from "../../architecture/celestialBody";
import { TransformNode } from "@babylonjs/core/Meshes";
import { Scene } from "@babylonjs/core/scene";
import { RingsUniforms } from "../../rings/ringsUniform";
import { Vector3 } from "@babylonjs/core/Maths/math.vector";
import { Cullable } from "../../utils/cullable";
import { OrbitalObjectPhysicalProperties } from "../../architecture/physicalProperties";
import { Anomaly } from "../anomaly";
import { AnomalyType } from "../anomalyType";
import { AsteroidField } from "../../asteroidFields/asteroidField";
import { StarSystemModel } from "../../starSystem/starSystemModel";
import { Orbit } from "../../orbit/orbit";

export class JuliaSet implements Anomaly, Cullable {
readonly name: string;
import { CelestialBody } from "../../architecture/celestialBody";
import { orbitalObjectTypeToDisplay } from "../../utils/strings/orbitalObjectTypeToDisplay";

export class JuliaSet implements CelestialBody, Cullable {
readonly model: JuliaSetModel;

readonly anomalyType = AnomalyType.JULIA_SET;

private readonly transform: TransformNode;

readonly postProcesses: PostProcessType[] = [];

readonly parent: CelestialBody | null = null;
readonly ringsUniforms = null;
readonly asteroidField = null;

/**
* New Gas Planet
* @param model The model to create the planet from or a seed for the planet in [-1, 1]
* @param starSystemModel
* @param scene
* @param parentBody The bodies the planet is orbiting
*/
constructor(model: JuliaSetModel | number, starSystemModel: StarSystemModel, scene: Scene, parentBody: CelestialBody | null = null) {
this.model = model instanceof JuliaSetModel ? model : new JuliaSetModel(model, starSystemModel, parentBody?.model);
constructor(model: JuliaSetModel, scene: Scene) {
this.model = model;

this.name = this.model.name;

this.parent = parentBody;

this.transform = new TransformNode(this.name, scene);
this.transform = new TransformNode(this.model.name, scene);

this.postProcesses.push(PostProcessType.JULIA_SET);

this.getTransform().rotate(Axis.X, this.model.physicalProperties.axialTilt);
this.getTransform().rotate(Axis.X, this.model.physics.axialTilt);
}

getTransform(): TransformNode {
Expand All @@ -74,22 +59,6 @@ export class JuliaSet implements Anomaly, Cullable {
return this.getTransform().up;
}

getOrbitProperties(): Orbit {
return this.model.orbit;
}

getPhysicalProperties(): OrbitalObjectPhysicalProperties {
return this.model.physicalProperties;
}

getRingsUniforms(): RingsUniforms | null {
return null;
}

getAsteroidField(): AsteroidField | null {
return null;
}

getRadius(): number {
return this.model.radius;
}
Expand All @@ -99,7 +68,7 @@ export class JuliaSet implements Anomaly, Cullable {
}

getTypeName(): string {
return this.model.typeName;
return orbitalObjectTypeToDisplay(this.model);
}

computeCulling(cameras: Camera[]): void {

Check warning on line 74 in src/ts/anomalies/julia/juliaSet.ts

View workflow job for this annotation

GitHub Actions / eslint (18)

'cameras' is defined but never used

Check warning on line 74 in src/ts/anomalies/julia/juliaSet.ts

View workflow job for this annotation

GitHub Actions / eslint (20)

'cameras' is defined but never used
Expand Down
Loading

0 comments on commit debb649

Please sign in to comment.