Nadnerb wrote:- Code: Select all
Nor = tmatrix.rotationPart() * Blender.Mathutils.Vector(face.no)
Nor.normalize()
OK, I've just tried this: In a new, empty Blender document, add a "plane" and go into edit mode. Grab its left two vertices and move them up by 2 units (G-Z-2), so that the face is at a 45° angle. Go to object mode and scale the object by 2 in the Z direction (S-Z-2). Then run the following session in the interactive Python console:
- Code: Select all
>>> o = bpy.data.scenes.active.objects.active
>>> o.getMatrix()
[1.000000, 0.000000, 0.000000, 0.000000](matrix [row 0])
[0.000000, 1.000000, 0.000000, 0.000000](matrix [row 1])
[0.000000, 0.000000, 2.000000, 0.000000](matrix [row 2])
[0.000000, 0.000000, 0.000000, 1.000000](matrix [row 3])
>>> n = o.getData(mesh=True).faces[0].no
>>> n
[0.707107, -0.000000, 0.707107](vector)
>>> o.getMatrix().rotationPart() * Blender.Mathutils.Vector(n)
[0.707107, -0.000000, 1.414214](vector)
# wrong normal!
>>> o.getMatrix().rotationPart().invert().transpose() * Blender.Mathutils.Vector(n)
[0.707107, -0.000000, 0.353553](vector)
>>> r = _.normalize()
>>> r
[0.894427, -0.000000, 0.447214](vector)
# correct normal!
q.e.d., the inverse-transpose is needed.
Nadnerb wrote:As to the change I didn't explain in my first post, we shouldn't need to invert the resulting vector (* -1) as multiplying it by the already transposed matrix (unfortunlately left out of the picture before) should accomplish what we're after. You'll have to test that though, as that doesn't seem to make it equivalent to the fix you posted as working.
As far as I can tell, the *-1 is what defines that where the Blender normal points is the inside of the volume. If you leave it away, where the Blender normal points becomes the outside of the volume. I do think that the latter way makes more sense, since outward-pointing normals are the default when you make a new mesh in Blender, but I don't think that we should break everyone's existing soft volumes now by changing that.
Also, Nadnerb, while I have your attention, since you seem to have some experience in this area: Do you have any opinion on whether it's a good idea to transpose the object's matrix in-place instead of operating on a copy, as I've wondered in the first post?