From: Jamie R. <jam...@gm...> - 2009-08-03 18:29:09
|
Bruce, Your suggestion for a quicker way to reset faces objects works great. Thanks for pointing this out. It is a significant speedup if recalculating lots of faces objects. Also, I copied the "try norm" lines right out of faces_heightfield.py in the examples folder. Probably should change that as it looks like it is no longer (if it ever was) needed. Thanks for you time on this - Jamie Riotto On Sat, Aug 1, 2009 at 3:09 PM, Bruce Sherwood<Bru...@nc...> wrote: > It occurred to me to try a different approach to the issue of deleting a > faces object and recreating it. I would guess that performance ought to > be significantly better if you simply change the faces.pos array as in > the following version. > > Also note the minor point that it isn't necessary to "try" whether > norm(v) works and then making v = vector(0,0,0) if it doesn't work. As > the documentation for vector operations in Visual says, if v is > vector(0,0,0), as a convenience norm(v) returns vector(0,0,0), just as > you wanted. > > Bruce Sherwood > ------------------------- > > from __future__ import division > from visual import * > > newframe = frame > > class Object(object): > > def __init__(self, parent=None, frame=None, pos=(0,0,0), axis=(1,0,0), > color=color.green): > self.frame = newframe(frame=frame, pos=pos, axis=axis) > self.surface = faces(frame=self.frame) > self.color = color > self.clearSurface() > > def clearSurface(self): > self.surface.pos = [] > self.vertexList = [] > self.normalList = [] > self.colorList = [] > > def addTri(self, p1, p2, p3): > """Add a triangle to the model""" > v1 = vector(p1) > v2 = vector(p2) > v3 = vector(p3) > > normal = norm( cross(v2-v1, v3-v1) ) > > ## try is not necessary; norm(vector(0,0,0)) is vector(0,0,0) - see docs > ## try: > ## normal = norm( cross(v2-v1, v3-v1) ) > ## except: > ## normal = vector(0,0,0) > > self.vertexList = self.vertexList + [v1,v2,v3] > self.normalList = self.normalList + [normal,normal,normal] > self.colorList = self.colorList + > [self.color,self.color,self.color] > > def computeSurface(self): > """ Create faces out of vertex, normal and color info""" > self.surface.pos = self.vertexList > self.surface.normal = self.normalList > self.surface.color = self.colorList > ## self.surface = faces(frame=self.frame, pos=self.vertexList, > ## normal=self.normalList, > ## color=self.colorList) > > if __name__ == '__main__': > # origin sphere for reference > sphere(radius=0.1) > > p1 = (-2, -1, 0) > p2 = (-1, 1, 0) > p3 = (-2, 1, 0) > > > p4 = (3, -1, 0) > p5 = (5, -1, 0) > p6 = (4, 2, 0) > > x=Object() > x.addTri(p1, p2, p3) > x.computeSurface() > scene.mouse.getclick() > > print "new surface" > x.clearSurface() > x.addTri(p4, p5, p6) > x.computeSurface() > print x.vertexList > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > |