0

3d cube with colored cells

TheInevitable360 4 months ago updated by anonymous 3 months ago 3

I am working on a code to build a 3D cube that has mesh/cell in each direction and each cell has its own color. now i sue this method which produces exactly what i want:

private void BuildCustomCube22(int x, int y, int z)
{
    double cubeSize = 1.0; // Size of each cube cell

    Random random = new Random();

    var modelGroup = new Model3DGroup();

    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            for (int k = 0; k < z; k++)
            {
                var position = new Point3D(
                    i * cubeSize + cubeSize / 2,
                    j * cubeSize + cubeSize / 2,
                   k * cubeSize + cubeSize / 2);

               // Generate a random color for each cube
               Color color = Color.FromRgb((byte)random.Next(256), (byte)random.Next(256),
               (byte)random.Next(256));

               var cube = new BoxVisual3D
               {
                   Center = position,
                   Width = cubeSize,
                   Height = cubeSize,
                   Length = cubeSize,
                  Material = MaterialHelper.CreateMaterial(color),

                };

               // Add the cube to the model group
               modelGroup.Children.Add(cube.Model);
           }
       }
   }

    // Add the model group to the viewport
    viewport.Children.Add(new ModelVisual3D { Content = modelGroup });
}

and the result is:

Image 195

The issue is when i increase mesh like 100*100*100, i get very poor performance like not being able to easily zoom in/out or move object around. I wonder how can i achieve the result i want event with high number of cells with no lag.

P.S: somebody told me: You are making way too many models. You can try to use Helix toolkit sharpdx version with instancing rendering capability

but i don't know if it can solve my issue and i don't know how to implement it. 

-1

I have a WPF application in which i want to show a cube which has colored cells. so i used the Helix Toolkit with following code:Colored hexagons stock photo containing Slope unblocked 3d and abstract. This 4500 x 3000 px photos misc stock photo features cell, color, and concept.The 3D cube represents the 3D color space perceived by a normal trichromat. Left to right: We show the 2D plane of perceivable colors for Protanopes, ...... cube into two-dimensional space. Parallel projection envelopes of the tesseract (each cell is drawn with different color faces, inverted cells are undrawn).