我最终使用了Eyeshot SDK。 我尝试过的替代方案:
- OpenSCAD - 不错,但我正在寻找与代码集成而不是外部应用程序的东西
- OpenCASCADE - 它似乎可以做任何事情,但是安装和配置花费了我太多时间。在我看来太乱了
Eyeshot有一个相当简单的SDK,可以直接从C#中使用。文档很糟糕,我花了太多时间试图弄清楚它抛出的异常 - 但它有很好的代码示例。一旦你了解它,就还好了。但稍微有点贵。
我仍在处理SolidWorks导出。Eyeshot支持STL、IGEN、OBJ和STEP格式 - Solidworks可以正常处理它们,但表面不光滑(圆不是圆形而是许多多边形)。就像我说的 - 还在努力中。
无论如何,以备将来参考 - 这里有一些代码示例,创建了与我在问题中描述的类似物品(外半径是恒定的,内半径在变化)(查看其中一个示例,比如Lego,了解如何使用WorkUnit):
public class CBuildOutput : WorkUnit
{
EntityList entities = new EntityList();
private void CreatePipe()
{
double outerRadius = 60;
double chordalError = 0.05;
int slices = Utility.NumberOfSegments(outerRadius, chordalError);
Solid cyl = Solid.CreateCylinder(outerRadius, 50, slices);
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)});
CompositeCurve holeSketch = new CompositeCurve(
new Line(Point3D.Origin, new Point3D(40, 0, 0)),
innerCurve,
new Line(40, 0, 50, 0, 0, 50));
Solid hole = Solid.Revolve(holeSketch, chordalError, 0, 2 * Math.PI, Vector3D.AxisZ, Point3D.Origin, slices, true);
Solid[] final = Solid.Difference<Solid>(cyl, hole);
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();
}
}