Error using Meshbuilder.AddRevolvedGeometry

Feb 9, 2012 at 5:51 PM

I'm receiving the following error when trying to add a revolved geometry:

Cannot implicitly convert type 'void' to 'System.Windows.Media.Media3D.Geometry3D'

My code looks like this:

private IList<Point> profile = new List<Point>();
private MeshBuilder mb = new MeshBuilder();

profile.Add(new Point(0, 0));
profile.Add(new Point(ShankRadius, 0));
profile.Add(new Point(ShankRadius, ShankLength - ChamferOffset));           
GeometryModel3D ShankGeometry = new GeometryModel3D();
ShankGeometry.Geometry = mb.AddRevolvedGeometry(profile, new Point3D(0, 0, 0), new Vector3D(0, 1, 0), 30);
ShankGeometry.Material = Materials.Hue;
ShankGeometry.BackMaterial = Materials.Hue;
vc.Add(ShankGeometry);

I get the error on the ShankGeometry.Geometry line. Any help would be greatly appreciated!

Coordinator
Feb 13, 2012 at 8:06 PM

try

mb.AddRevolvedGeometry(profile, new Point3D(0, 0, 0), new Vector3D(0, 1, 0), 30);
ShankGeometry.Geometry = mb.ToMesh();
Feb 21, 2012 at 2:10 PM

That worked perfect, thank you. One follow up question: I'm adding the revolves to a Model3D collection and want to set a different color for each revolved geometry (say I have two cylinders stacked on top of each other, one red and one blue) but for some reason it only uses the material of the last object added to the collection...do I need to clear this somehow? Should I be creating a new MeshBuilder for every revolve?

Coordinator
Feb 21, 2012 at 2:22 PM

you need a new GeometryModel3D to define objects with different materials. Geometry can be reused, but I think it is necessary to freeze (use the freeze argument in the MeshBuilder.ToMesh method).

Feb 21, 2012 at 2:28 PM

I'm creating a new GeometryModel3D every time I add to the collection:

points.Add(new Point(0, 0));
points.Add(new Point(0, 1));
points.Add(new Point(1, 1));

mb.AddRevolvedGeometry(points, new Point3D(0, 0, 0), new Vector3D(0, 1, 0), 50);
vc.Add(new GeometryModel3D(mb.ToMesh(), Materials.Gray));
points.Clear();

points.Add(new Point(0, 0));
points.Add(new Point(0, 2));
points.Add(new Point(2, 2));

mb.AddRevolvedGeometry(points, new Point3D(0, 0, 0), new Vector3D(0, 1, 0), 50);
vc.Add(new GeometryModel3D(mb.ToMesh(), Materials.Blue));
points.Clear();

Coordinator
Feb 21, 2012 at 8:47 PM

I think you should also create a new MeshBuilder every time - the add methods are not clearing the existing mesh in the MeshBuilder.