我最终使用了 Eyeshot SDK。我尝试过的替代方案:
- OpenSCAD - 很好,但我一直在寻找与代码集成的东西,而不是作为外部应用程序
- OpenCASCADE - 它似乎可以做任何事情,但我花了太多时间来安装和配置。在我看来太乱了
Eyeshot 有一个非常简单的 SDK,可以直接从 C# 中使用。文档很糟糕,我花了太多时间试图找出它抛出的异常 - 但它有很好的代码示例。一旦你了解它就可以了。不过有点贵。
我仍在处理 SolidWorks 导出。 Eyeshot 支持 STL、IGEN、OBJ 和 STEP - Solidworks 可以处理它们,但表面不光滑(圆不是圆,只是许多多边形)。正如我所说 - 仍在工作。
无论如何,供将来参考 - 这是一些代码示例,它们创建的内容与我在问题中描述的内容相似(外半径不变,内半径变化)(查看其中一个示例,如乐高,了解如何使用工作单元):
public class CBuildOutput : WorkUnit
{
EntityList entities = new EntityList();
private void CreatePipe()
{
double outerRadius = 60;
// First decide on accuracy
double chordalError = 0.05;
int slices = Utility.NumberOfSegments(outerRadius, chordalError);
// Make a cylinder, the cut a hole from it
// 1. Cylinder
Solid cyl = Solid.CreateCylinder(outerRadius, 50, slices);
// 2. Define the hole curve
Curve innerCurve = new Curve(2, new List<Point3D>() {
new Point3D(outerRadius - 20, 0, 0),
new Point3D(outerRadius - 25, 0, 10),
new Point3D(outerRadius - 15, 0, 20),
new Point3D(outerRadius - 25, 0, 30),
new Point3D(outerRadius - 15, 0, 40),
new Point3D(outerRadius - 20, 0, 50)});
// 3. Create an extrude-able sketch
CompositeCurve holeSketch = new CompositeCurve(
new Line(Point3D.Origin, new Point3D(40, 0, 0)),
innerCurve,
new Line(40, 0, 50, 0, 0, 50));
// 4. Create a hole solid
Solid hole = Solid.Revolve(holeSketch, chordalError, 0, 2 * Math.PI, Vector3D.AxisZ, Point3D.Origin, slices, true);
// 5. Cut the hole from the cylinder
Solid[] final = Solid.Difference<Solid>(cyl, hole);
// entities.Add(cyl, 0, Color.Red);
// entities.Add(hole, 0, Color.Red);
entities.Add(final[0], 0, Color.Red);
}
protected override void DoWork(System.ComponentModel.BackgroundWorker worker, System.ComponentModel.DoWorkEventArgs doWorkEventArgs)
{
CreatePipe();
}
protected override void WorkCompleted(ViewportLayout viewportLayout)
{
viewportLayout.Entities = entities;
viewportLayout.ZoomFit();
// viewportLayout.WriteIGES("model.iges", false);
}
}