Automatic matrix corrections - Printable Version +- LDraw.org Discussion Forums (https://forums.ldraw.org) +-- Forum: Models and Parts (https://forums.ldraw.org/forum-18.html) +--- Forum: Parts Authoring (https://forums.ldraw.org/forum-19.html) +--- Thread: Automatic matrix corrections (/thread-1519.html) |
Automatic matrix corrections - Roland Melkert - 2011-11-25 Hello all, I discovered rendering glitches in the Linux version of my LDCad are caused by the limited way I correct 'invalid' matrices in part files. The wrong matrices cause all kinds of lighting problems in Ubuntu 11.10 with the open source radeon driver. Yet for some reason the windows driver couldn't care less, how's that even possible? Anyhow I'm improving the correction code, but not being a part editor or a matrix expert I'm having difficulties with it. For example I can correct these (log fragment): Code: parts\2694.dat | line 164 | Matrix corrected from [10 0 0 0 0 0 0 0 10 ] to [10 0 0 0 1 0 0 0 10 ] These all have exactly one row that's all zero's, the position for an automatic '1' can be determined quite easily. But what about these: Code: parts\3039p32.dat | line 40 | Invalid matrix detected [2 0 0 0 0 1.4286 0 0 -1.4286]. It could not be corrected automatically, it might cause rendering glitches. I'm guessing the middle '1.4...' should move one place to the left, but how to automatically detect and correct for this (you could also do this for the 3rd row not?). And these are even worse I think: Code: parts\6016.dat | line 38 | Invalid matrix detected [2.84 0 2.84 0 0 0 2.84 0 -2.84]. It could not be corrected automatically, it might cause rendering glitches. Or could I just put a '1' in the middle row's middle pos?, but yet again how to do a fool proof correction. Any help would be appreciated. Or maybe someone could just fix all the part files (just kidding ) Re: Automatic matrix corrections - Tim Gould - 2011-11-25 > Or could I just put a '1' in the middle row's > middle pos?, but yet again how to do a fool proof > correction. Without knowing the intention of the matrix you can't! Firstly I think you should always assume that what is already in a column belongs there. However, what you do know is that no column should contain only zeroes. So if one does a simple fix would be to replace it by the cross product of the other two columns renormalised to 1. That way it will be orthogonal to the others columns but not large. If, as in the examples you give, the parts are flat and the third dimension is ignored then this will work perfectly. This solution works for all the examples you give eg. Code: M=[-2.84 0 -2.84 0 0 0 2.84 0 -2.84] > Any help would be appreciated. > > > Or maybe someone could just fix all the part files > (just kidding ) I think this would be the better solution. Tim Re: Automatic matrix corrections - Tim Gould - 2011-11-25 > Code: > parts\3039p32.dat | line 40 | Invalid matrix > I'm guessing the middle '1.4...' should move one > place to the left, but how to automatically detect > and correct for this (you could also do this for > the 3rd row not?). Actually it shouldn't. The 'proper' matrix is given by the rule I state and is Code: [2 0 0 0 0.7071 1.4286 0 0.7071 -1.4286] Re: Automatic matrix corrections - Roland Melkert - 2011-11-25 Brilliant, using the cross product just like with normals that's a much nicer approach then just tossing in a '1' somewhere. I'm going to change it so if ether (exactly) one row or col is all zero's it fills it with the crossproduct of the other two rows/cols. That should take care of most, if not all, det==0 problems. Thank you very much. Re: Automatic matrix corrections - Tim Gould - 2011-11-25 It should work on all flat parts that are otherwise correct. It basically comes from the fact that a plane is overdescribed by three vectors so you can simply set the third vector to be perpendicular and normalised. If you have two zero columns I think the part should be flagged as a dud. That's remapping a 3d object to a line and since there's no reason to ever do this it's definitely incorrect. Tim Re: Automatic matrix corrections - Roland Melkert - 2011-11-26 Thanks again, It turns out (most of) the actual rendering glitches are caused by a bug in the Open source Radeon driver in Ubuntu 11.10 (it doesn't apply two sided lighting correctly). But still thanks for this approach, parts like the model team wheel look nicer now. Re: Automatic matrix corrections - Travis Cobbs - 2011-11-28 I realize you've already had replies, but if you're still having problems, please look at the LDLModelLine::tryToFixPlanarMatrix() function in LDView's source code here. |