3 static void GetBoundsPoints(vector min, vector max, out vector points[19])
7 points[1] = Vector(max[0], min[1], min[2]);
8 points[2] = Vector(max[0], max[1], min[2]);
9 points[3] = Vector(min[0], max[1], min[2]);
13 points[5] = Vector(min[0], min[1], max[2]);
14 points[6] = Vector(min[0], max[1], max[2]);
17 points[7] = Vector(min[0], max[1], min[2]);
18 points[8] = Vector(max[0], max[1], min[2]);
22 points[10] = Vector(min[0], max[1], max[2]);
23 points[11] = Vector(min[0], min[1], max[2]);
24 points[12] = Vector(max[0], min[1], max[2]);
28 points[14] = Vector(max[0], max[1], min[2]);
29 points[15] = Vector(max[0], min[1], min[2]);
32 points[16] = Vector(max[0], min[1], max[2]);
33 points[17] = Vector(min[0], min[1], max[2]);
36 static Shape CreateBounds(vector min, vector max,
int color, ShapeFlags flags)
39 GetBoundsPoints(min, max, points);
41 return Shape.CreateLines(Color.RED, ShapeFlags.NOZBUFFER, points, 19);
52 static Resource CreateAreaMesh(array<vector> positions,
float height,
string material,
bool strechMaterial)
57 int resolution = positions.Count();
58 if (resolution == 0)
return null;
60 if (resolution * 12 > 720)
62 Print(
string.Format(
"Cannot generate shape, resolution %1 is above maximum value %2!", resolution, 720 / 12), LogLevel.ERROR);
70 float dirStep = Math.PI2 / resolution;
71 float uvsTemplate[] = {0,0, 0,1, 1,0, 1,1};
72 int vertsTemplate[] = {0,2,1, 1,2,3, 3,2,1, 1,2,0};
73 int indicesMod = 4 * resolution;
75 vector vectorUp = vector.Up * height;
76 vector pos0, pos1, pos2, pos3;
80 for (
int v = -1; v < resolution; v++)
94 if (
id < 0)
id += resolution;
96 pos3 = pos2 + vectorUp;
100 verts[vI] = pos3; vI++;
101 verts[vI] = pos2; vI++;
102 verts[vI] = pos1; vI++;
103 verts[vI] = pos0; vI++;
106 for (
int i = 0; i < 12; i++)
108 indices[iI] = (vI + vertsTemplate[iI - iIS]) % indicesMod; iI++;
111 for (
int i = 0; i < 4; i++)
115 uvs[uI] = (resolution - v + uvsTemplate[uI - uIS]) / resolution;
116 if (v == 0) uvs[uI] = uvs[uI] - 1;
120 uvs[uI] = uvsTemplate[uI - uIS];
123 uvs[uI] = uvsTemplate[uI - uIS]; uI++;
131 int numVertices[] = {vI};
132 int numIndices[] = {iI};
133 string materials[1] = {material};
135 Resource res = MeshObject.Create(1, numVertices, numIndices, materials, 0);
136 MeshObject meshObject = res.GetResource().ToMeshObject();
137 meshObject.UpdateVerts(0, verts, uvs);
138 meshObject.UpdateIndices(0, indices);
154 static void DrawCircle(vector transform[4],
float radius,
int colorOutline,
int colorPlane, ShapeFlags shapeFlags)
157 const int sectionCount = 36;
158 const int linesCount = sectionCount + 1;
159 const int trisCount = sectionCount * 3;
160 vector lines[linesCount];
161 vector tris[trisCount];
164 float sectionStep = -360 / sectionCount;
166 vector pivot = transform[3];
167 vector point = (vector.Forward * radius).Multiply4(transform);
169 for (
int i; i < sectionCount; i++)
173 tris[i*3 + 1] = point;
174 point = (Vector(sectionStep * (i + 1), 0, 0).AnglesToVector() * radius);
175 point = point.Multiply4(transform);
176 tris[i*3 + 2] = point;
180 lines[sectionCount] = point;
182 Shape.CreateLines(colorOutline, shapeFlags, lines, linesCount);
183 Shape.CreateTris(colorPlane, shapeFlags, tris, sectionCount);