bool MA_ParseAttribHeader(idParser &parser, maAttribHeader_t* header) { idToken token; memset(header, 0, sizeof(maAttribHeader_t)); parser.ReadToken(&token); if(!token.Icmp("-")) { parser.ReadToken(&token); if (!token.Icmp("s")) { header->size = parser.ParseInt(); parser.ReadToken(&token); } } strcpy(header->name, token.c_str()); return true; }
/* ============ sdDemoCamera_Anim::Parse ============ */ bool sdDemoCamera_Anim::Parse( idParser& src ) { if ( !src.ExpectTokenString( "{" ) ) { return false; } idToken token; int cycle = 1; idVec3 offset( vec3_origin ); while( true ) { if ( !src.ExpectAnyToken( &token ) ) { return false; } if ( !token.Cmp( "}" ) ) { break; } else if ( !token.Icmp( "anim" ) ) { if ( !src.ExpectAnyToken( &token ) ) { return false; } if ( !cameraMD5.LoadAnim( token ) ) { return false; } } else if ( !token.Icmp( "cycle" ) ) { cycle = src.ParseInt(); } else if ( !token.Icmp( "offset" ) ) { if ( !src.Parse1DMatrix( 3, offset.ToFloatPtr() ) ) { return false; } } else if ( !sdDemoCamera::ParseKey( token, src ) ) { src.Error( "sdDemoCamera_Anim::Parse : Unknown keyword '%s'", token.c_str() ); return false; } } if ( !cycle ) { cycle = 1; } cameraMD5.SetCycle( cycle ); cameraMD5.SetOffset( offset ); return true; }
bool MA_ParseFace(idParser& parser, maAttribHeader_t* header) { maMesh_t* pMesh = &maGlobal.currentObject->mesh; idToken token; //Allocate enough space for all the verts if this is the first attribute for verticies if(!pMesh->faces) { pMesh->numFaces = header->size; pMesh->faces = (maFace_t *)Mem_Alloc( sizeof( maFace_t ) * pMesh->numFaces ); } //Get the start and end index for this attribute int minIndex, maxIndex; if(!MA_ParseHeaderIndex(header, minIndex, maxIndex, "FaceHeader", NULL)) { //This was just a header return true; } //Read the face data int currentFace = minIndex-1; while(parser.ReadToken(&token)) { if(IsNodeComplete(token)) { parser.UnreadToken(&token); break; } if(!token.Icmp("f")) { int count = parser.ParseInt(); if(count != 3) { throw idException(va("Maya Loader '%s': Face is not a triangle.", parser.GetFileName())); } //Increment the face number because a new face always starts with an "f" token currentFace++; //We cannot reorder edges until later because the normal processing //assumes the edges are in the original order pMesh->faces[currentFace].edge[0] = parser.ParseInt(); pMesh->faces[currentFace].edge[1] = parser.ParseInt(); pMesh->faces[currentFace].edge[2] = parser.ParseInt(); //Some more init stuff pMesh->faces[currentFace].vertexColors[0] = pMesh->faces[currentFace].vertexColors[1] = pMesh->faces[currentFace].vertexColors[2] = -1; } else if(!token.Icmp("mu")) { /* int uvstIndex = */ parser.ParseInt(); int count = parser.ParseInt(); if(count != 3) { throw idException(va("Maya Loader '%s': Invalid texture coordinates.", parser.GetFileName())); } pMesh->faces[currentFace].tVertexNum[0] = parser.ParseInt(); pMesh->faces[currentFace].tVertexNum[1] = parser.ParseInt(); pMesh->faces[currentFace].tVertexNum[2] = parser.ParseInt(); } else if(!token.Icmp("mf")) { int count = parser.ParseInt(); if(count != 3) { throw idException(va("Maya Loader '%s': Invalid texture coordinates.", parser.GetFileName())); } pMesh->faces[currentFace].tVertexNum[0] = parser.ParseInt(); pMesh->faces[currentFace].tVertexNum[1] = parser.ParseInt(); pMesh->faces[currentFace].tVertexNum[2] = parser.ParseInt(); } else if(!token.Icmp("fc")) { int count = parser.ParseInt(); if(count != 3) { throw idException(va("Maya Loader '%s': Invalid vertex color.", parser.GetFileName())); } pMesh->faces[currentFace].vertexColors[0] = parser.ParseInt(); pMesh->faces[currentFace].vertexColors[1] = parser.ParseInt(); pMesh->faces[currentFace].vertexColors[2] = parser.ParseInt(); } } return true; }