Problem with material when adding new child to the group

Nov 8, 2012 at 7:13 AM

I have a problem with adding new child to group. Regardless of which material i use, all figures are filled with color of the last added one. Any idea how to solve this problem?

        static private Model3DGroup DrawLayers(int noOfLayers)
        {
            Material materialFiber = new DiffuseMaterial(new SolidColorBrush(Colors.Lime));
            Material materialCopper = new DiffuseMaterial(new SolidColorBrush(Colors.Orange));
          
            HelixToolkit.Wpf.MeshBuilder builder = new HelixToolkit.Wpf.MeshBuilder();
            Model3DGroup group = new Model3DGroup();

            for (int i = 0; i < noOfLayers; i++)
            {
                if (i == 0)
                {
                    builder.AddBox(new Point3D(0, 0, 0), 15, 15, 1);
                }
                else
                {
                    builder.AddBox(new Point3D(0, 0, 2*i), 15, 15, 1);
                }

                MeshGeometry3D layer = builder.ToMesh();

                if (i % 2 == 0)
                {
                    GeometryModel3D model = new GeometryModel3D() { Geometry = layer, Material = materialFiber, BackMaterial = materialFiber };
                    group.Children.Add(model);
                }
                else
                {
                    GeometryModel3D model = new GeometryModel3D() { Geometry = layer, Material = materialCopper, BackMaterial = materialCopper };
                    group.Children.Add(model);
                }
            }
            return group;
        }

Coordinator
Nov 8, 2012 at 7:25 AM

move

var builder = new HelixToolkit.Wpf.MeshBuilder();

inside your loop?

otherwise you are appending more and more boxes to your geometry...

Nov 8, 2012 at 7:31 AM

Works perfectly. Thanks a lot!