Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_VirtualAreaEntity.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Editor", description: "Core Editor manager", color: "251 91 0 255", dynamicBox: true)]
2 class SCR_VirtualAreaEntityClass: GenericEntityClass
3 {
4 };
5 
7 {
8  [Attribute(defvalue: "0", uiwidget: UIWidgets.ComboBox, category: "Virtual Area", enums: { ParamEnum("Ellipse (Inside Radius)", "0", ""), ParamEnum("Ellipse (Outside Radius)", "1", ""), ParamEnum("Rectangle", "2", "") }, desc: "Area shape")]
9  private int m_Shape;
10 
11  [Attribute("10 10 10", desc: "Minor axes (i.e., XZ values are radius, not diameter, and Y value is half the height).", category: "Virtual Area")]
12  private vector m_vSize;
13 
14  [Attribute("12", desc: "How many segments in the ellipse.", uiwidget: UIWidgets.Slider, params: "4 60 1", category: "Virtual Area")]
15  private int m_vResolution;
16 
17  [Attribute(desc: "True to let the border copy terrain, creating a 'wall'.", category: "Virtual Area")]
18  private bool m_bFollowTerrain;
19 
20  [Attribute(desc: "True to stretch the material along the whole circumference instead of mapping it on each segment.", category: "Virtual Area")]
21  private bool m_bStretchMaterial;
22 
23  [Attribute(desc: "Material mapped on outside and inside of the mesh. Inside mapping is mirrored.", uiwidget: UIWidgets.ResourcePickerThumbnail, params: "emat", category: "Virtual Area")]
24  private ResourceName m_Material;
25 
30  int GetShape()
31  {
32  return m_Shape;
33  }
38  vector GetSize()
39  {
40  return m_vSize;
41  }
46  bool InArea(vector pos)
47  {
48  pos = CoordToLocal(pos);
49  float sizeX = m_vSize[0];
50  float sizeY = m_vSize[1];
51  float sizeZ = m_vSize[2];
52  switch (m_Shape)
53  {
54  //--- Ellipse
55  case 0:
56  case 1:
57  {
58  if (m_Shape == 1)
59  {
60  //--- Outside
61  float coef = Math.Sqrt(Math.Pow(sizeX, 2) + Math.Pow(sizeZ, 2)) / ((sizeX + sizeZ) / 2); //--- Not accurate for ellipse (ToDo: Better calculation)
62  sizeX *= coef;
63  sizeZ *= coef;
64  }
65  if (sizeX == sizeZ)
66  {
67  //--- Circle
68  return vector.Distance(Vector(pos[0], 0, pos[2]), vector.Zero) < sizeX;
69  }
70  //--- ToDo: Ellipse
71  break;
72  }
73  case 2:
74  {
75  //--- Rectangle
76  return (pos[0] > -sizeX && pos[0] < sizeX) && (pos[2] > -sizeZ && pos[2] < sizeZ);
77  }
78  }
79  return false;
80  }
85  void SetMaterial(ResourceName material)
86  {
87  if (material == m_Material) return;
88 
89  m_Material = material;
90  Generate(m_vSize, m_vResolution, m_bFollowTerrain);
91  }
92 
98  void Generate(vector size, int resolution)
99  {
100  Generate(size, resolution, m_bFollowTerrain);
101  }
108  void Generate(vector size, int resolution, bool followTerrain = false)
109  {
110  m_vSize = size;
111  m_vResolution = resolution;
112  m_bFollowTerrain = followTerrain;
113 
114  if (resolution * 12 > 720)
115  {
116  Print(string.Format("Cannot generate shape, resolution %1 is above maximum value %2!", resolution, 720 / 12), LogLevel.ERROR);
117  return;
118  }
119 
120  float sizeX = m_vSize[0];
121  float sizeY = m_vSize[1];
122  float sizeZ = m_vSize[2];
123 
124  array<vector> positions = new array<vector>;
125  switch (m_Shape)
126  {
127  //--- Ellipse
128  case 0:
129  case 1:
130  {
131  if (m_Shape == 1)
132  {
133  //--- Outside
134  float coef = Math.Sqrt(Math.Pow(sizeX, 2) + Math.Pow(sizeZ, 2)) / ((sizeX + sizeZ) / 2); //--- Not accurate for ellipse (ToDo: Better calculation)
135  sizeX *= coef;
136  sizeZ *= coef;
137  }
138  float dirStep = Math.PI2 / resolution;
139  for (int v = 0; v < resolution; v++)
140  {
141  float dir = dirStep * v;
142  vector pos = Vector(Math.Sin(dir) * sizeX, -sizeY, Math.Cos(dir) * sizeZ);
143  positions.Insert(pos);
144  }
145  break;
146  }
147  //--- Rectangle
148  case 2:
149  {
150  float perimeter = (sizeX + sizeZ) * 2;
151  float segmentsX = Math.Max(resolution * (sizeX / perimeter), 1);
152  float segmentsY = Math.Max(resolution * (sizeZ / perimeter), 1);
153 
154  array<vector> corners = {
155  Vector(-sizeX, -sizeY, -sizeZ),
156  Vector(sizeX, -sizeY, -sizeZ),
157  Vector(sizeX, -sizeY, sizeZ),
158  Vector(-sizeX, -sizeY, sizeZ)
159  };
160  for (int i = 0; i < 4; i++)
161  {
162  vector start = corners[i];
163  vector end = corners[(i + 1) % 4];
164 
165  int segments = segmentsX;
166  if (i % 2 == 1) segments = segmentsY;
167  for (float s = 0; s < segments; s++)
168  {
169  vector pos = vector.Lerp(start, end, s / segments);
170  positions.Insert(pos);
171  }
172  }
173  break;
174  }
175  }
176 
177  //--- Snap all positions to ground
178  if (m_bFollowTerrain)
179  {
180  vector transform[4];
181  float entitySurfaceY;
182  GetTransform(transform);
183  entitySurfaceY = Math.Max(GetWorld().GetSurfaceY(transform[3][0], transform[3][2]), 0);
184  foreach (int i, vector pos: positions)
185  {
186  vector worldPos = transform[3] + transform[0] * pos[0] + transform[2] * pos[2];
187  pos[1] = Math.Max(GetWorld().GetSurfaceY(worldPos[0], worldPos[2]), 0) - entitySurfaceY;
188  positions[i] = pos;
189  }
190  }
191 
192  Resource res = SCR_Shape.CreateAreaMesh(positions, sizeY * 2, m_Material, m_bStretchMaterial);
193  MeshObject meshObject = res.GetResource().ToMeshObject();
194  if (meshObject) SetObject(meshObject,"");
195  }
196 
197  void SCR_VirtualAreaEntity(IEntitySource src, IEntity parent)
198  {
199  Generate(m_vSize, m_vResolution, m_bFollowTerrain);
200  }
201 
202 #ifdef WORKBENCH
203  override void _WB_GetBoundBox(inout vector min, inout vector max, IEntitySource src)
204  {
205  min = -m_vSize;
206  max = m_vSize;
207 
208  /*
209  if (m_Shape == 1)
210  {
211  float coef = Math.Sqrt(Math.Pow(m_vSize[0], 2) + Math.Pow(m_vSize[2], 2)) / Math.Max(m_vSize[0], m_vSize[2]);
212  min *= coef;
213  max *= coef;
214  }
215  */
216  }
217 #endif
218 };
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_VirtualAreaEntityClass
Definition: SCR_VirtualAreaEntity.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_bFollowTerrain
protected bool m_bFollowTerrain
Definition: SCR_BaseAreaMeshComponent.c:21
SCR_VirtualAreaEntity
Definition: SCR_VirtualAreaEntity.c:6
SCR_Shape
Definition: SCR_Shape.c:1
m_vResolution
protected int m_vResolution
Definition: SCR_BaseAreaMeshComponent.c:18
m_bStretchMaterial
protected bool m_bStretchMaterial
Definition: SCR_BaseAreaMeshComponent.c:24
m_Material
protected ResourceName m_Material
Definition: SCR_BaseAreaMeshComponent.c:27
m_Shape
private ref Shape m_Shape
Definition: UnitDisplayComponent.c:11
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180