More accurate bounding box calculation for submodels.

This commit is contained in:
Leonardo Zide 2020-04-11 11:04:27 -07:00
parent ca73f3e3ad
commit 70da56bb05
6 changed files with 50 additions and 8 deletions

View file

@ -1764,6 +1764,13 @@ bool lcModel::SubModelBoxTest(const lcVector4 Planes[6]) const
return false;
}
void lcModel::SubModelCompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const
{
for (lcPiece* Piece : mPieces)
if (Piece->IsVisibleInSubModel())
Piece->SubmodelCompareBoundingBox(WorldMatrix, Min, Max);
}
void lcModel::SaveCheckpoint(const QString& Description)
{
lcModelHistoryEntry* ModelHistoryEntry = new lcModelHistoryEntry();

View file

@ -237,6 +237,7 @@ public:
void BoxTest(lcObjectBoxTest& ObjectBoxTest) const;
bool SubModelMinIntersectDist(const lcVector3& WorldStart, const lcVector3& WorldEnd, float& MinDistance) const;
bool SubModelBoxTest(const lcVector4 Planes[6]) const;
void SubModelCompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const;
bool HasPieces() const
{

View file

@ -703,6 +703,11 @@ void lcPiece::AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMat
Scene.AddInterfaceObject(this);
}
void lcPiece::SubmodelCompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const
{
mPieceInfo->CompareBoundingBox(lcMul(mModelWorld, WorldMatrix), Min, Max);
}
void lcPiece::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance)
{
quint32 Section = GetFocusSection();
@ -934,19 +939,21 @@ const lcBoundingBox& lcPiece::GetBoundingBox() const
void lcPiece::CompareBoundingBox(lcVector3& Min, lcVector3& Max) const
{
lcVector3 Points[8];
if (!mMesh)
lcGetBoxCorners(GetBoundingBox(), Points);
mPieceInfo->CompareBoundingBox(mModelWorld, Min, Max);
else
{
lcVector3 Points[8];
lcGetBoxCorners(mMesh->mBoundingBox, Points);
for (int i = 0; i < 8; i++)
{
lcVector3 Point = lcMul31(Points[i], mModelWorld);
for (int i = 0; i < 8; i++)
{
lcVector3 Point = lcMul31(Points[i], mModelWorld);
Min = lcMin(Point, Min);
Max = lcMax(Point, Max);
Min = lcMin(Point, Min);
Max = lcMax(Point, Max);
}
}
}

View file

@ -407,6 +407,7 @@ public:
void AddMainModelRenderMeshes(lcScene& Scene, bool Highlight, bool Fade) const;
void AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const;
void SubmodelCompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const;
void InsertTime(lcStep Start, lcStep Time);
void RemoveTime(lcStep Start, lcStep Time);

View file

@ -358,6 +358,31 @@ void PieceInfo::GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorInd
ModelParts.emplace_back(lcModelPartsEntry{ WorldMatrix, this, nullptr, DefaultColorIndex });
}
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++)
{
lcVector3 Point = lcMul31(Points[i], WorldMatrix);
Min = lcMin(Point, Min);
Max = lcMax(Point, Max);
}
}
else
{
mModel->SubModelCompareBoundingBox(WorldMatrix, Min, Max);
}
}
void PieceInfo::UpdateBoundingBox(std::vector<lcModel*>& UpdatedModels)
{
if (IsModel())

View file

@ -159,6 +159,7 @@ public:
bool BoxTest(const lcMatrix44& WorldMatrix, const lcVector4 Planes[6]) const;
void GetPartsList(int DefaultColorIndex, bool ScanSubModels, bool AddSubModels, lcPartsList& PartsList) const;
void GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, std::vector<lcModelPartsEntry>& ModelParts) const;
void CompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const;
void UpdateBoundingBox(std::vector<lcModel*>& UpdatedModels);
void Load();