1 [
EntityEditorProps(
category:
"GameScripted/Editor", description:
"Core Editor manager", color:
"251 91 0 255", dynamicBox:
true)]
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")]
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;
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;
17 [
Attribute(
desc:
"True to let the border copy terrain, creating a 'wall'.",
category:
"Virtual Area")]
18 private bool m_bFollowTerrain;
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;
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;
46 bool InArea(vector pos)
48 pos = CoordToLocal(pos);
49 float sizeX = m_vSize[0];
50 float sizeY = m_vSize[1];
51 float sizeZ = m_vSize[2];
61 float coef = Math.Sqrt(Math.Pow(sizeX, 2) + Math.Pow(sizeZ, 2)) / ((sizeX + sizeZ) / 2);
68 return vector.Distance(Vector(pos[0], 0, pos[2]), vector.Zero) < sizeX;
76 return (pos[0] > -sizeX && pos[0] < sizeX) && (pos[2] > -sizeZ && pos[2] < sizeZ);
85 void SetMaterial(ResourceName material)
98 void Generate(vector size,
int resolution)
108 void Generate(vector size,
int resolution,
bool followTerrain =
false)
114 if (resolution * 12 > 720)
116 Print(
string.Format(
"Cannot generate shape, resolution %1 is above maximum value %2!", resolution, 720 / 12), LogLevel.ERROR);
120 float sizeX = m_vSize[0];
121 float sizeY = m_vSize[1];
122 float sizeZ = m_vSize[2];
124 array<vector> positions =
new array<vector>;
134 float coef = Math.Sqrt(Math.Pow(sizeX, 2) + Math.Pow(sizeZ, 2)) / ((sizeX + sizeZ) / 2);
138 float dirStep = Math.PI2 / resolution;
139 for (
int v = 0; v < resolution; v++)
141 float dir = dirStep * v;
142 vector pos = Vector(Math.Sin(dir) * sizeX, -sizeY, Math.Cos(dir) * sizeZ);
143 positions.Insert(pos);
150 float perimeter = (sizeX + sizeZ) * 2;
151 float segmentsX = Math.Max(resolution * (sizeX / perimeter), 1);
152 float segmentsY = Math.Max(resolution * (sizeZ / perimeter), 1);
154 array<vector> corners = {
155 Vector(-sizeX, -sizeY, -sizeZ),
156 Vector(sizeX, -sizeY, -sizeZ),
157 Vector(sizeX, -sizeY, sizeZ),
158 Vector(-sizeX, -sizeY, sizeZ)
160 for (
int i = 0; i < 4; i++)
162 vector start = corners[i];
163 vector end = corners[(i + 1) % 4];
165 int segments = segmentsX;
166 if (i % 2 == 1) segments = segmentsY;
167 for (
float s = 0; s < segments; s++)
169 vector pos = vector.Lerp(start, end, s / segments);
170 positions.Insert(pos);
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)
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;
193 MeshObject meshObject = res.GetResource().ToMeshObject();
194 if (meshObject) SetObject(meshObject,
"");
203 override void _WB_GetBoundBox(inout vector min, inout vector max, IEntitySource src)