Making a copy contructor for a Mesh object

Started by
3 comments, last by Magos 18 years, 1 month ago
The problem I'm having is that it's impossible to alocate memory for a LPD3DXMESH object, new LPD3DXMESH doesn't work. How do you do this? Also does anyone know any resource about copy contructors for DirectX objects (I'm interested in a copy constructor for a mesh object of course)?
Advertisement
you cant call new because directX follows Component Object Model
The constructors and destructors are either private or protected.. "i think"

you can always create a wrapper class for LPD3DXMESH and make all the little new and delete call you want...

but here is a copy mesh function for you

// copies a mesh// make sure the mesh you send in is valid or no copy will occure// if this fails it returns NULLLPD3DXMesh CopyMesh( LPD3DXMesh srcMesh ){	// make sure mesh is 	if( srcMesh == NULL )		return NULL;			LPDIRECT3DDEVICE9 pTempDevice = NULL;		// get the device	if( FAILED( srcMesh->GetDevice( pTempDevice ) ))		return NULL		// the new mesh to be created	LPD3DXMesh newMesh = NULL;		HRESULT hr			// clone the mesh	hr = srcMesh->CloneMeshFVF(srcMesh->GetOptions(), srcMesh->GetFVF(), pTempDevice, &newMesh);		// release the device	pTempDevice->Release();		// see if mesh was cloned	if( FAILED( hr ))		return NULL;			// success	return newMesh;}//////usage//LPD3DXMesh pMesh = CopyMesh( aValidMesh );if( pMesh == NULL )	// failed////


<<::EDIT::>> dont forget to release the newMesh if the mesh is not NULL
Wow, thanks!
Quote:Original post by Dan Caranfil
The problem I'm having is that it's impossible to alocate memory for a LPD3DXMESH object, new LPD3DXMESH doesn't work. How do you do this?

Use any of the mesh creation functions, passing it the address of a mesh interface pointer.


If you don't intend to modify the copied buffer they could point to the same data, call addRef on the LPD3DXMESH object (assuming you release it in the destructor).
----------------------------------------MagosX.com

This topic is closed to new replies.

Advertisement