merge from main

This commit is contained in:
greerdv
2021-05-19 12:14:25 +01:00
11816 changed files with 189923 additions and 1002401 deletions
+2 -5
View File
@@ -18,11 +18,9 @@
// Editor
#include "Viewport.h"
#include "GizmoManager.h"
#include "Grid.h"
#include "ViewManager.h"
#include "Settings.h"
#include "RenderHelpers/AxisHelper.h"
#include "RenderHelpers/AxisHelperExtended.h"
#include "IObjectManager.h"
//////////////////////////////////////////////////////////////////////////
@@ -36,7 +34,6 @@ CAxisGizmo::CAxisGizmo(CBaseObject* object)
assert(object != 0);
m_object = object;
m_pAxisHelper.reset(new CAxisHelper);
m_pAxisHelperExtended.reset(new CAxisHelperExtended);
// Set selectable flag.
SetFlags(EGIZMO_SELECTABLE | EGIZMO_TRANSFORM_MANIPULATOR);
@@ -60,7 +57,6 @@ CAxisGizmo::CAxisGizmo()
SetFlags(EGIZMO_SELECTABLE);
m_axisGizmoCount++;
m_pAxisHelper.reset(new CAxisHelper);
m_pAxisHelperExtended.reset(new CAxisHelperExtended);
m_bDragging = false;
m_bAlwaysUseLocal = false;
m_coordSysBackUp = COORDS_VIEW;
@@ -247,7 +243,8 @@ Matrix34 CAxisGizmo::GetTransformation(RefCoordSys coordSys, IDisplayViewport* v
break;
case COORDS_USERDEFINED:
{
Matrix34 userTM = GetIEditor()->GetViewManager()->GetGrid()->GetMatrix();
Matrix34 userTM;
userTM.SetIdentity();
userTM.SetTranslation(m_object->GetWorldTM().GetTranslation());
return userTM;
}
-2
View File
@@ -22,7 +22,6 @@
// forward declarations.
struct DisplayContext;
class CAxisHelper;
class CAxisHelperExtended;
/** Gizmo of Objects animation track.
*/
@@ -75,7 +74,6 @@ private:
CBaseObjectPtr m_object;
AABB m_bbox;
std::unique_ptr<CAxisHelper> m_pAxisHelper;
std::unique_ptr<CAxisHelperExtended> m_pAxisHelperExtended;
bool m_bDragging;
QPoint m_cMouseDownPos;
+4 -395
View File
@@ -30,8 +30,6 @@
#include "DisplaySettings.h"
#include "Undo/Undo.h"
#include "UsedResources.h"
#include "Material/Material.h"
#include "Material/MaterialManager.h"
#include "GizmoManager.h"
#include "Include/IIconManager.h"
#include "Objects/SelectionGroup.h"
@@ -39,6 +37,8 @@
#include "ViewManager.h"
#include "IEditorImpl.h"
#include "GameEngine.h"
#include <IEntityRenderState.h>
#include <IStatObj.h>
// To use the Andrew's algorithm in order to make convex hull from the points, this header is needed.
#include "Util/GeometryUtil.h"
@@ -398,7 +398,6 @@ CBaseObject::CBaseObject()
, m_classDesc(nullptr)
, m_numRefs(0)
, m_parent(nullptr)
, m_pMaterial(nullptr)
, m_bInSelectionBox(false)
, m_pTransformDelegate(nullptr)
, m_bMatrixInWorldSpace(false)
@@ -438,7 +437,6 @@ bool CBaseObject::Init([[maybe_unused]] IEditor* ie, CBaseObject* prev, [[maybe_
SetArea(prev->GetArea());
SetColor(prev->GetColor());
m_nMaterialLayersMask = prev->m_nMaterialLayersMask;
SetMaterial(prev->GetMaterial());
SetMinSpec(prev->GetMinSpec(), false);
// Copy all basic variables.
@@ -485,12 +483,6 @@ void CBaseObject::Done()
NotifyListeners(CBaseObject::ON_DELETE);
m_eventListeners.clear();
if (m_pMaterial)
{
m_pMaterial->Release();
m_pMaterial = NULL;
}
}
//////////////////////////////////////////////////////////////////////////
@@ -831,9 +823,8 @@ void CBaseObject::GetLocalBounds(AABB& box)
}
//////////////////////////////////////////////////////////////////////////
void CBaseObject::SetModified(bool boModifiedTransformOnly)
void CBaseObject::SetModified(bool)
{
((CObjectManager*)GetObjectManager())->OnObjectModified(this, false, boModifiedTransformOnly);
}
void CBaseObject::DrawDefault(DisplayContext& dc, const QColor& labelColor)
@@ -903,314 +894,10 @@ void CBaseObject::DrawDefault(DisplayContext& dc, const QColor& labelColor)
}
//////////////////////////////////////////////////////////////////////////
void CBaseObject::DrawDimensions(DisplayContext& dc, AABB* pMergedBoundBox)
void CBaseObject::DrawDimensions(DisplayContext&, AABB*)
{
if (HasMeasurementAxis() && GetIEditor()->GetDisplaySettings()->IsDisplayDimensionFigures())
{
AABB localBoundBox;
GetLocalBounds(localBoundBox);
DrawDimensionsImpl(dc, localBoundBox, pMergedBoundBox);
}
}
//////////////////////////////////////////////////////////////////////////
void CBaseObject::DrawDimensionsImpl(DisplayContext& dc, const AABB& localBoundBox, AABB* pMergedBoundBox)
{
AABB boundBox;
Matrix34 rotatedTM;
bool bHave2Axis(false);
float xLength(0);
float yLength(0);
float zLength(0);
if (pMergedBoundBox)
{
rotatedTM = Matrix34::CreateIdentity();
boundBox = *pMergedBoundBox;
xLength = boundBox.max.x - boundBox.min.x;
zLength = boundBox.max.z - boundBox.min.z;
yLength = boundBox.max.y - boundBox.min.y;
}
else
{
rotatedTM = GetWorldRotTM();
Matrix34 scaledTranslatedTM = GetWorldScaleTM();
scaledTranslatedTM.SetTranslation(GetWorldPos());
boundBox.SetTransformedAABB(scaledTranslatedTM, localBoundBox);
IVariable* pVarXLength(NULL);
IVariable* pVarYLength(NULL);
IVariable* pVarZLength(NULL);
IVariable* pVarDimX(NULL);
IVariable* pVarDimY(NULL);
IVariable* pVarDimZ(NULL);
CVarBlock* pVarBlock(GetVarBlock());
if (pVarBlock)
{
pVarXLength = pVarBlock->FindVariable("Width");
pVarYLength = pVarBlock->FindVariable("Length");
pVarZLength = pVarBlock->FindVariable("Height");
pVarDimX = pVarBlock->FindVariable("DimX");
pVarDimY = pVarBlock->FindVariable("DimY");
pVarDimZ = pVarBlock->FindVariable("DimZ");
}
xLength = boundBox.max.x - boundBox.min.x;
zLength = boundBox.max.z - boundBox.min.z;
yLength = boundBox.max.y - boundBox.min.y;
if (pVarDimX && pVarDimY && pVarDimZ)
{
pVarDimX->Get(xLength);
pVarDimZ->Get(zLength);
pVarDimY->Get(yLength);
xLength *= m_scale.x;
zLength *= m_scale.z;
yLength *= m_scale.y;
}
else if (pVarXLength && pVarYLength && pVarZLength)
{
// A case of an area box.
pVarXLength->Get(xLength);
pVarZLength->Get(zLength);
pVarYLength->Get(yLength);
xLength *= m_scale.x;
zLength *= m_scale.z;
yLength *= m_scale.y;
}
else if (!pVarXLength && !pVarYLength && pVarZLength)
{
// A case of an area shape.
pVarZLength->Get(zLength);
zLength *= m_scale.z;
}
}
const float kMinimumLimitation(0.4f);
if (xLength < kMinimumLimitation && yLength < kMinimumLimitation && zLength < kMinimumLimitation)
{
return;
}
const float kEpsilon(0.001f);
bHave2Axis = fabs(zLength) < kEpsilon;
Vec3 basePoints[] = {
Vec3(boundBox.min.x, boundBox.min.y, boundBox.min.z),
Vec3(boundBox.min.x, boundBox.max.y, boundBox.min.z),
Vec3(boundBox.max.x, boundBox.max.y, boundBox.min.z),
Vec3(boundBox.max.x, boundBox.min.y, boundBox.min.z),
Vec3(boundBox.min.x, boundBox.min.y, boundBox.max.z),
Vec3(boundBox.min.x, boundBox.max.y, boundBox.max.z),
Vec3(boundBox.max.x, boundBox.max.y, boundBox.max.z),
Vec3(boundBox.max.x, boundBox.min.y, boundBox.max.z)
};
const int kElementSize(sizeof(basePoints) / sizeof(*basePoints));
Vec3 axisDirections[kElementSize] = { Vec3(1, 1, 1), Vec3(1, -1, 1), Vec3(-1, -1, 1), Vec3(-1, 1, 1), Vec3(1, 1, -1), Vec3(1, -1, -1), Vec3(-1, -1, -1), Vec3(-1, 1, -1) };
int nLoopCount = bHave2Axis ? (kElementSize / 2) : kElementSize;
if (bHave2Axis)
{
for (int i = 0; i < nLoopCount; ++i)
{
basePoints[i].z = 0.5f * (boundBox.min.z + boundBox.max.z);
}
}
// Find out the nearest base point of a bounding box from a camera position and use it as a pivot.
const CCamera& camera = gEnv->pRenderer->GetCamera();
Vec3 cameraPos(camera.GetPosition());
Vec3 pivot(rotatedTM.TransformVector(basePoints[0] - GetWorldPos()) + GetWorldPos());
float fNearestDist = (cameraPos - pivot).GetLength();
int nNearestAxisIndex(0);
bool bPrevVisible(camera.IsPointVisible(pivot));
for (int i = 1; i < nLoopCount; ++i)
{
Vec3 candidatePivot(rotatedTM.TransformVector(basePoints[i] - GetWorldPos()) + GetWorldPos());
float candidateLength = (candidatePivot - cameraPos).GetLength();
bool bVisible = camera.IsPointVisible(candidatePivot);
if (bVisible)
{
if (!bPrevVisible || candidateLength < fNearestDist)
{
fNearestDist = candidateLength;
pivot = candidatePivot;
nNearestAxisIndex = i;
}
bPrevVisible = bVisible;
}
}
float fScale = dc.view->GetScreenScaleFactor(pivot);
float fArrowScale = fScale * 0.04f;
Vec3 vX(xLength, 0, 0);
Vec3 vY(0, yLength, 0);
Vec3 vZ(0, 0, zLength);
vX = vX * axisDirections[nNearestAxisIndex].x;
vY = vY * axisDirections[nNearestAxisIndex].y;
vZ = vZ * axisDirections[nNearestAxisIndex].z;
vX = rotatedTM.TransformVector(vX);
vY = rotatedTM.TransformVector(vY);
vZ = rotatedTM.TransformVector(vZ);
const float kArrowPivotOffset = 0.1f;
pivot = pivot + (-(vX + vY + vZ)).GetNormalized() * kArrowPivotOffset;
Vec3 centerPt(boundBox.GetCenter());
// Display texts of width, height and depth
float fTextScale(1.3f);
dc.SetColor(QColor(200, 200, 200));
QString str;
const float kBrightness(0.35f);
const ColorF kXColor(1.0f, kBrightness, kBrightness, 0.9f);
const ColorF kYColor(kBrightness, 1.0f, kBrightness, 0.9f);
const ColorF kZColor(kBrightness, kBrightness, 1.0f, 0.9f);
const ColorF TextBoxColor(0, 0, 0, 0.75f);
ColorB backupcolor = dc.GetColor();
uint32 backupstate = dc.GetState();
int backupThickness = dc.GetLineWidth();
dc.SetState(backupstate | e_DepthTestOff);
Vec3 vNX = vX.GetNormalized();
Vec3 vNY = vY.GetNormalized();
Vec3 vNZ = vZ.GetNormalized();
const float kMinimumOffset(0.20f);
const float kMaximumOffset(30.0f);
float fMaximumOffset[3] = { kMaximumOffset, kMaximumOffset, kMaximumOffset };
if (xLength > kMaximumOffset * 0.5f)
{
fMaximumOffset[0] = xLength * 3.0f;
}
if (yLength > kMaximumOffset * 0.5f)
{
fMaximumOffset[1] = yLength * 3.0f;
}
if (zLength > kMaximumOffset * 0.5f)
{
fMaximumOffset[2] = zLength * 3.0f;
}
Vec3 textPos[3] = {pivot, pivot, pivot};
Vec3 textMinPos[3] = { pivot + vNX * kMinimumOffset, pivot + vNY * kMinimumOffset, pivot + vNZ * kMinimumOffset };
Vec3 textCenterPos[3] = { pivot + vX * 0.5f, pivot + vY * 0.5f, pivot + vZ * 0.5f };
Vec3 textMaxPos[3] = { pivot + vNX * fMaximumOffset[0], pivot + vNY * fMaximumOffset[1], pivot + vNZ * fMaximumOffset[2] };
const Vec3& cameraDir(camera.GetViewdir());
for (int i = 0; i < 3; ++i)
{
Vec3 d = (textMaxPos[i] - cameraPos).GetNormalized();
float fCameraDir = d.Dot(cameraDir);
if (fCameraDir < 0)
{
fCameraDir = 0;
}
textPos[i] = textMinPos[i] + (textCenterPos[i] - textPos[i]) * fCameraDir;
}
str = QString::number(xLength, 'f', 3);
DrawTextOn2DBox(dc, textPos[0], str.toUtf8().data(), fTextScale, kXColor, TextBoxColor);
if (!bHave2Axis)
{
str = QString::number(zLength, 'f', 3);
DrawTextOn2DBox(dc, textPos[2], str.toUtf8().data(), fTextScale, kZColor, TextBoxColor);
}
str = QString::number(yLength, 'f', 3);
DrawTextOn2DBox(dc, textPos[1], str.toUtf8().data(), fTextScale, kYColor, TextBoxColor);
dc.SetState(backupstate | e_DepthTestOn);
dc.SetLineWidth(4);
// Draw arrows of each axis.
dc.SetColor(kXColor);
dc.DrawArrow(pivot, pivot + vX, fArrowScale, true);
if (!bHave2Axis)
{
dc.SetColor(kZColor);
dc.DrawArrow(pivot, pivot + vZ, fArrowScale, true);
}
dc.SetColor(kYColor);
dc.DrawArrow(pivot, pivot + vY, fArrowScale, true);
dc.SetState(backupstate);
dc.SetColor(backupcolor);
dc.SetLineWidth(backupThickness);
}
//////////////////////////////////////////////////////////////////////////
void CBaseObject::DrawTextOn2DBox(DisplayContext& dc, const Vec3& pos, const char* text, float textScale, const ColorF& TextColor, const ColorF& TextBackColor)
{
Vec3 worldPos = dc.ToWorldSpacePosition(pos);
int vx, vy, vw, vh;
gEnv->pRenderer->GetViewport(&vx, &vy, &vw, &vh);
const CCamera& camera = gEnv->pRenderer->GetCamera();
Vec3 screenPos;
camera.Project(worldPos, screenPos, Vec2i(0, 0), Vec2i(0, 0));
//! Font size information doesn't seem to exist so the proper size is used
int textlen = strlen(text);
float fontsize = 7.5f;
float textwidth = fontsize * textlen;
float textheight = 16.0f;
screenPos.x = screenPos.x - textwidth * 0.5f;
Vec3 textregion[4] = {
Vec3(screenPos.x, screenPos.y, screenPos.z),
Vec3(screenPos.x + textwidth, screenPos.y, screenPos.z),
Vec3(screenPos.x + textwidth, screenPos.y + textheight, screenPos.z),
Vec3(screenPos.x, screenPos.y + textheight, screenPos.z)
};
Vec3 textworldreign[4];
Matrix34 dcInvTm = dc.GetMatrix().GetInverted();
Matrix44A mProj, mView;
mathMatrixPerspectiveFov(&mProj, camera.GetFov(), camera.GetProjRatio(), camera.GetNearPlane(), camera.GetFarPlane());
mathMatrixLookAt(&mView, camera.GetPosition(), camera.GetPosition() + camera.GetViewdir(), Vec3(0, 0, 1));
Matrix44A mInvViewProj = (mView * mProj).GetInverted();
for (int i = 0; i < 4; ++i)
{
Vec4 projectedpos = Vec4((textregion[i].x - vx) / vw * 2.0f - 1.0f,
-((textregion[i].y - vy) / vh) * 2.0f + 1.0f,
textregion[i].z,
1.0f);
Vec4 wp = projectedpos * mInvViewProj;
wp.x /= wp.w;
wp.y /= wp.w;
wp.z /= wp.w;
textworldreign[i] = dcInvTm.TransformPoint(Vec3(wp.x, wp.y, wp.z));
}
ColorB backupcolor = dc.GetColor();
uint32 backupstate = dc.GetState();
dc.SetColor(TextBackColor);
dc.SetDrawInFrontMode(true);
dc.DrawQuad(textworldreign[3], textworldreign[2], textworldreign[1], textworldreign[0]);
dc.SetColor(TextColor);
dc.DrawTextLabel(pos, textScale, text);
dc.SetDrawInFrontMode(false);
dc.SetColor(backupcolor);
dc.SetState(backupstate);
}
//////////////////////////////////////////////////////////////////////////
void CBaseObject::DrawSelectionHelper(DisplayContext& dc, const Vec3& pos, const QColor& labelColor, [[maybe_unused]] float alpha)
{
@@ -1581,12 +1268,6 @@ int CBaseObject::MouseCreateCallback(CViewport* view, EMouseEvent event, QPoint&
if (event == eMouseWheel)
{
double angle = 1;
if (view->GetViewManager()->GetGrid()->IsAngleSnapEnabled())
{
angle = view->GetViewManager()->GetGrid()->GetAngleSnap();
}
Quat rot = GetRotation();
rot.SetRotationXYZ(Ang3(0, 0, rot.GetRotZ() + DEG2RAD(flags > 0 ? angle * (-1) : angle)));
SetRotation(rot);
@@ -1838,11 +1519,6 @@ void CBaseObject::Serialize(CObjectArchive& ar)
SetFrozen(bFrozen);
SetHidden(bHidden);
//////////////////////////////////////////////////////////////////////////
// Load material.
//////////////////////////////////////////////////////////////////////////
SetMaterial(mtlName);
ar.SetResolveCallback(this, parentId, AZStd::bind(&CBaseObject::ResolveParent, this, AZStd::placeholders::_1 ));
ar.SetResolveCallback(this, lookatId, AZStd::bind(&CBaseObject::SetLookAt, this, AZStd::placeholders::_1));
@@ -1912,11 +1588,6 @@ void CBaseObject::Serialize(CObjectArchive& ar)
xmlNode->setAttr("Flags", flags);
}
if (m_pMaterial)
{
xmlNode->setAttr("Material", GetMaterialName().toUtf8().data());
}
if (m_nMinSpec != 0)
{
xmlNode->setAttr("MinSpec", (uint32)m_nMinSpec);
@@ -1937,11 +1608,6 @@ XmlNodeRef CBaseObject::Export([[maybe_unused]] const QString& levelPath, XmlNod
objNode->setAttr("Type", GetTypeName().toUtf8().data());
objNode->setAttr("Name", GetName().toUtf8().data());
if (m_pMaterial)
{
objNode->setAttr("Material", m_pMaterial->GetName().toUtf8().data());
}
Vec3 pos, scale;
Quat rotate;
if (m_parent)
@@ -2926,7 +2592,6 @@ bool CBaseObject::ConvertFromObject(CBaseObject* object)
{
object->GetParent()->AttachChild(this);
}
SetMaterial(object->GetMaterial());
return true;
}
@@ -2981,14 +2646,6 @@ void CBaseObject::Validate(IErrorReport* report)
report->ReportError(err);
}
//////////////////////////////////////////////////////////////////////////
if (GetMaterial() != NULL && GetMaterial()->IsDummy())
{
CErrorRecord err;
err.error = QStringLiteral("Material: %1 for object: %2 not found,").arg(GetMaterial()->GetName(), GetName());
err.pObject = this;
report->ReportError(err);
}
};
//////////////////////////////////////////////////////////////////////////
@@ -3055,10 +2712,6 @@ void CBaseObject::GatherUsedResources(CUsedResources& resources)
{
GetVarBlock()->GatherUsedResources(resources);
}
if (m_pMaterial)
{
m_pMaterial->GatherUsedResources(resources);
}
}
//////////////////////////////////////////////////////////////////////////
@@ -3071,50 +2724,6 @@ bool CBaseObject::IsSimilarObject(CBaseObject* pObject)
return false;
}
//////////////////////////////////////////////////////////////////////////
void CBaseObject::SetMaterial(CMaterial* mtl)
{
if (m_pMaterial == mtl)
{
return;
}
StoreUndo("Assign Material");
if (m_pMaterial)
{
m_pMaterial->Release();
}
m_pMaterial = mtl;
if (m_pMaterial)
{
m_pMaterial->AddRef();
}
OnMaterialChanged(MATERIALCHANGE_ALL);
}
//////////////////////////////////////////////////////////////////////////
QString CBaseObject::GetMaterialName() const
{
if (m_pMaterial)
{
return m_pMaterial->GetName();
}
return "";
}
//////////////////////////////////////////////////////////////////////////
void CBaseObject::SetMaterial(const QString& materialName)
{
CMaterial* pMaterial = NULL;
CMaterialManager* pManager = GetIEditor()->GetMaterialManager();
if (!materialName.isEmpty() && pManager != NULL)
{
pMaterial = pManager->LoadMaterial(materialName);
}
SetMaterial(pMaterial);
}
//////////////////////////////////////////////////////////////////////////
void CBaseObject::SetMinSpec(uint32 nSpec, bool bSetChildren)
{
-37
View File
@@ -35,8 +35,6 @@ class CUndoBaseObject;
class CObjectManager;
class CGizmo;
class CObjectArchive;
class CMaterial;
class CEdGeometry;
struct SSubObjSelectionModifyContext;
struct SRayHitInfo;
class ISubObjectSelectionReferenceFrameCalculator;
@@ -135,13 +133,6 @@ enum ObjectEditFlags
OBJECT_COLLAPSE_OBJECTPANEL = 0x004
};
///////////////////////////////////////////////////////////////////////////
enum MaterialChangeFlags
{
MATERIALCHANGE_SURFACETYPE = 0x001,
MATERIALCHANGE_ALL = 0xFFFFFFFF,
};
//////////////////////////////////////////////////////////////////////////
//! Return values from CBaseObject::MouseCreateCallback method.
enum MouseCreateResult
@@ -554,22 +545,6 @@ public:
//! Remove event listener callback.
void RemoveEventListener(EventListener* listener);
//////////////////////////////////////////////////////////////////////////
//! Material handling for this base object.
//! Override in derived classes.
//////////////////////////////////////////////////////////////////////////
//! Assign new material to this object.
virtual void SetMaterial(CMaterial* mtl);
//! Assign new material to this object as a material name.
virtual void SetMaterial(const QString& materialName);
//! Get assigned material for this object.
virtual CMaterial* GetMaterial() const { return m_pMaterial; };
// Get actual rendering material for this object.
virtual CMaterial* GetRenderMaterial() const { return m_pMaterial; };
// Get the material name. Even though the material pointer is null, the material name can exist separately.
virtual QString GetMaterialName() const;
virtual void OnMaterialChanged([[maybe_unused]] MaterialChangeFlags change) {}
//////////////////////////////////////////////////////////////////////////
//! Analyze errors for this object.
virtual void Validate(IErrorReport* report);
@@ -604,10 +579,6 @@ public:
virtual void ModifySubObjSelection([[maybe_unused]] SSubObjSelectionModifyContext& modCtx) {};
virtual void AcceptSubObjectModify() {};
// Request a geometry pointer from the object.
// Return NULL if geometry can not be retrieved or object does not support geometries.
virtual CEdGeometry* GetGeometry() { return 0; };
//! In This function variables of the object must be initialized.
virtual void InitVariables() {};
@@ -633,9 +604,6 @@ public:
virtual IStatObj* GetIStatObj() { return NULL; }
//! Display length of each axis.
void DrawDimensionsImpl(DisplayContext& dc, const AABB& localBoundBox, AABB* pMergedBoundBox = NULL);
// Invalidates cached transformation matrix.
// nWhyFlags - Flags that indicate the reason for matrix invalidation.
virtual void InvalidateTM(int nWhyFlags);
@@ -707,8 +675,6 @@ protected:
virtual void DrawTextureIcon(DisplayContext& dc, const Vec3& pos, float alpha = 1.0f);
//! Draw warning icons
virtual void DrawWarningIcons(DisplayContext& dc, const Vec3& pos);
//! Display text with a 3d world coordinate.
void DrawTextOn2DBox(DisplayContext& dc, const Vec3& pos, const char* text, float textScale, const ColorF& TextColor, const ColorF& TextBackColor);
//! Check if dimension's figures can be displayed before draw them.
virtual void DrawDimensions(DisplayContext& dc, AABB* pMergedBoundBox = NULL);
@@ -861,9 +827,6 @@ private:
//! Pointer to parent node.
mutable CBaseObject* m_parent;
//! Material of this object.
CMaterial* m_pMaterial;
AABB m_worldBounds;
// The transform delegate
@@ -33,7 +33,6 @@ struct IDisplayViewport;
struct IRenderer;
struct IRenderAuxGeom;
struct IIconManager;
struct I3DEngine;
class CDisplaySettings;
class CCamera;
@@ -70,7 +69,6 @@ struct SANDBOX_API DisplayContext
IRenderer* renderer;
IRenderAuxGeom* pRenderAuxGeom;
IIconManager* pIconManager;
I3DEngine* engine;
CCamera* camera;
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
AABB box; // Bounding box of volume that need to be repainted.
@@ -229,7 +227,6 @@ struct SANDBOX_API DisplayContext
void DrawTextLabel(const Vec3& pos, float size, const char* text, const bool bCenter = false, int srcOffsetX = 0, int scrOffsetY = 0);
void Draw2dTextLabel(float x, float y, float size, const char* text, bool bCenter = false);
void DrawTextOn2DBox(const Vec3& pos, const char* text, float textScale, const ColorF& TextColor, const ColorF& TextBackColor);
void SetLineWidth(float width);
//! Is given bbox visible in this display context.
@@ -18,8 +18,6 @@
#include "Include/IIconManager.h"
#include "Include/IDisplayViewport.h"
#include <I3DEngine.h>
#include <QDateTime>
#include <QPoint>
@@ -32,7 +30,6 @@ DisplayContext::DisplayContext()
{
view = 0;
renderer = 0;
engine = 0;
flags = 0;
settings = 0;
pIconManager = 0;
@@ -40,7 +37,7 @@ DisplayContext::DisplayContext()
m_currentMatrix = 0;
m_matrixStack[m_currentMatrix].SetIdentity();
pRenderAuxGeom = gEnv->pRenderer ? gEnv->pRenderer->GetIRenderAuxGeom() : nullptr;
pRenderAuxGeom = nullptr; // ToDo: Remove DisplayContext or update to work with Atom: LYN-3670
m_thickness = 0;
m_width = 0;
@@ -981,27 +978,8 @@ void DisplayContext::RenderObject(int objectType, const Vec3& pos, float scale)
}
//////////////////////////////////////////////////////////////////////////
void DisplayContext::RenderObject(int objectType, const Matrix34& tm)
void DisplayContext::RenderObject(int, const Matrix34&)
{
IStatObj* object = pIconManager ? pIconManager->GetObject((EStatObject)objectType) : 0;
if (object)
{
float color[4];
color[0] = m_color4b.r * (1.0f / 255.0f);
color[1] = m_color4b.g * (1.0f / 255.0f);
color[2] = m_color4b.b * (1.0f / 255.0f);
color[3] = m_color4b.a * (1.0f / 255.0f);
SRenderingPassInfo passInfo = SRenderingPassInfo::CreateGeneralPassRenderingInfo(GetIEditor()->GetSystem()->GetViewCamera());
Matrix34 xform = m_matrixStack[m_currentMatrix] * tm;
SRendParams rp;
rp.pMatrix = &xform;
rp.AmbientColor = ColorF(color[0], color[1], color[2], 1);
rp.fAlpha = color[3];
object->Render(rp, passInfo);
}
}
/////////////////////////////////////////////////////////////////////////
@@ -1127,85 +1105,6 @@ void DisplayContext::Draw2dTextLabel(float x, float y, float size, const char* t
renderer->Draw2dLabel(x, y, size, col, bCenter, "%s", text);
}
void DisplayContext::DrawTextOn2DBox(const Vec3& pos, const char* text, float textScale, const ColorF& TextColor, const ColorF& TextBackColor)
{
Vec3 worldPos = ToWorldSpacePosition(pos);
int vx, vy, vw, vh;
gEnv->pRenderer->GetViewport(&vx, &vy, &vw, &vh);
uint32 backupstate = GetState();
SetState(backupstate | e_DepthTestOff);
const CCamera& renderCamera = gEnv->pRenderer->GetCamera();
Vec3 screenPos;
renderCamera.Project(worldPos, screenPos, Vec2i(0, 0), Vec2i(0, 0));
//! Font size information doesn't seem to exist so the proper size is used
int textlen = strlen(text);
float fontsize = 7.5f * textScale;
float textwidth = fontsize * textlen;
float textheight = 16.0f * textScale;
screenPos.x = screenPos.x - (textwidth * 0.5f);
Vec3 textregion[4] = {
Vec3(screenPos.x, screenPos.y, screenPos.z),
Vec3(screenPos.x + textwidth, screenPos.y, screenPos.z),
Vec3(screenPos.x + textwidth, screenPos.y + textheight, screenPos.z),
Vec3(screenPos.x, screenPos.y + textheight, screenPos.z)
};
Vec3 textworldreign[4];
Matrix34 dcInvTm = GetMatrix().GetInverted();
Matrix44A mProj, mView;
mathMatrixPerspectiveFov(&mProj, renderCamera.GetFov(), renderCamera.GetProjRatio(), renderCamera.GetNearPlane(), renderCamera.GetFarPlane());
mathMatrixLookAt(&mView, renderCamera.GetPosition(), renderCamera.GetPosition() + renderCamera.GetViewdir(), Vec3(0, 0, 1));
Matrix44A mInvViewProj = (mView * mProj).GetInverted();
if (vw == 0)
{
vw = 1;
}
if (vh == 0)
{
vh = 1;
}
for (int i = 0; i < 4; ++i)
{
Vec4 projectedpos = Vec4((textregion[i].x - vx) / vw * 2.0f - 1.0f,
-((textregion[i].y - vy) / vh) * 2.0f + 1.0f,
textregion[i].z,
1.0f);
Vec4 wp = projectedpos * mInvViewProj;
if (wp.w == 0.0f)
{
wp.w = 0.0001f;
}
wp.x /= wp.w;
wp.y /= wp.w;
wp.z /= wp.w;
textworldreign[i] = dcInvTm.TransformPoint(Vec3(wp.x, wp.y, wp.z));
}
ColorB backupcolor = GetColor();
SetColor(TextBackColor);
SetDrawInFrontMode(true);
DrawQuad(textworldreign[3], textworldreign[2], textworldreign[1], textworldreign[0]);
SetColor(TextColor);
DrawTextLabel(pos, textScale, text);
SetDrawInFrontMode(false);
SetColor(backupcolor);
SetState(backupstate);
}
//////////////////////////////////////////////////////////////////////////
void DisplayContext::SetLineWidth(float width)
{
+2 -231
View File
@@ -25,21 +25,15 @@
#include "Settings.h"
#include "Viewport.h"
#include "LineGizmo.h"
#include "Material/MaterialManager.h"
#include "Include/IObjectManager.h"
#include "Objects/ObjectManager.h"
#include "ViewManager.h"
#include "LensFlareEditor/LensFlareManager.h"
#include "LensFlareEditor/LensFlareUtil.h"
#include "LensFlareEditor/LensFlareLibrary.h"
#include "AnimationContext.h"
#include "HitContext.h"
#include "Objects/SelectionGroup.h"
const char* CEntityObject::s_LensFlarePropertyName("flare_Flare");
const char* CEntityObject::s_LensFlareMaterialName("EngineAssets/Materials/lens_optics");
#include <IEntityRenderState.h>
#include <IStatObj.h>
//////////////////////////////////////////////////////////////////////////
//! Undo Entity Link
@@ -1084,11 +1078,6 @@ XmlNodeRef CEntityObject::Export([[maybe_unused]] const QString& levelPath, XmlN
objNode->setAttr("Name", GetName().toUtf8().data());
if (GetMaterial())
{
objNode->setAttr("Material", GetMaterial()->GetName().toUtf8().data());
}
Vec3 pos = GetPos(), scale = GetScale();
Quat rotate = GetRotation();
@@ -1867,17 +1856,6 @@ void CEntityObject::OnLoadFailed()
GetIEditor()->GetErrorReport()->ReportError(err);
}
//////////////////////////////////////////////////////////////////////////
CMaterial* CEntityObject::GetRenderMaterial() const
{
if (GetMaterial())
{
return GetMaterial();
}
return NULL;
}
//////////////////////////////////////////////////////////////////////////
void CEntityObject::SetHelperScale(float scale)
{
@@ -1950,157 +1928,6 @@ void CEntityObject::OnContextMenu(QMenu* pMenu)
CBaseObject::OnContextMenu(pMenu);
}
//////////////////////////////////////////////////////////////////////////
void CEntityObject::OnMaterialChanged(MaterialChangeFlags change)
{
if (change & MATERIALCHANGE_SURFACETYPE)
{
m_statObjValidator.Validate(0, GetRenderMaterial());
}
}
//////////////////////////////////////////////////////////////////////////
QString CEntityObject::GetTooltip() const
{
return m_statObjValidator.GetDescription();
}
//////////////////////////////////////////////////////////////////////////
IOpticsElementBasePtr CEntityObject::GetOpticsElement()
{
CDLight* pLight = GetLightProperty();
if (pLight == NULL)
{
return NULL;
}
return pLight->GetLensOpticsElement();
}
//////////////////////////////////////////////////////////////////////////
void CEntityObject::SetOpticsElement(IOpticsElementBase* pOptics)
{
CDLight* pLight = GetLightProperty();
if (pLight == NULL)
{
return;
}
pLight->SetLensOpticsElement(pOptics);
if (GetEntityPropertyBool("bFlareEnable") && pOptics)
{
CBaseObject::SetMaterial(s_LensFlareMaterialName);
}
else
{
SetMaterial(NULL);
}
}
//////////////////////////////////////////////////////////////////////////
void CEntityObject::ApplyOptics(const QString& opticsFullName, IOpticsElementBasePtr pOptics)
{
if (pOptics == NULL)
{
CDLight* pLight = GetLightProperty();
if (pLight)
{
pLight->SetLensOpticsElement(NULL);
}
SetFlareName("");
SetMaterial(NULL);
}
else
{
int nOpticsIndex(0);
if (!gEnv->pOpticsManager->Load(opticsFullName.toUtf8().data(), nOpticsIndex))
{
IOpticsElementBasePtr pNewOptics = gEnv->pOpticsManager->Create(eFT_Root);
if (!gEnv->pOpticsManager->AddOptics(pNewOptics, opticsFullName.toUtf8().data(), nOpticsIndex))
{
CDLight* pLight = GetLightProperty();
if (pLight)
{
pLight->SetLensOpticsElement(NULL);
SetMaterial(NULL);
}
return;
}
LensFlareUtil::CopyOptics(pOptics, pNewOptics);
}
SetFlareName(opticsFullName);
}
}
//////////////////////////////////////////////////////////////////////////
void CEntityObject::SetOpticsName(const QString& opticsFullName)
{
if (opticsFullName.isEmpty())
{
CDLight* pLight = GetLightProperty();
if (pLight)
{
pLight->SetLensOpticsElement(NULL);
}
SetFlareName("");
SetMaterial(NULL);
}
else
{
if (GetOpticsElement())
{
if (gEnv->pOpticsManager->Rename(GetOpticsElement()->GetName(), opticsFullName.toUtf8().data()))
{
SetFlareName(opticsFullName);
}
}
}
}
//////////////////////////////////////////////////////////////////////////
CDLight* CEntityObject::GetLightProperty() const
{
const PodArray<ILightSource*>* pLightEntities = GetIEditor()->Get3DEngine()->GetLightEntities();
if (pLightEntities == NULL)
{
return NULL;
}
for (int i = 0, iLightSize(pLightEntities->Count()); i < iLightSize; ++i)
{
ILightSource* pLightSource = pLightEntities->GetAt(i);
if (pLightSource == NULL)
{
continue;
}
CDLight& lightProperty = pLightSource->GetLightProperties();
if (GetName() != lightProperty.m_sName)
{
continue;
}
return &lightProperty;
}
return NULL;
}
//////////////////////////////////////////////////////////////////////////
bool CEntityObject::GetValidFlareName(QString& outFlareName) const
{
IVariable* pFlareVar(m_pProperties->FindVariable(s_LensFlarePropertyName));
if (!pFlareVar)
{
return false;
}
QString flareName;
pFlareVar->Get(flareName);
if (flareName.isEmpty() || flareName == "@root")
{
return false;
}
outFlareName = flareName;
return true;
}
//////////////////////////////////////////////////////////////////////////
void CEntityObject::PreInitLightProperty()
{
@@ -2108,42 +1935,6 @@ void CEntityObject::PreInitLightProperty()
{
return;
}
QString flareFullName;
if (GetValidFlareName(flareFullName))
{
bool bEnableOptics = GetEntityPropertyBool("bFlareEnable");
if (bEnableOptics)
{
CLensFlareManager* pLensManager = GetIEditor()->GetLensFlareManager();
CLensFlareLibrary* pLevelLib = (CLensFlareLibrary*)pLensManager->GetLevelLibrary();
IOpticsElementBasePtr pLevelOptics = pLevelLib->GetOpticsOfItem(flareFullName.toUtf8().data());
if (pLevelLib && pLevelOptics)
{
int nOpticsIndex(0);
IOpticsElementBasePtr pNewOptics = GetOpticsElement();
if (pNewOptics == NULL)
{
pNewOptics = gEnv->pOpticsManager->Create(eFT_Root);
}
if (gEnv->pOpticsManager->AddOptics(pNewOptics, flareFullName.toUtf8().data(), nOpticsIndex))
{
LensFlareUtil::CopyOptics(pLevelOptics, pNewOptics);
SetOpticsElement(pNewOptics);
}
else
{
CDLight* pLight = GetLightProperty();
if (pLight)
{
pLight->SetLensOpticsElement(NULL);
SetMaterial(NULL);
}
}
}
}
}
}
//////////////////////////////////////////////////////////////////////////
@@ -2153,26 +1944,6 @@ void CEntityObject::UpdateLightProperty()
{
return;
}
QString flareName;
if (GetValidFlareName(flareName))
{
IOpticsElementBasePtr pOptics = GetOpticsElement();
if (pOptics == NULL)
{
pOptics = gEnv->pOpticsManager->Create(eFT_Root);
}
bool bEnableOptics = GetEntityPropertyBool("bFlareEnable");
if (bEnableOptics && GetIEditor()->GetLensFlareManager()->LoadFlareItemByName(flareName, pOptics))
{
pOptics->SetName(flareName.toUtf8().data());
SetOpticsElement(pOptics);
}
else
{
SetOpticsElement(NULL);
}
}
}
//////////////////////////////////////////////////////////////////////////
@@ -21,7 +21,6 @@
#include "IMovieSystem.h"
#include "IEntityObjectListener.h"
#include "StatObjValidator.h"
#include "Gizmo.h"
#include "CryListenerSet.h"
#include "StatObjBus.h"
@@ -36,7 +35,6 @@
class CEntityObject;
class QMenu;
class IOpticsElementBase;
/*!
* CEntityEventTarget is an Entity event target and type.
@@ -108,8 +106,6 @@ public:
void SetEntityPropertyFloat(const char* name, float value);
void SetEntityPropertyString(const char* name, const QString& value);
virtual QString GetTooltip() const;
virtual int MouseCreateCallback(CViewport* view, EMouseEvent event, QPoint& point, int flags);
virtual void OnContextMenu(QMenu* menu);
@@ -134,9 +130,6 @@ public:
virtual void SetTransformDelegate(ITransformDelegate* pTransformDelegate) override;
virtual CMaterial* GetRenderMaterial() const;
virtual void OnMaterialChanged(MaterialChangeFlags change);
// Set attach flags and target
enum EAttachmentType
{
@@ -220,11 +213,6 @@ public:
QString GetLightAnimation() const;
IVariable* GetLightVariable(const char* name) const;
IOpticsElementBasePtr GetOpticsElement();
void SetOpticsElement(IOpticsElementBase* pOptics);
void ApplyOptics(const QString& opticsFullName, IOpticsElementBasePtr pOptics);
void SetOpticsName(const QString& opticsFullName);
bool GetValidFlareName(QString& outFlareName) const;
void PreInitLightProperty();
void UpdateLightProperty();
@@ -236,14 +224,9 @@ public:
static void StoreUndoEntityLink(CSelectionGroup* pGroup);
static const char* s_LensFlarePropertyName;
static const char* s_LensFlareMaterialName;
void RegisterListener(IEntityObjectListener* pListener);
void UnregisterListener(IEntityObjectListener* pListener);
CDLight* GetLightProperty() const;
protected:
template <typename T>
void SetEntityProperty(const char* name, T value);
@@ -322,11 +305,6 @@ protected:
void AdjustLightProperties(CVarBlockPtr& properties, const char* pSubBlock);
IVariable* FindVariableInSubBlock(CVarBlockPtr& properties, IVariable* pSubBlockVar, const char* pVarName);
void SetFlareName(const QString& name)
{
SetEntityPropertyString(s_LensFlarePropertyName, name);
}
unsigned int m_bLoadFailed : 1;
unsigned int m_bCalcPhysics : 1;
unsigned int m_bDisplayBBox : 1;
@@ -416,8 +394,6 @@ protected:
static float m_helperScale;
CStatObjValidator m_statObjValidator;
EAttachmentType m_attachmentType;
bool m_bEnableReload;
@@ -17,7 +17,6 @@
// Editor
#include "Util/PakFile.h"
#include "Material/MaterialManager.h"
#include "WaitProgress.h"
#include "Include/IObjectManager.h"
@@ -239,14 +238,6 @@ void CObjectArchive::ResolveObjects()
obj.pObject->CreateGameObject();
CMaterial* pMaterial = obj.pObject->GetRenderMaterial();
CMaterialManager* pManager = GetIEditor()->GetMaterialManager();
if (pMaterial && pMaterial->GetMatInfo() && pManager)
{
pManager->OnRequestMaterial(pMaterial->GetMatInfo());
}
// unset the current validator object because the wait Step
// might generate unrelated errors
m_pCurrentErrorReport->SetCurrentValidatorObject(nullptr);
+2 -41
View File
@@ -25,7 +25,6 @@
#include "Viewport.h"
#include "GizmoManager.h"
#include "AxisGizmo.h"
#include "ObjectPhysicsManager.h"
#include "GameEngine.h"
#include "WaitProgress.h"
#include "Util/Image.h"
@@ -109,7 +108,6 @@ CObjectManager::CObjectManager()
, m_pLoadProgress(nullptr)
, m_loadedObjects(0)
, m_totalObjectsToLoad(0)
, m_pPhysicsManager(new CObjectPhysicsManager())
, m_bExiting(false)
, m_isUpdateVisibilityList(false)
, m_currentHideCount(CBaseObject::s_invalidHiddenID)
@@ -138,7 +136,6 @@ CObjectManager::~CObjectManager()
DeleteAllObjects();
delete m_gizmoManager;
delete m_pPhysicsManager;
}
//////////////////////////////////////////////////////////////////////////
@@ -403,8 +400,6 @@ void CObjectManager::DeleteObject(CBaseObject* obj)
CUndo::Record(new CUndoBaseObjectDelete(obj));
}
OnObjectModified(obj, true, false);
AABB objAAB;
obj->GetBoundBox(objAAB);
GetIEditor()->GetGameEngine()->OnAreaModified(objAAB);
@@ -841,8 +836,6 @@ void CObjectManager::Update()
{
prevActiveWindow->setFocus();
}
m_pPhysicsManager->Update();
}
//////////////////////////////////////////////////////////////////////////
@@ -1319,7 +1312,7 @@ void CObjectManager::ForceUpdateVisibleObjectCache(DisplayContext& dc)
FindDisplayableObjects(dc, false);
}
void CObjectManager::FindDisplayableObjects(DisplayContext& dc, bool bDisplay)
void CObjectManager::FindDisplayableObjects(DisplayContext& dc, [[maybe_unused]] bool bDisplay)
{
// if the new IVisibilitySystem is being used, do not run this logic
if (ed_visibility_use)
@@ -1346,8 +1339,6 @@ void CObjectManager::FindDisplayableObjects(DisplayContext& dc, bool bDisplay)
pDispayedViewObjects->ClearObjects();
pDispayedViewObjects->Reserve(m_visibleObjects.size());
const bool newViewportInteractionModelEnabled = GetIEditor()->IsNewViewportInteractionModelEnabled();
if (dc.flags & DISPLAY_2D)
{
int numVis = m_visibleObjects.size();
@@ -1359,14 +1350,6 @@ void CObjectManager::FindDisplayableObjects(DisplayContext& dc, bool bDisplay)
if (dc.box.IsIntersectBox(bbox))
{
pDispayedViewObjects->AddObject(obj);
if (bDisplay && dc.settings->IsDisplayHelpers() && (gSettings.viewports.nShowFrozenHelpers || !obj->IsFrozen()))
{
if (!newViewportInteractionModelEnabled)
{
obj->Display(dc);
}
}
}
}
}
@@ -1404,14 +1387,6 @@ void CObjectManager::FindDisplayableObjects(DisplayContext& dc, bool bDisplay)
if (visRatio > m_maxObjectViewDistRatio || (dc.flags & DISPLAY_SELECTION_HELPERS) || obj->IsSelected())
{
pDispayedViewObjects->AddObject(obj);
if (bDisplay && dc.settings->IsDisplayHelpers() && (gSettings.viewports.nShowFrozenHelpers || !obj->IsFrozen()) && !obj->CheckFlags(OBJFLAG_HIDE_HELPERS))
{
if (!newViewportInteractionModelEnabled)
{
obj->Display(dc);
}
}
}
}
}
@@ -2361,10 +2336,7 @@ void CObjectManager::UpdateVisibilityList()
// in the view (frustum) to the visible objects list so we can draw feedback for
// entities being hidden in the viewport when selected in the entity outliner
// (EditorVisibleEntityDataCache must be populated even if entities are 'hidden')
if (visible || GetIEditor()->IsNewViewportInteractionModelEnabled())
{
m_visibleObjects.push_back(obj);
}
m_visibleObjects.push_back(obj);
}
m_isUpdateVisibilityList = false;
@@ -2503,17 +2475,6 @@ IGizmoManager* CObjectManager::GetGizmoManager()
return m_gizmoManager;
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
void CObjectManager::OnObjectModified(CBaseObject* pObject, [[maybe_unused]] bool bDelete, [[maybe_unused]] bool boModifiedTransformOnly)
{
if (IRenderNode* pRenderNode = pObject->GetEngineNode())
{
GetIEditor()->Get3DEngine()->OnObjectModified(pRenderNode, pRenderNode->GetRndFlags());
}
}
//////////////////////////////////////////////////////////////////////////
bool CObjectManager::IsLightClass(CBaseObject* pObject)
{
@@ -326,17 +326,11 @@ public:
// Gathers all resources used by all objects.
void GatherUsedResources(CUsedResources& resources);
// Called when object gets modified.
void OnObjectModified(CBaseObject* pObject, bool bDelete, bool boModifiedTransformOnly);
virtual bool IsLightClass(CBaseObject* pObject);
virtual void FindAndRenameProperty2(const char* property2Name, const QString& oldValue, const QString& newValue);
virtual void FindAndRenameProperty2If(const char* property2Name, const QString& oldValue, const QString& newValue, const char* otherProperty2Name, const QString& otherValue);
class CObjectPhysicsManager* GetPhysicsManager()
{ return m_pPhysicsManager; }
bool IsReloading() const { return m_bInReloading; }
void SetSkipUpdate(bool bSkipUpdate) override { m_bSkipObjectUpdate = bSkipUpdate; }
@@ -433,8 +427,6 @@ private:
int m_totalObjectsToLoad;
//////////////////////////////////////////////////////////////////////////
class CObjectPhysicsManager* m_pPhysicsManager;
//////////////////////////////////////////////////////////////////////////
// Numbering for names.
//////////////////////////////////////////////////////////////////////////
@@ -1,191 +0,0 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "EditorDefs.h"
#include "ObjectPhysicsManager.h"
// Editor
#include "GameEngine.h"
#include "Commands/CommandManager.h"
#include "Objects/SelectionGroup.h"
#include "Include/IObjectManager.h"
#include "CryPhysicsDeprecation.h"
#define MAX_OBJECTS_PHYS_SIMULATION_TIME (5)
//////////////////////////////////////////////////////////////////////////
CObjectPhysicsManager::CObjectPhysicsManager()
{
CommandManagerHelper::RegisterCommand(GetIEditor()->GetCommandManager(),
"physics", "simulate_objects", "", "",
AZStd::bind(&CObjectPhysicsManager::Command_SimulateObjects, this));
CommandManagerHelper::RegisterCommand(GetIEditor()->GetCommandManager(),
"physics", "reset_objects_state", "", "",
AZStd::bind(&CObjectPhysicsManager::Command_ResetPhysicsState, this));
CommandManagerHelper::RegisterCommand(GetIEditor()->GetCommandManager(),
"physics", "get_objects_state", "", "",
AZStd::bind(&CObjectPhysicsManager::Command_GetPhysicsState, this));
m_fStartObjectSimulationTime = 0;
m_bSimulatingObjects = false;
m_wasSimObjects = 0;
}
//////////////////////////////////////////////////////////////////////////
CObjectPhysicsManager::~CObjectPhysicsManager()
{
}
//////////////////////////////////////////////////////////////////////////
void CObjectPhysicsManager::Command_SimulateObjects()
{
SimulateSelectedObjectsPositions();
}
/////////////////////////////////////////////////////////////////////////
void CObjectPhysicsManager::Command_ResetPhysicsState()
{
CSelectionGroup* pSelection = GetIEditor()->GetSelection();
for (int i = 0; i < pSelection->GetCount(); i++)
{
pSelection->GetObject(i)->OnEvent(EVENT_PHYSICS_RESETSTATE);
}
}
/////////////////////////////////////////////////////////////////////////
void CObjectPhysicsManager::Command_GetPhysicsState()
{
CSelectionGroup* pSelection = GetIEditor()->GetSelection();
for (int i = 0; i < pSelection->GetCount(); i++)
{
pSelection->GetObject(i)->OnEvent(EVENT_PHYSICS_GETSTATE);
}
}
//////////////////////////////////////////////////////////////////////////
void CObjectPhysicsManager::Update()
{
if (m_bSimulatingObjects)
{
UpdateSimulatingObjects();
}
}
//////////////////////////////////////////////////////////////////////////
void CObjectPhysicsManager::SimulateSelectedObjectsPositions()
{
CSelectionGroup* pSel = GetIEditor()->GetObjectManager()->GetSelection();
if (pSel->IsEmpty())
{
return;
}
if (GetIEditor()->GetGameEngine()->GetSimulationMode())
{
return;
}
GetIEditor()->GetGameEngine()->SetSimulationMode(true, true);
m_simObjects.clear();
CRY_PHYSICS_REPLACEMENT_ASSERT();
m_wasSimObjects = m_simObjects.size();
m_fStartObjectSimulationTime = GetISystem()->GetITimer()->GetAsyncCurTime();
m_bSimulatingObjects = true;
}
//////////////////////////////////////////////////////////////////////////
void CObjectPhysicsManager::UpdateSimulatingObjects()
{
{
CUndo undo("Simulate");
CRY_PHYSICS_REPLACEMENT_ASSERT();
}
float curTime = GetISystem()->GetITimer()->GetAsyncCurTime();
float runningTime = (curTime - m_fStartObjectSimulationTime);
if (m_simObjects.empty() || (runningTime > MAX_OBJECTS_PHYS_SIMULATION_TIME))
{
m_fStartObjectSimulationTime = 0;
m_bSimulatingObjects = false;
GetIEditor()->GetGameEngine()->SetSimulationMode(false, true);
}
}
//////////////////////////////////////////////////////////////////////////
void CObjectPhysicsManager::PrepareForExport()
{
// Clear the collision class set, ready for objects to register
// their collision classes
m_collisionClasses.clear();
m_collisionClassExportId = 0;
// First collision-class IS always the default one
RegisterCollisionClass(SCollisionClass(0, 0));
}
//////////////////////////////////////////////////////////////////////////
bool operator == (const SCollisionClass& lhs, const SCollisionClass& rhs)
{
return lhs.type == rhs.type && lhs.ignore == rhs.ignore;
}
//////////////////////////////////////////////////////////////////////////
int CObjectPhysicsManager::RegisterCollisionClass(const SCollisionClass& collclass)
{
TCollisionClassVector::iterator it = std::find(m_collisionClasses.begin(), m_collisionClasses.end(), collclass);
if (it == m_collisionClasses.end())
{
m_collisionClasses.push_back(collclass);
return m_collisionClasses.size() - 1;
}
return it - m_collisionClasses.begin();
}
//////////////////////////////////////////////////////////////////////////
int CObjectPhysicsManager::GetCollisionClassId(const SCollisionClass& collclass)
{
TCollisionClassVector::iterator it = std::find(m_collisionClasses.begin(), m_collisionClasses.end(), collclass);
if (it == m_collisionClasses.end())
{
return 0;
}
return it - m_collisionClasses.begin();
}
//////////////////////////////////////////////////////////////////////////
void CObjectPhysicsManager::SerializeCollisionClasses(CXmlArchive& xmlAr)
{
if (!xmlAr.bLoading)
{
// Storing
CLogFile::WriteLine("Storing Collision Classes ...");
XmlNodeRef root = xmlAr.root->newChild("CollisionClasses");
int count = m_collisionClasses.size();
for (int i = 0; i < count; i++)
{
SCollisionClass& cc = m_collisionClasses[i];
XmlNodeRef xmlCC = root->newChild("CollisionClass");
xmlCC->setAttr("type", cc.type);
xmlCC->setAttr("ignore", cc.ignore);
}
}
}
@@ -1,56 +0,0 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_EDITOR_OBJECTS_OBJECTPHYSICSMANAGER_H
#define CRYINCLUDE_EDITOR_OBJECTS_OBJECTPHYSICSMANAGER_H
#pragma once
//////////////////////////////////////////////////////////////////////////
class CObjectPhysicsManager
{
public:
CObjectPhysicsManager();
~CObjectPhysicsManager();
void SimulateSelectedObjectsPositions();
void Update();
//////////////////////////////////////////////////////////////////////////
/// Collision Classes
//////////////////////////////////////////////////////////////////////////
int RegisterCollisionClass(const SCollisionClass& collclass);
int GetCollisionClassId(const SCollisionClass& collclass);
void SerializeCollisionClasses(CXmlArchive& xmlAr);
void PrepareForExport();
private:
void Command_SimulateObjects();
void Command_GetPhysicsState();
void Command_ResetPhysicsState();
void UpdateSimulatingObjects();
bool m_bSimulatingObjects;
float m_fStartObjectSimulationTime;
int m_wasSimObjects;
std::vector<_smart_ptr<CBaseObject> > m_simObjects;
typedef std::vector<SCollisionClass> TCollisionClassVector;
int m_collisionClassExportId;
TCollisionClassVector m_collisionClasses;
};
#endif // CRYINCLUDE_EDITOR_OBJECTS_OBJECTPHYSICSMANAGER_H
+4 -12
View File
@@ -20,8 +20,9 @@
// Editor
#include "ViewManager.h"
#include "SurfaceInfoPicker.h"
#include "Include/IObjectManager.h"
#include <IStatObj.h>
//////////////////////////////////////////////////////////////////////////
CSelectionGroup::CSelectionGroup()
@@ -238,16 +239,6 @@ void CSelectionGroup::Move(const Vec3& offset, EMoveSelectionFlag moveFlag, [[ma
}
SRayHitInfo pickedInfo;
if (moveFlag == eMS_FollowGeometryPosNorm && bValidFollowGeometryMode)
{
CSurfaceInfoPicker::CExcludedObjects excludeObjects;
for (int i = 0; i < GetFilteredCount(); ++i)
{
excludeObjects.Add(GetFilteredObject(i));
}
CSurfaceInfoPicker surfacePicker;
bValidFollowGeometryMode = surfacePicker.Pick(point, pickedInfo, &excludeObjects);
}
if (moveFlag == eMS_FollowGeometryPosNorm)
{
@@ -351,7 +342,8 @@ void CSelectionGroup::Rotate(const Matrix34& rotateTM, int referenceCoordSys)
if (referenceCoordSys == COORDS_USERDEFINED)
{
Matrix34 userTM = GetIEditor()->GetViewManager()->GetGrid()->GetMatrix();
Matrix34 userTM;
userTM.SetIdentity();
Matrix34 invUserTM = userTM.GetInvertedFast();
ToOrigin = invUserTM * ToOrigin;
@@ -1,200 +0,0 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "EditorDefs.h"
#include "StatObjValidator.h"
// Editor
#include "Material/Material.h"
CStatObjValidator::CStatObjValidator()
: m_isValid(true)
{
}
template<size_t size>
bool HasPrefix(const char* name, const char (&prefix)[size])
{
return _strnicmp(name, prefix, size - 1) == 0;
}
struct SMeshMaterialIssue
{
AZStd::string nodeName;
AZStd::string description;
int subMaterialIndex;
SMeshMaterialIssue()
: subMaterialIndex(-1)
{
}
SMeshMaterialIssue(const AZStd::string& name, const AZStd::string& description)
: nodeName(name)
, description(description)
, subMaterialIndex(-1)
{
}
};
static void ValidateMeshMaterials(std::vector<SMeshMaterialIssue>* issues, IStatObj* pStatObj, CMaterial* pMaterial)
{
_smart_ptr<IMaterial> pIMaterial = 0;
if (pMaterial)
{
if (pMaterial->GetParent())
{
pIMaterial = pMaterial->GetParent()->GetMatInfo();
}
else
{
pIMaterial = pMaterial->GetMatInfo();
}
}
IIndexedMesh* pIndexedMesh = pStatObj->GetIndexedMesh(true);
if (pIndexedMesh)
{
int breakableSubmeshes = 0;
int nonbreakableSubmeshes = 0;
int subsetCount = pIndexedMesh->GetSubSetCount();
for (int i = 0; i < subsetCount; ++i)
{
const SMeshSubset& subset = pIndexedMesh->GetSubSet(i);
if (subset.nNumVerts == 0)
{
continue;
}
// Check to see if the material uses multiple uv sets and if the vertex format has the same number of texCoord attributes
SShaderItem shaderItem = pIMaterial->GetShaderItem(i);
if (shaderItem.m_pShader)
{
size_t materialUVs = shaderItem.m_pShader->GetNumberOfUVSets();
size_t meshUVs = subset.vertexFormat.GetAttributeUsageCount(AZ::Vertex::AttributeUsage::TexCoord);
if (materialUVs != meshUVs)
{
const char* meshName = pStatObj->GetRenderMesh() ? pStatObj->GetRenderMesh()->GetSourceName() : "unknown";
AZStd::string errorMessage;
errorMessage = AZStd::string::format("Material '%s' sub-material %d with %zu uv set(s) was assigned to mesh '%s' with %zu uv set(s). ", pIMaterial->GetName(), i + 1, materialUVs, meshName, meshUVs);
AZStd::string recommendedAction;
if (materialUVs < meshUVs)
{
recommendedAction = AZStd::string::format("If you do not intend to use %zu uv sets, remove the extra uv set(s) from the source mesh during the import process. Otherwise, consider checking the desired 'Use uv set 2 for...' shader gen params in the material editor.", meshUVs);
}
else
{
recommendedAction = AZStd::string::format("If you intend to use %zu uv sets, include the additional uv set(s) in the source mesh during the import process. Otherwise, consider unchecking the 'Use uv set 2 for...' shader gen params in the material editor.", materialUVs);
}
errorMessage += recommendedAction;
AZ_Warning("Material Editor", false, errorMessage.c_str());
SMeshMaterialIssue issue(meshName, errorMessage);
issues->push_back(issue);
}
}
_smart_ptr<IMaterial> pSubMaterial = pIMaterial->GetSubMtl(subset.nMatID);
if (!pSubMaterial)
{
continue;
}
if (size_t(subset.nMatID) > size_t(pMaterial->GetSubMaterialCount()))
{
continue;
}
if (pSubMaterial->GetSurfaceType()->GetBreakable2DParams())
{
++breakableSubmeshes;
}
else
{
++nonbreakableSubmeshes;
}
}
}
int subobjectCount = pStatObj->GetSubObjectCount();
for (int i = 0; i < subobjectCount; ++i)
{
const IStatObj::SSubObject* subobject = pStatObj->GetSubObject(i);
if (subobject->pStatObj)
{
ValidateMeshMaterials(issues, subobject->pStatObj, pMaterial);
}
}
}
void CStatObjValidator::Validate(IStatObj* statObj, CMaterial* editorMaterial)
{
m_description = QString();
m_isValid = true;
_smart_ptr<IMaterial> pIMaterial = 0;
if (editorMaterial)
{
if (editorMaterial->GetParent())
{
pIMaterial = editorMaterial->GetParent()->GetMatInfo();
}
else
{
pIMaterial = editorMaterial->GetMatInfo();
}
}
if (statObj && editorMaterial)
{
std::vector<SMeshMaterialIssue> issues;
ValidateMeshMaterials(&issues, statObj, editorMaterial);
if (!issues.empty())
{
m_isValid = false;
}
for (size_t i = 0; i < issues.size(); ++i)
{
const SMeshMaterialIssue& issue = issues[i];
if (!m_description.isEmpty())
{
m_description += "\n";
}
if (!issue.nodeName.empty())
{
m_description += "Node ";
m_description += issue.nodeName.c_str();
m_description += ":";
}
if (issue.subMaterialIndex >= 0)
{
m_description += QStringLiteral("SubMaterial %1:").arg(issue.subMaterialIndex + 1);
}
if (!issue.nodeName.empty() || issue.subMaterialIndex >= 0)
{
m_description += "\n ";
}
if (!issue.description.empty())
{
m_description += issue.description.c_str();
}
}
}
}
@@ -1,32 +0,0 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// This class is supposed to validate CGF with assigned material.
// Some of the asset issues may be diagnosed only when SurfaceType is known.
#pragma once
class CRYEDIT_API CStatObjValidator
{
public:
CStatObjValidator();
void Validate(IStatObj* statObj, CMaterial* editorMaterial);
bool IsValid() const { return m_isValid; }
QString GetDescription() const { return m_description; }
private:
bool m_isValid;
QString m_description;
};