diff options
author | Jiri Hnidek <jiri.hnidek@tul.cz> | 2004-12-12 16:42:49 +0300 |
---|---|---|
committer | Jiri Hnidek <jiri.hnidek@tul.cz> | 2004-12-12 16:42:49 +0300 |
commit | 20f463234015c72ef0d866128b944221719487c4 (patch) | |
tree | 4ac4d8557c538c8fc9d4ac1a7226c189916b5805 /release/scripts/obj_export.py | |
parent | d12960dd2d44cd28959ccabaad39540e52083dc4 (diff) |
- bug fix #1874
https://projects.blender.org/tracker/?func=detail&aid=1874&group_id=9&atid=125
normal vectors of vertexes are exported correctly now
Diffstat (limited to 'release/scripts/obj_export.py')
-rw-r--r-- | release/scripts/obj_export.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/release/scripts/obj_export.py b/release/scripts/obj_export.py index cba44b6ea61..cd37ee571fb 100644 --- a/release/scripts/obj_export.py +++ b/release/scripts/obj_export.py @@ -7,7 +7,7 @@ Group: 'Export' Tooltip: 'Save a Wavefront OBJ File' """ -__author__ = "Campbell Barton" +__author__ = "Campbell Barton, Jiri Hnidek" __url__ = ["blender", "elysiun"] __version__ = "0.9" @@ -62,10 +62,18 @@ def stripPath(path): #==================# # Apply Transform # #==================# -def apply_transform(vert, matrix): +def apply_transform(vert, matrix_4x4): vertCopy = Mathutils.CopyVec(vert) vertCopy.resize4D() - return Mathutils.VecMultMat(vertCopy, matrix) + return Mathutils.VecMultMat(vertCopy, matrix_4x4) + +#=================================# +# Apply Transform (normal vector) # +#=================================# +def apply_normal_transform(norm, matrix_3x3): + vertCopy = Mathutils.CopyVec(norm) + vertCopy.resize3D() + return Mathutils.VecMultMat(vertCopy, matrix_3x3) from Blender import * @@ -148,12 +156,17 @@ def save_obj(filename): file.write('o %s_%s\n' % (ob.getName(), m.name)) # Write Object name # Works 100% Yay - matrix = ob.getMatrix('worldspace') + matrix_4x4 = ob.getMatrix('worldspace') + + # matrix for transformation of normal vectors + matrix_3x3 = Mathutils.Matrix([matrix_4x4[0][0], matrix_4x4[0][1], matrix_4x4[0][2]], + [matrix_4x4[1][0], matrix_4x4[1][1], matrix_4x4[1][2]], + [matrix_4x4[2][0], matrix_4x4[2][1], matrix_4x4[2][2]]) # Vert for v in m.verts: # Transform the vert - vTx = apply_transform(v.co, matrix) + vTx = apply_transform(v.co, matrix_4x4) file.write('v %s %s %s\n' % (vTx[0], vTx[1], vTx[2])) # UV @@ -168,7 +181,7 @@ def save_obj(filename): for f1 in m.faces: for v in f1.v: # Transform the normal - noTx = apply_transform(v.no, matrix) + noTx = apply_normal_transform(v.no, matrix_3x3) noTx.normalize() file.write('vn %s %s %s\n' % (noTx[0], noTx[1], noTx[2])) |