Example #1
0
    def __init__(self, pos, texture, size_x=1.0, size_y=1.0, intensity=1.0, Tr=1.0):
        super(BillboardDisplay, self).__init__()
        
        self.intensity = intensity
        self.Tr = Tr

        self.translate = Translate()
        self.rotate_azi = Rotate(origin=(0,0,0), axis=(0,1,0))
        self.rotate_ele = Rotate(origin=(0,0,0), axis=(1,0,0))
        self.scale = Scale()
        self.color_instruction = InstructionGroup()
        self.mesh = Mesh(
            texture=texture,
            vertices=rectangle_nurb.vertices,
            indices=rectangle_nurb.indices,
            fmt=rectangle_nurb.vertex_format,
            mode='triangles'
        )

        self.add(PushMatrix())
        self.add(self.translate)
        self.add(self.rotate_azi)
        self.add(self.rotate_ele)
        self.add(self.scale)
        self.add(self.color_instruction)
        self.add(self.mesh)
        self.add(PopMatrix())

        self.set_color(intensity=intensity, Tr=Tr)
        self.set_size(size_x, size_y)
        self.set_pos(pos)
        self.set_texture(texture)
Example #2
0
    def get_mesh(self):
        v = []
        # first calculate the distance between endpoints of the outer
        # arc, so we know how many steps to use when calculating
        # vertices
        theta_step_outer = 0.1
        theta = self.theta_max - self.theta_min
        d_outer = int(theta / theta_step_outer)
        theta_step_outer = theta / d_outer

        if self.r_min == 0:
            for x in range(0, d_outer, 2):
                v += (polar_to_rect(self.origin, self.r_max,
                                    self.theta_min + x * theta_step_outer) * 2)
                v += polar_to_rect(self.origin, 0, 0) * 2
                v += (
                    polar_to_rect(self.origin, self.r_max, self.theta_min +
                                  (x + 1) * theta_step_outer) * 2)
            if not d_outer & 1:  # add a last point if d_outer is even
                v += (
                    polar_to_rect(self.origin, self.r_max, self.theta_min +
                                  d_outer * theta_step_outer) * 2)
        else:
            for x in range(d_outer + 1):
                v += (polar_to_rect(self.origin, self.r_min,
                                    self.theta_min + x * theta_step_outer) * 2)
                v += (polar_to_rect(self.origin, self.r_max,
                                    self.theta_min + x * theta_step_outer) * 2)

        return Mesh(vertices=v,
                    indices=range(int(len(v) / 4)),
                    mode='triangle_strip')
    def make_editable(self, editable = True, player_won_color = None, size_hint = None):
        self.editable = editable
        scores_holder = self.ids.scores_holder
        scores_holder.clear_widgets()

        if player_won_color != None:
            with self.canvas:
                # green terrain
                Color(player_won_color.r, player_won_color.g, player_won_color.b)
                self.mesh = Mesh(vertices=[0,0,0,0 ,0,size_hint.y,0,0 ,size_hint.x,size_hint.y,0,0 , size_hint.x,0,0,0], indices=[0,1,2,3], mode='triangle_fan')

        scores = []

        Path("./scores/").mkdir(parents=True, exist_ok=True)
        if not os.path.isfile('./scores/scores.txt'):
            with open('./scores/scores.txt', 'a'):
                pass
        if os.path.isfile('./scores/scores.txt') and os.stat('./scores/scores.txt').st_size > 0:
            with open('./scores/scores.txt', 'r') as f:
                content = f.readlines()
                scores = [line.strip('\n') for line in content]

        scores = scores + ["-Not filled yet-"] * (5-len(scores))

        if(editable):
            scores_holder.add_widget(TextInput(hint_text='Write your name..', id='score_input'))
            scores = scores[:-1]
        
        for score in scores:
            scores_holder.add_widget(Label(text=score, font_size = 15))
Example #4
0
    def __init__(self, edges=3, color=None, **kwargs):
        super(RegularShape, self).__init__(**kwargs)
        if edges < 3:
            raise Exception('Not enough edges! (3+ only)')

        color = color or [random() for i in range(3)]
        rad_edge = (pi * 2) / float(edges)
        r_x = self.width / 2.0
        r_y = self.height / 2.0
        poly = []
        vertices = []
        for i in range(edges):
            # get points within a circle with radius of [r_x, r_y]
            x = cos(rad_edge * i) * r_x + self.center_x
            y = sin(rad_edge * i) * r_y + self.center_y
            poly.extend([x, y])

            # add UV layout zeros for Mesh, see Mesh docs
            vertices.extend([x, y, 0, 0])

        # draw Mesh shape from generated poly points
        with self.canvas:
            Color(rgba=(color[0], color[1], color[2], 0.6))
            self.shape = Mesh(pos=self.pos,
                              vertices=vertices,
                              indices=list(range(edges)),
                              mode='triangle_fan')
        self.poly = poly
Example #5
0
    def draw_object(self, obj_id):
        m = self._scene.objects[obj_id]
        self.obj_rot_z = Rotate(self.obj_rotation[2], 0, 0, 1)
        self.obj_rot_y = Rotate(self.obj_rotation[1], 0, 1, 0)
        self.obj_rot_x = Rotate(self.obj_rotation[0], 1, 0, 0)
        self.obj_translate = Translate(xyz=self.obj_translation)

        if len(m.indices) > 2**16:
            print '%s too big! %s indices' % (obj_id, len(m.indices))

        if m.texture:
            print "loading texture %s " % m.texture
            img = Image(
                source=resource_find(join(dirname(self.scene), m.texture)))
            texture = img.texture
            if texture:
                texture.wrap = 'repeat'
        else:
            texture = None

        vertex_lenght = sum(x[1] for x in m.vertex_format)
        if len(m.vertices) % vertex_lenght:
            print(('warning: vertices lenght (%s)'
                   'is not a multiple of vertex_format lenght(%s)') %
                  (len(m.vertices), vertex_lenght))
        Mesh(vertices=m.vertices,
             indices=m.indices,
             fmt=m.vertex_format,
             texture=texture,
             mode=self.mode)
Example #6
0
    def drawTriangles(self, lastPos, newPos, lastHeight, newHeight):
        trianglePts = []
        baseWhite = lastHeight >= 0.5 * self.height and newHeight >= 0.5 * self.height \
            and (lastHeight > 0.5 * self.height or newHeight > 0.5 * self.height)
        baseBlack = lastHeight <= 0.5 * self.height and newHeight <= 0.5 * self.height \
            and (lastHeight < 0.5 * self.height or newHeight < 0.5 * self.height)
        if baseWhite or baseBlack:
            refHeight = min(lastHeight, newHeight) if baseWhite else max(
                lastHeight, newHeight)
            biggestHeight = max(lastHeight, newHeight) if baseWhite else min(
                lastHeight, newHeight)

            refPos = lastPos if refHeight == lastHeight else newPos
            biggestPos = lastPos if biggestHeight == lastHeight else newPos

            trianglePts += [
                self.x + self.width * lastPos, self.y + 0.5 * self.height, 0,
                0, self.x + self.width * lastPos, self.y + refHeight, 0, 0,
                self.x + self.width * newPos, self.y + 0.5 * self.height, 0, 0,
                self.x + self.width * lastPos, self.y + refHeight, 0, 0,
                self.x + self.width * newPos, self.y + 0.5 * self.height, 0, 0,
                self.x + self.width * newPos, self.y + refHeight, 0, 0,
                self.x + self.width * refPos, self.y + refHeight, 0, 0,
                self.x + self.width * biggestPos, self.y + refHeight, 0, 0,
                self.x + self.width * biggestPos, self.y + biggestHeight, 0, 0
            ]
        baseColor = 0.65 if baseWhite else 0.35

        with self.canvas:
            Color(baseColor, baseColor, baseColor)
            if len(trianglePts) > 0:
                Mesh(vertices=trianglePts,
                     mode="triangles",
                     indices=range(int(len(trianglePts) / 4)))
 def get_graphics(self, gc, polygons, points_line, rgbFace, closed=False):
     '''Return an instruction group which contains the necessary graphics
        instructions to draw the respective graphics.
     '''
     instruction_group = InstructionGroup()
     if isinstance(gc.line['dash_list'], tuple):
         gc.line['dash_list'] = list(gc.line['dash_list'])
     if rgbFace is not None:
         if len(polygons.meshes) != 0:
             instruction_group.add(Color(*rgbFace))
             for vertices, indices in polygons.meshes:
                 instruction_group.add(
                     Mesh(vertices=vertices,
                          indices=indices,
                          mode=str("triangle_fan")))
     instruction_group.add(Color(*gc.get_rgb()))
     if _mpl_1_5 and closed:
         points_poly_line = points_line[:-2]
     else:
         points_poly_line = points_line
     if gc.line['width'] > 0:
         instruction_group.add(
             Line(points=points_poly_line,
                  width=int(gc.line['width'] / 2),
                  dash_length=gc.line['dash_length'],
                  dash_offset=gc.line['dash_offset'],
                  dash_joint=gc.line['joint_style'],
                  dash_list=gc.line['dash_list']))
     return instruction_group
Example #8
0
 def draw_mesh(self, star_list):
     address = 'assets/particles/'
     tex_choice = choice([
         'particle.png', 'smokeparticle.png', 'VFX-0-Circle.png',
         'VFX-0-Star.png', 'VFX-1-Star.png'
     ])
     tex = Image(address + tex_choice).texture
     vertex_format = [(b'vPosition', 2, 'float'), (b'vSize', 1, 'float'),
                      (b'vRotation', 1, 'float'), (b'vColor', 4, 'float')]
     indices = []
     ia = indices.append
     for star_number in range(len(star_list)):
         ia(star_number)
     vertices = []
     e = vertices.extend
     for star in star_list:
         color = star[4]
         e([
             star[0], star[1], star[2], star[3], color[0], color[1],
             color[2], color[3]
         ])
     if self.mesh == None:
         with self.canvas:
             PushMatrix()
             self.mesh = Mesh(indices=indices,
                              vertices=vertices,
                              fmt=vertex_format,
                              mode='points',
                              texture=tex)
             PopMatrix()
     else:
         self.mesh.indices = indices
         self.mesh.vertices = vertices
         self.mesh.texture = tex
Example #9
0
    def _geojson_part_geometry(self, geometry, properties):
        tp = geometry["type"]
        graphics = []
        if tp == "Polygon":
            tess = Tesselator()
            for c in geometry["coordinates"]:
                xy = list(self._lonlat_to_xy(c))
                xy = flatten(xy)
                tess.add_contour(xy)

            tess.tesselate(WINDING_ODD, TYPE_POLYGONS)

            color = self._get_color_from(properties.get("style").get("stroke", "FF000088"))
            graphics.append(Color(*color))
            for vertices, indices in tess.meshes:
                graphics.append(
                    Mesh(
                        vertices=vertices,
                        indices=indices,
                        mode="triangle_fan"))

        elif tp == "LineString":
            stroke = get_color_from_hex(properties.get("style").get("stroke", "#ffffff"))
            print "stroke: " + `stroke`
            #storke =  [0.0, 0.0, 0.0, 1]

            print 'properties.get("width") :' + `properties.get("style").get("width")`
            stroke_width = dp(properties.get("style").get("width"))
            print "stroke_width: " + `stroke_width`
            xy = list(self._lonlat_to_xy(geometry["coordinates"]))
            xy = flatten(xy)
            graphics.append(Color(*stroke))
            graphics.append(Line(points=xy, width=stroke_width))

        return graphics
Example #10
0
 def generateMesh(self):
     hgt = self.generateHeightData(200, 200, 0.1)
     norm = self.calcNormals(hgt)
     idcs = self.generateTriangleCounterClockWiseIndices(hgt)
     print hgt.shape
     vtx = []
     idx = []
     i = 0
     for x in range(hgt.shape[0]):
         for y in range(hgt.shape[1]):
             vtx.extend([
                 float(x) / 10.0 - 5,
                 hgt[x, y],
                 float(y) / 10.0 - 5,
                 norm[x, y, 0] / 10.0,
                 norm[x, y, 1],
                 norm[x, y, 2] / 10.0,
                 0.0,
                 0.0,
             ])
             idx.append(i)
             i += 1
     m = Mesh(vertices=vtx,
              indices=idcs,
              mode='triangles',
              fmt=[('v_pos', 3, 'float'), ('v_normal', 3, 'float'),
                   ('v_tc0', 2, 'float')
                   ])  #[(b'v_pos', 2, b'float'), (b'tc', 2, b'float')])
     return m
Example #11
0
    def _geojson_part_geometry(self, geometry, properties):
        from kivy.graphics import Mesh, Line, Color
        from kivy.graphics.tesselator import Tesselator, WINDING_ODD, TYPE_POLYGONS
        from kivy.utils import get_color_from_hex
        from kivy.metrics import dp
        tp = geometry["type"]
        graphics = []
        if tp == "Polygon":
            tess = Tesselator()
            for c in geometry["coordinates"]:
                xy = list(self._lonlat_to_xy(c))
                xy = flatten(xy)
                tess.add_contour(xy)

            tess.tesselate(WINDING_ODD, TYPE_POLYGONS)

            graphics.append(Color(1, 0, 0, .5))
            for vertices, indices in tess.meshes:
                graphics.append(
                    Mesh(vertices=vertices,
                         indices=indices,
                         mode="triangle_fan"))

        elif tp == "LineString":
            stroke = get_color_from_hex(properties.get("stroke", "#ffffff"))
            stroke_width = dp(properties.get("stroke-width"))
            xy = list(self._lonlat_to_xy(geometry["coordinates"]))
            xy = flatten(xy)
            graphics.append(Color(*stroke))
            graphics.append(Line(points=xy, width=stroke_width))

        return graphics
Example #12
0
    def get_mesh(self):
        v = []
        # first calculate the distance between endpoints of the inner
        # arc, so we know how many steps to use when calculating
        # vertices
        end_point_inner = polar_to_rect(self.origin, self.r_min,
                                        self.theta_max)

        d_inner = d_outer = 3.
        theta_step_inner = (self.theta_max - self.theta_min) / d_inner

        end_point_outer = polar_to_rect(self.origin, self.r_max,
                                        self.theta_max)

        if self.r_min == 0:
            theta_step_outer = (self.theta_max - self.theta_min) / d_outer
            for x in range(int(d_outer)):
                v += (polar_to_rect(self.origin, 0, 0) * 2)
                v += (polar_to_rect(self.origin, self.r_max,
                                    self.theta_min + x * theta_step_outer) * 2)
        else:
            for x in range(int(d_inner + 2)):
                v += (polar_to_rect(self.origin, self.r_min - 1,
                                    self.theta_min + x * theta_step_inner) * 2)
                v += (polar_to_rect(self.origin, self.r_max + 1,
                                    self.theta_min + x * theta_step_inner) * 2)

        v += (end_point_inner * 2)
        v += (end_point_outer * 2)

        return Mesh(vertices=v,
                    indices=range(int(len(v) / 4)),
                    mode='triangle_strip')
Example #13
0
    def show_lines(self):
        indices = []
        grid = self.grid
        cols = grid.cols
        rows = grid.rows
        for col in range(grid.cols + 1):
            indices.extend((
                col * (rows + 1),
                col * (rows + 1) + rows,
            ))
        for row in range(grid.rows + 1):
            indices.extend((
                row,
                row + (cols * (rows + 1)),
            ))

        with self.canvas:
            self.g_canvas = Canvas()

        with self.g_canvas:
            Color(1, 0, 0, 0.5)
            PushMatrix()
            Scale(self.width, self.height, 1.)
            self.g_mesh = Mesh(vertices=self.grid.line_vertices,
                               indices=self.grid.line_indices,
                               mode="lines",
                               source="projectionmapping/data/white.png")
            PopMatrix()

        self.rebuild_informations()
 def draw_mesh(self, this_star_list):
     if self.this_op is None:
         self.this_op = PointRendererOp()
         star_tex = Image('star1.png').texture
         self.this_op.indices = []
         ia = self.this_op.indices.append
         for star_number in range(len(this_star_list)):
             ia(star_number)
         self.this_op.vertices = []
         e = self.this_op.vertices.extend
         for star in this_star_list:
             this_star = [ star[0], star[1], star[2], star[3], \
                           star[4], star[5], star[6], star[7] ]
             if len(this_star) != self.vertex_depth:
                 print("FATAL ERROR: array size does not match " + \
                       "vertex depth (offset)")
                 exit(1)
             e(this_star)
     if self.mesh == None:
         with self.canvas:
             PushMatrix()
             self.mesh = Mesh(indices=self.this_op.indices,
                              vertices=self.this_op.vertices,
                              fmt=self.vertex_format,
                              mode='points',
                              texture=star_tex)
             PopMatrix()
     else:
         # self.mesh.indices = self.this_op.indices
         self.mesh.vertices = self.this_op.vertices
         pass
Example #15
0
 def draw_mesh(self, star_list):
     star_tex = Image('star1.png').texture
     vertex_format = [
         (b'vPosition', 2, 'float'),
         (b'vSize', 1, 'float'),
         (b'vRotation', 1, 'float'),
     ]
     indices = []
     ia = indices.append
     for star_number in range(len(star_list)):
         ia(star_number)
     vertices = []
     e = vertices.extend
     for star in star_list:
         e([star[0], star[1], star[2], star[3]])
     if self.mesh == None:
         with self.canvas:
             PushMatrix()
             self.mesh = Mesh(indices=indices,
                              vertices=vertices,
                              fmt=vertex_format,
                              mode='points',
                              texture=star_tex)
             PopMatrix()
     else:
         self.mesh.indices = indices
         self.mesh.vertices = vertices
Example #16
0
    def make_pretty_dots(self):
        points_per_side = 50

        points = []
        for idx in range(points_per_side):
            v = -1.0 + ((2.0 / points_per_side) * float(idx))
            tex = idx / float(points_per_side)
            print("TEX: {}".format(str(tex)))
            points.append([[v, -1.0, -1.0, v, -1.0, -1.0, tex, 0.0],
                           [v, -1.0, 1.0, v, -1.0, 1.0, tex, 0.0],
                           [v, 1.0, -1.0, v, 1.0, -1.0, tex, 1.0],
                           [v, 1.0, 1.0, v, 1.0, 1.0, tex, 1.0],
                           [-1.0, v, -1.0, -1.0, v, -1.0, 0.0, tex],
                           [-1.0, v, 1.0, -1.0, v, 1.0, 0.0, tex],
                           [1.0, v, -1.0, 1.0, v, -1.0, 1.0, tex],
                           [1.0, v, 1.0, 1.0, v, 1.0, 1.0, tex],
                           [-1.0, -1.0, v, -1.0, -1.0, v, tex, tex],
                           [-1.0, 1.0, v, -1.0, 1.0, v, tex, tex],
                           [1.0, -1.0, v, 1.0, -1.0, v, tex, tex],
                           [1.0, 1.0, v, 1.0, 1.0, v, tex, tex]], )

        points = np.array(points).flatten()
        Color(1, 1, 1, 1)
        Mesh(
            vertices=points,
            indices=[i for i in range(len(points) / 8)],
            fmt=self.mesh_data.vertex_format,
            mode='points',
        )
Example #17
0
 def __init__(self):
     super(Sprite, self).__init__()
     with self:
         self.color = Color()
         self.mesh = Mesh(vertices=[0.0] * 16,
                          indices=range(4),
                          mode=MODE_TRIANGLE_FAN)
Example #18
0
        def _draw_element(m, texture='', texture1=''):
            #bind the texture BEFORE the draw (Mesh)
            if texture1:
                # here, we are binding a custom texture at index 1
                # this will be used as texture1 in shader.
                tex1 = Image(texture1).texture
                tex1.wrap = 'repeat'  #enable of uv support >1 or <0
                BindTexture(texture=tex1, index=1)
            #clear the texture if none
            else:
                BindTexture(source="", index=1)

            mesh = Mesh(
                vertices=m.vertices,
                indices=m.indices,
                fmt=m.vertex_format,
                mode='triangles',
                group='truc',
            )

            if texture:
                try:
                    texture = Image(texture).texture
                    texture.wrap = 'repeat'  #enable of uv support >1 or <0
                    mesh.texture = texture
                except:  #no texture if not found or not supported
                    pass
Example #19
0
    def __init__(self, **kwargs):
        self._color = Color(1, 1, 1, group='LinePlot%d' % id(self))
        self._mesh = Mesh(mode='line_strip', group='LinePlot%d' % id(self))
        super(MeshLinePlot, self).__init__(**kwargs)

        self._trigger = Clock.create_trigger(self._redraw)
        self.bind(_params=self._trigger, points=self._trigger)
Example #20
0
 def __init__(self, **kw):
     super(Background, self).__init__(**kw)
     # self.frames = -1
     with self.canvas:
         self.clr = Color(0, .2, .2, mode='hsv')
         self.mesh = Mesh(mode='triangles', source='img/background.png')
     self.build_mesh()
Example #21
0
    def build(self):
        tess = Tesselator()
        count = 0
        for shape in self.shapes:
            if len(shape) >= 3:
                tess.add_contour(shape)
                count += 1
        if self.shape and len(self.shape) >= 3:
            tess.add_contour(self.shape)
            count += 1
        if not count:
            return
        print("Tesselate {} shapes".format(count))
        ret = tess.tesselate(WINDING_ODD, TYPE_POLYGONS)
        print("Result: {}".format(ret))
        print("Vertex count: {}".format(tess.vertex_count))
        print("Element count: {}".format(tess.element_count))

        self.canvas.after.clear()

        debug = self.ids.debug.state == "down"
        if debug:
            from random import random
            with self.canvas.after:
                c = 0
                for vertices, indices in tess.meshes:
                    Color(c, 1, 1, mode="hsv")
                    c += 0.3
                    indices = [0]
                    for i in range(1, len(vertices) / 4):
                        if i > 0:
                            indices.append(i)
                        indices.append(i)
                        indices.append(0)
                        indices.append(i)
                    indices.pop(-1)
                    Mesh(vertices=vertices, indices=indices, mode="lines")
        else:
            with self.canvas.after:
                Color(1, 1, 1, 1)
                for vertices, indices in tess.meshes:
                    Mesh(vertices=vertices,
                         indices=indices,
                         mode="triangle_fan")

        self.ids.status.text = "Vertex: {} - Elements: {}".format(
            tess.vertex_count, tess.element_count)
Example #22
0
 def __init__(self, **kwargs):
     super(GridEditorCanvas, self).__init__(**kwargs)
     self.imagePlaceholderFrame = ImagePlaceholderFrame()
     self.add_widget(self.imagePlaceholderFrame)
     with self.canvas:
         self.imageMesh = Mesh(vertices=[],
                               indices=[],
                               mode='triangle_strip')
Example #23
0
    def Tick(self, dt):
        # Clean Canvas
        self.canvas.before.clear()

        meshVerticesList = []

        # Move and draw rays
        for ray in self.rayList:
            
            # if raycount>=self.tickCount: break
            # raycount +=1

            ray.Vi = Vector(self.particle.center_x, self.particle.center_y)
            ray.Vf = ray.Vi + dp(1000)*Vector(0,1).rotate(ray.angle)

            dist = dp(5000)
            
            # Check intersection with obstacles
            for obst in self.obstList:

                # Distance for each obstacle
                

                # Calculate intersection point
                interPoint, onLine1, onLine2 = self.LineIntersection([ray.Vi,ray.Vf],[obst.Vi, obst.Vf])
                if onLine2 == True and onLine1 == True:
                    if ray.Vi.distance(interPoint) < dist:
                        dist = ray.Vi.distance(interPoint)
                        ray.Vf.x, ray.Vf.y = Vector(interPoint[0], interPoint[1])

                    # Draw intersection points
                    # with self.canvas.before:
                    #     Color(1,0,0,1)
                    #     Ellipse(size=(2,2), pos=(interPoint[0]-1, interPoint[1]-1))

            # Draw end points
            with self.canvas.before:
                #Color(1,1,1,0.5)
                #Line(points=(ray.Vi, ray.Vf,), width = 1)
                Color(((1000-dist)/1000),(dist/200),0,1)
                Ellipse(size=(dp(4),dp(4)), pos=(ray.Vf.x-2, ray.Vf.y-2))

            meshVerticesList.extend([ray.Vf.x,ray.Vf.y,0,0])

        
        # Draw mesh
        meshIndList = list(range(len(meshVerticesList)//4))
        with self.canvas.before:
            Color(1,1,1,0.2)
            Mesh(mode='line_loop', vertices=meshVerticesList, indices=meshIndList)
        
        # Draw obstacles
        for obst in self.obstList:
            with self.canvas.before:
                Color(rgba=(0.5,0.5,0.5,1))
                Line(points=[obst.Vi, obst.Vf], width=dp(1))
                Color(rgba=(1,1,1,1))
Example #24
0
 def build_mesh(self):
     tess = Tesselator()
     tess.add_contour(self.points)
     tess.tesselate()
     with self.canvas:
         for vertices, indices in tess.meshes:
             self.canvas.add(Mesh(vertices=vertices,
                                  indices=indices,
                                  mode="triangle_fan"))
Example #25
0
 def prepare_graphics(self, canvas):
     self._mesh_vertices = vertices = [0] * 16
     vertices[2::4] = self._tex_coords[::2]
     vertices[3::4] = self._tex_coords[1::2]
     self.canvas = Canvas()
     with self.canvas:
         Color(1, 1, 1, 1)
         PushMatrix()
         self.g_mesh = Mesh(vertices=vertices,
                            indices=range(4),
                            mode="triangle_fan",
                            texture=self.texture)
         self.g_debug_color = Color(1, 0, 0, 1)
         self.g_debug_mesh = Mesh(
             vertices=vertices,
             indices=range(4),
             mode="line_loop",
         )
         PopMatrix()
Example #26
0
 def _create_monkey_mesh_no_norms(self):
     m = list(self._monkey_scene.objects.values())[0]
     self._mesh_data = GLMeshData(vertices=np.array(m.verts_raw),
                                  faces=m.faces)
     self._mesh = Mesh(
         vertices=self._mesh_data.verts_gl,
         indices=self._mesh_data.indices,
         fmt=self._mesh_data.vertex_format,
         mode=self._curr_mode,
     )
Example #27
0
    def __init__(self, **kwargs):
        super(Graph, self).__init__(**kwargs)

        self._mesh = Mesh(mode='lines')
        self._mesh_rect = Mesh(mode='line_strip')
        val = 0.25
        self.canvas.add(Color(1 * val, 1 * val, 1 * val))
        self.canvas.add(self._mesh)
        self.canvas.add(Color(1, 1, 1))
        self.canvas.add(self._mesh_rect)
        mesh = self._mesh_rect
        mesh.vertices = [0] * (5 * 4)
        mesh.indices = [k for k in xrange(5)]

        self._plot_area = StencilView()
        self.add_widget(self._plot_area)

        self._trigger = Clock.create_trigger(self._redraw_all)
        self._trigger_size = Clock.create_trigger(self._redraw_size)

        self.bind(center=self._trigger_size,
                  padding=self._trigger_size,
                  font_size=self._trigger_size,
                  plots=self._trigger_size,
                  x_grid=self._trigger_size,
                  y_grid=self._trigger_size,
                  draw_border=self._trigger_size)
        self.bind(xmin=self._trigger,
                  xmax=self._trigger,
                  xlog=self._trigger,
                  x_ticks_major=self._trigger,
                  x_ticks_minor=self._trigger,
                  xlabel=self._trigger,
                  x_grid_label=self._trigger,
                  ymin=self._trigger,
                  ymax=self._trigger,
                  ylog=self._trigger,
                  y_ticks_major=self._trigger,
                  y_ticks_minor=self._trigger,
                  ylabel=self._trigger,
                  y_grid_label=self._trigger)
        self._trigger()
Example #28
0
 def __init__(self, **kwargs):
     super(TestWidget, self).__init__()
     self.engine = e = GlslParticle(64)
     Clock.schedule_interval(self.iterate, 0)
     with self.canvas:
         Color(1, 1, 1, 1)
         Rectangle(pos=(0, 0), size=(100, 100), texture=e.tex_pos)
         Rectangle(pos=(100, 0), size=(100, 100), texture=e.tex_pos2)
         Rectangle(pos=(0, 100), size=(100, 100), texture=e.tex_vel)
         Rectangle(pos=(100, 100), size=(100, 100), texture=e.tex_vel2)
         self.mesh = Mesh(mode='points')
Example #29
0
 def build_mesh(self):
     vertices = []
     indices = []
     step = 10
     istep = (pi * 2) / float(step)
     for i in range(step):
         x = 300 + cos(istep * i) * 100
         y = 300 + sin(istep * i) * 100
         vertices.extend([x, y, 0, 0])
         indices.append(i)
     return Mesh(vertices=vertices, indices=indices)
Example #30
0
    def __setitem__(self, key, cell):
        ret = super().__setitem__(key, cell)

        group = InstructionGroup()
        if cell.food == 0:
            group.add(self.color)
            group.add(
                Mesh(vertices=self._mesh_vertices(cell),
                     indices=list(range(6)),
                     mode=self.mesh_mode))
        else:
            group.add(Color(0, 1, 0, 1))
            group.add(
                Mesh(vertices=self._mesh_vertices(cell),
                     indices=list(range(6)),
                     mode='triangle_fan'))

        self.canvas_groups[key] = group
        self.canvas.add(group)
        return ret