Today I have fixed an issue with object alignment with the surface. I forgot a couple of issues we face in trigonometry when calculating tangents. That's because tangents cannot be calculated at the poles, and my code didn't account for that. This is actually the reason why Euler rotations used in Poser face gridlock glitches. When we rotate objects at angles close to the poles, the rotation becomes unstable and jumps around at random. My object alignment code now accounts for that.
Another thing was that tangents behave differently at different quadrants. The result was objects aligning correctly at one side of a slope, and then getting twisted/inverted at the other side. The code now accounts for that, too.
HOWEVER, while doing this, I have discovered something new about Poser that I hadn't noticed before. We already know Poser doesn't use normals from OBJs, preferring to calculate its own. That is good and dandy with a surface - until we start morphing it out inside Poser. The more a morph changes the surface original shape, that is, the larger the morph deltas, the most disturbed the normal vectors become. As a result, morphs can cause vertex normals to point to unexpected directions. Of course, this affects object alignment, because these vertex normal vectors from Poser are the only thing I have to calculate the alignment.
We can see some of this in the image below. The red sticks are cubes I have reshaped to make it easier to see in what direction they are pointing to, which means how well aligned they are with the surface. For the most part, it looks quite good. However, there are a couple of sticks that are way off the correct alignment, and this seems to get worse with more extreme morphs. Anyway, I am glad it works for the most part (>98%), in both placement and alignment. ^_____^