mirror of
https://github.com/leozide/leocad
synced 2025-01-29 20:34:50 +01:00
Search the current path for submodels when opening files.
This commit is contained in:
parent
fd225d33d6
commit
61006184d1
5 changed files with 52 additions and 20 deletions
|
@ -871,6 +871,9 @@ bool lcPiecesLibrary::LoadPiece(PieceInfo* Info)
|
|||
lcLibraryMeshData MeshData;
|
||||
lcArray<lcLibraryTextureMap> TextureStack;
|
||||
|
||||
bool Loaded = false;
|
||||
bool SaveCache = false;
|
||||
|
||||
if (Info->mZipFileType != LC_NUM_ZIPFILES && mZipFiles[Info->mZipFileType])
|
||||
{
|
||||
if (LoadCachePiece(Info))
|
||||
|
@ -878,15 +881,14 @@ bool lcPiecesLibrary::LoadPiece(PieceInfo* Info)
|
|||
|
||||
lcMemFile PieceFile;
|
||||
|
||||
if (!mZipFiles[Info->mZipFileType]->ExtractFile(Info->mZipFileIndex, PieceFile))
|
||||
return false;
|
||||
if (mZipFiles[Info->mZipFileType]->ExtractFile(Info->mZipFileIndex, PieceFile))
|
||||
{
|
||||
const char* OldLocale = setlocale(LC_NUMERIC, "C");
|
||||
Loaded = ReadMeshData(PieceFile, lcMatrix44Identity(), 16, TextureStack, MeshData, LC_MESHDATA_SHARED, true);
|
||||
setlocale(LC_NUMERIC, OldLocale);
|
||||
}
|
||||
|
||||
const char* OldLocale = setlocale(LC_NUMERIC, "C");
|
||||
bool Ret = ReadMeshData(PieceFile, lcMatrix44Identity(), 16, TextureStack, MeshData, LC_MESHDATA_SHARED, true);
|
||||
setlocale(LC_NUMERIC, OldLocale);
|
||||
|
||||
if (!Ret)
|
||||
return false;
|
||||
SaveCache = Loaded && (Info->mZipFileType == LC_ZIPFILE_OFFICIAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -899,20 +901,33 @@ bool lcPiecesLibrary::LoadPiece(PieceInfo* Info)
|
|||
|
||||
sprintf(FileName, "%sparts/%s.dat", mLibraryPath, Name);
|
||||
|
||||
if (!PieceFile.Open(FileName, "rt"))
|
||||
return false;
|
||||
|
||||
const char* OldLocale = setlocale(LC_NUMERIC, "C");
|
||||
bool Ret = ReadMeshData(PieceFile, lcMatrix44Identity(), 16, TextureStack, MeshData, LC_MESHDATA_SHARED, true);
|
||||
setlocale(LC_NUMERIC, OldLocale);
|
||||
|
||||
if (!Ret)
|
||||
return false;
|
||||
if (PieceFile.Open(FileName, "rt"))
|
||||
{
|
||||
const char* OldLocale = setlocale(LC_NUMERIC, "C");
|
||||
Loaded = ReadMeshData(PieceFile, lcMatrix44Identity(), 16, TextureStack, MeshData, LC_MESHDATA_SHARED, true);
|
||||
setlocale(LC_NUMERIC, OldLocale);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Loaded && !mCurrentModelPath.isEmpty())
|
||||
{
|
||||
QFileInfo FileInfo(QDir(mCurrentModelPath), Info->m_strName);
|
||||
|
||||
lcDiskFile PieceFile;
|
||||
if (PieceFile.Open(FileInfo.absoluteFilePath().toLatin1().constData(), "rt")) // todo: qstring
|
||||
{
|
||||
const char* OldLocale = setlocale(LC_NUMERIC, "C");
|
||||
Loaded = ReadMeshData(PieceFile, lcMatrix44Identity(), 16, TextureStack, MeshData, LC_MESHDATA_SHARED, true);
|
||||
setlocale(LC_NUMERIC, OldLocale);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Loaded)
|
||||
return false;
|
||||
|
||||
CreateMesh(Info, MeshData);
|
||||
|
||||
if (mZipFiles[LC_ZIPFILE_OFFICIAL])
|
||||
if (SaveCache)
|
||||
SaveCachePiece(Info);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -158,6 +158,11 @@ public:
|
|||
mNumOfficialPieces = mPieces.GetSize();
|
||||
}
|
||||
|
||||
void SetCurrentModelPath(const QString& ModelPath)
|
||||
{
|
||||
mCurrentModelPath = ModelPath;
|
||||
}
|
||||
|
||||
bool ReadMeshData(lcFile& File, const lcMatrix44& CurrentTransform, lcuint32 CurrentColorCode, lcArray<lcLibraryTextureMap>& TextureStack, lcLibraryMeshData& MeshData, lcMeshDataType MeshDataType, bool Optimize);
|
||||
lcMesh* CreateMesh(PieceInfo* Info, lcLibraryMeshData& MeshData);
|
||||
void UpdateBuffers(lcContext* Context);
|
||||
|
@ -192,6 +197,7 @@ protected:
|
|||
bool LoadPrimitive(int PrimitiveIndex);
|
||||
|
||||
QString mCachePath;
|
||||
QString mCurrentModelPath;
|
||||
qint64 mArchiveCheckSum[4];
|
||||
char mLibraryFileName[LC_MAXPATH];
|
||||
char mUnofficialFileName[LC_MAXPATH];
|
||||
|
|
|
@ -1848,6 +1848,8 @@ void lcMainWindow::NewProject()
|
|||
if (!SaveProjectIfModified())
|
||||
return;
|
||||
|
||||
lcGetPiecesLibrary()->SetCurrentModelPath(QString());
|
||||
|
||||
Project* NewProject = new Project();
|
||||
g_App->SetProject(NewProject);
|
||||
lcGetPiecesLibrary()->UnloadUnusedParts();
|
||||
|
|
|
@ -122,8 +122,13 @@ void PieceInfo::Load()
|
|||
return;
|
||||
else if (mFlags & LC_PIECE_PLACEHOLDER)
|
||||
{
|
||||
mFlags |= LC_PIECE_HAS_DEFAULT | LC_PIECE_HAS_LINES;
|
||||
mBoundingBox = gPlaceholderMesh->mBoundingBox;
|
||||
if (lcGetPiecesLibrary()->LoadPiece(this))
|
||||
mFlags &= ~LC_PIECE_PLACEHOLDER;
|
||||
else
|
||||
{
|
||||
mFlags |= LC_PIECE_HAS_DEFAULT | LC_PIECE_HAS_LINES;
|
||||
mBoundingBox = gPlaceholderMesh->mBoundingBox;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -210,6 +210,8 @@ bool Project::Load(const QString& FileName)
|
|||
QFileInfo FileInfo(FileName);
|
||||
QString Extension = FileInfo.suffix().toLower();
|
||||
|
||||
lcGetPiecesLibrary()->SetCurrentModelPath(FileInfo.absolutePath());
|
||||
|
||||
if (Extension == QLatin1String("dat") || Extension == QLatin1String("ldr") || Extension == QLatin1String("mpd"))
|
||||
{
|
||||
QByteArray FileData = File.readAll();
|
||||
|
@ -284,6 +286,8 @@ bool Project::Save(const QString& FileName)
|
|||
return false;
|
||||
}
|
||||
|
||||
lcGetPiecesLibrary()->SetCurrentModelPath(QFileInfo(FileName).absolutePath());
|
||||
|
||||
QTextStream Stream(&File);
|
||||
bool MPD = mModels.GetSize() > 1;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue