mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Fixed loading files from the command line.
This commit is contained in:
parent
4c74b6ecf4
commit
e383eed986
8 changed files with 58 additions and 31 deletions
|
@ -288,7 +288,7 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal
|
|||
GL_DisableVertexBufferObject();
|
||||
|
||||
// Load project.
|
||||
if (ProjectName && mProject->Load(ProjectName))
|
||||
if (ProjectName && gMainWindow->OpenProject(ProjectName))
|
||||
{
|
||||
if (!SaveImage)
|
||||
return true;
|
||||
|
|
|
@ -663,9 +663,10 @@ bool lcPiecesLibrary::LoadCachePiece(PieceInfo* Info)
|
|||
if (!mCacheFile->ExtractFile(Info->m_strName, PieceFile))
|
||||
return false;
|
||||
|
||||
Info->mMesh = new lcMesh;
|
||||
lcMesh* Mesh = new lcMesh;
|
||||
Info->SetMesh(Mesh);
|
||||
|
||||
return Info->mMesh->FileLoad(PieceFile);
|
||||
return Mesh->FileLoad(PieceFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -684,9 +685,10 @@ bool lcPiecesLibrary::LoadCachePiece(PieceInfo* Info)
|
|||
if (!CacheFile.ExtractFile(Info->m_strName, PieceFile))
|
||||
return false;
|
||||
|
||||
Info->mMesh = new lcMesh;
|
||||
lcMesh* Mesh = new lcMesh;
|
||||
Info->SetMesh(Mesh);
|
||||
|
||||
return Info->mMesh->FileLoad(PieceFile);
|
||||
return Mesh->FileLoad(PieceFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -748,8 +750,9 @@ void lcPiecesLibrary::SaveCacheFile()
|
|||
continue;
|
||||
|
||||
bool Cached = (Info->mFlags & LC_PIECE_CACHED) != 0;
|
||||
lcMesh* Mesh = Info->GetMesh();
|
||||
|
||||
if (Info->mMesh)
|
||||
if (Mesh)
|
||||
Info->mFlags |= LC_PIECE_CACHED;
|
||||
|
||||
int Length = strlen(Info->m_strDescription);
|
||||
|
@ -761,12 +764,12 @@ void lcPiecesLibrary::SaveCacheFile()
|
|||
|
||||
NumPieces++;
|
||||
|
||||
if (Cached || !Info->mMesh)
|
||||
if (Cached || !Mesh)
|
||||
continue;
|
||||
|
||||
lcMemFile PieceFile;
|
||||
|
||||
Info->mMesh->FileSave(PieceFile);
|
||||
Mesh->FileSave(PieceFile);
|
||||
CacheFile.AddFile(Info->m_strName, PieceFile);
|
||||
|
||||
Info->mFlags |= LC_PIECE_CACHED;
|
||||
|
@ -975,7 +978,7 @@ bool lcPiecesLibrary::LoadPiece(PieceInfo* Info)
|
|||
}
|
||||
|
||||
Mesh->UpdateBuffers();
|
||||
Info->mMesh = Mesh;
|
||||
Info->SetMesh(Mesh);
|
||||
Info->AddRef();
|
||||
|
||||
if (mZipFiles[LC_ZIPFILE_OFFICIAL])
|
||||
|
|
|
@ -135,8 +135,10 @@ void lcMainWindow::AddRecentFile(const QString& FileName)
|
|||
QString SavedName = FileName;
|
||||
int FileIdx;
|
||||
|
||||
QFileInfo FileInfo(FileName);
|
||||
|
||||
for (FileIdx = 0; FileIdx < LC_MAX_RECENT_FILES; FileIdx++)
|
||||
if (mRecentFiles[FileIdx] == FileName)
|
||||
if (QFileInfo(mRecentFiles[FileIdx]) == FileInfo)
|
||||
break;
|
||||
|
||||
for (FileIdx = lcMin(FileIdx, LC_MAX_RECENT_FILES - 1); FileIdx > 0; FileIdx--)
|
||||
|
|
|
@ -181,15 +181,18 @@ void lcModel::DeleteModel()
|
|||
lcReleaseTexture(mBackgroundTexture);
|
||||
mBackgroundTexture = NULL;
|
||||
|
||||
const lcArray<View*>& Views = gMainWindow->GetViews();
|
||||
|
||||
for (int ViewIdx = 0; ViewIdx < Views.GetSize(); ViewIdx++)
|
||||
if (gMainWindow)
|
||||
{
|
||||
View* View = Views[ViewIdx];
|
||||
lcCamera* Camera = View->mCamera;
|
||||
const lcArray<View*>& Views = gMainWindow->GetViews();
|
||||
|
||||
if (!Camera->IsSimple())
|
||||
View->SetCamera(Camera, true);
|
||||
for (int ViewIdx = 0; ViewIdx < Views.GetSize(); ViewIdx++)
|
||||
{
|
||||
View* View = Views[ViewIdx];
|
||||
lcCamera* Camera = View->mCamera;
|
||||
|
||||
if (!Camera->IsSimple() && mCameras.FindIndex(Camera) != -1)
|
||||
View->SetCamera(Camera, true);
|
||||
}
|
||||
}
|
||||
|
||||
mPieces.DeleteAll();
|
||||
|
|
|
@ -24,6 +24,16 @@ public:
|
|||
|
||||
QString GetSaveID() const;
|
||||
|
||||
lcMesh* GetMesh() const
|
||||
{
|
||||
return mMesh;
|
||||
}
|
||||
|
||||
void SetMesh(lcMesh* Mesh)
|
||||
{
|
||||
mMesh = Mesh;
|
||||
}
|
||||
|
||||
int AddRef()
|
||||
{
|
||||
mRefCount++;
|
||||
|
@ -96,8 +106,6 @@ public:
|
|||
void GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcArray<lcModelPartsEntry>& ModelParts) const;
|
||||
|
||||
public:
|
||||
lcMesh* mMesh;
|
||||
|
||||
// Attributes
|
||||
char m_strName[LC_PIECE_NAME_LEN];
|
||||
char m_strDescription[128];
|
||||
|
@ -109,6 +117,7 @@ public:
|
|||
protected:
|
||||
int mRefCount;
|
||||
lcModel* mModel;
|
||||
lcMesh* mMesh;
|
||||
|
||||
void Load();
|
||||
void Unload();
|
||||
|
|
|
@ -682,9 +682,9 @@ void Project::Export3DStudio()
|
|||
for (int PartIdx = 0; PartIdx < ModelParts.GetSize(); PartIdx++)
|
||||
{
|
||||
PieceInfo* Info = ModelParts[PartIdx].Info;
|
||||
lcMesh* Mesh = Info->mMesh;
|
||||
lcMesh* Mesh = Info->GetMesh();
|
||||
|
||||
if (Mesh->mIndexType == GL_UNSIGNED_INT)
|
||||
if (!Mesh || Mesh->mIndexType == GL_UNSIGNED_INT)
|
||||
continue;
|
||||
|
||||
long NamedObjectStart = File.GetPosition();
|
||||
|
@ -1148,9 +1148,10 @@ void Project::ExportPOVRay()
|
|||
for (int PartIdx = 0; PartIdx < ModelParts.GetSize(); PartIdx++)
|
||||
{
|
||||
PieceInfo* Info = ModelParts[PartIdx].Info;
|
||||
lcMesh* Mesh = Info->GetMesh();
|
||||
int Index = Library->mPieces.FindIndex(Info);
|
||||
|
||||
if (PieceTable[Index * LC_PIECE_NAME_LEN])
|
||||
if (!Mesh || PieceTable[Index * LC_PIECE_NAME_LEN])
|
||||
continue;
|
||||
|
||||
char Name[LC_PIECE_NAME_LEN];
|
||||
|
@ -1162,7 +1163,7 @@ void Project::ExportPOVRay()
|
|||
|
||||
sprintf(PieceTable + Index * LC_PIECE_NAME_LEN, "lc_%s", Name);
|
||||
|
||||
Info->mMesh->ExportPOVRay(POVFile, Name, ColorTable);
|
||||
Mesh->ExportPOVRay(POVFile, Name, ColorTable);
|
||||
|
||||
POVFile.WriteLine("}\n\n");
|
||||
|
||||
|
@ -1314,11 +1315,15 @@ void Project::ExportWavefront()
|
|||
|
||||
for (int PartIdx = 0; PartIdx < ModelParts.GetSize(); PartIdx++)
|
||||
{
|
||||
const lcMatrix44& ModelWorld = ModelParts[PartIdx].WorldMatrix;
|
||||
PieceInfo* Info = ModelParts[PartIdx].Info;
|
||||
float* Verts = (float*)Info->mMesh->mVertexBuffer.mData;
|
||||
lcMesh* Mesh = ModelParts[PartIdx].Info->GetMesh();
|
||||
|
||||
for (int i = 0; i < Info->mMesh->mNumVertices * 3; i += 3)
|
||||
if (!Mesh)
|
||||
continue;
|
||||
|
||||
const lcMatrix44& ModelWorld = ModelParts[PartIdx].WorldMatrix;
|
||||
float* Verts = (float*)Mesh->mVertexBuffer.mData;
|
||||
|
||||
for (int i = 0; i < Mesh->mNumVertices * 3; i += 3)
|
||||
{
|
||||
lcVector3 Vertex = lcMul31(lcVector3(Verts[i], Verts[i+1], Verts[i+2]), ModelWorld);
|
||||
sprintf(Line, "v %.2f %.2f %.2f\n", Vertex[0], Vertex[1], Vertex[2]);
|
||||
|
@ -1335,8 +1340,13 @@ void Project::ExportWavefront()
|
|||
sprintf(Line, "g Piece%.3d\n", PartIdx);
|
||||
OBJFile.WriteLine(Line);
|
||||
|
||||
Info->mMesh->ExportWavefrontIndices(OBJFile, lcGetColorCode(ModelParts[PartIdx].ColorIndex), vert);
|
||||
vert += Info->mMesh->mNumVertices;
|
||||
lcMesh* Mesh = Info->GetMesh();
|
||||
|
||||
if (Mesh)
|
||||
{
|
||||
Mesh->ExportWavefrontIndices(OBJFile, lcGetColorCode(ModelParts[PartIdx].ColorIndex), vert);
|
||||
vert += Mesh->mNumVertices;
|
||||
}
|
||||
}
|
||||
|
||||
setlocale(LC_NUMERIC, OldLocale);
|
||||
|
|
|
@ -58,7 +58,7 @@ lcQMainWindow::lcQMainWindow(QWidget *parent)
|
|||
{
|
||||
for (int PieceIdx = 0; PieceIdx < Library->mPieces.GetSize(); PieceIdx++)
|
||||
{
|
||||
lcMesh* Mesh = Library->mPieces[PieceIdx]->mMesh;
|
||||
lcMesh* Mesh = Library->mPieces[PieceIdx]->GetMesh();
|
||||
|
||||
if (Mesh)
|
||||
Mesh->UpdateBuffers();
|
||||
|
|
|
@ -174,11 +174,11 @@ int main(int argc, char *argv[])
|
|||
|
||||
QDir dir;
|
||||
dir.mkpath(cachePath);
|
||||
gMainWindow = new lcMainWindow();
|
||||
|
||||
if (!g_App->Initialize(argc, argv, libPath, LDrawPath, cachePath.toLocal8Bit().data()))
|
||||
return 1;
|
||||
|
||||
gMainWindow = new lcMainWindow();
|
||||
lcQMainWindow w;
|
||||
gMainWindow->mHandle = &w;
|
||||
lcGetActiveModel()->UpdateInterface();
|
||||
|
|
Loading…
Reference in a new issue