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

  1. #!BPY
  2.  
  3. """
  4. Name: 'Apply Deformation'
  5. Blender: 234
  6. Group: 'Mesh'
  7. Tooltip: 'Create fixed copies of deformed meshes'
  8. """ 
  9.  
  10. __author__ = "Martin 'theeth' Poirier"
  11. __url__ = ("http://www.blender.org", "http://www.elysiun.com")
  12. __version__ = "1.5 09/21/04"
  13.  
  14. __bpydoc__ = """\
  15. This script creates "raw" copies of deformed meshes.
  16.  
  17. Usage:
  18.  
  19. Select the mesh(es) and run this script.  A fixed copy of each selected mesh
  20. will be created, with the word "_deformed" appended to its name. If an object with
  21. the same name already exists, it appends a number at the end as Blender itself does.
  22.  
  23. Meshes in Blender can be deformed by armatures, lattices, curve objects and subdivision, but this will only change its appearance on screen and rendered
  24. images -- the actual mesh data is still simpler, with vertices in an original
  25. "rest" position and less vertices than the subdivided version.
  26.  
  27. Use this script if you want a "real" version of the deformed mesh, so you can
  28. directly manipulate or export its data.
  29. """
  30.  
  31.  
  32. # $Id: Apply_def.py,v 1.5 2005/02/14 01:26:07 theeth Exp $
  33. #
  34. # --------------------------------------------------------------------------
  35. # ***** BEGIN GPL LICENSE BLOCK *****
  36. #
  37. # Copyright (C) 2003: Martin Poirier, theeth@yahoo.com
  38. #
  39. # Thanks to Jonathan Hudson for help with the vertex groups part
  40. #
  41. # This program is free software; you can redistribute it and/or
  42. # modify it under the terms of the GNU General Public License
  43. # as published by the Free Software Foundation; either version 2
  44. # of the License, or (at your option) any later version.
  45. #
  46. # This program is distributed in the hope that it will be useful,
  47. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  48. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  49. # GNU General Public License for more details.
  50. #
  51. # You should have received a copy of the GNU General Public License
  52. # along with this program; if not, write to the Free Software Foundation,
  53. # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  54. #
  55. # ***** END GPL LICENCE BLOCK *****
  56.  
  57. import Blender
  58.  
  59. Blender.Window.EditMode(0)
  60.  
  61. ob_list = Blender.Object.GetSelected()
  62. for ob in ob_list:
  63.     if ob.getType() == "Mesh":
  64.         name = ob.getName()
  65.         new_name = name + "_deformed"
  66.         num = 0
  67.         new_mesh = Blender.NMesh.GetRawFromObject(name)
  68.         mesh = Blender.NMesh.GetRaw(new_name)
  69.         while mesh:
  70.             num += 1
  71.             new_name = name + "_deformed." + "%03i" % num
  72.             mesh = Blender.NMesh.GetRaw(new_name)
  73.         new_ob = Blender.NMesh.PutRaw(new_mesh, new_name)
  74.         new_ob.setMatrix(ob.getMatrix())
  75.         try:
  76.             new_ob = Blender.Object.Get(new_name)
  77.             while 1:
  78.                 num += 1
  79.                 new_name = name + "_deformed." + "%03i" % num
  80.                 new_ob = Blender.Object.Get(new_name)
  81.         except:
  82.             pass
  83.         new_ob.setName(new_name)
  84.  
  85.         ob_mesh = ob.getData()
  86.         new_ob_mesh = new_ob.getData()
  87.  
  88.         # If SubSurf is off on the original, copy the vertex weight
  89.         if not ob_mesh.getMode() & Blender.NMesh.Modes['SUBSURF']:
  90.             for vgroupname in ob_mesh.getVertGroupNames():
  91.                 vlist = ob_mesh.getVertsFromGroup(vgroupname, True)
  92.                 new_ob_mesh.addVertGroup(vgroupname)
  93.                 for vpair in vlist:
  94.                     new_ob_mesh.assignVertsToGroup(vgroupname, [vpair[0]], vpair[1], 'add')
  95.         # If it's on, just add the vertex groups
  96.         else:
  97.             for vgroupname in ob_mesh.getVertGroupNames():
  98.                 new_ob_mesh.addVertGroup(vgroupname)
  99.  
  100.         new_ob_mesh.update()
  101.  
  102. Blender.Window.EditMode(1)
  103.