Import KML files in 3ds max

Looking for more advanced map making tools? Check out Maproom. You can try it out for free!

Importing and exporting KML files in 3ds max makes it a tad easier to reuse work done in 3ds max in maps and google earth. Using 3ds max to create maps isn’t a very obvious choice however. Max handles large distances pretty bad. If you want to respect geographical projections or UTM-coordinates, we need to think of a trick to make sure the maps are being displayed accurately. The KMLparser does just that.

Check out this short video-tutorial (no sound)

The script lets you import and export geo-referenced KML-files
Use shapes drawn in Google earth as a reference

KML

KML files have been created by google. They use it to store data in a geographical manner. You can load and save KML-files from google earth, but there are many more applications that support KML-files. Tilemill is one of them, as well as sketchup. At the moment the KMLparser maxscript supports paths and polygons. These are open and closed shapes. I intend to add support for 3D geometry in a later stage.

Coordinates

KML-files store geographical positions in latitude/latitude coordinates. These are angular coordinates on a globe. 3ds max uses an x/y coordinate system on a flat plane. When importing a KML-file these coordinates need to be converted between lat/long and UTM. UTM coordinates are coordinates on a flat plane. These are calculated for a specific UTM-zone. This means you need to know the UTM-zone your map is in. You can have the script calculate the UTM zone for you. This works fine except for a few edge cases. In those cases you can enter the UTM zone manually. You can find this UTM-zone on a map provided with the script, or with an online resource. There are 60 zones in total.

Pick a UTM zone to make sure your objects match their locations correctly

Import

After converting the coordinates, the shapes are moved towards the origin in 3ds max. This is done to avoid large distances between the objects and the origin as 3ds max handles these distances badly. The script can calculate this offset itself, or you can input an offset. Only use a custom offset if you know what you’re doing! The imported objects remember their offset. this helps when exporting the shapes back to a KML. This data is stored in a KML map helper-parent to which all imported shapes have been linked.

Let’s say you have to draw a map of a new road, but you already have a 3D model of that road. How do you get a shape from that model to the right location in google earth? You can draw some existing roads in google earth and save them as an kml. Import the kml-file in 3ds max. Draw the new road on top of the imported shapes and make sure they fit nicely. After that you can attach the new roads to the parent dummy and export that back to KML. Finally open that KML in google earth and voila: the new road is there!

This script uses some ideas from a kml-importer by Mario Morais

In 3ds Max you can draw shapes with the imported KML-file as a reference

22 Comments

Join the discussion and tell us your opinion.

Davidreply
2013-01-26 at 22:02

Hi Klaas Nienhuis, thank you very much for your work.

This script looks incredible, but I get an error on load a kml telling “Runtime error: update shape: curve with insufficient knots, knots added: Editable Spline”.

Am I doing something wrong?

Thank you again.

Klaas Nienhuisreply
2013-01-27 at 14:25
– In reply to: David

Hi David, thanks for the kind words.
When I read the error message I’d say there are shapes with 0 or 1 knots (vertices) in the kml. max probably has issues handling these. Could you send me the kml-file? I can take a look at it and write a fix for the script.
mail [at] klaasnienhuis [dot] nl
Klaas

Rodolforeply
2013-02-06 at 15:04

Hi Klaas, thanks for the script!

I´m trying to import to max and get this message (http://imageshack.us/photo/my-images/580/errorimportkml.jpg/)
How could i fix this?

Klaas Nienhuisreply
2013-02-06 at 19:56
– In reply to: Rodolfo

It’s hard to say. Maybe there are shapes with zero knots. If you could send me the file you’re importing I can check this out and maybe update the script. My email address is in the comment above yours, or you just share a link here in the comments.

Giftreply
2013-11-30 at 09:06

Hi Klass,

Thanks for your fantastic script!

One error, I just wonder why all points that exporting from MAX to KML are not as same as they were in MAX screen. I have tried on several shapes with Lat Long inputs, but all seems to be slightly distorted from an original shape. Any ideas or suggestion?

I thought that some point in the spline line can not be perfectly converted via decimal degree calculation, right?

Klaas Nienhuisreply
2013-11-30 at 23:05
– In reply to: Gift

Hi Gift, thanks for the compliment!
Yes, to begin with: the conversion between lat/long and the flat coordinate system in max is not 100%, though it should be good enough for most cases. However, I’m using the UTM-zones as a base coordinate system for all conversions. If you’re working with a location relatively far away from the origin of your UTM zone, the deviation becomes bigger. This might be what you’re experiencing. Try to work on a location closer to a UTM-origin to see if this solves the distortion. Of course, if you need a specific location on the edge of your zone, you’re screwed!
I had in mind to change this into a calculation where you can pick your own origin, but didn’t get around to it. I’m not a GIS specialist, so these calculations are a bit over my head at times.

stevereply
2014-10-08 at 15:13

Is there a way to name the shapes as they get imported? I’m importing about 4000 shapes and I need to name them inside 3dsmax instead of shape2222 etc.

Klaas Nienhuisreply
2014-10-09 at 07:05
– In reply to: steve

Hi Steve, shapes could be named if there’s a name available in the KML file. Could you post a link to a samplefile here? I can take a look how I could extract names and assign them to the imported shapes.

stevereply
2014-10-10 at 18:46

Hi Klass, thank you for the response! Here’s an example: http://pastebin.com/e7v66wsQ . Some entries have only one polygon without multigeometry. I think the name could be pulled from the /Placemark/Name or /ExtendedData/SchemaData/SimpleData or you could assume that people could insert the name before import like samplename directly inside of each polygon tag.

Andresreply
2014-11-21 at 02:32

Hi Klaas, awesome plug in, it’s truelly a time saver.
I’m trying to import a kml and 3ds Max is showing the next error:
— Type error: FilterString [String to filter] [Tokens] requires String, got: undefined
Then it hilights the line 261:
local arrKnot = filterString arrCoordinates[1] ” ”
any help? please?

Phil Suterreply
2015-06-03 at 13:20

Thank you so much, I followed your instructions and it worked first time with no bother, I just have to find a way now of importing terrain into Trainz Simulator and this will be a great asset

Hillreply
2016-04-08 at 10:31

Is will be available version to 3ds Max 2016? This version not work. Script generate empty file:

myFile

Klaas Nienhuisreply
2016-04-08 at 10:46
– In reply to: Hill

KML import/export will be integrated into Maproom. But it has not been integrated yet, I’m sorry.

Philreply
2016-10-26 at 10:13

Hi Klass, I have the same issue as Phil Suter – the Filterstring error – do you have any idea how to fix this? Thanks!

Philreply
2016-10-26 at 10:14

Sorry I meant Andres!

Klaas Nienhuisreply
2016-10-26 at 19:03

Hi Phil and Andres, this might be caused by the contents in the KML file. I’ve noticed there are KML files around which link to other kml files several layers deep. Only in the deepest layer there’d be any geo information. This script isn’t sophisticated enough to deal with that. This script can read lines and polygons from the kml and directly linked collada files (in case of a kmz). That’s about it.

Stevereply
2017-09-05 at 04:59

Hi Klaas, I was very excited to try your epic script, but after trying to make it work for the last 4 hours I cant get the output to line up with google earth. I imported from Globalmapper a river line, at UTM 55, moved it in CAD to 0,0 and then reexported to Google earth to see if it lined up but it was out by 1km. I would love to have a chat.

David Sugarreply
2019-07-30 at 15:46

Hey Klaas, I like your plugins and tutorials. I have a general question for you. So, I’ve been using Placemaker… which I think is okay. not very detailed. I don’t understand why I can’t export the paths from Google Earth with the 3d data for each point. It seems that most of the software out there has a 30 meter limitation for height data. Which make no sense to me.

I simply want to be able to take the paths that I draw in GE and import them into 3d max. And have them to scale with xyz coordinates per point.

Do you know any way to accomplish this?

Klaas Nienhuisreply
2019-08-08 at 08:37
– In reply to: David Sugar

Hi David,
generally, terrain heights do not export from GE. You could use rulers, but this becomes cumbersome. I suggest you look at maproom (https://www.klaasnienhuis.nl/wp/product/maproom) which supports kml import and export and also contains terrain elevation.

Amirreply
2019-10-03 at 22:39

Hi Klaas Nienhuis, thank you very much for your Amazing work.For my thesis, I need to convert the x, y, z coordinates to the UTM coordinates in the Navisworks.I work with VB.net Application language.Is there a mathematical formula to guide me.Please send your answer to my email.I’m waiting for your answer!
Best regard.

Klaas Nienhuisreply
2019-10-04 at 07:42
– In reply to: Amir

Hi Amir, I’m glad you like it. Wikipedia has a UTM formula https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system. Though I do most of my projection with the help of dotspatial.net

Philippe Lehnerreply
2021-06-04 at 13:17

Hi Klaas

Im looking for a workflow to get my Droneflightdata from a Phantom 4 pro (KML CVS or GPX) into 3dsmax to match the camera with my 3D scene.

Is there a update for your plugin?

kind regards

Philippe Lehner
pl@designraum.ch

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.