Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BaseAreaMeshComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Area Mesh", description: "")]
5
6class SCR_BaseAreaMeshComponent : ScriptComponent
7{
8 //~ Resolution of Ellipse mesh in preview (Rectangle by definition has a resolution of 4)
9 static const int PREVIEW_RESOLUTION = 48;
10
11 [Attribute(defvalue: "10", category: "Virtual Area", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(EAreaMeshShape), desc: "Area shape. If Ellipse it will use Radius while Rectangle uses diameter (width and length) rather like ellipse using half the diameter)")]
13
14 [Attribute("10", category: "Virtual Area")]
15 protected float m_fHeight;
16
17 [Attribute("12", desc: "How many segments in the ellipse (ELLIPSE Shapes only as RECTANGLE has a set resolution of 4).", uiwidget: UIWidgets.Slider, params: "4 60 1", category: "Virtual Area")]
18 protected int m_vResolution;
19
20 [Attribute(desc: "True to let the border copy terrain, creating a 'wall'.", category: "Virtual Area")]
21 protected bool m_bFollowTerrain;
22
23 [Attribute(desc: "True to stretch the material along the whole circumference instead of mapping it on each segment.", category: "Virtual Area")]
24 protected bool m_bStretchMaterial;
25
26 [Attribute(desc: "Material mapped on outside and inside of the mesh. Inside mapping is mirrored.", uiwidget: UIWidgets.ResourcePickerThumbnail, params: "emat", category: "Virtual Area")]
28
29 [Attribute("false", desc: "When enabled, the component will be active from init", category: "Virtual Area")]
31
32 [Attribute("0", desc: "If true always hide the zone in workbench. This setting is ignored when playing even within workbench", category: "Workbench")]
33 protected bool m_bHideInWorkbench;
34
35 protected vector m_vLastPos;
36 protected vector m_vLastDir;
37
38 //------------------------------------------------------------------------------------------------
41 {
42 SetEventMask(GetOwner(), EntityEvent.FRAME);
43 }
44
45 //------------------------------------------------------------------------------------------------
48 {
49 ClearEventMask(GetOwner(), EntityEvent.FRAME);
50 }
51
52 //------------------------------------------------------------------------------------------------
56 float GetRadius();
57
58 //------------------------------------------------------------------------------------------------
61 float GetHeight()
62 {
63 return m_fHeight;
64 }
65
66 //------------------------------------------------------------------------------------------------
70 {
71 return m_eShape;
72 }
73
74 //------------------------------------------------------------------------------------------------
79 {
80 if (GetShape() == EAreaMeshShape.RECTANGLE)
81 return 4;
82 else
83 return m_vResolution;
84 }
85
86 //------------------------------------------------------------------------------------------------
92 void GetDimensions2D(out float width, out float length)
93 {
94 width = GetRadius();
95 length = width;
96 }
97
98 //------------------------------------------------------------------------------------------------
101 void GetDimensions3D(out vector dimensions)
102 {
103 float width, length;
104 GetDimensions2D(width, length);
105 dimensions[0] = width;
106 dimensions[1] = GetHeight();
107 dimensions[2] = length;
108 }
109
110 //------------------------------------------------------------------------------------------------
114 protected vector GetMeshOffset(IEntity owner)
115 {
116 return vector.Zero;
117 }
118
119 //------------------------------------------------------------------------------------------------
122 {
123 return m_Material;
124 }
125
126 //------------------------------------------------------------------------------------------------
129 {
130 IEntity owner = GetOwner();
131
132 #ifdef WORKBENCH
133 if (m_bHideInWorkbench && owner.GetWorld() && owner.GetWorld().IsEditMode())
134 return;
135 #endif
136
137 vector dimensions;
138 GetDimensions3D(dimensions);
139
140 if (dimensions[0] <= 0 || dimensions[1] <= 0 || dimensions[2] <= 0)
141 {
142 owner.SetObject(null, "");
143 return;
144 }
145
146 array<vector> positions = {};
147 vector offset = GetMeshOffset(owner);
148
149 if (m_eShape == EAreaMeshShape.ELLIPSE)
150 {
151 int resolution = GetResolution();
152 float dirStep = Math.PI2 / resolution;
153
154 //--- Get positions
155 for (int v = 0; v < resolution; v++)
156 {
157 float dir = dirStep * v;
158 vector pos = Vector((Math.Sin(dir) * dimensions[0]) + offset[0], -dimensions[1], (Math.Cos(dir) * dimensions[2]) + offset[2]);
159 positions.Insert(pos);
160 }
161 }
162 else if (m_eShape == EAreaMeshShape.RECTANGLE)
163 {
164 //~ Make sure it uses half of the width and length
165 float width = dimensions[0] * 0.5;
166 float length = dimensions[2] * 0.5;
167
168 array<vector> corners =
169 {
170 { -width + offset[0], -dimensions[1], -length + offset[2] },
171 { width + offset[0], -dimensions[1], -length + offset[2] },
172 { width + offset[0], -dimensions[1], length + offset[2] },
173 { -width + offset[0], -dimensions[1], length + offset[2] }
174 };
175
176 //~ Set positions
177 for (int i = 0; i < 4; i++)
178 {
179 vector start = corners[i];
180 vector end = corners[(i + 1) % 4];
181
182 for (float s = 0; s < 4; s++)
183 {
184 vector pos = vector.Lerp(start, end, s * 0.25);
185 positions.Insert(pos);
186 }
187 }
188 }
189 else
190 {
191 Print(string.Format("'SCR_BaseAreaMeshComponent' does not support shape type %1 (%2)", typename.EnumToString(EAreaMeshShape, m_eShape), m_eShape), LogLevel.ERROR);
192 owner.SetObject(null, "");
193 return;
194 }
195
197 {
198 //--- Reset entity rotation
199 vector transform[4];
200 owner.GetWorldTransform(transform);
201 vector angles = Math3D.MatrixToAngles(transform);
202 angles[1] = 0; //--- Reset pitch
203 angles[2] = 0; //--- Reset roll
204 Math3D.AnglesToMatrix(angles, transform);
205 owner.SetWorldTransform(transform);
206
207 //--- Snap all positions to ground
208 BaseWorld world = owner.GetWorld();
209 vector worldPos;
210 foreach (int i, vector pos: positions)
211 {
212 worldPos = owner.CoordToParent(pos);
213 worldPos[1] = Math.Max(world.GetSurfaceY(worldPos[0], worldPos[2]), 0);
214 positions[i] = owner.CoordToLocal(worldPos);
215 }
216 }
217
218 Resource res = SCR_Shape.CreateAreaMesh(positions, dimensions[1] * 2, GetMaterial(), m_bStretchMaterial);
219 MeshObject meshObject = res.GetResource().ToMeshObject();
220 if (meshObject)
221 {
222 owner.SetObject(meshObject, "");
223
224 m_vLastPos = owner.GetOrigin();
225 m_vLastDir = owner.GetAngles();
226 }
227 }
228
229 //------------------------------------------------------------------------------------------------
230 override void EOnFrame(IEntity owner, float timeSlice)
231 {
232 if (vector.DistanceSq(m_vLastPos, owner.GetOrigin()) > 0.1 || vector.DistanceSq(m_vLastDir, owner.GetAngles()) > 0.1)
234 }
235
236 //------------------------------------------------------------------------------------------------
237 override void OnPostInit(IEntity owner)
238 {
239 SetEventMask(owner, EntityEvent.INIT);
240
243 }
244
245 #ifdef WORKBENCH
246 //------------------------------------------------------------------------------------------------
247 //~ Makes sure mesh area is generated at the correct position in workbench
248 override void _WB_SetTransform(IEntity owner, inout vector mat[4], IEntitySource src)
249 {
251 }
252 #endif
253}
254
256{
257 ELLIPSE = 10,
259}
ref array< string > angles
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
bool m_bHideInWorkbench
void DeactivateEveryFrame()
Deactivate the area.
int GetResolution()
ResourceName m_Material
float GetHeight()
EAreaMeshShape m_eShape
bool m_bActiveEveryFrameOnInit
void GetDimensions3D(out vector dimensions)
void ActivateEveryFrame()
Activate the area so it could be updated every frame.
ResourceName GetMaterial()
Get material used for area mesh.
SCR_BaseAreaMeshComponentClass PREVIEW_RESOLUTION
EAreaMeshShape GetShape()
@ ELLIPSE
Ellipse using Radius and Resolution.
@ RECTANGLE
Rectangle shape that has a width and length.
bool m_bFollowTerrain
void GetDimensions2D(out float width, out float length)
bool m_bStretchMaterial
void GenerateAreaMesh()
Generate area mesh based on its settings.
vector m_vLastDir
vector m_vLastPos
float m_fHeight
vector GetMeshOffset(IEntity owner)
override void EOnFrame(IEntity owner, float timeSlice)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
enum EVehicleType IEntity
proto external vector GetAngles()
Same as GetYawPitchRoll(), but returns rotation vector around X, Y and Z axis.
proto external vector GetOrigin()
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
proto external BaseWorld GetWorld()
proto external bool SetWorldTransform(vector mat[4])
See IEntity::SetTransform. Returns false, if there is no change in transformation.
proto external vector CoordToParent(vector coord)
proto external vector CoordToLocal(vector coord)
Definition Math.c:13
MeshObject.
Definition MeshObject.c:34
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
IEntity GetOwner()
Owner entity of the fuel tank.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
proto native vector Vector(float x, float y, float z)