Banging My Head For What???
Posted by ArmchairArmada
August 9th, 2008 1:57 pm
I spent the past couple of hours trying to get a simple spacial partitioning system working so ray/triangle intersection tests between game objects and the world mesh would be reasonably quick … or so I hoped. On my machine the frame rate drops horribly with even as few as 10 intersection tests per frame! I guess Python’s not a good platform to write a 3D engine in.
Have you tried using Soya? It’s a 3D engine for Python that has a lot of stuff you might need already pre-built.
It might have been a good idea for me to use an existing 3d engine … but I wanted to try to write a simple engine from scratch. I thought it would be fun!
I remember doing the same thing during a Pyweek once, rewrote the code almost a dozen times. Then abandoned the idea and moved on. Ended up being just a couple things I missed really.
I would suggest looking at how other projects handle it before giving up, as I don’t think it is a limitation in Python – you just have to do it differently. C++ will generally only get you 5-10x (at least from what I have seen, it can be higher, but not usually IIRC)…
Good luck with it though
I look forward to what you come up with
I forgot to mention it earlier, but I figured out how to speed it up quite a bit. I was using a simple 3D grid of cells for a spacial partitioning system with each cell containing the triangles that intersect with it. A lot of the slowdown problem had to do with how Python works. I found that dictionaries are A LOT faster than arrays, so I decided to use dictionaries as arrays. They dictionary keys were simply [z * width * height + y * width + x]. It sounds a little stupid, but the speed increase was amazing. I went from only being able to comfortably do about 7 ray-triangle tests per frame to being able to do around 70 — which would have permitted me to have around 20-25 moving objects (with around 3 ray-triangle tests per object). Unfortunately, this realization came after MANY hours of frustration, leaving me no time to actually complete the game.
You mentioned C++. I decided not to use C++ mainly because I thought development time would have been significantly shortened with Python. C++ requires a lot of extra typing and any change that’s made requires editing a lot of other bits of code. With that said, however, if I used C++ I estimate I would have been able to do thousands of ray-triangle tests per frame. Python is VERY slow.