[MDX] - Multiple meshes in single .x file

Started by
2 comments, last by jad_salloum 18 years ago
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.
Advertisement
bump
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

i would advice u to use Mesh.loadHierarchyFromFile(...) check for the Simple Animation Sample in the SDK's

hope this helps,

This topic is closed to new replies.

Advertisement