0
Problem with material when adding new child to the group
This discussion was imported from CodePlex
Tapir wrote at 2012-11-08 08:13:
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; }
objo wrote at 2012-11-08 08:25:
move
var builder = new HelixToolkit.Wpf.MeshBuilder();
inside your loop?
otherwise you are appending more and more boxes to your geometry...
Tapir wrote at 2012-11-08 08:31:
Works perfectly. Thanks a lot!
Customer support service by UserEcho