Import From LDD
LukeSkywalker started this discussion in General Discussion

So I saw that you're planning to add a function where you can import models from LDD. It sounds like a really cool feature. Does this mean that you'll add all the LDD parts to the database? How will colors on parts with decorations work (like on LDD when you have an orange jacket torso and you make the jacket green)? How long do you think it will be before this function is added?

49 replies ยท Page 1 of 3
Avatar of Scrubs
Administrator

It won't be a full support of the LDD files to start. No flex parts, probably limited decoration support and of course parts that are not in mecabricks won't be imported. Besides, it will take some time to go through every single part design in the library to enter transformation data - which I don't intent to do myself, so hopefully some of you guys can slowly fill in the database. it is not going to be all perfectly working from day one but will be an ongoing activity.

OK, thanks for the clarification.

Is this what Sim is doing? I'd be interested in testing it out. ๐Ÿ˜ƒ

Avatar of Scrubs
Administrator

He is probably doing something similar to what I am doing but I also need to code the whole process:

  • Upload the lxf file to the server
  • Unzip and parse the lxfml file
  • Verify the content
  • Check what's available in mecabricks and convert the transformation matrix for each part
  • Spit the code back

I also need to handle the new part data that will be required which means some modifications of the database and the UI of the part page.

So as you see, not something very straight forward! I also have to handle everything that can go wrong along the process mainly with users trying to upload random weird stuff that could crash everything...

How will decorations work? The identifications in LDD will be used to convert to identifications to Mecabricks.
In LDD it's just brick id and decoration id (decoration id = 0 when no decoration is applied to the brick) and in mecabricks it's just an id (decoration or not)
so let's say that the unique combination of brick id and decoration id give exact 1 result in mecabricks and so the mapping will go.
Ofcourse there will be parts that exist in LDD and not in mecabricks (for example satellite dish dia16) and those part cannot be imported.

There's currently still going to need a lot of research. LDD is software that's quite old already and they also didn't make it 'good' with the day 1 release. It's going to take some time to tackle down all the required things listed above. Then above that, the way that positions and rotations are stored in LDD is quite advanced. Above this, some special parts (such as the hinge plate) will require special attention to make sure that every special case that can happen is handled correctly. And I didn't talk about flex parts yet. ๐Ÿ˜‰ Let's say it could easily take some more time.

What I'm currently doing was to research how hard it would be to import LDD files into mecabricks because I was also a little bit interested in how it actually would work out. The research could then be used to make a final deciseon, but I see that Scrubs started with the implementation after I posted the traffic light some days ago. I'm currently having the first results and today I'm going to look further in it.

@Scrubs, I've actually used the new HTML5 File reader to gather the file from the user and then locally parse it in. If you don't want nyan cats or my little ponies on your server, you could actually use this. ๐Ÿ˜›

Avatar of Scrubs
Administrator

I've finished to code the file handling but on the server side. With the HTML5 file reader, do you open the .lxf or the .lxfml?
I delete the whole lot if the file is not containing what it is supposed to. I shall not have too many cats picture on the server! That said, MB users generally behave pretty well.

The first version of the importer will handle grouping, replace decorated parts by generic one but will ignore flex pieces as well as the ones not present in MB. Importing a model will probably require a little bit of work but I am sure that it will be sufficient for most people to start.

I'm using the lxfml currently. (as that's the only thing I need to parse the model)

Avatar of Scrubs
Administrator

An advantage of doing it on the server side is that I can upload directly the .lxf file and unzip/parse the lxfml automatically I guess. I almost finished to code the basic parsing. Maybe I can put something online in the next couple of days to do a very basic proof of concept

I don't understand anything but I follow what you are doing โ™ฅ๏ธ

Avatar of Scrubs
Administrator

Here is where I am with the development of the LDD import module. The code is not too far from being completed - I still need to handle the groups and solve issues with special cases - after I might need some help to complete the database.

[youtube]AS5K8rdJXEs[/youtube]

Wow, you're really that far already. ๐Ÿ˜› If you don't have problems with rotations and such like I'm having, then it's probably just my mathematics that's wrong ๐Ÿ˜› I'll help you out with the database as soon as you need help! In fact, I already have around 100 bricks mapped. If you're using the same method as I'm using (ldd id + decoration id = mecabricks id) then you can borrow those 100 already. Well, for the transformation, I'm really interested to know what you did do to get the result and from as soon as I know what you need for the transformation, I can help out with these as well. ๐Ÿ˜ƒ

I can't believe it. This is magic. ๐Ÿ˜ฎ
You are genius guys.

Avatar of Scrubs
Administrator

Transformations in LDD are stored as follow: a, b, c, d, e, f, g, h, i, j, k, l
a, b, c, d, e, f, g, h, i correspond to the rotation and j, k, l to the position. I use those values to build the transform matrix 4x4 in the LDD space:

m = [
	a, d, g, j,
	b, e, h, k,
	c, f, i, l
	0, 0, 0, 1
]

In my my database table, I store the conversion data between the 2 parts when they are positioned on 0, 0, 0 with a rotation 0, 0, 0 - for the rotation I work with Euler angles XYZ:

t = [x, y, z]
r = [x, y, z]

I compose the conversion matrix 4x4 n from t and r. I'm not going to detail the math here but this one is a little more complex to build.

The next step is to multiply the 2 matrices m and n to get the global transform matrix for mecabricks.

To finish, I extract the position and rotation (euler XYZ) from the last matrix which are the two vectors I need for mecabricks to locate the part correctly.

I still have some verification to ensure it works fine. After that, I will make a proper UI for the part page in order to enter the values - Nothing will be required for parts having the same reference and origin than on mecabricks. e.g. hair pieces, 1x1 brick, etc.

I will let you know when I have a proper workflow but it would be awesome if you could help filling in the database!

If by filling the database you mean going through and finding which LDD IDs corrsepond to which mecabricks IDs, I'll definitely help with that!

Me too! ๐Ÿ˜‰

Avatar of Scrubs
Administrator

Slow Friday at work... So I made a few tests with LDD to ensure I understood exactly how the software is working.

What I found is that:

  • Mecabricks and LDD both have the Y axis UP
  • LDD angles are left-handed and Mecabricks ones are right-handed
  • LDD uses extrinsic rotations and Mecabricks intrinsic ones

I knew about the first two but I did not notice the last one. I will have to write a function that converts extrinsic rotations to intrinsic.

If you guys are interested about knowing a bit more about that, check this wikipedia page https://en.wikipedia.org/wiki/Euler_angles

Lucky Scrubs is a day ahead of me (it's still Thursday where I'm at). The workshop seems faster and smoother in the video than it is when I use it on my computer, probably just my computer though. All this stuff sounds like a bunch of gibberish to me, some of you people might be related to Einstein. ๐Ÿ˜›

Avatar of Scrubs
Administrator

Yep and monday is a public day so 3 days holiday ahead of me. Yeah!
It is not that hard, it just requires a bit of concentration to understand it ๐Ÿ˜ƒ

Well I get February 15th off for Presidents Day. I bet they don't celebrate that in Europe ๐Ÿ˜„

Avatar of Scrubs
Administrator

Hehe no lol I am leaving in New Zealand and we have Queen's Birthday though! It's kinda similar as we don't have a president here but just a prime minister.

Previous
Next
Advertising
7 participants
Avatar of LukeSkywalker
Avatar of Scrubs
Avatar of Sim
Avatar of wlange
Avatar of UmbraManis
Avatar of IronBob
Avatar of zanna

LEGO, the LEGO logo, the Minifigure, and the Brick and Knob configurations are trademarks of the LEGO Group of Companies. ยฉ2024 The LEGO Group.

Mecabricks, the Mecabricks logo and all content not covered by The LEGO Group's copyright is, unless otherwise stated, ยฉ2011-2024 Mecabricks.