Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_LineTerrainShaperGeneratorBaseEntity.c
Go to the documentation of this file.
2 {
3 }
4 
5 class SCR_LineTerrainShaperGeneratorBaseEntity : SCR_GeneratorBaseEntity
6 {
7  /*
8  Terrain Sculpting
9  */
10 
11  [Attribute(defvalue: "0", desc: "Adjust terrain's Y around the track to fit the spline's location and clearance", category: "Terrain Sculpting")]
12  protected bool m_bSculptTerrain;
13 
14  [Attribute(defvalue: "0", desc: "Priority of terrain sculpting", category: "Terrain Sculpting")]
15  protected int m_iTerrainSculptingPriority;
16 
17  [Attribute(defvalue: "10", uiwidget: UIWidgets.EditBox, desc: "Width of the path before fall-off, the flat surface around the shape", category: "Terrain Sculpting", params: "0 100 0.1")]
18  protected float m_fTerrainSculptingPathWidth;
19 
20  [Attribute(defvalue: "20", uiwidget: UIWidgets.EditBox, desc: "Width of the path fall-off", category: "Terrain Sculpting", params: "0 100 0.1")]
21  protected float m_fTerrainSculptingFallOffWidth;
22 
23 #ifdef WORKBENCH
24 
27  protected ShapeEntity m_ShapeEntity;
28 
29  protected static ref array<string> s_aTerrainUpdateKeys = {
30  "m_bSculptTerrain", "m_iTerrainSculptingPriority",
31  "m_fTerrainSculptingPathWidth", "m_fTerrainSculptingFallOffWidth",
32  };
33 
34  //------------------------------------------------------------------------------------------------
35  protected override void OnShapeInitInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity)
36  {
37  super.OnShapeInitInternal(shapeEntitySrc, shapeEntity);
38 
39  UpdateTerrainSimple();
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  protected override void OnShapeTransformInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity, array<vector> mins, array<vector> maxes)
44  {
45  super.OnShapeTransformInternal(shapeEntitySrc, shapeEntity, mins, maxes);
46 
47  UpdateTerrain(shapeEntity, false, mins, maxes);
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  protected override void OnShapeChangedInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity, array<vector> mins, array<vector> maxes)
52  {
53  super.OnShapeChangedInternal(shapeEntitySrc, shapeEntity, mins, maxes);
54 
55  UpdateTerrain(shapeEntity, false, mins, maxes);
56  }
57 
58  //------------------------------------------------------------------------------------------------
59  override void _WB_OnInit(inout vector mat[4], IEntitySource src)
60  {
61  super._WB_OnInit(mat, src);
62 
63  UpdateTerrainSimple();
64  }
65 
66  //------------------------------------------------------------------------------------------------
67  override bool _WB_OnKeyChanged(BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
68  {
69  super._WB_OnKeyChanged(src, key, ownerContainers, parent);
70 
71  WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
72  if (!worldEditorAPI.AreGeneratorEventsEnabled())
73  return false;
74 
75  BaseContainerTools.WriteToInstance(this, src);
76 
77  if (s_aTerrainUpdateKeys.Contains(key))
78  {
79  bool forceUpdate;
80  if (key == "m_bSculptTerrain")
81  {
82  if (m_bSculptTerrain)
83  forceUpdate = true;
84  else
85  worldEditorAPI.RemoveTerrainFlatterEntity(this, true);
86  }
87 
88  UpdateTerrainSimple(forceUpdate);
89  }
90 
91  return true;
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  override void _WB_OnCreate(IEntitySource src)
96  {
97  super._WB_OnCreate(src);
98 
99  UpdateTerrainSimple();
100  }
101 
102  //------------------------------------------------------------------------------------------------
103  override void _WB_OnParentChange(IEntitySource src, IEntitySource prevParentSrc)
104  {
105  super._WB_OnParentChange(src, prevParentSrc);
106 
107  WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
108  if (!worldEditorAPI)
109  return;
110 
111  if (m_ParentShapeSource)
112  UpdateTerrainSimple(true);
113  else
114  worldEditorAPI.RemoveTerrainFlatterEntity(this, true);
115  }
116 
117  //------------------------------------------------------------------------------------------------
118  override void _WB_OnDelete(IEntitySource src)
119  {
120  super._WB_OnDelete(src);
121 
122  WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
123  if (!worldEditorAPI)
124  return;
125 
126  worldEditorAPI.RemoveTerrainFlatterEntity(this, true);
127  }
128 
129  //------------------------------------------------------------------------------------------------
130  // wrapper
131  protected void UpdateTerrainSimple(bool forceUpdate = false)
132  {
133  if (!m_bSculptTerrain || !m_ParentShapeSource)
134  return;
135 
136  WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
137  if (!worldEditorAPI)
138  return;
139 
140  m_ShapeEntity = ShapeEntity.Cast(worldEditorAPI.SourceToEntity(m_ParentShapeSource));
141  if (!m_ShapeEntity)
142  return;
143 
144  array<vector> updateMins = {};
145  array<vector> updateMaxes = {};
146  m_ShapeEntity.GetAllInfluenceBBoxes(m_ParentShapeSource, updateMins, updateMaxes);
147 
148  UpdateTerrain(m_ShapeEntity, forceUpdate, updateMins, updateMaxes);
149  }
150 
151  //------------------------------------------------------------------------------------------------
152  // where everything happens
153  protected void UpdateTerrain(notnull ShapeEntity shapeEntity, bool forceUpdate, notnull array<vector> updateMins, notnull array<vector> updateMaxes)
154  {
155  if (!m_bSculptTerrain)
156  return;
157 
158  WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
159  if (!worldEditorAPI)
160  return;
161 
162  vector mat[4];
163  shapeEntity.GetWorldTransform(mat);
164 
165  array<vector> points = {};
166  shapeEntity.GenerateTesselatedShape(points);
167 
168  if (points.Count() < 2)
169  {
170  Print("Terrain Flattener requires a shape with at least two points", LogLevel.WARNING);
171  return;
172  }
173 
174  vector firstPoint = points[0].Multiply4(mat);
175  vector mins = firstPoint;
176  vector maxs = firstPoint;
177 
178  vector pos;
179  foreach (vector point : points)
180  {
181  pos = point.Multiply4(mat);
182  for (int i = 0; i < 3; i++)
183  {
184  float val = pos[i];
185 
186  if (val < mins[i])
187  mins[i] = val;
188 
189  if (val > maxs[i])
190  maxs[i] = val;
191  }
192  }
193 
194  worldEditorAPI.AddTerrainFlatterEntity(this, mins, maxs, m_iTerrainSculptingPriority, m_fTerrainSculptingPathWidth * 0.5, m_fTerrainSculptingFallOffWidth, forceUpdate, updateMins, updateMaxes);
195  }
196 
197 #endif // WORKBENCH
198 
199  //------------------------------------------------------------------------------------------------
200  // constructor
201  protected void SCR_LineTerrainShaperGeneratorBaseEntity(IEntitySource src, IEntity parent)
202  {
203 #ifdef WORKBENCH
204  if (!_WB_GetEditorAPI())
205  return;
206 
207  m_ShapeEntity = ShapeEntity.Cast(parent);
208 #endif // WORKBENCH
209  }
210 }
SCR_GeneratorBaseEntity
SCR_GeneratorBaseEntityClass GeneratorBaseEntityClass SCR_GeneratorBaseEntity(IEntitySource src, IEntity parent)
Definition: SCR_GeneratorBaseEntity.c:335
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_LineTerrainShaperGeneratorBaseEntityClass
Definition: SCR_LineTerrainShaperGeneratorBaseEntity.c:1
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
Attribute
SCR_LineTerrainShaperGeneratorBaseEntityClass SCR_GeneratorBaseEntityClass Attribute(defvalue:"0", desc:"Adjust terrain's Y around the track to fit the spline's location and clearance", category:"Terrain Sculpting")
Definition: SCR_LineTerrainShaperGeneratorBaseEntity.c:11
SCR_GeneratorBaseEntityClass
Definition: SCR_GeneratorBaseEntity.c:1
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180