How to handle BSP geometry
BSP stands for Binary Space Partition. BSP allows you to quickly create and lay out surfaces such as floors, walls, and ceilings which are lined up with each other without having to worry about using any other software. BSP helps you in the design stage, and generally geometry made with BSP can later be replaced by more efficient, more detailed StaticMesh assets. But besides being a modeling tool, BSP can be used to do a lot more, like serve as triggers, lighting volumes, and collision. We'll look at how to generate BSP and how to convert it to a StaticMesh and to a Volume.
Getting ready
Open a Blank Map from the UDK templates. Make sure you follow these steps:
- Go to Viewport Options [ ] (which appears in the upper corner of each viewport) and choose Show | Use Defaults. If you ever hide scene elements accidentally and get lost, restore them by using Show | Use Defaults.
- In the main menu choose View | Viewport Configuration | 2x2 split.
- In the perspective viewport, choose Unlit mode [ ] or press Alt + 3. This is so when we add the BSP geometry it won't be so much in shadow we can't see it.
How to do it...
Getting to know the BSP geometry tools
- Along the side of the editor are light blue buttons representing some preset geometry. Almost always, a box is the best starting point for BSP. Pick the BSP cube brush [ ] from the brushes.
- Nothing much will change, because UDK levels always have a BSP cube at the world center when they open. However, if you right-click on that same icon you get options for changing the brush size. Set the brush size to something that will suffice for a floor, say 1024 x 1024 x 16. The XYZ values we set conform to powers of two, so it will mean the brush is easy to align on the grid.
- Now press the Close button. There's no need to press Build (in this dialog) as what this is for is moving the Builder Brush over to whatever object is selected in the scene, like an align.
- Before we start modeling, let's examine what the Builder Brush is. Edit the brush by pressing the Geometry Mode icon [ ] at the top of the buttons, above the brushes. It looks like a box wireframe, and this is because that's what it gives us access to. You can alternatively press Shift + 2.
- Having done so, click on the BSP brush in the Perspective view and notice how a surface is picked (it's shaded red) and the points at the corners are larger, so they are easy to pick. In the Perspective viewport, you will almost always just select a surface, not the entire brush.
- To circumvent this you can Ctrl + Shift + click on the BSP to grab the whole thing or click on it in the orthographic view.
- Now that the BSP is already selected, in one of the orthographic viewports, click directly over an edge. Doing so will actually select two edges, through the model, that align with each other in depth. It is rather hard to select edges directly in the perspective viewport by comparison, which is why we've set the view to 2x2 split. Try it if you want. If you must do it, zooming in a bit helps.
- Selecting a point is a matter of clicking on it. Then you can Ctrl + click on another to add to the selection. If you Ctrl + click on an already selected point it will deselect. Finally, you can Ctrl + Alt + drag to marquee select points falling inside the selection box in any view. If you marquee select one group of points then try adding to it using the same method it will only select the new points. To extend the current point selection using a marquee, use Ctrl + Shift + Alt + drag.
- In the perspective viewport, select one corner of the box, a single point, and use the Move tool (which should be active but if it isn't try pressing Space to cycle transforms), and nudge the point some distance along an axis, creating a spike. Your moved point will snap to the grid and appear to stagger a little. It's good to keep snapping on so model components align well. This is particularly important for placing architectural features but less so for elements like rocks, plants, or scattered objects that don't need to line up to anything. You can adjust and turn off snapping at the bottom right of the screen or through the View | Drag Grid options.
- When moving models and model components in the viewports there is a Drag Grid spacing or snap by default set to 16 units. This can be toggled and adjusted using the setting at the bottom of the editor, and you will also see the Rotation Grid snap toggle, Scale Grid snap toggle, and auto-save toggle and frequency setting there too. Click the little triangles to set the actual amounts for each.
- Try pressing Undo [ ] or Ctrl + Z to undo the spike you made earlier. Notice nothing happens except the pivot of the BSP jumps to the middle of the brush. Press undo once more and notice this time the spike is returned to its box shape. Create a spike again, but this time we'll commit the change.
- At the top of the editor are a row of buttons that are short cuts for menu items, highlighted below. The first button is Build | Geometry for Visible Levels. Press this. Alternatively, if you go to the menu and choose Build you will see the list of build methods.
- Now press undo twice, as before. This time there's no going back and indeed the Undo icon is greyed out, because after a build any geometry edits from beforehand are committed. However, you can always restore a basic BSP cube by pressing the BSP cube brush button again.
- Notice that your spiked BSP brush is now split from one corner to another by an added edge. This is to ensure the geometry remains convex. If you don't like the direction this edge has been added you can turn it by clicking on the edge in question then pressing Turn in the Geometry Tools floating window.
- We can extend this simple cube and give it more complexity. In Geometry Tools, change from Edit to Extrude mode. Now when you drag a selected surface of the brush along an axis it will extend new geometry in that direction. To stop extruding, just switch back to Edit mode. The following screenshot shows two extrude operations, before and after, in two directions:
- Besides the Extrude tool there is a method of creating new geometry in a brush called the Pen tool. This lets you use Space successively to define points on the viewport grid (orthographic) and create a closed shape, which is then extruded according to a preset depth. Press Space to add pen tool points. Pressing Space will create a point where the mouse is located. Dashed lines between points mark the edges of the geometry. You can hit Enter to stop adding points, which will connect the first and last points and form a new BSP brush.
- When you close the shape you've made with the Pen brush, its depth is auto extruded from the floating window Geometry Tools | Properties | Extrude Depth. This property, shown in the next screenshot, appears only when the Pen tool is active:
Starting construction of objects with BSP
- Now we have covered how to alter a BSP brush, we want to see what we can do with it. BSP is most often converted into geometry and then textured. It can also be used as a collision blocking volume, a spatially based moving trigger, and much more. First let's create some geometry from a basic BSP by recreating the
1024 x 1024 x 16
floor block we made earlier (remember to right click on the BSP cube brush [ ] to set this up), and this time go to the icon set called CSG). - Click on CSG Add [ ], the first of those four icons, and your BSP brush will leave its footprint in the form of a blue/white checkered surface. This coloring is from a default UDK Material: EngineMaterials.DefaultMaterial, and can be replaced later.
- Click on the top surface of the additive BSP then hold L and click to create a light shining on the surface. Move the light up in the Z axis and enlarge it a bit using scale. It helps us see what we are doing. Press Alt + 4 to see the effect of this light. Alt + 4 is the hot key for Lit mode [ ], and it is more appealing than Unlit mode. Press F4 if you want to edit the light's intensity and color, under Light | Light Component | Light Component | Brightness and so on. Lighting is covered in Chapter 8, Then There Was Light! Here, adding the one light will be fine since we're just starting.
- When you press CSG Add [ ] (Ctrl + A), the Builder Brush isn't replaced. It is still there and the geometry is stamped into place at its location. Move the brush out of the way, and maybe press Ctrl + A again to create a second mesh.
- You may notice the Builder Brush is singular and is red. CSG additive geometry is blue. If you click on it in the orthographic viewports, it can be selected directly and moved around. If you click on it in the perspective viewport you will more likely select the surface under the cursor. To circumvent that, hold down Ctrl + Shift when clicking on BSP. When you move the BSP geometry however, unlike the brush, you just move its frame, and the surface itself remains behind. This is because any geometry edit needs a rebuild. As well as moving the BSP geometry, you can readily clone it by holding down Alt when moving it.
- Suppose you want to cut a corner from a wall or dig a trap in the floor, based on an existing BSP geometry. This is fairly easy. First size the BSP brush to fit the area you want to remove, and then press CSG Subtract [ ], which is next to CSG Add. You may also notice there's CSG Intersect and CSG De-Intersect too, which handle combining brushes, a lot like Boolean operations. The next image is an arbitrary example of a subtraction; notice subtractive geometry is orange:
- To control the subtraction you may consider using Scale to adjust the area of the BSP brush. It is usually better to move the edges or points of the brush in Edit Geometry mode, because then you can be sure the sides align to the grid. Scaling is faster though. You will get an idea of when it is okay to scale and when you'll need the precision that manual point control offers. If you only ever use the precise method, and follow the grid all the time, it will take you a long time to get things done.
- With your large, flat additive BSP framed in the view, press Shift + 2 and select and move corners of the Builder Brush so it sits within the floor space with a bit of space around it, then press CSG Subtract.
- The order in which you make BSP geometry matters. If you build another additive mesh inside the hole created by the subtractive operation, then it will happily sit there. However, if you choose the subtractive BSP and right click and choose Order | To First or Order | To Last you can move its order upwards and downwards, reversing the overlap of each, or the build order. This is something to keep in mind at all times when using subtractive geometry. Always rebuild after sorting the BSP order. From now on, choose Build All so lights build too.
- Subtracted geometry will have a yellow outline in the orthographic views. If you delete the subtractive mesh the hole will remain until you rebuild. Delete the subtractive BSP and choose Build All [ ] to leave you with two boxes.
Tip
If you want to export BSP out of UDK as a mesh to use in another 3D editor, you can click on the BSP in the orthographic view then right-click and choose Convert | Convert to Static Mesh. This will create an asset you can store in a package. To export the asset, just right-click it in the Content Browser and choose Export to File. Once you alter the .OBJ in another software, remember to export the result back as .ASE or .FBX. This process is particularly useful if you want to match a model to specific BSP proportions in a scene.