2025-11-11 15:35:10 +00:00

118 lines
3.7 KiB
C#

namespace TheLabs;
public static class ShapeFactory
{
public static Mesh CreateTexturedCube()
{
float[] vertices = {
// Front face (z = +0.5)
-0.5f, -0.5f, 0.5f, 0f, 0f, // Bottom-left
0.5f, -0.5f, 0.5f, 1f, 0f, // Bottom-right
0.5f, 0.5f, 0.5f, 1f, 1f, // Top-right
-0.5f, 0.5f, 0.5f, 0f, 1f, // Top-left
// Back face (z = -0.5)
-0.5f, -0.5f, -0.5f, 1f, 0f, // Bottom-left
0.5f, -0.5f, -0.5f, 0f, 0f, // Bottom-right
0.5f, 0.5f, -0.5f, 0f, 1f, // Top-right
-0.5f, 0.5f, -0.5f, 1f, 1f, // Top-left
// Left face (x = -0.5)
-0.5f, -0.5f, -0.5f, 0f, 0f, // Bottom-left
-0.5f, -0.5f, 0.5f, 1f, 0f, // Bottom-right
-0.5f, 0.5f, 0.5f, 1f, 1f, // Top-right
-0.5f, 0.5f, -0.5f, 0f, 1f, // Top-left
// Right face (x = +0.5)
0.5f, -0.5f, -0.5f, 1f, 0f, // Bottom-left
0.5f, -0.5f, 0.5f, 0f, 0f, // Bottom-right
0.5f, 0.5f, 0.5f, 0f, 1f, // Top-right
0.5f, 0.5f, -0.5f, 1f, 1f, // Top-left
// Top face (y = +0.5)
-0.5f, 0.5f, -0.5f, 0f, 1f, // Bottom-left
0.5f, 0.5f, -0.5f, 1f, 1f, // Bottom-right
0.5f, 0.5f, 0.5f, 1f, 0f, // Top-right
-0.5f, 0.5f, 0.5f, 0f, 0f, // Top-left
// Bottom face (y = -0.5)
-0.5f, -0.5f, -0.5f, 1f, 1f, // Bottom-left
0.5f, -0.5f, -0.5f, 0f, 1f, // Bottom-right
0.5f, -0.5f, 0.5f, 0f, 0f, // Top-right
-0.5f, -0.5f, 0.5f, 1f, 0f, // Top-left
};
uint[] indices = {
// Front face
0, 1, 2,
0, 2, 3,
// Back face
4, 5, 6,
4, 6, 7,
// Left face
8, 9, 10,
8, 10, 11,
// Right face
12, 13, 14,
12, 14, 15,
// Top face
16, 17, 18,
16, 18, 19,
// Bottom face
20, 21, 22,
20, 22, 23
};
return new Mesh(vertices, indices, Mesh.VertexLayout.PosTex);
}
public static Mesh CreateColorCube()
{
float[] vertices = {
// Front face (z = +0.5)
-0.5f, -0.5f, 0.5f, 1f, 0f, 0f, 1f, // Bottom-left
0.5f, -0.5f, 0.5f, 1f, 0f, 0f, 1f, // Bottom-right
0.5f, 0.5f, 0.5f, 0f, 0f, 0f, 1f, // Top-right
-0.5f, 0.5f, 0.5f, 1f, 0f, 0f, 1f, // Top-left
// Back face (z = -0.5)
-0.5f, -0.5f, -0.5f, 1f, 0f, 1f, 1f, // Bottom-left
0.5f, -0.5f, -0.5f, 0f, 1f, 1f, 1f, // Bottom-right
0.5f, 0.5f, -0.5f, 1f, 1f, 1f, 1f, // Top-right
-0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 1f // Top-left
};
uint[] indices = {
// Front face
0, 1, 2,
2, 3, 0,
// Back face
4, 5, 6,
6, 7, 4,
// Left face
4, 0, 3,
3, 7, 4,
// Right face
1, 5, 6,
6, 2, 1,
// Top face
3, 2, 6,
6, 7, 3,
// Bottom face
4, 5, 1,
1, 0, 4
};
return new Mesh(vertices, indices, Mesh.VertexLayout.PosColor);
}
// You'd also add CreateCircle, CreateCylinder, etc.
// Your Cylinder should be ONE mesh, not 3 draw calls.
// Generate the top, bottom, and side vertices into one
// big array and use one EBO for all of it.
}