Skip to content

Commit

Permalink
Update for Blender 2.80
Browse files Browse the repository at this point in the history
  • Loading branch information
TobyLobster committed May 4, 2019
1 parent f24370a commit 82e6764
Show file tree
Hide file tree
Showing 4 changed files with 544 additions and 265 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ It supports **.mpd**, **.ldr**, **.l3b**, and **.dat** file formats.
It's intended to be accurate, compatible, and fast (in that order of priority).

## Features ##
+ Available for both Blender 2.79 and Blender 2.80
+ **Mac** and **Windows** supported (and hopefully **Linux**, but this is currently untested).
+ **Bricksmith** compatible.
+ **MPD** file compatible.
+ **LeoCAD** groups and cameras (both perspective and orthographic) supported.
+ **LSynth** bendable parts supported (synthesized models).
+ Both *Cycles* and *Blender Render* engines supported. It renders either engine from a single scene.
+ Import **photorealistic** look, or **Instructions** Look.
+ **Realistic materials** including standard brick material, transparent, rubber, and even the less common materials like chrome, metal, pearlescent, glow-in-the-dark, glitter and speckle.
+ **Principled Shader supported** Uses Blender's new 'Principled Shader' where available for optimal look (but still works well without).
+ *Cycles* and *Blender Render* engines supported. It renders either engine from a single scene.
+ Import **photorealistic** look, or **Instructions** look.
+ **Physically Based Realistic materials** - standard brick material, transparent, rubber, chrome, metal, pearlescent, glow-in-the-dark, glitter and speckle.
+ **Principled Shader supported** Uses Blender's 'Principled Shader' where available for optimal look (but still works well when unavailable).
+ **Accurate colour handling**. Correct colour space management is used so that e.g. black parts look black.
+ **Direct colours** supported.
+ **Back face culling** - fully parses all BFC information, for accurate normals.
Expand All @@ -30,6 +31,7 @@ It's intended to be accurate, compatible, and fast (in that order of priority).
+ **Gaps between bricks** - Optionally adds a small space between each brick, as in real life.
+ **Smart face smoothing** - Uses Edge-Split Modifier and Sharp Edges derived from Ldraw lines, for smooth curved surfaces and sharp corners.
+ **Concave walls** - Optionally look as if each brick has very slightly concave walls (with the photorealistic renderer), which affects the look of light reflections.
+ **Light bricks** - Bricks that emit light are supported.
+ **Fast** - even large models can be imported in seconds.

![Ghostbusters](./images/ghostbusters_960.png)
Expand All @@ -40,13 +42,14 @@ It's intended to be accurate, compatible, and fast (in that order of priority).

+ Download the latest version from the [Releases](https://github.com/TobyLobster/ImportLDraw/releases) page
+ Open Blender
+ From the Blender menu click: File > User Preferences
+ If you are in Blender 2.79 or lower, choose from the menu: File > User Preferences
+ If you are in Blender 2.80 or later, choose from the menu: Edit > Preferences
+ Click the *Add-ons* tab
+ Click the *Install from file...* button
+ Click the *Install from file...* button (Blender 2.79) or *Install...* button (Blender 2.80)
+ Navigate to the zip file you downloaded and select it
+ Find *Import LDraw* in the list of Add-ons (search for *LDraw* if necessary)
+ Tick the check mark next to it to activate the add-on.
+ Click the *Save User Settings* button so that it will still be active next time you launch Blender.
+ Click the *Save User Settings* button (Blender 2.79) or *Save Preferences* button (Blender 2.80) so that it will still be active next time you launch Blender.

**Setting the LDraw Parts Library directory**

Expand Down
20 changes: 15 additions & 5 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"description": "Import LDraw models in .mpd .ldr .l3b and .dat formats",
"author": "Toby Nelson <tobymnelson@gmail.com>",
"version": (1, 1, 9),
"blender": (2, 76, 0),
"blender": (2, 80, 0),
"location": "File > Import",
"warning": "",
"wiki_url": "https://github.com/TobyLobster/ImportLDraw",
Expand All @@ -43,14 +43,24 @@ def menuImport(self, context):

def register():
"""Register Menu Listing."""
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_file_import.append(menuImport)
bpy.utils.register_class(importldraw.ImportLDrawOps)
if hasattr(bpy.types, 'TOPBAR_MT_file_import'):
# Blender 2.80
bpy.types.TOPBAR_MT_file_import.append(menuImport)
else:
# Blender 2.79
bpy.types.INFO_MT_file_import.append(menuImport)


def unregister():
"""Unregister Menu Listing."""
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_file_import.remove(menuImport)
bpy.utils.unregister_class(importldraw.ImportLDrawOps)
if hasattr(bpy.types, 'TOPBAR_MT_file_import'):
# Blender 2.80
bpy.types.TOPBAR_MT_file_import.remove(menuImport)
else:
# Blender 2.79
bpy.types.INFO_MT_file_import.remove(menuImport)


if __name__ == "__main__":
Expand Down
58 changes: 30 additions & 28 deletions importldraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self):
self.__ldPath = None
self.__prefsPath = os.path.dirname(__file__)
self.__prefsFilepath = os.path.join(self.__prefsPath, "ImportLDrawPreferences.ini")
self.__config = configparser.ConfigParser()
self.__config = configparser.RawConfigParser()
self.__prefsRead = self.__config.read(self.__prefsFilepath)
if self.__prefsRead and not self.__config[Preferences.__sectionName]:
self.__prefsRead = False
Expand Down Expand Up @@ -121,24 +121,24 @@ class ImportLDrawOps(bpy.types.Operator, ImportHelper):

# File type filter in file browser
filename_ext = ".ldr"
filter_glob = StringProperty(
filter_glob: StringProperty(
default="*.mpd;*.ldr;*.l3b;*.dat",
options={'HIDDEN'}
)

ldrawPath = StringProperty(
ldrawPath: StringProperty(
name="",
description="Full filepath to the LDraw Parts Library (download from http://www.ldraw.org)",
default=prefs.get("ldrawDirectory", loadldraw.Configure.findDefaultLDrawDirectory())
)

importScale = FloatProperty(
importScale: FloatProperty(
name="Scale",
description="Sets a scale for the model",
default=prefs.get("scale", 0.01)
)

resPrims = EnumProperty(
resPrims: EnumProperty(
name="Resolution of part primitives",
description="Resolution of part primitives, ie. how much geometry they have",
default=prefs.get("resolution", "Standard"),
Expand All @@ -149,13 +149,13 @@ class ImportLDrawOps(bpy.types.Operator, ImportHelper):
)
)

smoothParts = BoolProperty(
smoothParts: BoolProperty(
name="Smooth faces and edge-split",
description="Smooth faces and add an edge-split modifier",
default=prefs.get("smoothShading", True)
)

look = EnumProperty(
look: EnumProperty(
name="Overall Look",
description="Realism or Schematic look",
default=prefs.get("useLook", "normal"),
Expand All @@ -165,7 +165,7 @@ class ImportLDrawOps(bpy.types.Operator, ImportHelper):
)
)

colourScheme = EnumProperty(
colourScheme: EnumProperty(
name="Colour scheme options",
description="Colour scheme options",
default=prefs.get("useColurScheme", "lgeo"),
Expand All @@ -176,73 +176,73 @@ class ImportLDrawOps(bpy.types.Operator, ImportHelper):
)
)

addGaps = BoolProperty(
addGaps: BoolProperty(
name="Add space between each part:",
description="Add a small space between each part",
default=prefs.get("gaps", False)
)

gapsSize = FloatProperty(
gapsSize: FloatProperty(
name="Space",
description="Amount of space between each part",
default=prefs.get("gapWidth", 0.01)
)

curvedWalls = BoolProperty(
curvedWalls: BoolProperty(
name="Use curved wall normals",
description="Makes surfaces look slightly concave",
default=prefs.get("curvedWalls", True)
)

importCameras = BoolProperty(
importCameras: BoolProperty(
name="Import cameras",
description="Import camera definitions (from models authored in LeoCAD)",
default=prefs.get("importCameras", True)
)

linkParts = BoolProperty(
linkParts: BoolProperty(
name="Link identical parts",
description="Identical parts (of the same type and colour) share the same mesh",
default=prefs.get("linkParts", True)
)

numberNodes = BoolProperty(
numberNodes: BoolProperty(
name="Number each object",
description="Each object has a five digit prefix eg. 00001_car. This keeps the list in it's proper order",
default=prefs.get("numberNodes", True)
)

positionOnGround = BoolProperty(
positionOnGround: BoolProperty(
name="Put model on ground at origin",
description="The object is centred at the origin, and on the ground plane",
default=prefs.get("positionObjectOnGroundAtOrigin", True)
)

flatten = BoolProperty(
flatten: BoolProperty(
name="Flatten tree",
description="In Scene Outliner, all parts are placed directly below the root - there's no tree of submodels",
default=prefs.get("flattenHierarchy", False)
)

useUnofficialParts = BoolProperty(
useUnofficialParts: BoolProperty(
name="Include unofficial parts",
description="Additionally searches for parts in the <ldraw-dir>/unofficial/ directory",
default=prefs.get("useUnofficialParts", True)
)

useLogoStuds = BoolProperty(
useLogoStuds: BoolProperty(
name="Show 'LEGO' logo on studs",
description="Shows the LEGO logo on each stud (at the expense of some extra geometry and import time)",
default=prefs.get("useLogoStuds", False)
)

instanceStuds = BoolProperty(
instanceStuds: BoolProperty(
name="Make individual studs",
description="Creates a Blender Object for each and every stud (WARNING: can be slow to import and edit in Blender if there are lots of studs)",
default=prefs.get("instanceStuds", False)
)

resolveNormals = EnumProperty(
resolveNormals: EnumProperty(
name="Resolve ambiguous normals option",
description="Some older LDraw parts have faces with ambiguous normals, this specifies what do do with them",
default=prefs.get("resolveNormals", "guess"),
Expand All @@ -252,31 +252,31 @@ class ImportLDrawOps(bpy.types.Operator, ImportHelper):
)
)

bevelEdges = BoolProperty(
bevelEdges: BoolProperty(
name="Bevel edges",
description="Adds a Bevel modifier for rounding off sharp edges",
default=prefs.get("bevelEdges", True)
)

bevelWidth = FloatProperty(
bevelWidth: FloatProperty(
name="Bevel Width",
description="Width of the bevelled edges",
default=prefs.get("bevelWidth", 0.5)
)

addEnvironment = BoolProperty(
addEnvironment: BoolProperty(
name="Add Environment",
description="Adds a ground plane and environment texture (for realistic look only)",
default=prefs.get("addEnvironment", True)
)

positionCamera = BoolProperty(
positionCamera: BoolProperty(
name="Position the camera",
description="Position the camera to show the whole model",
default=prefs.get("positionCamera", True)
)

cameraBorderPercentage = FloatProperty(
cameraBorderPercentage: FloatProperty(
name="Camera Border %",
description="When positioning the camera, include a (percentage) border around the model in the render",
default=prefs.get("cameraBorderPercentage", 5.0)
Expand All @@ -286,9 +286,11 @@ def draw(self, context):
"""Display import options."""

layout = self.layout
layout.use_property_split = True # Active single-column layout

box = layout.box()
box.label("Import Options", icon='SCRIPTWIN')
box.label("LDraw filepath:", icon='FILESEL')
box.label(text="Import Options", icon='PREFERENCES')
box.label(text="LDraw filepath:", icon='FILEBROWSER')
box.prop(self, "ldrawPath")
box.prop(self, "importScale")
box.prop(self, "look", expand=True)
Expand All @@ -315,7 +317,7 @@ def draw(self, context):
box.prop(self, "numberNodes")
box.prop(self, "flatten")

box.label("Resolve Ambiguous Normals:", icon='EDIT')
box.label(text="Resolve Ambiguous Normals:", icon='ORIENTATION_NORMAL')
box.prop(self, "resolveNormals", expand=True)

def execute(self, context):
Expand Down
Loading

0 comments on commit 82e6764

Please sign in to comment.