[PYTHON] Playing with LEGO and breaking into the 3D industry-The ultimate goal is to use Unity-

Modeling objects used in Unity, that's right. I don't know.

I have an image that 3D seems to take time, and I have to be an expert. So I'll give up and play with Lego blocks at best.

Play with Lego blocks at best.

When I was little, I played with messed up Lego. From morning till night. It's true. I loved it. That's why I will continue to play with unreasonable Lego. You can also play virtually on your computer ↓ http://ldd.lego.com/ja-jp/

It's boring if you're not productive.

If you are overseas, you can order the actual block required for assembly from the app as it is. But Japan is not compatible. Calling ... I want to somehow output it!

Then, let's use the one made from this block in Unity.

Let's set aside why that happened. If this goes well, you should be able to make a game app using the official LEGO app. First, let's export with LEGO in a file format called ldr. It is useless unless it is made into a general-purpose format. Let's prepare blender. http://blender.jp So I found a good add-on. ↓ http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/LDRAW_Importer Thank you for the person who made it.

Start blender, open the settings and import the add-on. If you drop the add-on with a zip, you can install it by specifying the zip as it is from blender without unzipping it.

Then in preparation for using the add-on http://www.ldraw.org/help/getting-started.html Get the required library (block data) from. The installation location is For Windows people, C: \ LDraw Mac people / Applications / ldraw Linux people ~ / ldraw I'm trying to be.

I don't like the location of the default

I'm sorry for the person who made it. I don't want to put non-app files in / Applications / when using a Mac. Even Windows doesn't want to be placed directly under C. Linux is right under the root. It's amazing.

I will change the location. I think that the directory where add-ons installed by blender are stored is different for each OS, so I will omit the location of the file, but for Mac it is ~ / Library / Application Support / Blender / version / scripts / addons.

If the add-on is installed properly by the above procedure, there is a file called import_ldraw.py. Looking at it with a text editor, there are the following lines.

import_ldraw.py


"""
Default LDraw installation paths
Index 0: Windows
Index 1: Mac OS X
Index 2: Linux
Index 3: User defined, raw string
Storing the paths in a list prevents the creation of global variables
if they are changed. Instead, simply update the proper index.
"""
LDrawDirs = ["C:\\LDraw", "/Applications/ldraw/", "~/ldraw/", r""]

The developer is smart. It is written that you can set your favorite path in the third argument, so be patient with your words

import_ldraw.py


"""
Default LDraw installation paths
Index 0: Windows
Index 1: Mac OS X
Index 2: Linux
Index 3: User defined, raw string
Storing the paths in a list prevents the creation of global variables
if they are changed. Instead, simply update the proper index.
"""
pwd = os.path.dirname(__file__)
LDrawDirs = ["C:\\LDraw", "/Applications/ldraw/", "~/ldraw/", pwd + r"/ldraw/"]

It's refreshing if you put the ldraw directory in the same directory where import_ldraw.py is, that is, in the add-on directory of blender. I feel like I can take it as it is when upgrading the version of blender. I wrote it for 1 minute in python history, but I'm thrilled if it works.

I'm ready so I'll use it

Select import-> LDraw from the menu at the top left of the blender screen. Specify the ldr file that you probably created earlier in.

Ah, it's amazing. I was able to read it properly.

How do you make use of it in Unity?

~~ I'll think about it soon, but that's all for today. But what about the fact that you can import it into blender and then export it as most general-purpose data, so it is guaranteed that there are endless possibilities? ?? ~~ It seems that Unity supports .blender files, which is the standard storage format of Blender. So save it normally in Blender and import the .blender file directly in Unity.

Added so as not to be misunderstood

I really liked the LEGO blocks. I was given enough to make a little SimCity before I even thought about it. Shake to parents. (Thank you)

Recommended Posts

Playing with LEGO and breaking into the 3D industry-The ultimate goal is to use Unity-
[Python] What is pip? Explain the command list and how to use it with actual examples
The strongest way to use MeCab and CaboCha with Google Colab
Specify the browser to use with Jupyter Notebook. Especially Mac. (And Vivaldi)
How to use is and == in Python
[Introduction to AWS] I tried porting the conversation app and playing with text2speech @ AWS ♪
Specify the Python executable to use with virtualenv
The easiest way to use OpenCV with python
It is easy to execute SQL with Python and output the result in Excel