tipam / pi3d Goto Github PK
View Code? Open in Web Editor NEWSimple, yet powerful, 3D Python graphics library for beginners and school children running on the Raspberry Pi.
License: Other
Simple, yet powerful, 3D Python graphics library for beginners and school children running on the Raspberry Pi.
License: Other
Hope I didn't screw it up with one of these refactorings!
I can't seem to get drawString to draw onto a 2D canvas. Maybe it's a Z issue or scaling issue?
This file is based on the bouncingballs code: https://github.com/pabloav/pi3d/blob/82c727cd0d8ab5211440b6cb547db673319923e9/pablo2.py
I added the coffee texture as a rectangle, but the next never seems to appear.
if you try to run without using Demo.py in the top directory:
when in top directory
..$ python demos/Pi3d2.py
Traceback (most recent call last):
File "demos/Pi3d2.py", line 5, in
from pi3d import *
ImportError: No module named pi3d
when in demos directory (which is really where we want the demos to run from i.e. if opened with geany this is where they would run from)
../demos $ python demos/Pi3d2.py
Traceback (most recent call last):
File "Pi3d2.py", line 5, in
from pi3d import *
ImportError: No module named pi3d
reminder that this needs tidying up
Right now, only textures are loadable in a background thread.
If the Shapes are created with x,y,z locations in the constructor they get scrambled as the animation progresses. If they get their locations set using the Shape.position() method straight after construction then everything is ok. This is probably an issue with Shape.init
Tim, I'm not sure that I have the full latest on my Pi now, lots of messages telling me about things that I think I've corrected but..
I had to change the name of the method call to get this to work.
We should probably use the relative mouse instead.
You seem to have forgotten to upload the textures used in Earth2.py demo. stars2.jpg is missing. Also world_map.jpg doesnt exist, but we do have world_map256x256.jpg, the moon.jpg texture is also missing.
Right now, we have two different sorts of mouse readers and two different keyboard readers. One of each needs to be done in a separate thread.
We should clarify which we recommend and for what purposes. The optional threads need to be correctly managed. (At first I thought we could have one thread for both but that means we wouldn't get a new keyboard event until the mouse moved and vice versa.)
Traceback (most recent call last):
File "Demo.py", line 129, in
run_demo(sys.argv[1], demo_list)
File "Demo.py", line 97, in run_demo
run_one_demo(d)
File "Demo.py", line 90, in run_one_demo
import('demos.' + demo)
File "/home/pi/pi3d/demos/ConferenceHall.py", line 49, in
name="Hall", x=x, y=y, z=z, sx=0.1, sy=0.1, sz=0.1)
File "/home/pi/pi3d/pi3d/shape/Model.py", line 27, in init
self.model = loaderEgg.loadFileEGG(self, file_string)
File "/home/pi/pi3d/pi3d/loader/loaderEgg.py", line 67, in loadFileEGG
f = open(fileName, 'r')
IOError: [Errno 2] No such file or directory: 'models/ConferenceHall/conferencehall.egg'
Tim, ForestWalk is now asking for a grass image file. This might be due to my lack of understanding of how to keep versions in synch but I can't see it in your repo either
"importing everything" isn't really a great idea but people do want to do it - so we should provide a "common" file for this purpose.
Why is "importing everything" bad?
It throws a large number of symbols into your "main" namespace. These might silently override other top-level symbols you have, which means you can update the library without changing your code and suddenly get hard-to-find, intermittent bugs because some new symbol overwrites one of your symbols.
Even if that doesn't happen, it means that when someone else reading your code sees a symbol, they have no idea where it comes from. As I say so often, code is written once but read a dozen times, so it's worth doing a little extra work to list the imports even if it's only to make it easier for someone else (perhaps you in six months) to read the code.
I have some TTFs that I'd like to use as fonts - what's the best way to turn them into PNG's that are usable as fonts? I was looking at the code and it looks like you are encoding the height and width so I'm guessing these aren't standard PNG's.
We should fix the demo, find out if that bug really exists, and if so file and fix that.
It crashes and when it was working, it didn't display the text in the right place.
When a shutdown is requested, all threads should terminate automatically.
Includes #17, "I think it's worth adding the thread stopping method to mouse"
Round where it would have a navel, except it isn't a mammal.
Not quite sure what it really is supposed to look like.
Fairly sure I didn't screw up the camera...?
Right now, we tend to get programs hanging when something goes wrong. Explaining to others how to kill all the threads is annoying...
Dying programs should print a stack trace, then graciously shut everything down.
I added this on rec/pi3d Mouse and it makes the terminal return to normal without having to press ctrl+shift+\
Another day of debugging, another reproducible bug.
Please see this simple test case.
The code paths are exactly the same except that in one case, the display is created as a top-level variable, in the other case it's a class member variable - one that's immediately created, but not a top-level variable.
No idea how this bug could possibly be caused or how it could possibly be fixed.
This means that there is no way to change the light for a shape once it's constructed.
Earth.py - remove the actual earth picture. You can see stars all the way down, but the moon and moonlet go behind the cloud curtain.
Not sure whether this is involved with how a texture is invisible on a plane when the plane has its back to you. (trick to avoid the problem: dupe the texture, flip horizontally, create an identical shape for the flipped texture as for the normal one, rotate the flipped shape on Y by 180 degrees, then whenever the normal shape is rotated X, Y, and Z, rotate the flipped one -X, Y, -Z.) Works on a plane. When the plane's backside is showing, you see it as if you're looking through the plane. Left to right: Europe, Americas, Australia.
This looks fantastic, but it's not clear under what terms it may be redistributed. MIT is always my personal choice. http://en.wikipedia.org/wiki/MIT_License
This took me a long time to boil down into a tiny test case. I still don't have a good fix for it in general though I can work around it in my codebase.
Take a look at this piece of test code. There's a tiny event_loop in a function called "event_loop" which simply displays a header image and nothing else.
You can see from the code that if you set ENABLE_BUG to False, event_loop runs in the main thread - if it's True, then the event loop runs in a new Python thread.
If you run the code with ENABLE_BUG=False, then you see the correct pink window with a header. If you run the code with ENABLE_BUG=True, you see a white screen with nothing in it.
(Note that if you set ENABLE_BUG to True, the program won't terminate with a control-C - you have to kill it from a separate terminal instance. This is expected behavior for Python threads - I could have put code to avoid that happening but didn't want to obscure the issue.)
These are slightly different tasks but both need doing.
Question:
Hi there. I am looking for python 3D library for Raspberry Pi and ended up at pi3d which looks great to me. I am starting programming in python on rpi, but have become interested in 3D stuff. I would like to build something like the Apple TV 2/3 photo screensaver animation. If you don't know what that looks like, have a look here: http://www.youtube.com/watch?v=_o7ikkq2Mug Take special attention at the effects shown around 1:44 in the video.
Would this be possible with this library?
You get a crash because the number of faces is not the same as the number of arrays.
It seems to me this is to do with the nobottom fix - because I could fix it by turning nobottom to off.
I added a top-level flag to do that and also an assertion to go off before the error does... I'll push it as soon as I get more bandwidth...
Don't think I broke it, assign it to me if I did!
Traceback (most recent call last):
File "Demo.py", line 129, in
run_demo(sys.argv[1], demo_list)
File "Demo.py", line 97, in run_demo
run_one_demo(d)
File "Demo.py", line 90, in run_one_demo
import('demos.' + demo)
File "/home/pi/pi3d/demos/Pi3d2.py", line 76, in
mystring.draw()
File "/home/pi/pi3d/pi3d/shape/Shape.py", line 124, in draw
b.draw(shader, txtrs, ntl, shny)
File "/home/pi/pi3d/pi3d/Buffer.py", line 114, in draw
opengles.glBindTexture(GL_TEXTURE_2D, texture.tex())
TypeError: 'c_long' object is not callable
Traceback (most recent call last):
File "Demo.py", line 129, in
run_demo(sys.argv[1], demo_list)
File "Demo.py", line 97, in run_demo
run_one_demo(d)
File "Demo.py", line 90, in run_one_demo
import('demos.' + demo)
File "/home/pi/pi3d/demos/Pong.py", line 214, in
score0.draw()
File "/home/pi/pi3d/pi3d/shape/Shape.py", line 124, in draw
b.draw(shader, txtrs, ntl, shny)
File "/home/pi/pi3d/pi3d/Buffer.py", line 114, in draw
opengles.glBindTexture(GL_TEXTURE_2D, texture.tex())
TypeError: 'c_long' object is not callable
Traceback (most recent call last):
File "Demo.py", line 129, in
run_demo(sys.argv[1], demo_list)
File "Demo.py", line 97, in run_demo
run_one_demo(d)
File "Demo.py", line 90, in run_one_demo
import('demos.' + demo)
File "/home/pi/pi3d/demos/Shapes.py", line 130, in
mystring.draw()
File "/home/pi/pi3d/pi3d/shape/Shape.py", line 124, in draw
b.draw(shader, txtrs, ntl, shny)
File "/home/pi/pi3d/pi3d/Buffer.py", line 114, in draw
opengles.glBindTexture(GL_TEXTURE_2D, texture.tex())
TypeError: 'c_long' object is not callable
Peculiar, it now works but the geometry is scaled so that we have tall, thin balls.
Traceback (most recent call last):
File "Demo.py", line 129, in
run_demo(sys.argv[1], demo_list)
File "Demo.py", line 97, in run_demo
run_one_demo(d)
File "Demo.py", line 90, in run_one_demo
import('demos.' + demo)
File "/home/pi/pi3d/demos/BouncingBalls.py", line 15, in
from pi3d.util.String import drawString2D
ImportError: cannot import name drawString2D
Traceback (most recent call last):
File "Demo.py", line 37, in <module>
__import__('demos.' + d)
File "/home/pi/pi3d/demos/Amazing.py", line 81, in <module>
shed = Model("models/shed1.obj",texs,"shed",0,3,0, 0,0,0, 2,2,2)
File "/home/pi/pi3d/pi3d/shape/Model.py", line 27, in __init__
self.model = loaderObj.loadFileOBJ(self, fileString, texs)
File "/home/pi/pi3d/pi3d/loaderObj.py", line 151, in loadFileOBJ
f = open(fileName, 'r')
IOError: [Errno 2] No such file or directory: 'models/shed1.obj'```
If a texture is read from a file, but then read from the same file later and flipped, the code in pi3dcommon.py::textures() will reuse the first texture instead of loading a new, flipped one.
The cache needs to remember flip and compare it, too, besides file name.
Separate subject, slightly: 'flip' could be 1 for TOP_BOTTOM flip and -1 for LEFT_RIGHT flip.
We can't as yet go full-screen if using tk windows, nor can we detect the screen size.
Look at this test file.
If you run it as is, it displays a pink window with a header.
If you set the ENABLE_BUG flag to be True, it doesn't display the header - but then the background appears as black.
Right now we duplicate more or less the same code in every demo.
Everything else is fine, doesn't appear to be anything I've done...
Traceback (most recent call last):
File "./demos/ConferenceHall.py", line 117, in
DISPLAY.resize(win.winx,win.winy,win.width,win.height-bord)
File "/home/pi/pi3d/pi3d/Display.py", line 105, in resize
self.opengl.resize(x, y, w, h)
File "/home/pi/pi3d/pi3d/util/DisplayOpenGL.py", line 110, in resize
self.create_surface(x, y, w, h)
File "/home/pi/pi3d/pi3d/util/DisplayOpenGL.py", line 92, in create_surface
assert self.surface != EGL_NO_SURFACE
AssertionError
AssertionError
Trying to use the save3Dfile function will result in following Tracebak:
Traceback (most recent call last):
File "Earth2.py", line 38, in
pi3d.save3Dfile("sphere.p3d",mysphere)
File "include/pi3dCommon.py", line 179, in save3Dfile
pickle.dump(model,f)
File "/usr/lib/python2.7/pickle.py", line 1370, in dump
Pickler(file, protocol).dump(obj)
File "/usr/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/usr/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/usr/lib/python2.7/pickle.py", line 419, in save_reduce
save(state)
File "/usr/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/lib/python2.7/pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "/usr/lib/python2.7/pickle.py", line 663, in _batch_setitems
save(v)
File "/usr/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/usr/lib/python2.7/pickle.py", line 401, in save_reduce
save(args)
File "/usr/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/lib/python2.7/pickle.py", line 562, in save_tuple
save(element)
File "/usr/lib/python2.7/pickle.py", line 300, in save
self.save_global(obj)
File "/usr/lib/python2.7/pickle.py", line 748, in save_global
(obj, module, name))
pickle.PicklingError: Can't pickle <class 'pi3dCommon.c_float_Array_1250'>: it's not found as pi3dCommon.c_float_Array_1250
I don't remember seeing this before - but I don't see how it'd work actually work any other way than considerable work on our part computing the clipping rectangle.
Traceback (most recent call last):
File "Demo.py", line 129, in
run_demo(sys.argv[1], demo_list)
File "Demo.py", line 97, in run_demo
run_one_demo(d)
File "Demo.py", line 90, in run_one_demo
import('demos.' + demo)
File "/home/pi/pi3d/demos/ForestWalk2.py", line 64, in
treemodel1.add(treeplane, 0,0,0)
File "/home/pi/pi3d/pi3d/shape/MergeShape.py", line 76, in add
self.merge(shape, x, y, z, rx, ry, rz, sx, sy, sz, cx, cy, cz)
File "/home/pi/pi3d/pi3d/shape/MergeShape.py", line 38, in merge
assert len(shape.vertices) == len(shape.normals)
AttributeError: 'Plane' object has no attribute 'vertices'
This is different between the two keyboard models.
We need to be able to support both ways of getting events from both models...
We need a document explaining all the ways that you can get bad results with the program - this includes documenting the white screens and stack traces with inadequate memory.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.