Space Engineers

Space Engineers

Real Stars
Echthros  [developer] 21 Feb, 2024 @ 12:07pm
Real Stars Mod API
Setup Steps:
1. Copy RealStarsApiClient.cs file to your code project.
2. Instantiate the RealStarsAPI class in the main MySessionComponentBase and store it in a property. (i.e. public RealStarsApi RealStarsApi = new RealStarsApi();)
3. Add the RealStarsAPI.Load() call to the LoadData() method and the RealStarsAPI.Unload() call to the UnloadData() override methods in the main MySessionComponentBase.
4. Use the API methods as you please.

Methods:
void SpawnStar(Vector3D position, float radius, Vector3I color, float effectBrightness, float lightBrightness, float damageRadius, float gravityStrength, float gravityFalloff)
Spawns a star with the listed config values. Values are identical to the ones listed in the Config.xml. Only one star can be spawned/configured at a time, so make sure to wait until spawn is complete before calling again.

MyTuple<bool, float, Vector3I, float, float, float> GetStarInfo(MyPlanet planet)
Get star info for the star/planet object requested. Return Tuple with a success flag (first element) and the first five star config values (Radius, Color, EffectBrightness, LightBrightness, DamageRadius).

MyTuple<bool, float, float> GetStarGravity(MyPlanet planet)
Get star info for the star/planet object requested. Return Tuple with a success flag (first element) and the gravity star config values (GravityStrength, GravityFalloff).

bool SetStarInfo(MyPlanet planet, float radius, Vector3I color, float effectBrightness, float lightBrightness, float damageRadius, float gravityStrength, float gravityFalloff)
Sets star info for the star/planet object requested. Returns success flag.

void SpawnPlanetNoCycle(string planetName, Vector3D position, float radius, int seed)
Creates a new planet with no day cycle. Only one planet can be spawned/configured at a time, so make sure to wait until spawn is complete before calling again.

void SpawnPlanetWithCycle(string planetName, Vector3D position, float radius, int seed, float daySeconds, bool isCounterClockwise)
Creates a new planet with specified day length and rotation direction. Only one planet can be spawned/configured at a time, so make sure to wait until spawn is complete before calling again.

MyTuple<bool, bool, float, bool> GetPlanetInfo(MyPlanet planet)
Get planet day cycle info for the planet requested. Returns Tuple with a success flag (first element) and the planet day cycle config values (DayCycleEnabled, DayLengthSeconds, SpinCounterClockwise).

bool SetPlanetInfo(MyPlanet planet, bool dayCycleEnabled, float dayLengthSeconds, bool spinCounterClockwise)
Sets planet day cycle info for the planet object requested. Returns success flag.

MyTuple<Vector3D, float> GetSunInfoAtPosition(Vector3D position)
Gets the weighted sun position (point from which sunlight originates) and the total sun brightness at a position in the world. Does not account for planets or day cycles whatsoever.

MyTuple<MyPlanet, MyPlanet> API_GetSunInfoNearbyPlanets(Vector3D position)
Gets the nearby planet info at the input position.

PlanetZone: planet whose time of day influence the position is under. The sun will appear to move across the sky around this planet if the value is not null.

PlanetNearest: planet that is nearest to the position. Most of the time this value and PlanetZone will be the same, but not always (such as if the position is near a moon that has no day cycle, but is still within the time of day sphere of the nearby planet). Value is used internally for the nighttime check (if sun is obscured by planet, sun brightness value is 0).

MyTuple<Vector3D, float, float> GetSunInfoWithPlanetAtPosition(Vector3D position, MyPlanet planetZone, MyPlanet planetNearest)
Gets the info about the sun at a position in the world accounting for nearby planets (takes the output values from API_GetSunInfoNearbyPlanets() as input). Returns Tuple with planet and sun info (PlanetZone, PlanetNearest, SunDirection, PlanetTimeOfDay, SunBrightness).

SunDirection: normalized vector pointing from the input position towards the sun.

PlanetTimeOfDay: value between 0 and 1 representing the time of day at the input position for PlanetZone. 0 => midnight; 0.25 => dawn; 0.5 => noon; 0.75 => sunset.

SunBrightness: sun brightness value at the input position. Similar to the brightness value returned by "GetSunInfoAtPosition", except this value is also modified by weather and the nighttime check for PlanetNearest.

MyTuple<float, float> API_GetSolarBlockMinMax()
Gets the min and max solar block output multipliers set in the settings Config.xml.

Vector3D GetCurrentRealSunDirection()
Gets the current local visual sun direction (the normal GetSunDirection() call does not return the correct value). Will return different values on different clients.

float API_GetCurrentRealSunDist()
Gets the current distance from the local camera to the sun light source.

float API_GetCurrentRealSunRad()
Gets the current apparent angular width (in radians) of the nearest star (how wide the star appears to be on screen).
Last edited by Echthros; 6 May, 2024 @ 9:51pm
< >
Showing 1-9 of 9 comments
Stollie 7 Mar, 2024 @ 11:20pm 
Niiiice, I'll have a crack at adding this to my scenario build files :steamhappy:
🅂🄸🅂🄺 14 Mar, 2024 @ 4:19pm 
ello, can we get GetSunDirection alike method for this API?
Echthros  [developer] 14 Mar, 2024 @ 8:59pm 
Like pass in a world position and get the sun vector at that position?
🅂🄸🅂🄺 15 Mar, 2024 @ 12:38am 
yes
Echthros  [developer] 15 Mar, 2024 @ 12:55am 
I'll look into it.
🅂🄸🅂🄺 15 Mar, 2024 @ 1:15am 
Great, once its done, i will implement support for Real Stars in SmartRotors: Solar
Last edited by 🅂🄸🅂🄺; 15 Mar, 2024 @ 1:16am
Echthros  [developer] 18 Mar, 2024 @ 10:34pm 
Added new API methods.
🅂🄸🅂🄺 19 Mar, 2024 @ 10:29am 
thank you
Echthros  [developer] 13 Apr, 2024 @ 4:20pm 
Update:
Added GetCurrentRealSunDirection() method to the RealStarsAPI. Any mods using the API will need to be updated.
< >
Showing 1-9 of 9 comments
Per page: 1530 50