官术网_书友最值得收藏!

Modifying heightmaps with Terrain Editor

In Terrain Editor, we find a number of functions that let us modify a heightmap-based terrain, something which is used in many games.

A heightmap, in its simplest form, is a 2D array (the dimensions representing x and y coordinates) usually storing floats that represent height values. These can be saved as grayscale images where brighter areas correspond to higher ground and, reversibly, darker areas correspond to lower ground.

The terrain fields of jMonkeyEngine have much more information to help you create a visually appealing terrain. Things like vertex normal data and color and texture data are available for modification through the API, for daring programmers.

A heightmap

How to do it...

We will begin by creating a terrain for the scene before exploring how to modify it. To do this, perform the following steps:

  1. First, we either create a new scene or load a scene we've worked with previously.
  2. In the SceneExplorer window, right-click on the main scene node and select Add Spatial and then Terrain...
  3. To edit the terrain, we have to find the scene j3o file in the Projects window. It should be present in the Scenes folder inside Project Assets. Right-click on the scene file and select Edit Terrain.
  4. Now, we have a flat and nice terrain. While it's perfectly functional, let's explore the functions in the TerrainEditor window. These functions are shown in the following screenshot:
  5. Next to the Add Terrain icon, you have the raise/lower terrain icon. This icon uses the values of Radius and Height/Weight sliders to modify the terrain. Try it out and see how it can be used to create hills and valleys. The Level terrain icon can be used to create flat areas in the terrain. It works by right-clicking on an area, the height of which you would like to have as a reference, and then holding the left mouse button and flattening out the terrain at the selected height, creating plateaus.

    Tip

    If you're going to use this as a test bed for the other chapters, try to keep the area just around Jaime at the default height, for now. This is because we don't have any logic to keep it at the actual ground level, and we would like to see what is going on in the recipes.

  6. While the terrain comes with basic texturing, we might want to do something more interesting. First of all, we need to add another texture layer. This is done with the icon that looks like a plane with a plus sign on top (the Add another texture layer icon).
  7. After clicking on it, there should be another row in the Painting window, below it. Clicking on the Texture field will bring up a selector with all the textures available to the project. Select a suitable texture among the available ones.
  8. Now, to paint, click on the button with a spray can on it. You can now paint by holding the left mouse button over the terrain, and erase by pressing the right mouse button. Like most of the other functions in the TerrainEditor window, it uses the Radius and Height/Weight values.

    Tip

    When painting a terrain by hand, it is a good idea to have a reference image of the terrain type at hand. That way we can, for example, see how grass grows on slopes, or snow gathers on mountains, and produce more realistic results. Always start by painting in broad strokes, gradually painting with smaller and smaller brushes.

How it works...

The function of most of the buttons is pretty self-explanatory, but let's look at what happens when either of them are applied.

A little bit of smoothing is something that might be needed after generating a heightmap using an automated tool. In such a case, you most likely won't use a brush, though, but rather a filter that will apply it evenly across the whole of the heightmap. The brush might instead be used to smooth out an area where a game character is supposed to move to make it a better game experience. It might also be that the ground of an area is of a type that would most likely be smoother than the surroundings, like a beach among rocky cliffs.

Level terrain has similar uses. If we need sufficient space to place a large building for example, it is the best way to ensure that no part of the building ends up floating or submerged beneath the ground.

主站蜘蛛池模板: 青岛市| 绥江县| 鄂托克前旗| 沙田区| 福建省| 平陆县| 尤溪县| 伊春市| 乳山市| 斗六市| 太仆寺旗| 建湖县| 邹平县| 郎溪县| 基隆市| 吕梁市| 大洼县| 德保县| 珠海市| 葫芦岛市| 康乐县| 神农架林区| 梅河口市| 三原县| 清流县| 大竹县| 如皋市| 北海市| 灵山县| 紫金县| 灵川县| 仁布县| 普兰县| 内乡县| 鄄城县| 密云县| 商都县| 朔州市| 介休市| 金川县| 闸北区|