Helixtoolkit BoxVisual3D

Jan 7, 2014 at 1:37 PM
hi everyone i want to create cubes that represented as point3D(x,y,z) and the value is represented as color..
I have tried to create some cubes with height=21cube width = 21 cube and length 21 cube, but the result is not quite good
because when I navigate the cubes, the motion of the cubes is so lag, (the code is shown below).
public MainWindow()
        {
            InitializeComponent();
            
            // Upper 
            for (double i = -10; i <= 12; i = i + 1.1)
            {
                for (double j = -10; j <= 12; j = j + 1.1)
                {

                    BoxVisual3D box = new BoxVisual3D() { Center = new Point3D() { X = i, Y = j, Z = 12 }, Fill = Brushes.DarkKhaki };
                    view3DHelix.Children.Add(box);
 

                }
            }
            //Bottom 
            for (double i = -10; i <= 12; i = i + 1.1)
            {
                for (double j = -10; j <= 12; j = j + 1.1)
                {

                    BoxVisual3D box = new BoxVisual3D() { Center = new Point3D() { X = i, Y = j, Z = -10 }, Fill = Brushes.DarkKhaki };
                    view3DHelix.Children.Add(box);
                }
            }

            //Right
            for (double i = -10; i <= 12; i = i + 1.1)
            {
                for (double k = -8.9; k <= 12; k = k + 1.1)
                {

                    BoxVisual3D box = new BoxVisual3D() { Center = new Point3D() { X = i, Y = 12, Z = k }, Fill = Brushes.DarkKhaki };
                    view3DHelix.Children.Add(box);
                }
            }
            //Left
            for (double i = -10; i <= 12; i = i + 1.1)
            {
                for (double k = -8.9; k <= 10.9; k = k + 1.1)
                {

                    BoxVisual3D box = new BoxVisual3D() { Center = new Point3D() { X = i, Y = -10, Z = k }, Fill = Brushes.DarkKhaki };
                    view3DHelix.Children.Add(box);
                }
            }
            //Front
            for (double j = -8.9; j <= 10.9; j = j + 1.1)
            {
                for (double k = -8.9; k <= 12; k = k + 1.1)
                {

                    BoxVisual3D box = new BoxVisual3D() { Center = new Point3D() { X = 12, Y = j, Z = k }, Fill = Brushes.DarkKhaki };
                    view3DHelix.Children.Add(box);
                }
            }
            //Behind
            for (double j = -8.9; j <= 10.9; j = j + 1.1)
            {
                for (double k = -8.9; k <= 12; k = k + 1.1)
                {

                    BoxVisual3D box = new BoxVisual3D() { Center = new Point3D() { X = -10, Y = j, Z = k }, Fill = Brushes.DarkKhaki };
                    view3DHelix.Children.Add(box);
                }
            }

        }
anyone have any idea for a better result?
Coordinator
Jan 7, 2014 at 9:51 PM
You can improve performance by grouping all cubes that share the same material in a GeometryModel3D. Use the HelixToolkit.Wpf.MeshBuilder to create a MeshGeometry3D of the cubes. You can then group all the models in a Model3DGroup and add it to a ModelVisual3D.

I also recommend reading
http://msdn.microsoft.com/en-us/library/bb613553(v=vs.110).aspx
http://blogs.msdn.com/b/johngossman/archive/2005/10/13/480748.aspx
Jan 10, 2014 at 6:51 AM
Something just came to my mind.
What if I add cubes (by add rectangular mesh or other method) to one MeshBuilder, add a linear gradient brush based material to the model and assign texture coordinates to every single cube in a way to apply the color I need?
It all would then count as one mesh, but "separate" cubes could have different colors.
I wonder if that would work?
Coordinator
Jan 10, 2014 at 8:03 AM
Yes, this works and I think performance should be much better. I have not tested if there is a performance hit related to assigning texture coordinates or not and gradient brush vs. solid color brush - that would be interesting to know!
Jan 10, 2014 at 8:15 AM
If it really works nice, maybe adding single texture coordinate to all convenience calls as optional parameter would be a nice way to assign different colors to elements belonging to the same mesh?

Then we would have calls like MeshBuilder.AddTube( {point1, point2}, width, segments, cap, uniformTextureCoordForTheWholeTubeMesh) , what do you think?
Coordinator
Jan 10, 2014 at 8:38 AM
Yes, I think this is a good idea. Can you add an issue on this?
Jan 10, 2014 at 8:54 AM
Sure, will do.