Game Development Reference
In-Depth Information
if (materialCount){
materials = new MATERIAL[materialCount];
memset(materials, 0, sizeof(MATERIAL)*materialCount);
if (!materials) return FALSE;
for (i=0; i<materialCount; i++){
if (!ReadMaterial(file, i)) return FALSE;
}
}
return TRUE;
}
The ReadMaterial function takes two parameters, the ASE file and the
current material number. The first step is to build a string of the form
MATERIAL n , where n is the current material number. If the token is found
then we get the section end and enter a loop that is terminated when the
file position exceeds the section end. In the loop we read and parse the
tokens MATERIAL_NAME, MATERIAL_DIFFUSE, MATERIAL_SPEC-
ULAR, MATERIAL_TRANSPARENCY, MAP_DIFFUSE and NUM-
SUBMTLS. Most of these tags are easy to follow involving a call to
ParseTokens and then a conversion of the tokens to integers or floats.
MAP_DIFFUSE is itself a subsection, but since this parser only accesses
the BITMAP file name it is read directly. First, a new texture is created and
initialized to zero. Then a search is made for the token BITMAP. If the
token is found then the filename is stored in the TEXTURE structure. The
token NUMSUBMTLS gives the number of sub-materials in the current
material. If this is found then memory is allocated for these sub-materials
and then each sub-material is read using the ReadSubMaterial
function.
BOOL C3DSAscii::ReadMaterial(CStdioFile &file, int matnum)
{
CString line,tmp;
int start,end;
TOKEN tokens[5];
if (matnum>(materialCount-1)) return FALSE;
tmp.Format("MATERIAL %i",matnum);
if (!FindToken(file, line, (LPCTSTR)tmp)) return FALSE;
start = file.GetPosition();
end = GetSectionEnd(file);
while(file.GetPosition()<(UINT)end){
Search Nedrilad ::




Custom Search