Beispiel #1
0
            def primCSDL(centers, radii, colors):
                if not doTransforms:
                    csdl = ColorSortedDisplayList()  # Transformless.
                else:
                    # Test pattern for TransformControl usage - vertical columns
                    # of TC domains, separated by X coord of first center point.
                    # Chunking will be visible when transforms are changed.
                    xCoord = centers[0][0] - start_pos[
                        0]  # Negate centering X.
                    xPercent = (
                        xCoord /
                        (nSpheres + nSpheres / 10 + nSpheres / 100 - 1 +
                         (nSpheres <= 1)))
                    xTenth = int(xPercent * 10 + .5)
                    csdl = ColorSortedDisplayList(TCs[xTenth % numTCs])
                    pass

                # Test selection using the CSDL glname.
                ColorSorter.pushName(csdl.glname)
                ColorSorter.start(glpane, csdl)
                for (color, center, radius) in zip(colors, centers, radii):
                    if not doCylinders:
                        # Through ColorSorter to the sphere primitive buffer...
                        drawsphere(color, center, radius,
                                   DRAWSPHERE_DETAIL_LEVEL)
                    else:
                        # Through ColorSorter to cylinder primitive buffer...
                        if not drawing_globals.cylinderShader_available():
                            print "warning: not cylinderShader_available(), error is likely:"
                        if (True and  # Whether to do tapered shader-cylinders.
                                # Display List cylinders don't support taper.
                                glpane.glprefs.cylinderShader_desired()):
                            ###cylRad = (radius/2.0, (.75-radius)/2.0)
                            cylRad = (radius / 1.5 - .167, .3 - radius / 1.5)
                        else:
                            cylRad = radius / 2.0
                            pass
                        endPt2 = center + V(0.5, 0.0, 0.0)  # 0.5, -0.5)
                        drawcylinder(color, center, endPt2, cylRad)
                        global test_endpoints
                        test_endpoints += [(center, endPt2)]
                        pass
                    continue
                ColorSorter.popName()
                ColorSorter.finish(draw_now=True)

                test_DrawingSet.addCSDL(csdl)
                return csdl
Beispiel #2
0
            def primCSDL(centers, radii, colors):
                if not doTransforms:
                    csdl = ColorSortedDisplayList() # Transformless.
                else:
                    # Test pattern for TransformControl usage - vertical columns
                    # of TC domains, separated by X coord of first center point.
                    # Chunking will be visible when transforms are changed.
                    xCoord = centers[0][0] - start_pos[0] # Negate centering X.
                    xPercent = (xCoord /
                                (nSpheres + nSpheres/10 +
                                 nSpheres/100 - 1 + (nSpheres <= 1)))
                    xTenth = int(xPercent * 10 + .5)
                    csdl = ColorSortedDisplayList(TCs[xTenth % numTCs])
                    pass

                # Test selection using the CSDL glname.
                ColorSorter.pushName(csdl.glname)
                ColorSorter.start(glpane, csdl)
                for (color, center, radius) in zip(colors, centers, radii):
                    if not doCylinders:
                        # Through ColorSorter to the sphere primitive buffer...
                        drawsphere(color, center, radius,
                                   DRAWSPHERE_DETAIL_LEVEL)
                    else:
                        # Through ColorSorter to cylinder primitive buffer...
                        if not drawing_globals.cylinderShader_available():
                            print "warning: not cylinderShader_available(), error is likely:"
                        if (True and  # Whether to do tapered shader-cylinders.
                            # Display List cylinders don't support taper.
                            glpane.glprefs.cylinderShader_desired()):
                            ###cylRad = (radius/2.0, (.75-radius)/2.0)
                            cylRad = (radius/1.5 - .167, .3 - radius/1.5)
                        else:
                            cylRad = radius/2.0
                            pass
                        endPt2 = center + V(0.5, 0.0, 0.0) # 0.5, -0.5)
                        drawcylinder(color, center, endPt2, cylRad)
                        global test_endpoints
                        test_endpoints += [(center, endPt2)]
                        pass
                    continue
                ColorSorter.popName()
                ColorSorter.finish(draw_now = True)

                test_DrawingSet.addCSDL(csdl)
                return csdl
    def schedule_cylinder(color, pos1, pos2, radius, capped = 0, opacity = 1.0):
        """
        Schedule a cylinder for rendering whenever ColorSorter thinks is
        appropriate.

        @param pos1: axis endpoint 1
        @type pos1: Numeric array (list or tuple won't always work)

        @param pos2: axis endpoint 2
        @type pos2: Numeric array

        @note: you can pass a tuple of two radii (in place of radius)
            to make this a tapered cylinder. When cylinder shaders are active
            and supported, this will use them, otherwise it will use a polycone.
        """
        # check type of radius in the same way for all calls [bruce 090225]
        if type(radius) == type(()):
            # radius must be a tuple of 2 radii (length not checked here)
            ColorSorter._schedule_tapered_cylinder(color, pos1, pos2, radius, capped, opacity)
            return

        radius = float(radius)

        if _DEBUG and ColorSorter._parent_csdl and ColorSorter._parent_csdl.reentrant:
            print "bare_prim cylinder:", ColorSorter._gl_name_stack[-1], \
                  color, pos1, pos2, radius, capped, ColorSorter._debug_transforms()

        if ColorSorter._parent_csdl and ColorSorter._parent_csdl.reentrant:
            # todo: use different flag than .reentrant

            # note: if drawing a cylinder requires an implicit coordinate system
            # rather than just the axis endpoints (e.g. if it has a polygonal
            # cross-section or a surface texture), we'd also need to pick a
            # disambiguating point on the barrel here, outside this condition,
            # and include it in what we transform, inside this condition.
            # This need may be present now if we use this case for non-shader
            # cylinders (since they have polygonal cross-section). ##### REVIEW
            pos1 = ColorSorter._transform_point(pos1)
            pos2 = ColorSorter._transform_point(pos2)

        if ColorSorter.glpane.glprefs.use_c_renderer and ColorSorter.sorting:
            if len(color) == 3:
                lcolor = (color[0], color[1], color[2], 1.0)
            else:
                lcolor = color
            ColorSorter._cur_shapelist.add_cylinder(
                lcolor, pos1, pos2, radius,
                ColorSorter._gl_name_stack[-1], capped)
        else:
            if len(color) == 3:
                lcolor = (color[0], color[1], color[2], opacity)
            else:
                lcolor = color

            # Russ 090119: Added.
            cylinderBatches = ( ColorSorter._permit_shaders and
                                ColorSorter.glpane.glprefs.cylinderShader_desired() and
                                drawing_globals.cylinderShader_available()
                              )
            if cylinderBatches and ColorSorter._parent_csdl:
                # Note: capped is not used; a test indicates it's always on
                # (at least in the tapered case). [bruce 090225 comment]
                assert ColorSorter.sorting # since _parent_csdl is present
                # note: radius can legally be a number, or a tuple of two radii,
                # but the tuple case never gets this far -- it's diverted above
                # into _schedule_tapered_cylinder.
                ColorSorter._parent_csdl.addCylinder(
                    (pos1, pos2), radius, lcolor,
                    # glnames come from ColorSorter.pushName()
                    ColorSorter._gl_name_stack[-1])
            else:
                ColorSorter.schedule(lcolor,
                                 drawcylinder_worker,
                                 (pos1, pos2, radius, capped))
Beispiel #4
0
    def schedule_cylinder(color, pos1, pos2, radius, capped=0, opacity=1.0):
        """
        Schedule a cylinder for rendering whenever ColorSorter thinks is
        appropriate.

        @param pos1: axis endpoint 1
        @type pos1: Numeric array (list or tuple won't always work)

        @param pos2: axis endpoint 2
        @type pos2: Numeric array

        @note: you can pass a tuple of two radii (in place of radius)
            to make this a tapered cylinder. When cylinder shaders are active
            and supported, this will use them, otherwise it will use a polycone.
        """
        # check type of radius in the same way for all calls [bruce 090225]
        if type(radius) == type(()):
            # radius must be a tuple of 2 radii (length not checked here)
            ColorSorter._schedule_tapered_cylinder(color, pos1, pos2, radius,
                                                   capped, opacity)
            return

        radius = float(radius)

        if _DEBUG and ColorSorter._parent_csdl and ColorSorter._parent_csdl.reentrant:
            print "bare_prim cylinder:", ColorSorter._gl_name_stack[-1], \
                  color, pos1, pos2, radius, capped, ColorSorter._debug_transforms()

        if ColorSorter._parent_csdl and ColorSorter._parent_csdl.reentrant:
            # todo: use different flag than .reentrant

            # note: if drawing a cylinder requires an implicit coordinate system
            # rather than just the axis endpoints (e.g. if it has a polygonal
            # cross-section or a surface texture), we'd also need to pick a
            # disambiguating point on the barrel here, outside this condition,
            # and include it in what we transform, inside this condition.
            # This need may be present now if we use this case for non-shader
            # cylinders (since they have polygonal cross-section). ##### REVIEW
            pos1 = ColorSorter._transform_point(pos1)
            pos2 = ColorSorter._transform_point(pos2)

        if ColorSorter.glpane.glprefs.use_c_renderer and ColorSorter.sorting:
            if len(color) == 3:
                lcolor = (color[0], color[1], color[2], 1.0)
            else:
                lcolor = color
            ColorSorter._cur_shapelist.add_cylinder(
                lcolor, pos1, pos2, radius, ColorSorter._gl_name_stack[-1],
                capped)
        else:
            if len(color) == 3:
                lcolor = (color[0], color[1], color[2], opacity)
            else:
                lcolor = color

            # Russ 090119: Added.
            cylinderBatches = (
                ColorSorter._permit_shaders
                and ColorSorter.glpane.glprefs.cylinderShader_desired()
                and drawing_globals.cylinderShader_available())
            if cylinderBatches and ColorSorter._parent_csdl:
                # Note: capped is not used; a test indicates it's always on
                # (at least in the tapered case). [bruce 090225 comment]
                assert ColorSorter.sorting  # since _parent_csdl is present
                # note: radius can legally be a number, or a tuple of two radii,
                # but the tuple case never gets this far -- it's diverted above
                # into _schedule_tapered_cylinder.
                ColorSorter._parent_csdl.addCylinder(
                    (pos1, pos2),
                    radius,
                    lcolor,
                    # glnames come from ColorSorter.pushName()
                    ColorSorter._gl_name_stack[-1])
            else:
                ColorSorter.schedule(lcolor, drawcylinder_worker,
                                     (pos1, pos2, radius, capped))