Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
void MA_ParseFileNode( idParser &parser )
{

	//Get the header info from the node
	maNodeHeader_t	header;
	MA_ParseNodeHeader( parser, &header );
	
	//Read the transform attributes
	idToken token;
	
	while( parser.ReadToken( &token ) )
	{
		if( IsNodeComplete( token ) )
		{
			parser.UnreadToken( &token );
			break;
		}
		
		if( !token.Icmp( "setAttr" ) )
		{
			maAttribHeader_t attribHeader;
			MA_ParseAttribHeader( parser, &attribHeader );
			
			if( strstr( attribHeader.name, ".ftn" ) )
			{
				parser.SkipUntilString( "string" );
				parser.ReadToken( &token );
				
				if( !token.Icmp( "(" ) )
				{
					parser.ReadToken( &token );
				}
				
				maFileNode_t *fileNode;
				fileNode = ( maFileNode_t * ) Mem_Alloc( sizeof( maFileNode_t ) );
				strcpy( fileNode->name, header.name );
				strcpy( fileNode->path, token.c_str() );
				
				maGlobal.model->fileNodes.Set( fileNode->name, fileNode );
			}
			else
			{
				parser.SkipRestOfLine();
			}
		}
	}
}
Ejemplo n.º 6
0
/*
================
sdDeclToolTip::ParseTimeline
================
*/
bool sdDeclToolTip::ParseTimeline( idParser& src ) {
	idToken token;

	src.SkipUntilString( "{", &token );

	while ( true ) {
		if( !src.ReadToken( &token ) ) {
			return false;
		}

		if ( !token.Icmp( "onTime" ) ) {
		
			src.ReadToken( &token );

			int time;
			if ( token.type == TT_NUMBER ) {
				time = ( token.GetIntValue() / 100.0f ) * GetLength();
			} else if ( token.type == TT_NAME && !token.Icmp( "end" )  ) {
				time = TLTIME_END;
			} else {
				src.Error( "sdDeclToolTip::ParseTimeline number expected for 'onTime'" );
				return false;
			}

			timelinePair_t event;
			event.first = time;

			if ( timeline.Num() > 0 ) {
				timelinePair_t lastEvent = timeline.Back();
				if ( lastEvent.first > time && time != TLTIME_END ) {
					src.Error( "sdDeclToolTip::ParseTimeline time  events must be in increasing order: '%i'", time );
					return false;
				}
			}

			src.ReadToken( &token );

			if ( !token.Icmp( "guiEvent" ) ) {
				
				event.second.eventType = TL_GUIEVENT;

				if( !src.ExpectTokenType( TT_STRING, 0, &token ) ) {
					src.Error( "sdDeclToolTip::ParseTimeline string expected after 'guiEvent'" );
					return false;
				}

				event.second.arg1 = token;

			} else if ( !token.Icmp( "pause" ) ) {
				event.second.eventType = TL_PAUSE;
			} else if ( !token.Icmp( "unpause" ) ) {
				event.second.eventType = TL_UNPAUSE;
			} else if ( !token.Icmp( "showInventory" ) ) {

				event.second.eventType = TL_SHOWINVENTORY;

				if( !src.ExpectTokenType( TT_STRING, 0, &token ) ) {
					src.Error( "sdDeclToolTip::ParseTimeline string expected after 'guiEvent'" );
					return false;
				}

				event.second.arg1 = token;

			} else if ( !token.Icmp( "hideInventory" ) ) {
				event.second.eventType = TL_HIDEINVENTORY;
			} else if ( !token.Icmp( "waypointHighlight" ) )  {

				event.second.eventType = TL_WAYPOINTHIGHLIGHT;

				if( !src.ExpectTokenType( TT_STRING, 0, &token ) ) {
					src.Error( "sdDeclToolTip::ParseTimeline string expected after 'guiEvent'" );
					return false;
				}

				event.second.arg1 = token;

			} else if ( !token.Icmp( "lookAtTask" ) ) {

				event.second.eventType = TL_LOOKATTASK;

			} else {
				src.Error( "sdDeclToolTip::ParseTimeline unexpected timeline event '%s'", token.c_str() );
				return false;
			}


			timeline.Append( event );

		} else if ( !token.Icmp( "unpauseWeaponSlot" ) ) {

			if( !src.ExpectTokenType( TT_NUMBER, 0, &token ) ) {
				src.Error( "sdDeclToolTip::ParseTimeline number expected after 'unpauseWeaponSlot'" );
				return false;
			}

			unpauseWeaponSlot = token.GetIntValue();

			if ( unpauseWeaponSlot > 9 || unpauseWeaponSlot < 0 ) {
				src.Warning( "sdDeclToolTip::ParseTimeline 0-9 expected as value for 'unpauseWeaponSlot'" );
				unpauseWeaponSlot = -1;
			}

			unpauseKeyString.SetKey( va( "_weapon%i", unpauseWeaponSlot - 1 ) );

		} else if( !token.Cmp( "}" ) ) {

			break;

		} else {

			src.Error( "sdDeclToolTip::ParseTimeline Invalid Token '%s'", token.c_str() );
			return false;

		}
	}

	return true;
}