# $ Introduction to the notion of game materials

The 3D engine animates characters in a virtual environment. This environment is what you can see : walls, trees, water, ice, grass, etc. At a glance you can recognise what you see thanks to its visual aspect. As is the real world, you guess that a character will slip when walking on ice or oil, for example, because the visual aspect enables you to identify the material (rock, wood, concrete, ice, grass, etc.). But for the 3D engine things are not that simple, because the visual aspect of a polygon (or any other geometric object) is not enough for the engine to compute the outcome of the encounter between a character and this geometric object. This is why additional information is to be associated to the visual part of a material. Therefore for the engine the visual part is the least interesting information that could possibly be contained in a material. This is why we have devised a more complete notion of material : the game material. 
Well, as you can probably guess, a game material groups all those aspects you just read about. In this respect, a game material is quite like an actor : it can have up to four parts, centralised in the game material itself. These parts are the visual aspect, the mechanical characteristics, the collision characteristics, and the sound characteristics. Quite obviously, each part gets a specific pane in the editor’s interface.

+ # $ The visual characteristics edition pane 

Since before all the game must be understandable for the player, the game material has a visual aspect. The various parameters enables the designers to create more or less realistic aspects for the objects that constitute the world.
{bmc Visual.shg}

$ # The visual material texture list
This list holds all the textures used by the visual material. This is an ordered list which associates a duration to each texture. This duration is edited in the texture edition pane. Note that two materials referencing  a same texture in their respective lists can associate it a different duration and order. It is also possible to reference a texture more than once in a single list. Every action upon this list can be undone (adding, removing, reordering).
{bmc animatedtexturelist.bmp}
Selecting a texture in the combo will make the texture edition pane display it. If there is only one texture in the list, this action is irrelevant, hence the combo is disabled. The duration edit in the texture edition pane is also disabled, because duration is irrelevant since the same texture will be displayed indefinitely.
{bmc animatedtextureplus.bmp} will bring out the texture chooser dialog for the user to select a texture that will be inserted after the current one in the list.
{bmc animatedtextureminus.bmp} will remove the current node in the list. If  there is no texture in the list, it is not possible to remove one, hence it is disabled, and the combo is empty.
{bmc animatedtexturearrows.bmp} are used to change the order in the list by moving the current texture up or down in the list order. If the current texture cannot be moved in a given direction, the corresponding arrow will be disabled.

$ # The textured flag button
This is a toggle-state button : 
{bmc texturedbuttontrue.bmp} Click once to set the value to true (the material will use the textures in the texture list button).
{bmc texturedbuttonfalse.bmp} Click again to set it to false (no texture will be used when displaying this material). The texture list will not be cleared, it just wont be used.

# The autoscroll button and edits
{bmc autoscrollbuttonfalse.bmp} If autoscroll is disabled, the textures wont move. Of course, scroll speeds are not editable.
{bmc autoscrollbuttontrue.bmp} When enabled, autoscroll will move the current texture of the material with the specified speed. This means the specified speed will be the same for all textures in the list. It is expressed in texture dimension percentage per frame (the base is a 60fps rate, i.e. 16.6% will cause a complete scroll cycle to occur in one second). In order to have a proper visual effect, the affected textures should have their tiling attributes enabled in the texture edition pane.

# $ The smoothing mode button
{bmc smoothingbuttongouraud.bmp} When “ Gouraud ” is displayed, the angles between  contiguous faces of an object will be smoothed.
{bmc smoothingbuttonflat.bmp} When “ Flat ” is displayed, angles between faces will be visible.

$ # The transparent flag button
{bmc transparentbuttontrue.bmp}{bmc transparentbuttonfalse.bmp}
When enabled, this attribute will force the material to be transparent halfway between opacity and invisibility. If it is not set, additional transparency coming from alpha sensitiveness will not be taken into account. For that reason, when alpha sensitiveness is enabled, transparency is enabled at the same time (but wont be disabled if alpha sensitiveness is).

# The color buttons
{bmc colorbuttons.bmp} The three buttons display the currently selected colours for the visual characteristics of the material. For the specular colour an additional information is required, the specular exponent. When clicking once on the coloured areas, you bring up a colour chooser dialog, with which you can define another colour. Once the colour has changed, it can be restored with the undo mechanism.
{bmc quartercolorchooserdialog.bmp}

# The specular exponent edit
{bmc specexpedit.bmp} This defines the hardness of the object : the higher the value, the less incident light will be diffused (a light spot will look smaller).

# The alpha sensitiveness button
{bmc alphabuttontrue.bmp}{bmc alphabuttonfalse.bmp}
This button makes the material sensitive to alpha components of lights. This means that the alpha channel of lights are added to the alpha channels of the materials colours. The resulting alpha coefficient will yield a transparency of the material. The lower the coefficient, the more transparent will be the material. In order for this characteristic to be active, the transparent characteristic must be enabled.

# The chrome checkbox
This attribute will generate a pseudo-metallic aspect on textured materials by warping the textures. The effect is best seen with contrasted textures, and will not be visible with uniform materials.

# The texture list dialog
{bml texturedialog.bmp} By default this dialog will list the textures that were loaded by the engine before the editor mode was entered. However, it is possible to make it list all available textures thanks to the “ Refresh ” button. Textures that are not currently loaded in the engine will appear with a different background, just as in the materials list view.

The aim of this dialog is to choose a texture in the proposed list. To do so simply highlight the texture of your choice, and close the dialog with “ OK ”. If you change your mind just click “ Cancel ”.

+ # $ The main material edition pane

The main pane for the current game material. From this pane you can select which set of game materials is displayed in the materials list view. You can also create, duplicate or destroy game materials.
{bmc Main.shg}

# The material file combo
All the files containing at least one loaded game material are listed here, sorted alphabetically. The materials list view will display all the game materials that the current file contains, whether they where effectively loaded or not. When some action in another editor causes materials from another file to be loaded (for example the creation of a model for a previously unloaded family), the file will be automatically added to this list.

# The material file purge button
{bmc purgebuttonenabled.bmp} when pressed, will cause any unused texture section to be removed from the script data. This button is enabled only if all the game materials of the current file were loaded by the engine. This can be done quickly with the material list view’s contextual menu.

# The material name edit
It displays the name of the currently edited game material. It also allows input to type the name of a new material. If the current content of the edit matches the name of an existing material, the creation and cloning buttons will be disabled. This is because two different materials cannot have the same name. If the edit is empty, a newly created game material would come with a default name.

# The material creation button
Press here to create a new game material. It will have the name currently in the edit, or a default name if it was empty. The newly created game material will only have default visual characteristics.

# The material duplication button
Press here to create a copy of the current game material. It will have the name currently in the edit, or a default name if it was empty. The newly created game material will receive a copy of the visual characteristics, and will share the other characteristics of the source game material.

# The material deletion button
Press here to delete the current game material. Its visual characteristics will be deleted as well. The other characteristics will not be deleted, so that they remain available for other game materials. Deletion is not available if the material is used somewhere in the loaded level. This means that all occurrences of the material you wish to delete must be removed before you can remove the material itself. The list of objects referencing this game material can be obtained from the coherence manager window.

+ # $ The mechanical characteristics edition pane

The mechanical characteristics of the game material describe how two objects will react when they are in contact. 
{bmc meca.shg}

# The numeric edit boxes of the mechanical characteristics
These edit boxes enable to enter numeric values between 0 and 1. The sliders are modified according to the value in the corresponding edit boxes. Go here to see an explanation of the different fields.

# The sliders of the mechanical characteristics
These sliders enable to modify the coefficients with the mouse. The edit boxes reflect the value selected by the corresponding slide bars. Go here to see an explanation of the different fields.

# The default mechanical characteristics
This button copies the values of the current mechanical characteristics. When another mechanical characteristic is created, it will contain the default values.

# Signification of the mechanical characteristic coefficients
blah blah blah

+ # $ The collision characteristics edition pane

The collision characteristics of the game material. These are mainly used by game materials referenced by collision zones.
{bmc collide.shg}

# The collision characteristics type
The collision characteristics belong to a certain type, related to collision zones. Hence you have to define which category of zones will collide faces using this material characteristics.

# The collision characteristics identifier checkboxes
These identify what the result of the collision will be for the owner of the colliding zone.

# The collision characteristics identifier names
These are labels that are referenced in the actors’ intelligence texts to select a subset of all the zones that collide it. These names can be edited and saved at will, but only if the safety catch is released.

# The collision names edition safety button
Since it is very easy to change text in an edit, a safety prevents you from doing it accidentally.
{bmc locknamesunlocked.bmp} The user can modify text at will in the edits, and save the changes.
{bmc locknamesunlocked.bmp} The user cannot edit text, and cannot save the changes.
Note : if the user unlocks edition, edits text, then locks edition again without saving, the changes wont be accounted for.

# The collision names save button
Since those names are not related to objects that can be found it the world, the modifications cannot be saved through the normal procedure. Hence this button. To save the names instantaneously just click it. If the name edition is locked, the save button is disabled.

+ $ # The texture edition pane

This pane was added when the textures developed new characteristics. When the visual materials directly referenced the texture bitmaps, some characteristics were stored in the texture file name. However, this was both impractical and limited. Therefore textures are now a bitmap and a set of characteristics. This pane was created in order to edit these characteristics, and can be henceforth considered as an embedded but quite independent editor.
{bmc texture.shg}

$ # The texture chooser button
When clicking once on this area, it opens a texture list dialog in which you can choose another texture for the visual  aspect of the game material. 
If the texture flag of the visual material edition pane is set to false, this area will become inactive. However, a texture may be displayed anyway, so that you can see which texture will be used in case the flag is set to true. 
{bml texturebutton_nontexturedmaterial.bmp}If the display looks like a rainbow, it means that no texture is assigned to the material, and only the colour attributes are relevant. 
{bml texturebutton_nomaterial.bmp}If the display is a red X, this means that no material is currently selected.
{bml texturebutton_texturedmaterial.bmp}Any other aspect will probably show the aspect of the texture for the current game material.

# The supply texture display toggle
Each texture can have a supply texture. When determining which textures will be loaded according to the available memory, a texture can be replaced by its supply texture, if there is one. This button enables to swap the edition between the primary and supply texture.

# The texture priority button
When determining which textures are to be retained, the engine tries to keep textures with the higher priority before replacing them with their supply texture. However, the button is present, but the priority attribute of the edited texture is neither modified nor saved when you click the button.

# The texture quality button
{bmc qualitybuttonlow.bmp}{bmc qualitybuttonnormal.bmp}{bmc qualitybuttonhigh.bmp}
When determining which textures are to be retained, the engine tries to keep textures with the higher quality before replacing them with their supply texture.

# The texture tiling checkboxes
The tiling attributes tell in which axis the texture will repeat itself on the affected faces. For some reason, this seems useful only with scrolling textures : the tiling attribute does not affect the aspect of faces that use a material that has this texture but with autoscroll disabled. For that reason, when the user enables autoscroll in the visual material edition pane, all the textures referenced in its list will get their tiling attribute set on both axis.

# The texture filtering checkboxes
These checkboxes tell which axis of the texture are to be filtered. This will cause smoothing to occur when the texture is close, so that there are no big squares when it is zoomed. The depth filtering is for details interpolation.

# The texture duration edit
This edit expresses the number of seconds during which the texture will be displayed by the current visual material. Although this characteristic is edited in the texture edition pane, it is not attached to the texture, but to the texture node in the material’s texture list. If the material has only one texture, the duration is irrelevant and cannot be edited.

+ # $ The sound characteristics edition pane

The sound characteristics of the game material. It is quite simple because the sound characteristics that can be chosen are referenced though identifiers, and the material editor does not know anything about their specificity. All it can do is select one, and the edition proper is done with the sound editor.
{bmc sound.shg}

# $ The game material editor interface

When the game material editor is activated, the screen looks like this. Just click anywhere to learn more about the editor.
{bmc FullScreen.shg}

# $ The main material edition pane
This pane enables you to select the file for which to edit materials. It also enables you to create, destroy or rename the current selected game material.
Go here for details.

$ # The visual characteristics edition pane
This pane enables you to modify the visual aspect of the material. When you modify something here, the 3D view will get updated so that you can see the changes (if an object using the edited material is visible, of course).
Go here for details.

$ # The mechanical characteristics edition pane
This pane enables you to modify the way an object will behave when colliding with another. The behaviour depends on the physical properties of the material.
Go here for details.

$ # The sound characteristics edition pane
This pane enables you to modify the way incident sounds will be altered when encountering an object using the material.
Go here for details.

$ # The collision characteristics edition pane
This pane enables you to tell which events will be triggered when a collision occurs with objects using this material.
Go here for details.

# The texture edition pane
This pane enables you to change some characteristics of the textures referenced by the materials.
Go here for details.

$ # The materials list view
This pane lists all available materials at a given moment. Selecting a material in this list will make the other panes display its properties. You can also drag materials from this list into the 3D view. A contextual menu enables to modify the aspect of this list.
Go here for details.

$ # The main 3D view
This view is where you can affect a material to an object. Simply drag a material from the materials list view and drop it on the item you want to modify. The material editor adds its own entries in the standard popup menu of the view. The Preferences menu is also affected when the material editor is active.

# The entries in the main view’s menu
{bml popupmenu_in_3dview.bmp}
The first entry closes the material editor and returns to the hierarchy editor.
The second entry drops the current material on the object that was under the cursor when the menu was opened, and not where the cursor is when you select this entry.
The third entry makes the edit panes display the content of the material that was under the cursor when the menu was invoked.

# The Preferences pulldown menu
{bml pulldownmenu.bmp} The first entry records the current dimensions of the panes as you see them. The next time you load the editors, the game material editor will come up with this screen configuration.
The second entry tells the current handling of the warning boxes that can pop-up quite often when entering the editors for the first time. The option cycles through Always, Once and Never, in that order.

# The material characteristics  copy button
This button is enabled only if a material characteristics is currently selected in the combo. This button causes the contents of the current material characteristics to be remembered, so that they can be pasted on another material characteristics.

# The material characteristics  paste button
This button is enabled only if a material characteristics is currently selected in the combo, and a material characteristics copy has been recorded with the copy button. This button causes the retained values to be pasted to the current material characteristics. Note that if you modify the values after they are pasted, another paste will still retain the originally copied values. Moreover, the modifications will not affect the material characteristics from which the values were copied.

# The material characteristics rename button
This button is enabled only if a material characteristics is currently selected in the combo, and the name typed in the combo does not already exist. This button causes the current material characteristics to be renamed with the contents of the edited text of the combo.

# The material characteristics selection combo
This combo lists all material characteristics that exist in the data file, whether they were loaded by the game or not. It is possible to make several game materials select the same material characteristics. Note that in this case, modifying the contents of the material characteristics will affect all game materials referencing it. The text in the combo can be edited. This enables to rename the current material characteristics with the. rename button.
# The material characteristics creation button
This button is off when no material characteristics is selected in the combo. In that case, clicking on it will create a new material characteristics, named from the current game material if possible, or with a default name otherwise.
If a material characteristics is selected in the combo, the button is on. In that case pressing on it will attempt to destroy it. If the current game material is the last one to reference the current materials characteristics, it will be destroyed. If some other game materials still reference it, the material characteristics will not be destroyed, but the current game material would no longer reference it. This would be equivalent to selecting the “ Nothing ” entry in the combo.

# The material characteristics highlighting color
In order to see in the main view which areas of the game are affected by a given materials characteristics, it is possible to highlight it with any colour. The checkmark tells if the current material characteristics is highlighted or not. When it is, the coloured area shows its colour. Clicking on its area brings out the standard windows colour chooser dialog. When the material characteristics is not highlighted, the coloured area is grey, and clicking on it has no effect.

+ # $ The materials list view
This is where you can select the current edited material. This list displays a series of boxes. Each box represents a game material for which a section exists. 
{bmc matlistview_displayall_bitmapandtext.bmp}
If the background of the box is green, the material is not referenced in the scene.
If the displayed image is some fancy thing (that depends on the editor’s version), the engine has not loaded the corresponding material.
If the displayed image is a rainbow, the game material is not textured.
This view also customises the standard popup menu and adds two entries.

# The material list view popup menu
{bml popupmenu_in_materiallistview.bmp}All the entries but the last two are standard, and I wont explain them.
The penultimate entry toggles the display mode. When checked, all materials are listed in the view, whether they are used in the scene or not. When unchecked, only the materials used in the scene are listed in the view, excepted when a new material is just created, in which case it will be listed anyway.
The last entry forces the engine to load all the materials listed in the view. Normally after that all the fancy bitmaps should be replaced by the actual texture of each material (if the materials are textured, of course). This is quite useful to convert and cleanup a file a little (see the purge command of the main edit pane for more information).

# Who can you thank for this wonderful editor ?

In fact there are three of us, all located in the Annecy subsidiary, Ubi Simulations.
 First Vincent Lhullier started to develop this editor. 
 Some time later, when the pressure fell down a bit on the actors editor I took up the material editor.
At some point, Yann Le Tensorer lent me a hand for some parts (I have no picture of him, though).

# The keyboard options

The material editor needs two keys to extend the operations it can perform (if one doesn’t count all the keys needed to enter text in the various panes ;-). Both modes are activated only when the corresponding key is depressed, and deactivated when it is released. These keys are entirely configurable in the standard keyboard configuration that can be found under Options / Configure Keyboard / Material editor. The default values are the CONTROL and SHIFT keys. The first one enables the picking mode, and the other one affects the way materials are dropped on objects.

# The keyboard picking mode, or “ How to select a game material in the 3D view to edit it ? ”

When the user moves the cursor around in the 3D view, the material editor displays in the status bar the name of the object under the cursor, and which material is on the face under the cursor. When the picking mode is enabled, clicking on the face will cause the material editor to update its panes with the contents of the picked material, so that the user can edit it. This operation has an equivalent in the 3D view’s contextual popup menu .

# The keyboard material drop mode, or “ How to drop a material on a single face of an object ? ”

In fact, you can always drop a material on an object. This mode just affects the way the material is used by the receiving object. To understand the purpose of this mode, I first must digress and explain how geometric objects are made. A geometric object is a compound of various elements, each element containing one or more items. There are different types of elements : spheres, boxes, lines... Depending on the type, the element may have a global game material, or a game material per item.
The type that interests us is the Indexed triangles type. This types groups many triangles in one element. These triangles share, among other things, the material with which they are displayed. This means that, when the user drops an material on any triangle of the element, all the triangles will be affected by the new material. Of course sometimes this is not what the user intended. Hence this mode that enables to drop the material one just the target triangle. This involves some modification in the structure of the owning geometric object, because the triangle has to be moved from its Indexed Triangle owner to a FaceMap Descriptor. The difference is that in the latter, each triangle has its own material, hence the other triangles, those that remain in the Index Triangle element, are not affected by the new material.

# How to create a new game material ?

Everything occurs in the main pane. The first thing you have to do is select in which file you want the new game material to be saved. Then it depends if you want to create an empty material, or a copy of an existing material. In that case you first have to select the game material from which you want to create a copy. Note that when you do this, the button performing the copy may not be available. This is because the name in the edit is an existing name, and it is not allowed to have two game materials with the same name in the same file. You can of course change the name to suit your needs, then click {bmc mainbuttonnew.bmp} to create a new empty material, or {bmc mainbuttonclone.bmp} to copy the currently selected material. Note that when created, the material name will be prepended with the user’s prefix.

# How to delete a game material ?

In fact it is quite simple : select the file in which it is stored, select the material in the material list, the press {bmc mainbuttondelete.bmp} in the main edition pane. The only thing is that quite often this button is disabled. The reason is quite simple : some objets in the scene use this game material, and the editor won’t authorise the deletion of the game material in that case. If you are sure you want to delete it, just find all the objects that use it and drop some other material on them until the material you want to delete becomes unreferenced. Then you will be able to delete it. The question is : how do you know that a game material is used in the scene ?

# How do I know if a game material is used in the scene ?

Well, just have a look in the material list view. If you see the material with a white background, it means that it is used. If the background is green, the material is not used in the scene.