Skip to main content
gamedev.net
🔒 Locked

Slow mesh loading

Started by AxelFR May 9, 2003 at 12:59 AM 1 replies 400+ views
Original Post
AxelFR
AxelFR
Hi, I have 25 Mesh Objects in my little Engine. The problem ist that it takes 10 Seconds to load or process or whatever these Mesh Files on my Athlon 2600. I load them directly from a ressource. Is this normal or can I do something to speedup the method. Here is the code:
  
bool D3DObjectClass::loadMesh(int mesh, LPDIRECT3DDEVICE8 *g_pD3DDevice)
{
	m_pD3DDevice = g_pD3DDevice;
	LPD3DXBUFFER pMaterialsBuffer = NULL;
	LPD3DXMESH pMesh = NULL;	
	if(FAILED(D3DXLoadMeshFromXResource(
		GetModuleHandle(NULL),
		MAKEINTRESOURCE(mesh),
		"Mesh",
		D3DXMESH_SYSTEMMEM,
		(*m_pD3DDevice),
		NULL,
		&pMaterialsBuffer,
		&m_dwNumMaterials,
		&pMesh)))
	{
		m_pMesh = NULL;
		m_pMeshMaterials = NULL;
		m_pMeshTextures = NULL;
		return false;
	}


    D3DXMATERIAL* matMaterials = (D3DXMATERIAL*)pMaterialsBuffer->GetBufferPointer();
	//Create two arrays. One to hold the materials and only to hold the textures

	m_pMeshMaterials = new D3DMATERIAL8[m_dwNumMaterials];
    m_pMeshTextures  = new LPDIRECT3DTEXTURE8[m_dwNumMaterials];

    for(DWORD m = 0; m < m_dwNumMaterials; m++)
    {
        // Copy the material

        m_pMeshMaterials[m] = matMaterials[m].MatD3D;

        // Set the ambient color for the material (D3DX does not do this)

		m_pMeshMaterials[m].Ambient = m_pMeshMaterials[m].Diffuse;
		cube_colour=0x10FFFFFF;

		// Create the texture

		if(matMaterials[m].pTextureFilename != NULL)
		{
			texture = ASTEROID_bmp;		}
		if(FAILED(D3DXCreateTextureFromResource((*m_pD3DDevice),NULL, 
                                            MAKEINTRESOURCE(texture), 
                                            &m_pMeshTextures[m])))
        {
            m_pMeshTextures[m] = NULL;
        }
		texture = false;
    }

    //We''ve finished with the material buffer, so release it

    SafeRelease(pMaterialsBuffer);

	
	//Make sure that the normals are setup for our mesh


	pMesh->CloneMeshFVF(D3DXMESH_MANAGED, MESH_D3DFVF_CUSTOMVERTEX, (*m_pD3DDevice), &m_pMesh);
	SafeRelease(pMesh);

	D3DXComputeNormals(m_pMesh, NULL);
	rot_x = 0;
	rot_y = 0;
	rot_z = 0;
	return true;
}
  
VladR
VladR
Although I dont have experience with X-files, your time seems to me pretty OK. In my engine, when loading 3D objects, I noticed great differences. When I just Parsed from ASE file, loading took 30 seconds on my TBird2100. But when I converted it to internal format that is ready to be put to Vertex Buffers, the time dropped to about 5 seconds. Reason ? ASE files had 25 MB in total, while my converted files had about 3 MB. Im already implementing some packing to get it down to 1,3 MB which should help tremendously - but that is something to benchmark.
I dont know about redundancy in Xfiles, but Id recommend converting them into your own format ready to be used with Vertex Buffers.

What is the total triangles count that you read from those files ?

VladR
Avenger game

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.