Extensions:2.4/Py/Scripts/Temp/Flatten.py

提供: wiki
< Extensions:2.4‎ | Py‎ | Scripts‎ | Temp
移動先: 案内検索
#!BPY

""" Registration info for Blender menus
Name: 'Flatten'
Blender: 234
Group: 'Mesh'
Tip: 'Flatten things along a given axis plane'
"""

# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Copyright (C) 2005 Mariano Hidalgo
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------

__author__ = "Mariano Hidalgo AKA uselessdreamer"
__url__ = ("blender", "elysiun")
__version__ = "1.0"

__bpydoc__ = """\

Flatten Vertex Loop for Blender

 This script lets you flatten things along the axis of you choose. Works
 for faces, edges and groups of vertices.
 Also usefull when deleting half of the object to perform a mirror and
 the middle loop has vertices not laying in the same plane.

 (c) 2005 Mariano Hidalgo a.k.a uselessdreamer

"""

import Blender
from Blender import NMesh, Window, Draw

wich_axis = Draw.PupMenu('Flatten at%t|  X Cursor|  Y Cursor|  Z Cursor|%l| X Median| Y Median| Z Median|')
wich_axis = wich_axis -1

is_editmode = Window.EditMode()
if is_editmode: Window.EditMode(0)
objects = Blender.Object.GetSelected()
me = NMesh.GetRaw(objects[0].data.name)

if wich_axis == -1: Exit()

if wich_axis < 3 :
  curpos = Window.GetCursorPos()
  print curpos
  for v in me.verts:
     if v.sel: v.co[wich_axis] = curpos[wich_axis]
else:
  count = 0
  midpoint = 0
  for v in me.verts:
    if v.sel:
      count = count + 1
      midpoint = midpoint + v.co[wich_axis-4]
  midpoint = midpoint /count

  for v in me.verts:
    if v.sel: v.co[wich_axis-4] = midpoint

me.update()
Draw.Redraw()