Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BaseAreaMeshComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Area Mesh", description: "")]
2 class SCR_BaseAreaMeshComponentClass : ScriptComponentClass
3 {
4 }
5 
6 class 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")]
27  protected ResourceName m_Material;
28 
29  [Attribute("false", desc: "When enabled, the component will be active from init", category: "Virtual Area")]
30  protected bool m_bActiveEveryFrameOnInit;
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  //------------------------------------------------------------------------------------------------
121  protected ResourceName GetMaterial()
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 
196  if (m_bFollowTerrain)
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,
258  RECTANGLE = 20,
259 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
EOnFrame
override void EOnFrame(IEntity owner, float timeSlice)
Definition: SCR_BaseAreaMeshComponent.c:230
m_fHeight
protected float m_fHeight
Definition: SCR_BaseAreaMeshComponent.c:15
m_vLastDir
protected vector m_vLastDir
Definition: SCR_BaseAreaMeshComponent.c:36
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
GetResolution
int GetResolution()
Definition: SCR_BaseAreaMeshComponent.c:78
EAreaMeshShape
EAreaMeshShape
Definition: SCR_BaseAreaMeshComponent.c:255
ActivateEveryFrame
void ActivateEveryFrame()
Activate the area so it could be updated every frame.
Definition: SCR_BaseAreaMeshComponent.c:40
SCR_BaseAreaMeshComponentClass
Definition: SCR_BaseAreaMeshComponent.c:2
GetMaterial
protected ResourceName GetMaterial()
Get material used for area mesh.
Definition: SCR_BaseAreaMeshComponent.c:121
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_bActiveEveryFrameOnInit
protected bool m_bActiveEveryFrameOnInit
Definition: SCR_BaseAreaMeshComponent.c:30
RECTANGLE
@ RECTANGLE
Rectangle shape that has a width and length.
Definition: SCR_BaseAreaMeshComponent.c:258
GetDimensions2D
void GetDimensions2D(out float width, out float length)
Definition: SCR_BaseAreaMeshComponent.c:92
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_vLastPos
protected vector m_vLastPos
Definition: SCR_BaseAreaMeshComponent.c:35
m_bFollowTerrain
protected bool m_bFollowTerrain
Definition: SCR_BaseAreaMeshComponent.c:21
GetHeight
float GetHeight()
Definition: SCR_BaseAreaMeshComponent.c:61
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_BaseAreaMeshComponent.c:237
DeactivateEveryFrame
void DeactivateEveryFrame()
Deactivate the area.
Definition: SCR_BaseAreaMeshComponent.c:47
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_Shape
Definition: SCR_Shape.c:1
GetMeshOffset
protected vector GetMeshOffset(IEntity owner)
Definition: SCR_BaseAreaMeshComponent.c:114
m_vResolution
protected int m_vResolution
Definition: SCR_BaseAreaMeshComponent.c:18
GetShape
EAreaMeshShape GetShape()
Definition: SCR_BaseAreaMeshComponent.c:69
PREVIEW_RESOLUTION
SCR_BaseAreaMeshComponentClass PREVIEW_RESOLUTION
m_bStretchMaterial
protected bool m_bStretchMaterial
Definition: SCR_BaseAreaMeshComponent.c:24
m_Material
protected ResourceName m_Material
Definition: SCR_BaseAreaMeshComponent.c:27
m_eShape
protected EAreaMeshShape m_eShape
Definition: SCR_BaseAreaMeshComponent.c:12
m_bHideInWorkbench
protected bool m_bHideInWorkbench
Definition: SCR_BaseAreaMeshComponent.c:33
ELLIPSE
@ ELLIPSE
Ellipse using Radius and Resolution.
Definition: SCR_BaseAreaMeshComponent.c:257
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
GetRadius
float GetRadius()
Definition: SCR_CampaignBuildingAreaMeshComponent.c:21
GenerateAreaMesh
void GenerateAreaMesh()
Generate area mesh based on its settings.
Definition: SCR_BaseAreaMeshComponent.c:128
GetDimensions3D
void GetDimensions3D(out vector dimensions)
Definition: SCR_BaseAreaMeshComponent.c:101
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180