OpenSceneGraph
OpenSceneGraph copied to clipboard
Obj reader stores image filenames as absolute paths
This line in the OBJ Reader causes images to be loaded as an absolute path. This produces undesirable behavior when writing the scene out again; any relative paths in the input OBJ are converted to absolute paths, meaning the asset files will no longer work if copied or moved. This happens for example when converting an OBJ to any format with osgconv.
As a solution, I'd recommend storing the image filename as a relative path, even if loaded as an absolute. For example:
// first try with database path of parent.
image = osgDB::readRefImageFile(model.getDatabasePath()+'/'+filename, options);
// preserve relative path in case filename is written out later
image->setFileName(filename);