• Advertisement
Sign in to follow this  

Progressive Meshing

This topic is 4260 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

I have code from Frank D. Luna's book that loads in a ID3DXMesh from an X file using D3DXLoadMeshFromX(). In his provided .x file, he has a model that can change from about 8000 polys down to about 200. I am trying to load in .x files that I exported from Blender, and they load in fine, and the progressive mesh is made, however the max faces equals the min faces (or only one or two edge collapses occur ie face count goes down a whopping two). I tried this with an icosphere, a complex 3d model (suzanne the monkey provided by Blender), and with various landscapes (which are not solid) that I created. The Progressive Mesh would have the min faces equal to the max faces equal to the Source Mesh' numfaces, meaning the Progressive Mesh is created, but it's exactly the same as the Source Mesh. I did however get one of the landscape meshes to actually change in size by a whopping two faces. So, I was wondering if there was something wrong with the .x files I am exporting from Blender? I am retrieving the adjacency buffer immediately upon call to D3DXLoadMeshFromX(), optimizing the Source Mesh, and then creating the Progressive Mesh. Here is the code:
ID3DXMesh*                      SourceMesh = 0;
ID3DXPMesh*                     PMesh      = 0; // progressive mesh

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

hr = D3DXLoadMeshFromX(  
	"bigship1.x",
	D3DXMESH_MANAGED,
	Device,
	&adjBuffer,
	&mtrlBuffer,
	0,
	&numMtrls,
	&SourceMesh);

/* Skipped Material loading code */


	//
	// Optimize the mesh.
	//

	hr = SourceMesh->OptimizeInplace(		
		D3DXMESHOPT_ATTRSORT |
		D3DXMESHOPT_COMPACT  |
		D3DXMESHOPT_VERTEXCACHE,
		(DWORD*)adjBuffer->GetBufferPointer(),
		(DWORD*)adjBuffer->GetBufferPointer(), // new adjacency info
		0, 0);

	if(FAILED(hr))
	{
		::MessageBox(0, "OptimizeInplace() - FAILED", 0, 0);
		d3d::Release<ID3DXBuffer*>(adjBuffer); // free
		return false;
	}

	//
	// Generate the progressive mesh. 
	//

	hr = D3DXGeneratePMesh(
		SourceMesh,
		(DWORD*)adjBuffer->GetBufferPointer(), // adjacency
		0,                  // default vertex attribute weights
		0,                  // default vertex weights
		1,                  // simplify as low as possible
		D3DXMESHSIMP_FACE,  // simplify by face count
		&PMesh);

	d3d::Release<ID3DXMesh*>(SourceMesh);  // done w/ source mesh
	d3d::Release<ID3DXBuffer*>(adjBuffer); // done w/ buffer

	if(FAILED(hr))
	{
		::MessageBox(0, "D3DXGeneratePMesh() - FAILED", 0, 0);
		return false;
	}

	// set to original detail
	DWORD maxFaces = PMesh->GetMaxFaces();
	PMesh->SetNumFaces(maxFaces);



Edit: I added code to check if the Source Mesh was valid using D3DXValidMesh and D3DXCleanMesh but they return S_OK, so that is not a problem. If no one can really explain what may be going wrong, maybe I could get a link to some sample .x file's that I may be able to load. I tried to view a couple from a game I dled on this site, but they were really low in face count to begin with, and not really made for progressive meshing. Again, only one edge collapse was occurring on a model that was about 200 polys. [Edited by - rpreller on June 26, 2006 3:26:04 AM]

Share this post


Link to post
Share on other sites
Advertisement
*bump* Still having the problem, which is seriously cramping my style. Still the same problem with the Dwarf model that the DirectX progressive meshing sample uses.

Edit: Great. I finally went into the DirectX progressive meshing sample and compared their code to mine. They cleaned the mesh before validating it, and then called the following. The progressive meshes work perfectly now with this one function call.


D3DXWELDEPSILONS Epsilons;
ZeroMemory( &Epsilons, sizeof(D3DXWELDEPSILONS) );
hr = D3DXWeldVertices( SMesh, 0, &Epsilons,
(DWORD*)this->adjBuffer->GetBufferPointer(),
(DWORD*)this->adjBuffer->GetBufferPointer(), NULL, NULL );



[Edited by - rpreller on June 26, 2006 9:07:51 PM]

Share this post


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

  • Advertisement