From a9248851acddf068e57d34ab719646371272eb6d Mon Sep 17 00:00:00 2001 From: BertVanRaemdonck Date: Wed, 9 Mar 2016 21:24:46 +0100 Subject: [PATCH] Add logo function The user now has the possibility to select an option that puts the LEGO logo on top off all studs in the file. A requirement for this is that the "logo3.dat" file from the LDraw parts tracker is located in the standard p folder. Note that I also changed the threshold for the cleanup, because otherwise the logo would loose its geometry because it's so small. To make sure the thershold is fit for all import scales, the threshold is now multiplied by the import scale. --- import_ldraw.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/import_ldraw.py b/import_ldraw.py index 2eff158..265a8e8 100644 --- a/import_ldraw.py +++ b/import_ldraw.py @@ -260,6 +260,14 @@ def parse(self, filename): subfiles.append(['orientation', orientation, '']) + # Adds the LEGO logo on top of every stud. It is + # assumed that the logo3.dat file is available in + # the given p directory + if LogosOpt and new_file == "stud.dat": + mat_logo = self.mat * mathutils.Matrix( + ((a,b,c,x),(d,e,f,y-4),(g,h,i,z),(0,0,0,1))) + subfiles.append(["logo3.dat", mat_logo, color]) + # Triangle (tri) if tmpdate[0] == "3": self.parse_line(tmpdate) @@ -825,7 +833,7 @@ def create_model(self, context, scale): bpy.ops.mesh.select_all(action='SELECT') # Remove doubles, calculate normals - bpy.ops.mesh.remove_doubles(threshold=0.01) + bpy.ops.mesh.remove_doubles(threshold=scale*0.005) bpy.ops.mesh.normals_make_consistent() if bpy.ops.object.mode_set.poll(): @@ -1038,6 +1046,12 @@ class LDRImporterOps(bpy.types.Operator, ImportHelper): default=prefs.get("addGaps", False) ) + addLogos = BoolProperty( + name="LEGO Logo On Studs", + description="Add the LEGO logo on top of all studs", + default=prefs.get("addLogos", False) + ) + lsynthParts = BoolProperty( name="Use LSynth Parts", description="Use LSynth parts during import", @@ -1065,16 +1079,18 @@ def draw(self, context): box.label("Additional Options", icon='PREFERENCES') box.prop(self, "altColors") box.prop(self, "addGaps") + box.prop(self, "addLogos") box.prop(self, "lsynthParts") box.prop(self, "linkParts") def execute(self, context): """Set import options and start the import process.""" - global LDrawDir, CleanUpOpt, AltColorsOpt, GapsOpt, LinkParts + global LDrawDir, CleanUpOpt, AltColorsOpt, GapsOpt, LogosOpt, LinkParts LDrawDir = str(self.ldrawPath) CleanUpOpt = str(self.cleanUpParts) AltColorsOpt = bool(self.altColors) GapsOpt = bool(self.addGaps) + LogosOpt = bool(self.addLogos) LinkParts = bool(self.linkParts) # Clear array before adding data if it contains data already @@ -1136,6 +1152,7 @@ def execute(self, context): # Create the preferences dictionary importOpts = { "addGaps": self.addGaps, + "addLogos": self.addLogos, "altColors": self.altColors, "cleanUpParts": self.cleanUpParts, "importScale": self.importScale,