osm2city.py Development

From FlightGear wiki
Revision as of 11:24, 12 April 2020 by Johan G (talk | contribs) (+ Template:Lowercase title)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Autogen Scenery
Started in 11/2013
Description Improved autogen support for FlightGear using OSM data
Contributor(s) radi, vanosten, Soitanen, portreekid
Status Under active development as of 02/2016
Topic branches:
$FG_SRC https://gitlab.com/osm2city/osm2city/
fgdata https://gitlab.com/osm2city/osm2city-data/


Textures

This section gives some general info about textures with osm2city. It also describes how to create your own facade textures.

Since you could have a number of cities generated by osm2city which would share textures, currently all textures reside in the folder /some/place/tex/. An actual scenery folder, say, Objects/w130n30/w123n37/ will have a link to /some/place/tex. The .ac objects inside Objects/w130n30/w123n37/ will then e.g. load a texture tex/facade.png The tex/ folder is included in the LOWI download.

Registering your own textures

Textures must be registered in textures.py. Currently we use facade textures and roof textures. Since some facade textures might not match with some roof textures, we use a mechanism of provides=[] and requires=[] features: A texture could require a black roof, while providing a modern, commercial facade.

Example entry in textures.py:

facades.append(Texture('tex/DSCF9495_pow2',
14, [585, 873, 1179, 1480, 2048], True,
19.4, [274, 676, 1114, 1542, 2048], False, True,
requires=['roof:color:black'],
provides=['shape:residential','age:old','compat:roof-flat','compat:roof-gable']))

This registeres a file tex/DSCF9495_pow2. The extention .png is added automatically when writing the .ac file, so make sure you use only .png textures.

The second line in the above example says the texture

  • is 14m wide
  • can be split at u = 585, 873, ... 2048 px, where u is the horizontal coordinate. The last value 2048 of this list also gives the width in px. Note that the .ac file uses nondimensionalized coordinates (0 ... 1). Internally, all coordinates are divided by the last value. Therefore, when preparing the textures, you can work with the highest resolution possible and register those numbers, then downscale the texture for actual flightgear use. Once the next generation of graphics cards arrives you just replace the textures with higher resolution ones.
  • the texture can repeat in horizontal direction

The third line gives the same information for the vertical direction:

  • 19.4m height
  • can split at 274, 676, ... 2048px,
  • the texture cannot repeat in vertical direction
  • the texture has a roof section (I've forgotten what this actually means, will have to check...)

The fourth and fifth line state compatibility with other textures: This facade texture requires a black roof. It provides an old-aged, residential facade, and is compatible with both flat and gable roofs.


Assigning specific textures

NB: line numbers might be outdated, but the principle still applies

Currently, the textures are assigned somewhat randomly to the buildings. Support for specific textures is not implemented yet. But with some python knowledge, you could code that yourself.

To use specific textures for specific types of buildings, you would have to read the building type from the OSM file. OSM parsing is done in the ways method (osm2city.py, line 145) of the class wayExtract(object). Check lines 160-165, you would probably need something similar to process your type tag. Then in line 176, a building object is created building = Building(osm_id, tags, _refs, _name, _height, _levels) You would pass your type tag to the building class here, and of course extend the Building class (starting at line 102) to store that tag.

Finally, in building_lib.py, around line 425: b.facade_texture = facades.find_matching(requires, b.height) This decides which facade texture is used for a building. b is an instance of the class Building. You could pass here the b.type tag, then extend the find_matching method to find a texture matching that tag.