On Apr 8, 10:39 pm, "Drew Smathers" <[EMAIL PROTECTED]> wrote:
> On Mon, Apr 7, 2008 at 10:49 AM, Simon Wittber <[EMAIL PROTECTED]> wrote:
>
> > I didn't finish anything for pyweek, though I think I produced some
> > code which other pyglet users may find useful.
>
> > I've created C extension types for representing arrays of vectors,
> > with support for arithmetic operations on those arrays. This array
> > type does neat things like pre-allocation, dynamic resizing, memory
> > usage optimisizing, in-place math etc.
>
> > I've also created a VertexArray type, which uses the above array type
> > to represent vertices, colors, texcoords and normals. This code is
> > fast enough to calculate the dynamics for rather massive particle
> > systems.
>
> Why not just use Numpy? Or rather, what limitations did you find in
> such preexisting work that made you decide you had to write your own
> C-extension.
>
AFAIK, numpy requires me to know how many vertices I need before I
create the array. This is not very dynamic.
[EMAIL PROTECTED]:~$ python
Python 2.5.1 (r251:54863, Mar 7 2008, 03:39:23)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> a = numpy.ones((2,3))
>>> a
array([[ 1., 1., 1.],
[ 1., 1., 1.]])
>>> a.append((1,2,3))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'append'
>>> import graphics.ext
>>> b = graphics.ext.Array(3)
>>> b
[]
>>> b.append((1,2,3))
>>> b
[(1.000000 2.000000 3.000000)]
>>>
Notice the Array works more like a Python list, yet keeps some of the
same desirable properties of a numpy array.
>>> T = timeit.Timer("a += a", "import numpy; a = numpy.zeros((100,3),
>>> numpy.float)")
>>> T.timeit()
2.8199739456176758
>>> T = timeit.Timer("a += a", "import graphics.ext; a = graphics.ext.Array(3,
>>> height=100)")
>>> T.timeit()
0.74925613403320312
>>>
Holy cow it is faster than numpy too! Thanks for making me do this
test!
> > It can also do neat things like weld the vertices of an OBJ
> > vertex array, and produce an index into the array.
>
> Welding?
An OBJ is essentially a list of seperate polygons. By welding vertices
together, polygons which have equal vertices will actually get the
same vertex. This means you can tranform a vertex, and effect all
polygons which use that vertex. Welding is a term that comes from 3D
modelling packages for the same operation.
>
> > There are some other goodies in there too, an OBJ loader with material
> > and texture support, a native Vector3 and a native OpenGL transform
> > class.
>
> Heh .. that makes 3 OBJ loaders for pyglet - the one in contrib is
> broken,
> though:http://hg.enterthefoo.com/Miru/file/d0c91d87c1ce/miru/tools/obj.py
>
> > These types are rather rigid and unflexible when compared to the
> > pyglet.graphics module, but when you have a need for speed, they will
> > prove useful.
>
> Really? Could you provide some numbers from performance tests you've done.
Check out the above test comparing numpy. Its also faster with non
inplace operations.
>>> T = timeit.Timer("a * 5", "import numpy; a = numpy.zeros((100,3),
>>> numpy.float)")
>>> T.timeit()
6.5689499378204346
>>> T = timeit.Timer("a * 5", "import graphics.ext; a = graphics.ext.Array(3,
>>> height=100)")
>>> T.timeit()
4.014955997467041
>>>
Of course, graphics.ext is not a numpy or pyglet.graphics
replacement, its just a specialized tool for working with and drawing
vectors.
-Sw.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---