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 01:41:58 +02:00
|
|
|
#include "lc_mesh.h"
|
2019-07-28 01:31:16 +02:00
|
|
|
#include "lc_meshloader.h"
|
2012-04-14 01:41:58 +02:00
|
|
|
#include "lc_colors.h"
|
2012-10-12 01:55:55 +02:00
|
|
|
#include "lc_texture.h"
|
2011-09-07 23:06:51 +02:00
|
|
|
#include "pieceinf.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"
|
2014-12-24 16:52:52 +01:00
|
|
|
#include "lc_model.h"
|
2016-11-26 02:12:19 +01:00
|
|
|
#include "project.h"
|
2017-04-02 01:53:54 +02:00
|
|
|
#include "lc_scene.h"
|
2016-02-29 21:13:54 +01:00
|
|
|
#include "lc_synth.h"
|
2024-11-03 03:34:22 +01:00
|
|
|
#include "lc_traintrack.h"
|
2016-05-02 21:13:54 +02:00
|
|
|
#include "lc_file.h"
|
2015-04-05 01:52:20 +02:00
|
|
|
#include <locale.h>
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-05-08 00:58:59 +02:00
|
|
|
PieceInfo::PieceInfo()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2021-01-18 21:09:33 +01:00
|
|
|
mZipFileType = lcZipFileType::Count;
|
2014-05-08 00:58:59 +02:00
|
|
|
mZipFileIndex = -1;
|
2021-11-15 03:34:24 +01:00
|
|
|
mFolderType = -1;
|
|
|
|
mFolderIndex = -1;
|
|
|
|
mState = lcPieceInfoState::Unloaded;
|
|
|
|
mFileName[0] = 0;
|
|
|
|
m_strDescription[0] = 0;
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-04-14 01:41:58 +02:00
|
|
|
PieceInfo::~PieceInfo()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2016-11-26 02:12:19 +01:00
|
|
|
delete mSynthInfo;
|
2024-11-03 03:34:22 +01:00
|
|
|
delete mTrainTrackInfo;
|
2016-11-26 02:12:19 +01:00
|
|
|
|
2021-11-15 03:34:24 +01:00
|
|
|
if (mState == lcPieceInfoState::Loaded)
|
2012-10-12 02:21:04 +02:00
|
|
|
Unload();
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2017-01-23 04:28:05 +01:00
|
|
|
void PieceInfo::SetMesh(lcMesh* Mesh)
|
|
|
|
{
|
|
|
|
mBoundingBox = Mesh->mBoundingBox;
|
2017-07-02 02:12:09 +02:00
|
|
|
ReleaseMesh();
|
2017-01-23 04:28:05 +01:00
|
|
|
mMesh = Mesh;
|
|
|
|
}
|
|
|
|
|
2015-01-08 05:50:38 +01:00
|
|
|
void PieceInfo::SetPlaceholder()
|
|
|
|
{
|
2020-12-31 23:23:08 +01:00
|
|
|
lcMesh* Mesh = new lcMesh;
|
|
|
|
Mesh->CreateBox();
|
|
|
|
SetMesh(Mesh);
|
2015-01-08 05:50:38 +01:00
|
|
|
|
2019-07-21 18:26:36 +02:00
|
|
|
mType = lcPieceInfoType::Placeholder;
|
2017-04-14 02:26:40 +02:00
|
|
|
mModel = nullptr;
|
|
|
|
mProject = nullptr;
|
2015-01-08 05:50:38 +01:00
|
|
|
}
|
|
|
|
|
2017-07-02 02:12:09 +02:00
|
|
|
void PieceInfo::SetModel(lcModel* Model, bool UpdateMesh, Project* CurrentProject, bool SearchProjectFolder)
|
2014-12-24 16:52:52 +01:00
|
|
|
{
|
2015-02-23 01:50:37 +01:00
|
|
|
if (mModel != Model)
|
|
|
|
{
|
2019-07-21 18:26:36 +02:00
|
|
|
mType = lcPieceInfoType::Model;
|
2015-02-23 01:50:37 +01:00
|
|
|
mModel = Model;
|
2021-01-01 23:28:08 +01:00
|
|
|
delete mMesh;
|
|
|
|
mMesh = nullptr;
|
2015-02-23 01:50:37 +01:00
|
|
|
}
|
2014-12-24 16:52:52 +01:00
|
|
|
|
2020-12-16 18:41:19 +01:00
|
|
|
strncpy(mFileName, Model->GetProperties().mFileName.toLatin1().data(), sizeof(mFileName) - 1);
|
2017-07-27 18:21:55 +02:00
|
|
|
mFileName[sizeof(mFileName)-1] = 0;
|
2020-12-16 18:41:19 +01:00
|
|
|
strncpy(m_strDescription, Model->GetProperties().mFileName.toLatin1().data(), sizeof(m_strDescription) - 1);
|
2015-01-17 19:29:10 +01:00
|
|
|
m_strDescription[sizeof(m_strDescription)-1] = 0;
|
|
|
|
|
2015-03-21 21:12:04 +01:00
|
|
|
const QStringList& MeshLines = Model->GetFileLines();
|
2015-02-23 01:50:37 +01:00
|
|
|
|
2015-02-28 21:31:57 +01:00
|
|
|
if (UpdateMesh && !MeshLines.isEmpty())
|
2015-02-23 01:50:37 +01:00
|
|
|
{
|
2015-02-28 21:31:57 +01:00
|
|
|
lcMemFile PieceFile;
|
2015-02-23 01:50:37 +01:00
|
|
|
|
2018-02-22 01:12:18 +01:00
|
|
|
for (const QString& Line : MeshLines)
|
2015-02-23 01:50:37 +01:00
|
|
|
{
|
2015-02-28 21:31:57 +01:00
|
|
|
QByteArray Buffer = Line.toLatin1();
|
|
|
|
PieceFile.WriteBuffer(Buffer.constData(), Buffer.size());
|
|
|
|
PieceFile.WriteBuffer("\r\n", 2);
|
2015-02-23 01:50:37 +01:00
|
|
|
}
|
|
|
|
|
2015-02-28 21:31:57 +01:00
|
|
|
lcLibraryMeshData MeshData;
|
|
|
|
PieceFile.Seek(0, SEEK_SET);
|
|
|
|
|
2019-07-28 01:31:16 +02:00
|
|
|
lcMeshLoader MeshLoader(MeshData, true, CurrentProject, SearchProjectFolder);
|
2020-03-23 04:18:52 +01:00
|
|
|
const bool Ret = MeshLoader.LoadMesh(PieceFile, LC_MESHDATA_SHARED);
|
2015-02-28 21:31:57 +01:00
|
|
|
|
2016-11-26 02:12:19 +01:00
|
|
|
if (Ret && !MeshData.IsEmpty())
|
2019-07-28 01:31:16 +02:00
|
|
|
SetMesh(MeshData.CreateMesh());
|
2015-02-23 01:50:37 +01:00
|
|
|
}
|
2014-12-24 16:52:52 +01:00
|
|
|
}
|
|
|
|
|
2017-07-27 18:21:55 +02:00
|
|
|
void PieceInfo::CreateProject(Project* Project, const char* PieceName)
|
2016-11-26 02:12:19 +01:00
|
|
|
{
|
|
|
|
if (mProject != Project)
|
|
|
|
{
|
2019-07-21 18:26:36 +02:00
|
|
|
mType = lcPieceInfoType::Project;
|
2016-11-26 02:12:19 +01:00
|
|
|
mProject = Project;
|
2021-11-15 03:34:24 +01:00
|
|
|
mState = lcPieceInfoState::Loaded;
|
2016-11-26 02:12:19 +01:00
|
|
|
}
|
|
|
|
|
2020-12-16 18:41:19 +01:00
|
|
|
strncpy(mFileName, PieceName, sizeof(mFileName) - 1);
|
2017-07-27 18:21:55 +02:00
|
|
|
mFileName[sizeof(mFileName) - 1] = 0;
|
2020-12-16 18:41:19 +01:00
|
|
|
strncpy(m_strDescription, Project->GetFileName().toLatin1().data(), sizeof(m_strDescription) - 1);
|
2017-07-27 18:21:55 +02:00
|
|
|
m_strDescription[sizeof(m_strDescription) - 1] = 0;
|
2016-11-26 02:12:19 +01:00
|
|
|
}
|
|
|
|
|
2022-07-06 16:23:31 +02:00
|
|
|
bool PieceInfo::IsProjectPiece() const
|
|
|
|
{
|
|
|
|
if (mProject)
|
|
|
|
return !strcmp(m_strDescription, mProject->GetFileName().toLatin1().data());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-29 19:20:36 +02:00
|
|
|
bool PieceInfo::GetPieceWorldMatrix(lcPiece* Piece, lcMatrix44& WorldMatrix) const
|
|
|
|
{
|
2019-07-21 18:26:36 +02:00
|
|
|
if (IsModel())
|
2018-03-29 19:20:36 +02:00
|
|
|
return mModel->GetPieceWorldMatrix(Piece, WorldMatrix);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-24 16:52:52 +01:00
|
|
|
bool PieceInfo::IncludesModel(const lcModel* Model) const
|
|
|
|
{
|
2019-07-21 18:26:36 +02:00
|
|
|
if (IsModel())
|
2014-12-24 16:52:52 +01:00
|
|
|
{
|
|
|
|
if (mModel == Model)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return mModel->IncludesModel(Model);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-05 06:03:59 +01:00
|
|
|
void PieceInfo::CreatePlaceholder(const char* Name)
|
|
|
|
{
|
2017-07-27 18:21:55 +02:00
|
|
|
strncpy(mFileName, Name, sizeof(mFileName));
|
|
|
|
mFileName[sizeof(mFileName) - 1] = 0;
|
2012-02-05 06:03:59 +01:00
|
|
|
strncpy(m_strDescription, Name, sizeof(m_strDescription));
|
2017-07-27 18:21:55 +02:00
|
|
|
m_strDescription[sizeof(m_strDescription) - 1] = 0;
|
2012-02-05 06:03:59 +01:00
|
|
|
|
2015-01-08 05:50:38 +01:00
|
|
|
SetPlaceholder();
|
2012-02-05 06:03:59 +01:00
|
|
|
}
|
|
|
|
|
2012-10-12 01:55:55 +02:00
|
|
|
void PieceInfo::Load()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2019-07-21 18:26:36 +02:00
|
|
|
if (!IsModel() && !IsProject())
|
2016-02-19 18:53:54 +01:00
|
|
|
{
|
2021-11-15 03:34:24 +01:00
|
|
|
mState = lcPieceInfoState::Loading; // todo: mutex lock when changing load state
|
2017-01-23 04:28:05 +01:00
|
|
|
|
2019-07-21 18:26:36 +02:00
|
|
|
if (IsPlaceholder())
|
2016-05-28 19:35:13 +02:00
|
|
|
{
|
2017-01-23 04:28:05 +01:00
|
|
|
if (lcGetPiecesLibrary()->LoadPieceData(this))
|
2019-07-21 18:26:36 +02:00
|
|
|
mType = lcPieceInfoType::Part;
|
2016-05-28 19:35:13 +02:00
|
|
|
}
|
2017-01-23 04:28:05 +01:00
|
|
|
else
|
|
|
|
lcGetPiecesLibrary()->LoadPieceData(this);
|
2016-02-19 18:53:54 +01:00
|
|
|
}
|
2017-01-23 04:28:05 +01:00
|
|
|
|
2021-11-15 03:34:24 +01:00
|
|
|
mState = lcPieceInfoState::Loaded;
|
2014-09-11 21:55:34 +02:00
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2017-07-02 02:12:09 +02:00
|
|
|
void PieceInfo::ReleaseMesh()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2014-12-24 16:52:52 +01:00
|
|
|
if (mMesh)
|
2012-10-12 01:55:55 +02:00
|
|
|
{
|
2015-05-24 06:36:25 +02:00
|
|
|
for (int LodIdx = 0; LodIdx < LC_NUM_MESH_LODS; LodIdx++)
|
2014-12-24 16:52:52 +01:00
|
|
|
{
|
2015-05-24 06:36:25 +02:00
|
|
|
for (int SectionIdx = 0; SectionIdx < mMesh->mLods[LodIdx].NumSections; SectionIdx++)
|
|
|
|
{
|
|
|
|
lcMeshSection& Section = mMesh->mLods[LodIdx].Sections[SectionIdx];
|
2012-10-12 01:55:55 +02:00
|
|
|
|
2015-05-24 06:36:25 +02:00
|
|
|
if (Section.Texture)
|
2021-06-27 21:42:53 +02:00
|
|
|
Section.Texture->Release();
|
2015-05-24 06:36:25 +02:00
|
|
|
}
|
2014-12-24 16:52:52 +01:00
|
|
|
}
|
2012-10-12 01:55:55 +02:00
|
|
|
|
2014-12-24 16:52:52 +01:00
|
|
|
delete mMesh;
|
2017-04-14 02:26:40 +02:00
|
|
|
mMesh = nullptr;
|
2014-12-24 16:52:52 +01:00
|
|
|
}
|
2017-07-02 02:12:09 +02:00
|
|
|
}
|
2015-01-07 17:52:42 +01:00
|
|
|
|
2017-07-02 02:12:09 +02:00
|
|
|
void PieceInfo::Unload()
|
|
|
|
{
|
|
|
|
ReleaseMesh();
|
2021-11-15 03:34:24 +01:00
|
|
|
mState = lcPieceInfoState::Unloaded;
|
2017-04-14 02:26:40 +02:00
|
|
|
mModel = nullptr;
|
2015-02-22 03:39:15 +01:00
|
|
|
|
|
|
|
if (IsModel())
|
|
|
|
lcGetPiecesLibrary()->RemovePiece(this);
|
2016-11-26 02:12:19 +01:00
|
|
|
else if (IsProject())
|
|
|
|
{
|
|
|
|
delete mProject;
|
2017-04-14 02:26:40 +02:00
|
|
|
mProject = nullptr;
|
2016-11-26 02:12:19 +01:00
|
|
|
lcGetPiecesLibrary()->RemovePiece(this);
|
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2021-12-25 00:42:37 +01:00
|
|
|
bool PieceInfo::MinIntersectDist(const lcVector3& Start, const lcVector3& End, float& MinDistance, lcPieceInfoRayTest& PieceInfoRayTest) const
|
2014-12-26 16:44:46 +01:00
|
|
|
{
|
2015-02-23 01:50:37 +01:00
|
|
|
bool Intersect = false;
|
2014-12-26 16:44:46 +01:00
|
|
|
|
2019-07-21 18:26:36 +02:00
|
|
|
if (IsPlaceholder() || IsModel() || IsProject())
|
2015-02-23 01:50:37 +01:00
|
|
|
{
|
2016-02-29 21:13:54 +01:00
|
|
|
float Distance;
|
2021-12-25 00:42:37 +01:00
|
|
|
lcVector3 Plane;
|
2021-12-24 02:27:38 +01:00
|
|
|
|
2021-12-25 00:42:37 +01:00
|
|
|
if (!lcBoundingBoxRayIntersectDistance(mBoundingBox.Min, mBoundingBox.Max, Start, End, &Distance, nullptr, &Plane) || (Distance >= MinDistance))
|
2016-02-29 21:13:54 +01:00
|
|
|
return false;
|
|
|
|
|
2019-07-21 18:26:36 +02:00
|
|
|
if (IsPlaceholder())
|
2021-12-24 02:27:38 +01:00
|
|
|
{
|
2022-01-09 21:54:45 +01:00
|
|
|
PieceInfoRayTest.Info = this;
|
2021-12-25 00:42:37 +01:00
|
|
|
PieceInfoRayTest.Transform = lcMatrix44Identity();
|
|
|
|
MinDistance = Distance;
|
|
|
|
PieceInfoRayTest.Plane = Plane;
|
2016-02-29 21:13:54 +01:00
|
|
|
return true;
|
2021-12-24 02:27:38 +01:00
|
|
|
}
|
2016-02-29 21:13:54 +01:00
|
|
|
|
2019-07-21 18:26:36 +02:00
|
|
|
if (IsModel())
|
2021-12-25 00:42:37 +01:00
|
|
|
Intersect |= mModel->SubModelMinIntersectDist(Start, End, MinDistance, PieceInfoRayTest);
|
2019-07-21 18:26:36 +02:00
|
|
|
else if (IsProject())
|
2016-11-26 02:12:19 +01:00
|
|
|
{
|
2020-03-23 04:18:52 +01:00
|
|
|
const lcModel* const Model = mProject->GetMainModel();
|
2016-11-26 02:12:19 +01:00
|
|
|
if (Model)
|
2021-12-25 00:42:37 +01:00
|
|
|
Intersect |= Model->SubModelMinIntersectDist(Start, End, MinDistance, PieceInfoRayTest);
|
2016-11-26 02:12:19 +01:00
|
|
|
}
|
2015-02-23 01:50:37 +01:00
|
|
|
}
|
|
|
|
|
2016-02-29 21:13:54 +01:00
|
|
|
if (mMesh)
|
2021-12-24 02:27:38 +01:00
|
|
|
{
|
2021-12-25 00:42:37 +01:00
|
|
|
if (mMesh->MinIntersectDist(Start, End, MinDistance, PieceInfoRayTest.Plane))
|
2021-12-24 02:27:38 +01:00
|
|
|
{
|
2022-01-09 21:54:45 +01:00
|
|
|
PieceInfoRayTest.Info = this;
|
2021-12-25 00:42:37 +01:00
|
|
|
PieceInfoRayTest.Transform = lcMatrix44Identity();
|
2021-12-24 02:27:38 +01:00
|
|
|
Intersect = true;
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 01:50:37 +01:00
|
|
|
|
|
|
|
return Intersect;
|
2014-12-26 16:44:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PieceInfo::BoxTest(const lcMatrix44& WorldMatrix, const lcVector4 WorldPlanes[6]) const
|
|
|
|
{
|
|
|
|
lcMatrix44 InverseWorldMatrix = lcMatrix44AffineInverse(WorldMatrix);
|
|
|
|
|
2020-03-23 04:18:52 +01:00
|
|
|
constexpr int NumCorners = 8;
|
|
|
|
constexpr int NumPlanes = 6;
|
2014-12-26 16:44:46 +01:00
|
|
|
lcVector4 LocalPlanes[NumPlanes];
|
|
|
|
|
|
|
|
for (int PlaneIdx = 0; PlaneIdx < NumPlanes; PlaneIdx++)
|
|
|
|
{
|
2020-03-23 04:18:52 +01:00
|
|
|
const lcVector3 PlaneNormal = lcMul30(WorldPlanes[PlaneIdx], InverseWorldMatrix);
|
2014-12-26 16:44:46 +01:00
|
|
|
LocalPlanes[PlaneIdx] = lcVector4(PlaneNormal, WorldPlanes[PlaneIdx][3] - lcDot3(InverseWorldMatrix[3], PlaneNormal));
|
|
|
|
}
|
|
|
|
|
2016-02-19 18:53:54 +01:00
|
|
|
lcVector3 Box[NumCorners];
|
|
|
|
lcGetBoxCorners(mBoundingBox, Box);
|
2014-12-26 16:44:46 +01:00
|
|
|
|
|
|
|
int Outcodes[NumCorners];
|
|
|
|
|
|
|
|
for (int CornerIdx = 0; CornerIdx < NumCorners; CornerIdx++)
|
|
|
|
{
|
|
|
|
Outcodes[CornerIdx] = 0;
|
|
|
|
|
|
|
|
for (int PlaneIdx = 0; PlaneIdx < NumPlanes; PlaneIdx++)
|
|
|
|
{
|
|
|
|
if (lcDot3(Box[CornerIdx], LocalPlanes[PlaneIdx]) + LocalPlanes[PlaneIdx][3] > 0)
|
|
|
|
Outcodes[CornerIdx] |= 1 << PlaneIdx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int OutcodesOR = 0, OutcodesAND = 0x3f;
|
|
|
|
|
|
|
|
for (int CornerIdx = 0; CornerIdx < NumCorners; CornerIdx++)
|
|
|
|
{
|
|
|
|
OutcodesAND &= Outcodes[CornerIdx];
|
|
|
|
OutcodesOR |= Outcodes[CornerIdx];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OutcodesAND != 0)
|
|
|
|
return false;
|
|
|
|
|
2015-02-23 01:50:37 +01:00
|
|
|
if (OutcodesOR == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (mMesh && mMesh->IntersectsPlanes(LocalPlanes))
|
|
|
|
return true;
|
|
|
|
|
2019-07-21 18:26:36 +02:00
|
|
|
if (IsModel())
|
2015-02-23 01:50:37 +01:00
|
|
|
return mModel->SubModelBoxTest(LocalPlanes);
|
2019-07-21 18:26:36 +02:00
|
|
|
else if (IsProject())
|
2016-11-26 02:12:19 +01:00
|
|
|
{
|
2020-03-23 04:18:52 +01:00
|
|
|
const lcModel* const Model = mProject->GetMainModel();
|
2016-11-26 02:12:19 +01:00
|
|
|
return Model ? Model->SubModelBoxTest(LocalPlanes) : false;
|
|
|
|
}
|
2015-01-08 05:50:38 +01:00
|
|
|
|
2015-02-23 01:50:37 +01:00
|
|
|
return false;
|
2014-12-26 16:44:46 +01:00
|
|
|
}
|
|
|
|
|
2017-12-21 23:02:16 +01:00
|
|
|
void PieceInfo::ZoomExtents(float FoV, float AspectRatio, lcMatrix44& ProjectionMatrix, lcMatrix44& ViewMatrix) const
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2016-02-19 18:53:54 +01:00
|
|
|
lcVector3 Points[8];
|
|
|
|
lcGetBoxCorners(mBoundingBox, Points);
|
|
|
|
|
2020-03-23 04:18:52 +01:00
|
|
|
const lcVector3 Center = (mBoundingBox.Min + mBoundingBox.Max) / 2.0f;
|
2017-12-21 23:02:16 +01:00
|
|
|
lcVector3 Position = Center + lcVector3(100.0f, -100.0f, 75.0f);
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2017-12-21 23:02:16 +01:00
|
|
|
ProjectionMatrix = lcMatrix44Perspective(FoV, AspectRatio, 1.0f, 12500.0f);
|
2020-03-23 04:18:52 +01:00
|
|
|
const lcMatrix44 ModelView = lcMatrix44LookAt(Position, Center, lcVector3(0, 0, 1));
|
2017-12-21 23:02:16 +01:00
|
|
|
float FarDistance;
|
|
|
|
std::tie(Position, FarDistance) = lcZoomExtents(Position, ModelView, ProjectionMatrix, Points, 8);
|
2015-01-02 12:58:14 +01:00
|
|
|
ViewMatrix = lcMatrix44LookAt(Position, Center, lcVector3(0, 0, 1));
|
2017-12-21 23:02:16 +01:00
|
|
|
ProjectionMatrix = lcMatrix44Perspective(FoV, AspectRatio, 1.0f, FarDistance);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2015-02-23 01:50:37 +01:00
|
|
|
void PieceInfo::AddRenderMesh(lcScene& Scene)
|
2014-12-24 16:52:52 +01:00
|
|
|
{
|
2017-03-23 07:35:02 +01:00
|
|
|
if (mMesh)
|
2020-01-02 02:06:17 +01:00
|
|
|
Scene.AddMesh(mMesh, lcMatrix44Identity(), gDefaultColor, lcRenderMeshState::Default);
|
2014-04-23 16:53:43 +02:00
|
|
|
}
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2020-12-05 20:02:10 +01:00
|
|
|
void PieceInfo::AddRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const
|
2015-02-23 01:50:37 +01:00
|
|
|
{
|
2019-07-21 18:26:36 +02:00
|
|
|
if (mMesh || IsPlaceholder())
|
2020-12-31 23:23:08 +01:00
|
|
|
Scene->AddMesh(mMesh, WorldMatrix, ColorIndex, RenderMeshState);
|
2015-02-23 01:50:37 +01:00
|
|
|
|
2019-07-21 18:26:36 +02:00
|
|
|
if (IsModel())
|
2018-04-07 20:45:00 +02:00
|
|
|
mModel->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive);
|
2019-07-21 18:26:36 +02:00
|
|
|
else if (IsProject())
|
2016-11-26 02:12:19 +01:00
|
|
|
{
|
2020-03-23 04:18:52 +01:00
|
|
|
const lcModel* const Model = mProject->GetMainModel();
|
2016-11-26 02:12:19 +01:00
|
|
|
if (Model)
|
2018-04-07 20:45:00 +02:00
|
|
|
Model->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive);
|
2016-11-26 02:12:19 +01:00
|
|
|
}
|
2015-02-23 01:50:37 +01:00
|
|
|
}
|
|
|
|
|
2020-01-11 21:45:36 +01:00
|
|
|
void PieceInfo::GetPartsList(int DefaultColorIndex, bool ScanSubModels, bool AddSubModels, lcPartsList& PartsList) const
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2020-01-11 21:45:36 +01:00
|
|
|
if (IsModel())
|
|
|
|
{
|
|
|
|
if (ScanSubModels)
|
|
|
|
mModel->GetPartsList(DefaultColorIndex, ScanSubModels, AddSubModels, PartsList);
|
|
|
|
|
2021-01-23 19:21:00 +01:00
|
|
|
if (AddSubModels)
|
2020-01-11 21:45:36 +01:00
|
|
|
PartsList[this][DefaultColorIndex]++;
|
|
|
|
}
|
2022-07-06 16:23:31 +02:00
|
|
|
else if (IsProject() && !IsProjectPiece())
|
2016-11-26 02:12:19 +01:00
|
|
|
{
|
2020-03-23 04:18:52 +01:00
|
|
|
const lcModel* const Model = mProject->GetMainModel();
|
2016-11-26 02:12:19 +01:00
|
|
|
if (Model)
|
2020-01-11 21:45:36 +01:00
|
|
|
Model->GetPartsList(DefaultColorIndex, ScanSubModels, AddSubModels, PartsList);
|
2016-11-26 02:12:19 +01:00
|
|
|
}
|
2021-01-23 19:21:00 +01:00
|
|
|
else
|
2016-11-16 23:53:41 +01:00
|
|
|
PartsList[this][DefaultColorIndex]++;
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
|
|
|
|
2019-05-28 01:39:51 +02:00
|
|
|
void PieceInfo::GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, std::vector<lcModelPartsEntry>& ModelParts) const
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
2019-07-21 18:26:36 +02:00
|
|
|
if (IsModel())
|
2014-12-30 17:30:12 +01:00
|
|
|
{
|
|
|
|
mModel->GetModelParts(WorldMatrix, DefaultColorIndex, ModelParts);
|
|
|
|
return;
|
|
|
|
}
|
2019-07-21 18:26:36 +02:00
|
|
|
else if (IsProject())
|
2016-11-26 02:12:19 +01:00
|
|
|
{
|
2020-03-23 04:18:52 +01:00
|
|
|
const lcModel* const Model = mProject->GetMainModel();
|
2016-11-26 02:12:19 +01:00
|
|
|
if (Model)
|
|
|
|
Model->GetModelParts(WorldMatrix, DefaultColorIndex, ModelParts);
|
|
|
|
return;
|
|
|
|
}
|
2014-12-30 17:30:12 +01:00
|
|
|
|
2019-05-28 01:39:51 +02:00
|
|
|
ModelParts.emplace_back(lcModelPartsEntry{ WorldMatrix, this, nullptr, DefaultColorIndex });
|
2014-12-30 17:30:12 +01:00
|
|
|
}
|
2015-01-02 17:44:01 +01:00
|
|
|
|
2020-04-11 20:04:27 +02:00
|
|
|
void PieceInfo::CompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const
|
|
|
|
{
|
|
|
|
if (!IsModel())
|
|
|
|
{
|
|
|
|
lcVector3 Points[8];
|
|
|
|
|
|
|
|
if (!mMesh)
|
|
|
|
lcGetBoxCorners(GetBoundingBox(), Points);
|
|
|
|
else
|
|
|
|
lcGetBoxCorners(mMesh->mBoundingBox, Points);
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
2021-11-15 03:34:24 +01:00
|
|
|
const lcVector3 Point = lcMul31(Points[i], WorldMatrix);
|
2020-04-11 20:04:27 +02:00
|
|
|
|
|
|
|
Min = lcMin(Point, Min);
|
|
|
|
Max = lcMax(Point, Max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mModel->SubModelCompareBoundingBox(WorldMatrix, Min, Max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-31 19:22:12 +01:00
|
|
|
void PieceInfo::AddSubModelBoundingBoxPoints(const lcMatrix44& WorldMatrix, std::vector<lcVector3>& Points) const
|
|
|
|
{
|
|
|
|
if (!IsModel())
|
|
|
|
{
|
|
|
|
lcVector3 BoxPoints[8];
|
|
|
|
|
|
|
|
if (!mMesh)
|
|
|
|
lcGetBoxCorners(GetBoundingBox(), BoxPoints);
|
|
|
|
else
|
|
|
|
lcGetBoxCorners(mMesh->mBoundingBox, BoxPoints);
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
Points.emplace_back(lcMul31(BoxPoints[i], WorldMatrix));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mModel->SubModelAddBoundingBoxPoints(WorldMatrix, Points);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-17 21:27:57 +01:00
|
|
|
void PieceInfo::UpdateBoundingBox(std::vector<lcModel*>& UpdatedModels)
|
2015-01-02 17:44:01 +01:00
|
|
|
{
|
2019-07-21 18:26:36 +02:00
|
|
|
if (IsModel())
|
2015-01-17 19:29:10 +01:00
|
|
|
mModel->UpdatePieceInfo(UpdatedModels);
|
2019-07-21 18:26:36 +02:00
|
|
|
else if (IsProject())
|
2016-11-26 02:12:19 +01:00
|
|
|
mProject->UpdatePieceInfo(this);
|
2015-01-02 17:44:01 +01:00
|
|
|
}
|