bool MA_ParseEdge(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->edges) { pMesh->numEdges = header->size; pMesh->edges = (idVec3 *)Mem_Alloc( sizeof( idVec3 ) * pMesh->numEdges ); } //Get the start and end index for this attribute int minIndex, maxIndex; if(!MA_ParseHeaderIndex(header, minIndex, maxIndex, "EdgeHeader", NULL)) { //This was just a header return true; } //Read each vert for(int i = minIndex; i <= maxIndex; i++) { pMesh->edges[i].x = parser.ParseFloat(); pMesh->edges[i].y = parser.ParseFloat(); pMesh->edges[i].z = parser.ParseFloat(); } return true; }
bool MA_ParseColor(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->colors) { pMesh->numColors = header->size; pMesh->colors = (byte *)Mem_Alloc( sizeof( byte ) * pMesh->numColors * 4 ); } //Get the start and end index for this attribute int minIndex, maxIndex; if(!MA_ParseHeaderIndex(header, minIndex, maxIndex, "ColorHeader", NULL)) { //This was just a header return true; } //Read each vert for(int i = minIndex; i <= maxIndex; i++) { pMesh->colors[i*4] = parser.ParseFloat() * 255; pMesh->colors[i*4+1] = parser.ParseFloat() * 255; pMesh->colors[i*4+2] = parser.ParseFloat() * 255; pMesh->colors[i*4+3] = parser.ParseFloat() * 255; } return true; }
bool MA_ParseTVert( idParser &parser, maAttribHeader_t *header ) { maMesh_t *pMesh = &maGlobal.currentObject->mesh; idToken token; //This is not the texture coordinates. It is just the name so ignore it if( strstr( header->name, "uvsn" ) ) { return true; } //Allocate enough space for all the data if( !pMesh->tvertexes ) { pMesh->numTVertexes = header->size; pMesh->tvertexes = ( idVec2 * ) Mem_Alloc( sizeof( idVec2 ) * pMesh->numTVertexes ); } //Get the start and end index for this attribute int minIndex, maxIndex; if( !MA_ParseHeaderIndex( header, minIndex, maxIndex, "TextureCoordHeader", "uvsp" ) ) { //This was just a header return true; } parser.ReadToken( &token ); if( !token.Icmp( "-" ) ) { idToken tk2; parser.ReadToken( &tk2 ); if( !tk2.Icmp( "type" ) ) { parser.SkipUntilString( "float2" ); } else { parser.UnreadToken( &tk2 ); parser.UnreadToken( &token ); } } else { parser.UnreadToken( &token ); } //Read each tvert for( int i = minIndex; i <= maxIndex; i++ ) { pMesh->tvertexes[i].x = parser.ParseFloat(); pMesh->tvertexes[i].y = 1.0f - parser.ParseFloat(); } return true; }
bool MA_ParseNormal(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->normals) { pMesh->numNormals = header->size; pMesh->normals = (idVec3 *)Mem_Alloc( sizeof( idVec3 ) * pMesh->numNormals ); } //Get the start and end index for this attribute int minIndex, maxIndex; if(!MA_ParseHeaderIndex(header, minIndex, maxIndex, "NormalHeader", NULL)) { //This was just a header return true; } parser.ReadToken(&token); if(!token.Icmp("-")) { idToken tk2; parser.ReadToken(&tk2); if(!tk2.Icmp("type")) { parser.SkipUntilString("float3"); } else { parser.UnreadToken(&tk2); parser.UnreadToken(&token); } } else { parser.UnreadToken(&token); } //Read each vert for(int i = minIndex; i <= maxIndex; i++) { pMesh->normals[i].x = parser.ParseFloat(); //Adjust the normals for the change in coordinate systems pMesh->normals[i].z = parser.ParseFloat(); pMesh->normals[i].y = -parser.ParseFloat(); pMesh->normals[i].Normalize(); } pMesh->normalsParsed = true; pMesh->nextNormal = 0; return true; }
bool MA_ParseVertexTransforms(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->vertTransforms) { if(header->size == 0) { header->size = 1; } pMesh->numVertTransforms = header->size; pMesh->vertTransforms = (idVec4 *)Mem_Alloc( sizeof( idVec4 ) * pMesh->numVertTransforms ); pMesh->nextVertTransformIndex = 0; } //Get the start and end index for this attribute int minIndex, maxIndex; if(!MA_ParseHeaderIndex(header, minIndex, maxIndex, "VertexTransformHeader", NULL)) { //This was just a header return true; } parser.ReadToken(&token); if(!token.Icmp("-")) { idToken tk2; parser.ReadToken(&tk2); if(!tk2.Icmp("type")) { parser.SkipUntilString("float3"); } else { parser.UnreadToken(&tk2); parser.UnreadToken(&token); } } else { parser.UnreadToken(&token); } //Read each vert for(int i = minIndex; i <= maxIndex; i++) { pMesh->vertTransforms[pMesh->nextVertTransformIndex].x = parser.ParseFloat(); pMesh->vertTransforms[pMesh->nextVertTransformIndex].z = parser.ParseFloat(); pMesh->vertTransforms[pMesh->nextVertTransformIndex].y = -parser.ParseFloat(); //w hold the vert index pMesh->vertTransforms[pMesh->nextVertTransformIndex].w = i; pMesh->nextVertTransformIndex++; } return true; }
bool MA_ReadVec3(idParser& parser, idVec3& vec) { idToken token; if(!parser.SkipUntilString("double3")) { throw idException( va("Maya Loader '%s': Invalid Vec3", parser.GetFileName()) ); } //We need to flip y and z because of the maya coordinate system vec.x = parser.ParseFloat(); vec.z = parser.ParseFloat(); vec.y = parser.ParseFloat(); return true; }
/* ================ sdDeclDamageFilter::ParseFilter ================ */ bool sdDeclDamageFilter::ParseFilter( damageFilter_t& filter, idParser& src ) { idToken token; if( !src.ReadToken( &token ) || token.Cmp( "{" ) ) { return false; } while ( true ) { if ( !src.ReadToken( &token ) ) { return false; } if ( !token.Cmp( "}" ) ) { break; } if( !token.Icmp( "damage" ) ) { bool error; filter.damage = src.ParseFloat( &error ); if ( error ) { src.Error( "sdDeclDamageFilter::ParseLevel Invalid Parm for 'damage'" ); return false; } if ( src.PeekTokenString( "%" ) ) { src.ReadToken( &token ); filter.mode = DFM_PERCENT; } else { filter.mode = DFM_NORMAL; } } else if( !token.Icmp( "target" ) ) { if ( !src.ReadToken( &token ) ) { src.Error( "sdDeclDamageFilter::ParseLevel Missing Parm for 'target'" ); return false; } filter.target = gameLocal.declTargetInfoType.LocalFind( token, false ); if ( !filter.target ) { src.Error( "sdDeclDamageFilter::ParseLevel Invalid Target '%s'", token.c_str() ); return false; } } else if( !token.Icmp( "noScale" ) ) { filter.noScale = true; } else { src.Error( "sdDeclDamageFilter::ParseLevel Unknown Parameter %s", token.c_str() ); return false; } } return true; }
/* ============ sdDemoCamera_Fixed::Parse ============ */ bool sdDemoCamera_Fixed::Parse( idParser& src ) { if ( !src.ExpectTokenString( "{" ) ) { return false; } idToken token; while( true ) { if ( !src.ExpectAnyToken( &token ) ) { return false; } if ( !token.Cmp( "}" ) ) { break; } else if ( !token.Icmp( "origin" ) ) { if ( !src.Parse1DMatrix( 3, origin.ToFloatPtr() ) ) { return false; } } else if ( !token.Icmp( "axis" ) ) { if ( !src.Parse2DMatrix( 3, 3, axis.ToFloatPtr() ) ) { return false; } } else if ( !token.Icmp( "angles" ) ) { idAngles angles; if ( !src.Parse1DMatrix( 3, angles.ToFloatPtr() ) ) { return false; } axis = angles.ToMat3(); } else if ( !token.Icmp( "fov" ) ) { fov = src.ParseFloat(); } else if ( !sdDemoCamera::ParseKey( token, src ) ) { src.Error( "sdDemoCamera_Fixed::Parse : Unknown keyword '%s'", token.c_str() ); return false; } } return true; }