-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from BarthPaleologue/WIP
Architecture Revamp
- Loading branch information
Showing
106 changed files
with
1,111 additions
and
858 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
<section id="helmetOverlay"> | ||
<div id="bodyData"> | ||
<p id="bodyName"></p> | ||
<p id="bodySeed"></p> | ||
</div> | ||
<div id="speedometer"></div> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Architecture of interface spanning from simple Transforms to complex Celestial bodies and Space stations: | ||
|
||
![img.png](img.png) | ||
|
||
This folder contains all the abstraction necessary to the architecture of the image. | ||
|
||
This means all the node except the leaves (upper nodes) which are the actual concrete implementation of celestial bodies and space stations. | ||
|
||
It all starts with simple `Transformable` and `BoundingSphere`: | ||
those are simple objects that possess a BaylonJS `TransformNode` for their position, rotation, scaling and a bounding volume to make simple calculations for distances. | ||
|
||
An `OrbitalObject` builds on top of this by adding the notion of orbit. They possess `OrbitProperties` that describes their motion around their `parent` which can be null in the case of some objects (think like stars). | ||
|
||
`OrbitalObject` also possess `PhysicalProperties` that complement the `OrbitProperties` with information such as mass, axial tilting and rotation period. | ||
|
||
To sum up, an `OrbitalObject` is an object that can rotate around another `OrbitalObject` and rotate on itself. | ||
|
||
`CelestialBody` builds up on top of `OrbitalObject` by adding the notion of `BODY_TYPE` and `radius` that is expected from spherical objects. | ||
|
||
`CelestialBody` are spherical orbital objects that encompasses both planets and stellar objects. | ||
They can have specific post-processes applied to them (like atmosphere, clouds, rings...), which is why they also implement `HasPostProcesses`. | ||
|
||
`StellarObject` builds on top of `CelestialBody` by adding a `PointLight` that is used to light up the scene. They also have a `STELLAR_TYPE` that describes their type (star, black hole, neutron star). | ||
|
||
`Planet` builds on top of `CelestialBody` by adding new `PlanetPhysicalProperties` that describe their temperature and pressure. They also keep track of their number of moons. | ||
|
||
The other nodes are the concrete implementations of all these abstractions. | ||
They can be found in their respective folders (`planets` for `TelluricPlanet` and `GasPlanet`, `stellarObjects` for `Star`, `BlackHole` and `NeutronStar`, and spaceStations for `SpaceStation`). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface BoundingSphere { | ||
getBoundingRadius(): number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { RingsUniforms } from "../postProcesses/rings/ringsUniform"; | ||
|
||
export interface CanHaveRings { | ||
getRingsUniforms(): RingsUniforms | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { OrbitalObject, OrbitalObjectModel } from "./orbitalObject"; | ||
import { HasPostProcesses } from "./hasPostProcesses"; | ||
import { CanHaveRings } from "./canHaveRings"; | ||
import { BODY_TYPE } from "../model/common"; | ||
|
||
export interface CelestialBody extends OrbitalObject, CanHaveRings, HasPostProcesses { | ||
model: CelestialBodyModel; | ||
|
||
/** | ||
* Returns the radius of the celestial body | ||
*/ | ||
getRadius(): number; | ||
} | ||
|
||
export interface CelestialBodyModel extends OrbitalObjectModel { | ||
readonly bodyType: BODY_TYPE; | ||
readonly radius: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { PostProcessType } from "../postProcesses/postProcessTypes"; | ||
|
||
export interface HasPostProcesses { | ||
postProcesses: PostProcessType[]; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Transformable } from "./transformable"; | ||
import { BoundingSphere } from "./boundingSphere"; | ||
import { OrbitProperties } from "../orbit/orbitProperties"; | ||
import { rotateVector3AroundInPlace } from "../utils/algebra"; | ||
import { Quaternion, Vector3 } from "@babylonjs/core/Maths/math"; | ||
import { getRotationQuaternion, setRotationQuaternion, translate } from "../uberCore/transforms/basicTransform"; | ||
import { OrbitalObjectPhysicalProperties } from "./physicalProperties"; | ||
|
||
export interface OrbitalObject extends Transformable, BoundingSphere { | ||
name: string; | ||
|
||
model: OrbitalObjectModel; | ||
|
||
getRotationAxis(): Vector3; | ||
|
||
getOrbitProperties(): OrbitProperties; | ||
|
||
getPhysicalProperties(): OrbitalObjectPhysicalProperties; | ||
|
||
getTypeName(): string; | ||
|
||
parent: OrbitalObject | null; | ||
} | ||
|
||
export class OrbitalObject { | ||
static getRotationAxis(object: OrbitalObject) { | ||
return object.getTransform().up; | ||
} | ||
|
||
static computeNextOrbitalPosition(object: OrbitalObject, deltaTime: number) { | ||
const orbit = object.getOrbitProperties(); | ||
if (orbit.period === 0 || object.parent === null) return object.getTransform().getAbsolutePosition(); | ||
|
||
const barycenter = object.parent.getTransform().getAbsolutePosition(); | ||
|
||
// enforce distance to orbit center | ||
const oldPosition = object.getTransform().getAbsolutePosition().subtract(barycenter); | ||
const newPosition = oldPosition.clone(); | ||
|
||
// rotate the object around the barycenter of the orbit, around the normal to the orbital plane | ||
const dtheta = (2 * Math.PI * deltaTime) / orbit.period; | ||
rotateVector3AroundInPlace(newPosition, barycenter, orbit.normalToPlane, dtheta); | ||
|
||
newPosition.normalize().scaleInPlace(orbit.radius); | ||
|
||
// enforce orbital plane | ||
const correctionAxis = Vector3.Cross(orbit.normalToPlane, newPosition.normalizeToNew()); | ||
const correctionAngle = 0.5 * Math.PI - Vector3.GetAngleBetweenVectors(orbit.normalToPlane, newPosition.normalizeToNew(), correctionAxis); | ||
newPosition.applyRotationQuaternionInPlace(Quaternion.RotationAxis(correctionAxis, correctionAngle)); | ||
|
||
return newPosition.addInPlace(barycenter); | ||
} | ||
|
||
static updateOrbitalPosition(object: OrbitalObject, deltaTime: number) { | ||
const orbit = object.getOrbitProperties(); | ||
if (orbit.period === 0 || object.parent === null) return; | ||
|
||
const oldPosition = object.getTransform().getAbsolutePosition(); | ||
const newPosition = OrbitalObject.computeNextOrbitalPosition(object, deltaTime); | ||
translate(object.getTransform(), newPosition.subtractInPlace(oldPosition)); | ||
} | ||
|
||
static getDeltaTheta(object: OrbitalObject, deltaTime: number) { | ||
if (object.getPhysicalProperties().rotationPeriod === 0) return 0; | ||
return (2 * Math.PI * deltaTime) / object.getPhysicalProperties().rotationPeriod; | ||
} | ||
|
||
/** | ||
* Updates the rotation of the body around its axis | ||
* @param object | ||
* @param deltaTime The time elapsed since the last update | ||
* @returns The elapsed angle of rotation around the axis | ||
*/ | ||
static updateRotation(object: OrbitalObject, deltaTime: number) { | ||
const dtheta = OrbitalObject.getDeltaTheta(object, deltaTime); | ||
if (dtheta === 0) return; | ||
|
||
const elementaryRotationQuaternion = Quaternion.RotationAxis(OrbitalObject.getRotationAxis(object), dtheta); | ||
const newQuaternion = elementaryRotationQuaternion.multiply(getRotationQuaternion(object.getTransform())); | ||
|
||
setRotationQuaternion(object.getTransform(), newQuaternion); | ||
} | ||
} | ||
|
||
export interface OrbitalObjectModel { | ||
rng: (step: number) => number; | ||
seed: number; | ||
|
||
orbit: OrbitProperties; | ||
physicalProperties: OrbitalObjectPhysicalProperties; | ||
|
||
readonly parentBody: OrbitalObjectModel | null; | ||
readonly childrenBodies: OrbitalObjectModel[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export type OrbitalObjectPhysicalProperties = { | ||
mass: number; | ||
rotationPeriod: number; | ||
axialTilt: number; | ||
}; | ||
|
||
export type StarPhysicalProperties = OrbitalObjectPhysicalProperties & { | ||
temperature: number; | ||
}; | ||
|
||
export type BlackHolePhysicalProperties = OrbitalObjectPhysicalProperties & { | ||
accretionDiskRadius: number; | ||
}; | ||
|
||
export type PlanetPhysicalProperties = OrbitalObjectPhysicalProperties & { | ||
minTemperature: number; | ||
maxTemperature: number; | ||
pressure: number; | ||
}; | ||
|
||
export type TelluricPlanetPhysicalProperties = PlanetPhysicalProperties & { | ||
waterAmount: number; | ||
oceanLevel: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Camera } from "@babylonjs/core/Cameras/camera"; | ||
import { CelestialBody, CelestialBodyModel } from "./celestialBody"; | ||
import { PlanetPhysicalProperties } from "./physicalProperties"; | ||
import { Transformable } from "./transformable"; | ||
|
||
export interface Planet extends CelestialBody { | ||
model: PlanetModel; | ||
|
||
updateMaterial(controller: Camera, stellarObjects: Transformable[], deltaTime: number): void; | ||
} | ||
|
||
export interface PlanetModel extends CelestialBodyModel { | ||
physicalProperties: PlanetPhysicalProperties; | ||
|
||
nbMoons: number; | ||
|
||
getApparentRadius(): number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { PointLight } from "@babylonjs/core/Lights/pointLight"; | ||
import { CelestialBody, CelestialBodyModel } from "./celestialBody"; | ||
import { STELLAR_TYPE } from "../stellarObjects/common"; | ||
|
||
export interface StellarObject extends CelestialBody { | ||
model: StellarObjectModel; | ||
|
||
getLight(): PointLight; | ||
} | ||
|
||
export interface StellarObjectModel extends CelestialBodyModel { | ||
stellarType: STELLAR_TYPE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { TransformNode } from "@babylonjs/core/Meshes"; | ||
|
||
export interface Transformable { | ||
getTransform(): TransformNode; | ||
|
||
dispose(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.