From 298baa9045320c6f4e5c09e5f10e2d7efbeb592d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Sun, 28 Jan 2024 11:52:37 +0100 Subject: [PATCH 1/7] fixed warp tunnel not disappearing when switching controls --- src/ts/spaceship/spaceship.ts | 2 +- src/ts/starSystem/StarSystemView.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ts/spaceship/spaceship.ts b/src/ts/spaceship/spaceship.ts index 8fabf1478..d5c646c1b 100644 --- a/src/ts/spaceship/spaceship.ts +++ b/src/ts/spaceship/spaceship.ts @@ -52,7 +52,7 @@ export class Spaceship implements Transformable { radius: 1 }; - private readonly warpTunnel: WarpTunnel; + readonly warpTunnel: WarpTunnel; private readonly scene: Scene; diff --git a/src/ts/starSystem/StarSystemView.ts b/src/ts/starSystem/StarSystemView.ts index 181c13c70..5cf539e19 100644 --- a/src/ts/starSystem/StarSystemView.ts +++ b/src/ts/starSystem/StarSystemView.ts @@ -281,6 +281,7 @@ export class StarSystemView { setRotationQuaternion(characterControls.getTransform(), getRotationQuaternion(defaultControls.getTransform()).clone()); this.getStarSystem().postProcessManager.rebuild(); + shipControls.spaceship.warpTunnel.setThrottle(0); shipControls.spaceship.setEnabled(false, this.havokPlugin); } @@ -290,6 +291,7 @@ export class StarSystemView { const defaultControls = this.getDefaultControls(); characterControls.getTransform().setEnabled(false); + shipControls.spaceship.warpTunnel.setThrottle(0); shipControls.spaceship.setEnabled(false, this.havokPlugin); this.scene.setActiveController(defaultControls); From a9f1aaa30c11f94b1b140b073504c0c437c0ff25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Sun, 28 Jan 2024 11:54:36 +0100 Subject: [PATCH 2/7] added missing licenses --- src/ts/spaceship/spaceship.ts | 17 +++++++++++++++++ src/ts/utils/warpTunnel.ts | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/ts/spaceship/spaceship.ts b/src/ts/spaceship/spaceship.ts index d5c646c1b..412283ce7 100644 --- a/src/ts/spaceship/spaceship.ts +++ b/src/ts/spaceship/spaceship.ts @@ -1,3 +1,20 @@ +// This file is part of CosmosJourneyer +// +// Copyright (C) 2024 Barthélemy Paléologue +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + import { Scene } from "@babylonjs/core/scene"; import { Vector3 } from "@babylonjs/core/Maths/math.vector"; import { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh"; diff --git a/src/ts/utils/warpTunnel.ts b/src/ts/utils/warpTunnel.ts index 41a610991..ab6c9d497 100644 --- a/src/ts/utils/warpTunnel.ts +++ b/src/ts/utils/warpTunnel.ts @@ -1,3 +1,20 @@ +// This file is part of CosmosJourneyer +// +// Copyright (C) 2024 Barthélemy Paléologue +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + import { Scene } from "@babylonjs/core/scene"; import { Vector3 } from "@babylonjs/core/Maths/math.vector"; import { TransformNode } from "@babylonjs/core/Meshes"; From 794aa5cd59f4cf001a932313e81cfcad3761a946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Sun, 28 Jan 2024 11:55:11 +0100 Subject: [PATCH 3/7] removed useless enum --- src/ts/spaceship/shipControls.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/ts/spaceship/shipControls.ts b/src/ts/spaceship/shipControls.ts index ad542fd09..f890e2a3c 100644 --- a/src/ts/spaceship/shipControls.ts +++ b/src/ts/spaceship/shipControls.ts @@ -35,12 +35,6 @@ import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera"; import { ArcRotateCamera } from "@babylonjs/core/Cameras/arcRotateCamera"; import { Spaceship } from "./spaceship"; -enum ShipState { - FLYING, - LANDING, - LANDED -} - export class ShipControls implements Controls { readonly spaceship: Spaceship; From a35eabc369c35e7c378c32faa49060f4cf9bbf2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Sun, 28 Jan 2024 12:04:00 +0100 Subject: [PATCH 4/7] lowered cloud height --- src/ts/settings.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ts/settings.ts b/src/ts/settings.ts index 6a1edec96..d6b050a93 100644 --- a/src/ts/settings.ts +++ b/src/ts/settings.ts @@ -26,7 +26,7 @@ export const Settings = { VERTEX_RESOLUTION: 64, MIN_DISTANCE_BETWEEN_VERTICES: 1.5, - CLOUD_LAYER_HEIGHT: 15e3, + CLOUD_LAYER_HEIGHT: 7e3, ATMOSPHERE_HEIGHT: 100e3, OCEAN_DEPTH: 7e3, From 4ce44de7ba3f0dd1f3583b5cf7b385d328c2da84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Sun, 28 Jan 2024 14:35:20 +0100 Subject: [PATCH 5/7] Stellar objects refactorings - Neutron stars are no longer based on normal stars - Neutron stars now have an accurate diameter - Adapted matter jet postprocess to account for the diameter reduction - Neutron stars are now flagged as themselves on the star map - Neutron stars are no longer bananas - Black hole is no longer a StellarType - StellarTypes proportions are now based on real world classification data - Star radiuses are now based on their stellar type - Removed old and deprecated stellartype definition - StellarObjects now share by their interface some blackbody radiation logic with a temperature and an associated color --- src/shaders/matterjet.glsl | 4 +- src/ts/architecture/stellarObject.ts | 7 +- src/ts/model/common.ts | 1 + src/ts/planets/gasPlanet/gasPlanetMaterial.ts | 4 +- .../telluricPlanet/telluricPlanetMaterial.ts | 5 +- src/ts/postProcesses/lensFlarePostProcess.ts | 7 +- src/ts/postProcesses/matterJetPostProcess.ts | 2 +- src/ts/postProcesses/postProcessManager.ts | 6 +- src/ts/postProcesses/uniforms.ts | 5 +- .../volumetricCloudsPostProcess.ts | 2 +- src/ts/postProcesses/volumetricLight.ts | 5 +- src/ts/starSystem/StarSystemView.ts | 6 +- src/ts/starSystem/starSystemController.ts | 4 +- src/ts/starSystem/starSystemHelper.ts | 20 +-- src/ts/starSystem/starSystemModel.ts | 10 +- src/ts/starmap/starMap.ts | 45 +++++-- .../blackHole/blackHoleModel.ts | 10 +- src/ts/stellarObjects/common.ts | 4 - .../stellarObjects/neutronStar/neutronStar.ts | 127 +++++++++++++++++- .../neutronStar/neutronStarModel.ts | 69 +++++++++- src/ts/stellarObjects/star/starMaterial.ts | 8 +- src/ts/stellarObjects/star/starModel.ts | 87 +++++++++--- src/ts/stellarObjects/stellarObject.ts | 21 --- src/ts/uberCore/postProcesses/types.ts | 8 +- .../uberCore/postProcesses/uberPostProcess.ts | 7 +- src/ts/utils/algebra.ts | 9 ++ src/ts/utils/specrend.ts | 6 +- src/ts/utils/wheelOfFortune.ts | 34 +++++ 28 files changed, 412 insertions(+), 111 deletions(-) delete mode 100644 src/ts/stellarObjects/stellarObject.ts create mode 100644 src/ts/utils/wheelOfFortune.ts diff --git a/src/shaders/matterjet.glsl b/src/shaders/matterjet.glsl index 50dd3c6ee..b04bb1139 100644 --- a/src/shaders/matterjet.glsl +++ b/src/shaders/matterjet.glsl @@ -98,8 +98,8 @@ float spiralDensity(vec3 pointOnCone, vec3 coneAxis, float coneMaxHeight) { float density = 1.0; - // smoothstep fadeout when the height is too much (outside of cone) or too low (too close to the star) - density *= smoothstep(1.0, 0.0, heightFraction) * smoothstep(0.0, 0.05, heightFraction); + // smoothstep fadeout when the height is too much (outside of cone) + density *= smoothstep(1.0, 0.0, heightFraction); float d = spiralSDF(theta + time, 0.2 + sqrt(heightFraction) / 2.0) / (0.3 + heightFraction * 2.0); //d = pow(d, 4.0); diff --git a/src/ts/architecture/stellarObject.ts b/src/ts/architecture/stellarObject.ts index e19892d90..dde659d9f 100644 --- a/src/ts/architecture/stellarObject.ts +++ b/src/ts/architecture/stellarObject.ts @@ -17,7 +17,7 @@ import { PointLight } from "@babylonjs/core/Lights/pointLight"; import { CelestialBody, CelestialBodyModel } from "./celestialBody"; -import { STELLAR_TYPE } from "../stellarObjects/common"; +import { Color3 } from "@babylonjs/core/Maths/math.color"; export interface StellarObject extends CelestialBody { model: StellarObjectModel; @@ -26,5 +26,6 @@ export interface StellarObject extends CelestialBody { } export interface StellarObjectModel extends CelestialBodyModel { - stellarType: STELLAR_TYPE; -} + readonly temperature: number; + readonly color: Color3; +} \ No newline at end of file diff --git a/src/ts/model/common.ts b/src/ts/model/common.ts index f9f84c02a..5c27377c0 100644 --- a/src/ts/model/common.ts +++ b/src/ts/model/common.ts @@ -31,6 +31,7 @@ export enum GENERATION_STEPS { ACCENNT_COLOR = 400, TEMPERATURE = 1100, + STELLAR_TYPE = 1900, PRESSURE = 1100, WATER_AMOUNT = 1200, diff --git a/src/ts/planets/gasPlanet/gasPlanetMaterial.ts b/src/ts/planets/gasPlanet/gasPlanetMaterial.ts index 0cc306500..696935048 100644 --- a/src/ts/planets/gasPlanet/gasPlanetMaterial.ts +++ b/src/ts/planets/gasPlanet/gasPlanetMaterial.ts @@ -27,7 +27,7 @@ import { Color3 } from "@babylonjs/core/Maths/math.color"; import { Vector3 } from "@babylonjs/core/Maths/math.vector"; import { TransformNode } from "@babylonjs/core/Meshes"; import { Star } from "../../stellarObjects/star/star"; -import { flattenVector3Array } from "../../utils/algebra"; +import { flattenColor3Array, flattenVector3Array } from "../../utils/algebra"; import { Camera } from "@babylonjs/core/Cameras/camera"; import { Transformable } from "../../architecture/transformable"; @@ -103,7 +103,7 @@ export class GasPlanetMaterial extends ShaderMaterial { this.setVector3("playerPosition", player.globalPosition); this.setArray3("star_positions", flattenVector3Array(stellarObjects.map((star) => star.getTransform().getAbsolutePosition()))); - this.setArray3("star_colors", flattenVector3Array(stellarObjects.map((star) => (star instanceof Star ? star.model.surfaceColor : Vector3.One())))); + this.setArray3("star_colors", flattenColor3Array(stellarObjects.map((star) => (star instanceof Star ? star.model.color : Color3.White())))); this.setInt("nbStars", stellarObjects.length); this.setFloat("time", this.clock % 100000); diff --git a/src/ts/planets/telluricPlanet/telluricPlanetMaterial.ts b/src/ts/planets/telluricPlanet/telluricPlanetMaterial.ts index 34c58ea8c..8d740d6c8 100644 --- a/src/ts/planets/telluricPlanet/telluricPlanetMaterial.ts +++ b/src/ts/planets/telluricPlanet/telluricPlanetMaterial.ts @@ -28,9 +28,8 @@ import { ShaderMaterial } from "@babylonjs/core/Materials/shaderMaterial"; import { Color3 } from "@babylonjs/core/Maths/math.color"; import { Vector3 } from "@babylonjs/core/Maths/math"; import { TransformNode } from "@babylonjs/core/Meshes"; -import { getInverseRotationMatrix } from "../../uberCore/transforms/basicTransform"; import { Star } from "../../stellarObjects/star/star"; -import { flattenVector3Array } from "../../utils/algebra"; +import { flattenColor3Array, flattenVector3Array } from "../../utils/algebra"; import lutFragment from "../../../shaders/telluricPlanetMaterial/utils/lut.glsl"; import { ProceduralTexture } from "@babylonjs/core/Materials/Textures/Procedurals/proceduralTexture"; @@ -216,7 +215,7 @@ export class TelluricPlanetMaterial extends ShaderMaterial { this.setVector3("playerPosition", cameraPosition); this.setArray3("star_positions", flattenVector3Array(stellarObjects.map((star) => star.getTransform().getAbsolutePosition()))); - this.setArray3("star_colors", flattenVector3Array(stellarObjects.map((star) => (star instanceof Star ? star.model.surfaceColor : Vector3.One())))); + this.setArray3("star_colors", flattenColor3Array(stellarObjects.map((star) => (star instanceof Star ? star.model.color : Color3.White())))); this.setInt("nbStars", stellarObjects.length); this.setVector3("planetPosition", this.planetTransform.getAbsolutePosition()); diff --git a/src/ts/postProcesses/lensFlarePostProcess.ts b/src/ts/postProcesses/lensFlarePostProcess.ts index 538192dab..dc907450f 100644 --- a/src/ts/postProcesses/lensFlarePostProcess.ts +++ b/src/ts/postProcesses/lensFlarePostProcess.ts @@ -29,6 +29,7 @@ import { PhysicsRaycastResult } from "@babylonjs/core/Physics/physicsRaycastResu import { PhysicsEngineV2 } from "@babylonjs/core/Physics/v2"; import { Matrix } from "@babylonjs/core/Maths/math"; import { StellarObject } from "../architecture/stellarObject"; +import { Color3 } from "@babylonjs/core/Maths/math.color"; export type LensFlareSettings = { visibility: number; @@ -57,10 +58,10 @@ export class LensFlarePostProcess extends UberPostProcess implements ObjectPostP ...getActiveCameraUniforms(scene), { name: "flareColor", - type: UniformEnumType.Vector3, + type: UniformEnumType.Color3, get: () => { - if (object instanceof Star) return object.model.surfaceColor; - else return new Vector3(1, 1, 1); + if (object instanceof Star) return object.model.color; + else return new Color3(1, 1, 1); } }, { diff --git a/src/ts/postProcesses/matterJetPostProcess.ts b/src/ts/postProcesses/matterJetPostProcess.ts index 8798acf81..d50714ed1 100644 --- a/src/ts/postProcesses/matterJetPostProcess.ts +++ b/src/ts/postProcesses/matterJetPostProcess.ts @@ -20,9 +20,9 @@ import { UberScene } from "../uberCore/uberScene"; import { getActiveCameraUniforms, getObjectUniforms, getSamplers } from "./uniforms"; import { UberPostProcess } from "../uberCore/postProcesses/uberPostProcess"; import { Effect } from "@babylonjs/core/Materials/effect"; -import { StellarObject } from "../stellarObjects/stellarObject"; import { ObjectPostProcess, UpdatablePostProcess } from "./objectPostProcess"; import { UniformEnumType, ShaderSamplers, ShaderUniforms } from "../uberCore/postProcesses/types"; +import { StellarObject } from "../architecture/stellarObject"; export interface MatterJetUniforms { // the rotation period in seconds of the matter jet diff --git a/src/ts/postProcesses/postProcessManager.ts b/src/ts/postProcesses/postProcessManager.ts index 6ed79b406..f03098370 100644 --- a/src/ts/postProcesses/postProcessManager.ts +++ b/src/ts/postProcesses/postProcessManager.ts @@ -281,7 +281,7 @@ export class PostProcessManager { * Creates a new VolumetricLight postprocess for the given star and adds it to the manager. * @param star A star */ - public addVolumetricLight(star: Star) { + public addVolumetricLight(star: Star | NeutronStar) { this.volumetricLights.push(new VolumetricLight(star, this.scene)); } @@ -289,13 +289,14 @@ export class PostProcessManager { * Returns the volumetric light post process for the given star. Throws an error if no volumetric light is found. * @param star A star */ - public getVolumetricLight(star: Star): VolumetricLight | null { + public getVolumetricLight(star: Star | NeutronStar): VolumetricLight | null { return this.volumetricLights.find((vl) => vl.object === star) ?? null; } /** * Creates a new BlackHole postprocess for the given black hole and adds it to the manager. * @param blackHole A black hole + * @param starfieldRotation */ public addBlackHole(blackHole: BlackHole, starfieldRotation: Quaternion) { const blackhole = new BlackHolePostProcess(blackHole, this.scene, starfieldRotation); @@ -307,6 +308,7 @@ export class PostProcessManager { } public addMatterJet(neutronStar: NeutronStar) { + console.log("add matter jet"); this.matterJets.push(new MatterJetPostProcess(neutronStar.name, neutronStar, this.scene)); } diff --git a/src/ts/postProcesses/uniforms.ts b/src/ts/postProcesses/uniforms.ts index 510cbccfa..c9a8c1f67 100644 --- a/src/ts/postProcesses/uniforms.ts +++ b/src/ts/postProcesses/uniforms.ts @@ -22,6 +22,7 @@ import { BoundingSphere } from "../architecture/boundingSphere"; import { Star } from "../stellarObjects/star/star"; import { Transformable } from "../architecture/transformable"; import { Scene } from "@babylonjs/core/scene"; +import { Color3 } from "@babylonjs/core/Maths/math.color"; export function getActiveCameraUniforms(scene: Scene): ShaderUniforms { return [ @@ -93,8 +94,8 @@ export function getStellarObjectsUniforms(stars: Transformable[]): ShaderUniform }, { name: "star_colors", - type: UniformEnumType.Vector3Array, - get: () => stars.map((star) => (star instanceof Star ? star.model.surfaceColor : Vector3.One())) + type: UniformEnumType.Color3Array, + get: () => stars.map((star) => (star instanceof Star ? star.model.color : Color3.White())) }, { name: "nbStars", diff --git a/src/ts/postProcesses/volumetricCloudsPostProcess.ts b/src/ts/postProcesses/volumetricCloudsPostProcess.ts index 7a79e3fdc..85fd6a328 100644 --- a/src/ts/postProcesses/volumetricCloudsPostProcess.ts +++ b/src/ts/postProcesses/volumetricCloudsPostProcess.ts @@ -23,11 +23,11 @@ import { ObjectPostProcess } from "./objectPostProcess"; import { FlatCloudsPostProcess } from "./clouds/flatCloudsPostProcess"; import { Effect } from "@babylonjs/core/Materials/effect"; import { UniformEnumType, ShaderSamplers, ShaderUniforms } from "../uberCore/postProcesses/types"; -import { StellarObject } from "../stellarObjects/stellarObject"; import { CloudsUniforms } from "./clouds/cloudsUniforms"; import { BoundingSphere } from "../architecture/boundingSphere"; import { Transformable } from "../architecture/transformable"; +import { StellarObject } from "../architecture/stellarObject"; export type CloudsPostProcess = FlatCloudsPostProcess | VolumetricCloudsPostProcess; diff --git a/src/ts/postProcesses/volumetricLight.ts b/src/ts/postProcesses/volumetricLight.ts index d183f8792..3d2796403 100644 --- a/src/ts/postProcesses/volumetricLight.ts +++ b/src/ts/postProcesses/volumetricLight.ts @@ -20,11 +20,12 @@ import { UberScene } from "../uberCore/uberScene"; import { Texture } from "@babylonjs/core/Materials/Textures/texture"; import { ObjectPostProcess } from "./objectPostProcess"; import { Star } from "../stellarObjects/star/star"; +import { NeutronStar } from "../stellarObjects/neutronStar/neutronStar"; export class VolumetricLight extends VolumetricLightScatteringPostProcess implements ObjectPostProcess { - readonly object: Star; + readonly object: Star | NeutronStar; - constructor(star: Star, scene: UberScene) { + constructor(star: Star | NeutronStar, scene: UberScene) { if (scene.activeCamera === null) throw new Error("no camera"); super(`${star.name}VolumetricLight`, 1, scene.activeCamera, star.mesh, 100, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, scene); diff --git a/src/ts/starSystem/StarSystemView.ts b/src/ts/starSystem/StarSystemView.ts index 5cf539e19..50a747744 100644 --- a/src/ts/starSystem/StarSystemView.ts +++ b/src/ts/starSystem/StarSystemView.ts @@ -48,6 +48,7 @@ import { parsePercentageFrom01, parseSpeed } from "../utils/parseToStrings"; import { Assets } from "../assets"; import { getRotationQuaternion, setRotationQuaternion } from "../uberCore/transforms/basicTransform"; import { Observable } from "@babylonjs/core/Misc/observable"; +import { NeutronStar } from "../stellarObjects/neutronStar/neutronStar"; export class StarSystemView { private readonly helmetOverlay: HelmetOverlay; @@ -159,7 +160,10 @@ export class StarSystemView { this.axisRenderer.setObjects(this.getStarSystem().getBodies()); const activeController = this.scene.getActiveController(); - positionNearObjectBrightSide(activeController, firstBody, this.getStarSystem(), firstBody instanceof BlackHole ? 7 : 5); + let controllerDistanceFactor = 5; + if(firstBody instanceof BlackHole) controllerDistanceFactor = 7; + else if(firstBody instanceof NeutronStar) controllerDistanceFactor = 100_000; + positionNearObjectBrightSide(activeController, firstBody, this.getStarSystem(), controllerDistanceFactor); this.getStarSystem() .initPostProcesses() diff --git a/src/ts/starSystem/starSystemController.ts b/src/ts/starSystem/starSystemController.ts index 41f16ed24..fd8b59f9b 100644 --- a/src/ts/starSystem/starSystemController.ts +++ b/src/ts/starSystem/starSystemController.ts @@ -298,8 +298,8 @@ export class StarSystemController { this.postProcessManager.addOcean(object as TelluricPlanet, this.stellarObjects); break; case PostProcessType.VOLUMETRIC_LIGHT: - if (!(object instanceof Star)) throw new Error("Volumetric light post process can only be added to stars. Source:" + object.name); - this.postProcessManager.addVolumetricLight(object as Star); + if (!(object instanceof Star) && !(object instanceof NeutronStar)) throw new Error("Volumetric light post process can only be added to stars and neutron stars. Source:" + object.name); + this.postProcessManager.addVolumetricLight(object); break; case PostProcessType.MANDELBULB: if (!(object instanceof Mandelbulb)) throw new Error("Mandelbulb post process can only be added to mandelbulbs. Source:" + object.name); diff --git a/src/ts/starSystem/starSystemHelper.ts b/src/ts/starSystem/starSystemHelper.ts index f3cd1a5aa..fc81f7f3b 100644 --- a/src/ts/starSystem/starSystemHelper.ts +++ b/src/ts/starSystem/starSystemHelper.ts @@ -77,7 +77,7 @@ export class StarSystemHelper { to a system that already has ${starsystem.stellarObjects.length} stars. The capacity of the generator was supposed to be ${starsystem.model.getNbStars()} starsystem is not a problem, but it may be.`); const name = starName(starsystem.model.getName(), starsystem.stellarObjects.length); - const neutronStar = new NeutronStar(name, starsystem.scene, model, starsystem.stellarObjects[0]); + const neutronStar = new NeutronStar(name, starsystem.scene, model, starsystem.stellarObjects.length > 0 ? starsystem.stellarObjects[0] : null); starsystem.addStellarObject(neutronStar); return neutronStar; @@ -89,13 +89,17 @@ export class StarSystemHelper { * @param seed The seed to use for the star generation (by default, the next available seed planned by the system model) */ public static makeStellarObject(starsystem: StarSystemController, seed: number = starsystem.model.getStarSeed(starsystem.stellarObjects.length)): StellarObject { - const isStellarObjectBlackHole = starsystem.model.getBodyTypeOfStar(starsystem.stellarObjects.length) === BODY_TYPE.BLACK_HOLE; - if (isStellarObjectBlackHole) return StarSystemHelper.makeBlackHole(starsystem, seed); - - const isStellarObjectNeutronStar = starsystem.model.getBodyTypeOfStar(starsystem.stellarObjects.length) === BODY_TYPE.NEUTRON_STAR; - if (isStellarObjectNeutronStar) return StarSystemHelper.makeNeutronStar(starsystem, seed); - - return this.makeStar(starsystem, seed); + const stellarObjectType = starsystem.model.getBodyTypeOfStar(starsystem.stellarObjects.length); + switch (stellarObjectType) { + case BODY_TYPE.BLACK_HOLE: + return StarSystemHelper.makeBlackHole(starsystem, seed); + case BODY_TYPE.NEUTRON_STAR: + return StarSystemHelper.makeNeutronStar(starsystem, seed); + case BODY_TYPE.STAR: + return StarSystemHelper.makeStar(starsystem, seed); + default: + throw new Error(`Unknown stellar object type ${stellarObjectType}`); + } } /** diff --git a/src/ts/starSystem/starSystemModel.ts b/src/ts/starSystem/starSystemModel.ts index ef058fcd5..d8a8ab48f 100644 --- a/src/ts/starSystem/starSystemModel.ts +++ b/src/ts/starSystem/starSystemModel.ts @@ -67,11 +67,17 @@ export class StarSystemModel { return centeredRand(this.rng, GENERATION_STEPS.GENERATE_STARS + index) * Settings.SEED_HALF_RANGE; } + /** + * Get the body type of the star + * @param index + * @see https://physics.stackexchange.com/questions/442154/how-common-are-neutron-stars + */ public getBodyTypeOfStar(index: number) { if (index > this.getNbStars()) throw new Error("Star out of bound! " + index); - if (uniformRandBool(0.002, this.rng, GENERATION_STEPS.GENERATE_STARS + index)) return BODY_TYPE.BLACK_HOLE; - if (uniformRandBool(0.05, this.rng, GENERATION_STEPS.GENERATE_STARS + index)) return BODY_TYPE.NEUTRON_STAR; + // percentages are taken from https://physics.stackexchange.com/questions/442154/how-common-are-neutron-stars + if (uniformRandBool(0.0006, this.rng, GENERATION_STEPS.GENERATE_STARS + index)) return BODY_TYPE.BLACK_HOLE; + if (uniformRandBool(0.0026, this.rng, GENERATION_STEPS.GENERATE_STARS + index)) return BODY_TYPE.NEUTRON_STAR; return BODY_TYPE.STAR; } diff --git a/src/ts/starmap/starMap.ts b/src/ts/starmap/starMap.ts index a451d6cfb..a72a9af17 100644 --- a/src/ts/starmap/starMap.ts +++ b/src/ts/starmap/starMap.ts @@ -49,6 +49,7 @@ import { Keyboard } from "../inputs/keyboard"; import { StarModel } from "../stellarObjects/star/starModel"; import { BlackHoleModel } from "../stellarObjects/blackHole/blackHoleModel"; import { SystemSeed } from "../utils/systemSeed"; +import { NeutronStarModel } from "../stellarObjects/neutronStar/neutronStarModel"; export class StarMap { readonly scene: Scene; @@ -140,9 +141,9 @@ export class StarMap { pipeline.fxaaEnabled = true; pipeline.bloomEnabled = true; pipeline.bloomThreshold = 0.0; - pipeline.bloomWeight = 1.2; + pipeline.bloomWeight = 1.5; pipeline.bloomKernel = 128; - pipeline.imageProcessing.exposure = 1.1; + pipeline.imageProcessing.exposure = 1.5; pipeline.imageProcessing.contrast = 1.0; this.starMapCenterPosition = Vector3.Zero(); @@ -367,14 +368,28 @@ export class StarMap { const starSystemModel = new StarSystemModel(starSystemSeed); const starSeed = starSystemModel.getStarSeed(0); - const isStarBlackHole = starSystemModel.getBodyTypeOfStar(0) === BODY_TYPE.BLACK_HOLE; - - const starModel = !isStarBlackHole ? new StarModel(starSeed) : new BlackHoleModel(starSeed); + const stellarObjectType = starSystemModel.getBodyTypeOfStar(0); + + let starModel: StarModel | BlackHoleModel | NeutronStarModel | null = null; + switch (stellarObjectType) { + case BODY_TYPE.STAR: + starModel = new StarModel(starSeed); + break; + case BODY_TYPE.BLACK_HOLE: + starModel = new BlackHoleModel(starSeed); + break; + case BODY_TYPE.NEUTRON_STAR: + starModel = new NeutronStarModel(starSeed); + break; + default: + throw new Error("Unknown stellar object type!"); + } + if(starModel === null) throw new Error("Star model is null!"); let instance: InstancedMesh | null = null; let recycled = false; - if (!isStarBlackHole) { + if (stellarObjectType === BODY_TYPE.STAR || stellarObjectType === BODY_TYPE.NEUTRON_STAR) { if (this.recycledStars.length > 0) { instance = this.recycledStars[0]; this.recycledStars.shift(); @@ -396,9 +411,9 @@ export class StarMap { initializedInstance.scaling = Vector3.One().scaleInPlace(data.scale); initializedInstance.position = data.position.add(this.starMapCenterPosition); - if (starModel instanceof StarModel) { - const starColor = starModel.surfaceColor; - initializedInstance.instancedBuffers.color = new Color4(starColor.x, starColor.y, starColor.z, 0.0); + if (starModel.bodyType === BODY_TYPE.STAR || starModel.bodyType === BODY_TYPE.NEUTRON_STAR) { + const starColor = starModel.color; + initializedInstance.instancedBuffers.color = new Color4(starColor.r, starColor.g, starColor.b, 0.0); } else { initializedInstance.instancedBuffers.color = new Color4(1.0, 0.6, 0.3, 0.0); } @@ -431,7 +446,15 @@ export class StarMap { const distance = 15 * currentInstance.getAbsolutePosition().subtract(initializedInstance.getAbsolutePosition()).length(); text += `Distance: ${distance.toFixed(2)}ly\n`; } - text += `Type: ${getStellarTypeString(starModel.stellarType)}\n`; + + if(starModel === null) throw new Error("Star model is null!"); + + let typeString = ""; + if(starModel.bodyType === BODY_TYPE.BLACK_HOLE) typeString = "Black hole"; + else if(starModel.bodyType === BODY_TYPE.NEUTRON_STAR) typeString = "Neutron star"; + else typeString = getStellarTypeString(starModel.stellarType); + text += `Type: ${typeString}\n`; + text += `Planets: ${starSystemModel.getNbPlanets()}\n`; this.starMapUI.attachUIToMesh(initializedInstance); @@ -449,7 +472,7 @@ export class StarMap { this.fadeIn(initializedInstance); - if (isStarBlackHole) this.loadedStarSectors.get(data.sectorString)?.blackHoleInstances.push(initializedInstance); + if (starModel.bodyType === BODY_TYPE.BLACK_HOLE) this.loadedStarSectors.get(data.sectorString)?.blackHoleInstances.push(initializedInstance); else this.loadedStarSectors.get(data.sectorString)?.starInstances.push(initializedInstance); } diff --git a/src/ts/stellarObjects/blackHole/blackHoleModel.ts b/src/ts/stellarObjects/blackHole/blackHoleModel.ts index 310a8e77b..cf042bcc1 100644 --- a/src/ts/stellarObjects/blackHole/blackHoleModel.ts +++ b/src/ts/stellarObjects/blackHole/blackHoleModel.ts @@ -20,11 +20,11 @@ import { getOrbitalPeriod } from "../../orbit/orbit"; import { Vector3 } from "@babylonjs/core/Maths/math.vector"; import { normalRandom } from "extended-random"; import { OrbitProperties } from "../../orbit/orbitProperties"; -import { STELLAR_TYPE } from "../common"; import { BODY_TYPE, GENERATION_STEPS } from "../../model/common"; -import { StellarObjectModel } from "../../architecture/stellarObject"; import { BlackHolePhysicalProperties } from "../../architecture/physicalProperties"; import { CelestialBodyModel } from "../../architecture/celestialBody"; +import { StellarObjectModel } from "../../architecture/stellarObject"; +import { Color3 } from "@babylonjs/core/Maths/math.color"; export class BlackHoleModel implements StellarObjectModel { readonly bodyType = BODY_TYPE.BLACK_HOLE; @@ -33,12 +33,14 @@ export class BlackHoleModel implements StellarObjectModel { readonly radius: number; - readonly stellarType = STELLAR_TYPE.BLACK_HOLE; - readonly orbit: OrbitProperties; readonly physicalProperties: BlackHolePhysicalProperties; + //TODO: compute temperature of accretion disk (function of rotation speed) + readonly temperature = 0; + readonly color = Color3.Black(); + readonly parentBody: CelestialBodyModel | null; readonly childrenBodies: CelestialBodyModel[] = []; diff --git a/src/ts/stellarObjects/common.ts b/src/ts/stellarObjects/common.ts index 6edde025b..5ab4d25ae 100644 --- a/src/ts/stellarObjects/common.ts +++ b/src/ts/stellarObjects/common.ts @@ -30,8 +30,6 @@ export enum STELLAR_TYPE { K, /** 2,700 - 3,500 K */ M, - /** Black hole */ - BLACK_HOLE } export function getStellarTypeString(type: STELLAR_TYPE): string { @@ -50,7 +48,5 @@ export function getStellarTypeString(type: STELLAR_TYPE): string { return "K"; case STELLAR_TYPE.M: return "M"; - case STELLAR_TYPE.BLACK_HOLE: - return "Black hole"; } } diff --git a/src/ts/stellarObjects/neutronStar/neutronStar.ts b/src/ts/stellarObjects/neutronStar/neutronStar.ts index d58bac651..ee3c72329 100644 --- a/src/ts/stellarObjects/neutronStar/neutronStar.ts +++ b/src/ts/stellarObjects/neutronStar/neutronStar.ts @@ -15,14 +15,47 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import { Star } from "../star/star"; import { NeutronStarModel } from "./neutronStarModel"; import { UberScene } from "../../uberCore/uberScene"; import { PostProcessType } from "../../postProcesses/postProcessTypes"; import { CelestialBody } from "../../architecture/celestialBody"; +import { StellarObject } from "../../architecture/stellarObject"; +import { Cullable } from "../../bodies/cullable"; +import { Mesh } from "@babylonjs/core/Meshes/mesh"; +import { PointLight } from "@babylonjs/core/Lights/pointLight"; +import { StarMaterial } from "../star/starMaterial"; +import { PhysicsAggregate } from "@babylonjs/core/Physics/v2/physicsAggregate"; +import { OrbitalObject } from "../../architecture/orbitalObject"; +import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder"; +import { PhysicsShapeType } from "@babylonjs/core/Physics/v2/IPhysicsEnginePlugin"; +import { Vector3 } from "@babylonjs/core/Maths/math.vector"; +import { PhysicsShapeSphere } from "@babylonjs/core/Physics/v2/physicsShape"; +import { getRgbFromTemperature } from "../../utils/specrend"; +import { Light } from "@babylonjs/core/Lights/light"; +import { setRotationQuaternion } from "../../uberCore/transforms/basicTransform"; +import { Quaternion } from "@babylonjs/core/Maths/math"; +import { TransformNode } from "@babylonjs/core/Meshes"; +import { OrbitProperties } from "../../orbit/orbitProperties"; +import { OrbitalObjectPhysicalProperties } from "../../architecture/physicalProperties"; +import { RingsUniforms } from "../../postProcesses/rings/ringsUniform"; +import { Camera } from "@babylonjs/core/Cameras/camera"; +import { isSizeOnScreenEnough } from "../../utils/isObjectVisibleOnScreen"; -export class NeutronStar extends Star { - readonly descriptor: NeutronStarModel; +export class NeutronStar implements StellarObject, Cullable { + readonly model: NeutronStarModel; + + readonly name: string; + + readonly mesh: Mesh; + readonly light: PointLight; + + private readonly material: StarMaterial; + + readonly aggregate: PhysicsAggregate; + + readonly postProcesses: PostProcessType[] = []; + + readonly parent: OrbitalObject | null; /** * New Star @@ -32,14 +65,96 @@ export class NeutronStar extends Star { * @param parentBody */ constructor(name: string, scene: UberScene, model: number | NeutronStarModel, parentBody: CelestialBody | null = null) { - super(name, scene, model, parentBody); + this.model = model instanceof NeutronStarModel ? model : new NeutronStarModel(model, parentBody?.model); + this.name = name; + + this.parent = parentBody; + + this.mesh = MeshBuilder.CreateSphere( + `${name}Mesh`, + { + diameter: this.model.radius * 2, + segments: 32 + }, + scene + ); + + this.aggregate = new PhysicsAggregate( + this.getTransform(), + PhysicsShapeType.CONTAINER, + { + mass: 0, + restitution: 0.2 + }, + scene + ); + this.aggregate.body.setMassProperties({ inertia: Vector3.Zero(), mass: 0 }); + this.aggregate.body.disablePreStep = false; + const physicsShape = new PhysicsShapeSphere(Vector3.Zero(), this.model.radius, scene); + this.aggregate.shape.addChildFromParent(this.getTransform(), physicsShape, this.mesh); - this.descriptor = model instanceof NeutronStarModel ? model : new NeutronStarModel(model, parentBody?.model); + this.light = new PointLight(`${name}Light`, Vector3.Zero(), scene); + this.light.diffuse.fromArray(getRgbFromTemperature(this.model.physicalProperties.temperature).asArray()); + this.light.falloffType = Light.FALLOFF_STANDARD; + this.light.parent = this.getTransform(); - this.postProcesses.push(PostProcessType.MATTER_JETS); + this.material = new StarMaterial(this.getTransform(), this.model, scene); + this.mesh.material = this.material; + + setRotationQuaternion(this.getTransform(), Quaternion.Identity()); + + this.postProcesses.push(PostProcessType.VOLUMETRIC_LIGHT, PostProcessType.LENS_FLARE, PostProcessType.MATTER_JETS); + if (this.model.ringsUniforms !== null) this.postProcesses.push(PostProcessType.RING); + } + + getTransform(): TransformNode { + return this.mesh; } getTypeName(): string { return "Neutron Star"; } + + + getRotationAxis(): Vector3 { + return this.getTransform().up; + } + + getLight(): PointLight { + return this.light; + } + + getOrbitProperties(): OrbitProperties { + return this.model.orbit; + } + + getPhysicalProperties(): OrbitalObjectPhysicalProperties { + return this.model.physicalProperties; + } + + getRingsUniforms(): RingsUniforms | null { + return this.model.ringsUniforms; + } + + public updateMaterial(deltaTime: number): void { + this.material.update(deltaTime); + } + + public getRadius(): number { + return this.model.radius; + } + + public getBoundingRadius(): number { + return this.getRadius(); + } + + public computeCulling(camera: Camera): void { + this.mesh.isVisible = isSizeOnScreenEnough(this, camera); + } + + public dispose(): void { + this.mesh.dispose(); + this.light.dispose(); + this.material.dispose(); + } } diff --git a/src/ts/stellarObjects/neutronStar/neutronStarModel.ts b/src/ts/stellarObjects/neutronStar/neutronStarModel.ts index 8e2a60342..04052a00d 100644 --- a/src/ts/stellarObjects/neutronStar/neutronStarModel.ts +++ b/src/ts/stellarObjects/neutronStar/neutronStarModel.ts @@ -15,11 +15,74 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import { StarModel } from "../star/starModel"; import { CelestialBodyModel } from "../../architecture/celestialBody"; +import { BODY_TYPE, GENERATION_STEPS } from "../../model/common"; +import { Vector3 } from "@babylonjs/core/Maths/math.vector"; +import { OrbitProperties } from "../../orbit/orbitProperties"; +import { StarPhysicalProperties } from "../../architecture/physicalProperties"; +import { StellarObjectModel } from "../../architecture/stellarObject"; +import { seededSquirrelNoise } from "squirrel-noise"; +import { getRgbFromTemperature } from "../../utils/specrend"; +import { getOrbitalPeriod } from "../../orbit/orbit"; +import { normalRandom, randRangeInt, uniformRandBool } from "extended-random"; +import { RingsUniforms } from "../../postProcesses/rings/ringsUniform"; +import { clamp } from "../../utils/math"; +import { Color3 } from "@babylonjs/core/Maths/math.color"; + +export class NeutronStarModel implements StellarObjectModel { + readonly bodyType = BODY_TYPE.NEUTRON_STAR; + readonly rng: (step: number) => number; + readonly seed: number; + + readonly temperature: number; + readonly color: Color3; + readonly radius: number; + + readonly orbit: OrbitProperties; + + readonly physicalProperties: StarPhysicalProperties; + + static RING_PROPORTION = 0.02; + readonly ringsUniforms; + + readonly parentBody: CelestialBodyModel | null; + + readonly childrenBodies: CelestialBodyModel[] = []; -export class NeutronStarModel extends StarModel { constructor(seed: number, parentBody: CelestialBodyModel | null = null) { - super(seed, parentBody); + this.seed = seed; + this.rng = seededSquirrelNoise(this.seed); + + this.temperature = randRangeInt(200_000, 5_000_000_000, this.rng, GENERATION_STEPS.TEMPERATURE); + this.color = getRgbFromTemperature(this.temperature); + + this.parentBody = parentBody; + + this.physicalProperties = { + mass: 1000, + rotationPeriod: 24 * 60 * 60, + temperature: this.temperature, + axialTilt: 0 + }; + + this.radius = clamp(normalRandom(10e3, 1e3, this.rng, GENERATION_STEPS.RADIUS), 2e3, 50e3); + + // TODO: do not hardcode + const orbitRadius = this.rng(GENERATION_STEPS.ORBIT) * 5000000e3; + + this.orbit = { + radius: orbitRadius, + p: 2, + period: getOrbitalPeriod(orbitRadius, this.parentBody?.physicalProperties.mass ?? 0), + normalToPlane: Vector3.Up(), + isPlaneAlignedWithParent: true + }; + + if (uniformRandBool(NeutronStarModel.RING_PROPORTION, this.rng, GENERATION_STEPS.RINGS)) { + this.ringsUniforms = new RingsUniforms(this.rng); + } else { + this.ringsUniforms = null; + } + } } diff --git a/src/ts/stellarObjects/star/starMaterial.ts b/src/ts/stellarObjects/star/starMaterial.ts index 1fbc88924..27c319715 100644 --- a/src/ts/stellarObjects/star/starMaterial.ts +++ b/src/ts/stellarObjects/star/starMaterial.ts @@ -21,20 +21,20 @@ import { Effect } from "@babylonjs/core/Materials/effect"; import { ShaderMaterial } from "@babylonjs/core/Materials/shaderMaterial"; import { Scene } from "@babylonjs/core/scene"; import { TransformNode } from "@babylonjs/core/Meshes/transformNode"; -import { StarModel } from "./starModel"; import { getInverseRotationQuaternion } from "../../uberCore/transforms/basicTransform"; import { Assets } from "../../assets"; import { ProceduralTexture } from "@babylonjs/core/Materials/Textures/Procedurals/proceduralTexture"; import lutFragment from "../../../shaders/starMaterial/utils/lut.glsl"; +import { StellarObjectModel } from "../../architecture/stellarObject"; export class StarMaterial extends ShaderMaterial { star: TransformNode; - starModel: StarModel; + starModel: StellarObjectModel; starSeed: number; private internalClock = 0; - constructor(star: TransformNode, model: StarModel, scene: Scene) { + constructor(star: TransformNode, model: StellarObjectModel, scene: Scene) { const shaderName = "starMaterial"; if (Effect.ShadersStore[`${shaderName}FragmentShader`] === undefined) { Effect.ShadersStore[`${shaderName}FragmentShader`] = starMaterialFragment; @@ -69,7 +69,7 @@ export class StarMaterial extends ShaderMaterial { this.internalClock += deltaTime; this.setFloat("time", this.internalClock % 100000); - this.setVector3("starColor", this.starModel.surfaceColor); + this.setColor3("starColor", this.starModel.color); this.setQuaternion("starInverseRotationQuaternion", getInverseRotationQuaternion(this.star)); this.setFloat("seed", this.starSeed); this.setVector3("starPosition", this.star.getAbsolutePosition()); diff --git a/src/ts/stellarObjects/star/starModel.ts b/src/ts/stellarObjects/star/starModel.ts index 9fe926308..d86789d3a 100644 --- a/src/ts/stellarObjects/star/starModel.ts +++ b/src/ts/stellarObjects/star/starModel.ts @@ -16,8 +16,7 @@ // along with this program. If not, see . import { seededSquirrelNoise } from "squirrel-noise"; -import { clamp } from "terrain-generation"; -import { normalRandom, randRange, uniformRandBool } from "extended-random"; +import { randRange, randRangeInt, uniformRandBool } from "extended-random"; import { Vector3 } from "@babylonjs/core/Maths/math.vector"; import { getRgbFromTemperature } from "../../utils/specrend"; import { Settings } from "../../settings"; @@ -28,20 +27,20 @@ import { STELLAR_TYPE } from "../common"; import { RingsUniforms } from "../../postProcesses/rings/ringsUniform"; import { StarPhysicalProperties } from "../../architecture/physicalProperties"; import { CelestialBodyModel } from "../../architecture/celestialBody"; +import { wheelOfFortune } from "../../utils/wheelOfFortune"; import { StellarObjectModel } from "../../architecture/stellarObject"; +import { Color3 } from "@babylonjs/core/Maths/math.color"; export class StarModel implements StellarObjectModel { readonly bodyType = BODY_TYPE.STAR; readonly rng: (step: number) => number; readonly seed: number; - readonly surfaceColor: Vector3; + readonly temperature: number; + readonly color: Color3; stellarType: STELLAR_TYPE; readonly radius: number; - readonly mass = 1000; - readonly rotationPeriod = 24 * 60 * 60; - readonly orbit: OrbitProperties; readonly physicalProperties: StarPhysicalProperties; @@ -57,23 +56,21 @@ export class StarModel implements StellarObjectModel { this.seed = seed; this.rng = seededSquirrelNoise(this.seed); - const surfaceTemperature = clamp(normalRandom(5778, 2000, this.rng, GENERATION_STEPS.TEMPERATURE), 3000, 10000); + this.stellarType = StarModel.GetRandomStellarType(this.rng); + + this.temperature = StarModel.GetRandomTemperatureFromStellarType(this.stellarType, this.rng); + this.color = getRgbFromTemperature(this.temperature); this.parentBody = parentBody; this.physicalProperties = { - mass: this.mass, - rotationPeriod: this.rotationPeriod, - temperature: surfaceTemperature, + mass: 1000, + rotationPeriod: 24 * 60 * 60, + temperature: this.temperature, axialTilt: 0 }; - this.surfaceColor = getRgbFromTemperature(surfaceTemperature); - - this.stellarType = StarModel.getStellarTypeFromTemperature(surfaceTemperature); - - //TODO: make it dependent on star type - this.radius = randRange(50, 200, this.rng, GENERATION_STEPS.RADIUS) * Settings.EARTH_RADIUS; + this.radius = StarModel.GetRandomRadiusFromStellarType(this.stellarType, this.rng); // TODO: do not hardcode const orbitRadius = this.rng(GENERATION_STEPS.ORBIT) * 5000000e3; @@ -96,7 +93,7 @@ export class StarModel implements StellarObjectModel { public setSurfaceTemperature(temperature: number) { this.physicalProperties.temperature = temperature; this.stellarType = StarModel.getStellarTypeFromTemperature(temperature); - this.surfaceColor.copyFrom(getRgbFromTemperature(temperature)); + this.color.copyFrom(getRgbFromTemperature(temperature)); } static getStellarTypeFromTemperature(temperature: number) { @@ -108,4 +105,60 @@ export class StarModel implements StellarObjectModel { else if (temperature < 30000) return STELLAR_TYPE.B; else return STELLAR_TYPE.O; } + + static GetRandomStellarType(rng: (step: number) => number) { + // use wheel of fortune + const wheel: [STELLAR_TYPE, number][] = [ + [STELLAR_TYPE.M, 0.765], + [STELLAR_TYPE.K, 0.121], + [STELLAR_TYPE.G, 0.076], + [STELLAR_TYPE.F, 0.03], + [STELLAR_TYPE.A, 0.006], + [STELLAR_TYPE.B, 0.0013], + [STELLAR_TYPE.O, 0.0000003] + ]; + + const r = rng(GENERATION_STEPS.STELLAR_TYPE); + + return wheelOfFortune(wheel, r); + } + + static GetRandomTemperatureFromStellarType(stellarType: STELLAR_TYPE, rng: (step: number) => number) { + switch (stellarType) { + case STELLAR_TYPE.M: + return randRangeInt(2100, 3400, rng, GENERATION_STEPS.TEMPERATURE); + case STELLAR_TYPE.K: + return randRangeInt(3400, 4900, rng, GENERATION_STEPS.TEMPERATURE); + case STELLAR_TYPE.G: + return randRangeInt(4900, 5700, rng, GENERATION_STEPS.TEMPERATURE); + case STELLAR_TYPE.F: + return randRangeInt(5700, 7200, rng, GENERATION_STEPS.TEMPERATURE); + case STELLAR_TYPE.A: + return randRangeInt(7200, 9700, rng, GENERATION_STEPS.TEMPERATURE); + case STELLAR_TYPE.B: + return randRangeInt(9700, 30000, rng, GENERATION_STEPS.TEMPERATURE); + case STELLAR_TYPE.O: + return randRangeInt(30000, 52000, rng, GENERATION_STEPS.TEMPERATURE); + } + } + + static GetRandomRadiusFromStellarType(stellarType: STELLAR_TYPE, rng: (step: number) => number) { + const solarSize = 109 * Settings.EARTH_RADIUS; + switch (stellarType) { + case STELLAR_TYPE.M: + return randRange(0.5, 0.7, rng, GENERATION_STEPS.RADIUS) * solarSize; + case STELLAR_TYPE.K: + return randRange(0.7, 0.9, rng, GENERATION_STEPS.RADIUS) * solarSize; + case STELLAR_TYPE.G: + return randRange(0.9, 1.1, rng, GENERATION_STEPS.RADIUS) * solarSize; + case STELLAR_TYPE.F: + return randRange(1.1, 1.4, rng, GENERATION_STEPS.RADIUS) * solarSize; + case STELLAR_TYPE.A: + return randRange(1.4, 1.8, rng, GENERATION_STEPS.RADIUS) * solarSize; + case STELLAR_TYPE.B: + return randRange(1.8, 6.6, rng, GENERATION_STEPS.RADIUS) * solarSize; + case STELLAR_TYPE.O: + return randRange(6.6, 15.0, rng, GENERATION_STEPS.RADIUS) * solarSize; + } + } } diff --git a/src/ts/stellarObjects/stellarObject.ts b/src/ts/stellarObjects/stellarObject.ts deleted file mode 100644 index b2776e372..000000000 --- a/src/ts/stellarObjects/stellarObject.ts +++ /dev/null @@ -1,21 +0,0 @@ -// This file is part of CosmosJourneyer -// -// Copyright (C) 2024 Barthélemy Paléologue -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -import { Star } from "./star/star"; -import { BlackHole } from "./blackHole/blackHole"; - -export type StellarObject = Star | BlackHole; diff --git a/src/ts/uberCore/postProcesses/types.ts b/src/ts/uberCore/postProcesses/types.ts index 8000bbf84..42c006d62 100644 --- a/src/ts/uberCore/postProcesses/types.ts +++ b/src/ts/uberCore/postProcesses/types.ts @@ -63,7 +63,11 @@ export enum UniformEnumType { /** * An array of floats. Shader code: float[] */ - FloatArray + FloatArray, + /** + * An array of Color3. Shader code: vec3[] + */ + Color3Array, } export enum SamplerEnumType { @@ -71,7 +75,7 @@ export enum SamplerEnumType { Texture } -export type UniformType = number | boolean | Vector3 | Color3 | Matrix | Quaternion | Texture | Vector3[] | Vector4[] | number[]; +export type UniformType = number | boolean | Vector3 | Color3 | Matrix | Quaternion | Texture | Vector3[] | Vector4[] | number[] | Color3[]; export type SamplerType = Texture | undefined; diff --git a/src/ts/uberCore/postProcesses/uberPostProcess.ts b/src/ts/uberCore/postProcesses/uberPostProcess.ts index 066b0bd4d..83ad84d6f 100644 --- a/src/ts/uberCore/postProcesses/uberPostProcess.ts +++ b/src/ts/uberCore/postProcesses/uberPostProcess.ts @@ -16,11 +16,11 @@ // along with this program. If not, see . import { Matrix, Quaternion, Vector3, Vector4 } from "@babylonjs/core/Maths/math.vector"; -import { flattenVector3Array, flattenVector4Array } from "../../utils/algebra"; +import { flattenColor3Array, flattenVector3Array, flattenVector4Array } from "../../utils/algebra"; import { Color3 } from "@babylonjs/core/Maths/math.color"; import { Texture } from "@babylonjs/core/Materials/Textures/texture"; import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess"; -import { UniformEnumType, ShaderSamplers, ShaderUniforms, SamplerEnumType } from "./types"; +import { SamplerEnumType, ShaderSamplers, ShaderUniforms, UniformEnumType } from "./types"; import { Scene } from "@babylonjs/core/scene"; /** @@ -79,6 +79,9 @@ export class UberPostProcess extends PostProcess { case UniformEnumType.FloatArray: effect.setFloatArray(uniform.name, uniform.get() as number[]); break; + case UniformEnumType.Color3Array: + effect.setFloatArray3(uniform.name, flattenColor3Array(uniform.get() as Color3[])); + break; case UniformEnumType.Auto: // BabylonJS already handles this break; diff --git a/src/ts/utils/algebra.ts b/src/ts/utils/algebra.ts index 0413ee2fe..712170b02 100644 --- a/src/ts/utils/algebra.ts +++ b/src/ts/utils/algebra.ts @@ -16,6 +16,7 @@ // along with this program. If not, see . import { Quaternion, Vector3, Vector4 } from "@babylonjs/core/Maths/math.vector"; +import { Color3 } from "@babylonjs/core/Maths/math.color"; /** * Removes the rotation around an axis from the quaternion @@ -58,6 +59,14 @@ export function flattenVector3Array(vector3Array: Vector3[]): number[] { return result; } +export function flattenColor3Array(color3Array: Color3[]): number[] { + const result: number[] = []; + for (const color3 of color3Array) { + result.push(color3.r, color3.g, color3.b); + } + return result; +} + export function flattenVector4Array(vector4Array: Vector4[]): number[] { const result: number[] = []; for (const vector4 of vector4Array) { diff --git a/src/ts/utils/specrend.ts b/src/ts/utils/specrend.ts index 0b5c22e42..31d323ead 100644 --- a/src/ts/utils/specrend.ts +++ b/src/ts/utils/specrend.ts @@ -468,9 +468,9 @@ export function demonstrate() { } } -import { Vector3 } from "@babylonjs/core/Maths/math.vector"; +import { Color3 } from "@babylonjs/core/Maths/math.color"; -export function getRgbFromTemperature(temperature: number): Vector3 { +export function getRgbFromTemperature(temperature: number): Color3 { const cs = HDTVsystem; bbTemp = temperature; @@ -478,5 +478,5 @@ export function getRgbFromTemperature(temperature: number): Vector3 { let [r, g, b] = xyz_to_rgb(cs, x, y, z); [r, g, b] = constrain_rgb(r, g, b); [r, g, b] = norm_rgb(r, g, b); - return new Vector3(r, g, b); + return new Color3(r, g, b); } diff --git a/src/ts/utils/wheelOfFortune.ts b/src/ts/utils/wheelOfFortune.ts new file mode 100644 index 000000000..87fa065a7 --- /dev/null +++ b/src/ts/utils/wheelOfFortune.ts @@ -0,0 +1,34 @@ +// This file is part of CosmosJourneyer +// +// Copyright (C) 2024 Barthélemy Paléologue +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +/** + * A useful function to randomly choose an option from a list of options, each option having a weight. + * @param options An array of tuples, each tuple being an option of type T and its weight. (The weights don't have to add up to 1.0, they are normalized internally.) + * @param randomValue A random value between 0.0 and 1.0 that you can provide with any random number generator of your choice. + * @returns The chosen option. + * @throws An error if the wheel of fortune failed. (This should never happen.) + */ +export function wheelOfFortune(options: [T, number][], randomValue: number): T { + const total = options.reduce((acc, [_, weight]) => acc + weight, 0); + const choice = randomValue * total; + let current = 0; + for (const [option, weight] of options) { + current += weight; + if (choice < current) return option; + } + throw new Error("Wheel of fortune failed"); +} \ No newline at end of file From 59fe055725b45a40ec8a197f6534af9ce047dcf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Sun, 28 Jan 2024 14:40:51 +0100 Subject: [PATCH 6/7] linting --- .eslintrc.json | 3 ++- package.json | 2 +- src/ts/defaultController/defaultControls.ts | 2 +- src/ts/planets/telluricPlanet/terrain/chunks/chunkTree.ts | 2 +- src/ts/spaceship/shipControls.ts | 4 ++++ src/ts/spaceship/spaceship.ts | 2 +- src/ts/spaceshipExtended/spaceship.ts | 4 ++-- src/ts/spaceshipExtended/thrusterMatrix.ts | 4 ++-- src/ts/starSystem/StarSystemView.ts | 2 +- src/ts/ui/objectOverlay.ts | 2 +- 10 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 0f1e325c9..592c053ef 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -15,6 +15,7 @@ "import/no-cycle": "error", "import/no-unresolved": "off", "@typescript-eslint/switch-exhaustiveness-check": "error", - "@typescript-eslint/no-inferrable-types": "off" + "@typescript-eslint/no-inferrable-types": "off", + "eqeqeq": "error" } } diff --git a/package.json b/package.json index 3f7cc5b6e..63f80b215 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "test": "jest --coverage", "docs": "typedoc --options typedoc.json", "serve:docs": "http-server docs -p 8081", - "lint:check": "eslint src/ts/**/*.ts", + "lint:check": "eslint 'src/ts/**/**/*.ts'", "lint:fix": "eslint src/ts/**/*.ts --fix" } } diff --git a/src/ts/defaultController/defaultControls.ts b/src/ts/defaultController/defaultControls.ts index cdf74e445..93edf92bb 100644 --- a/src/ts/defaultController/defaultControls.ts +++ b/src/ts/defaultController/defaultControls.ts @@ -90,7 +90,7 @@ export class DefaultControls implements Controls { displacement.addInPlace(upwardDisplacement); displacement.addInPlace(rightDisplacement); - if (input.getAcceleration() != 0) this.speed *= 1 + input.getAcceleration() / 10; + if (input.getAcceleration() !== 0) this.speed *= 1 + input.getAcceleration() / 10; return displacement; } diff --git a/src/ts/planets/telluricPlanet/terrain/chunks/chunkTree.ts b/src/ts/planets/telluricPlanet/terrain/chunks/chunkTree.ts index 9b89780bf..4f8334338 100644 --- a/src/ts/planets/telluricPlanet/terrain/chunks/chunkTree.ts +++ b/src/ts/planets/telluricPlanet/terrain/chunks/chunkTree.ts @@ -169,7 +169,7 @@ export class ChunkTree { * @returns The updated tree */ private updateLODRecursively(observerPositionW: Vector3, chunkForge: ChunkForge, tree: quadTree = this.tree, walked: number[] = []): quadTree { - if (walked.length == this.maxDepth) return tree; + if (walked.length === this.maxDepth) return tree; const nodeRelativePosition = getChunkSphereSpacePositionFromPath(walked, this.direction, this.rootChunkLength / 2, getRotationQuaternion(this.parent)); const nodePositionW = nodeRelativePosition.add(this.parent.getAbsolutePosition()); diff --git a/src/ts/spaceship/shipControls.ts b/src/ts/spaceship/shipControls.ts index f890e2a3c..1a9d17ab6 100644 --- a/src/ts/spaceship/shipControls.ts +++ b/src/ts/spaceship/shipControls.ts @@ -154,6 +154,10 @@ export class ShipControls implements Controls { for (const input of this.inputs) this.listenTo(input, deltaTime); + // camera shake + // this.thirdPersonCamera.alpha += (Math.random() - 0.5) / 500; + // this.thirdPersonCamera.beta += (Math.random() - 0.5) / 500; + this.getActiveCamera().getViewMatrix(true); return this.getTransform().getAbsolutePosition(); } diff --git a/src/ts/spaceship/spaceship.ts b/src/ts/spaceship/spaceship.ts index 412283ce7..ea6608a14 100644 --- a/src/ts/spaceship/spaceship.ts +++ b/src/ts/spaceship/spaceship.ts @@ -246,7 +246,7 @@ export class Spaceship implements Transformable { this.aggregate.body.setAngularDamping(1); } - if (this.state == ShipState.LANDING) { + if (this.state === ShipState.LANDING) { if (this.landingTarget === null) { throw new Error("Closest walkable object is null while landing"); } diff --git a/src/ts/spaceshipExtended/spaceship.ts b/src/ts/spaceshipExtended/spaceship.ts index 2cb1df35b..ce2688890 100644 --- a/src/ts/spaceshipExtended/spaceship.ts +++ b/src/ts/spaceshipExtended/spaceship.ts @@ -176,14 +176,14 @@ export class Spaceship { const spacePressed = keyboard.isPressed(" "); const forwardPressed = keyboard.isAnyPressed(["w", "z"]); - if (spacePressed != this.hoverThrustersRunning) { + if (spacePressed !== this.hoverThrustersRunning) { if (spacePressed) Assets.EngineRunningSound.play(); else Assets.EngineRunningSound.stop(); this.hoverThrustersRunning = spacePressed; } - if (forwardPressed != this.mainThrustersRunning) { + if (forwardPressed !== this.mainThrustersRunning) { if (forwardPressed) Assets.EngineRunningSound.play(); else Assets.EngineRunningSound.stop(); diff --git a/src/ts/spaceshipExtended/thrusterMatrix.ts b/src/ts/spaceshipExtended/thrusterMatrix.ts index adb31dfa8..79f08d315 100644 --- a/src/ts/spaceshipExtended/thrusterMatrix.ts +++ b/src/ts/spaceshipExtended/thrusterMatrix.ts @@ -45,7 +45,7 @@ export function buildThrusterMatrix(hoverThrusters: Thruster[]) { } export function getThrustAndTorque(thrusterConfiguration: number[], thrusterMatrix: Matrix): [Vector3, Vector3] { - if (thrusterMatrix.rows != 6) throw new Error("Thruster matrix must have 6 rows!"); + if (thrusterMatrix.rows !== 6) throw new Error("Thruster matrix must have 6 rows!"); const thrustAndTorque: [number, number, number, number, number, number] = [0, 0, 0, 0, 0, 0]; for (let i = 0; i < thrusterMatrix.rows; i++) { const row = thrusterMatrix.getRow(i); @@ -57,7 +57,7 @@ export function getThrustAndTorque(thrusterConfiguration: number[], thrusterMatr } export function getThrusterConfiguration(targetThrust: Vector3, targetTorque: Vector3, inverseThrusterMatrix: Matrix): number[] { - if (inverseThrusterMatrix.columns != 6) throw new Error("Inverse thruster matrix must have 6 columns!"); + if (inverseThrusterMatrix.columns !== 6) throw new Error("Inverse thruster matrix must have 6 columns!"); const targetThrustAndTorque = [targetThrust.x, targetThrust.y, targetThrust.z, targetTorque.x, targetTorque.y, targetTorque.z]; const nbThrusters = inverseThrusterMatrix.rows; const thrusterConfiguration = new Array(nbThrusters).fill(0); diff --git a/src/ts/starSystem/StarSystemView.ts b/src/ts/starSystem/StarSystemView.ts index 50a747744..78deaea16 100644 --- a/src/ts/starSystem/StarSystemView.ts +++ b/src/ts/starSystem/StarSystemView.ts @@ -337,7 +337,7 @@ export class StarSystemView { unZoom(callback: () => void) { const activeControls = this.scene.getActiveController(); - if (activeControls != this.getSpaceshipControls()) { + if (activeControls !== this.getSpaceshipControls()) { callback(); return; } diff --git a/src/ts/ui/objectOverlay.ts b/src/ts/ui/objectOverlay.ts index 0664d52ba..5dc8d6b62 100644 --- a/src/ts/ui/objectOverlay.ts +++ b/src/ts/ui/objectOverlay.ts @@ -104,7 +104,7 @@ export class ObjectOverlay { const objectRay = this.object.getTransform().getAbsolutePosition().subtract(camera.globalPosition); const distance = objectRay.length(); const deltaDistance = this.lastDistance - distance; - const speed = deltaDistance != 0 ? deltaDistance / (camera.getScene().getEngine().getDeltaTime() / 1000) : 0; + const speed = deltaDistance !== 0 ? deltaDistance / (camera.getScene().getEngine().getDeltaTime() / 1000) : 0; objectRay.scaleInPlace(1 / distance); if (Vector3.Dot(viewRay, objectRay) < 0) { From b8157e7f37993cc19f11a61c3e9e88e478205b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Sun, 28 Jan 2024 14:41:25 +0100 Subject: [PATCH 7/7] formatting --- src/ts/architecture/stellarObject.ts | 2 +- src/ts/index.ts | 1 - src/ts/settings.ts | 2 +- src/ts/spaceship/shipControls.ts | 8 +------- src/ts/spaceship/spaceship.ts | 2 +- src/ts/starSystem/StarSystemView.ts | 4 ++-- src/ts/starSystem/starSystemController.ts | 3 ++- src/ts/starmap/starMap.ts | 8 ++++---- src/ts/stellarObjects/common.ts | 2 +- src/ts/stellarObjects/neutronStar/neutronStar.ts | 1 - src/ts/stellarObjects/neutronStar/neutronStarModel.ts | 1 - src/ts/uberCore/postProcesses/types.ts | 2 +- src/ts/utils/wheelOfFortune.ts | 2 +- 13 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/ts/architecture/stellarObject.ts b/src/ts/architecture/stellarObject.ts index dde659d9f..e8554f97b 100644 --- a/src/ts/architecture/stellarObject.ts +++ b/src/ts/architecture/stellarObject.ts @@ -28,4 +28,4 @@ export interface StellarObject extends CelestialBody { export interface StellarObjectModel extends CelestialBodyModel { readonly temperature: number; readonly color: Color3; -} \ No newline at end of file +} diff --git a/src/ts/index.ts b/src/ts/index.ts index 02aacd516..cb66f4439 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -36,7 +36,6 @@ document.addEventListener("keydown", (e) => { if (e.key === "y") { if (starSystemView.scene.getActiveController() === shipControls) { - console.log("disembark"); characterController.getTransform().setEnabled(true); diff --git a/src/ts/settings.ts b/src/ts/settings.ts index d6b050a93..ce6427340 100644 --- a/src/ts/settings.ts +++ b/src/ts/settings.ts @@ -41,7 +41,7 @@ export const Settings = { export const CollisionMask = { GROUND: 0b00000001, SPACESHIP: 0b00000010, - LANDING_PADS: 0b00000100, + LANDING_PADS: 0b00000100 }; const seedableRNG = seededSquirrelNoise(Settings.UNIVERSE_SEED); diff --git a/src/ts/spaceship/shipControls.ts b/src/ts/spaceship/shipControls.ts index 1a9d17ab6..4af98deab 100644 --- a/src/ts/spaceship/shipControls.ts +++ b/src/ts/spaceship/shipControls.ts @@ -18,13 +18,7 @@ import { Scene } from "@babylonjs/core/scene"; import { Vector3 } from "@babylonjs/core/Maths/math.vector"; import { LOCAL_DIRECTION } from "../uberCore/localDirections"; -import { - getForwardDirection, - getUpwardDirection, - pitch, - roll, - translate -} from "../uberCore/transforms/basicTransform"; +import { getForwardDirection, getUpwardDirection, pitch, roll, translate } from "../uberCore/transforms/basicTransform"; import { TransformNode } from "@babylonjs/core/Meshes"; import { Controls } from "../uberCore/controls"; import { Input, InputType } from "../inputs/input"; diff --git a/src/ts/spaceship/spaceship.ts b/src/ts/spaceship/spaceship.ts index ea6608a14..c52489ff8 100644 --- a/src/ts/spaceship/spaceship.ts +++ b/src/ts/spaceship/spaceship.ts @@ -224,7 +224,7 @@ export class Spaceship implements Transformable { this.warpDrive.update(currentForwardSpeed, this.closestObject.distance, this.closestObject.radius, deltaTime); // the warp throttle goes from 0.1 to 1 smoothly using an inverse function - if(this.warpDrive.isEnabled()) this.warpTunnel.setThrottle(1 - 1 / (1.1 * (1 + 1e-6 * this.warpDrive.getWarpSpeed()))); + if (this.warpDrive.isEnabled()) this.warpTunnel.setThrottle(1 - 1 / (1.1 * (1 + 1e-6 * this.warpDrive.getWarpSpeed()))); else this.warpTunnel.setThrottle(0); for (const thruster of this.mainThrusters) thruster.update(); diff --git a/src/ts/starSystem/StarSystemView.ts b/src/ts/starSystem/StarSystemView.ts index 78deaea16..226f17d14 100644 --- a/src/ts/starSystem/StarSystemView.ts +++ b/src/ts/starSystem/StarSystemView.ts @@ -161,8 +161,8 @@ export class StarSystemView { const activeController = this.scene.getActiveController(); let controllerDistanceFactor = 5; - if(firstBody instanceof BlackHole) controllerDistanceFactor = 7; - else if(firstBody instanceof NeutronStar) controllerDistanceFactor = 100_000; + if (firstBody instanceof BlackHole) controllerDistanceFactor = 7; + else if (firstBody instanceof NeutronStar) controllerDistanceFactor = 100_000; positionNearObjectBrightSide(activeController, firstBody, this.getStarSystem(), controllerDistanceFactor); this.getStarSystem() diff --git a/src/ts/starSystem/starSystemController.ts b/src/ts/starSystem/starSystemController.ts index fd8b59f9b..04dcde9ea 100644 --- a/src/ts/starSystem/starSystemController.ts +++ b/src/ts/starSystem/starSystemController.ts @@ -298,7 +298,8 @@ export class StarSystemController { this.postProcessManager.addOcean(object as TelluricPlanet, this.stellarObjects); break; case PostProcessType.VOLUMETRIC_LIGHT: - if (!(object instanceof Star) && !(object instanceof NeutronStar)) throw new Error("Volumetric light post process can only be added to stars and neutron stars. Source:" + object.name); + if (!(object instanceof Star) && !(object instanceof NeutronStar)) + throw new Error("Volumetric light post process can only be added to stars and neutron stars. Source:" + object.name); this.postProcessManager.addVolumetricLight(object); break; case PostProcessType.MANDELBULB: diff --git a/src/ts/starmap/starMap.ts b/src/ts/starmap/starMap.ts index a72a9af17..6db8eceab 100644 --- a/src/ts/starmap/starMap.ts +++ b/src/ts/starmap/starMap.ts @@ -384,7 +384,7 @@ export class StarMap { default: throw new Error("Unknown stellar object type!"); } - if(starModel === null) throw new Error("Star model is null!"); + if (starModel === null) throw new Error("Star model is null!"); let instance: InstancedMesh | null = null; let recycled = false; @@ -447,11 +447,11 @@ export class StarMap { text += `Distance: ${distance.toFixed(2)}ly\n`; } - if(starModel === null) throw new Error("Star model is null!"); + if (starModel === null) throw new Error("Star model is null!"); let typeString = ""; - if(starModel.bodyType === BODY_TYPE.BLACK_HOLE) typeString = "Black hole"; - else if(starModel.bodyType === BODY_TYPE.NEUTRON_STAR) typeString = "Neutron star"; + if (starModel.bodyType === BODY_TYPE.BLACK_HOLE) typeString = "Black hole"; + else if (starModel.bodyType === BODY_TYPE.NEUTRON_STAR) typeString = "Neutron star"; else typeString = getStellarTypeString(starModel.stellarType); text += `Type: ${typeString}\n`; diff --git a/src/ts/stellarObjects/common.ts b/src/ts/stellarObjects/common.ts index 5ab4d25ae..665114510 100644 --- a/src/ts/stellarObjects/common.ts +++ b/src/ts/stellarObjects/common.ts @@ -29,7 +29,7 @@ export enum STELLAR_TYPE { /** 3,500 - 5,000 K */ K, /** 2,700 - 3,500 K */ - M, + M } export function getStellarTypeString(type: STELLAR_TYPE): string { diff --git a/src/ts/stellarObjects/neutronStar/neutronStar.ts b/src/ts/stellarObjects/neutronStar/neutronStar.ts index ee3c72329..2bbdb13ce 100644 --- a/src/ts/stellarObjects/neutronStar/neutronStar.ts +++ b/src/ts/stellarObjects/neutronStar/neutronStar.ts @@ -115,7 +115,6 @@ export class NeutronStar implements StellarObject, Cullable { return "Neutron Star"; } - getRotationAxis(): Vector3 { return this.getTransform().up; } diff --git a/src/ts/stellarObjects/neutronStar/neutronStarModel.ts b/src/ts/stellarObjects/neutronStar/neutronStarModel.ts index 04052a00d..f9b52f67c 100644 --- a/src/ts/stellarObjects/neutronStar/neutronStarModel.ts +++ b/src/ts/stellarObjects/neutronStar/neutronStarModel.ts @@ -83,6 +83,5 @@ export class NeutronStarModel implements StellarObjectModel { } else { this.ringsUniforms = null; } - } } diff --git a/src/ts/uberCore/postProcesses/types.ts b/src/ts/uberCore/postProcesses/types.ts index 42c006d62..49f2d3678 100644 --- a/src/ts/uberCore/postProcesses/types.ts +++ b/src/ts/uberCore/postProcesses/types.ts @@ -67,7 +67,7 @@ export enum UniformEnumType { /** * An array of Color3. Shader code: vec3[] */ - Color3Array, + Color3Array } export enum SamplerEnumType { diff --git a/src/ts/utils/wheelOfFortune.ts b/src/ts/utils/wheelOfFortune.ts index 87fa065a7..b872cbc45 100644 --- a/src/ts/utils/wheelOfFortune.ts +++ b/src/ts/utils/wheelOfFortune.ts @@ -31,4 +31,4 @@ export function wheelOfFortune(options: [T, number][], randomValue: number): if (choice < current) return option; } throw new Error("Wheel of fortune failed"); -} \ No newline at end of file +}