前言
好吧,这次总结的还是UE4,在这里要向CE3的朋友们道一声歉,因为本人水品有限,对于CE3的探索学习陷入了一个非常大的瓶颈,暂时抽不出一块儿大的单独的时间去解决,另外,自己也有一点小小的私念,就是期盼Cryteck官方能够推出新的版本,至少能完善一下现在的文档,所以只能暂时把CE3搁置下来,但是我并不会放弃CE3,CE3对我来说,绝对是个非常大的挑战,我不会轻易放弃他的。
好了回归正题,先来简单说一下写这篇文章的背景吧,这两天我试着看了一下UE4官方提供的实例“2014功能介绍”,在里面发现一个疑惑,在GDC_Demo这个场景的关卡蓝图部分,发现了一个没听说的玩意儿----“子蓝图”,这个实例中,有三个地图,感觉像是嵌套在了一起组成了一个大地图,于是带着这样的疑惑,就去群里问了一下,得到了“LevelStream”的信息,再然后,就去官方文档搜索,发现有专门这么一部分,于是,这篇文章便应运而生了!好吧,先从对官方文档的翻译总结说起!
LevelStream 实现超大无缝地图--官方文档学习
The Level Streaming feature makes it possible to load and unload map files into memory as well as toggle their visibility all during play. This makes it possible to have worlds broken up into smaller chunks so that only the relevant parts of the world are taking up resources and being rendered at any point. If done properly, this allows for the creation of very large, seamless levels that can make the player feel as if they are playing within a world that dwarfs them in size.
关卡流(LevelStreaming)使得我们在游戏运行的整个过程中动态的加载、卸载地图,这样以来,使得通过“把大地图分成许多小的部分,只有与当前状态有关的地图部分资源加载”的思路来创建无缝超大地图成为了可能。
World Composition User Guide 世界组合使用指南
- Overview概述
- Activating World Composition 激活世界组合功能
- Levels Hierarchy 关卡层级关系
- Levels Composition关卡组合
- Layers层
- Minimap小地图
- UI KeyUI交互与提示
- Level Details层详细信息
- Tile Settings瓦片设置
- LOD SettingsLOD设置
- World Origin Shifting 世界原点
- Big Worlds and Multiplayer 超大世界和多玩家
- Creating Landscape Levels 创建地形关卡
- Tiled Landscape Import 导入瓦片地形
World Composition has been designed to simplify managing large worlds. One of the goals is to avoid using a persistent level to store streaming information as it becomes a bottleneck when a team of level designers want to work on levels simultaneously. The persistent level does not store any streaming information and instead scans a folder and treats all found levels as streaming levels. Each streaming level has information stored in the package header, which World Composition can read without loading the level into memory. Initially, all levels except the persistent level are unloaded in World Composition. You can load or unload any part of the world manually at any time.
World Composition relies on a world origin shifting feature which, when used with distance based level streaming, allows you to create worlds which are not limited to the WORLD_MAX
constant value hard-coded into the engine.
WORLD_MAX
constant这个常量。
Activating World Composition 激活“世界组合”功能
World Composition managed worlds can be activated by switching on Enable World Composition flag in World Settings.
You can also disable world origin shifting by switching off Enable World Origin Rebasing flag in World Settings.
被”世界组合“(World Composition)管理的世界可以通过勾选在世界设置中的Enable World Composition布尔值。
当然你也可以通过不勾选世界设置中的Enable World Origin Rebasing 布尔值来不使用世界原始转移特性。
Levels Hierarchy 关卡的层次
After you have activated World Composition, all the levels in your project will be visible in the Levels window. To open this window, click on theWindows menu, and then select Levels.
The entries in the Levels window represent your world hierarchy.
当你激活了世界组合的命令后,你可以在关卡面板(英文:Level)中看到你项目中的所有关卡。关卡面板可以这样打开
在关卡窗口的条目代表你的世界的层次结构。
The level with its name in blue text is the current level. Currently loaded levels will have their names in white text, while levels that are unloaded have grayed-out names.
To load a level in the world composition, just double-click its name. Using drag-and-drop, you can establish relationships between individual levels. Child levels store position relative to the parent level, so when you change the parent level's position all child levels will recalculate their position accordingly.
In the Levels window, you can lock and save levels, as well as open the Level Blueprint for each level, with buttons to the right of the level name.
窗口中名字为蓝色的关卡是当前的关卡,当前加载的关卡(如图中:SmallMap1)的名字为白色,卸载了的关卡(图中:SmallMap2)的名字为灰色。
只需要通过在窗口中双击关卡的名字你就可以把它加载到世界组合( world composition)中,加载完成后你可以观察一下关卡名字的颜色变化哦!可以通过拖拽的形式来建立关卡之间的父子关系。这里注意,子关卡存储的是相对位置!即相对于父关卡的位置,所以一旦你改变了父关卡的位置时,对应的所有子关卡的位置也会因此发生改变。
在关卡窗口中,你可以锁定或者保存关卡,也可以直接打开每一个关卡的关卡蓝图。
这里注意一下吧,一旦加载了一个地图后,可以观察到永久性关卡有许多属性发生了变化:
Levels Composition 关卡组合:
When Enable World Composition is on, there is a button to open World Composition at the top of the Levels window.
当勾选了Enable World Composition时,可以通过下面这个按钮来打开世界组合窗口
Here, you can see the layout of your world.
在这里,你可以看到你的世界的布局
Layers 层
By default, all levels are assigned to an Uncategorized layer. Layers hold information about streaming distances, so levels assigned to a particular layer will inherit that streaming distance. Levels assigned to a layer with streaming distance disabled will be excluded from distance streaming, and can instead be controlled using Blueprints.
You can create new layers by clicking the + button to the right of the existing layer names. Each level can only be assigned to one layer at a time.
Layers can not be deleted or edited, so if you would like to change streaming distance settings, create a new layer with your desired settings and assign levels to it. Layers which have no assigned levels will be deleted automatically the next time you open a level.
You can filter your levels by layer by clicking on the layer name above the minimap. You can toggle multiple layers by using Control+Mouse Click. When there are no layers toggled on, no filtering is performed.
默认情况下,所有的关卡被分配到 未分类 (Uncategorized )这一层。各个层都保存了关卡流的距离信息 ,所以被分配到一个特定的层的关卡会继承这个关卡流的距离信息。 分配层 的流媒体 远程 禁用 将被排除在 距离 流 水平 , 并可 控制 使用的蓝图 。被分派到一个禁用了关卡流距离的层中将会排除掉关卡流距离的影响,并且可以被蓝图所控制。
可以通过点击已经存在的层的名字右边的+按钮来创建新的层,记住,每一个关卡同一时刻只能被指定到一个层。
特别注意!层不能被删除或编辑的,所以如果你想改变关卡流的距离设置,用你需要的设计来创建一个新的层,并且给它分配对应的关卡。没有指定关卡的层将会在你下一次你打开关卡的时候被自动删除。
你可以通过层来过滤关卡,方法是在小地图上单击层的名字。您可以通过Ctrl+Mouse单击切换多个层。当没有层打开的时候,不会存在过滤。
Minimap 小地图
Each level except the persistent level has an image and position in the world, which are displayed in the minimap. The image of the level is updated every time content in the level is changed. This map allows you to preview your world from the top and arrange the position of levels by dragging them. When dragging levels, they will snap to the edges of other levels. Holding the Control key will cause the level movement to use the Level Editor's snapping settings. Note that level position is stored as integer coordinates, so for exact matching of adjacent level tiles, your levels must have integer bounds sizes.
除了永久的关卡,其他所有的关卡都会在小地图中有一个图片和一个在世界中的位置。当关卡里面的内容发生改变时关卡的这张图片也会更新。小地图允许你在顶视图预览你的世界,并且通过拖拽各个关卡来设定他们的位置。当拖动关卡的时候,他们将会捕捉在其他关卡的边缘。按住Control键会使得水平运动时使用关卡编辑器的捕捉设置功能。注意关卡位置存储为整数坐标,所以当需要精确的调整关卡瓦片(瓦片地图)位置的时候,你的关卡必须有整数范围大小。
Levels based on Landscape Actors have snapping based on the base landscape component size. This is done to enable seamless editing between Landscape Actors in different levels.
基于 Landscape Actors 地形物体的关卡的边缘是基于父类landscape 地形组件的尺寸的。这样做是为了在不同Landscape Actors地形物体不层次间无缝启用编辑。
All Landscape Actors will have tranformations disabled in the Editor Viewport to ensure that the landscape can not be moved by an arbitrary amount and lose its ability to be aligned with other landscape levels.
所有的Landscape Actors地形物体都可以在编辑器试图中禁用transform的属性,来确保l地形andscape 不能通过任意量来移动并且也不能被和其他关卡中的地形landscape 对齐。
The first time a level is loaded in World Composition, a new Level Bounds Actor is automatically created in the level. The Level Bounds Actor is used to calculate the size of the level.
By default, the Level Bounds Actor automatically resizes to include all Actors found in the level. However, some Actors, like skyboxes, can have very large bounding boxes, which will result in overly large level tiles in the world minimap. If you have Actors like this that you do not want to include in the level bounds calculations, you can disable automatic level bounds calculations and set a fixed size for the Level Bounds Actor.
一个关卡在第一次被加载到世界组合World Composition时,一个新的叫做关卡边界(Level Bounds Actor)的物体 将会被自动在这个关卡中创建。 关卡边界物体(Level Bounds Actor) 物体是用来计算关卡的大小的,可以在世界大纲试图中搜索找到他!
默认情况下,关卡边界物体会自动调整当前关卡中的所有物体的大小。然而,一些物体,比如天空盒,可以有一个非常大的边界盒子,这将导致在世界地图中存在过大的瓦片关卡。如果你有一些这样的不想要被关卡边界计算的物体,你可以禁止自动关卡边界计算并且给关卡边界物体设置一个固定大小的值。
Currently, realtime must be enabled in the viewports for the Level Bounds Actor to function.
目前来说,realtime 必须在视图中启用 Level Bounds Actor这样才会起到作用。
The minimap has a yellow square indicating the safe edit area. The safe edit area's size is equal to the WORLD_MAX
contant in the engine. Levels outside of this area will be hidden automatically, and their level images will reflect this. World Composition tries to keep levels you are working on close to the Editor world origin. This feature is called "focusing" and may shift the current world origin to a new position if you begin editing a level outside of the safe edit area. Shifted levels still preserve their Actors' original transformations when they are saved, so saving a level that is currently shifted will not change the Actors' absolute positions.
UI Key UI的值
Number 数字 | Status Bar 状态栏 | Description 描述 |
---|---|---|
1 | Layers 层 | Click on a layer name to toggle filtering by that layer, or click on the + to create a new layer. 点击层名字可以切换层,+号新建一个层 |
2 | WORLD_MAX | Bar indicating the scale of the WORLD_MAX constant.显示 WORLD_MAX 常亮的值 |
3 | World Origin 世界原点 | Current position of the world origin. 当前世界的原点坐标 |
4 | Current Level 当前的层 | Name of the current level. 当前层的名字 |
5 | Mouse Cursor Position 鼠标指针的位置 | Current world position of the mouse cursor. 当前鼠标指针所在的世界位置 |
6 | Marquee Selection 选框 | Size of the marquee selection box in the world units. 在世界单元的选框的大小 |
7 | World Size 世界的大小 | Size of the world, calculated as the sum of all level bounding boxes. 世界的大小,这个值时所有关卡中绑定的盒子大小的总数 |
Level Details
To see the details for any level in the Level window, select it and then click on the magnifying glass icon in the toolbar. This will summon theLevel Details window, where you can also swap between available levels' information with a dropdown menu.
如果想要查看关卡窗口里面任意关卡的详细信息,选择他,点击就行了。注意,这里还有一个小技巧,就是可以在关卡详细信息窗口中可以切换到其他关卡,点击上面那个下拉框即可。
Tile Settings 瓦片设置
Setting 设置 | Description 描述 |
---|---|
Package Name 包的名字 | Package name of the selected level. This information is read-only. 当前选择的关卡的包的名字,这里的信息是只读的。 |
Parent Package Name 父包的名字 | Package name of the parent level. If the level has specified a parent, its position becomes relative to the parent level. 父类包名,如果当前关卡有一个指定的父类,他的位置就会变成与父类的相对位置 |
Position 位置 | Level offset from the zero world origin, stored as an integer 2D vector. All Actors in the level will be shifted by this value when the level is added to the world (becomes visible), and shifted back when the level is removed from the world (hidden). 关卡相对于世界原点0的偏移量,使用一个2维数组存储的。关卡中所有的物体将会通过这个值移动,当关卡被加载到世界中,当关卡被卸载时,会回到原来的位置。 |
Absolute Position 绝对位置 | Absolute position of the level. This is the same as Position when the level has no parent. This information is read-only. 关卡的绝对位置。当关卡没有父物体的时候,他和Position时一样的,这个值也是只读的。 |
Z Order Z方向上的顺序 | Defines Z sorting order of the level tile in the minimap. This can be useful when there are several overlapping tiles and you want to sort them in a specific order. 这个值定义了在小地图上瓦片关卡的顺序,当小地图中有很多关卡瓦片重叠的时候,把他们整理到一个正确的顺序是非常有用的。 |
LOD Settings 细节设置(Levels of Detail)
Each level in the world composition can have up to 4 LOD streaming levels. LOD streaming levels are similar to mesh LOD. Depending on streaming distance settings streaming level will be replaced with corresponding LOD level. LOD levels automatically discovered by World Composition using pattern _LOD#. Where number should be from 1 to 4. LOD levels can be created manually or with automatic LOD map generator which requires Simplygon.
世界组合中的每一个关卡都可以拥有最多4个LOD关卡流,LOD关卡流和普通的LOD网格很相似。根据流距离的设置关卡流将会被相应的LOD关卡所取代。LOD关卡会通过世界组合中使用的LOD# 来被查询到。
这个数值的取值范围时1--4.LOD关卡可以被手动创建,或者使用LOD地图生成器来自动创建,注意,后者需要Simplygon技术。
Unreal Engine 4 ships with a Simplygon integration, but you will need a license from Simplygon to use it.
虚幻四引擎整合了Simplygon ,但是如果你想要使用它的话,需要取得一个证书认证才可以
Setting 设置 | Description 描述 |
---|---|
Num LOD LOD数字 | Number of LOD levels for selected level. 代表选中关卡的LOD数字 |
LOD[1..4] 数字1--4 | |
Generate 生成 | Generates simplified version of an original level using Simplygon ProxyLOD feature to merge Static Mesh Actors found in the level into one simplified proxy mesh. Landscape Actors will be converted to Static Meshes using highest landscape LOD. In general, a level with landscape, an Actor, and a bunch of Static Mesh Actors will result in LOD level which contain 2 simplified Static Mesh Actors. This operation will overwrite previous LOD level if it exists on the disk. 通过使用 Simplygon ProxyLOD 混合关卡中所有的静态网格物体成为一个代表的物体,来生成一个简单版本的LOD。 使用高质量的LODlandscape会吧Landscape Actors转换为静态网格。一般来说,一个有地形、物体,和静态网格的关卡将会导致LOD关卡包含两个简单的静态网格物体。这个操作会被重写当磁盘上已经纯在它的时候。 |
Distance 距离 | Distance relative to original level streaming distance. For example, if original level has streaming distance = 1000, and LOD1 level has distance 1500, then LOD1 level will be visible at [1000..2500] range and original at [0..1000] range. |
Details percentage 细节百分比 | Percent of details to preserve when reducing original meshes. |
World Origin Shifting 世界原点的偏移
The World Composition editor supports shifting of the world origin by some arbitrary amount. Shifting the world origin results in adding an offset vector to all registered Actors in the world. Each Actor has an ApplyWorldOffset function which can be overridden in the child classes to do additional things. In case you have created a new AActor derived class and store absolute position values in it, you have to override ApplyWorldOffset function to make it work correctly with world origin changes and shift your absolute values in it. Rendering and physics primitives will be shifted in parallel to Actors in game thread.
世界组成编辑器支持移动世界原点到任意位置。移动世界原点将会导致在世界中注册的所有Actor物体添加一个偏移量。每一个Actor物体都有一个ApplyWorldOffset ()函数,当添加一些其他的事情时,他会被在子类里重载。如果你已经创建了一个新的AActor派生类并且存储了它的绝对位置值,你必须重写applyworldoffset函数,使它与世界的原点的改变正常的变化。渲染和物理元素将被转移在平行于游戏中的线程的一个Actor物体中。
Big Worlds and Multiplayer 超大地图和多玩家
Right now world origin shifting is not supported in the multiplayer games. Here are two solutions that can be implemented for your specific needs:
-
Implement your own server solution. MMO licensees mostly do this.
-
Implement some layer between clients and unreal dedicated servers which will transform shifted absolute positions from the clients and route them to the right dedicated server, which only holds part of the world where client is.
However if you disable world origin, shifting you can run a tiled world with a dedicated server. Dedicated servers will load all distance dependent levels, and each connected client will work as usual loading only level that satisfy streaming distance settings. A server holds a list of visible levels for each client and filters Actor replication by this list.
目前为止,世界的原点偏移将不在多人游戏中支持。但是这里有两个解决方案,可以实现为您的特定需求:
-
实现你自己的服务器解决方案。网络游戏授权大多做这个。
-
实现客户和虚幻的专用服务器,将转移的绝对位置从客户和路由到正确的服务器之间的一些层,只能装的世界里,客户端部分。
Creating Landscape Levels 创建地形关卡
Right-clicking on a level tile, to summon the context menu, which has a Landscape Actor inside will bring an options for adding adjacent levels with landscape proxy Actors in them. This requires the adjacent levels landscapes have size equal to source Landscape size.
右键一个关卡瓦片,召唤一个有着Landscape Actor 地形物体的上下文菜单,将会给你提供一个增添相邻的关卡的选项并在其中有一个代表性的actor物体。这需要相邻的关卡地形的大小一致。
Tiled Landscape Import 瓦片地形的载入
In the Levels panel toolbar you can find an option for importing tiled landscape. Tiled landscapes are created from a tiled heightmap, where each heightmap tile will represent a level with a landscape Actor in it. Tiled heightmaps/weightmaps can be exported from an application like World Machine. Adjacent heightmaps tiles should share border vertices ("Share edge vertices" in World Machine). And, each tile resolution should follow the recommendations from this page Creating Landscapes.
在关卡工具栏中,你可以找到一个载入瓦片地形的选项。瓦片地形从一个瓦片高度图中创建,每一个高度图瓦片将会代表一个有地形的关卡。瓦片地形高度图可以被一些其他的工具到处,比如worldmachine。相邻的瓦片高度图应该分享边界最高点(在worldmachine中叫做”"Share edge vertices"“), 并且每一个瓦片地图高度图的分辨率最好和这一章节创建地形Creating Landscapes.匹配。
Setting 设置 | Description 描述 |
---|---|
Select Heightmap Tiles... 选择高度图 | Allows you to select multiple heightmap tiles you want to import. 允许你导入多张瓦片地性高度图 |
Tile Coordinates Offset 瓦片坐标的偏移 | Offset in tiles from origin. If set to zero tile wih coordinates x0_y0 will be created at world origin. 对比原点,瓦片的偏移量。如果设置为零将会被在世界原点出创建 |
Import Configuration 导入选项 | Generates all possible landscape configurations depending on resolution of selected tiles. 生成所有可能的地形选项 ,这主要是由选择的瓦片高度图的分辨率决定的 |
Landscape Scale 地形大小 | How much to scale the tiled landscape by. 瓦片地形的大小 |
Material 材质 | Material to use. When a material has be chosen, you will be able to assign weightmap tiles for each landscape layer found in the material and how each layer is blended. 使用的材质。 |
总结
但是官方的实例GDC_Demo中的地图好像并不是这样,三个地图都没有选中世界组合的选项!
所以我认为,它用的不是上面提到的动态创建无缝地图的方式。
可是问题又出现了
在其中一个地图里,同样有着其他两个地图,而且也存在子蓝图的说法,那么问题来了,它又是怎么实现的呢?
我们可以简单的分析一下这个实例中给我们展示出来的一些细节
1.三个地图
1.中间这个是整个最终呈现出来的地图,它有三个大的部分吧,一部分展示了UE4的材质,这部分是在第三个地图里面完成的,中间一部分是展示UE4的蓝图,这部分是在第一个地图中实现的,剩下最后一部分展示一些可破坏的模型等等,就是在他本身是实现的。
2.我们以展示蓝图的那部分为例,下图是第二个地图中其中一个球的信息,我们重点关注他的transform属性
接下来,我们打开实现它的第一个地图,同样找到这个球
可见二者的坐标是完全一样的,那么似乎可以得出这么一个结论,就是这个实例中实现的这种地图嵌套的这种功能里,三个地图的原点是重合的。当然这只是我的推测,具体情况是怎么样,尚未可知,这部分内容属于UE4里面一些比较高级的部分了,所以一下子理解清楚也不可能。
经过我的初步分析,哈哈,它只是重复使用了地图场景,也就是说两个地图拼成了第三个地图,这个过程并不是上面所说的动态的。方法也和前面差不多,当然也简单了好多
怎么做呢?哈哈,打开一个场景,打开它的关卡窗口,首先,关卡窗口里是没有其他关卡的,这时候,只要把内容浏览器里面保存的任意关卡拖放进关卡窗口即可了
总结一下吧,其实本篇文章的起因是对于GDC_Demo中三个地图嵌套关系的疑惑,然后我去群里问了一下,得到了LevelStream的信息,于是就去官网的文档上搜索了关了LevelStream的知识,结果发现了官方文档专门有介绍这部分的内容,即如何动态创建无缝超大地图的知识,然后就....有了这篇文章的主题部分,然后当翻译完了这部分内容后,发现这并不是最初疑惑的解决方案,但是似乎要比翻译的内容简单一些。最后呢,就有了这里的总结了。
其实整个过程还是非常享受的,虽然对于这部分也仅限于了解有这么回事的层面上,但是至少对UE4关于地图的处理有了更新的一点点小认识。当然还有一点感触就是官方文档真的是个非常好的东西,里面有太多太多精华等着我们去挖掘了,所以如果时间允许,我会继续去里面探索探索,为大家总结的。
当然了,我要申明一下,因为作者水品有限,这部分内容从官方文档的翻译,到最后的总结,应该会有一些错误,这些错误可能源于自己的无知,也有可能是因为表达的问题,所以如果有大神了解这一块儿,还希望您能给出一些指点,当然如果大家愿意和我一起探讨这部分内容,自当恭敬不如从命,哈哈~
最后打一个小广告吧,鄙人很荣幸收到虚幻中国论坛的邀请,为大家总结更多的内容。使用过Unity引擎的童鞋肯定清楚小岛求生那个小DEMO,我已经把他转移到UE4上实现了,不久这套教程可能就会问世啦,其实整个功能非常简单,但是涉及了很多内容,算是从无到有完成一个小游戏的全过程吧,大概会包括以下内容:
1地形创建部分
--简单使用worldmachine到处地形网格、法线和普通贴图
--简单实用SpeedTree导出从网上下载好的树木资源到UE4中
--简单实用UE4的地形编辑工具,稍微处理以下地形
2.模型导入
--简单比较一下静态网格的导入和骨骼模型的导入
3.蓝图部分
--从无到有,用蓝图实现UE4自带的一些模板,以FPS,第三人称为例
--简单分析一下官方”蓝图“实例,学习蓝图的一些基本用法,比如蓝图类的实现,蓝图类之间的关系,碰撞检测,触发器等
--实现小岛的基本逻辑
-- 最后优化蓝图逻辑(考虑中)
4.材质部分(考虑中)
--简单为大家总结一下官方材质视频的简单部分
--使用蓝图动态创建、替换材质
5.角色动画
--第三人称的实现
--向场景中导入一些简单的动画
6.粒子系统(考虑中)
--创建引擎自带的火焰的特效
7.界面部分
--为小岛游戏做一个简单的界面,能实现一些简单的交互
8.音乐部分
--为整个demo添加音效
好吧,工程还是有些浩大,希望能赶在四月中旬虚幻教育上线时赶出来。就这样了,转载别忘注明