Portable VPython environment - OR - export options?

115 views
Skip to first unread message

lorenzo...@gmail.com

unread,
Nov 18, 2015, 5:15:00 PM11/18/15
to VPython-users
I'm new to VPython, and I've created a model that I'd like to be able to share with others who do NOT have VPython.  I would prefer to share a version that would be interactive (as opposed to, say, taking various screenshots of the model or posting an animation of it).

As far as I know, this means I need the ability to run VPython scripts in a completely portable environment, OR the ability to export the model to another, more standard 3D format.

Are there such options available?  Specifically, I'm hoping to either be able to run my code as-is in a totally portable environment that anyone could view, or to end up with an accurate replica of my VPython model in one of the following formats: .obj, .stl, .ply, .wrml, .vrml, or .dwg.

Thanks in advance for any help!

Attempts at a solution so far:
  • One issue is that GlowScript does not want to run my code directly.  I've also tried the conversion script written by Bruce Sherwood (http://www.glowscript.org/docs/GlowScriptDocs/VPtoGS.py), but it just tells me that GlowScript does not support extrusions.
  • Trinket appears to embed GlowScript, so I presume it would inherit any limitations imposed by GlowScript.
  • Python Anywhere does not seem to include access to the VPython module.
One potential solution:
  • I've come across a module that allows one to export a VPython scene to POV-Ray (http://vpython.org/contents/contributed.html), so perhaps such a file could be converted to .dwg or other file types.  I'm in the process of trying this solution now, and of determining whether POV-Ray can be converted into a desired file type.

Bruce Sherwood

unread,
Nov 18, 2015, 5:23:42 PM11/18/15
to vpytho...@googlegroups.com
Thanks for the report. Is it just extrusion that is stopping you from using GlowScript? I should update VPtoGS.py, because GlowScript does now have limited support for extrusions, the main limitation being that only closed paths are currently handled (see the GlowScript VPython documentation on the details). I'm currently working on overcoming that limitation.

There is some useful information about making a (necessarily non-interactive) movie here:

lorenzo...@gmail.com

unread,
Nov 19, 2015, 4:45:13 PM11/19/15
to VPython-users
Thank you for your reply.

I believe GlowScript also doesn't like the use of Polygon, but in my case I can convert my Polygon use to shapes.rectangle use, if necessary.  I presumed that VPtoGS.py might convert other troublesome things automatically, but wasn't able to obtain a result due to the extrusions.  I did see that GlowScript does not have some extrusion support, but I haven't begun to look at VPtoGS.py in detail to see if I could modify it to ignore my extrusions (I'm thinking that, as long as my paths are rectangles or circles, and as long as I can modify VPtoGS.py to ignore its check on extrusions, I may have some success); perhaps that would be a wise approach.

I should note that, at some point, I did try to put my VPython code into GlowScript, piece by piece.  I came across some errors that I didn't understand, as I'm more familiar with Python than I am with GlowScript.  If I come across them again, I'd be happy to post them somewhere, if it might be useful.

If these other ideas fail, a movie is probably my best option; thank you for posting the link!

lorenzo...@gmail.com

unread,
Nov 19, 2015, 4:49:05 PM11/19/15
to VPython-users
Typo in post above: "I did see that GlowScript does not have some extrusion support..." should be "I did see that GlowScript does now have some extrusion support..."

Bruce Sherwood

unread,
Nov 19, 2015, 6:09:01 PM11/19/15
to vpytho...@googlegroups.com
In VPtoGS.py, just delete 'extrusion':'not_implemented" from the list "primtypes". That will probably let you get through the conversion process, though you'll have to deal with the Polygon element by hand. Or comment out your extrusion statements before passing your program to VPtoGS.py

By all means, please report errors. It's useful to post them to the GlowScript forum, so that other GlowScript users are aware of them.

lorenzo...@gmail.com

unread,
Nov 19, 2015, 9:13:04 PM11/19/15
to VPython-users
I took your advice and removed the extrusion bits from VPtoGS.py, and that got me through the conversion process.  I also changed all Polygon uses to shapes.rectangle uses.

I now come across this error after running my (converted and "de-Polygoned") script through GlowScript:

Error: Unexpected token: punc �)�; line 143: nest_piece = extrusion( pos = paths.circle( pos = vector( 0 , current_height ,0), radius = 1e-20 ), shape = nest_piece_rect - shapes.rectangle( pos = vector( 0 , nest_piece_height - 0.5 * nest_extrusion_height ,0), width = 2.0 * nest_extrusion_inner_radius, height = nest_extrusion_height ) )

I thought it might be due to the call to paths.circle, due to the hint that there is unexpected punctuation.  But after reading more about GlowScript, I believe GlowScript should support this particular call; I'm not sure what's wrong here.  I should note that VPython runs the script just fine.

Bruce Sherwood

unread,
Nov 19, 2015, 10:04:08 PM11/19/15
to vpytho...@googlegroups.com
It looks like you're trying to subtract one shape from another, which won't work. GlowScript does not yet support holes in a shape (I'm working on it).

It is possible to make hollow objects, however. See

lorenzo...@gmail.com

unread,
Nov 19, 2015, 10:30:40 PM11/19/15
to VPython-users
That's exactly what I'm attempting to do there.

Thanks for the information, and for the link.  It looks like the tube is made from extruding a shapes.rectangle around a paths.circle.  With a little work, I should be able to build up my extrusions using these ones, then - even without the use of shape subtraction.

After commenting the shape subtraction out of the offending line above (as a test), though, the error persists:

Error: Unexpected token: punc �)�; line 143: nest_piece = extrusion( pos = paths.circle( pos = vector( 0 , current_height ,0), radius = 1e-20 ), shape = nest_piece_rect)

null

Is it possible that my underscores are causing issues here?

Bruce Sherwood

unread,
Nov 19, 2015, 11:27:54 PM11/19/15
to vpytho...@googlegroups.com
No, the underscores should be fine. Could you show all or most of your complete program? I tried making an extrusion like yours and didn't get the error you see, which suggests something is odd in the neighborhood of this statement.

I will comment that I found that with distances of the order of 1e-20 the display I see (with my working extrusion) doesn't render very well. It's very unusual to see distances this small in a VPython program, and I'm guessing you're running into precision difficulties in the GPU.

lorenzo...@gmail.com

unread,
Nov 20, 2015, 10:03:53 AM11/20/15
to VPython-users
The script is over 100 lines at that point, so I'll have to do a bit of intelligent filtering in order to cut it down to a reasonable chunk.  This exercise itself may hint at the source of the error; either way, I'll reply with additional details.

The reason for the 1e-20 here is that a radius of 0, while conceptually seeming to be the correct choice, actually produces no 3D object at all (this may be a bug, or - more likely - using "0" for the radius is somewhat of an abuse of the way the paths.circle function is defined).  So the "1e-20" is just a placeholder for "a number close enough to 0 to render visually as though it were 0, without actually being 0 and making the object vanish."  For what it's worth, I did replace the "1e-20" with "0.001" - to check both the notation and the magnitude - to no avail.

I appreciate all your help!
Reply all
Reply to author
Forward
0 new messages