save/loadScene with relative file paths?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
freetimecoder
Posts: 226
Joined: Fri Aug 22, 2008 8:50 pm
Contact:

save/loadScene with relative file paths?

Post by freetimecoder »

Hi,

I have a problem. I want to save my scene with my mapeditor. Therefore I am using saveScene. But when loading it via loadScene on a different PC it cannot load any textures. I checked the xml file and I just found absolute filepaths. So I changed a few things and loaded the meshes with setWorkingDirectory and relative filepaths. That way I got half of a solution, because the xml now looks like this:

Code: Select all

	<node type="animatedMesh">

		<attributes>
			<string name="Name" value="" />
			<int name="Id" value="-1" />
			<vector3d name="Position" value="0.000000, 0.000000, 0.000000" />
			<vector3d name="Rotation" value="0.000000, 0.000000, 0.000000" />
			<vector3d name="Scale" value="1.000000, 1.000000, 1.000000" />
			<bool name="Visible" value="true" />
			<enum name="AutomaticCulling" value="box" />
			<int name="DebugDataVisible" value="0" />
			<bool name="IsDebugObject" value="false" />
			<string name="Mesh" value="data/mesh_second.b3d" />
			<bool name="Looping" value="true" />
			<bool name="ReadOnlyMaterials" value="false" />
			<float name="FramesPerSecond" value="0.025000" />
		</attributes>

		<materials>
			<attributes>
				<enum name="Type" value="lightmap" />
				<color name="Ambient" value="ffffffff" />
				<color name="Diffuse" value="ffffffff" />
				<color name="Emissive" value="00000000" />
				<color name="Specular" value="ffffffff" />
				<float name="Shininess" value="0.000000" />
				<float name="Param1" value="0.000000" />
				<float name="Param2" value="0.000000" />
				<texture name="Texture1" value="i:\map\code\mapeditor\xmltest\data\diffuse.png" />
				<texture name="Texture2" value="i:\map\code\mapeditor\xmltest\data\lightmap.tga" />
				<texture name="Texture3" value="" />

[...]
So I tried to correct it manually by adjusting all the texture paths, but I did not get far, because the ITexture's path is protected and I cannot set it. Is there a way to tell Irrlicht to only use relative paths?

greetings
Nox
Posts: 304
Joined: Wed Jan 14, 2009 6:23 pm

Post by Nox »

No, there was a time irrlicht only used the given paths but this made some misuses and bugs possible. So now every relative path is made absolute and there is no real solution for it.
One proposal is to give a "workingpath" to the save and load method which is used to made the absolute paths relative but nobody really concerned with this problem.
freetimecoder
Posts: 226
Joined: Fri Aug 22, 2008 8:50 pm
Contact:

Post by freetimecoder »

Hm...

So I would have to programm my own workaround.
But if it is not possible to set Irrlicht to relative paths, what point is there in saveScene/loadScene if you want to really use it in games?

Is there a way to access an ITexture's name attribute (one that I might overlooked)?

greetings
Nox
Posts: 304
Joined: Wed Jan 14, 2009 6:23 pm

Post by Nox »

Well i made it quick and dry and just reverted this change :>
freetimecoder
Posts: 226
Joined: Fri Aug 22, 2008 8:50 pm
Contact:

Post by freetimecoder »

Hi,

ok I used a different approach :lol:
I just wrote a custom writeSceneNode method and created my own ITexture class, which has only the purpose to allow a "setPath" ;)

Still, could you tell me, where exactly is that piece of code that is responsible for making all paths absolute?

greetings
Nox
Posts: 304
Joined: Wed Jan 14, 2009 6:23 pm

Post by Nox »

For textures

Code: Select all

// Identify textures by their absolute filenames if possible.
	const io::path absolutePath = FileSystem->getAbsolutePath(filename);
CNullDriver.cpp
vins
Posts: 51
Joined: Mon Aug 16, 2004 6:14 pm
Location: Sofia, Bulgaria
Contact:

Post by vins »

Also in CFileSystem.cpp - createAndOpenFile:

Code: Select all

return createReadFile(getAbsolutePath(filename));
Post Reply