So first of all, as a little announcement, I've started work on a virtual reality lego builder, which I'm really excited for, and a lot of the work's already done, but I've only recently started on the work for actually allowing the LDraw .dat files to be used to load in bricks instead of inefficiently storing the bricks as models. I'm using the game engine unity since I have a reasonable amount of experience with it and integrating VR is easy-peasy, but now I'm having problems getting the normals to display correctly.
I'm aware of BFC and winding, and I've taken an example of little bits and bobs from the old LDrawToObj convertor from Rold Redford (https://github.com/rredford/LdrawToObj) and that got me most of the way there, but now I'm stuck with some issues with faces not having correct normals. I have to admit I think that it's a bit difficult to explain why this is happening since I don't really know what I'm missing, but I hope that when I share some images and examples other people might be able to help me out. I can post the C# code I'm using if anyone thinks it'll help, but it's fairly messy and lacking comments so I don't think it'll be too useful.
On top of that, apologies if this forum already holds the answer to my question, but I wasn't able to find it.
So here we have the standard 2x2 brick. This brick is generated perfectly except that the 4 quads at the bottom of the brick are facing the wrong way. The winding should be correct, and the inversion system should be correct, else how could the rest of the brick generate perfectly? The only real repeating logic I can see with this problem is that (as far as I'm aware) normals never face the right way when primitives are created in the base brick file, only in subparts. But how is that possible? Are there some rules that I'm missing here?
But primitives in the root file aren't the only ones to not work consistently; for instance here in the 2x3 brick:
The same four quads at the bototm are inverted, but also one of the faces of the outer box-5. This image has my debug-lines enabled so you can see the shape it's supposed to have more clearly. (Note that the normals on the inside of the brick are correct, since you are supposed to see through them from this angle.)
Lastly, the standard 2x4 brick shows some strange behaviour. This might be an unrelated issue and this is the only brick I've tested where this problem occurs (it's also easily fixable by changing one of the transformations in the 2x4 brick file, but that cant be right.) but I'm posting it here anyways just in case some very clever person can tell me that that's related to the same issue.
Thanks so much for anyone willing to help me out here! I've been stuck on this for ages...
I'm aware of BFC and winding, and I've taken an example of little bits and bobs from the old LDrawToObj convertor from Rold Redford (https://github.com/rredford/LdrawToObj) and that got me most of the way there, but now I'm stuck with some issues with faces not having correct normals. I have to admit I think that it's a bit difficult to explain why this is happening since I don't really know what I'm missing, but I hope that when I share some images and examples other people might be able to help me out. I can post the C# code I'm using if anyone thinks it'll help, but it's fairly messy and lacking comments so I don't think it'll be too useful.
On top of that, apologies if this forum already holds the answer to my question, but I wasn't able to find it.
So here we have the standard 2x2 brick. This brick is generated perfectly except that the 4 quads at the bottom of the brick are facing the wrong way. The winding should be correct, and the inversion system should be correct, else how could the rest of the brick generate perfectly? The only real repeating logic I can see with this problem is that (as far as I'm aware) normals never face the right way when primitives are created in the base brick file, only in subparts. But how is that possible? Are there some rules that I'm missing here?
But primitives in the root file aren't the only ones to not work consistently; for instance here in the 2x3 brick:
The same four quads at the bototm are inverted, but also one of the faces of the outer box-5. This image has my debug-lines enabled so you can see the shape it's supposed to have more clearly. (Note that the normals on the inside of the brick are correct, since you are supposed to see through them from this angle.)
Lastly, the standard 2x4 brick shows some strange behaviour. This might be an unrelated issue and this is the only brick I've tested where this problem occurs (it's also easily fixable by changing one of the transformations in the 2x4 brick file, but that cant be right.) but I'm posting it here anyways just in case some very clever person can tell me that that's related to the same issue.
Thanks so much for anyone willing to help me out here! I've been stuck on this for ages...