File: BPyNMesh.py

package info (click to toggle)
blender 2.42a-8
  • links: PTS
  • area: main
  • in suites: etch
  • size: 60,724 kB
  • ctags: 83,393
  • sloc: ansic: 576,763; cpp: 187,760; python: 48,472; sh: 15,811; makefile: 4,298; perl: 2,082; asm: 1,471; java: 8
file content (48 lines) | stat: -rw-r--r-- 2,170 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# $Id: BPyNMesh.py,v 1.1 2005/05/17 07:17:52 ianwill Exp $
#
# --------------------------------------------------------------------------
# BPyNMesh.py version 0.1
# --------------------------------------------------------------------------
# helper functions to be used by other scripts
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# 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 *****
# --------------------------------------------------------------------------


# --------------------------------------------------------------------------
# "Apply size and rotation" function by Jonas Petersen
# --------------------------------------------------------------------------
# This function does (hopefully) exactly what the
# "Apply size and rotation" command does (CTRL-A in Object Mode).
def ApplySizeAndRotation(obj): 
	if obj.getType() != "Mesh": return
	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
	mesh = obj.getData()
	matrix = obj.matrix
	v = [0,0,0]
	for vert in mesh.verts:
		co = vert.co
		v[0] = co[0]*matrix[0][0] + co[1]*matrix[1][0] + co[2]*matrix[2][0] 
		v[1] = co[0]*matrix[0][1] + co[1]*matrix[1][1] + co[2]*matrix[2][1]
		v[2] = co[0]*matrix[0][2] + co[1]*matrix[1][2] + co[2]*matrix[2][2]
		co[0], co[1], co[2] = v
	obj.SizeX = obj.SizeY = obj.SizeZ = 1.0
	obj.RotX = obj.RotY = obj.RotZ = 0.0
	mesh.update()