home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2005 November / WNnov2005.iso / Windows / Equipement / Blender / blender-2.37a-windows.exe / $_5_ / .blender / scripts / bpymodules / BPyNMesh.py < prev    next >
Text File  |  2005-05-17  |  2KB  |  49 lines

  1. # $Id: BPyNMesh.py,v 1.1 2005/05/17 07:17:52 ianwill Exp $
  2. #
  3. # --------------------------------------------------------------------------
  4. # BPyNMesh.py version 0.1
  5. # --------------------------------------------------------------------------
  6. # helper functions to be used by other scripts
  7. # --------------------------------------------------------------------------
  8. # ***** BEGIN GPL LICENSE BLOCK *****
  9. #
  10. # This program is free software; you can redistribute it and/or
  11. # modify it under the terms of the GNU General Public License
  12. # as published by the Free Software Foundation; either version 2
  13. # of the License, or (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program; if not, write to the Free Software Foundation,
  22. # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  23. #
  24. # ***** END GPL LICENCE BLOCK *****
  25. # --------------------------------------------------------------------------
  26.  
  27.  
  28. # --------------------------------------------------------------------------
  29. # "Apply size and rotation" function by Jonas Petersen
  30. # --------------------------------------------------------------------------
  31. # This function does (hopefully) exactly what the
  32. # "Apply size and rotation" command does (CTRL-A in Object Mode).
  33. def ApplySizeAndRotation(obj): 
  34.     if obj.getType() != "Mesh": return
  35.     if obj.SizeX==1.0 and obj.SizeY==1.0 and obj.SizeZ==1.0 and obj.RotX == 0.0 and obj.RotY == 0.0 and obj.RotZ == 0.0: return
  36.     mesh = obj.getData()
  37.     matrix = obj.matrix
  38.     v = [0,0,0]
  39.     for vert in mesh.verts:
  40.         co = vert.co
  41.         v[0] = co[0]*matrix[0][0] + co[1]*matrix[1][0] + co[2]*matrix[2][0] 
  42.         v[1] = co[0]*matrix[0][1] + co[1]*matrix[1][1] + co[2]*matrix[2][1]
  43.         v[2] = co[0]*matrix[0][2] + co[1]*matrix[1][2] + co[2]*matrix[2][2]
  44.         co[0], co[1], co[2] = v
  45.     obj.SizeX = obj.SizeY = obj.SizeZ = 1.0
  46.     obj.RotX = obj.RotY = obj.RotZ = 0.0
  47.     mesh.update()
  48.  
  49.