Question

I want to make a solid box with ILNumerics. As I read in the documentation website, there is only a way to make a sphere object. I want a box (cube).

I just read this thread: ILNumerics plot a plane at specific location . Then I have an idea to make 6 plane then arrange them as a box.

But it is seems an empty box. I want a solid box. Are there any idea to do this? I will duplicate this box to make many of them for the further work.

Was it helpful?

Solution

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:

enter image description here

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top