Creating Lego models with LDraw, Part 4: Advanced editing and Sketchfab uploads

Hello again everybody!

First and foremost, I would like to sincerely apologize for the delay in publishing this post: unforeseen circumstances, work and life have taken over and I've had much less time on hand to spare.

I am eager to share with you the last (sadly) and most valuable tidbits of information regarding LDraw Lego model editing and some of the hidden (or not so obvious) secrets of how to get by in manipulating a model and on how to share your builds using what I consider to be the find of the decade: Sketchfab.

I hope you've had plenty of time to play around with some of the editors and setup requirements to get yourself to a comfortable level of understanding of how things work, without having to explicitly spell out 'who does what'.

So, one assumes you will get the point in understanding the general indications in matter of relative and absolute transformations, basic parts and model positioning and LDraw file structures. If not, please refresh your memory (and possibly skills) after reviewing what was stated in the previous article from this series.

Laying out the requirements:

  • One fully set up LDraw editing suit of your choice, complete with parts database (and configuration of your liking for shortcuts, preferences and whatnot)
  • One UTF8 locale compatible text editor of your choice (my Linux people know what I'm talking about. If not go check out Notepad++ and install it)
  • One WebGL compatible web browser (preferably Google's Chrome, or Mozilla's Firefox - updated or latest revision installed)
  • One mean desire to make bad-ass models and show them to the world using the Sketchfab platform ^_^

Advanced editing:

The use of the term 'advanced editing' depicts any form of non-standard method used to create or modify an LDraw model. The obvious method is to use one of the editors mentioned in the previous posts and manually adjusting the spatial positioning and other obvious properties attributed to a part, such as colour, grouping or array assignment for duplication purposes, with the use of an interface.

When an editor does not have all the appropriate features already embedded into it to help us manage such properties, or does so in a way that cannot answer the user's or creator's way of handling a given workflow, you can also refer to 'advanced editing' as new measures or tools that are built, created or added to help with such needs.

The first thing one can look to understand how advanced editing works and how to go about in making changes more efficiently is to probe and understand the contents of the model file itself (and the information it contains).

Handling and modifying the information that translates into the model we see is a means of such editing measures that vary and expand into a multitude of techniques, one of which will be discussed later on - Keep in mind that whatever you are creating, rather than simply take the result of the application or editor's processing as the final result you are searching for, there is surely another way to go about things.

What you see vs. what it really is...

Let's use a less complex example as a model to make you understand - both image previews depict one and the same thing: a red 2x4 lego brick.

On the left, the editor view - on the right, the actual data contents of what the model file is and what parameters are being edited by the operations submitted via the editor's interface and tools.

All this being said, an LDraw model file (ldr or mpd), is an assembly of relative and absolute vector coordinates attributed to a part's identity or reference number...

Let's analyze the contents of the simple model shown in the example above:

0 !LEOCAD MODEL AUTHOR Nathanel Titane - - Copyright 2003-2014
0 !LEOCAD MODEL BACKGROUND COLOR 0.870588 0.870588 0.870588
1 4 0 -24 0 1 0 0 0 1 0 0 0 1 3001.DAT

The LDraw specification defines the way the file and data content should be built to be universal and cross compatible for all editors and viewers. (The full LDraw file specification is available for consultation here.)

The first character on each line defines the attribution of either the line being optional or non compliant to the specification [0] or and actual part data or sub-file reference for a program such as an editor, viewer or renderer to parse to be able to display and manipulate the model [1].

Line 1: Header line (META) as optionally described by the LeoCAD editor, attributing the model's AUTHOR tag information as described within the preferences panel of the application.

Line 2: Model BACKGROUND COLOR parameter (META), that can be set individually for each and every model created using the program.

Line 3: The actual data corresponding to that red 2x4 Lego brick we set into the 3D virtual editor plane and is described as follows:

flag color x y z a b c d e f g h i part

  1. 'x y z' are the actual coordinates of the part in the virtual space
  2. 'a b c d e f g h i' is a top left 3x3 matrix of a standard 4x4 homogeneous transformation matrix (this represents the rotation and scaling of the part)

The entire 4x4 3D transformation matrix would then take either of the following forms:

⎡ a d g 0 ⎤ ⎡ a b c x ⎤ ⎢ b e h 0 ⎥ ⎢ d e f y ⎥ ⎢ c f i 0 ⎥ ⎢ g h i z ⎥ ⎣ x y z 1 ⎦ ⎣ 0 0 0 1 ⎦

The idea in presenting this seemingly complex bit of information is to present you with another view of how the model file is built, parsed, handled and how it can be understood - one can easily avert the use of a full 3D LDraw editor to make or change a model when understanding how a line (part attribution and placement) is composed. This also leads to even more creative solutions (such as stream editing to modify the values through scripting), which can help in modifying a tremendous amount of model files (main and sub assemblies, single or multiple files) that can easily contain thousands of lines.


I have scripted such utilities (BASH) to help maintain all my models, to help change and update them through new part releases and revisions, implement colour changes and standardize element positioning throughout a given model series. The possibilities are endless when you open up to the idea that and LDraw model file is nothing more than lines of code referencing vector coordinates and part or sub assembly properties.

Such a use of advanced editing techniques is paramount when serious about putting minimal effort in creating quality content and maintaining it and I do encourage you to look into scripting to make any burden or repetitive task a breeze to handle.

One of those tasks may just be the mass export/upload/re-upload (for update and maintenance purposes) of your model files to Sketchfab... *wink wink*

Sketchfab Uploads:

So, all is just fine and dandy when you produce a few models here and there. Oh! how lovely the weather is when you take some time to manually sign-in and upload your file after having taken a few minutes to review your export settings! The world is also beautiful when you go about in taking your sweet time to review and tweak the fabulous array of render settings provided to us by the Sketchfab developers...

When you have close to 100 models already built and continue to create more consistently and want all of them to be presented evenly, in a clean professional and seamless manner, the game changes - drastically. (Simply put: S**t just got real.)

As you might have noticed under my blog's 'Lego' section, all my models are presented using a consistent and uniform language, using automated measures backed by scripted tools and routines, all housed and hosted under Dropbox (and all of it auto-updates on any given change whenever new renders and exports are triggered after I finalize a new model build or finish updating another). All those files and models are all handled, edited or created by the editors and renderers that I've already mentioned in the early stages of the series.

With a little scripting magic and some API usage (graciously provided by the Sketchfab developer team), anyone can achieve this level of worry-free automation and can enjoy the greatest part of it all: creating virtual Lego models!

Using the Sketchfab upload API provided here, you can customize and tailor the upload process of the model and tune the environment it will be showcased in directly from the command line using GET/POST HTML requests (authenticated by your user token (found in your user profile under the 'Password & API' section)). From there, you simply make sure to retrieve and transpose your newly created model ID on Sketchfab which is returned to you when the model upload has been confirmed as successful!

Your private API token lets you upload 3D models from exporters and other applications directly to your account.

Command line samples for the exporter and uploader utilities:

Model UUID:

The standard Sketchfab model URL is formatted as

A - One example of such an ID can be presented as
B - '29e3e5f06f2e4f71a29cc14be165f1c2' points to where the model referenced should be found and loaded from within the Sketchfab model servers.
C - This same UUID and URL format can be reused and extended into hyper-link embeds and HTML iframe model showcases (such as the ones I use on my blog).

In this case UUID '29e3e5f06f2e4f71a29cc14be165f1c2' refers to this specific model [Queadlunn Rau - Power Armor]:

And is referenced as follows:

<iframe allowfullscreen="" mozallowfullscreen="true" src=";transparent=0&amp;autospin=0&amp;controls=0" webkitallowfullscreen="true"></iframe>

You can basically plug this iframe content and use CSS code to tailor it to your needs for it to fit the page it will be put in or the elements that will sit beside it.

I leave you to explore the fabulous world of digital Lego model editing via the use of the LDraw system and its many tools, utilities, editors, renderers and great surprises! ^_^

My experience with LDraw has been one of great enjoyment, up to this day, as I continue to create, build, maintain and update continuously (when time permits it), and I sure hope to be doing so for many more years to come, alongside the physical Lego builds I've come back to develop and assemble after a very long hiatus.

Sketchfab has proven to be the key tool in letting people into your creations, making them see and explore every little detail of your passion, and I cannot thank them enough for having created such a beautiful tool, and wish them great success in their endeavour. The platform has seen many great improvements since its debut and is heading in the right direction, merging creativity, abstraction, reality and communication under the same roof.

Up to you now to explore and find your inner child (we all have one still lying around in there) and get back to enjoying the pleasure of model building, virtual or not.

Don't forget to stop by my blog to find more interesting posts about builds, other tips and other various updates!

Happy building!