Hey folks,
I’m looking for a way to calculate a transformation matrix that will take a face (BMFace) and “flatten” via rotation so that its face normal is parallel with the world Z axis. The matrix will be applied to each vertex in the face. The significant bit is that I also need to be able to reverse it to get each vertex back to its original location. I don’t want to store each vert’s original location as I might move some of them around on the virtual X/Y plane before reverting the face to its original orientation — I may also drop new points down onto the face (just a good old Vector3) and want them to “stick” in position on the face when it’s reoriented back to its original rotation.
Hopefully I haven’t butchered that description, any ideas?
For a rudimentary visual reference, here’s what I’m looking to achieve. The face in its original orientation:
And after it’s been “flattened”:
On my phone so I can’t type a bunch of code- but I can give you the basic idea if that helps you along.
The short version is that you need to create a vector that is the difference between your face’s normal and where you want it to be.
Let’s pretend the face normal is (.5, .5, .5) and you know you want it to face up: (0, 0, 1), that gives us a delta vector of (.5, .5, -.5).
once you have that, you can create an Euler/Quaternion out of it and then compose a new 3x3 matrix using the center of the face (or whatever ‘pivot point’ you like) as the translation component.
once you have a matrix, just multiply each vert by that matrix and you’ll have a face that is ‘rotated flat’. as long as you keep your matrix around you should be able to re-rotate the face back into its original orientation.
It sounds exactly like what I’m after. Given your description, I’ll attempt it and see if I can get it to work, but if you have the opportunity to provide some example code later (absolutely no rush), I’ll check to see if I’m on the right track. Appreciate your help!