private void LoadMesh(string file)
{
ExtendedMaterial[] mtrl;
GraphicsStream adj;
// Load our mesh
mesh = Mesh.FromFile(file, MeshFlags.Managed, device,out adj, out mtrl);
// If we have any materials, store them
if ((mtrl != null) && (mtrl.Length > 0))
{
meshMaterials = new Material[mtrl.Length];
meshTextures = new Texture[mtrl.Length];
// Store each material and texture
for (int i = 0; i < mtrl.Length; i++)
{
meshMaterials = mtrl.Material3D;
if ((mtrl.TextureFilename != null) && (mtrl.TextureFilename != string.Empty))
{
// We have a texture, try to load it
meshTextures = TextureLoader.FromFile(device, @"..\..\" + mtrl.TextureFilename);
}
}
}
//clean our main mesh
Mesh tempMesh = Mesh.Clean(CleanType.Simplification,mesh,adj,adj);
//replace our existing mesh with this one
mesh.Dispose();
mesh = tempMesh;
//get our simplified mesh
simplifiedMesh = Mesh.Simplify(mesh,adj,null,1,MeshFlags.SimplifyVertex);
}
Simplifying meshes, Managed Dx C# help
Hi, i am working my way through Managed Direct x 9 kickstart by tom miller and there are some differences in the code. I can correct most of them myself but i am having a problem simplifying meshes.
i am using the latest direct x and .net
pg 125. this is what i have atm.
it gives me an exception.
An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.directx.direct3dx.dll
Additional information: Object reference not set to an instance of an object.
the problem is in trying to simplify and not the loading, the last method throws the exception.
any help would be much appreciated. Thank you
Riviera Kid
[Edited by - Riviera Kid on November 25, 2004 8:27:01 AM]
It looks like mesh != null, check that adj != null and maybe the argument where you put null should not be null.
Hope this helps
Hope this helps
Not entirely sure on this one, but I believe that on this line:
Mesh tempMesh = Mesh.Clean(CleanType.Simplification,mesh,adj,adj);
if the cleaning fails, it returns the same mesh, and probably the "adjacencyOut" which is your adj graphicsstream get filled with a null value, cause the cleaning failed.
that's just my guess by looking at the directx docs
Mesh tempMesh = Mesh.Clean(CleanType.Simplification,mesh,adj,adj);
if the cleaning fails, it returns the same mesh, and probably the "adjacencyOut" which is your adj graphicsstream get filled with a null value, cause the cleaning failed.
that's just my guess by looking at the directx docs
This is thread starter, rivierakid
in the text book the overload is
Mesh.Clean(mesh,adj,adj);
but it seams the last updates have changed the overload
so i wasnt really sure what to do instead.
why would the clean fail?
in the text book the overload is
Mesh.Clean(mesh,adj,adj);
but it seams the last updates have changed the overload
so i wasnt really sure what to do instead.
why would the clean fail?
Once, Clean for me found some 'bowie' vertex ordering or sharing or something that it couldn't fix.
Don't dispose the mesh...just assign the mesh like :
mesh = tempMesh;
There seems to be a problem with the disposing of the original mesh also disposing the tempMesh (although they are not the same reference).
It's not really a memory leak since the GC will eventually get to it.
Shadx
Look at : http://www.gamedev.net/community/forums/topic.asp?topic_id=285414
mesh = tempMesh;
There seems to be a problem with the disposing of the original mesh also disposing the tempMesh (although they are not the same reference).
It's not really a memory leak since the GC will eventually get to it.
Shadx
Look at : http://www.gamedev.net/community/forums/topic.asp?topic_id=285414
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement