Fix reading single image file with sequenced file name

This commit is contained in:
manongjohn 2022-04-04 08:31:37 -04:00
parent afee5ccec3
commit 45013348ff
3 changed files with 19 additions and 3 deletions

View file

@ -35,7 +35,8 @@ TLevelReader::TLevelReader(const TFilePath &path)
, m_info(0)
, m_path(path)
, m_contentHistory(0)
, m_frameFormat(TFrameId::FOUR_ZEROS) {}
, m_frameFormat(TFrameId::FOUR_ZEROS)
, m_useExactPath(false) {}
//-----------------------------------------------------------
@ -102,6 +103,9 @@ const TImageInfo *TLevelReader::getImageInfo() {
TLevelP TLevelReader::loadInfo() {
TFilePath parentDir = m_path.getParentDir();
TFilePath levelName(m_path.getLevelName());
// For scene loading, use what was stored in the file instead
// of auto converting to a level name.
if (useExactPath()) levelName = m_path.withoutParentDir();
// cout << "Parent dir = '" << parentDir << "'" << endl;
// cout << "Level name = '" << levelName << "'" << endl;
TFilePathSet files;
@ -115,9 +119,13 @@ TLevelP TLevelReader::loadInfo() {
for (TFilePathSet::iterator it = files.begin(); it != files.end(); it++) {
TFilePath ln(it->getLevelName());
// cout << "try " << *it << " " << it->getLevelName() << endl;
if (levelName == TFilePath(it->getLevelName())) {
if (levelName == TFilePath(it->getLevelName()) ||
levelName == it->withoutParentDir()) {
try {
level->setFrame(it->getFrame(), TImageP());
if (levelName == it->withoutParentDir())
level->setFrame(TFrameId::NO_FRAME, TImageP());
else
level->setFrame(it->getFrame(), TImageP());
data.push_back(*it);
} catch (TMalformedFrameException tmfe) {
// skip frame named incorrectly warning to the user in the message
@ -163,6 +171,7 @@ TLevelP TLevelReader::loadInfo() {
//-----------------------------------------------------------
TImageReaderP TLevelReader::getFrameReader(TFrameId fid) {
if (fid.isNoFrame()) return m_path;
return TImageReaderP(m_path.withFrame(fid, m_frameFormat));
}

View file

@ -49,6 +49,8 @@ protected:
TFilePath m_path;
TContentHistory *m_contentHistory;
bool m_useExactPath;
public:
TLevelReader(const TFilePath &path);
virtual ~TLevelReader();
@ -95,6 +97,9 @@ public:
//! TLevelReader keeps the ownership of TContentHistory. Don't delete it
const TContentHistory *getContentHistory() const { return m_contentHistory; }
void setUseExactPath(bool useExactPath) { m_useExactPath = useExactPath; }
bool useExactPath() { return m_useExactPath; }
private:
TFrameId::FrameFormat m_frameFormat;
};

View file

@ -1220,6 +1220,8 @@ void TXshSimpleLevel::load() {
TLevelReaderP lr(path); // May throw
assert(lr);
lr->setUseExactPath(getScene()->isLoading());
TLevelP level = lr->loadInfo();
if (level->getFrameCount() > 0) {
const TImageInfo *info = lr->getImageInfo(level->begin()->first);