Most Simple Solution
In the (barely documented) ILNumerics.Drawing.Shapes
class you can find an UnitCubeFilled
shape and its wireframe version:
private void ilPanel1_Load(object sender, EventArgs e) {
ilpanel1.Scene.Camera.Add(Shapes.UnitCubeFilled);
ilpanel1.Scene.Camera.Add(Shapes.UnitCubeWireframe);
ilpanel1.Scene.First<ILTriangles>().AutoNormals = false;
ilpanel1.Configure();
}
Note, all edges of the cube share the only 8 vertices in the shape. Therefore, the lighting normals are shared and interpolated between all edges which would cause any lighting to look unnatural. Thats why I deactivated the light by disabling the auto normals creation.
You can easily reuse those shapes - their storage is shared by ILNumerics under the hood. In large setups you would place several of these shapes under individual ILGroup
nodes. The groups are used in order to relocate and rotate the shapes accordingly.
Advanced Solution
The Shapes.UnitCubeFilled
focusses on a cheap setup. If you need individual colors for the sides or a better lighting, you need to assemble the cube from individual vertices for each edge. Basically, what one would do:
- Start with a fresh
ILTriangles
shape
- Give it 24 vertices: 4 for each side
- Create 24 color entries with individual color information for the sides
A simple example could look as follows:

This is the code for the front and right side. The other sides are left as an exercise... ;)
ilpanel1.Scene.Camera.Add(new ILTriangles("tri")
{
Positions = new float[,] {
// front side
{0,0,0},{1,0,0},{1,1,0},
{0,0,0},{1,1,0},{0,1,0},
// right side
{1,0,0},{1,0,-1},{1,1,-1},
{1,0,0},{1,1,-1},{1,1,0},
},
Colors = new float[,] {
// front side
{0,0,1},{0,0,1},{0,0,1},
{0,0,1},{0,0,1},{0,0,1},
// right side
{0,1,0},{0,1,0},{0,1,0},
{0,1,0},{0,1,0},{0,1,0},
}
});
ilpanel1.Configure();