Blender Basics (#6): Optimising Models

Spread the love

Previously we learned how Blenders interfaces is divided into working ‘zones’, how to navigate and move around the interface and then how to make a model and apply UVW maps as we progressed through each section of the tutorial series to make a simple chair.

For the next and final section, we’ll be looking in to one of the most essential, but least discussed, ‘skills’ of making 3D content – how to optimise it for use in a game or interactive environment (3D chat, game, virtual world and so on).

If you’ve jumped ahead to this final section of the Blender Basics tutorial then it’s assumed you know how to use Blender and where all the buttons and shortcuts are.

If you don’t it’s recommended that you read through the entire tutorial to get to grips with Blender before tackling this part of the process.

Download: Chair exercise source file Katsbits chair source (c. 600 KB | *.blend, *.tga).

The Golden rule of optimising

When making anything for use in a game there is one ‘golden rule’ that you must keep in mind at all times; if you learn one thing from this entire tutorial series you would do well for it to be this simple rule;

Less is more

What does this mean?

Take a look at the following image below showing a simple block shape typical of a ‘wall’ prefab. Both objects appear to be the exact same model; same height, same width and same breath.

As it happens, they’re not.

Optimising mesh objects in Blender

Two visually identical mesh objects in Blender

The difference isn’t revealed however, until the objects are looked at Edit mode and their respective mesh densities shown; the object on the left is made up of significantly fewer faces than the one on the right, which has several additional sub-divisions across it’s structure.

Optimising mesh objects in Blender

Looking at the object in Edit mode reveals a significant difference in how the mesh objects are constructed with the object in the right being composed of many more faces and polygons than its counterpart on the left

wireframe view showing the unnecessary subdivision of the mesh object

Wire-frame view of the above showing the extent to which the extra polygons of the right hand mesh go all the way around the object

For games, especially those run online over the internet, this would make the right hand version ‘inefficient‘; it may not seem that way when looked at as a single object in isolation, but put into a scene or room built from or containing several similarly inefficient objects and all those extra faces – hundreds, thousands or tens of thousand in a large scene or room – soon add up to your computer using a lot of memory, CPU and graphics resources rendering elements that aren’t necessary, resources that could be better spent on something else – extra AI for instance, slightly better frame-rate or smoother experience and so on.

Just because you can, doesn’t mean you should

The upshot of this is that your models should be properly optimised; use as few polygons and textures as possible, keep images correctly proportioned (using the “power of two” rule) and minimally sized. This simple, single ‘principle’ – “less is more” – matters a great deal when making content or developing games; executing an idea will count for naught if the results don’t run well as they should as a result of un-optimised content over-taxing rendering technology.

Optimising meshes, where to reducing polygon count

Open the chair you’ve been making throughout this tutorial series into Blender and enter Edit mode, “Select All” (“A“) faces of the object so you can see the UVW map that’s currently applied to the mesh; you should have something similar to the image below.

The chair 'as is' before optimising it for better performance in game

The chair built throughout this Blender Basics tutorial showing faces selected to display the UVW map applied to the mesh

Looking at the chair at this point it may not be immediately apparent that the mesh can be ‘cleaned’ up further than it already has been so it uses fewer polygons, making it more efficient as an object. The image below highlights these some areas where optimisation can be done safely without ruining the model – green lines indicate edge loops that can be safely removed; blue, where edges or vertices can be collapsed; pale blue are optional but would mean the chair using the least number of polygons.

Possible options to optimise a mesh by removing unnecessary edge loops and faces

Potential areas where the mesh can be optimised by removing edge loops

Reducing poly count – selecting edge loops

The first type of elements you want to look at removing or collapsing are faces, edges or vertices in the middle of a given area, these are items that can be edited without causing any major disruption to the structure of the object itself – a point to bear in mind before doing anything however, whatever is done now will ‘break’ the UVW map so it will need to be reapplied once optimisation is done.

A useful tool to use here is “Loop Select“. Whilst in Edit mode hold down the “Alt” key and RMB click an edge – make sure to be in either ‘Vertex‘ or ‘Edge‘ “Select Mode” (“Ctrl+TAB“) as edges can’t be selected when in ‘Face‘ select mode – as shown below (highlighted green and pink) this will select the most complete ‘loop’ around the mesh; if it doesn’t, try selecting a different edge along the same loop.

Hold ALT and RMB click and edge to select the loop around a model

Hold “Alt” and RMB click and edge to select the loop around the model

Edge loop selected in Blender

Edge loop selected – shown in textured view

Wireframe view of selected loop showing its path around the mesh

Edge selected and shown in wireframe view – loop wraps around the model

Reducing poly count – edge slide

With an edge-loop selected the next step is to collapse it into its nearest neighbour, this is done using the “Edge Slide” tool. To do this, with the mouse over the 3D view press “Ctrl+E” to open the “Edge Specials” menu pop-up (shown below). Click “Edge Slide” to active the tool, a green marker will appear (usually along the last edge to be selected) indicating the direction the edge-loop will slide, simply move the mouse to then slide the loop along the corresponding edge and LMB click to ‘set’ the final position.

Design note: holding “Ctrl” whilst sliding the loop snaps to the grid.

Once the loop across the seat is done, repeat the process for the edge-loop that runs from the front and up the back of the seat down the centre (the loop highlighted in pink above), this also needs collapsing as, like the seat, it doesn’t ‘add’ anything structurally to the object (the chair still functions as a chair without them).

This process of collapsing unnecessary edges and edge loops needs to continue. However, doing so now will hit a few snags because a number of the loops terminate at an end point meaning that selecting a loop and moving it will also move elements that shouldn’t be.

Ctrl+E to slide and edge loop

Activate the ‘Edge Slide’ tool pressing key combination “Ctrl+E” to open the “Edge Specials” pop-up menu

Edge Slide indicator line showing the direction along which the edge will slide

A green direction marker will appear…

Collapsed edge

Move the mouse (hold “Ctrl” whilst moving to snap to the grid) and LMB click to set the final position of the loop

Reducing poly count – vertex selection

Selecting loops from now on will be a bit tricky because they often terminate at a vertex rather than loop around the model as before. This then means de-selecting the odd vertex so we still have control over the sliding of an edge without necessarily effecting the terminating vertices – which generally form part of another element of the mesh, so need to stay put.

To do this switch to “Vertex Select” mode – “Alt+TAB” select “Vertex” – and simply select a ‘loop’ as before (hold “Alt” and RMB click an edge) then with the partial loop now active press the “Shift” key and RMB click a terminating vertices (circled in red below) to de-select them, this should then leave a partial line still highlighted. Once the partial loop is active, as mentioned previously above activate the “Edge Slide” tool – “Ctrl+E“, select “Edge Slide” – and collapse the edge by sliding it along the active edge (highlighted green).

Selecting an edge loop that hits a 'terminator' at each end (note that 'seams' have been removed to make edge selection easier to see - see below)

Selecting an edge loop that hits a ‘terminator’ at each end (note that ‘seams’ have been removed to make edge selection easier to see – see below)

'Terminator' vertices shown circled

‘Terminator’ vertices shown circled

De-selecting the terminal vertices leaves a partial edge loop still highlighted

De-selecting the terminal vertices leaves a partial edge loop still highlighted

Activate the "Edge Slide" tool and collapse the edge into it's nearest neighbour

Activate the “Edge Slide” tool and collapse the edge into it’s nearest neighbour

A partial edge collapsed using "Edge Slide"

A partial edge collapsed using “Edge Slide”

Mesh tools and Rem Doubles

Because edges have been collapse they way they have, it now means that areas of the mesh contain vertices sharing the exact same co-ordinates in space, this can make further work tricky so they need to be removed using the “Rem Doubles” tool.

To do this, enter Edit mode (“TAB” key) and select all vertices (“A“). Press “F9” to make sure the ‘Edit’ buttons are visible then in the “Mesh Tools” panel click the “Rem Doubles” button; a pop-up will appear informing you as to how many ‘duplicate’ vertices will be removed – click the pop-up to confirm the action.

Using "Rem Doubles" to delete excess vertices as a results of optimising the mesh and collapsing edges

Using “Rem Doubles” to delete excess vertices as a results of optimising the mesh and collapsing edges

Once done, carry on collapsing unnecessary edges, typically anything similar to those shown highlighted in green below. Select partial edge loops and de-selecting the terminating vertices one element at a time so the edges can be collapsed by sliding as described above; press “B” once to use the “Border Select” tool to deselect tricky groups of vertices after they’ve been collapsed by MMB clicking the group. You should end up with something similar to the image below.

Additional edge loops highlighted for collapse and removal - red indicates where care needs to be taken with terminating vertices

Additional edge loops highlighted for collapse and removal – red indicates where care needs to be taken with terminating vertices

The terminating vertices that need to be de-selected after selecting an edge loop

The terminating vertices that need to be de-selected after selecting an edge loop

The chair after the additional edge loops have been collapsed

The chair after the additional edge loops have been collapsed

Closer view of the collapsed edge loops

Closer view of the collapsed edge loops

Mesh tools – collapsing individual vertices

There are still one or two vertices we can clean up but those have to be done individually rather than through edge loop selection. For this we need to use the “Merge” tool. Before doing that however, use “Rem Doubles” again to remove any duplicate vertices resulting from previous collapsing. So, select all (“A“) and in the “Mesh Tools” panel click the “Rem Doubles” button again, once done this should leave a clean mesh from which to do the final vertex collapsing.

To do this, first RMB select the destination vertex – this is the point you want other vertices to collapse to – then hold “Shift” and RMB select the vertex you want to collapse into the first. With the vertices selected, press “Alt+M” to open the “Merge” pop-up menu and select “First” from the list; this will collapse and ‘merge’ selected vertices into the initial selection point, removing ‘doubles’ as it does this. Repeat the process for the remaining stray vertices on the front of the chair.

Design note: Because this tutorial chair is very regular in shape it means that vertices at the top of the chair legs can be collapsed and removed, keep in mind that doing this will depend a great deal on the ‘lines’ of the model – if you collapse a set of vertices is it going to alter the shape of the mesh, if so then don’t merge them.

Two vertices selected for mergeing and collapse; select the 'target' vertice first

Two vertices selected for merging and collapse; select the ‘target’ vertex first

"Alt+M" opens the "Merge" menu, select "First"

“Alt+M” opens the “Merge” menu, select “First”

All selected vertices are merged to the initially selected point

All selected vertices are merged to the initially selected point

Long, thin triangles/polygons

If a situation arises where collapsing an edge or vertex means creating long, thin triangles, it’s best to avoid them because they have a tendency to cause rendering issues as well as texture and UVW map problems. If an object is to be animated they’ll often cause a mesh to collapse in on itself rather than fold, bend, or twist the way they should. So for situations similar to the back of the chair shown below, merging vertices isn’t strictly necessary or required.

Avoid collapsing vertices so they create long, thin polygons

Avoid collapsing vertices so they create long, thin polygons

Instead, where appropriate, leave a mesh 'as is' to limit the number of potential issues that could crop up as a result optimising

Instead, where appropriate, leave a mesh ‘as is’ to limit the number of potential issues that could crop up as a result optimising

UVW maps and optimisation

One of the problems associated with optimising meshes by deleting vertices, edges and/or faces to reduce poly count is that it invariably corrupts any UVW maps previously applied to the model, it’ll ‘break’ the maps faces apart, including those belonging to ‘island’ elements that may have been created to aid more efficient texturing. This obviously happens because in removing certain vertices and edges the corresponding vertices and edges are removed from the UVW map itself.

This means for example, in collapsing what appear to be unnecessary vertices at the top of the chair leg into the vertex at the top of the seat (circled below), what were originally the corners of the ‘seat’ UVW map (green area below) then become part of the upper leg (brighter yellow below). On creating the texture for the chair it then means several additional matters need to be taken into account, all of which revolve around the separated seat corner UVW’s and making sure they still match the rest of the seat even though they’re now part of the leg UVW element, any differences between the two will be visible.

So, when optimising a mesh keep in mind the final layout of the UVW map and how that will then effect the different elements of a texture applied to it; ideally it’s best to try and keep individual elements ‘unified’ as much as possible so that, for example, a chair is treated as if it’s broken down in to clearly defined sub-elements, ‘legs’, ‘seat’ and ‘back’, as opposed to having a UVW map that’s fractured with faces disassociated from their neighbours and where they are on the mesh/UVW map.

Avoid collapsing vertices and edges where the results break a UVW up into disassociated elements

Avoid collapsing vertices and edges where the results break a UVW up into disassociated elements

Instead, try and keep the mesh structured so it can be easily broken down into clean sub-elements

Instead, try and keep the mesh structured so it can be easily broken down into clean sub-elements

Rebuilding the UVW map

Optimising will likely have broken any UVW map previously applied to the mesh, so once all the work has been done it’s time to rebuilt it in exactly the same way as before any optimisation were carried out. So mark out your seams so as to create a series of ‘elements’ – ‘seat’, ‘legs’ and ‘back’ – and then re-assign the texture to the map so it to appear over the mesh; because the overall structure of the chair hasn’t been changed it should be possible to use more or less the same amount of space on the map and/or use the same areas as previously (as shown below).

The completed UVW map of the chair model

The UVW mapped chair before optimisation

UVW map after the mesh has been optimised

UVW map after the mesh has been optimised

Conclusion

Less is more
Just because you can, doesn’t mean you should

As mentioned at the beginning of this part of the Blender Basics tutorial series, optimising helps reduce overheads by limiting a game engine from rendering more information to screen that it really needs to. For example, the chair used in throughout this series, once triangulated and exported, originally used 148 triangles, after optimisation that was reduced to 76, almost a 50% saving. The thing is, removing those additional 72 polygons mattered. Why? Because ten chairs means an extra 720 triangles being rendered to screen, that’s almost another ten chairs in of itself that could have been placed in a scene had the object been properly optimised in the first place.

Once the model is optimised it’s then ready to be exported from Blender to a game, for example, you can learn about how to exporting models to 3D chat services like IMVU and Frenzoo here. Or export models to traditional First Person Shooters like Doom 3, Quake 4 or Unreal.


Spread the love