Creating Material Scripts
From Multiverse
| Creating and Importing Models |
|
Creating Assets • Creating Collision Volumes • Exporting Models to COLLADA • Targeting a Wide Range of Hardware • Model Conversion Tool • Creating Material Scripts |
| Using 3ds Max |
|
Using the 3ds Max Export Tool Creating Attachment Models Creating Morph Animations Transferring Biped Skeletons Implementing Vertex Lighting |
| Other Tools |
|
Blender: Static Model • Blender: Anim. Model • Blender Physics • DeleD: Static Model • DAZ Studio: Creating Characters • DAZ Studio: Avatars • Using Poser |
Contents |
Overview
The Model Conversion Tool converts 3D models in COLLADA format to the native Multiverse mesh format. This tool currently creates a material script based on information from the COLLADA file. You can customize these files to create more complex materials that enable you to run shaders on your model, change alpha blending, use multiple layers of textures, control lighting data or perform other similar effects. Occasionally, you will want to generate a basic material from scratch. The example below describes how to create a simple material script. The next section describes an alternate approach for simple materials, using a Windows batch script to create a new material file.
For a tutorial on editing material scripts, see the Platform Tutorial.
Best practices
When creating material scripts, follow these guidelines:
- If you have multiple meshes using materials that are the same except for the textures (and possibly a few other settings), build a base material and use the Copying Materials feature to create the model-specific material. Doing this will make most model-specific materials very simple, usually containing only "set_texture_alias" commands.
- If you create a base material that multiple material files will copy, add a number at the beginning of the material file name for the base material (we use "00") so that the engine will load it before the materials that reference it. For example, the sampleworld assets have a material file named
00SimpleLighting.material.
- Provide specific names for all techniques, passes, and texture units to make it easy for Python scripts to access them.
- If you have rendering techniques that require more advanced hardware, such as the more recent shader models, provide a fallback rendering technique that will work (with some visual degradation) on lower end hardware. For more information, see Techniques.
- If your material will be modified by script, make a separate Python script file that contains all the functions for editing the material. Your high-level game logic can then call these functions to make material changes. Keeping all the code related to material internals in one place will make future changes much easier.
Creating a basic material script
The example below is a simple material that applies a single texture to the model. To use this simple material script with your model, follow these steps:
- Copy and paste the code below into a text editor.
- Save the file with a name that matches your mesh. For example, if your mesh is called "goblin.mesh", then save the material script in a file called
goblin.material. - Edit the file to change the material name on the first line, "wolf.wolf_rig_019_wolf_phong1". The material name is in two parts, separated by a period. The first part is the name of the mesh file, minus the extension, so for "goblin.mesh", the first part would be "goblin". The second part is the name of the material assigned in the 3D modeling tool, for example "goblin_rig_013_goblin_phong1". Using that example, the material name would be "goblin.goblin_rig_013_goblin_phong1".
NOTE: If you do not know the name of the material assigned in the 3D tool, look in the DAE file, find the<material>tag, and look for theidattribute value. If this is still not correct, you can use the Model Viewer tool to see the material name. - Edit the file to change the texture file name (in this case "wolf_re.dds") to the name of the texture file for this model. You can use TGA or DDS textures.
- To use your model with the Multiverse tools, create an asset definition file using Asset Importer. For more information, see Creating asset definition files with Asset Importer.
The Multiverse asset repositories contain many more example material files .
For information on how to create more complex materials, see Material Scripts.
Example material script
Here is an example material file for the Multiverse wolf model:
material wolf.wolf_rig_019_wolf_phong1
{
technique
{
pass
{
shading phong
ambient 1.00000 1.00000 1.00000 1.00000
diffuse 1.00000 1.00000 1.00000 1.00000
specular 0.00000 0.00000 0.00000 1.00000
emissive 0.00000 0.00000 0.00000 1.00000
texture_unit
{
texture wolf_re.dds
tex_coord_set 0
}
}
}
}
Batch script to create a material file
The following Windows batch script, contributed by LuckyWolf19, creates a material script, given the name of the material in the mesh file and the associated texture file name.
NOTE: This batch script works with the software shader. It does not work for materials with more than one texture, or materials that use normal or specular maps,
To use it:
- In Windows Explorer, go to the
C:\Documents and Settings\YourLoginNamedirectory. By default, the command prompt window will start in this working directory, so creating the batch file here will make it easy to access. - Create a new text file, called
CreateMaterial.bat. An easy way to do this is to right-click, then choose New | Text Document. - Edit the file, then cut and paste the code below into the file.
- Edit the line
SET MaterialFile="C:\MVAssets\Materials\%1.material"
and changeC:\MVAssets\to the location of your asset repository. - Save and file, making sure the extension is still .bat (Notepad may try to change it to .txt).
- By putting it in this directory you can access it most time when entering the DOS window.
Use the batch script as follows:
CreateMaterial MaterialNameInMeshFile FullTextureNameInTextureDirectory
For example:
c:\Documents and Settings\Owner> CreateMaterial MyMaterialNameInMeshFile MyTexture.png
Batch script
:: This script is used to auto create a material file. You must pass in the name of the material
:: as defined by your .mesh file and your texture filename with extension
:: You must change the MaterialFile variable to the location of your asset repository directory.
:: PUBLIC DOMAIN USE - Created by Scott Peal, Peal Labs
@ECHO OFF
IF "%1"== "" GOTO NOFILE
IF "%2"== "" GOTO NOFILE
SET MaterialFile="C:\MVAssets\Materials\%1.material"
ECHO Creating file %MaterialFile%
ECHO material %1.material > %MaterialFile%
ECHO { >> %MaterialFile%
ECHO technique >> %MaterialFile%
ECHO { >> %MaterialFile%
ECHO pass >> %MaterialFile%
ECHO { >> %MaterialFile%
ECHO shading phong >> %MaterialFile%
ECHO. >> %MaterialFile%
ECHO ambient 1.00000 1.00000 1.00000 1.00000 >> %MaterialFile%
ECHO diffuse 1.00000 1.00000 1.00000 1.00000 >> %MaterialFile%
ECHO specular 0.00000 0.00000 0.00000 1.00000 0.00000 >> %MaterialFile%
ECHO emissive 0.00000 0.00000 0.00000 1.00000 >> %MaterialFile%
ECHO. >> %MaterialFile%
ECHO texture_unit >> %MaterialFile%
ECHO { >> %MaterialFile%
ECHO texture %2 >> %MaterialFile%
ECHO tex_coord_set 0 >> %MaterialFile%
ECHO } >> %MaterialFile%
ECHO } >> %MaterialFile%
ECHO } >> %MaterialFile%
ECHO } >> %MaterialFile%
GOTO END
:NOFILE
ECHO.
ECHO ERROR:
ECHO You have to provide a material name first and the texture file name second (with extension)
ECHO Example: CreateMaterial myMaterialName myTexture.png
ECHO.
:END
