1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
5 #include "Geometry/EdMesh.h"
6 #include "CollisionFilteringProperties.h"
8 #include <Objects/BaseObject.h>
10 class SANDBOX_API CBrushObject
: public CBaseObject
13 DECLARE_DYNCREATE(CBrushObject
)
15 //////////////////////////////////////////////////////////////////////////
16 // Overrides from CBaseObject.
17 //////////////////////////////////////////////////////////////////////////
18 bool Init(CBaseObject
* prev
, const string
& file
);
20 void Display(CObjectRenderHelper
& objRenderHelper
);
21 const ColorB
& GetSelectionPreviewHighlightColor() override
;
22 bool CreateGameObject();
24 void GetLocalBounds(AABB
& box
);
26 bool HitTest(HitContext
& hc
);
27 int HitTestAxis(HitContext
& hc
);
29 virtual void SetSelected(bool bSelect
);
30 virtual void SetMinSpec(uint32 nSpec
, bool bSetChildren
= true);
31 virtual IPhysicalEntity
* GetCollisionEntity() const;
33 void CreateInspectorWidgets(CInspectorWidgetCreator
& creator
) override
;
35 virtual float GetCreationOffsetFromTerrain() const override
{ return 0.f
; }
37 void Serialize(CObjectArchive
& ar
);
38 XmlNodeRef
Export(const string
& levelPath
, XmlNodeRef
& xmlNode
);
40 virtual void Validate();
41 virtual string
GetAssetPath() const override
;
42 virtual void GatherUsedResources(CUsedResources
& resources
);
43 virtual bool IsSimilarObject(CBaseObject
* pObject
);
44 virtual bool StartSubObjSelection(int elemType
);
45 virtual void EndSubObjectSelection();
46 virtual void CalculateSubObjectSelectionReferenceFrame(SubObjectSelectionReferenceFrameCalculator
* pCalculator
);
48 virtual CEdGeometry
* GetGeometry();
49 //////////////////////////////////////////////////////////////////////////
51 //////////////////////////////////////////////////////////////////////////
52 virtual IStatObj
* GetIStatObj();
53 uint64
GetRenderFlags() const { return m_renderFlags
; }
54 IRenderNode
* GetEngineNode() const { return m_pRenderNode
; }
55 float GetRatioLod() const { return mv_ratioLOD
; }
56 float GetRatioViewDist() const { return mv_ratioViewDist
; }
57 const string
& GetGeometryFile() const { return mv_geometryFile
; }
58 void SetGeometryFile(const string
& geometryFile
);
60 //////////////////////////////////////////////////////////////////////////
62 //////////////////////////////////////////////////////////////////////////
63 virtual void SetMaterial(IEditorMaterial
* mtl
);
64 virtual IEditorMaterial
* GetRenderMaterial() const;
65 virtual void SetMaterialLayersMask(uint32 nLayersMask
);
67 virtual void InvalidateGeometryFile(const string
& gamePath
) override
;
69 bool ApplyIndirLighting() const { return false; }
72 void ReloadGeometry();
76 void CreateBrushFromMesh(const char* meshFilname
);
78 void GetVerticesInWorld(std::vector
<Vec3
>& vertices
) const;
81 //! Dtor must be protected.
85 virtual void UpdateVisibility(bool visible
);
87 //! Convert ray given in world coordinates to the ray in local brush coordinates.
88 void WorldToLocalRay(Vec3
& raySrc
, Vec3
& rayDir
);
90 bool ConvertFromObject(CBaseObject
* object
);
91 void DeleteThis() { delete this; }
92 void InvalidateTM(int nWhyFlags
);
93 void OnEvent(ObjectEvent event
);
95 void UpdateEngineNode(bool bOnlyTransform
= false);
97 void OnFileChange(string filename
);
99 //////////////////////////////////////////////////////////////////////////
101 void OnGeometryChange(IVariable
* var
);
102 void OnRenderVarChange(IVariable
* var
);
103 void OnAIRadiusVarChange(IVariable
* var
);
104 void OnExludeFromNavigationVarChange(IVariable
* var
);
105 //////////////////////////////////////////////////////////////////////////
107 virtual string
GetMouseOverStatisticsText() const;
109 virtual void UpdateHighlightPassState(bool bSelected
, bool bHighlighted
);
115 //! Node that registered in engine and used to render brush prefab
116 IRenderNode
* m_pRenderNode
;
117 _smart_ptr
<CEdMesh
> m_pGeometry
;
118 bool m_bNotSharedGeom
;
120 //////////////////////////////////////////////////////////////////////////
122 //////////////////////////////////////////////////////////////////////////
123 CVariable
<string
> mv_geometryFile
;
125 //////////////////////////////////////////////////////////////////////////
126 // Brush rendering parameters.
127 //////////////////////////////////////////////////////////////////////////
129 CCollisionFilteringProperties m_collisionFiltering
;
130 CVariable
<bool> mv_outdoor
;
131 CVariable
<bool> mv_castShadowMaps
;
132 CSmartVariable
<bool> mv_giMode
;
133 CVariable
<bool> mv_dynamicDistanceShadows
;
134 CVariable
<bool> mv_rainOccluder
;
135 CVariable
<bool> mv_registerByBBox
;
136 CVariableEnum
<int> mv_hideable
;
137 CVariable
<int> mv_ratioLOD
;
138 CVariable
<int> mv_ratioViewDist
;
139 CVariable
<bool> mv_excludeFromTriangulation
;
140 CVariable
<bool> mv_noDynWater
;
141 CVariable
<float> mv_aiRadius
;
142 CVariable
<bool> mv_noDecals
;
143 CVariable
<bool> mv_recvWind
;
144 CVariable
<bool> mv_Occluder
;
145 CVariable
<bool> mv_drawLast
;
146 CVariable
<int> mv_shadowLodBias
;
147 CVariable
<bool> mv_ignoreTerrainLayerBlend
;
148 CVariable
<bool> mv_ignoreDecalBlend
;
150 //////////////////////////////////////////////////////////////////////////
152 uint64 m_renderFlags
;
154 bool m_bIgnoreNodeUpdate
;
155 bool m_RePhysicalizeOnVisible
;
158 // Brushes need to explicitly notify the NavMesh of their old AABB *before* it gets changed by transformation, because
159 // scaling and rotation will re-physicalize the brush, and then the old AABB doesn't exist anymore and the physics system
160 // will report the "wrong" old AABB to the NavMesh. In fact, what gets reported then is the new AABB, but in local space, and
161 // that would cause the NavMesh to regenerate only a part of the affected area.
162 virtual bool ShouldNotifyOfUpcomingAABBChanges() const override
{ return true; }
164 // Initialize brush parameters from properties of the current geometry, if any.
165 void ApplyStatObjProperties();
169 * Class Description of CBrushObject.
171 class CBrushObjectClassDesc
: public CObjectClassDesc
174 ObjectType
GetObjectType() { return OBJTYPE_BRUSH
; }
175 const char* ClassName() { return "Brush"; }
176 const char* Category() { return "Brush"; }
177 CRuntimeClass
* GetRuntimeClass() { return RUNTIME_CLASS(CBrushObject
); }
178 const char* GetFileSpec() { return "*.cgf"; }
179 virtual const char* GetDataFilesFilterString() override
{ return GetFileSpec(); }