0

Helixtoolkit BoxVisual3D

Anonymous 10 years ago updated by anonymous 4 years ago 0
This discussion was imported from CodePlex

Irfan_Maulana wrote at 2014-01-07 14:37:

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?

objo wrote at 2014-01-07 22:51:

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

AnotherBor wrote at 2014-01-10 07:51:

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?

objo wrote at 2014-01-10 09:03:

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!

AnotherBor wrote at 2014-01-10 09:15:

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?

objo wrote at 2014-01-10 09:38:

Yes, I think this is a good idea. Can you add an issue on this?

AnotherBor wrote at 2014-01-10 09:54:

Sure, will do.