Jump to content
  • Advertisement
Sign in to follow this  

[MDX] - Multiple meshes in single .x file

This topic is 4435 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 exported an .x file mesh with DeleD 3d Editor which was composed of a grid of rectangles and can't get them to load/render in my app. I used the box tool to create two identical rectangles side by side and inside the .x file contains "mesh Cube2" + "mesh Cube4". DirectX viewer correctly loads/renders the x file and I wonder what my app is missing.
//'class Model' - loads a mesh from file and stores it
public Model(Device device, string folderPath, string fileName)
{
	GraphicsBuffer outputAdjacency = new GraphicsBuffer();
	MaterialList ml = new MaterialList();
	EffectInstanceList el = new EffectInstanceList();
	mesh = new Mesh(device, folderPath + fileName, MeshFlags.Managed, outputAdjacency, ml, el);

	textures = new Texture[mesh.AttributeCount];
	materials = new Material[mesh.AttributeCount];

	for (int i = 0; i < mesh.AttributeCount; i++)
	{
		materials = ml.Material;
		materials.AmbientColor = materials.DiffuseColor;

		// Create the texture.
		if (ml.TextureFileName != null && ml.TextureFileName.Length > 0)
		{
			string textureFile = System.IO.Path.GetFileName(ml.TextureFileName);
			textures = new Texture(device, folderPath + textureFile);
		}
		else
		{
			textures = null;
		}
	}
}

//'class Unit' - contains a model and represents a movable entity
Model model;

public void Draw(Device device)
{
	device.Transform.World = Transform;
	device.VertexFormat = model.Mesh.VertexFormat;

	for (int i = 0; i < model.Materials.Length; i++)
	{
		// Set the material and texture for this subset.
		device.Material = model.Materials;
		device.SetTexture(0, model.Textures);

		// Draw the mesh subset.
		model.Mesh.DrawSubset(i);
	}
}

My app will only load and render an .x file with a single mesh, not more. 1) Does my loading function only load the first mesh in the .x file? If so, how would I load them all? 2) Are multiple mesh objects per x file normal, or is deleD improperly separating each box.

Share this post


Link to post
Share on other sites
Advertisement
Whilst you seem to be using MDX, the C++ code for dxviewer is included in the SDK - if you're able to read C++ code then you should be able to isolate the relevant parts and cross-reference against your code.

The finer details of the .X file format are a mystery most of the time, but I'm pretty sure it can handle multiple objects - possibly part of the animation/heirarchy system. I still use conv3ds.exe for my meshes, and I have to specify -m to get it to collapse all objects into a single mesh...

hth
Jack

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!