OpenSceneGraph icon indicating copy to clipboard operation
OpenSceneGraph copied to clipboard

Obj reader stores image filenames as absolute paths

Open matthew-reid opened this issue 3 years ago • 0 comments

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);

matthew-reid avatar Jul 09 '21 02:07 matthew-reid