Loading a mesh

Started by
7 comments, last by Say 18 years, 8 months ago
I'm using this procedure to load a mesh .x file It came from microsoft direct3d example, and it works but just if i load tiger.x file. while if i try to load other normal mesh i get the following error:

---------------------------

---------------------------
Application Error.
-2005529767 (D3DXERR_INVALIDDATA)
   at Microsoft.DirectX.Direct3D.TextureLoader.FromFile(Device device, String srcFile)

   at Load_X_File(String path) in c:\documents and settings\me\documents\visual studio projects\pk\form1.cs:line 445

this is the code

				device.RenderState.ZBufferEnable = true;
				device.RenderState.Ambient = System.Drawing.Color.White;
		
				ExtendedMaterial[] materials = null;

				Mesh temp = new XFileObject();
				temp = Mesh.FromFile(path, MeshFlags.SystemMemory, device, out materials);

				if(meshTextures == null)
				{
					meshTextures = new Texture[materials.Length];
					meshMaterials = new Direct3D.Material[materials.Length];
					for(int i=0; i<materials.Length; i++)
					{
						meshMaterials = materials.Material3D;
						meshMaterials.Ambient = meshMaterials.Diffuse;
						meshTextures = TextureLoader.FromFile(device, materials.TextureFilename);
					}
				}
what does it depend by?
Advertisement
That looks perfectly valid code to load .X files. Now, the error you get receive is an Exception, which can be handled by try/catch blocks.

My question is: Are you loading a .X file or a different model type(Suchs as .3ds, .blend, .cob, etc.)? Because this loading function ONLY works with .X files, and not with different formats. You'll need to convert the other formats to .X or write functionality to load different models(Which may or may not be easy)

Also, this line is redundant:
Mesh temp = new XFileObject();

As the next line, will overwrite the mesh reference.

Toolmaker

The problem is either the path or type to the texture associated with the mesh. My first guess is that you are trying to load an unsupported texture type.
sorry friend this is the real line i use;
Mesh temp = Mesh.FromFile(path, MeshFlags.SystemMemory, device, out materials);

i can confirm you i load only pure .x file.
These are loaded without trouble in microsoft mesh viewer, but if i try the error wrote above is showed to me from catch (DirectXExceprion) statement.
Maybe these .x file has not texture and i need to load .x file without texture in other way.
Can you confirm it? If so what is the way?
if(materials.TextureFilename != null){   meshTextures = TextureLoader.FromFile(device, materials.TextureFilename);}


That way you won't try to load a null texture if one doesn't exist :)
Quote:Original post by Saruman
The problem is either the path or type to the texture associated with the mesh. My first guess is that you are trying to load an unsupported texture type.


materials.TextureFilename) is "texture.dds"

if i try to open right this .x file within mesh viewer of microsoft, it is loaded correctly (it is the gun.x with grey material)
so anyone?
You could provide me with the .X file and the textures? I'll try to load it in my own Managed DirectX 9 project and see if it works.

Toolmaker

ok now i'm not at my house, when i arrive i send it to you, can you give me your email lso via pm?
tnx

This topic is closed to new replies.

Advertisement