This software loads SVG files and converts them into pyglet Batch objects, optimized for OpenGL rendering. The process provides a fast and efficient method of rendering graphics in games and other applications.
In addition to rendering, each path in the input SVG can be accessed in its untesselated form. This can be used for collision detection, just to mention an example. Each path is indexed by its 'id' attribute, thus providing easy access to the vertices of the path.
Currently, SvgBatch only handles a subset of SVG- closed polygons which are 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 supported.
Utilizing SvgBatch is very straightforward. Upon loading an SVG file, create a batch object by invoking svg.create_batch( ). This returns a pyglet Batch object that can be rendered using batch.draw( ). Every filled path tag in the input SVG corresponds to a primitive in the resulting batch. The primitives consist of indexed vertices of GL_TRIANGLES, which the batch aggregates into a single large primitive.
To access the untessellated geometry of the loaded paths, simply use the below syntax:
path = svg.path_by_id['pathid']
Here, pathid refers to the string ID of the path tag in the SVG file. This ID can be set from within Inkscape by selecting Object properties for the path. The returned Path object has various attributes, such as id, color (as a triple of unsigned bytes), loops (a list of loops where each loop is a list of vertices), bounds (which provides xmin, xmax, ymin, ymax, denoting the axis-aligned extents of the path), and offset(x, y) (which is a method that adds the given offset to all vertices in the path).
Version 0.1.9: N/A