Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

GeoJson export for Unity3D integration

A topic by InsaneQA created Dec 30, 2019 Views: 2,599 Replies: 7
Viewing posts 1 to 7

Hi!

I've started creating a 2D medieval game in Unity, and I must say that the Medieval Fantasy City Generator is totally superb, especially with the GeoJson export available!

However, it seems there is a bug in every exported json (please see the image below. I've used http://geojson.io/ for validation):

Basically, the first and the last points in the array should be the same. With this bug, the FeatureCollection object cannot be correctly deserialized. It can only be reproduced for buildings (not earth or walls).

 watabou, could you please fix the bug if that's not too timeconsuming?

I've fixed the bug manually for 2 documents (it took about 15-20 minutes), and here is the result of the mesh generation:

That's the first day of work with the GeoJson, so there are some buildings with the wrong shape, and the city is mirrowed, however it seems I'm on the right track.

I'm going to share the deserialization tool for Unity after it's done.

A small update: I've added a script to fix the Json problem. The script will also remove any ring with 3 points or less, since it's not allowed by the GeoJson specification.

Developer

Hi!

It doesn't conform to specification, but I wouldn't like to change this behavior.  Serializing the same point two times is obviously excessive for polygons. Of course, it's not much work to implement this serialization, but it seems to me that in most cases you'll need to discard that additional point after deserialization anyway.  And if you are writing your own importer (rather than using some strict existing one) it shouldn't be a problem, should it?

I said that I wouldn't like to change it, but it doesn't mean that I won't. This whole GeoJSON thing is work in progress, so how it will end up working depends on users feedback and my own experience with it. Any notes, suggestions and arguments are welcome!

(+1)

Sure, no need to worry - I've already handled the missing points in the code. 

There is also a situation when a building is imported with only 3 points and the last point equals to the first point (it's basically a line). I simply remove those buildings as well in the importer. 

Thanks!

Done!

The Unity importer can be found here: https://github.com/InsaneQA/UnityMedievalCityImporter

The unitypackage is in the root of the repository

Developer

Awesome! I can't really appreciate it myself, since my Unity knowledge is virtually zero:), but I'm going to share the link if you don't mind.

Btw, in the next version of MFCG exported JSONs will include some additional information. For example to build a river we need to know not only it course, but also its width. That's one of the discoveries I've made while working on Toy Town 2 :)

(+1)

I AM SO GLAD TO HAVE FOUND THIS

(+1)

I am a novice unity developer and plan to use your stuff to spawn medieval cities.