M2m

Blender - LDD Plugin

Recommended Posts

On 3/4/2024 at 4:16 PM, MixedMocs said:

Hello!

First of all, THANK YOU FOR MAKING THIS! I've been searching for days for a way to finally render my LDD mocs with the modded parts, and your plugin (mostly)  works like an absolute charm for that! Compared to bluerender, which doesn't accept the new lif file that LIFCreator gives me, or importing into Stud.io, which rotates half the pieces wrong, your plugin is definitely the best option for me right now.

That being said, I have been getting a few smaller issues with some of my complex models.

First of all, it seems that the plugin doesn't like decorated bricks a lot. When I try to import something with a brick that has a print on it, i get the following error:

Python: Traceback (most recent call last):
  File "C:\Users\[my name]\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\importldd.py", line 1454, in execute
    return convertldd_data(context, self.filepath, self.lddLIFPath, self.useLogoStuds, self.useLDDCamera)
  File "C:\Users\[my name]\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\importldd.py", line 1394, in convertldd_data
    converter.Export(filename=filepath, useLogoStuds=useLogoStuds, useLDDCamera=useLDDCamera)  
  File "C:\Users\[my name]\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\importldd.py", line 1144, in Export
    texImage.image = bpy.data.images.load(os.path.normpath(decofilename))
RuntimeError: Error: Cannot read '\Decorations\101321.png': No such file or directory

It will then stop importing, so I'll have only half a model or nothing at all in blender. If I go back into LDD and remove the decoration from the part, the model is imported without issue. Apparently it just can't find the decoration files, I've tried it with both the new and old decorations, same issue.

Second of all, on some models, some brick faces will show up pink when imported. I'll attach a screenshot. I have no idea why this happens, but at least it seems to be constistent per brick: the sand-yellow 1x1 bricks in the screenshot all consistently have 3 pink faces (some of them are just rotated apparently).

The import doesn't throw any errors for this issue.

I'm sorry about the shoddy screenshot compression. I would love to attach more screenshots, but I'm only allowed a max total size of 0.1mb, which isn't enough for much of anything if we're honest (does this get better if I post more? This is my first forum contribution after all).

I can also send you some of my "incriminating" model files if you want, just tell me through which channel you'd like to receive them. Be aware that I do use the new modded LDD parts from the key topic on here, though I think I can also find some with just the "vanilla" parts.

Screenshot 2024-03-04 160243.png

Apparently, the "Pink Bricks Bug" was just an artifact from the fact that i made those files before installing the new bricks - If anyone else is having the same issue: changing anything about your file and then saving it (in your new version) fixed it for me. Apparently the old files have to be "reconciled" with your modified LDD at least once to be translated properly. Weird edge case, but not a problem!

Share this post


Link to post
Share on other sites
Posted (edited)

 

"Fan made" modification to the plugin:

I made a little modification to how the plugin creates materials. This allows for adding a glossy effect which closer resembles Lego plastic IRL, in my opinion. I'm appending some before and after shots below (I read the beginner post an understand now that I'm supposed to embed links, lol).

Technobabbel as to how it works:

I changed the code to use the nodetrees instead of just setting the diffuse material colors. I use the "Principled BDSF" shader and set the roughness to 0.1, which makes the material glossy (without making in mirror-like), even in the cycles renderer (only editing the diffuse material directly will change how it shows up in the viewport/eevee, but not in the final cycles render itself). I keep the same colors you set.

Code Modification:

 

        material.roughness = 0.1
        material.use_nodes = True
        material.node_tree.nodes["Principled BSDF"].inputs[0].default_value = (self.r, self.g, self.b, self.a)
        material.node_tree.nodes["Principled BSDF"].inputs[2].default_value = 0.1

Paste this at line 765 of the file importldd.py inside your Blender's scripts directory (the folder C:\Users\[your name]\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons). You can just open the file with Editor; it's what I did.

The lines just before where you paste it should read:

        material = bpy.data.materials.new(matId_or_decId)
        material.diffuse_color = (self.r, self.g, self.b, self.a)

If you do that and indent everything so that it matches the two lines above, it should now work after reloading your scripts. That is, assuming you didn't mess up capitalization (yes, python cares about that) or add any spacebars/tabs anywhere (yes, python cares about that as well). You should now notice that your bricks are a lot more glossy the next time you import anything.

Example images:

Before:

53573442574_d6d9031c82_c.jpg

After:

53573119781_e1f41aec45_c.jpg

 

Notice how the bricks now catch the light and reflect each other a lot better, whereas they just looked dull before.

Further suggestions and notes:

This might not work for parts with decorations. I didn't test those because I couldn't get decorated parts to import correctly in the first place, with or without my mod, lol.

This also does not change any existing blender saves where you have already imported something; those bricks will stay matte, but anything you import from now on will be glossy.

This is mostly a proof of concept; individuals with more energy than me can now come along and add any number of fun properties to the materials (maybe even the "used brick" look with the little nooks and scratches that Studio does, just using a shader / normal map?)

You could also now try detecting when a color is supposed to be metallic, and then making it so. I currently don't have any motivation to do that, though. My approach would just be a big if-statement with all the metal colors. I suppose the "right approach" would be to store the ldd name of each color in an excel table, then the settings needed to recreate it in the columns next to the name, and then somehow make python read all that. I don't know how to do that; this was my first dabble with python.

Also, technically, some lego bricks will be annoying because they're shiny on some surfaces but rough on others - c.f. part 303921 "roof tile". I think worrying about that is just my perfectionism rearing its ugly head, though.

In conclusion:

@M2m

Feel free to add my modification to your base version of the script, if you so desire. You can credit me just in a comment next to the part I contributed.

If you want to discuss any of this further, feel free to dm me. Preferably with an email adress we can use, cause I still have like 4 posts left to go until I can actually dm anybody, lol.

 

So long, and thanks for all the fish!

Edited by MixedMocs

Share this post


Link to post
Share on other sites

Thats a nice change. You might also create a pull request in github. I'm not working on the blender plugin or LDD as much currently as i did in the past. But I'm happy to see that its of use to some people :)

Share this post


Link to post
Share on other sites
Posted (edited)

Are you kidding? I love the plugin! LDD has always been my preferred method for digital lego (Studio has improved, but the way it sorts its parts confuses me, plus it seems to freee up if I ever hit the "stability" tool on accident) and I love using Blender for my renders because of its versatility, so your plugin is pretty much perfect for me!

I'll see about the pull request; I've never really interacted with github beyond finding the download button, lol.

I've also figured out the metallic colors in the meantime, I'm doing the naive method where I'm basically just checking the color ID against a list of all the metal colors and then changing the material accordingly:

53589259078_8933d9e550_w.jpg

Notice how all the former "yellow" pieces are nice and golden now, as intended. I might add in a little more roughness or dial back the metallic value so it looks less like actual metal; the material now was kind of inspired by this post by Cezium on Instagram.

Edited by MixedMocs

Share this post


Link to post
Share on other sites

Yeah I'm pretty much on the same page with you. LDD is still the best tool for building in my opinion. I switched my render workflow to import my LDD builds into Mecabricks and then use it's Blender Plugin for rendering. Mecabricks has amazing materials :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.