Skip to content

Commit

Permalink
get rid of name duplication in orbital object
Browse files Browse the repository at this point in the history
it is not needed as the model already holds the information
  • Loading branch information
BarthPaleologue committed Oct 14, 2024
1 parent 5c84f7b commit 2b7ec5c
Show file tree
Hide file tree
Showing 22 changed files with 114 additions and 81 deletions.
6 changes: 1 addition & 5 deletions src/ts/anomalies/julia/juliaSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import { CelestialBody } from "../../architecture/celestialBody";
import { orbitalObjectTypeToDisplay } from "../../utils/strings/orbitalObjectTypeToDisplay";

export class JuliaSet implements CelestialBody, Cullable {
readonly name: string;

readonly model: JuliaSetModel;

private readonly transform: TransformNode;
Expand All @@ -45,9 +43,7 @@ export class JuliaSet implements CelestialBody, Cullable {
constructor(model: JuliaSetModel, scene: Scene) {
this.model = model;

this.name = this.model.name;

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

this.postProcesses.push(PostProcessType.JULIA_SET);

Expand Down
2 changes: 1 addition & 1 deletion src/ts/anomalies/julia/juliaSetPostProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class JuliaSetPostProcess extends PostProcess implements ObjectPostProces

const samplers: string[] = Object.values(SamplerUniformNames);

super(julia.name, shaderName, uniforms, samplers, 1, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, null, Constants.TEXTURETYPE_HALF_FLOAT);
super(julia.model.name, shaderName, uniforms, samplers, 1, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, null, Constants.TEXTURETYPE_HALF_FLOAT);

this.object = julia;

Expand Down
4 changes: 0 additions & 4 deletions src/ts/anomalies/mandelbulb/mandelbulb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import { CelestialBody } from "../../architecture/celestialBody";
import { orbitalObjectTypeToDisplay } from "../../utils/strings/orbitalObjectTypeToDisplay";

export class Mandelbulb implements CelestialBody, Cullable {
readonly name: string;

readonly model: MandelbulbModel;

private readonly transform: TransformNode;
Expand All @@ -45,8 +43,6 @@ export class Mandelbulb implements CelestialBody, Cullable {
constructor(model: MandelbulbModel, scene: Scene) {
this.model = model;

this.name = this.model.name;

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

this.postProcesses.push(PostProcessType.MANDELBULB);
Expand Down
2 changes: 1 addition & 1 deletion src/ts/anomalies/mandelbulb/mandelbulbPostProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class MandelbulbPostProcess extends PostProcess implements ObjectPostProc

const samplers: string[] = Object.values(SamplerUniformNames);

super(mandelbulb.name, shaderName, uniforms, samplers, 1, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, null, Constants.TEXTURETYPE_HALF_FLOAT);
super(mandelbulb.model.name, shaderName, uniforms, samplers, 1, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, null, Constants.TEXTURETYPE_HALF_FLOAT);

this.object = mandelbulb;
this.settings = settings;
Expand Down
5 changes: 0 additions & 5 deletions src/ts/architecture/orbitalObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ import { getPointOnOrbit, Orbit } from "../orbit/orbit";
* Describes all objects that can have an orbital trajectory and rotate on themselves
*/
export interface OrbitalObject extends Transformable, HasBoundingSphere, TypedObject {
/**
* The name of the object
*/
readonly name: string;

readonly model: OrbitalObjectModel;

/**
Expand Down
16 changes: 14 additions & 2 deletions src/ts/clouds/flatCloudsPostProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class FlatCloudsPostProcess extends PostProcess implements ObjectPostProc

private activeCamera: Camera | null = null;

constructor(name: string, planet: Transformable & HasBoundingSphere, cloudUniforms: CloudsUniforms, scene: Scene, stellarObjects: Transformable[]) {
constructor(planet: Transformable & HasBoundingSphere, cloudUniforms: CloudsUniforms, stellarObjects: Transformable[], scene: Scene) {
const shaderName = "flatClouds";
if (Effect.ShadersStore[`${shaderName}FragmentShader`] === undefined) {
Effect.ShadersStore[`${shaderName}FragmentShader`] = flatCloudsFragment;
Expand All @@ -53,7 +53,19 @@ export class FlatCloudsPostProcess extends PostProcess implements ObjectPostProc

const samplers: string[] = [...Object.values(SamplerUniformNames), ...Object.values(CloudsSamplerNames)];

super(name, shaderName, uniforms, samplers, 1, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, null, Constants.TEXTURETYPE_HALF_FLOAT);
super(
`${planet.getTransform().name}CloudsPostProcess`,
shaderName,
uniforms,
samplers,
1,
null,
Texture.BILINEAR_SAMPLINGMODE,
scene.getEngine(),
false,
null,
Constants.TEXTURETYPE_HALF_FLOAT
);

this.object = planet;
this.cloudUniforms = cloudUniforms;
Expand Down
7 changes: 2 additions & 5 deletions src/ts/planets/gasPlanet/gasPlanet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export class GasPlanet implements Planet, Cullable {
readonly aggregate: PhysicsAggregate;
readonly model: GasPlanetModel;

name: string;
postProcesses: PostProcessType[] = [];

readonly ringsUniforms: RingsUniforms | null;
Expand All @@ -57,10 +56,8 @@ export class GasPlanet implements Planet, Cullable {
constructor(model: GasPlanetModel, scene: Scene) {
this.model = model;

this.name = this.model.name;

this.mesh = MeshBuilder.CreateSphere(
this.name,
this.model.name,
{
diameter: this.model.radius * 2,
segments: 64
Expand All @@ -82,7 +79,7 @@ export class GasPlanet implements Planet, Cullable {
const physicsShape = new PhysicsShapeSphere(Vector3.Zero(), this.model.radius, scene);
this.aggregate.shape.addChildFromParent(this.getTransform(), physicsShape, this.mesh);

this.material = new GasPlanetMaterial(this.name, this.model, scene);
this.material = new GasPlanetMaterial(this.model.name, this.model, scene);
this.mesh.material = this.material;

this.postProcesses.push(PostProcessType.ATMOSPHERE, PostProcessType.SHADOW);
Expand Down
20 changes: 8 additions & 12 deletions src/ts/planets/telluricPlanet/telluricPlanet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import { AsteroidField } from "../../asteroidFields/asteroidField";
import { orbitalObjectTypeToDisplay } from "../../utils/strings/orbitalObjectTypeToDisplay";

export class TelluricPlanet implements Planet, Cullable {
readonly name: string;

readonly sides: ChunkTree[]; // stores the 6 sides of the sphere

readonly material: TelluricPlanetMaterial;
Expand All @@ -65,9 +63,7 @@ export class TelluricPlanet implements Planet, Cullable {
constructor(model: TelluricPlanetModel, scene: Scene) {
this.model = model;

this.name = this.model.name;

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

rotate(this.transform, Axis.X, this.model.physics.axialTilt);
this.transform.computeWorldMatrix(true);
Expand Down Expand Up @@ -110,15 +106,15 @@ export class TelluricPlanet implements Planet, Cullable {
this.cloudsUniforms = null;
}

this.material = new TelluricPlanetMaterial(this.name, this.model, scene);
this.material = new TelluricPlanetMaterial(this.model, scene);

this.sides = [
new ChunkTree(Direction.UP, this.name, this.model, this.aggregate, this.material, scene),
new ChunkTree(Direction.DOWN, this.name, this.model, this.aggregate, this.material, scene),
new ChunkTree(Direction.FORWARD, this.name, this.model, this.aggregate, this.material, scene),
new ChunkTree(Direction.BACKWARD, this.name, this.model, this.aggregate, this.material, scene),
new ChunkTree(Direction.RIGHT, this.name, this.model, this.aggregate, this.material, scene),
new ChunkTree(Direction.LEFT, this.name, this.model, this.aggregate, this.material, scene)
new ChunkTree(Direction.UP, this.model, this.aggregate, this.material, scene),
new ChunkTree(Direction.DOWN, this.model, this.aggregate, this.material, scene),
new ChunkTree(Direction.FORWARD, this.model, this.aggregate, this.material, scene),
new ChunkTree(Direction.BACKWARD, this.model, this.aggregate, this.material, scene),
new ChunkTree(Direction.RIGHT, this.model, this.aggregate, this.material, scene),
new ChunkTree(Direction.LEFT, this.model, this.aggregate, this.material, scene)
];
}

Expand Down
7 changes: 3 additions & 4 deletions src/ts/planets/telluricPlanet/telluricPlanetMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ export class TelluricPlanetMaterial extends ShaderMaterial {

/**
* Creates a new telluric planet material
* @param planetName The name of the planet
* @param model The model of the planet associated with this material
* @param scene
*/
constructor(planetName: string, model: TelluricPlanetModel, scene: Scene) {
constructor(model: TelluricPlanetModel, scene: Scene) {
const shaderName = "surfaceMaterial";
if (Effect.ShadersStore[`${shaderName}FragmentShader`] === undefined) {
Effect.ShadersStore[`${shaderName}FragmentShader`] = surfaceMaterialFragment;
Expand All @@ -106,7 +105,7 @@ export class TelluricPlanetMaterial extends ShaderMaterial {
Effect.ShadersStore[`${shaderName}VertexShader`] = surfaceMaterialVertex;
}

super(`${planetName}SurfaceColor`, scene, shaderName, {
super(`${model.name}SurfaceColor`, scene, shaderName, {
attributes: ["position", "normal"],
uniforms: [...Object.values(TelluricPlanetMaterialUniformNames), ...Object.values(StellarObjectUniformNames)],
samplers: [...Object.values(TelluricPlanetMaterialSamplerNames)]
Expand Down Expand Up @@ -151,7 +150,7 @@ export class TelluricPlanetMaterial extends ShaderMaterial {
}

this.setTexture("lut", Textures.EMPTY_TEXTURE);
const lut = new ProceduralTexture(`${planetName}MaterialLut`, 4096, "telluricPlanetLut", scene, null, true, false);
const lut = new ProceduralTexture(`${model.name}MaterialLut`, 4096, "telluricPlanetLut", scene, null, true, false);
lut.setFloat(TelluricPlanetMaterialUniformNames.MIN_TEMPERATURE, this.planetModel.physics.minTemperature);
lut.setFloat(TelluricPlanetMaterialUniformNames.MAX_TEMPERATURE, this.planetModel.physics.maxTemperature);
lut.setFloat(TelluricPlanetMaterialUniformNames.PRESSURE, this.planetModel.physics.pressure);
Expand Down
5 changes: 2 additions & 3 deletions src/ts/planets/telluricPlanet/terrain/chunks/chunkTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,14 @@ export class ChunkTree implements Cullable {
/**
*
* @param direction
* @param planetName
* @param planetModel
* @param parentAggregate
* @param material
* @param scene
*/
constructor(direction: Direction, planetName: string, planetModel: TelluricPlanetModel, parentAggregate: PhysicsAggregate, material: Material, scene: Scene) {
constructor(direction: Direction, planetModel: TelluricPlanetModel, parentAggregate: PhysicsAggregate, material: Material, scene: Scene) {
this.rootChunkLength = planetModel.radius * 2;
this.planetName = planetName;
this.planetName = planetModel.name;
this.planetSeed = planetModel.seed;
this.terrainSettings = planetModel.terrainSettings;

Expand Down
16 changes: 14 additions & 2 deletions src/ts/postProcesses/atmosphericScatteringPostProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class AtmosphericScatteringPostProcess extends PostProcess implements Obj

private activeCamera: Camera | null = null;

constructor(name: string, planet: GasPlanet | TelluricPlanet, atmosphereHeight: number, scene: Scene, stellarObjects: Transformable[]) {
constructor(planet: GasPlanet | TelluricPlanet, atmosphereHeight: number, stellarObjects: Transformable[], scene: Scene) {
const shaderName = "atmosphericScattering";
if (Effect.ShadersStore[`${shaderName}FragmentShader`] === undefined) {
Effect.ShadersStore[`${shaderName}FragmentShader`] = atmosphericScatteringFragment;
Expand Down Expand Up @@ -102,7 +102,19 @@ export class AtmosphericScatteringPostProcess extends PostProcess implements Obj

const samplers: string[] = [...Object.values(SamplerUniformNames), ...Object.values(AtmosphereSamplerNames)];

super(name, shaderName, uniforms, samplers, 1, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, null, Constants.TEXTURETYPE_HALF_FLOAT);
super(
`${planet.model.name}AtmospherePostProcess`,
shaderName,
uniforms,
samplers,
1,
null,
Texture.BILINEAR_SAMPLINGMODE,
scene.getEngine(),
false,
null,
Constants.TEXTURETYPE_HALF_FLOAT
);

this.object = planet;
this.atmosphereUniforms = atmosphereUniforms;
Expand Down
2 changes: 1 addition & 1 deletion src/ts/postProcesses/lensFlarePostProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class LensFlarePostProcess extends PostProcess implements ObjectPostProce

const samplers: string[] = Object.values(SamplerUniformNames);

super(object.name + "LensFlare", shaderName, uniforms, samplers, 1, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, null, Constants.TEXTURETYPE_HALF_FLOAT);
super(object.model.name + "LensFlare", shaderName, uniforms, samplers, 1, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, null, Constants.TEXTURETYPE_HALF_FLOAT);

this.object = object;
this.settings = settings;
Expand Down
18 changes: 15 additions & 3 deletions src/ts/postProcesses/oceanPostProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class OceanPostProcess extends PostProcess implements ObjectPostProcess,

private activeCamera: Camera | null = null;

constructor(name: string, planet: TelluricPlanet, scene: Scene, stars: Transformable[]) {
constructor(planet: TelluricPlanet, stellarObjects: Transformable[], scene: Scene) {
const shaderName = "ocean";
if (Effect.ShadersStore[`${shaderName}FragmentShader`] === undefined) {
Effect.ShadersStore[`${shaderName}FragmentShader`] = oceanFragment;
Expand Down Expand Up @@ -87,7 +87,19 @@ export class OceanPostProcess extends PostProcess implements ObjectPostProcess,

const samplers: string[] = [...Object.values(SamplerUniformNames), ...Object.values(OceanSamplerNames)];

super(name, shaderName, uniforms, samplers, 1, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, null, Constants.TEXTURETYPE_HALF_FLOAT);
super(
`${planet.model.name}OceanPostProcess`,
shaderName,
uniforms,
samplers,
1,
null,
Texture.BILINEAR_SAMPLINGMODE,
scene.getEngine(),
false,
null,
Constants.TEXTURETYPE_HALF_FLOAT
);

this.object = planet;
this.oceanUniforms = oceanUniforms;
Expand All @@ -100,7 +112,7 @@ export class OceanPostProcess extends PostProcess implements ObjectPostProcess,
}

setCameraUniforms(effect, this.activeCamera);
setStellarObjectUniforms(effect, stars);
setStellarObjectUniforms(effect, stellarObjects);
setObjectUniforms(effect, planet);

effect.setFloat(OceanUniformNames.OCEAN_RADIUS, planet.getRadius() + planet.model.physics.oceanLevel);
Expand Down
15 changes: 7 additions & 8 deletions src/ts/postProcesses/postProcessManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class PostProcessManager {
* @param stellarObjects An array of stars or black holes
*/
public addOcean(planet: TelluricPlanet, stellarObjects: StellarObject[]) {
const ocean = new OceanPostProcess(`${planet.name}Ocean`, planet, this.scene, stellarObjects);
const ocean = new OceanPostProcess(planet, stellarObjects, this.scene);
this.oceans.push(ocean);
}

Expand All @@ -234,9 +234,9 @@ export class PostProcessManager {
const uniforms = planet.getCloudsUniforms();
if (uniforms === null)
throw new Error(
`PostProcessManager: addClouds: uniforms are null. This should not be possible as the postprocess should not be created if the body has no clouds. Body: ${planet.name}`
`PostProcessManager: addClouds: uniforms are null. This should not be possible as the postprocess should not be created if the body has no clouds. Body: ${planet.model.name}`
);
this.clouds.push(new FlatCloudsPostProcess(`${planet.name}Clouds`, planet, uniforms, this.scene, stellarObjects));
this.clouds.push(new FlatCloudsPostProcess(planet, uniforms, stellarObjects, this.scene));
}

/**
Expand All @@ -254,11 +254,10 @@ export class PostProcessManager {
*/
public addAtmosphere(planet: GasPlanet | TelluricPlanet, stellarObjects: StellarObject[]) {
const atmosphere = new AtmosphericScatteringPostProcess(
`${planet.name}Atmosphere`,
planet,
Settings.ATMOSPHERE_HEIGHT * Math.max(1, planet.model.radius / Settings.EARTH_RADIUS),
this.scene,
stellarObjects
stellarObjects,
this.scene
);
this.atmospheres.push(atmosphere);
}
Expand All @@ -277,7 +276,7 @@ export class PostProcessManager {
* @param stellarObjects An array of stars or black holes
*/
public addRings(body: CelestialBody, stellarObjects: StellarObject[]) {
this.rings.push(new RingsPostProcess(body.name + "Rings", this.scene, body, stellarObjects));
this.rings.push(new RingsPostProcess(body, stellarObjects, this.scene));
}

/**
Expand Down Expand Up @@ -365,7 +364,7 @@ export class PostProcessManager {
* @param stellarObjects An array of stellar objects
*/
public addShadowCaster(body: CelestialBody, stellarObjects: StellarObject[]) {
this.shadows.push(new ShadowPostProcess(body.name + "Shadow", body, stellarObjects, this.scene));
this.shadows.push(new ShadowPostProcess(body, stellarObjects, this.scene));
}

/**
Expand Down
16 changes: 14 additions & 2 deletions src/ts/postProcesses/shadowPostProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ShadowPostProcess extends PostProcess implements ObjectPostProcess

private activeCamera: Camera | null = null;

constructor(name: string, body: CelestialBody, stellarObjects: StellarObject[], scene: Scene) {
constructor(body: CelestialBody, stellarObjects: StellarObject[], scene: Scene) {
const shaderName = "shadow";
if (Effect.ShadersStore[`${shaderName}FragmentShader`] === undefined) {
Effect.ShadersStore[`${shaderName}FragmentShader`] = shadowFragment;
Expand Down Expand Up @@ -74,7 +74,19 @@ export class ShadowPostProcess extends PostProcess implements ObjectPostProcess

const samplers: string[] = [...Object.values(SamplerUniformNames), ...Object.values(RingsSamplerNames)];

super(name, shaderName, uniforms, samplers, 1, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, null, Constants.TEXTURETYPE_HALF_FLOAT);
super(
`${body.model.name}ShadowPostProcess`,
shaderName,
uniforms,
samplers,
1,
null,
Texture.BILINEAR_SAMPLINGMODE,
scene.getEngine(),
false,
null,
Constants.TEXTURETYPE_HALF_FLOAT
);

this.object = body;
this.shadowUniforms = shadowUniforms;
Expand Down
2 changes: 1 addition & 1 deletion src/ts/postProcesses/volumetricLight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class VolumetricLight extends VolumetricLightScatteringPostProcess implem

constructor(star: Star | NeutronStar, excludedMeshes: AbstractMesh[], scene: Scene) {
if (scene.activeCameras === null || scene.activeCameras.length === 0) throw new Error("no camera");
super(`${star.name}VolumetricLight`, 1, null, star.mesh, 100, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, scene);
super(`${star.mesh.name}VolumetricLight`, 1, null, star.mesh, 100, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false, scene);

// This is necessary because BabylonJS post process sets the scene using the camera. However, I don't pass a camera to the constructor as I use a PostProcessRenderPipeline.
this._scene = scene;
Expand Down
Loading

0 comments on commit 2b7ec5c

Please sign in to comment.