搜档网
当前位置:搜档网 › Unity3d-地形制作教程

Unity3d-地形制作教程

Unity3d-地形制作教程
Unity3d-地形制作教程

Unity3d-地形制作教程

Using Terrains 使用地形

Creating a new Terrain创建一个新的地形

A new Terrain can be created from Terrain->Create Terrain. This will add a Terrain to your Project and Hierarchy Views. 如要创建地形,点击Terrain->Create Terrain. 如下图所示

Your new Terrain will look like this in the Scene View: 刚创建好的地形在场景视图中如下图.

A new Terrain in Scene View

If you would like a differently sized Terrain, choose Terrain->Set Resolution from the menu bar. There are a number of settings that related to Terrain size which you can change from this dialog.

点击Terrain->Set Resolution,可以设置地形的大小.如下图所示.从上而下依次为地形的宽度,高度,长度,高度图像素,细节像素-草或其它细节贴图,像素,贴图像素—对应第二个及其之后的贴图,底层贴图像素-对应第一个贴图.

Setting the resolution of your terrain.

On the above image, there are values that can be changed.

These values are:

?Terrain Width: The width of the Terrain in units.

?Terrain Height: The height of the Terrain in units.

?Terrain Length: The length of the Terrain in units.

?HeightMap Resolution: The HeightMap resolution for the selected Terrain.

?Detail Resolution: The resolution of the map that controls grass and detail meshes. For performance reasons (to save on draw calls) the lower you set this number the better.

?Control Texture Resolution: The resolution of the splat map used to layer the different textures painted onto the Terrain.

?Base Texture Resolution: The resolution of the composite texture that is used in place of the splat map at certain distances.

Navigating the Terrain

Terrains work a bit differently than other GameObjects. Most notably, there is no Transform Gizmo that allows you to position the Terrain. Instead, you use Brushes to paint and manipulate your Terrain. If you do want to reposition a Terrain, you can modify its Transform Position values in the Inspector. This allows you to move your Terrain around, but you cannot rotate or scale it.

地形对象与其他游戏对象有点不同,它没有转换轴,不可以通过鼠标直接改变它的坐标.如果要改变坐标,可以通过在属性面板修改.不过不可以旋转和缩放.

While your Terrain is selected in the Hierarchy, you can gracefully navigate the terrain with the F (focus) key. When you press F, wherever your mouse is positioned will be moved to the center of the Scene View. This allows you to touch up an area, and quickly zoom over to a different area and change something else. If your mouse is not hovering over an area of the Terrain when you press the F key, the entire Terrain will be centered in your Scene View.

地形被选择后,按F按可以以鼠标点击位置为中心察看地形.如果没有用鼠标点击任何一点,会以整个地形为中心察看地形.

Editing the Terrain 编辑地形

With the Terrain selected, you can look at the Inspector to see some incredible new Terrain editing tools.

选择地形后,在属性面板会出现7个按钮以方便地形的编辑.从左到右依次为高度工具.特定高度工具.平滑工具.贴图工具.画树工具.细节工具.其他设置.如下图所示.

Terrain Editing Tools appear in the Inspector

Each rectangular button is a different Terrain tool. There are tools to change the height, paint splat maps, or attach details like trees or rocks. To use a specific tool, click on it. You will then see a short description of the tool appear in text below the tool buttons.

点击任何一个按钮,按钮下面都会出现关于此按钮的说明及相关的快捷键.

Most of the tools make use of a brush. Many different brushes are displayed for any tool that uses a brush. To select a brush, just click on it. The currently selected brush will display a preview when you hover the mouse over the terrain, at the size you have specified.

每个工具都有不同的笔刷.选取笔刷后,在地形上都会出现蓝色图形表示笔刷的范围.

You will use all of these brushes in the Scene View to paint directly onto your Terrain. Simply choose the tool and brush you want, then click & drag on the Terrain to alter it in real-time. To paint height, textures, or decorations, you must have the Terrain selected in the Hierarchy View.

花点时间熟悉这些工具.选取一个工具及笔刷,用拖放的方式就可以实时地编辑地形.F键,多用用这个键,你会发现没有它,修改地形是件困难与痛苦的事.享受它带来的方便吧…

Note: When you have a brush selected, move your mouse over the Terrain in the Scene View and press F. This will center the Scene View over the mouse pointer position and automatically zoom in to the Brush Size distance. This is the quickest & easiest way to navigate around your Terrain while creating it.

Terrain Keyboard Shortcuts 地形编辑的快捷键

While Terrain Inspector is active, those keyboard shortcuts can be used for fast editing (all of them customizable in Unity Preferences): 以下是地形编辑的快捷键.只有在地形被选取后才可用.

?Shift-Q to Shift-Y selects active terrain tool. Shift-Q 到Shift-Y 对应从左到右六个工具

?Comma (,) and dot (.) cycle through active brush. 逗号和句号向前或向后选取笔刷

?Shift-comma (<) and Shift-dot (>) cycle through active tree/texture/detail object. Shift-逗号和Shift-句号向前或向后选取树/贴图/细节物体.

以下是对各个工具的详细说明.

Height 地形高度工具

Using any of the Terrain editing tools is very simple. You will literally paint the Terrain from within the Scene View. For the height tools and all others, you just have to select the tool, and click the Terrain in Scene View to manipulate it in real-time.

使用地形工具画地形是很简单的.你所要做的就是选取工具,再用鼠标在地形上拖拽就可以实时地画出地形.不然,要画出游戏级别的地形,还要一张原画以及多多的练习.总体的思路就是先画高度,再分出层次,画贴图,画树以及增加细节.

Raising & Lowering Height

The first tool on the left is the Raise Height tool .

第一个工具:地形高度工具.

With this tool, you paint brush strokes that will raise the height of the Terrain. Clicking the mouse once will increment the height. Keeping the mouse button depressed and moving the mouse will continually raise the height until the maximum height is reached.

使用这个工具,可以依据笔刷的类型及强度画出隆起或凹陷的地形(初始时不可用).按鼠标一次,就会隆起地形.按住鼠标同时拖拽,可以不断隆起地形.直到达到最大高度.如下图所示.

You can use any of the brushes to achieve different results 使用不同的笔刷可以得到不同的效果.

If you want to lower the height when you click, hold the Shift key. 如要凹陷地形,按住Shift 键.如下图所示在做地形时,一个很重要的按键就是F键.多多用这个键吧.

Note:When you have a brush selected, move your mouse over the Terrain in the Scene View and press F. This will center the Scene View over the mouse pointer position and automatically zoom in to the Brush Size distance. This is the quickest & easiest way to navigate around your Terrain while creating it.

Paint Height

The second tool from the left is the Paint Height tool .

第二个工具,最大高度工具. 可以设定最大高度,当达到这个高度后,地形就不再加高.周围高度一样时,就会

变平.这个工具用于分出地形高度的层次.Shift键在这个工具上的用途是选取最大高度.

This tool allows you to specify a target height, and move any part of the terrain toward that height. Once the terrain reaches the target height, it will stop moving and rest at that height.

To specify the target height, hold Shift and click on the terrain at the height you desire. You can also manually adjust the Height slider in the Inspector.

Now you've specified the target height, and any clicks you make on the terrain will move the terrain up or down to reach that height. 下图所示,最大高度工具的应用.

Smoothing Height

The third tool from the left is the Smoothing Height tool . 第三个工具是高度平滑工具.用于再个不高度地形之间的过渡部分.这样地形不会有棱有角.如下图所示.

This tool allows you to soften any height differences within the area you're painting. Like the other brushes, paint the areas you want to smooth in the Scene View.

Working with Heightmaps 高度图创建地形

If you like, you can import a greyscale Heightmap created in Photoshop, or from real-world geography data and apply it to your Terrain. To do this, choose Terrain->Import Heightmap - Raw..., then select

the desired RAW file. You'll then see some import settings. These will be set for you, but you have the option of changing the size of your Terrain from this dialog if you like. When you're ready, click the Import button. Once the Heightmap has been applied to the Terrain, you can edit it normally with all the Tools described above. Note that the Unity Heightmap importer can only import grayscale raw files. Thus you can't create a raw heightmap using RGB channels, you must use grayscale.

用Photoshop或其他3D软件导出灰度图可以使用灰度图来创建地形.灰度图的格式应为RAW格式.点击, Terrain->Import Heightmap – Raw 出现对话框,可以修改地形的大小.点击Import就可以创建地形了.创建好后,你可以使用所有的地形工具再进行编辑. Unity可以支持16位的灰度图.可以通过

Photoshop,Bryce,Terragen这几个软件来创建灰度图.同样,可以在Unity中导出灰度图.在

Terrain->Import Heightmap - Raw...对话框中,点击Export.就OK. 通过Terrain->Flatten....命令可以将地形整体设置一个高度.这个命令最好在最初使用.不然,做好的地形会变成平面.需要重新编辑.

Unity works with RAW files which make use of full 16-bit resolution. Any other heightmap editing application like Bryce, Terragen, or Photoshop can work with a Unity Heightmap at full resolution.

You also have the option of exporting your Heightmap to RAW format. Choose Terrain->Import Heightmap - Raw... and you'll see a export settings dialog. Make any changes you like, and click Export to save your new Heightmap.

Unity also provides an easy way to flatten your terrain. Choose Terrain->Flatten.... This lets you flatten your terrain to a height you specify in the wizard.

Textures 给地形加贴图

Decorate the landscape of your terrain by tiling Terrain Textures across the entire terrain. You can blend and combine Terrain Textures to make smooth transitions from one map to another, or to keep the surroundings varied. 地形贴图就如角色贴图一样,是地形整体风貌.出于游戏整体性能和地形引擎数据结构的原因.地形的贴图数最好是4的倍数.

Terrain Textures are also called splat maps. What this means is you can define several repeating high resolution textures and blend between them arbitrarily, using alpha maps which you paint directly onto the Terrain. Because the textures are not large compared to the size of the terrain, the distribution size of the Textures is very small.

Note: Using an amount of textures in a multiple of four provides the greatest benefit for performance and storage of the Terrain alpha maps.

To being working with textures, click on the Paint Textures button下图所示就是贴图画笔

in the Inspector.

Adding a Terrain Texture为地形增加贴图

Before you can begin painting Terrain Textures, you will add at least one to the Terrain from your Project folder. Click the Options Button->Add Texture.... 如图所示, Options Button->Add Texture....你需要为地形增加贴图,才能用贴图来画地形.第一个地形会作用于整个地形.第二个之后的贴图才能用笔刷画.重复以上步骤就可以为地形增加需要的贴图了.如果要更换贴图,就在当前贴图选取后(被选取的贴图会以高亮蓝

色表示),点击Edit Texture,之后就可以重新选取贴图.另一个Remove Texture 就是移除贴图.贴图尺寸越小,过渡会越自然.反之亦然.

This will bring up the Add Terrain Texture dialog.

The Add Terrain Texture dialog 在Splat 中选取需要的贴图文件.第二三个参数是贴图的尺寸大小.

From here, select a tileable texture in the Splat property. You can either drag a texture to the property from the Project View, or choose one from the drop-down.

Now, set the Tile Size X and Tile Size Y properties. The larger the number, the larger each "tile" of the texture will be scaled. Textures with large Tile Sizes will be repeated fewer times across the entire Terrain. Smaller numbers will repeat the texture more often with smaller tiles.

Click the Add Button and you'll see your first Terrain Texture tile across the entire Terrain.

Repeat this process for as many Terrain Textures as you like.

Painting Terrain Textures 画地形贴图

Once you've added at least two Terrain Textures, you can blend them together in various ways. This part gets really fun, so let's jump right to the good stuff. 为地形增加了两个或以上贴图后,就可以使用贴图画地形了.选取贴图和笔刷,用鼠标在地形上拖拽,画贴图就是如此简单.画贴图时记得使用F和Alt键,这样的效率会更高.

Select the Terrain Texture you want to use. The currently selected Terrain Texture will be highlighted in blue.

Select the Brush you want to use. The currently selected Brush will be highlighted in blue.

Select the Brush Size, Opacity, and Target Strength.

Click and drag on the terrain to draw the Terrain Texture.上图从上而下参数为:笔刷大小,透明度,笔刷强度

Use a variety of Textures, Brushes, Sizes, and Opacities to create a great variety of blended styles.

不同的笔刷,大小和透明度可以得到不同的效果.

Note:When you have a brush selected, move your mouse over the Terrain in the Scene View and press F. This will center the Scene View over the mouse pointer position and automatically zoom in to the Brush Size distance. This is the quickest & easiest way to navigate around your Terrain while creating it.

Trees

Unity's Terrain Engine has special support for Trees. You can put thousands of trees onto a Terrain, and render them in-game with a practical frame rate. This works by rendering trees near the camera in full 3D, and transitioning far-away trees to 2D billboards. Billboards in the distance will automatically update to orient themselves correctly as they are viewed from different angles. This transition system makes a detailed tree environment very simple for performance. You have complete control over tweaking the parameters of the mesh-to-billboard transition so you can get the best performance you need.

You can easily paint lots of trees for beautiful environments like this

Adding Trees 增加树木

Select the Place Trees button in the Inspector.

Before you can place trees on your terrain, you have to add them to the library of available trees. To do this, click the Edit Trees button->Add Tree. You'll see the Add Tree dialog appear.

The Add Tree dialog

Select the tree from your Project View and drag it to the Tree variable. You can also edit the Bend Factor if you want to add an additional bit of animated "bending in the wind" effect to the trees. When you're ready, click Add. The tree will now appear selected in the Inspector.

The newly added tree appears selected in the Inspector

You can add as many trees as you like. Each one will be selectable in the Inspector for you to place on your Terrain.

The currently selected tree will always be highlighted in blue

增加树和增加贴图是一样的,所不同的只是Blend factor 这个参数,如果要有树在风中摇摆的效果,就设置为1 或以上,不要风的效果就设置为0. 按住Shift, 可以移除树.还是两个快捷键F键和Alt键.可以提高效率.

Painting Trees

While still using the Place Trees tool, click anywhere on the Terrain to place your trees. To erase trees, hold the Shift button and click on the Terrain.

Painting trees is as easy as using a paintbrush tool

There are a number of options at your disposal when placing trees. 树的参数如下

Brush Size Radius in meters of the tree placing brush. 以米为单位,树的半径.一次画多少棵树Tree Spacing Percentage of tree width between trees.树与树之间的百分数

Color Variation Allowed amount of color difference between each tree. 树与树之间颜色差的范围Tree Height Height adjustment of each tree compared to the asset.场景中树与模型之间高度比Height Variation Allowed amount of difference in height between each tree.树与树之间的高度比Tree Width Width adjustment of each tree compared to the asset. 场景中树与模型之间宽度比Width Variation Allowed amount of difference in width between each tree. 树与树之间的宽度比

Tree Painting Tips 技巧:不同区域选用不同的笔刷类型.通过树之间的距离(Tree Space)来表现树的疏密.

Different Brush sizes cover different area sizes

Adjust Tree Spacing to change the density of the trees you're painting

Editing Trees通过Edit Trees button->Edit Detail 或双击树,会出现对话框,可以设置树的参数.

To change any import parameters for an added tree, select the detail and choose Edit Trees

button->Edit Detail. Or double-click the tree you want to edit. You will then see the Edit Tree dialog, and you can change any of the settings.

Mass Placement If you don't want to paint your trees and you just want a whole forest created, you can use Terrain->Mass Place Trees. Here, you will see the Mass Place Trees dialog. You can set the number of trees you want placed, and they'll be instantly positioned. All the trees added to your Terrain will be used in this mass placement. 通过Terrain->Mass Place Trees, 可以一次增加数量巨大的树.下图一次增加一万棵树.树的类型以当前选取的为准.

10,000 Trees placed at once

Refreshing Source Assets

If you make any updates to your tree asset source file, it must be manually re-imported into the Terrain. To do this, use Terrain->Refresh Tree and Detail Prototypes. This is done after you've changed your source asset and saved it, and will refresh the trees in your Terrain immediately.

如果使用第三方软件修改树的模型.需要使用Terrain->Refresh Tree and Detail Prototypes.来更新

Creating Trees 自定义树

Every tree should consist of a single mesh with two Materials. One for the trunk and one for the leaves. For performance reasons, triangle count should be kept below 2000 for an average tree. The fewer triangles the better. The pivot point of the tree mesh must be exactly at the root of the tree, that is at the point where the tree should meet the surface it is placed on. This makes it the easiest to import into Unity and other modelling applications.

树的模型由一个网格加两个材质组成.一个材质用于树干,另一材质用于树叶.基于性能上的考虑,一棵树的三角面数应少于2000.越少性能越好.树的轴中心应刚好在树根.树干的材质文件命名为:树的文件名+Bark,树叶的命名为树的文件名+Branch.模型文件以FBX格式存放.如需一次画一棵以上的树,需再做一个模型,把好几棵树放在一个FBX文件里.模型文件名与文件夹的名称要一致.可以参考官方的模型,之后再创建模型.

Trees must use the Nature/Soft Occlusion Leaves and Nature/Soft Occlusion Bark shader. In order to use those shaders you also have to place the tree in a special folder that contains the name "Ambient-Occlusion". When you place a model in that folder and reimport it, Unity will calculate soft ambient occlusion specialized for trees. The "Nature/Soft Occlusion" shaders need this information. If you don't follow the naming conventions the tree will look weird with completely black parts.

树需要使用Nature/Soft Occlusion Leaves和Nature/Soft Occlusion Bark shader 这两个效果.把树的整个文件夹放到Trees Ambient-Occlusion夹内.在Unity 项目面板里找到自定义树的FBX文件,在属性面板可以看到shader 选取项.在下拉菜单为树干选取Nature/Soft Occlusion Bark 效果.为树叶选取Nature/Soft Occlusion Leaves 效果. 从官方网站上可以下载到Terrain Demo.unitypackage, 这个资源包里有不少树,可以商用.如果真的需要自定义树模型,最好也好好看看官方的树是怎么建模,明白之后再进行建模.

Unity also ships with several high quality trees in the "Terrain Demo.unitypackage". You can use those trees readily in your game. Even if you don't want to use the builtin trees, we strongly recommend that you take a look at those trees as an example on how to model trees.

Using Low Poly Trees 低模树创建

One branch with leaves is done with only six triangles and shows quite a bit of curvature. You can add more triangles for even more curvature. But the main point is: When making trees, work with triangles not with quads. If you use quads you basically need twice as many triangles to get the same curvature on branches. 一个树叉用六个三面效果还不错,如果要更好,可以增加三角面.重点就是需三角而不是四角来创建模型.如果用四角,可以把它分成两个三角面.,

The tree itself wastes a lot of fillrate by having large polygons but almost everything is invisible due to the alpha. This should be avoided for performance reasons and of course because the goal is to make dense trees. This is one of the things that makes Oblivion's trees look great. They are so dense you cant even see through the leaves. 树的模型如有大多边形时,因透明通道的原因.会很浪费内存,同时会导致不可见.这是必须避免的,以提高性能.更重要的是,我们的目标是通过三角面做茂密的树.茂密得可以我们的眼睛都没法穿透它.

Setting up Tree Collisions设置树的碰撞.

If you'd like your trees to make use of colliders, it's very easy. When you've imported your Tree asset file, all you need to do is instantiate it in the Scene View, add a Capsule Collider and tweak it, and make the GameObject into a new Prefab. Then when you're adding trees to your Terrain, you add the tree Prefab with the Capsule Collider attached. You can only use Capsule Colliders when adding collisions with trees. 设置树的碰撞是件很简单的事情.只需要把树拖入场景,加上Capsule Collider这个碰撞,再做成预制就可

以了.在加树的时候选取这个预制就OK.

Grass 画草工具

The Paint Foliage button allows you to paint grass, rocks, or other decorations around the Terrain. To paint grass, choose Edit Details button->Add Grass Texture. You don't need to create a mesh for grass, just a texture. 如上图就是画草的工具.当然它还可以画石头,或其他可以作为地形装饰的东西.同样,需要先加草的贴图之后才能画.以下是它的参数.

The Add Grass Texture dialog

At this dialog, you can fine-tune the appearance of the grass with the following options:

Detail Texture The texture to be used for the grass.草的贴图

Min Width Minimum width of each grass section in meters.以米为单位,草的最小宽度

Max Width Maximum width of each grass section in meters. 以米为单位,草的最大宽度

Min Height Minimum height of each grass section in meters. 以米为单位,草的最小高度

Max Height Maximum height of each grass section in meters. 以米为单位,草的最大高度Noise Spread The size of noise-generated clusters of grass. Lower numbers mean less noise .

树叶变黄生成器的大小,数值越小,变黄范围越小.

Healthy Color Color of healthy grass, prominent in the center of Noise Spread clusters.

健康叶的颜色.树叶中心的颜色

Dry Color Color of dry grass, prominent on the outer edges of Noise Spread clusters.

树叶干枯的颜色.树叶变黄外围的颜色

Grayscale Lighting If enabled, grass textures will not be tinted by any colored light shining on the Terrain.灯光灰度.如果设置为可用,树叶会以灰度图渲染.

Lightmap Factor How much the grass will be influenced by the Lightmap. Lightmap的影响范围Billboard If checked, this grass will always rotate to face the main Camera.

如可用,草会总以主摄像机为中心旋转

After you've clicked the Add button, you'll see the grass appear selectable in the Inspector.

The added grass appears in the Inspector

上图为在属性面板上加入草贴图后的效果

Painting Grass 画草.方法和上面的工具一样.就不多言了.同样记得F键和Alt键.

Painting grass works the same as painting textures or trees. Select the grass you want to paint, and paint right onto the Terrain in the Scene View

Painting grass is easy as pie

Note:When you have a brush selected, move your mouse over the Terrain in the Scene View and press F. This will center the Scene View over the mouse pointer position and automatically zoom in to the Brush Size distance. This is the quickest & easiest way to navigate around your Terrain while creating it.

Editing Grass 草的编辑和树的一样.对比下图.修改参数最小/最大高/宽度来让它来点变化

To change any import parameters for a particular Grass Texture, select it choose Edit Details

button->Edit. You can also double-click it. You will then see the Edit Grass dialog appear, and be able to adjust the parameters described above.

You'll find that changing a few parameters can make a world of difference. Even changing the Max/Min Width and Height parameters can vastly change the way the grass looks, even with the same number of grass objects painted on the Terrain.

Grass created with the default parameters默认参数下的草

The same number of painted grass objects, now wider and taller 修改宽度和高度的效果

Detail Meshes 细节网格

相关主题