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;
15 protected int m_iTerrainSculptingPriority;
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;
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;
27 protected ShapeEntity m_ShapeEntity;
29 protected static ref array<string> s_aTerrainUpdateKeys = {
30 "m_bSculptTerrain",
"m_iTerrainSculptingPriority",
31 "m_fTerrainSculptingPathWidth",
"m_fTerrainSculptingFallOffWidth",
35 protected override void OnShapeInitInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity)
37 super.OnShapeInitInternal(shapeEntitySrc, shapeEntity);
39 UpdateTerrainSimple();
43 protected override void OnShapeTransformInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity, array<vector> mins, array<vector> maxes)
45 super.OnShapeTransformInternal(shapeEntitySrc, shapeEntity, mins, maxes);
47 UpdateTerrain(shapeEntity,
false, mins, maxes);
51 protected override void OnShapeChangedInternal(IEntitySource shapeEntitySrc, ShapeEntity shapeEntity, array<vector> mins, array<vector> maxes)
53 super.OnShapeChangedInternal(shapeEntitySrc, shapeEntity, mins, maxes);
55 UpdateTerrain(shapeEntity,
false, mins, maxes);
59 override void _WB_OnInit(inout vector mat[4], IEntitySource src)
61 super._WB_OnInit(mat, src);
63 UpdateTerrainSimple();
67 override bool _WB_OnKeyChanged(BaseContainer src,
string key, BaseContainerList ownerContainers, IEntity parent)
69 super._WB_OnKeyChanged(src, key, ownerContainers, parent);
71 WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
72 if (!worldEditorAPI.AreGeneratorEventsEnabled())
75 BaseContainerTools.WriteToInstance(
this, src);
77 if (s_aTerrainUpdateKeys.Contains(key))
80 if (key ==
"m_bSculptTerrain")
85 worldEditorAPI.RemoveTerrainFlatterEntity(
this,
true);
88 UpdateTerrainSimple(forceUpdate);
95 override void _WB_OnCreate(IEntitySource src)
97 super._WB_OnCreate(src);
99 UpdateTerrainSimple();
103 override void _WB_OnParentChange(IEntitySource src, IEntitySource prevParentSrc)
105 super._WB_OnParentChange(src, prevParentSrc);
107 WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
111 if (m_ParentShapeSource)
112 UpdateTerrainSimple(
true);
114 worldEditorAPI.RemoveTerrainFlatterEntity(
this,
true);
118 override void _WB_OnDelete(IEntitySource src)
120 super._WB_OnDelete(src);
122 WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
126 worldEditorAPI.RemoveTerrainFlatterEntity(
this,
true);
131 protected void UpdateTerrainSimple(
bool forceUpdate =
false)
133 if (!m_bSculptTerrain || !m_ParentShapeSource)
136 WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
140 m_ShapeEntity = ShapeEntity.Cast(worldEditorAPI.SourceToEntity(m_ParentShapeSource));
144 array<vector> updateMins = {};
145 array<vector> updateMaxes = {};
146 m_ShapeEntity.GetAllInfluenceBBoxes(m_ParentShapeSource, updateMins, updateMaxes);
148 UpdateTerrain(m_ShapeEntity, forceUpdate, updateMins, updateMaxes);
153 protected void UpdateTerrain(notnull ShapeEntity shapeEntity,
bool forceUpdate, notnull array<vector> updateMins, notnull array<vector> updateMaxes)
155 if (!m_bSculptTerrain)
158 WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
163 shapeEntity.GetWorldTransform(mat);
165 array<vector> points = {};
166 shapeEntity.GenerateTesselatedShape(points);
168 if (points.Count() < 2)
170 Print(
"Terrain Flattener requires a shape with at least two points", LogLevel.WARNING);
174 vector firstPoint = points[0].Multiply4(mat);
175 vector mins = firstPoint;
176 vector maxs = firstPoint;
179 foreach (vector point : points)
181 pos = point.Multiply4(mat);
182 for (
int i = 0; i < 3; i++)
194 worldEditorAPI.AddTerrainFlatterEntity(
this, mins, maxs, m_iTerrainSculptingPriority, m_fTerrainSculptingPathWidth * 0.5, m_fTerrainSculptingFallOffWidth, forceUpdate, updateMins, updateMaxes);
201 protected void SCR_LineTerrainShaperGeneratorBaseEntity(IEntitySource src, IEntity parent)
204 if (!_WB_GetEditorAPI())
207 m_ShapeEntity = ShapeEntity.Cast(parent);