Jump to content
  • Advertisement
Sign in to follow this  
Ksingh30

Meshes

This topic is 4768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok im having problem loading meshes. I can get it to load from .X file but its all glitchy and messed up. its suppose to look like the left, but on the right you can see its not rendering properly. http://roger.inkandpixel.com/badload.gif please help
HRESULT hr = 0;
	//
	// Load the XFile data.
	//

	ID3DXBuffer* adjBuffer  = 0;
	ID3DXBuffer* mtrlBuffer = 0;
	DWORD        numMtrls   = 0;

	hr = D3DXLoadMeshFromX(  
		_name,
		D3DXMESH_MANAGED,
		_device,
		&adjBuffer,
		&mtrlBuffer,
		0,
		&numMtrls,
		&Mesh);


	//
	// Extract the materials, and load textures.
	//

	if( mtrlBuffer != 0 && numMtrls != 0 )
	{
		D3DXMATERIAL* mtrls = (D3DXMATERIAL*)mtrlBuffer->GetBufferPointer();

		for(int i = 0; i < numMtrls; i++)
		{
			// the MatD3D property doesn't have an ambient value set
			// when its loaded, so set it now:
			mtrls.MatD3D.Ambient = mtrls.MatD3D.Diffuse;

			// save the ith material
			Mtrls.push_back( mtrls.MatD3D );

			// check if the ith material has an associative texture
			if( mtrls.pTextureFilename != 0 )
			{
				// load the texture for the ith subset
				IDirect3DTexture9* tex = 0;
				D3DXCreateTextureFromFile(
					_device,
					mtrls.pTextureFilename,
					&tex);

				// save the loaded texture
				Textures.push_back( tex );
			}
			else
			{
				// no texture for the ith subset
				Textures.push_back( 0 );
			}
		}
	}
	delete mtrlBuffer; // done w/ buffer

	//
	// Optimize the mesh.
	//

	hr = Mesh->OptimizeInplace(		
		D3DXMESHOPT_ATTRSORT |
		D3DXMESHOPT_COMPACT  |
		D3DXMESHOPT_VERTEXCACHE,
		(DWORD*)adjBuffer->GetBufferPointer(),
		0, 0, 0);

	delete adjBuffer; // done w/ buffer


Share this post


Link to post
Share on other sites
Advertisement
First of all, do not delete the buffers! Use Release().
Try skipping optimization for now.
Then I would recommend not using STL (or whatever you're using there), you can store materials/textures like that:

// ID3DXBuffer* mtrlBuffer;

D3DMATERIAL* mats = new D3DMATERIAL [numMtrls];
IDirect3DTexture9** textures = new IDirect3DTexture9* [numMtrls];

D3DXMATERIAL bufPtr = (D3DXMATERIAL) mtrlBuffer->GetBufferPointer ();

for ( int i = 0; i < numMtrls; i++ )
{
mats = bufPtr .MatD3D;
textures = NULL;
if ( bufPtr .TextureFilename )
D3DXCreateTextureFromFile ( _device,
bufPtr .TextureFilename, &textures );
}
mtrlBuffer->Release ();


Share this post


Link to post
Share on other sites
It is to replace "Extract the materials and load textures". The problem can be with your delete'ing the textures (though I'm not sure).

!EDIT! oh. I think the problem is with frames. Don't use D3DXLoadMeshFromX, instead create your own parser and use D3DXCreateMeshFromXof.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!