DXF Spline importer improvements

We’d like to give people a little more visibility into the stuff that happens “behind the scenes” here, so I thought I’d share an upcoming change to LightBurn’s DXF importer (specifically for spline objects) and show you how it came to be.

This change will be included in LightBurn 1.5.00, and no, we don’t know exactly when that will be other than “when it’s ready”. :slight_smile:

First, some background:

DXF is a file format supported by many CAD programs, and they store curves in a way that’s quite different than artistic drawing programs. CorelDraw, InkScape, and Illustrator use Bezier curves, while CAD applications typically use NURBS (Non-Uniform Rational Basis Splines), which are more powerful, but more complex to program.

A NURBS curve can represent a Bezier curve, but the opposite isn’t necessarily true. Most of the information you can find on NURBS looks kind of like this:

When I read things like that, I tend to glaze over, but I managed to write the code that reads the NURBS curves into LightBurn. It first converts them to lots of small line segments, and then tries to recover curves from those, so the in-between stage looks like this:

It took a while to write, and it works, but I’ve never been very happy with it. It always felt clunky, and going from tiny segments back to curves is time consuming and imperfect.

The Problem:

One of our support folks was working with a customer who was having an issue with a DXF file - it was importing with “dents” in the shapes that weren’t in the original. If you look at the top of this, the straight bit isn’t supposed to be there:
image

The customer provided the file, and while working on solving the import issue, I noticed that the control points of the shape looked an awful lot like Bezier control points:
image

So I did a bunch of Googling, and it turns out that NURBS are a super-set of Bezier curves. They include all the stuff that Beziers can do, and more, but if you don’t use the extra fancy features that NURBS give you, there’s a way to directly translate from NURBS to Beziers. Better still, even if you use some of the fancy bits, some of those can be massaged back into Beziers too.

The Outcome:

After a couple days of reading really ugly math papers, other people’s posts, and a great article I found from an Apple developer magazine in 1996, I started coding.

A day later, LightBurn’s DXF importer can recognize and directly convert NURBS that can be represented as Beziers.

Here are a few examples of the old way (left) vs the new way (right) - Click on any of these for a larger image:

Since the process is much less a “translation” and more of a direct mapping, it doesn’t lose information like the old way did - We’re not trying to approximate the NURBS curves with our curve format; we’re just recognizing when the NURBS are really just Beziers already, and converting them directly. This means the imported curves are perfect, and doing it this way is faster than the old way.

This doesn’t work for every possible NURBS curve, but as it turns out, “NURBS that are really just Beziers” is a very common case, so this change should improve things for a lot of our users.

28 Likes