Exemplo n.º 1
0
 def __init__(self, interestMgr, name, doneEvent=None,
              recurse=True, start=True, mustCollect=False, doCollectionMgr=None):
     DirectObject.__init__(self)
     self._interestMgr = interestMgr
     if doCollectionMgr is None:
         doCollectionMgr = interestMgr
     self._doCollectionMgr = doCollectionMgr
     self._eGroup = EventGroup(name, doneEvent=doneEvent)
     self._doneEvent = self._eGroup.getDoneEvent()
     self._gotEvent = False
     self._recurse = recurse
     if self._recurse:
         # this will hold a dict of parentId to set(zoneIds) that are closing
         self.closingParent2zones = {}
     if start:
         self.startCollect(mustCollect)
Exemplo n.º 2
0
    def __init__(self, name, parent_node_path):

        DirectObject.__init__(self)
        NodePath.__init__(self, name)

        # required initialization
        self.active = True
        self.enable = True

        self.pause = False
        self.pause_time = 0.0

        self.fade = False
        self.fade_end = False
        self.fade_start_time = 0.0
        self.fade_color_scale = 1.0

        self.total_vertices = 0
        self.last_update_time = 0.0
        self.texture = None
        self.vertex_list = []
        self.frame_list = []

        self.parent_node_path = parent_node_path

        self.previous_matrix = None
        self.calculate_relative_matrix = False

        self.playing = False

        # default options
        self.continuous_motion_trail = True
        self.color_scale = 1.0
        self.time_window = 1.0
        self.sampling_time = 0.0
        self.square_t = True

        #        self.task_transform = False
        self.root_node_path = None

        # node path states
        self.reparentTo(parent_node_path)
        self.geom_node = GeomNode("motion_trail")
        self.geom_node_path = self.attachNewNode(self.geom_node)
        node_path = self.geom_node_path

        ### set render states

        node_path.setTwoSided(True)

        # set additive blend effects
        OTPRender.setAdditiveEffect(node_path, 'motion_trail')

        if (MotionTrail.task_added == False):
            #            taskMgr.add (self.motion_trail_task, "motion_trail_task", priority = 50)
            taskMgr.add(self.motion_trail_task,
                        MotionTrail.motion_trail_task_name)

            self.acceptOnce("clientLogout", remove_task)

            MotionTrail.task_added = True

        self.relative_to_render = False

        self.use_nurbs = False
        self.resolution_distance = 0.5

        self.cmotion_trail = CMotionTrail()
        self.cmotion_trail.setGeomNode(self.geom_node)

        self.modified_vertices = True
        if base.config.GetBool('want-python-motion-trails', 0):
            self.use_python_version = True
        else:
            self.use_python_version = False

        return
Exemplo n.º 3
0
    def __init__(self, gsg=None, limit=None):
        DirectObject.__init__(self)

        # First, we'll need a name to uniquify the object.
        self.name = 'tex-mem%s' % (TexMemWatcher.NextIndex)
        TexMemWatcher.NextIndex += 1

        self.cleanedUp = False
        self.top = 1.0

        # The textures managed by the TexMemWatcher are packed
        # arbitrarily into the canvas, which is the viewable region
        # that represents texture memory allocation.  The packing
        # arrangement has no relation to actual layout within texture
        # memory (which we have no way to determine).

        # The visual size of each texture is chosen in proportion to
        # the total number of bytes of texture memory the texture
        # consumes.  This includes mipmaps, and accounts for texture
        # compression.  Visually, a texture with mipmaps will be
        # represented by a rectangle 33% larger than an
        # equivalent-sized texture without mipmaps.  Of course, this
        # once again has little bearing to the way the textures are
        # actually arranged in memory; but it serves to give a visual
        # indication of how much texture memory each texture consumes.

        # There is an arbitrary limit, self.limit, which may have been
        # passed to the constructor, or which may be arbitrarily
        # determined.  This represents the intended limit to texture
        # memory utilization.  We (generously) assume that the
        # graphics card will implement a perfect texture packing
        # algorithm, so that as long as our total utilization <=
        # self.limit, it must fit within texture memory.  We represent
        # this visually by aggressively packing textures within the
        # self.limit block so that they are guaranteed to fit, as long
        # as we do not exceed the total utilization.  This may
        # sometimes mean distorting a texture block or even breaking
        # it into multiple pieces to get it to fit, clearly
        # fictionalizing whatever the graphics driver is actually
        # doing.

        # Internally, textures are packed into an integer grid of
        # Q-units.  Q-units are in proportion to texture bytes.
        # Specifically, each Q-unit corresponds to a block of
        # self.quantize * self.quantize texture bytes in the Texture
        # Memory window.  The Q-units are the smallest packable unit;
        # increasing self.quantize therefore reduces the visual
        # packing resolution correspondingly.  Q-units very roughly
        # correspond to pixels onscreen (they may be larger, sometimes
        # considerably larger, than 1 pixel, depending on the window
        # size).

        # This number defines the size of a Q-unit square, in texture
        # bytes.  It is automatically adjusted in repack() based on
        # the window size and the texture memory size.
        self.quantize = 1

        # This is the maximum number of bitmask rows (within
        # self.limit) to allocate for packing.  This controls the
        # value assigned to self.quantize in repack().
        self.maxHeight = base.config.GetInt('tex-mem-max-height', 300)

        # The total number of texture bytes tracked, including overflow.
        self.totalSize = 0

        # The total number of texture bytes placed, not including
        # overflow (that is, within self.limit).
        self.placedSize = 0

        # The total number of Q-units placed, not including overflow.
        self.placedQSize = 0

        # If no GSG is specified, use the main GSG.
        if gsg is None:
            gsg = base.win.getGsg()
        elif isinstance(gsg, GraphicsOutput):
            # If we were passed a window, use that window's GSG.
            gsg = gsg.getGsg()

        self.gsg = gsg

        # Now open a new window just to render the output.
        size = ConfigVariableInt('tex-mem-win-size', '300 300')
        origin = ConfigVariableInt('tex-mem-win-origin', '100 100')
        self.winSize = (size[0], size[1])
        name = 'Texture Memory'
        props = WindowProperties()
        props.setOrigin(origin[0], origin[1])
        props.setSize(*self.winSize)
        props.setTitle(name)
        props.setFullscreen(False)
        props.setUndecorated(False)

        fbprops = FrameBufferProperties.getDefault()
        flags = GraphicsPipe.BFFbPropsOptional | GraphicsPipe.BFRequireWindow

        self.pipe = None

        # Set this to tinydisplay if you're running on a machine with
        # limited texture memory.  That way you won't compete for
        # texture memory with the main scene.
        moduleName = base.config.GetString('tex-mem-pipe', '')
        if moduleName:
            self.pipe = base.makeModulePipe(moduleName)

        # If the requested pipe fails for some reason, we'll use the
        # regular pipe.
        if not self.pipe:
            self.pipe = base.pipe

        self.win = base.graphicsEngine.makeOutput(self.pipe, name, 0, fbprops,
                                                  props, flags)
        assert self.win

        # We should render at the end of the frame.
        self.win.setSort(10000)

        # We don't need to clear the color buffer, since we'll be
        # filling it with a texture.  We also don't need to clear the
        # depth buffer, since we won't be using it.
        self.win.setClearColorActive(False)
        self.win.setClearDepthActive(False)

        eventName = '%s-window' % (self.name)
        self.win.setWindowEvent(eventName)
        self.accept(eventName, self.windowEvent)

        # Listen for this event so we can update appropriately, if
        # anyone changes the window's graphics memory limit,
        self.accept('graphics_memory_limit_changed',
                    self.graphicsMemoryLimitChanged)

        # We'll need a mouse object to get mouse events.
        self.mouse = base.dataRoot.attachNewNode(
            MouseAndKeyboard(self.win, 0, '%s-mouse' % (self.name)))
        bt = ButtonThrower('%s-thrower' % (self.name))
        self.mouse.attachNewNode(bt)
        bt.setPrefix('button-%s-' % (self.name))
        self.accept('button-%s-mouse1' % (self.name), self.mouseClick)

        self.setupGui()
        self.setupCanvas()

        # Now start handling up the actual stuff in the scene.

        self.background = None
        self.nextTexRecordKey = 0
        self.rollover = None
        self.isolate = None
        self.isolated = None
        self.needsRepack = False

        # How frequently should the texture memory window check for
        # state changes?
        updateInterval = base.config.GetDouble("tex-mem-update-interval", 0.5)
        self.task = taskMgr.doMethodLater(updateInterval, self.updateTextures,
                                          'TexMemWatcher')

        self.setLimit(limit)
Exemplo n.º 4
0
    def __init__ (self,name,parent_node_path):

        DirectObject.__init__(self)
        NodePath.__init__ (self,name)

        # required initialization
        self.active = True
        self.enable = True

        self.pause = False
        self.pause_time = 0.0

        self.fade = False
        self.fade_end = False
        self.fade_start_time = 0.0
        self.fade_color_scale = 1.0

        self.total_vertices = 0
        self.last_update_time = 0.0
        self.texture = None
        self.vertex_list = [ ]
        self.frame_list = [ ]

        self.parent_node_path = parent_node_path

        self.previous_matrix = None
        self.calculate_relative_matrix = False

        self.playing = False;

        # default options
        self.continuous_motion_trail = True
        self.color_scale = 1.0
        self.time_window = 1.0
        self.sampling_time = 0.0
        self.square_t = True

#        self.task_transform = False
        self.root_node_path = None

        # node path states
        self.reparentTo (parent_node_path)
        self.geom_node = GeomNode ("motion_trail")
        self.geom_node_path = self.attachNewNode(self.geom_node)
        node_path = self.geom_node_path

        ### set render states

        node_path.setTwoSided (True)

        # set additive blend effects
        OTPRender.setAdditiveEffect (node_path, 'motion_trail')

        if (MotionTrail.task_added == False):
#            taskMgr.add (self.motion_trail_task, "motion_trail_task", priority = 50)
            taskMgr.add (self.motion_trail_task, MotionTrail.motion_trail_task_name)

            self.acceptOnce ("clientLogout", remove_task)

            MotionTrail.task_added = True


        self.relative_to_render = False

        self.use_nurbs = False
        self.resolution_distance = 0.5
        
        self.cmotion_trail = CMotionTrail ( )
        self.cmotion_trail.setGeomNode (self.geom_node)

        self.modified_vertices = True
        if base.config.GetBool('want-python-motion-trails', 0):
            self.use_python_version = True
        else:
            self.use_python_version = False
        
        return
Exemplo n.º 5
0
 def __init__(self, **kargs):
   DirectObject.__init__(self)
   
   self.handlers = {}
Exemplo n.º 6
0
    def __init__(self, gsg = None, limit = None):
        DirectObject.__init__(self)

        # First, we'll need a name to uniquify the object.
        self.name = 'tex-mem%s' % (TexMemWatcher.NextIndex)
        TexMemWatcher.NextIndex += 1

        self.cleanedUp = False
        self.top = 1.0

        # The textures managed by the TexMemWatcher are packed
        # arbitrarily into the canvas, which is the viewable region
        # that represents texture memory allocation.  The packing
        # arrangement has no relation to actual layout within texture
        # memory (which we have no way to determine).

        # The visual size of each texture is chosen in proportion to
        # the total number of bytes of texture memory the texture
        # consumes.  This includes mipmaps, and accounts for texture
        # compression.  Visually, a texture with mipmaps will be
        # represented by a rectangle 33% larger than an
        # equivalent-sized texture without mipmaps.  Of course, this
        # once again has little bearing to the way the textures are
        # actually arranged in memory; but it serves to give a visual
        # indication of how much texture memory each texture consumes.

        # There is an arbitrary limit, self.limit, which may have been
        # passed to the constructor, or which may be arbitrarily
        # determined.  This represents the intended limit to texture
        # memory utilization.  We (generously) assume that the
        # graphics card will implement a perfect texture packing
        # algorithm, so that as long as our total utilization <=
        # self.limit, it must fit within texture memory.  We represent
        # this visually by aggressively packing textures within the
        # self.limit block so that they are guaranteed to fit, as long
        # as we do not exceed the total utilization.  This may
        # sometimes mean distorting a texture block or even breaking
        # it into multiple pieces to get it to fit, clearly
        # fictionalizing whatever the graphics driver is actually
        # doing.

        # Internally, textures are packed into an integer grid of
        # Q-units.  Q-units are in proportion to texture bytes.
        # Specifically, each Q-unit corresponds to a block of
        # self.quantize * self.quantize texture bytes in the Texture
        # Memory window.  The Q-units are the smallest packable unit;
        # increasing self.quantize therefore reduces the visual
        # packing resolution correspondingly.  Q-units very roughly
        # correspond to pixels onscreen (they may be larger, sometimes
        # considerably larger, than 1 pixel, depending on the window
        # size).


        # This number defines the size of a Q-unit square, in texture
        # bytes.  It is automatically adjusted in repack() based on
        # the window size and the texture memory size.
        self.quantize = 1

        # This is the maximum number of bitmask rows (within
        # self.limit) to allocate for packing.  This controls the
        # value assigned to self.quantize in repack().
        self.maxHeight = base.config.GetInt('tex-mem-max-height', 300)
        
        # The total number of texture bytes tracked, including overflow.
        self.totalSize = 0

        # The total number of texture bytes placed, not including
        # overflow (that is, within self.limit).
        self.placedSize = 0

        # The total number of Q-units placed, not including overflow.
        self.placedQSize = 0
        
        # If no GSG is specified, use the main GSG.
        if gsg is None:
            gsg = base.win.getGsg()
        elif isinstance(gsg, GraphicsOutput):
            # If we were passed a window, use that window's GSG.
            gsg = gsg.getGsg()

        self.gsg = gsg

        # Now open a new window just to render the output.
        size = ConfigVariableInt('tex-mem-win-size', '300 300')
        origin = ConfigVariableInt('tex-mem-win-origin', '100 100')
        self.winSize = (size[0], size[1])
        name = 'Texture Memory'
        props = WindowProperties()
        props.setOrigin(origin[0], origin[1])
        props.setSize(*self.winSize)
        props.setTitle(name)
        props.setFullscreen(False)
        props.setUndecorated(False)

        fbprops = FrameBufferProperties.getDefault()
        flags = GraphicsPipe.BFFbPropsOptional | GraphicsPipe.BFRequireWindow

        self.pipe = None

        # Set this to tinydisplay if you're running on a machine with
        # limited texture memory.  That way you won't compete for
        # texture memory with the main scene.
        moduleName = base.config.GetString('tex-mem-pipe', '')
        if moduleName:
            self.pipe = base.makeModulePipe(moduleName)

        # If the requested pipe fails for some reason, we'll use the
        # regular pipe.
        if not self.pipe:
            self.pipe = base.pipe
        
        self.win = base.graphicsEngine.makeOutput(self.pipe, name, 0, fbprops,
                                                  props, flags)
        assert self.win

        # We should render at the end of the frame.
        self.win.setSort(10000)

        # We don't need to clear the color buffer, since we'll be
        # filling it with a texture.  We also don't need to clear the
        # depth buffer, since we won't be using it.
        self.win.setClearColorActive(False)
        self.win.setClearDepthActive(False)

        eventName = '%s-window' % (self.name)
        self.win.setWindowEvent(eventName)
        self.accept(eventName, self.windowEvent)

        # Listen for this event so we can update appropriately, if
        # anyone changes the window's graphics memory limit,
        self.accept('graphics_memory_limit_changed',
                    self.graphicsMemoryLimitChanged)

        # We'll need a mouse object to get mouse events.
        self.mouse = base.dataRoot.attachNewNode(MouseAndKeyboard(self.win, 0, '%s-mouse' % (self.name)))
        bt = ButtonThrower('%s-thrower' % (self.name))
        self.mouse.attachNewNode(bt)
        bt.setPrefix('button-%s-' % (self.name))
        self.accept('button-%s-mouse1' % (self.name), self.mouseClick)

        self.setupGui()
        self.setupCanvas()

        # Now start handling up the actual stuff in the scene.
        
        self.background = None
        self.nextTexRecordKey = 0
        self.rollover = None
        self.isolate = None
        self.isolated = None
        self.needsRepack = False

        # How frequently should the texture memory window check for
        # state changes?
        updateInterval = base.config.GetDouble("tex-mem-update-interval", 0.5)
        self.task = taskMgr.doMethodLater(updateInterval, self.updateTextures, 'TexMemWatcher')

        self.setLimit(limit)