2012-03-20 01:57:42 +01:00
|
|
|
#include "lc_global.h"
|
2012-03-29 03:10:55 +02:00
|
|
|
#include "lc_math.h"
|
2012-04-14 04:20:27 +02:00
|
|
|
#include "lc_mesh.h"
|
2011-09-07 23:06:51 +02:00
|
|
|
#include <locale.h>
|
|
|
|
#include "pieceinf.h"
|
|
|
|
#include "camera.h"
|
|
|
|
#include "project.h"
|
2021-01-06 03:48:12 +01:00
|
|
|
#include "lc_instructions.h"
|
2011-09-07 23:06:51 +02:00
|
|
|
#include "image.h"
|
2013-08-16 03:25:51 +02:00
|
|
|
#include "lc_mainwindow.h"
|
2020-12-25 19:43:22 +01:00
|
|
|
#include "lc_view.h"
|
2012-10-02 03:23:44 +02:00
|
|
|
#include "lc_library.h"
|
2011-09-07 23:06:51 +02:00
|
|
|
#include "lc_application.h"
|
2013-08-09 06:57:18 +02:00
|
|
|
#include "lc_profile.h"
|
2016-05-02 21:13:54 +02:00
|
|
|
#include "lc_file.h"
|
2017-06-26 03:20:34 +02:00
|
|
|
#include "lc_zipfile.h"
|
2016-08-01 05:44:15 +02:00
|
|
|
#include "lc_qimagedialog.h"
|
2023-04-30 05:32:27 +02:00
|
|
|
#include "lc_modellistdialog.h"
|
2021-02-21 03:44:12 +01:00
|
|
|
#include "lc_bricklink.h"
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2017-12-11 20:14:37 +01:00
|
|
|
lcHTMLExportOptions::lcHTMLExportOptions(const Project* Project)
|
|
|
|
{
|
|
|
|
QString FileName = Project->GetFileName();
|
|
|
|
|
|
|
|
if (!FileName.isEmpty())
|
|
|
|
PathName = QFileInfo(FileName).canonicalPath();
|
|
|
|
|
|
|
|
int ImageOptions = lcGetProfileInt(LC_PROFILE_HTML_IMAGE_OPTIONS);
|
|
|
|
int HTMLOptions = lcGetProfileInt(LC_PROFILE_HTML_OPTIONS);
|
|
|
|
|
|
|
|
TransparentImages = (ImageOptions & LC_IMAGE_TRANSPARENT) != 0;
|
|
|
|
SubModels = (HTMLOptions & (LC_HTML_SUBMODELS)) != 0;
|
|
|
|
CurrentOnly = (HTMLOptions & LC_HTML_CURRENT_ONLY) != 0;
|
|
|
|
SinglePage = (HTMLOptions & LC_HTML_SINGLEPAGE) != 0;
|
|
|
|
IndexPage = (HTMLOptions & LC_HTML_INDEX) != 0;
|
|
|
|
StepImagesWidth = lcGetProfileInt(LC_PROFILE_HTML_IMAGE_WIDTH);
|
|
|
|
StepImagesHeight = lcGetProfileInt(LC_PROFILE_HTML_IMAGE_HEIGHT);
|
|
|
|
PartsListStep = (HTMLOptions & LC_HTML_LISTSTEP) != 0;
|
|
|
|
PartsListEnd = (HTMLOptions & LC_HTML_LISTEND) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcHTMLExportOptions::SaveDefaults()
|
|
|
|
{
|
|
|
|
int HTMLOptions = 0;
|
|
|
|
|
|
|
|
if (SubModels)
|
|
|
|
HTMLOptions |= LC_HTML_SUBMODELS;
|
|
|
|
if (CurrentOnly)
|
|
|
|
HTMLOptions |= LC_HTML_CURRENT_ONLY;
|
|
|
|
if (SinglePage)
|
|
|
|
HTMLOptions |= LC_HTML_SINGLEPAGE;
|
|
|
|
if (IndexPage)
|
|
|
|
HTMLOptions |= LC_HTML_INDEX;
|
|
|
|
if (PartsListStep)
|
|
|
|
HTMLOptions |= LC_HTML_LISTSTEP;
|
|
|
|
if (PartsListEnd)
|
|
|
|
HTMLOptions |= LC_HTML_LISTEND;
|
|
|
|
|
|
|
|
lcSetProfileInt(LC_PROFILE_HTML_IMAGE_OPTIONS, TransparentImages ? LC_IMAGE_TRANSPARENT : 0);
|
|
|
|
lcSetProfileInt(LC_PROFILE_HTML_OPTIONS, HTMLOptions);
|
|
|
|
lcSetProfileInt(LC_PROFILE_HTML_IMAGE_WIDTH, StepImagesWidth);
|
|
|
|
lcSetProfileInt(LC_PROFILE_HTML_IMAGE_HEIGHT, StepImagesHeight);
|
|
|
|
}
|
|
|
|
|
2020-10-03 12:02:27 +02:00
|
|
|
Project::Project(bool IsPreview)
|
|
|
|
: mIsPreview(IsPreview)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2014-12-08 08:32:39 +01:00
|
|
|
mModified = false;
|
2020-12-16 02:19:32 +01:00
|
|
|
mActiveModel = new lcModel(tr(mIsPreview ? "Preview.ldr" : "New Model.ldr"), this, mIsPreview);
|
2015-02-22 03:39:15 +01:00
|
|
|
mActiveModel->CreatePieceInfo(this);
|
2014-12-16 00:55:17 +01:00
|
|
|
mActiveModel->SetSaved();
|
2014-12-13 00:42:09 +01:00
|
|
|
mModels.Add(mActiveModel);
|
2018-01-02 15:10:58 +01:00
|
|
|
|
2021-01-07 02:55:38 +01:00
|
|
|
if (!mIsPreview && gMainWindow)
|
2020-10-03 12:02:27 +02:00
|
|
|
QObject::connect(&mFileWatcher, SIGNAL(fileChanged(const QString&)), gMainWindow, SLOT(ProjectFileChanged(const QString&)));
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Project::~Project()
|
|
|
|
{
|
2014-12-08 08:32:39 +01:00
|
|
|
mModels.DeleteAll();
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2020-05-03 21:11:51 +02:00
|
|
|
lcModel* Project::GetModel(const QString& FileName) const
|
2018-01-03 04:46:50 +01:00
|
|
|
{
|
|
|
|
for (lcModel* Model : mModels)
|
2020-05-03 21:11:51 +02:00
|
|
|
if (Model->GetProperties().mFileName == FileName)
|
2018-01-03 04:46:50 +01:00
|
|
|
return Model;
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-12-13 00:42:09 +01:00
|
|
|
bool Project::IsModified() const
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2014-12-13 00:42:09 +01:00
|
|
|
if (mModified)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
|
|
|
if (mModels[ModelIdx]->IsModified())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Project::GetTitle() const
|
|
|
|
{
|
2015-02-22 03:39:15 +01:00
|
|
|
if (!mFileName.isEmpty())
|
|
|
|
return QFileInfo(mFileName).fileName();
|
|
|
|
|
2017-12-11 00:01:12 +01:00
|
|
|
return mModels.GetSize() == 1 ? tr("New Model.ldr") : tr("New Model.mpd");
|
2014-12-13 00:42:09 +01:00
|
|
|
}
|
|
|
|
|
2018-04-15 03:27:16 +02:00
|
|
|
QString Project::GetImageFileName(bool AllowCurrentFolder) const
|
2017-12-27 22:55:37 +01:00
|
|
|
{
|
2018-04-15 03:27:16 +02:00
|
|
|
QString FileName = GetFileName();
|
2017-12-27 22:55:37 +01:00
|
|
|
|
|
|
|
if (!FileName.isEmpty())
|
|
|
|
{
|
|
|
|
QString Extension = QFileInfo(FileName).suffix();
|
|
|
|
if (!Extension.isEmpty())
|
|
|
|
FileName = FileName.left(FileName.length() - Extension.length() - 1);
|
|
|
|
}
|
|
|
|
else
|
2018-04-15 03:27:16 +02:00
|
|
|
{
|
2018-04-18 20:28:18 +02:00
|
|
|
if (AllowCurrentFolder)
|
|
|
|
FileName = QLatin1String("image");
|
|
|
|
else
|
2018-04-15 03:27:16 +02:00
|
|
|
{
|
2021-01-08 19:35:52 +01:00
|
|
|
QStringList CachePathList = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
|
|
|
|
FileName = CachePathList.first();
|
2018-04-18 20:28:18 +02:00
|
|
|
FileName = QDir(FileName).absoluteFilePath(QLatin1String("image"));
|
2018-04-15 03:27:16 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-27 22:55:37 +01:00
|
|
|
|
2018-04-15 03:27:16 +02:00
|
|
|
return QDir::toNativeSeparators(FileName) + lcGetProfileString(LC_PROFILE_IMAGE_EXTENSION);
|
2017-12-27 22:55:37 +01:00
|
|
|
}
|
|
|
|
|
2014-12-13 00:42:09 +01:00
|
|
|
void Project::SetActiveModel(int ModelIndex)
|
|
|
|
{
|
|
|
|
if (ModelIndex < 0 || ModelIndex >= mModels.GetSize())
|
|
|
|
return;
|
|
|
|
|
2014-12-25 16:25:50 +01:00
|
|
|
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
2014-12-30 17:56:13 +01:00
|
|
|
mModels[ModelIdx]->SetActive(ModelIdx == ModelIndex);
|
2014-12-25 16:25:50 +01:00
|
|
|
|
2019-03-17 21:27:57 +01:00
|
|
|
std::vector<lcModel*> UpdatedModels;
|
|
|
|
UpdatedModels.reserve(mModels.GetSize());
|
2015-01-17 19:29:10 +01:00
|
|
|
|
2015-01-02 17:44:01 +01:00
|
|
|
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
2015-01-17 19:29:10 +01:00
|
|
|
mModels[ModelIdx]->UpdatePieceInfo(UpdatedModels);
|
2015-01-02 17:44:01 +01:00
|
|
|
|
2014-12-13 00:42:09 +01:00
|
|
|
mActiveModel = mModels[ModelIndex];
|
2021-01-06 18:55:03 +01:00
|
|
|
|
|
|
|
if (!mIsPreview && gMainWindow)
|
|
|
|
{
|
2020-10-03 12:02:27 +02:00
|
|
|
gMainWindow->SetCurrentModelTab(mActiveModel);
|
|
|
|
mActiveModel->UpdateInterface();
|
|
|
|
}
|
2014-12-13 00:42:09 +01:00
|
|
|
}
|
|
|
|
|
2020-05-03 21:11:51 +02:00
|
|
|
void Project::SetActiveModel(const QString& FileName)
|
2017-06-20 05:03:49 +02:00
|
|
|
{
|
2017-06-21 06:43:39 +02:00
|
|
|
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
|
|
|
{
|
2020-05-03 21:11:51 +02:00
|
|
|
if (FileName.compare(mModels[ModelIdx]->GetFileName(), Qt::CaseInsensitive) == 0)
|
2017-06-21 06:43:39 +02:00
|
|
|
{
|
2017-06-20 05:03:49 +02:00
|
|
|
SetActiveModel(ModelIdx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 00:34:51 +02:00
|
|
|
QString Project::GetNewModelName(QWidget* ParentWidget, const QString& DialogTitle, const QString& CurrentName, const QStringList& ExistingModels) const
|
2014-12-13 00:42:09 +01:00
|
|
|
{
|
2016-09-09 00:34:51 +02:00
|
|
|
QString Name = CurrentName;
|
2014-12-13 00:42:09 +01:00
|
|
|
|
2016-09-09 00:34:51 +02:00
|
|
|
if (Name.isEmpty())
|
2014-12-13 00:42:09 +01:00
|
|
|
{
|
2017-12-11 00:01:12 +01:00
|
|
|
const QString Prefix = tr("Submodel #");
|
2016-09-09 00:34:51 +02:00
|
|
|
int Max = 0;
|
2014-12-13 00:42:09 +01:00
|
|
|
|
2016-09-09 00:34:51 +02:00
|
|
|
for (int ModelIdx = 0; ModelIdx < ExistingModels.size(); ModelIdx++)
|
2014-12-13 00:42:09 +01:00
|
|
|
{
|
2019-05-18 20:33:27 +02:00
|
|
|
const QString& ExistingName = ExistingModels[ModelIdx];
|
2016-09-09 00:34:51 +02:00
|
|
|
|
2019-05-18 20:33:27 +02:00
|
|
|
if (ExistingName.startsWith(Prefix))
|
2016-09-09 00:34:51 +02:00
|
|
|
{
|
2019-05-18 20:33:27 +02:00
|
|
|
QString NumberString = ExistingName.mid(Prefix.length());
|
2016-09-09 00:34:51 +02:00
|
|
|
QTextStream Stream(&NumberString);
|
|
|
|
int Number;
|
|
|
|
Stream >> Number;
|
|
|
|
Max = qMax(Max, Number);
|
|
|
|
}
|
2014-12-13 00:42:09 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 00:34:51 +02:00
|
|
|
Name = Prefix + QString::number(Max + 1) + ".ldr";
|
|
|
|
}
|
2014-12-13 00:42:09 +01:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
bool Ok = false;
|
|
|
|
|
2017-12-11 00:01:12 +01:00
|
|
|
Name = QInputDialog::getText(ParentWidget, DialogTitle, tr("Submodel Name:"), QLineEdit::Normal, Name, &Ok);
|
2014-12-13 00:42:09 +01:00
|
|
|
|
|
|
|
if (!Ok)
|
2016-09-09 00:34:51 +02:00
|
|
|
return QString();
|
2014-12-13 00:42:09 +01:00
|
|
|
|
|
|
|
if (Name.isEmpty())
|
2016-09-09 00:34:51 +02:00
|
|
|
{
|
2017-12-11 00:01:12 +01:00
|
|
|
QMessageBox::information(ParentWidget, tr("Empty Name"), tr("The submodel name cannot be empty."));
|
2016-09-09 00:34:51 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-12-13 00:42:09 +01:00
|
|
|
|
2016-09-09 00:34:51 +02:00
|
|
|
bool ExtensionValid = false;
|
2015-12-02 02:16:12 +01:00
|
|
|
|
2016-09-09 00:34:51 +02:00
|
|
|
if (Name.length() < 5)
|
|
|
|
ExtensionValid = false;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString Extension = Name.right(4);
|
2016-09-17 22:21:29 +02:00
|
|
|
if (Extension.compare(".dat", Qt::CaseInsensitive) == 0 || Extension.compare(".ldr", Qt::CaseInsensitive) == 0 || Extension.compare(".mpd", Qt::CaseInsensitive) == 0)
|
2016-09-09 00:34:51 +02:00
|
|
|
ExtensionValid = true;
|
|
|
|
}
|
2015-12-02 02:16:12 +01:00
|
|
|
|
2016-09-09 00:34:51 +02:00
|
|
|
if (!ExtensionValid)
|
2017-12-11 00:01:12 +01:00
|
|
|
Name += ".ldr";
|
2016-09-09 00:34:51 +02:00
|
|
|
|
|
|
|
if (ExistingModels.contains(Name, Qt::CaseInsensitive) && Name != CurrentName)
|
|
|
|
{
|
2017-12-15 21:02:37 +01:00
|
|
|
QMessageBox::information(ParentWidget, tr("Duplicate Submodel"), tr("A submodel named '%1' already exists, please enter a unique name.").arg(Name));
|
2016-09-09 00:34:51 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
lcModel* Project::CreateNewModel(bool ShowModel)
|
|
|
|
{
|
|
|
|
QStringList ModelNames;
|
|
|
|
|
|
|
|
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
2020-05-03 21:11:51 +02:00
|
|
|
ModelNames.append(mModels[ModelIdx]->GetProperties().mFileName);
|
2016-09-09 00:34:51 +02:00
|
|
|
|
2017-12-11 00:01:12 +01:00
|
|
|
QString Name = GetNewModelName(gMainWindow, tr("New Submodel"), QString(), ModelNames);
|
2016-09-09 00:34:51 +02:00
|
|
|
|
|
|
|
if (Name.isEmpty())
|
2017-04-14 02:26:40 +02:00
|
|
|
return nullptr;
|
2016-09-09 00:34:51 +02:00
|
|
|
|
|
|
|
mModified = true;
|
2020-12-16 02:19:32 +01:00
|
|
|
lcModel* Model = new lcModel(Name, this, false);
|
2016-09-09 00:34:51 +02:00
|
|
|
Model->CreatePieceInfo(this);
|
|
|
|
Model->SetSaved();
|
|
|
|
mModels.Add(Model);
|
|
|
|
|
|
|
|
if (ShowModel)
|
|
|
|
{
|
|
|
|
SetActiveModel(mModels.GetSize() - 1);
|
2021-05-02 01:24:55 +02:00
|
|
|
|
|
|
|
lcView* ActiveView = gMainWindow ? gMainWindow->GetActiveView() : nullptr;
|
|
|
|
if (ActiveView)
|
|
|
|
ActiveView->GetCamera()->SetViewpoint(lcViewpoint::Home);
|
|
|
|
|
2016-09-09 00:34:51 +02:00
|
|
|
gMainWindow->UpdateTitle();
|
2014-12-13 00:42:09 +01:00
|
|
|
}
|
2016-09-09 00:34:51 +02:00
|
|
|
else
|
|
|
|
SetActiveModel(mModels.FindIndex(mActiveModel));
|
2015-12-02 02:16:12 +01:00
|
|
|
|
|
|
|
return Model;
|
2014-12-13 00:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Project::ShowModelListDialog()
|
|
|
|
{
|
2023-04-30 05:10:50 +02:00
|
|
|
lcModelListDialog Dialog(gMainWindow, mModels);
|
2014-12-13 00:42:09 +01:00
|
|
|
|
2020-09-07 20:29:37 +02:00
|
|
|
if (Dialog.exec() != QDialog::Accepted)
|
2014-12-13 00:42:09 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
lcArray<lcModel*> NewModels;
|
2020-09-07 20:29:37 +02:00
|
|
|
std::vector<lcModelListDialogEntry> Results = Dialog.GetResults();
|
2014-12-13 00:42:09 +01:00
|
|
|
|
2020-09-07 20:29:37 +02:00
|
|
|
for (const lcModelListDialogEntry& Entry : Results)
|
2014-12-13 00:42:09 +01:00
|
|
|
{
|
2020-09-07 20:29:37 +02:00
|
|
|
lcModel* Model = Entry.ExistingModel;
|
2014-12-13 00:42:09 +01:00
|
|
|
|
|
|
|
if (!Model)
|
|
|
|
{
|
2020-09-07 20:29:37 +02:00
|
|
|
const lcModel* Source = Entry.DuplicateSource;
|
|
|
|
|
|
|
|
if (!Source)
|
|
|
|
{
|
2020-12-16 02:19:32 +01:00
|
|
|
Model = new lcModel(Entry.Name, this, false);
|
2020-09-07 20:29:37 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-16 02:19:32 +01:00
|
|
|
Model = new lcModel(Source->GetProperties().mFileName, this, false);
|
2020-09-07 20:29:37 +02:00
|
|
|
|
|
|
|
QByteArray File;
|
|
|
|
|
|
|
|
QTextStream SaveStream(&File);
|
|
|
|
Source->SaveLDraw(SaveStream, false);
|
|
|
|
SaveStream.flush();
|
|
|
|
|
|
|
|
QBuffer Buffer(&File);
|
|
|
|
Buffer.open(QIODevice::ReadOnly);
|
|
|
|
|
|
|
|
Model->LoadLDraw(Buffer, this);
|
|
|
|
Model->SetFileName(Entry.Name);
|
|
|
|
Model->CreatePieceInfo(this);
|
|
|
|
}
|
|
|
|
|
2015-02-22 03:39:15 +01:00
|
|
|
Model->CreatePieceInfo(this);
|
2014-12-16 00:55:17 +01:00
|
|
|
Model->SetSaved();
|
2020-09-07 20:29:37 +02:00
|
|
|
|
2014-12-13 00:42:09 +01:00
|
|
|
mModified = true;
|
|
|
|
}
|
2020-09-07 20:29:37 +02:00
|
|
|
else if (Model->GetProperties().mFileName != Entry.Name)
|
2014-12-13 00:42:09 +01:00
|
|
|
{
|
2020-09-07 20:29:37 +02:00
|
|
|
Model->SetFileName(Entry.Name);
|
|
|
|
lcGetPiecesLibrary()->RenamePiece(Model->GetPieceInfo(), Entry.Name.toLatin1().constData());
|
2017-07-24 04:35:18 +02:00
|
|
|
|
|
|
|
for (lcModel* CheckModel : mModels)
|
|
|
|
CheckModel->RenamePiece(Model->GetPieceInfo());
|
|
|
|
|
2014-12-13 00:42:09 +01:00
|
|
|
mModified = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NewModels.Add(Model);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
|
|
|
{
|
|
|
|
lcModel* Model = mModels[ModelIdx];
|
|
|
|
|
|
|
|
if (NewModels.FindIndex(Model) == -1)
|
|
|
|
{
|
|
|
|
delete Model;
|
|
|
|
mModified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mModels = NewModels;
|
|
|
|
|
|
|
|
gMainWindow->UpdateTitle();
|
2019-03-10 17:21:09 +01:00
|
|
|
gMainWindow->UpdateModels();
|
2019-03-12 21:08:43 +01:00
|
|
|
|
|
|
|
int ModelIndex = Dialog.GetActiveModelIndex();
|
|
|
|
if (ModelIndex != -1)
|
|
|
|
SetActiveModel(ModelIndex);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2018-01-02 15:10:58 +01:00
|
|
|
void Project::SetFileName(const QString& FileName)
|
|
|
|
{
|
2019-07-05 00:35:52 +02:00
|
|
|
if (mFileName == FileName)
|
|
|
|
return;
|
|
|
|
|
2020-10-03 12:02:27 +02:00
|
|
|
if (!mIsPreview && !mFileName.isEmpty())
|
2018-01-02 15:10:58 +01:00
|
|
|
mFileWatcher.removePath(mFileName);
|
|
|
|
|
2020-10-03 12:02:27 +02:00
|
|
|
if (!mIsPreview && !FileName.isEmpty())
|
2018-01-02 15:10:58 +01:00
|
|
|
mFileWatcher.addPath(FileName);
|
|
|
|
|
|
|
|
mFileName = FileName;
|
|
|
|
}
|
|
|
|
|
2021-04-17 20:49:41 +02:00
|
|
|
bool Project::Load(const QString& FileName, bool ShowErrors)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2020-10-03 12:02:27 +02:00
|
|
|
QWidget *parent = nullptr;
|
|
|
|
if (!mIsPreview)
|
|
|
|
parent = gMainWindow;
|
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
QFile File(FileName);
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
if (!File.open(QIODevice::ReadOnly))
|
2019-03-10 21:41:21 +01:00
|
|
|
{
|
2021-04-17 20:49:41 +02:00
|
|
|
if (ShowErrors)
|
|
|
|
QMessageBox::warning(parent, tr("Error"), tr("Error reading file '%1':\n%2").arg(FileName, File.errorString()));
|
2014-12-08 08:32:39 +01:00
|
|
|
return false;
|
2019-03-10 21:41:21 +01:00
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-12-13 00:42:09 +01:00
|
|
|
mModels.DeleteAll();
|
2018-01-02 15:10:58 +01:00
|
|
|
SetFileName(FileName);
|
2015-02-22 03:39:15 +01:00
|
|
|
QFileInfo FileInfo(FileName);
|
|
|
|
QString Extension = FileInfo.suffix().toLower();
|
2013-12-19 14:41:49 +01:00
|
|
|
|
2016-09-23 21:48:29 +02:00
|
|
|
QByteArray FileData = File.readAll();
|
|
|
|
bool LoadDAT;
|
2016-05-28 19:35:13 +02:00
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
if (Extension == QLatin1String("dat") || Extension == QLatin1String("ldr") || Extension == QLatin1String("mpd"))
|
2016-09-23 21:48:29 +02:00
|
|
|
LoadDAT = true;
|
|
|
|
else if (Extension == QLatin1String("lcd") || Extension == QLatin1String("leocad"))
|
|
|
|
LoadDAT = false;
|
|
|
|
else
|
2019-03-10 21:41:21 +01:00
|
|
|
LoadDAT = FileData.size() > 7 && memcmp(FileData, "LeoCAD ", 7);
|
2016-09-23 21:48:29 +02:00
|
|
|
|
|
|
|
if (LoadDAT)
|
2013-01-06 20:24:25 +01:00
|
|
|
{
|
2015-01-06 16:38:51 +01:00
|
|
|
QBuffer Buffer(&FileData);
|
|
|
|
Buffer.open(QIODevice::ReadOnly);
|
2019-11-26 21:13:22 +01:00
|
|
|
std::vector<std::pair<int, lcModel*>> Models;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2015-01-06 16:38:51 +01:00
|
|
|
while (!Buffer.atEnd())
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2020-12-16 02:19:32 +01:00
|
|
|
lcModel* Model = new lcModel(QString(), this, mIsPreview);
|
2019-11-26 21:13:22 +01:00
|
|
|
int Pos = Model->SplitMPD(Buffer);
|
2015-03-25 16:33:58 +01:00
|
|
|
|
2020-05-03 21:11:51 +02:00
|
|
|
if (Models.empty() || !Model->GetFileName().isEmpty())
|
2017-08-29 20:11:29 +02:00
|
|
|
{
|
2020-11-26 04:54:32 +01:00
|
|
|
auto ModelCompare = [Model](const std::pair<int, lcModel*>& ModelIt)
|
|
|
|
{
|
2021-01-14 00:36:12 +01:00
|
|
|
return ModelIt.second->GetFileName().compare(Model->GetFileName(), Qt::CaseInsensitive) == 0;
|
2020-11-26 04:54:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
if (std::find_if(Models.begin(), Models.end(), ModelCompare) == Models.end())
|
|
|
|
{
|
|
|
|
mModels.Add(Model);
|
|
|
|
Models.emplace_back(std::make_pair(Pos, Model));
|
|
|
|
Model->CreatePieceInfo(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
delete Model;
|
2017-08-29 20:11:29 +02:00
|
|
|
}
|
2015-03-25 16:33:58 +01:00
|
|
|
else
|
|
|
|
delete Model;
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
2016-11-26 02:12:19 +01:00
|
|
|
|
2019-11-26 21:13:22 +01:00
|
|
|
for (size_t ModelIdx = 0; ModelIdx < Models.size(); ModelIdx++)
|
2016-11-26 02:12:19 +01:00
|
|
|
{
|
2019-11-26 21:13:22 +01:00
|
|
|
Buffer.seek(Models[ModelIdx].first);
|
|
|
|
lcModel* Model = Models[ModelIdx].second;
|
2016-11-26 02:12:19 +01:00
|
|
|
Model->LoadLDraw(Buffer, this);
|
|
|
|
Model->SetSaved();
|
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-08 08:32:39 +01:00
|
|
|
lcMemFile MemFile;
|
|
|
|
MemFile.WriteBuffer(FileData.constData(), FileData.size());
|
|
|
|
MemFile.Seek(0, SEEK_SET);
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2020-12-16 02:19:32 +01:00
|
|
|
lcModel* Model = new lcModel(QString(), this, mIsPreview);
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
if (Model->LoadBinary(&MemFile))
|
2014-12-16 00:55:17 +01:00
|
|
|
{
|
2014-12-08 08:32:39 +01:00
|
|
|
mModels.Add(Model);
|
2017-08-29 20:11:29 +02:00
|
|
|
Model->CreatePieceInfo(this);
|
2014-12-16 00:55:17 +01:00
|
|
|
Model->SetSaved();
|
|
|
|
}
|
2014-12-08 08:32:39 +01:00
|
|
|
else
|
|
|
|
delete Model;
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
if (mModels.IsEmpty())
|
2019-03-10 21:41:21 +01:00
|
|
|
{
|
2021-04-17 20:49:41 +02:00
|
|
|
if (ShowErrors)
|
|
|
|
QMessageBox::warning(parent, tr("Error"), tr("Error loading file '%1':\nFile format is not recognized.").arg(FileName));
|
2014-12-08 08:32:39 +01:00
|
|
|
return false;
|
2019-03-10 21:41:21 +01:00
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2015-02-22 03:39:15 +01:00
|
|
|
if (mModels.GetSize() == 1)
|
2014-12-24 16:52:52 +01:00
|
|
|
{
|
2015-02-22 03:39:15 +01:00
|
|
|
lcModel* Model = mModels[0];
|
2014-12-24 16:52:52 +01:00
|
|
|
|
2020-05-03 21:11:51 +02:00
|
|
|
if (Model->GetProperties().mFileName.isEmpty())
|
2017-08-29 20:11:29 +02:00
|
|
|
{
|
2020-05-03 21:11:51 +02:00
|
|
|
Model->SetFileName(FileInfo.fileName());
|
2017-08-29 20:11:29 +02:00
|
|
|
lcGetPiecesLibrary()->RenamePiece(Model->GetPieceInfo(), FileInfo.fileName().toLatin1());
|
|
|
|
}
|
2014-12-24 16:52:52 +01:00
|
|
|
}
|
|
|
|
|
2019-03-17 21:27:57 +01:00
|
|
|
std::vector<lcModel*> UpdatedModels;
|
|
|
|
UpdatedModels.reserve(mModels.GetSize());
|
2015-02-23 21:25:53 +01:00
|
|
|
|
2018-02-07 07:07:35 +01:00
|
|
|
for (lcModel* Model : mModels)
|
|
|
|
{
|
|
|
|
Model->UpdateMesh();
|
|
|
|
Model->UpdatePieceInfo(UpdatedModels);
|
|
|
|
}
|
2015-02-23 21:25:53 +01:00
|
|
|
|
2014-12-13 00:42:09 +01:00
|
|
|
mModified = false;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
bool Project::Save(const QString& FileName)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2019-07-15 03:03:17 +02:00
|
|
|
SetFileName(QString());
|
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
QFile File(FileName);
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
if (!File.open(QIODevice::WriteOnly))
|
2012-03-23 00:44:56 +01:00
|
|
|
{
|
2015-01-26 00:04:39 +01:00
|
|
|
QMessageBox::warning(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
|
2014-12-08 08:32:39 +01:00
|
|
|
return false;
|
2012-03-23 00:44:56 +01:00
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
QTextStream Stream(&File);
|
2016-09-26 02:15:30 +02:00
|
|
|
bool Success = Save(Stream);
|
2018-01-02 15:10:58 +01:00
|
|
|
File.close();
|
2016-09-26 02:15:30 +02:00
|
|
|
|
2019-07-05 00:35:52 +02:00
|
|
|
if (Success)
|
|
|
|
{
|
|
|
|
SetFileName(FileName);
|
|
|
|
mModified = false;
|
|
|
|
}
|
2016-09-26 02:15:30 +02:00
|
|
|
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Project::Save(QTextStream& Stream)
|
|
|
|
{
|
2014-12-08 08:32:39 +01:00
|
|
|
bool MPD = mModels.GetSize() > 1;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2019-07-05 00:35:52 +02:00
|
|
|
for (lcModel* Model : mModels)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2014-12-08 08:32:39 +01:00
|
|
|
if (MPD)
|
2020-05-03 21:11:51 +02:00
|
|
|
Stream << QLatin1String("0 FILE ") << Model->GetProperties().mFileName << QLatin1String("\r\n");
|
2013-08-16 18:16:45 +02:00
|
|
|
|
2016-02-17 00:11:52 +01:00
|
|
|
Model->SaveLDraw(Stream, false);
|
2014-12-08 08:32:39 +01:00
|
|
|
Model->SetSaved();
|
2013-08-16 18:16:45 +02:00
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
if (MPD)
|
2014-12-26 18:09:11 +01:00
|
|
|
Stream << QLatin1String("0 NOFILE\r\n");
|
2014-12-08 08:32:39 +01:00
|
|
|
}
|
2013-08-16 18:16:45 +02:00
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-08-16 18:16:45 +02:00
|
|
|
|
2014-12-23 18:02:23 +01:00
|
|
|
void Project::Merge(Project* Other)
|
|
|
|
{
|
2018-11-01 00:16:45 +01:00
|
|
|
for (lcModel* Model : Other->mModels)
|
2015-02-22 03:39:15 +01:00
|
|
|
{
|
2020-05-03 21:11:51 +02:00
|
|
|
QString FileName = Model->GetProperties().mFileName;
|
2015-02-22 03:39:15 +01:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
bool Duplicate = false;
|
|
|
|
|
|
|
|
for (int SearchIdx = 0; SearchIdx < mModels.GetSize(); SearchIdx++)
|
|
|
|
{
|
2020-05-03 21:11:51 +02:00
|
|
|
if (mModels[SearchIdx]->GetProperties().mFileName == FileName)
|
2015-02-22 03:39:15 +01:00
|
|
|
{
|
|
|
|
Duplicate = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Duplicate)
|
|
|
|
break;
|
|
|
|
|
2020-05-03 21:11:51 +02:00
|
|
|
FileName = tr("Merged ") + FileName;
|
|
|
|
Model->SetFileName(FileName);
|
2015-02-22 03:39:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mModels.Add(Model);
|
|
|
|
}
|
2014-12-23 18:02:23 +01:00
|
|
|
|
2018-11-01 00:16:45 +01:00
|
|
|
Other->mModels.RemoveAll();
|
2014-12-23 18:02:23 +01:00
|
|
|
mModified = true;
|
|
|
|
}
|
|
|
|
|
2017-06-26 03:20:34 +02:00
|
|
|
bool Project::ImportLDD(const QString& FileName)
|
|
|
|
{
|
|
|
|
lcZipFile ZipFile;
|
|
|
|
|
|
|
|
if (!ZipFile.OpenRead(FileName))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
lcMemFile XMLFile;
|
|
|
|
if (!ZipFile.ExtractFile("IMAGE100.LXFML", XMLFile))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
mModels.DeleteAll();
|
2020-05-03 21:11:51 +02:00
|
|
|
QString ModelName = QFileInfo(FileName).completeBaseName();
|
2020-12-16 02:19:32 +01:00
|
|
|
lcModel* Model = new lcModel(ModelName, this, false);
|
2017-06-26 03:20:34 +02:00
|
|
|
|
|
|
|
if (Model->LoadLDD(QString::fromUtf8((const char*)XMLFile.mBuffer)))
|
|
|
|
{
|
|
|
|
mModels.Add(Model);
|
|
|
|
Model->SetSaved();
|
|
|
|
}
|
|
|
|
else
|
2019-05-18 20:33:27 +02:00
|
|
|
{
|
2017-06-26 03:20:34 +02:00
|
|
|
delete Model;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
|
|
|
mModels[ModelIdx]->CreatePieceInfo(this);
|
|
|
|
|
2019-03-17 21:27:57 +01:00
|
|
|
std::vector<lcModel*> UpdatedModels;
|
|
|
|
UpdatedModels.reserve(mModels.GetSize());
|
2017-08-20 22:47:53 +02:00
|
|
|
|
|
|
|
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
|
|
|
mModels[ModelIdx]->UpdatePieceInfo(UpdatedModels);
|
|
|
|
|
|
|
|
mModified = false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Project::ImportInventory(const QByteArray& Inventory, const QString& Name, const QString& Description)
|
|
|
|
{
|
|
|
|
if (Inventory.isEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
mModels.DeleteAll();
|
2020-12-16 02:19:32 +01:00
|
|
|
lcModel* Model = new lcModel(Name, this, false);
|
2017-08-20 22:47:53 +02:00
|
|
|
|
|
|
|
if (Model->LoadInventory(Inventory))
|
|
|
|
{
|
|
|
|
mModels.Add(Model);
|
|
|
|
Model->SetSaved();
|
|
|
|
}
|
|
|
|
else
|
2019-05-18 20:33:27 +02:00
|
|
|
{
|
2017-08-20 22:47:53 +02:00
|
|
|
delete Model;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-18 20:33:27 +02:00
|
|
|
Model->SetDescription(Description);
|
|
|
|
|
2017-08-20 22:47:53 +02:00
|
|
|
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
|
|
|
mModels[ModelIdx]->CreatePieceInfo(this);
|
|
|
|
|
2019-03-17 21:27:57 +01:00
|
|
|
std::vector<lcModel*> UpdatedModels;
|
|
|
|
UpdatedModels.reserve(mModels.GetSize());
|
2017-06-26 03:20:34 +02:00
|
|
|
|
|
|
|
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
|
|
|
|
mModels[ModelIdx]->UpdatePieceInfo(UpdatedModels);
|
|
|
|
|
|
|
|
mModified = false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-28 01:39:51 +02:00
|
|
|
std::vector<lcModelPartsEntry> Project::GetModelParts()
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2019-05-28 01:39:51 +02:00
|
|
|
std::vector<lcModelPartsEntry> ModelParts;
|
|
|
|
|
2014-12-30 17:30:12 +01:00
|
|
|
if (mModels.IsEmpty())
|
2019-05-28 01:39:51 +02:00
|
|
|
return ModelParts;
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
for (lcModel* Model : mModels)
|
|
|
|
Model->CalculateStep(LC_STEP_MAX);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
mModels[0]->GetModelParts(lcMatrix44Identity(), gDefaultColor, ModelParts);
|
|
|
|
|
|
|
|
SetActiveModel(mModels.FindIndex(mActiveModel));
|
2019-05-28 01:39:51 +02:00
|
|
|
|
|
|
|
return ModelParts;
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
|
|
|
|
2019-05-28 01:39:51 +02:00
|
|
|
bool Project::ExportModel(const QString& FileName, lcModel* Model) const
|
2017-12-11 00:01:12 +01:00
|
|
|
{
|
|
|
|
QFile File(FileName);
|
|
|
|
|
|
|
|
if (!File.open(QIODevice::WriteOnly))
|
|
|
|
{
|
|
|
|
QMessageBox::warning(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream Stream(&File);
|
|
|
|
|
|
|
|
Model->SaveLDraw(Stream, false);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-27 21:39:43 +01:00
|
|
|
QString Project::GetExportFileName(const QString& FileName, const QString& DefaultExtension, const QString& DialogTitle, const QString& DialogFilter) const
|
|
|
|
{
|
|
|
|
if (!FileName.isEmpty())
|
|
|
|
return FileName;
|
|
|
|
|
|
|
|
QString SaveFileName;
|
|
|
|
|
|
|
|
if (!mFileName.isEmpty())
|
|
|
|
SaveFileName = mFileName;
|
|
|
|
else
|
|
|
|
SaveFileName = GetTitle();
|
|
|
|
|
|
|
|
QString Extension = QFileInfo(SaveFileName).suffix().toLower();
|
|
|
|
|
|
|
|
if (Extension.isEmpty())
|
|
|
|
SaveFileName += "." + DefaultExtension;
|
|
|
|
else if (Extension != DefaultExtension && SaveFileName.length() > 4)
|
|
|
|
{
|
|
|
|
SaveFileName = SaveFileName.left(SaveFileName.length() - Extension.length() - 1);
|
|
|
|
SaveFileName += "." + DefaultExtension;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QFileDialog::getSaveFileName(gMainWindow, DialogTitle, SaveFileName, DialogFilter);
|
|
|
|
}
|
|
|
|
|
2021-01-11 03:07:27 +01:00
|
|
|
bool Project::Export3DStudio(const QString& FileName)
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2019-05-28 01:39:51 +02:00
|
|
|
std::vector<lcModelPartsEntry> ModelParts = GetModelParts();
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2019-05-28 01:39:51 +02:00
|
|
|
if (ModelParts.empty())
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2015-01-30 17:30:13 +01:00
|
|
|
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Nothing to export."));
|
2021-01-11 03:07:27 +01:00
|
|
|
return false;
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
|
|
|
|
2015-03-27 21:39:43 +01:00
|
|
|
QString SaveFileName = GetExportFileName(FileName, "3ds", tr("Export 3D Studio"), tr("3DS Files (*.3ds);;All Files (*.*)"));
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2015-03-27 21:39:43 +01:00
|
|
|
if (SaveFileName.isEmpty())
|
2021-01-11 03:07:27 +01:00
|
|
|
return false;
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
lcDiskFile File(SaveFileName);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
if (!File.Open(QIODevice::WriteOnly))
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2017-08-11 03:40:43 +02:00
|
|
|
QMessageBox::warning(gMainWindow, tr("LeoCAD"), tr("Could not open file '%1' for writing.").arg(SaveFileName));
|
2021-01-11 03:07:27 +01:00
|
|
|
return false;
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
long M3DStart = File.GetPosition();
|
|
|
|
File.WriteU16(0x4D4D); // CHK_M3DMAGIC
|
|
|
|
File.WriteU32(0);
|
|
|
|
|
|
|
|
File.WriteU16(0x0002); // CHK_M3D_VERSION
|
|
|
|
File.WriteU32(10);
|
|
|
|
File.WriteU32(3);
|
|
|
|
|
|
|
|
long MDataStart = File.GetPosition();
|
|
|
|
File.WriteU16(0x3D3D); // CHK_MDATA
|
|
|
|
File.WriteU32(0);
|
|
|
|
|
|
|
|
File.WriteU16(0x3D3E); // CHK_MESH_VERSION
|
|
|
|
File.WriteU32(10);
|
|
|
|
File.WriteU32(3);
|
|
|
|
|
|
|
|
const int MaterialNameLength = 11;
|
|
|
|
char MaterialName[32];
|
|
|
|
|
2019-07-09 03:34:34 +02:00
|
|
|
for (size_t ColorIdx = 0; ColorIdx < gColorList.size(); ColorIdx++)
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
|
|
|
lcColor* Color = &gColorList[ColorIdx];
|
|
|
|
|
2019-07-09 03:34:34 +02:00
|
|
|
sprintf(MaterialName, "Material%03d", (int)ColorIdx);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
long MaterialStart = File.GetPosition();
|
|
|
|
File.WriteU16(0xAFFF); // CHK_MAT_ENTRY
|
|
|
|
File.WriteU32(0);
|
|
|
|
|
|
|
|
File.WriteU16(0xA000); // CHK_MAT_NAME
|
|
|
|
File.WriteU32(6 + MaterialNameLength + 1);
|
|
|
|
File.WriteBuffer(MaterialName, MaterialNameLength + 1);
|
|
|
|
|
|
|
|
File.WriteU16(0xA010); // CHK_MAT_AMBIENT
|
|
|
|
File.WriteU32(24);
|
|
|
|
|
|
|
|
File.WriteU16(0x0011); // CHK_COLOR_24
|
|
|
|
File.WriteU32(9);
|
|
|
|
|
|
|
|
File.WriteU8(floor(255.0 * Color->Value[0] + 0.5));
|
|
|
|
File.WriteU8(floor(255.0 * Color->Value[1] + 0.5));
|
|
|
|
File.WriteU8(floor(255.0 * Color->Value[2] + 0.5));
|
|
|
|
|
|
|
|
File.WriteU16(0x0012); // CHK_LIN_COLOR_24
|
|
|
|
File.WriteU32(9);
|
|
|
|
|
|
|
|
File.WriteU8(floor(255.0 * Color->Value[0] + 0.5));
|
|
|
|
File.WriteU8(floor(255.0 * Color->Value[1] + 0.5));
|
|
|
|
File.WriteU8(floor(255.0 * Color->Value[2] + 0.5));
|
|
|
|
|
|
|
|
File.WriteU16(0xA020); // CHK_MAT_AMBIENT
|
|
|
|
File.WriteU32(24);
|
|
|
|
|
|
|
|
File.WriteU16(0x0011); // CHK_COLOR_24
|
|
|
|
File.WriteU32(9);
|
|
|
|
|
|
|
|
File.WriteU8(floor(255.0 * Color->Value[0] + 0.5));
|
|
|
|
File.WriteU8(floor(255.0 * Color->Value[1] + 0.5));
|
|
|
|
File.WriteU8(floor(255.0 * Color->Value[2] + 0.5));
|
|
|
|
|
|
|
|
File.WriteU16(0x0012); // CHK_LIN_COLOR_24
|
|
|
|
File.WriteU32(9);
|
|
|
|
|
|
|
|
File.WriteU8(floor(255.0 * Color->Value[0] + 0.5));
|
|
|
|
File.WriteU8(floor(255.0 * Color->Value[1] + 0.5));
|
|
|
|
File.WriteU8(floor(255.0 * Color->Value[2] + 0.5));
|
|
|
|
|
|
|
|
File.WriteU16(0xA030); // CHK_MAT_SPECULAR
|
|
|
|
File.WriteU32(24);
|
|
|
|
|
|
|
|
File.WriteU16(0x0011); // CHK_COLOR_24
|
|
|
|
File.WriteU32(9);
|
|
|
|
|
|
|
|
File.WriteU8(floor(255.0 * 0.9f + 0.5));
|
|
|
|
File.WriteU8(floor(255.0 * 0.9f + 0.5));
|
|
|
|
File.WriteU8(floor(255.0 * 0.9f + 0.5));
|
|
|
|
|
|
|
|
File.WriteU16(0x0012); // CHK_LIN_COLOR_24
|
|
|
|
File.WriteU32(9);
|
|
|
|
|
|
|
|
File.WriteU8(floor(255.0 * 0.9f + 0.5));
|
|
|
|
File.WriteU8(floor(255.0 * 0.9f + 0.5));
|
|
|
|
File.WriteU8(floor(255.0 * 0.9f + 0.5));
|
|
|
|
|
|
|
|
File.WriteU16(0xA040); // CHK_MAT_SHININESS
|
|
|
|
File.WriteU32(14);
|
|
|
|
|
|
|
|
File.WriteU16(0x0030); // CHK_INT_PERCENTAGE
|
|
|
|
File.WriteU32(8);
|
|
|
|
|
2017-12-02 21:22:04 +01:00
|
|
|
File.WriteS16((quint8)floor(100.0 * 0.25 + 0.5));
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0xA041); // CHK_MAT_SHIN2PCT
|
|
|
|
File.WriteU32(14);
|
|
|
|
|
|
|
|
File.WriteU16(0x0030); // CHK_INT_PERCENTAGE
|
|
|
|
File.WriteU32(8);
|
|
|
|
|
2017-12-02 21:22:04 +01:00
|
|
|
File.WriteS16((quint8)floor(100.0 * 0.05 + 0.5));
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0xA050); // CHK_MAT_TRANSPARENCY
|
|
|
|
File.WriteU32(14);
|
|
|
|
|
|
|
|
File.WriteU16(0x0030); // CHK_INT_PERCENTAGE
|
|
|
|
File.WriteU32(8);
|
|
|
|
|
2017-12-02 21:22:04 +01:00
|
|
|
File.WriteS16((quint8)floor(100.0 * (1.0f - Color->Value[3]) + 0.5));
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0xA052); // CHK_MAT_XPFALL
|
|
|
|
File.WriteU32(14);
|
|
|
|
|
|
|
|
File.WriteU16(0x0030); // CHK_INT_PERCENTAGE
|
|
|
|
File.WriteU32(8);
|
|
|
|
|
2017-12-02 21:22:04 +01:00
|
|
|
File.WriteS16((quint8)floor(100.0 * 0.0 + 0.5));
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0xA053); // CHK_MAT_REFBLUR
|
|
|
|
File.WriteU32(14);
|
|
|
|
|
|
|
|
File.WriteU16(0x0030); // CHK_INT_PERCENTAGE
|
|
|
|
File.WriteU32(8);
|
|
|
|
|
2017-12-02 21:22:04 +01:00
|
|
|
File.WriteS16((quint8)floor(100.0 * 0.2 + 0.5));
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0xA100); // CHK_MAT_SHADING
|
|
|
|
File.WriteU32(8);
|
|
|
|
|
|
|
|
File.WriteS16(3);
|
|
|
|
|
|
|
|
File.WriteU16(0xA084); // CHK_MAT_SELF_ILPCT
|
|
|
|
File.WriteU32(14);
|
|
|
|
|
|
|
|
File.WriteU16(0x0030); // CHK_INT_PERCENTAGE
|
|
|
|
File.WriteU32(8);
|
|
|
|
|
2017-12-02 21:22:04 +01:00
|
|
|
File.WriteS16((quint8)floor(100.0 * 0.0 + 0.5));
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0xA081); // CHK_MAT_TWO_SIDE
|
|
|
|
File.WriteU32(6);
|
|
|
|
|
|
|
|
File.WriteU16(0xA087); // CHK_MAT_WIRE_SIZE
|
|
|
|
File.WriteU32(10);
|
|
|
|
|
|
|
|
File.WriteFloat(1.0f);
|
|
|
|
|
|
|
|
long MaterialEnd = File.GetPosition();
|
|
|
|
File.Seek(MaterialStart + 2, SEEK_SET);
|
|
|
|
File.WriteU32(MaterialEnd - MaterialStart);
|
|
|
|
File.Seek(MaterialEnd, SEEK_SET);
|
|
|
|
}
|
|
|
|
|
|
|
|
const lcModelProperties& Properties = mModels[0]->GetProperties();
|
|
|
|
|
|
|
|
File.WriteU16(0x0100); // CHK_MASTER_SCALE
|
|
|
|
File.WriteU32(10);
|
|
|
|
|
|
|
|
File.WriteFloat(1.0f);
|
|
|
|
|
|
|
|
File.WriteU16(0x1400); // CHK_LO_SHADOW_BIAS
|
|
|
|
File.WriteU32(10);
|
|
|
|
|
|
|
|
File.WriteFloat(1.0f);
|
|
|
|
|
|
|
|
File.WriteU16(0x1420); // CHK_SHADOW_MAP_SIZE
|
|
|
|
File.WriteU32(8);
|
|
|
|
|
|
|
|
File.WriteS16(512);
|
|
|
|
|
|
|
|
File.WriteU16(0x1450); // CHK_SHADOW_FILTER
|
|
|
|
File.WriteU32(10);
|
|
|
|
|
|
|
|
File.WriteFloat(3.0f);
|
|
|
|
|
|
|
|
File.WriteU16(0x1460); // CHK_RAY_BIAS
|
|
|
|
File.WriteU32(10);
|
|
|
|
|
|
|
|
File.WriteFloat(1.0f);
|
|
|
|
|
|
|
|
File.WriteU16(0x1500); // CHK_O_CONSTS
|
|
|
|
File.WriteU32(18);
|
|
|
|
|
|
|
|
File.WriteFloat(0.0f);
|
|
|
|
File.WriteFloat(0.0f);
|
|
|
|
File.WriteFloat(0.0f);
|
|
|
|
|
|
|
|
File.WriteU16(0x2100); // CHK_AMBIENT_LIGHT
|
|
|
|
File.WriteU32(42);
|
|
|
|
|
|
|
|
File.WriteU16(0x0010); // CHK_COLOR_F
|
|
|
|
File.WriteU32(18);
|
|
|
|
|
|
|
|
File.WriteFloats(Properties.mAmbientColor, 3);
|
|
|
|
|
|
|
|
File.WriteU16(0x0013); // CHK_LIN_COLOR_F
|
|
|
|
File.WriteU32(18);
|
|
|
|
|
|
|
|
File.WriteFloats(Properties.mAmbientColor, 3);
|
|
|
|
|
|
|
|
File.WriteU16(0x1200); // CHK_SOLID_BGND
|
|
|
|
File.WriteU32(42);
|
|
|
|
|
|
|
|
File.WriteU16(0x0010); // CHK_COLOR_F
|
|
|
|
File.WriteU32(18);
|
|
|
|
|
2020-11-26 20:51:50 +01:00
|
|
|
const lcPreferences& Preferences = lcGetPreferences();
|
|
|
|
lcVector3 BackgroundSolidColor = lcVector3FromColor(Preferences.mBackgroundSolidColor);
|
|
|
|
|
|
|
|
File.WriteFloats(BackgroundSolidColor, 3);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0x0013); // CHK_LIN_COLOR_F
|
|
|
|
File.WriteU32(18);
|
|
|
|
|
2020-11-26 20:51:50 +01:00
|
|
|
File.WriteFloats(BackgroundSolidColor, 3);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0x1300); // CHK_V_GRADIENT
|
|
|
|
File.WriteU32(118);
|
|
|
|
|
|
|
|
File.WriteFloat(1.0f);
|
|
|
|
|
|
|
|
File.WriteU16(0x0010); // CHK_COLOR_F
|
|
|
|
File.WriteU32(18);
|
|
|
|
|
2020-11-26 20:51:50 +01:00
|
|
|
const lcVector3 BackgroundGradientColor1 = lcVector3FromColor(Preferences.mBackgroundGradientColorTop);
|
|
|
|
const lcVector3 BackgroundGradientColor2 = lcVector3FromColor(Preferences.mBackgroundGradientColorBottom);
|
|
|
|
|
|
|
|
File.WriteFloats(BackgroundGradientColor1, 3);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0x0013); // CHK_LIN_COLOR_F
|
|
|
|
File.WriteU32(18);
|
|
|
|
|
2020-11-26 20:51:50 +01:00
|
|
|
File.WriteFloats(BackgroundGradientColor1, 3);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0x0010); // CHK_COLOR_F
|
|
|
|
File.WriteU32(18);
|
|
|
|
|
2020-11-26 20:51:50 +01:00
|
|
|
File.WriteFloats((BackgroundGradientColor1 + BackgroundGradientColor2) / 2.0f, 3);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0x0013); // CHK_LIN_COLOR_F
|
|
|
|
File.WriteU32(18);
|
|
|
|
|
2020-11-26 20:51:50 +01:00
|
|
|
File.WriteFloats((BackgroundGradientColor1 + BackgroundGradientColor2) / 2.0f, 3);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0x0010); // CHK_COLOR_F
|
|
|
|
File.WriteU32(18);
|
|
|
|
|
2020-11-26 20:51:50 +01:00
|
|
|
File.WriteFloats(BackgroundGradientColor2, 3);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0x0013); // CHK_LIN_COLOR_F
|
|
|
|
File.WriteU32(18);
|
|
|
|
|
2020-11-26 20:51:50 +01:00
|
|
|
File.WriteFloats(BackgroundGradientColor2, 3);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2020-11-26 20:51:50 +01:00
|
|
|
if (Preferences.mBackgroundGradient)
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
|
|
|
File.WriteU16(0x1301); // LIB3DS_USE_V_GRADIENT
|
|
|
|
File.WriteU32(6);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
File.WriteU16(0x1201); // LIB3DS_USE_SOLID_BGND
|
|
|
|
File.WriteU32(6);
|
|
|
|
}
|
|
|
|
|
|
|
|
int NumPieces = 0;
|
2019-05-26 20:08:47 +02:00
|
|
|
for (const lcModelPartsEntry& ModelPart : ModelParts)
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2019-05-26 20:08:47 +02:00
|
|
|
lcMesh* Mesh = !ModelPart.Mesh ? ModelPart.Info->GetMesh() : ModelPart.Mesh;
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2014-12-31 17:38:30 +01:00
|
|
|
if (!Mesh || Mesh->mIndexType == GL_UNSIGNED_INT)
|
2014-12-30 17:30:12 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
long NamedObjectStart = File.GetPosition();
|
|
|
|
File.WriteU16(0x4000); // CHK_NAMED_OBJECT
|
|
|
|
File.WriteU32(0);
|
|
|
|
|
|
|
|
char Name[32];
|
|
|
|
sprintf(Name, "Piece%.3d", NumPieces);
|
|
|
|
NumPieces++;
|
|
|
|
File.WriteBuffer(Name, strlen(Name) + 1);
|
|
|
|
|
|
|
|
long TriObjectStart = File.GetPosition();
|
|
|
|
File.WriteU16(0x4100); // CHK_N_TRI_OBJECT
|
|
|
|
File.WriteU32(0);
|
|
|
|
|
|
|
|
File.WriteU16(0x4110); // CHK_POINT_ARRAY
|
|
|
|
File.WriteU32(8 + 12 * Mesh->mNumVertices);
|
|
|
|
|
|
|
|
File.WriteU16(Mesh->mNumVertices);
|
|
|
|
|
2017-02-18 20:12:35 +01:00
|
|
|
lcVertex* Verts = (lcVertex*)Mesh->mVertexData;
|
2019-05-26 20:08:47 +02:00
|
|
|
const lcMatrix44& ModelWorld = ModelPart.WorldMatrix;
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
for (int VertexIdx = 0; VertexIdx < Mesh->mNumVertices; VertexIdx++)
|
|
|
|
{
|
2017-02-18 20:12:35 +01:00
|
|
|
lcVector3 Pos = lcMul31(Verts[VertexIdx].Position, ModelWorld);
|
2014-12-30 17:30:12 +01:00
|
|
|
File.WriteFloat(Pos[0]);
|
|
|
|
File.WriteFloat(Pos[1]);
|
|
|
|
File.WriteFloat(Pos[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
File.WriteU16(0x4160); // CHK_MESH_MATRIX
|
|
|
|
File.WriteU32(54);
|
|
|
|
|
|
|
|
lcMatrix44 Matrix = lcMatrix44Identity();
|
|
|
|
File.WriteFloats(Matrix[0], 3);
|
|
|
|
File.WriteFloats(Matrix[1], 3);
|
|
|
|
File.WriteFloats(Matrix[2], 3);
|
|
|
|
File.WriteFloats(Matrix[3], 3);
|
|
|
|
|
|
|
|
File.WriteU16(0x4165); // CHK_MESH_COLOR
|
|
|
|
File.WriteU32(7);
|
|
|
|
|
|
|
|
File.WriteU8(0);
|
|
|
|
|
|
|
|
long FaceArrayStart = File.GetPosition();
|
|
|
|
File.WriteU16(0x4120); // CHK_FACE_ARRAY
|
|
|
|
File.WriteU32(0);
|
|
|
|
|
|
|
|
int NumTriangles = 0;
|
|
|
|
|
2015-05-24 06:36:25 +02:00
|
|
|
for (int SectionIdx = 0; SectionIdx < Mesh->mLods[LC_MESH_LOD_HIGH].NumSections; SectionIdx++)
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2015-05-24 06:36:25 +02:00
|
|
|
lcMeshSection* Section = &Mesh->mLods[LC_MESH_LOD_HIGH].Sections[SectionIdx];
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-08-22 03:11:32 +02:00
|
|
|
if (Section->PrimitiveType != LC_MESH_TRIANGLES && Section->PrimitiveType != LC_MESH_TEXTURED_TRIANGLES)
|
2014-12-30 17:30:12 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
NumTriangles += Section->NumIndices / 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
File.WriteU16(NumTriangles);
|
|
|
|
|
2015-05-24 06:36:25 +02:00
|
|
|
for (int SectionIdx = 0; SectionIdx < Mesh->mLods[LC_MESH_LOD_HIGH].NumSections; SectionIdx++)
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2015-05-24 06:36:25 +02:00
|
|
|
lcMeshSection* Section = &Mesh->mLods[LC_MESH_LOD_HIGH].Sections[SectionIdx];
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-08-22 03:11:32 +02:00
|
|
|
if (Section->PrimitiveType != LC_MESH_TRIANGLES && Section->PrimitiveType != LC_MESH_TEXTURED_TRIANGLES)
|
2014-12-30 17:30:12 +01:00
|
|
|
continue;
|
|
|
|
|
2017-12-02 21:22:04 +01:00
|
|
|
quint16* Indices = (quint16*)Mesh->mIndexData + Section->IndexOffset / sizeof(quint16);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
for (int IndexIdx = 0; IndexIdx < Section->NumIndices; IndexIdx += 3)
|
|
|
|
{
|
|
|
|
File.WriteU16(Indices[IndexIdx + 0]);
|
|
|
|
File.WriteU16(Indices[IndexIdx + 1]);
|
|
|
|
File.WriteU16(Indices[IndexIdx + 2]);
|
|
|
|
File.WriteU16(7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NumTriangles = 0;
|
|
|
|
|
2015-05-24 06:36:25 +02:00
|
|
|
for (int SectionIdx = 0; SectionIdx < Mesh->mLods[LC_MESH_LOD_HIGH].NumSections; SectionIdx++)
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2015-05-24 06:36:25 +02:00
|
|
|
lcMeshSection* Section = &Mesh->mLods[LC_MESH_LOD_HIGH].Sections[SectionIdx];
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-08-22 03:11:32 +02:00
|
|
|
if (Section->PrimitiveType != LC_MESH_TRIANGLES && Section->PrimitiveType != LC_MESH_TEXTURED_TRIANGLES)
|
2014-12-30 17:30:12 +01:00
|
|
|
continue;
|
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
int MaterialIndex = Section->ColorIndex == gDefaultColor ? ModelPart.ColorIndex : Section->ColorIndex;
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
File.WriteU16(0x4130); // CHK_MSH_MAT_GROUP
|
|
|
|
File.WriteU32(6 + MaterialNameLength + 1 + 2 + 2 * Section->NumIndices / 3);
|
|
|
|
|
|
|
|
sprintf(MaterialName, "Material%03d", MaterialIndex);
|
|
|
|
File.WriteBuffer(MaterialName, MaterialNameLength + 1);
|
|
|
|
|
|
|
|
File.WriteU16(Section->NumIndices / 3);
|
|
|
|
|
|
|
|
for (int IndexIdx = 0; IndexIdx < Section->NumIndices; IndexIdx += 3)
|
|
|
|
File.WriteU16(NumTriangles++);
|
|
|
|
}
|
|
|
|
|
|
|
|
long FaceArrayEnd = File.GetPosition();
|
|
|
|
File.Seek(FaceArrayStart + 2, SEEK_SET);
|
|
|
|
File.WriteU32(FaceArrayEnd - FaceArrayStart);
|
|
|
|
File.Seek(FaceArrayEnd, SEEK_SET);
|
|
|
|
|
|
|
|
long TriObjectEnd = File.GetPosition();
|
|
|
|
File.Seek(TriObjectStart + 2, SEEK_SET);
|
|
|
|
File.WriteU32(TriObjectEnd - TriObjectStart);
|
|
|
|
File.Seek(TriObjectEnd, SEEK_SET);
|
|
|
|
|
|
|
|
long NamedObjectEnd = File.GetPosition();
|
|
|
|
File.Seek(NamedObjectStart + 2, SEEK_SET);
|
|
|
|
File.WriteU32(NamedObjectEnd - NamedObjectStart);
|
|
|
|
File.Seek(NamedObjectEnd, SEEK_SET);
|
|
|
|
}
|
|
|
|
|
|
|
|
long MDataEnd = File.GetPosition();
|
|
|
|
File.Seek(MDataStart + 2, SEEK_SET);
|
|
|
|
File.WriteU32(MDataEnd - MDataStart);
|
|
|
|
File.Seek(MDataEnd, SEEK_SET);
|
|
|
|
|
|
|
|
long KFDataStart = File.GetPosition();
|
|
|
|
File.WriteU16(0xB000); // CHK_KFDATA
|
|
|
|
File.WriteU32(0);
|
|
|
|
|
|
|
|
File.WriteU16(0xB00A); // LIB3DS_KFHDR
|
|
|
|
File.WriteU32(6 + 2 + 1 + 4);
|
|
|
|
|
|
|
|
File.WriteS16(5);
|
|
|
|
File.WriteU8(0);
|
|
|
|
File.WriteS32(100);
|
|
|
|
|
|
|
|
long KFDataEnd = File.GetPosition();
|
|
|
|
File.Seek(KFDataStart + 2, SEEK_SET);
|
|
|
|
File.WriteU32(KFDataEnd - KFDataStart);
|
|
|
|
File.Seek(KFDataEnd, SEEK_SET);
|
|
|
|
|
|
|
|
long M3DEnd = File.GetPosition();
|
|
|
|
File.Seek(M3DStart + 2, SEEK_SET);
|
|
|
|
File.WriteU32(M3DEnd - M3DStart);
|
|
|
|
File.Seek(M3DEnd, SEEK_SET);
|
2021-01-11 03:07:27 +01:00
|
|
|
|
|
|
|
return true;
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Project::ExportBrickLink()
|
|
|
|
{
|
2021-02-28 22:02:58 +01:00
|
|
|
lcPartsList PartsList;
|
|
|
|
|
|
|
|
if (!mModels.IsEmpty())
|
|
|
|
mModels[0]->GetPartsList(gDefaultColor, true, false, PartsList);
|
|
|
|
|
|
|
|
if (PartsList.empty())
|
|
|
|
{
|
|
|
|
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Nothing to export."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SaveFileName = GetExportFileName(QString(), "xml", tr("Export BrickLink"), tr("XML Files (*.xml);;All Files (*.*)"));
|
|
|
|
|
|
|
|
if (SaveFileName.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
lcExportBrickLink(SaveFileName, PartsList);
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
|
|
|
|
2021-01-11 03:07:27 +01:00
|
|
|
bool Project::ExportCOLLADA(const QString& FileName)
|
2017-08-11 03:40:43 +02:00
|
|
|
{
|
2019-05-28 01:39:51 +02:00
|
|
|
std::vector<lcModelPartsEntry> ModelParts = GetModelParts();
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2019-05-28 01:39:51 +02:00
|
|
|
if (ModelParts.empty())
|
2017-08-11 03:40:43 +02:00
|
|
|
{
|
|
|
|
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Nothing to export."));
|
2021-01-11 03:07:27 +01:00
|
|
|
return false;
|
2017-08-11 03:40:43 +02:00
|
|
|
}
|
|
|
|
|
2017-08-26 01:10:06 +02:00
|
|
|
QString SaveFileName = GetExportFileName(FileName, "dae", tr("Export COLLADA"), tr("COLLADA Files (*.dae);;All Files (*.*)"));
|
2017-08-11 03:40:43 +02:00
|
|
|
|
|
|
|
if (SaveFileName.isEmpty())
|
2021-01-11 03:07:27 +01:00
|
|
|
return false;
|
2017-08-11 03:40:43 +02:00
|
|
|
|
|
|
|
QFile File(SaveFileName);
|
|
|
|
|
|
|
|
if (!File.open(QIODevice::WriteOnly))
|
|
|
|
{
|
|
|
|
QMessageBox::warning(gMainWindow, tr("LeoCAD"), tr("Could not open file '%1' for writing.").arg(SaveFileName));
|
2021-01-11 03:07:27 +01:00
|
|
|
return false;
|
2017-08-11 03:40:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream Stream(&File);
|
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
|
|
|
|
Stream << "<COLLADA xmlns=\"http://www.collada.org/2005/11/COLLADASchema\" version=\"1.4.1\">\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "<asset>\r\n";
|
|
|
|
Stream << "\t<created>" << QDateTime::currentDateTime().toString(Qt::ISODate) << "</created>\r\n";
|
|
|
|
Stream << "\t<modified>" << QDateTime::currentDateTime().toString(Qt::ISODate) << "</modified>\r\n";
|
|
|
|
Stream << "<unit name=\"LeoCAD\" meter=\"0.0004\" />\r\n";
|
|
|
|
Stream << "\t<up_axis>Z_UP</up_axis>\r\n";
|
|
|
|
Stream << "</asset>\r\n";
|
|
|
|
|
|
|
|
Stream << "<library_effects>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
|
|
|
|
for (const lcColor& Color : gColorList)
|
|
|
|
{
|
|
|
|
const char* ColorName = Color.SafeName;
|
|
|
|
|
2017-08-12 17:56:56 +02:00
|
|
|
Stream << QString("\t<effect id=\"%1-phong\">\r\n").arg(ColorName);
|
|
|
|
Stream << "\t\t<profile_COMMON>\r\n";
|
|
|
|
Stream << "\t\t\t<technique sid=\"phong1\">\r\n";
|
|
|
|
Stream << "\t\t\t\t<phong>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t<emission>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t\t<color>0.0 0.0 0.0 0.0</color>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t</emission>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t<ambient>\r\n";
|
|
|
|
Stream << QString("\t\t\t\t\t\t<color>%1 %2 %3 1.0</color>\r\n").arg(QString::number(Color.Value[0]), QString::number(Color.Value[1]), QString::number(Color.Value[2]));
|
|
|
|
Stream << "\t\t\t\t\t</ambient>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t<diffuse>\r\n";
|
|
|
|
Stream << QString("\t\t\t\t\t\t<color>%1 %2 %3 1.0</color>\r\n").arg(QString::number(Color.Value[0]), QString::number(Color.Value[1]), QString::number(Color.Value[2]));
|
|
|
|
Stream << "\t\t\t\t\t</diffuse>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t<specular>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t\t<color>0.9 0.9 0.9 1.0</color>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t</specular>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t<shininess>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t\t<float>20.0</float>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t</shininess>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t<transparent>\r\n";
|
|
|
|
Stream << QString("\t\t\t\t\t\t<color>%1 %2 %3 %4</color>\r\n").arg(QString::number(Color.Value[0]), QString::number(Color.Value[1]), QString::number(Color.Value[2]), QString::number(Color.Value[3]));
|
|
|
|
Stream << "\t\t\t\t\t</transparent>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t<transparency>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t\t<float>1.0</float>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t</transparency>\r\n";
|
|
|
|
Stream << "\t\t\t\t</phong>\r\n";
|
|
|
|
Stream << "\t\t\t</technique>\r\n";
|
|
|
|
Stream << "\t\t</profile_COMMON>\r\n";
|
|
|
|
Stream << "\t</effect>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "</library_effects>\r\n";
|
|
|
|
Stream << "<library_materials>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
|
|
|
|
for (const lcColor& Color : gColorList)
|
|
|
|
{
|
|
|
|
const char* ColorName = Color.SafeName;
|
2017-08-12 17:56:56 +02:00
|
|
|
Stream << QString("\t<material id=\"%1-material\">\r\n").arg(ColorName);
|
|
|
|
Stream << QString("\t\t<instance_effect url=\"#%1-phong\" />\r\n").arg(ColorName);
|
|
|
|
Stream << "\t</material>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "</library_materials>\r\n";
|
|
|
|
Stream << "<library_geometries>\r\n";
|
2019-05-26 20:08:47 +02:00
|
|
|
std::set<lcMesh*> AddedMeshes;
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
auto GetMeshID = [](const lcModelPartsEntry& ModelPart)
|
2017-08-11 03:40:43 +02:00
|
|
|
{
|
2019-05-28 01:39:51 +02:00
|
|
|
const PieceInfo* Info = ModelPart.Info;
|
2019-05-26 20:08:47 +02:00
|
|
|
QString ID = QString(Info->mFileName).replace('.', '_');
|
|
|
|
|
|
|
|
if (ModelPart.Mesh)
|
|
|
|
ID += "_" + QString::number((quintptr)ModelPart.Mesh, 16);
|
|
|
|
|
|
|
|
return ID;
|
|
|
|
};
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
for (const lcModelPartsEntry& ModelPart : ModelParts)
|
|
|
|
{
|
|
|
|
lcMesh* Mesh = !ModelPart.Mesh ? ModelPart.Info->GetMesh() : ModelPart.Mesh;
|
|
|
|
|
|
|
|
if (!AddedMeshes.insert(Mesh).second)
|
2017-08-11 03:40:43 +02:00
|
|
|
continue;
|
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
QString ID = GetMeshID(ModelPart);
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2017-08-26 01:10:06 +02:00
|
|
|
if (!Mesh)
|
2020-12-31 23:23:08 +01:00
|
|
|
continue;
|
2017-08-26 01:10:06 +02:00
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << QString("\t<geometry id=\"%1\">\r\n").arg(ID);
|
|
|
|
Stream << "\t\t<mesh>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << QString("\t\t\t<source id=\"%1-pos\">\r\n").arg(ID);
|
|
|
|
Stream << QString("\t\t\t\t<float_array id=\"%1-pos-array\" count=\"%2\">\r\n").arg(ID, QString::number(Mesh->mNumVertices));
|
2017-08-11 03:40:43 +02:00
|
|
|
|
|
|
|
lcVertex* Verts = (lcVertex*)Mesh->mVertexData;
|
|
|
|
|
|
|
|
for (int VertexIdx = 0; VertexIdx < Mesh->mNumVertices; VertexIdx++)
|
|
|
|
{
|
|
|
|
lcVector3& Position = Verts[VertexIdx].Position;
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << QString("\t\t\t\t\t%1 %2 %3\r\n").arg(QString::number(Position.x), QString::number(Position.y), QString::number(Position.z));
|
2017-08-11 03:40:43 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "\t\t\t\t</float_array>\r\n";
|
|
|
|
Stream << "\t\t\t\t<technique_common>\r\n";
|
|
|
|
Stream << QString("\t\t\t\t\t<accessor source=\"#%1-pos-array\" count=\"%2\" stride=\"3\">\r\n").arg(ID, QString::number(Mesh->mNumVertices));
|
|
|
|
Stream << "\t\t\t\t\t\t<param name=\"X\" type=\"float\" />\r\n";
|
|
|
|
Stream << "\t\t\t\t\t\t<param name=\"Y\" type=\"float\" />\r\n";
|
|
|
|
Stream << "\t\t\t\t\t\t<param name=\"Z\" type=\"float\" />\r\n";
|
|
|
|
Stream << "\t\t\t\t\t</accessor>\r\n";
|
|
|
|
Stream << "\t\t\t\t</technique_common>\r\n";
|
|
|
|
Stream << "\t\t\t</source>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << QString("\t\t\t<source id=\"%1-normal\">\r\n").arg(ID);
|
|
|
|
Stream << QString("\t\t\t\t<float_array id=\"%1-normal-array\" count=\"%2\">\r\n").arg(ID, QString::number(Mesh->mNumVertices));
|
2017-08-11 03:40:43 +02:00
|
|
|
|
|
|
|
for (int VertexIdx = 0; VertexIdx < Mesh->mNumVertices; VertexIdx++)
|
|
|
|
{
|
|
|
|
lcVector3 Normal = lcUnpackNormal(Verts[VertexIdx].Normal);
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << QString("\t\t\t\t\t%1 %2 %3\r\n").arg(QString::number(Normal.x), QString::number(Normal.y), QString::number(Normal.z));
|
2017-08-11 03:40:43 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "\t\t\t\t</float_array>\r\n";
|
|
|
|
Stream << "\t\t\t\t<technique_common>\r\n";
|
|
|
|
Stream << QString("\t\t\t\t\t<accessor source=\"#%1-normal-array\" count=\"%2\" stride=\"3\">\r\n").arg(ID, QString::number(Mesh->mNumVertices));
|
|
|
|
Stream << "\t\t\t\t\t\t<param name=\"X\" type=\"float\" />\r\n";
|
|
|
|
Stream << "\t\t\t\t\t\t<param name=\"Y\" type=\"float\" />\r\n";
|
|
|
|
Stream << "\t\t\t\t\t\t<param name=\"Z\" type=\"float\" />\r\n";
|
|
|
|
Stream << "\t\t\t\t\t</accessor>\r\n";
|
|
|
|
Stream << "\t\t\t\t</technique_common>\r\n";
|
|
|
|
Stream << "\t\t\t</source>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << QString("\t\t\t<vertices id=\"%1-vertices\">\r\n").arg(ID);
|
|
|
|
Stream << QString("\t\t\t\t<input semantic=\"POSITION\" source=\"#%1-pos\"/>\r\n").arg(ID);
|
|
|
|
Stream << "\t\t\t</vertices>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
|
|
|
|
for (int SectionIdx = 0; SectionIdx < Mesh->mLods[LC_MESH_LOD_HIGH].NumSections; SectionIdx++)
|
|
|
|
{
|
|
|
|
lcMeshSection* Section = &Mesh->mLods[LC_MESH_LOD_HIGH].Sections[SectionIdx];
|
|
|
|
|
|
|
|
if (Section->PrimitiveType != LC_MESH_TRIANGLES && Section->PrimitiveType != LC_MESH_TEXTURED_TRIANGLES)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const char* ColorName = gColorList[Section->ColorIndex].SafeName;
|
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
if (Mesh->mIndexType == GL_UNSIGNED_SHORT)
|
2017-08-11 03:40:43 +02:00
|
|
|
{
|
2017-08-12 04:02:26 +02:00
|
|
|
quint16* Indices = (quint16*)Mesh->mIndexData + Section->IndexOffset / sizeof(quint16);
|
|
|
|
|
|
|
|
Stream << QString("\t\t\t<triangles count=\"%1\" material=\"%2\">\r\n").arg(QString::number(Section->NumIndices / 3), ColorName);
|
2017-08-12 17:56:56 +02:00
|
|
|
Stream << QString("\t\t\t<input semantic=\"VERTEX\" source=\"#%1-vertices\" offset=\"0\" />\r\n").arg(ID);
|
|
|
|
Stream << QString("\t\t\t<input semantic=\"NORMAL\" source=\"#%1-normal\" offset=\"0\" />\r\n").arg(ID);
|
|
|
|
Stream << "\t\t\t<p>\r\n";
|
2017-08-12 04:02:26 +02:00
|
|
|
|
|
|
|
for (int Idx = 0; Idx < Section->NumIndices; Idx += 3)
|
|
|
|
{
|
|
|
|
QString idx1 = QString::number(Indices[Idx + 0]);
|
|
|
|
QString idx2 = QString::number(Indices[Idx + 1]);
|
|
|
|
QString idx3 = QString::number(Indices[Idx + 2]);
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << QString("\t\t\t\t %1 %2 %3\r\n").arg(idx1, idx2, idx3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
quint32* Indices = (quint32*)Mesh->mIndexData + Section->IndexOffset / sizeof(quint32);
|
|
|
|
|
|
|
|
Stream << QString("\t\t\t<triangles count=\"%1\" material=\"%2\">\r\n").arg(QString::number(Section->NumIndices / 3), ColorName);
|
2017-08-12 17:56:56 +02:00
|
|
|
Stream << QString("\t\t\t<input semantic=\"VERTEX\" source=\"#%1-vertices\" offset=\"0\" />\r\n").arg(ID);
|
|
|
|
Stream << QString("\t\t\t<input semantic=\"NORMAL\" source=\"#%1-normal\" offset=\"0\" />\r\n").arg(ID);
|
|
|
|
Stream << "\t\t\t<p>\r\n";
|
2017-08-12 04:02:26 +02:00
|
|
|
|
|
|
|
for (int Idx = 0; Idx < Section->NumIndices; Idx += 3)
|
|
|
|
{
|
|
|
|
QString idx1 = QString::number(Indices[Idx + 0]);
|
|
|
|
QString idx2 = QString::number(Indices[Idx + 1]);
|
|
|
|
QString idx3 = QString::number(Indices[Idx + 2]);
|
|
|
|
|
|
|
|
Stream << QString("\t\t\t\t %1 %2 %3\r\n").arg(idx1, idx2, idx3);
|
|
|
|
}
|
2017-08-11 03:40:43 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "\t\t\t\t</p>\r\n";
|
2017-08-12 17:56:56 +02:00
|
|
|
Stream << "\t\t\t</triangles>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "\t\t</mesh>\r\n";
|
|
|
|
Stream << "\t</geometry>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "</library_geometries>\r\n";
|
|
|
|
Stream << "<library_visual_scenes>\r\n";
|
|
|
|
Stream << "\t<visual_scene id=\"DefaultScene\">\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
for (const lcModelPartsEntry& ModelPart : ModelParts)
|
2017-08-11 03:40:43 +02:00
|
|
|
{
|
2020-12-31 23:23:08 +01:00
|
|
|
lcMesh* Mesh = !ModelPart.Mesh ? ModelPart.Info->GetMesh() : ModelPart.Mesh;
|
|
|
|
|
|
|
|
if (!Mesh)
|
|
|
|
continue;
|
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
QString ID = GetMeshID(ModelPart);
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "\t\t<node>\r\n";
|
|
|
|
Stream << "\t\t\t<matrix>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
const lcMatrix44& Matrix = ModelPart.WorldMatrix;
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << QString("\t\t\t\t%1 %2 %3 %4\r\n").arg(QString::number(Matrix[0][0]), QString::number(Matrix[1][0]), QString::number(Matrix[2][0]), QString::number(Matrix[3][0]));
|
|
|
|
Stream << QString("\t\t\t\t%1 %2 %3 %4\r\n").arg(QString::number(Matrix[0][1]), QString::number(Matrix[1][1]), QString::number(Matrix[2][1]), QString::number(Matrix[3][1]));
|
|
|
|
Stream << QString("\t\t\t\t%1 %2 %3 %4\r\n").arg(QString::number(Matrix[0][2]), QString::number(Matrix[1][2]), QString::number(Matrix[2][2]), QString::number(Matrix[3][2]));
|
|
|
|
Stream << QString("\t\t\t\t%1 %2 %3 %4\r\n").arg(QString::number(Matrix[0][3]), QString::number(Matrix[1][3]), QString::number(Matrix[2][3]), QString::number(Matrix[3][3]));
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "\t\t\t</matrix>\r\n";
|
|
|
|
Stream << QString("\t\t\t<instance_geometry url=\"#%1\">\r\n").arg(ID);
|
|
|
|
Stream << "\t\t\t\t<bind_material>\r\n";
|
|
|
|
Stream << "\t\t\t\t\t<technique_common>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
|
|
|
|
for (int SectionIdx = 0; SectionIdx < Mesh->mLods[LC_MESH_LOD_HIGH].NumSections; SectionIdx++)
|
|
|
|
{
|
|
|
|
lcMeshSection* Section = &Mesh->mLods[LC_MESH_LOD_HIGH].Sections[SectionIdx];
|
|
|
|
|
|
|
|
if (Section->PrimitiveType != LC_MESH_TRIANGLES && Section->PrimitiveType != LC_MESH_TEXTURED_TRIANGLES)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const char* SourceColorName = gColorList[Section->ColorIndex].SafeName;
|
|
|
|
const char* TargetColorName;
|
|
|
|
if (Section->ColorIndex == gDefaultColor)
|
2019-05-26 20:08:47 +02:00
|
|
|
TargetColorName = gColorList[ModelPart.ColorIndex].SafeName;
|
2017-08-11 03:40:43 +02:00
|
|
|
else
|
|
|
|
TargetColorName = gColorList[Section->ColorIndex].SafeName;
|
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << QString("\t\t\t\t\t\t<instance_material symbol=\"%1\" target=\"#%2-material\"/>\r\n").arg(SourceColorName, TargetColorName);
|
2017-08-11 03:40:43 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "\t\t\t\t\t</technique_common>\r\n";
|
|
|
|
Stream << "\t\t\t\t</bind_material>\r\n";
|
|
|
|
Stream << "\t\t\t</instance_geometry>\r\n";
|
|
|
|
Stream << "\t\t</node>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
}
|
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "\t</visual_scene>\r\n";
|
|
|
|
Stream << "</library_visual_scenes>\r\n";
|
|
|
|
Stream << "<scene>\r\n";
|
|
|
|
Stream << "\t<instance_visual_scene url=\"#DefaultScene\"/>\r\n";
|
|
|
|
Stream << "</scene>\r\n";
|
2017-08-11 03:40:43 +02:00
|
|
|
|
2017-08-12 04:02:26 +02:00
|
|
|
Stream << "</COLLADA>\r\n";
|
2021-01-11 03:07:27 +01:00
|
|
|
|
|
|
|
return true;
|
2017-08-11 03:40:43 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 22:12:34 +01:00
|
|
|
bool Project::ExportCSV(const QString& FileName)
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2016-11-16 23:53:41 +01:00
|
|
|
lcPartsList PartsList;
|
2014-12-30 17:30:12 +01:00
|
|
|
|
|
|
|
if (!mModels.IsEmpty())
|
2020-01-11 21:45:36 +01:00
|
|
|
mModels[0]->GetPartsList(gDefaultColor, true, false, PartsList);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2017-04-16 00:54:17 +02:00
|
|
|
if (PartsList.empty())
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2015-01-30 17:30:13 +01:00
|
|
|
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Nothing to export."));
|
2022-10-30 22:12:34 +01:00
|
|
|
return false;
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
|
|
|
|
2022-10-30 22:12:34 +01:00
|
|
|
QString SaveFileName = GetExportFileName(FileName, "csv", tr("Export CSV"), tr("CSV Files (*.csv);;All Files (*.*)"));
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2015-03-27 21:39:43 +01:00
|
|
|
if (SaveFileName.isEmpty())
|
2022-10-30 22:12:34 +01:00
|
|
|
return false;
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
lcDiskFile CSVFile(SaveFileName);
|
2014-12-30 17:30:12 +01:00
|
|
|
char Line[1024];
|
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
if (!CSVFile.Open(QIODevice::WriteOnly))
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2015-03-27 21:39:43 +01:00
|
|
|
QMessageBox::warning(gMainWindow, tr("LeoCAD"), tr("Could not open file '%1' for writing.").arg(SaveFileName));
|
2022-10-30 22:12:34 +01:00
|
|
|
return false;
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CSVFile.WriteLine("Part Name,Color,Quantity,Part ID,Color Code\n");
|
|
|
|
|
2017-04-16 00:54:17 +02:00
|
|
|
for (const auto& PartIt : PartsList)
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2017-04-16 00:54:17 +02:00
|
|
|
const PieceInfo* Info = PartIt.first;
|
2016-11-16 23:53:41 +01:00
|
|
|
|
2017-04-16 00:54:17 +02:00
|
|
|
for (const auto& ColorIt : PartIt.second)
|
2016-11-16 23:53:41 +01:00
|
|
|
{
|
2022-11-07 02:45:33 +01:00
|
|
|
std::string Description = Info->m_strDescription;
|
|
|
|
Description.erase(std::remove(Description.begin(), Description.end(), ','), Description.end());
|
|
|
|
|
|
|
|
sprintf(Line, "\"%s\",\"%s\",%d,%s,%d\n", Description.c_str(), gColorList[ColorIt.first].Name, ColorIt.second, Info->mFileName, gColorList[ColorIt.first].Code);
|
2016-11-16 23:53:41 +01:00
|
|
|
CSVFile.WriteLine(Line);
|
|
|
|
}
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
2022-10-30 22:12:34 +01:00
|
|
|
|
|
|
|
return true;
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
|
|
|
|
2021-01-15 03:19:58 +01:00
|
|
|
lcInstructions* Project::GetInstructions()
|
2019-12-31 01:04:58 +01:00
|
|
|
{
|
2021-01-15 03:19:58 +01:00
|
|
|
mInstructions.reset();
|
|
|
|
mInstructions = std::unique_ptr<lcInstructions>(new lcInstructions(this));
|
|
|
|
|
|
|
|
return mInstructions.get();
|
2019-12-31 01:04:58 +01:00
|
|
|
}
|
|
|
|
|
2017-12-11 20:14:37 +01:00
|
|
|
void Project::ExportHTML(const lcHTMLExportOptions& Options)
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
|
|
|
QDir Dir(Options.PathName);
|
|
|
|
Dir.mkpath(QLatin1String("."));
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
lcArray<lcModel*> Models;
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
if (Options.CurrentOnly)
|
|
|
|
Models.Add(mActiveModel);
|
|
|
|
else if (Options.SubModels)
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2016-05-31 00:41:03 +02:00
|
|
|
Models.Add(mActiveModel);
|
|
|
|
mActiveModel->GetSubModels(Models);
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2016-05-31 00:41:03 +02:00
|
|
|
else
|
|
|
|
Models = mModels;
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
QString ProjectTitle = GetTitle();
|
2015-01-12 05:49:30 +01:00
|
|
|
|
2020-02-24 23:31:08 +01:00
|
|
|
auto AddPartsListImage = [&Dir](QTextStream& Stream, lcModel* Model, lcStep Step, const QString& BaseName)
|
2017-07-03 01:10:30 +02:00
|
|
|
{
|
2021-01-17 00:14:05 +01:00
|
|
|
QImage Image = Model->GetPartsListImage(1024, Step, LC_RGBA(255, 255, 255, 0), QFont("Arial", 16, QFont::Bold), Qt::black);
|
2017-07-03 01:10:30 +02:00
|
|
|
|
|
|
|
if (!Image.isNull())
|
|
|
|
{
|
2017-12-13 07:23:26 +01:00
|
|
|
QString ImageName = BaseName + QLatin1String("-parts.png");
|
|
|
|
QString FileName = QFileInfo(Dir, ImageName).absoluteFilePath();
|
2017-07-03 01:10:30 +02:00
|
|
|
|
|
|
|
Image.save(FileName);
|
|
|
|
|
2020-01-14 21:48:18 +01:00
|
|
|
Stream << QString::fromLatin1("<p><IMG SRC=\"%1\" /></p><br><br>\r\n").arg(ImageName);
|
2017-07-03 01:10:30 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-01-14 21:48:18 +01:00
|
|
|
for (lcModel* Model : Models)
|
2016-05-31 00:41:03 +02:00
|
|
|
{
|
|
|
|
QString BaseName = ProjectTitle.left(ProjectTitle.length() - QFileInfo(ProjectTitle).suffix().length() - 1);
|
|
|
|
lcStep LastStep = Model->GetLastStep();
|
|
|
|
QString PageTitle;
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
if (Models.GetSize() > 1)
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2020-05-03 21:11:51 +02:00
|
|
|
BaseName += '-' + Model->GetProperties().mFileName;
|
|
|
|
PageTitle = Model->GetProperties().mFileName;
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
2016-05-31 00:41:03 +02:00
|
|
|
else
|
|
|
|
PageTitle = ProjectTitle;
|
|
|
|
BaseName.replace('#', '_');
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
if (Options.SinglePage)
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2016-05-31 00:41:03 +02:00
|
|
|
QString FileName = QFileInfo(Dir, BaseName + QLatin1String(".html")).absoluteFilePath();
|
2015-01-12 05:49:30 +01:00
|
|
|
QFile File(FileName);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
if (!File.open(QIODevice::WriteOnly))
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2015-01-26 00:04:39 +01:00
|
|
|
QMessageBox::warning(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
|
2015-01-12 05:49:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
QTextStream Stream(&File);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
Stream << QString::fromLatin1("<HTML>\r\n<HEAD>\r\n<TITLE>Instructions for %1</TITLE>\r\n</HEAD>\r\n<BR>\r\n<CENTER>\r\n").arg(PageTitle);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
for (lcStep Step = 1; Step <= LastStep; Step++)
|
2016-05-31 00:41:03 +02:00
|
|
|
{
|
|
|
|
QString StepString = QString::fromLatin1("%1").arg(Step, 2, 10, QLatin1Char('0'));
|
2020-01-14 21:48:18 +01:00
|
|
|
Stream << QString::fromLatin1("<p><IMG SRC=\"%1-%2.png\" ALT=\"Step %3\" WIDTH=%4 HEIGHT=%5></p><BR><BR>\r\n").arg(BaseName, StepString, StepString, QString::number(Options.StepImagesWidth), QString::number(Options.StepImagesHeight));
|
2016-05-31 00:41:03 +02:00
|
|
|
|
|
|
|
if (Options.PartsListStep)
|
2020-01-14 21:48:18 +01:00
|
|
|
AddPartsListImage(Stream, Model, Step, QString("%1-%2").arg(BaseName, StepString));
|
2016-05-31 00:41:03 +02:00
|
|
|
}
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
if (Options.PartsListEnd)
|
2017-12-13 07:23:26 +01:00
|
|
|
AddPartsListImage(Stream, Model, 0, BaseName);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2018-03-22 00:47:00 +01:00
|
|
|
Stream << QLatin1String("</CENTER>\r\n<BR><HR><BR><B><I>Created by <A HREF=\"https://www.leocad.org\">LeoCAD</A></I></B><BR></HTML>\r\n");
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
2016-05-31 00:41:03 +02:00
|
|
|
else
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2016-05-31 00:41:03 +02:00
|
|
|
if (Options.IndexPage)
|
|
|
|
{
|
|
|
|
QString FileName = QFileInfo(Dir, BaseName + QLatin1String("-index.html")).absoluteFilePath();
|
|
|
|
QFile File(FileName);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
if (!File.open(QIODevice::WriteOnly))
|
|
|
|
{
|
|
|
|
QMessageBox::warning(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream Stream(&File);
|
|
|
|
|
|
|
|
Stream << QString::fromLatin1("<HTML>\r\n<HEAD>\r\n<TITLE>Instructions for %1</TITLE>\r\n</HEAD>\r\n<BR>\r\n<CENTER>\r\n").arg(PageTitle);
|
|
|
|
|
|
|
|
for (lcStep Step = 1; Step <= LastStep; Step++)
|
|
|
|
Stream << QString::fromLatin1("<A HREF=\"%1-%2.html\">Step %3<BR>\r\n</A>").arg(BaseName, QString("%1").arg(Step, 2, 10, QLatin1Char('0')), QString::number(Step));
|
|
|
|
|
|
|
|
if (Options.PartsListEnd)
|
|
|
|
Stream << QString::fromLatin1("<A HREF=\"%1-pieces.html\">Pieces Used</A><BR>\r\n").arg(BaseName);
|
|
|
|
|
2018-03-22 00:47:00 +01:00
|
|
|
Stream << QLatin1String("</CENTER>\r\n<BR><HR><BR><B><I>Created by <A HREF=\"https://www.leocad.org\">LeoCAD</A></B></I><BR></HTML>\r\n");
|
2016-05-31 00:41:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (lcStep Step = 1; Step <= LastStep; Step++)
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2016-05-31 00:41:03 +02:00
|
|
|
QString StepString = QString::fromLatin1("%1").arg(Step, 2, 10, QLatin1Char('0'));
|
|
|
|
QString FileName = QFileInfo(Dir, QString("%1-%2.html").arg(BaseName, StepString)).absoluteFilePath();
|
|
|
|
QFile File(FileName);
|
|
|
|
|
|
|
|
if (!File.open(QIODevice::WriteOnly))
|
|
|
|
{
|
|
|
|
QMessageBox::warning(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream Stream(&File);
|
|
|
|
|
|
|
|
Stream << QString::fromLatin1("<HTML>\r\n<HEAD>\r\n<TITLE>%1 - Step %2</TITLE>\r\n</HEAD>\r\n<BR>\r\n<CENTER>\r\n").arg(PageTitle, QString::number(Step));
|
|
|
|
Stream << QString::fromLatin1("<IMG SRC=\"%1-%2.png\" ALT=\"Step %3\" WIDTH=%4 HEIGHT=%5><BR><BR>\r\n").arg(BaseName, StepString, StepString, QString::number(Options.StepImagesWidth), QString::number(Options.StepImagesHeight));
|
|
|
|
|
|
|
|
if (Options.PartsListStep)
|
2020-01-14 21:48:18 +01:00
|
|
|
AddPartsListImage(Stream, Model, Step, QString("%1-%2").arg(BaseName, StepString));
|
2016-05-31 00:41:03 +02:00
|
|
|
|
|
|
|
Stream << QLatin1String("</CENTER>\r\n<BR><HR><BR>");
|
|
|
|
if (Step != 1)
|
|
|
|
Stream << QString::fromLatin1("<A HREF=\"%1-%2.html\">Previous</A> ").arg(BaseName, QString("%1").arg(Step - 1, 2, 10, QLatin1Char('0')));
|
|
|
|
|
|
|
|
if (Options.IndexPage)
|
|
|
|
Stream << QString::fromLatin1("<A HREF=\"%1-index.html\">Index</A> ").arg(BaseName);
|
|
|
|
|
|
|
|
if (Step != LastStep)
|
|
|
|
Stream << QString::fromLatin1("<A HREF=\"%1-%2.html\">Next</A>").arg(BaseName, QString("%1").arg(Step + 1, 2, 10, QLatin1Char('0')));
|
|
|
|
else if (Options.PartsListEnd)
|
|
|
|
Stream << QString::fromLatin1("<A HREF=\"%1-pieces.html\">Pieces Used</A>").arg(BaseName);
|
|
|
|
|
|
|
|
Stream << QLatin1String("<BR></HTML>\r\n");
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
if (Options.PartsListEnd)
|
|
|
|
{
|
|
|
|
QString FileName = QFileInfo(Dir, BaseName + QLatin1String("-pieces.html")).absoluteFilePath();
|
|
|
|
QFile File(FileName);
|
|
|
|
|
|
|
|
if (!File.open(QIODevice::WriteOnly))
|
|
|
|
{
|
|
|
|
QMessageBox::warning(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
|
|
|
|
return;
|
|
|
|
}
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
QTextStream Stream(&File);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
Stream << QString::fromLatin1("<HTML>\r\n<HEAD>\r\n<TITLE>Pieces used by %1</TITLE>\r\n</HEAD>\r\n<BR>\r\n<CENTER>\n").arg(PageTitle);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2017-12-13 07:23:26 +01:00
|
|
|
AddPartsListImage(Stream, Model, 0, BaseName);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2017-12-13 07:23:26 +01:00
|
|
|
Stream << QLatin1String("</CENTER>\r\n<BR><HR><BR>");
|
2016-05-31 00:41:03 +02:00
|
|
|
Stream << QString::fromLatin1("<A HREF=\"%1-%2.html\">Previous</A> ").arg(BaseName, QString("%1").arg(LastStep, 2, 10, QLatin1Char('0')));
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
if (Options.IndexPage)
|
|
|
|
Stream << QString::fromLatin1("<A HREF=\"%1-index.html\">Index</A> ").arg(BaseName);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
Stream << QLatin1String("<BR></HTML>\r\n");
|
|
|
|
}
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
QString StepImageBaseName = QFileInfo(Dir, BaseName + QLatin1String("-%1.png")).absoluteFilePath();
|
2020-04-25 20:36:28 +02:00
|
|
|
Model->SaveStepImages(StepImageBaseName, true, false, Options.StepImagesWidth, Options.StepImagesHeight, 1, LastStep);
|
2016-05-31 00:41:03 +02:00
|
|
|
}
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
if (Models.GetSize() > 1)
|
|
|
|
{
|
|
|
|
QString BaseName = ProjectTitle.left(ProjectTitle.length() - QFileInfo(ProjectTitle).suffix().length() - 1);
|
|
|
|
QString FileName = QFileInfo(Dir, BaseName + QLatin1String("-index.html")).absoluteFilePath();
|
|
|
|
QFile File(FileName);
|
2015-01-12 05:49:30 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
if (!File.open(QIODevice::WriteOnly))
|
|
|
|
{
|
|
|
|
QMessageBox::warning(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString()));
|
|
|
|
return;
|
|
|
|
}
|
2015-01-12 05:49:30 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
QTextStream Stream(&File);
|
2015-01-12 05:49:30 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
Stream << QString::fromLatin1("<HTML>\r\n<HEAD>\r\n<TITLE>Instructions for %1</TITLE>\r\n</HEAD>\r\n<BR>\r\n<CENTER>\r\n").arg(ProjectTitle);
|
2015-01-12 05:49:30 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
for (int ModelIdx = 0; ModelIdx < Models.GetSize(); ModelIdx++)
|
|
|
|
{
|
|
|
|
lcModel* Model = Models[ModelIdx];
|
2020-05-03 21:11:51 +02:00
|
|
|
BaseName = ProjectTitle.left(ProjectTitle.length() - QFileInfo(ProjectTitle).suffix().length() - 1) + '-' + Model->GetProperties().mFileName;
|
2016-05-31 00:41:03 +02:00
|
|
|
BaseName.replace('#', '_');
|
2015-01-12 05:49:30 +01:00
|
|
|
|
2016-05-31 00:41:03 +02:00
|
|
|
if (Options.SinglePage)
|
2017-12-13 07:39:11 +01:00
|
|
|
{
|
2016-05-31 00:41:03 +02:00
|
|
|
FileName = BaseName + QLatin1String(".html");
|
2020-05-03 21:11:51 +02:00
|
|
|
Stream << QString::fromLatin1("<p><a href=\"%1\">%2</a>").arg(FileName, Model->GetProperties().mFileName);
|
2017-12-13 07:39:11 +01:00
|
|
|
}
|
|
|
|
else if (Options.IndexPage)
|
|
|
|
{
|
2016-05-31 00:41:03 +02:00
|
|
|
FileName = BaseName + QLatin1String("-index.html");
|
2020-05-03 21:11:51 +02:00
|
|
|
Stream << QString::fromLatin1("<p><a href=\"%1\">%2</a>").arg(FileName, Model->GetProperties().mFileName);
|
2017-12-13 07:39:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lcStep LastStep = Model->GetLastStep();
|
2015-01-12 05:49:30 +01:00
|
|
|
|
2020-05-03 21:11:51 +02:00
|
|
|
Stream << QString::fromLatin1("<p>%1</p>").arg(Model->GetProperties().mFileName);
|
2017-12-13 07:39:11 +01:00
|
|
|
|
|
|
|
for (lcStep Step = 1; Step <= LastStep; Step++)
|
|
|
|
Stream << QString::fromLatin1("<A HREF=\"%1-%2.html\">Step %3<BR>\r\n</A>").arg(BaseName, QString("%1").arg(Step, 2, 10, QLatin1Char('0')), QString::number(Step));
|
|
|
|
|
|
|
|
if (Options.PartsListEnd)
|
|
|
|
Stream << QString::fromLatin1("<A HREF=\"%1-pieces.html\">Pieces Used</A><BR>\r\n").arg(BaseName);
|
|
|
|
}
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2016-05-31 00:41:03 +02:00
|
|
|
|
2018-03-22 00:47:00 +01:00
|
|
|
Stream << QLatin1String("</CENTER>\r\n<BR><HR><BR><B><I>Created by <A HREF=\"https://www.leocad.org\">LeoCAD</A></B></I><BR></HTML>\r\n");
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 19:08:02 +02:00
|
|
|
bool Project::ExportPOVRay(const QString& FileName)
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2019-05-28 01:39:51 +02:00
|
|
|
std::vector<lcModelPartsEntry> ModelParts = GetModelParts();
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2019-05-28 01:39:51 +02:00
|
|
|
if (ModelParts.empty())
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2015-01-30 17:30:13 +01:00
|
|
|
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Nothing to export."));
|
2017-09-22 19:08:02 +02:00
|
|
|
return false;
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
|
|
|
|
2017-09-22 19:08:02 +02:00
|
|
|
QString SaveFileName = GetExportFileName(FileName, QLatin1String("pov"), tr("Export POV-Ray"), tr("POV-Ray Files (*.pov);;All Files (*.*)"));
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2017-09-22 19:08:02 +02:00
|
|
|
if (SaveFileName.isEmpty())
|
|
|
|
return false;
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2017-09-22 19:08:02 +02:00
|
|
|
lcDiskFile POVFile(SaveFileName);
|
2015-01-12 05:49:30 +01:00
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
if (!POVFile.Open(QIODevice::WriteOnly))
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2017-09-22 19:08:02 +02:00
|
|
|
QMessageBox::warning(gMainWindow, tr("LeoCAD"), tr("Could not open file '%1' for writing.").arg(SaveFileName));
|
|
|
|
return false;
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
|
|
|
|
2017-11-04 22:32:21 +01:00
|
|
|
POVFile.WriteLine("#version 3.7;\n\nglobal_settings {\n assumed_gamma 1.0\n}\n\n");
|
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
char Line[1024];
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
2020-12-16 19:00:31 +01:00
|
|
|
std::map<const PieceInfo*, std::pair<char[LC_PIECE_NAME_LEN + 1], int>> PieceTable;
|
2019-07-05 02:06:26 +02:00
|
|
|
size_t NumColors = gColorList.size();
|
2017-09-23 01:42:22 +02:00
|
|
|
std::vector<std::array<char, LC_MAX_COLOR_NAME>> ColorTable(NumColors);
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
LGEO_PIECE_LGEO = 0x01,
|
|
|
|
LGEO_PIECE_AR = 0x02,
|
|
|
|
LGEO_PIECE_SLOPE = 0x04
|
|
|
|
};
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
enum
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2015-01-12 05:49:30 +01:00
|
|
|
LGEO_COLOR_SOLID = 0x01,
|
|
|
|
LGEO_COLOR_TRANSPARENT = 0x02,
|
|
|
|
LGEO_COLOR_CHROME = 0x04,
|
|
|
|
LGEO_COLOR_PEARL = 0x08,
|
|
|
|
LGEO_COLOR_METALLIC = 0x10,
|
|
|
|
LGEO_COLOR_RUBBER = 0x20,
|
|
|
|
LGEO_COLOR_GLITTER = 0x40
|
|
|
|
};
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2017-09-22 19:08:02 +02:00
|
|
|
QString LGEOPath; // todo: load lgeo from registry and make sure it still works
|
|
|
|
|
|
|
|
if (!LGEOPath.isEmpty())
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2017-09-22 19:08:02 +02:00
|
|
|
lcDiskFile TableFile(QFileInfo(QDir(LGEOPath), QLatin1String("lg_elements.lst")).absoluteFilePath());
|
2014-12-31 17:38:30 +01:00
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
if (!TableFile.Open(QIODevice::ReadOnly))
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2017-09-22 19:08:02 +02:00
|
|
|
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Could not find LGEO files in folder '%1'.").arg(LGEOPath));
|
|
|
|
return false;
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
while (TableFile.ReadLine(Line, sizeof(Line)))
|
2014-12-31 17:38:30 +01:00
|
|
|
{
|
2020-12-16 19:00:31 +01:00
|
|
|
char Src[129], Dst[129], Flags[11];
|
2013-12-08 00:15:28 +01:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
if (*Line == ';')
|
|
|
|
continue;
|
2013-08-16 18:16:45 +02:00
|
|
|
|
2020-12-16 19:00:31 +01:00
|
|
|
if (sscanf(Line,"%128s%128s%10s", Src, Dst, Flags) != 3)
|
2015-01-12 05:49:30 +01:00
|
|
|
continue;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2017-07-27 18:21:55 +02:00
|
|
|
strcat(Src, ".dat");
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2017-04-14 02:26:40 +02:00
|
|
|
PieceInfo* Info = Library->FindPiece(Src, nullptr, false, false);
|
2015-01-12 05:49:30 +01:00
|
|
|
if (!Info)
|
|
|
|
continue;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
if (strchr(Flags, 'L'))
|
|
|
|
{
|
2020-12-16 19:00:31 +01:00
|
|
|
std::pair<char[LC_PIECE_NAME_LEN + 1], int>& Entry = PieceTable[Info];
|
2017-04-16 00:54:17 +02:00
|
|
|
Entry.second |= LGEO_PIECE_LGEO;
|
|
|
|
sprintf(Entry.first, "lg_%s", Dst);
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-10-12 01:26:23 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
if (strchr(Flags, 'A'))
|
|
|
|
{
|
2020-12-16 19:00:31 +01:00
|
|
|
std::pair<char[LC_PIECE_NAME_LEN + 1], int>& Entry = PieceTable[Info];
|
2017-04-16 00:54:17 +02:00
|
|
|
Entry.second |= LGEO_PIECE_AR;
|
|
|
|
sprintf(Entry.first, "ar_%s", Dst);
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-10-12 01:26:23 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
if (strchr(Flags, 'S'))
|
2016-11-17 21:10:33 +01:00
|
|
|
{
|
2020-12-16 19:00:31 +01:00
|
|
|
std::pair<char[LC_PIECE_NAME_LEN + 1], int>& Entry = PieceTable[Info];
|
2017-04-16 00:54:17 +02:00
|
|
|
Entry.second |= LGEO_PIECE_SLOPE;
|
|
|
|
Entry.first[0] = 0;
|
2016-11-17 21:10:33 +01:00
|
|
|
}
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-10-12 01:26:23 +02:00
|
|
|
|
2017-09-22 19:08:02 +02:00
|
|
|
lcDiskFile ColorFile(QFileInfo(QDir(LGEOPath), QLatin1String("lg_colors.lst")).absoluteFilePath());
|
2017-05-29 22:31:24 +02:00
|
|
|
|
|
|
|
if (!ColorFile.Open(QIODevice::ReadOnly))
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2017-09-22 19:08:02 +02:00
|
|
|
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Could not find LGEO files in folder '%1'.").arg(LGEOPath));
|
|
|
|
return false;
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-10-12 01:26:23 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
while (ColorFile.ReadLine(Line, sizeof(Line)))
|
|
|
|
{
|
|
|
|
char Name[1024], Flags[1024];
|
|
|
|
int Code;
|
2014-10-12 01:26:23 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
if (*Line == ';')
|
|
|
|
continue;
|
2014-10-12 01:26:23 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
if (sscanf(Line,"%d%s%s", &Code, Name, Flags) != 3)
|
|
|
|
continue;
|
2014-10-12 01:26:23 +02:00
|
|
|
|
2019-07-09 03:34:34 +02:00
|
|
|
size_t Color = lcGetColorIndex(Code);
|
2015-01-12 05:49:30 +01:00
|
|
|
if (Color >= NumColors)
|
|
|
|
continue;
|
2014-10-12 01:26:23 +02:00
|
|
|
|
2017-09-23 01:42:22 +02:00
|
|
|
strcpy(ColorTable[Color].data(), Name);
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-05-18 01:03:05 +02:00
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
std::set<lcMesh*> AddedMeshes;
|
|
|
|
|
2017-09-22 19:08:02 +02:00
|
|
|
if (!LGEOPath.isEmpty())
|
2014-05-18 01:03:05 +02:00
|
|
|
{
|
2015-01-12 05:49:30 +01:00
|
|
|
POVFile.WriteLine("#include \"lg_defs.inc\"\n#include \"lg_color.inc\"\n\n");
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
for (const lcModelPartsEntry& ModelPart : ModelParts)
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2019-05-26 20:08:47 +02:00
|
|
|
if (ModelPart.Mesh)
|
|
|
|
continue;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
auto Search = PieceTable.find(ModelPart.Info);
|
|
|
|
if (Search == PieceTable.end())
|
|
|
|
continue;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
lcMesh* Mesh = ModelPart.Info->GetMesh();
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
if (!Mesh)
|
|
|
|
continue;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
if (!AddedMeshes.insert(Mesh).second)
|
|
|
|
continue;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2020-12-16 19:00:31 +01:00
|
|
|
const std::pair<char[LC_PIECE_NAME_LEN + 1], int>& Entry = Search->second;
|
2019-05-26 20:08:47 +02:00
|
|
|
if (Entry.first[0])
|
|
|
|
{
|
|
|
|
sprintf(Line, "#include \"%s.inc\"\n", Entry.first);
|
|
|
|
POVFile.WriteLine(Line);
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
2015-01-12 05:49:30 +01:00
|
|
|
|
|
|
|
POVFile.WriteLine("\n");
|
2014-05-18 01:03:05 +02:00
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2019-07-09 03:34:34 +02:00
|
|
|
for (size_t ColorIdx = 0; ColorIdx < gColorList.size(); ColorIdx++)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2015-01-12 05:49:30 +01:00
|
|
|
lcColor* Color = &gColorList[ColorIdx];
|
2013-08-31 23:58:47 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
if (lcIsColorTranslucent(ColorIdx))
|
2013-08-31 23:58:47 +02:00
|
|
|
{
|
2015-01-12 05:49:30 +01:00
|
|
|
sprintf(Line, "#declare lc_%s = texture { pigment { rgb <%f, %f, %f> filter 0.9 } finish { ambient 0.3 diffuse 0.2 reflection 0.25 phong 0.3 phong_size 60 } }\n",
|
|
|
|
Color->SafeName, Color->Value[0], Color->Value[1], Color->Value[2]);
|
2014-05-18 01:03:05 +02:00
|
|
|
}
|
2015-01-12 05:49:30 +01:00
|
|
|
else
|
2014-05-18 01:03:05 +02:00
|
|
|
{
|
2015-01-12 05:49:30 +01:00
|
|
|
sprintf(Line, "#declare lc_%s = texture { pigment { rgb <%f, %f, %f> } finish { ambient 0.1 phong 0.2 phong_size 20 } }\n",
|
2016-11-17 21:10:33 +01:00
|
|
|
Color->SafeName, Color->Value[0], Color->Value[1], Color->Value[2]);
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-05-18 01:03:05 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
POVFile.WriteLine(Line);
|
2013-08-31 23:58:47 +02:00
|
|
|
|
2017-09-23 01:42:22 +02:00
|
|
|
if (!ColorTable[ColorIdx][0])
|
|
|
|
sprintf(ColorTable[ColorIdx].data(), "lc_%s", Color->SafeName);
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2013-08-31 23:58:47 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
POVFile.WriteLine("\n");
|
2013-08-31 23:58:47 +02:00
|
|
|
|
2019-07-09 17:47:15 +02:00
|
|
|
std::vector<const char*> ColorTablePointer;
|
|
|
|
ColorTablePointer.resize(NumColors);
|
2019-07-09 03:34:34 +02:00
|
|
|
for (size_t ColorIdx = 0; ColorIdx < NumColors; ColorIdx++)
|
2017-09-23 01:42:22 +02:00
|
|
|
ColorTablePointer[ColorIdx] = ColorTable[ColorIdx].data();
|
2016-11-17 21:10:33 +01:00
|
|
|
|
2020-12-16 19:00:31 +01:00
|
|
|
auto GetMeshName = [](const lcModelPartsEntry& ModelPart, char (&Name)[LC_PIECE_NAME_LEN])
|
2019-05-26 20:08:47 +02:00
|
|
|
{
|
|
|
|
strcpy(Name, ModelPart.Info->mFileName);
|
|
|
|
|
|
|
|
for (char* c = Name; *c; c++)
|
|
|
|
if (*c == '-' || *c == '.')
|
|
|
|
*c = '_';
|
|
|
|
|
|
|
|
if (ModelPart.Mesh)
|
|
|
|
{
|
|
|
|
char Suffix[32];
|
|
|
|
sprintf(Suffix, "_%p", ModelPart.Mesh);
|
2020-12-16 19:00:31 +01:00
|
|
|
strncat(Name, Suffix, sizeof(Name) - 1);
|
|
|
|
Name[sizeof(Name) - 1] = 0;
|
2019-05-26 20:08:47 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const lcModelPartsEntry& ModelPart : ModelParts)
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2019-05-26 20:08:47 +02:00
|
|
|
lcMesh* Mesh = !ModelPart.Mesh ? ModelPart.Info->GetMesh() : ModelPart.Mesh;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
if (!AddedMeshes.insert(Mesh).second)
|
2015-01-12 05:49:30 +01:00
|
|
|
continue;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
if (!Mesh)
|
|
|
|
continue;
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
char Name[LC_PIECE_NAME_LEN];
|
|
|
|
GetMeshName(ModelPart, Name);
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
if (!ModelPart.Mesh)
|
|
|
|
{
|
2020-12-16 19:00:31 +01:00
|
|
|
std::pair<char[LC_PIECE_NAME_LEN + 1], int>& Entry = PieceTable[ModelPart.Info];
|
|
|
|
strcpy(Entry.first, "lc_");
|
|
|
|
strncat(Entry.first, Name, sizeof(Entry.first) - 1);
|
|
|
|
Entry.first[sizeof(Entry.first) - 1] = 0;
|
2019-05-26 20:08:47 +02:00
|
|
|
}
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2016-11-17 21:10:33 +01:00
|
|
|
Mesh->ExportPOVRay(POVFile, Name, &ColorTablePointer[0]);
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
sprintf(Line, "#declare lc_%s_clear = lc_%s\n\n", Name, Name);
|
|
|
|
POVFile.WriteLine(Line);
|
|
|
|
}
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2020-12-04 21:49:01 +01:00
|
|
|
const lcCamera* Camera = gMainWindow->GetActiveView()->GetCamera();
|
2015-01-12 05:49:30 +01:00
|
|
|
const lcVector3& Position = Camera->mPosition;
|
|
|
|
const lcVector3& Target = Camera->mTargetPosition;
|
|
|
|
const lcVector3& Up = Camera->mUpVector;
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2017-11-04 22:21:50 +01:00
|
|
|
sprintf(Line, "camera {\n perspective\n right x * image_width / image_height\n sky<%1g,%1g,%1g>\n location <%1g, %1g, %1g>\n look_at <%1g, %1g, %1g>\n angle %.0f * image_width / image_height\n}\n\n",
|
|
|
|
Up[1], Up[0], Up[2], Position[1] / 25.0f, Position[0] / 25.0f, Position[2] / 25.0f, Target[1] / 25.0f, Target[0] / 25.0f, Target[2] / 25.0f, Camera->m_fovy);
|
2015-01-12 05:49:30 +01:00
|
|
|
POVFile.WriteLine(Line);
|
2020-11-26 20:51:50 +01:00
|
|
|
lcVector3 BackgroundColor = lcVector3FromColor(lcGetPreferences().mBackgroundSolidColor);
|
|
|
|
sprintf(Line, "background { color rgb <%1g, %1g, %1g> }\n\n", BackgroundColor[0], BackgroundColor[1], BackgroundColor[2]);
|
2017-12-09 23:28:11 +01:00
|
|
|
POVFile.WriteLine(Line);
|
|
|
|
|
|
|
|
lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX);
|
|
|
|
lcVector3 Max(-FLT_MAX, -FLT_MAX, -FLT_MAX);
|
|
|
|
|
|
|
|
for (const lcModelPartsEntry& ModelPart : ModelParts)
|
|
|
|
{
|
|
|
|
lcVector3 Points[8];
|
|
|
|
|
|
|
|
lcGetBoxCorners(ModelPart.Info->GetBoundingBox(), Points);
|
|
|
|
|
|
|
|
for (int PointIdx = 0; PointIdx < 8; PointIdx++)
|
|
|
|
{
|
|
|
|
lcVector3 Point = lcMul31(Points[PointIdx], ModelPart.WorldMatrix);
|
|
|
|
|
|
|
|
Min = lcMin(Point, Min);
|
|
|
|
Max = lcMax(Point, Max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lcVector3 Center = (Min + Max) / 2.0f;
|
|
|
|
float Radius = (Max - Center).Length() / 25.0f;
|
|
|
|
Center = lcVector3(Center[1], Center[0], Center[2]) / 25.0f;
|
|
|
|
|
|
|
|
sprintf(Line, "light_source{ <%f, %f, %f>\n color rgb 0.75\n area_light 200, 200, 10, 10\n jitter\n}\n\n", 0.0f * Radius + Center.x, -1.5f * Radius + Center.y, -1.5f * Radius + Center.z);
|
|
|
|
POVFile.WriteLine(Line);
|
|
|
|
sprintf(Line, "light_source{ <%f, %f, %f>\n color rgb 0.75\n area_light 200, 200, 10, 10\n jitter\n}\n\n", 1.5f * Radius + Center.x, -1.0f * Radius + Center.y, 0.866026f * Radius + Center.z);
|
|
|
|
POVFile.WriteLine(Line);
|
|
|
|
sprintf(Line, "light_source{ <%f, %f, %f>\n color rgb 0.5\n area_light 200, 200, 10, 10\n jitter\n}\n\n", 0.0f * Radius + Center.x, -2.0f * Radius + Center.y, 0.0f * Radius + Center.z);
|
|
|
|
POVFile.WriteLine(Line);
|
|
|
|
sprintf(Line, "light_source{ <%f, %f, %f>\n color rgb 0.5\n area_light 200, 200, 10, 10\n jitter\n}\n\n", 2.0f * Radius + Center.x, 0.0f * Radius + Center.y, -2.0f * Radius + Center.z);
|
2015-01-12 05:49:30 +01:00
|
|
|
POVFile.WriteLine(Line);
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
for (const lcModelPartsEntry& ModelPart : ModelParts)
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2019-05-26 20:08:47 +02:00
|
|
|
int Color = ModelPart.ColorIndex;
|
2015-01-12 05:49:30 +01:00
|
|
|
const char* Suffix = lcIsColorTranslucent(Color) ? "_clear" : "";
|
2019-05-26 20:08:47 +02:00
|
|
|
const float* f = ModelPart.WorldMatrix;
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
if (!ModelPart.Mesh)
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2020-12-16 19:00:31 +01:00
|
|
|
std::pair<char[LC_PIECE_NAME_LEN + 1], int>& Entry = PieceTable[ModelPart.Info];
|
2019-05-26 20:08:47 +02:00
|
|
|
|
|
|
|
if (Entry.second & LGEO_PIECE_SLOPE)
|
|
|
|
{
|
|
|
|
sprintf(Line, "merge {\n object {\n %s%s\n texture { %s }\n }\n"
|
|
|
|
" object {\n %s_slope\n texture { %s normal { bumps 0.3 scale 0.02 } }\n }\n"
|
|
|
|
" matrix <%.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f>\n}\n",
|
|
|
|
Entry.first, Suffix, ColorTable[Color].data(), Entry.first, ColorTable[Color].data(),
|
|
|
|
-f[5], -f[4], -f[6], -f[1], -f[0], -f[2], f[9], f[8], f[10], f[13] / 25.0f, f[12] / 25.0f, f[14] / 25.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!ModelPart.Info || !ModelPart.Info->GetMesh())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sprintf(Line, "object {\n %s%s\n texture { %s }\n matrix <%.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f>\n}\n",
|
|
|
|
Entry.first, Suffix, ColorTable[Color].data(), -f[5], -f[4], -f[6], -f[1], -f[0], -f[2], f[9], f[8], f[10], f[13] / 25.0f, f[12] / 25.0f, f[14] / 25.0f);
|
|
|
|
|
|
|
|
}
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-26 20:08:47 +02:00
|
|
|
char Name[LC_PIECE_NAME_LEN];
|
|
|
|
GetMeshName(ModelPart, Name);
|
2019-03-06 18:08:51 +01:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
sprintf(Line, "object {\n lc_%s%s\n texture { %s }\n matrix <%.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f>\n}\n",
|
|
|
|
Name, Suffix, ColorTable[Color].data(), -f[5], -f[4], -f[6], -f[1], -f[0], -f[2], f[9], f[8], f[10], f[13] / 25.0f, f[12] / 25.0f, f[14] / 25.0f);
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
POVFile.WriteLine(Line);
|
2014-10-13 05:43:33 +02:00
|
|
|
}
|
2015-01-12 05:49:30 +01:00
|
|
|
|
2017-09-22 19:08:02 +02:00
|
|
|
return true;
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2021-01-11 03:07:27 +01:00
|
|
|
bool Project::ExportWavefront(const QString& FileName)
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2019-05-28 01:39:51 +02:00
|
|
|
std::vector<lcModelPartsEntry> ModelParts = GetModelParts();
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2019-05-28 01:39:51 +02:00
|
|
|
if (ModelParts.empty())
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2015-01-30 17:30:13 +01:00
|
|
|
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Nothing to export."));
|
2021-01-11 03:07:27 +01:00
|
|
|
return false;
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
QString SaveFileName = GetExportFileName(FileName, QLatin1String("obj"), tr("Export Wavefront"), tr("Wavefront Files (*.obj);;All Files (*.*)"));
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2015-03-27 21:39:43 +01:00
|
|
|
if (SaveFileName.isEmpty())
|
2021-01-11 03:07:27 +01:00
|
|
|
return false;
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
lcDiskFile OBJFile(SaveFileName);
|
2015-01-12 05:49:30 +01:00
|
|
|
char Line[1024];
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
if (!OBJFile.Open(QIODevice::WriteOnly))
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2015-01-30 17:30:13 +01:00
|
|
|
QMessageBox::warning(gMainWindow, tr("LeoCAD"), tr("Could not open file '%1' for writing.").arg(SaveFileName));
|
2021-01-11 03:07:27 +01:00
|
|
|
return false;
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2017-12-02 21:22:04 +01:00
|
|
|
quint32 vert = 1;
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
OBJFile.WriteLine("# Model exported from LeoCAD\n");
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
QFileInfo SaveInfo(SaveFileName);
|
|
|
|
QString MaterialFileName = QDir(SaveInfo.absolutePath()).absoluteFilePath(SaveInfo.completeBaseName() + QLatin1String(".mtl"));
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
sprintf(Line, "#\n\nmtllib %s\n\n", QFileInfo(MaterialFileName).fileName().toLatin1().constData());
|
|
|
|
OBJFile.WriteLine(Line);
|
|
|
|
|
|
|
|
lcDiskFile MaterialFile(MaterialFileName);
|
|
|
|
if (!MaterialFile.Open(QIODevice::WriteOnly))
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2017-05-29 22:31:24 +02:00
|
|
|
QMessageBox::warning(gMainWindow, tr("LeoCAD"), tr("Could not open file '%1' for writing.").arg(MaterialFileName));
|
2021-01-11 03:07:27 +01:00
|
|
|
return false;
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
MaterialFile.WriteLine("# Colors used by LeoCAD\n\n");
|
2019-07-05 02:06:26 +02:00
|
|
|
for (const lcColor& Color : gColorList)
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2019-07-05 02:06:26 +02:00
|
|
|
if (Color.Translucent)
|
|
|
|
sprintf(Line, "newmtl %s\nKd %.2f %.2f %.2f\nD %.2f\n\n", Color.SafeName, Color.Value[0], Color.Value[1], Color.Value[2], Color.Value[3]);
|
2017-02-15 01:48:19 +01:00
|
|
|
else
|
2019-07-05 02:06:26 +02:00
|
|
|
sprintf(Line, "newmtl %s\nKd %.2f %.2f %.2f\n\n", Color.SafeName, Color.Value[0], Color.Value[1], Color.Value[2]);
|
2017-05-29 22:31:24 +02:00
|
|
|
MaterialFile.WriteLine(Line);
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
for (const lcModelPartsEntry& ModelPart : ModelParts)
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2019-05-26 20:08:47 +02:00
|
|
|
lcMesh* Mesh = !ModelPart.Mesh ? ModelPart.Info->GetMesh() : ModelPart.Mesh;
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
if (!Mesh)
|
|
|
|
continue;
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
const lcMatrix44& ModelWorld = ModelPart.WorldMatrix;
|
2017-02-18 20:12:35 +01:00
|
|
|
lcVertex* Verts = (lcVertex*)Mesh->mVertexData;
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2017-02-18 20:12:35 +01:00
|
|
|
for (int VertexIdx = 0; VertexIdx < Mesh->mNumVertices; VertexIdx++)
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2017-02-18 20:12:35 +01:00
|
|
|
lcVector3 Vertex = lcMul31(Verts[VertexIdx].Position, ModelWorld);
|
2015-01-12 05:49:30 +01:00
|
|
|
sprintf(Line, "v %.2f %.2f %.2f\n", Vertex[0], Vertex[1], Vertex[2]);
|
|
|
|
OBJFile.WriteLine(Line);
|
|
|
|
}
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
OBJFile.WriteLine("#\n\n");
|
|
|
|
}
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
for (const lcModelPartsEntry& ModelPart : ModelParts)
|
2017-09-09 20:33:46 +02:00
|
|
|
{
|
2019-05-26 20:08:47 +02:00
|
|
|
lcMesh* Mesh = !ModelPart.Mesh ? ModelPart.Info->GetMesh() : ModelPart.Mesh;
|
2017-09-09 20:33:46 +02:00
|
|
|
|
|
|
|
if (!Mesh)
|
|
|
|
continue;
|
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
const lcMatrix44& ModelWorld = ModelPart.WorldMatrix;
|
2017-09-09 20:33:46 +02:00
|
|
|
lcVertex* Verts = (lcVertex*)Mesh->mVertexData;
|
|
|
|
|
|
|
|
for (int VertexIdx = 0; VertexIdx < Mesh->mNumVertices; VertexIdx++)
|
|
|
|
{
|
|
|
|
lcVector3 Normal = lcMul30(lcUnpackNormal(Verts[VertexIdx].Normal), ModelWorld);
|
|
|
|
sprintf(Line, "vn %.2f %.2f %.2f\n", Normal[0], Normal[1], Normal[2]);
|
|
|
|
OBJFile.WriteLine(Line);
|
|
|
|
}
|
|
|
|
|
|
|
|
OBJFile.WriteLine("#\n\n");
|
|
|
|
}
|
|
|
|
|
2019-05-28 20:10:21 +02:00
|
|
|
int NumPieces = 0;
|
|
|
|
for (const lcModelPartsEntry& ModelPart : ModelParts)
|
2015-01-12 05:49:30 +01:00
|
|
|
{
|
2019-05-28 20:10:21 +02:00
|
|
|
sprintf(Line, "g Piece%.3d\n", NumPieces++);
|
2015-01-12 05:49:30 +01:00
|
|
|
OBJFile.WriteLine(Line);
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2019-05-26 20:08:47 +02:00
|
|
|
lcMesh* Mesh = !ModelPart.Mesh ? ModelPart.Info->GetMesh() : ModelPart.Mesh;
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
if (Mesh)
|
|
|
|
{
|
2019-05-26 20:08:47 +02:00
|
|
|
Mesh->ExportWavefrontIndices(OBJFile, ModelPart.ColorIndex, vert);
|
2015-01-12 05:49:30 +01:00
|
|
|
vert += Mesh->mNumVertices;
|
2014-10-13 05:43:33 +02:00
|
|
|
}
|
|
|
|
}
|
2021-01-11 03:07:27 +01:00
|
|
|
|
|
|
|
return true;
|
2015-01-12 05:49:30 +01:00
|
|
|
}
|
2014-10-13 05:43:33 +02:00
|
|
|
|
2015-01-12 05:49:30 +01:00
|
|
|
void Project::SaveImage()
|
|
|
|
{
|
2016-08-01 05:44:15 +02:00
|
|
|
lcQImageDialog Dialog(gMainWindow);
|
2015-01-12 05:49:30 +01:00
|
|
|
|
2016-08-01 05:44:15 +02:00
|
|
|
if (Dialog.exec() != QDialog::Accepted)
|
2015-01-12 05:49:30 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-01 05:44:15 +02:00
|
|
|
QString Extension = QFileInfo(Dialog.mFileName).suffix();
|
2015-01-12 05:49:30 +01:00
|
|
|
|
|
|
|
if (!Extension.isEmpty())
|
2016-08-01 05:44:15 +02:00
|
|
|
lcSetProfileString(LC_PROFILE_IMAGE_EXTENSION, Dialog.mFileName.right(Extension.length() + 1));
|
2015-01-12 05:49:30 +01:00
|
|
|
|
2016-08-01 05:44:15 +02:00
|
|
|
if (Dialog.mStart != Dialog.mEnd)
|
|
|
|
Dialog.mFileName = Dialog.mFileName.insert(Dialog.mFileName.length() - Extension.length() - 1, QLatin1String("%1"));
|
2015-01-12 05:49:30 +01:00
|
|
|
|
2020-04-25 20:36:28 +02:00
|
|
|
mActiveModel->SaveStepImages(Dialog.mFileName, Dialog.mStart != Dialog.mEnd, false, Dialog.mWidth, Dialog.mHeight, Dialog.mStart, Dialog.mEnd);
|
2014-10-13 05:43:33 +02:00
|
|
|
}
|
2016-11-26 02:12:19 +01:00
|
|
|
|
|
|
|
void Project::UpdatePieceInfo(PieceInfo* Info) const
|
|
|
|
{
|
|
|
|
if (!mModels.IsEmpty())
|
|
|
|
{
|
2019-03-17 21:27:57 +01:00
|
|
|
std::vector<lcModel*> UpdatedModels;
|
2016-11-26 02:12:19 +01:00
|
|
|
mModels[0]->UpdatePieceInfo(UpdatedModels);
|
|
|
|
|
|
|
|
lcBoundingBox BoundingBox = mModels[0]->GetPieceInfo()->GetBoundingBox();
|
|
|
|
Info->SetBoundingBox(BoundingBox.Min, BoundingBox.Max);
|
|
|
|
}
|
|
|
|
}
|
2019-03-08 19:54:58 +01:00
|
|
|
|
|
|
|
void Project::MarkAsModified()
|
|
|
|
{
|
|
|
|
mModified = true;
|
|
|
|
}
|