Sign in to follow this  
Say

Loading a mesh

Recommended Posts

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[i] = materials[i].Material3D;
						meshMaterials[i].Ambient = meshMaterials[i].Diffuse;
						meshTextures[i] = TextureLoader.FromFile(device, materials[i].TextureFilename);
					}
				}
what does it depend by?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

if(materials[i].TextureFilename != null)
{
meshTextures[i] = TextureLoader.FromFile(device, materials[i].TextureFilename);
}




That way you won't try to load a null texture if one doesn't exist :)

Share this post


Link to post
Share on other sites
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[i].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)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this