Ejemplo n.º 1
0
 def sortKey( self, mode, matrix ):
     """Produce the sorting key for this shape's appearance/shaders/etc"""
     # distance calculation...
     distance = polygonsort.distances(
         LOCAL_ORIGIN,
         modelView = matrix,
         projection = mode.getProjection(),
         viewport = mode.getViewport(),
     )[0]
     if self.appearance:
         key = self.appearance.sortKey( mode, matrix )
     else:
         key = (False,[],None)
     if key[0]:
         distance = -distance
     return key[0:2]+ (distance,) + key[1:]
 def sortKey(self, mode, matrix):
     """Produce the sorting key for this shape's appearance/shaders/etc"""
     # distance calculation...
     distance = polygonsort.distances(
         LOCAL_ORIGIN,
         modelView=matrix,
         projection=mode.getProjection(),
         viewport=mode.getViewport(),
     )[0]
     if self.appearance:
         key = self.appearance.sortKey(mode, matrix)
     else:
         key = (False, [], None)
     if key[0]:
         distance = -distance
     return key[0:2] + (distance, ) + key[1:]
Ejemplo n.º 3
0
 def drawTransparent( self, constant, mode=None ):
     """Fairly complex mechanism for drawing sorted polygons"""
     # we have to create a temporary array of centres for
     # each polygon, that requires taking the centres and then
     # creating an index-set that re-orders the polygons...
     centers = mode.cache.getData(self, key='centers')
     if centers is None:
         ## cache centers for future rendering passes...
         ordered_points = take( 
             self.coord.point, self.index.astype('i'), 0 
         )
         centers = triangleutilities.centers(
             ordered_points,
             vertexCount=self.polygonSides,
             components = 3,
         )
         holder = mode.cache.holder(self, key = "centers", data = centers)
         for name in ("polygonSides", "index", "coord"):
             field = protofunctions.getField( self, name )
             holder.depend( self, field )
         for (n, attr) in [
             (self.coord, 'point'),
         ]:
             if n:
                 holder.depend( n, protofunctions.getField( n,attr) )
     assert centers is not None
     
     # get distances to the viewer
     centers = polygonsort.distances(
         centers,
         modelView = mode.getModelView(),
         projection = mode.getProjection(),
         viewport = mode.getViewport(),
     )
     assert len(centers) == len(self.index)//self.polygonSides
     # get the center indices in sorted order
     indices = argsort( centers )
     sortedIndices = self.index[:]
     sortedIndices = reshape( sortedIndices, (-1,self.polygonSides))
     sortedIndices = take( sortedIndices, indices, 0 )
     # okay, now we can render...
     glDrawElementsui(
         constant,
         sortedIndices,
     )
Ejemplo n.º 4
0
    def drawTransparent(self, constant, mode=None):
        """Fairly complex mechanism for drawing sorted polygons"""
        # we have to create a temporary array of centres for
        # each polygon, that requires taking the centres and then
        # creating an index-set that re-orders the polygons...
        centers = mode.cache.getData(self, key='centers')
        if centers is None:
            ## cache centers for future rendering passes...
            ordered_points = take(self.coord.point, self.index.astype('i'), 0)
            centers = triangleutilities.centers(
                ordered_points,
                vertexCount=self.polygonSides,
                components=3,
            )
            holder = mode.cache.holder(self, key="centers", data=centers)
            for name in ("polygonSides", "index", "coord"):
                field = protofunctions.getField(self, name)
                holder.depend(self, field)
            for (n, attr) in [
                (self.coord, 'point'),
            ]:
                if n:
                    holder.depend(n, protofunctions.getField(n, attr))
        assert centers is not None

        # get distances to the viewer
        centers = polygonsort.distances(
            centers,
            modelView=mode.getModelView(),
            projection=mode.getProjection(),
            viewport=mode.getViewport(),
        )
        assert len(centers) == len(self.index) // self.polygonSides
        # get the center indices in sorted order
        indices = argsort(centers)
        sortedIndices = self.index[:]
        sortedIndices = reshape(sortedIndices, (-1, self.polygonSides))
        sortedIndices = take(sortedIndices, indices, 0)
        # okay, now we can render...
        glDrawElementsui(
            constant,
            sortedIndices,
        )