home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2005 November / WNnov2005.iso / Windows / Equipement / Blender / blender-2.37a-windows.exe / $_5_ / .blender / scripts / Axiscopy.py < prev    next >
Text File  |  2004-11-07  |  4KB  |  116 lines

  1. #!BPY
  2.  
  3. """ Registration info for Blender menus: <- these words are ignored
  4. Name: 'Axis Orientation Copy'
  5. Blender: 233
  6. Group: 'Object'
  7. Tip: 'Copy the axis orientation of the active object to all selected mesh objects'
  8. """
  9.  
  10. __author__ = "A Vanpoucke (xand)"
  11. __url__ = ("blender", "elysiun",
  12. "French Blender support forum, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender")
  13. __version__ = "1.1 11/05/04"
  14.  
  15. __bpydoc__ = """\
  16. This script copies the axis orientation -- X, Y and Z rotations -- of the
  17. active object to all selected meshes.
  18.  
  19. It's useful to align the orientations of all meshes of a structure, a human
  20. skeleton, for example.
  21.  
  22. Usage:
  23.  
  24. Select all mesh objects that need to have their orientations changed
  25. (reminder: keep SHIFT pressed after the first, to add each new one to the
  26. selection), then select the object whose orientation will be copied from and
  27. finally run this script to update the angles.
  28.  
  29. Notes:<br>
  30.     Before copying the orientation to each object, the script stores its
  31. transformation matrix.  Then the angles are copied and after that the object's
  32. vertices are transformed "back" so that they still have the same positions as
  33. before.  In other words, the rotations are updated, but you won't notice that
  34. just from looking at the objects.<br>
  35.     Checking their X, Y and Z rotation values with "Transform Properties" in
  36. the 3D View's Object menu shows the angles are now the same of the active
  37. object.
  38. """
  39.  
  40.  
  41. # $Id: Axiscopy.py,v 1.2 2004/11/07 16:31:13 ianwill Exp $
  42. #
  43. #----------------------------------------------
  44. # A Vanpoucke (xand)
  45. #from the previous script realignaxis
  46. #----------------------------------------------
  47. # Communiquer les problemes et erreurs sur:
  48. #   http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
  49. # --------------------------------------------------------------------------
  50. # ***** BEGIN GPL LICENSE BLOCK *****
  51. #
  52. # Copyright (C) 2003, 2004: A Vanpoucke
  53. #
  54. # This program is free software; you can redistribute it and/or
  55. # modify it under the terms of the GNU General Public License
  56. # as published by the Free Software Foundation; either version 2
  57. # of the License, or (at your option) any later version.
  58. #
  59. # This program is distributed in the hope that it will be useful,
  60. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  61. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  62. # GNU General Public License for more details.
  63. #
  64. # You should have received a copy of the GNU General Public License
  65. # along with this program; if not, write to the Free Software Foundation,
  66. # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  67. #
  68. # ***** END GPL LICENCE BLOCK *****
  69. # --------------------------------------------------------------------------
  70.  
  71. from Blender import *
  72. from Blender import Mathutils
  73. from Blender.Mathutils import *
  74.  
  75.  
  76. def applyTransform(mesh,mat):
  77.   for v in mesh.verts:
  78.       vec = VecMultMat(v.co,mat)
  79.       v.co[0], v.co[1], v.co[2] = vec[0], vec[1], vec[2]
  80.  
  81.  
  82.  
  83.  
  84. oblist =Object.GetSelected()
  85. lenob=len(oblist)
  86.  
  87. error = 0
  88. for o in oblist[1:]:
  89.     if o.getType() != "Mesh":
  90.         Draw.PupMenu("ERROR%t|Selected objects must be meshes")
  91.         error = 1
  92.  
  93. if not error:
  94.     if lenob<2:
  95.         Draw.PupMenu("ERROR%t|You must select at least 2 objects")
  96.     else :    
  97.         source=oblist[0]
  98.         nsource=source.name
  99.         texte="Copy axis orientation from: " + nsource + " ?%t|OK"
  100.         result=Draw.PupMenu(texte)
  101.  
  102.  
  103.         for cible in oblist[1:]:
  104.             if source.rot!=cible.rot:
  105.                 rotcible=cible.mat.toEuler().toMatrix()
  106.                 rotsource=source.mat.toEuler().toMatrix()
  107.                 rotsourcet = CopyMat(rotsource)
  108.                 rotsourcet.invert()
  109.                 mat=rotcible*rotsourcet
  110.                 ncible=cible.name
  111.                 me=NMesh.GetRaw(ncible)
  112.                 applyTransform(me,mat)
  113.                 NMesh.PutRaw(me,ncible)
  114.                 cible.makeDisplayList()
  115.                 cible.rot=source.rot
  116.