All pastes #476592 Raw Edit

MrArmadillo

public python v1 · immutable
·published 2007-05-08 06:12 UTC
rendered paste body
##Generate the Node TreepathTree = Blender.Mesh.Get("Path")def dist(a,b):	return ((a[0]-b[0])**2+(a[1]-b[1])**2+(a[2]-b[2])**2)**.5class node:                             #each node is a class!	def __init__(self,coord):           #containing:		self.neighbors = {}             #empty dictionary		self.distance = 0 		self.coord = coord		class path:	def __init__(self,nodes,distance,length):		self.nodes = nodes		self.distance = distance		self.length = length		def generateTree(pathTree):	nodes = {}  # a dictionary, not to be confused with class 'node'	for v in pathTree.verts:		nodes[v.index] = node(v.co) #adds a _class_ 'node' to the dictionary 'nodes'	for edge in pathTree.edges:		distance = dist(edge.v1.co , edge.v2.co)		nodes[edge.v1.index].neighbors[edge.v2.index] = distance #appends a new key:value pair in the dictionary 'neighbors'		nodes[edge.v2.index].neighbors[edge.v1.index] = distance	return nodes#############if not hasattr(GameLogic,"nodes"):	g.nodes = generateTree(pathTree)##############print "\t ALL node vectors:"#for node in g.nodes:#	print node , "\t", g.nodes.values()[node].coprint g.nodes.values()[0].neighbors.values() #g.nodes is a dictionary with verticie index keys, class instances 'node' as values. #'neighbors' is a dictionary within the class instance 'node,' with neighboring verticies as keys, and their distance from the 'node.coords' as values.