使用 openNURBS 导出的曲线是无效的曲线

我在尝试使用 openNURBS 库将我们自己的数据转换成 3dm 格式,但发现导出的曲线在 rhino 中打开显示“无效的曲线”

for(MyBSplineCurve* pCurve : curves) {
    if(pCurve; int pntCnt = pCurve->CtrlPoints().size()) {
        ON_NurbsCurve* rhinoCurve = new ON_NurbsCurve(
            3, // dimension
            true, // true if rational
            pCurve->Degree()+1,     // order = degree+1
            pntCnt      // number of control vertices
        );
        for(int j = 0; j < pntCnt; j++) {
            ON_3dPoint pt(pCurve->CtrlPoints()[j].GetPos().x(), 
                          pCurve->CtrlPoints()[j].GetPos().y(), 
                          pCurve->CtrlPoints()[j].GetPos().z());
            rhinoCurve->SetCV(j, pt);
        }
        // ON_NurbsCurve's have order+cv_count-2 knots
        int nKnots = pCurve->KnotVec().GetCount();
        lxd::print("order:{}, cv:{}, knots:{}\n", pCurve->Degree() + 1, pntCnt, nKnots);
        for(int k = 1; k < nKnots - 1; k++) {
            rhinoCurve->SetKnot(k, pCurve->KnotVec().GetKnots()[k]);
        }
        auto name = fmt::format(L"RefCurve {}_{}", pair.first, w++);
        model.AddManagedModelGeometryComponent(
            rhinoCurve,
            Internal_CreateManagedAttributes(layerRefCurve[i], name.c_str())
        );
    }
}

85RT_P1_20220915160131_15.3dm (328.1 KB)

不同曲线 order, cv, knots 数量对比:

order:4, cv:153, knots:157
order:4, cv:159, knots:163
order:4, cv:146, knots:150
order:4, cv:147, knots:151
order:4, cv:142, knots:146
order:4, cv:145, knots:149
order:4, cv:147, knots:151
order:4, cv:146, knots:150
order:4, cv:142, knots:146
order:4, cv:145, knots:149
order:4, cv:144, knots:148
order:4, cv:140, knots:144
order:4, cv:146, knots:150
order:4, cv:145, knots:149
order:4, cv:142, knots:146
order:4, cv:144, knots:148
order:4, cv:149, knots:153
order:4, cv:150, knots:154
order:4, cv:142, knots:146
order:4, cv:146, knots:150
order:4, cv:148, knots:152
order:4, cv:148, knots:152
order:4, cv:146, knots:150
order:4, cv:154, knots:158
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190
order:4, cv:186, knots:190

这里有个帖子你可以参考,或者跟帖提问:

原因在于 Knots 个数的定义在 OpenGL 和 openNURBS 中不一样:

// in openNURBS
nKnots = nCV + order - 2
// in OpenGL
nKnots = nCV + order