• Advertisement
Sign in to follow this  

problem optimizing, cleaning and simplifying meshes c#

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

hi I wanted to optimize my meshes removing some unseen vertex and i find a tutorial that has this code but when I implemented my app crashes when rendering the mesh :S. What is what Im doing wrong??? heres is the code :::::::::::::::::::::: public void setMeshFromFile(string filename) { GraphicsStream adj; m = Mesh.FromFile(dirMeshes + filename,MeshFlags.Managed,device,out adj,out materials); m.ComputeNormals(); meshMaterials = new Material[materials.Length]; meshTextures = new Texture[materials.Length]; for( int i=0; i< materials.Length; i++ ) { meshMaterials = materials.Material3D; if ((materials.TextureFilename != null) && ((materials.TextureFilename != string.Empty))) { meshTextures = TextureLoader.FromFile(device, dirMeshes + materials.TextureFilename); } } Mesh tempMesh; if ((m.VertexFormat & VertexFormats.Normal) != VertexFormats.Normal) { tempMesh = m.Clone(m.Options.Value,m.VertexFormat | VertexFormats.Normal, device); tempMesh.ComputeNormals(); m.Dispose(); m = tempMesh; } // optimize mesh tempMesh = m.Optimize (MeshFlags.Managed | MeshFlags.OptimizeAttributeSort | MeshFlags.OptimizeDoNotSplit, adj); m.Dispose(); m = tempMesh; // Clean our main mesh Mesh tempMesh = Mesh.Clean(CleanType.Simplification,m, adj, adj); m.Dispose(); m = tempMesh; simplifiedMesh = Mesh.Simplify(m, adj, null, 1, MeshFlags.SimplifyVertex); }

Share this post


Link to post
Share on other sites
Advertisement
Ouch, this early in the morning, reading code without indenting is quite difficult ^^'' please check the FAQ to post some codes with indenting :


public void setMeshFromFile(string filename)
{
GraphicsStream adj;
m = Mesh.FromFile(dirMeshes + filename,MeshFlags.Managed,device,out adj,out materials);
m.ComputeNormals();
meshMaterials = new Material[materials.Length];
meshTextures = new Texture[materials.Length];
for( int i=0; i< materials.Length; i++ )
{
meshMaterials = materials.Material3D;
if ((materials.TextureFilename != null) && ((materials.TextureFilename != string.Empty)))
{
meshTextures = TextureLoader.FromFile(device, dirMeshes + materials.TextureFilename);
}
}

Mesh tempMesh;

if ((m.VertexFormat & VertexFormats.Normal) != VertexFormats.Normal)
{
tempMesh = m.Clone(m.Options.Value, m.VertexFormat | VertexFormats.Normal, device);
tempMesh.ComputeNormals();
m.Dispose();
m = tempMesh;
}

// optimize mesh
tempMesh = m.Optimize (MeshFlags.Managed | MeshFlags.OptimizeAttributeSort | MeshFlags.OptimizeDoNotSplit, adj);
m.Dispose();
m = tempMesh;

// Clean our main mesh
Mesh tempMesh = Mesh.Clean(CleanType.Simplification, m, adj, adj);
m.Dispose();
m = tempMesh;

simplifiedMesh = Mesh.Simplify(m, adj, null, 1, MeshFlags.SimplifyVertex);
}



Well, I would use OptimizeInPlace instead of Optimize. That would save the m.Dispose() and the m = tempMesh; after that. Because I'm not too sure (it's C# ^^) but is it right to do tempMesh = m.Optimize(...); although just before that, you have m = tempMesh; ?

And ... is it also right to do Mesh tempMesh twice ???? In C++, it shouldn't even compile (i think) So maybe try to replace the seconde Mesh tempMesh = ...; by a Mesh tempMesh2 = ...; or something like that.

Again, I'm not good with C#, maybe I missed something ...

Share this post


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

  • Advertisement