2014-08-11 20:15:20|?次阅读|上传:huigezrx【已有?条评论】发表评论

关键词:游戏, 虚拟现实, Unity3D|来源:唯设编程网


Reference Manual > Terrain Engine Guide > 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.

Unity的地形引擎有特别为树的支持。You can put thousands of trees onto a Terrain, and render them in-game with a practical frame rate.你可以在一个地形上放置数千棵树,并用一个实际的帧速渲染它们。在一个全3D的摄像机附近进行树的重绘工作,并且把远的树变换成2D揭示牌。在远处的揭示牌它们自己将自动更正到恰当的方向以符合它们从不同的角度展示。这个变换系统处理一个元件树环境是非常简单特性。 你可以完全控制网格的参数到揭示牌的转换,以便你达到你需要的最佳性能。

Unity3D基础教程2-7:地形引擎指南(Terrain Engine Guide)
You can easily paint lots of trees for beautiful environments like this 你可以轻松的绘制出像这个美丽的多树环境。

Adding Trees 添加树

Select the Place Trees button Unity3D基础教程2-7:地形引擎指南(Terrain Engine Guide)in the Inspector.

在检视面板选择Place Trees(种树)按钮

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.

在你的地形上种树之前,你必须添加它们到可以使用的树木库。为此,点击 Edit Trees button->Add Tree(编辑树木按钮->添加树)。你将看到添加树木的对话框显示。

Unity3D基础教程2-7:地形引擎指南(Terrain Engine Guide)
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.

从你的项目面板视图中选择树木,然后拖拽它到这个树变量。如果你想增加额外的“风中的弯曲效应”效果动画给这些树木,你可以编辑Bend Factor(弯曲因子)。当你准备好,点击 添加 按钮,这个选定的树木将在检视面板中显示。

Unity3D基础教程2-7:地形引擎指南(Terrain Engine Guide)
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.


Unity3D基础教程2-7:地形引擎指南(Terrain Engine Guide)
The currently selected tree will always be highlighted in blue  当前选定的树总是以蓝色突出显示

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.


Unity3D基础教程2-7:地形引擎指南(Terrain Engine Guide)
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 树绘制技巧

Unity3D基础教程2-7:地形引擎指南(Terrain Engine Guide)
Different Brush sizes cover different area sizes 不同的画刷大小覆盖不同区域的大小

Unity3D基础教程2-7:地形引擎指南(Terrain Engine Guide)
Adjust Tree Spacing to change the density of the trees you're painting 在你绘制时,调整树间距改变树木的密度

Editing Trees 编辑树

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.

为添加树木更改任何重要的参数,选取元件并选择Edit Trees button->Edit Detail.(编辑树木按钮 ->编辑元件)。或双击你想要编辑的树。你将看到编辑树对话框,然后,你可以任意更改设置。

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(地形->大规模种树).


Unity3D基础教程2-7:地形引擎指南(Terrain Engine Guide)
10,000 Trees placed at once   10000棵树木立即种植

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.


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.

树必须使用自然/软闭塞树叶自然/软闭塞树皮着色。为使用这些着色器,你也必须同样在一个指定的文件夹名称中含"Ambient-Occlusion"的文件夹中放置树。当你放置一个模型在那个文件夹中并重新引入它,Unity将计算软环境闭塞专有的树木,这个"Nature/Soft Occlusion"(自然/软闭塞)着色器需要这个信息。如果你不遵循这个命名约定,这个树看起来是完全怪异的黑色。

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.

Unity也附带了几个高品质的树木在"Terrain Demo.unitypackage"中。你可以在你的游戏里容易的使用这些树。即使你不想使用内置的树,但我们强烈的建议你把这些树作为模型例子看看。

Using Low Poly Trees 使用低聚树

Unity3D基础教程2-7:地形引擎指南(Terrain Engine Guide)

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.

树本身损耗庞大的供应速率由巨大的无形阿尔法大量填充率的多边形提供。这应该是性能避免的原因,当然,目标为茂密树林也是其原因。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 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和调整它,使它成为一个新的预制游戏物体。然后,当你添加树木到你的地形时,你添加带有附着Capsule Collider预制的树。你也可以在添加带有碰撞的树时单独使用Capsule Colliders。

发表评论0条 】