Sunday, June 14, 2009

I'm not stupid :-)




import maya.cmds as cmds

def IsBounded(item):
for x in item:
if x < 0:
return False
return True

class delauney:
def __init__(self):
self.vertices = []
self.regions = []
self.dimension = ""
self.path = "C:/MAYA/"
print "Instance of class Delauney created."

def load(self):
# Get vertices positions in the points.txt

print "Loading Qhull file..."
# Open the file and get the second line in order to get the number of vertices
f = open('C:/MAYA/points.txt', 'r')
d = f.readline()
i = f.readline()
i = int(i.strip())

# Get line by line the x, y positions (and z if it exists)
while i > 0:
l = f.readline()
t = l.split()
pt1 = float(t[0])
pt2 = float(t[1])
if len(t) > 2:
pt3 = float(t[2])
self.dimension = "3D"
self.vertices.append([pt1, pt2, pt3])

else:
pt3 = 0
self.dimension = "2D"
self.vertices.append([pt1, pt2])
i = i-1

# Feedback
print ">>> RESULTS"
print len(self.vertices), " vertices ", self.vertices

# Open the qHullResults.txt in order to get the name of the points to join.
# Get the first number, in order to get number of regions
# Daniel, I'm sorry for the hardcoding for the names of the files, and for the "region.append(int(t[2]))" if its not a 3D drawing, but i'm really tired
f = open('C:/MAYA/qHullResults.txt', 'r')
l = f.readline()
i = int(l)

# Get line by line the name of the points to join
while i > 0:
l = f.readline()
t = l.split()
region = []
j=0
while j < i:
region.append(int(t[0]))
region.append(int(t[1]))
region.append(int(t[2]))
j = j + 1
self.regions.append(region)
i = i-1

# Feedback
print len(self.regions), " regions ", self.regions
f.close()

def draw(self):
# draw a curve between the points to create the regions!

for region in filter(IsBounded, self.regions):
vs = []
neg = 0

for i in region:
if i < 0:
neg = 1
break

v = self.vertices[i]
vs.append(v)

if neg == 0:
crv = cmds.curve(ep=vs, d=1)
cmds.closeCurve(crv, rpo=1)

No comments:

Post a Comment