求生之路2关卡设计/VMF 实例

来自Valve Developer Community
跳转至: 导航搜索
English (en)中文 (zh)
编辑

本简体中文界面由大康翻译。最后更新于2021年8月27日。本页面部分内容由机器翻译。(早期翻译作品可能不太好,请见谅)


VMF 地图实例是用于地图编辑的简单但功能强大的新工具。基本上,它们使你可以将一个 .VMF 引用到另一个。对文件的任何更改都将反映在所有实例中。

好处

预制的 .VMF 文件

需要重复放置的地图数据可以方便地作为实例保存和编辑。这与预制文件的工作原理类似。基本上,你要一起工作的实体收集至一个文件中,然后将该文件引用到地图中的任意多个位置。每个实例都有自己的“name fixup”(名称修正),因此当文件被引用到另一个地图中时,所有的逻辑仍然有效。《教区》战役中的警报车停车场就是这样做的。另外,《暴风骤雨》 中的城镇也被引用到地图的前后版本版本中,从而使单个更改都可以反映在这两个版本中。

分割

实例还可以用于将大型笨拙的地图分为几个较小的、更易于管理的 VMF 文件。当多个地图作者同时在一张地图上工作时,这也简化了工作流程。

脱离网格工作

如果地图的一部分需要成非正交的角度,你可以将其保留在的单独文件的网格上。如果随后你将文件实例化至主地图中,然后旋转该实例,则可以继续享受在网格上为每个文件进行编辑的好处。

将一个地图升级至《求生之路2》

如果你要升级一个《求生之路》地图以便与《求生之路2》一起运行,并且同时与《求生之路》保持兼容,则实例是最好的选择。你可以保持一个新版本,但是由于需要在两个地方进行常见的修复或更改,因此该“分支”可能会变得难以支持。或者,你可以简单地将新内容添加到“L4D2”可见组中,但是这种方法的可伸缩性不是很高。这很容易出错,丝毫的复杂性会使它变得笨拙。
相反,你现在可以将公共资产保留在一个与 L4D1 兼容的文件中,将 L4D2 的“增量”保留在另一个文件中。要进行设置,你将需要创建一个新的 L4D2 VMF 文件地图,然后将一个实例实体引用其中的现有 L4D1 地图,从而在每次编译之前自动导入旧地图的内容。只需将新的仅L4D2实体添加到L4D2 的VMF文件,就可以从一组非重复的源数据中为两个游戏提供一个地图版本。这样做的好处是,你在较旧的 L4D1 地图中进行的任何更新都会自动反映在新的 L4D2 VMF 版本中。
让我们使用入门教程之一的实例进行操作。

添加一个新实例

首先,从 Hammer 中创建一个新地图:

  1. 从菜单上点击选项卡 File
  2. 点击 New

另存为:

sdk_content\mapsrc\Your_First_L4D_Level_Tutorial\tutorial07.vmf

我们将引用同一文件夹中的另一个文件,因此将其保存在正确的位置很重要。
接下来,我们需要放置一个称为“func_instance”的实体,该实体将表示你希望引用的地图数据。
点击实体工具Entity tool Mt-entities.png,然后从 Hammer 窗口右侧的“对象”下拉菜单中选择“func_instance”。

将 func_instance 放在世界中心点

L4D2 instance 1place3.png


左键单击在顶部(右上)视口中深青色线相交的位置,将其放置在世界中心点(坐标0、0、0)。你可以从状态栏的右侧验证其位置。

由于它是一个点实体,因此你可以将 func_instance 放置在任何位置,但是将其放置在世界中心点且没有旋转的情况下,你可以非常精确地在基础地图和实例之间剪切然后粘贴特殊对象。在地图之间进行紧密协调时,这非常方便,你会发现自己在做很多事情。

接下来,使用箭头选择工具选择 func_instance 并通过按 Alt + Enter 打开其属性。


单击 VMF Filename 字段,然后单击 Browse... 按钮。继续并在同一文件夹中选择完成的教程文件之一:

sdk_content\mapsrc\Your_First_L4D_Level_Tutorial\tutorial05_complete.vmf


L4D2 instance 2properties.png

如果没有出现该名称,请确保你正在编辑的 VMF 文件保存到同一文件夹中。你也可以尝试手动输入文件名。

Note.png注意:实例必须引用与主文件位于同一文件夹或子文件夹中的VMF文件。路径总是相对的。
Note.png注意:多个文件使用的实例通常放置在名为“instance”的子文件夹中,以避免混淆。
加载了 VMF 内容的实例

现在,“tutorial05”的内容已在新地图中引用,并用淡黄色橙色表示以将引用的内容与当前打开的 VMF 文件中的其他内容区分开。

即使当前打开的 VMF 文件从技术上讲仅包含一个 func_instance 实体,当你编译地图时,所有实例都会被暂时“展平”并包含在地图中。它们出现在最终的 BSP 文件中,就像它们已经在地图本身中一样。

尽管现在你需要两个 VMF 源文件来创建关卡,但是你可以为自己提供更大的编辑灵活性,因为你可以将内容保存在单独的存储桶(separate buckets)中。正如我们将在接下来的几篇教程中看到的那样,当你添加对多种游戏模式的支持或执行其他使你的地图更加复杂的事情时,这将变得非常方便。

修正名称和查看选项

再次查看属性对话框。

将文本放在 Fix Up Name(修复名称)字段中,可以为可命名实体指定前缀或后缀。如果你要让多个 func_instances 在分别定位实体的同时引用同一文件,这将非常方便。实际上,如果你未指定修正名称,则会自动提供一个修正名称,从而使你可以放置​​多个实例,同时仍然能够单独触发内部实体。

在本教程中,让我们将修复程序保留为空白,但是在 Deadline2 附加组件的警报车示例中可以找到一个很好的示例。

Tip.png提示:你可以从 Hammer 的 Instancing 菜单中切换实例的色调和整体可见性。现在将其保留为默认设置,因为我们很快将混合实例对象和非实例对象。

编辑

编辑实例

继续并选择实例化的几何图形,然后再次打开属性窗口。

在底部,你会注意到一个名为 Edit Instance(编辑实例)的按钮。

这将打开实例 VMF 文件进行编辑(如果尚未编辑),同时在两个文件之间保持完全相同的相对摄像机坐标。你进行的任何更改都会在你在新地图中切换时反映出来。

但是,出于我们的目的,我们希望“升级”旧版地图,并希望保留新文件中的更改,同时避免尽可能多地编辑实例。我们稍后会再次谈到这一点,尤其是在遍历多个游戏模式支持实体 info_gamemode 时。让我们继续进行 L4D2 特有的武器生成实体。


VMF map instances are a simple yet powerful new tool for map editing. Basically, they let you reference one .VMF into another. Any changes to the file will be reflected in all instances.

Benefits

.VMF Prefabs

Map data that will need to be placed repeatedly in your maps are convenient to save and edit as instances. This is similar to how Prefabs work. Basically, you collect entities that are meant to work together into a file, then reference that file into your map in as many locations as you like. Each instance gets it own "name fixup", so all logic still works when the file is referenced into another map. This is how the alarmed car lot in The Parish is set up. Also the town in Hard Rain is referenced into the forward and back version of map, allowing a single change to be reflected in both.

Sectioning

Instances may also be used to divide a large, unwieldy map into several smaller, easier to manage .VMFs. This also simplifies workflow when multiple authors are working on a single map simultaneously.

Working off grid

If you have a portion of a map that needs to be at a non-orthogonal angle, you can keep it on-grid inside a separate file. If you then instance the file into your main map, then rotate the instance, you can continue to enjoy the benefits of on editing on the grid for each file.

Updating a map for L4D2

If you have a L4D map that you'd like to update to run with L4D2 while maintaining a version that is compatible with L4D1, instances are the best way to go. You could save out a new version, but this "fork" can become a hassle to support, as common fixes or changes need to happen in two places. Alternatively, you could simply add the new content into a "L4D2" visgroup, but that approach isn't very scalable. It's error-prone, and the slightest bit of complexity can make it unwieldy.

Instead, you can now keep the common assets in one file that remains compatible with L4D1, and the "delta" for L4D2 in another file. To set this up, you will need to create a new L4D2 .VMF map, then place an instance entity that will reference the existing L4D1 map into it, thereby automatically importing the contents of the older map before each compile. Simply add your new L4D2-only entities to the L4D2 .VMF, and you can provide a version of your map for both games from a non-duplicated set of source data. The nice thing about this is that any updates you make in the older L4D1 map are automatically reflected in the new L4D2 version of the .VMF.

Let's run through using instances with one of the beginning tutorial levels.

Adding a new Instance

To start, go ahead and create a new level in Hammer from the menu: File > New

Save it as:

sdk_content\mapsrc\Your_First_L4D_Level_Tutorial\tutorial07.vmf

We will be referencing another file in the same folder, so it's important to keep it in the correct place.

Next, we need to place an entity called a func_instance that will represent the map data you wish to reference.

Go into the Entity tool Mt-entities.png and select "func_instance" from the Objects drop-down menu on the right hand side of the Hammer window.

Placing a func_instance at the origin

L4D2 instance 1place3.png


Place it at the origin (coordinates 0,0,0) by left-clicking where the dark cyan lines intersect in the Top (upper right) viewport. You can verify it's position from the right side of the status bar.

Since it's a point entity, you can place a func_instance anywhere, but placing it at the origin and with no rotation allows you to Cut and then Paste Special objects between the base map and instance very accurately. This is very handy when tightly coordinating between maps, which you'll find yourself doing a lot.

Next, select the func_instance with the arrow selection tool and open its properties by pressing Alt+ Enter.


Click on the VMF Filename field and click the Browse... button. Go ahead and select one of the finished tutorial files in the same folder:

sdk_content\mapsrc\Your_First_L4D_Level_Tutorial\tutorial05_complete.vmf


L4D2 instance 2properties.png

If the name doesn't appear, make sure the .VMF you're editing is saved to the same folder. You can also try typing in the filename manually.

Note.png注意: Instances must refer to VMF files that are either in the same folder as the main file or in a sub-folder. Paths are always relative.
Note.png注意: Instances that are used by multiple files are usually placed in a sub-folder named "instance" to avoid confusion.
Instance with .VMF content loaded

The contents of tutorial05 are now referenced into your new map, and are tinted in yellowish-orange to distinguish the referenced content from other content that may be in the currently open .VMF.

Even though the currently open .VMF technically only contains one entity, the func_instance, when you compile your map, all instances will be temporarily "flattened" and included in your map. They appear in the final .BSP just as if they had been in the map itself.

Although you now need two VMF source files to create your level, you've provided yourself with much greater editing flexibility, as you can keep content in separate buckets. As we shall see in the next several tutorials, this will become very handy as you add support for multiple gamemodes or do other things that make your maps more complex.

Fixup naming and viewing options

Take a look at the Properties dialog again.

Putting text in the Fix Up Name field allows you to specify a prefix or suffix to nameable entities. This is very handy if you want to have multiple func_instances referencing the same file while targeting the entities separately. In fact, if you do not specify a fixup name, one will be provided automatically, thus allowing you to place multiple instances while still being able to trigger the entities inside individually.

Let's keep the fix up blank for the purposes of this tutorial but a good example can be found in the car alarm lot example in the Deadline2 add-on.

Tip.png提示:You can toggle the tint as well as the overall visibility of instances from the Hammer Instancing menu. Let's keep it on the default setting for now since we will soon be mixing instanced and non-instanced objects.

Editing

Edit instance

Go ahead and select the instanced geometry and open the properties window again.

Along the bottom, you'll notice a button titled Edit Instance.

This will open the instance .VMF for editing if it isn't already while maintaining the exact same relative camera coordinates between the two files. Any changes you make will be reflected in the new map as you switch between them.

For our purposes, though, we want to "upgrade" a legacy map, and will want to keep out changes in the new file while avoiding editing the instance as much as possible. We'll touch on this again later, in particular when going over the multiple gamemode support entity info_gamemode. Let's move on to the L4D2-specific weapon spawning entities.