def update(self, secs, app):
        if self.keepMovieTimeLocally:
            self.localMovieTime += self.localMovieFrameTime
            #self.localCurrentFrame += 1
            if self.localMovieTime > self.localMovieDuration + self.localMovieFrameTime:
                self.localMovieTime = 0.0
                #self.localCurrentFrame = 0

        # set positions, etc.
        GroupObject.update(self, secs, app)
    def update(self, secs, app):
        if  self.keepMovieTimeLocally:
            self.localMovieTime += self.localMovieFrameTime
            #self.localCurrentFrame += 1
            if self.localMovieTime > self.localMovieDuration + self.localMovieFrameTime:
                self.localMovieTime = 0.0
                #self.localCurrentFrame = 0

        # set positions, etc.
        GroupObject.update(self, secs, app)
    def __init__(self, name, objectsToGroup=None, duration = None, fps=None):
        GroupObject.__init__(self, name, objectsToGroup)

        if self.getFirstNonNullChild() == None:
            self.keepMovieTimeLocally = True
            if duration == None:
                raise Exception("Tiled Movie duration is unknown, please ensure there is a duration entry in the description.txt")
            if fps == None:
                raise Exception("Tiled Movie FPS is unknown, please ensure there is a FPS entry in the description.txt")
            self.localMovieDuration = duration
            self.localMovieFps = fps
            self.localMovieFrameTime = 1.0 / fps
            self.localMovieTime = 0.0
            #self.localMovieNumFrames = 0
            #self.localCurrentFrame = 0
            print "NOTE: TiledMovieGroupObject:keeping time locally (no movie tile to decode on this node)"
        else:
            self.keepMovieTimeLocally = False
    def __init__(self, name, objectsToGroup=None, duration=None, fps=None):
        GroupObject.__init__(self, name, objectsToGroup)

        if self.getFirstNonNullChild() == None:
            self.keepMovieTimeLocally = True
            if duration == None:
                raise Exception(
                    "Tiled Movie duration is unknown, please ensure there is a duration entry in the description.txt"
                )
            if fps == None:
                raise Exception(
                    "Tiled Movie FPS is unknown, please ensure there is a FPS entry in the description.txt"
                )
            self.localMovieDuration = duration
            self.localMovieFps = fps
            self.localMovieFrameTime = 1.0 / fps
            self.localMovieTime = 0.0
            #self.localMovieNumFrames = 0
            #self.localCurrentFrame = 0
            print "NOTE: TiledMovieGroupObject:keeping time locally (no movie tile to decode on this node)"
        else:
            self.keepMovieTimeLocally = False
Exemple #5
0
def CreateMultiNetGroupTileDisplayStreamObject(addresses,
                                               objDesc,
                                               screenRect,
                                               pos,
                                               absRect,
                                               fullRect,
                                               gridColsRows,
                                               netGridColsRows,
                                               blend=True,
                                               scale=None,
                                               doCenter=True,
                                               plant=False):
    #from streamView import StreamView
    objectsToGroup = []
    if len(addresses) != netGridColsRows[0] * netGridColsRows[1]:
        raise Exception(
            "Number of addresses should match number of net grid tiles (e.g. use: --streamGroupsColsRows=3x2). currently: %d, %s"
            % (len(addresses), netGridColsRows))
    #for address in addresses:

    gridCols = gridColsRows[0]
    gridRows = gridColsRows[1]
    bigTileWidth = gridCols * objDesc.streamWidth  # 352
    bigTileHeight = gridRows * objDesc.streamHeight  # 288
    if scale != None:
        bigTileWidth *= scale[0]
        bigTileHeight *= scale[1]
    netGridCols = netGridColsRows[0]
    netGridRows = netGridColsRows[1]
    print "BIGTILESIZE:", bigTileWidth, bigTileHeight

    basePos = pos
    if doCenter:
        centeredPos = Vec2(pos[0], pos[1]) - Vec2(
            netGridCols * bigTileWidth / 2, netGridRows * bigTileHeight / 2)
        basePos = centeredPos

    # for xcol in range(1,2):
    print "grid within network stream:", gridCols, gridRows
    print "bigTile width,height:", bigTileWidth, bigTileHeight
    for xcol in range(netGridCols):
        for yrow in range(netGridRows):
            streamAddressIndex = netGridCols * yrow + xcol  # btm left to right, to top
            address = addresses[streamAddressIndex]
            yOffset = yrow * bigTileHeight
            xOffset = xcol * bigTileWidth
            singlePos = Vec2(xOffset + basePos[0], yOffset + basePos[1])

            loadTile = True
            if plant:  # only load if it's on this machine
                streamTileRenderRect = Rect(singlePos[0], singlePos[1],
                                            bigTileWidth, bigTileHeight)
                # print "Checking colliderects to see if stream tile is on this display tile:", movieRenderRect.colliderect(absRect), movieRenderRect, absRect, movieRenderRect.colliderect(absRect), "indexes:", xIndex, yIndex, "flipped indexes:", xIndex,yIndexBZ
                if streamTileRenderRect.colliderect(absRect):
                    loadTile = True
                    # Debug
                    import mpi
                    print mpi.rank, " Loading stream with rect: ", streamTileRenderRect, "me:", (
                        absRect.x, absRect.y, absRect.width,
                        absRect.height), address
                else:
                    import mpi
                    print mpi.rank, " Not loading stream with rect: ", streamTileRenderRect, "me:", (
                        absRect.x, absRect.y, absRect.width,
                        absRect.height), address
                    loadTile = False

            if loadTile:
                groupStreamObj = GroupTiledStreamObject(
                    address,
                    objDesc,
                    screenRect=screenRect,
                    pos=singlePos,
                    absRect=absRect,
                    fullRect=fullRect,
                    blend=blend,
                    scale=scale,
                    gridColsRows=gridColsRows,
                    doCenter=False)
                objectsToGroup.append(groupStreamObj)
            else:
                groupStreamObj = NullTileDisplayObject(
                    pos=singlePos, size=(bigTileWidth, bigTileHeight)
                )  # Empty object to represent objects on other nodes and help describe large object on this node .
                objectsToGroup.append(groupStreamObj)

    shortName = "_".join(addresses)
    largeGroupObject = GroupObject(shortName,
                                   objectsToGroup,
                                   doChildUpdates=True)

    return largeGroupObject
Exemple #6
0
def CreateTileImageObject(imageFilename,
                          screenRect,
                          pos,
                          absRect,
                          fullRect,
                          blend=True,
                          scale=None):
    print "CreateTileImageObject", imageFilename, "at", pos
    imageSize = Image.open(imageFilename).size
    maxTextureSize = GetMaxTextureSize()
    numTiles = (int(math.ceil(float(imageSize[0]) / maxTextureSize)),
                int(math.ceil(float(imageSize[1]) / maxTextureSize)))
    print "NUMTILES:", numTiles

    if numTiles[0] == 1 and numTiles[1] == 1:
        returnObj = glTxtrBox(imageFilename,
                              screenRect=screenRect,
                              imagePos=pos,
                              absRect=absRect,
                              fullRect=fullRect,
                              blend=blend,
                              scale=scale)

    else:
        objectsToGroup = []

        # Create a group object
        xSrcOffset = 0
        xRenderOffset = 0
        subImageWidth = imageSize[0] / numTiles[0]
        subImageHeight = imageSize[1] / numTiles[1]
        for xIndex in range(numTiles[0]):
            ySrcOffset = 0
            yRenderOffset = 0

            if xIndex == numTiles[0] - 1:
                # make sure we don't cut off any
                # pixels if it's not evenly divisible.
                width = imageSize[0] - xSrcOffset
            else:
                width = subImageWidth

            for yIndex in range(numTiles[1]):

                if yIndex == numTiles[1] - 1:
                    # make sure we don't cut off any
                    # pixels if it's not evenly divisible.
                    height = imageSize[1] - ySrcOffset
                else:
                    height = subImageHeight

                pos = Vec2(xRenderOffset, -yRenderOffset)  # flip y coord
                # cropRect is for cropping a subsection out of the source image
                cropRect = Rect(xSrcOffset, ySrcOffset, width, height)
                print "Loading with crop rect:", cropRect
                obj = glTxtrBox(imageFilename,
                                screenRect=screenRect,
                                imagePos=pos,
                                absRect=absRect,
                                fullRect=fullRect,
                                blend=blend,
                                cropRect=cropRect,
                                scale=scale)
                objectsToGroup.append(obj)

                ySrcOffset += obj.getSrcSize()[1]
                yRenderOffset += obj.getRenderSize()[1]
            xSrcOffset += obj.getSrcSize()[0]
            xRenderOffset += obj.getRenderSize()[0]

        shortName = os.path.basename(imageFilename.strip(os.path.sep))
        groupObject = GroupObject(shortName, objectsToGroup)
        returnObj = groupObject
    print "************* CreateTileDisplayObject finished", returnObj
    return returnObj