0

Error using Meshbuilder.AddRevolvedGeometry

Anonymous 10 years ago 0
This discussion was imported from CodePlex

mcrxb wrote at 2012-02-09 17:51:

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!


objo wrote at 2012-02-13 20:06:

try

mb.AddRevolvedGeometry(profile, new Point3D(0, 0, 0), new Vector3D(0, 1, 0), 30);
ShankGeometry.Geometry = mb.ToMesh();

mcrxb wrote at 2012-02-21 14:10:

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?


objo wrote at 2012-02-21 14:22:

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).


mcrxb wrote at 2012-02-21 14:28:

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();


objo wrote at 2012-02-21 20:47:

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