Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_LineTerrainShaperGeneratorBaseEntity.c
Go to the documentation of this file.
4
5// TODO: terrain shaping's line offset support
6class SCR_LineTerrainShaperGeneratorBaseEntity : SCR_LineGeneratorBaseEntity
7{
8 /*
9 Terrain Sculpting
10 */
11
12 [Attribute(defvalue: "0", desc: "Adjust terrain's Y around the track to fit the spline's location and clearance", category: "Terrain Sculpting")]
13 protected bool m_bSculptTerrain;
14
15 [Attribute(defvalue: "0", desc: "Priority of terrain sculpting", category: "Terrain Sculpting")]
16 protected int m_iTerrainSculptingPriority;
17
18 [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")]
19 protected float m_fTerrainSculptingPathWidth;
20
21 [Attribute(defvalue: "20", uiwidget: UIWidgets.EditBox, desc: "Width of the path fall-off", category: "Terrain Sculpting", params: "0 100 0.1")]
22 protected float m_fTerrainSculptingFallOffWidth;
23
24#ifdef WORKBENCH
25
28 protected ShapeEntity m_ShapeEntity;
29
30 protected static const ref array<string> TERRAIN_UPDATE_KEYS = {
31 "m_bSculptTerrain", "m_iTerrainSculptingPriority",
32 "m_fTerrainSculptingPathWidth", "m_fTerrainSculptingFallOffWidth",
33 };
34 protected static const string OFFSET_SHAPE_COLOUR = "1 0 1 1"; // RGBA - magic pink (#F0F)
35
36 //------------------------------------------------------------------------------------------------
37 protected override void OnShapeInitInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity)
38 {
39 super.OnShapeInitInternal(shapeEntitySrc, shapeEntity);
40
41 UpdateTerrainSimple();
42 }
43
44 //------------------------------------------------------------------------------------------------
45 protected override void OnShapeTransformInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity, array<vector> mins, array<vector> maxes)
46 {
47 super.OnShapeTransformInternal(shapeEntitySrc, shapeEntity, mins, maxes);
48
49 UpdateTerrainSimple(false);
50 }
51
52 //------------------------------------------------------------------------------------------------
53 protected override void OnShapeChangedInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity, array<vector> mins, array<vector> maxes)
54 {
55 super.OnShapeChangedInternal(shapeEntitySrc, shapeEntity, mins, maxes);
56
57 UpdateTerrainSimple(false);
58 }
59
60 //------------------------------------------------------------------------------------------------
61 override void _WB_OnInit(inout vector mat[4], IEntitySource src)
62 {
63 super._WB_OnInit(mat, src);
64
65 UpdateTerrainSimple();
66 }
67
68 //------------------------------------------------------------------------------------------------
69 override bool _WB_OnKeyChanged(BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
70 {
71 if (!super._WB_OnKeyChanged(src, key, ownerContainers, parent))
72 return false;
73
74 WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
75 if (!worldEditorAPI || worldEditorAPI.UndoOrRedoIsRestoring()) // sorry Ctrl+Z, but you cannot act here
76 return false;
77
78 if (!worldEditorAPI.AreGeneratorEventsEnabled())
79 return false;
80
81 BaseContainerTools.WriteToInstance(this, src);
82
83 if (TERRAIN_UPDATE_KEYS.Contains(key))
84 {
85 bool forceUpdate;
86 if (key == "m_bSculptTerrain")
87 {
88 if (m_bSculptTerrain)
89 {
90 forceUpdate = true;
91 }
92 else
93 {
94 worldEditorAPI.RemoveTerrainFlatterEntity(this, true);
95
96// // delete offset shape
97// IEntitySource offsetShapeSource;
98// for (int i, count = m_ParentShapeSource.GetNumChildren(); i < count; ++i)
99// {
100// offsetShapeSource = m_ParentShapeSource.GetChild(i);
101// if (offsetShapeSource.GetClassName().ToType() && offsetShapeSource.GetClassName().ToType().IsInherited(ShapeEntity))
102// {
103// worldEditorAPI.DeleteEntity(offsetShapeSource);
104// break;
105// }
106// }
107 }
108 }
109
110 UpdateTerrainSimple(forceUpdate);
111 }
112
113 return true;
114 }
115
116 //------------------------------------------------------------------------------------------------
117 override void _WB_OnCreate(IEntitySource src)
118 {
119 super._WB_OnCreate(src);
120
121 UpdateTerrainSimple();
122 }
123
124 //------------------------------------------------------------------------------------------------
125 override void _WB_OnParentChange(IEntitySource src, IEntitySource prevParentSrc)
126 {
127 super._WB_OnParentChange(src, prevParentSrc);
128
129 WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
130 if (!worldEditorAPI)
131 return;
132
133 if (m_ParentShapeSource)
134 UpdateTerrainSimple(true);
135 else
136 worldEditorAPI.RemoveTerrainFlatterEntity(this, true);
137 }
138
139 //------------------------------------------------------------------------------------------------
140 override void _WB_OnDelete(IEntitySource src)
141 {
142 super._WB_OnDelete(src);
143
144 WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
145 if (!worldEditorAPI)
146 return;
147
148 worldEditorAPI.RemoveTerrainFlatterEntity(this, true);
149 }
150
151 //------------------------------------------------------------------------------------------------
154 protected void UpdateTerrainSimple(bool forceUpdate = false)
155 {
156 if (!m_bSculptTerrain || !m_ParentShapeSource)
157 return;
158
159 WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
160 if (!worldEditorAPI)
161 return;
162
163// IEntitySource offsetShapeSource;
164// for (int i, count = m_ParentShapeSource.GetNumChildren(); i < count; ++i)
165// {
166// offsetShapeSource = m_ParentShapeSource.GetChild(i);
167// if (offsetShapeSource.GetClassName().ToType() && offsetShapeSource.GetClassName().ToType().IsInherited(ShapeEntity))
168// break;
169//
170// offsetShapeSource = null;
171// }
172//
173// if (offsetShapeSource)
174// worldEditorAPI.DeleteEntity(offsetShapeSource);
175//
176// offsetShapeSource = worldEditorAPI.CreateEntity(m_ParentShapeSource.GetClassName(), string.Empty, 0, m_ParentShapeSource, vector.Zero, vector.Zero);
177// if (!offsetShapeSource)
178// return;
179//
180// worldEditorAPI.SetVariableValue(offsetShapeSource, null, "LineColor", OFFSET_SHAPE_COLOUR);
181// foreach (int i, vector anchorPoint : m_ShapeNextPointHelper.GetAnchorPoints())
182// {
183// worldEditorAPI.CreateObjectArrayVariableMember(offsetShapeSource, null, "Points", "ShapePoint", i);
184// worldEditorAPI.SetVariableValue(offsetShapeSource, { new ContainerIdPathEntry("Points", i) }, "Position", string.Format("%1 %2 %3", anchorPoint[0], anchorPoint[1], anchorPoint[2]));
185// }
186//
187// ShapeEntity shapeEntity = ShapeEntity.Cast(worldEditorAPI.SourceToEntity(offsetShapeSource));
188 ShapeEntity shapeEntity = ShapeEntity.Cast(worldEditorAPI.SourceToEntity(m_ParentShapeSource));
189 if (shapeEntity)
190 {
191 array<vector> updateMins = {};
192 array<vector> updateMaxes = {};
193// shapeEntity.GetAllInfluenceBBoxes(offsetShapeSource, updateMins, updateMaxes);
194 shapeEntity.GetAllInfluenceBBoxes(m_ParentShapeSource, updateMins, updateMaxes);
195
196 UpdateTerrain(shapeEntity, forceUpdate, updateMins, updateMaxes);
197 }
198
199// worldEditorAPI.DeleteEntity(offsetShapeSource);
200 }
201
202 //------------------------------------------------------------------------------------------------
203 // where everything happens
208 protected void UpdateTerrain(notnull ShapeEntity shapeEntity, bool forceUpdate, notnull array<vector> updateMins, notnull array<vector> updateMaxes)
209 {
210 m_ShapeEntity = shapeEntity;
211
212 if (!m_bSculptTerrain)
213 return;
214
215 WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
216 if (!worldEditorAPI)
217 return;
218
219 array<vector> points = {};
220 shapeEntity.GenerateTesselatedShape(points);
221
222 if (points.Count() < 2)
223 {
224 Print("Terrain Flattener requires a shape with at least two points", LogLevel.WARNING);
225 return;
226 }
227
228 vector firstPoint = shapeEntity.CoordToParent(points[0]);
229 vector mins = firstPoint;
230 vector maxs = firstPoint;
231
232 foreach (vector point : points)
233 {
234 vector pos = shapeEntity.CoordToParent(point);
235 for (int i = 0; i < 3; ++i)
236 {
237 float val = pos[i];
238
239 if (val < mins[i])
240 mins[i] = val;
241
242 if (val > maxs[i])
243 maxs[i] = val;
244 }
245 }
246
247 worldEditorAPI.AddTerrainFlatterEntity(this, mins, maxs, m_iTerrainSculptingPriority, m_fTerrainSculptingPathWidth * 0.5, m_fTerrainSculptingFallOffWidth, forceUpdate, updateMins, updateMaxes);
248 }
249
250 //------------------------------------------------------------------------------------------------
251 // constructor
252 protected void SCR_LineTerrainShaperGeneratorBaseEntity(IEntitySource src, IEntity parent)
253 {
254 if (!_WB_GetEditorAPI())
255 return;
256
257 m_ShapeEntity = ShapeEntity.Cast(parent);
258 }
259#endif // WORKBENCH
260}
override void _WB_OnInit(IEntity owner, inout vector mat[4], IEntitySource src)
override bool _WB_OnKeyChanged(IEntity owner, BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
Any property value has been changed. You can use editor API here and do some additional edit actions ...
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
enum EVehicleType IEntity
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
void OnShapeTransformInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity, array< vector > mins, array< vector > maxes)
void OnShapeInitInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity)
void OnShapeChangedInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity, array< vector > mins, array< vector > maxes)