Last week I briefly played with Google Earth (GE) and KML, exploring the potential of using it to do something useful with FlightGear (FG).
The quickest hack I did was the GE version FGMap, which shows a moving map of all the online pilots on the FG MP servers. It is basically a very simple change with the FGMap CGI that translate MP server info into XML, only this time it outputs KML. Very simple and straight forward, nothing fancy at all. Check it out by opening this file in GE (if no one is on the server, you’ll see nothing! Check FGMap too).
[Updated] GE MP map using 3D models work-in-progress:
This weekend I started looking into GE’s 3D model support. Currently it supports two kinds of 3D model definition. KML embedded model using MultiGeometry, or a Collada .dae format. After some investigation I figured I have to use Collada to do what I want – having a 3D model of an aircraft and updating its position/orientation in GE. MultiGeometry (current version at least) is a fixed coordinates format, while with a Collada model you can place it in GE and then move it around, and also altering its heading/pitch/roll.
Quickly I found this Collada exportor plugin for Blender. As a test I loaded the C172P aircraft AC3D model from FG into Blender, followed by a few trail-and-error and I figured out what I need to export for GE: 1) Convert all faces to triangles, 2) Export Triangles, Disable Physics, Use UV Image and optionally Use Relative Paths.
According to the KML tutorial I have to pack up the .dae file together with the textures, along with a textures.txt for textures path mapping. However I discovered you could actually alter the path referenced in the .dae file to a local jpeg file, or even an HTTP URL.
So now I’ve got GE to show a 3D model of an aircraft from FG. Next is to get FG to talk to GE. There are many ways (network, serial port, etc) in FG you can export real time flight data. To make things easier for now, I’ve set it up to export simply latitude, longitude, altitude, pitch, roll, heading to a file (or actually a fifo), then I wrote a little program to read and output a KML file for GE to read. Then on the GE side, I have to create a KML with a NetworkLink to refresh the actual FG KML.
Now, problems. It seems even if I set the refresh time to be 0 seconds, and I can see GE refreshing the link continuously, on screen it still only updates the position/orientation about once per second. It could well be a GE internal limitation (or feature). The bottom line is, we need a sane way to feed data into GE.
Another thing is I can never get GE to “follow” the aircraft properly. It’s either not panning faster enough, or it will go kinda crazy and jitter a lot. Guess I’m not a GE/KML yet. I need to test it more and tidy up my codes/scripts/things a bit and I’ll put them up.
Nevertheless, it’s kind of fun to “fly FG inside GE”.
Screenshots of FlightGear running side by side with Google Earth, whereby FG sending data to GE and showing the 3D aircraft. Possibly more screenshots here
Hong Kong with Computamaps Hong Kong 3D models