# HG changeset patch # User paulb # Date 1189965528 0 # Node ID 3c743856195c42e46f0d15f40c0b3556f7d83351 # Parent 07efb8b50f735ae9648e2fa409086719dd5fc747 [project @ 2007-09-16 17:58:48 by paulb] Made the reuse example use the MakeReusable class and a simpler render_row method. diff -r 07efb8b50f73 -r 3c743856195c examples/PyGmy/ppygmy_reuse.py --- a/examples/PyGmy/ppygmy_reuse.py Sun Sep 16 16:54:17 2007 +0000 +++ b/examples/PyGmy/ppygmy_reuse.py Sun Sep 16 17:58:48 2007 +0000 @@ -322,49 +322,39 @@ self.imageplane=5.0 self.aspect=self.width/float(self.height) - def render_row(self, channel, sy): + def render_row(self, sy): """ - Render the given row, using the 'channel' provided to communicate - result data back to the coordinating process. The row position 'sy', - provided for the first row, will subsequently be read from the - 'channel' for the rendering of new rows. A tuple containing 'sy' and a - list of result numbers is returned by this function via the given - 'channel'. + Render the given row, using 'sy' as the row position, and returning a + tuple containing 'sy' and a list of result numbers. """ - while 1: - - row = [] - for sx in range(0,self.width): - x=2*(0.5-sx/float(self.width))*self.aspect - y=2*(0.5-sy/float(self.height)) - if self.cameratype=="ortho": - ray = line(vec(x,y,0),vec(x,y,self.backplane)) - else: - ray = line(vec(0,0,0),vec(x,y,self.imageplane)) - ray.end=ray.end*self.backplane - - col=vec(0,0,0) - depth=self.backplane - shaderinfo={"ray":ray,"lights":self.lights,"objects":self.objects,"depth":2} + row = [] + for sx in range(0,self.width): + x=2*(0.5-sx/float(self.width))*self.aspect + y=2*(0.5-sy/float(self.height)) + if self.cameratype=="ortho": + ray = line(vec(x,y,0),vec(x,y,self.backplane)) + else: + ray = line(vec(0,0,0),vec(x,y,self.imageplane)) + ray.end=ray.end*self.backplane - for obj in self.objects: - intersects,position,normal = obj.intersect(ray) - if intersects is not "none": - if position.z0: - depth=position.z - shaderinfo["thisobj"]=obj - shaderinfo["position"]=position - shaderinfo["normal"]=normal - col=obj.shader.shade(shaderinfo) - row.append(col) + col=vec(0,0,0) + depth=self.backplane + shaderinfo={"ray":ray,"lights":self.lights,"objects":self.objects,"depth":2} - channel.send((sy, row)) - t = channel.receive() - if t is None: - break - (sy,), kw = t + for obj in self.objects: + intersects,position,normal = obj.intersect(ray) + if intersects is not "none": + if position.z0: + depth=position.z + shaderinfo["thisobj"]=obj + shaderinfo["position"]=position + shaderinfo["normal"]=normal + col=obj.shader.shade(shaderinfo) + row.append(col) + + return sy, row def render(self, filename, limit): @@ -375,7 +365,7 @@ image = Image.new("RGB", (self.width, self.height)) exchange = PyGmyExchange(self.width, self.height, image, limit=limit, reuse=1) - render_row = exchange.manage(self.render_row) + render_row = exchange.manage(pprocess.MakeReusable(self.render_row)) for y in range(0, self.height): render_row(y)