[code]X file not loading textures

Started by
10 comments, last by gsamour 12 years, 9 months ago
I exported an X file from 3DS max using the Panda X exporter. The X file loads just fine on my machine when I tick on the "Use full file path" in the textures tab, which causes it to point directly to it using the path on my hard drive.

That works fine, until my other programmer wants to use it on his computer. Because it is pointing to a place on my hard drive in the X file, it can't find it on his drive. So I tried doing it without that option in the file, which means it is just

Material Material_#26 {
0.006275; 0.006275; 0.006275; 1.000000;;
96.078431;
0.449020; 0.449020; 0.449020;;
0.000000; 0.000000; 0.000000;;
TextureFilename {"ground.png";}
}
Material Material_#25 {
0.467451; 0.467451; 0.467451; 1.000000;;
96.078431;
0.449020; 0.449020; 0.449020;;
0.000000; 0.000000; 0.000000;;
TextureFilename {"sunset.png";}
}

Which means it should point to the textures in this file, because they are all in the same folder right?

But of course, wrong.

Here is the code I use to load my models

void Model::LoadModel(LPDIRECT3DDEVICE9 dev, LPCSTR file)
{
Position = D3DXVECTOR3(0,0,0);
Rotation = D3DXVECTOR3(0,0,0);
Scale = D3DXVECTOR3(1.0f,1.0f,1.0f);
LPD3DXBUFFER bufMaterial;

D3DXLoadMeshFromX(file,
D3DXMESH_SYSTEMMEM,
dev,
NULL,
&bufMaterial,
NULL,
&NumMaterials,
&mesh);

D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufMaterial->GetBufferPointer();

Materials = new D3DMATERIAL9[NumMaterials];
Textures = new LPDIRECT3DTEXTURE9[NumMaterials];

for(DWORD i = 0; i < NumMaterials; i++)
{
Materials = tempMaterials.MatD3D; //Get material info
Materials.Ambient = Materials.Diffuse; //And make the ambient the same as diffuse

OutputDebugString(tempMaterials.pTextureFilename);

if(FAILED(D3DXCreateTextureFromFileA(dev,
tempMaterials.pTextureFilename,
&Textures)))
{

MessageBox(GetHwnd(),"Null","null",MB_OK);
Textures = NULL;
}

Textures->SetLOD(GraphicsLevel);

}
}

It tells me that it is NULL each time, meaning that something is preventing it from opening. Can someone give me a hand?
Advertisement
What is the output of [color=#1C2837][size=2]OutputDebugString(tempMaterials.pTextureFilename); ?
[color=#1C2837][size=2]

[color="#1C2837"]If it is a relative path or just the filename, then:
[color="#1C2837"]

[color="#1C2837"]1. If you're running from within Visual Studio, it will take the base path as the Working Directory from Project Properties -> Configuration Properties -> Debugging. If it's empty, then it's the project file's path.
[color="#1C2837"]2. If you're running the .exe directly, then it'll take the exe's path as the base path.
I have them all in a subfolder, how would I set it up to include that in the working directory
you could set an absolute path in the "Working Directory" field... like C:\my_project_folder\my_sub_folder\
or you could use a variable like [font="Consolas, Menlo, Monaco,"][color="#000000"][size="4"]$[color="#000000"][size="4"]([color="#2B91AF"][size="4"]TargetDir[color="#000000"][size="4"]) and add your own subfolder[/font]
So, I just put the Models subfolder in the working directory, and it'll work?
I can't really guarantee that it will, since I don't know your exact setup, but it *should*.

If the output of "[color=#1C2837][size=2]OutputDebugString(tempMaterials.pTextureFilename)" is just the filename, then try putting the absolute path of your Models folder into the working directory field (C:\blablabla\moreblablabla\Models) and it should work
It's pretty much the default, with some Folders for the models and it didn't work lol.
Can you share a few things with us?

1. What does this code print out... [color=#1C2837][size=2]OutputDebugString(tempMaterials.pTextureFilename) ?
[color=#1C2837][size=2]2. Are you using Visual Studio or another IDE?
[color=#1C2837][size=2]3. How are you running your program? From Visual Studio? Or running the exe directly?
[color=#1C2837][size=2]4. What is the path to your Visual Studio project file? *.cproj or something like that...
[color=#1C2837][size=2]5. What is the path to your .exe file?
1. It prints out "sunset.png"
2. VS 2010
3. From the debugger
4 Projects/(My solutions name)/(My projects name)
5 Debug/(Project Name).exe

And then models is in

Projects/(My Solution name)/(My Project Name)/Models

Projects/(My Solution name)/Debug/Models
Just to confirm, are the texture files in that same Models folder? Or are they in something like Models\Textures?

According to: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vcproject.vcprojectconfigurationproperties.workingdirectory.aspx :

What I said before about using the absolute path to the project file's (.vcxproj) folder should work...

Use whatever the absolute path is of "[color=#1C2837][size=2]Projects/(My solutions name)/(My projects name)" and append "/Models" at the end

VCProjectConfigurationProperties.WorkingDirectory Property

"The debugger's working directory. The default location is the directory containing the .vcxproj file."

This topic is closed to new replies.

Advertisement