Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_TerrainMeshEntity.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Shapes", description: "Procedural box", color: "255 0 0 255", style: "box", dynamicBox: true)]
2class SCR_TerrainMeshEntityClass: GenericEntityClass
3{
4};
5
9class SCR_TerrainMeshEntity : GenericEntity
10{
11 [Attribute(category: "Terrain Mesh", defvalue: "4", params: "2 32 1", uiwidget: UIWidgets.Slider)]
12 protected int m_iResolution;
13
14 [Attribute(category: "Terrain Mesh", defvalue: "0.01", params: "0 1 0.01", uiwidget: UIWidgets.Slider)]
15 protected float m_fHeightCoef;
16
17 [Attribute(category: "Terrain Mesh")]
18 protected ref array<float> m_aHeights;
19
20 [Attribute(category: "Terrain Mesh", desc: "Material mapped on the mesh.", uiwidget: UIWidgets.ResourcePickerThumbnail, params: "emat")]
21 private ResourceName m_Material;
22
23 void Generate(array<float> heights, ResourceName material)
24 {
25 int heightsCount = heights.Count();
26 if (heightsCount != m_iResolution * m_iResolution)
27 {
28 Print(string.Format("Resolution of height values (%1) doesn't match the resolution attribute (%2)", Math.Sqrt(heightsCount), m_iResolution), LogLevel.WARNING);
29 return;
30 }
31 int resolution1 = m_iResolution - 1;
32
33 vector verts[2048];
34 float uvs[2048];
35 int indices[2048];
36 int vI, iI, uI, row, column;
37
38 //--- Get positions
39 for (int y = 0; y < m_iResolution; y++)
40 {
41 for (int x = 0; x < m_iResolution; x++)
42 {
43 verts[vI] = Vector(
44 x / resolution1 - 0.5,
45 heights[vI] * m_fHeightCoef,
46 y / resolution1 - 0.5
47 );
48 vI++;
49
50 uvs[uI] = x / resolution1; uI++;
51 uvs[uI] = 1 - y / resolution1; uI++;
52 }
53 }
54
55 /*
56 6 - 7 - 8
57 | \ | \ |
58 3 - 4 - 5
59 | \ | \ |
60 0 - 1 - 2
61
62 Vertex 1: 0-3-4
63 Vertex 2: 4-1-0
64 ...
65 */
66 for (int s = 0; s < vI - m_iResolution; s++)
67 {
68 column = s % m_iResolution;
69 if (column == resolution1)
70 {
71 row++;
72 continue;
73 }
74
75 int pointBottomLeft = s;
76 int pointBottomRight = s + 1;
77 int pointTopLeft = pointBottomLeft + m_iResolution;
78 int pointTopRight = pointBottomRight + m_iResolution;
79
80 indices[iI] = pointBottomLeft; iI++;
81 indices[iI] = pointTopLeft; iI++;
82 indices[iI] = pointTopRight; iI++;
83
84 indices[iI] = pointTopRight; iI++;
85 indices[iI] = pointBottomRight; iI++;
86 indices[iI] = pointBottomLeft; iI++;
87 }
88
89 int numVertices[] = {vI};
90 int numIndices[] = {iI};
91 string materials[] = {material};
92
93 Resource res = MeshObject.Create(1, numVertices, numIndices, materials, 0);
94 MeshObject meshObject = res.GetResource().ToMeshObject();
95 meshObject.UpdateVerts(0, verts, uvs);
96 meshObject.UpdateIndices(0, indices);
97 SetObject(meshObject,"");
98 Physics.CreateStatic(this, 0xffffffff);
99 }
100
102 {
104 }
105
106#ifdef WORKBENCH
107 override array<ref WB_UIMenuItem> _WB_GetContextMenuItems()
108 {
109 return { new WB_UIMenuItem("Generate from the current terrain", 0) };
110 }
111 override void _WB_OnContextMenu(int id)
112 {
113 WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
114 if (!worldEditor) return;
115
116 WorldEditorAPI api = _WB_GetEditorAPI();
117 if (!api) return;
118
119 BaseWorld world = api.GetWorld();
120 if (!world) return;
121
122 vector min, max, size;
123 //world.GetBoundBox(mins, maxs);
124 worldEditor.GetTerrainBounds(min, max);
125 size = max - min;
126 float stepX = size[0] / m_iResolution;
127 float stepY = size[2] / m_iResolution;
128 float heightMax = max[1] - Math.Max(min[1], 0);
129
130 int resolution1 = m_iResolution - 1;
131 bool addComma = false;
132 string value;
133 float posX, posY, posZ;
134 for (int y = 0; y < m_iResolution; y++)
135 {
136 for (int x = 0; x < m_iResolution; x++)
137 {
138 if (addComma) value += ",";
139 posX = min[0] + size[0] * x / resolution1;
140 posY = min[2] + size[2] * y / resolution1;
141 posZ = Math.Max(world.GetSurfaceY(posX, posY), 0) / heightMax;
142 value += posZ.ToString();
143 addComma = true;
144 }
145 }
146 Print(value);
147
148 api.BeginEntityAction();
149 api.SetVariableValue(api.EntityToSource(this), null, "m_aHeights", value);
150 api.EndEntityAction();
151 }
152#endif
153};
int size
ResourceName m_Material
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
void Generate()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
event array< ref WB_UIMenuItem > _WB_GetContextMenuItems()
An opportunity to append items into editor's "Entity" context menu. Do not call editor API here!
proto external WorldEditorAPI _WB_GetEditorAPI()
This returns world editor API, which is safe to use from editor events bellow.
event void _WB_OnContextMenu(int id)
User has chosen any of your menu item from editor's "Entity" menu which you have recently provided in...
Definition Math.c:13
MeshObject.
Definition MeshObject.c:34
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
ref array< float > m_aHeights
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
proto native vector Vector(float x, float y, float z)