默认 Compute 暴露了大量 RhinoCommon 相关端点,也支持 Grasshopper 求解。但有些业务更适合自定义端点:
官方方式是在 Rhino 插件中注册 Compute 端点:
OnLoad 中调用 Rhino.Runtime.HostUtils.RegisterComputeEndPoint。/sdk 检查新端点是否出现。using Rhino; using Rhino.Geometry; using Rhino.PlugIns; static class MyCustomComputeFunctions { public static double Add(double x, double y, double z) { return x + y + z; } public static double AdjustedArea(Curve curve, double factor) { var amp = AreaMassProperties.Compute(curve); return amp.Area * factor; } } public class MyPlugin : PlugIn { protected override LoadReturnCode OnLoad(ref string errorMessage) { Rhino.Runtime.HostUtils.RegisterComputeEndPoint( "Rhino.CustomEndPoint", typeof(MyCustomComputeFunctions) ); return base.OnLoad(ref errorMessage); } }
注册后,访问:
http://localhost:6500/sdk
如果插件加载成功,应能在 SDK 页面看到自定义函数。
如果业务系统通过 base64 上传 DWG,不建议把完整 base64 字符串直接接入 Grasshopper/Hops 画布。更稳妥的做法是先用自定义 Compute 插件端点接收、校验、解码、落盘并导入 DWG,再把 job_id、3dm_path、图层摘要或几何结果交给 Grasshopper 自定义电池继续处理。
详细方案见:
public static,输入输出类型应能被 Compute 序列化。服务器上的 Compute 子进程是无界面 Rhino 环境。插件能在普通 Rhino 中运行,不代表一定能在 Compute 中稳定运行。
需要检查:
/sdk,确认自定义端点出现。| 方案 | 优点 | 风险 |
|---|---|---|
| Grasshopper/Hops | 设计人员容易维护;可视化;快速迭代。 | 复杂定义可维护性下降;插件依赖多;序列化开销大。 |
| 自定义 Compute 端点 | API 稳定;性能可控;易测试;适合工程化。 | 需要 C# 插件开发能力;部署和版本管理更严格。 |
实践建议:
/sdk 是否能看到自定义端点?