This topic is 3915 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I can load a mesh file easy enough but have a few questions on loading X files. q1) each subset holds a texture and material for lighting purposes that are loaded with corresponding array elements. Why doesnt the x file hold data about all the lighting like ambient, as you have to set it yourself? q2)how many ways is there to load a x file as i am reading 1 method only, to load the xfile then iterate through the DXDXMATERIAL array. is this the onlt way you do it or the easiest way?

if( g_mtrlBuffer != 0 && g_numMtrls != 0 )
{
D3DXMATERIAL* mtrls = (D3DXMATERIAL*)g_mtrlBuffer->GetBufferPointer();

for(int i = 0; i < g_numMtrls; i++)
{
mtrls.MatD3D.Ambient = mtrls.MatD3D.Diffuse;

// save the ith material
Mtrls.push_back( mtrls.MatD3D );

// check if the ith material has an associative texture
if( mtrls.pTextureFilename != 0 )
{
// yes, load the texture for the ith subset
IDirect3DTexture9* tex = 0;
D3DXCreateTextureFromFile(
g_pd3dDevice,
mtrls.pTextureFilename,
&tex);

Textures.push_back( tex );
}
else
{
// no texture for the ith subset
Textures.push_back( 0 );
}
}


##### Share on other sites
q2) You have D3DXLoadMeshFromX or D3DXLoadMeshFromXInMemory at your disposal, but the first is probably what you want. Are there other ways? Sure, you'd just need to write a file parser, a way to make the vertices and indices, and then create the mesh from that data.

q1) The X file does contain the diffuse, speculative, and emissive colors and power value of each material.
Where the material/texture pair is defined in the X file will look something like this: (I added the comments)
Material hull // Material name{    0.600000;0.600000;0.600000;1.000000;; // Diffuse    0.000000; // Power    0.000000;0.000000;0.000000;; // Speculative    0.000000;0.000000;0.000000;; // Emissive     TextureFileName    {        "Craft/hull.png"; // Texture file location from the exe (or .sln in C++ VS2003/5)    }}

To retrieve and set the values switch this code:
mtrls.MatD3D.Ambient = mtrls.MatD3D.Diffuse;

With this:
mtrls.MatD3D.Ambient = /*Some Ambient Value*/;mtrls.MatD3D.Diffuse = mtrls.MatD3D.Diffuse;mtrls.MatD3D.Emissive = mtrls.MatD3D.Emissive;mtrls.MatD3D.Power = mtrls.MatD3D.Power;mtrls.MatD3D.Specular = mtrls.MatD3D.Specular;

As for why there is no ambient: (this is my guess on why they decided to keep it out of the file specification, so if I'm incorrect someone please correct me)

The ambient value is almost like a global constant brightness. Every face of every object no matter if the light is shining on it or not will be at least the ambient's brightness. So to make sure all faces of all objects on the screen look uniform the ambient is kept constant from object to object.

##### Share on other sites
Quote:
 Original post by tollinerq2) You have D3DXLoadMeshFromX or D3DXLoadMeshFromXInMemory at your disposal, but the first is probably what you want. Are there other ways? Sure, you'd just need to write a file parser, a way to make the vertices and indices, and then create the mesh from that data.q1) Tlike this: (I added the comments)Material hull // Material name{ 0.600000;0.600000;0.600000;1.000000;; // Diffuse 0.000000; // Power 0.000000;0.000000;0.000000;; // Speculative 0.000000;0.000000;0.000000;; // Emissive TextureFileName { "Craft/hull.png"; // Texture file location from the exe (or .sln in C++ VS2003/5) }}To retrieve and set the values switch this code:mtrls.MatD3D.Ambient = mtrls.MatD3D.Diffuse;With this:mtrls.MatD3D.Ambient = /*Some Ambient Value*/;mtrls.MatD3D.Diffuse = mtrls.MatD3D.Diffuse;mtrls.MatD3D.Emissive = mtrls.MatD3D.Emissive;mtrls.MatD3D.Power = mtrls.MatD3D.Power;mtrls.MatD3D.Specular = mtrls.MatD3D.Specular;

hi,

The material hull has a bunch of numbers so are these the values you read into the relevant variables for materials?

why do this as your just assigning it to itself so i dont understand?
mtrls.MatD3D.Diffuse = mtrls.MatD3D.Diffuse;??

##### Share on other sites
Doh my bad, i thought you were assigning each color value from each D3DXMATERIAL to a D3DMATERIAL9 but I see what you're doing. You're just assigning the diffuse to the ambient then saving that D3DMATERIAL9 defined by MatD3D... please disregard all of those assignments I had. Sorry for the confusion.

Yeah your code's correct... So it's up to you whether you want to always assign the diffuse to the ambient or have a global ambient.

so
mtrls.MatD3D.Ambient = mtrls.MatD3D.Diffuse;
is fine and you can also do something like this:
mtrls.MatD3D.Ambient = // Some global D3DCOLORVALUE;

With the material hull I just wanted to give you a sample of what was being read in. All those numbers are stored in the MatD3D struct for you. Unless you wanted to write a X file parser yourself you wont need to worry about parsing the materials yourself

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
18
5. 5

• 10
• 9
• 33
• 13
• 13

×