LBRN2 File Documentation

I’m trying to edit the LBRN2 files with a Python script by parsing the XML.
My goal is to apply an X and Y translation and then a rotation, all using the top right corner as a reference point. My files are coming in as DXF which I’m importing (with group on import) and then saving as LBRN2. I’m using LightBurn 0.9.24

So far I’ve found that I can change the XForm values on the group to apply rotations and translations, even skew, but I’m getting a bit stuck as it’s also flipping my files and my results are not yet predictable and consistent.

Can you please explain the 6 values in the XForm tag for me, by any chance? I think I can get the rest of the way with a little explanation on those.

Here’s what I’ve got so far:
Import DXF and then save as LBRN2. Here’s a snippet of how the XML looks:

</CutSetting>
< Shape Type="Group" CutIndex="0">
    < XForm>-1 0 0 -1 320 0</XForm>
    < Children>
        < Shape Type="Path" CutIndex="4" VertID="20" PrimID="12">
            < XForm>1 0 0 1 0 0</XForm>
            < VertList>V303.50201 -112.423c0x1c1x1V303.46301 -112.423c0x1c1x1V303.35999

I can change values in the area to successfully apply speed, power, and priority based on the index.
I can set the XForm values based on this formula:
{cos_theta} {sin_theta} {sin_theta} {-cos_theta} {x} {y}
That does the translation to X and Y with a rotation of theta (in radians) but it also flips the job through the vertical axis.

I think the XForm might be in reference to the top left corner?

I can see that the XForm values get applied in a hierarchy to all objects below them. It looks like there is a reference frame that the VertList points are in reference to, which is based on how the DXF file is set up. And then the reference frames get all the XForm translations above them, with the values 1 0 0 1 0 0 causing no translation.

This post was helpful for the vector encoding, but I’m after some more info on the XForm values.

Thanks for the info

The values are m11, m12, m21, m22, m31, m32 - in that order.
Since you are already working with matrix transforms, I’m going to assume you know what I mean by that :slight_smile:
As for the origin - yes, all the paths and the XForm is in reference to top left, however look back at the top of the file:

MirrorX and MirrorY define what origin was used to create the file. In the case of this example, it’s top left. So if you had:
MirrorX="False" MirrorY="True" is bottom left.

Whereas MirrorX="True" MirrorY="False" is top right.

So these flips are further applied to the contents of the file to get things right.
Hopefully that makes a little more sense.

Thanks. I had some further issues with my DXF files as I found the origin point is not always in the corner of the DXF file as I had expected. I was able to create the transforms and cut settings I require and edit them into the XML of the lbrn2 file successfully.

For completeness, here is what worked for me:

My laser is set with the origin at the top right corner and my lbrn2 files have the following as the first two lines (note: I’m adding spaces after the < to make it display correctly on the forum):

< ?xml version="1.0" encoding="UTF-8"?>
< LightBurnProject AppVersion="0.9.24" FormatVersion="1" MaterialHeight="0" MirrorX="True" MirrorY="True">

UIPrefs correspond to the selections made in the Optimization Settings dialog, with the ByLayer, ByGroup, ByPriority showing their selected order number (starting at 0) or showing -1 if not included.

CutSetting include an entry for each cut layer (colour) available in the file. The index value is the one that is important as it is referenced in the shapes data later to connect the shape with the colour/layer.

Shape is a hierarchy of groups, paths, polygons and rectangles (Rect). Objects will have properties that define them, such as a rectangle (Rect) has width (W, height (H) and corner radius (Cr) values with a reference point at the centre.

Each shape object or group has an XForm value that corresponds to a transformation matrix that is applied to all the items below that in the hierarchy. (For example, a rectangle in a group will first have the properties of the rectangle applied, then have the XForm of the rectangle applied, then have the XForm of the group it is in applied).

The XForm can be translated into an affine transformation using this layout:

"""
Translation matrix is encoded in <XForm> values as follows:

<XForm>a b c d e f</XForm>

⎡x'⎤   ⎡a c e⎤ ⎡x⎤
⎢y'⎥ = ⎢b d f⎥ ⎢y⎥
⎣1 ⎦   ⎣0 0 1⎦ ⎣1⎦

where x and y are the original coordinates and x’ and y’ are the transformed coordinates.

As an example, you can apply a translation of x and y with:

⎡1 0 x⎤
⎢0 1 y⎥
⎣0 0 1⎦

and a rotation of t radians with:

⎡cos(t) -sin(t)  0⎤
⎢sin(t)  cos(t)  0⎥
⎣    0      0    1⎦

and a reflection along the vertical axis with

⎡-1 0 0⎤
⎢0  1 0⎥
⎣0  0 1⎦

These can also be combined with matrix multiplication rules into a single matrix with multiple actions. Look at the wikipedia page for more examples.

Lastly, the VertList is explained by Oz here but to add to that description:

VertList is a list of vertices that can be split into chunks with this form
(replace the braces with numerical values in mm):
V{x coordinate} {y coordinate}{control point info}
Note there is a space between the x and y coordinate, but no space between vertices so split them at the V.

The control point info depends on if the point is a line or a bezier curve and can include some or all of this info:
c0x{left handle x point}c0y{left handle y point}c1x{right handle x point}c1y{right handle y point}S

For example, a straight line will look like this with its control point info:
V10 20c0x1c1x1
and a bezier curve from a point could look like this:
V10 20c0x10c0y24c1x10c1y12S
The presence of the S at the end indicates it is a smooth line at the point.

PrimList is a list of lines that join the corresponding vertices with this form:
{line type}{start} {end}
Where start and end are integers corresponding to the position of their vertices in the VerList, and the line type is a letter corresponding to:
B = bezier curve
L = straight line
Learn how to draw and display those curves and control points here.

Finally, I’d recommend creating some test files, saving them, and then opening the lbrn2 files with a text editor to see the XML structure. Make changes and then see what effect those changes have. Worst case is that the file will not open with an error message.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.