LDraw.org Discussion Forums

Full Version: [SOLVED!] coordinate-handedness confusion
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
What coordinate system do lDraw parts ACTUALLY use? The documentation *says* "Right handed with -y up", but shows a picture of a left-handed -y up coordinate axis.

Further - how would I go about translating the matrix to a left-handed +y-up format? I am trying to read ldr files inside of UE4, and the typical method of flopping the y/z coords and negating x/y/z is not working.
(2021-08-28, 12:31)KristyB Wrote: [ -> ]What coordinate system do lDraw parts ACTUALLY use? The documentation *says* "Right handed with -y up", but shows a picture of a left-handed -y up coordinate axis.

Further - how would I go about translating the matrix to a left-handed +y-up format? I am trying to read ldr files inside of UE4, and the typical method of flopping the y/z coords and negating x/y/z is not working.

It is right handed, to get the y up it only rotates 180 degrees around x.

the picture might be confusing because it shows an arrow pointing up labeled -Y (if it was left handed it would be labeled just Y)
(2021-08-28, 16:20)Roland Melkert Wrote: [ -> ]to get the y up it only rotates 180 degrees around x.
Oh my god this would have taken me forever to work out, that the whole system rotates to get -y Up rather than just flipping the sinage of Y. Thank you!

Is there anywhere I can submit to have this note considered to be added to the documentation?
(2021-08-30, 9:37)KristyB Wrote: [ -> ]Oh my god this would have taken me forever to work out, that the whole system rotates to get -y Up rather than just flipping the sinage of Y. Thank you!

Is there anywhere I can submit to have this note considered to be added to the documentation?

Flipping the signage of Y would turn it into a left-handed coordinate system.
(2021-08-28, 16:20)Roland Melkert Wrote: [ -> ]It is right handed, to get the y up it only rotates 180 degrees around x.

the picture might be confusing because it shows an arrow pointing up labeled -Y (if it was left handed it would be labeled just Y)

I'm flipping the LDR files Y/Z coordinate to switch from left-handed to right-handed coords, and then rotating 180 degrees about the x-axis to get -y up like you said, but the bricks are all still mis-aligned.

https://imgur.com/a/EwC2rc0

Picture one shows the flipping of each coordinate in a single line of ldr including each vector in the rotator, picture 2 shows flipping the axis of the rotator. I'm not entirely sure the axis of the rotator need to be flipped after each vector component's axis has also been flipped, but I have tried plugging it in straight through and still get garbled location and rotation placements.
Don't multiply any axes by -1. Simply rotate 180 degrees around the X axis.
(2021-08-31, 17:57)KristyB Wrote: [ -> ]https://imgur.com/a/EwC2rc0

To go from right handed (LDraw) to left handed (UE4) you need only to flip one axis, I think flipping the Z one is best.

But you need to do that after the whole model is loaded and assembled/flattened into a mesh.

After the z flip you need to do an additional rotation to compensate for the LDraw neg Y up and Unreal's weird z is up orientation.

But the z flip alone should give you a clean model, it will just sit on its side or something without the additional rotation.

Even without the z flip it should be a solid model it will only be mirrored.

So the most important thing is to make sure you assemble the LDraw data correctly, before worrying about the coordinate system.
(2021-08-31, 18:11)Roland Melkert Wrote: [ -> ]To go from right handed (LDraw) to left handed (UE4) you need only to flip one axis, I think flipping the Z one is best.

But you need to do that after the whole model is loaded and assembled/flattened into a mesh.

After the z flip you need to do an additional rotation to compensate for the LDraw neg Y up and Unreal's weird z is up orientation.

But the z flip alone should give you a clean model, it will just sit on its side or something without the additional rotation.

Even without the z flip it should be a solid model it will only be mirrored.

Thank you for all the help so far!

I've tried just passing the rotation and location coords straight in to setting the location and rotation of each brick, but the model it produces is still garbled beyond simply needing rotated/flipped at the end.

The ldr file I'm using for importing:
Code:
0 Untitled Model
0 Name:  UntitledModel
0 Author: 
0 CustomBrick
1 15 0.000000 -24.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 3003.dat
1 15 40.000000 -24.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 3003.dat
1 15 80.000000 -24.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 3003.dat
1 15 120.000000 -24.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 3003.dat
1 15 160.000000 -24.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 3003.dat
1 15 120.000000 -24.000000 -40.000000 1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 3003.dat
1 15 80.000000 -24.000000 -80.000000 1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 3003.dat
1 15 0.000000 -24.000000 90.000000 1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 3039.dat
1 15 30.000000 -24.000000 80.000000 0.000000 0.000000 -1.000000 0.000000 1.000000 0.000000 1.000000 0.000000 0.000000 3039.dat
1 15 80.000010 -30.000010 70.000000 1.000000 0.000000 0.000000 0.000000 0.000000 -1.000000 0.000000 1.000000 0.000000 3039.dat
1 15 110.000000 -20.000000 70.000000 0.000000 0.000000 -1.000000 -1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 3039.dat
Image of the stud.io file I generated the ldr from: https://i.imgur.com/3L3CUqW.png
Actual stud.io file I'm using, in case there's something hinky going on with Stud.IO's ldr exporter: https://drive.google.com/file/d/1xGRxNRW...sp=sharing
The results in UE4: https://i.imgur.com/242mQB0.png
Quote:So the most important thing is to make sure you assemble the LDraw data correctly, before worrying about the coordinate system.

I'm pretty confident I'm parsing the ldr lines correctly, but I'll post my node setup and explanation, as well as a preview of the output of the first line of the above ldr here as well.

Step 1: https://i.imgur.com/0UoYYXl.png
The ldr string is parsed into an array ArtificalBrickArray01, delimiting each array entry by the newline character, i.e. each entry in the array should be one line of ldr file. The commented section removes the first four lines, 0 through 3, and stores them in it's own array SetInfo, so that ArtificialBrickArray01 is just brick color/location/rotation/brickID info.

Step 2: https://i.imgur.com/vrzfOsf.png
BrickSet is an array of a custom data structure called ldrLine that follows the line type 1 format: https://i.imgur.com/QlmJMlm.png 'file' is for 'brickID'.
Step 2 loops through ArtificialBrickArray and turns each line into it's own array delimitied by a space, ' '. Each array then has each element stored into it's appropriate spot in an ldrLine structure, and has that ldrLine structure added to the end of an array 'BrickSet', resulting in an array of ldr data that can be easily broken into it's base components.  The function that does this is pretty straightforaward: https://i.imgur.com/CUijzd9.png

Step 3: https://i.imgur.com/j5c14Ot.png
The rest of the code has already been shown. From here the array of ldrLines is iterated through, each line is broken, and sorted into it's component vectors for location, and each axis of the rotator. The code in the upper right simply uses the brickID to locate a mesh in a directory, then adds that component to the blueprintInstance, scales it, and then moves on to the brick placement, which I've shown before but will show again for completion's sake.

Step 4: https://i.imgur.com/QL3xtVl.png
Pretty straight forward. I am just plugging the Location(here poorly named 'Position') into UE4's built-in SetRelativeLocationAndRotation, using the built-in Make Rotator to make a UE4 rotator out of the ldraw rotation axis.

A line from the array of ldrLines: https://i.imgur.com/hm1SI3q.png
As far as I can tell this, and every element of the array, lines up perfectly with the lines of code in the ldr file.


And finally, the actual project zipped and uploaded to gDrive: https://drive.google.com/file/d/1zq24FAv...sp=sharing
I'm not sure if asking to look at the UE4 project is in bad-taste or not when asking for help, but I'm at the end of my ability with this project.
(2021-09-01, 9:43)KristyB Wrote: [ -> ]And finally, the actual project zipped and uploaded to gDrive: https://drive.google.com/file/d/1zq24FAv...sp=sharing
I'm not sure if asking to look at the UE4 project is in bad-taste or not when asking for help, but I'm at the end of my ability with this project.
I actually wanted to take a look at UE4 at some point, but I have zero experience with it at the moment Big Grin

Maybe this weekend if there aren't too many hoops one must jump trough in order to download it.


I think the main problem is I assumed you imported the whole model as a single mesh, but it seems you are using loose bricks.

This means you need to convert the LDraw type 1 line matrices the same way the brick meshes did.

Where did the brick meshes come from?
(2021-09-01, 18:25)Roland Melkert Wrote: [ -> ]I actually wanted to take a look at UE4 at some point, but I have zero experience with it at the moment Big Grin

Maybe this weekend if there aren't too many hoops one must jump trough in order to download it.


I think the main problem is I assumed you imported the whole model as a single mesh, but it seems you are using loose bricks.

This means you need to convert the LDraw type 1 line matrices the same way the brick meshes did.

Not a lot of hoops to jump through if you're on Windows, you do need an Epic account though. Not sure about Mac, on Linux I had to compile it myself. Which wasn't terribly hoop-jumpy, I've seen worse with a lot smaller projects. HMU if you want help with any of it.

And yep, I'm aiming to build something that let's users drop an ldr file in their compiled game and have the engine read it on load to build a model out of it, hopefully to be released open-source as a tool for other game developers to use.

I'll walk through the z-flip of the type 1 lines here to make sure I am doing it right.
Flipping the z-axis for each set of coords in a line type 1: https://i.imgur.com/sBgsRFp.png
Results: https://i.imgur.com/l1p57El.png

Also flipping each axis of the rotator: https://i.imgur.com/ugFZC9t.png
Results: https://i.imgur.com/aH6oViE.png
Similar to just flipping the z-axis for each set of coords, but note the bricks on the bottom are more garbled.

Quote:Where did the brick meshes come from?
I downloaded lDraw's entire database, then import each .dat file using Toby Nelson's lDraw Importer: https://github.com/TobyLobster/ImportLDraw. I leave origins and orientations as-is. I then export as an fbx using the default transform settings, which are "-Z Forward, Y Up". This seems counterintuitive to me, but when I import them into UE4 (again using default import settings), they load visually being upright. For the project I am working on I will have to import and export every single brick anyways, so if there's transform settings here that you think would work better I could tinker with that.
Pages: 1 2