Hello 
There are two very different questions here so I’ll separate them :
1. 3D modeling → Storing to PostgreSQL DB
I don’t exactly get the usage of BabylonJS you do here
. BabylonJS’ purpose is realtime rendering some meshes in a web context. It’s not (like, not at all
) a 3D modeling tool. Why don’t you use Blender or such tool to generate your geometry, if you aim to render in Unity at the end ?
To answer your question, maybe the simpler would be to used the binary format data available on PostgreSQL, and store your meshes as .GLB files. Depending on the size, you might look for another solution better suited for big files…
2. Converting Lat/Long coord to X,Y,Z
Since Unity is cartesian X,Y,Z, what you need is retrieving those coordinates from the Latitude and Longitude (and eventually altitude)… The official computation would take in consideration curvature and exentricity (the earth is not a sphere…) but considering it’s for a Unity project, I think you could just get rid of them and simply use basic Cos
and Sin
compute…
If you need to actually convert coord from Lat/Long to X,Y,Z (For example you are rendering stuffs on an actual globe, and you need X,Y,Z coords on a sphere)
It would be :
public class CoordinateConverter : MonoBehaviour
{
public static Vector3 LatLongTo3D(float latitude, float longitude, float altitude = 0)
{
const float R = 6371000f; // Earth's radius in meters
float latRad = Mathf.Deg2Rad * latitude;
float lonRad = Mathf.Deg2Rad * longitude;
// XY is Equator plane
float x = (R + altitude) * Mathf.Cos(latRad) * Mathf.Sin(lonRad);
float y = (R + altitude) * Mathf.Cos(latRad) * Mathf.Cos(lonRad);
// Z is from South Pole to North Pole
float z = (R + altitude) * Mathf.Sin(latRad);
return new Vector3(x, y, z);
}
}
If you need to get flat coords (for example you want to get positions on a flat map, like a GPS or Google Map)
Then it’s much simpler, Y is proportionnal to Latitude, and X is proportionnal to Longitude (with cos(lat) as a ratio)
public class CoordinateConverter : MonoBehaviour
{
public static Vector3 LatLongTo3D(float latitude, float longitude, float altitude = 0)
{
const float R = 6371000f; // Earth's radius in meters
float latRad = Mathf.Deg2Rad * latitude;
float lonRad = Mathf.Deg2Rad * longitude;
float x = R * Mathf.Cos(latRad) * lonRad;
float y = R * latRad;
float z = altitude;
return new Vector3(x, y, z);
}
}