git mv Code\Sandbox\Editor Code/Editor

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
Esteban Papp
2021-06-29 12:41:59 -07:00
parent 9f0bbf3b74
commit e34e36cb35
1415 changed files with 0 additions and 0 deletions
+137
View File
@@ -0,0 +1,137 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "EditorDefs.h"
#include "DeepSelection.h"
// Editor
#include "Objects/BaseObject.h"
//! Functor for sorting selected objects on deep selection mode.
struct NearDistance
{
NearDistance(){}
bool operator()(const CDeepSelection::RayHitObject& lhs, const CDeepSelection::RayHitObject& rhs) const
{
return lhs.distance < rhs.distance;
}
};
//-----------------------------------------------------------------------------
CDeepSelection::CDeepSelection()
: m_Mode(DSM_NONE)
, m_previousMode(DSM_NONE)
, m_CandidateObjectCount(0)
, m_CurrentSelectedPos(-1)
{
m_LastPickPoint = QPoint(-1, -1);
}
//-----------------------------------------------------------------------------
CDeepSelection::~CDeepSelection()
{
}
//-----------------------------------------------------------------------------
void CDeepSelection::Reset(bool bResetLastPick)
{
for (int i = 0; i < m_CandidateObjectCount; ++i)
{
m_RayHitObjects[i].object->ClearFlags(OBJFLAG_NO_HITTEST);
}
m_CandidateObjectCount = 0;
m_CurrentSelectedPos = -1;
m_RayHitObjects.clear();
if (bResetLastPick)
{
m_LastPickPoint = QPoint(-1, -1);
}
}
//-----------------------------------------------------------------------------
void CDeepSelection::AddObject(float distance, CBaseObject* pObj)
{
m_RayHitObjects.push_back(RayHitObject(distance, pObj));
}
//-----------------------------------------------------------------------------
bool CDeepSelection::OnCycling (const QPoint& pt)
{
QPoint diff = m_LastPickPoint - pt;
LONG epsilon = 2;
m_LastPickPoint = pt;
if (abs(diff.x()) < epsilon && abs(diff.y()) < epsilon)
{
return true;
}
else
{
return false;
}
}
//-----------------------------------------------------------------------------
void CDeepSelection::ExcludeHitTest(int except)
{
int nExcept = except % m_CandidateObjectCount;
for (int i = 0; i < m_CandidateObjectCount; ++i)
{
m_RayHitObjects[i].object->SetFlags(OBJFLAG_NO_HITTEST);
}
m_RayHitObjects[nExcept].object->ClearFlags(OBJFLAG_NO_HITTEST);
}
//-----------------------------------------------------------------------------
int CDeepSelection::CollectCandidate(float fMinDistance, float fRange)
{
m_CandidateObjectCount = 0;
if (!m_RayHitObjects.empty())
{
std::sort(m_RayHitObjects.begin(), m_RayHitObjects.end(), NearDistance());
for (std::vector<CDeepSelection::RayHitObject>::iterator itr = m_RayHitObjects.begin();
itr != m_RayHitObjects.end(); ++itr)
{
if (itr->distance - fMinDistance < fRange)
{
++m_CandidateObjectCount;
}
else
{
break;
}
}
}
return m_CandidateObjectCount;
}
//-----------------------------------------------------------------------------
CBaseObject* CDeepSelection::GetCandidateObject(int index)
{
m_CurrentSelectedPos = index % m_CandidateObjectCount;
return m_RayHitObjects[m_CurrentSelectedPos].object;
}
//-----------------------------------------------------------------------------
//!
void CDeepSelection::SetMode(EDeepSelectionMode mode)
{
m_previousMode = m_Mode;
m_Mode = mode;
}
+86
View File
@@ -0,0 +1,86 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : Deep Selection Header
#ifndef CRYINCLUDE_EDITOR_EDITMODE_DEEPSELECTION_H
#define CRYINCLUDE_EDITOR_EDITMODE_DEEPSELECTION_H
#pragma once
class CBaseObject;
//! Deep Selection
//! Additional output information of HitContext on using "deep selection mode".
//! At the deep selection mode, it supports second selection pass for easy
//! selection on crowded area with two different method.
//! One is to show pop menu of candidate objects list. Another is the cyclic
//! selection on pick clicking.
class CDeepSelection
: public _i_reference_target_t
{
public:
//! Deep Selection Mode Definition
enum EDeepSelectionMode
{
DSM_NONE = 0, // Not using deep selection.
DSM_POP = 1, // Deep selection mode with pop context menu.
DSM_CYCLE = 2 // Deep selection mode with cyclic selection on each clinking same point.
};
//! Subclass for container of the selected object with hit distance.
struct RayHitObject
{
RayHitObject(float dist, CBaseObject* pObj)
: distance(dist)
, object(pObj)
{
}
float distance;
CBaseObject* object;
};
//! Constructor
CDeepSelection();
virtual ~CDeepSelection();
void Reset(bool bResetLastPick = false);
void AddObject(float distance, CBaseObject* pObj);
//! Check if clicking point is same position with last position,
//! to decide whether to continue cycling mode.
bool OnCycling (const QPoint& pt);
//! All objects in list are excluded for hitting test except one, current selection.
void ExcludeHitTest(int except);
void SetMode(EDeepSelectionMode mode);
inline EDeepSelectionMode GetMode() const { return m_Mode; }
inline EDeepSelectionMode GetPreviousMode() const { return m_previousMode; }
//! Collect object in the deep selection range. The distance from the minimum
//! distance is less than deep selection range.
int CollectCandidate(float fMinDistance, float fRange);
//! Return the candidate object in index position, then it is to be current
//! selection position.
CBaseObject* GetCandidateObject(int index);
//! Return the current selection position that is update in "GetCandidateObject"
//! function call.
inline int GetCurrentSelectPos() const { return m_CurrentSelectedPos; }
//! Return the number of objects in the deep selection range.
inline int GetCandidateObjectCount() const { return m_CandidateObjectCount; }
private:
//! Current mode
EDeepSelectionMode m_Mode;
EDeepSelectionMode m_previousMode;
//! Last picking point to check whether cyclic selection continue.
QPoint m_LastPickPoint;
//! List of the selected objects with ray hitting
std::vector<RayHitObject> m_RayHitObjects;
int m_CandidateObjectCount;
int m_CurrentSelectedPos;
};
#endif // CRYINCLUDE_EDITOR_EDITMODE_DEEPSELECTION_H
@@ -0,0 +1,74 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : Calculate the reference frame for sub-object selections.
#include "EditorDefs.h"
#include "SubObjectSelectionReferenceFrameCalculator.h"
SubObjectSelectionReferenceFrameCalculator::SubObjectSelectionReferenceFrameCalculator(ESubObjElementType selectionType)
: m_anySelected(false)
, pos(0.0f, 0.0f, 0.0f)
, normal(0.0f, 0.0f, 0.0f)
, nNormals(0)
, selectionType(selectionType)
, bUseExplicitFrame(false)
, bExplicitAnySelected(false)
{
}
void SubObjectSelectionReferenceFrameCalculator::SetExplicitFrame(bool bAnySelected, const Matrix34& refFrame)
{
this->m_refFrame = refFrame;
this->bUseExplicitFrame = true;
this->bExplicitAnySelected = bAnySelected;
}
bool SubObjectSelectionReferenceFrameCalculator::GetFrame(Matrix34& refFrame)
{
if (this->bUseExplicitFrame)
{
refFrame = this->m_refFrame;
return this->bExplicitAnySelected;
}
else
{
refFrame.SetIdentity();
if (this->nNormals > 0)
{
this->normal = this->normal / this->nNormals;
if (!this->normal.IsZero())
{
this->normal.Normalize();
}
// Average position.
this->pos = this->pos / this->nNormals;
refFrame.SetTranslation(this->pos);
}
if (this->m_anySelected)
{
if (!this->normal.IsZero())
{
Vec3 xAxis(1, 0, 0), yAxis(0, 1, 0), zAxis(0, 0, 1);
if (this->normal.IsEquivalent(zAxis) || normal.IsEquivalent(-zAxis))
{
zAxis = xAxis;
}
xAxis = this->normal.Cross(zAxis).GetNormalized();
yAxis = xAxis.Cross(this->normal).GetNormalized();
refFrame.SetFromVectors(xAxis, yAxis, normal, pos);
}
}
return m_anySelected;
}
}
@@ -0,0 +1,41 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : Calculate the reference frame for sub-object selections.
#ifndef CRYINCLUDE_EDITOR_EDITMODE_SUBOBJECTSELECTIONREFERENCEFRAMECALCULATOR_H
#define CRYINCLUDE_EDITOR_EDITMODE_SUBOBJECTSELECTIONREFERENCEFRAMECALCULATOR_H
#pragma once
#include "ISubObjectSelectionReferenceFrameCalculator.h"
#include "Objects/SubObjSelection.h"
class SubObjectSelectionReferenceFrameCalculator
: public ISubObjectSelectionReferenceFrameCalculator
{
public:
SubObjectSelectionReferenceFrameCalculator(ESubObjElementType selectionType);
virtual void SetExplicitFrame(bool bAnySelected, const Matrix34& refFrame);
bool GetFrame(Matrix34& refFrame);
private:
bool m_anySelected;
Vec3 pos;
Vec3 normal;
int nNormals;
ESubObjElementType selectionType;
std::vector<Vec3> positions;
Matrix34 m_refFrame;
bool bUseExplicitFrame;
bool bExplicitAnySelected;
};
#endif // CRYINCLUDE_EDITOR_EDITMODE_SUBOBJECTSELECTIONREFERENCEFRAMECALCULATOR_H