File: BPyCurve.py

package info (click to toggle)
blender 2.49.2~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 89,664 kB
  • ctags: 113,718
  • sloc: ansic: 738,048; cpp: 231,960; python: 104,955; asm: 33,960; sh: 16,233; ml: 12,962; makefile: 4,477; perl: 3,474; fortran: 108; java: 8
file content (79 lines) | stat: -rw-r--r-- 2,300 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# --------------------------------------------------------------------------
# BPyImage.py version 0.15
# --------------------------------------------------------------------------
# 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 *****
# --------------------------------------------------------------------------

from Blender import *

def curve2vecs(ob, WORLDSPACE= True):
	'''
	Takes a curve object and retuirns a list of vec lists (polylines)
	one list per curve
	
	This is usefull as a way to get a polyline per curve
	so as not to have to deal with the spline types directly
	'''
	if ob.type != 'Curve':
		raise 'must be a curve object'
	
	me_dummy = Mesh.New()
	me_dummy.getFromObject(ob)
	
	if WORLDSPACE:
		me_dummy.transform(ob.matrixWorld)
	
	# build an edge dict
	edges = {} # should be a set
	
	def sort_pair(i1, i2):
		if i1 > i2:		return i2, i1
		else:			return i1, i2
	
	for ed in me_dummy.edges:
		edges[sort_pair(ed.v1.index,ed.v2.index)] = None # dummy value
	
	# now set the curves
	first_time = True
	
	current_vecs = []
	vec_list = [current_vecs]
	
	for v in me_dummy.verts:
		if first_time:
			first_time = False
			current_vecs.append(v.co.copy())
			last_index = v.index
		else:
			index = v.index
			if edges.has_key(sort_pair(index, last_index)):
				current_vecs.append( v.co.copy() )
			else:
				current_vecs = []
				vec_list.append(current_vecs)
			
			last_index = index
	
	me_dummy.verts = None
	
	return vec_list