Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
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.º 4
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.º 5
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.º 6
0
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;
}