Guide: Siege University - 216: Siege Max: Terrain

== Introduction ==
Siege Nodes are the geometry that makes up the terrain of Dungeon Siege. A Siege Node could be a house, a bridge, a river, a dungeon feature or just a simple flat plane. The following tutorial will lead you through the process of exporting a node and will highlight topics related to how a node should be constructed for best results.
Examples of nodes.
For the purposes of this tutorial we're assuming that you've already taken the time to learn the basics about creating models and applying texture maps. gmax™ comes with a very nice set of basic tutorials to get you up to speed on these things. We'll be focusing on what's needed to get terrain nodes working in Dungeon Siege. 
=== What You Need For This Tutorial ===
* Dungeon Siege v1.1 or newer
* Dungeon Siege Tool Kit (includes Siege Editor and Siege Max)
* gmax™
** For further help in gmax™, first download the help files.
** In gmax™, please refer to Help > User Reference.
* The tutorial files for this course, located in your \gmax\gamepacks\SiegeMax\Scenes\ArtAssets\Terrain folder.
=== What This Tutorial Assumes You Have Already Learned ===
* Siege University: 211 - Naming Key
=== What This Tutorial Will Teach You ===
* Basic concepts of node construction
* How to designate doors and walkable areas
* Properties and benefits of normals and smoothing
* How to use the Siege Node Tool Kit
* Exporting your nodes to Dungeon Siege
=== Siege Max Setup ===
When constructing a node there are a few guidelines to adhere to. First and foremost, make sure you have your units in Siege Max set up properly. Your units should be in meters under "Customize -> Units setup…" and under "Customize -> Preferences…" set the "System Unit Scale" so that 1 Unit = 1 millimeter. The textures that the node uses should be in: \gmax\gamepacks\SiegeMAX\Scenes\ArtAssets\bitmapsand named properly (see Siege U: 211 - Naming Key). The node must have "t_" in the beginning of its name ("t" is for terrain). Be sure to add some special personal label to your node name so that it is unique from all nodes created by everyone (i.e. t_joesnode-floor-a). Only use an underscore after the first "t" and nowhere else. 
== Node Basics ==
The terrain is split up into nodes for two reasons. One is so that the engine can load in the nodes quickly for streaming and the other is to allow flexibility when creating landscapes. When creating nodes for Dungeon Siege we discovered that things were easier when we made the node work as modular as possible. Early on we constructed big custom scenes out of one mesh and then carved that mesh up into smaller sections. This was like a jigsaw puzzle where every piece had its own place and could not be used anywhere else. Because of this, making any fundamental design changes to the scene required a lot of work, sometimes redoing things from scratch. Figure 2 - Jigsaw puzzle construction approach. 
A better approach is to think of the nodes as building blocks that can be arranged multiple ways to create many different layouts. Instead of a jigsaw puzzle approach, the nodes became more like Legos™. This required a bit more planning on how the pieces fit together, especially to minimalize texture seams, but it was well worth the extra effort. Figure 3 - Modular rock wall nodes. 
The best guideline for knowing if your node will connect properly with other nodes is to build stuff out of nodes in Siege Max itself. If things don't line up properly in Siege Max, they won't work in the Siege Editor. Use Siege Max as your testing ground first. It is very important to keep your nodes on a grid when working in Siege Max. A good technique is to find a good ratio of node sizes that work well both in creating regions and streaming in the game itself. Our average node is about 4 meters square. In making sets we stuck with various ratios that included 2,4,8,12,24 and 32 meters. We also matched our texture mapping to these ratios. A 4x4 meter floor is mapped with a 128x128 pixel texture map while an 8x8 meter floor is mapped with a 256x256 texture map. The pattern follows logically from there so that a rectangle that's 8 meters tall and 24 meters wide will be mapped with two 256x256 textures or one 256x256 texture tiled twice. Once you have your node or set of nodes built and can make a scene out of them in Siege Max, you are ready to export it for use in the Siege Editor. The exporting process consists of defining the node connection edges ("doors"), the walk able surfaces ("floors"), water for triggering special effects, and setting up vertex normals for accurate lighting between nodes. 
=== Doors ===
Nodes connect along a common edge that you define. Two nodes share a common edge when the vertices that make up that edge line up perfectly. This is an important point: If the vertices don't line up perfectly then you will get cracks between the nodes when connecting them in the Siege Editor. The edge that nodes can connect to is called a "door". Any edge in the mesh can be used as a door connection with another node, not just edges that are on a boundary. A door can be defined by one edge or multiple edges, though multiple edges must be continuous without a gap or break. Figure 4 - Example of node with three doors defined. 
A door's primary attribute is its direction. The direction that a door faces is illustrated with a yellow line after the door has been defined. Two nodes will connect properly if their respective door directions point to each other. 
=== Floors ===
Faces in the node that the characters can walk on are defined as "floors". The only rule that applies to floors is that you cannot have faces that overlap each other on the z-axis within the same node. If you want to overlap two floors on the z-axis, the respective faces must be in separate nodes. Figure 5 - Example of node with faces flagged as "floor". 
=== Water ===
Water is defined much the same way as floors. You flag individual faces as "water" so that the game engine knows to draw special splash effects when characters walk through them. The flagging of faces only applies to the special effects, so you still need to actually create polygons that are mapped with textures that look like water. 
=== Vertex Normals ===
Each vertex has a normal. You can see this normal by marking the checkbox "show normals" under the Vertex Selection rollout. Siege Max uses this normal to calculate smoothing groups. Smoothing groups are used to calculate how faces will shade when lighted. Vertex normals that are generally parallel to each other will fall into the same smoothing group. Normals that don't point in the same direction within a given threshold will fall into two separate smoothing groups. Having control over vertex normals is important when creating nodes because it ensures that lighting will be consistent across two attached nodes. Generally this isn't a problem if the two nodes have edge vertex normals that have similar trajectories, such as two flat floor planes. Vertex normals become an issue is when the two nodes have curved edges and you want light to shade across the seam consistently, like joining the left and right sides of a split cylinder. Figure 6 - Joining two hemispheres of a cylinder causes a shading seam. 
To clarify, smoothing information isn't automatically translated across two separate nodes that are joined together in the Siege Editor. If the faces that make up the two door edges are close to parallel, such as two flat planes connecting, then there probably won't be an issue with smoothing. If the two nodes connect on a curved surface like the above cylinder, the Siege Editor will not be able to smooth the seam properly because the default smoothing value does not take in account the continuation of the curved surface. To remedy this problem, Siege Max has a couple tools that allow you to force what the smoothing information will be at a door edge. Siege Max comes with two tools that allow you to define vertex normals: "Ignore Faces" and "Lock Vertex Normals" "Ignore Faces" is a powerful tool that lets you select faces in a node that will be ignored by the exporter, but it still keeps the smoothing information of those faces. Ignored faces won't draw in the Siege Editor or the game. The smoothing information of those ignored faces still applies to the lighting calculations. Using this tool, you can attach extra faces to the edges of a given node and that node will light as if those faces existed. Figure 7 - The white areas represent faces that are flagged as "ignored". These ignored faces won't be exported with the rest of the geometry, but their smoothing information will. Thus when the two hemispheres of the cylinder are joined, the surface will shade properly. 
"Lock Vertex Normals" lets you select vertices and force their normals to be parallel to the z-axis. A good example for using this tool would be to lock the joining bottom edge vertices of a curved wall to a flat floor plane. Figure 8 - The bottom vertices of the curved wall are a good example of ones that should be flagged as "locked" so that the wall will shade smoothly with the joining floor. 
== Cleanup And Round Off ==
Cleanup and Round Off is a very important feature in the Siege Node Tool Kit. What this function does is move all vertices to the nearest .01m grid point. This will help ensure that door vertices are exactly aligned. This function will work properly only if your nodes are on a grid to begin with.
== Siege Node Tool Kit ==
Siege Node information is stored as a modifier labeled "Siege Max SNO". This modifier behaves like other gmax™ modifiers. Collapsing the stack will delete any Siege Node information. You activate the Siege Node Tool Kit floating panel by pressing the "Open SNO Tool Kit" button at the bottom of the Siege Max SNO rollout or by selecting it in the right-click menu after selecting a node. There are two major fields in this panel: "Siege Node Doors" and "Siege Node Tools". Siege Node Doors is used to define and modify door flags while Siege Node Tools contains five tools for flagging the rest of the Siege Node information. Figure 9 - The Siege Node Tool Kit 
=== Doors ===
Selecting a node and clicking the "Edit Doors" button activates the "Siege Node Doors" panel. This will change the selection level to Edge and allow you to begin selecting edges to define as doors. The "Edit Door" button is a toggle that can be turned on/off. "Num Doors" identifies how many doors the node currently has defined. "Selected Door" identifies which door is currently selected. The slider bar is a quick and easy way to select doors. "Append New Door" button defines the selected edges as a door. The number on the button will be the new door's identifying number. "Insert New Door" will insert a door into the current sequence of doors. The number on button will be the newly inserted door's identifier. All doors following the newly inserted door will be renumbered accordingly. "Delete Door" will delete the current door. The doors following the deleted door will be renumbered accordingly. "Flip Door" will flip the direction the selected door 180 degrees. "Delete All Doors" will delete all dooring information from the selected node. 
=== Floors, Water, Ignored, Locked, No Round ===
The bottom panel contains the functions floor, water, ignored, locked and no round. These functions share the same three buttons of "Add Selected", "Remove Selected" and "Remove All". These buttons are self-explanatory and will be covered in greater detail in the following tutorials. Once you have defined all the applicable properties to the node you are ready to export it to a .sno file for use in the Siege Editor. With the node selected, bring up the right click menu and select "Export Siege Node". The .sno file will be exported to this directory: \gmax\gamepacks\SiegeMAX\Scenes\ArtAssets\meshes and will have the same name as your mesh object in Siege Max.
== Making Changes To The Mesh After Creating A Siege Node ==
Because the Siege Max SNO is a modifier, it behaves like any other gmax™ modifier. You can add modifiers above or below the Siege Max SNO modifier and collapse modifiers around it. You cannot collapse the Siege Max SNO modifier; this will delete all Siege Node information. Adding or deleting vertices is acceptable, but you may alter the position of some of your flagged information because these are referenced to specific vertex, edge or face identification numbers. If this number shifts, so will your flagged information. A good rule of thumb is that adding vertices, edges or faces will most likely be OK, while subtracting vertices, edges or faces won't.
== Practical Exercises ==
=== Dooring And Flooring ===
In this exercise we will add doors and floor flags to a sample node. To begin, load "Tutorial_Floor.gmax" into Siege Max. This is a simple 4x4 meter node made with eight faces. It is named "t_dgn-floor-04x04-a". The "t_" labels the node as a terrain piece and makes it valid for exporting. The following labels describe the nodes function: "dgn" for a dungeon piece, "floor" for a floor piece, "04x04" for the size of the node, and "a" to allow for iterations of the type of node; in this way we could build a similar node and use the same name only with a "b" at the end of the name. This is useful if we have two nodes that have the same function (a 4x4 dungeon floor), but maybe have difference textures or other features. Figure 10 - The sample floor node "t_dgn-floor-04x04-a". 
To begin with, make sure Siege Max's main viewport is set to view in wireframe mode with "Shade Selected Faces" toggled on (the default hotkey toggle is F2). Select the node and add the Siege Max SNO modifier. Press the "Open SNO Toolkit" button at the bottom of the rollout. We will start by defining doors. Click the "Edit Doors" button at the top of the panel to activate the dooring tools. The editable mesh selection will be automatically switched to Edge. Select the bottom two edges and click the "Append New Door #1" button. The edge is now defined as a door. You will notice that the vertices that make up the door are labeled with green triangles and the first and last vertices are connected with a blue line with a smaller yellow line perpendicular to it. This yellow line points in the direction the door is facing. The door is also labeled with a red number, in this case a "1". This is the number for this door and it is the same number used in the Siege Editor to select doors for connecting. Figure 11 - The node with Door #1 defined. 
Next, select the two edges on the right side of the node and press the "Append New Door #2" button. The new door is similar to the first, except this door is labeled "2". Now select the top two edges and press the "Append New Door #3" button. This new door is now labeled "3". With door #3 still selected, press the "Flip Door #3" button. You will notice the yellow line flipped 180 degrees to point in the opposite direction. If we would keep this orientation for the door, any node connecting to it on a door that faces outward would overlap this floor node, since doors connect facing opposite of each other. We don't want this so press the "Flip Door #3" button again to put the door back to its original orientation. This exercise was just to show the flip door functionality. Occasionally, based on the geometry of a given node, a door may default facing a direction opposite to what you want and the flip door function lets you correct it. Figure 12 - An example of Door #3 (the door in the first image) flipping 180 degrees, before and after. 
Using the slider bar, select door #2. You will know door #2 is selected when it's highlighted red. Now press the "Delete Door #2" button. The door will be deleted and you will notice that what was door #3 is now door #2. Next, select the two edges on the left side and press the "Insert New Door #2" button. You now have this new door labeled "#2" and the top door has been changed to door #3. Finally, select the two edges on the ride side and press the "Append New Door #4". This node is now doored with four doors in a clockwise rotation. Figure 13 - Node with four doors flagged in a clockwise order. 
We will now add floor flags to the faces of the node to finish up. Make sure your node is still selected and press the "flr" (floor) button on the bottom panel. Your sub-object mode is now switched to face level and all the buttons in the Siege Node Tools are now activated. Select all the faces of the node and click the "Add Selected" button. The value in the "Num Floor Faces" field will be 8. This is a good time to try out the other two buttons as well. Select one of the faces and press the "Remove Selected" button. The shaded selected faces will update to show the face you selected being unfloored and the number of floor faces is now 7. Now try out the "Remove All" button. All the floored faces of the node are now removed. Select all the faces again and press the "Add Selected" button to re-floor the node. Now that your node is doored and floored, right click the node and select the "Export Siege Node" function to export the node to a .SNO file. That's it! You've just created a Siege Node. Figure 14 - Finished node floored and doored. 
=== Flagging Faces As Water, Locking And Rounding Off Vertices ===
In this exercise we will introduce the water flag along with locking vertices and using the round off function. Begin the tutorial by loading "Tutorial_Water.gmax" into Siege Max. Figure 15 - Tutorial_Water.gmax. 
Select the node "slope-water-a". To begin with, we need to change the name of the node. Rename the node "t_joenode-slope-water-a". The "joenode" part is a unique name that you will give all your new nodes to differentiate them from nodes that others have created. Instead of "joenode" use a name you have made up. Right-click on the node to bring up the Siege Max's quad menu and select "Open Siege Node Toolkit". We will begin by making sure all the XYZ positional values of the node's vertices have been rounded off. With your main viewport set to wireframe, press the "Cleanup and Round Off Siege Node" button. You will notice several of the vertices moved. All the vertice's XYZ positions on the grid have been rounded off to the nearest .01m. Now we'll flag the faces on the node that are textured with a water bitmap. Click the "wtr" (water) button. Your Editable Mesh sub-object selection is now set to the Face level. Scroll the editable mesh modifier rollups down to the "Material" field and click the "Select By ID" button. Choose ID 2 and press "OK". All the faces textured with material #2 in the node's multimaterial are now selected. Press the "Add Selected" button in the Siege Node Took Kit. The number of water faces is now 20. Figure 16 - Location of the "Select By ID" field. 
Figure 17 - Node with water faces selected. 
Now press the "flr" (floor) button and use the same method outlined above to select by material ID number all faces textured with material 1. Press the "Add Selected" button in the Siege Node Tool Kit. Our next step will be to flag all the vertices on the top and bottom boundary edges as locked. To illustrate why we do this, select the vertex on the bottom left corner and the vertex to its right (vertex#47 and vertex #41). Put a check mark in the "Show Normals" box and change the scale value to 5000. If you view the node from the left or right side you can easily see that the normals' angle are not the same. We want all the normals of the top and bottom edge to point straight up, parallel to the z-axis. This is the same direction the normals will point on a flat floor node. Figure 18 - Vertices with their normals shown. 
To do this, select the "lck" (lock) button on the Siege Node Tool Kit Panel and then select all the vertices of the top and bottom edges of the node. Now press the "Add Selected" button. All the vertices are now marked with a yellow triangle and the Num Locked Normal Verts should be 10. The tool doesn't adjust the normals in Siege Max, but they will export out with the newly adjusted angle, one that is parallel to the z-axis. Figure 19 - The locked vertices are labeled with yellow triangles. 
The last step is to flag the boundary edges as doors. Use the screenshot below for your guideline. When you are done, the node is now ready for exporting. Figure 20 - The node has six doors labeled counterclockwise starting from the bottom left corner. 
=== Ignoring Faces And Flagging Vertices Not To Round Off ===
In this exercise we will introduce the ignore faces functionality along with how to flag vertices so they don't move when the Round Off Siege Node tool is used. Begin the tutorial by loading "Tutorial_Archway.gmax" into Siege Max. There are two nodes in this scene: "t_dgn-wall-archway-bottom-a" and "t_dgn-wall-archway-top-a". You will notice that when you view them in smooth + highlights mode there are parts of the node textured white. These are the faces we will be ignoring when exporting. We have the top of the archway separate because we want to be able to fade it off when a character walks through the archway. We include these faces in the model because we want the smoothing information they provide. Figure 21 - "t_dgn-wall-archway-bottom-a" and "t_dgn-wall-archway-top-a" 
Begin by selecting the "t_dgn-wall-archway-bottom-a" node and select all the faces that are assigned material ID # 8. All the white faces should be selected. Now hide these faces (first major button on the "Selection" rollout). You will see that there are faces that cap off the gap of the hidden arch top. You can select these faces and move them around to see that they are not welded to the rest of the geometry. This is because if we were to weld the vertices to the rest of the archway, we would create bad geometry where three faces would join on a common edge. This isn't allowed since Siege Max won't know how to shade such an instance and otherwise it's just sloppy modeling. Having the capped faces attached but not welded will work fine for what we want. Undo any moving of faces you might have done and unhide all the hidden faces. Figure 22 - Node with capping geometry when the top is hidden. 
With "t_dgn-wall-archway-bottom-a" still selected, open up the Siege Node Tool Kit. Press the "ign" (ignore) button in the "Siege Node Tools" panel. Now select all the white faces either by hand or by using the Select By Material ID method. Once you have them selected, press the "Add Selected" button. The number of ignored faces should now be 46. Now press the "flr" (floor) button. If you examine the geometry of the floor of the archway node, you will see that there are extra faces that are close to the wall. This is done because we don't want those faces that hug the wall to be walkable. If these extra faces were not there, then a character would be able to walk right up to the wall and in some cases be able to have parts of its body go through, or clip, the wall. To minimalize this problem, we added the extra faces to put a bit of a barrier between the wall and a character. Select all the faces of the floor except those that hug the wall and use the "Add Selected" button to flag them as floor. Your selected faces should look like the screenshot below. Figure 23 - Faces that should be floored. 
Now press the "Edit Doors" button and door the node like the screenshot below. Notice the last door that will be the connection edge for the top of the arch. Selecting this door could be tricky since you need to select this door and not any of the edges of the capping geometry. Figure 24 - Don't forget the seventh door at the top of the node. 
Now press the "Edit Doors" button again to toggle it off. Select the "t_dgn-wall-archway-top-a" node and click the "Edit Doors" button once again. Using the buttons in the Siege Node Tool Kit in this way (as toggles) lets you move from node to node to flag properties without having to close the Siege Node Tool Kit and reopen it for each node. Now press the "nrd" (no round) button. The selection sub-object level will switch to vertex. We want to flag some of the vertices of the actual archway not to move when we cleanup and round off the node. This functionality is useful if we want to preserve the geometry in a node and not have it move when rounded. Common examples of needing this are for curved surfaces or angles were the points can't be on a nice, even XYZ position. This isn't recommended for vertices that make up a door edge, but it is allowed so use at your own risk. Now select all the vertices that make up the top part of the curve of the archway, just like the screenshot below. Figure 25 - Select the vertices at the top of the arch. 
Press the "Add Selected" button. All those vertices should now be tagged with red triangles. Press the "Cleanup and Round Off Siege Node" button. The flagged vertices did not move even though they have XYZ positions that could be rounded off. Now press the "ign" (ignore) button. Select all the white faces either by hand or by using the Select By Material ID method. Once you have them selected, press the "Add Selected" button. We will now define a door connection. Select "Edit Door" and door the edge that matches the connecting edge in node "t_dgn-wall-archway-bottom-a". This door is facing the same direction as the one in the bottom piece, which won't work for us since that would make the top connect up wrong. We need this door to point in the opposide direction as the door in "t_dgn-wall-archway-bottom-a". Press the "Flip Door #1" button to flip the direction of the door 180 degrees (facing the opposite direction as the door in the bottom node). The screenshot below is how it should look. Figure 26 - The door for "t_dgn-wall-archway-top-a" should point to the left. 
You now can export each node. 
=== Sample Node Set ===
Included with the tutorial files is a sample dungeon node set called "Tutorial_Dungeon.gmax" This file contains 13 nodes that are the very basic pieces for making a dungeon including floors, corners, doorways and different wall variations. These are the same nodes used in the game so take some time to study how they were constructed, how they were texture mapped, what kind of textures were used, and how they were flagged with the Siege Node Tool Kit. Also pay attention to how the nodes are named and how they list in alphabetical order when the "Select By Name" button (found in the main toolbar) is pressed in Siege Max. It is highly recommended that you use the nodes for practicing your texturing abilities along with using the Siege Node Tool Kit. Feel free to add pieces to the set to expand it and give it more functionality, such as making a stairway or adding pillars to a floor node. Try to use the premade textures as a template for creating your own dungeon look. Have fun! Figure 27 - Sample dungeon node set. 
== Conclusion ==
The information outlined above is all you need to know when exporting a mesh from Siege Max to a usable node for the Siege Editor. The process of defining Siege Node properties is straightforward and is consistent from one node to the next. The only area that is open to subjectivity is building nodes themselves. There were over 3800 individual nodes created for Dungeon Siege ranging from very simple flat floor planes that were a couple faces all the way to complex sections of a custom terrain feature that required pulling every trick to get it to work properly. There is no single right way to build a node and you are limited only by your ingenuity and imagination. We highly recommend taking a look at the nodes we made and study how they were constructed. Pay close attention to how we used ignored faces, how we divided edges to support walk able surfaces and keep character from walking part way into walls, why we separated nodes a certain way to facilitate fading, and how we UV mapped nodes so that bitmap resolutions were consistent. The best advice we can give you is to start off with very simple geometry. Keep your sets as basic as possible and take baby steps until you get a feel for how the Siege Node tools behave. Work with prototype geometry to see how things connect and whether they light property. Don't worry about making the nodes look good until you know they are fundamentally sound and functional in Siege Edit. This will save you much frustration and hair pulling in the end. Good luck and happy node building!