[Bf-python] Applying an Object matrix using mathutils.

Joseph Gilbert models at paposo.com
Tue Jun 8 03:30:22 CEST 2004


Mathutils handles 2D, 3D and 4D vectors and 2x? 3x? and 4x? square and
non-square matrix types. Mathutils should handle this kind of stuff.
Take the vector and resize it to 4D using the internal method
vector.resize4D() or get the rotation and transformation parts of the 4x4
matrix using mat.transformationPart() and mat.rotationPart().


-----Original Message-----
From: bf-python-admin at blender.org [mailto:bf-python-admin at blender.org]On
Behalf Of Campbell Barton
Sent: Monday, June 07, 2004 7:32 PM
To: bf-python at blender.org
Subject: [Bf-python] Applying an Object matrix using mathutils.


Im just writing because I think there must be a better way to apply an
object matrix when exporting vert positions.

The problem is that I cant use Mathutils because a vector is a [3]
length vector and an object matrix is 4x4.

I have used the function below, mabe It can be done in mathutils, or an
extra function that replaces this could be added to mathutils.
- Cam


#==================#
# Apply Transform  #
#==================#
def apply_transform(vert, matrix):
   x, y, z = vert
   xloc, yloc, zloc = matrix[3][0], matrix[3][1], matrix[3][2]
   xcomponent = x*matrix[0][0] + y*matrix[1][0] + z*matrix[2][0] + xloc
   ycomponent = x*matrix[0][1] + y*matrix[1][1] + z*matrix[2][1] + yloc
   zcomponent = x*matrix[0][2] + y*matrix[1][2] + z*matrix[2][2] + zloc

   return [xcomponent, ycomponent, zcomponent]
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://www.blender.org/mailman/listinfo/bf-python





More information about the Bf-python mailing list