SvgBatch

Loads SVG files into pyglet Batch objects for OpenGL rendering.
Download

SvgBatch Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Jonathan Hartley
  • Publisher web site:
  • http://code.google.com/u/@WBVQRlJTAxZGWwY=/

SvgBatch Tags


SvgBatch Description

Loads SVG files into pyglet Batch objects for OpenGL rendering. SvgBatch is a Python library to load SVG vector graphic files, and convert them into pyglet Batch objects, for OpenGL rendering.The polygons from the SVG file are tesselated using GLU functions, and used to create a pyglet Batch object of indexed vertex arrays. The Batch will aggregate all paths from an SVG file into a single OpenGL GL_TRIANGLES primitive for rendering. Each path is also exposed in its untessellated form, indexed by 'id' attribute, so the application could use them for collision detection, for example.Currently only a subset of SVG is handled - closed polygons, filled with solid color. These may comprise multiple loops (disjoint areas or holes), but must be made up from straight line edges. Arc polygon edges, gradient fills and other SVG entities (such as rectangles or text) are not currently handled.Usage:Very straightforward: svg = SvgBatch('data/logo.svg') batch = svg.create_batch()create_batch() returns a , which can be rendered in a pyglet program using batch.draw() (see demo.py.)Each path in the input SVG can include multiple loops, including holes or islands. The resulting batch is populated with one primitive for each filled path tag in the SVG. The primitives are all indexed vertices of GL_TRIANGLES, which I understand the batch will aggregate into a single large primitive.The untessellated geometry of the loaded paths can also be accessed for things other than rendering (eg. if your application wants to access the vertices of the loaded shape to create a collision boundary): path = svg.path_by_idwhere pathid is the string ID of the path tag in the SVG file. This can be set from within Inkscape by selecting Object properties for the path. The returned Path object has the following attributes: * id: string, copied from the svg tag's id attribute * color: triple of unsigned bytes, (r, g, b) * loops: a list of loops. A loop is a list of vertices. A vertex is a pair of floats or ints. * bounds: an object which provides xmin, xmax, ymin, ymax, denoting the axis-aligned extents of the path * offset(x, y): a method which will add the given offset to all vertices in the path Requirements: · Python


SvgBatch Related Software