Fundamentals of Level Editor Design and Implementation – Pt.2.

27
Fundamentals of Level Editor Design and Implementation – Pt.2

Transcript of Fundamentals of Level Editor Design and Implementation – Pt.2.

Page 1: Fundamentals of Level Editor Design and Implementation – Pt.2.

Fundamentals of Level Editor Design and

Implementation – Pt.2

Page 2: Fundamentals of Level Editor Design and Implementation – Pt.2.

Introduction

• At the end of this lecture you will be able to:–Understand what level objects are–Understand, at a high level, some more design and

implementation aspects of a Level Builder tool–Learn about Geometry Editing support in a Level

Builder tool–Learn about other features which can be implemented

in a Level Builder tool

Page 3: Fundamentals of Level Editor Design and Implementation – Pt.2.

References

• Zerbst, Stefan, 3D Game Engine Programming, Premier Press, 2004–Chapter 14

• http://en.wikipedia.org/wiki/Constructive_solid_geometry

Page 4: Fundamentals of Level Editor Design and Implementation – Pt.2.

Level Objects

• Level objects can be created, saved, loaded and manipulated within the level editor

• They can be seen as a type of ‘shell’ object which corresponds to some kind of in-game object

• They can have a visual representation (ideally similar to its in-game representation if present), and methods to set, save and load properties applicable in-game

Page 5: Fundamentals of Level Editor Design and Implementation – Pt.2.

Level Objects

• Some examples of level objects:–Player spawn points–Power ups–Save points–Enemy spawners–Lights–Static meshes and decorations–Event triggers–Interactive props–Portals

Page 6: Fundamentals of Level Editor Design and Implementation – Pt.2.

Level Objects

• May have the following attributes:– Name / ID– Position– Orientation– Scale– Any other specific attributes ( e.g. for an enemy spawner: enemy

type to spawn, number of enemies to spawn etc. )

• May support the following functionality (within the editor):– Selectable– Movable– Rotatable– Any other specific functionality applicable to level editor

Page 7: Fundamentals of Level Editor Design and Implementation – Pt.2.

Object Selection• MOGRE supports the detection of Movable objects in its

RaySceneQuery (refer to previous lecture notes)

• It makes sense to associate Level Objects with a unique Movable (by inheritance or through a mapping of some kind)

• This can be mapped back to the level editor objects either by a direct cast or by using some kind of a mapped list (with the movable object as a key and the level object as the value ).

Page 8: Fundamentals of Level Editor Design and Implementation – Pt.2.

Object Selection

• Alternatively, a LevelObject can be selected by name or ID via …

• A dialog box which allows the user to enter in the name / ID and have that LevelObject selected in the level

• This is easier if the user is finding it difficult to visually single out a specific instance of an object in a large level, but can’t remember its name

• Would be implemented as a list keyed on the name or ID

Page 9: Fundamentals of Level Editor Design and Implementation – Pt.2.

Object Selection

• When selected, the user will require some kind of visual feedback to indicate this selection.

• E.g. a bounding box, highlighted texture etc.

• Similarly, when unselected, this visual feedback will be undone.

• We will discuss a very rough highlighting approach in MOGRE

Page 10: Fundamentals of Level Editor Design and Implementation – Pt.2.

Object Highlightingpublic void HighlightOn(LevelObject lob)

{

Entity ent = lob.Entity;

m_SelectedMaterial = new MaterialPtr[ent.NumSubEntities];

m_SavedMaterialNames = new string[ent.NumSubEntities];

for (uint i = 0; i < ent.NumSubEntities; i++)

{

SubEntity subEntity = ent.GetSubEntity(i);

m_SelectedMaterial[i] = subEntity.GetMaterial().Clone(ent.Name + ent.GetSubEntity(i).GetMaterial().Name + i);

m_SavedMaterialNames[i] = subEntity.MaterialName;

subEntity.MaterialName = m_SelectedMaterial[i].Name;

TextureUnitState tus = subEntity.GetMaterial().GetTechnique(0).GetPass(0).GetTextureUnitState(0);

tus.SetColourOperationEx(LayerBlendOperationEx.LBX_MODULATE, LayerBlendSource.LBS_MANUAL, LayerBlendSource.LBS_TEXTURE, ColourValue.Green);

}

}

Page 11: Fundamentals of Level Editor Design and Implementation – Pt.2.

Object Highlighting

• We can’t just change the material of the selected entity because all other entities sharing this material will be altered also

• Material name is saved, Material is cloned, and then the changes are made to the clone material

• In this example, the first texture unit state is blended with a green colour to achieve a green highlighting effect

• When highlighting is off (entity is deselected) , this material is disposed and the saved material restored to the entity

Page 12: Fundamentals of Level Editor Design and Implementation – Pt.2.

Multiple Object Selection

• A user may wish to select multiple objects ( via click dragging a rectangle etc. or ctrl-clicking on separate objects )

• Maintain a queue or list to store references to these selected objects

• Update this queue when new objects are added or existing objects removed

• Highlighting performed before addition to queue• User operations must be performed to all selected items in

the queue

Page 13: Fundamentals of Level Editor Design and Implementation – Pt.2.

Object Movement and Placement

• Each level object has its own position, orientation, etc.

• The user may wish to alter these directly by entering in specific values (via a dialog box) or visually (via moving / rotating the object in the editor until it looks right)

• Movement and rotation can be relative to either the model space of the object, relative to an arbitrary point in the world space (usually rotation) or global world space (rarely)

Page 14: Fundamentals of Level Editor Design and Implementation – Pt.2.

Object Movement and Placement

• Ensure that we are in the correct coordinate space before we perform the movement / rotation.

• For local transforms, –rotations will rotate the selected object about it’s local

axes–translations will translate the selected object along it’s

local axes• For rotations around a point in world space,

–usually done in the orthographic view–i.e. fixed plane of rotation ( xy, yz, xz )

Page 15: Fundamentals of Level Editor Design and Implementation – Pt.2.

Object Movement and Placement

• Consider the following additional functionality:–Displaying a local coordinate axes graphic for the

selected object so that it is clear for the user how the object is oriented relative to the world

–This also makes it clear how translations relative to the object’s coordinate space will be directed

–A “snap-to-grid” function for quick alignment to the world’s space so it can be placed accurately in relation to other world aligned objects

Page 16: Fundamentals of Level Editor Design and Implementation – Pt.2.

Saving and Loading• Choose the interfaced format : text or binary

• In textual form, it is easily inspectable and alterable in a text editor allowing for very quick tweaks and debugging

• Is a decoupled interface between the game and the tool

• Don’t have to worry about data structure packing etc. between C# and native C++

• However it will be slower to process in-game during the loading phase

Page 17: Fundamentals of Level Editor Design and Implementation – Pt.2.

Saving and Loading

• The textual data can be compiled into a binary form during a later process in the pipeline to ensure security and portability

• Must ensure that the interface is adhered to and up-to-date in the game engine

• Changes to interface between tool and game may be costly – also need to consider developing an updater tool to retrospectively update the data generated by previous versions of the tool (if required)

Page 18: Fundamentals of Level Editor Design and Implementation – Pt.2.

Saving and Loadingpublic void Save(string filePath)

{

FileStream fs = new FileStream(filePath, FileMode.Create);

StreamWriter w = new StreamWriter(fs);

w.WriteLine(m_LevelObjects.Count);

foreach (LevelObject lob in m_LevelObjects)

{

w.WriteLine(lob.Class);

w.WriteLine(lob.Position.x);

w.WriteLine(lob.Position.y);

w.WriteLine(lob.Position.z);

w.WriteLine(lob.Orientation.w);

w.WriteLine(lob.Orientation.x);

w.WriteLine(lob.Orientation.y);

w.WriteLine(lob.Orientation.z);

}

w.Flush();

w.Close();

}

Page 19: Fundamentals of Level Editor Design and Implementation – Pt.2.

Saving and Loadingpublic void Load(string filePath )

{

FileStream fs = new FileStream(filePath, FileMode.Open);

StreamReader r = new StreamReader(fs);

int nNumLobs = int.Parse(r.ReadLine());

while (nNumLobs > 0)

{

int type = int.Parse(r.ReadLine());

Vector3 position = new Vector3(float.Parse(r.ReadLine()),

float.Parse(r.ReadLine()),

float.Parse(r.ReadLine()));

Quaternion orientation = new Quaternion(float.Parse(r.ReadLine()),

float.Parse(r.ReadLine()),

float.Parse(r.ReadLine()),

float.Parse(r.ReadLine()));

AddLevelObject(m_Editor.CreateLevelObject(position, orientation));

}

r.Close();

}

Page 20: Fundamentals of Level Editor Design and Implementation – Pt.2.

User Defined Keysets

• Improves usability of tool by allowing customisation of input keys according to user preferences

• Can implement as a simple mapping class method or a more complete abstracted input system

• Can save and load – as it doesn’t interface with the game itself, a binary format is fine

Page 21: Fundamentals of Level Editor Design and Implementation – Pt.2.

User Defined Keysetsvoid KeyDownHandler(object sender, KeyEventArgs e){switch (e.KeyCode){

// movement keyscase KeyMap.GetKeyCode( KeyMap::StrafeLeft ):{

...break;

}case KeyMap.GetKeyCode( KeyMap::StrafeRight ):{

...break;

}

Page 22: Fundamentals of Level Editor Design and Implementation – Pt.2.

Geometry Editing

• Geometry editing in a level builder can be useful for:–Building and tweaking level geometry (visual or collision

meshes)–Defining 3D lines, planes, polygons, volumes for game

constructs

• Consider the level of support for geometry editing in our tool – a fairly complex area to implement

• At the very least, must need to support the importing of static meshes and the loading of terrain height maps etc.

Page 23: Fundamentals of Level Editor Design and Implementation – Pt.2.

Geometry Editing

• Considerations:–Class types to encapsulate vertices and polygons–Selection and editing of vertices, edges and faces–Tesselation–Texturing–Basic extrusion, splits etc.–Terrain editing – load from heightmap, randomise

terrain surface generation (using perlin noise etc.)–user customisation using terrain “painting” tools

Page 24: Fundamentals of Level Editor Design and Implementation – Pt.2.

Constructive Solid Geometry

• A method of quickly building complex looking geometry by performing boolean operations on geometry primitives

• Boolean operations include: Union (add), Difference (subtract), Intersection

• Primitives include: cube, cylinder, cone, pyramids

• Can be used to build indoor levels very quickly compared to drawing faces and vertices (and duplicating them) individually

Page 25: Fundamentals of Level Editor Design and Implementation – Pt.2.

Scene Management

• The Level Editor may also need to support the scene management technique used in the actual game

• E.g. If a portal engine is being used in-game, then the editor will need to be able to specify portals and group level objects and level geometry into sectors etc.

• E.g. If BSPs are used (for visual or collision detection), then the editor may need to support a BSP compiler so that the output can be used directly in the game

Page 26: Fundamentals of Level Editor Design and Implementation – Pt.2.

Other considerations

• Integration with game – can launch the game from within the level editor

• Generation of static shadow maps and other geometry

• Integrated scripting support

• Sound events and music integration

Page 27: Fundamentals of Level Editor Design and Implementation – Pt.2.

Lecture Review

• Understand what level objects are

• Understand, at a high level, some more design and implementation aspects of a Level Builder tool

• Learn about Geometry Editing support in a Level Builder tool

• Learn about other features which can be implemented in a Level Builder tool