Example #1
0
void main ()
{
	char filename[64];
	FILE *f;
	int meshes=0;
	long start=0, end=0, last=0;
	mdh_tempholder temp[MAX_MESHES];

	printf("WARNING TEXTURE NAMES LACK EXTENSTION!\nASE -> DH Convert v%d\n\n", VERSION);

	printf ("Enter File name : ");
	scanf("%s", filename);

	if (f = fopen(filename, "r"))
	{
		while (FindNextToken(f, "*GEOMOBJECT", last, &start, &end))
		{
			char	str[64], meshname[64];
			char	texture[64];
			int		*faces, *tfaces;
			float	*verts, *vnorms, *tverts = NULL;
			int		numverts=0, numfaces=0, numtverts=0, numtfaces=0;
			int		mesh_no, s, e;
			// maybe get texture
			mesh_no = meshes++;

			
			GetName(f, str, start, end);
			str[strlen(str)-1] = 0;
			sscanf(str, "\"%s", meshname);
			// TODO : if tag remove! and add tag vectors at end of file
			//sprintf(texture, "%s.nfo", meshname);
			strcpy(texture, meshname);
			printf("Reading node %s.\n", meshname);

			GetInfo(f, start, end, 
				&numverts, &numfaces, &numtverts, &numtfaces);
			// Allocate
			faces = (int *)malloc (numfaces * 3 * sizeof(int));
			verts =	(float *)malloc (numverts * 3 * sizeof(float));
			vnorms = (float *)malloc (numverts * 3 * sizeof(float));
			if (numtverts)
				tverts = (float *)malloc (numtverts * 3 * sizeof(float));
			if (numtfaces)
				tfaces = (int *)malloc (numtfaces * 3 * sizeof(int));

			// get the data
			printf("MESH_VERTEX_LIST ");
			FindNextToken(f, "*MESH_VERTEX_LIST", start, &s, &e);
			GetVerts(f, verts, s, e);

			printf("MESH_FACE_LIST ");
			FindNextToken(f, "*MESH_FACE_LIST", start, &s, &e);
			GetFaces(f, faces, s, e);

			printf("MESH_NORMALS ");
			FindNextToken(f, "*MESH_NORMALS", start, &s, &e);
			GetVNorms(f, vnorms, s, e);

			// Only these are optional
			if (numtverts) {
				printf("MESH_TVERTLIST ");
				FindNextToken(f, "*MESH_TVERTLIST", start, &s, &e);
				GetTVerts(f, tverts, s, e);
			}
			if (numtfaces) {
				printf("MESH_TFACELIST ");
				FindNextToken(f, "*MESH_TFACELIST", start, &s, &e);
				GetTFaces(f, tfaces, s, e);	
			}	
			printf("\n");
			rewind(f);
			last = end;
			
			// store them for a mo
			strcpy (temp[mesh_no].name, meshname);
			strcpy (temp[mesh_no].texture, texture);
			
			temp[mesh_no].num_faces = numfaces;
			temp[mesh_no].num_verts = numverts;

			temp[mesh_no].faces = faces;
			temp[mesh_no].verts = verts;
			temp[mesh_no].norms = vnorms;
			if (numtverts)
				temp[mesh_no].tverts = tverts;
			else
				temp[mesh_no].tverts = NULL;
			// Dunno if i need t verts
		}

		fclose(f);
		
		filename[strlen(filename)-3] = 0;
		strcat(filename, "dh4");
		if (f = fopen(filename, "wb"))
		{
			int i;
			WriteDH4(f, meshes, temp);
			fclose(f);

			for (i = 0; i < meshes; i++)
			{
				free (temp[i].faces);
				free (temp[i].verts);
				free (temp[i].norms);
				if (temp[i].tverts)
					free (temp[i].tverts);
			}

		}
	}
}
Example #2
0
int MyMeshText::CreateString(bool concat, float fontheight, float x, float y, float z, float rotz, unsigned char justificationflags, ColorByte color, Vector2 size, const char* text, ...)
{
    assert( m_pFont && m_pFont->m_pFont );

    if( strlen( text ) == 0 )
        return 0;

    const char* stringtodraw = text;
    if( g_pLanguageTable != 0 && text[0] == '.' )
        stringtodraw = g_pLanguageTable->LookUp( text );

    int numlines = 0;

    if( concat == false )
    {
        ClearText();
    }

    bool moretexttocome = true;
    const char* stringpos = stringtodraw;

    while( moretexttocome )
    {
        numlines++;

        char singlelinebuffer[300];
        singlelinebuffer[0] = 0;
        char* singlelinebufferpos = singlelinebuffer;

        // word wrap if width of text is not 0.
        if( size.x != 0 )
        {
            float linewidth = -1;// = GetStringSize( fontheight, Vector2(0,0), singlelinebuffer ).x;
            while( linewidth < size.x &&
                    *stringpos != 0 )
            {
                *singlelinebufferpos = *stringpos;
                singlelinebufferpos++;
                *singlelinebufferpos = 0;
                stringpos++;

                linewidth = GetStringSize( fontheight, Vector2(0,0), singlelinebuffer ).x;

                assert( singlelinebufferpos < singlelinebuffer + 300 );
            }

            int numcharswewentback = 0;
            while( ( *(singlelinebufferpos-1) != ' ' && *stringpos != 0 ) &&
                    singlelinebufferpos > singlelinebuffer )
            {
                singlelinebufferpos--;
                numcharswewentback++;
            }

            if( singlelinebufferpos != singlelinebuffer )
            {
                *singlelinebufferpos = 0;
                stringpos -= numcharswewentback;
            }

            if( *stringpos == 0 )
                moretexttocome = false;

            stringtodraw = singlelinebuffer;
        }
        else
        {
            moretexttocome = false;
        }
            
        //// don't bother drawing if fontheight is zero... still doing logic above so the currect number of lines will be returned.
        //if( g_pRTQGlobals->m_WordWrapCountLinesOnly )
        //    continue;

        Vertex_XYZUV_RGBA* pVertsToDraw = (Vertex_XYZUV_RGBA*)GetVerts( true );

        int newverts = (int)strlen( stringtodraw ) * 4;
#if _DEBUG
        m_MostLettersAttemptedToDrawThisFrame += newverts/4;
        if( m_MostLettersAttemptedToDrawThisFrame > m_MostLettersAttemptedToDrawEver )
            m_MostLettersAttemptedToDrawEver = m_MostLettersAttemptedToDrawThisFrame;
#endif

        if( m_NumVertsToDraw + newverts > GetNumVerts() )
        {
#if _DEBUG
            LOGInfo( LOGTag, "TextMesh buffer isn't big enough for string (%s) - %d of %d letters used - most letters needed (%d)\n", stringtodraw, m_NumVertsToDraw/4, GetNumVerts()/4, m_MostLettersAttemptedToDrawEver );
#endif
            //assert( false ); // drawing more than we have room for.
            return 0;
        }

        pVertsToDraw += m_NumVertsToDraw;

        unsigned int textstrlen = m_pFont->m_pFont->GenerateVerts( stringtodraw, true, pVertsToDraw, fontheight, GL_TRIANGLES, justificationflags, color );

        m_NumVertsToDraw += (unsigned short)(textstrlen * 4);
        m_NumIndicesToDraw += textstrlen * 6;

        MyMatrix position;
        position.SetIdentity();
        position.Rotate( rotz, 0, 0, 1 );
        position.SetPosition( x, y - (numlines-1)*fontheight, z );
        //position.SetPosition( x, y - (numlines-1)*g_pRTQGlobals->m_WordWrapLineIncSize, z );
        //position.SetPosition( x, y, z );

        for( unsigned int i=0; i<textstrlen*4; i++ )
        {
            Vector3 out = position.TransformVector3( *(Vector3*)&pVertsToDraw[i].x );
            pVertsToDraw[i].x = out.x;
            pVertsToDraw[i].y = out.y;
            pVertsToDraw[i].z = out.z;
        }
    }

    return numlines;
}
Example #3
0
void ase_model::Load(char *file_name)
{

	long start = 0, end = 0, last = 0;
	FILE *f;

	if (f = fopen(file_name, "r"))
	{
		int		mesh_no = 0;
		no_meshes = 0;
		while (FindNextToken(f, "*GEOMOBJECT", last, &start, &end))
		{
			no_meshes++;
			last = end;
		}

		rewind(f);
		mesh = new ase_mesh_t [no_meshes];
		start = 0; 
		end = 0; 
		last = 0;

		while (FindNextToken(f, "*GEOMOBJECT", last, &start, &end))
		{
			char	str[64];
			long	s, e;
			// maybe get texture

			
			GetName(f, str, start, end);
			str[strlen(str)-1] = 0;
	//		sscanf(str, "\"%s", mesh->name);
			strcpy(mesh[mesh_no].name, str+1);

			//printf("Reading node %s.\n", meshname);

			GetInfo(f, start, end, 
				&mesh[mesh_no].numverts, &mesh[mesh_no].numfaces, 
				&mesh[mesh_no].numtverts, &mesh[mesh_no].numtfaces);
			// Allocate
			mesh[mesh_no].faces = new int[mesh[mesh_no].numfaces * 3];
			mesh[mesh_no].verts = new float[mesh[mesh_no].numverts * 3];
			mesh[mesh_no].vnorms = new float[mesh[mesh_no].numverts * 3];
			if (mesh[mesh_no].numtverts)
				mesh[mesh_no].tverts = new float[mesh[mesh_no].numtverts * 3];
			if (mesh[mesh_no].numtfaces)
				mesh[mesh_no].tfaces = new int[mesh[mesh_no].numtfaces * 3];

			// get the data
			//printf("MESH_VERTEX_LIST ");
			FindNextToken(f, "*MESH_VERTEX_LIST", start, &s, &e);
			GetVerts(f, mesh[mesh_no].verts, s, e);

			//printf("MESH_FACE_LIST ");
			FindNextToken(f, "*MESH_FACE_LIST", start, &s, &e);
			GetFaces(f, mesh[mesh_no].faces, s, e);

			//printf("MESH_NORMALS ");
			FindNextToken(f, "*MESH_NORMALS", start, &s, &e);
			GetVNorms(f, mesh[mesh_no].vnorms, s, e);

			// Only these are optional
			if (mesh[mesh_no].numtverts) {
			//	printf("MESH_TVERTLIST ");
				FindNextToken(f, "*MESH_TVERTLIST", start, &s, &e);
				GetTVerts(f, mesh[mesh_no].tverts, s, e);
			}
			if (mesh[mesh_no].numtfaces) {
			//	printf("MESH_TFACELIST ");
				FindNextToken(f, "*MESH_TFACELIST", start, &s, &e);
				GetTFaces(f, mesh[mesh_no].tfaces, s, e);	
			}	
			//printf("\n");
			rewind(f);
			last = end;
			mesh_no++;
			
		}

		fclose(f);
	}

}