Ejemplo n.º 1
0
 def rotate(self, quat):
     """
     Post-multiply self's transform with a rotation given by a quaternion.
     """
     self.transform = Numeric.matrixmultiply(self.transform, qmat4x4(quat))
     self.changed = drawing_constants.eventStamp()
     return
Ejemplo n.º 2
0
 def rotate(self, quat):
     """
     Post-multiply self's transform with a rotation given by a quaternion.
     """
     self.transform = Numeric.matrixmultiply(self.transform, qmat4x4(quat))
     self.changed = drawing_constants.eventStamp()
     return
Ejemplo n.º 3
0
 def translate(self, vec):
     """
     Post-multiply the transform with a translation given by a 3-vector.
     """
     # This only affects the fourth row x,y,z elements.
     self.transform[3, 0:3] += vec
     self.changed = drawing_constants.eventStamp()
     return
Ejemplo n.º 4
0
 def translate(self, vec):
     """
     Post-multiply the transform with a translation given by a 3-vector.
     """
     # This only affects the fourth row x,y,z elements.
     self.transform[3, 0:3] += vec
     self.changed = drawing_constants.eventStamp()
     return
Ejemplo n.º 5
0
    def start(self, pickstate):  #bruce 090224 split this out of caller
        """
        Clear self and start collecting new primitives for use inside it.

        (They are collected by staticmethods in the ColorSorter singleton class,
         and saved partly in ColorSorter class attributes, partly in self
         by direct assignment (maybe not anymore), and partly in self by
         methods ColorSorter calls in self.)

        [meant to be called only by ColorSorter.start, for now]
        """
        if pickstate is not None:
            # todo: refactor to remove this deprecated argument
            ### review: is it correct to not reset self.selected when this is None??
            self.selectPick(pickstate)
            pass

        # Russ 080915: This supports lazily updating drawing caches.
        self.changed = drawing_constants.eventStamp()

        # Clear the primitive data to start collecting a new set.

        # REVIEW: is it good that we don't also deallocate DLs here?
        # Guess: yes if we reuse them, no if we don't.
        # It looks like finish calls _reset, which deallocates them,
        # so we might as well do that right here instead. Also, that
        # way I can remove _reset from finish, which is good since
        # I've made _reset clearPrimitives, which is a bug if done
        # in finish (when were added between start and finish).
        # [bruce 090224 comment and revision]
        ## self._clearPrimitives()
        self._reset()

        if 0:  # keep around, in case we want a catchall DL in the future
            #bruce 090114 removed support for
            # [note: later: these are no longer in drawing_globals]
            # (not (drawing_globals.allow_color_sorting and
            #       drawing_globals.use_color_sorted_dls)):
            # This is the beginning of the single display list created when
            # color sorting is turned off. It is ended in
            # ColorSorter.finish . In between, the calls to
            # draw{sphere,cylinder,polycone} methods pass through
            # ColorSorter.schedule_* but are immediately sent to *_worker
            # where they do OpenGL drawing that is captured into the display
            # list.
            try:
                if self.dl == 0:
                    self.activate()  # Allocate a display list for our use.
                    pass
                # Start a single-level list.
                glNewList(self.dl, GL_COMPILE)
            except:
                print("data related to following exception: self.dl = %r" %
                      (self.dl, ))  #bruce 070521
                raise
            pass
        return
    def start(self, pickstate):  # bruce 090224 split this out of caller
        """
        Clear self and start collecting new primitives for use inside it.

        (They are collected by staticmethods in the ColorSorter singleton class,
         and saved partly in ColorSorter class attributes, partly in self
         by direct assignment (maybe not anymore), and partly in self by
         methods ColorSorter calls in self.)

        [meant to be called only by ColorSorter.start, for now]
        """
        if pickstate is not None:
            # todo: refactor to remove this deprecated argument
            ### review: is it correct to not reset self.selected when this is None??
            self.selectPick(pickstate)
            pass

        # Russ 080915: This supports lazily updating drawing caches.
        self.changed = drawing_constants.eventStamp()

        # Clear the primitive data to start collecting a new set.

        # REVIEW: is it good that we don't also deallocate DLs here?
        # Guess: yes if we reuse them, no if we don't.
        # It looks like finish calls _reset, which deallocates them,
        # so we might as well do that right here instead. Also, that
        # way I can remove _reset from finish, which is good since
        # I've made _reset clearPrimitives, which is a bug if done
        # in finish (when were added between start and finish).
        # [bruce 090224 comment and revision]
        ## self._clearPrimitives()
        self._reset()

        if 0:  # keep around, in case we want a catchall DL in the future
            # bruce 090114 removed support for
            # [note: later: these are no longer in drawing_globals]
            # (not (drawing_globals.allow_color_sorting and
            #       drawing_globals.use_color_sorted_dls)):
            # This is the beginning of the single display list created when
            # color sorting is turned off. It is ended in
            # ColorSorter.finish . In between, the calls to
            # draw{sphere,cylinder,polycone} methods pass through
            # ColorSorter.schedule_* but are immediately sent to *_worker
            # where they do OpenGL drawing that is captured into the display
            # list.
            try:
                if self.dl == 0:
                    self.activate()  # Allocate a display list for our use.
                    pass
                # Start a single-level list.
                glNewList(self.dl, GL_COMPILE)
            except:
                print("data related to following exception: self.dl = %r" % (self.dl,))  # bruce 070521
                raise
            pass
        return
Ejemplo n.º 7
0
    def __init__(self, csdl_list):
        """
        """
        self.CSDLs = csdl_list

        # Collect lists of primitives to draw in batches, and those CSDLs with
        # display lists to draw as well.  (A given CSDL may have both.)
        self.spheres = []            # Generalize to a dict of lists?
        self.cylinders = []
        self._CSDLs_with_nonshader_drawing = []
            #bruce 090312 renamed this from CSDLs_with_DLs,
            # since the logic herein only cares that they have some sort of
            # drawing to do in immediate-mode OpenGL, not how it's done.
            #
            # (todo, in future: split this into whatever can be compiled
            #  into an overall DL of our own (meaning it never changes and
            #  is all legal while compiling a DL -- in particular, it can call
            #  other DLs but it can't recompile them), and whatever really has
            #  to be done in immediate mode and perhaps recomputed on each
            #  draw, as a further optimization. This requires splitting
            #  each of the associated CSDL API methods, has_nonshader_drawing
            #  and .draw(..., draw_shader_primitives = False,
            #                 transform_nonshaders = False ).
            #  If that's done, draw the immediate-mode-parts first here, in case
            #  any of them also want to recompile DLs which are called in the
            #  ok-for-inside-one-big-DL parts.)

        for csdl in self.CSDLs:
            self.spheres += csdl.spheres
            self.cylinders += csdl.cylinders
            if csdl.has_nonshader_drawing():
                self._CSDLs_with_nonshader_drawing += [csdl]
                pass
            continue

        self.drawIndices = {}           # Generated on demand.

        # Support for lazily updating drawing caches, namely a
        # timestamp showing when this GLPrimitiveSet was created.
        self.created = drawing_constants.eventStamp()

        # optimization: sort _CSDLs_with_nonshader_drawing by their transformControl.
        # [bruce 090225]
        items = [(id(csdl.transformControl), csdl)
                 for csdl in self._CSDLs_with_nonshader_drawing]
        items.sort()
        self._CSDLs_with_nonshader_drawing = [csdl for (junk, csdl) in items]

        return
Ejemplo n.º 8
0
    def __init__(self, csdl_list):
        """
        """
        self.CSDLs = csdl_list

        # Collect lists of primitives to draw in batches, and those CSDLs with
        # display lists to draw as well.  (A given CSDL may have both.)
        self.spheres = []  # Generalize to a dict of lists?
        self.cylinders = []
        self._CSDLs_with_nonshader_drawing = []
        #bruce 090312 renamed this from CSDLs_with_DLs,
        # since the logic herein only cares that they have some sort of
        # drawing to do in immediate-mode OpenGL, not how it's done.
        #
        # (todo, in future: split this into whatever can be compiled
        #  into an overall DL of our own (meaning it never changes and
        #  is all legal while compiling a DL -- in particular, it can call
        #  other DLs but it can't recompile them), and whatever really has
        #  to be done in immediate mode and perhaps recomputed on each
        #  draw, as a further optimization. This requires splitting
        #  each of the associated CSDL API methods, has_nonshader_drawing
        #  and .draw(..., draw_shader_primitives = False,
        #                 transform_nonshaders = False ).
        #  If that's done, draw the immediate-mode-parts first here, in case
        #  any of them also want to recompile DLs which are called in the
        #  ok-for-inside-one-big-DL parts.)

        for csdl in self.CSDLs:
            self.spheres += csdl.spheres
            self.cylinders += csdl.cylinders
            if csdl.has_nonshader_drawing():
                self._CSDLs_with_nonshader_drawing += [csdl]
                pass
            continue

        self.drawIndices = {}  # Generated on demand.

        # Support for lazily updating drawing caches, namely a
        # timestamp showing when this GLPrimitiveSet was created.
        self.created = drawing_constants.eventStamp()

        # optimization: sort _CSDLs_with_nonshader_drawing by their transformControl.
        # [bruce 090225]
        items = [(id(csdl.transformControl), csdl)
                 for csdl in self._CSDLs_with_nonshader_drawing]
        items.sort()
        self._CSDLs_with_nonshader_drawing = [csdl for (junk, csdl) in items]

        return
Ejemplo n.º 9
0
    def __init__(self):
        # A unique integer ID for each TransformControl.
        global _transform_id_counter
        _transform_id_counter += 1
        self.transform_id = _transform_id_counter

        # Support for lazily updating drawing caches, namely a
        # timestamp showing when this transform matrix was last changed.
        ### REVIEW: I think we only need a valid flag, not any timestamps --
        # at least for internal use. If we have clients but not subscribers,
        # then they could make use of our changed timestamp. [bruce 090203]
        self.changed = drawing_constants.eventStamp()
        self.cached = drawing_constants.NO_EVENT_YET

        self.transform = floatIdent(4)
        return
Ejemplo n.º 10
0
    def __init__(self):
        # A unique integer ID for each TransformControl.
        global _transform_id_counter
        _transform_id_counter += 1
        self.transform_id = _transform_id_counter

        # Support for lazily updating drawing caches, namely a
        # timestamp showing when this transform matrix was last changed.
        ### REVIEW: I think we only need a valid flag, not any timestamps --
        # at least for internal use. If we have clients but not subscribers,
        # then they could make use of our changed timestamp. [bruce 090203]
        self.changed = drawing_constants.eventStamp()
        self.cached = drawing_constants.NO_EVENT_YET

        self.transform = floatIdent(4)
        return
Ejemplo n.º 11
0
    def __init__(self, transformControl=None, reentrant=False):
        """
        """
        self._clear_when_deallocate_DLs_might_be_unsafe()
        #bruce 090224 moved this earlier, made it do more,
        # removed inits from this method which are now redundant

        if reentrant:
            self.reentrant = True  # permits reentrant ColorSorter.start

        # [Russ 080915: Added.
        # A unique integer ID for each CSDL.
        global _csdl_id_counter
        _csdl_id_counter += 1
        self.csdl_id = _csdl_id_counter

        # Support for lazily updating drawing caches, namely a
        # timestamp showing when this CSDL was last changed.
        self.changed = drawing_constants.eventStamp()

        if transformControl is not None:
            self.transformControl = transformControl
            try:
                ##### KLUGE (temporary), for dealing with a perhaps-permanent change:
                # transformControl might be a Chunk,
                # which has (we assume & depend on) no transform_id
                _x = self.transformControl.transform_id  # should fail for Chunk
            except AttributeError:
                # Assume transformControl is a Chunk.
                # Note: no point in doing self.updateTransform() yet (to record
                # untransformed data early) -- we have no data, since no
                # shader primitives have been stored yet. Untransformed data
                # will be recorded the first time it's transformed (after init,
                # and after each time primitives get cleared and remade).
                pass
            else:
                assert _x is not None
                assert _x is not -1
                self._transform_id = _x
            pass

# CSDLs should not have a glname since they are never a selobj.
# Any testCases which depend on this should be rewritten.
# [bruce 090311]
##        # Russ 081122: Mark CSDLs with a glname for selection.
##        # (Note: this is a temporary kluge for testing. [bruce 090223 comment])
##        self.glname = env._shared_glselect_name_dict. \
##                      alloc_my_glselect_name(self)
##        ###self.glname = 0x12345678 ### For testing.

# Whether to draw in the selection over-ride color.
        self.selected = False

        ### TODO [bruce 090114 comment]: a near-term goal is to remove
        # self.selected and self.dl, so that self only knows
        # how to draw either way, but always finds out as-needed
        # (from client state) which way to actually draw.
        # Reviewing the current code, I think the only remaining
        # essential use of self.dl is in CrystalShape.py
        # (see new comment in its docstring for how to clean that up),
        # and the only remaining essential use of self.selected
        # (aside from maintaining self.dl, no longer needed if it's removed)
        # is in ColorSorter.finish (which should be replaced by
        # passing finish the same drawing-style arguments that
        # CSDL.draw accepts).

        return
    def __init__(self, transformControl=None, reentrant=False):
        """
        """
        self._clear_when_deallocate_DLs_might_be_unsafe()
        # bruce 090224 moved this earlier, made it do more,
        # removed inits from this method which are now redundant

        if reentrant:
            self.reentrant = True  # permits reentrant ColorSorter.start

        # [Russ 080915: Added.
        # A unique integer ID for each CSDL.
        global _csdl_id_counter
        _csdl_id_counter += 1
        self.csdl_id = _csdl_id_counter

        # Support for lazily updating drawing caches, namely a
        # timestamp showing when this CSDL was last changed.
        self.changed = drawing_constants.eventStamp()

        if transformControl is not None:
            self.transformControl = transformControl
            try:
                ##### KLUGE (temporary), for dealing with a perhaps-permanent change:
                # transformControl might be a Chunk,
                # which has (we assume & depend on) no transform_id
                _x = self.transformControl.transform_id  # should fail for Chunk
            except AttributeError:
                # Assume transformControl is a Chunk.
                # Note: no point in doing self.updateTransform() yet (to record
                # untransformed data early) -- we have no data, since no
                # shader primitives have been stored yet. Untransformed data
                # will be recorded the first time it's transformed (after init,
                # and after each time primitives get cleared and remade).
                pass
            else:
                assert _x is not None
                assert _x is not -1
                self._transform_id = _x
            pass

        # CSDLs should not have a glname since they are never a selobj.
        # Any testCases which depend on this should be rewritten.
        # [bruce 090311]
        ##        # Russ 081122: Mark CSDLs with a glname for selection.
        ##        # (Note: this is a temporary kluge for testing. [bruce 090223 comment])
        ##        self.glname = env._shared_glselect_name_dict. \
        ##                      alloc_my_glselect_name(self)
        ##        ###self.glname = 0x12345678 ### For testing.

        # Whether to draw in the selection over-ride color.
        self.selected = False

        ### TODO [bruce 090114 comment]: a near-term goal is to remove
        # self.selected and self.dl, so that self only knows
        # how to draw either way, but always finds out as-needed
        # (from client state) which way to actually draw.
        # Reviewing the current code, I think the only remaining
        # essential use of self.dl is in CrystalShape.py
        # (see new comment in its docstring for how to clean that up),
        # and the only remaining essential use of self.selected
        # (aside from maintaining self.dl, no longer needed if it's removed)
        # is in ColorSorter.finish (which should be replaced by
        # passing finish the same drawing-style arguments that
        # CSDL.draw accepts).

        return