[Addon] Ldraw Importer

Hello

I have created an importer for the LDraw Parts Library. (LDraw™ is an open standard for LEGO CAD programs that allow the user to create virtual LEGO models and scenes.) I have asked permission to publish this addon at LDraw and they said it wouldn’t be a problem, the legal info can be found here.

It can import the 3 file types LDraw uses .mpd, .ldr and .dat
It support the 3 types of colour:

  • The official colours, which definitions can be found in the ldconfig.ldr file and is provided here and is necessary for using the importer.
  • Direct colours
  • Blended colours

When you want to use the importer just place the unzipped folder “io_scene_ldraw” inside the addons folder of blender. And then just start blender up and activate it under the user preferences.
Then if you click File > Import > LDraw, you need to insert 3 paths:

  • The default one, just by navigating in the screen file explorer and selecting it
  • Then on the left part of the screen, the path to the file which contains the colour definitions
    (example: C:\Users\Kevin\LDConfig.ldr)
  • Also on the left, the path to the folder which contains the parts
    (example: C:\Users\Kevin\ldraw), the folder you specify needs to contain the two subfolders “parts” and “p”.

Then adjust the other settings:

  • Remove doubles: will run the default remove doubles function of blender on al the bricks you are importing.
  • High res primitives: Certain parts of a brick are provided in two resolutions, sometimes using high res primitives can give gaps or overlapping faces when not al the parts are provided in high res
  • Smooth: will apply smooth shading on all the bricks
  • sRGB to Linear colorspace: maybe named it wrong, but I added this function because some colours look different in Blender then you maybe expect. Like in this picture. The left train is with sRGB to Linear colorspace enabled, the left with disabled. The biggest difference you will immediately notice is the black on the left which is bluish on the right. The colour defined in the CAD program I build it with was black (#05131D). So because of this I added this function. (Don’t mind the artifacts on the windows this is a bug in the LDraw part and has been reported)

The LDConfig file contains different definitions for colours, some colours have extra attributes where under speckle, glitter, etc. The material setup for these is not great. Because I have no experience in this I have copied the setup from thisLDraw importer project, he is aware of it that I copied that part of his code and therefore I have mentioned him in the author credits of this plugin.
If you can help me out with better material setups, faster code or enchantments please post it.
I am busy with also adding support for linking bricks when importing but run into a small problem with that.


Update log:
Version 0.2:

  • Added cleanup for unused textures
  • Use filename for main group instead of “MAIN”
    Version 0.1:
  • Initial release

Attachments

io_scene_ldraw.zip (5.52 KB)

Looks nice :slight_smile: Thanks a lot !